antoine-source/diskotape/diskotape.s

625 lines
15 KiB
ArmAsm
Raw Normal View History

2024-03-13 03:41:35 +00:00
*
* Disk-o-Tape
* (c) 1980, Dann McCreary
*
TYP BIN
ORG $005100
MX %11
*-----------------------------------
CSWL = $36
CSWH = $37
A1L = $3C
A1H = $3D
2024-03-13 10:24:18 +00:00
KBD = $C000
KBDSTROBE = $C010
PRBL2 = $F94A
HOME = $FC58
WAIT = $FCA8
RDCHAR = $FD35
GETLN = $FD6A
CROUT = $FD8E
PRBYTE = $FDDA
COUT = $FDED
COUT1 = $FDF0
WRITE = $FECD
READ = $FEFD
BELL = $FF3A
2024-03-13 03:41:35 +00:00
L1000 = $1000
L5000 = $5000 ; Where the VTOC is loaded
*-----------------------------------
2024-03-13 10:24:18 +00:00
L5100 JMP L510A ; read entry point
2024-03-13 03:41:35 +00:00
2024-03-13 10:24:18 +00:00
LDY $8034 ; write entry point
2024-03-13 03:41:35 +00:00
LDA #$02
BNE L510C
L510A LDA #$01 ; Read command
L510C PHA
2024-03-13 10:24:18 +00:00
LDX #$14 ; copy default IOB table
2024-03-13 03:41:35 +00:00
L510F LDA IOB_DFT,X
STA IOB,X
DEX
BNE L510F
PLA
STA IOB_COMMAND
2024-03-13 10:24:18 +00:00
JSR resetCOUT
2024-03-13 03:41:35 +00:00
JSR HOME
LDA IOB_COMMAND
LSR
2024-03-13 10:24:18 +00:00
BNE L5131 ; go write
JSR L54E1 ; go read
2024-03-13 03:41:35 +00:00
JSR CROUT
JMP L514D
2024-03-13 10:24:18 +00:00
L5131 LDY #$0A ; COPY TAPE -> DISK
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$25 ; wait
2024-03-13 03:41:35 +00:00
L513B LDA #$FF
JSR WAIT
DEY
BNE L513B
2024-03-13 10:24:18 +00:00
LDY #$1A ; DISK NAME
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDY #$1E ; :
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
L514D LDY #$1C ; The disk name
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
JSR L52AA ; handle VTOC
2024-03-13 03:41:35 +00:00
LDA #$01
STA L55FB
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$0C ; TK/SC
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
L5162 JSR L51D8 ; read/write buffer
JSR L51A5 ; write/read it
LDA IOB_TRACK ; are we done?
2024-03-13 03:41:35 +00:00
BMI L5175
CLC
ADC IOB_SECTOR
CMP #$00
BNE L5162
2024-03-13 10:24:18 +00:00
2024-03-13 03:41:35 +00:00
L5175 LDA IOB_COMMAND
LSR
2024-03-13 10:24:18 +00:00
BNE L517E ; go write
JMP L554E ; go verify/read
2024-03-13 03:41:35 +00:00
L517E JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$08 ; COPY DONE
2024-03-13 03:41:35 +00:00
L5183 JSR CROUT
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
JSR L518F ; wait for key
JMP $03D0 ; return to DOS
2024-03-13 03:41:35 +00:00
L518F BIT KBDSTROBE
L5192 LDY #$07
L5194 LDA #$FF
JSR WAIT
DEY
BNE L5194
JSR BELL
LDA KBD
BPL L5192
RTS
2024-03-13 10:24:18 +00:00
*----------
2024-03-13 03:41:35 +00:00
L51A5 LDA IOB_COMMAND
LSR
2024-03-13 10:24:18 +00:00
BNE L51DE ; go write
2024-03-13 03:41:35 +00:00
L51AB LDY #$00
2024-03-13 10:24:18 +00:00
*-----------------------------------
doTAPECMD LDX #$03 ; move tape parms to A1/A2
2024-03-13 03:41:35 +00:00
L51AF LDA L52FC,Y
STA A1L,X
INY
DEX
BPL L51AF
2024-03-13 10:24:18 +00:00
LDA IOB_COMMAND ; either read from or write to tape
2024-03-13 03:41:35 +00:00
AND #$01
BNE L51D5
2024-03-13 10:24:18 +00:00
JSR setCOUT ; modify COUT
JSR READ ; read from tape
2024-03-13 03:41:35 +00:00
PHP
2024-03-13 10:24:18 +00:00
JSR resetCOUT ; reset COUT
2024-03-13 03:41:35 +00:00
PLP
BEQ L51D4
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$18 ; TAPE READ ERROR
2024-03-13 03:41:35 +00:00
JMP L52A2
L51D4 RTS
2024-03-13 10:24:18 +00:00
L51D5 JMP WRITE ; write to tape
*-----------------------------------
2024-03-13 03:41:35 +00:00
L51D8 LDA IOB_COMMAND
LSR
2024-03-13 10:24:18 +00:00
BNE L51AB ; go write
L51DE LDA #>L1000 ; set buffer at $1000
2024-03-13 03:41:35 +00:00
STA IOB_BUFFER+1
STA A1H
LDA #<L1000
STA IOB_BUFFER
STA A1L
2024-03-13 10:24:18 +00:00
LDA IOB_COMMAND ; command?
2024-03-13 03:41:35 +00:00
LSR
BNE L5206
2024-03-13 10:24:18 +00:00
*-- Read
LDA #$20 ; read means clear $1000..$2FFF
STA nbPAGES
2024-03-13 03:41:35 +00:00
LDY #$00
TYA
2024-03-13 10:24:18 +00:00
L51FA STA (A1L),Y
2024-03-13 03:41:35 +00:00
INY
BNE L51FA
INC A1H
2024-03-13 10:24:18 +00:00
DEC nbPAGES ; page--
2024-03-13 03:41:35 +00:00
BNE L51FA
2024-03-13 10:24:18 +00:00
*-- Write means do not erase buffer
2024-03-13 03:41:35 +00:00
L5206 LDA #$20
2024-03-13 10:24:18 +00:00
STA nbPAGES
LDA L55FB ; check pass
2024-03-13 03:41:35 +00:00
BEQ L5215
2024-03-13 10:24:18 +00:00
DEC L55FB ; tell we've been there
BEQ L522F ; handle first case
L5215 JSR L52D5 ; get sector usage
2024-03-13 03:41:35 +00:00
LDA IOB_TRACK
SEC
SBC #$00
BPL L522F
STA IOB_TRACK
2024-03-13 10:24:18 +00:00
LDY nbPAGES ; wait again
2024-03-13 03:41:35 +00:00
L5226 LDA #$D7
JSR WAIT
DEY
BNE L5226
RTS
L522F JSR GO_RWTS
2024-03-13 10:24:18 +00:00
LDA IOB_TRACK ; show T
2024-03-13 03:41:35 +00:00
JSR PRBYTE
LDX #$01
JSR PRBL2
2024-03-13 10:24:18 +00:00
LDA IOB_SECTOR ; show S
2024-03-13 03:41:35 +00:00
JSR PRBYTE
LDA #$00
STA $24
INC IOB_BUFFER+1
2024-03-13 10:24:18 +00:00
DEC nbPAGES ; nb pages
2024-03-13 03:41:35 +00:00
BNE L5215
RTS
2024-03-13 10:24:18 +00:00
*---------- Redirect COUT vector
setCOUT LDA #<L5262
2024-03-13 03:41:35 +00:00
STA CSWL
LDA #>L5262
STA CSWH
RTS
2024-03-13 10:24:18 +00:00
*---------- Reset COUT vector
resetCOUT LDA #<COUT1
2024-03-13 03:41:35 +00:00
STA CSWL
2024-03-13 10:24:18 +00:00
LDA #>COUT1
2024-03-13 03:41:35 +00:00
STA CSWH
RTS
2024-03-13 10:24:18 +00:00
*---------- My COUT routine
2024-03-13 03:41:35 +00:00
L5262 CMP #$87
BEQ L526A
PLA
PLA
LDA #$FF
L526A RTS
*-----------------------------------
PRINTSTRING LDA L5329,Y ; PRINT STRING
STA $01
LDA L532A,Y
STA $00
LDY #$FF
L5277 INY
LDA ($00),Y
ORA #$80
JSR COUT
LDA ($00),Y
BMI L5277
RTS
*-----------------------------------
2024-03-13 10:24:18 +00:00
GO_RWTS LDA #>IOB ; execute a RWTS call
2024-03-13 03:41:35 +00:00
LDY #<IOB
JSR $03D9
BCC L5290
JSR L5291
L5290 RTS
2024-03-13 10:24:18 +00:00
*---------- Handle error
2024-03-13 03:41:35 +00:00
L5291 LDA IOB_ERRCODE
2024-03-13 10:24:18 +00:00
LDY #$0E ; DISK WRITE PROTECTED
CMP #$10 ;
2024-03-13 03:41:35 +00:00
BEQ L52A2
2024-03-13 10:24:18 +00:00
LDY #$10 ; DISK READ ERROR
CMP #$80 ;
2024-03-13 03:41:35 +00:00
BEQ L52A2
2024-03-13 10:24:18 +00:00
LDY #$12 ; DISK DRIVE ERROR
2024-03-13 03:41:35 +00:00
L52A2 JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDY #$16 ; COPY ABORT
2024-03-13 03:41:35 +00:00
JMP L5183
*-----------------------------------
2024-03-13 10:24:18 +00:00
* See the DOS 3.3 manual, page 132
2024-03-13 03:41:35 +00:00
2024-03-13 10:24:18 +00:00
L52AA LDA #$23 ; last track
2024-03-13 03:41:35 +00:00
NOP
STA IOB_TRACK
2024-03-13 10:24:18 +00:00
ASL ; *2
ASL ; *4
2024-03-13 03:41:35 +00:00
CLC
2024-03-13 10:24:18 +00:00
ADC #$38 ; C4
2024-03-13 03:41:35 +00:00
STA L55F9
L52B8 LDA #$00
STA L55F8
2024-03-13 10:24:18 +00:00
LDA L55F9 ; C4 - 4 = C0 => T22 bitmap
2024-03-13 03:41:35 +00:00
SEC
SBC #$04
TAX
STX L55F9
STX L55FA
2024-03-13 10:24:18 +00:00
2024-03-13 03:41:35 +00:00
DEC IOB_TRACK
BMI L52FB
2024-03-13 10:24:18 +00:00
LDA #$10 ; last sector
2024-03-13 03:41:35 +00:00
NOP
STA IOB_SECTOR
2024-03-13 10:24:18 +00:00
*---------- The VTOC is at $5000
* Bitmap starts at $5038
2024-03-13 12:17:19 +00:00
* Each bit set means a free sector
2024-03-13 10:24:18 +00:00
* Byte 1 Byte 2
* Bit 76543210 76543210
* Sector FEDCBA98 76543210
L52D5 LDX L55FA ; index within T22..
2024-03-13 03:41:35 +00:00
DEC IOB_SECTOR
2024-03-13 10:24:18 +00:00
BMI L52B8 ; next track please
L52DD CLC ; return bit sector usage within bitmap
2024-03-13 03:41:35 +00:00
LDA L55F8
BNE L52E4
SEC
L52E4 ROR
BNE L52EB
INX
STX L55FA
L52EB STA L55F8
LDA L55F8
BEQ L52DD
2024-03-13 10:24:18 +00:00
AND $5000,X ; The VTOC lies at $5000
2024-03-13 03:41:35 +00:00
NOP
NOP
STX L55FA
L52FB RTS
*---------- Read/Write Tape commands
2024-03-13 10:24:18 +00:00
* Put at A1/A2 ($3C..$3F): FROM..TO
2024-03-13 03:41:35 +00:00
* Code puts it inverted
2024-03-13 10:24:18 +00:00
L52FC DB $2F ; 0 1000..2FFF
2024-03-13 03:41:35 +00:00
DB $FF
DB $10
DB $00
2024-03-13 10:24:18 +00:00
DB $4F ; 4 3000..4FFF
2024-03-13 03:41:35 +00:00
DB $FF
DB $30
DB $00
2024-03-13 10:24:18 +00:00
DB $54 ; 8 5000..5460
2024-03-13 03:41:35 +00:00
DB $60
DB $50
DB $00
2024-03-13 10:24:18 +00:00
DB $34 ; C 3000..3460
2024-03-13 03:41:35 +00:00
DB $60
DB $30
DB $00
2024-03-13 10:24:18 +00:00
DB $54 ; 10 53FE..543E
2024-03-13 03:41:35 +00:00
DB $3E
DB $53
DB $FE
2024-03-13 10:24:18 +00:00
DB $30 ; 14 3000..3040
2024-03-13 03:41:35 +00:00
DB $40
DB $30
DB $00
*---------- Default IOB table
IOB_DFT DB $01
DB $60
DB $01
DB $00
DB $00
DB $00
DA $54DD
DA $1000
DB $00
DB $00
DB $00
DB $00
DB $00
DB $60
DB $01
DB $00
DB $01
DB $EF
DB $D8
*---------- Pointers to strings (all inverted...)
2024-03-13 10:24:18 +00:00
L5329 DB >L53C3 ; 0 DISK-O-TAPE/PASCAL
2024-03-13 03:41:35 +00:00
L532A DB <L53C3
2024-03-13 10:24:18 +00:00
DB >L543C ; 2 PLEASE INSERT DISK TO BE COPIED
2024-03-13 03:41:35 +00:00
DB <L543C
2024-03-13 10:24:18 +00:00
DB >L5418 ; 4 COPYRIGHT
2024-03-13 03:41:35 +00:00
DB <L5418
2024-03-13 10:24:18 +00:00
DB >L5498 ; 6 PLEASE REWIND TAPE...
2024-03-13 03:41:35 +00:00
DB <L5498
2024-03-13 10:24:18 +00:00
DB >L536A ; 8 COPY DONE
2024-03-13 03:41:35 +00:00
DB <L536A
2024-03-13 10:24:18 +00:00
DB >L5374 ; A COPY TAPE -> DISK
2024-03-13 03:41:35 +00:00
DB <L5374
2024-03-13 10:24:18 +00:00
DB >L5386 ; C TK/SC
2024-03-13 03:41:35 +00:00
DB <L5386
2024-03-13 10:24:18 +00:00
DB >L538C ; E DISK WRITE PROTECTED
2024-03-13 03:41:35 +00:00
DB <L538C
2024-03-13 10:24:18 +00:00
DB >L53A1 ; 10 DISK READ ERROR
2024-03-13 03:41:35 +00:00
DB <L53A1
2024-03-13 10:24:18 +00:00
DB >L53B1 ; 12 DISK DRIVE ERROR
2024-03-13 03:41:35 +00:00
DB <L53B1
2024-03-13 10:24:18 +00:00
DB >L545C ; 14 COPY DISK -> TAPE
2024-03-13 03:41:35 +00:00
DB <L545C
2024-03-13 10:24:18 +00:00
DB >L534F ; 16 COPY ABORT
2024-03-13 03:41:35 +00:00
DB <L534F
2024-03-13 10:24:18 +00:00
DB >L535A ; 18 TAPE READ ERROR
2024-03-13 03:41:35 +00:00
DB <L535A
2024-03-13 10:24:18 +00:00
DB >L53D6 ; 1A DISK NAME
2024-03-13 03:41:35 +00:00
DB <L53D6
2024-03-13 10:24:18 +00:00
DB >L53DF ; 1C " "
2024-03-13 03:41:35 +00:00
DB <L53DF
2024-03-13 10:24:18 +00:00
DB >L53C2 ; 1E :
2024-03-13 03:41:35 +00:00
DB <L53C2
2024-03-13 10:24:18 +00:00
DB >L546E ; 20 ERROR DURING
2024-03-13 03:41:35 +00:00
DB <L546E
2024-03-13 10:24:18 +00:00
DB >L547B ; 22 TAPE VERIFY
2024-03-13 03:41:35 +00:00
DB <L547B
2024-03-13 10:24:18 +00:00
DB >L5488 ; 24 VERIFY COMPLETE
2024-03-13 03:41:35 +00:00
DB >L5488
L534F ASC "COPY ABORT"0D
L535A ASC "TAPE READ ERROR"0D
L536A ASC "COPY DONE"0D
L5374 ASC "COPY TAPE -> DISK"0D
L5386 ASC "TK/SC"0D
L538C ASC "DISK WRITE PROTECTED"0D
L53A1 ASC "DISK READ ERROR"0D
L53B1 ASC "DISK DRIVE ERROR"0D
L53C2 ASC ':'
L53C3 ASC "DISK-O-TAPE/PASCAL"0D
L53D6 ASC "DISK NAM"
ASC 'E'
L53DF ASC " "
L53E0 ASC "SPACE RESERVED FOR DISK NAME "0D
L53FE ASC "200.240R 5000.5460R 5103G"8D
L5418 ASC "COPYRIGHT (C) 1980 BY DANN MCCREARY"0D
L543C ASC "PLEASE INSERT DISK TO BE COPIED"0D
L545C ASC "COPY DISK -> TAPE"0D
L546E ASC "ERROR DURING "
L547B ASC "TAPE VERIFY"8D0D
L5488 ASC "VERIFY COMPLETE"0D
L5498 ASC "PLEASE REWIND TAPE, START"8D
ASC "RECORDER AND PRESS RETURN"0D
*-----------------------------------
IOB DB $01 ; 0 IOB type
DB $60 ; 1 Slot number * 16
DB $01 ; 2 Disk drive
DB $00 ; 3 Expected volume number
IOB_TRACK DB $00 ; 4 Track
IOB_SECTOR DB $00 ; 5 Sector
DA L54DD
IOB_BUFFER DA $1000 ; 8 Buffer
DB $00
DB $00
IOB_COMMAND DB $00 ; Command
IOB_ERRCODE DB $00 ; Error code
DB $00
DB $60
DB $01
L54DD DB $00 ; DCT
DB $01
DB $EF
DB $D8
*-----------------------------------
MX %11
2024-03-13 10:24:18 +00:00
L54E1 LDY #$00 ; DISK-O-TAPE PASCAL
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDY #$04 ; COPYRIGHT
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$02 ; PLEASE INSERT DISK TO BE COPIED
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$1A ; DISK NAME
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDA #$BF ; cursor
2024-03-13 03:41:35 +00:00
STA |$0033
JSR GETLN
2024-03-13 10:24:18 +00:00
CPX #$1D ; length of string
2024-03-13 03:41:35 +00:00
BCC L5509
2024-03-13 10:24:18 +00:00
LDX #$1D ; put a final CR
2024-03-13 03:41:35 +00:00
L5509 LDA #$0D
STA L53E0,X
2024-03-13 10:24:18 +00:00
L550E LDA $0200,X ; copy disk name
2024-03-13 03:41:35 +00:00
STA L53DF,X
DEX
BPL L550E
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$06 ; PLEASE REWIND TAPE
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
JSR RDCHAR
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$14 ; COPY DISK -> TAPE
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDY #$10 ; 53FE..543E -> 200.240R 5000.5460R 5103G + COPYRIGHT (C) 1980 BY DANN MCCREARY
JSR doTAPECMD
2024-03-13 03:41:35 +00:00
JSR L5537 ; read VTOC
2024-03-13 10:24:18 +00:00
LDY #$08 ;
JMP doTAPECMD
2024-03-13 03:41:35 +00:00
*---------- Read (write?) VTOC
L5537 LDA #$00
STA IOB_SECTOR
LDA #$11
STA IOB_TRACK
LDA #>L5000
STA IOB_BUFFER+1
LDA #<L5000
STA IOB_BUFFER
JMP GO_RWTS
*----------
L554E JSR HOME
2024-03-13 10:24:18 +00:00
LDY #$22 ; TAPE VERIFY
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDY #$06 ; PLEASE REWIND TAPE...
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
JSR L518F
2024-03-13 10:24:18 +00:00
LDA #$01 ; read
2024-03-13 03:41:35 +00:00
STA IOB_COMMAND
JSR L5537
2024-03-13 10:24:18 +00:00
LDY #$14 ; 3000..3040
2024-03-13 03:41:35 +00:00
JSR L55B9
2024-03-13 10:24:18 +00:00
LDY #$0C ; 3000..3460
2024-03-13 03:41:35 +00:00
JSR L55B9
JSR L52AA
LDA #$01
STA L55FB
JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$1C ; " "
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
LDY #$0C ; TK/SC
2024-03-13 03:41:35 +00:00
JSR PRINTSTRING
2024-03-13 10:24:18 +00:00
L5585 LDA #$01 ; read
2024-03-13 03:41:35 +00:00
STA IOB_COMMAND
JSR L51DE
2024-03-13 10:24:18 +00:00
LDY #$04 ; 3000..4FFF
2024-03-13 03:41:35 +00:00
JSR L55B9
LDA IOB_TRACK
BMI L559F
CLC
ADC IOB_SECTOR
CMP #$00
BNE L5585
L559F JSR CROUT
2024-03-13 10:24:18 +00:00
LDY #$24 ; VERIFY COMPLETE
2024-03-13 03:41:35 +00:00
JMP L5183
L55A7 LDX #$07
L55A9 CPX #$05
BNE L55AF
DEX
DEX
L55AF LDA L52FC,Y
STA A1L,X
INY
DEX
BPL L55A9
RTS
L55B9 STY L55FE
2024-03-13 10:24:18 +00:00
LDA #$02 ; write
2024-03-13 03:41:35 +00:00
STA IOB_COMMAND
2024-03-13 10:24:18 +00:00
JSR doTAPECMD
2024-03-13 03:41:35 +00:00
LDY L55FE
DEY
DEY
JSR L55A7
JSR L55E4
LDY #$00
2024-03-13 10:24:18 +00:00
JSR $FE36 ; ROM entry point VFY for verify
2024-03-13 03:41:35 +00:00
PHP
2024-03-13 10:24:18 +00:00
JSR resetCOUT
2024-03-13 03:41:35 +00:00
PLP
BCS L55E3
JSR CROUT
LDY #$20
JMP L52A2
L55E3 RTS
2024-03-13 10:24:18 +00:00
*---------- Set my COUT vector
2024-03-13 03:41:35 +00:00
L55E4 LDA #<L55ED
STA CSWL
LDA #>L55ED
STA CSWH
RTS
2024-03-13 10:24:18 +00:00
*---------- My second COUT routine
2024-03-13 03:41:35 +00:00
L55ED CMP #$87
BEQ L55F5
PLA
PLA
PLA
PLA
L55F5 CLC
RTS
2024-03-13 10:24:18 +00:00
*----------
nbPAGES DB $00
2024-03-13 03:41:35 +00:00
L55F8 DB $00
L55F9 DB $00
L55FA DB $00
L55FB DB $00
DB $00
DB $00
L55FE DB $00
DB $51