💾 Archived View for spam.works › mirrors › textfiles › apple › ANATOMY › rwts.s.txt captured on 2023-06-16 at 21:11:46.

View Raw

More Information

-=-=-=-=-=-=-


SLOTZ = $27
CSUM = $27
PRIOR = $27
WTEMP = $26
TO = $26
IDX = $26
COUNT = $26
LAST = $26
TRKCNT = $26
VOLFND = $2F
TRKFND = $2E
SECFND = $2D
SLOTEMP = $2B
TRKN = $2A
PTRSDEST = $36
DRIVNO = $35
BUFADR = $3E
DEVCTBL = $3C
MONTIMEH = $47
MONTIMEL = $46
SYNCNT = $45
TRACK = $44
VOLUME = $41
IOBPH = $49
IOBPL = $48
DRV0TRK = $478
CURTRK = $478
SEEKCNT = $4F8
DRV1TRK = $4F8
RETRYCNT = $578
SLOT = $5F8
SLOTABS = $678
RECALCNT = $6F8
CLOSEALL = $A316
RSET0 = $A75B
TEMP1 = $AA63
BYTVAL = $AA70
RUNINTRC = $AAB7
SAVFMW = $AE7E
SETERROR = $B385
STKSAVE = $B39B
RESTART = $B744
ROM = $C081
PHASEOFF = $C080
SETWRT = $C08F
SETRD = $C08E
WRTDAT = $C08D
RDDATA = $C08C
DRVSL2 = $C08B
DRVSL1 = $C08A
DRVON = $C089
DRVOFF = $C088
BASIC = $E000
SETVID = $FE93

 ORG $B800

PRENIB16 LDX #0
 LDY #2

PRENIB1 DEY 
 LDA (BUFADR),Y

 LSR 
 ROL NBUF2,X
 LSR 
 ROL NBUF2,X

 STA NBUF1,Y
 INX 
 CPX #$56
 BCC PRENIB1

 LDX #0
 TYA 
 BNE PRENIB1

 LDX #$55
PRENIB2 LDA NBUF2,X
 AND #$3F
 STA NBUF2,X
 DEX 
 BPL PRENIB2
 RTS 

 ORG $B82A

WRITE16 SEC ;anticipate write protect
 STX SLOTZ
 STX SLOTABS
 LDA WRTDAT,X
 LDA SETRD,X ;sense write protect
 BMI WEXIT
 LDA NBUF2
 STA WTEMP
 LDA #$FF ;sync byte
 STA SETWRT,X ;write 1st nibble
 ORA RDDATA,X
 PHA 
 PLA 
 NOP 
 LDY #4

WSYNC PHA 
 PLA 
 JSR WNIBL7
 DEY 
 BNE WSYNC
 LDA #$D5 ;first data mark
 JSR WNIBL9
 LDA #$AA ;2nd data mark
 JSR WNIBL9
 LDA #$AD ;3rd data mark
 JSR WNIBL9
 TYA ;clear checksum
 LDY #$56 ;NBUF2 index
 BNE WDATA1 ;always taken

WDATA LDA NBUF2,Y ;get prior 6-bit nibble
WDATA1 EOR NBUF2-1,Y ;and XOR with current nibble
 TAX 
 LDA NIBL,X
 LDX SLOTZ
 STA WRTDAT,X ;write nibble
 LDA RDDATA,X
 DEY ;next nibble
 BNE WDATA

 LDA WTEMP
 NOP 

WDATA2 EOR NBUF1,Y
 TAX 
 LDA NIBL,X
 LDX SLOTABS
 STA WRTDAT,X ;write nibble
 LDA RDDATA,X
 LDA NBUF1,Y
 INY 
 BNE WDATA2
 TAX 
 LDA NIBL,X

 LDX SLOTZ
 JSR WNIBL

 LDA #$DE ;DM4, bit slip mark
 JSR WNIBL9
 LDA #$AA ;DM5, bsm
 JSR WNIBL9
 LDA #$EB ;DM6, bsm
 JSR WNIBL9

 LDA #$FF
 JSR WNIBL9

 LDA SETRD,X

WEXIT LDA RDDATA,X
 RTS 

 ORG $B8B8

WNIBL9 CLC 

WNIBL7 PHA 
 PLA 

WNIBL STA WRTDAT,X
 ORA RDDATA,X
 RTS 

 ORG $B8C2

POSTNB16 LDY #0
POST1 LDX #$56
POST2 DEX 
 BMI POST1

 LDA NBUF1,Y
 LSR NBUF2,X
 ROL 
 LSR NBUF2,X
 ROL 

 STA (BUFADR),Y
 INY 
 CPY TO
 BNE POST2
 RTS 

 ORG $B8DC

READ16 LDY #$20

RSYNC DEY 
 BEQ RDERR

RSYNC1 LDA RDDATA,X
 BPL RSYNC1

RSYNC2 EOR #$D5
 BNE RSYNC
 NOP 

RSYNC3 LDA RDDATA,X
 BPL RSYNC3
 CMP #$AA
 BNE RSYNC2
 LDY #$56

RSYNC4 LDA RDDATA,X
 BPL RSYNC4
 CMP #$AD
 BNE RSYNC2

 LDA #0 ;init checksum

RDATA DEY
 STY IDX
RDATA1 LDY RDDATA,X
 BPL RDATA1
 EOR MSWAIT,Y
 LDY IDX
 STA NBUF2,Y
 BNE RDATA

RDATA2 STY IDX
RDATA3 LDY RDDATA,X
 BPL RDATA3
 EOR MSWAIT,Y
 LDY IDX
 STA NBUF1,Y
 INY 
 BNE RDATA2

RDATA4 LDY RDDATA,X
 BPL RDATA4
 CMP MSWAIT,Y
 BNE RDERR

RDATA5 LDA RDDATA,X
 BPL RDATA5
 CMP #$DE
 BNE RDERR
 NOP 

RDATA6 LDA RDDATA,X
 BPL RDATA6
 CMP #$AA
 BEQ RDADRX
RDERR SEC 
 RTS 

 ORG $B944

RDADR16 LDY #$FC
 STY COUNT
RDASYN INY 
 BNE RDASYN1
 INC COUNT
 BEQ RDERR

RDASYN1 LDA RDDATA,X
 BPL RDASYN1
RDASYN2 CMP #$D5
 BNE RDASYN
 NOP 

RDASYN3 LDA RDDATA,X
 BPL RDASYN3
 CMP #$AA
 BNE RDASYN2
 LDY #3

RDASYN4 LDA RDDATA,X
 BPL RDASYN4
 CMP #$96
 BNE RDASYN2

 LDA #0
RDAFLD STA CSUM

RDAFLD1 LDA RDDATA,X
 BPL RDAFLD1
 ROL 
 STA LAST

RDAFLD2 LDA RDDATA,X
 BPL RDAFLD2

 AND LAST

 STA SLOTEMP+1,Y
 EOR CSUM
 DEY 
 BPL RDAFLD

 TAY 
 BNE RDERR

RDAFLD3 LDA RDDATA,X
 BPL RDAFLD3
 CMP #$DE
 BNE RDERR
 NOP 

RDAFLD4 LDA RDDATA,X
 BPL RDAFLD4
 CMP #$AA
 BNE RDERR
RDADRX CLC 
 RTS 

 ORG $B9A0

SEEKABS STX SLOTEMP
 STA TRKN
 CMP DRV0TRK
 BEQ RTS0
 LDA #0
 STA TRKCNT
MOVHEAD LDA DRV0TRK
 STA PRIOR
 SEC 
 SBC TRKN
 BEQ ISTHERE
 BCS MOVHEAD1
 EOR #$FF
 INC DRV0TRK
 BCC MOVHEAD2
MOVHEAD1 ADC #$FE
 DEC DRV0TRK
MOVHEAD2 CMP TRKCNT
 BCC MOVHEAD3
 LDA TRKCNT
MOVHEAD3 CMP #$C
 BCS MOVHEAD4
 TAY 
MOVHEAD4 SEC
 JSR CHKPOS
 LDA ONTBL,Y
 JSR MSWAIT
 LDA PRIOR
 CLC 
 JSR CHKPOS2
 LDA OFFTBL,Y
 JSR MSWAIT
 INC TRKCNT
 BNE MOVHEAD
ISTHERE JSR MSWAIT
 CLC 
CHKPOS LDA DRV0TRK
CHKPOS2 AND #3
 ROL 
 ORA SLOTEMP
 TAX 
 LDA PHASEOFF,X
 LDX SLOTEMP
RTS0 RTS 
 TAX 
 LDY #$A0

 ORG $BA00

MSWAIT LDX #$11
MSWAIT1 DEX ;delay 86 usec
 BNE MSWAIT1
 INC MONTIMEL
 BNE MSWAIT2
 INC MONTIMEH
MSWAIT2 SEC
 SBC #1
 BNE MSWAIT
 RTS 

 ORG $BA11

ONTBL HEX 0130
 HEX 2824201E1D1C1C1C1C1C
OFFTBL HEX 702C26221F1E1D1C1C1C1C1C

NIBL HEX 96979A9B9D9E9FA6A7ABACADAEAFB2B3
 HEX B4B5B6B7B9BABBBCBDBEBFCBCDCECFD3
 HEX D6D7D9DADBDCDDDEDFE5E6E7E9EAEBEC
 HEX EDEEEFF2F3F4F5F6F7F9FAFBFCFDFEFF

 DS 45

 HEX 0001989902039C040506A0A1A2A3A4A5
 HEX 0708A8A9AA090A0B0C0DB0B10E0F1011
 HEX 1213B81415161718191AC0C1C2C3C4C5
 HEX C6C7C8C9CA1BCC1C1D1ED0D1D21FD4D5
 HEX 2021D822232425262728E0E1E2E3E429
 HEX 2A2BE82C2D2E2F303132F0F133343536
 HEX 3738F8393A3B3C3D3E3F

 ORG $BB00

NBUF1 DS $100
NBUF2 DS $56

 ORG $BC56

WRADR16 SEC ;assume W/P error
 LDA WRTDAT,X
 LDA SETRD,X
 BMI WPERROR

 LDA #$FF
 STA SETWRT,X
 CMP RDDATA,X
 PHA 
 PLA 
FRMSYNC JSR WAIT12
 JSR WAIT12
 STA WRTDAT,X
 CMP RDDATA,X
 NOP 
 DEY 
 BNE FRMSYNC

 LDA #$D5
 JSR WBYTE9
 LDA #$AA
 JSR WBYTE9
 LDA #$96
 JSR WBYTE9

 LDA VOLUME
 JSR WBYTE
 LDA TRACK
 JSR WBYTE
 LDA BUFADR+1
 JSR WBYTE
 LDA VOLUME
 EOR TRACK
 EOR BUFADR+1
 PHA 
 LSR 
 ORA BUFADR
 STA WRTDAT,X
 LDA RDDATA,X
 PLA 
 ORA #$AA
 JSR WBYTE11

 LDA #$DE
 JSR WBYTE9
 LDA #$AA
 JSR WBYTE9
 LDA #$EB
 JSR WBYTE9
 CLC 
WPERROR LDA SETRD,X
 LDA RDDATA,X
WAIT12 RTS 

 ORG $BCC4

WBYTE PHA 
 LSR 
 ORA BUFADR

 STA WRTDAT,X
 CMP RDDATA,X
 PLA 
 NOP 
 NOP 
 NOP 
 ORA #$AA
WBYTE11 NOP 
WBYTE9 NOP 
 PHA 
 PLA 

 STA WRTDAT,X
 CMP RDDATA,X
 RTS 

 DS 33

 ORG $BD00

RWTS = *

 STY IOBPL
 STA IOBPH

 LDY #2
 STY RECALCNT
 LDY #4
 STY SEEKCNT

 LDY #1
 LDA (IOBPL),Y
 TAX 

 LDY #$F
 CMP (IOBPL),Y
 BEQ SAMESLOT

 TXA 
 PHA 
 LDA (IOBPL),Y
 TAX 
 PLA 
 PHA 
 STA (IOBPL),Y
 LDA SETRD,X

STILLON LDY #8
 LDA RDDATA,X
NOTSURE CMP RDDATA,X
 BNE STILLON
 DEY 
 BNE NOTSURE
 PLA 
 TAX 

SAMESLOT LDA SETRD,X
 LDA RDDATA,X
 LDY #8
NOTSURE1 LDA RDDATA,X
 PHA 
 PLA 
 PHA 
 PLA 
 STX SLOT
 CMP RDDATA,X
 BNE NOTSURE2
 DEY 
 BNE NOTSURE1
NOTSURE2 PHP
 LDA DRVON,X

 LDY #6
PTRMOVE LDA (IOBPL),Y
 STA PTRSDEST,Y
 INY 
 CPY #$A
 BNE PTRMOVE

 LDY #3
 LDA (DEVCTBL),Y
 STA MONTIMEH
 LDY #2
 LDA (IOBPL),Y
 LDY #$10
 CMP (IOBPL),Y
 BEQ PTRMOVE1
 STA (IOBPL),Y
 PLP 
 LDY #0
 PHP 
PTRMOVE1 ROR
 BCC PTRMOVE2
 LDA DRVSL1,X
 BCS DRVSEL
PTRMOVE2 LDA DRVSL2,X

DRVSEL ROR DRIVNO
 PLP 
 PHP 
 BNE NOWAIT
 LDY #7

STEPWAIT JSR MSWAIT
 DEY 
 BNE STEPWAIT
 LDX SLOT
NOWAIT LDY #4
 LDA (IOBPL),Y
 JSR MYSEEK
 PLP 
 BNE TRYTRK
 LDY MONTIMEH
 BPL TRYTRK

MOTOROF LDY #$12
MOTOROF1 DEY
 BNE MOTOROF1
 INC MONTIMEL
 BNE MOTOROF
 INC MONTIMEH
 BNE MOTOROF

TRYTRK LDY #$C
 LDA (IOBPL),Y
 BEQ GALLDONE
 CMP #4
 BEQ FORMDSK
 ROR 
 PHP ;save R/W status
 BCS TRYTRK2

 JSR PRENIB16

TRYTRK2 LDY #$30
 STY RETRYCNT
TRYADR LDX SLOT
 JSR RDADR16
 BCC RDRIGHT
TRYADR2 DEC RETRYCNT
 BPL TRYADR

RECAL LDA CURTRK
 PHA 
 LDA #$60
 JSR SETTRK
 DEC RECALCNT
 BEQ DRVERROR
 LDA #4
 STA SEEKCNT
 LDA #0
 JSR MYSEEK
 PLA 
RESEEK JSR MYSEEK
 JMP TRYTRK2

 ORG $BDED

RDRIGHT LDY TRKFND
 CPY CURTRK
 BEQ RTTRK

 LDA CURTRK
 PHA 
 TYA 
 JSR SETTRK
 PLA 
 DEC SEEKCNT
 BNE RESEEK
 BEQ RECAL

DRVERROR PLA 
 LDA #$40

JMPTO1 PLP 
 JMP HNDLERR
GALLDONE BEQ ALLDONE
FORMDSK JMP DSKFORM

 ORG $BE10

RTTRK LDY #3
 LDA (IOBPL),Y ;get desired volume
 PHA 

 LDA VOLFND
 LDY #$E
 STA (IOBPL),Y

 PLA 
 BEQ CRCTVOL

 CMP VOLFND
 BEQ CRCTVOL
 LDA #$20
 BNE JMPTO1

CRCTVOL LDY #5
 LDA (IOBPL),Y ;get the sector #

 TAY 
 LDA INTRLEAV,Y

 CMP SECFND
 BNE TRYADR2

 PLP 
 BCC WRIT

 JSR READ16
 PHP 
 BCS TRYADR2
 PLP 
 LDX #0
 STX TO

 JSR POSTNB16
 LDX SLOT
ALLDONE CLC 
 DFB $24 ;BIT L38
HNDLERR SEC ;OPCODE SKIPPED BY BIT L38
 LDY #$D
 STA (IOBPL),Y
 LDA DRVOFF,X
 RTS 

 ORG $BE51

WRIT JSR WRITE16
 BCC ALLDONE
 LDA #$10
 BCS HNDLERR

MYSEEK PHA 
 LDY #1
 LDA (DEVCTBL),Y
 ROR 
 PLA 
 BCC SEEK1
 ASL 
 JSR SEEK1
 LSR CURTRK
 RTS 
SEEK1 STA TRKN
 JSR XTOY
 LDA DRV0TRK,Y
 BIT DRIVNO
 BMI WASDO
 LDA DRV1TRK,Y
WASDO STA DRV0TRK
 LDA TRKN
 BIT DRIVNO
 BMI ISDRV0
 STA DRV1TRK,Y
 BPL GOSEEK
ISDRV0 STA DRV0TRK,Y
GOSEEK JMP SEEKABS
XTOY TXA 
 LSR 
 LSR 
 LSR 
 LSR 
 TAY 
 RTS 

 ORG $BE95

SETTRK PHA 
 LDY #2
 LDA (IOBPL),Y
 ROR 
 ROR DRIVNO
 JSR XTOY
 PLA 
 ASL 
 BIT DRIVNO
 BMI ONDRV0
 STA DRV1TRK,Y
 BPL RTS3
ONDRV0 STA DRV0TRK,Y
RTS3 RTS 

 ORG $BEAF

DSKFORM LDY #3
 LDA (IOBPL),Y
 STA VOLUME

 LDA #$AA
 STA BUFADR
 LDY #$56

 LDA #0
 STA TRACK

DSKFORM1 STA NBUF2-1,Y
 DEY 
 BNE DSKFORM1

DSKFORM2 STA NBUF1,Y
 DEY
 BNE DSKFORM2

 LDA #$50
 JSR SETTRK

 LDA #$28
 STA SYNCNT

NXTTRK LDA TRACK
 JSR MYSEEK
 JSR DISKF2

 LDA #8
 BCS HNDERR
 LDA #$30
 STA RETRYCNT

NOGOOD SEC 
 DEC RETRYCNT
 BEQ HNDERR

 JSR RDADR16
 BCS NOGOOD ;something wrong?

 LDA SECFND
 BNE NOGOOD

 JSR READ16
 BCS NOGOOD

 INC TRACK

 LDA TRACK
 CMP #$23
 BCC NXTTRK

 CLC 
 BCC DONEDSK

HNDERR LDY #$D
 STA (IOBPL),Y
 SEC 

DONEDSK LDA DRVOFF,X
 RTS 

 ORG $BF00

DISKF2 LDA #0 ;init sector #
 STA BUFADR+1
 LDY #$80 ;begin track with 128 sync bytes

 BNE TRKFRM1

TRKFRM LDY SYNCNT
TRKFRM1 JSR WRADR16 ;write an address field
 BCS DELAY12

 JSR WRITE16
 BCS DELAY12

 INC BUFADR+1
 LDA BUFADR+1
 CMP #$10
 BCC TRKFRM

 LDY #$F
 STY BUFADR+1

 LDA #$30
 STA RETRYCNT
INITMAP STA SECMAP,Y
 DEY 
 BPL INITMAP
 LDY SYNCNT
DELAY JSR DELAY12
 JSR DELAY12
 JSR DELAY12
 PHA 
 PLA 
 NOP 
 DEY 
 BNE DELAY
 JSR RDADR16
 BCS DOAGAIN
 LDA SECFND
 BEQ ITSGOOD
 LDA #$10
 CMP SYNCNT
 LDA SYNCNT
 SBC #1
 STA SYNCNT
 CMP #5
 BCS DOAGAIN
 SEC 
 RTS 
NXTSEC JSR RDADR16
 BCS NXTTRY
ITSGOOD JSR READ16
 BCC MARKMAP
NXTTRY DEC RETRYCNT
 BNE NXTSEC
DOAGAIN JSR RDADR16
 BCS ERRCNT
 LDA SECFND
 CMP #$F
 BNE ERRCNT
 JSR READ16
 BCC DISKF2
ERRCNT DEC RETRYCNT
 BNE DOAGAIN
 SEC 
DELAY12 RTS 
MARKMAP LDY SECFND
 LDA SECMAP,Y
 BMI NXTTRY
 LDA #$FF
 STA SECMAP,Y
 DEC BUFADR+1
 BPL NXTSEC
 LDA TRACK
 BNE TRKDONE
 LDA SYNCNT
 CMP #$10
 BCC DELAY12
 DEC SYNCNT
 DEC SYNCNT
TRKDONE CLC 
 RTS 

 ORG $BFA8

SECMAP HEX FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

INTRLEAV HEX 000D0B09070503010E0C0A080604020F

 ORG $BFC8

 JSR SETVID
 LDA ROM
 LDA ROM
 LDA #0
 STA BASIC
 JMP RESTART

 DS 3

 ORG $BFDC

 STA TEMP1
 STA BYTVAL
 STA BYTVAL+1
 RTS 
 JSR RSET0
 STY RUNINTRC
 RTS 
 JSR SAVFMW
 LDX STKSAVE
 TXS 
 JSR CLOSEALL
 TSX 
 STX STKSAVE
 LDA #9
 JMP SETERROR