From 3ee911dcf68d53ea0febcb256b34e7848b7c2bf0 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 10 Sep 2017 00:43:09 +0300 Subject: [PATCH] sramtest: new test note to self: EDv9 exposes 16bit RAM, but even byte writes don't work --- megaed-stop-md/main.c | 2 +- megaed-stop/main.c | 2 +- sramtest/Makefile | 33 +++ sramtest/UNLICENSE | 24 ++ sramtest/asmtools.h | 4 + sramtest/asmtools.s | 97 ++++++++ sramtest/data.s | 10 + sramtest/font.bin | Bin 0 -> 3936 bytes sramtest/main.c | 545 ++++++++++++++++++++++++++++++++++++++++++ sramtest/sega.ld | 117 +++++++++ sramtest/sega_gcc.s | 128 ++++++++++ 11 files changed, 960 insertions(+), 2 deletions(-) create mode 100644 sramtest/Makefile create mode 100644 sramtest/UNLICENSE create mode 100644 sramtest/asmtools.h create mode 100644 sramtest/asmtools.s create mode 100644 sramtest/data.s create mode 100644 sramtest/font.bin create mode 100644 sramtest/main.c create mode 100644 sramtest/sega.ld create mode 100644 sramtest/sega_gcc.s diff --git a/megaed-stop-md/main.c b/megaed-stop-md/main.c index 618f3b5..fa7dc85 100644 --- a/megaed-stop-md/main.c +++ b/megaed-stop-md/main.c @@ -283,7 +283,7 @@ int main() printf("\n"); printf("MD version: %02x\n", read8(0xa10001)); - printf("ROM witable? "); + printf("ROM writable? "); vptr = (void *)0x120; old = *vptr; diff --git a/megaed-stop/main.c b/megaed-stop/main.c index 4fbac7a..9101272 100644 --- a/megaed-stop/main.c +++ b/megaed-stop/main.c @@ -79,7 +79,7 @@ static void VDP_drawTextML(const char *str, u16 plane_base, while (len-- > 0) { write16(GFX_DATA_PORT, - basetile | ((*src++) - 32 + TILE_FONT_BASE)); + basetile | ((*src++) - 32 + TILE_FONT_BASE / 32)); } } diff --git a/sramtest/Makefile b/sramtest/Makefile new file mode 100644 index 0000000..f21669c --- /dev/null +++ b/sramtest/Makefile @@ -0,0 +1,33 @@ +CROSS = m68k-elf- +CC = $(CROSS)gcc +AS = $(CROSS)as +LD = $(CROSS)ld +OBJCOPY = $(CROSS)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 +LDLIBS += $(shell $(CC) -print-file-name=libgcc.a) + +TARGET = sramtest +OBJS = sega_gcc.o main.o asmtools.o data.o + +all: $(TARGET).bin + +$(TARGET).elf: $(OBJS) + $(LD) -o $@ -Tsega.ld -Map $(TARGET).map $^ $(LDLIBS) + +$(TARGET)_e.bin: $(TARGET).bin + dd if=/dev/zero of=$@ bs=1M count=1 + dd if=$^ of=$@ bs=1M seek=1 + dd if=$^ of=$@ conv=notrunc + +clean: + $(RM) $(TARGET).bin $(OBJS) $(TARGET).elf $(TARGET).map + + +%.bin: %.elf + $(OBJCOPY) -I elf32-m68k -O binary $^ $@ + +%.o: %.S + $(CC) -c -o $@ $^ $(ASFLAGS_CC) diff --git a/sramtest/UNLICENSE b/sramtest/UNLICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/sramtest/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/sramtest/asmtools.h b/sramtest/asmtools.h new file mode 100644 index 0000000..b820ec2 --- /dev/null +++ b/sramtest/asmtools.h @@ -0,0 +1,4 @@ +void write_rreg_i0(unsigned char val); +void write_rreg_i1(unsigned char val); +void fillpx16(void *d, unsigned int blocks, unsigned char val); +int checkpx4(void *d, unsigned int blocks, unsigned char val); diff --git a/sramtest/asmtools.s b/sramtest/asmtools.s new file mode 100644 index 0000000..dd4beb5 --- /dev/null +++ b/sramtest/asmtools.s @@ -0,0 +1,97 @@ +# Assemble with gas +# --register-prefix-optional --bitwise-or + +.macro ldarg arg, stacksz, reg + move.l (4 + \arg * 4 + \stacksz)(%sp), \reg +.endm + +# write with instructions that have bit0 clear +.global write_rreg_i0 /* u8 val */ +write_rreg_i0: + ldarg 0, 0, d0 + movea.l #0xa130f1, a0 + move.b d0, d0 + move.b d0, d0 + move.b d0, (a0) + move.b d0, d0 + move.b d0, d0 + move.b d0, d0 + move.b d0, d0 + rts + + +.global write_rreg_i1 /* u8 val */ +write_rreg_i1: + ldarg 0, 0, d1 + movea.l #0xa130f1, a0 + move.b d1, d1 + move.b d1, d1 + move.b d1, (a0) + move.b d1, d1 + move.b d1, d1 + move.b d1, d1 + move.b d1, d1 + rts + + +.global fillpx16 /* u8 *d, unsigned int blocks, u8 val */ +fillpx16: + ldarg 0, 0, a0 + ldarg 2, 0, d0 + move.b d0, d1 + lsl.w #8, d1 + or.w d1, d0 + move.w d0, d1 + swap d0 + move.w d1, d0 + ldarg 1, 0, d1 + subq.l #1, d1 + movem.l d2, -(sp) + move.l #32, d2 +0: + movep.l d0, 0(a0) + movep.l d0, 8(a0) + movep.l d0, 16(a0) + movep.l d0, 24(a0) + add.l d2, a0 + dbra d1, 0b + + movem.l (sp)+, d2 + rts + + +.global checkpx4 /* u8 *d, unsigned int blocks, u8 val */ +checkpx4: + ldarg 0, 0, a0 + ldarg 2, 0, d0 + move.b d0, d1 + lsl.w #8, d1 + or.w d1, d0 + move.w d0, d1 + swap d0 + move.w d1, d0 + ldarg 1, 0, d1 + subq.l #1, d1 + movem.l d2-d4, -(sp) + move.w d1, d3 + move.w d1, d4 + swap d3 +0: + move.w d4, d1 +1: + movep.l 0(a0), d2 + addq.l #8, a0 + cmp.l d0, d2 + dbne d1, 1b + dbne d3, 0b + + movem.l (sp)+, d2-d4 + move.l d1, d0 + cmp.w #-1, d1 + beq 0f + moveq.l #0, d0 +0: + rts + + +# vim:filetype=asmM68k:ts=4:sw=4:expandtab diff --git a/sramtest/data.s b/sramtest/data.s new file mode 100644 index 0000000..1de9b6f --- /dev/null +++ b/sramtest/data.s @@ -0,0 +1,10 @@ +.section .rodata + +# I don't know why multiple different .align don't work.. +.align 0x8000 + +.global font_base +font_base: +.incbin "font.bin" + +# vim:filetype=asmM68k:ts=4:sw=4:expandtab diff --git a/sramtest/font.bin b/sramtest/font.bin new file mode 100644 index 0000000000000000000000000000000000000000..c11cc3797d9d08cf787e2c9c095c1f7712e0ed2a GIT binary patch literal 3936 zcma)931Z|R49gGl|6k4zQc1RKLzuQ?Dd0nv&C%_3{iEHV>zbV|TxYvK{aH3gY9BOP zc`h5`JP$0edLI0M6~`BT$~3^n1~&vizBFP$B*wX(4;0ymxE0@JYq1{Y+;)^@Oa^i8}!0~UcMclYf``n!~;M1g+8<^|G-lcRRe~sX8t+8 z__aQZK(3Wuz=&YV=G;N1%yV(z0+SpxiW~*qB8ONnb6OEc=8dy>o4?}_W*Su9taIJP zj!)aNL3Okr4S+S^B#$xY45MZ}VCc2i_tv#Y4Eo~gQsx%%;3u5K*v^-5r@r0E9hi>I zIabqO67lyeY?1)uCvk)187+o|PJ_g^G9{7I%+&_Xt>71Yvc&4q2^(6s;}yu0L^;LPWzX; zr#MZIP+2q7jy2>5S;FW3P{O?W93J(=bvHk8fiLAbD5nB=pPzZa`4-c4xyK<9g6@K2 z<~Z-ib&(Uf$Id$JZ=-%!*+9H`K5=fC3+o_4Ho&O;f{-@&I9f|n^-(+ESRJEuX{TJL zJ`oao#}|OHWdq5ApYH%YjdWO~2M}^OtR8Lszxe-k4~pJAU|W(HTE7R$g6u zdBYg~+upG#-CntA56^n#wh_P*wW0 zLQKdiPt`$zyI{22J5A)L8bO`+PljZeJ}e(g#!d{%+5EWheV~Cx+Jss^`EKZ41S#^? ze|YUrTlYw!*RtV7{@%+suH7t)VxROwHdu<9{8zmaQ{s99gT6{(Vx%vI?+Hv;31euJ z5J>lIc_WJmH?BJ?VCaxCPyH>Rzj>x@%nL}9MmlLJi?(|Gz53>NjHfff)Z?q)Cwmwi z5*VSgj@gIJF{bS>mVU^}J)m_zc-~dwQuf3cHA1EOe;M0z)N;ljb7QVPu`hewyskP3 ICz6={KQiQ{DgXcg literal 0 HcmV?d00001 diff --git a/sramtest/main.c b/sramtest/main.c new file mode 100644 index 0000000..f9500b4 --- /dev/null +++ b/sramtest/main.c @@ -0,0 +1,545 @@ +/* + * This software is released into the public domain. + * See UNLICENSE file in top level directory. + */ +#include +#include + +#define u8 unsigned char +#define u16 unsigned short +#define u32 unsigned int + +#define noinline __attribute__((noinline)) +#define unused __attribute__((unused)) +#define _packed __attribute__((packed)) + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +#include "asmtools.h" + +#define GFX_DATA_PORT 0xC00000 +#define GFX_CTRL_PORT 0xC00004 + +#define TILE_MEM_END 0xB000 + +#define FONT_LEN 128 +#define TILE_FONT_BASE (TILE_MEM_END / 32 - FONT_LEN) + +/* note: using ED menu's layout here.. */ +#define WPLANE (TILE_MEM_END + 0x0000) +#define HSCRL (TILE_MEM_END + 0x0800) +#define SLIST (TILE_MEM_END + 0x0C00) +#define APLANE (TILE_MEM_END + 0x1000) +#define BPLANE (TILE_MEM_END + 0x3000) + +#define read8(a) \ + *((volatile u8 *) (a)) +#define read16(a) \ + *((volatile u16 *) (a)) +#define read32(a) \ + *((volatile u32 *) (a)) +#define write8(a, d) \ + *((volatile u8 *) (a)) = (d) +#define write16(a, d) \ + *((volatile u16 *) (a)) = (d) +#define write32(a, d) \ + *((volatile u32 *) (a)) = (d) + +#define GFX_WRITE_VRAM_ADDR(adr) \ + (((0x4000 | ((adr) & 0x3FFF)) << 16) | ((adr) >> 14) | 0x00) +#define GFX_WRITE_VSRAM_ADDR(adr) \ + (((0x4000 | ((adr) & 0x3FFF)) << 16) | ((adr) >> 14) | 0x10) +#define GFX_WRITE_CRAM_ADDR(adr) \ + (((0xC000 | ((adr) & 0x3FFF)) << 16) | ((adr) >> 14) | 0x00) + +#define VDP_setReg(r, v) \ + write16(GFX_CTRL_PORT, 0x8000 | ((r) << 8) | (v)) + +enum { + VDP_MODE1 = 0x00, + VDP_MODE2 = 0x01, + VDP_NT_SCROLLA = 0x02, + VDP_NT_WIN = 0x03, + VDP_NT_SCROLLB = 0x04, + VDP_SAT_BASE = 0x05, + VDP_BACKDROP = 0x07, + VDP_MODE3 = 0x0b, + VDP_MODE4 = 0x0c, + VDP_HSCROLL = 0x0d, + VDP_AUTOINC = 0x0f, + VDP_SCROLLSZ = 0x10, +}; + +/* cell counts */ +#define LEFT_BORDER 1 /* lame TV */ +#define PLANE_W 64 +#define PLANE_H 32 +#define CSCREEN_H 28 + +static int text_pal; + +static noinline void VDP_drawTextML(const char *str, u16 plane_base, + u16 x, u16 y) +{ + const u8 *src = (const u8 *)str; + u16 basetile = text_pal << 13; + int max_len = 40 - LEFT_BORDER; + int len; + u32 addr; + + x += LEFT_BORDER; + + for (len = 0; str[len] && len < max_len; len++) + ; + if (len > (PLANE_W - x)) + len = PLANE_W - x; + + addr = plane_base + ((x + (PLANE_W * y)) << 1); + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(addr)); + + while (len-- > 0) { + write16(GFX_DATA_PORT, + basetile | ((*src++) - 32 + TILE_FONT_BASE / 32)); + } +} + +static int printf_ypos; + +static void printf_line(int x, const char *buf) +{ + u32 addr; + int i; + + VDP_drawTextML(buf, APLANE, x, printf_ypos++ & (PLANE_H - 1)); + + if (printf_ypos >= CSCREEN_H) { + /* clear next line */ + addr = APLANE; + addr += (PLANE_W * (printf_ypos & (PLANE_H - 1))) << 1; + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(addr)); + for (i = 0; i < 40 / 2; i++) + write32(GFX_DATA_PORT, 0); + + /* scroll plane */ + write32(GFX_CTRL_PORT, GFX_WRITE_VSRAM_ADDR(0)); + write16(GFX_DATA_PORT, (printf_ypos - CSCREEN_H + 1) * 8); + } +} + +#define PRINTF_LEN 40 + +static int printf_xpos; + +static noinline int printf(const char *fmt, ...) +{ + static const char hexchars[] = "0123456789abcdef"; + char c, buf[PRINTF_LEN + 11 + 1]; + const char *s; + va_list ap; + int ival; + u32 uval; + int d = 0; + int i, j; + + va_start(ap, fmt); + for (d = 0; *fmt; ) { + int prefix0 = 0; + int fwidth = 0; + + c = *fmt++; + if (d < PRINTF_LEN) + buf[d] = c; + + if (c != '%') { + if (c == '\n') { + buf[d] = 0; + printf_line(printf_xpos, buf); + d = 0; + printf_xpos = 0; + continue; + } + d++; + continue; + } + if (d >= PRINTF_LEN) + continue; + + if (*fmt == '0') { + prefix0 = 1; + fmt++; + } + + while ('1' <= *fmt && *fmt <= '9') { + fwidth = fwidth * 10 + *fmt - '0'; + fmt++; + } + + switch (*fmt++) { + case '%': + d++; + break; + case 'd': + case 'i': + ival = va_arg(ap, int); + if (ival < 0) { + buf[d++] = '-'; + ival = -ival; + } + for (i = 1000000000; i >= 10; i /= 10) + if (ival >= i) + break; + for (; i >= 10; i /= 10) { + buf[d++] = '0' + ival / i; + ival %= i; + } + buf[d++] = '0' + ival; + break; + case 'x': + uval = va_arg(ap, int); + while (fwidth > 1 && uval < (1 << (fwidth - 1) * 4)) { + buf[d++] = prefix0 ? '0' : ' '; + fwidth--; + } + for (j = 1; j < 8 && uval >= (1 << j * 4); j++) + ; + for (j--; j >= 0; j--) + buf[d++] = hexchars[(uval >> j * 4) & 0x0f]; + break; + case 's': + s = va_arg(ap, char *); + while (*s && d < PRINTF_LEN) + buf[d++] = *s++; + break; + default: + // don't handle, for now + d++; + va_arg(ap, void *); + break; + } + } + buf[d] = 0; + va_end(ap); + + if (d != 0) { + // line without \n + VDP_drawTextML(buf, APLANE, printf_xpos, + printf_ypos & (PLANE_H - 1)); + printf_xpos += d; + } + + return d; // wrong.. +} + +static const char *exc_names[] = { + NULL, + NULL, + "Bus Error", + "Address Error", + "Illegal Instruction", + "Zero Divide", + "CHK Instruction", + "TRAPV Instruction", + "Privilege Violation", /* 8 8 */ + "Trace", + "Line 1010 Emulator", + "Line 1111 Emulator", + NULL, + NULL, + NULL, + "Uninitialized Interrupt", + NULL, /* 10 16 */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + "Spurious Interrupt", /* 18 24 */ + "l1 irq", + "l2 irq", + "l3 irq", + "l4 irq", + "l5 irq", + "l6 irq", + "l7 irq", +}; + +struct exc_frame { + u32 dr[8]; + u32 ar[8]; + u16 ecxnum; // from handler + union { + struct { + u16 sr; + u32 pc; + } g _packed; + struct { + u16 fc; + u32 addr; + u16 ir; + u16 sr; + u32 pc; + } bae _packed; // bus/address error frame + }; +} _packed; + +int xtttt(void) { return sizeof(struct exc_frame); } + +void exception(const struct exc_frame *f) +{ + int i; + + while (read16(GFX_CTRL_PORT) & 2) + ; + write16(GFX_CTRL_PORT, 0x8000 | (VDP_MODE1 << 8) | 0x04); + write16(GFX_CTRL_PORT, 0x8000 | (VDP_MODE2 << 8) | 0x44); + /* adjust scroll */ + write32(GFX_CTRL_PORT, GFX_WRITE_VSRAM_ADDR(0)); + write16(GFX_DATA_PORT, + printf_ypos >= CSCREEN_H ? + (printf_ypos - CSCREEN_H + 1) * 8 : 0); + + printf("exception %i ", f->ecxnum); + if (f->ecxnum < ARRAY_SIZE(exc_names) && exc_names[f->ecxnum] != NULL) + printf("(%s)", exc_names[f->ecxnum]); + if (f->ecxnum < 4) + printf(" (%s)", (f->bae.fc & 0x10) ? "r" : "w"); + printf(" \n"); + + if (f->ecxnum < 4) { + 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); + } + else { + printf(" PC: %08x SR: %04x \n", f->g.pc, f->g.sr); + } + for (i = 0; i < 8; i++) + printf(" D%d: %08x A%d: %08x \n", i, f->dr[i], i, f->ar[i]); + printf(" \n"); +} + +extern u32 font_base[]; +extern u8 test_data[]; +extern u8 test_data_end[]; + +static void simple_test(int *odd, int *even, int *rom) +{ + u32 old, new, v0, v1; + + *odd = *even = *rom = 0; + old = read16(0x200000); + new = old ^ 0xa55a; + write16(0x200000, new); + v0 = read16(0x200000); + write8(0x200000, ~new >> 8); + write8(0x200001, ~new); + //write16(0x200000, ~new); + v1 = read16(0x200000); + if (((v0 ^ new) & 0xff00) == 0 && ((v1 ^ ~new) & 0xff00) == 0) { + printf(" even"); + *even = 1; + } + if (((v0 ^ new) & 0x00ff) == 0 && ((v1 ^ ~new) & 0x00ff) == 0) { + printf(" odd"); + *odd = 1; + } + if (v0 == old && v1 == old) { + printf(" ROM"); + *rom = 1; + } + else if (!(*odd | *even)) { + text_pal = 2; + printf(" bad value"); + text_pal = 0; + } +} + +static int detect_size(u8 *a) +{ + int i, v; + + write8(a, 0); + for (i = 2, v = 1; i < 0x200000; i <<= 1, v++) { + write8(a + i, v); + if (read8(a) || read8(a + i) != v) + break; + } + return i > 2 ? i / 2 : 0; +} + +static unused void fill(u8 *d, unsigned int size, u8 val) +{ + unsigned int i; + + for (i = 0; i < size * 2; i += 2) + d[i] = val; +} + +static int check(u8 *d, unsigned int size, u8 val) +{ + unsigned int i; + + for (i = 0; i < size * 2; i += 2) + if (d[i] != val) + break; + + if (i == size * 2) + return 1; + + text_pal = 2; + printf("\nfailed at byte %x, val %02x vs %02x\n", + i / 2, d[i], val); + text_pal = 0; + return 0; +} + +static void do_test(u8 *d, unsigned int size) +{ + int spos = printf_xpos; + int i; + + for (i = 0; i < 0x100; i++) { + printf_xpos = spos; + printf("%02x", i); + //fill(d, size, i); + fillpx16(d, size / 16, i); + if (!checkpx4(d, size / 4, i)) { + check(d, size, i); // for log + break; + } + } +} + +int main() +{ + volatile u32 *vptr32; + int odd, even, rom; + u32 old; + int i; + + /* z80 */ + write16(0xa11100, 0x100); + write16(0xa11200, 0); + + /* setup VDP */ + while (read16(GFX_CTRL_PORT) & 2) + ; + + VDP_setReg(VDP_MODE1, 0x04); + VDP_setReg(VDP_MODE2, 0x44); + VDP_setReg(VDP_MODE3, 0x00); + VDP_setReg(VDP_MODE4, 0x81); + VDP_setReg(VDP_NT_SCROLLA, APLANE >> 10); + VDP_setReg(VDP_NT_SCROLLB, BPLANE >> 13); + VDP_setReg(VDP_SAT_BASE, SLIST >> 9); + VDP_setReg(VDP_HSCROLL, HSCRL >> 10); + VDP_setReg(VDP_AUTOINC, 2); + VDP_setReg(VDP_SCROLLSZ, 0x01); + VDP_setReg(VDP_BACKDROP, 0); + + /* clear name tables */ + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(APLANE)); + for (i = 0; i < PLANE_W * PLANE_H / 2; i++) + write32(GFX_DATA_PORT, 0); + + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(BPLANE)); + for (i = 0; i < PLANE_W * PLANE_H / 2; i++) + write32(GFX_DATA_PORT, 0); + + /* SAT, h. scroll */ + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(SLIST)); + write32(GFX_DATA_PORT, 0); + + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(HSCRL)); + write32(GFX_DATA_PORT, 0); + + /* scroll plane vscroll */ + write32(GFX_CTRL_PORT, GFX_WRITE_VSRAM_ADDR(0)); + write32(GFX_DATA_PORT, 0); + printf_xpos = printf_ypos = 0; + + /* load font */ + write32(GFX_CTRL_PORT, GFX_WRITE_VRAM_ADDR(TILE_FONT_BASE)); + for (i = 0; i < FONT_LEN * 32 / 4; i++) + write32(GFX_DATA_PORT, font_base[i]); + + /* set colors */ + write32(GFX_CTRL_PORT, GFX_WRITE_CRAM_ADDR(0)); + write32(GFX_DATA_PORT, 0); + write32(GFX_CTRL_PORT, GFX_WRITE_CRAM_ADDR(15 * 2)); // font normal + write16(GFX_DATA_PORT, 0xeee); + write32(GFX_CTRL_PORT, GFX_WRITE_CRAM_ADDR(31 * 2)); // green + write16(GFX_DATA_PORT, 0x0e0); + write32(GFX_CTRL_PORT, GFX_WRITE_CRAM_ADDR(47 * 2)); // red + write16(GFX_DATA_PORT, 0x00e); + text_pal = 0; + + printf("\n"); + printf("MD version: %02x\n", read8(0xa10001)); + printf("ROM writable? "); + + vptr32 = (void *)0x120; + old = *vptr32; + *vptr32 ^= ~0; + printf("%s\n", *vptr32 == old ? "no" : "yes"); + + printf("200000 initial state:"); + simple_test(&odd, &even, &rom); + + printf("\nenable with i0: "); + write_rreg_i0(1); + simple_test(&odd, &even, &rom); + + printf("\ndisable with i0:"); + write_rreg_i0(0); + simple_test(&odd, &even, &rom); + + printf("\nenable with i1: "); + write_rreg_i1(1); + simple_test(&odd, &even, &rom); + + printf("\ndisable with i1:"); + write_rreg_i1(0); + simple_test(&odd, &even, &rom); + + printf("\nenable with 16: "); + write16(0xa130f0, 1); + simple_test(&odd, &even, &rom); + printf("\n"); + + if (even) { + even = detect_size((void *)0x200000); + printf("detected even size: %d\n", even); + } + if (odd) { + odd = detect_size((void *)0x200001); + printf("detected odd size: %d\n", odd); + } + if (even) { + printf("testing even: ", even); + do_test((void *)0x200000, even); + printf("\n"); + } + if (odd) { + printf("testing odd: ", odd); + do_test((void *)0x200001, odd); + printf("\n"); + } + + if (!odd && !even) { + text_pal = 2; + printf("no RAM\n"); + text_pal = 0; + } + + printf("done.\n"); + + for (;;) + ; + + return 0; +} + +// vim:ts=4:sw=4:expandtab diff --git a/sramtest/sega.ld b/sramtest/sega.ld new file mode 100644 index 0000000..0921912 --- /dev/null +++ b/sramtest/sega.ld @@ -0,0 +1,117 @@ +OUTPUT_ARCH(m68k) +SEARCH_DIR(.) +/*GROUP(-lbcc -lc -lgcc)*/ +__DYNAMIC = 0; + +/* + * Setup the memory map of the SEGA Genesis. + * stack grows down from high memory. + * + * The memory map look like this: + * +--------------------+ <- low memory + * | .text | + * | _etext | + * | ctor list | the ctor and dtor lists are for + * | dtor list | C++ support + * +--------------------+ + * | .data | initialized data goes here + * | _edata | + * +--------------------+ + * | .bss | + * | __bss_start | start of bss, cleared by crt0 + * | _end | start of heap, used by sbrk() + * +--------------------+ + * . . + * . . + * . . + * | __stack | top of stack + * +--------------------+ + */ +MEMORY +{ + rom : ORIGIN = 0x00000000, LENGTH = 0x00400000 + ram : ORIGIN = 0x00ff0000, LENGTH = 0x00010000 +} + +/* + * allocate the stack to be at the top of memory, since the stack + * grows down + */ + +PROVIDE (__stack = 0x00fffff0); + +/* + * Initalize some symbols to be zero so we can reference them in the + * crt0 without core dumping. These functions are all optional, but + * we do this so we can have our crt0 always use them if they exist. + * This is so BSPs work better when using the crt0 installed with gcc. + * We have to initalize them twice, so we cover a.out (which prepends + * an underscore) and coff object file formats. + */ +PROVIDE (hardware_init_hook = 0); +PROVIDE (_hardware_init_hook = 0); +PROVIDE (software_init_hook = 0); +PROVIDE (_software_init_hook = 0); + +SECTIONS +{ + .text 0x00000000: + { + *(.text) + . = ALIGN(0x4); + __CTOR_LIST__ = .; + LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) + *(.ctors) + LONG(0) + __CTOR_END__ = .; + __DTOR_LIST__ = .; + LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) + *(.dtors) + LONG(0) + __DTOR_END__ = .; + *(.rodata*) +/* + *(.gcc_except_table) + + __INIT_SECTION__ = . ; + *(.init) + SHORT (0x4e75) + + __FINI_SECTION__ = . ; + *(.fini) + SHORT (0x4e75) +*/ + _etext = .; + *(.lit) + } > rom + + .data 0xff0000 : + { + *(.shdata) + *(.data) + _edata = .; + } > ram + + /* .bss 0xff0100 : */ + .bss BLOCK (0x4) : + { + __bss_start = . ; + *(.shbss) + *(.bss) + *(COMMON) + *(.eh_fram) + *(.eh_frame) + _end = ALIGN (0x8); + __end = _end; + } > ram + + .stab 0 (NOLOAD) : + { + *(.stab) + } + + .stabstr 0 (NOLOAD) : + { + *(.stabstr) + } +} diff --git a/sramtest/sega_gcc.s b/sramtest/sega_gcc.s new file mode 100644 index 0000000..3f3afec --- /dev/null +++ b/sramtest/sega_gcc.s @@ -0,0 +1,128 @@ +exc_tab: + dc.l 0, 0x200, exc02, exc03, exc04, exc05, exc06, exc07 + dc.l exc08, exc09, exc0a, exc0b, exc0c, exc0d, exc0e, exc0f + dc.l exc10, exc11, exc12, exc13, exc14, exc15, exc16, exc17 + dc.l exc18, exc19, exc1a, exc1b, HBL, exc1d, VBL, exc1f + dc.l exc20, exc21, exc22, exc23, exc24, exc25, exc26, exc27 + dc.l exc28, exc29, exc2a, exc2b, exc2c, exc2d, exc2e, exc2f + dc.l exc30, exc31, exc32, exc33, exc34, exc35, exc3e, exc37 + dc.l exc38, exc39, exc3a, exc3b, exc3c, exc3d, exc3e, exc3f + + .ascii "SEGA GENESIS " + .ascii "SRAM test " + .ascii "SRAM test " + .ascii "GM 00000000-00" + .byte 0x00,0x00 + .ascii "J " + .byte 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00 + .byte 0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff + .ascii "RA"; .byte 0xf8,0x20 /* 1b0 */ + .byte 0x00,0x02,0x00,0x00,0x00,0x3f,0xff,0xff /* 1b4 */ + .ascii " " /* 1bc */ + .ascii " " /* 1c0 */ + .ascii " " + .ascii "JUE " /* 1f0 */ + +RST: + move.w #0x2700, %sr + + move.b (0xA10001), %d0 + andi.b #0x0F, %d0 + beq.s 0f + move.l #0x53454741, (0xA14000) /* 'SEGA' */ +0: + tst.w (0xc00004).l + + moveq #0, %d0 + movea.l %d0, %a7 + move %a7, %usp +# move.w #0x2000, %sr + jsr main +0: + bra 0b + +#HBL: +#VBL: +# rte + +pre_exception: + move.w #0x2700, %sr + movem.l %d0-%d7/%a0-%a7,-(%sp) + move.l %sp, %d0 + move.l %d0,-(%sp) + jsr exception +0: + bra 0b + +.macro exc_stub num +exc\num: + move.w #0x\num, -(%sp) + jmp pre_exception +.endm + +exc_stub 02 +exc_stub 03 +exc_stub 04 +exc_stub 05 +exc_stub 06 +exc_stub 07 +exc_stub 08 +exc_stub 09 +exc_stub 0a +exc_stub 0b +exc_stub 0c +exc_stub 0d +exc_stub 0e +exc_stub 0f +exc_stub 10 +exc_stub 11 +exc_stub 12 +exc_stub 13 +exc_stub 14 +exc_stub 15 +exc_stub 16 +exc_stub 17 +exc_stub 18 +exc_stub 19 +exc_stub 1a +exc_stub 1b +HBL: +exc_stub 1c +exc_stub 1d +VBL: +exc_stub 1e +exc_stub 1f +exc_stub 20 +exc_stub 21 +exc_stub 22 +exc_stub 23 +exc_stub 24 +exc_stub 25 +exc_stub 26 +exc_stub 27 +exc_stub 28 +exc_stub 29 +exc_stub 2a +exc_stub 2b +exc_stub 2c +exc_stub 2d +exc_stub 2e +exc_stub 2f +exc_stub 30 +exc_stub 31 +exc_stub 32 +exc_stub 33 +exc_stub 34 +exc_stub 35 +exc_stub 36 +exc_stub 37 +exc_stub 38 +exc_stub 39 +exc_stub 3a +exc_stub 3b +exc_stub 3c +exc_stub 3d +exc_stub 3e +exc_stub 3f + +# vim:filetype=asmM68k:ts=4:sw=4:expandtab -- 2.39.5