From a80d49059019a15889101860f95fcae301da05e4 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 26 Jul 2019 18:30:07 +0200 Subject: [PATCH] fixes to Kernal character handling routines --- c64/basic/wedge_dos.s | 1 + c64/kernal/chkinout.s | 14 +++++++------- c64/kernal/chrin.s | 6 ++++-- c64/kernal/chrout.s | 43 +++++++++++++++++++++++++++++-------------- c64/kernal/clall.s | 6 +++++- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/c64/basic/wedge_dos.s b/c64/basic/wedge_dos.s index 041949c7..5408f8bb 100644 --- a/c64/basic/wedge_dos.s +++ b/c64/basic/wedge_dos.s @@ -103,6 +103,7 @@ wedge_dos_status: ;; Print out everything retrieved from the drive bne + jsr via_IBASIN + bcs wedge_dos_basic_error jsr via_IBSOUT jmp - * diff --git a/c64/kernal/chkinout.s b/c64/kernal/chkinout.s index 1af2fc02..1075665c 100644 --- a/c64/kernal/chkinout.s +++ b/c64/kernal/chkinout.s @@ -44,13 +44,13 @@ chkin: lda FAT,Y jsr iec_check_devnum bcs chkin_set_device - + jsr talk - bcs chkinout_end ; don't set DFLTN in case of failure + bcs chkinout_device_not_present ; don't set DFLTN in case of failure lda LAT, Y jsr tksa - bcs chkinout_end + bcs chkinout_device_not_present chkin_set_device: lda FAT,Y @@ -126,16 +126,16 @@ ckout: ;; For IEC devices, send LISTEN + SECOND first lda FAT,Y jsr iec_check_devnum - bcs chkin_set_device + bcs chkout_set_device jsr listen - bcs chkinout_end ; don't set DFLTO in case of failure + bcs chkinout_device_not_present ; don't set DFLTO in case of failure lda LAT, Y jsr second - bcs chkinout_end + bcs chkinout_device_not_present -hkout_set_device: +chkout_set_device: lda FAT,Y sta DFLTO clc ; for success diff --git a/c64/kernal/chrin.s b/c64/kernal/chrin.s index b20014e2..8a84f5d6 100644 --- a/c64/kernal/chrin.s +++ b/c64/kernal/chrin.s @@ -15,14 +15,16 @@ ;; Repeated calls after that read out the successive bytes of the line of input. chrin: - ;; First determine the device number + + ;; Determine the device number lda DFLTN beq chrin_keyboard ; #$00 - keyboard ;; XXX add screen support jsr iec_check_devnum - bcs chrin_done_fail ; not a supported device + bcc chrin_iec + jmp lvs_device_not_found_error ; not a supported device chrin_iec: diff --git a/c64/kernal/chrout.s b/c64/kernal/chrout.s index 48f5a606..6f340a0f 100644 --- a/c64/kernal/chrout.s +++ b/c64/kernal/chrout.s @@ -11,40 +11,41 @@ chrout: + sta last_printed_character_ascii + ;; Save X and Y values ;; (Confirmed by writing a test program that X and Y ;; don't get modified, in agreement with C64 PRG's ;; description of CHROUT) - sta last_printed_character_ascii txa pha tya pha php - ;; First determine the device number + ;; Determine the device number lda DFLTO cmp #$03 ; screen beq chrout_screen jsr iec_check_devnum - bcs chrout_done_fail ; not a supported device + bcs chrout_done_unknown_device ; not a supported device chrout_iec: lda last_printed_character_ascii jsr JCIOUT bcc chrout_done - + ;; FALLTROUGH chrout_done_fail: jsr show_cursor_if_enabled - + plp - - ;; Restore X and Y, set carry to mark success on exit + + ;; Restore X and Y pla tay pla @@ -52,12 +53,26 @@ chrout_done_fail: sec ; indicate failure rts +chrout_done_unknown_device: + jsr show_cursor_if_enabled + + plp + + ;; Restore X and Y + pla + tay + pla + tax + + ;; End wioth error + jmp lvs_device_not_found_error + chrout_done: jsr show_cursor_if_enabled - + plp - - ;; Restore X and Y, set carry to mark success on exit + + ;; Restore X and Y pla tay pla @@ -70,12 +85,12 @@ chrout_screen: ;; Crude implementation of character output sei ;; XXX why do we need to disable interrupts? - + jsr hide_cursor_if_visible - + lda last_printed_character_ascii tax - + ;; Check for special characters cmp #$00 @@ -89,7 +104,7 @@ not_00: bne not_0a jmp chrout_done not_0a: - + ;; Carriage return cmp #$0d bne not_0d diff --git a/c64/kernal/clall.s b/c64/kernal/clall.s index 01145a00..ba595c20 100644 --- a/c64/kernal/clall.s +++ b/c64/kernal/clall.s @@ -31,4 +31,8 @@ clall: tay ;; 'C64 Programmers Reference Guide', page 281, claims it calls CLRCHN too - jmp clrchn + jsr clrchn + + ;; Not sure whether original Kernal does so, but it seems sane to also clear possible errors + jmp kernalstatus_reset +