implemented CLALL routine, added support for LAT/SAT/FAT and LDTND variables

This commit is contained in:
FeralChild64 committed 2019-06-16 19:32:40 +02:00
1 parent 9fa2e8b1fa
commit 9ee2fd2af5
5 files changed
+102 -7

No files matched your search

+7
View File
@@ -58,6 +58,7 @@
.alias BUCKYSTATUS $91
.alias load_or_verify_flag $93
.alias current_file_num $98
.alias LDTND $98 ; number of entries in LAT / FAT / SAT tables
.alias DFLTN $99
.alias input_device_number DFLTN
; bit 6 = error messages, bit 7 = control messages
@@ -74,6 +75,7 @@
;; - 'Compute's Mapping the Commodore 64', page 32
.alias CMP0 $B0 ;; $B0-$B1
.alias cassette_buffer_ptr $B2
.alias current_filename_length $B7
.alias current_logical_filenum $B8
@@ -110,6 +112,11 @@
.alias basic_input_buffer $0200
;; Kernal tables for opened files, 10 entries each
.alias LAT $0259 ; logical file numbers
.alias FAT $0263 ; device numbers
.alias SAT $026D ; secondary addresses
; "Compute's Mapping the 64" book
.alias keyboard_buffer $0277
.alias MEMSTR $0281
+6
View File
@@ -9,6 +9,7 @@
.alias BUCKYSTATUS $91
.alias kernal_load_or_verify_flag $93
.alias current_file_num $98
.alias LDTND $98 ; number of entries in LAT / FAT / SAT tables
.alias DFLTN $99
.alias input_device_number DFLTN
; bit 6 = error messages, bit 7 = control messages
@@ -58,6 +59,11 @@
;; - 'Compute's Mapping the Commodore 64', page 32
.alias CMP0 $B0 ;; $B0-$B1
;; Kernal tables for opened files, 10 entries each
.alias LAT $0259 ; logical file numbers
.alias FAT $0263 ; device numbers
.alias SAT $026D ; secondary addresses
; "Compute's Mapping the 64" book
.alias keyboard_buffer $0277
.alias MEMSTR $0281
+15 -1
View File
@@ -1,2 +1,16 @@
clall:
rts
;; Implemented according to 'C64 Programmer's Reference Guide', page 281
;; Not entirely sure if it just sets LDTND to 0 or actually calls CLOSE,
;; but calling CLOSE for all open channels seems to be the safest
ldy LDTND
beq +
dey
lda LAT, y
jsr close
jmp clall
*
;; 'C64 Programmers Reference Guide', page 281, claims it calls CLRCHN too
jmp clrchn
+38
View File
@@ -1,3 +1,41 @@
; Function defined on pp272-273 of C64 Programmers Reference Guide
close:
;; Implemented accorging to 'C64 Programmers Reference Guide', page 281
;; XXX this needs more testing (opening 10 files at once, closing in various orders, etc) once the code is more mature
;; Find the LAT / SAT / FAT entry which LAT corresponds to A
ldy LDTND
beq close_error_not_found ; table empty
*
dey
bmi close_error_not_found ; no more entries
cmp LAT, y
bne - ; does not match, try the next one
;; We have the entry index in Y
;; XXX some devices (like IEC) needs special support here, to free their internal resources!
;; Just make sure the Y register value is kept, or redo ldy DFTLN
*
iny
cpy #$0A
bpl +
lda LAT, y
sta LAT-1, y
lda FAT, y
sta FAT-1, y
lda SAT, y
sta SAT-1, y
jmp -
*
;; Decrement the list size variable
dec LDTND
;; FALLTHROUGH (for now) - success
close_error_not_found:
;; XXX it seems that this function can't report errors, am I right?
rts
+36 -6
View File
@@ -4,6 +4,38 @@
open:
;; LAT / FAT / SAT support implemented according to
;; 'Compute's Mapping the Commodore 64', page 52
;; Check if we have space in tables
ldy LDTND
cpy #$0A
bcs +
bmi open_has_space
*
jsr printf
.byte "FULL", $0D, 0
;; Table is full - according to https://codebase64.org/doku.php?id=base:kernalreference
;; C flag set means error occured
sec
rts
open_has_space:
;; Update the tables
lda current_logical_filenum
sta LAT, y
lda current_device_number
sta FAT, y
lda current_secondary_address
sta SAT, y
iny
sty LDTND
;; Kernal API is shared between several types of devices - we have
;; to dispatch the call to appropriate subroutine
@@ -54,17 +86,15 @@ open_iec:
jsr iec_assert_atn
;; CLK is now asserted, and we are ready to transmit a byte
lda #$20 ; listen
clc
adc current_device_number
jsr iec_tx_byte
bcs open_error
lda current_device_number
jsr listen
bcs open_iec_error
;; Indicate success
lda #$00
clc
open_error:
open_iec_error:
;; Re-enable interrupts and return
;; (iec_tx_byte will have set/cleared C flag and put result code
;; in A if it was an error).