From bf4e22b99a8987511af3a6b1fa91b6d80baec649 Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Fri, 19 Apr 2019 21:11:24 +0930 Subject: [PATCH] save X and Y in CHROUT --- c64/kernal/chrout.s | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/c64/kernal/chrout.s b/c64/kernal/chrout.s index 18842a3d..af9b11f0 100644 --- a/c64/kernal/chrout.s +++ b/c64/kernal/chrout.s @@ -1,9 +1,29 @@ ; Function defined on pp272-273 of C64 Programmers Reference Guide chrout: ;; Crude implementation of character output + + ;; 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 + lda last_printed_character_ascii ;; Write character on the screen ldy current_screen_x + + ;; Convert PETSCII to screen code + cmp #$40 + bcc chrout_l1 + cmp #$59 + bcs chrout_l1 + and #$1f + +chrout_l1: sta (current_screen_line_ptr),y ;; Advance the column, and scroll screen down if we need @@ -13,9 +33,19 @@ chrout: iny sty current_screen_x cpy #40 - beq screen_grow_logical_line + bne no_screen_advance_to_next_line + jsr screen_grow_logical_line cpy #79 - bcs screen_advance_to_next_line + bcc no_screen_advance_to_next_line + jsr screen_advance_to_next_line +no_screen_advance_to_next_line: + + ;; Restore X and Y + pla + tay + pla + tax + rts screen_grow_logical_line: