2021-07-17 16:59:17 +00:00
|
|
|
;
|
|
|
|
; HFS boot. Boot block.
|
|
|
|
; This is stage 0 of the bootloader. It will find a file named
|
|
|
|
; '!' in the root directory of an HFS volume, load it, and execute it
|
|
|
|
; in full 16-bit mode, with a = prodos block call vector.
|
|
|
|
;
|
|
|
|
; this currently only works with 512-byte blocks (max volume size = 64M)
|
|
|
|
; but there's enough room to support variable block sizes.
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
include 'hfs.aii'
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
string asis
|
|
|
|
blanks on
|
|
|
|
|
2021-07-17 21:01:49 +00:00
|
|
|
; smartport doesn't currently work ($28 no drive error because the unit isn't setup correctly?)
|
|
|
|
__smartport__ set 0
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
zp record 0
|
|
|
|
slot ds.w 1
|
2021-07-17 16:59:17 +00:00
|
|
|
;vector ds.w 1
|
2021-07-17 16:10:06 +00:00
|
|
|
|
|
|
|
offset ds.w 1
|
|
|
|
bnum ds.w 1
|
|
|
|
count ds.w 1
|
|
|
|
extents ds.b 3*HFSExtentDescriptor.sizeof
|
|
|
|
|
|
|
|
endr
|
|
|
|
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
sp record $20
|
|
|
|
ReadBlock equ $01
|
|
|
|
pcount ds.b 1
|
|
|
|
unit ds.b 1
|
|
|
|
buffer ds.w 1
|
|
|
|
block ds.l 1 ; actually 24-bit
|
|
|
|
endr
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
pro record $42
|
|
|
|
cmd ds.b 1
|
|
|
|
unit ds.b 1
|
|
|
|
buffer ds.b 2
|
|
|
|
block ds.b 2
|
|
|
|
endr
|
|
|
|
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
data record $2000
|
|
|
|
ds.b 512
|
|
|
|
endr
|
|
|
|
|
|
|
|
|
|
|
|
entry read_block, read_block_abs, read_extent_block
|
2021-07-17 16:59:17 +00:00
|
|
|
entry vector
|
2021-07-17 16:10:06 +00:00
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
boot proc
|
2021-07-17 16:10:06 +00:00
|
|
|
longi off
|
|
|
|
longa off
|
2021-07-17 04:21:31 +00:00
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
with zp
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
dc.b $01 ; prodos boot id :D
|
|
|
|
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
stx sp.unit
|
|
|
|
else
|
2021-07-17 16:10:06 +00:00
|
|
|
stx pro.unit
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
2021-07-17 16:10:06 +00:00
|
|
|
txa
|
|
|
|
lsr a
|
|
|
|
lsr a
|
|
|
|
lsr a
|
|
|
|
lsr a
|
|
|
|
ora #$c0
|
|
|
|
sta vector+1
|
|
|
|
sta slot+1
|
|
|
|
stz slot
|
|
|
|
; check for prodos block-device signature bytes
|
|
|
|
; todo -- switch to extended smartport? needed for second stage.
|
2021-07-17 16:59:17 +00:00
|
|
|
; xx $20 xx $00 xx $03 [xx $00 - smarport ]
|
2021-07-17 16:10:06 +00:00
|
|
|
ldy #1
|
|
|
|
lda (slot),y
|
|
|
|
cmp #$20
|
|
|
|
bne noboot
|
|
|
|
ldy #3
|
|
|
|
lda (slot),y
|
|
|
|
bne noboot
|
|
|
|
ldy #5
|
2021-07-17 16:59:17 +00:00
|
|
|
lda (slot),y
|
|
|
|
cmp #$03
|
2021-07-17 16:10:06 +00:00
|
|
|
bne noboot
|
2021-07-17 21:01:49 +00:00
|
|
|
|
|
|
|
if __smartport__ then
|
|
|
|
ldy #7
|
|
|
|
lda (slot),y
|
|
|
|
bne noboot
|
|
|
|
; ,$fb = smartport id byte which indicates if extended. not needed (yet)
|
|
|
|
endif
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
ldy #$ff
|
|
|
|
lda (slot),y
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
inc a
|
|
|
|
inc a
|
|
|
|
inc a
|
|
|
|
endif
|
2021-07-17 16:10:06 +00:00
|
|
|
sta vector
|
|
|
|
bra ok
|
|
|
|
|
2021-07-17 21:01:49 +00:00
|
|
|
; not a prodos/smartport device.
|
2021-07-17 16:10:06 +00:00
|
|
|
noboot brk $ea
|
|
|
|
|
|
|
|
ok
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
lda #3
|
|
|
|
sta sp.pcount
|
|
|
|
else
|
2021-07-17 16:10:06 +00:00
|
|
|
lda #1 ; prodos read block
|
|
|
|
sta pro.cmd
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
clc
|
2021-07-17 16:10:06 +00:00
|
|
|
xce
|
|
|
|
rep #$30
|
|
|
|
longi on
|
|
|
|
longa on
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
stz offset
|
|
|
|
stz bnum
|
|
|
|
stz count
|
|
|
|
lda #data
|
2021-07-17 21:01:49 +00:00
|
|
|
|
|
|
|
if __smartport__ then
|
|
|
|
sta sp.buffer
|
|
|
|
; stz sp.block ; will overwrite
|
|
|
|
stz sp.block+2
|
|
|
|
else
|
2021-07-17 16:10:06 +00:00
|
|
|
sta pro.buffer
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
2021-07-17 16:10:06 +00:00
|
|
|
lda #2
|
|
|
|
jsr read_block_abs
|
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
;
|
2021-07-17 16:10:06 +00:00
|
|
|
; assumes 512-byte blocks (max size = 64MB)
|
2021-07-17 04:21:31 +00:00
|
|
|
;
|
|
|
|
; wait a minute... max 65535 blocks, therefore high word of allocation block, etc, always 0.
|
2021-07-17 16:10:06 +00:00
|
|
|
; i assume hfs use 32-bit links in the btree for in-memory use (24-bit or 32 pointers)
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
;
|
|
|
|
; search for a file named ! in the root directory.
|
|
|
|
; ! is ascii char $21 so it should sort early.
|
|
|
|
;
|
|
|
|
;
|
2021-07-17 16:10:06 +00:00
|
|
|
with HFSMasterDirectoryBlock
|
|
|
|
lda data+drAlBlSt
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
|
|
|
sta offset
|
|
|
|
|
2021-07-17 16:59:17 +00:00
|
|
|
ldx #3*HFSExtentDescriptor.sizeof-2
|
|
|
|
@cloop lda data+drCTExtRec,x
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
2021-07-17 16:59:17 +00:00
|
|
|
sta extents,x
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
bpl @cloop
|
2021-07-17 16:10:06 +00:00
|
|
|
endwith
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
; lda offset
|
|
|
|
; clc
|
2021-07-17 16:10:06 +00:00
|
|
|
; adc extents
|
|
|
|
lda extents
|
2021-07-17 04:21:31 +00:00
|
|
|
jsr read_block
|
|
|
|
|
|
|
|
;
|
|
|
|
; block should be a btree header block. find the first leaf node.
|
|
|
|
;
|
2021-07-17 16:10:06 +00:00
|
|
|
with BTHeaderRec
|
|
|
|
; lda data+BTNodeDescriptor.sizeof+firstLeafNode
|
|
|
|
; xba
|
|
|
|
; sta leaf+2
|
|
|
|
lda data+BTNodeDescriptor.sizeof+firstLeafNode+2
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
2021-07-17 16:10:06 +00:00
|
|
|
; sta bnum
|
|
|
|
|
|
|
|
endwith
|
2021-07-17 04:21:31 +00:00
|
|
|
;
|
|
|
|
; assert leaf < # allocated lbocks?
|
|
|
|
;
|
|
|
|
;lda leaf
|
2021-07-17 16:10:06 +00:00
|
|
|
; s/b leaf + cat extent + offset; todo - this offset is in terms of the catalog extent
|
|
|
|
jsr read_extent_block
|
2021-07-17 04:21:31 +00:00
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
lda data+BTNodeDescriptor.numRecords ; # of records
|
2021-07-18 01:24:28 +00:00
|
|
|
beq advance
|
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
|
|
|
sta count
|
|
|
|
|
|
|
|
again
|
|
|
|
ldx #512-2 ; last entry
|
|
|
|
@loop
|
2021-07-17 16:59:17 +00:00
|
|
|
lda data,x ; entry offset
|
|
|
|
xba
|
2021-07-17 04:21:31 +00:00
|
|
|
tay
|
2021-07-17 16:10:06 +00:00
|
|
|
lda data+HFSCatalogKey.parentID,y ; parent id
|
2021-07-17 04:21:31 +00:00
|
|
|
bne notfound
|
2021-07-17 16:10:06 +00:00
|
|
|
lda data+HFSCatalogKey.parentID+2,y
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
|
|
|
cmp #2
|
|
|
|
blt @next
|
|
|
|
beq @name
|
|
|
|
bge notfound
|
|
|
|
@name ; name is a p-string.
|
2021-07-17 16:10:06 +00:00
|
|
|
lda data+HFSCatalogKey.nodeName,y
|
|
|
|
cmp #$2101 ; pstr !
|
|
|
|
beq found
|
2021-07-17 04:21:31 +00:00
|
|
|
bge notfound
|
2021-07-17 16:10:06 +00:00
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
@next dex
|
|
|
|
dex
|
|
|
|
dec count
|
|
|
|
bne @loop
|
|
|
|
advance ; next block!
|
2021-07-17 16:10:06 +00:00
|
|
|
lda data+BTNodeDescriptor.fLink+2
|
2021-07-17 04:21:31 +00:00
|
|
|
beq notfound
|
|
|
|
xba
|
2021-07-17 16:10:06 +00:00
|
|
|
jsr read_extent_block
|
2021-07-17 04:21:31 +00:00
|
|
|
bra again
|
|
|
|
|
|
|
|
notfound
|
|
|
|
brk $ea
|
|
|
|
|
|
|
|
found
|
|
|
|
; y = offset in block
|
|
|
|
;
|
|
|
|
; only works with contiguous files....
|
|
|
|
; first block?
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
; 8 is magic offset for a key named !
|
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
; assume < 65535 bytes :)
|
2021-07-17 16:10:06 +00:00
|
|
|
with HFSCatalogFile
|
|
|
|
lda data+8+recordType,y
|
|
|
|
and #$00ff
|
|
|
|
cmp #kHFSFileRecord
|
|
|
|
bne notfound
|
|
|
|
|
|
|
|
lda data+8+dataPhysicalSize+2,y
|
2021-07-17 04:21:31 +00:00
|
|
|
; xba
|
|
|
|
lsr a ; >>9 since already xba
|
|
|
|
and #%01111111
|
|
|
|
beq notfound
|
|
|
|
sta count
|
2021-07-17 16:59:17 +00:00
|
|
|
|
|
|
|
; todo -- all extents...
|
2021-07-17 16:10:06 +00:00
|
|
|
lda data+8+dataExtents,y
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
2021-07-17 16:10:06 +00:00
|
|
|
sta extents
|
|
|
|
lda data+8+dataExtents+2,y
|
2021-07-17 04:21:31 +00:00
|
|
|
xba
|
2021-07-17 16:10:06 +00:00
|
|
|
sta extents+2
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
; now load the blocks and
|
|
|
|
lda #$2000
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
sta sp.buffer
|
|
|
|
else
|
2021-07-17 16:10:06 +00:00
|
|
|
sta pro.buffer
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
2021-07-17 16:10:06 +00:00
|
|
|
stz bnum
|
2021-07-17 04:21:31 +00:00
|
|
|
@loop
|
2021-07-17 16:10:06 +00:00
|
|
|
lda bnum
|
|
|
|
jsr read_extent_block
|
|
|
|
inc bnum
|
2021-07-17 04:21:31 +00:00
|
|
|
lda #512
|
|
|
|
clc
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
adc sp.buffer
|
|
|
|
sta sp.buffer
|
|
|
|
else
|
2021-07-17 16:10:06 +00:00
|
|
|
adc pro.buffer
|
|
|
|
sta pro.buffer
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
2021-07-17 04:21:31 +00:00
|
|
|
dec count
|
|
|
|
bne @loop
|
|
|
|
|
2021-07-17 21:01:49 +00:00
|
|
|
ldx slot
|
|
|
|
ldy vector
|
|
|
|
if __smartport__ then
|
|
|
|
lda sp.unit
|
|
|
|
else
|
|
|
|
lda pro.unit
|
|
|
|
endif
|
|
|
|
and #$00ff
|
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
jmp $2000 ; kiss of life.
|
|
|
|
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
read_block proc
|
|
|
|
entry read_block_abs
|
2021-07-17 16:59:17 +00:00
|
|
|
entry vector
|
2021-07-17 16:10:06 +00:00
|
|
|
|
|
|
|
; input
|
|
|
|
; a = hfs block #
|
|
|
|
; will be adjusted for allocation block offset
|
|
|
|
;
|
|
|
|
with zp
|
|
|
|
clc
|
|
|
|
adc offset
|
|
|
|
|
|
|
|
read_block_abs
|
2021-07-17 16:59:17 +00:00
|
|
|
;
|
|
|
|
; based on testing, this drops into emulation mode, so do it and recover.
|
|
|
|
;
|
2021-07-17 21:01:49 +00:00
|
|
|
|
|
|
|
if __smartport__ then
|
|
|
|
sta sp.block
|
|
|
|
else
|
2021-07-17 16:10:06 +00:00
|
|
|
sta pro.block
|
2021-07-17 21:01:49 +00:00
|
|
|
endif
|
|
|
|
|
2021-07-17 16:59:17 +00:00
|
|
|
php
|
|
|
|
sec
|
|
|
|
xce
|
|
|
|
dc.b $20 ; jsr
|
|
|
|
vector dc.w $ffff
|
2021-07-17 21:01:49 +00:00
|
|
|
if __smartport__ then
|
|
|
|
dc.b sp.ReadBlock
|
|
|
|
dc.w sp
|
|
|
|
endif
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
bcs @fail
|
2021-07-17 16:59:17 +00:00
|
|
|
xce
|
|
|
|
plp
|
2021-07-17 16:10:06 +00:00
|
|
|
rts
|
|
|
|
@fail brk $ea
|
|
|
|
endp
|
|
|
|
|
|
|
|
read_extent_block proc
|
|
|
|
; a = block #
|
|
|
|
|
|
|
|
; This doesn't check beyond the 3rd extent
|
|
|
|
|
|
|
|
with zp,HFSExtentDescriptor
|
|
|
|
|
|
|
|
@0
|
|
|
|
cmp extents+0+blockCount
|
|
|
|
bcs @1
|
|
|
|
; clc
|
|
|
|
adc extents+0+startBlock
|
|
|
|
bra read_block
|
|
|
|
|
|
|
|
@1 sbc extents+0+blockCount
|
|
|
|
cmp extents+4+blockCount
|
|
|
|
bcs @2
|
|
|
|
; clc
|
|
|
|
adc extents+4+startBlock
|
|
|
|
bra read_block
|
|
|
|
|
|
|
|
@2 sbc extents+4+blockCount
|
|
|
|
cmp extents+8+blockCount
|
|
|
|
bcs @3
|
|
|
|
adc extents+8+startBlock
|
|
|
|
bra read_block
|
|
|
|
|
|
|
|
@3 brk $ea
|
|
|
|
endp
|
|
|
|
|
2021-07-17 04:21:31 +00:00
|
|
|
|
|
|
|
|
2021-07-17 16:10:06 +00:00
|
|
|
end
|