Make relocatable

This commit is contained in:
Joshua Bell 2018-12-31 20:47:35 -08:00
parent 0310508579
commit 197d0dad90
1 changed files with 47 additions and 15 deletions

View File

@ -80,11 +80,7 @@ SSGINFO := $BEB4 ; Get/Set Info Parameter block
FIFILID := $BEB8 ; (set size to set=7 or get=$A) FIFILID := $BEB8 ; (set size to set=7 or get=$A)
FIAUXID := $BEB9 FIAUXID := $BEB9
FIMDATE := $BEBE FIMDATE := $BEBE
GETBUFR := $BEF5
;;; ============================================================
;;; TODO: Relocate into ProDOS-allocated buffer
;;; ============================================================ ;;; ============================================================
;; Save previous external command address ;; Save previous external command address
@ -93,18 +89,45 @@ FIMDATE := $BEBE
lda EXTRNCMD+2 lda EXTRNCMD+2
sta next_command+1 sta next_command+1
;; Install in external command address ;; Request a 1-page buffer
lda #<handler lda #1
sta EXTRNCMD+1 jsr GETBUFR
lda #>handler bcc :+
lda #$C ; NO BUFFERS AVAILABLE
rts
:
;; A = MSB of new page - update absolute addresses
;; (aligned to page boundary so only MSB changes)
sta page_num1
sta page_num2
sta page_num3
;; Install new address in external command address
sta EXTRNCMD+2 sta EXTRNCMD+2
lda #0
sta EXTRNCMD+1
;; Relocate
ldx #0
: lda handler,x
page_num3 := *+2
sta $2100,x ; self-modified
inx
bne :-
;; Complete
rts rts
;;; ============================================================ ;;; ============================================================
;;; Command Handler ;;; Command Handler
;;; ============================================================ ;;; ============================================================
handler: ;; Align handler to page boundary for easier
;; relocation
.res $2100 - *, 0
.proc handler
;; Check for this command, character by character. ;; Check for this command, character by character.
ldx #0 ldx #0
nxtchr: lda INBUF,x nxtchr: lda INBUF,x
@ -116,19 +139,21 @@ nxtchr: lda INBUF,x
bcs :+ bcs :+
and #$DF and #$DF
: cmp cmd,x page_num1 := *+2 ; address needing updating
: cmp command_string,x
bne not_ours bne not_ours
inx inx
cpx #cmdlen cpx #command_length
bne nxtchr bne nxtchr
;; A match - indicate end of command string for BI's parser. ;; A match - indicate end of command string for BI's parser.
lda #cmdlen-1 lda #command_length-1
sta XLEN sta XLEN
;; Point BI's parser at the command execution routine. ;; Point BI's parser at the command execution routine.
lda #<execute lda #<execute
sta XTRNADDR sta XTRNADDR
page_num2 := *+1 ; address needing updating
lda #>execute lda #>execute
sta XTRNADDR+1 sta XTRNADDR+1
@ -219,5 +244,12 @@ rts1: rts
;;; ============================================================ ;;; ============================================================
;;; Data ;;; Data
cmd: .byte "CHTYPE" ; Command string command_string:
cmdlen = *-cmd .byte "CHTYPE" ; Command string
command_length = *-command_string
.endproc
.assert .sizeof(handler) <= $100, error, "Must fit on one page"
page_num1 := handler::page_num1
page_num2 := handler::page_num2
next_command := handler::next_command