From 48e8482fc2d74c9b96e581241390bade986acb22 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 20 Mar 2007 22:39:50 +0000 Subject: [PATCH] bugfixes, but silpheed is broken git-svn-id: file:///home/notaz/opt/svn/PicoDrive@72 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/PicoInt.h | 1 + Pico/cd/Area.c | 1 + Pico/cd/Memory.c | 33 +++-- Pico/cd/Memory.s | 301 ++++++++++++++++++++++++++++++++++++++++++-- Pico/cd/Pico.c | 1 + Pico/cd/cd_sys.h | 2 +- platform/gp2x/emu.c | 3 +- platform/readme.txt | 1 + 8 files changed, 317 insertions(+), 26 deletions(-) diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index 694952e2..18e779b5 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -269,6 +269,7 @@ void z80_write16(unsigned short data, unsigned short a); // cd/Memory.c void PicoMemSetupCD(void); void PicoMemResetCD(int r3); +void PicoMemResetCDdecode(int r3); unsigned char PicoReadCD8 (unsigned int a); unsigned short PicoReadCD16(unsigned int a); unsigned int PicoReadCD32(unsigned int a); diff --git a/Pico/cd/Area.c b/Pico/cd/Area.c index bd8d157c..baf501f2 100644 --- a/Pico/cd/Area.c +++ b/Pico/cd/Area.c @@ -245,6 +245,7 @@ int PicoCdLoadState(void *file) wram_2M_to_1M(Pico_mcd->word_ram2M); #ifdef _ASM_CD_MEMORY_C PicoMemResetCD(Pico_mcd->s68k_regs[3]); + PicoMemResetCDdecode(Pico_mcd->s68k_regs[3]); #endif if (Pico_mcd->m.audio_track > 0 && Pico_mcd->m.audio_track < Pico_mcd->TOC.Last_Track) mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset); diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index ce23433b..1a1bb840 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -34,12 +34,6 @@ typedef unsigned int u32; // ----------------------------------------------------------------- -#ifndef _ASM_CD_MEMORY_C -void PicoMemResetCD(int r3) -{ -} -#endif - #ifndef _ASM_CD_MEMORY_C static u32 m68k_reg_read16(u32 a) { @@ -237,6 +231,7 @@ void s68k_reg_write8(u32 a, u32 d) //dprintf("s68k_regs w%2i: [%02x] %02x @ %06x", realsize, a, d, SekPcS68k); // TODO: review against Gens + // Warning: d might have upper bits set switch (a) { case 2: return; // only m68k can change WP @@ -252,6 +247,10 @@ void s68k_reg_write8(u32 a, u32 d) PicoMemResetCD(d); #endif } +#ifdef _ASM_CD_MEMORY_C + if ((d ^ dold) & 0x1d) + PicoMemResetCDdecode(d); +#endif if (!(dold & 4)) { dprintf("wram mode 2M->1M"); wram_2M_to_1M(Pico_mcd->word_ram2M); @@ -298,7 +297,7 @@ void s68k_reg_write8(u32 a, u32 d) return; case 0x31: dprintf("s68k set int3 timer: %02x", d); - Pico_mcd->m.timer_int3 = d << 16; + Pico_mcd->m.timer_int3 = (d & 0xff) << 16; break; case 0x33: // IRQ mask dprintf("s68k irq mask: %02x", d); @@ -1048,6 +1047,8 @@ static void decode_write16(u32 a, u16 d, int r3) // ----------------------------------------------------------------- +//void PicoWriteS68k8_(u32 a,u8 d); +//void PicoWriteS68k8__(u32 a,u8 d); #ifdef _ASM_CD_MEMORY_C void PicoWriteS68k8(u32 a,u8 d); #else @@ -1058,6 +1059,16 @@ static void PicoWriteS68k8(u32 a,u8 d) #endif a&=0xffffff; +#if 0 + PicoWriteS68k8_(a, d); +/* if ((a&0xfc0000)!=0x080000) { + PicoWriteS68k8_(a, d); + return; + } + printf("r3: %02x\n", Pico_mcd->s68k_regs[3]); + PicoWriteS68k8__(a,d);*/ + return; +#endif // prg RAM if (a < 0x80000) { @@ -1071,7 +1082,7 @@ static void PicoWriteS68k8(u32 a,u8 d) a &= 0x1ff; rdprintf("s68k_regs w8: [%02x] %02x @ %06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) - gfx_cd_write(a&~1, (d<<8)|d); + gfx_cd_write16(a&~1, (d<<8)|d); else s68k_reg_write8(a,d); return; } @@ -1146,7 +1157,7 @@ static void PicoWriteS68k16(u32 a,u16 d) a &= 0x1fe; rdprintf("s68k_regs w16: [%02x] %04x @ %06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) - gfx_cd_write(a, d); + gfx_cd_write16(a, d); else { if (a == 0xe) { // special case, 2 byte writes would be handled differently Pico_mcd->s68k_regs[0xf] = d; @@ -1231,8 +1242,8 @@ static void PicoWriteS68k32(u32 a,u32 d) a &= 0x1fe; rdprintf("s68k_regs w32: [%02x] %08x @ %06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) { - gfx_cd_write(a, d>>16); - gfx_cd_write(a+2, d&0xffff); + gfx_cd_write16(a, d>>16); + gfx_cd_write16(a+2, d&0xffff); } else { s68k_reg_write8(a, d>>24); s68k_reg_write8(a+1,(d>>16)&0xff); diff --git a/Pico/cd/Memory.s b/Pico/cd/Memory.s index ecfc7ec2..80f628a3 100644 --- a/Pico/cd/Memory.s +++ b/Pico/cd/Memory.s @@ -62,7 +62,7 @@ .endm -@ the jumptables themselves +@ the jumptables themselves. m_m68k_read8_table: mk_m68k_jump_table read 8 m_m68k_read16_table: mk_m68k_jump_table read 16 m_m68k_read32_table: mk_m68k_jump_table read 32 @@ -77,6 +77,26 @@ m_s68k_write8_table: mk_s68k_jump_table write 8 m_s68k_write16_table: mk_s68k_jump_table write 16 m_s68k_write32_table: mk_s68k_jump_table write 32 +m_s68k_decode_write_table: + .long m_s68k_write8_2M_decode_b0_m0 + .long m_s68k_write16_2M_decode_b0_m0 + .long m_s68k_write32_2M_decode_b0_m0 + .long m_s68k_write8_2M_decode_b0_m1 + .long m_s68k_write16_2M_decode_b0_m1 + .long m_s68k_write32_2M_decode_b0_m1 + .long m_s68k_write8_2M_decode_b0_m2 + .long m_s68k_write16_2M_decode_b0_m2 + .long m_s68k_write32_2M_decode_b0_m2 + .long m_s68k_write8_2M_decode_b1_m0 + .long m_s68k_write16_2M_decode_b1_m0 + .long m_s68k_write32_2M_decode_b1_m0 + .long m_s68k_write8_2M_decode_b1_m1 + .long m_s68k_write16_2M_decode_b1_m1 + .long m_s68k_write32_2M_decode_b1_m1 + .long m_s68k_write8_2M_decode_b1_m2 + .long m_s68k_write16_2M_decode_b1_m2 + .long m_s68k_write32_2M_decode_b1_m2 + @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -84,6 +104,7 @@ m_s68k_write32_table: mk_s68k_jump_table write 32 .align 4 .global PicoMemResetCD +.global PicoMemResetCDdecode .global PicoReadM68k8 .global PicoReadM68k16 .global PicoReadM68k32 @@ -141,10 +162,12 @@ m_s68k_write32_table: mk_s68k_jump_table write 32 ldr r3, =m_m68k_&\on&\sz&_wordram1_1M_b0 str r2, [r1, #16*4] str r3, [r1, #17*4] - ldr r2, =m_s68k_&\on&\sz&_wordram_2M_decode_b1 ldr r3, =m_s68k_&\on&\sz&_wordram_1M_b1 +.ifeqs "\on", "read" + ldr r2, =m_s68k_&\on&\sz&_wordram_2M_decode_b1 str r2, [r12,#4*4] str r2, [r12,#5*4] +.endif str r3, [r12,#6*4] b 9f @ pmr_8_done @@ -153,10 +176,12 @@ m_s68k_write32_table: mk_s68k_jump_table write 32 ldr r3, =m_m68k_&\on&\sz&_wordram1_1M_b1 str r2, [r1, #16*4] str r3, [r1, #17*4] - ldr r2, =m_s68k_&\on&\sz&_wordram_2M_decode_b0 ldr r3, =m_s68k_&\on&\sz&_wordram_1M_b0 +.ifeqs "\on", "read" + ldr r2, =m_s68k_&\on&\sz&_wordram_2M_decode_b0 str r2, [r12,#4*4] str r2, [r12,#5*4] +.endif str r3, [r12,#6*4] 9: @ pmr_8_done: @@ -173,6 +198,27 @@ PicoMemResetCD: @ r3 bx lr +PicoMemResetCDdecode: @r3 + ldr r1, =m_s68k_write8_table + ldr r3, =m_s68k_decode_write_table + and r2, r0, #0x18 + mov r2, r2, lsr #3 + cmp r2, #3 + moveq r2, #2 @ mode3 is same as mode2? + tst r0, #1 + addeq r2, r2, #3 @ bank1 (r2=0..5) + add r2, r2, r2, lsl #1 @ *= 3 + add r2, r3, r2, lsl #2 + ldmia r2, {r0,r3,r12} + str r0, [r1, #4*4] + str r0, [r1, #5*4] + str r3, [r1, #4*4+8*4] + str r3, [r1, #5*4+8*4] + str r12,[r1, #4*4+8*4*2] + str r12,[r1, #5*4+8*4*2] + bx lr + + .pool @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -1529,6 +1575,50 @@ m_s68k_read32_regs_gfx: bx lr .endm +.macro m_s68k_write8_2M_decode map_addr + ldr r2, =(Pico+0x22200) + eor r0, r0, #2 + ldr r2, [r2] + movs r0, r0, lsr #1 @ +4-6 <<16 + add r2, r2, #\map_addr @ map to our address +.endm + +.macro m_s68k_write8_2M_decode_m0 map_addr @ mode off + m_s68k_write8_2M_decode \map_addr + ldrb r0, [r2, r0]! + and r1, r1, #0x0f + movcc r1, r1, lsl #4 + andcc r3, r0, #0x0f + andcs r3, r0, #0xf0 + orr r3, r3, r1 + cmp r0, r3 @ avoid writing if result is same + strneb r3, [r2] + bx lr +.endm + +.macro m_s68k_write8_2M_decode_m1 map_addr @ mode underwrite + ands r1, r1, #0x0f + bxeq lr + m_s68k_write8_2M_decode \map_addr + ldrb r0, [r2, r0]! + movcc r1, r1, lsl #4 + andcc r3, r0, #0x0f + andcs r3, r0, #0xf0 + tst r3, r3 + bxeq lr + orr r3, r3, r1 + cmp r0, r3 + strneb r3, [r2] + bx lr +.endm + +.macro m_s68k_write8_2M_decode_m2 map_addr @ mode overwrite + ands r1, r1, #0x0f + bxeq lr + m_s68k_write8_2M_decode_m0 \map_addr @ same as in off mode +.endm + + m_s68k_write8_prg: @ 0x000000 - 0x07ffff m_s68k_write8_wordram_2M: @ 0x080000 - 0x0bffff @@ -1536,9 +1626,23 @@ m_s68k_write8_wordram_1M_b1: @ 0x0c0000 - 0x0dffff, maps to 0x0e0000 m_s68k_write8_ram 0x020000 -m_s68k_write8_wordram_2M_decode_b0: @ 0x080000 - 0x0bffff -m_s68k_write8_wordram_2M_decode_b1: @ 0x080000 - 0x0bffff - bx lr @ TODO +m_s68k_write8_2M_decode_b0_m0: @ 0x080000 - 0x0bffff + m_s68k_write8_2M_decode_m0 0x080000 + +m_s68k_write8_2M_decode_b0_m1: + m_s68k_write8_2M_decode_m1 0x080000 + +m_s68k_write8_2M_decode_b0_m2: + m_s68k_write8_2M_decode_m2 0x080000 + +m_s68k_write8_2M_decode_b1_m0: + m_s68k_write8_2M_decode_m0 0x0a0000 + +m_s68k_write8_2M_decode_b1_m1: + m_s68k_write8_2M_decode_m1 0x0a0000 + +m_s68k_write8_2M_decode_b1_m2: + m_s68k_write8_2M_decode_m2 0x0a0000 m_s68k_write8_wordram_1M_b0: @ 0x0c0000 - 0x0dffff (same as our offset :) @@ -1614,6 +1718,57 @@ m_s68k_write8_regs: bx lr .endm +.macro m_s68k_write16_2M_decode map_addr + ldr r2, =(Pico+0x22200) + eor r0, r0, #2 + ldr r2, [r2] + mov r0, r0, lsr #1 @ +4-6 <<16 + add r2, r2, #\map_addr @ map to our address +.endm + +.macro m_s68k_write16_2M_decode_m0 map_addr @ mode off + m_s68k_write16_2M_decode \map_addr + bic r1, r1, #0xf0 + orr r1, r1, r1, lsr #4 + strb r1, [r2, r0] + bx lr +.endm + +.macro m_s68k_write16_2M_decode_m1 map_addr @ mode underwrite + bics r1, r1, #0xf000 + bicnes r1, r1, #0x00f0 + bxeq lr + orr r1, r1, r1, lsr #4 + m_s68k_write16_2M_decode \map_addr + ldrb r0, [r2, r0]! + and r3, r1, #0x0f + and r1, r1, #0xf0 + tst r0, #0x0f + orreq r0, r0, r3 + tst r0, #0xf0 + orreq r0, r0, r1 + strb r0, [r2] + bx lr +.endm + +.macro m_s68k_write16_2M_decode_m2 map_addr @ mode overwrite + bics r1, r1, #0xf000 + bicnes r1, r1, #0x00f0 + bxeq lr + orr r1, r1, r1, lsr #4 + m_s68k_write16_2M_decode \map_addr + ldrb r0, [r2, r0]! + ands r3, r1, #0x0f + andne r0, r0, #0xf0 + orrne r0, r0, r3 + ands r1, r1, #0xf0 + andne r0, r0, #0x0f + orrne r0, r0, r1 + strb r0, [r2] + bx lr +.endm + + m_s68k_write16_prg: @ 0x000000 - 0x07ffff m_s68k_write16_wordram_2M: @ 0x080000 - 0x0bffff @@ -1621,9 +1776,23 @@ m_s68k_write16_wordram_1M_b1: @ 0x0c0000 - 0x0dffff, maps to 0x0e0000 m_s68k_write16_ram 0x020000 -m_s68k_write16_wordram_2M_decode_b0: @ 0x080000 - 0x0bffff -m_s68k_write16_wordram_2M_decode_b1: @ 0x080000 - 0x0bffff - bx lr @ TODO +m_s68k_write16_2M_decode_b0_m0: @ 0x080000 - 0x0bffff + m_s68k_write16_2M_decode_m0 0x080000 + +m_s68k_write16_2M_decode_b0_m1: + m_s68k_write16_2M_decode_m1 0x080000 + +m_s68k_write16_2M_decode_b0_m2: + m_s68k_write16_2M_decode_m2 0x080000 + +m_s68k_write16_2M_decode_b1_m0: + m_s68k_write16_2M_decode_m0 0x0a0000 + +m_s68k_write16_2M_decode_b1_m1: + m_s68k_write16_2M_decode_m1 0x0a0000 + +m_s68k_write16_2M_decode_b1_m2: + m_s68k_write16_2M_decode_m2 0x0a0000 m_s68k_write16_wordram_1M_b0: @ 0x0c0000 - 0x0dffff (same as our offset :) @@ -1664,7 +1833,7 @@ m_s68k_write16_regs_spec: @ special case ldr r2, [r2] add r0, r0, #0x00000f strb r1, [r2, r0] @ if (a == 0xe) s68k_regs[0xf] = d; - bxeq lr + bx lr @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -1681,6 +1850,98 @@ m_s68k_write16_regs_spec: @ special case bx lr .endm +.macro m_s68k_write32_2M_decode map_addr + ldr r2, =(Pico+0x22200) + eor r0, r0, #2 + ldr r2, [r2] + mov r0, r0, lsr #1 @ +4-6 <<16 + add r2, r2, #\map_addr @ map to our address +.endm + +.macro m_s68k_write32_2M_decode_m0 map_addr @ mode off + m_s68k_write32_2M_decode \map_addr + bic r1, r1, #0x000000f0 + bic r1, r1, #0x00f00000 + orr r1, r1, r1, lsr #4 + mov r3, r1, lsr #16 + strb r3, [r2, r0]! + tst r0, #1 + strneb r1, [r2, #-1] + streqb r1, [r2, #3] + bx lr +.endm + +.macro m_s68k_write32_2M_decode_m1 map_addr @ mode underwrite + bics r1, r1, #0x000000f0 + bicnes r1, r1, #0x0000f000 + bicnes r1, r1, #0x00f00000 + bicnes r1, r1, #0xf0000000 + bxeq lr + orr r1, r1, r1, lsr #4 + m_s68k_write32_2M_decode \map_addr + ldrb r3, [r2, r0]! + tst r0, #1 + ldrneb r0, [r2, #-1] + ldreqb r0, [r2, #3] + and r12,r1, #0x0000000f + orr r0, r0, r3, lsl #16 + orrne r0, r0, #0x80000000 @ remember addr lsb bit + tst r0, #0x0000000f + orreq r0, r0, r12 + tst r0, #0x000000f0 + andeq r12,r1, #0x000000f0 + orreq r0, r0, r12 + tst r0, #0x000f0000 + andeq r12,r1, #0x000f0000 + orreq r0, r0, r12 + tst r0, #0x00f00000 + andeq r12,r1, #0x00f00000 + orreq r0, r0, r12 + tst r0, #0x80000000 + strneb r0, [r2, #-1] + streqb r0, [r2, #3] + mov r0, r0, lsr #16 + strb r0, [r2] + bx lr +.endm + +.macro m_s68k_write32_2M_decode_m2 map_addr @ mode overwrite + bics r1, r1, #0x000000f0 + bicnes r1, r1, #0x0000f000 + bicnes r1, r1, #0x00f00000 + bicnes r1, r1, #0xf0000000 + bxeq lr + orr r1, r1, r1, lsr #4 + m_s68k_write32_2M_decode \map_addr + ldrb r3, [r2, r0]! + tst r0, #1 + ldrneb r0, [r2, #-1] + ldreqb r0, [r2, #3] + orrne r1, r1, #0x80000000 @ remember addr lsb bit + orr r0, r0, r3, lsl #16 + tst r1, #0x0000000f + andeq r12,r0, #0x0000000f + orreq r1, r1, r12 + tst r1, #0x000000f0 + andeq r12,r0, #0x000000f0 + orreq r1, r1, r12 + tst r1, #0x000f0000 + andeq r12,r0, #0x000f0000 + orreq r1, r1, r12 + tst r1, #0x00f00000 + andeq r12,r0, #0x00f00000 + orreq r1, r1, r12 + cmp r0, r1 + bxeq lr + tst r1, #0x80000000 + strneb r1, [r2, #-1] + streqb r1, [r2, #3] + mov r1, r1, lsr #16 + strb r1, [r2] + bx lr +.endm + + m_s68k_write32_prg: @ 0x000000 - 0x07ffff m_s68k_write32_wordram_2M: @ 0x080000 - 0x0bffff @@ -1688,9 +1949,23 @@ m_s68k_write32_wordram_1M_b1: @ 0x0c0000 - 0x0dffff, maps to 0x0e0000 m_s68k_write32_ram 0x020000 -m_s68k_write32_wordram_2M_decode_b0: @ 0x080000 - 0x0bffff -m_s68k_write32_wordram_2M_decode_b1: @ 0x080000 - 0x0bffff - bx lr @ TODO +m_s68k_write32_2M_decode_b0_m0: @ 0x080000 - 0x0bffff + m_s68k_write32_2M_decode_m0 0x080000 + +m_s68k_write32_2M_decode_b0_m1: + m_s68k_write32_2M_decode_m1 0x080000 + +m_s68k_write32_2M_decode_b0_m2: + m_s68k_write32_2M_decode_m2 0x080000 + +m_s68k_write32_2M_decode_b1_m0: + m_s68k_write32_2M_decode_m0 0x0a0000 + +m_s68k_write32_2M_decode_b1_m1: + m_s68k_write32_2M_decode_m1 0x0a0000 + +m_s68k_write32_2M_decode_b1_m2: + m_s68k_write32_2M_decode_m2 0x0a0000 m_s68k_write32_wordram_1M_b0: @ 0x0c0000 - 0x0dffff (same as our offset :) diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index fc45be1c..bd60d7b7 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -51,6 +51,7 @@ int PicoResetMCD(int hard) gfx_cd_reset(); #ifdef _ASM_CD_MEMORY_C PicoMemResetCD(1); + PicoMemResetCDdecode(1); #endif return 0; diff --git a/Pico/cd/cd_sys.h b/Pico/cd/cd_sys.h index 8ba0fe6a..a71f5d25 100644 --- a/Pico/cd/cd_sys.h +++ b/Pico/cd/cd_sys.h @@ -55,7 +55,7 @@ typedef struct { unsigned int Cur_Track; int File_Add_Delay; char CDD_Complete; - int pad[7]; + int pad[6]; } _scd; diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 632ad180..ce056b3e 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -987,7 +987,6 @@ void emu_forced_frame(void) PicoOpt |= 0x10; PicoFrameFull(); - PicoOpt = po_old; if (!(Pico.video.reg[12]&1)) { vidCpyM2 = vidCpyM2_32col; @@ -997,6 +996,8 @@ void emu_forced_frame(void) vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); + + PicoOpt = po_old; } static void simpleWait(int thissec, int lim_time) diff --git a/platform/readme.txt b/platform/readme.txt index dcab22ec..d2879db1 100644 --- a/platform/readme.txt +++ b/platform/readme.txt @@ -220,6 +220,7 @@ Changelog * Integrated "better sync" code into cyclone code, what made this mode much faster. * Fixed a bug related to game specific config saving. * Frameskipper was skipping sound processing, what caused some audio desyncs. Fixed. + * Fixed reset not working for some games. 1.201 + Added basic cheat support (GameGenie and Genecyst patches). -- 2.39.5