2021-04-20 04:27:11 +00:00
|
|
|
gRWTSParams
|
|
|
|
!byte $01,$60,$01,$00
|
|
|
|
_track !byte $00
|
|
|
|
_sector !byte $00
|
|
|
|
!word dct
|
|
|
|
gAddress !word $1F00
|
|
|
|
!byte $00,$00
|
2021-06-04 03:42:19 +00:00
|
|
|
gCommand !byte $01
|
|
|
|
gError !byte $00,$FE,$60,$01,$00,$00
|
2021-04-20 04:27:11 +00:00
|
|
|
dct !byte $00,$01,$EF,$D8,$00
|
|
|
|
|
2017-01-08 03:35:35 +00:00
|
|
|
;-------------------------------
|
|
|
|
; ReadSector
|
|
|
|
; high-level function to read a single sector.
|
|
|
|
; in: gIsProtDOS is TRUE or FALSE
|
2017-11-09 05:47:12 +00:00
|
|
|
; 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
|
|
|
|
;-------------------------------
|
2021-04-19 14:19:57 +00:00
|
|
|
ReadSectorXY
|
|
|
|
stx gTrack
|
|
|
|
sty gSector
|
2017-01-08 03:35:35 +00:00
|
|
|
ReadSector
|
2017-10-08 21:54:03 +00:00
|
|
|
;
|
|
|
|
; 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
|
2017-10-08 21:54:03 +00:00
|
|
|
;
|
|
|
|
; 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
|
2021-04-20 04:27:11 +00:00
|
|
|
@go
|
2017-01-08 03:35:35 +00:00
|
|
|
ldy #<gRWTSParams
|
|
|
|
lda #>gRWTSParams
|
2017-11-09 05:47:12 +00:00
|
|
|
jsr jCallRWTS
|
2021-04-20 04:27:11 +00:00
|
|
|
bcc +
|
2017-01-14 15:13:06 +00:00
|
|
|
lda gOnAClearDayYouCanReadForever
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @go
|
|
|
|
+ rts
|
2017-01-08 03:35:35 +00:00
|
|
|
|
|
|
|
;
|
|
|
|
; "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.
|
|
|
|
;
|
|
|
|
_protread
|
|
|
|
lda gTrack ; T02,S05+ use "protected" mode
|
|
|
|
cmp #$03 ; (altered data prologue and
|
2021-04-20 04:27:11 +00:00
|
|
|
bcs @protected ; nibble translate table)
|
2017-01-08 03:35:35 +00:00
|
|
|
cmp #$02 ; T00,S00 - T02,S04 use
|
2021-04-20 04:27:11 +00:00
|
|
|
bcc @standard ; "standard" mode
|
2017-01-08 03:35:35 +00:00
|
|
|
lda gSector
|
|
|
|
cmp #$05
|
2021-04-20 04:27:11 +00:00
|
|
|
bcs @protected
|
|
|
|
@standard
|
2017-01-08 03:35:35 +00:00
|
|
|
lda #$9B
|
|
|
|
sta $BF2C
|
2021-04-20 04:27:11 +00:00
|
|
|
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
|
2021-04-20 04:27:11 +00:00
|
|
|
@go lda #<gRWTSParams
|
2017-01-08 03:35:35 +00:00
|
|
|
ldy #>gRWTSParams
|
|
|
|
jsr $BA00 ; note non-standard entry point
|
2021-04-20 04:27:11 +00:00
|
|
|
bcc +
|
2017-01-14 15:13:06 +00:00
|
|
|
lda gOnAClearDayYouCanReadForever
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @go
|
|
|
|
+ rts
|
2017-01-08 03:35:35 +00:00
|
|
|
|
2017-10-02 01:36:43 +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
|
2017-12-12 20:43:41 +00:00
|
|
|
cmp #kSectorResetAdaptiveRWTS
|
2021-04-20 03:48:41 +00:00
|
|
|
beq @reset
|
2017-12-12 20:43:41 +00:00
|
|
|
cmp #kSectorIgnoreAddressChecksum
|
2020-07-22 23:01:07 +00:00
|
|
|
beq IgnoreAddressChecksum
|
2017-10-02 01:36:43 +00:00
|
|
|
cmp #kSectorCustomDOS32B4BB
|
2021-04-20 03:48:41 +00:00
|
|
|
beq @b4bb
|
2021-04-28 21:37:56 +00:00
|
|
|
cmp #kSectorCustomEarthware
|
|
|
|
beq @earthware
|
2017-12-12 20:43:41 +00:00
|
|
|
rts
|
2021-04-20 03:48:41 +00:00
|
|
|
@reset
|
2017-12-12 20:43:41 +00:00
|
|
|
jsr CopyUniversal
|
|
|
|
lda #kSectorRequired
|
|
|
|
rts
|
2021-04-20 03:48:41 +00:00
|
|
|
@b4bb
|
2017-11-09 05:47:12 +00:00
|
|
|
ldx jCallRWTS+2
|
2017-10-02 01:36:43 +00:00
|
|
|
dex
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
dex
|
2021-04-20 03:48:41 +00:00
|
|
|
stx @a+2
|
|
|
|
stx @b+2
|
2017-10-02 01:36:43 +00:00
|
|
|
ldx #$D5
|
2021-04-20 03:48:41 +00:00
|
|
|
@a stx $FF76
|
2017-10-02 01:36:43 +00:00
|
|
|
ldx #$ED
|
2021-04-20 03:48:41 +00:00
|
|
|
@b stx $FFB2
|
|
|
|
rts
|
2021-04-28 21:37:56 +00:00
|
|
|
@earthware
|
|
|
|
ldx #$4C
|
|
|
|
stx $B8F6
|
|
|
|
ldx #$89
|
|
|
|
stx $B8F7
|
|
|
|
ldx #$B6
|
|
|
|
stx $B8F8
|
|
|
|
rts
|
2017-10-02 01:36:43 +00:00
|
|
|
|
2017-10-30 01:00:15 +00:00
|
|
|
IgnoreAddressChecksum
|
2017-12-12 20:43:41 +00:00
|
|
|
; out: A,Y preserved
|
|
|
|
; X clobbered
|
|
|
|
ldx #$00
|
|
|
|
stx $B98A
|
|
|
|
rts
|
|
|
|
|
2021-04-20 03:48:41 +00:00
|
|
|
;-------------------------------
|
|
|
|
; ChangeTrack
|
|
|
|
; in: A = new track
|
|
|
|
;-------------------------------
|
|
|
|
ChangeTrack
|
2021-04-20 04:27:11 +00:00
|
|
|
sta @new+1
|
2021-04-20 03:48:41 +00:00
|
|
|
jsr WriteTrack
|
2021-04-20 04:27:11 +00:00
|
|
|
@new lda #$d1 ; modified at runtime
|
2018-08-09 23:31:26 +00:00
|
|
|
|
2021-04-20 03:48:41 +00:00
|
|
|
; note: execution falls through here
|
2017-12-12 20:43:41 +00:00
|
|
|
|
2021-04-20 03:48:41 +00:00
|
|
|
ChangeTrackNW ; "N"o "W"rite
|
|
|
|
sta gTrack
|
2021-06-18 17:53:17 +00:00
|
|
|
jmp ClearTSBuffer
|
2017-10-30 01:00:15 +00:00
|
|
|
|
2021-04-20 03:48:41 +00:00
|
|
|
;-------------------------------
|
|
|
|
; ChangeSector
|
|
|
|
; in: A = new sector
|
|
|
|
;-------------------------------
|
|
|
|
ChangeSector
|
|
|
|
sta gSector
|
|
|
|
clc
|
|
|
|
adc #BASEPAGE
|
|
|
|
sta gAddress+1
|
2020-07-22 23:01:07 +00:00
|
|
|
rts
|
|
|
|
|
2021-04-20 03:48:41 +00:00
|
|
|
;-------------------------------
|
|
|
|
; WriteTrack
|
|
|
|
; in: none
|
|
|
|
;-------------------------------
|
|
|
|
WriteTrack
|
|
|
|
jsr AnalyzeTrack
|
|
|
|
WriteTrackNA ; entry point used by Special Delivery tracer
|
|
|
|
; to write track with 'N'o 'A'nalysis
|
|
|
|
bit gMode
|
|
|
|
bpl @exit ; don't write anything in verify mode
|
|
|
|
lda gSaidWriting
|
|
|
|
beq @doTheWriteThing ; only print 'writing to' message once
|
|
|
|
|
|
|
|
; we haven't yet printed any 'writing to...' message in the log, so
|
|
|
|
; figure out what that should look like and do it now
|
|
|
|
jsr PrintByID
|
2021-06-13 02:07:26 +00:00
|
|
|
!byte s_writingto
|
2021-04-20 03:48:41 +00:00
|
|
|
|
|
|
|
lda gHardDiskRef
|
|
|
|
beq @maybeWritingToRAMDisk
|
|
|
|
; we are writing to a file on a hard disk, so print the
|
|
|
|
; full pathname of that file
|
2021-06-19 00:54:26 +00:00
|
|
|
+PrintHardDiskImagePath
|
2021-04-20 03:48:41 +00:00
|
|
|
bvc @doneSaidWriting ; always branches
|
|
|
|
|
|
|
|
@maybeWritingToRAMDisk
|
|
|
|
lda gRAMDiskRef
|
|
|
|
beq @notWritingToRAMDisk
|
|
|
|
lda #s_ramdisk ; writing to (a file on) a RAM disk
|
|
|
|
!byte $2C
|
|
|
|
@notWritingToRAMDisk
|
|
|
|
lda #s_slotanddrive ; writing to a slot and drive
|
2021-06-13 02:07:26 +00:00
|
|
|
sta +
|
2021-04-18 04:49:26 +00:00
|
|
|
jsr PrintByID
|
2021-06-13 02:07:26 +00:00
|
|
|
+ !byte $FD ; SMC
|
2021-04-20 03:48:41 +00:00
|
|
|
|
|
|
|
@doneSaidWriting
|
2021-04-18 04:49:26 +00:00
|
|
|
lda #TRUE
|
2021-04-20 03:48:41 +00:00
|
|
|
sta gSaidWriting
|
2021-04-18 04:49:26 +00:00
|
|
|
|
2021-04-20 03:48:41 +00:00
|
|
|
@doTheWriteThing
|
|
|
|
jsr SwapProDOS ; ProDOS out -> in
|
|
|
|
jsr WriteTrackFirstPass
|
|
|
|
jsr SwapProDOS ; ProDOS in -> out
|
|
|
|
bcs FatalWriteError
|
|
|
|
@exit rts
|
|
|
|
|
|
|
|
;-------------------------------
|
|
|
|
; FatalWriteError
|
2021-04-20 04:27:11 +00:00
|
|
|
; in: A has MLI error code
|
2021-04-20 03:48:41 +00:00
|
|
|
; out: does not return, exits via TheEnd
|
|
|
|
;-------------------------------
|
|
|
|
FatalWriteError
|
2021-04-20 04:27:11 +00:00
|
|
|
sta gDisplayBytes
|
2021-04-20 03:48:41 +00:00
|
|
|
tax
|
|
|
|
lda #s_writeioerr
|
|
|
|
cpx #MLI_IOERR
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @print
|
2021-04-20 03:48:41 +00:00
|
|
|
lda #s_writenodev
|
|
|
|
cpx #MLI_NODEV
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @print
|
2021-04-20 03:48:41 +00:00
|
|
|
lda #s_writeprot
|
|
|
|
cpx #MLI_WRITEPROT
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @print
|
2021-04-20 03:48:41 +00:00
|
|
|
lda #s_othermli
|
2021-06-13 02:07:26 +00:00
|
|
|
@print sta +
|
2021-04-20 03:48:41 +00:00
|
|
|
jsr PrintByID
|
2021-06-13 02:07:26 +00:00
|
|
|
!byte s_writeerr
|
2021-04-20 03:48:41 +00:00
|
|
|
jsr PrintByID
|
2021-06-13 02:07:26 +00:00
|
|
|
+ !byte $FD ; SMC
|
2021-04-20 03:48:41 +00:00
|
|
|
jmp TheEnd
|