From fb7d4acd5c42ab190b876c9c966fbf4ce0126a9e Mon Sep 17 00:00:00 2001 From: bbbradsmith Date: Wed, 29 May 2019 16:04:54 -0400 Subject: [PATCH] versionable header for sim65 load and run address now configured from header fix error codes not to conflict with test fix test/misc/endless.c which is supposed to fail if an endless loop does not occur --- cfg/sim6502.cfg | 2 +- cfg/sim65c02.cfg | 2 +- doc/sim65.sgml | 29 +++++++++++++++------- libsrc/sim6502/crt0.s | 2 ++ libsrc/sim6502/exehdr.s | 10 ++++++-- src/sim65/error.c | 18 ++++++++++++-- src/sim65/error.h | 17 +++++++++++++ src/sim65/main.c | 55 +++++++++++++++++++++++++++++++++++------ src/sim65/memory.c | 17 ++++++++----- src/sim65/memory.h | 5 +++- src/sim65/paravirt.c | 9 ------- test/misc/endless.c | 2 +- 12 files changed, 129 insertions(+), 39 deletions(-) diff --git a/cfg/sim6502.cfg b/cfg/sim6502.cfg index 546671641..c768ab4a3 100644 --- a/cfg/sim6502.cfg +++ b/cfg/sim6502.cfg @@ -4,7 +4,7 @@ SYMBOLS { } MEMORY { ZP: file = "", start = $0000, size = $001B; - HEADER: file = %O, start = $0000, size = $0002; + HEADER: file = %O, start = $0000, size = $000C; MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__; } SEGMENTS { diff --git a/cfg/sim65c02.cfg b/cfg/sim65c02.cfg index 546671641..c768ab4a3 100644 --- a/cfg/sim65c02.cfg +++ b/cfg/sim65c02.cfg @@ -4,7 +4,7 @@ SYMBOLS { } MEMORY { ZP: file = "", start = $0000, size = $001B; - HEADER: file = %O, start = $0000, size = $0002; + HEADER: file = %O, start = $0000, size = $000C; MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__; } SEGMENTS { diff --git a/doc/sim65.sgml b/doc/sim65.sgml index 6f197f518..0c3687e2b 100644 --- a/doc/sim65.sgml +++ b/doc/sim65.sgml @@ -140,28 +140,39 @@ Assembly tests may similarly be assembled and linked with and the sim65 library provides an -The binary input file has a 2 byte header. The first byte indicates CPU type: - 0 = 6502, 1 = 65C02. The second byte is the address of the C parameter stack pointer - 5 byte **signature**: The rest of the input file, after the header, will be loaded at 1 byte **version**: 1 byte **CPU type**: 1 byte **sp address**: the zero page address of the C parameter stack pointer 1 word **load address**: where to load the data from the file into memory (default: 1 word **reset address**: specifies where to begin execution after loading (default: + +Other internal details: + + The entire 64 kilobyte address space is writeable RAM. Aside from the loaded binary, the reset vector at The The built-in functions are provided by 6 paravirtualization hooks present at = MaxCycles)) { - Error ("Maximum number of cycles reached."); - exit (-99); /* do not use EXIT_FAILURE to avoid conflicts with the - same value being used in a test program */ + ErrorCode (SIM65_ERROR_TIMEOUT, "Maximum number of cycles reached."); } } diff --git a/src/sim65/memory.c b/src/sim65/memory.c index 305b26a73..11f0be55a 100644 --- a/src/sim65/memory.c +++ b/src/sim65/memory.c @@ -64,6 +64,15 @@ void MemWriteByte (unsigned Addr, unsigned char Val) +void MemWriteWord (unsigned Addr, unsigned Val) +/* Write a word to a memory location */ +{ + MemWriteByte (Addr, Val & 0xFF); + MemWriteByte (Addr + 1, Val >> 8); +} + + + unsigned char MemReadByte (unsigned Addr) /* Read a byte from a memory location */ { @@ -82,7 +91,7 @@ unsigned MemReadWord (unsigned Addr) unsigned MemReadZPWord (unsigned char Addr) -/* Read a word from the zero page. This function differs from ReadMemW in that +/* Read a word from the zero page. This function differs from MemReadWord in that ** the read will always be in the zero page, even in case of an address ** overflow. */ @@ -96,10 +105,6 @@ unsigned MemReadZPWord (unsigned char Addr) void MemInit (void) /* Initialize the memory subsystem */ { - /* Fill momory with illegal opcode */ + /* Fill memory with illegal opcode */ memset (Mem, 0xFF, sizeof (Mem)); - - /* Set RESET vector to 0x0200 */ - Mem[0xFFFC] = 0x00; - Mem[0xFFFD] = 0x02; } diff --git a/src/sim65/memory.h b/src/sim65/memory.h index 5de3a2bb8..41cc800d3 100644 --- a/src/sim65/memory.h +++ b/src/sim65/memory.h @@ -47,6 +47,9 @@ void MemWriteByte (unsigned Addr, unsigned char Val); /* Write a byte to a memory location */ +void MemWriteWord (unsigned Addr, unsigned Val); +/* Write a word to a memory location */ + unsigned char MemReadByte (unsigned Addr); /* Read a byte from a memory location */ @@ -54,7 +57,7 @@ unsigned MemReadWord (unsigned Addr); /* Read a word from a memory location */ unsigned MemReadZPWord (unsigned char Addr); -/* Read a word from the zero page. This function differs from ReadMemW in that +/* Read a word from the zero page. This function differs from MemReadWord in that ** the read will always be in the zero page, even in case of an address ** overflow. */ diff --git a/src/sim65/paravirt.c b/src/sim65/paravirt.c index b03767c5a..5abae9091 100644 --- a/src/sim65/paravirt.c +++ b/src/sim65/paravirt.c @@ -103,15 +103,6 @@ static void SetAX (CPURegs* Regs, unsigned Val) -static void MemWriteWord (unsigned Addr, unsigned Val) -{ - MemWriteByte (Addr, Val); - Val >>= 8; - MemWriteByte (Addr + 1, Val); -} - - - static unsigned char Pop (CPURegs* Regs) { return MemReadByte (0x0100 + ++Regs->SP); diff --git a/test/misc/endless.c b/test/misc/endless.c index fe0782941..f637d1f22 100644 --- a/test/misc/endless.c +++ b/test/misc/endless.c @@ -9,5 +9,5 @@ int main(void) ; } printf("error: should not come here\n"); - return EXIT_FAILURE; + return EXIT_SUCCESS; /* test verifies failure, not success */ }