diff options
-rw-r--r-- | avr/z180-serv.c | 61 | ||||
-rw-r--r-- | include/config.h | 1 |
2 files changed, 32 insertions, 30 deletions
diff --git a/avr/z180-serv.c b/avr/z180-serv.c index f613510..e2a39d3 100644 --- a/avr/z180-serv.c +++ b/avr/z180-serv.c @@ -24,7 +24,7 @@ #include "bcd.h" #include "rtc.h" -#define DEBUG_CPM_SDIO 1 /* set to 1 to debug */ +#define DEBUG_CPM_SDIO 0 /* set to 1 to debug */ #define debug_cpmsd(fmt, args...) \ debug_cond(DEBUG_CPM_SDIO, fmt, ##args) @@ -242,7 +242,7 @@ int cpm_drv_to(int state) if (drv_table[i].dirty) { f_sync(&drv_table[i].fd); drv_table[i].dirty = false; - debug_cpmsd("## %7lu f_sync: %c:\n", get_timer(0), i+'A'); + debug_cpmsd("## %7lu f_sync: %c:\n", get_timer(0), i + CONFIG_CPM_BASE_DRIVE); } } state = 0; @@ -280,21 +280,20 @@ void msg_cpm_result(uint8_t subf, uint8_t rc, int res) void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) { - FRESULT res = 0; uint8_t drv; char *np; (void)subf; - if (len != 5) { /* TODO: check adrv, rdrv */ + if (len != 5) { return msg_cpm_result(subf, 0x01, res); } - debug_cpmsd("\n## %7lu login: %c:\n", get_timer(0), msg[0]+'A'); - + debug_cpmsd("\n## %7lu login: %c:\n", get_timer(0), msg[1]+CONFIG_CPM_BASE_DRIVE); - drv = msg[0]; + /* Get relative drive number */ + drv = msg[1]; if ( drv>= CONFIG_CPM_MAX_DRIVE) { return msg_cpm_result(subf, 0x02, res); } @@ -325,6 +324,24 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg) debug_cpmsd("## %7lu open: '%s', (env: '%s'), res: %d\n", get_timer(0), drv_table[drv].img_name, disk_buffer, res); + if (!res && f_size(&drv_table[drv].fd) < CONFIG_CPM_DISKSIZE) { + unsigned int bw; + + debug_cpmsd(" expanding image file from %ld to %ld\n", + f_size(&drv_table[drv].fd), CONFIG_CPM_DISKSIZE); + + res = f_lseek(&drv_table[drv].fd, CONFIG_CPM_DISKSIZE-CONFIG_CPM_BLOCK_SIZE); + if (!res) { + memset(disk_buffer, 0xe5, CONFIG_CPM_BLOCK_SIZE); + res = f_write(&drv_table[drv].fd, disk_buffer, CONFIG_CPM_BLOCK_SIZE, &bw); + if (res || bw < CONFIG_CPM_BLOCK_SIZE) { + debug_cpmsd(" failed! res: %d, bytes written: %u\n", res, bw); + } + drv_table[drv].dirty = true; + bg_setstat(handle_cpm_drv_to, 1); + } + } + /* send result*/ msg_cpm_result(subf, 0x00, res); } @@ -359,11 +376,11 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) uint8_t rc = 0; bool buserr = 0; - if (len != 10) { /* TODO: check adrv, rdrv */ + if (len != 10) { return msg_cpm_result(subf, 0x01, res); } - drv = msg[ADRV]; + drv = msg[RDRV]; if ( drv>= CONFIG_CPM_MAX_DRIVE) { return msg_cpm_result(subf, 0x02, res); } @@ -378,8 +395,8 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) debug_cpmsd("## %7lu cpm_rw: %s %c: trk:%4d, sec: %d, pos: %.8lx, secs: %2d, " "addr: %.5lx\n", get_timer(0), dowrite ? "write" : " read", - msg[ADRV]+'A', ((uint16_t)(msg[TRK+1] << 8) + msg[TRK]), msg[SEC], - pos, msg[CNT], addr); + msg[RDRV]+CONFIG_CPM_BASE_DRIVE, + ((uint16_t)(msg[TRK+1] << 8) + msg[TRK]), msg[SEC], pos, msg[CNT], addr); if (pos + secs * CONFIG_CPM_BLOCK_SIZE > CONFIG_CPM_DISKSIZE) { debug_cpmsd(" access > DISKSIZE (%.8lx > %.8lx) aborted!\n", @@ -388,11 +405,6 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) } res = f_lseek(&drv_table[drv].fd, pos); -#if 0 - if (f_tell(&drv_table[drv].fd) != pos) { - return msg_cpm_result(subf, 0x05, res); - } -#endif while (!res && secs--) { unsigned int brw; @@ -412,34 +424,23 @@ void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg) buserr = 1; break; } else { - if (brw == 0) { - debug_cpmsd(" short read, brw: %d\n", brw); - z80_memset(addr, 0, CONFIG_CPM_BLOCK_SIZE); - brw = CONFIG_CPM_BLOCK_SIZE; - } else { - z80_write_block(disk_buffer, addr, CONFIG_CPM_BLOCK_SIZE); - } + z80_write_block(disk_buffer, addr, CONFIG_CPM_BLOCK_SIZE); z80_bus_cmd(Release); } } } - if (brw != CONFIG_CPM_BLOCK_SIZE) { - debug_cpmsd("## %7lu f_read res: %d, bytes rd/wr: %u\n", get_timer(0), res, brw); - dump_ram(disk_buffer, 0, 64, "Read Data"); - res = -1; + debug_cpmsd(" short read or write: res: %d, bytes rd/wr: %u\n", res, brw); + res = 64; } - addr += CONFIG_CPM_BLOCK_SIZE; } if (dowrite && !res) { -// res = f_sync(&drv_table[drv].fd); drv_table[drv].dirty = true; bg_setstat(handle_cpm_drv_to, 1); } - if (buserr) { debug_cpmsd("Bus timeout\n"); rc = 0x03; diff --git a/include/config.h b/include/config.h index 71e3dbb..90ff6fa 100644 --- a/include/config.h +++ b/include/config.h @@ -42,6 +42,7 @@ #define CONFIG_CPM3_BANKED_BASE_STR "0" #define CONFIG_CPM_MAX_DRIVE 8 +#define CONFIG_CPM_BASE_DRIVE 'A' #define CONFIG_CPM_BLOCK_SIZE 512 #define CONFIG_CMD_MEMTEST |