From f2e2db3a4de71a5880e3c8377d7c6d9171595e1c Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Mon, 22 Apr 2019 23:15:58 +0930 Subject: [PATCH] add files for BASIC interpretor main loop and message printing --- c64/basic/,aliases.s | 3 ++- c64/basic/ab1e.print_string.s | 36 ++++++++++++++++++++++++++++++++ c64/basic/basic_do_error.s | 39 +++++++++++++++++++++++++++++++++++ c64/basic/basic_main_loop.s | 27 ++++++++++++++++++++++++ c64/basic/basic_warm_start.s | 4 ++-- c64/basic/ready_message.s | 5 +++++ 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 c64/basic/ab1e.print_string.s create mode 100644 c64/basic/basic_do_error.s create mode 100644 c64/basic/basic_main_loop.s create mode 100644 c64/basic/ready_message.s diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index 481a9ec7..3fbb1f97 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -53,7 +53,8 @@ .alias rs232_rx_buffer_ptr $F7 .alias rs232_tx_buffer_ptr $F9 - + .alias basic_input_buffer $0200 + ; "Compute's Mapping the 64" book .alias keyboard_buffer $0277 .alias MEMSTR $0281 diff --git a/c64/basic/ab1e.print_string.s b/c64/basic/ab1e.print_string.s new file mode 100644 index 00000000..9ca8a586 --- /dev/null +++ b/c64/basic/ab1e.print_string.s @@ -0,0 +1,36 @@ + ;; Print string at $YYAA + ;; Compute's Mapping the 64 p101 + +print_string: + ;; Setup pointer + sty temp_string_ptr+1 + sta temp_string_ptr+0 + + txa + pha + + ;; Get offset ready + ldy #$00 + +print_string_loop: + ;; Save Y in X, since X is preserved by chrout, but Y is not + tya + tax + + lda (temp_string_ptr),y + beq print_string_end + + jsr $FFD2 ; KERNAL CHROUT + + txa + tay + + iny + bne print_string_loop + + +print_string_end: + + pla + tax + rts diff --git a/c64/basic/basic_do_error.s b/c64/basic/basic_do_error.s new file mode 100644 index 00000000..bd06ab29 --- /dev/null +++ b/c64/basic/basic_do_error.s @@ -0,0 +1,39 @@ + ;; Compute's Mapping the 64 p93 + +basic_do_error: + + + + + + +basic_error_messages: + .byte "TOO MANY FILES",0 + .byte "FILE OPEN",0 + .byte "FILE NOT OPEN",0 + .byte "FILE NOT FOUND",0 + .byte "DEVICE NOT PRESENT",0 + .byte "NOT INPUT FILE",0 + .byte "NOT OUTPUT FILE",0 + .byte "MISSING FILENAME",0 + .byte "ILLEGAL DEVICE NUMBER",0 + .byte "NEXT WITHOUT FOR",0 + .byte "SYNTAX",0 + .byte "RETURN WITHOUT GOSUB",0 + .byte "OUT OF DATA",0 + .byte "ILLEGAL QUANTITY",0 + .byte "OVERFLOW",0 + .byte "OUT OF MEMORY",0 + .byte "UNDEF'D STATEMENT",0 + .byte "BAD SUBSCRIPT",0 + .byte "REDIM'D ARRAY",0 + .byte "DIVISION BY ZERO",0 + .byte "ILLEGAL DIRECT",0 + .byte "TYPE MISMATCH",0 + .byte "STRING TOO LONG",0 + .byte "FILE DATA",0 + .byte "FORMULA TOO COMPLEX",0 + .byte "CAN'T CONTINUE",0 + .byte "UNDEF'D FUNCTION",0 + .byte "VERIFY",0 + .byte "LOAD",0 diff --git a/c64/basic/basic_main_loop.s b/c64/basic/basic_main_loop.s new file mode 100644 index 00000000..e8d2f0ef --- /dev/null +++ b/c64/basic/basic_main_loop.s @@ -0,0 +1,27 @@ +basic_main_loop: + + ;; XXX - Check if direct or program mode, and get next line of input + ;; the appropriate way. + ;; XXX - For now, it is hard coded to direct mode + + ;; Read a line of input + ldx #$00 +read_line_loop: + jsr $ffe4 ; KERNAL CHRIN + cmp #$0d + beq got_line_of_input + ;; Not carriage return, so try to append to line so far + cpx #80 + bcc + + ;; Report STRING TOO LONG error (Compute's Mapping the 64 p93) + ldx #23 + jmp basic_do_error +* + sta basic_input_buffer,x + inx + jmp read_line_loop + +got_line_of_input: + jsr ready_message + + jmp basic_main_loop diff --git a/c64/basic/basic_warm_start.s b/c64/basic/basic_warm_start.s index 3ed8b376..c9f89540 100644 --- a/c64/basic/basic_warm_start.s +++ b/c64/basic/basic_warm_start.s @@ -1,6 +1,6 @@ ;; Clear screen etc, show READY prompt. basic_warm_start: - * inc $d020 - jmp - + jsr ready_message + jmp basic_main_loop diff --git a/c64/basic/ready_message.s b/c64/basic/ready_message.s new file mode 100644 index 00000000..bf0ad136 --- /dev/null +++ b/c64/basic/ready_message.s @@ -0,0 +1,5 @@ +ready_message: + ;; See src/make_error_tables.c for packed message handling + ;; information. + ldx #0 + jmp print_packed_message