From 88fd63ad10faa746ef9d7ad7d98a72e51fe2aa86 Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 5 Oct 2017 02:06:21 +0300 Subject: [PATCH] split memories away from Pico saves ~3k of code on ARM because Pico no longer crosses ldr limit --- pico/32x/memory.c | 2 +- pico/32x/pwm.c | 6 +- pico/cart.c | 72 +++++++-------- pico/carthw/carthw.c | 12 +-- pico/carthw/eeprom_spi.c | 10 +- pico/cd/gfx_dma.c | 6 +- pico/cd/mcd.c | 50 +++++----- pico/cd/memory.c | 18 ++-- pico/cd/{memory_arm.s => memory_arm.S} | 57 ++++++------ pico/debug.c | 38 ++++---- pico/draw.c | 56 ++++++------ pico/draw2.c | 24 ++--- pico/draw2_arm.S | 40 ++++---- pico/draw_arm.S | 116 ++++++++++++------------ pico/eeprom.c | 38 ++++---- pico/memory.c | 95 +++++++++---------- pico/{memory_amips.s => memory_amips.S} | 64 ++++++------- pico/{memory_arm.s => memory_arm.S} | 90 +++++++++--------- pico/mode4.c | 10 +- pico/pico.c | 42 ++++----- pico/pico_cmn.c | 28 +++--- pico/pico_int.h | 83 +++++++++-------- pico/pico_int_o32.h | 37 +++++--- pico/sek.c | 29 +++--- pico/sms.c | 20 ++-- pico/state.c | 50 +++++----- pico/videoport.c | 54 +++++------ platform/common/common.mak | 4 +- platform/common/emu.c | 16 ++-- tools/mkoffsets.c | 53 ++++++++--- 30 files changed, 633 insertions(+), 587 deletions(-) rename pico/cd/{memory_arm.s => memory_arm.S} (93%) rename pico/{memory_amips.s => memory_amips.S} (93%) rename pico/{memory_arm.s => memory_arm.S} (73%) diff --git a/pico/32x/memory.c b/pico/32x/memory.c index 2f3499c..f3b7006 100644 --- a/pico/32x/memory.c +++ b/pico/32x/memory.c @@ -1159,7 +1159,7 @@ static void bank_switch(int b) return; bank = b << 20; - if ((Pico.m.sram_reg & SRR_MAPPED) && bank == SRam.start) { + if ((Pico.m.sram_reg & SRR_MAPPED) && bank == Pico.sv.start) { bank_map_handler(); return; } diff --git a/pico/32x/pwm.c b/pico/32x/pwm.c index 1aba914..5073564 100644 --- a/pico/32x/pwm.c +++ b/pico/32x/pwm.c @@ -326,11 +326,11 @@ void p32x_pwm_state_loaded(void) p32x_pwm_ctl_changed(); // for old savestates - cycles_diff_sh2 = SekCycleCnt * 3 - Pico32x.pwm_cycle_p; + cycles_diff_sh2 = Pico.t.m68c_cnt * 3 - Pico32x.pwm_cycle_p; if (cycles_diff_sh2 >= pwm_cycles || cycles_diff_sh2 < 0) { Pico32x.pwm_irq_cnt = pwm_irq_reload; - Pico32x.pwm_cycle_p = SekCycleCnt * 3; - p32x_pwm_schedule(SekCycleCnt); + Pico32x.pwm_cycle_p = Pico.t.m68c_cnt * 3; + p32x_pwm_schedule(Pico.t.m68c_cnt); } } diff --git a/pico/cart.c b/pico/cart.c index 1ce8059..f17ce5e 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -617,9 +617,9 @@ int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_ Pico.rom=rom; Pico.romsize=romsize; - if (SRam.data) { - free(SRam.data); - SRam.data = NULL; + if (Pico.sv.data) { + free(Pico.sv.data); + Pico.sv.data = NULL; } if (PicoCartUnloadHook != NULL) { @@ -949,8 +949,8 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram) elprintf(EL_STATUS, "carthw:%d: bad sram_range: %08x - %08x", line, start, end); goto bad_nomsg; } - SRam.start = start; - SRam.end = end; + Pico.sv.start = start; + Pico.sv.end = end; continue; } else if (is_expr("prop", &p)) { @@ -959,9 +959,9 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram) rstrip(p); if (strcmp(p, "no_sram") == 0) - SRam.flags &= ~SRF_ENABLED; + Pico.sv.flags &= ~SRF_ENABLED; else if (strcmp(p, "no_eeprom") == 0) - SRam.flags &= ~SRF_EEPROM; + Pico.sv.flags &= ~SRF_EEPROM; else if (strcmp(p, "filled_sram") == 0) *fill_sram = 1; else if (strcmp(p, "force_6btn") == 0) @@ -982,8 +982,8 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram) type = strtoul(p, &r, 0); if (r == p || type < 0) goto bad; - SRam.eeprom_type = type; - SRam.flags |= SRF_EEPROM; + Pico.sv.eeprom_type = type; + Pico.sv.flags |= SRF_EEPROM; continue; } else if (is_expr("eeprom_lines", &p)) { @@ -998,9 +998,9 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram) sda_out < 0 || sda_out > 15) goto bad; - SRam.eeprom_bit_cl = scl; - SRam.eeprom_bit_in = sda_in; - SRam.eeprom_bit_out= sda_out; + Pico.sv.eeprom_bit_cl = scl; + Pico.sv.eeprom_bit_in = sda_in; + Pico.sv.eeprom_bit_out= sda_out; continue; } else if ((tmp = is_expr("prot_ro_value16", &p)) || is_expr("prot_rw_value16", &p)) { @@ -1040,54 +1040,54 @@ static void PicoCartDetect(const char *carthw_cfg) { int fill_sram = 0; - memset(&SRam, 0, sizeof(SRam)); + memset(&Pico.sv, 0, sizeof(Pico.sv)); if (Pico.rom[0x1B1] == 'R' && Pico.rom[0x1B0] == 'A') { - SRam.start = rom_read32(0x1B4) & ~0xff000001; // align - SRam.end = (rom_read32(0x1B8) & ~0xff000000) | 1; + Pico.sv.start = rom_read32(0x1B4) & ~0xff000001; // align + Pico.sv.end = (rom_read32(0x1B8) & ~0xff000000) | 1; if (Pico.rom[0x1B2] & 0x40) // EEPROM - SRam.flags |= SRF_EEPROM; - SRam.flags |= SRF_ENABLED; + Pico.sv.flags |= SRF_EEPROM; + Pico.sv.flags |= SRF_ENABLED; } - if (SRam.end == 0 || SRam.start > SRam.end) + if (Pico.sv.end == 0 || Pico.sv.start > Pico.sv.end) { // some games may have bad headers, like S&K and Sonic3 // note: majority games use 0x200000 as starting address, but there are some which // use something else (0x300000 by HardBall '95). Luckily they have good headers. - SRam.start = 0x200000; - SRam.end = 0x203FFF; - SRam.flags |= SRF_ENABLED; + Pico.sv.start = 0x200000; + Pico.sv.end = 0x203FFF; + Pico.sv.flags |= SRF_ENABLED; } // set EEPROM defaults, in case it gets detected - SRam.eeprom_type = 0; // 7bit (24C01) - SRam.eeprom_bit_cl = 1; - SRam.eeprom_bit_in = 0; - SRam.eeprom_bit_out= 0; + Pico.sv.eeprom_type = 0; // 7bit (24C01) + Pico.sv.eeprom_bit_cl = 1; + Pico.sv.eeprom_bit_in = 0; + Pico.sv.eeprom_bit_out= 0; if (carthw_cfg != NULL) parse_carthw(carthw_cfg, &fill_sram); - if (SRam.flags & SRF_ENABLED) + if (Pico.sv.flags & SRF_ENABLED) { - if (SRam.flags & SRF_EEPROM) - SRam.size = 0x2000; + if (Pico.sv.flags & SRF_EEPROM) + Pico.sv.size = 0x2000; else - SRam.size = SRam.end - SRam.start + 1; + Pico.sv.size = Pico.sv.end - Pico.sv.start + 1; - SRam.data = calloc(SRam.size, 1); - if (SRam.data == NULL) - SRam.flags &= ~SRF_ENABLED; + Pico.sv.data = calloc(Pico.sv.size, 1); + if (Pico.sv.data == NULL) + Pico.sv.flags &= ~SRF_ENABLED; - if (SRam.eeprom_type == 1) // 1 == 0 in PD EEPROM code - SRam.eeprom_type = 0; + if (Pico.sv.eeprom_type == 1) // 1 == 0 in PD EEPROM code + Pico.sv.eeprom_type = 0; } - if ((SRam.flags & SRF_ENABLED) && fill_sram) + if ((Pico.sv.flags & SRF_ENABLED) && fill_sram) { elprintf(EL_STATUS, "SRAM fill"); - memset(SRam.data, 0xff, SRam.size); + memset(Pico.sv.data, 0xff, Pico.sv.size); } // Unusual region 'code' diff --git a/pico/carthw/carthw.c b/pico/carthw/carthw.c index a8b4333..a18e5a4 100644 --- a/pico/carthw/carthw.c +++ b/pico/carthw/carthw.c @@ -318,7 +318,7 @@ static void carthw_pier_write8(u32 a, u32 d) base = d << 19; goto do_map; case 0x09: - SRam.changed = 1; + Pico.sv.changed = 1; eeprom_spi_write(d); break; case 0x0b: @@ -449,11 +449,11 @@ void carthw_pier_startup(void) // save EEPROM eeprom_state = eeprom_spi_init(&eeprom_size); - SRam.flags = 0; - SRam.size = 0x10000; - SRam.data = calloc(1, SRam.size); - if (!SRam.data) - SRam.size = 0; + Pico.sv.flags = 0; + Pico.sv.size = 0x10000; + Pico.sv.data = calloc(1, Pico.sv.size); + if (!Pico.sv.data) + Pico.sv.size = 0; carthw_pier_state[2].ptr = eeprom_state; carthw_pier_state[2].size = eeprom_size; diff --git a/pico/carthw/eeprom_spi.c b/pico/carthw/eeprom_spi.c index 9643067..b250aff 100644 --- a/pico/carthw/eeprom_spi.c +++ b/pico/carthw/eeprom_spi.c @@ -210,7 +210,7 @@ void eeprom_spi_write(unsigned char data) if (spi_eeprom.opcode & 0x01) { /* READ operation */ - spi_eeprom.buffer = SRam.data[spi_eeprom.addr]; + spi_eeprom.buffer = Pico.sv.data[spi_eeprom.addr]; spi_eeprom.state = READ_BYTE; } else @@ -266,7 +266,7 @@ void eeprom_spi_write(unsigned char data) /* $C000-$FFFF (sector #3) is protected */ if (spi_eeprom.addr < 0xC000) { - SRam.data[spi_eeprom.addr] = spi_eeprom.buffer; + Pico.sv.data[spi_eeprom.addr] = spi_eeprom.buffer; } break; } @@ -276,7 +276,7 @@ void eeprom_spi_write(unsigned char data) /* $8000-$FFFF (sectors #2 and #3) is protected */ if (spi_eeprom.addr < 0x8000) { - SRam.data[spi_eeprom.addr] = spi_eeprom.buffer; + Pico.sv.data[spi_eeprom.addr] = spi_eeprom.buffer; } break; } @@ -290,7 +290,7 @@ void eeprom_spi_write(unsigned char data) default: { /* no sectors protected */ - SRam.data[spi_eeprom.addr] = spi_eeprom.buffer; + Pico.sv.data[spi_eeprom.addr] = spi_eeprom.buffer; break; } } @@ -332,7 +332,7 @@ void eeprom_spi_write(unsigned char data) { /* read next array byte */ spi_eeprom.addr = (spi_eeprom.addr + 1) & SIZE_MASK; - spi_eeprom.buffer = SRam.data[spi_eeprom.addr]; + spi_eeprom.buffer = Pico.sv.data[spi_eeprom.addr]; } } } diff --git a/pico/cd/gfx_dma.c b/pico/cd/gfx_dma.c index a24a1c3..7dfe4bc 100644 --- a/pico/cd/gfx_dma.c +++ b/pico/cd/gfx_dma.c @@ -26,7 +26,7 @@ PICO_INTERNAL void DmaSlowCell(unsigned int source, unsigned int a, int len, uns switch (Pico.video.type) { case 1: // vram - r = Pico.vram; + r = PicoMem.vram; for(; len; len--) { asrc = cell_map(source >> 2) << 2; @@ -42,7 +42,7 @@ PICO_INTERNAL void DmaSlowCell(unsigned int source, unsigned int a, int len, uns case 3: // cram Pico.m.dirtyPal = 1; - r = Pico.cram; + r = PicoMem.cram; for(a2=a&0x7f; len; len--) { asrc = cell_map(source >> 2) << 2; @@ -58,7 +58,7 @@ PICO_INTERNAL void DmaSlowCell(unsigned int source, unsigned int a, int len, uns break; case 5: // vsram[a&0x003f]=d; - r = Pico.vsram; + r = PicoMem.vsram; for(a2=a&0x7f; len; len--) { asrc = cell_map(source >> 2) << 2; diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 6d23604..043b4a2 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -76,16 +76,16 @@ PICO_INTERNAL int PicoResetMCD(void) { // reset button doesn't affect MCD hardware - // use SRam.data for RAM cart + // use Pico.sv.data for RAM cart if (PicoOpt & POPT_EN_MCD_RAMCART) { - if (SRam.data == NULL) - SRam.data = calloc(1, 0x12000); + if (Pico.sv.data == NULL) + Pico.sv.data = calloc(1, 0x12000); } - else if (SRam.data != NULL) { - free(SRam.data); - SRam.data = NULL; + else if (Pico.sv.data != NULL) { + free(Pico.sv.data); + Pico.sv.data = NULL; } - SRam.start = SRam.end = 0; // unused + Pico.sv.start = Pico.sv.end = 0; // unused return 0; } @@ -95,17 +95,17 @@ static void SekRunM68kOnce(void) int cyc_do; pevt_log_m68k_o(EVT_RUN_START); - if ((cyc_do = SekCycleAim - SekCycleCnt) > 0) { - SekCycleCnt += cyc_do; + if ((cyc_do = Pico.t.m68c_aim - Pico.t.m68c_cnt) > 0) { + Pico.t.m68c_cnt += cyc_do; #if defined(EMU_C68K) PicoCpuCM68k.cycles = cyc_do; CycloneRun(&PicoCpuCM68k); - SekCycleCnt -= PicoCpuCM68k.cycles; + Pico.t.m68c_cnt -= PicoCpuCM68k.cycles; #elif defined(EMU_M68K) - SekCycleCnt += m68k_execute(cyc_do) - cyc_do; + Pico.t.m68c_cnt += m68k_execute(cyc_do) - cyc_do; #elif defined(EMU_F68K) - SekCycleCnt += fm68k_emulate(cyc_do, 0) - cyc_do; + Pico.t.m68c_cnt += fm68k_emulate(cyc_do, 0) - cyc_do; #endif } @@ -316,39 +316,39 @@ static void SekSyncM68k(void); void pcd_run_cpus_normal(int m68k_cycles) { - SekCycleAim += m68k_cycles; + Pico.t.m68c_aim += m68k_cycles; if (SekShouldInterrupt() || Pico_mcd->m.m68k_poll_cnt < 12) Pico_mcd->m.m68k_poll_cnt = 0; else if (Pico_mcd->m.m68k_poll_cnt >= 16) { - int s68k_left = pcd_sync_s68k(SekCycleAim, 1); + int s68k_left = pcd_sync_s68k(Pico.t.m68c_aim, 1); if (s68k_left <= 0) { elprintf(EL_CDPOLL, "m68k poll [%02x] x%d @%06x", Pico_mcd->m.m68k_poll_a, Pico_mcd->m.m68k_poll_cnt, SekPc); - SekCycleCnt = SekCycleAim; + Pico.t.m68c_cnt = Pico.t.m68c_aim; return; } - SekCycleCnt = SekCycleAim - (s68k_left * 40220 >> 16); + Pico.t.m68c_cnt = Pico.t.m68c_aim - (s68k_left * 40220 >> 16); } - while (CYCLES_GT(SekCycleAim, SekCycleCnt)) { + while (CYCLES_GT(Pico.t.m68c_aim, Pico.t.m68c_cnt)) { SekRunM68kOnce(); if (Pico_mcd->m.need_sync) { Pico_mcd->m.need_sync = 0; - pcd_sync_s68k(SekCycleCnt, 0); + pcd_sync_s68k(Pico.t.m68c_cnt, 0); } } } void pcd_run_cpus_lockstep(int m68k_cycles) { - unsigned int target = SekCycleAim + m68k_cycles; + unsigned int target = Pico.t.m68c_aim + m68k_cycles; do { - SekCycleAim += 8; + Pico.t.m68c_aim += 8; SekSyncM68k(); - pcd_sync_s68k(SekCycleAim, 0); - } while (CYCLES_GT(target, SekCycleAim)); + pcd_sync_s68k(Pico.t.m68c_aim, 0); + } while (CYCLES_GT(target, Pico.t.m68c_aim)); - SekCycleAim = target; + Pico.t.m68c_aim = target; } #define PICO_CD @@ -364,7 +364,7 @@ void pcd_prepare_frame(void) // need this because we can't have direct mapping between // master<->slave cycle counters because of overflows - mcd_m68k_cycle_base = SekCycleAim; + mcd_m68k_cycle_base = Pico.t.m68c_aim; mcd_s68k_cycle_base = SekCycleAimS68k; } @@ -390,7 +390,7 @@ void pcd_state_loaded(void) Pico_mcd->pcm_regs_dirty = 1; // old savestates.. - cycles = pcd_cycles_m68k_to_s68k(SekCycleAim); + cycles = pcd_cycles_m68k_to_s68k(Pico.t.m68c_aim); diff = cycles - SekCycleAimS68k; if (diff < -1000 || diff > 1000) { SekCycleCntS68k = SekCycleAimS68k = cycles; diff --git a/pico/cd/memory.c b/pico/cd/memory.c index fbc7c47..94b81b7 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -602,14 +602,14 @@ static u32 PicoReadM68k8_ramc(u32 a) { u32 d = 0; if (a == 0x400001) { - if (SRam.data != NULL) + if (Pico.sv.data != NULL) d = 3; // 64k cart return d; } if ((a & 0xfe0000) == 0x600000) { - if (SRam.data != NULL) - d = SRam.data[((a >> 1) & 0xffff) + 0x2000]; + if (Pico.sv.data != NULL) + d = Pico.sv.data[((a >> 1) & 0xffff) + 0x2000]; return d; } @@ -629,9 +629,9 @@ static u32 PicoReadM68k16_ramc(u32 a) static void PicoWriteM68k8_ramc(u32 a, u32 d) { if ((a & 0xfe0000) == 0x600000) { - if (SRam.data != NULL && (Pico_mcd->m.bcram_reg & 1)) { - SRam.data[((a>>1) & 0xffff) + 0x2000] = d; - SRam.changed = 1; + if (Pico.sv.data != NULL && (Pico_mcd->m.bcram_reg & 1)) { + Pico.sv.data[((a>>1) & 0xffff) + 0x2000] = d; + Pico.sv.changed = 1; } return; } @@ -877,7 +877,7 @@ static u32 PicoReadS68k16_bram(u32 a) static void PicoWriteS68k8_bram(u32 a, u32 d) { Pico_mcd->bram[(a >> 1) & 0x1fff] = d; - SRam.changed = 1; + Pico.sv.changed = 1; } static void PicoWriteS68k16_bram(u32 a, u32 d) @@ -886,7 +886,7 @@ static void PicoWriteS68k16_bram(u32 a, u32 d) a = (a >> 1) & 0x1fff; Pico_mcd->bram[a++] = d; Pico_mcd->bram[a++] = d >> 8; // TODO: verify.. - SRam.changed = 1; + Pico.sv.changed = 1; } #ifndef _ASM_CD_MEMORY_C @@ -1175,7 +1175,7 @@ PICO_INTERNAL void PicoMemSetupCD(void) 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)); + PicoCpuFM68k.Fetch[i] = (unsigned long)PicoMem.ram - (i<<(24-FAMEC_FETCHBITS)); // S68k // PRG RAM is default for (i = 0; i < M68K_FETCHBANK1; i++) diff --git a/pico/cd/memory_arm.s b/pico/cd/memory_arm.S similarity index 93% rename from pico/cd/memory_arm.s rename to pico/cd/memory_arm.S index f3a1372..23f0b94 100644 --- a/pico/cd/memory_arm.s +++ b/pico/cd/memory_arm.S @@ -6,6 +6,8 @@ @* See COPYING file in the top-level directory. @* +#include "../pico_int_o32.h" + .equiv PCM_STEP_SHIFT, 11 .text @@ -127,9 +129,9 @@ PicoReadM68k8_cell1: @ 0x220000 - 0x23ffff, cell arranged mov r3, #0x0e0000 0: cell_map - ldr r1, =(Pico+0x22200) + ldr r1, =Pico add r0, r0, r3 - ldr r1, [r1] + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd (used everywhere) eor r0, r0, #1 ldrb r0, [r1, r0] bx lr @@ -140,9 +142,9 @@ PicoRead8_mcd_io: cmp r1, #0x2000 @ a120xx? bne PicoRead8_io - ldr r1, =(Pico+0x22200) + ldr r1, =Pico and r0, r0, #0x3f - ldr r1, [r1] @ Pico.mcd (used everywhere) + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd cmp r0, #0x0e ldrlt pc, [pc, r0, lsl #2] b m_m68k_read8_hi @@ -237,9 +239,9 @@ PicoReadM68k16_cell1: @ 0x220000 - 0x23ffff, cell arranged mov r3, #0x0e0000 0: cell_map - ldr r1, =(Pico+0x22200) + ldr r1, =Pico add r0, r0, r3 - ldr r1, [r1] + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd bic r0, r0, #1 ldrh r0, [r1, r0] bx lr @@ -251,9 +253,9 @@ PicoRead16_mcd_io: bne PicoRead16_io m_m68k_read16_m68k_regs: - ldr r1, =(Pico+0x22200) + ldr r1, =Pico and r0, r0, #0x3e - ldr r1, [r1] @ Pico.mcd (used everywhere) + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd cmp r0, #0x0e ldrlt pc, [pc, r0, lsl #1] b m_m68k_read16_hi @@ -328,8 +330,9 @@ PicoWriteM68k8_cell1: @ 0x220000 - 0x23ffff, cell arranged 0: mov r3, r1 cell_map - ldr r2, =(Pico+0x22200) + ldr r2, =Pico add r0, r0, r12 + ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd ldr r2, [r2] eor r0, r0, #1 strb r3, [r2, r0] @@ -355,9 +358,9 @@ PicoWriteM68k16_cell1: @ 0x220000 - 0x23ffff, cell arranged 0: mov r3, r1 cell_map - ldr r1, =(Pico+0x22200) + ldr r1, =Pico add r0, r0, r12 - ldr r1, [r1] + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd bic r0, r0, #1 strh r3, [r1, r0] bx lr @@ -397,9 +400,9 @@ PicoReadS68k8_dec0: @ 0x080000 - 0x0bffff PicoReadS68k8_dec1: mov r3, #0x0a0000 @ + ^ / 2 0: - ldr r2, =(Pico+0x22200) + ldr r2, =Pico eor r0, r0, #2 - ldr r2, [r2] + ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd movs r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address ldrb r0, [r2, r0] @@ -429,8 +432,8 @@ m_s68k_read8_regs: bx lr m_s68k_read8_comm: - ldr r1, =(Pico+0x22200) - ldr r1, [r1] + ldr r1, =Pico + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd add r1, r1, #0x110000 ldrb r1, [r1, r0] bic r0, r0, #1 @@ -442,9 +445,9 @@ m_s68k_read8_pcm: bne m_read_null @ must not trash r3 and r12 - ldr r1, =(Pico+0x22200) + ldr r1, =Pico bic r0, r0, #0xff0000 - ldr r1, [r1] + ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd mov r2, #0x110000 orr r2, r2, #0x002200 cmp r0, #0x2000 @@ -477,9 +480,9 @@ PicoReadS68k16_dec0: @ 0x080000 - 0x0bffff PicoReadS68k16_dec1: mov r3, #0x0a0000 @ + ^ / 2 0: - ldr r2, =(Pico+0x22200) + ldr r2, =Pico eor r0, r0, #2 - ldr r2, [r2] + ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd mov r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address ldrb r0, [r2, r0] @@ -508,9 +511,9 @@ m_s68k_read16_regs: .macro m_s68k_write8_2M_decode - ldr r2, =(Pico+0x22200) + ldr r2, =Pico eor r0, r0, #2 - ldr r2, [r2] @ Pico.rom + ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd movs r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address .endm @@ -592,9 +595,9 @@ m_s68k_write8_pcm: bxlt lr m_s68k_write8_pcm_ram: - ldr r3, =(Pico+0x22200) + ldr r3, =Pico bic r0, r0, #0x00e000 - ldr r3, [r3] + ldr r3, [r3, #OFS_Pico_rom] @ Pico.mcd mov r0, r0, lsr #1 add r2, r3, #0x110000 add r2, r2, #0x002200 @@ -611,9 +614,9 @@ m_s68k_write8_pcm_ram: .macro m_s68k_write16_2M_decode - ldr r2, =(Pico+0x22200) + ldr r2, =Pico eor r0, r0, #2 - ldr r2, [r2] + ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd mov r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address .endm @@ -692,9 +695,9 @@ m_s68k_write16_regs: bne s68k_reg_write16 m_s68k_write16_regs_spec: @ special case - ldr r2, =(Pico+0x22200) + ldr r2, =Pico mov r0, #0x110000 - ldr r2, [r2] + ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd add r0, r0, #0x00000f strb r1, [r2, r0] @ if (a == 0xe) s68k_regs[0xf] = d; bx lr diff --git a/pico/debug.c b/pico/debug.c index eb775bf..82ae8a5 100644 --- a/pico/debug.c +++ b/pico/debug.c @@ -40,8 +40,8 @@ char *PDebugMain(void) sprintf(dstrp, "mode set 4: %02x\n", (r=reg[0xC])); MVP; sprintf(dstrp, "interlace: %i%i, cells: %i, shadow: %i\n", bit(r,2), bit(r,1), (r&0x80) ? 40 : 32, bit(r,3)); MVP; sprintf(dstrp, "scroll size: w: %i, h: %i SRAM: %i; eeprom: %i (%i)\n", reg[0x10]&3, (reg[0x10]&0x30)>>4, - !!(SRam.flags & SRF_ENABLED), !!(SRam.flags & SRF_EEPROM), SRam.eeprom_type); MVP; - sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", SRam.start, SRam.end, Pico.m.sram_reg); MVP; + !!(Pico.sv.flags & SRF_ENABLED), !!(Pico.sv.flags & SRF_EEPROM), Pico.sv.eeprom_type); MVP; + sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", Pico.sv.start, Pico.sv.end, Pico.m.sram_reg); MVP; sprintf(dstrp, "pend int: v:%i, h:%i, vdp status: %04x\n", bit(pv->pending_ints,5), bit(pv->pending_ints,4), pv->status); MVP; sprintf(dstrp, "pal: %i, hw: %02x, frame#: %i, cycles: %u\n", Pico.m.pal, Pico.m.hardware, Pico.m.frame_count, SekCyclesDone()); MVP; sprintf(dstrp, "M68k: PC: %06x, SR: %04x, irql: %i\n", SekPc, SekSr, SekIrqLevel); MVP; @@ -117,7 +117,7 @@ char *PDebugSpriteList(void) unsigned int *sprite; int code, code2, sx, sy, height; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // get sprite info code = sprite[0]; @@ -245,23 +245,23 @@ void PDebugShowSprite(unsigned short *screen, int stride, int which) for (u=0; u < max_sprites && u <= which; u++) { - sprite=(int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite link=(sprite[0]>>16)&0x7f; if (!link) break; // End of sprites } if (u >= max_sprites) return; - fsprite = (int *)(Pico.vram+(table&0x7ffc)); + fsprite = (int *)(PicoMem.vram+(table&0x7ffc)); oldsprite[0] = fsprite[0]; oldsprite[1] = fsprite[1]; fsprite[0] = (sprite[0] & ~0x007f01ff) | 0x000080; fsprite[1] = (sprite[1] & ~0x01ff8000) | 0x800000; oldreg = pvid->reg[7]; - oldcol = Pico.cram[0]; + oldcol = PicoMem.cram[0]; olddbg = pvid->debug_p; pvid->reg[7] = 0; - Pico.cram[0] = 0; + PicoMem.cram[0] = 0; pvid->debug_p = PVD_KILL_A | PVD_KILL_B; PicoFrameFull(); @@ -276,7 +276,7 @@ void PDebugShowSprite(unsigned short *screen, int stride, int which) fsprite[0] = oldsprite[0]; fsprite[1] = oldsprite[1]; pvid->reg[7] = oldreg; - Pico.cram[0] = oldcol; + PicoMem.cram[0] = oldcol; pvid->debug_p = olddbg; } @@ -325,18 +325,18 @@ void PDebugDumpMem(void) dump_ram_m(buf, "dumps/cart.bin", a ? "ab" : "wb"); } #endif - dump_ram_noswab(Pico.zram, "dumps/zram.bin"); - dump_ram(Pico.cram, "dumps/cram.bin"); + dump_ram_noswab(PicoMem.zram, "dumps/zram.bin"); + dump_ram(PicoMem.cram, "dumps/cram.bin"); if (PicoAHW & PAHW_SMS) { - dump_ram_noswab(Pico.vramb, "dumps/vram.bin"); + dump_ram_noswab(PicoMem.vramb, "dumps/vram.bin"); } else { - dump_ram(Pico.ram, "dumps/ram.bin"); - dump_ram(Pico.vram, "dumps/vram.bin"); - dump_ram(Pico.vsram,"dumps/vsram.bin"); + dump_ram(PicoMem.ram, "dumps/ram.bin"); + dump_ram(PicoMem.vram, "dumps/vram.bin"); + dump_ram(PicoMem.vsram,"dumps/vsram.bin"); } if (PicoAHW & PAHW_MCD) @@ -386,12 +386,12 @@ void PDebugZ80Frame(void) PsndStartFrame(); if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) - PicoSyncZ80(SekCycleCnt + line_sample * 488); + PicoSyncZ80(Pico.t.m68c_cnt + line_sample * 488); if (PsndOut) PsndGetSamples(line_sample); if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) { - PicoSyncZ80(SekCycleCnt + 224 * 488); + PicoSyncZ80(Pico.t.m68c_cnt + 224 * 488); z80_int(); } if (PsndOut) @@ -399,15 +399,15 @@ void PDebugZ80Frame(void) // sync z80 if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) { - SekCycleCnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter - PicoSyncZ80(SekCycleCnt); + Pico.t.m68c_cnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter + PicoSyncZ80(Pico.t.m68c_cnt); } if (PsndOut && ym2612.dacen && PsndDacLine < lines) PsndDoDAC(lines - 1); PsndDoPSG(lines - 1); timers_cycle(); - SekCycleAim = SekCycleCnt; + Pico.t.m68c_aim = Pico.t.m68c_cnt; } void PDebugCPUStep(void) diff --git a/pico/draw.c b/pico/draw.c index 5ecbca8..6408f20 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -215,7 +215,7 @@ static void DrawStrip(struct TileStrip *ts, int lflags, int cellskip) { unsigned int pack; - code = Pico.vram[ts->nametab + (tilex & ts->xmask)]; + code = PicoMem.vram[ts->nametab + (tilex & ts->xmask)]; if (code == blank) continue; if ((code >> 15) | (lflags & LF_FORCE)) { // high priority tile @@ -235,7 +235,7 @@ static void DrawStrip(struct TileStrip *ts, int lflags, int cellskip) pal=((code>>9)&0x30)|sh; } - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -274,7 +274,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) //if((cell&1)==0) { int line,vscroll; - vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)]; + vscroll=PicoMem.vsram[(plane_sh&1)+(cell&~1)]; // Find the line in the name table line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask .. @@ -282,7 +282,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) ty=(line&7)<<1; // Y-Offset into tile } - code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)]; + code=PicoMem.vram[ts->nametab+nametabadd+(tilex&ts->xmask)]; if (code==blank) continue; if (code>>15) { // high priority tile int cval = code | (dx<<16) | (ty<<25); @@ -300,7 +300,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) pal=((code>>9)&0x30)|((plane_sh<<5)&0x40); } - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -336,7 +336,7 @@ void DrawStripInterlace(struct TileStrip *ts) { unsigned int pack; - code=Pico.vram[ts->nametab+(tilex&ts->xmask)]; + code = PicoMem.vram[ts->nametab + (tilex & ts->xmask)]; if (code==blank) continue; if (code>>15) { // high priority tile int cval = (code&0xfc00) | (dx<<16) | (ty<<25); @@ -356,7 +356,7 @@ void DrawStripInterlace(struct TileStrip *ts) pal=((code>>9)&0x30); } - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -409,11 +409,11 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells, htab+=plane_sh&1; // A or B // Get horizontal scroll value, will be masked later - ts.hscroll=Pico.vram[htab&0x7fff]; + ts.hscroll = PicoMem.vram[htab & 0x7fff]; if((pvid->reg[12]&6) == 6) { // interlace mode 2 - vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value + vscroll = PicoMem.vsram[plane_sh & 1]; // Get vertical scroll value // Find the line in the name table ts.line=(vscroll+(est->DrawScanline<<1))&((ymask<<1)|1); @@ -426,7 +426,7 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells, ts.line=ymask|(shift[width]<<24); // save some stuff instead of line DrawStripVSRam(&ts, plane_sh, cellskip); } else { - vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value + vscroll = PicoMem.vsram[plane_sh & 1]; // Get vertical scroll value // Find the line in the name table ts.line=(vscroll+est->DrawScanline)&ymask; @@ -463,7 +463,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, if (!(est->rendstatus & PDRAW_WND_DIFF_PRIO)) { // check the first tile code - code=Pico.vram[nametab+tilex]; + code = PicoMem.vram[nametab + tilex]; // if the whole window uses same priority (what is often the case), we may be able to skip this field if ((code>>15) != prio) return; } @@ -480,7 +480,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, int dx, addr; int pal; - code=Pico.vram[nametab+tilex]; + code = PicoMem.vram[nametab + tilex]; if (code==blank) continue; if ((code>>15) != prio) { est->rendstatus |= PDRAW_WND_DIFF_PRIO; @@ -491,7 +491,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, addr=(code&0x7ff)<<4; if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -512,7 +512,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, int dx, addr; int pal; - code=Pico.vram[nametab+tilex]; + code = PicoMem.vram[nametab + tilex]; if(code==blank) continue; if((code>>15) != prio) { est->rendstatus |= PDRAW_WND_DIFF_PRIO; @@ -533,7 +533,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, addr=(code&0x7ff)<<4; if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -587,7 +587,7 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est addr = (code & 0x7ff) << 4; addr += code >> 25; // y offset into tile - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = (short)code; continue; @@ -615,7 +615,7 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) continue; @@ -717,7 +717,7 @@ static void DrawSprite(int *sprite, int sh) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); fTileFunc(sx, pack, pal); } } @@ -737,7 +737,7 @@ static NOINLINE void DrawTilesFromCacheForced(const int *hc) dx = (code >> 16) & 0x1ff; pal = ((code >> 9) & 0x30); - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (code & 0x0800) TileFlip_and(dx, pack, pal); else TileNorm_and(dx, pack, pal); @@ -783,7 +783,7 @@ static void DrawSpriteInterlace(unsigned int *sprite) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); if (code & 0x0800) TileFlip(sx, pack, pal); else TileNorm(sx, pack, pal); } @@ -805,7 +805,7 @@ static NOINLINE void DrawAllSpritesInterlace(int pri, int sh) unsigned int *sprite; int code, sx, sy, height; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // get sprite info code = sprite[0]; @@ -908,7 +908,7 @@ static void DrawSpritesSHi(unsigned char *sprited, const struct PicoEState *est) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); fTileFunc(sx, pack, pal); } } @@ -982,7 +982,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); fTileFunc(sx, pack, pal); } } @@ -1042,7 +1042,7 @@ static NOINLINE void PrepareSprites(int full) unsigned int *sprite; int code2, sx, sy, height; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // parse sprite info code2 = sprite[1]; @@ -1095,7 +1095,7 @@ found:; unsigned int *sprite; int code, code2, sx, sy, hv, height, width; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // parse sprite info code = sprite[0]; @@ -1219,7 +1219,7 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est) Pico.m.dirtyPal = 0; - spal = (void *)Pico.cram; + spal = (void *)PicoMem.cram; dpal = (void *)est->HighPal; for (i = 0; i < 0x40 / 2; i++) { @@ -1301,9 +1301,9 @@ static void FinalizeLine8bit(int sh, int line, struct PicoEState *est) rs |= PDRAW_SONIC_MODE; est->rendstatus = rs; if (dirty_count == 3) { - blockcpy(est->HighPal, Pico.cram, 0x40*2); + blockcpy(est->HighPal, PicoMem.cram, 0x40*2); } else if (dirty_count == 11) { - blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2); + blockcpy(est->HighPal+0x40, PicoMem.cram, 0x40*2); } } diff --git a/pico/draw2.c b/pico/draw2.c index db155fa..f0e0518 100644 --- a/pico/draw2.c +++ b/pico/draw2.c @@ -25,7 +25,7 @@ static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; static int HighCache2A[41*(TILE_ROWS+1)+1+1]; // caches for high layers static int HighCache2B[41*(TILE_ROWS+1)+1+1]; -unsigned short *PicoCramHigh=Pico.cram; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now) +unsigned short *PicoCramHigh=PicoMem.cram; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now) void (*PicoPrepareCram)()=0; // prepares PicoCramHigh for renderer to use @@ -46,7 +46,7 @@ static int TileXnormYnorm(unsigned char *pd,int addr,unsigned char pal) int i; for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) { - pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels if(!pack) continue; t=pack&0x0000f000; if (t) pd[0]=(unsigned char)((t>>12)|pal); @@ -69,7 +69,7 @@ static int TileXflipYnorm(unsigned char *pd,int addr,unsigned char pal) int i; for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) { - pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels if(!pack) continue; t=pack&0x000f0000; if (t) pd[0]=(unsigned char)((t>>16)|pal); @@ -92,7 +92,7 @@ static int TileXnormYflip(unsigned char *pd,int addr,unsigned char pal) addr+=14; for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) { - pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels if(!pack) continue; t=pack&0x0000f000; if (t) pd[0]=(unsigned char)((t>>12)|pal); @@ -116,7 +116,7 @@ static int TileXflipYflip(unsigned char *pd,int addr,unsigned char pal) addr+=14; for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) { - pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels if(!pack) continue; t=pack&0x000f0000; if (t) pd[0]=(unsigned char)((t>>16)|pal); @@ -161,7 +161,7 @@ static void DrawWindowFull(int start, int end, int prio, struct PicoEState *est) nametab += nametab_step*start; // check priority - code=Pico.vram[nametab+tile_start]; + code=PicoMem.vram[nametab+tile_start]; if ((code>>15) != prio) return; // hack: just assume that whole window uses same priority scrpos+=8*LINE_WIDTH+8; @@ -175,7 +175,7 @@ static void DrawWindowFull(int start, int end, int prio, struct PicoEState *est) // unsigned short *pal=NULL; unsigned char pal; - code=Pico.vram[nametab+tilex]; + code=PicoMem.vram[nametab+tilex]; if (code==blank) continue; // Get tile address/2: @@ -222,7 +222,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend, if(!(pvid->reg[11]&3)) { // full screen scroll // Get horizontal scroll value - hscroll=Pico.vram[htab&0x7fff]; + hscroll=PicoMem.vram[htab&0x7fff]; htab = 0; // this marks that we don't have to update scroll value } @@ -243,7 +243,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend, scrpos+=8*LINE_WIDTH*(planestart-START_ROW); // Get vertical scroll value: - vscroll=Pico.vsram[plane]&0x1ff; + vscroll=PicoMem.vsram[plane]&0x1ff; scrpos+=(8-(vscroll&7))*LINE_WIDTH; if(vscroll&7) planeend++; // we have vertically clipped tiles due to vscroll, so we need 1 more row @@ -262,7 +262,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend, if(htab) { int htaddr=htab+(trow<<4); if(trow) htaddr-=(vscroll&7)<<1; - hscroll=Pico.vram[htaddr&0x7fff]; + hscroll=PicoMem.vram[htaddr&0x7fff]; } // Draw tiles across screen: @@ -276,7 +276,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend, // unsigned short *pal=NULL; unsigned char pal; - code=Pico.vram[nametab_row+(tilex&xmask)]; + code=PicoMem.vram[nametab_row+(tilex&xmask)]; if (code==blank) continue; if (code>>15) { // high priority tile @@ -422,7 +422,7 @@ static void DrawAllSpritesFull(int prio, int maxwidth) unsigned int *sprite=NULL; int code, code2, sx, sy, height; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // get sprite info code = sprite[0]; diff --git a/pico/draw2_arm.S b/pico/draw2_arm.S index 6e7e1ac..1575653 100644 --- a/pico/draw2_arm.S +++ b/pico/draw2_arm.S @@ -353,10 +353,10 @@ DrawLayerFull: mov r6, r1 @ hcache - ldr r11, [r12, #OFS_Pico_video] - ldr r10, [r12, #OFS_Pico_vram] - ldrb r5, [r11, #13] @ pvid->reg[13] - ldrb r7, [r11, #11] + ldr r11, [r12, #OFS_EST_Pico] + ldr r10, [r12, #OFS_EST_PicoMem_vram] + ldrb r5, [r11, #OFS_Pico_video_reg+13] @ pvid->reg[13] + ldrb r7, [r11, #OFS_Pico_video_reg+11] sub lr, r3, r2 and lr, lr, #0x00ff0000 @ lr=cells @@ -366,7 +366,7 @@ DrawLayerFull: bic r5, r5, #0x00ff0000 @ just in case tst r7, #3 @ full screen scroll? (if ==0) - ldrb r7, [r11, #16] @ ??hh??ww + ldrb r7, [r11, #OFS_Pico_video_reg+16] @ ??hh??ww ldreqh r5, [r10, r5] biceq r5, r5, #0x0000fc00 @ r5=hscroll (0-0x3ff) movne r5, r5, lsr #1 @@ -397,15 +397,15 @@ DrawLayerFull: @ Find name table: tst r0, r0 - ldreqb r4, [r11, #2] + ldreqb r4, [r11, #OFS_Pico_video_reg+2] moveq r4, r4, lsr #3 - ldrneb r4, [r11, #4] + ldrneb r4, [r11, #OFS_Pico_video_reg+4] and r4, r4, #7 orr lr, lr, r4, lsl #13 @ lr|=nametab_bits{3}<<13 ldr r11,[sp, #9*4] @ est sub r4, r9, #(START_ROW<<24) - ldr r11, [r11, #OFS_Draw2FB] + ldr r11, [r11, #OFS_EST_Draw2FB] mov r4, r4, asr #24 mov r7, #328*8 mla r11, r4, r7, r11 @ scrpos+=8*328*(planestart-START_ROW); @@ -582,13 +582,13 @@ DrawTilesFromCacheF: mov r9, #0xff000000 @ r9=prevcode=-1 mvn r6, #0 @ r6=prevy=-1 - ldr r4, [r1, #OFS_Draw2FB] + ldr r4, [r1, #OFS_EST_Draw2FB] ldr r2, [r0], #4 @ read y offset mov r7, #328 mla r2, r7, r2, r4 sub r12, r2, #(328*8*START_ROW) @ r12=scrpos - ldr r10, [r1, #OFS_Pico_vram] + ldr r10, [r1, #OFS_EST_PicoMem_vram] mov r8, r0 @ hc mov r0, #0xf @@ -674,11 +674,11 @@ DrawTilesFromCacheF: DrawWindowFull: stmfd sp!, {r4-r11,lr} - ldr r11, [r3, #OFS_Pico_video] - ldrb r12, [r11, #3] @ pvid->reg[3] + ldr r11, [r3, #OFS_EST_Pico] + ldrb r12, [r11, #OFS_Pico_video_reg+3] @ pvid->reg[3] mov r12, r12, lsl #10 - ldr r4, [r11, #12] + ldr r4, [r11, #OFS_Pico_video_reg+12] mov r5, #1 @ nametab_step tst r4, #1 @ 40 cell mode? andne r12, r12, #0xf000 @ 0x3c<<10 @@ -689,7 +689,7 @@ DrawWindowFull: and r4, r0, #0xff mla r12, r5, r4, r12 @ nametab += nametab_step*start; - ldr r10, [r3, #OFS_Pico_vram] + ldr r10, [r3, #OFS_EST_PicoMem_vram] mov r4, r0, lsr #16 @ r4=start_cell_h add r7, r12, r4, lsl #1 @@ -707,7 +707,7 @@ DrawWindowFull: mov r9, #0xff000000 @ r9=prevcode=-1 - ldr r11, [r3, #OFS_Draw2FB] + ldr r11, [r3, #OFS_EST_Draw2FB] and r4, r0, #0xff add r11, r11, #328*8 sub r4, r4, #START_ROW @@ -760,7 +760,8 @@ DrawWindowFull: tst r9, #0x080000 @ hflip? bne .dwf_hflip - @ Tile (r1=pdest, r3=pal, r9=prevcode, r10=Pico.vram) r2,r4,r7: scratch, r0=0xf + @ Tile (r1=pdest, r3=pal, r9=prevcode, r10=PicoMem.vram) + @ r2,r4,r7: scratch, r0=0xf Tile 0, 0 b .dwfloop @@ -870,7 +871,8 @@ DrawWindowFull: cmp r6, #(END_ROW*8+8) bge 52b - @ Tile (r1=pdest, r3=pal, r9=prevcode, r10=Pico.vram) r2,r4,r7: scratch, r0=0xf + @ Tile (r1=pdest, r3=pal, r9=prevcode, r10=PicoMem.vram) + @ r2,r4,r7: scratch, r0=0xf Tile \hflip, \vflip b 52b .endm @@ -905,8 +907,8 @@ DrawSpriteFull: and r3, lr, #0x6000 mov r3, r3, lsr #9 @ r3=pal=((code>>9)&0x30); - ldr r11, [r1, #OFS_Draw2FB] - ldr r10, [r1, #OFS_Pico_vram] + ldr r11, [r1, #OFS_EST_Draw2FB] + ldr r10, [r1, #OFS_EST_PicoMem_vram] sub r1, r12, #(START_ROW*8) mov r0, #328 mla r11, r1, r0, r11 @ scrpos+=(sy-START_ROW*8)*328; diff --git a/pico/draw_arm.S b/pico/draw_arm.S index fae07b8..d53e04b 100644 --- a/pico/draw_arm.S +++ b/pico/draw_arm.S @@ -287,10 +287,10 @@ DrawLayer: ldr r12, [sp] @ est stmfd sp!, {r4-r11,lr} - ldr r11, [r12, #OFS_Pico_video] + ldr r11, [r12, #OFS_EST_Pico] mov r8, #1 - ldrb r7, [r11, #16] @ ??vv??hh + ldrb r7, [r11, #OFS_Pico_video_reg+16] @ ??vv??hh mov r6, r1 @ hcache orr r9, r3, r0, lsl #29 @ r9=force[31]|sh[30]|plane[29] @@ -311,13 +311,13 @@ DrawLayer: cmp r10, #7 subge r10, r10, #1 @ r10=shift[width] (5,6,6,7) - ldr r2, [r12, #OFS_DrawScanline] - ldr lr, [r12, #OFS_Pico_vram] + ldr r2, [r12, #OFS_EST_DrawScanline] + ldr lr, [r12, #OFS_EST_PicoMem_vram] @ Find name table: ands r0, r0, #1 - ldreqb r12, [r11, #2] - ldrneb r12, [r11, #4] + ldreqb r12, [r11, #OFS_Pico_video_reg+2] + ldrneb r12, [r11, #OFS_Pico_video_reg+4] @ calculate xmask: mov r5, r8, lsl r10 @@ -327,8 +327,8 @@ DrawLayer: movne r12, r12, lsl #13 and r12, r12, #(7<<13) @ r12=(ts->nametab<<1) (halfword compliant) - ldrh r8, [r11, #12] - ldrb r7, [r11, #11] + ldrh r8, [r11, #OFS_Pico_video_reg+12] + ldrb r7, [r11, #OFS_Pico_video_reg+11] mov r4, r8, lsr #8 @ pvid->reg[13] mov r4, r4, lsl #10 @ htab=pvid->reg[13]<<9; (halfwords) @@ -345,7 +345,7 @@ DrawLayer: @ Get vertical scroll value: add r7, lr, #0x012000 - add r7, r7, #0x000180 @ r7=Pico.vsram (Pico+0x22180) + add r7, r7, #0x000180 @ r7=PicoMem.vsram (PicoMem+0x22180) ldr r7, [r7] tst r8, #2 @@ -392,7 +392,7 @@ DrawLayer: @ cache some stuff to avoid mem access ldr r11,[sp, #9*4] @ est mov r0, #0xf - ldr r11,[r11, #OFS_HighCol] + ldr r11,[r11, #OFS_EST_HighCol] mvn r9, #0 @ r9=prevcode=-1 add r1, r11, r7 @ r1=pdest @@ -497,10 +497,10 @@ DrawLayer: tst r10, #1<<21 @ seen non hi-prio tile ldr r1, [sp, #9*4] @ est mov r0, #0 - ldreq r2, [r1, #OFS_rendstatus] + ldreq r2, [r1, #OFS_EST_rendstatus] str r0, [r6] @ terminate the cache list orreq r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles - streq r2, [r1, #OFS_rendstatus] + streq r2, [r1, #OFS_EST_rendstatus] ldmfd sp!, {r4-r11,lr} bx lr @@ -515,7 +515,7 @@ DrawLayer: ldr r11, [sp, #9*4] @ est orr r5, r1, r10, lsl #24 - ldr r4, [r11, #OFS_DrawScanline] + ldr r4, [r11, #OFS_EST_DrawScanline] sub r1, r3, #1 orr r5, r5, r4, lsl #16 @ r5=(shift_width[31:24]|scanline[23:16]|ymask[15:0]) and r1, r1, #7 @@ -541,7 +541,7 @@ DrawLayer: @ cache some stuff to avoid mem access ldr r11,[sp, #9*4] @ est mov r0, #0xf - ldr r11,[r11, #OFS_HighCol] + ldr r11,[r11, #OFS_EST_HighCol] mvn r9, #0 @ r9=prevcode=-1 add r1, r11, r7 @ r1=pdest @@ -557,7 +557,7 @@ DrawLayer: @ calc offset and read tileline code to r7, also calc ty add r7, lr, #0x012000 - add r7, r7, #0x000180 @ r7=Pico.vsram (Pico+0x22180) + add r7, r7, #0x000180 @ r7=PicoMem.vsram (PicoMem+0x22180) add r7, r7, r10,asr #23 @ vsram + ((cell&~1)<<1) bic r7, r7, #3 tst r10,#0x8000 @ plane1? @@ -576,7 +576,7 @@ DrawLayer: mov r4, r4, lsl r7 @ nametabadd and r7, r8, r8, lsr #25 - add r7, lr, r7, lsl #1 @ Pico.vram+((tilex&ts->xmask) as halfwords) + add r7, lr, r7, lsl #1 @ PicoMem.vram+((tilex&ts->xmask) as halfwords) add r7, r7, r4, lsl #1 ldrh r7, [r7, r12] @ r7=code (int, but from unsigned, no sign extend) @@ -598,7 +598,7 @@ DrawLayer: mov r2, r2, lsr #17 eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe; - ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels bic r7, r3, #0x3f and r3, r9, #0x6000 @@ -656,7 +656,7 @@ DrawLayer: add r2, r2, r10, lsl #17 mov r2, r2, lsr #17 eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe; - ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels mov r9, r7 @ remember code tst r2, r2 orrne r10, r10, #1<<22 @@ -667,10 +667,10 @@ DrawLayer: tst r8, #(1<<24) @ seen non hi-prio tile ldr r1, [sp, #9*4] @ est mov r0, #0 - ldreq r2, [r1, #OFS_rendstatus] + ldreq r2, [r1, #OFS_EST_rendstatus] str r0, [r6] @ terminate the cache list orreq r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles - streq r2, [r1, #OFS_rendstatus] + streq r2, [r1, #OFS_EST_rendstatus] ldmfd sp!, {r4-r11,lr} bx lr @@ -716,7 +716,7 @@ BackFill: stmfd sp!, {r4-r9,lr} mov r0, r0, lsl #26 - ldr lr, [r2, #OFS_HighCol] + ldr lr, [r2, #OFS_EST_HighCol] mov r0, r0, lsr #26 add lr, lr, #8 @@ -758,9 +758,9 @@ DrawTilesFromCache: stmfd sp!, {r4-r9,r11,lr} @ cache some stuff to avoid mem access - ldr r11,[r3, #OFS_HighCol] + ldr r11,[r3, #OFS_EST_HighCol] mov r12,#0xf - ldr lr, [r3, #OFS_Pico_vram] + ldr lr, [r3, #OFS_EST_PicoMem_vram] mov r9, r3 @ est mvn r5, #0 @ r5=prevcode=-1 @@ -892,14 +892,14 @@ DrawTilesFromCache: @ check if we have detected layer covered with hi-prio tiles: .dtfc_check_rendflags: - ldr r2, [r9, #OFS_rendstatus] + ldr r2, [r9, #OFS_EST_rendstatus] tst r2, #(PDRAW_PLANE_HI_PRIO|PDRAW_SHHI_DONE) beq .dtfc_loop bic r8, r8, #1 @ sh/hi mode off tst r2, #PDRAW_SHHI_DONE bne .dtfc_loop @ already processed orr r2, r2, #PDRAW_SHHI_DONE - str r2, [r9, #OFS_rendstatus] + str r2, [r9, #OFS_EST_rendstatus] add r1, r11,#8 mov r3, #320/4/4 @@ -939,16 +939,16 @@ DrawSpritesSHi: add r10,r0, #3 @ r10=HighLnSpr end add r10,r10,r3 @ r10=HighLnSpr end - ldr r11,[r1, #OFS_HighCol] + ldr r11,[r1, #OFS_EST_HighCol] mov r12,#0xf - ldr lr, [r1, #OFS_Pico_vram] + ldr lr, [r1, #OFS_EST_PicoMem_vram] DrawSpriteSHi: @ draw next sprite ldrb r0, [r10,#-1]! ldr r7, [sp] @ est - ldr r1, [r7, #OFS_HighPreSpr] + ldr r1, [r7, #OFS_EST_HighPreSpr] cmp r0, #0xff ldmeqfd sp!, {r1,r4-r11,pc} @ end of list and r0, r0, #0x7f @@ -974,7 +974,7 @@ DrawSpriteSHi: mov r5, r3, lsr #24 and r5, r5, #7 @ r5=height - ldr r7, [r7, #OFS_DrawScanline] + ldr r7, [r7, #OFS_EST_DrawScanline] mov r0, r3, lsl #16 @ r4=sy<<16 (tmp) sub r7, r7, r0, asr #16 @ r7=row=DrawScanline-sy @@ -1015,7 +1015,7 @@ DrawSpriteSHi: mov r8, r8, lsl #17 mov r8, r8, lsr #17 @ tile&=0x7fff; // Clip tile address - ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels add r1, r11, r0 @ r1=pdest tst r2, r2 beq .dsprShi_loop @@ -1117,9 +1117,9 @@ DrawAllSprites: add r10,r0, #3 add r10,r10,r2 @ r10=HighLnSpr end - ldr r11,[r3, #OFS_HighCol] + ldr r11,[r3, #OFS_EST_HighCol] mov r12,#0xf - ldr lr, [r3, #OFS_Pico_vram] + ldr lr, [r3, #OFS_EST_PicoMem_vram] @ + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: horiz. size @ + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8 @@ -1134,12 +1134,12 @@ DrawSprite: ldmeqfd sp!, {r1,r3-r11,pc} @ end of list cmp r2, r8, lsr #1 bne DrawSprite @ wrong priority - ldr r1, [r7, #OFS_HighPreSpr] + ldr r1, [r7, #OFS_EST_HighPreSpr] and r0, r0, #0x7f add r0, r1, r0, lsl #3 ldr r3, [r0] @ sprite[0] - ldr r7, [r7, #OFS_DrawScanline] + ldr r7, [r7, #OFS_EST_DrawScanline] mov r6, r3, lsr #28 sub r6, r6, #1 @ r6=width-1 (inc later) mov r5, r3, lsr #24 @@ -1198,7 +1198,7 @@ DrawSprite: mov r8, r8, lsl #17 mov r8, r8, lsr #17 @ tile&=0x7fff; // Clip tile address - ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels + ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels add r1, r11, r0 @ r1=pdest tst r2, r2 beq .dspr_loop @@ -1267,12 +1267,12 @@ DrawWindow: ldr r12, [sp] @ est stmfd sp!, {r4-r11,lr} - ldr r6, [r12, #OFS_Pico_video] - ldr r10, [r12, #OFS_DrawScanline] + ldr r6, [r12, #OFS_EST_Pico] + ldr r10, [r12, #OFS_EST_DrawScanline] mov r11, r12 @ est - ldrb r12, [r6, #3] @ pvid->reg[3] + ldrb r12, [r6, #OFS_Pico_video_reg+3] @ pvid->reg[3] - ldr r4, [r6, #12] + ldr r4, [r6, #OFS_Pico_video_reg+12] mov r5, r10, lsr #3 and r10, r10, #7 mov r10, r10, lsl #1 @ r10=ty @@ -1286,8 +1286,8 @@ DrawWindow: addeq r12, r12, r5, lsl #6 @ nametab add r12, r12, r0, lsl #2 @ +starttile - ldr lr, [r11, #OFS_Pico_vram] - ldr r6, [r11, #OFS_rendstatus] + ldr lr, [r11, #OFS_EST_PicoMem_vram] + ldr r6, [r11, #OFS_EST_rendstatus] @ fetch the first code now ldrh r7, [lr, r12] @@ -1304,7 +1304,7 @@ DrawWindow: sub r8, r1, r0 @ cache some stuff to avoid mem access - ldr r11, [r11, #OFS_HighCol] + ldr r11, [r11, #OFS_EST_HighCol] mov r8, r8, lsl #1 @ cells add r11,r11,#8 mvn r9, #0 @ r9=prevcode=-1 @@ -1392,9 +1392,9 @@ DrawWindow: and r2, r6, #PDRAW_WND_DIFF_PRIO ldmfd sp!, {r4-r11,lr} ldr r0, [sp] - ldr r1, [r0, #OFS_rendstatus] + ldr r1, [r0, #OFS_EST_rendstatus] orr r1, r1, r2 - str r1, [r0, #OFS_rendstatus] + str r1, [r0, #OFS_EST_rendstatus] bx lr @@ -1486,17 +1486,17 @@ PicoDoHighPal555: stmfd sp!, {r4-r10,lr} mov r10,r2 @ est mov r1, #0 - ldr r8, [r10, #OFS_Pico_video] + ldr r8, [r10, #OFS_EST_Pico] PicoDoHighPal555_nopush: orr r9, r1, r0, lsl #31 @ 0:called from FinalizeLine555, 31: s/h - add r0, r10, #OFS_HighPal + add r0, r10, #OFS_EST_HighPal mov r1, #0 - strb r1, [r8, #-0x1a] @ 0x2220e ~ dirtyPal + strb r1, [r8, #OFS_Pico_m_dirtyPal] - sub r1, r8, #0x128 @ r1=Pico.cram + ldr r1, [r10, #OFS_EST_PicoMem_cram] mov r2, #0x40 mov r8, #0x0061 orr r8, r8, #0x0800 @@ -1507,7 +1507,7 @@ PicoDoHighPal555_nopush: tst r9, #(1<<31) beq PicoDoHighPal555_end - add r3, r10, #OFS_HighPal + add r3, r10, #OFS_EST_HighPal @ shadowed pixels: mov r12, #0x008e @@ -1550,7 +1550,7 @@ PicoDoHighPal555_end: tst r9, #1 ldmeqfd sp!, {r4-r10,pc} - ldr r8, [r10, #OFS_Pico_video] + ldr r8, [r10, #OFS_EST_Pico] b FinalizeLineRGB555_pal_done @@ -1561,33 +1561,33 @@ PicoDoHighPal555_end: FinalizeLine555: stmfd sp!, {r4-r10,lr} mov r10,r2 @ est - ldr r8, [r10, #OFS_Pico_video] + ldr r8, [r10, #OFS_EST_Pico] - ldrb r2, [r8, #-0x1a] @ 0x2220e ~ dirtyPal + ldrb r2, [r8, #OFS_Pico_m_dirtyPal] mov r1, #1 tst r2, r2 bne PicoDoHighPal555_nopush FinalizeLineRGB555_pal_done: - add r3, r10, #OFS_HighPal + add r3, r10, #OFS_EST_HighPal - ldr r12, [r10, #OFS_rendstatus] + ldr r12, [r10, #OFS_EST_rendstatus] eors r0, r0, #1 @ sh is 0 mov lr, #0xff tstne r12,#PDRAW_ACC_SPRITES movne lr, #0x3f - ldr r1, [r10, #OFS_HighCol] - ldr r0, [r10, #OFS_DrawLineDest] + ldr r1, [r10, #OFS_EST_HighCol] + ldr r0, [r10, #OFS_EST_DrawLineDest] add r1, r1, #8 - ldrb r12, [r8, #12] + ldrb r12, [r8, #OFS_Pico_video_reg+12] mov lr, lr, lsl #1 tst r12, #1 movne r2, #320/8 @ len bne .fl_no32colRGB555 - ldr r4, [r10, #OFS_PicoOpt] + ldr r4, [r10, #OFS_EST_PicoOpt] mov r2, #256/8 ldr r4, [r4] tst r4, #0x4000 diff --git a/pico/eeprom.c b/pico/eeprom.c index 16f6c05..d727766 100644 --- a/pico/eeprom.c +++ b/pico/eeprom.c @@ -42,14 +42,14 @@ static void EEPROM_write_do(unsigned int d) // ???? ??la (l=SCL, a=SDA) { // we are started and SCL went high - next cycle scyc++; // pre-increment - if(SRam.eeprom_type) { + if(Pico.sv.eeprom_type) { // X24C02+ if((ssa&1) && scyc == 18) { scyc = 9; saddr++; // next address in read mode - /*if(SRam.eeprom_type==2) saddr&=0xff; else*/ saddr&=0x1fff; // mask + /*if(Pico.sv.eeprom_type==2) saddr&=0xff; else*/ saddr&=0x1fff; // mask } - else if(SRam.eeprom_type == 2 && scyc == 27) scyc = 18; + else if(Pico.sv.eeprom_type == 2 && scyc == 27) scyc = 18; else if(scyc == 36) scyc = 27; } else { // X24C01 @@ -63,29 +63,29 @@ static void EEPROM_write_do(unsigned int d) // ???? ??la (l=SCL, a=SDA) else if((sreg & 8) && (sreg & 2) && !(d&2)) { // we are started and SCL went low (falling edge) - if(SRam.eeprom_type) { + if(Pico.sv.eeprom_type) { // X24C02+ if(scyc == 9 || scyc == 18 || scyc == 27); // ACK cycles - else if( (SRam.eeprom_type == 3 && scyc > 27) || (SRam.eeprom_type == 2 && scyc > 18) ) { + else if( (Pico.sv.eeprom_type == 3 && scyc > 27) || (Pico.sv.eeprom_type == 2 && scyc > 18) ) { if(!(ssa&1)) { // data write - unsigned char *pm=SRam.data+saddr; + unsigned char *pm=Pico.sv.data+saddr; *pm <<= 1; *pm |= d&1; if(scyc == 26 || scyc == 35) { saddr=(saddr&~0xf)|((saddr+1)&0xf); // only 4 (?) lowest bits are incremented elprintf(EL_EEPROM, "eeprom: write done, addr inc to: %x, last byte=%02x", saddr, *pm); } - SRam.changed = 1; + Pico.sv.changed = 1; } } else if(scyc > 9) { if(!(ssa&1)) { // we latch another addr bit saddr<<=1; - if(SRam.eeprom_type == 2) saddr&=0xff; else saddr&=0x1fff; // mask + if(Pico.sv.eeprom_type == 2) saddr&=0xff; else saddr&=0x1fff; // mask saddr|=d&1; if(scyc==17||scyc==26) { elprintf(EL_EEPROM, "eeprom: addr reg done: %x", saddr); - if(scyc==17&&SRam.eeprom_type==2) { saddr&=0xff; saddr|=(ssa<<7)&0x700; } // add device bits too + if(scyc==17&&Pico.sv.eeprom_type==2) { saddr&=0xff; saddr|=(ssa<<7)&0x700; } // add device bits too } } } else { @@ -99,13 +99,13 @@ static void EEPROM_write_do(unsigned int d) // ???? ??la (l=SCL, a=SDA) else if(scyc > 9) { if(!(saddr&1)) { // data write - unsigned char *pm=SRam.data+(saddr>>1); + unsigned char *pm=Pico.sv.data+(saddr>>1); *pm <<= 1; *pm |= d&1; if(scyc == 17) { saddr=(saddr&0xf9)|((saddr+2)&6); // only 2 lowest bits are incremented elprintf(EL_EEPROM, "eeprom: write done, addr inc to: %x, last byte=%02x", saddr>>1, *pm); } - SRam.changed = 1; + Pico.sv.changed = 1; } } else { // we latch another addr bit @@ -129,11 +129,11 @@ static void EEPROM_upd_pending(unsigned int d) sreg &= ~0xc0; // SCL - d1 = (d >> SRam.eeprom_bit_cl) & 1; + d1 = (d >> Pico.sv.eeprom_bit_cl) & 1; sreg |= d1 << 7; // SDA in - d1 = (d >> SRam.eeprom_bit_in) & 1; + d1 = (d >> Pico.sv.eeprom_bit_in) & 1; sreg |= d1 << 6; Pico.m.eeprom_status = (unsigned char) sreg; @@ -190,23 +190,23 @@ unsigned int EEPROM_read(void) } else if (scyc > 9 && scyc < 18) { // started and first command word received shift = 17-scyc; - if (SRam.eeprom_type) { + if (Pico.sv.eeprom_type) { // X24C02+ if (ssa&1) { elprintf(EL_EEPROM, "eeprom: read: addr %02x, cycle %i, reg %02x", saddr, scyc, sreg); - if (shift==0) elprintf(EL_EEPROM, "eeprom: read done, byte %02x", SRam.data[saddr]); - d = (SRam.data[saddr]>>shift)&1; + if (shift==0) elprintf(EL_EEPROM, "eeprom: read done, byte %02x", Pico.sv.data[saddr]); + d = (Pico.sv.data[saddr]>>shift)&1; } } else { // X24C01 if (saddr&1) { elprintf(EL_EEPROM, "eeprom: read: addr %02x, cycle %i, reg %02x", saddr>>1, scyc, sreg); - if (shift==0) elprintf(EL_EEPROM, "eeprom: read done, byte %02x", SRam.data[saddr>>1]); - d = (SRam.data[saddr>>1]>>shift)&1; + if (shift==0) elprintf(EL_EEPROM, "eeprom: read done, byte %02x", Pico.sv.data[saddr>>1]); + d = (Pico.sv.data[saddr>>1]>>shift)&1; } } } - return (d << SRam.eeprom_bit_out); + return (d << Pico.sv.eeprom_bit_out); } diff --git a/pico/memory.c b/pico/memory.c index 436f545..e747552 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -265,8 +265,8 @@ static port_read_func *port_readers[3] = { static NOINLINE u32 port_read(int i) { - u32 data_reg = Pico.ioports[i + 1]; - u32 ctrl_reg = Pico.ioports[i + 4] | 0x80; + u32 data_reg = PicoMem.ioports[i + 1]; + u32 ctrl_reg = PicoMem.ioports[i + 4] | 0x80; u32 in, out; out = data_reg & ctrl_reg; @@ -310,7 +310,7 @@ NOINLINE u32 io_ports_read(u32 a) case 1: d = port_read(0); break; case 2: d = port_read(1); break; case 3: d = port_read(2); break; - default: d = Pico.ioports[a]; break; // IO ports can be used as RAM + default: d = PicoMem.ioports[a]; break; // IO ports can be used as RAM } return d; } @@ -323,17 +323,17 @@ NOINLINE void io_ports_write(u32 a, u32 d) if (1 <= a && a <= 2) { Pico.m.padDelay[a - 1] = 0; - if (!(Pico.ioports[a] & 0x40) && (d & 0x40)) + if (!(PicoMem.ioports[a] & 0x40) && (d & 0x40)) Pico.m.padTHPhase[a - 1]++; } // certain IO ports can be used as RAM - Pico.ioports[a] = d; + PicoMem.ioports[a] = d; } static int z80_cycles_from_68k(void) { - int m68k_cnt = SekCyclesDone() - timing.m68c_frame_start; + int m68k_cnt = SekCyclesDone() - Pico.t.m68c_frame_start; return cycles_68k_to_z80(m68k_cnt); } @@ -345,7 +345,7 @@ void NOINLINE ctl_write_z80busreq(u32 d) { if (d) { - timing.z80c_cnt = z80_cycles_from_68k() + 2; + Pico.t.z80c_cnt = z80_cycles_from_68k() + 2; } else { @@ -377,7 +377,7 @@ void NOINLINE ctl_write_z80reset(u32 d) } else { - timing.z80c_cnt = z80_cycles_from_68k() + 2; + Pico.t.z80c_cnt = z80_cycles_from_68k() + 2; z80_reset(); } Pico.m.z80_reset = d; @@ -414,14 +414,14 @@ static void psg_write_z80(u32 d) static u32 PicoRead8_sram(u32 a) { u32 d; - if (SRam.start <= a && a <= SRam.end && (Pico.m.sram_reg & SRR_MAPPED)) + if (Pico.sv.start <= a && a <= Pico.sv.end && (Pico.m.sram_reg & SRR_MAPPED)) { - if (SRam.flags & SRF_EEPROM) { + if (Pico.sv.flags & SRF_EEPROM) { d = EEPROM_read(); if (!(a & 1)) d >>= 8; } else - d = *(u8 *)(SRam.data - SRam.start + a); + d = *(u8 *)(Pico.sv.data - Pico.sv.start + a); elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc); return d; } @@ -436,12 +436,12 @@ static u32 PicoRead8_sram(u32 a) static u32 PicoRead16_sram(u32 a) { u32 d; - if (SRam.start <= a && a <= SRam.end && (Pico.m.sram_reg & SRR_MAPPED)) + if (Pico.sv.start <= a && a <= Pico.sv.end && (Pico.m.sram_reg & SRR_MAPPED)) { - if (SRam.flags & SRF_EEPROM) + if (Pico.sv.flags & SRF_EEPROM) d = EEPROM_read(); else { - u8 *pm = (u8 *)(SRam.data - SRam.start + a); + u8 *pm = (u8 *)(Pico.sv.data - Pico.sv.start + a); d = pm[0] << 8; d |= pm[1]; } @@ -459,20 +459,20 @@ static u32 PicoRead16_sram(u32 a) static void PicoWrite8_sram(u32 a, u32 d) { - if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { + if (a > Pico.sv.end || a < Pico.sv.start || !(Pico.m.sram_reg & SRR_MAPPED)) { m68k_unmapped_write8(a, d); return; } elprintf(EL_SRAMIO, "sram w8 [%06x] %02x @ %06x", a, d & 0xff, SekPc); - if (SRam.flags & SRF_EEPROM) + if (Pico.sv.flags & SRF_EEPROM) { EEPROM_write8(a, d); } else { - u8 *pm = (u8 *)(SRam.data - SRam.start + a); + u8 *pm = (u8 *)(Pico.sv.data - Pico.sv.start + a); if (*pm != (u8)d) { - SRam.changed = 1; + Pico.sv.changed = 1; *pm = (u8)d; } } @@ -480,24 +480,24 @@ static void PicoWrite8_sram(u32 a, u32 d) static void PicoWrite16_sram(u32 a, u32 d) { - if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { + if (a > Pico.sv.end || a < Pico.sv.start || !(Pico.m.sram_reg & SRR_MAPPED)) { m68k_unmapped_write16(a, d); return; } elprintf(EL_SRAMIO, "sram w16 [%06x] %04x @ %06x", a, d & 0xffff, SekPc); - if (SRam.flags & SRF_EEPROM) + if (Pico.sv.flags & SRF_EEPROM) { EEPROM_write16(d); } else { - u8 *pm = (u8 *)(SRam.data - SRam.start + a); + u8 *pm = (u8 *)(Pico.sv.data - Pico.sv.start + a); if (pm[0] != (u8)(d >> 8)) { - SRam.changed = 1; + Pico.sv.changed = 1; pm[0] = (u8)(d >> 8); } if (pm[1] != (u8)d) { - SRam.changed = 1; + Pico.sv.changed = 1; pm[1] = (u8)d; } } @@ -515,7 +515,7 @@ static u32 PicoRead8_z80(u32 a) } if ((a & 0x4000) == 0x0000) - d = Pico.zram[a & 0x1fff]; + d = PicoMem.zram[a & 0x1fff]; else if ((a & 0x6000) == 0x4000) // 0x4000-0x5fff d = ym2612_read_local_68k(); else @@ -538,7 +538,7 @@ static void PicoWrite8_z80(u32 a, u32 d) } if ((a & 0x4000) == 0x0000) { // z80 RAM - Pico.zram[a & 0x1fff] = (u8)d; + PicoMem.zram[a & 0x1fff] = (u8)d; return; } if ((a & 0x6000) == 0x4000) { // FM Sound @@ -765,7 +765,7 @@ static void m68k_mem_setup(void); PICO_INTERNAL void PicoMemSetup(void) { - int mask, rs, a; + int mask, rs, sstart, a; // setup the memory map cpu68k_map_set(m68k_read8_map, 0x000000, 0xffffff, m68k_unmapped_read8, 1); @@ -781,15 +781,16 @@ PICO_INTERNAL void PicoMemSetup(void) cpu68k_map_set(m68k_read16_map, 0x000000, rs - 1, Pico.rom, 0); // Common case of on-cart (save) RAM, usually at 0x200000-... - if ((SRam.flags & SRF_ENABLED) && SRam.data != NULL) { - rs = SRam.end - SRam.start; + if ((Pico.sv.flags & SRF_ENABLED) && Pico.sv.data != NULL) { + sstart = Pico.sv.start; + rs = Pico.sv.end - sstart; rs = (rs + mask) & ~mask; - if (SRam.start + rs >= 0x1000000) - rs = 0x1000000 - SRam.start; - cpu68k_map_set(m68k_read8_map, SRam.start, SRam.start + rs - 1, PicoRead8_sram, 1); - cpu68k_map_set(m68k_read16_map, SRam.start, SRam.start + rs - 1, PicoRead16_sram, 1); - cpu68k_map_set(m68k_write8_map, SRam.start, SRam.start + rs - 1, PicoWrite8_sram, 1); - cpu68k_map_set(m68k_write16_map, SRam.start, SRam.start + rs - 1, PicoWrite16_sram, 1); + if (sstart + rs >= 0x1000000) + rs = 0x1000000 - sstart; + cpu68k_map_set(m68k_read8_map, sstart, sstart + rs - 1, PicoRead8_sram, 1); + cpu68k_map_set(m68k_read16_map, sstart, sstart + rs - 1, PicoRead16_sram, 1); + cpu68k_map_set(m68k_write8_map, sstart, sstart + rs - 1, PicoWrite8_sram, 1); + cpu68k_map_set(m68k_write16_map, sstart, sstart + rs - 1, PicoWrite16_sram, 1); } // Z80 region @@ -816,10 +817,10 @@ PICO_INTERNAL void PicoMemSetup(void) // RAM and it's mirrors for (a = 0xe00000; a < 0x1000000; a += 0x010000) { - cpu68k_map_set(m68k_read8_map, a, a + 0xffff, Pico.ram, 0); - cpu68k_map_set(m68k_read16_map, a, a + 0xffff, Pico.ram, 0); - cpu68k_map_set(m68k_write8_map, a, a + 0xffff, Pico.ram, 0); - cpu68k_map_set(m68k_write16_map, a, a + 0xffff, Pico.ram, 0); + cpu68k_map_set(m68k_read8_map, a, a + 0xffff, PicoMem.ram, 0); + cpu68k_map_set(m68k_read16_map, a, a + 0xffff, PicoMem.ram, 0); + cpu68k_map_set(m68k_write8_map, a, a + 0xffff, PicoMem.ram, 0); + cpu68k_map_set(m68k_write16_map, a, a + 0xffff, PicoMem.ram, 0); } // Setup memory callbacks: @@ -896,10 +897,10 @@ static int get_scanline(int is_from_z80) { if (is_from_z80) { int mclk_z80 = z80_cyclesDone() * 15; - int mclk_line = timing.z80_scanline * 488 * 7; + int mclk_line = Pico.t.z80_scanline * 488 * 7; while (mclk_z80 - mclk_line >= 488 * 7) - timing.z80_scanline++, mclk_line += 488 * 7; - return timing.z80_scanline; + Pico.t.z80_scanline++, mclk_line += 488 * 7; + return Pico.t.z80_scanline; } return Pico.m.scanline; @@ -1282,14 +1283,14 @@ static void z80_md_out(unsigned short p, unsigned char d) static void z80_mem_setup(void) { - z80_map_set(z80_read_map, 0x0000, 0x1fff, Pico.zram, 0); - z80_map_set(z80_read_map, 0x2000, 0x3fff, Pico.zram, 0); + z80_map_set(z80_read_map, 0x0000, 0x1fff, PicoMem.zram, 0); + z80_map_set(z80_read_map, 0x2000, 0x3fff, PicoMem.zram, 0); z80_map_set(z80_read_map, 0x4000, 0x5fff, ym2612_read_local_z80, 1); z80_map_set(z80_read_map, 0x6000, 0x7fff, z80_md_vdp_read, 1); z80_map_set(z80_read_map, 0x8000, 0xffff, z80_md_bank_read, 1); - z80_map_set(z80_write_map, 0x0000, 0x1fff, Pico.zram, 0); - z80_map_set(z80_write_map, 0x2000, 0x3fff, Pico.zram, 0); + z80_map_set(z80_write_map, 0x0000, 0x1fff, PicoMem.zram, 0); + z80_map_set(z80_write_map, 0x2000, 0x3fff, PicoMem.zram, 0); z80_map_set(z80_write_map, 0x4000, 0x5fff, z80_md_ym2612_write, 1); z80_map_set(z80_write_map, 0x6000, 0x7fff, z80_md_vdp_br_write, 1); z80_map_set(z80_write_map, 0x8000, 0xffff, z80_md_bank_write, 1); @@ -1299,8 +1300,8 @@ static void z80_mem_setup(void) drZ80.z80_out = z80_md_out; #endif #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (FPTR)Pico.zram); // main RAM - Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (FPTR)Pico.zram); // mirror + Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (FPTR)PicoMem.zram); // main RAM + Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (FPTR)PicoMem.zram); // mirror Cz80_Set_INPort(&CZ80, z80_md_in); Cz80_Set_OUTPort(&CZ80, z80_md_out); #endif diff --git a/pico/memory_amips.s b/pico/memory_amips.S similarity index 93% rename from pico/memory_amips.s rename to pico/memory_amips.S index b11c2e2..7ae2592 100644 --- a/pico/memory_amips.s +++ b/pico/memory_amips.S @@ -8,6 +8,8 @@ # OUT OF DATE +#include "pico_int_o32.h" + .set noreorder .set noat @@ -184,8 +186,8 @@ m_read32_table: PicoMemReset: - lui $v1, %hi(Pico+0x22204) - lw $v1, %lo(Pico+0x22204)($v1) # romsize + lui $v1, %hi(Pico+OFS_Pico_romsize) + lw $v1, %lo(Pico+OFS_Pico_romsize)($v1) # romsize lui $t0, 8 addu $v1, $t0 addiu $v1, -1 @@ -235,12 +237,11 @@ m_read_neg1: jr $ra addiu $v0, $0, 0xffff -# loads &Pico.rom to $t3 +# loads &Pico to $t3 .macro m_read_rom_try_sram is200000 size - lui $t2, %hi(SRam) - addiu $t2, %lo(SRam) - lui $t3, %hi(Pico+0x22200) - lw $t1, 8($t2) # SRam.end + lui $t2, %hi(Pico) + addiu $t2, %lo(Pico) + lw $t1, OFS_Pico_sv_end($t2) .if \is200000 ins $a0, $0, 19, 13 lui $t4, 0x20 @@ -248,12 +249,11 @@ m_read_neg1: .endif subu $t4, $a0, $t1 bgtz $t4, 1f - addiu $t3, %lo(Pico+0x22200) - lw $t1, 4($t2) # SRam.start + lw $t1, OFS_Pico_sv_start($t2) subu $t4, $t1, $a0 bgtz $t4, 1f nop - lb $t1, 0x11($t3) # Pico.m.sram_reg + lb $t1, OFS_Pico_m_sram_reg($t2) andi $t4, $t1, 5 beqz $t4, 1f nop @@ -288,8 +288,8 @@ m_read_neg1: .endm .macro m_read8_rom sect - lui $t0, %hi(Pico+0x22200) - lw $t0, %lo(Pico+0x22200)($t0) # rom + lui $t0, %hi(Pico+OFS_Pico_rom) + lw $t0, %lo(Pico+OFS_Pico_rom)($t0) # rom xori $a0, 1 ins $a0, $0, 19, 13 .if \sect @@ -388,15 +388,15 @@ m_read8_misc_io: nop m_read8_misc_hwreg: - lui $v0, %hi(Pico+0x2220f) + lui $v0, %hi(Pico+OFS_Pico_m_hardware) jr $ra - lb $v0, %lo(Pico+0x2220f)($v0) + lb $v0, %lo(Pico+OFS_Pico_m_hardware)($v0) m_read8_misc_ioports: - lui $v0, %hi(Pico+0x22000) + lui $v0, %hi(PicoMem+0x22000) ins $v0, $t0, 0, 5 jr $ra - lb $v0, %lo(Pico+0x22000)($v0) + lb $v0, %lo(PicoMem+0x22000)($v0) m_read8_misc2: lui $t0, 0xa1 @@ -423,10 +423,10 @@ m_read8_z80_misc: nop m_read8_fake_ym2612: - lb $v0, %lo(Pico+0x22208)($t0) # Pico.m.rotate + lb $v0, %lo(Pico+OFS_Pico_m_rotate)($t0) addiu $t1, $v0, 1 jr $ra - sb $t1, %lo(Pico+0x22208)($t0) + sb $t1, %lo(Pico+OFS_Pico_m_rotate)($t0) # delay slot friendly .macro m_read8_call16 funcname is_func_ptr=0 @@ -472,11 +472,11 @@ m_read8_vdp: nop m_read8_ram: - lui $t0, %hi(Pico) + lui $t0, %hi(PicoMem) ins $t0, $a0, 0, 16 xori $t0, 1 jr $ra - lb $v0, %lo(Pico)($t0) + lb $v0, %lo(PicoMem)($t0) m_read8_above_rom: # might still be SRam (Micro Machines, HardBall '95) @@ -486,8 +486,8 @@ m_read8_above_rom: # ############################################################################# .macro m_read16_rom sect - lui $t0, %hi(Pico+0x22200) - lw $t0, %lo(Pico+0x22200)($t0) # rom + lui $t0, %hi(Pico+OFS_Pico_rom) + lw $t0, %lo(Pico+OFS_Pico_rom)($t0) # rom ins $a0, $0, 0, 1 ins $a0, $0, 19, 13 .if \sect @@ -583,11 +583,11 @@ m_read16_vdp: nop m_read16_ram: - lui $t0, %hi(Pico) + lui $t0, %hi(PicoMem) ins $a0, $0, 0, 1 ins $t0, $a0, 0, 16 jr $ra - lh $v0, %lo(Pico)($t0) + lh $v0, %lo(PicoMem)($t0) m_read16_above_rom: # might still be SRam @@ -600,8 +600,8 @@ m_read16_above_rom: # ############################################################################# .macro m_read32_rom sect - lui $t0, %hi(Pico+0x22200) - lw $t0, %lo(Pico+0x22200)($t0) # rom + lui $t0, %hi(Pico+OFS_Pico_rom) + lw $t0, %lo(Pico+OFS_Pico_rom)($t0) # rom ins $a0, $0, 0, 1 ins $a0, $0, 19, 13 .if \sect @@ -723,11 +723,11 @@ m_read32_vdp: m_read32_call16 PicoVideoRead m_read32_ram: - lui $t0, %hi(Pico) + lui $t0, %hi(PicoMem) ins $a0, $0, 0, 1 ins $t0, $a0, 0, 16 - lh $v1, %lo(Pico)($t0) - lh $v0, %lo(Pico+2)($t0) + lh $v1, %lo(PicoMem)($t0) + lh $v0, %lo(PicoMem+2)($t0) jr $ra ins $v0, $v1, 16, 16 @@ -771,11 +771,11 @@ PicoWriteRomHW_SSF2: # u32 a, u32 d bnez $a0, pwr_banking # sram register - lui $t0, %hi(Pico+0x22211) - lb $t1, %lo(Pico+0x22211)($t0) # Pico.m.sram_reg + lui $t0, %hi(Pico+OFS_Pico_m_sram_reg) + lb $t1, %lo(Pico+OFS_Pico_m_sram_reg)($t0) # Pico.m.sram_reg ins $t1, $a1, 0, 2 jr $ra - sb $t1, %lo(Pico+0x22211)($t0) + sb $t1, %lo(Pico+OFS_Pico_m_sram_reg)($t0) pwr_banking: andi $a1, 0x1f diff --git a/pico/memory_arm.s b/pico/memory_arm.S similarity index 73% rename from pico/memory_arm.s rename to pico/memory_arm.S index f6d7f79..87846d6 100644 --- a/pico/memory_arm.s +++ b/pico/memory_arm.S @@ -6,6 +6,8 @@ * See COPYING file in the top-level directory. */ +#include "pico_int_o32.h" + .equ SRR_MAPPED, (1 << 0) .equ SRR_READONLY, (1 << 1) .equ SRF_EEPROM, (1 << 1) @@ -21,35 +23,32 @@ .global PicoWrite8_io .global PicoWrite16_io -PicoRead8_sram: @ u32 a, u32 d - ldr r2, =(SRam) - ldr r3, =(Pico+0x22200) - ldr r1, [r2, #8] @ SRam.end +PicoRead8_sram: @ u32 a + ldr r3, =Pico + ldr r1, [r3, #OFS_Pico_sv_end] cmp r0, r1 bgt m_read8_nosram - ldr r1, [r2, #4] @ SRam.start - cmp r0, r1 + ldr r2, [r3, #OFS_Pico_sv_start] + cmp r0, r2 blt m_read8_nosram - ldrb r1, [r3, #0x11] @ Pico.m.sram_reg + ldrb r1, [r3, #OFS_Pico_m_sram_reg] tst r1, #SRR_MAPPED beq m_read8_nosram - ldr r1, [r2, #0x0c] + ldr r1, [r3, #OFS_Pico_sv_flags] tst r1, #SRF_EEPROM bne m_read8_eeprom - ldr r1, [r2, #4] @ SRam.start - ldr r2, [r2] @ SRam.data - sub r0, r0, r1 - add r0, r0, r2 - ldrb r0, [r0] + ldr r1, [r3, #OFS_Pico_sv_data] + sub r0, r0, r2 + ldrb r0, [r0, r1] bx lr m_read8_nosram: - ldr r1, [r3, #4] @ romsize + ldr r1, [r3, #OFS_Pico_romsize] cmp r0, r1 movgt r0, #0 bxgt lr @ bad location @ XXX: banking unfriendly - ldr r1, [r3] + ldr r1, [r3, #OFS_Pico_rom] eor r0, r0, #1 ldrb r0, [r1, r0] bx lr @@ -63,7 +62,7 @@ m_read8_eeprom: bx lr -PicoRead8_io: @ u32 a, u32 d +PicoRead8_io: @ u32 a bic r2, r0, #0x001f @ most commonly we get i/o port read, cmp r2, #0xa10000 @ so check for it first beq io_ports_read @@ -73,11 +72,11 @@ m_read8_not_io: cmp r2, #0x1000 bne m_read8_not_brq - ldr r3, =(Pico+0x22200) + ldr r3, =Pico mov r1, r0 - ldr r0, [r3, #8] @ Pico.m.rotate + ldr r0, [r3, #OFS_Pico_m_rotate] add r0, r0, #1 - strb r0, [r3, #8] + strb r0, [r3, #OFS_Pico_m_rotate] eor r0, r0, r0, lsl #6 tst r1, #1 @@ -87,8 +86,8 @@ m_read8_not_io: cmp r2, #0x1100 bxne lr @ not busreq - ldrb r1, [r3, #(8+0x01)] @ Pico.m.z80Run - ldrb r2, [r3, #(8+0x0f)] @ Pico.m.z80_reset + ldrb r1, [r3, #OFS_Pico_m_z80Run] + ldrb r2, [r3, #OFS_Pico_m_z80_reset] orr r0, r0, r1 orr r0, r0, r2 bx lr @@ -104,36 +103,33 @@ m_read8_not_brq: @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ PicoRead16_sram: @ u32 a, u32 d - ldr r2, =(SRam) - ldr r3, =(Pico+0x22200) - ldr r1, [r2, #8] @ SRam.end + ldr r3, =Pico + ldr r1, [r3, #OFS_Pico_sv_end] cmp r0, r1 bgt m_read16_nosram - ldr r1, [r2, #4] @ SRam.start - cmp r0, r1 + ldr r2, [r3, #OFS_Pico_sv_start] + cmp r0, r2 blt m_read16_nosram - ldrb r1, [r3, #0x11] @ Pico.m.sram_reg + ldrb r1, [r3, #OFS_Pico_m_sram_reg] tst r1, #SRR_MAPPED beq m_read16_nosram - ldr r1, [r2, #0x0c] + ldr r1, [r3, #OFS_Pico_sv_flags] tst r1, #SRF_EEPROM bne EEPROM_read - ldr r1, [r2, #4] @ SRam.start - ldr r2, [r2] @ SRam.data - sub r0, r0, r1 - add r0, r0, r2 - ldrb r1, [r0], #1 - ldrb r0, [r0] + ldr r1, [r3, #OFS_Pico_sv_data] + sub r0, r0, r2 + ldrb r1, [r0, r1]! + ldrb r0, [r0, #1] orr r0, r0, r1, lsl #8 bx lr m_read16_nosram: - ldr r1, [r3, #4] @ romsize + ldr r1, [r3, #OFS_Pico_romsize] cmp r0, r1 movgt r0, #0 bxgt lr @ bad location @ XXX: banking unfriendly - ldr r1, [r3] + ldr r1, [r3, #OFS_Pico_rom] ldrh r0, [r1, r0] bx lr @@ -152,19 +148,19 @@ m_read16_not_io: cmp r2, #0x1000 bne m_read16_not_brq - ldr r3, =(Pico+0x22200) + ldr r3, =Pico and r2, r0, #0xff00 - ldr r0, [r3, #8] @ Pico.m.rotate + ldr r0, [r3, #OFS_Pico_m_rotate] add r0, r0, #1 - strb r0, [r3, #8] + strb r0, [r3, #OFS_Pico_m_rotate] eor r0, r0, r0, lsl #5 eor r0, r0, r0, lsl #8 bic r0, r0, #0x100 @ bit8 defined in this area cmp r2, #0x1100 bxne lr @ not busreq - ldrb r1, [r3, #(8+0x01)] @ Pico.m.z80Run - ldrb r2, [r3, #(8+0x0f)] @ Pico.m.z80_reset + ldrb r1, [r3, #OFS_Pico_m_z80Run] + ldrb r2, [r3, #OFS_Pico_m_z80_reset] orr r0, r0, r1, lsl #8 orr r0, r0, r2, lsl #8 bx lr @@ -202,12 +198,12 @@ m_write8_not_z80ctl: eor r2, r2, #0x003000 eors r2, r2, #0x0000f1 bne m_write8_not_sreg - ldr r3, =(Pico+0x22200) - ldrb r2, [r3, #(8+9)] @ Pico.m.sram_reg + ldr r3, =Pico + ldrb r2, [r3, #OFS_Pico_m_sram_reg] and r1, r1, #(SRR_MAPPED|SRR_READONLY) bic r2, r2, #(SRR_MAPPED|SRR_READONLY) orr r2, r2, r1 - strb r2, [r3, #(8+9)] + strb r2, [r3, #OFS_Pico_m_sram_reg] bx lr m_write8_not_sreg: @@ -239,12 +235,12 @@ m_write16_not_z80ctl: eor r2, r2, #0x003000 eors r2, r2, #0x0000f0 bne m_write16_not_sreg - ldr r3, =(Pico+0x22200) - ldrb r2, [r3, #(8+9)] @ Pico.m.sram_reg + ldr r3, =Pico + ldrb r2, [r3, #OFS_Pico_m_sram_reg] and r1, r1, #(SRR_MAPPED|SRR_READONLY) bic r2, r2, #(SRR_MAPPED|SRR_READONLY) orr r2, r2, r1 - strb r2, [r3, #(8+9)] + strb r2, [r3, #OFS_Pico_m_sram_reg] bx lr m_write16_not_sreg: diff --git a/pico/mode4.c b/pico/mode4.c index bda1188..55e6d10 100644 --- a/pico/mode4.c +++ b/pico/mode4.c @@ -31,7 +31,7 @@ static int TileNormM4(int sx, int addr, int pal) unsigned char *pd = Pico.est.HighCol + sx; unsigned int pack, t; - pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */ + pack = *(unsigned int *)(PicoMem.vram + addr); /* Get 4 bitplanes / 8 pixels */ if (pack) { PLANAR_PIXEL(0, 0) @@ -53,7 +53,7 @@ static int TileFlipM4(int sx,int addr,int pal) unsigned char *pd = Pico.est.HighCol + sx; unsigned int pack, t; - pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */ + pack = *(unsigned int *)(PicoMem.vram + addr); /* Get 4 bitplanes / 8 pixels */ if (pack) { PLANAR_PIXEL(0, 7) @@ -83,7 +83,7 @@ static void draw_sprites(int scanline) if (pv->reg[0] & 8) xoff = 0; - sat = (unsigned char *)Pico.vram + ((pv->reg[5] & 0x7e) << 7); + sat = (unsigned char *)PicoMem.vram + ((pv->reg[5] & 0x7e) << 7); if (pv->reg[1] & 2) { addr_mask = 0xfe; h = 16; } else { @@ -161,7 +161,7 @@ static void DrawDisplayM4(int scanline) line -= 224; // Find name table: - nametab = Pico.vram; + nametab = PicoMem.vram; nametab += (pv->reg[2] & 0x0e) << (10-1); nametab += (line>>3) << (6-1); @@ -248,7 +248,7 @@ void PicoLineMode4(int line) void PicoDoHighPal555M4(void) { - unsigned int *spal=(void *)Pico.cram; + unsigned int *spal=(void *)PicoMem.cram; unsigned int *dpal=(void *)Pico.est.HighPal; unsigned int t; int i; diff --git a/pico/pico.c b/pico/pico.c index 0404367..bcd8aa1 100644 --- a/pico/pico.c +++ b/pico/pico.c @@ -11,6 +11,7 @@ #include "sound/ym2612.h" struct Pico Pico; +struct PicoMem PicoMem; int PicoOpt; int PicoSkipFrame; // skip rendering frame? int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU @@ -20,11 +21,8 @@ int PicoQuirks; // game-specific quirks int PicoRegionOverride; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe int PicoAutoRgnOrder; -struct PicoSRAM SRam; int emustatus; // rapid_ym2612, multi_ym_updates -struct PicoTiming timing; - void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware void (*PicoResetHook)(void) = NULL; void (*PicoLineHook)(void) = NULL; @@ -34,11 +32,13 @@ void PicoInit(void) { // Blank space for state: memset(&Pico,0,sizeof(Pico)); + memset(&PicoMem,0,sizeof(PicoMem)); memset(&PicoPad,0,sizeof(PicoPad)); memset(&PicoPadInt,0,sizeof(PicoPadInt)); - Pico.est.Pico_video = &Pico.video; - Pico.est.Pico_vram = Pico.vram; + Pico.est.Pico = &Pico; + Pico.est.PicoMem_vram = PicoMem.vram; + Pico.est.PicoMem_cram = PicoMem.cram; Pico.est.PicoOpt = &PicoOpt; // Init CPUs: @@ -61,18 +61,18 @@ void PicoExit(void) PicoCartUnload(); z80_exit(); - if (SRam.data) - free(SRam.data); + if (Pico.sv.data) + free(Pico.sv.data); pevt_dump(); } void PicoPower(void) { Pico.m.frame_count = 0; - SekCycleCnt = SekCycleAim = 0; + Pico.t.m68c_cnt = Pico.t.m68c_aim = 0; // clear all memory of the emulated machine - memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram); + memset(&PicoMem,0,sizeof(PicoMem)); memset(&Pico.video,0,sizeof(Pico.video)); memset(&Pico.m,0,sizeof(Pico.m)); @@ -81,7 +81,7 @@ void PicoPower(void) z80_reset(); // my MD1 VA6 console has this in IO - Pico.ioports[1] = Pico.ioports[2] = Pico.ioports[3] = 0xff; + PicoMem.ioports[1] = PicoMem.ioports[2] = PicoMem.ioports[3] = 0xff; // default VDP register values (based on Fusion) Pico.video.reg[0] = Pico.video.reg[1] = 0x04; @@ -211,12 +211,12 @@ int PicoReset(void) // reset sram state; enable sram access by default if it doesn't overlap with ROM Pico.m.sram_reg = 0; - if ((SRam.flags & SRF_EEPROM) || Pico.romsize <= SRam.start) + if ((Pico.sv.flags & SRF_EEPROM) || Pico.romsize <= Pico.sv.start) Pico.m.sram_reg |= SRR_MAPPED; - if (SRam.flags & SRF_ENABLED) - elprintf(EL_STATUS, "sram: %06x - %06x; eeprom: %i", SRam.start, SRam.end, - !!(SRam.flags & SRF_EEPROM)); + if (Pico.sv.flags & SRF_ENABLED) + elprintf(EL_STATUS, "sram: %06x - %06x; eeprom: %i", Pico.sv.start, Pico.sv.end, + !!(Pico.sv.flags & SRF_EEPROM)); return 0; } @@ -274,7 +274,7 @@ PICO_INTERNAL int CheckDMA(void) elprintf(EL_VDPDMA, "~Dma %i op=%i can=%i burn=%i [%u]", Pico.m.dma_xfers, dma_op1, xfers_can, burn, SekCyclesDone()); - //dprintf("~aim: %i, cnt: %i", SekCycleAim, SekCycleCnt); + //dprintf("~aim: %i, cnt: %i", Pico.t.m68c_aim, Pico.t.m68c_cnt); return burn; } @@ -286,18 +286,18 @@ PICO_INTERNAL void PicoSyncZ80(unsigned int m68k_cycles_done) int m68k_cnt; int cnt; - m68k_cnt = m68k_cycles_done - timing.m68c_frame_start; - timing.z80c_aim = cycles_68k_to_z80(m68k_cnt); - cnt = timing.z80c_aim - timing.z80c_cnt; + m68k_cnt = m68k_cycles_done - Pico.t.m68c_frame_start; + Pico.t.z80c_aim = cycles_68k_to_z80(m68k_cnt); + cnt = Pico.t.z80c_aim - Pico.t.z80c_cnt; pprof_start(z80); elprintf(EL_BUSREQ, "z80 sync %i (%u|%u -> %u|%u)", cnt, - timing.z80c_cnt, timing.z80c_cnt * 15 / 7 / 488, - timing.z80c_aim, timing.z80c_aim * 15 / 7 / 488); + Pico.t.z80c_cnt, Pico.t.z80c_cnt * 15 / 7 / 488, + Pico.t.z80c_aim, Pico.t.z80c_aim * 15 / 7 / 488); if (cnt > 0) - timing.z80c_cnt += z80_run(cnt); + Pico.t.z80c_cnt += z80_run(cnt); pprof_end(z80); } diff --git a/pico/pico_cmn.c b/pico/pico_cmn.c index 0907b93..a450757 100644 --- a/pico/pico_cmn.c +++ b/pico/pico_cmn.c @@ -21,24 +21,24 @@ SekRunM68k(m68k_cycles) #endif -// sync m68k to SekCycleAim +// sync m68k to Pico.t.m68c_aim static void SekSyncM68k(void) { int cyc_do; pprof_start(m68k); pevt_log_m68k_o(EVT_RUN_START); - while ((cyc_do = SekCycleAim - SekCycleCnt) > 0) { - SekCycleCnt += cyc_do; + while ((cyc_do = Pico.t.m68c_aim - Pico.t.m68c_cnt) > 0) { + Pico.t.m68c_cnt += cyc_do; #if defined(EMU_C68K) PicoCpuCM68k.cycles = cyc_do; CycloneRun(&PicoCpuCM68k); - SekCycleCnt -= PicoCpuCM68k.cycles; + Pico.t.m68c_cnt -= PicoCpuCM68k.cycles; #elif defined(EMU_M68K) - SekCycleCnt += m68k_execute(cyc_do) - cyc_do; + Pico.t.m68c_cnt += m68k_execute(cyc_do) - cyc_do; #elif defined(EMU_F68K) - SekCycleCnt += fm68k_emulate(cyc_do, 0) - cyc_do; + Pico.t.m68c_cnt += fm68k_emulate(cyc_do, 0) - cyc_do; #endif } @@ -51,11 +51,11 @@ static void SekSyncM68k(void) static inline void SekRunM68k(int cyc) { - SekCycleAim += cyc; - cyc = SekCycleAim - SekCycleCnt; + Pico.t.m68c_aim += cyc; + cyc = Pico.t.m68c_aim - Pico.t.m68c_cnt; if (cyc <= 0) return; - SekCycleCnt += cyc >> 6; // refresh slowdowns + Pico.t.m68c_cnt += cyc >> 6; // refresh slowdowns SekSyncM68k(); } @@ -108,7 +108,7 @@ static int PicoFrameHints(void) } else skip=PicoSkipFrame; - timing.m68c_frame_start = SekCyclesDone(); + Pico.t.m68c_frame_start = SekCyclesDone(); pv->v_counter = Pico.m.scanline = 0; z80_resetCycles(); PsndStartFrame(); @@ -170,7 +170,7 @@ static int PicoFrameHints(void) } // Run scanline: - line_base_cycles = SekCyclesDone(); + Pico.t.m68c_line_start = SekCyclesDone(); do_timing_hacks_as(pv, vdp_slots); CPUS_RUN(CYCLES_M68K_LINE); @@ -212,7 +212,7 @@ static int PicoFrameHints(void) // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga) // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants) // also delay between last H-int and V-int (Golden Axe 3) - line_base_cycles = SekCyclesDone(); + Pico.t.m68c_line_start = SekCyclesDone(); do_timing_hacks_vb(); CPUS_RUN(CYCLES_M68K_VINT_LAG); @@ -276,7 +276,7 @@ static int PicoFrameHints(void) } // Run scanline: - line_base_cycles = SekCyclesDone(); + Pico.t.m68c_line_start = SekCyclesDone(); do_timing_hacks_vb(); CPUS_RUN(CYCLES_M68K_LINE); @@ -300,7 +300,7 @@ static int PicoFrameHints(void) } // Run scanline: - line_base_cycles = SekCyclesDone(); + Pico.t.m68c_line_start = SekCyclesDone(); do_timing_hacks_as(pv, vdp_slots); CPUS_RUN(CYCLES_M68K_LINE); diff --git a/pico/pico_int.h b/pico/pico_int.h index 89cccc7..765afaf 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -128,26 +128,18 @@ extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k; #endif #endif // EMU_M68K -// while running, cnt represents target of current timeslice -// while not in SekRun(), it's actual cycles done -// (but always use SekCyclesDone() if you need current position) -// cnt may change if timeslice is ended prematurely or extended, -// so we use SekCycleAim for the actual target -extern unsigned int SekCycleCnt; -extern unsigned int SekCycleAim; - // number of cycles done (can be checked anywhere) -#define SekCyclesDone() (SekCycleCnt - SekCyclesLeft) +#define SekCyclesDone() (Pico.t.m68c_cnt - SekCyclesLeft) // burn cycles while not in SekRun() and while in -#define SekCyclesBurn(c) SekCycleCnt += c +#define SekCyclesBurn(c) Pico.t.m68c_cnt += c #define SekCyclesBurnRun(c) { \ SekCyclesLeft -= c; \ } // note: sometimes may extend timeslice to delay an irq #define SekEndRun(after) { \ - SekCycleCnt -= SekCyclesLeft - (after); \ + Pico.t.m68c_cnt -= SekCyclesLeft - (after); \ SekCyclesLeft = after; \ } @@ -212,10 +204,10 @@ extern struct DrZ80 drZ80; #define Z80_STATE_SIZE 0x60 #define z80_resetCycles() \ - timing.z80c_cnt = timing.z80c_aim = timing.z80_scanline = 0 + Pico.t.z80c_cnt = Pico.t.z80c_aim = Pico.t.z80_scanline = 0 #define z80_cyclesDone() \ - (timing.z80c_aim - z80_cyclesLeft) + (Pico.t.z80c_aim - z80_cyclesLeft) #define cycles_68k_to_z80(x) ((x) * 3823 >> 13) @@ -359,15 +351,16 @@ struct PicoEState void *DrawLineDest; // draw destination unsigned char *HighCol; int *HighPreSpr; - void *Pico_video; - void *Pico_vram; + struct Pico *Pico; + void *PicoMem_vram; + void *PicoMem_cram; int *PicoOpt; unsigned char *Draw2FB; unsigned short HighPal[0x100]; }; -// some assembly stuff depend on these, do not touch! -struct Pico +// some assembly stuff still depends on these, do not touch! +struct PicoMem { unsigned char ram[0x10000]; // 0x00000 scratch ram union { // vram is byteswapped for easier reads when drawing @@ -379,14 +372,6 @@ struct Pico unsigned char pad[0xf0]; // unused unsigned short cram[0x40]; // 0x22100 unsigned short vsram[0x40]; // 0x22180 - - unsigned char *rom; // 0x22200 - unsigned int romsize; // 0x22204 (on 32bits) - - struct PicoMisc m; - struct PicoVideo video; - struct PicoMS ms; - struct PicoEState est; }; // sram @@ -396,7 +381,7 @@ struct Pico #define SRF_ENABLED (1 << 0) #define SRF_EEPROM (1 << 1) -struct PicoSRAM +struct PicoCartSave { unsigned char *data; // actual data unsigned int start; // start address in 68k address space @@ -412,6 +397,38 @@ struct PicoSRAM unsigned int size; }; +struct PicoTiming +{ + // while running, cnt represents target of current timeslice + // while not in SekRun(), it's actual cycles done + // (but always use SekCyclesDone() if you need current position) + // _cnt may change if timeslice is ended prematurely or extended, + // so we use _aim for the actual target + unsigned int m68c_cnt; + unsigned int m68c_aim; + unsigned int m68c_frame_start; // m68k cycles + unsigned int m68c_line_start; + + unsigned int z80c_cnt; // z80 cycles done (this frame) + unsigned int z80c_aim; + int z80_scanline; +}; + +// run tools/mkoffsets pico/pico_int_o32.h if you change these +// careful with savestate compat +struct Pico +{ + struct PicoVideo video; + struct PicoMisc m; + struct PicoTiming t; + struct PicoCartSave sv; + struct PicoEState est; + struct PicoMS ms; + + unsigned char *rom; + unsigned int romsize; +}; + // MCD #define PCM_MIXBUF_LEN ((12500000 / 384) / 50 + 1) @@ -592,15 +609,6 @@ struct Pico32xMem unsigned short pwm_fifo[2][4]; // [0] - current raw, others - fifo entries }; -struct PicoTiming -{ - unsigned int m68c_frame_start; // m68k cycles - unsigned int z80c_cnt; // z80 cycles done (this frame) - unsigned int z80c_aim; - int z80_scanline; -}; -extern struct PicoTiming timing; - // area.c extern void (*PicoLoadStateHook)(void); @@ -699,7 +707,7 @@ void pcd_state_loaded_mem(void); // pico.c extern struct Pico Pico; -extern struct PicoSRAM SRam; +extern struct PicoMem PicoMem; extern int PicoPadInt[2]; extern int emustatus; extern void (*PicoResetHook)(void); @@ -809,7 +817,6 @@ void ym2612_unpack_state(void); // videoport.c -extern int line_base_cycles; PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d); PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a); unsigned char PicoVideoRead8DataH(void); @@ -898,7 +905,7 @@ void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after); void p32x_schedule_hint(SH2 *sh2, int m68k_cycles); // 32x/memory.c -struct Pico32xMem *Pico32xMem; +extern struct Pico32xMem *Pico32xMem; unsigned int PicoRead8_32x(unsigned int a); unsigned int PicoRead16_32x(unsigned int a); void PicoWrite8_32x(unsigned int a, unsigned int d); diff --git a/pico/pico_int_o32.h b/pico/pico_int_o32.h index dc7aaa2..720a5ee 100644 --- a/pico/pico_int_o32.h +++ b/pico/pico_int_o32.h @@ -1,11 +1,26 @@ -/* autogenerated by ./tools/mkoffsets, do not edit */ -#define OFS_DrawScanline 0x00 -#define OFS_rendstatus 0x04 -#define OFS_DrawLineDest 0x08 -#define OFS_HighCol 0x0c -#define OFS_HighPreSpr 0x10 -#define OFS_Pico_video 0x14 -#define OFS_Pico_vram 0x18 -#define OFS_PicoOpt 0x1c -#define OFS_Draw2FB 0x20 -#define OFS_HighPal 0x24 +/* autogenerated by tools/mkoffsets, do not edit */ +#define OFS_Pico_video_reg 0x0000 +#define OFS_Pico_m_rotate 0x0040 +#define OFS_Pico_m_z80Run 0x0041 +#define OFS_Pico_m_dirtyPal 0x0046 +#define OFS_Pico_m_hardware 0x0047 +#define OFS_Pico_m_z80_reset 0x004f +#define OFS_Pico_m_sram_reg 0x0049 +#define OFS_Pico_sv 0x007c +#define OFS_Pico_sv_data 0x007c +#define OFS_Pico_sv_start 0x0080 +#define OFS_Pico_sv_end 0x0084 +#define OFS_Pico_sv_flags 0x0088 +#define OFS_Pico_rom 0x031c +#define OFS_Pico_romsize 0x0320 +#define OFS_EST_DrawScanline 0x00 +#define OFS_EST_rendstatus 0x04 +#define OFS_EST_DrawLineDest 0x08 +#define OFS_EST_HighCol 0x0c +#define OFS_EST_HighPreSpr 0x10 +#define OFS_EST_Pico 0x14 +#define OFS_EST_PicoMem_vram 0x18 +#define OFS_EST_PicoMem_cram 0x1c +#define OFS_EST_PicoOpt 0x20 +#define OFS_EST_Draw2FB 0x24 +#define OFS_EST_HighPal 0x28 diff --git a/pico/sek.c b/pico/sek.c index c91374b..f599d9b 100644 --- a/pico/sek.c +++ b/pico/sek.c @@ -10,11 +10,6 @@ #include "pico_int.h" #include "memory.h" - -unsigned int SekCycleCnt; -unsigned int SekCycleAim; - - /* context */ // Cyclone 68000 #ifdef EMU_C68K @@ -36,8 +31,8 @@ M68K_CONTEXT PicoCpuFM68k; static int SekIntAck(int level) { // try to emulate VDP's reaction to 68000 int ack - if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, SekCycleCnt); } - else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, SekCycleCnt); } + if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); } + else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); } PicoCpuCM68k.irq = 0; return CYCLONE_INT_ACK_AUTOVECTOR; } @@ -76,8 +71,8 @@ static int SekUnrecognizedOpcode() #ifdef EMU_M68K static int SekIntAckM68K(int level) { - if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, SekCycleCnt); } - else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, SekCycleCnt); } + if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); } + else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%u]", SekPc, Pico.t.m68c_cnt); } CPU_INT_LEVEL = 0; return M68K_INT_ACK_AUTOVECTOR; } @@ -168,17 +163,17 @@ PICO_INTERNAL int SekReset(void) void SekStepM68k(void) { - SekCycleAim=SekCycleCnt+1; + Pico.t.m68c_aim = Pico.t.m68c_cnt + 1; #if defined(EMU_CORE_DEBUG) - SekCycleCnt+=CM_compareRun(1, 0); + Pico.t.m68c_cnt += CM_compareRun(1, 0); #elif defined(EMU_C68K) PicoCpuCM68k.cycles=1; CycloneRun(&PicoCpuCM68k); - SekCycleCnt+=1-PicoCpuCM68k.cycles; + Pico.t.m68c_cnt += 1 - PicoCpuCM68k.cycles; #elif defined(EMU_M68K) - SekCycleCnt+=m68k_execute(1); + Pico.t.m68c_cnt += m68k_execute(1); #elif defined(EMU_F68K) - SekCycleCnt+=fm68k_emulate(1, 0); + Pico.t.m68c_cnt += fm68k_emulate(1, 0); #endif } @@ -228,7 +223,7 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub) *(unsigned int *)(cpu+0x40) = pc; *(unsigned int *)(cpu+0x50) = - is_sub ? SekCycleCntS68k : SekCycleCnt; + is_sub ? SekCycleCntS68k : Pico.t.m68c_cnt; } PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) @@ -268,7 +263,7 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) if (is_sub) SekCycleCntS68k = *(unsigned int *)(cpu+0x50); else - SekCycleCnt = *(unsigned int *)(cpu+0x50); + Pico.t.m68c_cnt = *(unsigned int *)(cpu+0x50); } @@ -467,7 +462,7 @@ void SekTrace(int is_s68k) struct ref_68k *x68k = &ref_68ks[is_s68k]; u32 pc = is_s68k ? SekPcS68k : SekPc; u32 sr = is_s68k ? SekSrS68k : SekSr; - u32 cycles = is_s68k ? SekCycleCntS68k : SekCycleCnt; + u32 cycles = is_s68k ? SekCycleCntS68k : Pico.t.m68c_cnt; u32 r; u8 cmd; #ifdef CPU_CMP_W diff --git a/pico/sms.c b/pico/sms.c index 7dc796e..a2351b0 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -23,7 +23,7 @@ static unsigned char vdp_data_read(void) struct PicoVideo *pv = &Pico.video; unsigned char d; - d = Pico.vramb[pv->addr]; + d = PicoMem.vramb[pv->addr]; pv->addr = (pv->addr + 1) & 0x3fff; pv->pending = 0; return d; @@ -44,10 +44,10 @@ static void vdp_data_write(unsigned char d) struct PicoVideo *pv = &Pico.video; if (pv->type == 3) { - Pico.cram[pv->addr & 0x1f] = d; + PicoMem.cram[pv->addr & 0x1f] = d; Pico.m.dirtyPal = 1; } else { - Pico.vramb[pv->addr] = d; + PicoMem.vramb[pv->addr] = d; } pv->addr = (pv->addr + 1) & 0x3fff; @@ -180,7 +180,7 @@ static void xwrite(unsigned int a, unsigned char d) { elprintf(EL_IO, "z80 write [%04x] %02x", a, d); if (a >= 0xc000) - Pico.zram[a & 0x1fff] = d; + PicoMem.zram[a & 0x1fff] = d; if (a >= 0xfff8) write_bank(a, d); } @@ -195,7 +195,7 @@ void PicoPowerMS(void) { int s, tmp; - memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram); + memset(&PicoMem,0,sizeof(PicoMem)); memset(&Pico.video,0,sizeof(Pico.video)); memset(&Pico.m,0,sizeof(Pico.m)); Pico.m.pal = 0; @@ -219,11 +219,11 @@ void PicoPowerMS(void) void PicoMemSetupMS(void) { z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0); - z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0); - z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0); + z80_map_set(z80_read_map, 0xc000, 0xdfff, PicoMem.zram, 0); + z80_map_set(z80_read_map, 0xe000, 0xffff, PicoMem.zram, 0); z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1); - z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0); + z80_map_set(z80_write_map, 0xc000, 0xdfff, PicoMem.zram, 0); z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1); #ifdef _USE_DRZ80 @@ -232,8 +232,8 @@ void PicoMemSetupMS(void) #endif #ifdef _USE_CZ80 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom); - Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram); - Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram); + Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)PicoMem.zram); + Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)PicoMem.zram); Cz80_Set_INPort(&CZ80, z80_sms_in); Cz80_Set_OUTPort(&CZ80, z80_sms_out); #endif diff --git a/pico/state.c b/pico/state.c index fce247a..8a2f2aa 100644 --- a/pico/state.c +++ b/pico/state.c @@ -230,9 +230,9 @@ static int state_save(void *file) memset(buff, 0, sizeof(buff)); SekPackCpu(buff, 0); CHECKED_WRITE_BUFF(CHUNK_M68K, buff); - CHECKED_WRITE_BUFF(CHUNK_RAM, Pico.ram); - CHECKED_WRITE_BUFF(CHUNK_VSRAM, Pico.vsram); - CHECKED_WRITE_BUFF(CHUNK_IOPORTS, Pico.ioports); + CHECKED_WRITE_BUFF(CHUNK_RAM, PicoMem.ram); + CHECKED_WRITE_BUFF(CHUNK_VSRAM, PicoMem.vsram); + CHECKED_WRITE_BUFF(CHUNK_IOPORTS, PicoMem.ioports); ym2612_pack_state(); CHECKED_WRITE(CHUNK_FM, 0x200+4, ym2612_regs); } @@ -240,9 +240,9 @@ static int state_save(void *file) CHECKED_WRITE_BUFF(CHUNK_SMS, Pico.ms); } - CHECKED_WRITE_BUFF(CHUNK_VRAM, Pico.vram); - CHECKED_WRITE_BUFF(CHUNK_ZRAM, Pico.zram); - CHECKED_WRITE_BUFF(CHUNK_CRAM, Pico.cram); + CHECKED_WRITE_BUFF(CHUNK_VRAM, PicoMem.vram); + CHECKED_WRITE_BUFF(CHUNK_ZRAM, PicoMem.zram); + CHECKED_WRITE_BUFF(CHUNK_CRAM, PicoMem.cram); CHECKED_WRITE_BUFF(CHUNK_MISC, Pico.m); CHECKED_WRITE_BUFF(CHUNK_VIDEO, Pico.video); @@ -421,14 +421,14 @@ static int state_load(void *file) CHECKED_READ_BUFF(buff_z80); break; - case CHUNK_RAM: CHECKED_READ_BUFF(Pico.ram); break; - case CHUNK_VRAM: CHECKED_READ_BUFF(Pico.vram); break; - case CHUNK_ZRAM: CHECKED_READ_BUFF(Pico.zram); break; - case CHUNK_CRAM: CHECKED_READ_BUFF(Pico.cram); break; - case CHUNK_VSRAM: CHECKED_READ_BUFF(Pico.vsram); break; + case CHUNK_RAM: CHECKED_READ_BUFF(PicoMem.ram); break; + case CHUNK_VRAM: CHECKED_READ_BUFF(PicoMem.vram); break; + case CHUNK_ZRAM: CHECKED_READ_BUFF(PicoMem.zram); break; + case CHUNK_CRAM: CHECKED_READ_BUFF(PicoMem.cram); break; + case CHUNK_VSRAM: CHECKED_READ_BUFF(PicoMem.vsram); break; case CHUNK_MISC: CHECKED_READ_BUFF(Pico.m); break; case CHUNK_VIDEO: CHECKED_READ_BUFF(Pico.video); break; - case CHUNK_IOPORTS: CHECKED_READ_BUFF(Pico.ioports); break; + case CHUNK_IOPORTS: CHECKED_READ_BUFF(PicoMem.ioports); break; case CHUNK_PSG: CHECKED_READ2(28*4, sn76496_regs); break; case CHUNK_FM: ym2612_regs = YM2612GetRegs(); @@ -553,7 +553,7 @@ readend: z80_unpack(buff_z80); // due to dep from 68k cycles.. - SekCycleAim = SekCycleCnt; + Pico.t.m68c_aim = Pico.t.m68c_cnt; if (PicoAHW & PAHW_32X) Pico32xStateLoaded(0); if (PicoAHW & PAHW_MCD) @@ -596,9 +596,9 @@ static int state_load_gfx(void *file) switch (buff[0]) { - case CHUNK_VRAM: CHECKED_READ_BUFF(Pico.vram); found++; break; - case CHUNK_CRAM: CHECKED_READ_BUFF(Pico.cram); found++; break; - case CHUNK_VSRAM: CHECKED_READ_BUFF(Pico.vsram); found++; break; + case CHUNK_VRAM: CHECKED_READ_BUFF(PicoMem.vram); found++; break; + case CHUNK_CRAM: CHECKED_READ_BUFF(PicoMem.cram); found++; break; + case CHUNK_VSRAM: CHECKED_READ_BUFF(PicoMem.vsram); found++; break; case CHUNK_VIDEO: CHECKED_READ_BUFF(Pico.video); found++; break; #ifndef NO_32X @@ -679,10 +679,10 @@ int PicoStateLoadGfx(const char *fname) if (ret != 0) { // assume legacy areaSeek(afile, 0x10020, SEEK_SET); // skip header and RAM - areaRead(Pico.vram, 1, sizeof(Pico.vram), afile); + areaRead(PicoMem.vram, 1, sizeof(PicoMem.vram), afile); areaSeek(afile, 0x2000, SEEK_CUR); - areaRead(Pico.cram, 1, sizeof(Pico.cram), afile); - areaRead(Pico.vsram, 1, sizeof(Pico.vsram), afile); + areaRead(PicoMem.cram, 1, sizeof(PicoMem.cram), afile); + areaRead(PicoMem.vsram, 1, sizeof(PicoMem.vsram), afile); areaSeek(afile, 0x221a0, SEEK_SET); areaRead(&Pico.video, 1, sizeof(Pico.video), afile); } @@ -715,9 +715,9 @@ void *PicoTmpStateSave(void) if (t == NULL) return NULL; - memcpy(t->vram, Pico.vram, sizeof(Pico.vram)); - memcpy(t->cram, Pico.cram, sizeof(Pico.cram)); - memcpy(t->vsram, Pico.vsram, sizeof(Pico.vsram)); + memcpy(t->vram, PicoMem.vram, sizeof(PicoMem.vram)); + memcpy(t->cram, PicoMem.cram, sizeof(PicoMem.cram)); + memcpy(t->vsram, PicoMem.vsram, sizeof(PicoMem.vsram)); memcpy(&t->video, &Pico.video, sizeof(Pico.video)); #ifndef NO_32X @@ -737,9 +737,9 @@ void PicoTmpStateRestore(void *data) if (t == NULL) return; - memcpy(Pico.vram, t->vram, sizeof(Pico.vram)); - memcpy(Pico.cram, t->cram, sizeof(Pico.cram)); - memcpy(Pico.vsram, t->vsram, sizeof(Pico.vsram)); + memcpy(PicoMem.vram, t->vram, sizeof(PicoMem.vram)); + memcpy(PicoMem.cram, t->cram, sizeof(PicoMem.cram)); + memcpy(PicoMem.vsram, t->vsram, sizeof(PicoMem.vsram)); memcpy(&Pico.video, &t->video, sizeof(Pico.video)); Pico.m.dirtyPal = 1; diff --git a/pico/videoport.c b/pico/videoport.c index 4da3ce3..072a941 100644 --- a/pico/videoport.c +++ b/pico/videoport.c @@ -11,7 +11,6 @@ #define NEED_DMA_SOURCE #include "memory.h" -int line_base_cycles; extern const unsigned char hcounts_32[]; extern const unsigned char hcounts_40[]; @@ -33,23 +32,24 @@ static NOINLINE void VideoWrite128(u32 a, u16 d) { // nasty a = ((a & 2) >> 1) | ((a & 0x400) >> 9) | (a & 0x3FC) | ((a & 0x1F800) >> 1); - ((u8 *)Pico.vram)[a] = d; + ((u8 *)PicoMem.vram)[a] = d; } static void VideoWrite(u16 d) { - unsigned int a=Pico.video.addr; + unsigned int a = Pico.video.addr; switch (Pico.video.type) { - case 1: if(a&1) d=(u16)((d<<8)|(d>>8)); // If address is odd, bytes are swapped (which game needs this?) - Pico.vram [(a>>1)&0x7fff]=d; + case 1: if (a & 1) + d = (u16)((d << 8) | (d >> 8)); + PicoMem.vram [(a >> 1) & 0x7fff] = d; if (a - ((unsigned)(Pico.video.reg[5]&0x7f) << 9) < 0x400) Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES; break; case 3: Pico.m.dirtyPal = 1; - Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike) - case 5: Pico.vsram[(a>>1)&0x003f]=d; break; + PicoMem.cram [(a >> 1) & 0x3f] = d; break; + case 5: PicoMem.vsram[(a >> 1) & 0x3f] = d; break; case 0x81: a |= Pico.video.addr_u << 16; VideoWrite128(a, d); @@ -68,9 +68,9 @@ static unsigned int VideoRead(void) switch (Pico.video.type) { - case 0: d=Pico.vram [a&0x7fff]; break; - case 8: d=Pico.cram [a&0x003f]; break; - case 4: d=Pico.vsram[a&0x003f]; break; + case 0: d=PicoMem.vram [a & 0x7fff]; break; + case 8: d=PicoMem.cram [a & 0x003f]; break; + case 4: d=PicoMem.vsram[a & 0x003f]; break; default:elprintf(EL_ANOMALY, "VDP read with bad type %i", Pico.video.type); break; } @@ -106,7 +106,7 @@ static void DmaSlow(int len, unsigned int source) SekCyclesBurnRun(CheckDMA()); if ((source & 0xe00000) == 0xe00000) { // Ram - base = (u16 *)Pico.ram; + base = (u16 *)PicoMem.ram; mask = 0xffff; } else if (PicoAHW & PAHW_MCD) @@ -154,7 +154,7 @@ static void DmaSlow(int len, unsigned int source) switch (Pico.video.type) { case 1: // vram - r = Pico.vram; + r = PicoMem.vram; if (inc == 2 && !(a & 1) && a + len * 2 < 0x10000 && !(((source + len - 1) ^ source) & ~mask)) { @@ -178,7 +178,7 @@ static void DmaSlow(int len, unsigned int source) case 3: // cram Pico.m.dirtyPal = 1; - r = Pico.cram; + r = PicoMem.cram; for (; len; len--) { r[(a / 2) & 0x3f] = base[source++ & mask]; @@ -188,7 +188,7 @@ static void DmaSlow(int len, unsigned int source) break; case 5: // vsram - r = Pico.vsram; + r = PicoMem.vsram; for (; len; len--) { r[(a / 2) & 0x3f] = base[source++ & mask]; @@ -219,9 +219,9 @@ static void DmaSlow(int len, unsigned int source) static void DmaCopy(int len) { - u16 a=Pico.video.addr; - unsigned char *vr = (unsigned char *) Pico.vram; - unsigned char inc=Pico.video.reg[0xf]; + u16 a = Pico.video.addr; + u8 *vr = (u8 *)PicoMem.vram; + u8 inc = Pico.video.reg[0xf]; int source; elprintf(EL_VDPDMA, "DmaCopy len %i [%u]", len, SekCyclesDone()); @@ -246,10 +246,10 @@ static void DmaCopy(int len) static NOINLINE void DmaFill(int data) { - unsigned short a=Pico.video.addr; - unsigned char *vr=(unsigned char *) Pico.vram; - unsigned char high = (unsigned char) (data >> 8); - unsigned char inc=Pico.video.reg[0xf]; + u16 a = Pico.video.addr; + u8 *vr = (u8 *)PicoMem.vram; + u8 high = (u8)(data >> 8); + u8 inc = Pico.video.reg[0xf]; int source; int len, l; @@ -367,7 +367,7 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d) // try avoiding the sync.. if (Pico.m.scanline < 224 && (pvid->reg[1]&0x40) && !(!pvid->pending && - ((pvid->command & 0xc00000f0) == 0x40000010 && Pico.vsram[pvid->addr>>1] == d)) + ((pvid->command & 0xc00000f0) == 0x40000010 && PicoMem.vsram[pvid->addr>>1] == d)) ) DrawSync(0); @@ -421,7 +421,7 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d) return; } - if (num == 1 && !(d&0x40) && SekCyclesDone() - line_base_cycles <= 488-390) + if (num == 1 && !(d&0x40) && SekCyclesDone() - Pico.t.m68c_line_start <= 488-390) blank_on = 1; DrawSync(blank_on); pvid->reg[num]=(unsigned char)d; @@ -512,7 +512,7 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) unsigned int d; d=pv->status; //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast) - if (SekCyclesDone() - line_base_cycles >= 488-88) + if (SekCyclesDone() - Pico.t.m68c_line_start >= 488-88) d|=0x0004; // H-Blank (Sonic3 vs) d |= ((pv->reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled @@ -544,7 +544,7 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) { unsigned int d; - d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME + d = (SekCyclesDone() - Pico.t.m68c_line_start) & 0x1ff; // FIXME if (Pico.video.reg[12]&1) d = hcounts_40[d]; else d = hcounts_32[d]; @@ -588,7 +588,7 @@ unsigned char PicoVideoRead8CtlL(void) //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast) d |= ((Pico.video.reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled d |= (Pico.video.pending_ints&0x20)<<2; // V-int pending? - if (SekCyclesDone() - line_base_cycles >= 488-88) d |= 4; // H-Blank + if (SekCyclesDone() - Pico.t.m68c_line_start >= 488-88) d |= 4; // H-Blank Pico.video.pending = 0; elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc); return d; @@ -603,7 +603,7 @@ unsigned char PicoVideoRead8HV_H(void) // FIXME: broken unsigned char PicoVideoRead8HV_L(void) { - u32 d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME + u32 d = (SekCyclesDone() - Pico.t.m68c_line_start) & 0x1ff; // FIXME if (Pico.video.reg[12]&1) d = hcounts_40[d]; else d = hcounts_32[d]; diff --git a/platform/common/common.mak b/platform/common/common.mak index 32b7a64..cd92f54 100644 --- a/platform/common/common.mak +++ b/platform/common/common.mak @@ -49,7 +49,7 @@ SRCS_COMMON += $(R)pico/draw_arm.S $(R)pico/draw2_arm.S endif ifeq "$(asm_memory)" "1" DEFINES += _ASM_MEMORY_C -SRCS_COMMON += $(R)pico/memory_arm.s +SRCS_COMMON += $(R)pico/memory_arm.S endif ifeq "$(asm_ym2612)" "1" DEFINES += _ASM_YM2612_C @@ -62,7 +62,7 @@ SRCS_COMMON += $(R)pico/cd/misc_arm.s endif ifeq "$(asm_cdmemory)" "1" DEFINES += _ASM_CD_MEMORY_C -SRCS_COMMON += $(R)pico/cd/memory_arm.s +SRCS_COMMON += $(R)pico/cd/memory_arm.S endif ifeq "$(asm_32xdraw)" "1" DEFINES += _ASM_32X_DRAW diff --git a/platform/common/emu.c b/platform/common/emu.c index 6a8c940..9535bfd 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -889,7 +889,7 @@ int emu_save_load_game(int load, int sram) { if (PicoOpt & POPT_EN_MCD_RAMCART) { sram_size = 0x12000; - sram_data = SRam.data; + sram_data = Pico.sv.data; if (sram_data) memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4); } else { @@ -898,11 +898,11 @@ int emu_save_load_game(int load, int sram) truncate = 0; // the .brm may contain RAM cart data after normal brm } } else { - sram_size = SRam.size; - sram_data = SRam.data; + sram_size = Pico.sv.size; + sram_data = Pico.sv.data; } if (sram_data == NULL) - return 0; // SRam forcefully disabled for this game + return 0; // cart saves forcefully disabled for this game if (load) { @@ -1262,9 +1262,9 @@ void emu_init(void) void emu_finish(void) { // save SRAM - if ((currentConfig.EmuOpt & EOPT_EN_SRAM) && SRam.changed) { + if ((currentConfig.EmuOpt & EOPT_EN_SRAM) && Pico.sv.changed) { emu_save_load_game(0, 1); - SRam.changed = 0; + Pico.sv.changed = 0; } if (!(currentConfig.EmuOpt & EOPT_NO_AUTOSVCFG)) { @@ -1514,10 +1514,10 @@ void emu_loop(void) emu_set_fastforward(0); // save SRAM - if ((currentConfig.EmuOpt & EOPT_EN_SRAM) && SRam.changed) { + if ((currentConfig.EmuOpt & EOPT_EN_SRAM) && Pico.sv.changed) { plat_status_msg_busy_first("Writing SRAM/BRAM..."); emu_save_load_game(0, 1); - SRam.changed = 0; + Pico.sv.changed = 0; } pemu_loop_end(); diff --git a/tools/mkoffsets.c b/tools/mkoffsets.c index a5c475f..b371cf4 100644 --- a/tools/mkoffsets.c +++ b/tools/mkoffsets.c @@ -3,10 +3,22 @@ #include "../pico/pico_int.h" -#define DUMP(f, field) \ +#define DUMP(f, prefix, type, field) \ fprintf(f, "#define %-20s 0x%02x\n", \ - "OFS_" #field, \ - (int)offsetof(struct PicoEState, field)) + prefix #field, (int)offsetof(type, field)) + +#define DUMP_P(f, field) \ + fprintf(f, "#define %-20s 0x%04x\n", \ + "OFS_Pico_" #field, (char *)&p.field - (char *)&p) + +#define DUMP_PS(f, s1, field) \ + fprintf(f, "#define %-20s 0x%04x\n", \ + "OFS_Pico_" #s1 "_" #field, (char *)&p.s1.field - (char *)&p) + +#define DUMP_EST(f, field) \ + DUMP(f, "OFS_EST_", struct PicoEState, field) + +extern struct Pico p; int main(int argc, char *argv[]) { @@ -21,16 +33,31 @@ int main(int argc, char *argv[]) } fprintf(f, "/* autogenerated by %s, do not edit */\n", argv[0]); - DUMP(f, DrawScanline); - DUMP(f, rendstatus); - DUMP(f, DrawLineDest); - DUMP(f, HighCol); - DUMP(f, HighPreSpr); - DUMP(f, Pico_video); - DUMP(f, Pico_vram); - DUMP(f, PicoOpt); - DUMP(f, Draw2FB); - DUMP(f, HighPal); + DUMP_PS(f, video, reg); + DUMP_PS(f, m, rotate); + DUMP_PS(f, m, z80Run); + DUMP_PS(f, m, dirtyPal); + DUMP_PS(f, m, hardware); + DUMP_PS(f, m, z80_reset); + DUMP_PS(f, m, sram_reg); + DUMP_P (f, sv); + DUMP_PS(f, sv, data); + DUMP_PS(f, sv, start); + DUMP_PS(f, sv, end); + DUMP_PS(f, sv, flags); + DUMP_P (f, rom); + DUMP_P (f, romsize); + DUMP_EST(f, DrawScanline); + DUMP_EST(f, rendstatus); + DUMP_EST(f, DrawLineDest); + DUMP_EST(f, HighCol); + DUMP_EST(f, HighPreSpr); + DUMP_EST(f, Pico); + DUMP_EST(f, PicoMem_vram); + DUMP_EST(f, PicoMem_cram); + DUMP_EST(f, PicoOpt); + DUMP_EST(f, Draw2FB); + DUMP_EST(f, HighPal); fclose(f); return 0; -- 2.39.2