4cade/src/prodos.impl.lc2.a

583 lines
12 KiB
Plaintext
Raw Permalink Normal View History

2019-09-06 22:12:17 +00:00
;license:MIT
2022-04-29 01:01:37 +00:00
;(c) 2019-2022 by 4am & qkumba
2019-09-06 22:12:17 +00:00
;
; Pseudo-ProDOS environment
;
; /!\ These live in LC RAM 2 and rely on the ProRWTS code which is also in LC RAM 2. /!\
2019-09-06 22:12:17 +00:00
;------------------------------------------------------------------------------
; ProDOS_enter
; intercept certain ProDOS requests
; wrap them to ProRWTS2 file requests
;
; in: return address+1 is command and pointer to parameter block
; out: all flags clobbered
; A=0, X and Y preserved
; stack set to next instruction after parameters
;------------------------------------------------------------------------------
2019-09-29 15:08:57 +00:00
ipacket = first_zp ;word
2019-09-06 22:12:17 +00:00
buffer = first_zp+2 ;word
ProDOS_enter
!set CloseHandles = @imp_close
2021-10-19 18:09:57 +00:00
!set swap_zpg = @swap_zp
2021-10-24 03:53:24 +00:00
!set SavedZP = @saved_zp
2019-09-24 00:01:42 +00:00
stx ProDOS_savedX+1
sty ProDOS_savedY+1
jsr @swap_zp
pla
tay
pla
sta @fetchaddr+1
pla
sta @fetchaddr+2
jsr @fetchbyte
sta @request+1
jsr @fetchbyte
2019-09-29 15:08:57 +00:00
sta ipacket
2019-09-24 00:01:42 +00:00
jsr @fetchbyte
2019-09-29 15:08:57 +00:00
sta ipacket+1
2019-09-24 00:01:42 +00:00
lda @fetchaddr+2
pha
lda @fetchaddr+1
pha
tya
pha
2020-02-21 06:07:54 +00:00
ldy #2
2019-09-06 22:12:17 +00:00
@request
2019-09-24 00:01:42 +00:00
lda #$d1
cmp #$40
beq @imp_allocint ;;@do_allocint
cmp #$41
beq @do_deallocint
2020-02-21 06:07:54 +00:00
cmp #$65
beq @do_quit
2019-09-24 00:01:42 +00:00
cmp #$80
beq @imp_rdwrblock ;;@do_readblock
2019-09-24 00:01:42 +00:00
cmp #$81
beq @imp_rdwrblock ;;@do_writeblock
cmp #$c0
beq @do_create
2019-09-24 00:01:42 +00:00
cmp #$c4
beq @imp_getattrib ;;@do_getattrib
2019-09-24 00:01:42 +00:00
cmp #$c6
beq @do_setprefix
2019-09-24 00:01:42 +00:00
cmp #$c7
beq @do_getprefix
2019-09-24 00:01:42 +00:00
cmp #$c8
beq @do_open
cmp #$ca
beq @do_read
cmp #$cb
beq @do_write
cmp #$cc
beq @do_close
cmp #$ce
beq @do_seek
cmp #$d0
beq @do_seteof
;; cmp #$d1
2019-09-24 00:01:42 +00:00
;; bne @do_fatal
@do_geteof
jmp @imp_geteof
@do_allocint
;; jmp @imp_allocint
2020-02-21 06:07:54 +00:00
@do_quit
jmp $100
2019-09-06 22:12:17 +00:00
@do_readblock
@do_writeblock
;; jmp @imp_rdwrblock
2019-09-06 22:12:17 +00:00
@do_getattrib
;; jmp @imp_getattrib
@do_getprefix
jmp @imp_getprefix
2019-09-06 22:12:17 +00:00
@do_open
2019-09-24 00:01:42 +00:00
jmp @imp_open
2019-09-06 22:12:17 +00:00
@do_read
2019-09-24 00:01:42 +00:00
jmp @imp_read
2019-09-06 22:12:17 +00:00
@do_write
2019-09-24 00:01:42 +00:00
jmp @imp_write
2019-09-06 22:12:17 +00:00
@do_close
2019-09-24 00:01:42 +00:00
jsr @imp_close ;subroutine special case because of dual-use
@do_deallocint ;nothing for now
@do_create ;nothing for now
@do_setprefix ;nothing for now
@do_seteof ;nothing for now
2019-09-24 00:01:42 +00:00
jmp @restore_zp
2019-09-06 22:12:17 +00:00
@do_seek
2019-09-24 00:01:42 +00:00
jmp @imp_seek
2019-09-20 19:42:02 +00:00
@do_fatal
2019-09-24 00:01:42 +00:00
;; jmp ProDOS_fatal
2019-09-06 22:12:17 +00:00
@imp_allocint
2020-02-21 06:07:54 +00:00
;;ldy #2
lda (ipacket), y
sta ProDOS_irq + 1
iny
lda (ipacket), y
sta ProDOS_irq + 2
lda #<ProDOS_int
ldx #>ProDOS_int
sta $3fe
sta $fffe
stx $3ff
stx $ffff
bne @jmp_zp2 ;always
2019-09-06 22:12:17 +00:00
@imp_rdwrblock
2019-09-24 00:01:42 +00:00
and #$7f
2020-02-21 06:07:54 +00:00
adc #0
sta @rdwrop+1
2019-09-24 00:01:42 +00:00
ldx #$44
2020-02-21 06:07:54 +00:00
;;ldy #2
2019-09-24 00:01:42 +00:00
jsr @setbuffer
2019-09-29 15:08:57 +00:00
lda (ipacket), y
2019-09-24 00:01:42 +00:00
tax
iny
2019-09-29 15:08:57 +00:00
lda (ipacket), y
2019-09-06 22:12:17 +00:00
@rdwrop
2019-09-24 00:01:42 +00:00
ldy #$d1 ; SMC
jsr hddseekrd+2
bcc @jmp_zp2 ;always
2019-09-06 22:12:17 +00:00
@imp_getattrib
2019-09-29 15:08:57 +00:00
lda ipacket+1
2019-09-24 00:01:42 +00:00
pha
2019-09-29 15:08:57 +00:00
lda ipacket
2019-09-24 00:01:42 +00:00
pha
ldx #namlo
jsr @setbuffer1
lda #$60
sta attribpatch
jsr hddopendir
lda #$10
sta attribpatch
pla
2019-09-29 15:08:57 +00:00
sta ipacket
2019-09-24 00:01:42 +00:00
pla
2019-09-29 15:08:57 +00:00
sta ipacket+1
2019-09-24 00:01:42 +00:00
ldy #5
lda ldrlo2
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2019-09-24 00:01:42 +00:00
iny
lda ldrlo2+1
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2019-09-24 00:01:42 +00:00
ldy #$13
jsr fetchscratch
2019-09-24 00:01:42 +00:00
ldy #9
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2019-09-24 00:01:42 +00:00
txa
dey
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2019-09-06 22:12:17 +00:00
@jmp_zp2
2019-09-24 00:01:42 +00:00
jmp @restore_zp
2019-09-06 22:12:17 +00:00
@imp_getprefix
2019-09-24 00:01:42 +00:00
ldx #buffer
jsr @setbuffer1
ldy ProDOS_prefix
iny
iny
tya
pha
2019-09-06 22:12:17 +00:00
@copy_prefix
2019-10-11 03:06:36 +00:00
lda ProDOS_prefix-1, y
2019-09-24 00:01:42 +00:00
sta (buffer), y
dey
bne @copy_prefix
pla
sta (buffer), y
2019-10-11 03:06:36 +00:00
tay
2019-09-24 00:01:42 +00:00
lda #'/'
2019-10-11 03:06:36 +00:00
sta (buffer), y
ldy #1
2019-09-24 00:01:42 +00:00
sta (buffer), y
2020-05-22 20:06:37 +00:00
bne @jmp_zp2 ;always
2019-09-06 22:12:17 +00:00
@imp_open
2019-09-24 00:01:42 +00:00
ldx #namlo
jsr @setbuffer1
inc @handles+1
2019-09-06 22:12:17 +00:00
@handles
2019-09-24 00:01:42 +00:00
ldx #0
iny
2019-09-29 15:08:57 +00:00
lda (ipacket), y
2019-09-24 00:01:42 +00:00
sta @handle-1, x
jsr @patch_buffer
iny
lda #1
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2020-02-21 06:07:54 +00:00
lsr
2019-09-24 00:01:42 +00:00
sta reqcmd
sta sizehi
sta sizelo
jsr hddopendir
2020-05-22 20:06:37 +00:00
stx blkidx
2020-05-23 19:30:30 +00:00
beq @link_jmpzp ;always
2019-09-06 22:12:17 +00:00
2020-05-22 20:06:37 +00:00
resetval=$f0
2019-09-06 22:12:17 +00:00
@imp_seek
2019-09-24 00:01:42 +00:00
jsr @set_rdwrbuff
2022-04-29 01:01:37 +00:00
jsr @reset
lda sizelo
lsr
2021-11-15 20:18:23 +00:00
tay
lda ldrhi
ror
sta blkidx
2021-11-15 20:18:23 +00:00
ldx istree
beq @sametree
2021-11-15 20:18:23 +00:00
tax
beq @skiptree
iny
cpy treeidx
@skiptree
sty treeidx
beq @sametree
2021-11-15 20:18:23 +00:00
ldx hddtreebuf - 1, y
lda hddtreebuf + 255, y
jsr hddreaddirsel
2019-09-06 22:12:17 +00:00
@sametree
2022-04-29 01:01:37 +00:00
jsr @close_reset
lda ldrlo
sta sizelo
2019-09-24 00:01:42 +00:00
lda ldrhi
and #1
2019-09-24 00:01:42 +00:00
sta sizehi
ora sizelo
beq @link_jmpzp
2019-09-24 00:01:42 +00:00
jsr @seekreset
2020-05-23 19:30:30 +00:00
@link_jmpzp
jmp @restore_zp
2019-09-06 22:12:17 +00:00
@seekreset
2022-04-29 01:01:37 +00:00
lda #cmdseek
sta reqcmd
2019-09-24 00:01:42 +00:00
jsr hddrdwrpart
2019-09-06 22:12:17 +00:00
@reset
2020-05-22 20:06:37 +00:00
lda #resetval
2019-09-24 00:01:42 +00:00
sta blefthi
stx bleftlo
2019-09-24 00:01:42 +00:00
rts
2019-09-06 22:12:17 +00:00
@imp_read
2019-09-24 00:01:42 +00:00
clc
2019-09-06 22:12:17 +00:00
@imp_write
2019-09-24 00:01:42 +00:00
php
lda #cmdread
adc #0
sta reqcmd
jsr @set_rdwrbuff
plp
bcc @skip_align
2020-06-06 19:50:12 +00:00
ldx #sizelo
jsr @round
2020-01-29 17:20:29 +00:00
lda #0
2020-06-06 19:50:12 +00:00
sta sizelo
ldx #bleftlo
jsr @round
2019-09-06 22:12:17 +00:00
@skip_align
2019-09-24 00:01:42 +00:00
jsr hddrdwrpart
2020-03-15 18:25:29 +00:00
ldx #<sizelo2
2019-09-24 00:01:42 +00:00
ldy #6
2019-09-06 22:12:17 +00:00
2020-03-15 18:25:29 +00:00
+HIDE_NEXT_2_BYTES
@imp_geteof
2020-03-15 18:25:29 +00:00
ldx #<bleftlo
2020-02-21 06:07:54 +00:00
;;ldy #2
2020-03-15 18:25:29 +00:00
lda $0, x
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2020-03-15 18:25:29 +00:00
inx
2019-09-24 00:01:42 +00:00
iny
2020-03-15 18:25:29 +00:00
lda $0, x
2019-09-29 15:08:57 +00:00
sta (ipacket), y
2020-03-15 18:25:29 +00:00
@jmp_zp
jmp @restore_zp
2019-09-06 22:12:17 +00:00
@imp_close
2019-09-24 00:01:42 +00:00
lda @handles+1
beq @close_ret
dec @handles+1
2022-04-29 01:01:37 +00:00
bne @close_reset
2019-09-24 00:01:42 +00:00
lda #>hddencbuf
2019-09-06 22:12:17 +00:00
@patch_buffer
2019-09-24 00:01:42 +00:00
sta encbufpatch1+1
sta encbufpatch2+1
tax
inx
stx dirbufpatch1+1
inx
stx dirbufpatch2+2
stx dirbufpatch3+2
stx dirbufpatch4+2
stx dirbufpatch6+1
stx dirbufpatch7+2
stx dirbufpatch9+2
stx dirbufpatch10+1
2021-10-18 22:37:40 +00:00
stx dirbufpatch11+1
2019-09-24 00:01:42 +00:00
inx
stx dirbufpatch5+2
stx dirbufpatch8+2
inx
stx treebufpatch1+1
stx treebufpatch2+2
inx
stx treebufpatch3+2
2019-09-06 22:12:17 +00:00
@close_ret
2019-09-24 00:01:42 +00:00
rts
2019-09-06 22:12:17 +00:00
2022-04-29 01:01:37 +00:00
@close_reset
lda #0
sta blkofflo
sta blkoffhi
rts
2019-09-06 22:12:17 +00:00
@fetchbyte
2019-09-24 00:01:42 +00:00
inc @fetchaddr+1
bne @fetchaddr
inc @fetchaddr+2
2019-09-06 22:12:17 +00:00
@fetchaddr
2019-09-24 00:01:42 +00:00
lda $d1d1
rts
2019-09-06 22:12:17 +00:00
@set_rdwrbuff
2019-09-24 00:01:42 +00:00
ldy #1
2019-09-29 15:08:57 +00:00
lda (ipacket), y
2019-09-24 00:01:42 +00:00
tax
lda @handle-1, x
jsr @patch_buffer
ldx #ldrlo
iny
jsr @setbuffer
ldx #sizelo
!byte $2c
2019-09-06 22:12:17 +00:00
@setbuffer1
2019-09-24 00:01:42 +00:00
ldy #1
2019-09-06 22:12:17 +00:00
@setbuffer
2019-09-29 15:08:57 +00:00
lda (ipacket), y
2019-09-24 00:01:42 +00:00
sta $0,x
iny
2019-09-29 15:08:57 +00:00
lda (ipacket), y
2019-09-24 00:01:42 +00:00
sta $1,x
2020-02-21 06:07:54 +00:00
iny
2019-09-24 00:01:42 +00:00
rts
2019-09-06 22:12:17 +00:00
2020-06-06 19:50:12 +00:00
@round
clc
lda $0,x
adc #$ff
lda $1,x
adc #1
and #$fe
sta $1,x
rts
2019-09-06 22:12:17 +00:00
@swap_zp
2019-09-24 00:01:42 +00:00
ldx #last_zp-first_zp
2019-09-06 22:12:17 +00:00
@save_zp
2019-09-24 00:01:42 +00:00
lda first_zp,x
ldy @saved_zp,x
sta @saved_zp,x
sty first_zp,x
dex
bpl @save_zp
rts
2019-09-06 22:12:17 +00:00
@restore_zp
2019-09-24 00:01:42 +00:00
jsr @swap_zp
jmp ProDOS_exit
2019-09-06 22:12:17 +00:00
@handle
2019-09-24 00:01:42 +00:00
!byte 0, 0 ;only up to two handles at a time
2019-09-06 22:12:17 +00:00
@saved_zp
2019-09-24 00:01:42 +00:00
!fill (last_zp - first_zp) + 1
2019-09-09 21:28:13 +00:00
2021-10-29 18:39:43 +00:00
resetRoot
gRootDirectory
+LDADDR 0 ; SMC
sta (reloc + unrhddblocklo - unrelochdd) + 1
sty (reloc + unrhddblockhi - unrelochdd) + 1
rts
2019-09-09 21:28:13 +00:00
;------------------------------------------------------------------------------
; traverse [private]
;
; in: (namlo) points to length-prefixed pathname+filename
; out: all flags clobbered
; all registers clobbered
;------------------------------------------------------------------------------
!ifdef PASS2 {
} else { ;PASS2
!if * != itraverse {
2021-10-15 20:00:40 +00:00
!error "itraverse=",*, ", fix constants.a, rebuild prelaunch"
}
}
2019-09-09 21:28:13 +00:00
traverse
2021-10-29 18:39:43 +00:00
jsr resetRoot
2019-09-09 21:28:13 +00:00
;search for '/' character in filename
ldx #0
ldy #0
lda (namlo), y
tay
- inx
dey
2022-05-05 20:56:14 +00:00
beq @go ; no '/', just do the read
2019-09-09 21:28:13 +00:00
lda (namlo), y
cmp #'/'
bne -
sty sizelo
txa
pha
2021-10-20 19:02:42 +00:00
lda #$B1 ; LDA (), y
sta pathpatch1
lda #$68 ; PLA
sta pathpatch2
lda #$60 ; RTS
sta pathpatch2 + 1
2019-09-09 21:28:13 +00:00
@myreadblock
2021-10-20 19:02:42 +00:00
jsr hddopendir
- tax
2019-09-09 21:28:13 +00:00
;parse path until last directory is seen
lda (namlo), y
cmp #'/'
2021-10-20 19:02:42 +00:00
beq +
-- jsr pathresume
bne - ; always taken
+ txa
bmi --
2019-09-09 21:28:13 +00:00
tya
eor #$ff
adc sizelo
sta sizelo
clc
tya
adc namlo
sta namlo
2021-10-20 19:02:42 +00:00
bcc +
inc namhi
+
2019-09-09 21:28:13 +00:00
;cache block number of current directory
;as starting position for subsequent searches
ldy #(KEY_POINTER + 1)
2021-10-20 19:02:42 +00:00
lda (scratchlo), y
2019-09-09 21:28:13 +00:00
tax
dey
2021-10-20 19:02:42 +00:00
lda (scratchlo), y
2019-09-09 21:28:13 +00:00
sta (reloc + unrhddblocklo - unrelochdd) + 1
stx (reloc + unrhddblockhi - unrelochdd) + 1
2021-10-20 19:02:42 +00:00
lda sizelo
2019-09-09 21:28:13 +00:00
bne @myreadblock
tay
2021-10-20 19:02:42 +00:00
lda #$D1 ; CMP (), y
sta pathpatch1
lda #$86 ; STX
sta pathpatch2
lda #$5A
sta pathpatch2 + 1
2019-09-09 21:28:13 +00:00
pla
sta (namlo), y
@go
rts
;------------------------------------------------------------------------------
; promote [private]
;
; tiny ProDOS-style interface for ProRWTS
; in: whatever ProDOS expects for the supported functions
; out: carry clear, A=0
; X, Y, and other flags clobbered
;------------------------------------------------------------------------------
promote
!pseudopc $bf00 {
php
sei
2019-09-24 00:01:42 +00:00
bit $c083
!byte $24
2019-09-09 21:28:13 +00:00
!if * != $bf06 {
!error "$BF06 misplaced (",*,")"
}
rts ;clock interface, must be RTS on real ProDOS if program uses $20x
2019-09-24 00:01:42 +00:00
bit $c083
jmp ProDOS_enter
2019-09-20 19:42:02 +00:00
ProDOS_exit
2020-02-28 23:33:10 +00:00
sta $c082
bmi ProDOS_savedX ;always
!if * != $bf12 {
!error "$BF12 misplaced (",*,")"
}
!word $c1d1, $c2d1, $c3d1, $c4d1, $c5d1, $c6d1, $c7d1
2019-09-20 19:42:02 +00:00
ProDOS_savedX
2019-09-24 00:01:42 +00:00
ldx #$d1
2019-09-09 21:28:13 +00:00
ProDOS_savedY
2019-09-24 00:01:42 +00:00
ldy #$d1
2020-02-28 23:33:10 +00:00
plp
clc
2019-09-24 00:01:42 +00:00
lda #0
2019-09-20 19:42:02 +00:00
rts
!if * > $bf30 {
2019-09-09 21:28:13 +00:00
!error "$BF30 misplaced (",*,")"
2019-09-20 19:42:02 +00:00
} else {
!if * != $bf30 {
2019-09-24 00:01:42 +00:00
!fill $bf30-*
2019-09-20 19:42:02 +00:00
}
2019-09-09 21:28:13 +00:00
}
2019-09-20 23:53:43 +00:00
ProDOS_unit
2019-09-24 00:01:42 +00:00
!byte $d1
2019-09-09 21:28:13 +00:00
ProDOS_int
pha
txa
pha
tya
pha
ProDOS_irq
jsr $d1d1 ;SMC
pla
tay
pla
tax
pla
bit $c012
bmi +
lda $45
+ rti
!if * > $bf58 {
!error "code is too large, ends at ", *
}
2019-09-09 21:28:13 +00:00
ProDOS_fatal ;only for debugging, will be removed
2019-09-24 00:01:42 +00:00
;; bit $c081
;; pha
;; jsr $fe89
;; jsr $fe93
;; pla
;; jsr $fdda
;; jmp $ff65
2019-09-20 19:42:02 +00:00
;;*=$bf58
2019-09-24 00:01:42 +00:00
;; !fill $18 ;filled by init instead
2019-09-09 21:28:13 +00:00
2019-10-09 04:25:10 +00:00
ProDOS_prefix=gPathname
2019-09-24 00:01:42 +00:00
; !fill $2e
2019-09-09 21:28:13 +00:00
}
end_promote