begin implementing basic text manipulation routines.
This commit is contained in:
1 parent
6d57d17b74
commit
5358743318
7 files changed
+149
-1
No files matched your search
@@ -25,6 +25,7 @@
|
|||||||
.alias basic_start_of_free_space_ptr $31
|
.alias basic_start_of_free_space_ptr $31
|
||||||
.alias basic_start_of_strings_ptr $33
|
.alias basic_start_of_strings_ptr $33
|
||||||
.alias basic_top_of_memory_ptr $37
|
.alias basic_top_of_memory_ptr $37
|
||||||
|
.alias basic_current_line_ptr $3d
|
||||||
|
|
||||||
.alias basic_numeric_work_area $57 ; $57 - $60 inclusive = 10 bytes
|
.alias basic_numeric_work_area $57 ; $57 - $60 inclusive = 10 bytes
|
||||||
|
|
||||||
@@ -115,3 +116,15 @@
|
|||||||
.alias enable_case_switch $0291
|
.alias enable_case_switch $0291
|
||||||
.alias screen_scroll_disable $0292
|
.alias screen_scroll_disable $0292
|
||||||
.alias pal_or_ntsc $02A6
|
.alias pal_or_ntsc $02A6
|
||||||
|
|
||||||
|
|
||||||
|
;; BASIC uses some extra bytes for memory access under ROMs located at $2A7 onwards
|
||||||
|
;; IRQs are disabled when doing such accesses, and a default NMI handler only increments
|
||||||
|
;; a counter, so that if an NMI occurs, it doesn't crash the machine, but can be captured.
|
||||||
|
.alias missed_nmi_flag $2A7
|
||||||
|
.alias tiny_nmi_handler $2A8
|
||||||
|
.alias peek_under_roms tiny_nmi_handler+peek_under_roms_routine-tiny_nmi_handler_routine
|
||||||
|
.alias poke_under_roms tiny_nmi_handler+poke_under_roms_routine-tiny_nmi_handler_routine
|
||||||
|
.alias memmap_allram tiny_nmi_handler+memmap_allram_routine-tiny_nmi_handler_routine
|
||||||
|
.alias memmap_normal tiny_nmi_handler+memmap_normal_routine-tiny_nmi_handler_routine
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
;; Delete the current BASIC line, which is assumed to have already
|
||||||
|
;; been found with basic_find_line.
|
||||||
|
;; Really only consists of copying memory down.
|
||||||
|
;; The only complication is that we have to do the copy with ROMs
|
||||||
|
;; banked out. Oh, yes, and we have to update all the links in
|
||||||
|
;; the following basic lines.
|
||||||
|
basic_delete_line:
|
||||||
|
sec
|
||||||
|
rts
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
;; Find the BASIC line with number basic_line_number
|
||||||
|
|
||||||
|
|
||||||
|
basic_find_line:
|
||||||
|
;; Get pointer to start of BASIC text
|
||||||
|
lda basic_start_of_text_ptr+0
|
||||||
|
sta basic_current_line_ptr+0
|
||||||
|
lda basic_start_of_text_ptr+1
|
||||||
|
sta basic_current_line_ptr+1
|
||||||
|
|
||||||
|
basic_find_line_loop:
|
||||||
|
;; Then search for line number
|
||||||
|
;; Line number
|
||||||
|
ldy #2
|
||||||
|
ldx #<basic_current_line_ptr
|
||||||
|
jsr peek_under_roms
|
||||||
|
cmp basic_line_number+0
|
||||||
|
bne not_this_line
|
||||||
|
iny
|
||||||
|
jsr peek_under_roms
|
||||||
|
cmp basic_line_number+1
|
||||||
|
bne not_this_line
|
||||||
|
|
||||||
|
clc
|
||||||
|
rts
|
||||||
|
not_this_line:
|
||||||
|
;; Not this line, so advance to next line
|
||||||
|
ldy #0
|
||||||
|
ldx #<basic_current_line_ptr
|
||||||
|
jsr peek_under_roms
|
||||||
|
bne more_lines_exist
|
||||||
|
iny
|
||||||
|
jsr peek_under_roms
|
||||||
|
bne more_lines_exist
|
||||||
|
;; no more lines exist, return failure
|
||||||
|
sec
|
||||||
|
rts
|
||||||
|
more_lines_exist:
|
||||||
|
;; A = high byte of line
|
||||||
|
pha
|
||||||
|
dey
|
||||||
|
jsr peek_under_roms
|
||||||
|
sta basic_current_line_ptr+0
|
||||||
|
pla
|
||||||
|
sta basic_current_line_ptr+1
|
||||||
|
jmp basic_find_line_loop
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
;; Insert the tokenised line stored at $0200.
|
||||||
|
;; First work out where in the list to put it
|
||||||
|
;; (basic_find_line with the line number can be used to work
|
||||||
|
;; out the insertion point, as it should abort once it finds a
|
||||||
|
;; line number too high).
|
||||||
|
;; Then all we have to do is push the rest of the BASIC text up,
|
||||||
|
;; and update the pointers in all following basic lines.
|
||||||
|
basic_insert_line:
|
||||||
|
sec
|
||||||
|
rts
|
||||||
|
|
||||||
@@ -91,6 +91,12 @@ ml_bad_line_number:
|
|||||||
|
|
||||||
;; Got a valid line number.
|
;; Got a valid line number.
|
||||||
|
|
||||||
|
;; First, clear all variables, so that we only have to shove BASIC text around.
|
||||||
|
;; (We could later remove this requirement, and the only effect should be
|
||||||
|
;; to slow things down, and that you might have to either CLR if there is no
|
||||||
|
;; memory free, or else it would auto CLR when you ran out of program space).
|
||||||
|
jsr basic_do_clr
|
||||||
|
|
||||||
;; Copy to line number holder
|
;; Copy to line number holder
|
||||||
lda basic_fac1_mantissa+0
|
lda basic_fac1_mantissa+0
|
||||||
sta basic_line_number+0
|
sta basic_line_number+0
|
||||||
@@ -98,8 +104,12 @@ ml_bad_line_number:
|
|||||||
sta basic_line_number+1
|
sta basic_line_number+1
|
||||||
|
|
||||||
;; Delete line if present
|
;; Delete line if present
|
||||||
|
jsr basic_find_line
|
||||||
|
bcs +
|
||||||
|
jsr basic_delete_line
|
||||||
|
*
|
||||||
;; Insert new line if non-zero length
|
;; Insert new line if non-zero length
|
||||||
|
jsr basic_insert_line
|
||||||
|
|
||||||
not_a_line:
|
not_a_line:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
;; Clear screen etc, show READY prompt.
|
;; Clear screen etc, show READY prompt.
|
||||||
|
|
||||||
basic_warm_start:
|
basic_warm_start:
|
||||||
|
jsr install_ram_routines
|
||||||
|
|
||||||
jmp basic_main_loop
|
jmp basic_main_loop
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
;; IMPORTANT:
|
||||||
|
;; These routines lengths cannot be changed without changing
|
||||||
|
;; the aliases for peek_under_roms, poke_under_roms etc
|
||||||
|
;; in ,aliases.s.
|
||||||
|
;; Thus those addresses are expressed using formulae.
|
||||||
|
|
||||||
|
install_ram_routines:
|
||||||
|
;; Copy routines into place
|
||||||
|
ldx #ram_routines_len-1
|
||||||
|
*
|
||||||
|
lda ram_routines_start,x
|
||||||
|
sta tiny_nmi_handler,x
|
||||||
|
dex
|
||||||
|
bpl -
|
||||||
|
|
||||||
|
;; Point NMI handler to tiny_nmi_handler
|
||||||
|
lda #<tiny_nmi_handler
|
||||||
|
sta $FFFE
|
||||||
|
lda #>tiny_nmi_handler
|
||||||
|
sta $FFFF
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
ram_routines_start:
|
||||||
|
|
||||||
|
tiny_nmi_handler_routine:
|
||||||
|
inc missed_nmi_flag
|
||||||
|
rti
|
||||||
|
|
||||||
|
peek_under_roms_routine:
|
||||||
|
stx peek_under_roms+7 ;Offset of arg of lda ($00),y
|
||||||
|
jsr memmap_allram
|
||||||
|
lda ($00),y
|
||||||
|
jmp memmap_normal
|
||||||
|
|
||||||
|
poke_under_roms_routine:
|
||||||
|
stx poke_under_roms+7 ;Offset of arg of lda ($00),y
|
||||||
|
jsr memmap_allram
|
||||||
|
sta ($00),y
|
||||||
|
;; FALL THROUGH
|
||||||
|
memmap_normal_routine:
|
||||||
|
pha
|
||||||
|
lda #$37
|
||||||
|
sta $01
|
||||||
|
pla
|
||||||
|
cli
|
||||||
|
rts
|
||||||
|
|
||||||
|
memmap_allram_routine:
|
||||||
|
sei
|
||||||
|
lda #$04
|
||||||
|
sta $01
|
||||||
|
rts
|
||||||
|
|
||||||
|
ram_routines_end:
|
||||||
|
.alias ram_routines_len ram_routines_end-ram_routines_start
|
||||||
|
|
||||||
Reference in new issue
Block a user