passport/src/rwts.a

267 lines
6.2 KiB
Plaintext
Raw Normal View History

2017-01-08 03:35:35 +00:00
;-------------------------------
; ReadSector
; high-level function to read a single sector.
; in: gIsProtDOS is TRUE or FALSE
; if gProtDOS is FALSE, jCallRWTS has been set to
; the RWTS entry point (e.g. $BDxx or $3Dxx)
2017-01-08 03:35:35 +00:00
; out: all registers clobbered
; C clear if read was successful
; C set if read failed
;-------------------------------
ReadSectorXY
stx gTrack
sty gSector
2017-01-08 03:35:35 +00:00
ReadSector
;
; Lots of custom RWTS routines need these zero page locations
; set to magic values. Always the same values though!
;
lda #$AA
sta $31
lda #$AD
2017-01-08 03:35:35 +00:00
sta $4E
;
; Copy requested track and sector into RWTS parameter table.
; These are maintained outside the table because some disks
; alter the values from inside the RWTS. (MUSE)
;
lda gTrack
sta _track
lda gSector
sta _sector
2017-01-08 03:35:35 +00:00
lda gIsProtDOS
beq _protread
setuprwts
2017-01-08 03:35:35 +00:00
ldy #<gRWTSParams
lda #>gRWTSParams
jsr jCallRWTS
bcc endread
lda gOnAClearDayYouCanReadForever
beq setuprwts
endread
2017-01-08 03:35:35 +00:00
rts
;
; "Protected.DOS" has enough differences that we just
; split everything out here. The hi/lo RWTS parameter
; table address is set in A/Y instead of Y/A. The
; RWTS entry point is $BA00. The third data prologue
; nibble is stored in zp$4E and varies based on track
; and sector.
;
!zone {
2017-01-08 03:35:35 +00:00
_protread
lda gTrack ; T02,S05+ use "protected" mode
cmp #$03 ; (altered data prologue and
bcs .protected ; nibble translate table)
2017-01-08 03:35:35 +00:00
cmp #$02 ; T00,S00 - T02,S04 use
bcc .standard ; "standard" mode
2017-01-08 03:35:35 +00:00
lda gSector
cmp #$05
bcs .protected
.standard
2017-01-08 03:35:35 +00:00
lda #$9B
sta $BF2C
bne .go ; unconditional branch
.protected
2017-01-08 03:35:35 +00:00
lda #$B5
sta $4E
lda #$D5
sta $BF2C ; execution falls through here
.go
2017-01-08 03:35:35 +00:00
lda #<gRWTSParams
ldy #>gRWTSParams
jsr $BA00 ; note non-standard entry point
bcc endprotread
lda gOnAClearDayYouCanReadForever
beq .go
endprotread
2017-01-08 03:35:35 +00:00
rts
}
2017-01-08 03:35:35 +00:00
;-------------------------------
; PreReadSector
; in: A contains sector map code that specifies what to do
; out: A contains (possibly new) sector map code
; assume all other things clobbered
;-------------------------------
PreReadSector
!zone {
cmp #kSectorResetAdaptiveRWTS
beq .reset
cmp #kSectorIgnoreAddressChecksum
2020-07-22 23:01:07 +00:00
beq IgnoreAddressChecksum
cmp #kSectorCustomDOS32B4BB
beq .b4bb
rts
.reset
jsr CopyUniversal
lda #kSectorRequired
rts
.b4bb
ldx jCallRWTS+2
dex
dex
dex
dex
stx .a+2
stx .b+2
ldx #$D5
.a stx $FF76
ldx #$ED
.b stx $FFB2
.exit rts
}
!zone {
IgnoreAddressChecksum
; out: A,Y preserved
; X clobbered
ldx #$00
stx $B98A
rts
}
!zone {
PatchUniversalRWTSForNoRecal
lda #$B0
2018-08-09 23:32:00 +00:00
sta $BDD2
lda #$30
2018-08-09 23:32:00 +00:00
sta $BDD3
rts
}
!zone {
PatchUniversalRWTSForAdaptive
; out: N flag set
ldy #$09
- lda .addressepilogue, y
sta $B994, y
lda .dataepilogue, y
sta $B938, y
dey
bpl -
rts
.addressepilogue ; to $B994
!byte $8D,$91,$B9
!byte $A9,$AE
!byte $8D,$93,$B9
!byte $D0,$00
.dataepilogue ; to $B938
!byte $8D,$35,$B9
!byte $A9,$0A
!byte $8D,$37,$B9
!byte $18
!byte $60
}
!zone {
PatchUniversalRWTSForOrigin
2020-07-22 23:01:07 +00:00
; out: N=1
ldy #$0F
- lda .addressepilogue, y
sta $B990, y
dey
bpl -
ldy #$0A
- lda .dataepilogue, y
sta $B92F, y
dey
bpl -
rts
.addressepilogue ; to $B990
!byte $C9,$AB
!byte $D0,$0A
!byte $EA
!byte $BD,$8C,$C0
!byte $C9,$AB
!byte $F0,$95
!byte $D0,$00
!byte $18,$60
.dataepilogue ; to $B92F
!byte $18
!byte $60
!byte $38
!byte $A5,$2D
!byte $E9,$11
!byte $85,$2D
!byte $18
!byte $60
}
2020-07-22 23:01:07 +00:00
!zone {
PatchUniversalRWTSForTSR
; out: Z=0
lda #<tsr_callback
sta $BE8C
lda #>tsr_callback
sta $BE8D
rts
tsr_callback
pha
ldy gTrack
cpy #$05
bcc .normal
lda $F800, y
and #$42
bne +
lda #$42
+ ora #$B5
!byte $2C
.normal lda #$AD
sta $B8FC
pla
jmp $B9A0
}
SwitchToUniv
lda gSector
sta gDisplayBytes
lda #s_switch
!byte $2C ; hide next LDA
StartWithUniv
lda #s_builtin
jsr PrintByID
lda #TRUE
sta gTriedUniv
lda #FALSE
sta gIsProtDOS
; /!\ execution falls through here
CopyUniversal
lda #$B8
CopyUniversalAnywhere
sta universalrwts
clc
adc #$02
sta .cu+2
lda #>universalrwts
sta _byte_hi
lda #<universalrwts
sta _byte_lo
jsr decrunch
sty jCallRWTS+1
lda #$BD
sta jCallRWTS+2
ldy #$96
.culoop lda gNIBTable,y
.cu sta $d100,y ; set at runtime
iny
bne .culoop
rts
gTrack !byte $00
gSector !byte $00
gRWTSParams ; used to read each sector
!byte $01,$60,$01,$00
_track !byte $00
_sector !byte $00
2017-01-08 03:35:35 +00:00
!word dct
gAddress !word $1F00
2019-04-13 17:33:15 +00:00
!byte $00,$00
gCommand !byte $01,$00,$FE,$60,$01,$00,$00
dct !byte $00,$01,$EF,$D8,$00