X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fmemory.c;h=5d1d25f7cbe8dfb0351506e91bc4af1f9726dafa;hb=e42a47e2086e6512519dd86af420363498302f49;hp=4f38e5e2a355a838e34684969389ff4d1744c115;hpb=9a1f192a146e9b9752ec1a760745b1261fe9bdec;p=picodrive.git diff --git a/pico/memory.c b/pico/memory.c index 4f38e5e..5d1d25f 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -63,6 +63,17 @@ void cpu68k_map_set(uptr *map, int start_addr, int end_addr, const void *func_or_mh, int is_func) { xmap_set(map, M68K_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func); +#ifdef EMU_F68K + // setup FAME fetchmap + if (!is_func) + { + int shiftout = 24 - FAMEC_FETCHBITS; + int i = start_addr >> shiftout; + uptr base = (uptr)func_or_mh - (i << shiftout); + for (; i <= (end_addr >> shiftout); i++) + PicoCpuFM68k.Fetch[i] = base; + } +#endif } // more specialized/optimized function (does same as above) @@ -89,6 +100,17 @@ void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub) addr >>= 1; for (i = start_addr >> shift; i <= end_addr >> shift; i++) r8map[i] = r16map[i] = w8map[i] = w16map[i] = addr; +#ifdef EMU_F68K + // setup FAME fetchmap + { + M68K_CONTEXT *ctx = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k; + int shiftout = 24 - FAMEC_FETCHBITS; + i = start_addr >> shiftout; + addr = (uptr)ptr - (i << shiftout); + for (; i <= (end_addr >> shiftout); i++) + ctx->Fetch[i] = addr; + } +#endif } static u32 m68k_unmapped_read8(u32 a) @@ -363,6 +385,28 @@ void NOINLINE ctl_write_z80reset(u32 d) } } +static int get_scanline(int is_from_z80); + +static void psg_write_68k(u32 d) +{ + // look for volume write and update if needed + if ((d & 0x90) == 0x90 && PsndPsgLine < Pico.m.scanline) + PsndDoPSG(Pico.m.scanline); + + SN76496Write(d); +} + +static void psg_write_z80(u32 d) +{ + if ((d & 0x90) == 0x90) { + int scanline = get_scanline(1); + if (PsndPsgLine < scanline) + PsndDoPSG(scanline); + } + + SN76496Write(d); +} + // ----------------------------------------------------------------- #ifndef _ASM_MEMORY_C @@ -448,11 +492,14 @@ static void PicoWrite16_sram(u32 a, u32 d) EEPROM_write16(d); } else { - // XXX: hardware could easily use MSB too.. u8 *pm = (u8 *)(SRam.data - SRam.start + a); - if (*pm != (u8)d) { + if (pm[0] != (u8)(d >> 8)) { SRam.changed = 1; - *pm = (u8)d; + pm[0] = (u8)(d >> 8); + } + if (pm[1] != (u8)d) { + SRam.changed = 1; + pm[1] = (u8)d; } } } @@ -492,7 +539,6 @@ static void PicoWrite8_z80(u32 a, u32 d) } if ((a & 0x4000) == 0x0000) { // z80 RAM - SekCyclesBurnRun(2); // FIXME hack Pico.zram[a & 0x1fff] = (u8)d; return; } @@ -503,8 +549,7 @@ static void PicoWrite8_z80(u32 a, u32 d) } // TODO: probably other VDP access too? Maybe more mirrors? if ((a & 0x7ff9) == 0x7f11) { // PSG Sound - if (PicoOpt & POPT_EN_PSG) - SN76496Write(d); + psg_write_68k(d); return; } if ((a & 0x7f00) == 0x6000) // Z80 BANK register @@ -657,10 +702,21 @@ void PicoWrite16_io(u32 a, u32 d) // VDP area (0xc00000 - 0xdfffff) // TODO: verify if lower byte goes to PSG on word writes -static u32 PicoRead8_vdp(u32 a) +u32 PicoRead8_vdp(u32 a) { - if ((a & 0x00e0) == 0x0000) - return PicoVideoRead8(a); + if ((a & 0x00f0) == 0x0000) { + switch (a & 0x0d) + { + case 0x00: return PicoVideoRead8DataH(); + case 0x01: return PicoVideoRead8DataL(); + case 0x04: return PicoVideoRead8CtlH(); + case 0x05: return PicoVideoRead8CtlL(); + case 0x08: + case 0x0c: return PicoVideoRead8HV_H(); + case 0x09: + case 0x0d: return PicoVideoRead8HV_L(); + } + } elprintf(EL_UIO|EL_ANOMALY, "68k bad read [%06x] @%06x", a, SekPc); return 0; @@ -678,8 +734,7 @@ static u32 PicoRead16_vdp(u32 a) static void PicoWrite8_vdp(u32 a, u32 d) { if ((a & 0x00f9) == 0x0011) { // PSG Sound - if (PicoOpt & POPT_EN_PSG) - SN76496Write(d); + psg_write_68k(d); return; } if ((a & 0x00e0) == 0x0000) { @@ -693,11 +748,8 @@ static void PicoWrite8_vdp(u32 a, u32 d) static void PicoWrite16_vdp(u32 a, u32 d) { - if ((a & 0x00f9) == 0x0010) { // PSG Sound - if (PicoOpt & POPT_EN_PSG) - SN76496Write(d); - return; - } + if ((a & 0x00f9) == 0x0010) // PSG Sound + psg_write_68k(d); if ((a & 0x00e0) == 0x0000) { PicoVideoWrite(a, d); return; @@ -796,14 +848,12 @@ PICO_INTERNAL void PicoMemSetup(void) { int i; // by default, point everything to first 64k of ROM - for (i = 0; i < M68K_FETCHBANK1; i++) + for (i = 0; i < M68K_FETCHBANK1 * 0xe0 / 0x100; i++) PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); // now real ROM for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++) PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom; - // .. and RAM - for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.ram - (i<<(24-FAMEC_FETCHBITS)); + // RAM already set } #endif #ifdef EMU_M68K @@ -909,7 +959,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80) int scanline = get_scanline(is_from_z80); //elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", PsndDacLine, scanline, d, is_from_z80); ym2612.dacout = ((int)d - 0x80) << 6; - if (PsndOut && ym2612.dacen && scanline >= PsndDacLine) + if (ym2612.dacen) PsndDoDAC(scanline); return 0; } @@ -993,8 +1043,10 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80) } case 0x2b: { /* DAC Sel (YM2612) */ int scanline = get_scanline(is_from_z80); - ym2612.dacen = d & 0x80; - if (d & 0x80) PsndDacLine = scanline; + if (ym2612.dacen != (d & 0x80)) { + ym2612.dacen = d & 0x80; + PsndDacLine = scanline; + } #ifdef __GP2X__ if (PicoOpt & POPT_EXT_FM) YM2612Write_940(a, d, scanline); #endif @@ -1142,7 +1194,22 @@ void PicoWrite16_32x(u32 a, u32 d) {} static unsigned char z80_md_vdp_read(unsigned short a) { - // TODO? + z80_subCLeft(2); + + if ((a & 0x00f0) == 0x0000) { + switch (a & 0x0d) + { + case 0x00: return PicoVideoRead8DataH(); + case 0x01: return PicoVideoRead8DataL(); + case 0x04: return PicoVideoRead8CtlH(); + case 0x05: return PicoVideoRead8CtlL(); + case 0x08: + case 0x0c: return get_scanline(1); // FIXME: make it proper + case 0x09: + case 0x0d: return Pico.m.rotate++; + } + } + elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, 0xff); return 0xff; } @@ -1152,8 +1219,10 @@ static unsigned char z80_md_bank_read(unsigned short a) unsigned int addr68k; unsigned char ret; - addr68k = Pico.m.z80_bank68k<<15; - addr68k += a & 0x7fff; + z80_subCLeft(3); + + addr68k = Pico.m.z80_bank68k << 15; + addr68k |= a & 0x7fff; ret = m68k_read8(addr68k); @@ -1169,13 +1238,12 @@ static void z80_md_ym2612_write(unsigned int a, unsigned char data) static void z80_md_vdp_br_write(unsigned int a, unsigned char data) { - // TODO: allow full VDP access if ((a&0xfff9) == 0x7f11) // 7f11 7f13 7f15 7f17 { - if (PicoOpt & POPT_EN_PSG) - SN76496Write(data); + psg_write_z80(data); return; } + // at least VDP data writes hang my machine if ((a>>8) == 0x60) {