X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FMemory.c;h=004d3af078eac2257f3090e29e7c288d0ec3c34d;hb=48dc74f20a90629b55c1ab676639c05a125ea383;hp=a9f0927434083ec96bb308a3ff3d849da1ef00b0;hpb=453d2a6edadbd6a0977b76eba14961006c907f01;p=picodrive.git diff --git a/Pico/Memory.c b/Pico/Memory.c index a9f0927..004d3af 100644 --- a/Pico/Memory.c +++ b/Pico/Memory.c @@ -89,10 +89,9 @@ PICO_INTERNAL u32 PicoCheckPc(u32 pc) } -PICO_INTERNAL int PicoInitPc(u32 pc) +PICO_INTERNAL void PicoInitPc(u32 pc) { PicoCheckPc(pc); - return 0; } #ifndef _ASM_MEMORY_C @@ -345,9 +344,9 @@ PICO_INTERNAL_ASM u32 PicoRead8(u32 a) log_io(a, 8, 0); if ((a&0xff4000)==0xa00000) { d=z80Read8(a); goto end; } // Z80 Ram - if ((a&0xe700e0)==0xc00000) // VDP - d=PicoVideoRead(a); - else d=OtherRead16(a&~1, 8); + if ((a&0xe700e0)==0xc00000) { d=PicoVideoRead8(a); goto end; } // VDP + + d=OtherRead16(a&~1, 8); if ((a&1)==0) d>>=8; end: @@ -689,8 +688,6 @@ static void m68k_mem_setup(void) // ----------------------------------------------------------------- -extern const unsigned short vcounts[]; - static int get_scanline(int is_from_z80) { if (is_from_z80) { @@ -700,13 +697,10 @@ static int get_scanline(int is_from_z80) return z80_scanline; } - if (Pico.m.scanline != -1) - return Pico.m.scanline; - - return vcounts[SekCyclesDone()>>8]; + return Pico.m.scanline; } -/* probably not should be in this file, but it's near related code here */ +/* probably should not be in this file, but it's near related code here */ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new) { int xcycles = z80_cycles << 8; @@ -720,34 +714,30 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new) /* update timer a */ if (mode_old & 1) - while (xcycles >= timer_a_next_oflow) + while (xcycles > timer_a_next_oflow) timer_a_next_oflow += timer_a_step; if ((mode_old ^ mode_new) & 1) // turning on/off { - if (mode_old & 1) { - timer_a_offset = timer_a_next_oflow - xcycles; - timer_a_next_oflow = 0x70000000; - } + if (mode_old & 1) + timer_a_next_oflow = TIMER_NO_OFLOW; else - timer_a_next_oflow = xcycles + timer_a_offset; + timer_a_next_oflow = xcycles + timer_a_step; } if (mode_new & 1) elprintf(EL_YMTIMER, "timer a upd to %i @ %i", timer_a_next_oflow>>8, z80_cycles); /* update timer b */ if (mode_old & 2) - while (xcycles >= timer_b_next_oflow) + while (xcycles > timer_b_next_oflow) timer_b_next_oflow += timer_b_step; if ((mode_old ^ mode_new) & 2) { - if (mode_old & 2) { - timer_b_offset = timer_b_next_oflow - xcycles; - timer_b_next_oflow = 0x70000000; - } + if (mode_old & 2) + timer_b_next_oflow = TIMER_NO_OFLOW; else - timer_b_next_oflow = xcycles + timer_b_offset; + timer_b_next_oflow = xcycles + timer_b_step; } if (mode_new & 2) elprintf(EL_YMTIMER, "timer b upd to %i @ %i", timer_b_next_oflow>>8, z80_cycles); @@ -798,9 +788,9 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80) ym2612.OPN.ST.TA = TAnew; //ym2612.OPN.ST.TAC = (1024-TAnew)*18; //ym2612.OPN.ST.TAT = 0; - // - timer_a_step = timer_a_offset = 16495 * (1024 - TAnew); + timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew); if (ym2612.OPN.ST.mode & 1) { + // this is not right, should really be done on overflow only int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone()); timer_a_next_oflow = (cycles << 8) + timer_a_step; } @@ -812,10 +802,9 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80) if (ym2612.OPN.ST.TB != d) { //elprintf(EL_STATUS, "timer b set %i", d); ym2612.OPN.ST.TB = d; - //ym2612.OPN.ST.TBC = (256-d)<<4; - //ym2612.OPN.ST.TBC *= 18; + //ym2612.OPN.ST.TBC = (256-d) * 288; //ym2612.OPN.ST.TBT = 0; - timer_b_step = timer_b_offset = 263912 * (256 - d); + timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800 if (ym2612.OPN.ST.mode & 2) { int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone()); timer_b_next_oflow = (cycles << 8) + timer_b_step; @@ -841,7 +830,7 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80) if ((d ^ old_mode) & 0xc0) { #ifdef __GP2X__ - if (PicoOpt & POPT_EXT_FM) YM2612Write_940(a, d, get_scanline(is_from_z80)); + if (PicoOpt & POPT_EXT_FM) return YM2612Write_940(a, d, get_scanline(is_from_z80)); #endif return 1; } @@ -912,21 +901,77 @@ u32 ym2612_read_local_68k(void) return ym2612.OPN.ST.status; } -// TODO: new ym2612 savestates +void ym2612_pack_state(void) +{ + // timers are saved as tick counts, in 16.16 int format + int tac, tat = 0, tbc, tbt = 0; + tac = 1024 - ym2612.OPN.ST.TA; + tbc = 256 - ym2612.OPN.ST.TB; + if (timer_a_next_oflow != TIMER_NO_OFLOW) + tat = (int)((double)(timer_a_step - timer_a_next_oflow) / (double)timer_a_step * tac * 65536); + if (timer_b_next_oflow != TIMER_NO_OFLOW) + tbt = (int)((double)(timer_b_step - timer_b_next_oflow) / (double)timer_b_step * tbc * 65536); + elprintf(EL_YMTIMER, "save: timer a %i/%i", tat >> 16, tac); + elprintf(EL_YMTIMER, "save: timer b %i/%i", tbt >> 16, tbc); + +#ifdef __GP2X__ + if (PicoOpt & POPT_EXT_FM) + YM2612PicoStateSave2_940(tat, tbt); + else +#endif + YM2612PicoStateSave2(tat, tbt); +} + void ym2612_unpack_state(void) { - int i; + int i, ret, tac, tat, tbc, tbt; YM2612PicoStateLoad(); // feed all the registers and update internal state - for (i = 0x20; i < 0xC0; i++) { + for (i = 0x20; i < 0xA0; i++) { + ym2612_write_local(0, i, 0); + ym2612_write_local(1, ym2612.REGS[i], 0); + } + for (i = 0x30; i < 0xA0; i++) { + ym2612_write_local(2, i, 0); + ym2612_write_local(3, ym2612.REGS[i|0x100], 0); + } + for (i = 0xAF; i >= 0xA0; i--) { // must apply backwards + ym2612_write_local(2, i, 0); + ym2612_write_local(3, ym2612.REGS[i|0x100], 0); ym2612_write_local(0, i, 0); ym2612_write_local(1, ym2612.REGS[i], 0); } - for (i = 0x30; i < 0xC0; i++) { + for (i = 0xB0; i < 0xB8; i++) { + ym2612_write_local(0, i, 0); + ym2612_write_local(1, ym2612.REGS[i], 0); ym2612_write_local(2, i, 0); ym2612_write_local(3, ym2612.REGS[i|0x100], 0); } + +#ifdef __GP2X__ + if (PicoOpt & POPT_EXT_FM) + ret = YM2612PicoStateLoad2_940(&tat, &tbt); + else +#endif + ret = YM2612PicoStateLoad2(&tat, &tbt); + if (ret != 0) { + elprintf(EL_STATUS, "old ym2612 state"); + return; // no saved timers + } + + tac = (1024 - ym2612.OPN.ST.TA) << 16; + tbc = (256 - ym2612.OPN.ST.TB) << 16; + if (ym2612.OPN.ST.mode & 1) + timer_a_next_oflow = (int)((double)(tac - tat) / (double)tac * timer_a_step); + else + timer_a_next_oflow = TIMER_NO_OFLOW; + if (ym2612.OPN.ST.mode & 2) + timer_b_next_oflow = (int)((double)(tbc - tbt) / (double)tbc * timer_b_step); + else + timer_b_next_oflow = TIMER_NO_OFLOW; + elprintf(EL_YMTIMER, "load: %i/%i, timer_a_next_oflow %i", tat>>16, tac>>16, timer_a_next_oflow >> 8); + elprintf(EL_YMTIMER, "load: %i/%i, timer_b_next_oflow %i", tbt>>16, tbc>>16, timer_b_next_oflow >> 8); } // -----------------------------------------------------------------