pitch-dark/src/path.a
2018-03-28 11:48:47 -04:00

81 lines
2.2 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; Functions to build a ProDOS pathname from length-prefixed strings
;
; Public functions
; - ResetPath
; - AddToPath
; - SetStartupPath
;
; Public variables
; - gPathname
;
;------------------------------------------------------------------------------
; ResetPath
; reset gPathname to length 0
;
; in: none
; out: all registers preserved
;------------------------------------------------------------------------------
ResetPath
stz gPathname
rts
;------------------------------------------------------------------------------
; AddToPath
; append a length-prefixed string to gPathname
;
; in: A contains low byte of address of length-prefixed string to append
; Y contains high byte of address of length-prefixed string to append
; out: all registers and flags clobbered
; $00/$01 clobbered
; gPathname updated with concatenated length-prefixed string
;------------------------------------------------------------------------------
!zone {
AddToPath
sta $00
sty $01
ldx gPathname ; current pathname length
lda ($00) ; length of this segment
inc
sta .a+1
ldy #$01
- lda ($00),y
sta gPathname+1,x
inx
iny
.a cpy #$FD ; SMC
bcc -
stx gPathname
rts
}
;------------------------------------------------------------------------------
; SetStartupPath
; copy a length-prefixed string to $2006 (to pass it as the startup file when
; launching a .system file)
;
; in: A contains low byte of address of length-prefixed string to append
; Y contains high byte of address of length-prefixed string to append
; out: all registers and flags clobbered
; $00/$01 clobbered
;------------------------------------------------------------------------------
!zone {
SetStartupPath
sta $00
sty $01
lda ($00)
tay
- lda ($00),y
and #$7F
sta $2006,y
dey
bpl -
rts
}
gPathname
!fill 65 ; enough zeroes for any ProDOS pathname