work towards CHKIN, CHKOUT and CLRCHN
This commit is contained in:
1 parent
c30d4b31c9
commit
273eb3ee6a
7 files changed
+182
-125
No files matched your search
@@ -88,11 +88,11 @@ NOTE: Even the 'DONE' routines won't support features described as missing in on
|
||||
| $FFB7 | READST | DONE | |
|
||||
| $FFBA | SETFLS | DONE | |
|
||||
| $FFBD | SETNAM | DONE | |
|
||||
| $FFC0 | OPEN | NOT DONE | * work in progress |
|
||||
| $FFC0 | OPEN | DONE | |
|
||||
| $FFC3 | CLOSE | PARTIAL | * work in progress |
|
||||
| $FFC6 | CHKIN | NOT DONE | * work in progress |
|
||||
| $FFC9 | CHKOUT | NOT DONE | * work in progress |
|
||||
| $FFCC | CLRCHN | NOT DONE | * work in progress |
|
||||
| $FFC6 | CHKIN | PARTIAL | * work in progress |
|
||||
| $FFC9 | CHKOUT | PARTIAL | * work in progress |
|
||||
| $FFCC | CLRCHN | PARTIAL | * work in progress |
|
||||
| $FFCF | CHRIN | NOT DONE | * work in progress |
|
||||
| $FFD2 | CHROUT | NOT DONE | * work in progress |
|
||||
| $FFD5 | LOAD | PARTIAL | no VERIFY support yet |
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
;;
|
||||
;; Official Kernal routine, described in:
|
||||
;;
|
||||
;; - [RG64] C64 Programmer's Reference Guide - page 275
|
||||
;; - [CM64] Compute's Mapping the Commodore 64 - page 229
|
||||
;;
|
||||
;; CPU registers that has to be preserved (see [RG64]): .Y
|
||||
;;
|
||||
|
||||
chkin:
|
||||
|
||||
;; Implemented according to 'C64 Programmers Reference Guide', page 277
|
||||
|
||||
;; First retrieve the FAT/LAT/SAT table index (and check if file is open)
|
||||
|
||||
; txa
|
||||
; jsr find_fls
|
||||
; bcs kernalerror_FILE_NOT_OPEN
|
||||
|
||||
;; Now we have table index in Y - check if file is open for reading
|
||||
|
||||
;; XXX continue implementation
|
||||
|
||||
rts
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
|
||||
;;
|
||||
;; Official Kernal routines, described in:
|
||||
;;
|
||||
;; - [RG64] C64 Programmer's Reference Guide - page 275 (CHKIN) / 276 (CHKOUT)
|
||||
;; - [CM64] Compute's Mapping the Commodore 64 - page 229
|
||||
;;
|
||||
;; CPU registers that has to be preserved (see [RG64]): .Y
|
||||
;;
|
||||
|
||||
|
||||
;; CHKIN implementation
|
||||
|
||||
chkin:
|
||||
|
||||
;; Store Y for preservation
|
||||
tya
|
||||
pha
|
||||
|
||||
;; Reset status
|
||||
jsr kernalstatus_reset
|
||||
|
||||
;; First retrieve the FAT/LAT/SAT table index (and check if file is open)
|
||||
|
||||
txa
|
||||
jsr find_fls
|
||||
bcs chkinout_file_not_open
|
||||
|
||||
;; Now we have table index in Y - first filter out unsuitable devices
|
||||
|
||||
lda FAT,Y
|
||||
cmp #$01
|
||||
beq chkinout_device_not_present ; tape not implemented
|
||||
cmp #$02
|
||||
beq chkinout_device_not_present ; RS-232 not implemented
|
||||
|
||||
;; Fail if the file is open for writing (secondary address 1)
|
||||
|
||||
lda LAT, Y
|
||||
cmp #$01
|
||||
beq chkinout_file_not_input
|
||||
|
||||
;; For IEC devices, send TALK first
|
||||
lda FAT,Y
|
||||
jsr iec_devnum_check
|
||||
bcs chkin_set_device
|
||||
|
||||
jsr talk
|
||||
bcs chkinout_end ; don't set DFLTN in case of failure
|
||||
|
||||
chkin_set_device:
|
||||
lda FAT,Y
|
||||
sta DFLTN
|
||||
clc ; for success
|
||||
;; FALLTROUGH
|
||||
|
||||
;; Common part for booth CHKIN and CHKOUT
|
||||
|
||||
chkinout_end:
|
||||
pla
|
||||
tay
|
||||
rts
|
||||
|
||||
chkinout_file_not_open:
|
||||
pla
|
||||
tay
|
||||
jmp kernalerror_FILE_NOT_OPEN
|
||||
|
||||
chkinout_device_not_present:
|
||||
pla
|
||||
tay
|
||||
jsr kernalstatus_DEVICE_NOT_FOUND
|
||||
jmp kernalerror_DEVICE_NOT_FOUND
|
||||
|
||||
chkinout_file_not_input:
|
||||
pla
|
||||
tay
|
||||
jmp kernalerror_FILE_NOT_INPUT
|
||||
|
||||
chkinout_file_not_output:
|
||||
pla
|
||||
tay
|
||||
jmp kernalerror_FILE_NOT_OUTPUT
|
||||
|
||||
chkinout_common:
|
||||
|
||||
;; CHKOUT implementation
|
||||
|
||||
chkout:
|
||||
|
||||
;; Store Y for preservation
|
||||
tya
|
||||
pha
|
||||
|
||||
;; Reset status
|
||||
jsr kernalstatus_reset
|
||||
|
||||
;; First retrieve the FAT/LAT/SAT table index (and check if file is open)
|
||||
|
||||
txa
|
||||
jsr find_fls
|
||||
bcs chkinout_file_not_open
|
||||
|
||||
;; Now we have table index in Y - first filter out unsuitable devices
|
||||
|
||||
lda FAT,Y
|
||||
cmp #$01
|
||||
beq chkinout_device_not_present ; tape not implemented
|
||||
cmp #$02
|
||||
beq chkinout_device_not_present ; RS-232 not implemented
|
||||
|
||||
cmp #$00
|
||||
beq chkinout_file_not_output ; cannot output to keyboard - XXX check real ROM behaviour
|
||||
|
||||
;; Fail if the file is open for reading (secondary address 0)
|
||||
|
||||
lda LAT, Y
|
||||
beq chkinout_file_not_output
|
||||
|
||||
;; For IEC devices, send LISTEN first
|
||||
lda FAT,Y
|
||||
jsr iec_devnum_check
|
||||
bcs chkin_set_device
|
||||
|
||||
jsr listen
|
||||
bcs chkinout_end ; don't set DFLTO in case of failure
|
||||
|
||||
chkout_set_device:
|
||||
lda FAT,Y
|
||||
sta DFLTO
|
||||
clc ; for success
|
||||
|
||||
jmp chkinout_end
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
;;
|
||||
;; Official Kernal routine, described in:
|
||||
;;
|
||||
;; - [RG64] C64 Programmer's Reference Guide - page 276
|
||||
;; - [CM64] Compute's Mapping the Commodore 64 - page 229
|
||||
;;
|
||||
;; CPU registers that has to be preserved (see [RG64]): .Y
|
||||
;;
|
||||
|
||||
chkout:
|
||||
|
||||
;; Implemented according to 'C64 Programmers Reference Guide', page 278
|
||||
|
||||
;; First retrieve the FAT/LAT/SAT table index (and check if file is open)
|
||||
|
||||
; txa
|
||||
; jsr find_fls
|
||||
; bcs kernalerror_FILE_NOT_OPEN
|
||||
|
||||
;; Now we have table index in Y - check if file is open for writing
|
||||
|
||||
;; XXX continue implementation
|
||||
|
||||
rts
|
||||
@@ -9,4 +9,27 @@
|
||||
;;
|
||||
|
||||
clrchn:
|
||||
|
||||
;; Restore input device to default
|
||||
lda DFLTN
|
||||
jsr iec_devnum_check
|
||||
bcs +
|
||||
;; Previous device was IEC one - send UNTALK first
|
||||
jsr untlk
|
||||
*
|
||||
;; Set input device number to keyboard
|
||||
lda #$00
|
||||
sta DFLTN
|
||||
|
||||
;; Restore output device to default
|
||||
lda DFLTO
|
||||
jsr iec_devnum_check
|
||||
bcs +
|
||||
;; Previous device was IEC one - send UNLISTEN first
|
||||
jsr unlsn
|
||||
*
|
||||
;; Set output device number to screen
|
||||
lda #$03
|
||||
sta DFLTO
|
||||
|
||||
rts
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
;; Just a helper routine
|
||||
;; Just a helper routines
|
||||
|
||||
;; Find the LAT / SAT / FAT entry index where LAT corresponds to A, returns index in Y
|
||||
;; Carry flag set means not found
|
||||
@@ -13,7 +13,7 @@ find_fls:
|
||||
bmi find_fls_not_found ; no more entries
|
||||
cmp LAT, y
|
||||
bne - ; does not match, try the next one
|
||||
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
@@ -21,3 +21,4 @@ find_fls_not_found:
|
||||
|
||||
sec
|
||||
rts
|
||||
|
||||
+19
-67
@@ -8,13 +8,23 @@
|
||||
;; CPU registers that has to be preserved (see [RG64]): none
|
||||
;;
|
||||
|
||||
;; XXX this is only a test implementation, does not do what the Kernal does!
|
||||
|
||||
open:
|
||||
|
||||
;; LAT / FAT / SAT support implemented according to
|
||||
;; 'Compute's Mapping the Commodore 64', page 52
|
||||
;; Reset status
|
||||
jsr kernalstatus_reset
|
||||
|
||||
;; Check if the logical file number is unique
|
||||
ldy LDTND
|
||||
*
|
||||
beq +
|
||||
dey
|
||||
lda LAT, y
|
||||
cmp current_logical_filenum
|
||||
beq kernalerror_FILE_ALREADY_OPEN
|
||||
cpy #$00
|
||||
jmp -
|
||||
*
|
||||
;; Check if we have space in tables
|
||||
|
||||
ldy LDTND
|
||||
@@ -22,15 +32,16 @@ open:
|
||||
bcs +
|
||||
bmi open_has_space
|
||||
*
|
||||
;; Table is full - according to https://codebase64.org/doku.php?id=base:kernalreference
|
||||
;; C flag set means error occured
|
||||
sec
|
||||
rts
|
||||
;; Table is full
|
||||
jmp kernalerror_TOO_MANY_OPEN_FILES
|
||||
|
||||
open_has_space:
|
||||
|
||||
;; Update the tables
|
||||
|
||||
;; LAT / FAT / SAT support implemented according to
|
||||
;; 'Compute's Mapping the Commodore 64', page 52
|
||||
|
||||
lda current_logical_filenum
|
||||
sta LAT, y
|
||||
lda current_device_number
|
||||
@@ -40,66 +51,7 @@ open_has_space:
|
||||
|
||||
iny
|
||||
sty LDTND
|
||||
|
||||
;; Kernal API is shared between several types of devices - we have
|
||||
;; to dispatch the call to appropriate subroutine
|
||||
|
||||
lda current_device_number
|
||||
beq open_keyboard
|
||||
cmp #$01
|
||||
beq open_tape
|
||||
cmp #$02
|
||||
beq open_rs232
|
||||
cmp #$03
|
||||
beq open_screen
|
||||
cmp #$1F
|
||||
bcs +
|
||||
bmi open_iec
|
||||
*
|
||||
;; Device numbers over 30 are not allowed on IEC bus
|
||||
|
||||
;; FALLTHROUGH to error routine
|
||||
|
||||
open_keyboard:
|
||||
open_tape:
|
||||
open_screen:
|
||||
|
||||
;; XXX implement support for these devices
|
||||
lda #$05 ; device not present
|
||||
sta IOSTATUS
|
||||
rts
|
||||
|
||||
open_rs232:
|
||||
|
||||
;; XXX implement support for RS-232
|
||||
lda #$FF ; set every single error bit to discourage using RS-232
|
||||
sta RSSTAT
|
||||
rts
|
||||
|
||||
open_iec:
|
||||
|
||||
;; Part implemented according to https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc
|
||||
;; XXX note: this is only a temporary test implementation, real 'open' does not send anything to IEC,
|
||||
;; see http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
|
||||
|
||||
;; Request device to talk
|
||||
lda current_device_number
|
||||
jsr talk
|
||||
bcs open_iec_error
|
||||
|
||||
;; Send secondary address
|
||||
lda current_secondary_address
|
||||
jsr second
|
||||
bcs open_iec_error
|
||||
|
||||
;; Turnaround
|
||||
jsr iec_turnaround_to_listen
|
||||
bcs open_iec_error
|
||||
|
||||
;; Indicate success
|
||||
lda #$00
|
||||
clc
|
||||
|
||||
open_iec_error:
|
||||
;; Carry flag will be set by low-level routines
|
||||
rts
|
||||
|
||||
Reference in new issue
Block a user