Skip to content

Commit

Permalink
Eliminate magic numbers for volume dir key block, case bits
Browse files Browse the repository at this point in the history
Introduce VolumeDirectoryHeader::case_bits rather than hardcoding the
offset. Also, introduce FileEntry::case_bits alias for
FileEntry::version and change some variable names to better match
usage.

No binary changes
  • Loading branch information
inexorabletash committed Mar 17, 2024
1 parent b15b99e commit fb6b657
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion desktop.system/desktop.system.s
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ PreserveQuitCode := PreserveQuitCodeImpl::start

rts ; not found

DEFINE_READ_BLOCK_PARAMS read_block_params, block_buffer, 2
DEFINE_READ_BLOCK_PARAMS read_block_params, block_buffer, kVolumeDirKeyBlock

found:
;; Found it in DEVLST, X = index
Expand Down
18 changes: 9 additions & 9 deletions desktop/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -9254,7 +9254,7 @@ f35: ldax #dib_buffer+SPDIB::ID_String_Length
ldy #IconType::floppy800
rts

DEFINE_READ_BLOCK_PARAMS block_params, block_buffer, 2
DEFINE_READ_BLOCK_PARAMS block_params, block_buffer, kVolumeDirKeyBlock
unit_number := block_params::unit_num

blocks: .word 0
Expand Down Expand Up @@ -11973,17 +11973,17 @@ failure:
IF_EQ
;; Volume
copy DEVNUM, block_params::unit_num
copy16 #2, block_params::block_num
copy16 #kVolumeDirKeyBlock, block_params::block_num
MLI_CALL READ_BLOCK, block_params
bcs ret
copy16 block_buffer + $1A, case_bits
copy16 block_buffer + VolumeDirectoryHeader::case_bits, case_bits
ELSE
;; File
ldax #src_path_buf
jsr GetFileEntryBlock ; leaves $06 pointing at `FileEntry`
bcs ret
entry_ptr := $06
ldy #FileEntry::version
ldy #FileEntry::case_bits
copy16in (entry_ptr),y, case_bits
END_IF

Expand All @@ -12005,7 +12005,7 @@ ret: rts
copy DEVNUM, block_params::unit_num
MLI_CALL READ_BLOCK, block_params
bcs ret
ldy #FileEntry::version
ldy #FileEntry::case_bits
copy16in case_bits, (block_ptr),y
MLI_CALL WRITE_BLOCK, block_params

Expand Down Expand Up @@ -12968,7 +12968,7 @@ match: lda flag
eor #$40 ; bit 6 = relink supported
: rts

DEFINE_READ_BLOCK_PARAMS block_params, block_buffer, 2
DEFINE_READ_BLOCK_PARAMS block_params, block_buffer, kVolumeDirKeyBlock
block_params__unit_num := block_params::unit_num
.endproc ; CheckMoveOrCopy

Expand Down Expand Up @@ -13102,7 +13102,7 @@ ShowErrorAlertDst := ShowErrorAlertImpl::flag_set

MLI_CALL READ_BLOCK, block_params
bcs fallback
ldy #FileEntry::version
ldy #FileEntry::case_bits
copy16in #0, (block_ptr),y
write_block:
MLI_CALL WRITE_BLOCK, block_params
Expand Down Expand Up @@ -13141,10 +13141,10 @@ appleworks:
;; --------------------------------------------------
;; Wipe volume GS/OS case bits
volume:
copy16 #2, block_number ; volume directory key block
copy16 #kVolumeDirKeyBlock, block_number
MLI_CALL READ_BLOCK, block_params
bcs fallback
copy16 #0, block_buffer + $1A
copy16 #0, block_buffer + VolumeDirectoryHeader::case_bits
jmp write_block

block_buffer := $800
Expand Down
2 changes: 1 addition & 1 deletion desktop/ovl_format_erase.s
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ maybe_dos:

;;; Handle Pascal disk - name suffixed with ':'
pascal_disk:
copy16 #$0002, read_block_params::block_num
copy16 #kVolumeDirKeyBlock, read_block_params::block_num
MLI_CALL READ_BLOCK, read_block_params
bcc :+
;; Pascal disk, empty name - use " :" (weird, but okay?)
Expand Down
10 changes: 5 additions & 5 deletions disk_copy/auxlc.s
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ match: clc
ptr := $06

stax ptr
copy16 #2, main__block_params_block_num
copy16 #kVolumeDirKeyBlock, main__block_params_block_num
jsr main__ReadBlock
IF_CS
;; Just use a single space as the name
Expand Down Expand Up @@ -1385,17 +1385,17 @@ match: clc
;; --------------------------------------------------
;; Check for GS/OS case bits, apply if found

copy16 #2, main__block_params_block_num
copy16 #kVolumeDirKeyBlock, main__block_params_block_num
copy16 #default_block_buffer, main__block_params_data_buffer
jsr main__ReadBlock
bcs fallback

case_bytes := default_block_buffer + $1A
asl16 case_bytes
case_bits := default_block_buffer + VolumeDirectoryHeader::case_bits
asl16 case_bits
bcc fallback ; High bit set = GS/OS case bits present

ldy #1
bloop: asl16 case_bytes ; Shift out high byte first
bloop: asl16 case_bits ; Shift out high byte first
bcc :+
lda (ptr),y
ora #AS_BYTE(~CASE_MASK)
Expand Down
4 changes: 4 additions & 0 deletions inc/prodos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ SELECTOR_ORG := $1000 ; QUIT handler execution load address

BLOCK_SIZE = $200

kVolumeDirKeyBlock = 2

;;; ============================================================
;;; Unit Numbers
;;; ============================================================
Expand Down Expand Up @@ -238,6 +240,7 @@ NAME_LENGTH_MASK = $0F
total_blocks .word
.endstruct
.assert .sizeof(VolumeDirectoryHeader) = $2B, error, "incorrect struct size"
VolumeDirectoryHeader::case_bits = $1A

;;; Subdirectory Header structure
.struct SubdirectoryHeader
Expand Down Expand Up @@ -280,6 +283,7 @@ NAME_LENGTH_MASK = $0F
header_pointer .word
.endstruct
.assert .sizeof(FileEntry) = $27, error, "incorrect struct size"
FileEntry::case_bits = FileEntry::version

;;; ============================================================
;;; ProDOS Driver Protocol
Expand Down
16 changes: 8 additions & 8 deletions lib/adjustfilecase.s
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ vol_name:
bcs fallback
MLI_CALL CLOSE, volname_close_params

copy16 volbuf + $1A, version_bytes
copy16 volbuf + VolumeDirectoryHeader::case_bits, case_bits
jmp common

;;; --------------------------------------------------
Expand All @@ -67,12 +67,12 @@ file_entry:
cmp #FT_ASP
beq appleworks

ldy #FileEntry::version
copy16in (ptr),y, version_bytes
ldy #FileEntry::case_bits
copy16in (ptr),y, case_bits
FALL_THROUGH_TO common

common:
asl16 version_bytes
asl16 case_bits
bcs apply_bits ; High bit set = GS/OS case bits present

;;; --------------------------------------------------
Expand Down Expand Up @@ -122,7 +122,7 @@ check_alpha:

apply_bits:
ldy #1
@bloop: asl16 version_bytes ; NOTE: Shift out high byte first
@bloop: asl16 case_bits ; NOTE: Shift out high byte first
bcc :+
lda (ptr),y
ora #AS_BYTE(~CASE_MASK)
Expand Down Expand Up @@ -153,10 +153,10 @@ apply_bits:
appleworks:
ldy #FileEntry::aux_type
lda (ptr),y
sta version_bytes+1
sta case_bits+1
iny
lda (ptr),y
sta version_bytes
sta case_bits
jmp apply_bits

;;; --------------------------------------------------
Expand All @@ -168,7 +168,7 @@ file_name:

;;; --------------------------------------------------

version_bytes:
case_bits:
.word 0
.endproc ; AdjustCaseImpl

Expand Down

0 comments on commit fb6b657

Please sign in to comment.