improvements and successful assembly. current size = 273 bytes.

This commit is contained in:
Kelvin Sherlock 2021-07-17 12:10:06 -04:00
parent 371780b11b
commit 5b6539a99d
2 changed files with 198 additions and 66 deletions

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
bootblock : bootblock.omf
mpw makebiniigs -org 2048 bootblock.omf -o bootblock
bootblock.omf : bootblock.obj
mpw linkiigs bootblock.obj -o bootblock.omf
bootblock.obj : bootblock.aii hfs.aii
mpw asmiigs bootblock.aii -o bootblock.obj

View File

@ -1,79 +1,145 @@
include 'hfs.aii' include 'hfs.aii'
string asis
blanks on
zp record 0
slot ds.w 1
vector ds.w 1
offset ds.w 1
bnum ds.w 1
count ds.w 1
extents ds.b 3*HFSExtentDescriptor.sizeof
endr
pro record $42
cmd ds.b 1
unit ds.b 1
buffer ds.b 2
block ds.b 2
endr
data record $2000
ds.b 512
endr
entry read_block, read_block_abs, read_extent_block
boot proc boot proc
longi off
longa off
with zp
dc.b $01 ; prodos boot id :D
stx pro.unit
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.
ldy #1
lda (slot),y
cmp #$20
bne noboot
ldy #3
lda (slot),y
bne noboot
ldy #5
bne noboot
; smartport - ,7 = 00
ldy #$ff
lda (slot),y
sta vector
bra ok
noboot brk $ea
ok
lda #1 ; prodos read block
sta pro.cmd
clc
xce
rep #$30
longi on
longa on
stz offset stz offset
stz bnum
stz count
lda #data
sta pro.buffer
lda #2 lda #2
jsr read_block jsr read_block_abs
endp
read_block proc
; input
; a = hfs block #
; will be adjusted for allocation block offset
;
clc
adc offset
sta block
phx
phy
ply
plx
rts
endp
findit proc
; ;
; assumes 512-byte blocks (max size = ....?) ; assumes 512-byte blocks (max size = 64MB)
; ;
; wait a minute... max 65535 blocks, therefore high word of allocation block, etc, always 0. ; wait a minute... max 65535 blocks, therefore high word of allocation block, etc, always 0.
; ; i assume hfs use 32-bit links in the btree for in-memory use (24-bit or 32 pointers)
; ;
; search for a file named ! in the root directory. ; search for a file named ! in the root directory.
; ! is ascii char $21 so it should sort early. ; ! is ascii char $21 so it should sort early.
; ;
; ;
lda header+drAlBlSt with HFSMasterDirectoryBlock
lda data+drAlBlSt
xba xba
sta offset sta offset
lda header+drCTExtRec ; 1st allocation block lda data+drCTExtRec ; 1st allocation block
xba xba
sta cat_extents sta extents
lda header+drCTExtRec+2 ; # of allocation blocks lda data+drCTExtRec+2 ; # of allocation blocks
xba xba
sta cat_extents+2 sta extents+2
; ;
; need to do all 3? ; need to do all 3?
; ;
endwith
; lda offset ; lda offset
; clc ; clc
; adc cat_extents ; adc extents
lda cat_extents lda extents
jsr read_block jsr read_block
; ;
; block should be a btree header block. find the first leaf node. ; block should be a btree header block. find the first leaf node.
; ;
lda block+$18 with BTHeaderRec
; lda data+BTNodeDescriptor.sizeof+firstLeafNode
; xba
; sta leaf+2
lda data+BTNodeDescriptor.sizeof+firstLeafNode+2
xba xba
sta leaf+2 ; sta bnum
lda block+$18+2
xba endwith
sta leaf
; ;
; assert leaf < # allocated lbocks? ; assert leaf < # allocated lbocks?
; ;
;lda leaf ;lda leaf
jsr read_block ; s/b leaf + cat extent + offset; todo - this offset is in terms of the catalog extent
jsr read_extent_block
lda block+$a ; # of records lda data+BTNodeDescriptor.numRecords ; # of records
xba xba
; asl a ; x 2 ; asl a ; x 2
; sec ; sec
@ -88,36 +154,31 @@ findit proc
again again
ldx #512-2 ; last entry ldx #512-2 ; last entry
@loop @loop
lda block,x lda data,x
tay tay
lda block+2,y ; parent id lda data+HFSCatalogKey.parentID,y ; parent id
bne notfound bne notfound
lda block+4,y lda data+HFSCatalogKey.parentID+2,y
xba xba
cmp #2 cmp #2
blt @next blt @next
beq @name beq @name
bge notfound bge notfound
@name ; name is a p-string. @name ; name is a p-string.
lda block+6+1,y lda data+HFSCatalogKey.nodeName,y
and #$ff cmp #$2101 ; pstr !
cmp #'!' beq found
blt @next
beq @name2
bge notfound bge notfound
@name2 lda block+6,y
cmp #$2101
bne notfound
brl found
@next dex @next dex
dex dex
dec count dec count
bne @loop bne @loop
advance ; next block! advance ; next block!
lda block+2 lda data+BTNodeDescriptor.fLink+2
beq notfound beq notfound
xba xba
jsr read_block jsr read_extent_block
bra again bra again
notfound notfound
@ -129,43 +190,103 @@ found
; only works with contiguous files.... ; only works with contiguous files....
; first block? ; first block?
; 8 is magic offset for a key named !
; assume < 65535 bytes :) ; assume < 65535 bytes :)
lda block+filPyLen+2,y with HFSCatalogFile
lda data+8+recordType,y
and #$00ff
cmp #kHFSFileRecord
bne notfound
lda data+8+dataPhysicalSize+2,y
; xba ; xba
lsr a ; >>9 since already xba lsr a ; >>9 since already xba
and #%01111111 and #%01111111
beq notfound beq notfound
sta count sta count
lda block+filExtRec,y lda data+8+dataExtents,y
xba xba
sta extent sta extents
lda block+filExtRec+2,y lda data+8+dataExtents+2,y
xba xba
sta extent+2 sta extents+2
; now load the blocks and ; now load the blocks and
lda #$2000 lda #$2000
sta dest sta pro.buffer
lda extent stz bnum
clc
adc offset
sta block
@loop @loop
jsr read_block2 lda bnum
inc block jsr read_extent_block
inc bnum
lda #512 lda #512
clc clc
adc dest adc pro.buffer
sta dest sta pro.buffer
dec count dec count
bne @loop bne @loop
lda vector ; pass in
jmp $2000 ; kiss of life. jmp $2000 ; kiss of life.
endp endp
read_block proc
entry read_block_abs
; input
; a = hfs block #
; will be adjusted for allocation block offset
;
with zp
clc
adc offset
read_block_abs
sta pro.block
sep #$30
jmp (vector)
rep #$30
bcs @fail
; bcs error...
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
end
end