From ecbb77072ed617d45cbe51dcf0de175dbb26dfbf Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 3 Jun 2019 08:42:08 -0400 Subject: [PATCH] tools/emul/shell: allow the growing of fsdev --- tools/emul/shell/shell.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/emul/shell/shell.c b/tools/emul/shell/shell.c index 8193e9d..eb252a0 100644 --- a/tools/emul/shell/shell.c +++ b/tools/emul/shell/shell.c @@ -26,6 +26,7 @@ */ //#define DEBUG +#define MAX_FSDEV_SIZE 0x20000 // in sync with shell.asm #define RAMSTART 0x4000 @@ -37,7 +38,7 @@ static Z80Context cpu; static uint8_t mem[0xffff] = {0}; -static uint8_t fsdev[0x20000] = {0}; +static uint8_t fsdev[MAX_FSDEV_SIZE] = {0}; static uint32_t fsdev_size = 0; static uint32_t fsdev_ptr = 0; static int running; @@ -58,7 +59,10 @@ static uint8_t io_read(int unused, uint16_t addr) #endif return fsdev[fsdev_ptr++]; } else { - fprintf(stderr, "Out of bounds FSDEV read at %d\n", fsdev_ptr); + // don't warn when ==, we're not out of bounds, just at the edge. + if (fsdev_ptr > fsdev_size) { + fprintf(stderr, "Out of bounds FSDEV read at %d\n", fsdev_ptr); + } return 0; } } else if (addr == FS_SEEKL_PORT) { @@ -85,6 +89,10 @@ static void io_write(int unused, uint16_t addr, uint8_t val) } else if (addr == FS_DATA_PORT) { if (fsdev_ptr < fsdev_size) { fsdev[fsdev_ptr++] = val; + } else if ((fsdev_ptr == fsdev_size) && (fsdev_ptr < MAX_FSDEV_SIZE)) { + // We're at the end of fsdev, grow it + fsdev[fsdev_ptr++] = val; + fsdev_size++; } else { fprintf(stderr, "Out of bounds FSDEV write at %d\n", fsdev_ptr); }