diff --git a/src/basic/wedge/wedge_dos.s b/src/basic/wedge/wedge_dos.s index 5a9eea52..f214d91d 100644 --- a/src/basic/wedge/wedge_dos.s +++ b/src/basic/wedge/wedge_dos.s @@ -5,6 +5,7 @@ #if CONFIG_DOS_WEDGE + // .X has to contain size of the buffer wedge_dos: @@ -23,72 +24,76 @@ wedge_dos: ldy #$0F jsr JSETFLS - // Setup necessary parts of BASIC + // Setup necessary part of BASIC - lda #<(BUF+1) - sta TXTPTR+0 - lda #>(BUF+1) - sta TXTPTR+1 - - lda #$FF - sta CURLIN+1 + jsr prepare_direct_execution + jsr fetch_character // Now we have to check what the user wants us to do // Check if user asked for a status + ldy #$00 lda (TXTPTR), y - bne !+ - jmp wedge_dos_status // XXX try to optimize this, perhaps move 'wedge_dos_status' above? -!: + beq_16 wedge_dos_status + // Check if asked for a directory + cmp #$24 - bne !+ - jmp wedge_dos_directory -!: + beq_16 wedge_dos_directory + // Check if asked to change drive number, or if it is a regular command - cmp #$30 - bcc wedge_dos_command // char code before 0 - cmp #$3A - bcs wedge_dos_command // char code after 9 - iny - lda (TXTPTR), y - beq wedge_dos_change_drive // end of buffer - cmp #$20 - beq wedge_dos_change_drive - jmp !- + + jsr is_09 + bcc wedge_dos_change_drive + + // FALLTROUGH wedge_dos_command: // Provide command name + jsr wedge_dos_setnam jsr JSETNAM jsr JOPEN - bcc !+ - jmp wedge_dos_basic_error // XXX combine with other such jumps -!: + bcs_16 wedge_dos_basic_error + // Retrieve status, print it if not OK + jsr JCLALL jsr wedge_dos_status_get + lda BUF+0 cmp #$30 // '0' bne wedge_dos_status_print + lda BUF+1 cmp #$30 // '0' bne wedge_dos_status_print // Clean-up and exit + jmp wedge_dos_clean_exit wedge_dos_change_drive: + // Fetch new drive number, make sure this is the last part of the command + jsr fetch_uint8 + pha + jsr fetch_character_skip_spaces + cmp #$00 + bne_16 do_SYNTAX_error + pla + + // Check if device number is valid for IEC drive + cmp #$08 - bpl !+ - bcs !+ - jmp do_ILLEGAL_DEVICE_NUMBER_error -!: + bcc_16 do_ILLEGAL_DEVICE_NUMBER_error + + // Store new device number and return to shell + sta FA jmp shell_main_loop @@ -102,37 +107,49 @@ wedge_dos_status_get: // https://codebase64.org/doku.php?id=base:reading_the_error_channel_of_a_disk_drive // Set remaining file parameters, open the channel + lda #$00 // empty file name jsr JSETNAM jsr JOPEN - bcc !+ - jmp wedge_dos_basic_error // XXX combine with other such jumps -!: + bcs_16 wedge_dos_basic_error // Set channel for input + ldx #$0F jsr JCHKIN - bcc !+ - jmp wedge_dos_basic_error // XXX combine with other such jumps -!: + bcs_16 wedge_dos_basic_error + + // Fetch the drive status ldy #$00 -!: - cpy #$50 // buffer overflow protection - beq !+ - jsr JREADST // retrieve errors - // XXX error in case of status != EOF - // Print out everything retrieved from the drive - bne !+ - jsr JCHRIN - bcc wedge_dos_x1 - jmp wedge_dos_basic_error // XXX try to optimize this -wedge_dos_x1: + // FALLTROUGH + +wedge_dos_status_get_loop: + + // Check for buffer overflow + + cpy #$50 + beq_16 do_OVERFLOW_error + + // Check for EOF + + jsr JREADST + // XXX check for transfer errors + bne wedge_dos_status_get_done + + // Retrieve a byte and put it into the buffer + + jsr JCHRIN + bcs_16 wedge_dos_basic_error + sta BUF, y iny - jmp !- -!: + + bne wedge_dos_status_get_loop // branch always + +wedge_dos_status_get_done: + // Strip ending RETURN dey @@ -141,11 +158,13 @@ wedge_dos_x1: wedge_dos_status: jsr wedge_dos_status_get + // FALLTROUGH wedge_dos_status_print: // Print buffered status + ldx #$00 !: dey @@ -156,38 +175,48 @@ wedge_dos_status_print: bne !- !: // Clean-up and exit + +#if HAS_OPCODES_65C02 + bra wedge_dos_clean_exit +#else jmp wedge_dos_clean_exit +#endif wedge_dos_directory: - // First change the secondary address to the one suitable for - // directory loading - lda #$00 // logical device number + // First change the secondary address to the one suitable for directory loading + + lda #$00 // logical device number ldx FA ldy #$60 jsr JSETFLS // Provide file name + jsr wedge_dos_setnam - // Open the file + // Open the file, set channel for reading + jsr JOPEN bcs wedge_dos_basic_error - // Set channel for file reading ldx #$00 jsr JCHKIN bcs wedge_dos_basic_error // Ignore start address (2 first bytes) - XXX check for errors + jsr JCHRIN bcs wedge_dos_basic_error jsr JCHRIN bcs wedge_dos_basic_error + // FALLTROUGH + wedge_dos_directory_line: // Load a single line, reuse BASIC input buffer + ldy #$FF !: iny @@ -195,29 +224,33 @@ wedge_dos_directory_line: bcs wedge_dos_basic_error sta BUF, y cpy #$50 - beq !+ // line too long, terminate loading file + beq_16 do_OVERFLOW_error // branch if line too long jsr JREADST bne !+ // end of file cpy #$04 // 2 bytes (pointer to next line) + 2 bytes (line number) bcc !- lda BUF, y bne !- + // End of line, but not end of file + beq wedge_dos_directory_display !: lda #K_STS_END_OF_FILE sta IOSTATUS // make sure end of file is marked + // FALLTROUGH wedge_dos_directory_display: - cpy #$05 // protection against malformed directory + cpy #$05 // protection against malformed directory bcc wedge_dos_clean_exit - lda #$00 // extra protection agains buffer overflow + lda #$00 // extra protection agains buffer overflow sta BUF, y // Display line + ldx #BUF @@ -226,22 +259,28 @@ wedge_dos_directory_display: jsr list_single_line // Read & display next line or quit + lda IOSTATUS beq wedge_dos_directory_line + // FALLTROUGH wedge_dos_clean_exit: + jsr JCLALL jmp shell_main_loop wedge_dos_basic_error: + pha jsr JCLALL pla jmp do_kernal_error wedge_dos_setnam: + // Now determine the length of the 'file' name + ldy #$FF !: iny @@ -249,9 +288,12 @@ wedge_dos_setnam: bne !- // Set the name to open + tya ldx TXTPTR+0 ldy TXTPTR+1 + jmp JSETNAM + #endif // CONFIG_DOS_WEDGE