Sonic CD runs on GP2X

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@21 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-01-19 22:08:50 +00:00
parent 15f385743a
commit 8dfb9fd5df
13 changed files with 113 additions and 106 deletions

View file

@ -1,9 +1,5 @@
#include "940shared.h"
/* this code assumes that we live @ 0x3000000 bank */
//static volatile unsigned short *gp2x_memregs = (void *) 0x0xbd000000;
//static volatile unsigned long *gp2x_memregl = (void *) 0x0xbd000000;
static _940_data_t *shared_data = (_940_data_t *) 0x100000;
static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x200000;
YM2612 *ym2612_940;
@ -28,10 +24,10 @@ void Main940(int startvector)
shared_ctl->vstarts[startvector]++;
asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0");
/* unmask IRQs */
for (;; shared_ctl->loopc++)
{
int job_num;
/*
while (!shared_ctl->busy)
{
@ -44,50 +40,54 @@ void Main940(int startvector)
wait_irq();
}
switch (shared_ctl->job)
for (job_num = 0; job_num < MAX_940JOBS; job_num++)
{
case JOB940_YM2612INIT:
shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff;
YM2612Init_(shared_ctl->baseclock, shared_ctl->rate);
break;
switch (shared_ctl->jobs[job_num])
{
case JOB940_YM2612INIT:
shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff;
YM2612Init_(shared_ctl->baseclock, shared_ctl->rate);
break;
case JOB940_YM2612RESETCHIP:
YM2612ResetChip_();
break;
case JOB940_YM2612RESETCHIP:
YM2612ResetChip_();
break;
case JOB940_PICOSTATELOAD:
YM2612PicoStateLoad_();
break;
case JOB940_PICOSTATELOAD:
YM2612PicoStateLoad_();
break;
case JOB940_YM2612UPDATEONE: {
int i, dw, *wbuff;
if (shared_ctl->writebuffsel == 1) {
wbuff = (int *) shared_ctl->writebuff1;
} else {
wbuff = (int *) shared_ctl->writebuff0;
case JOB940_YM2612UPDATEONE: {
int i, dw, *wbuff;
if (shared_ctl->writebuffsel == 1) {
wbuff = (int *) shared_ctl->writebuff1;
} else {
wbuff = (int *) shared_ctl->writebuff0;
}
/* playback all writes */
for (i = 2048/2; i > 0; i--) {
UINT16 d;
dw = *wbuff++;
d = dw;
if (d == 0xffff) break;
YM2612Write_(d >> 8, d);
d = (dw>>16);
if (d == 0xffff) break;
YM2612Write_(d >> 8, d);
}
YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo);
break;
}
/* playback all writes */
for (i = 2048/2; i > 0; i--) {
UINT16 d;
dw = *wbuff++;
d = dw;
if (d == 0xffff) break;
YM2612Write_(d >> 8, d);
d = (dw>>16);
if (d == 0xffff) break;
YM2612Write_(d >> 8, d);
}
YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo);
// cache_clean_flush();
cache_clean();
// asm volatile ("mov r0, #0" ::: "r0");
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer, should be done on nonbuffered write */
break;
}
}
shared_ctl->busy = 0;
// cache_clean_flush();
cache_clean();
// asm volatile ("mov r0, #0" ::: "r0");
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer, should be done on nonbuffered write */
}
}

View file

@ -250,9 +250,10 @@ static void wait_busy_940(void)
}
static void add_job_940(int job)
static void add_job_940(int job0, int job1)
{
shared_ctl->job = job;
shared_ctl->jobs[0] = job0;
shared_ctl->jobs[1] = job1;
shared_ctl->busy = 1;
gp2x_memregs[0x3B3E>>1] = 0xffff; // cause an IRQ for 940
}
@ -276,7 +277,7 @@ void YM2612PicoStateLoad_940(void)
addr_A1 = old_A1;
add_job_940(JOB940_PICOSTATELOAD);
add_job_940(JOB940_PICOSTATELOAD, 0);
}
@ -299,10 +300,9 @@ extern char **g_argv;
void YM2612Init_940(int baseclock, int rate)
{
printf("YM2612Init_940()\n");
//printf("sizeof(*shared_data): %i (%x)\n", sizeof(*shared_data), sizeof(*shared_data));
//printf("sizeof(*shared_ctl): %i (%x)\n", sizeof(*shared_ctl), sizeof(*shared_ctl));
printf("Mem usage: shared_data: %i, shared_ctl: %i\n", sizeof(*shared_data), sizeof(*shared_ctl));
Reset940(1);
Reset940(1, 2);
Pause940(1);
gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940
@ -312,7 +312,7 @@ void YM2612Init_940(int baseclock, int rate)
if (shared_mem == NULL)
{
shared_mem = (unsigned char *) mmap(0, 0x210000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x3000000);
shared_mem = (unsigned char *) mmap(0, 0x210000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x2000000);
if(shared_mem == MAP_FAILED)
{
printf("mmap(shared_data) failed with %i\n", errno);
@ -373,11 +373,12 @@ void YM2612Init_940(int baseclock, int rate)
/* now cause 940 to init it's ym2612 stuff */
shared_ctl->baseclock = baseclock;
shared_ctl->rate = rate;
shared_ctl->job = JOB940_YM2612INIT;
shared_ctl->jobs[0] = JOB940_YM2612INIT;
shared_ctl->jobs[1] = 0;
shared_ctl->busy = 1;
/* start the 940 */
Reset940(0);
Reset940(0, 2);
Pause940(0);
// YM2612ResetChip_940(); // will be done on JOB940_YM2612INIT
@ -396,7 +397,7 @@ void YM2612ResetChip_940(void)
internal_reset();
add_job_940(JOB940_YM2612RESETCHIP);
add_job_940(JOB940_YM2612RESETCHIP, 0);
}
@ -444,7 +445,7 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo)
shared_ctl->writebuffsel ^= 1;
shared_ctl->length = length;
shared_ctl->stereo = stereo;
add_job_940(JOB940_YM2612UPDATEONE);
add_job_940(JOB940_YM2612UPDATEONE, 0);
//spend_cycles(512);
//printf("SRCPND: %08lx, INTMODE: %08lx, INTMASK: %08lx, INTPEND: %08lx\n",
// gp2x_memregl[0x4500>>2], gp2x_memregl[0x4504>>2], gp2x_memregl[0x4508>>2], gp2x_memregl[0x4510>>2]);

View file

@ -31,9 +31,9 @@ code940: @ interrupt table:
b .Begin
.b_irq:
mov r12, #6
mov sp, #0x100000 @ reset stack
sub sp, sp, #4
mov r1, #0xbd000000 @ assume we live @ 0x3000000 bank
mov sp, #0x100000 @ reset stack
sub sp, sp, #4
mov r1, #0xbe000000 @ assume we live @ 0x2000000 bank
orr r2, r1, #0x3B00
orr r2, r2, #0x0046
mvn r3, #0
@ -48,51 +48,51 @@ code940: @ interrupt table:
b .Begin
.Begin:
mov sp, #0x100000 @ set the stack top (1M)
sub sp, sp, #4 @ minus 4
mov sp, #0x100000 @ set the stack top (1M)
sub sp, sp, #4 @ minus 4
@ set up memory region 0 -- the whole 4GB address space
mov r0, #(0x1f<<1)|1 @ region data
mcr p15, 0, r0, c6, c0, 0 @ opcode2 ~ data/instr
mcr p15, 0, r0, c6, c0, 1
@ set up memory region 0 -- the whole 4GB address space
mov r0, #(0x1f<<1)|1 @ region data
mcr p15, 0, r0, c6, c0, 0 @ opcode2 ~ data/instr
mcr p15, 0, r0, c6, c0, 1
@ set up region 1 which is the first 2 megabytes.
mov r0, #(0x14<<1)|1 @ region data
mcr p15, 0, r0, c6, c1, 0
mcr p15, 0, r0, c6, c1, 1
mov r0, #(0x14<<1)|1 @ region data
mcr p15, 0, r0, c6, c1, 0
mcr p15, 0, r0, c6, c1, 1
@ set up region 2: 64k 0x200000-0x210000
mov r0, #(0x0f<<1)|1
mov r0, #(0x0f<<1)|1
orr r0, r0, #0x200000
mcr p15, 0, r0, c6, c2, 0
mcr p15, 0, r0, c6, c2, 1
mcr p15, 0, r0, c6, c2, 0
mcr p15, 0, r0, c6, c2, 1
@ set up region 3: 64k 0xbd000000-0xbd010000 (hw control registers)
mov r0, #(0x0f<<1)|1
orr r0, r0, #0xbd000000
mcr p15, 0, r0, c6, c3, 0
mcr p15, 0, r0, c6, c3, 1
@ set up region 3: 64k 0xbe000000-0xbe010000 (hw control registers)
mov r0, #(0x0f<<1)|1
orr r0, r0, #0xbe000000
mcr p15, 0, r0, c6, c3, 0
mcr p15, 0, r0, c6, c3, 1
@ set region 1 to be cacheable (so the first 2M will be cacheable)
mov r0, #2
mcr p15, 0, r0, c2, c0, 0
mcr p15, 0, r0, c2, c0, 1
mov r0, #2
mcr p15, 0, r0, c2, c0, 0
mcr p15, 0, r0, c2, c0, 1
@ set region 1 to be bufferable too (only data)
mcr p15, 0, r0, c3, c0, 0
mcr p15, 0, r0, c3, c0, 0
@ set protection, allow accsess only to regions 1 and 2
mov r0, #(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, no access] for regions [3 2 1 0]
mcr p15, 0, r0, c5, c0, 0
mov r0, #(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, full, no]
mcr p15, 0, r0, c5, c0, 1
mov r0, #(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, no access] for regions [3 2 1 0]
mcr p15, 0, r0, c5, c0, 0
mov r0, #(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, full, no]
mcr p15, 0, r0, c5, c0, 1
mrc p15, 0, r0, c1, c0, 0 @ fetch current control reg
orr r0, r0, #1 @ 0x00000001: enable protection unit
orr r0, r0, #4 @ 0x00000004: enable D cache
orr r0, r0, #0x1000 @ 0x00001000: enable I cache
orr r0, r0, #0xC0000000 @ 0xC0000000: async+fastbus
mcr p15, 0, r0, c1, c0, 0 @ set control reg
mrc p15, 0, r0, c1, c0, 0 @ fetch current control reg
orr r0, r0, #1 @ 0x00000001: enable protection unit
orr r0, r0, #4 @ 0x00000004: enable D cache
orr r0, r0, #0x1000 @ 0x00001000: enable I cache
orr r0, r0, #0xC0000000 @ 0xC0000000: async+fastbus
mcr p15, 0, r0, c1, c0, 0 @ set control reg
@ flush (invalidate) the cache (just in case)
mov r0, #0
@ -172,3 +172,5 @@ wait_irq:
b .b_reserved
.pool
@ vim:filetype=ignored:

View file

@ -8,24 +8,26 @@ enum _940_job_t {
JOB940_NUMJOBS
};
#define MAX_940JOBS 2
typedef struct
{
YM2612 ym2612; /* current state of the emulated YM2612 */
int mix_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */
int mix_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */
short mp3_buffer[2][1152*2]; /* buffer for mp3 decoder's output */
} _940_data_t;
typedef struct
{
int job; /* a job for second core */
int jobs[MAX_940JOBS]; /* jobs for second core */
int busy; /* busy status of the 940 core */
int length; /* number of samples to mix (882 max) */
int stereo; /* mix samples as stereo, doubles sample count automatically */
int baseclock; /* ym2612 settings */
int rate;
int writebuffsel; /* which write buffer to use (from 940 side) */
UINT16 writebuff0[2048]; /* 1024 for savestates, 1024 extra */
UINT16 writebuff0[2048]; /* list of writes to ym2612, 1024 for savestates, 1024 extra */
UINT16 writebuff1[2048];
int vstarts[8]; /* debug: number of starts from each of 8 vectors */
int loopc; /* debug: main loop counter */

View file

@ -10,7 +10,7 @@ CROSS = arm-linux-
dprint = 1
#mz80 = 1
#debug_cyclone = 1
asm_memory = 1
asm_memory = 0 # TODO
asm_render = 1
asm_ym2612 = 1
#profile = 1
@ -42,7 +42,7 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory
../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
# Pico - CD
OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \
../../Pico/cd/cd_sys.o
../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o
# asm stuff
ifeq "$(asm_render)" "1"
DEFINC += -D_ASM_DRAW_C

View file

@ -374,7 +374,7 @@ int emu_ReloadRom(void)
}
}
gettimeofday(&noticeMsgTime, 0);
printf("PicoMCD: %x\n", PicoMCD);
// load SRAM for this ROM
if(currentConfig.EmuOpt & 1)
emu_SaveLoadGame(1, 1);
@ -586,8 +586,10 @@ void osd_text(int x, int y, char *text)
static void cd_leds(void)
{
static int old_reg = 0;
if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change
// mmu problems?
// static
int old_reg;
// if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change
old_reg = Pico_mcd->s68k_regs[0];
if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {
@ -1021,7 +1023,7 @@ void emu_Loop(void)
if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) {
/* if 940 is turned off, we need it to be put back to sleep */
if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) {
Reset940(1);
Reset940(1, 2);
Pause940(1);
}
sound_rerate();

View file

@ -223,9 +223,9 @@ void Pause940(int yes)
}
void Reset940(int yes)
void Reset940(int yes, int bank)
{
gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (0x03); /* bank=3 */
gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03); /* bank=3 */
}
@ -280,7 +280,7 @@ char *ext_menu = 0, *ext_state = 0;
void gp2x_deinit(void)
{
Reset940(1);
Reset940(1, 3);
Pause940(1);
gp2x_video_changemode(15);

View file

@ -25,7 +25,7 @@ unsigned long gp2x_joystick_read(int allow_usb_joy);
/* 940 core */
void Pause940(int yes);
void Reset940(int yes);
void Reset940(int yes, int bank);
extern void *gp2x_screen;

View file

@ -86,8 +86,8 @@ int main(int argc, char *argv[])
mmuhack_status = ret;
}
cpuctrl_init();
Reset940(1);
Pause940(1);
// Reset940(1);
// Pause940(1);
if (currentConfig.EmuOpt&0x100) {
printf("setting RAM timings.. "); fflush(stdout);
// craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2

View file

@ -959,7 +959,7 @@ static void draw_menu_root(int menu_sel)
} else {
y += 30;
}
gp2x_text_out8(tl_x, (y+=10), "Load new ROM");
gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO");
gp2x_text_out8(tl_x, (y+=10), "Change options");
gp2x_text_out8(tl_x, (y+=10), "Configure controls");
gp2x_text_out8(tl_x, (y+=10), "Credits");

View file

@ -12,7 +12,7 @@
// pico.c
#define CAN_HANDLE_240_LINES 1
//#define dprintf(f,...) printf(f"\n",##__VA_ARGS__)
//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)
#define dprintf(x...)
#endif //PORT_CONFIG_H

View file

@ -1,2 +1,2 @@
#define VERSION "0.965"
#define VERSION "1.10"

View file

@ -327,7 +327,7 @@ void Pause940(int yes)
{
}
void Reset940(int yes)
void Reset940(int yes, int bank)
{
}