From eef572e0ab9ee5a260e7ab2b641fadd8b9f3d57f Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Sat, 27 Apr 2019 23:00:20 +0930 Subject: [PATCH] work on getting BASIC line number entry working. --- c64/basic/,aliases.s | 13 +++++++++++ c64/basic/basic_cold_start.s | 2 ++ c64/basic/basic_main_loop.s | 35 +++++++++++++++++++++++++---- c64/basic/basic_warm_start.s | 1 - c64/basic/cmd_new.s | 33 +++++++++++++++++++++++++++ c64/basic/do_basic_error.s | 5 ++++- c64/basic/fac1_mul.s | 2 +- c64/basic/injest_number.s | 43 +++++++++++++++++++++++++++++++++++- 8 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 c64/basic/cmd_new.s diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index 9ca68d2d..3a886555 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -6,6 +6,7 @@ .alias tokenise_work2 $8 .alias tokenise_work3 $B .alias tokenise_work4 $F + .alias basic_line_number $14 .alias temp_string_ptr $35 .alias load_or_verify_or_tokenise_work5 $C .alias basic_work22 $22 @@ -13,6 +14,18 @@ .alias basic_work24 $24 .alias basic_work25 $25 + ;; The various pointers that separate memory regions for BASIC storage + ;; We have multiple names for the ones that mark the boundary of regions. + .alias basic_start_of_text_ptr $2b + .alias basic_end_of_text_ptr $2d + .alias basic_start_of_vars_ptr $2d + .alias basic_end_of_vars_ptr $2f + .alias basic_start_of_arrays_ptr $2f + .alias basic_end_of_arrays_ptr $31 + .alias basic_start_of_free_space_ptr $31 + .alias basic_start_of_strings_ptr $33 + .alias basic_top_of_memory_ptr $35 + .alias basic_numeric_work_area $57 ; $57 - $60 inclusive = 10 bytes ;; Floating point accumulator 1 $61 - $68 diff --git a/c64/basic/basic_cold_start.s b/c64/basic/basic_cold_start.s index 8ea150c4..cd1bb82f 100644 --- a/c64/basic/basic_cold_start.s +++ b/c64/basic/basic_cold_start.s @@ -14,6 +14,8 @@ basic_cold_start: ;; Print the rest of the start up message ldx #34 jsr print_packed_message + + jsr basic_do_new ;; jump into warm start loop jmp basic_warm_start diff --git a/c64/basic/basic_main_loop.s b/c64/basic/basic_main_loop.s index f5a20df2..bc7d7bda 100644 --- a/c64/basic/basic_main_loop.s +++ b/c64/basic/basic_main_loop.s @@ -3,10 +3,14 @@ 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 + + ;; Tell user we are ready + jsr ready_message ;; Read a line of input ldx #$00 -read_line_loop: +read_line_loop: + jsr $ffcf ; KERNAL CHRIN bcs read_line_loop @@ -73,10 +77,33 @@ rsl_l1: lda $0200,x lda tokenise_work1 sta $0427 - + + ;; Check if the number is a valid line number + ;; i.e., 16 bits, no exponent, no decimal + lda basic_fac1_mantissa+2 + ora basic_fac1_mantissa+3 + ora basic_fac1_exponent + beq + +ml_bad_line_number: + ;; Syntax error + ldx #10 + jmp do_basic_error +* lda tokenise_work4 + cmp #$ff + beq ml_bad_line_number + + ;; Got a valid line number. + + ;; Copy to line number holder + lda basic_fac1_mantissa+0 + sta basic_line_number+0 + lda basic_fac1_mantissa+1 + sta basic_line_number+1 + + ;; Delete line if present + + ;; Insert new line if non-zero length not_a_line: - jsr ready_message - jmp basic_main_loop diff --git a/c64/basic/basic_warm_start.s b/c64/basic/basic_warm_start.s index c9f89540..a00620e1 100644 --- a/c64/basic/basic_warm_start.s +++ b/c64/basic/basic_warm_start.s @@ -1,6 +1,5 @@ ;; Clear screen etc, show READY prompt. basic_warm_start: - jsr ready_message jmp basic_main_loop diff --git a/c64/basic/cmd_new.s b/c64/basic/cmd_new.s new file mode 100644 index 00000000..b1743998 --- /dev/null +++ b/c64/basic/cmd_new.s @@ -0,0 +1,33 @@ + +cmd_new: + jsr basic_do_new + jmp basic_main_loop + +cmd_clr: + jsr basic_do_clr + jmp basic_main_loop + +basic_do_new: + ;; Setup pointers to memory storage + lda #<$0801 + sta basic_start_of_text_ptr+0 + lda >$0801 + sta basic_start_of_text_ptr+1 + sta basic_start_of_vars_ptr+1 + lda #<$0803 + sta basic_start_of_vars_ptr+0 + + ;; FALL THROUGH + +basic_do_clr: + ;; Clear variables, arrays and strings + lda basic_start_of_vars_ptr+0 + sta basic_start_of_arrays_ptr+0 + sta basic_start_of_free_space_ptr+0 + lda basic_start_of_vars_ptr+1 + sta basic_start_of_arrays_ptr+1 + sta basic_start_of_free_space_ptr+1 + + rts + + diff --git a/c64/basic/do_basic_error.s b/c64/basic/do_basic_error.s index 76db367d..c65e3045 100644 --- a/c64/basic/do_basic_error.s +++ b/c64/basic/do_basic_error.s @@ -4,6 +4,8 @@ do_basic_error: ;; "?" txa pha + lda #$0d + jsr $ffd2 lda #$3f jsr $ffd2 pla @@ -12,6 +14,7 @@ do_basic_error: ;; Error message text jsr print_packed_message + ;; A space between error name and word error lda #$20 jsr $ffd2 @@ -26,6 +29,6 @@ do_basic_error: jsr $ffd2 ;; XXX - Restore stack depth first? - + jmp basic_main_loop diff --git a/c64/basic/fac1_mul.s b/c64/basic/fac1_mul.s index 0a5ea84b..89425ea1 100644 --- a/c64/basic/fac1_mul.s +++ b/c64/basic/fac1_mul.s @@ -52,7 +52,7 @@ f1m10_l3: ;; All done, return clc rts - +* ;; Divide mantissa by two, and increment exponent jsr fac1_mantissa_div2 inc basic_fac1_exponent diff --git a/c64/basic/injest_number.s b/c64/basic/injest_number.s index b2a6d9fc..45042819 100644 --- a/c64/basic/injest_number.s +++ b/c64/basic/injest_number.s @@ -6,8 +6,38 @@ ;; after to produce normalised floating point number. ij_not_a_digit: - ;; XXX check for ".", "E", "+" and "-" + ;; XXX check for "." or "E" ;; Other chars terminate the accumulation. + + ;; Look for exponentiation marker + ;; XXX - Implement me! + ;; Probably should have a flag so that we know if we are accumulating + ;; exponent or mantissa digits + + ;; Look for decimal point + sta $0420 + cmp #$2e + bne ij_not_decimal + lda tokenise_work4 + cmp #$ff + beq ij_found_decimal + ;; More than one decimal point in a number means we have reached the end of the number + clc + rts + +ij_found_decimal: + ;; Found decimal. + ;; Thus start counting digits after the decimal, so that we + ;; can do the necessary number of divide by 10s on the final + ;; number. + lda #$00 + sta tokenise_work4 + + jmp ij_consider_next_digit + +ij_not_decimal: + + CLC RTS @@ -22,6 +52,17 @@ injest_number: ;; Check if leading char is a - sign ;; Note: the - will have been tokenised to $AB ;; XXX - implement + ldx tokenise_work1 + lda $0200,x + cmp #$AB + bne ij_not_minus + + ;; Set sign to negative + lda #$ff + sta basic_fac1_sign + +ij_not_minus: + ij_loop1: ldx tokenise_work1