#if defined(EMU_C68K)\r
pc-=PicoCpu.membase; // Get real pc\r
pc&=0xfffffe;\r
+ if (pc == 0)\r
+ return (int)Pico.rom + Pico.romsize; // common crash condition, can happen if acc timing is off\r
\r
PicoCpu.membase=PicoMemBase(pc);\r
\r
//if(a==0x200000) dprintf("cc : %02x @ %06x [%i|%i]", d, SekPc, SekCyclesDoneT(), SekCyclesDone());\r
//if(a==0x200001) dprintf("w8 : %02x @ %06x [%i]", d, SekPc, SekCyclesDoneT());\r
if(a >= SRam.start && a <= SRam.end) {\r
+ dprintf("sram w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc);\r
unsigned int sreg = Pico.m.sram_reg;\r
if(!(sreg & 0x10)) {\r
// not detected SRAM\r
#else\r
// sram access register\r
if(a == 0xA130F1) {\r
- Pico.m.sram_reg = (u8)(d&3);\r
+ dprintf("sram reg=%02x", d);\r
+ Pico.m.sram_reg &= ~3;\r
+ Pico.m.sram_reg |= (u8)(d&3);\r
return;\r
}\r
#endif\r
mov r0, r0, lsr #8\r
orr r0, r0, r1, lsl #8\r
bx lr\r
+\r
m_read16_nosram:\r
ldr r1, [r3, #4] @ 1ci\r
cmp r0, r1\r
bic r0, r0, #1\r
mov r1, #16\r
b OtherRead16\r
-@ ldr r2, =OtherRead16\r
-@ bx r2\r
\r
m_read16_vdp:\r
tst r0, #0x70000\r
bxne lr @ invalid read\r
bic r0, r0, #1\r
b PicoVideoRead\r
-@ ldr r1, =PicoVideoRead\r
-@ bx r1\r
\r
m_read16_ram:\r
ldr r1, =Pico\r
bic r0, r0, #1\r
mov r1, #16\r
b OtherRead16End\r
-@ ldr r2, =OtherRead16End\r
-@ bx r2\r
\r
.pool\r
\r
and r1, r1, #0xff\r
orr r0, r0, r1, lsl #8\r
bx lr\r
+\r
m_read32_nosram:\r
ldr r1, [r3, #4] @ (1ci)\r
cmp r0, r1\r
\r
@ sram register\r
ldr r2, =(Pico+0x22211) @ Pico.m.sram_reg\r
+ ldrb r0, [r2]\r
and r1, r1, #3\r
- strb r1, [r2]\r
+ bic r0, r0, #3\r
+ orr r0, r0, r1\r
+ strb r0, [r2]\r
bx lr\r
\r
pwr_banking:\r
str r12, [r2, r0, lsl #2]\r
\r
bx lr\r
+\r
// |=0x80 for Shadow of the Beast & Super Offroad; rotate fakes next fetched instruction for Time Killers
if (a==0xa11100) { // z80 busreq
d=Pico.m.z80Run&1;
+#if 1
if (!d) {
// needed by buggy Terminator (Sega CD)
extern int z80stopCycle;
if (stop_before > 0 && stop_before <= 32) // Gens uses 16 here
d = 1; // bus not yet available
}
+#endif
d=(d<<8)|0x8000|Pico.m.rotate++;
dprintf("get_zrun: %04x [%i|%i] @%06x", d, Pico.m.scanline, SekCyclesDone(), SekPc);
goto end;
// Dino Dini's Soccer malfunctions if SRAM is not filled with 0xff\r
if (strncmp((char *)Pico.rom+0x150, "IDOND NI'I", 10) == 0)\r
memset(SRam.data, 0xff, sram_size);\r
+ dprintf("sram: det: %i; eeprom: %i; start: %06x; end: %06x\n",\r
+ (Pico.m.sram_reg>>4)&1, (Pico.m.sram_reg>>2)&1, SRam.start, SRam.end);\r
}\r
\r
Pico.m.sram_reg = SRam.reg_back; // restore sram_reg\r
extern void (*PicoWriteSound)(int len); // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
extern void (*PicoMessage)(const char *msg); // callback to output text message from emu\r
\r
+// cd/Pico.c\r
int PicoFrameMCD(void);\r
+extern void (*PicoMCDopenTray)(void);\r
+extern int (*PicoMCDcloseTray)(void);\r
\r
extern int PicoCDBuffers;\r
\r
char dirtyPal; // Is the palette dirty (1 - change @ this frame, 2 - some time before)\r
unsigned char hardware; // Hardware value for country\r
unsigned char pal; // 1=PAL 0=NTSC\r
- unsigned char sram_reg; // SRAM mode register. bit0: allow read? bit1: deny write? bit2: EEPROM?\r
+ unsigned char sram_reg; // SRAM mode register. bit0: allow read? bit1: deny write? bit2: EEPROM? bit4: detected? (header or by access)\r
unsigned short z80_bank68k;\r
unsigned short z80_lastaddr; // this is for Z80 faking\r
unsigned char z80_fakeval;\r
unsigned short sram_addr; // EEPROM address register\r
unsigned char sram_cycle; // EEPROM SRAM cycle number\r
unsigned char sram_slave; // EEPROM slave word for X24C02 and better SRAMs\r
- unsigned char prot_bytes[2]; // simple protection fakeing\r
+ unsigned char prot_bytes[2]; // simple protection faking\r
unsigned short dma_bytes; //\r
unsigned char pad[2];\r
unsigned int frame_count; // mainly for movies\r
\r
memcpy16bswap(dest, src, length);\r
\r
- { // debug\r
+ /*{ // debug\r
unsigned char *b1 = Pico_mcd->word_ram1M[bank] + dep;\r
unsigned char *b2 = (unsigned char *)(dest+length) - 8;\r
dprintf("%02x %02x %02x %02x .. %02x %02x %02x %02x",\r
b1[0], b1[1], b1[4], b1[5], b2[0], b2[1], b2[4], b2[5]);\r
- }\r
+ }*/\r
}\r
else\r
{\r
\r
memcpy16bswap(dest, src, length);\r
\r
- { // debug\r
+ /*{ // debug\r
unsigned char *b1 = Pico_mcd->word_ram2M + dep;\r
unsigned char *b2 = (unsigned char *)(dest+length) - 4;\r
dprintf("%02x %02x %02x %02x .. %02x %02x %02x %02x",\r
b1[0], b1[1], b1[2], b1[3], b2[0], b2[1], b2[2], b2[3]);\r
- }\r
+ }*/\r
}\r
}\r
else if (which == 4) // PCM RAM (check: popful Mail)\r
\r
memcpy16bswap(dest, src, length);\r
\r
- { // debug\r
+ /*{ // debug\r
unsigned char *b1 = Pico_mcd->prg_ram + dep;\r
unsigned char *b2 = (unsigned char *)(dest+length) - 4;\r
dprintf("%02x %02x %02x %02x .. %02x %02x %02x %02x",\r
b1[0], b1[1], b1[2], b1[3], b2[0], b2[1], b2[2], b2[3]);\r
- }\r
+ }*/\r
}\r
\r
length <<= 1;\r
(Pico_mcd->cdc.Buffer[addr]<<8) | Pico_mcd->cdc.Buffer[addr+1], Pico_mcd->cdc.DAC.N, Pico_mcd->cdc.DBC.N);\r
\r
return (Pico_mcd->cdc.Buffer[addr]<<8) | Pico_mcd->cdc.Buffer[addr+1];\r
-\r
-#if 0\r
- __asm\r
- {\r
- mov esi, Pico_mcd->cdc.DAC.N\r
- lea ebx, Pico_mcd->cdc.Buffer\r
-// and esi, 0x3FFF\r
- mov ax, [ebx + esi]\r
- add esi, 2\r
- rol ax, 8\r
- mov Pico_mcd->cdc.DAC.N, esi\r
- mov val, ax\r
- }\r
-#endif\r
}\r
\r
\r
//#define __debug_io\r
//#define __debug_io2\r
\r
-//#define rdprintf dprintf\r
-#define rdprintf(...)\r
+#define rdprintf dprintf\r
+//#define rdprintf(...)\r
//#define wrdprintf dprintf\r
#define wrdprintf(...)\r
-//#define plprintf dprintf\r
-#define plprintf(...)\r
+#define plprintf dprintf\r
+//#define plprintf(...)\r
\r
// -----------------------------------------------------------------\r
\r
Pico_mcd->m.busreq = d;\r
return;\r
case 2:\r
+ dprintf("m68k: prg wp=%02x", d);\r
Pico_mcd->s68k_regs[2] = d; // really use s68k side register\r
return;\r
case 3: {\r
{\r
if ((a&0xffffc0)==0xa12000) { m68k_reg_write8(a, d); return; }\r
\r
- dprintf("m68k FIXME: strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc);\r
+ dprintf("m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc);\r
}\r
\r
\r
if (a < 0x20000) { d = *(u8 *)(Pico_mcd->bios+(a^1)); goto end; } // bios\r
\r
// prg RAM\r
- if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+ if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
d = *(prg_bank+((a^1)&0x1ffff));\r
goto end;\r
if (a < 0x20000) { d = *(u16 *)(Pico_mcd->bios+a); goto end; } // bios\r
\r
// prg RAM\r
- if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+ if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
wrdprintf("m68k_prgram r16: [%i,%06x] @%06x", Pico_mcd->s68k_regs[3]>>6, a, SekPc);\r
d = *(u16 *)(prg_bank+(a&0x1fffe));\r
if (a < 0x20000) { u16 *pm=(u16 *)(Pico_mcd->bios+a); d = (pm[0]<<16)|pm[1]; goto end; } // bios\r
\r
// prg RAM\r
- if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+ if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
u16 *pm=(u16 *)(prg_bank+(a&0x1fffe));\r
d = (pm[0]<<16)|pm[1];\r
\r
\r
// -----------------------------------------------------------------\r
-// Write Ram\r
\r
#ifdef _ASM_CD_MEMORY_C\r
void PicoWriteM68k8(u32 a,u8 d);\r
a&=0xffffff;\r
\r
// prg RAM\r
- if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+ if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
*(u8 *)(prg_bank+((a^1)&0x1ffff))=d;\r
return;\r
a&=0xfffffe;\r
\r
// prg RAM\r
- if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+ if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
wrdprintf("m68k_prgram w16: [%i,%06x] %04x @%06x", Pico_mcd->s68k_regs[3]>>6, a, d, SekPc);\r
*(u16 *)(prg_bank+(a&0x1fffe))=d;\r
a&=0xfffffe;\r
\r
// prg RAM\r
- if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+ if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
u16 *pm=(u16 *)(prg_bank+(a&0x1fffe));\r
pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
#endif\r
\r
\r
+// -----------------------------------------------------------------\r
+// S68k\r
// -----------------------------------------------------------------\r
\r
#ifdef _ASM_CD_MEMORY_C\r
// prg RAM\r
if (a < 0x80000) {\r
u8 *pm=(u8 *)(Pico_mcd->prg_ram+(a^1));\r
- *pm=d;\r
+ if (a >= (Pico_mcd->s68k_regs[2]<<8)) *pm=d;\r
return;\r
}\r
\r
// prg RAM\r
if (a < 0x80000) {\r
wrdprintf("s68k_prgram w16: [%06x] %04x @%06x", a, d, SekPcS68k);\r
- *(u16 *)(Pico_mcd->prg_ram+a)=d;\r
+ if (a >= (Pico_mcd->s68k_regs[2]<<8)) // needed for Dungeon Explorer\r
+ *(u16 *)(Pico_mcd->prg_ram+a)=d;\r
return;\r
}\r
\r
\r
// prg RAM\r
if (a < 0x80000) {\r
- u16 *pm=(u16 *)(Pico_mcd->prg_ram+a);\r
- pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
+ if (a >= (Pico_mcd->s68k_regs[2]<<8)) {\r
+ u16 *pm=(u16 *)(Pico_mcd->prg_ram+a);\r
+ pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
+ }\r
return;\r
}\r
\r
orr r3, r2, #0x002200
ldr r3, [r1, r3]
ldr r2, [r1, r2]
- tst r3, #0x00020000 @ have bus?
+ and r3, r3, #0x00030000
+ cmp r3, #0x00010000 @ have bus or in reset state?
moveq r0, #0
bxeq lr
and r2, r2, #0xc0000000 @ r3 & 0xC0
orr r3, r2, #0x002200
ldr r3, [r1, r3]
ldr r2, [r1, r2]
- tst r3, #0x00020000 @ have bus?
+ and r3, r3, #0x00030000
+ cmp r3, #0x00010000 @ have bus or in reset state?
moveq r0, #0
bxeq lr
and r2, r2, #0xc0000000 @ r3 & 0xC0
orr r3, r2, #0x002200
ldr r3, [r1, r3]
ldr r2, [r1, r2]
- tst r3, #0x00020000 @ have bus?
+ and r3, r3, #0x00030000
+ cmp r3, #0x00010000 @ have bus or in reset state?
moveq r0, #0
bxeq lr
and r2, r2, #0xc0000000 @ r3 & 0xC0
orr r3, r12, #0x002200
ldr r3, [r2, r3]
ldr r12,[r2, r12]
- tst r3, #0x00020000 @ have bus?
+ and r3, r3, #0x00030000
+ cmp r3, #0x00010000 @ have bus or in reset state?
bxeq lr
and r12,r12,#0xc0000000 @ r3 & 0xC0
add r2, r2, r12, lsr #12
orr r3, r12, #0x002200
ldr r3, [r2, r3]
ldr r12,[r2, r12]
- tst r3, #0x00020000 @ have bus?
+ and r3, r3, #0x00030000
+ cmp r3, #0x00010000 @ have bus or in reset state?
bxeq lr
and r12,r12,#0xc0000000 @ r3 & 0xC0
add r2, r2, r12, lsr #12
orr r3, r12, #0x002200
ldr r3, [r2, r3]
ldr r12,[r2, r12]
- tst r3, #0x00020000 @ have bus?
+ and r3, r3, #0x00030000
+ cmp r3, #0x00010000 @ have bus or in reset state?
bxeq lr
and r12,r12,#0xc0000000 @ r3 & 0xC0
add r2, r2, r12, lsr #12
m_s68k_write8_prg: @ 0x000000 - 0x07ffff
+ ldr r2, =(Pico+0x22200)
+ eor r0, r0, #1
+ ldr r2, [r2]
+ add r3, r0, #0x020000 @ map to our address
+ add r12,r2, #0x110000
+ ldr r12,[r12]
+ and r12,r12,#0x00ff0000 @ wp
+ cmp r0, r12, lsr #8
+ strgeb r1, [r2, r3]
+ bx lr
+
+
m_s68k_write8_wordram_2M: @ 0x080000 - 0x0bffff
m_s68k_write8_wordram_1M_b1: @ 0x0c0000 - 0x0dffff, maps to 0x0e0000
m_s68k_write8_ram 0x020000
m_s68k_write16_prg: @ 0x000000 - 0x07ffff
+ ldr r2, =(Pico+0x22200)
+ bic r0, r0, #1
+ ldr r2, [r2]
+ add r3, r0, #0x020000 @ map to our address
+ add r12,r2, #0x110000
+ ldr r12,[r12]
+ and r12,r12,#0x00ff0000 @ wp
+ cmp r0, r12, lsr #8
+ strgeh r1, [r2, r3]
+ bx lr
+
+
m_s68k_write16_wordram_2M: @ 0x080000 - 0x0bffff
m_s68k_write16_wordram_1M_b1: @ 0x0c0000 - 0x0dffff, maps to 0x0e0000
m_s68k_write16_ram 0x020000
m_s68k_write32_prg: @ 0x000000 - 0x07ffff
+ ldr r2, =(Pico+0x22200)
+ bic r0, r0, #1
+ ldr r2, [r2]
+ add r3, r0, #0x020000 @ map to our address
+ add r12,r2, #0x110000
+ ldr r12,[r12]
+ and r12,r12,#0x00ff0000 @ wp
+ cmp r0, r12, lsr #8
+ bxlt lr
+ mov r0, r1, lsr #16
+ strh r0, [r2, r3]!
+ strh r1, [r2, #2]
+ bx lr
+
+
m_s68k_write32_wordram_2M: @ 0x080000 - 0x0bffff
m_s68k_write32_wordram_1M_b1: @ 0x0c0000 - 0x0dffff, maps to 0x0e0000
m_s68k_write32_ram 0x020000
extern unsigned char formatted_bram[4*0x10];
extern unsigned int s68k_poll_adclk;
+void (*PicoMCDopenTray)(void) = NULL;
+int (*PicoMCDcloseTray)(void) = NULL;
#define dump_ram(ram,fname) \
{ \
Pico_mcd->scd.Cur_Track = 0;\r
Pico_mcd->scd.Cur_LBA = -150;\r
Pico_mcd->scd.Status_CDC &= ~1;\r
- Pico_mcd->scd.Status_CDD = READY;\r
+ Pico_mcd->scd.Status_CDD = CD_Present ? READY : NOCD;\r
Pico_mcd->scd.CDD_Complete = 0;\r
Pico_mcd->scd.File_Add_Delay = 0;\r
}\r
// memset(CD_Audio_Buffer_R, 0, 4096 * 4);\r
\r
CD_Present = 0;\r
+ Pico_mcd->scd.Status_CDD = NOCD;\r
\r
if (iso_name != NULL)\r
{\r
ret = Load_ISO(iso_name, is_bin);\r
- if (ret == 0)\r
+ if (ret == 0) {\r
CD_Present = 1;\r
+ Pico_mcd->scd.Status_CDD = READY;\r
+ }\r
}\r
\r
return ret;\r
\r
int Close_Tray_CDD_cC(void)\r
{\r
+ CD_Present = 0;\r
//Clear_Sound_Buffer();\r
\r
Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
\r
- {\r
-#if 0 // TODO\r
- char new_iso[1024];\r
-\r
- memset(new_iso, 0, 1024);\r
+ printf("tray close\n");\r
\r
- while (!Change_File_L(new_iso, Rom_Dir, "Load SegaCD image file", "SegaCD image file\0*.bin;*.iso;*.raw\0All files\0*.*\0\0", ""));\r
- Reload_SegaCD(new_iso);\r
+ if (PicoMCDcloseTray != NULL)\r
+ CD_Present = PicoMCDcloseTray();\r
\r
- CD_Present = 1;\r
-#else\r
- CD_Present = 0;\r
-#endif\r
- Pico_mcd->scd.Status_CDD = STOPPED;\r
- Pico_mcd->cdd.Status = 0x0000;\r
+ Pico_mcd->scd.Status_CDD = CD_Present ? STOPPED : NOCD;\r
+ Pico_mcd->cdd.Status = 0x0000;\r
\r
- Pico_mcd->cdd.Minute = 0;\r
- Pico_mcd->cdd.Seconde = 0;\r
- Pico_mcd->cdd.Frame = 0;\r
- Pico_mcd->cdd.Ext = 0;\r
- }\r
+ Pico_mcd->cdd.Minute = 0;\r
+ Pico_mcd->cdd.Seconde = 0;\r
+ Pico_mcd->cdd.Frame = 0;\r
+ Pico_mcd->cdd.Ext = 0;\r
\r
Pico_mcd->scd.CDD_Complete = 1;\r
\r
\r
Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
\r
+ printf("tray open\n");\r
+\r
Unload_ISO();\r
CD_Present = 0;\r
\r
+ if (PicoMCDopenTray != NULL)\r
+ PicoMCDopenTray();\r
+\r
Pico_mcd->scd.Status_CDD = TRAY_OPEN;\r
Pico_mcd->cdd.Status = 0x0E00;\r
\r
}\r
\r
\r
-\r
-\r
-/***************************\r
- * Others CD functions *\r
- **************************/\r
-\r
-\r
-// do we need them?\r
-#if 0\r
-void Write_CD_Audio(short *Buf, int rate, int channel, int lenght)\r
-{\r
- unsigned int lenght_src, lenght_dst;\r
- unsigned int pos_src, pas_src;\r
-\r
- if (rate == 0) return;\r
- if (Sound_Rate == 0) return;\r
-\r
- if (CD_Audio_Starting)\r
- {\r
- CD_Audio_Starting = 0;\r
- memset(CD_Audio_Buffer_L, 0, 4096 * 4);\r
- memset(CD_Audio_Buffer_R, 0, 4096 * 4);\r
- CD_Audio_Buffer_Write_Pos = (CD_Audio_Buffer_Read_Pos + 2000) & 0xFFF;\r
- }\r
-\r
- lenght_src = rate / 75; // 75th of a second\r
- lenght_dst = Sound_Rate / 75; // 75th of a second\r
-\r
- pas_src = (lenght_src << 16) / lenght_dst;\r
- pos_src = 0;\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "\n********* Write Pos = %d ", CD_Audio_Buffer_Write_Pos);\r
-#endif\r
-\r
- if (channel == 2)\r
- {\r
- __asm\r
- {\r
- mov edi, CD_Audio_Buffer_Write_Pos\r
- mov ebx, Buf\r
- xor esi, esi\r
- mov ecx, lenght_dst\r
- xor eax, eax\r
- mov edx, pas_src\r
- dec ecx\r
- jmp short loop_stereo\r
-\r
-align 16\r
-\r
-loop_stereo:\r
- movsx eax, word ptr [ebx + esi * 4]\r
- mov CD_Audio_Buffer_L[edi * 4], eax\r
- movsx eax, word ptr [ebx + esi * 4 + 2]\r
- mov CD_Audio_Buffer_R[edi * 4], eax\r
- mov esi, dword ptr pos_src\r
- inc edi\r
- add esi, edx\r
- and edi, 0xFFF\r
- mov dword ptr pos_src, esi\r
- shr esi, 16\r
- dec ecx\r
- jns short loop_stereo\r
-\r
- mov CD_Audio_Buffer_Write_Pos, edi\r
- }\r
- }\r
- else\r
- {\r
- __asm\r
- {\r
- mov edi, CD_Audio_Buffer_Write_Pos\r
- mov ebx, Buf\r
- xor esi, esi\r
- mov ecx, lenght_dst\r
- xor eax, eax\r
- mov edx, pas_src\r
- dec ecx\r
- jmp short loop_mono\r
-\r
-align 16\r
-\r
-loop_mono:\r
- movsx eax, word ptr [ebx + esi * 2]\r
- mov CD_Audio_Buffer_L[edi * 4], eax\r
- mov CD_Audio_Buffer_R[edi * 4], eax\r
- mov esi, dword ptr pos_src\r
- inc edi\r
- add esi, edx\r
- and edi, 0xFFF\r
- mov dword ptr pos_src, esi\r
- shr esi, 16\r
- dec ecx\r
- jns short loop_mono\r
-\r
- mov CD_Audio_Buffer_Write_Pos, edi\r
- }\r
- }\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "Write Pos 2 = %d\n\n", CD_Audio_Buffer_Write_Pos);\r
-#endif\r
-}\r
-\r
-\r
-void Update_CD_Audio(int **buf, int lenght)\r
-{\r
- int *Buf_L, *Buf_R;\r
- int diff;\r
-\r
- Buf_L = buf[0];\r
- Buf_R = buf[1];\r
-\r
- if (Pico_mcd->s68k_regs[0x36] & 0x01) return;\r
- if (!(Pico_mcd->scd.Status_CDC & 1)) return;\r
- if (CD_Audio_Starting) return;\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "\n********* Read Pos Normal = %d ", CD_Audio_Buffer_Read_Pos);\r
-#endif\r
-\r
- if (CD_Audio_Buffer_Write_Pos < CD_Audio_Buffer_Read_Pos)\r
- {\r
- diff = CD_Audio_Buffer_Write_Pos + (4096) - CD_Audio_Buffer_Read_Pos;\r
- }\r
- else\r
- {\r
- diff = CD_Audio_Buffer_Write_Pos - CD_Audio_Buffer_Read_Pos;\r
- }\r
-\r
- if (diff < 500) CD_Audio_Buffer_Read_Pos -= 2000;\r
- else if (diff > 3500) CD_Audio_Buffer_Read_Pos += 2000;\r
-\r
-#ifdef DEBUG_CD\r
- else fprintf(debug_SCD_file, " pas de modifs ");\r
-#endif\r
-\r
- CD_Audio_Buffer_Read_Pos &= 0xFFF;\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "Read Pos = %d ", CD_Audio_Buffer_Read_Pos);\r
-#endif\r
-\r
- if (CDDA_Enable)\r
- {\r
- __asm\r
- {\r
- mov ecx, lenght\r
- mov esi, CD_Audio_Buffer_Read_Pos\r
- mov edi, Buf_L\r
- dec ecx\r
-\r
-loop_L:\r
- mov eax, CD_Audio_Buffer_L[esi * 4]\r
- add [edi], eax\r
- inc esi\r
- add edi, 4\r
- and esi, 0xFFF\r
- dec ecx\r
- jns short loop_L\r
-\r
- mov ecx, lenght\r
- mov esi, CD_Audio_Buffer_Read_Pos\r
- mov edi, Buf_R\r
- dec ecx\r
-\r
-loop_R:\r
- mov eax, CD_Audio_Buffer_R[esi * 4]\r
- add [edi], eax\r
- inc esi\r
- add edi, 4\r
- and esi, 0xFFF\r
- dec ecx\r
- jns short loop_R\r
-\r
- mov CD_Audio_Buffer_Read_Pos, esi\r
- }\r
- }\r
- else\r
- {\r
- CD_Audio_Buffer_Read_Pos += lenght;\r
- CD_Audio_Buffer_Read_Pos &= 0xFFF;\r
- }\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "Read Pos 2 = %d\n\n", CD_Audio_Buffer_Read_Pos);\r
-#endif\r
-}\r
-#endif\r
-\r
\r
/* checks if romFileName points to valid MegaCD image\r
* if so, checks for suitable BIOS */\r
-static int cd_check(char **bios_file)\r
+int emu_cd_check(char **bios_file)\r
{\r
unsigned char buf[32];\r
pm_file *cd_f;\r
return 0;\r
}\r
\r
- /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */\r
+ /* it seems we have a CD image here. Try to detect region now.. */\r
pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
pm_read(buf, 1, cd_f);\r
pm_close(cd_f);\r
printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
}\r
\r
- if(find_bios(region, bios_file))\r
+ if (bios_file == NULL) return type;\r
+\r
+ if (find_bios(region, bios_file))\r
return type; // CD and BIOS detected\r
\r
return -1; // CD detected but load failed\r
}\r
\r
// check for MegaCD image\r
- cd_state = cd_check(&used_rom_name);\r
+ cd_state = emu_cd_check(&used_rom_name);\r
if (cd_state > 0) {\r
PicoMCD |= 1;\r
get_ext(used_rom_name, ext);\r
\r
\r
static void emu_msg_cb(const char *msg);\r
+static void emu_msg_tray_open(void);\r
\r
void emu_Init(void)\r
{\r
\r
PicoInit();\r
PicoMessage = emu_msg_cb;\r
-\r
-// logf = fopen("log.txt", "w");\r
+ PicoMCDopenTray = emu_msg_tray_open;\r
+ PicoMCDcloseTray = menu_loop_tray;\r
}\r
\r
\r
}\r
scaling_update();\r
// some sanity checks\r
- if (currentConfig.CPUclock < 1 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
+ if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
+ if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50;\r
// if volume keys are unbound, bind them to volume control\r
if (!currentConfig.KeyBinds[23] && !currentConfig.KeyBinds[22]) {\r
currentConfig.KeyBinds[23] = 1<<29; // vol up\r
free(framebuff);\r
\r
PicoExit();\r
-// fclose(logf);\r
\r
// restore gamma\r
if (gp2x_old_gamma != 100)\r
blit("", str);\r
}\r
\r
+static void emu_msg_tray_open(void)\r
+{\r
+ strcpy(noticeMsg, "CD tray opened");\r
+ gettimeofday(¬iceMsgTime, 0);\r
+}\r
+\r
static void RunEvents(unsigned int which)\r
{\r
if(which & 0x1800) { // save or load (but not both)\r
if(events & 0x6000) {\r
int vol = currentConfig.volume;\r
if (events & 0x2000) {\r
- if (vol < 90) vol++;\r
+ if (vol < 99) vol++;\r
} else {\r
if (vol > 0) vol--;\r
}\r
if (frames_shown > frames_done) frames_shown = frames_done;\r
}\r
}\r
-#if 1\r
+#if 0\r
sprintf(fpsbuff, "%05i", Pico.m.frame_count);\r
#endif\r
lim_time = (frames_done+1) * target_frametime;\r
PGS_KeyConfig,\r
PGS_ReloadRom,\r
PGS_Menu,\r
+ PGS_RestartRun,\r
};\r
\r
typedef struct {\r
int emu_check_save_file(int slot);\r
void emu_set_save_cbs(int gz);\r
void emu_forced_frame(void);\r
+int emu_cd_check(char **bios_file);\r
int find_bios(int region, char **bios_file);\r
void scaling_update(void);\r
\r
}\r
break;\r
\r
+ case PGS_RestartRun:\r
+ engineState = PGS_Running;\r
+\r
case PGS_Running:\r
emu_Loop();\r
break;\r
#include "menu.h"\r
#include "fonts.h"\r
#include "usbjoy.h"\r
+#include "asmutils.h"\r
#include "version.h"\r
\r
#include <Pico/PicoInt.h>\r
static unsigned long wait_for_input(unsigned long interesting)\r
{\r
unsigned long ret;\r
- static int repeats = 0, wait = 300*1000;\r
+ static int repeats = 0, wait = 50*1000;\r
int release = 0, i;\r
\r
- if (repeats == 5 || repeats == 15 || repeats == 30) wait /= 2;\r
+ if (repeats == 2 || repeats == 4) wait /= 2;\r
+ if (repeats == 6) wait = 15 * 1000;\r
\r
for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {\r
- if(i == 0) repeats++;\r
- usleep(wait/6);\r
+ if (i == 0) repeats++;\r
+ if (wait >= 30*1000) usleep(wait); // usleep sleeps for ~30ms minimum\r
+ else spend_cycles(wait * currentConfig.CPUclock);\r
}\r
\r
while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {\r
\r
if (release || ret != inp_prev) {\r
repeats = 0;\r
- wait = 300*1000;\r
+ wait = 50*1000;\r
}\r
inp_prev = ret;\r
inp_prevjoy = 0;\r
inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }\r
if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }\r
- if(inp &(GP2X_LEFT|GP2X_L)) { sel-=10; if (sel < 0) sel = 0; }\r
- if(inp &(GP2X_RIGHT|GP2X_R)) { sel+=10; if (sel > n-2) sel = n-2; }\r
+ if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r
+ if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }\r
+ if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
+ if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }\r
if(inp & GP2X_B) { // enter dir/select\r
again:\r
if (namelist[sel+1]->d_type == DT_REG) {\r
gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 2\r
gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 3\r
gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 4\r
- gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 5\r
+ gp2x_text_out8(tl_x, (y+=10), "Don't save last used ROM %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 5\r
gp2x_text_out8(tl_x, (y+=10), "needs restart:");\r
gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 7\r
gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 8\r
if(inp & GP2X_B ) {\r
switch (menu_sel) {\r
case 0: // resume game\r
- if (rom_data) { engineState = PGS_Running; return; }\r
+ if (rom_data) {\r
+ while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+ engineState = PGS_Running;\r
+ return;\r
+ }\r
break;\r
case 1: // save state\r
if (rom_data) {\r
\r
menuErrorMsg[0] = 0;\r
}\r
+\r
+\r
+// --------- CD tray close menu ----------\r
+\r
+static void draw_menu_tray(int menu_sel)\r
+{\r
+ int tl_x = 70, tl_y = 90, y;\r
+ memset(gp2x_screen, 0xe0, 320*240);\r
+\r
+ gp2x_text_out8(tl_x, 20, "The unit is about to");\r
+ gp2x_text_out8(tl_x, 30, "close the CD tray.");\r
+\r
+ y = tl_y;\r
+ gp2x_text_out8(tl_x, y, "Load new CD image");\r
+ gp2x_text_out8(tl_x, (y+=10), "Insert nothing");\r
+\r
+ // draw cursor\r
+ gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+ // error\r
+ if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r
+ gp2x_video_flip2();\r
+}\r
+\r
+\r
+int menu_loop_tray(void)\r
+{\r
+ int menu_sel = 0, menu_sel_max = 1;\r
+ unsigned long inp = 0;\r
+ char curr_path[PATH_MAX], *selfname;\r
+ FILE *tstf;\r
+\r
+ gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
+ menu_gfx_prepare();\r
+\r
+ if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
+ {\r
+ fclose(tstf);\r
+ strcpy(curr_path, currentConfig.lastRomFile);\r
+ }\r
+ else\r
+ {\r
+ getcwd(curr_path, PATH_MAX);\r
+ }\r
+\r
+ /* make sure action buttons are not pressed on entering menu */\r
+ draw_menu_tray(menu_sel);\r
+ while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+\r
+ for (;;)\r
+ {\r
+ draw_menu_tray(menu_sel);\r
+ inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B);\r
+ if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+ if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+ if(inp & GP2X_B ) {\r
+ switch (menu_sel) {\r
+ case 0: // select image\r
+ selfname = romsel_loop(curr_path);\r
+ if (selfname) {\r
+ int ret = -1, cd_type;\r
+ cd_type = emu_cd_check(NULL);\r
+ if (cd_type > 0)\r
+ ret = Insert_CD(romFileName, cd_type == 2);\r
+ if (ret != 0) {\r
+ sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r
+ printf("%s\n", menuErrorMsg);\r
+ continue;\r
+ }\r
+ engineState = PGS_RestartRun;\r
+ return 1;\r
+ }\r
+ break;\r
+ case 1: // insert nothing\r
+ engineState = PGS_RestartRun;\r
+ return 0;\r
+ }\r
+ }\r
+ menuErrorMsg[0] = 0; // clear error msg\r
+ }\r
+}\r
+\r
+\r
void gp2x_text_out15 (int x, int y, const char *text);\r
void gp2x_text_out8_2(int x, int y, const char *texto, int color);\r
void menu_loop(void);\r
+int menu_loop_tray(void);\r
\r
#define CONFIGURABLE_KEYS \\r
(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_A|GP2X_B|GP2X_X|GP2X_Y| \\r
---------\r
1.32\r
+ Added some new scaling options.\r
+ + Added ability to reaload CD images while game is running (needed for games\r
+ with multiple CDs, like Night Trap).\r
* Fixed DMA timing emulation (caused lock-ups for some genesis games).\r
* Idle loop detection was picking up wrong code and causing glitches, fixed.\r
* The ym2612 code on 940 now can handle multiple updates per frame\r
(fixes Thunger Force III "seiren" level drums for example).\r
* Memory handlers were ignoring some writes to PSG chip, fixed (missing sounds in\r
Popful Mail, Silpheed).\r
+ * Improved z80 timing, should fix some sound problems.\r
+ * Fixed a bug with sram register (fixes Phantasy Star 4).\r
+ * Added code for PRG ram write protection register (Dungeon Explorer).\r
\r
1.31\r
* Changed the way memory mode register is read (fixes Lunar 2, broken in 1.30).\r