home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
SIMTEL
/
CPMUG
/
CPMUG019.ARK
/
TREAD.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-04-29
|
16KB
|
519 lines
; TDUMP - DUMP CASSETTE TAPE TO CONSOLE
;
; L.E. HUGHES 8080SDC 77/06/21
ORG 100H
; BDOS ENTRY POINT AND FUNCTION CODES
BDOS EQU 5
TYPEF EQU 2 ;TYPE CONSOLE CHARACTER
CONS EQU 01 ;READ CONSOLE
BRKF EQU 11 ;CONSOLE BREAKIN CHECK
CLOSEF EQU 16 ;CLOSE FILE
DELTF EQU 19 ;DELETE FILE
WRITEF EQU 21 ;WRITE FILE
MAKEF EQU 22 ;MAKE NEW FILE
; FILE CONTROL BLOCK DEFINITIONS
FCB EQU 5CH ;DEFAULT FILE CONTROL BLOCK ADDRESS
DBUF EQU 80H ;DEFAULT DISK BUFFER
FCBFN EQU FCB+1 ;FILE NAME
FCBFT EQU FCB+9 ;FILE TYPE
FCBCR EQU FCB+32 ;CURRENT RECORD
FNAME EQU FCBFN
; MISC. EQUATES
CASC EQU 6EH ;CASSETTE TAPE CONTROL/STATUS PORT
CASD EQU 6FH ;CASSETTE TAPE DATA PORT
CR EQU 0DH ;ASCII CARRIAGE RETURN
LF EQU 0AH ;ASCII LINE FEED
SOH EQU 01H ;ASCII START OF HEADER
STX EQU 02H ;ASCII START OF TEXT
ETX EQU 03H ;ASCII END OF TEXT
; MAIN PROGRAM
TDUMP: LXI H,0 ;SAVE ENTRY SP
DAD SP
SHLD OLDSP
LXI SP,STACK+64 ;SETUP LOCAL STACK
LXI H,MSG0 ;PRINT INSTRUCTIONS
CALL WAS
CALL RAC ;AWAIT RESPONSE, AND DISCARD IT
MVI A,0 ;READ FIRST PRU FROM TAPE 0
LXI H,TBUF
CALL CTRR
PUSH PSW
LXI H,MSG1 ;PRINT 'FILE NAME = '
CALL WAS
LXI H,FNAME ;PRINT FILE NAME
CALL WAS
CALL CRLF
POP PSW
CALL CTERR
IN 0FFH ;READ SENSESWITCHES
ANI 02H ;JUMP IF SW1 OFF
JZ TDUM7
CALL DELT ;DELETE FILE, IF IT EXISTS
CALL MAKE ;CREATE NEW FILE
XRA A ;POSITION TO BEGINNING OF FILE
STA FCBCR
TDUM7: PUSH D ;SAVE PRU SIZE
LXI H,0 ;INITIALIZE COUNTER
SHLD CTR
TDUM0: LXI H,MSG3 ;PRINT 'PRN = '
CALL WAS
LDA PRN ;PRINT PRN
CALL WHB
LXI H,MSG4 ;PRINT ' SIZE = '
CALL WAS
MOV A,D ;PRINT SIZE
CALL WHB
MOV A,E
CALL WHB
IN 0FFH ;READ SENSESWITCHES
ANI 01H ;JUMP IF SW0 OFF
JZ TDUM3
CALL CRLF
LXI H,TBUF ;DUMP PRU TO CONSOLE
TDUM1: MVI C,16 ;NUMBER OF BYTES PER LINE
CALL CRLF
PUSH H
LHLD CTR
MOV A,H ;PRINT COUNTER
CALL WHB
MOV A,L
CALL WHB
MVI A,' ' ;PRINT ONE SPACE
CALL WAC
POP H
PUSH D
PUSH H ;SAVE BUFFER POINTER
TDUM2: MOV A,D ;EXIT IF ENTIRE PRU DUMPED
ORA E
JZ TDUM6
MOV A,M ;FETCH NEXT BYTE
INX H
CALL WHB ;WRITE BYTE IN HEX
MVI A,' ' ;WRITE A SPACE
CALL WAC
PUSH H ;INCREMENT COUNTER
LHLD CTR
INX H
SHLD CTR
POP H
DCX D
DCR C ;LOOP IF MORE ROOM ON LINE
JNZ TDUM2
MVI A,' ' ;PRINT TWO SPACES
CALL WAC
CALL WAC
TDUM6: POP H ;RESTORE BUFFER POINTER
POP D
MVI C,16 ;NUMBER OF BYTES PER LINE
TDUM5: MOV A,D ;EXIT IF ENTIRE PRU DUMPED
ORA E
JZ TDUM3
MOV A,M ;FETCH NEXT BYTE
INX H
DCX D ;DECREMENT COUNT
ANI 7FH ;DISCARD TOP BIT
CPI ' ' ;CHANGE CONTROL CODES TO PERIOD
JNC $+5
MVI A,'.'
CALL WAC
DCR C
JNZ TDUM5
CALL BREAK ;CHECK FOR CONSOLE BREAKIN
RRC
JNC TDUM1 ;LOOP IF NO BREAKIN
CALL RAC ;ELSE DISCARD CHARACTER
JMP TDUM4 ;AND EXIT
TDUM3: CALL CRLF
POP D ;RESTORE BLOCK SIZE
IN 0FFH ;READ SENSESWITCHES
ANI 02H ;JUMP IF SW1 OFF
JZ TDUMB
PUSH D ;SAVE PRU SIZE
LXI H,TBUF
TDUM8: MOV A,D ;EXIT IF ENTIRE TAPE PRU WRITTEN
ORA E
JZ TDUMA
PUSH D ;COPY NEXT 128 BYTES FROM TBUF TO DBUF
LXI D,DBUF
MVI C,128
TDUM9: MOV A,M
INX H
STAX D
INX D
DCR C
JNZ TDUM9
POP D
CALL WRITE ;WRITE DBUF TO DISK
MOV A,E ;DE = DE - 128
SUI 128
MOV E,A
JNC $+4
DCR D
JMP TDUM8 ;LOOP
TDUMA: POP D ;RESTORE PRU SIZE
TDUMB: MOV A,D ;EXIT IF SHORT PRU
CPI 4
JC TDUM4
MVI A,0
LXI H,TBUF ;READ NEXT PRU FROM TAPE 0
CALL CTRR
CALL CTERR
PUSH D ;SAVE PRU SIZE
JMP TDUM0
TDUM4: CALL CRLF
IN 0FFH ;READ SENSESWITCHES
ANI 02H ;IF SW1 ON, CLOSE FILE
CNZ CLOSE
LHLD OLDSP ;RESTORE ENTRY SP
SPHL
RET ;RETURN TO CP/M
; WHB - WRITE HEX BYTE (FROM A)
WHB: PUSH PSW
RLC
RLC
RLC
RLC
CALL WHD
POP PSW
PUSH PSW
CALL WHD
POP PSW
RET
; WHD - WRITE HEX DIGIT (FROM LO 4 BITS OF A)
WHD: ANI 0FH ;MASK OFF LO 4 BITS
ADI '0' ;CONVERT TO ASCII
CPI '9'+1 ;IF '0' TO '9', GO PRINT
JC WAC
ADI 7 ;ELSE ADJUST 10-15 TO A-F
JMP WAC
; CLOSE - CLOSE DISK FILE
CLOSE: PUSH H
PUSH D
PUSH B
MVI C,CLOSEF
LXI D,FCB
CALL BDOS
POP B
POP D
POP H
RET
; DELT - DELETE FILE
DELT: PUSH H
PUSH D
PUSH B
MVI C,DELTF
LXI D,FCB
CALL BDOS
POP B
POP D
POP H
RET
; MAKE - MAKE NEW FILE
MAKE: PUSH H
PUSH D
PUSH B
MVI C,MAKEF
LXI D,FCB
CALL BDOS
POP B
POP D
POP H
RET
; WRITE - WRITE DISK FILE
WRITE: PUSH H
PUSH D
PUSH B
MVI C,WRITEF
LXI D,FCB
CALL BDOS
POP B
POP D
POP H
RET
; WAC - WRITE ASCII CHARACTER TO CONSOLE
;
; ENTRY CONDITIONS
; A - CHARACTER TO WRITE
WAC: PUSH H
PUSH D
PUSH B
MVI C,TYPEF
MOV E,A
CALL BDOS
POP B
POP D
POP H
RET
; RAC - READ ASCII CHARACTER FROM CONSOLE
;
; EXIT CONDITIONS
; A - 7 BIT ASCII CHARACTER
RAC: PUSH H
PUSH D
PUSH B
MVI C,CONS
CALL BDOS
POP B
POP D
POP H
RET
; BREAK - CHECK FOR CONSOLE BREAKIN
BREAK: PUSH H
PUSH D
PUSH B
MVI C,BRKF
CALL BDOS
POP B
POP D
POP H
RET
; WAS - WRITE ASCII STRING TO CONSOLE
;
; ENTRY CONDITIONS
; HL - POINTS TO STRING TO WRITE (TERM BY ZERO BYTE)
WAS: MOV A,M
INX H
ORA A
RZ
CALL WAC
JMP WAS
; CRLF - WRITE CR,LF TO CONSOLE
CRLF: MVI A,CR
CALL WAC
MVI A,LF
JMP WAC
; CTRR - READ PHYSICAL RECORD FROM CASSETTE TAPE
;
; FOR TARBELL INTERFACE WITH LASALLE RELAY BOARD
;
; PHYSICAL RECORD FORMAT
;
; BYTE SIZE FIELD CONTENTS
; 00 01 SOH (ASCII START-OF-HEADER)
; 01 08 FILENAME, LEFT JUSTIFIED, BLANK FILLED
; 09 03 FILETYPE, LEFT JUSTIFIED, BLANK FILLED
; 12 01 PHYSICAL RECORD NUMBER, 1 BYTE INTEGER
; 13 02 PHYSICAL RECORD SIZE, 2 BYTE INTEGER
; 15 01 STX (ASCII START-OF-TEXT)
; 16 XX DATA BYTES
; 16+XX 01 ETX (ASCII END-OF-TEXT)
; 17+XX 02 CYCLIC REDUNDANCY CHECK
;
; ENTRY CONDITIONS
; HL - POINTS TO BUFFER TO READ INTO
; A - TAPE UNIT NUMBER (0 OR 1)
;
; EXIT CONDITIONS
; DE - PHYSICAL RECORD SIZE
; PRN - PHYSICAL RECORD NUMBER
; FNAME - 11 BYTE NAME.TYPE BUFFER
; C-FLAG - SET IF ERROR(S), ELSE RESET
CTRR: PUSH PSW ;SAVE UNIT NO., ETC
ADD A ;MOVE UNIT NO. INTO POSITION
ORI 10H ;OR IN HUNT-MODE BIT
CALL CTON ;TURN ON SELECTED UNIT'S MOTOR
CALL CTINP ;READ FIRST BYTE OF RECORD
CPI SOH ;JUMP IF SOH (ALL IS GOOD)
JZ CTRR1
POP PSW ;ELSE IGNORE FALSE START
JMP CTRR
CTRR1: PUSH H ;SAVE BUFFER POINTER
LXI H,0 ;CLEAR CRC
SHLD CRC
LXI H,FNAME ;READ FILE NAME.TYPE
LXI D,11
CALL CTRS
CALL CTINP ;READ PHYSICAL RECORD NUMBER INTO PRN
STA PRN
CALL CTINP ;READ PHYSICAL RECORD SIZE INTO DE
MOV D,A
CALL CTINP
MOV E,A
CALL CTINP ;READ NEXT BYTE
CPI STX ;JUMP IF NOT STX (ERROR)
JNZ CTRR2
POP H ;RESTORE BUFFER POINTER
PUSH D ;SAVE PHYS REC SIZE
CALL CTRS ;READ DATA BYTES
CALL CTINP ;READ NEXT BYTE
CPI ETX ;JUMP IF NOT ETX (ERROR)
JNZ CTRR2
LHLD CRC ;FETCH NEW CRC INTO HL
CALL CTINP ;READ OLD CRC INTO DE
MOV D,A
CALL CTINP
MOV E,A
MOV A,H ;JUMP IF DE<>HL
CMP D
JNZ CTRR2
MOV A,L
CMP E
JNZ CTRR2
POP D ;RESTORE PHYS REC SIZE
POP PSW ;RESTORE UNIT NO., ETC
CALL CTOFF ;TURN OFF CASSETTE MOTOR
STC ;CLEAR ERROR FLAG AND RETURN
CMC
RET
CTRR2: POP D ;RESTORE BUFFER SIZE
POP PSW ;RESTORE UNIT. NO., ETC
CALL CTOFF ;TURN OFF CASSETTE MOTOR
STC ;SET ERROR FLAG AND RETURN
RET
; CTRS - READ STRING FROM CASSETTE TAPE
;
; ENTRY CONDITIONS
; HL - POINTS TO BUFFER TO READ INTO
; DE - NUMBER OF BYTES TO READ
CTRS: MOV A,D ;RETURN IF COUNT = 0
ORA E
RZ
CALL CTINP ;READ NEXT BYTE
MOV M,A ;STORE IT
INX H
DCX D ;DECREMENT COUNT
JMP CTRS ;AND LOOP
; CTINP - READ BYTE FROM CASSETTE TAPE
;
; ENTRY CONDITIONS
; CRC - RUNNING CRC (INIT BY USER)
;
; EXIT CONDITIONS
; A - 8 BIT BYTE FROM TAPE
CTINP: IN CASC ;AWAIT RDA (INVERTED)
ANI 10H
JNZ CTINP
IN CASD ;READ BYTE
CMA ;DISPLAY ON LIGHTS
OUT 0FFH ;AND FALL THRU TO CTCRC
CMA
; CTCRC - UPDATE CRC
;
; ENTRY CONDITIONS
; A - NEW DATA BYTE
; CRC - 2 BYTE BUFFER CONTAINING CRC
; CRCP - 2 BYTE CRC POLYNOMIAL CONSTANT
CTCRC: PUSH PSW ;SAVE REGS
PUSH B
PUSH D
PUSH H
MOV B,A ;SAVE DATA BYTE
MVI C,8 ;SET LOOP COUNT
CTCR1: ANI 80H ;MASK OFF MSB OF DATA BYTES
LHLD CRC ;FETCH CRC INTO HL
XRA H ;XOR MSB OF DATA INTO CRC
MOV H,A
DAD H ;LEFT SHIFT CRC 1 BIT
JNC CTCR2 ;JUMP IF NO CARRY
MOV A,H ;HL = HL XOR CRCP
XRI CRCP SHR 8
MOV H,A
MOV A,L
XRI CRCP AND 0FFH
MOV L,A
CTCR2: SHLD CRC ;REPLACE CRC
DCR C ;DECREMTN LOOP COUNT
JZ CTCR3 ;EXIT WHEN ENTIRE BYTE PROCESSED
MOV A,B ;SHIFT DATA BYTE LEFT 1 BIT
ADD A
MOV B,A
JMP CTCR1 ;LOOP
CTCR3: POP H ;RESTORE REGS AND RETURN
POP D
POP B
POP PSW
RET
; CTON - TURN ON CASSETTE TAPE MOTOR
;
; ENTRY CONDITIONS
; A - UNIT NO. (SHL 1) AND OPTIONAL HUNT-MODE BIT
CTON: ORI 1 ;TURN ON MOTOR CONTROL BIT
OUT CASC
RET
; CTOFF - IDLE CASSETTE TAPE MOTOR
CTOFF: PUSH PSW ;SAVE A AND FLAGS
XRA A ;CLEAR INTERFACE
OUT CASC
POP PSW
RET
; CTERR - PROCESS TAPE ERROR
;
; ENTRY CONDITIONS
; C-FLAG - SET IF ERROR
CTERR: RNC ;RETURN IF NO ERROR
PUSH H ;ELSE PRINT 'TAPE ERROR'
LXI H,MSG2
CALL WAS
POP H
RET
; DATA AREA
PRN: DS 1 ;PHYSICAL RECORD NUMBER BUFFER
CTR: DS 2 ;SCRATCH COUNTER
CRC: DS 2 ;CRC BUFFER
CRCP: EQU 8005H ;CRC POLYNOMIAL (CRC-16)
TBUF: DS 1024 ;PHYSICAL RECORD BUFFER
MSG0: DB 'SET SENSESWITCHES TO SELECT OPTIONS, THEN TYPE CR',CR,LF
DB ' SW0 - ON TO GET HEX/ASCII DUMP TO CONSOLE',CR,LF
DB ' SW1 - ON TO SAVE FILE ON DISK',CR,LF
DB 0
MSG1: DB 'FILE NAME = ',0
MSG2: DB 'TAPE ERROR',CR,LF,0
MSG3: DB 'PRN = ',0
MSG4: DB ' SIZE = ',0
OLDSP: DS 2 ;STORAGE FOR ENTRY SP
STACK: DS 64 ;LOCAL STACK
END