- if (buserr)
- my_puts_P(PSTR("Bus timeout\n"));
- if (res)
- put_rc(res);
- if (buserr || res)
- return CMD_RET_FAILURE;
-
- return CMD_RET_SUCCESS;
-}
-
-/*
- * fatwrite - write file into a dos filesystem
- * <d:/path/filename> <addr> <bytes>
- */
-command_ret_t do_fat_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
- FATFS FatFs;
- FIL File;
- unsigned long bytes;
- unsigned long bytes_written;
- uint32_t addr;
- FRESULT res;
- bool buserr = 0;
- uint32_t timer;
- uint8_t buffer[512];
-
- (void) cmdtp; (void) flag;
-
- if (argc < 4)
- return CMD_RET_USAGE;
-
- addr = strtoul(argv[2], 0, 16);
- bytes = strtoul(argv[3], 0, 16);
-
- res = f_mount(&FatFs, argv[1], 0);
- if (!res) {
- res = f_open(&File, argv[1], FA_CREATE_ALWAYS | FA_WRITE);
- if (!res) {
- bytes_written = 0;
- timer = get_timer(0);
- while (bytes) {
- unsigned int cnt, br;
-
- if (bytes >= sizeof buffer) {
- cnt = sizeof buffer;
- bytes -= sizeof buffer;
- } else {
- cnt = bytes; bytes = 0;
- }
- if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
- buserr = 1;
- break;
- }
- z80_read_block(buffer, addr, cnt);
- z80_bus_cmd(Release);
- res = f_write(&File, buffer, cnt, &br);
- if (res != FR_OK)
- break;
- addr += br;
- bytes_written += br;
- if (cnt != br)
- break;
- }
- res = f_close(&File);
- timer = get_timer(timer);
- printf_P(PSTR("%lu bytes written with %lu bytes/sec.\n"),
- bytes_written, timer ? (bytes_written * 1000 / timer) : 0);
- }
- f_mount(NULL, argv[1], 0);
- }