From 27934ac54151e09f2ed644158b4a957d489ea777 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 6 Feb 2022 08:31:37 +0100 Subject: [PATCH] Add additional pass that writes values based on memory address --- .gitignore | 2 +- Makefile | 24 ++++++------- emu6502.c | 54 ++++++++++------------------ memtest-f000.901465.asm | 78 +++++++++++++++++++++++++++++++++-------- 4 files changed, 96 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 0696c40..aab2aad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ emu6502 -*.o +*.o65 *.bin \ No newline at end of file diff --git a/Makefile b/Makefile index 68a6297..d01d671 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,25 @@ -.PHONY: all memtest-f000.901465.bin memtest-f000.901465.o ascii memtest-f000.901465+ascii.o emu5602 +.PHONY: all memtest-f000.901465.bin memtest-f000.901465.o65 ascii memtest-f000.901465+ascii.o65 emu5602 all: memtest-f000.901465.bin ascii emu5602 clean: - rm -f memtest-f000.901465.bin memtest-f000.901465.o - rm -f memtest-f000.901465+ascii.bin memtest-f000.901465+ascii.o + rm -f memtest-f000.901465.bin memtest-f000.901465.o65 memtest-f000.901465.map + rm -f memtest-f000.901465+ascii.bin memtest-f000.901465+ascii.o65 memtest-f000.901465+ascii.map rm -f emu6502 -memtest-f000.901465.bin: memtest-f000.901465.o - dd if=memtest-f000.901465.o bs=1 skip=2 of=memtest-f000.901465.bin +memtest-f000.901465.bin: memtest-f000.901465.o65 + dd if=memtest-f000.901465.o65 bs=1 skip=2 of=memtest-f000.901465.bin -memtest-f000.901465.o: - xa -M -A F000 -O PETSCREEN -c -C -v -o memtest-f000.901465.o memtest-f000.901465.asm +memtest-f000.901465.o65: + xa -M -A F000 -O PETSCREEN -c -C -v -l memtest-f000.901465.map -o memtest-f000.901465.o65 memtest-f000.901465.asm -ascii: memtest-f000.901465+ascii.o - dd if=memtest-f000.901465+ascii.o bs=1 skip=2 of=memtest-f000.901465+ascii.bin +ascii: memtest-f000.901465+ascii.o65 + dd if=memtest-f000.901465+ascii.o65 bs=1 skip=2 of=memtest-f000.901465+ascii.bin -memtest-f000.901465+ascii.o: - xa -M -A F000 -O ASCII -c -C -v -o memtest-f000.901465+ascii.o memtest-f000.901465.asm +memtest-f000.901465+ascii.o65: + xa -M '-D_MEMEND=$$1000' -A F000 -O ASCII -c -C -v -l memtest-f000.901465+ascii.map -o memtest-f000.901465+ascii.o65 memtest-f000.901465.asm emu5602: - gcc -o emu6502 emu6502.c fake6502.c + gcc -D_END=$$(cat memtest-f000.901465+ascii.map | grep ^done, | cut -d, -f2 | tr -d ' ,') -o emu6502 emu6502.c fake6502.c diff --git a/emu6502.c b/emu6502.c index c768993..bb93fb6 100644 --- a/emu6502.c +++ b/emu6502.c @@ -7,23 +7,28 @@ #include #include +#define RAMSIZE 0x1000 + extern uint32_t instructions; extern void reset6502(void); extern void step6502(void); -uint8_t *ram, *screen, *a000, *b000, *c000, *d000, *e000, *f000; +uint8_t *ram, *screen, *f000; uint8_t read6502(uint16_t address) { - if (address == 0xf27e) { + if (address == _END) { printf("DONE\n"); exit(0); } uint8_t value = 0x00; - if (address < 0x4000) { - // emulate memory error in uppermost page - if (address >= 0x3ff0) { + if (address < RAMSIZE) { + if (address >= RAMSIZE-16) { + // emulate memory error in uppermost page value = ram[address] & 0xf7; + } else if (address >= 0x0100 && address <= 0x01ff) { + // simulate broken LSB in stack page + value = ram[address & 0xfffe]; } else { value = ram[address]; } @@ -32,21 +37,6 @@ uint8_t read6502(uint16_t address) { // screen buffer is mirrored 4 times, discard upper 2 bytes value = screen[address & 0x03ff]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); - } else if (address >= 0xa000 && address <= 0xafff) { - value = a000[address-0xa000]; - printf("%08x: READ %04x -> %02x\n", instructions, address, value); - } else if (address >= 0xb000 && address <= 0xbfff) { - value = b000[address-0xb000]; - printf("%08x: READ %04x -> %02x\n", instructions, address, value); - } else if (address >= 0xc000 && address <= 0xcfff) { - value = c000[address-0xc000]; - printf("%08x: READ %04x -> %02x\n", instructions, address, value); - } else if (address >= 0xd000 && address <= 0xdfff) { - value = d000[address-0xd000]; - printf("%08x: READ %04x -> %02x\n", instructions, address, value); - } else if (address >= 0xe000 && address <= 0xe7ff) { - value = e000[address-0xe000]; - printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xf000) { value = f000[address-0xf000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); @@ -57,10 +47,15 @@ uint8_t read6502(uint16_t address) { } void write6502(uint16_t address, uint8_t value) { - if (address < 0x4000) { + if (address < RAMSIZE) { printf("%08x: WRITE %04x <- %02x\n", instructions, address, value); - ram[address] = value; - } else if (address >= 0x800 && address <= 0x8fff) { + // simulate broken LSB in stack page + if (address >= 0x100 && address <= 0x1ff) { + ram[address & 0xfffe] = value; + } else { + ram[address] = value; + } + } else if (address >= 0x8000 && address <= 0x8fff) { printf("%08x: WRITE %04x <- %02x, SCREEN(%d,%d)\n", instructions, address, value, (address&0x03ff)%40, (address&0x03ff)/40); screen[address & 0x03ff] = value; } else { @@ -69,20 +64,9 @@ void write6502(uint16_t address, uint8_t value) { } int main() { - ram = (uint8_t*) malloc(0x4000); + ram = (uint8_t*) malloc(RAMSIZE); screen = (uint8_t*) malloc(0x400); memset(screen, 'X', 0x400); - int afd = open("memtest-9000.901465.bin", O_RDONLY); - a000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, afd, 0); - int bfd = open("memtest-9000.901465.bin", O_RDONLY); - b000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, bfd, 0); - int cfd = open("basic-2-c000.901465-01.bin", O_RDONLY); - c000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, cfd, 0); - int dfd = open("basic-2-d000.901465-02.bin", O_RDONLY); - d000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, dfd, 0); - int efd = open("edit-2-n.901447-24.bin", O_RDONLY); - e000 = mmap(0, 0x0800, PROT_READ, MAP_PRIVATE, efd, 0); - //int ffd = open("kernal-2.901465-03.bin", O_RDONLY); int ffd = open("memtest-f000.901465+ascii.bin", O_RDONLY); f000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, ffd, 0); diff --git a/memtest-f000.901465.asm b/memtest-f000.901465.asm index 3174d00..257595e 100644 --- a/memtest-f000.901465.asm +++ b/memtest-f000.901465.asm @@ -1,13 +1,18 @@ - .word $f000 - * = $f000 +#ifndef _MEMSTART +#define _MEMSTART $0007 +#endif + +#ifndef _MEMEND +#define _MEMEND $4000 +#endif scrptr = $8000 eoscr = $83e7 ; last screen address lastline = $83c0 ; start of last line - memstart = $0010 - memend = $4000 + memstart = _MEMSTART + memend = _MEMEND addr = $0100 aoff = $02 @@ -15,6 +20,10 @@ pbyte = $04 scroff = $0605 + + .word $f000 + * = $f000 + main: sei ;; clear screen @@ -83,11 +92,23 @@ noskip: sty eoscr-1 ;; store pass value at the current address lda pbyte + ;; special case $42: was already written, read only and compare to address' (HI xor LO) + cmp #$42 + beq special42 sta (addr + cmp (memstart + stx >addr + ldy #addr + sta (addr + cpx #>memend + bne fillloop + jmp pass + + hexchars: .asc "0123456789ABCDEF" passbytes: - .byt $FF, $00, $AA, $55, $01, $02, $04, $08, $10, $20, $40, $80, $FE, $FD, $FB, $F7, $EF, $DF, $BF, $7F + .byt $FF, $00, $AA, $55, $42, $01, $02, $04, $08, $10, $20, $40, $80, $FE, $FD, $FB, $F7, $EF, $DF, $BF, $7F passchars: - .asc "FF00AA550102040810204080FEFDFBF7EFDFBF7F" + .asc "FF00AA55XX0102040810204080FEFDFBF7EFDFBF7F" infotext: - .asc " = MOS6502 memtest 2022, s3lph =" + .asc " CBM 3001 memtest, 2022 s3lph.me" + +done: + ;; done, loop forever + jmp done + eot: - ;; done, loop forever - jmp eot - - ;; Fill with FF * = $fffa - .dsb (*-eot-3), $ff + .dsb (*-eot), $ff ;; 6502 vectors * = $fffa - .byt main ; NMIV + .byt done ; NMIV .byt main ; RESV .byt main ; IRQV