From fa55c83fff5db42b717a9393e61e8e9ee39639de Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Sat, 4 May 2019 23:12:54 +0930 Subject: [PATCH] generally remove some debug output, add missing file, and make KERNAL LOAD routine more complete. --- c64/kernal/iec_assert_atn.s | 2 - c64/kernal/iec_release_atn.s | 2 - c64/kernal/iec_rx_byte.s | 8 -- c64/kernal/iec_turnaround_to_listen.s | 4 - c64/kernal/iec_tx_byte.s | 11 -- c64/kernal/load.s | 6 +- c64/kernal/printf.s | 158 ++++++++++++++++++++++++++ src/compress_text.c | 2 +- 8 files changed, 162 insertions(+), 31 deletions(-) create mode 100644 c64/kernal/printf.s diff --git a/c64/kernal/iec_assert_atn.s b/c64/kernal/iec_assert_atn.s index e16de6ef..57560c3a 100644 --- a/c64/kernal/iec_assert_atn.s +++ b/c64/kernal/iec_assert_atn.s @@ -1,6 +1,4 @@ iec_assert_atn: - jsr printf - .byte "ASSERT ATN",$0d,0 lda $dd00 ora #$08 sta $dd00 diff --git a/c64/kernal/iec_release_atn.s b/c64/kernal/iec_release_atn.s index b1305815..56644746 100644 --- a/c64/kernal/iec_release_atn.s +++ b/c64/kernal/iec_release_atn.s @@ -1,6 +1,4 @@ iec_release_atn: - jsr printf - .byte "RELEASE ATN",$0d,0 lda $dd00 and #$f7 sta $dd00 diff --git a/c64/kernal/iec_rx_byte.s b/c64/kernal/iec_rx_byte.s index 599e254d..9d168597 100644 --- a/c64/kernal/iec_rx_byte.s +++ b/c64/kernal/iec_rx_byte.s @@ -5,19 +5,13 @@ iec_rx_byte: - inc $062f - ;; First, we wait for the talker to release the CLK line. jsr iec_wait_for_clock_release - inc $0630 - ;; We then release the data line ;; (We can use this routine, since we weren't holding CLK, anyway) jsr iec_release_clk_and_data - inc $0631 - ;; Wait for talker to assert CLK. ;; If >200usec, then it is EOI and we have to assert the ;; DATA line for 60 usec to tell the TALKER that we have @@ -99,8 +93,6 @@ iec_rx_bit_loop: dex bpl iec_rx_bit_loop - inc $0637 - ;; Then we must within 1000usec acknowledge the frame by ;; asserting DATA. At this point, CLK is asserted by the ;; talker and DATA by us, i.e., we are ready to receive diff --git a/c64/kernal/iec_turnaround_to_listen.s b/c64/kernal/iec_turnaround_to_listen.s index eb7c82c3..db021689 100644 --- a/c64/kernal/iec_turnaround_to_listen.s +++ b/c64/kernal/iec_turnaround_to_listen.s @@ -5,14 +5,12 @@ iec_turnaround_to_listen: ;; Assert data and release clock lda $dd00 - sta $0420 and #$ef ; release clock (bit 4) ora #$20 ; assert data (bit 5) sta $dd00 ;; Wait for clock line to be asserted by the drive * lda $dd00 - sta $0421 and #$40 bne - @@ -36,8 +34,6 @@ iec_turnaround_to_listen: ;; sec ;; rts * - jsr printf - .byte "TURNAROUND SUCEEDED",$0d,$00 ;; ATN turn around successful clc diff --git a/c64/kernal/iec_tx_byte.s b/c64/kernal/iec_tx_byte.s index 3e1e53d9..03f35c6d 100644 --- a/c64/kernal/iec_tx_byte.s +++ b/c64/kernal/iec_tx_byte.s @@ -2,13 +2,6 @@ iec_tx_byte: pha - sta $0400 - - jsr printf - .byte "IEC TX BYTE $" - .byte $f0, <$0400,>$0400 - .byte $0d,0 - jsr iec_assert_clk_release_data ;; Give devices time to respond @@ -16,12 +9,10 @@ iec_tx_byte: ;; Did a device respond? (DATA will be pulled if so) lda $DD00 - sta $0418 bpl + ;; No devices present, so we can immediately return with device not found pla - inc $420 jmp kernalerror_DEVICE_NOT_FOUND * @@ -87,12 +78,10 @@ iec_tx_byte_l1: bne - ;; Timeout - DEVICE NOT PRESENT - inc $421 jmp kernalerror_DEVICE_NOT_FOUND * ;; All done. ;; End state is TALKER is asserting CLK, and listener is asserting DATA ;; until they are ready for the next byte. - inc $044f clc rts diff --git a/c64/kernal/load.s b/c64/kernal/load.s index fcdc8d7f..1dce5587 100644 --- a/c64/kernal/load.s +++ b/c64/kernal/load.s @@ -5,6 +5,9 @@ load: ;; Disable IRQs, since timing matters! SEI + ;; Display SEARCHING FOR + jsr printf + .byte "SEARCHING FOR ",$0d,$0 ;; Begin sending under attention jsr iec_assert_atn @@ -84,9 +87,6 @@ load: beq - load_done: - jsr printf - .byte "LOADED",$0d,0 - ;; Close file on drive ;; Command drive to listen and to close the file diff --git a/c64/kernal/printf.s b/c64/kernal/printf.s new file mode 100644 index 00000000..c1edc71c --- /dev/null +++ b/c64/kernal/printf.s @@ -0,0 +1,158 @@ + ;; printf()-like routine for simplifying debugging + + ;; Prints the literal zero-terminated string that follows, + ;; which may also include special tokens that allow + ;; printing of hex byte and word values stored at the indicated + ;; addresses. + + ;; .byte 1,$byte = display byte as hex + ;; .byte 2,$low,$hi = display word as hex + ;; .byte $f0+n,$low,$hi = display byte at $hi$lo+n as hex + +printf: + ;; Temporary storage is between end of screen at $0400 + ;; and the sprite pointers at $7f8 + sta $7f0 + stx $7f1 + sty $7f2 + php + pla + sta $7f3 + + ;; Set up read routine + lda #$ad ; LDA $nnnn + sta $7f4 + lda #$60 + sta $7f7 ; RTS + + ;; Get PC of caller from the stack, so that + ;; we can parse through it + pla + clc + adc #$01 + sta $7f5 + pla + adc #$00 + sta $7f6 + +printf_loop: + jsr $7f4 + cmp #$00 + bne printf_continues + ;; Put return address on stack and restore + ;; registers + lda $7f6 + pha + lda $7f5 + pha + lda $7f3 + pha + lda $7f0 + ldx $7f1 + ldy $7f2 + plp + rts + +printf_continues: + cmp #$01 + bne not_hexbyte + ;; Print a hex byte + + ;; Skip the token + jsr printf_advance + ;; Read the low byte + jsr $7f4 + ;; Print as hex + jsr printf_printhexbyte + jmp printf_nextchar + +not_hexbyte: + cmp #$02 + bne not_hexword + ;; Print a hex word + + ;; Skip the token + jsr printf_advance + jsr printf_advance + ;; Read the high byte + jsr $7f4 + ;; Print as hex + jsr printf_printhexbyte + ;; Skip the token + jsr printf_retreat + ;; Read the low byte + jsr $7f4 + ;; Print as hex + jsr printf_printhexbyte + jsr printf_advance + jmp printf_nextchar + +not_hexword: + cmp #$f0 + bcc not_pointer + + ;; Treat two-byte arg as base address + ;; and lower 4 bits of token as offset from + ;; that location. + + ;; Get offset + and #$0f + tay + + jsr printf_advance + jsr $7f4 + sta $fd + jsr printf_advance + jsr $7f4 + sta $fe + + lda ($fd),y + jsr printf_printhexbyte + jmp printf_nextchar + +not_pointer: + ;; Print character + jsr $ffd2 + +printf_nextchar: + jsr printf_advance + + jmp printf_loop + +printf_advance: + ;; Advance pointer to next character + inc $7f5 + bne + + inc $7f6 + * + rts + +printf_retreat: + ;; Retreat pointer to previous char + lda $7f5 + sec + sbc #1 + sta $7f5 + lda $7f6 + sbc #0 + sta $7f6 + rts + +printf_printhexbyte: + pha + lsr + lsr + lsr + lsr + ora #$30 + cmp #$3A + bcc + + adc #6 +* jsr $ffd2 + pla + and #$0f + ora #$30 + cmp #$3A + bcc + + adc #6 +* jmp $ffd2 diff --git a/src/compress_text.c b/src/compress_text.c index 64a365ba..fd156b19 100644 --- a/src/compress_text.c +++ b/src/compress_text.c @@ -159,7 +159,7 @@ char *error_list[]={ "LOAD", // https://www.discogs.com/Gimmik-Load-Error/release/482462 // Non-error messages "READY.\r", // #29 // https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zconcepts/zconc_whatistsonative.htm https://github.com/stefanhaustein/expressionparser - "LOADING", // https://community.tibco.com/wiki/how-show-loading-prompt-when-reloading-external-data + "LOADING", // #30 // https://community.tibco.com/wiki/how-show-loading-prompt-when-reloading-external-data "VERIFYING", // https://discussions.apple.com/thread/8087203 "SAVING", "ERROR", // #33 // Simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html