Fix chaining

This commit is contained in:
Joshua Bell 2019-06-18 22:10:49 -07:00
parent d115882280
commit 903cd4ff1e
3 changed files with 118 additions and 116 deletions

View File

@ -29,5 +29,6 @@ ROMIN2 := $C082
;;; Monitor ROM routines ;;; Monitor ROM routines
;;; ============================================================ ;;; ============================================================
HOME := $FC58
PRBYTE := $FDDA PRBYTE := $FDDA
COUT := $FDED COUT := $FDED

View File

@ -135,15 +135,6 @@ ERR_NETWORK_ERROR = $88
STORAGE_TYPE_MASK = $F0 STORAGE_TYPE_MASK = $F0
NAME_LENGTH_MASK = $0F NAME_LENGTH_MASK = $0F
;;; Volume Directory Block Header structure
.scope VolumeDirectoryBlockHeader
prev_block := $00
next_block := $02
entry_length := $23
entries_per_block := $24
header_length := $2B
.endscope
;;; Volume Directory Header structure ;;; Volume Directory Header structure
.struct VolumeDirectoryHeader .struct VolumeDirectoryHeader
prev_block .word prev_block .word

View File

@ -2,7 +2,10 @@
;;; Based on Glen E. Bredon's "RAM.DRV.SYSTEM" ;;; Based on Glen E. Bredon's "RAM.DRV.SYSTEM"
;;; Some details c/o http://boutillon.free.fr/Underground/Outils/Ram_Drv_System/Ram_Drv_System.html ;;; Some details c/o http://boutillon.free.fr/Underground/Outils/Ram_Drv_System/Ram_Drv_System.html
;;; ;;;
;;; Modifications to chain to next .SYSTEM file ;;; Modifications:
;;; * Chain to next .SYSTEM file dynamically
.feature string_escapes
.setcpu "6502" .setcpu "6502"
@ -21,18 +24,19 @@ zpproc_relay_addr := $2D0
PATHNAME := $280 PATHNAME := $280
data_buffer := $1800 ; I/O when chaining to next SYS file data_buf := $1C00 ; I/O when chaining to next SYS file
driver_target := $FF00 ; Install location in ProDOS driver_target := $FF00 ; Install location in ProDOS
kMaxUsableBanks = 24 ; Why is this capped so low??? kMaxUsableBanks = 24 ; Why is this capped so low???
; (driver has room for another ~20?) ; (driver has room for another ~20?)
SYS_ADDR := $2000 ; Load address for SYS files SYS_ADDR := $2000 ; Load address for SYS files
SYS_LEN = $BF00 - SYS_ADDR ; Maximum SYS file length SYS_LEN = $BF00 - SYS_ADDR ; Maximum SYS file length
;;; ============================================================ .define PRODUCT "RAMWorks RAM Disk"
;;; ============================================================
;; SYS files load at $2000; relocates self to $1000 ;; SYS files load at $2000; relocates self to $1000
.org SYS_ADDR .org SYS_ADDR
@ -42,70 +46,41 @@ SYS_LEN = $BF00 - SYS_ADDR ; Maximum SYS file length
.proc relocate .proc relocate
src := SYS_ADDR src := SYS_ADDR
dst := $1000
ldx #(sys_end - sys_start + $FF) / $100 ; pages ldx #(sys_end - sys_start + $FF) / $100 ; pages
ldy #0 ldy #0
load: lda src,y ; self-modified load: lda sys_start,y ; self-modified
load_hi := *-1 load_hi := *-1
sta dst,y ; self-modified sta dst_addr,y ; self-modified
store_hi := *-1 store_hi := *-1
iny iny
bne load bne load
inc load_hi inc load_hi
inc store_hi inc store_hi
dex dex
beq find_self_name ; done bne load
jmp load
jmp dst_addr
.endproc .endproc
;;; ============================================================ ;;; ============================================================
;;; Start of relocated code ;;; Start of relocated code
sys_start: sys_start:
pushorg dst_addr
;; Save most recent device for later, when chaining
;; to next .SYSTEM file.
lda DEVNUM
sta read_block_params_unit_num
jmp install_driver
;;; ============================================================ ;;; ============================================================
;;; Configuration Parameters ;;; Configuration Parameters
banks_to_reserve: .byte 0 ; banks to reserve (e.g. for AppleWorks) banks_to_reserve: .byte 0 ; banks to reserve (e.g. for AppleWorks)
unitnum: .byte $03 ; S3D1; could be $B for S3D2
slot: .byte 3 ; S3D1; could be $B for S3D2
;;; ============================================================
;;; Identify the name of this SYS file, which should be present at
;;; $280 with or without a path prefix. This is used when searching
;;; for the next .SYSTEM file to execute.
.proc find_self_name
;; Search pathname buffer backwards for '/', then
;; copy name into |self_name|; this is used later
;; to find/invoke the next .SYSTEM file.
;; Find '/' (which may not be present, prefix is optional)
lda #0
sta $A8
ldx PATHNAME
beq install_driver
floop: inc $A8
dex
beq copy_name
lda PATHNAME,x
eor #'/'
asl a
bne floop
;; Copy name into |self_name| buffer
copy_name:
ldy #0
cloop: iny
inx
lda PATHNAME,x
sta self_name,y
cpy $A8
bcc cloop
sty self_name
.endproc
;; Fall through...
;;; ============================================================ ;;; ============================================================
;;; Install the driver ;;; Install the driver
@ -275,7 +250,7 @@ break:
bmi L21F0 bmi L21F0
jmp do_install jmp do_install
fail: jmp do_chain fail: jmp install_failure
sloop: lda sig,x sloop: lda sig,x
set_sig: set_sig:
@ -389,14 +364,14 @@ copy_driver:
cpy #sizeof_driver cpy #sizeof_driver
bcc :- bcc :-
;; Check if slot already has a device ;; Check if unitnum already has a device
ldy DEVCNT ldy DEVCNT
: lda DEVLST,y : lda DEVLST,y
lsr a lsr a
lsr a lsr a
lsr a lsr a
lsr a lsr a
cmp slot cmp unitnum
beq install_device beq install_device
dey dey
bpl :- bpl :-
@ -412,7 +387,7 @@ copy_driver:
;; Install device in ProDOS via DEVLST/DEVADR. ;; Install device in ProDOS via DEVLST/DEVADR.
;; (Y has index in DEVLST) ;; (Y has index in DEVLST)
install_device: install_device:
lda slot lda unitnum
asl a asl a
tax tax
asl a asl a
@ -424,7 +399,7 @@ install_device:
copy16 #(driver_target+1), DEVADR,x copy16 #(driver_target+1), DEVADR,x
;; Did we install into S3D2? ;; Did we install into S3D2?
lda slot lda unitnum
cmp #$0B ; Slot 3 Drive 2 cmp #$0B ; Slot 3 Drive 2
beq finish beq finish
@ -456,8 +431,8 @@ finish: bit ROMIN2
ldx #$00 ldx #$00
lda on_line_params_buffer lda on_line_params_buffer
ora L239F ora L239F
bne do_chain bne install_success
bcc do_chain bcc install_success
copy #$FF, L239F copy #$FF, L239F
sta ALTZPON sta ALTZPON
copy driver_bank_list, BANKSEL copy driver_bank_list, BANKSEL
@ -466,8 +441,24 @@ finish: bit ROMIN2
stx vol_dir_header+VolumeDirectoryHeader::total_blocks stx vol_dir_header+VolumeDirectoryHeader::total_blocks
jmp install_driver ; retry??? jmp install_driver ; retry???
do_chain: install_success:
sta ALTZPOFF sta ALTZPOFF
jsr HOME
jsr zstrout
scrcode "\r\r\r", PRODUCT, " - Installed"
.byte 0
jmp launch_next_sys_file
install_failure:
sta ALTZPOFF
jsr HOME
jsr zstrout
scrcode "\r\r\r", PRODUCT, " - Not Installed"
.byte 0
jmp launch_next_sys_file jmp launch_next_sys_file
;;; ============================================================ ;;; ============================================================
@ -735,6 +726,11 @@ bank_list:
;;; Find and invoke the next .SYSTEM file ;;; Find and invoke the next .SYSTEM file
.proc launch_next_sys_file .proc launch_next_sys_file
ptr := $A5
num := $A7
len := $A8
;; --------------------------------------------------
;; Update reset vector - now terminates. ;; Update reset vector - now terminates.
lda #<quit lda #<quit
sta $03F2 sta $03F2
@ -743,24 +739,51 @@ bank_list:
eor #$A5 eor #$A5
sta $03F4 sta $03F4
ptr := $A5 ;; --------------------------------------------------
num := $A7 ;; Identify the name of this SYS file, which should be present at
len := $A8 ;; $280 with or without a path prefix. Search pathname buffer
;; backwards for '/', then copy name into |self_name|.
lda DEVNUM ; stick with most recent device ;; Find '/' (which may not be present, prefix is optional)
sta read_block_params_unit_num lda #0
sta len
ldx PATHNAME
beq read_dir
floop: inc len
dex
beq copy_name
lda PATHNAME,x
eor #'/'
asl a
bne floop
;; Copy name into |self_name| buffer
copy_name:
ldy #0
cloop: iny
inx
lda PATHNAME,x
sta self_name,y
cpy len
bcc cloop
sty self_name
;; --------------------------------------------------
;; Read directory and look for .SYSTEM files; find this
;; one, and invoke the following one.
read_dir:
jsr read_block jsr read_block
lda data_buffer + VolumeDirectoryBlockHeader::entry_length lda data_buf + VolumeDirectoryHeader::entry_length
sta entry_length_mod sta entry_length_mod
lda data_buffer + VolumeDirectoryBlockHeader::entries_per_block lda data_buf + VolumeDirectoryHeader::entries_per_block
sta entries_per_block_mod sta entries_per_block_mod
lda #1 lda #1
sta num sta num
lda #<(data_buffer + VolumeDirectoryBlockHeader::header_length) lda #<(data_buf + .sizeof(VolumeDirectoryHeader))
sta ptr sta ptr
lda #>(data_buffer + VolumeDirectoryBlockHeader::header_length) lda #>(data_buf + .sizeof(VolumeDirectoryHeader))
sta ptr+1 sta ptr+1
;; Process directory entry ;; Process directory entry
@ -780,11 +803,11 @@ entry: ldy #FileEntry::file_type ; file_type
;; Compare suffix - is it .SYSTEM? ;; Compare suffix - is it .SYSTEM?
ldx suffix ldx suffix
: lda (ptr),y : lda (ptr),y
cmp suffix+1,x cmp suffix,x
bne next bne next
dey dey
dex dex
bpl :- bne :-
;; Yes; is it *this* .SYSTEM file? ;; Yes; is it *this* .SYSTEM file?
ldy self_name ldy self_name
@ -812,18 +835,18 @@ next: lda ptr
entries_per_block_mod := *-1 entries_per_block_mod := *-1
bcc entry bcc entry
lda data_buffer + VolumeDirectoryBlockHeader::next_block lda data_buf + VolumeDirectoryHeader::next_block
sta read_block_params_block_num sta read_block_params_block_num
lda data_buffer + VolumeDirectoryBlockHeader::next_block + 1 lda data_buf + VolumeDirectoryHeader::next_block + 1
sta read_block_params_block_num+1 sta read_block_params_block_num+1
ora read_block_params_block_num ora read_block_params_block_num
beq not_found ; last block has next=0 beq not_found ; last block has next=0
jsr read_block jsr read_block
lda #0 lda #0
sta num sta num
lda #<(data_buffer + $04) lda #<(data_buf + $04)
sta ptr sta ptr
lda #>(data_buffer + $04) lda #>(data_buf + $04)
sta ptr+1 sta ptr+1
jmp entry jmp entry
@ -857,7 +880,9 @@ append: ldy #0
not_found: not_found:
jsr zstrout jsr zstrout
scrcode "\r\r\r* Unable to find next '.SYSTEM' file *\r" scrcode "\r\r* Unable to find next '.SYSTEM' file *\r"
.byte 0
bit KBDSTRB bit KBDSTRB
: lda KBD : lda KBD
bpl :- bpl :-
@ -935,13 +960,7 @@ lowercase_mask:
.byte 0 ; crash if QUIT fails .byte 0 ; crash if QUIT fails
rts rts
.proc quit_params DEFINE_QUIT_PARAMS quit_params
.byte 4 ; param_count
.byte 0 ; quit_type
.word 0000 ; reserved
.byte 0 ; reserved
.word 0000 ; reserved
.endproc
.endproc .endproc
;;; ------------------------------------------------------------ ;;; ------------------------------------------------------------
@ -953,12 +972,8 @@ lowercase_mask:
rts rts
.endproc .endproc
.proc read_block_params ;; block 2 is volume directory
.byte 3 ; param_count DEFINE_READ_BLOCK_PARAMS read_block_params, data_buf, 2
unit_num: .byte $60 ; unit_num
.addr data_buffer ; data_buffer
block_num: .word 2 ; block_num - block 2 is volume directory
.endproc
read_block_params_unit_num := read_block_params::unit_num read_block_params_unit_num := read_block_params::unit_num
read_block_params_block_num := read_block_params::block_num read_block_params_block_num := read_block_params::block_num
@ -987,11 +1002,16 @@ block_num: .word 2 ; block_num - block 2 is volume directory
.proc on_error .proc on_error
pha pha
jsr zstrout jsr zstrout
scrcode "\r\r\r** Disk Error $" scrcode "\r\r* Disk Error $"
.byte 0
pla pla
jsr PRBYTE jsr PRBYTE
jsr zstrout jsr zstrout
scrcode " **\r" scrcode " *\r"
.byte 0
bit KBDSTRB bit KBDSTRB
: lda KBD : lda KBD
bpl :- bpl :-
@ -1001,27 +1021,13 @@ block_num: .word 2 ; block_num - block 2 is volume directory
;;; ------------------------------------------------------------ ;;; ------------------------------------------------------------
.proc open_params DEFINE_OPEN_PARAMS open_params, PATHNAME, data_buf
.byte 3 ; param_count
.addr PATHNAME ; pathname
.addr data_buffer ; io_buffer
ref_num:.byte 1 ; ref_num
.endproc
open_params_ref_num := open_params::ref_num open_params_ref_num := open_params::ref_num
.proc read_params DEFINE_READ_PARAMS read_params, SYS_ADDR, SYS_LEN
.byte 4 ; param_count
ref_num:.byte 1 ; ref_num
.addr SYS_ADDR ; data_buffer
.word SYS_LEN ; request_count
.word 0 ; trans_count
.endproc
read_params_ref_num := read_params::ref_num read_params_ref_num := read_params::ref_num
.proc close_params DEFINE_CLOSE_PARAMS close_params
.byte 1 ; param_count
ref_num:.byte 0 ; ref_num
.endproc
;;; ============================================================ ;;; ============================================================
;;; Data ;;; Data
@ -1032,9 +1038,6 @@ suffix:
found_self_flag: found_self_flag:
.byte 0 .byte 0
;;; ============================================================
;;; End of relocated code
sys_end:
;;; ============================================================ ;;; ============================================================
;;; Scratch space beyond code used during install ;;; Scratch space beyond code used during install
@ -1046,3 +1049,10 @@ map2 := *+2+$80 ; len: $80
stash_00 := *+2+$100 ; len: $80 stash_00 := *+2+$100 ; len: $80
stash_01 := *+2+$180 ; len: $80 stash_01 := *+2+$180 ; len: $80
self_name := *+2+$200 ; len: 65 self_name := *+2+$200 ; len: 65
.assert self_name + 64 < data_buf, error, "Too long"
;;; ============================================================
;;; End of relocated code
poporg
sys_end: