From 234c45567cc77a4eca9cddca7daaacab27cab767 Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 22 Jun 2023 21:05:33 +0300 Subject: [PATCH] testpico: adjust for irixxxx's PD, 32x disable --- testpico/Makefile | 18 ++++++++---- testpico/asmtools.S | 17 +++++++++++- testpico/asmtools.h | 2 ++ testpico/main.c | 67 +++++++++++++++++++++++++++++++-------------- testpico/sega_gcc.s | 2 +- 5 files changed, 77 insertions(+), 29 deletions(-) diff --git a/testpico/Makefile b/testpico/Makefile index 67e4a84..b8c7988 100644 --- a/testpico/Makefile +++ b/testpico/Makefile @@ -13,19 +13,25 @@ OBJCOPY_SH = $(CROSS_SH)objcopy ASFLAGS += -m68000 --register-prefix-optional --bitwise-or -pic ASFLAGS_CC += -Wa,-m68000 -Wa,--register-prefix-optional -Wa,--bitwise-or -Wa,-pic CFLAGS += -Wall -g -O2 -m68000 -fomit-frame-pointer -#CFLAGS += -DPICO -LDLIBS += $(shell $(CC) -print-file-name=libgcc.a) - -TARGET = testpico +LDLIBS_LIBGCC := $(shell $(CC) -print-file-name=libgcc.a) +LDLIBS += $(LDLIBS_LIBGCC) + +SUFFIX := $(shell git describe --always --dirty) +ifdef PICO +CFLAGS += -DPICO +SUFFIX := $(SUFFIX)-for-pd +endif +TARGET_BASE = testpico +TARGET = $(TARGET_BASE)-$(SUFFIX) OBJS = sega_gcc.o main.o asmtools.o all: $(TARGET).bin $(TARGET).elf: $(OBJS) - $(LD) -o $@ -Tsega.ld -Map $(TARGET).map $^ $(LDLIBS) + $(LD) -o $@ -Tsega.ld -Map $(TARGET_BASE).map $^ $(LDLIBS) clean: - $(RM) $(TARGET).bin $(OBJS) *.elf *.map fill + $(RM) $(TARGET_BASE)*.bin $(OBJS) *.elf *.map fill $(RM) *.lst *.bin80 *.osh *.binsh $(TARGET).bin: $(TARGET).elf fill diff --git a/testpico/asmtools.S b/testpico/asmtools.S index d216a83..811f35d 100644 --- a/testpico/asmtools.S +++ b/testpico/asmtools.S @@ -73,6 +73,8 @@ write_and_read1: #ifndef PICO move.w d0, (a0) #else + /* different timing due to extra fetch of offset, */ + /* less troulesome to emulate */ movea.l a0, a1 subq.l #1, a1 move.w d0, 1(a1) @@ -249,12 +251,25 @@ x32x_enable: .global x32x_enable_end x32x_enable_end: +.global x32x_disable +x32x_disable: + movea.l #0xa15100, a0 + move.w #1, (a0) /* ADEN (reset sh2) */ + move.w #0, (a0) /* adapter disable, reset sh2 */ + move.w #1, d0 +0: + dbra d0, 0b + move.w #2, (a0) /* nRES - sh2s should see no ADEN and sleep */ + rts +.global x32x_disable_end +x32x_disable_end: + .global test_32x_b_c0 test_32x_b_c0: ldarg 0, 0, a1 ldargw 1, 0, d0 jsr (0xc0).l /* move.b d0, (a1); RV=0 */ - bset #0, (0xa15107).l + bset #0, (0xa15107).l /* RV=1 */ rts .global test_32x_b_c0_end test_32x_b_c0_end: diff --git a/testpico/asmtools.h b/testpico/asmtools.h index ffc48a8..63974f8 100644 --- a/testpico/asmtools.h +++ b/testpico/asmtools.h @@ -33,5 +33,7 @@ extern const char test_f_vint[]; extern const char test_f_vint_end[]; extern const char x32x_enable[]; extern const char x32x_enable_end[]; +extern const char x32x_disable[]; +extern const char x32x_disable_end[]; extern const char test_32x_b_c0[]; extern const char test_32x_b_c0_end[]; diff --git a/testpico/main.c b/testpico/main.c index 892319c..4202748 100644 --- a/testpico/main.c +++ b/testpico/main.c @@ -312,6 +312,7 @@ struct exc_frame { void exception(const struct exc_frame *f) { + u32 *sp, sp_add; int i; while (read16(VDP_CTRL_PORT) & 2) @@ -332,16 +333,21 @@ void exception(const struct exc_frame *f) printf(" \n"); if (f->ecxnum < 4) { - printf(" PC: %08x SR: %04x \n", f->bae.pc, f->bae.sr); + printf(" PC: %08x SR: %04x \n", f->bae.pc, f->bae.sr); printf("addr: %08x IR: %04x FC: %02x \n", f->bae.addr, f->bae.ir, f->bae.fc); + sp_add = 14; } else { - printf(" PC: %08x SR: %04x \n", f->g.pc, f->g.sr); + printf(" PC: %08x SR: %04x \n", f->g.pc, f->g.sr); + sp_add = 6; } for (i = 0; i < 8; i++) printf(" D%d: %08x A%d: %08x \n", i, f->dr[i], i, f->ar[i]); - printf(" \n"); + printf(" \n"); + sp = (u32 *)(f->ar[7] + sp_add); + printf(" %08x %08x %08x %08x\n", sp[0], sp[1], sp[2], sp[3]); + printf(" %08x %08x %08x %08x\n", sp[4], sp[5], sp[6], sp[7]); } // --- @@ -1096,11 +1102,7 @@ static int t_tim_z80_vdp(void) z80_read_loop(zram, 0x7f08); expect(ok, zram[0x1000], 0); -#ifndef PICO expect_range(ok, zram[0x1100], 0x91, 0x91); -#else - expect_range(ok, zram[0x1100], 0x8e, 0x91); -#endif return ok; } @@ -1115,11 +1117,7 @@ static int t_tim_z80_bank_rom(void) z80_read_loop(zram, 0x8000); expect(ok, zram[0x1000], 0); -#ifndef PICO expect_range(ok, zram[0x1100], 0x95, 0x96); -#else - expect_range(ok, zram[0x1100], 0x93, 0x96); -#endif return ok; } @@ -1219,9 +1217,7 @@ static int t_tim_hblank_h32(void) test_hb(); VDP_setReg(VDP_MODE4, 0x81); -#ifndef PICO expect_bits(ok, r[0], 0, SR_HB); -#endif // set: 1-4 expect_bits(ok, r[4], SR_HB, SR_HB); expect_bits(ok, r[5], SR_HB, SR_HB); @@ -1260,11 +1256,7 @@ static int t_tim_vdp_as_cram_w(void) setup_default_palette(); -#ifndef PICO expect(ok, vcnt, 112); -#else - expect_range(ok, vcnt, 111, 112); -#endif return ok; } @@ -1664,6 +1656,8 @@ static int t_32x_md_bios(void) expect(ok, rmb[0], 0x5a); expect(ok, rl[0x04/4], 0x880200); + expect(ok, rl[0x10/4], 0x880212); + expect(ok, rl[0x94/4], 0x8802d8); return ok; } @@ -1735,6 +1729,35 @@ static int t_32x_sh_fb(void) return ok; } +static int t_32x_disable(void) +{ + void (*do_32x_disable)(void) = (void *)0xff0040; + u32 *r = (u32 *)0xa15100; + u16 *r16 = (u16 *)r; + u32 *rl = (u32 *)0; + int ok = 1; + + expect(ok, r16[0x00/2], 0x83); + + memcpy_(do_32x_disable, x32x_disable, + x32x_disable_end - x32x_disable); + do_32x_disable(); + + expect(ok, r16[0x00/2], 0x82); + expect(ok, r16[0x02/2], 0); + expect(ok, r16[0x04/2], 0); + expect(ok, r16[0x06/2], 1); // RV + expect(ok, r[0x14/4], 0); + expect(ok, r[0x18/4], 0); + expect(ok, r[0x1c/4], 0); + expect(ok, rl[0x04/4], 0x000800); + + write16(&r16[0x06/2], 0); // can just set without ADEN + mem_barrier(); + expect(ok, r16[0x06/2], 0); // RV + return ok; +} + enum { T_MD = 0, T_32 = 1, // 32X @@ -1755,9 +1778,7 @@ static const struct { { T_MD, t_dma_short_cmd, "dma short cmd" }, { T_MD, t_dma_fill3_odd, "dma fill3 odd" }, { T_MD, t_dma_fill3_even, "dma fill3 even" }, -#ifndef PICO // later { T_MD, t_dma_fill3_vsram, "dma fill3 vsram" }, -#endif { T_MD, t_dma_fill_dis, "dma fill disabled" }, { T_MD, t_dma_fill_src, "dma fill src incr" }, { T_MD, t_dma_128k, "dma 128k mode" }, @@ -1796,6 +1817,7 @@ static const struct { { T_32, t_32x_md_rom, "32x md rom" }, { T_32, t_32x_md_fb, "32x md fb" }, { T_32, t_32x_sh_fb, "32x sh fb" }, + { T_32, t_32x_disable, "32x disable" }, // must be last 32x }; static void setup_z80(void) @@ -1855,6 +1877,7 @@ int main() int passed = 0; int skipped = 0; int have_32x; + int en_32x; int ret; u8 v8; int i; @@ -1921,11 +1944,13 @@ int main() VDP_setReg(VDP_MODE2, VDP_MODE2_MD | VDP_MODE2_DMA | VDP_MODE2_DISP); have_32x = read32(0xa130ec) == MKLONG('M','A','R','S'); + en_32x = have_32x && (read32(0xa15100) & 1); v8 = read8(0xa10001); - printf("MD version: %02x %s %s %s\n", v8, + printf("MD version: %02x %s %s %s%s\n", v8, (v8 & 0x80) ? "world" : "jap", (v8 & 0x40) ? "pal" : "ntsc", - have_32x ? "32X" : ""); + have_32x ? "32X" : "", + en_32x ? "+" : ""); for (i = 0; i < ARRAY_SIZE(g_tests); i++) { // print test number if we haven't scrolled away diff --git a/testpico/sega_gcc.s b/testpico/sega_gcc.s index efe0a00..d4fdc58 100644 --- a/testpico/sega_gcc.s +++ b/testpico/sega_gcc.s @@ -144,7 +144,7 @@ pre_exception: movem.l %d0-%d7/%a0-%a7,-(%sp) add.w #2, 0x3e(%sp) move.l %sp, %d0 - move.l %d0,-(%sp) + move.l %d0,-(%sp) /* arg0 */ jsr exception 0: bra 0b -- 2.39.5