cleanup in DOS Wedge, adapted to currently available helper routines

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