From 9ee2fd2af53dcb05062093715209ca649a376023 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 16 Jun 2019 19:32:40 +0200 Subject: [PATCH] implemented CLALL routine, added support for LAT/SAT/FAT and LDTND variables --- c64/basic/,aliases.s | 7 +++++++ c64/kernal/,aliases.s | 6 ++++++ c64/kernal/clall.s | 16 +++++++++++++++- c64/kernal/close.s | 38 ++++++++++++++++++++++++++++++++++++++ c64/kernal/open.s | 42 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 102 insertions(+), 7 deletions(-) diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index 59fddba5..f500a630 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -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 diff --git a/c64/kernal/,aliases.s b/c64/kernal/,aliases.s index be1a53d2..d438620d 100644 --- a/c64/kernal/,aliases.s +++ b/c64/kernal/,aliases.s @@ -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 diff --git a/c64/kernal/clall.s b/c64/kernal/clall.s index 3a701b3d..a24918fb 100644 --- a/c64/kernal/clall.s +++ b/c64/kernal/clall.s @@ -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 diff --git a/c64/kernal/close.s b/c64/kernal/close.s index df7f3603..e89ace83 100644 --- a/c64/kernal/close.s +++ b/c64/kernal/close.s @@ -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 diff --git a/c64/kernal/open.s b/c64/kernal/open.s index 1dc5d99e..92981de6 100644 --- a/c64/kernal/open.s +++ b/c64/kernal/open.s @@ -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).