* TEST UTILITY
*
* COPYRIGHT (C) 1980 BY
* TECHNICAL SYSTEMS CONSULTANTS, INC.
* BOX 2570; W. LAFAYETTE, IN 47906
*
* TESTS SINGLE SECTOR READ AND WRITE ROUTINES.
* PROGRAM PROMPTS USER FOR FUNCTION (F?) TO WHICH THE
* USER CAN RESPOND 'R' (READ) OR 'W' (WRITE). THEN IT
* PROMPTS FOR SINGLE DIGIT DRIVE NUMBER (D?), TWO DIGIT
* HEX TRACK NUMBER (T?) AND TWO DIGIT HEX SECTOR 
* NUMBER (S?). AFTER PERFORMING THE FUNCTION, TEST
* REPEATS THE PROMPTING FOR ANOTHER FUNCTION.
*
* ASSUMES THE CONSOLE I/O PACKAGE DRIVERS ARE RESIDENT.
* BEGIN EXECUTION BY JUMPING TO $0100.
*
*    EQUATES
*
INCH EQU $B3FB
OUTCH EQU $B3F9
TINIT EQU $B3F5
MONITR EQU $B3F3
STACK EQU $A07F
FCB EQU $A840
BUFFER EQU $1000
READ EQU $BE80
WRITE EQU $BE83
DRIVE EQU $BE8C

* TEMPORARY STORAGE

 ORG $0020
COMMND RMB 1
TRACK RMB 1
SECTOR RMB 1
BYTE RMB 1

* START OF PROGRAM

 ORG $0100

TEST LDS #STACK SETUP STACK
 LDX TINIT
 JSR 0,X INITIALIZE TERMINAL
 LDX INCH SETUP INPUT
 STX INPUT+1
 LDX OUTCH SETUP OUTPUT
 STX OUTPUT+1

* GET COMMAND

TEST1 LDS #STACK RESET STACK
 BSR PCRLF
 LDAA #'F PROMPT FOR FUNCTION
 BSR PROMPT
 BSR INPUT GET RESPONSE
 CMPA #'R READ COMMAND?
 BEQ TEST2
 CMPA #'W WRITE COMMAND?
 BEQ TEST2
 LDX MONITR
 JMP 0,X EXIT THE PROGRAM
TEST2 STAA COMMND SAVE COMMAND
 LDAA #'D PROMPT FOR DRIVE
 BSR PROMPT
 JSR INHEX GET RESPONSE
 CMPA #4 ENSURE 0 TO 3
 BHS TEST1
 STAA FCB+3 SAVE IT
 LDAA #'T PROMPT FOR TRACK
 BSR HPRMPT GET HEX PROMPT
 STAA TRACK
 LDAA #'S PROMPT FOR SECTOR
 BSR HPRMPT GET HEX RESPONSE
 STAA SECTOR SAVE IT
 BSR PCRLF DO LINE FEED

* GOT COMMAND, NOW DO IT

 LDAA COMMND GET COMMAND
 CMPA #'W A WRITE COMMAND?
 BNE DOREAD IF NOT, ITS A READ
 BSR SELECT SELECT DRIVE
 LDX #BUFFER POINT TO BUFFER
 LDAA TRACK POINT TO TRACK 
 LDAB SECTOR POINT TO SECTOR
 JSR WRITE WRITE THE DATA
 BNE ERROR
 BSR PCRLF
 LDAA #'O PRINT OK
 BSR OUTPUT
 LDAA #'K 
 BSR OUTPUT
XX BRA TEST1 DO AGAIN

* PROMPT ROUTINES

PROMPT BSR PCRLF DO LINE FEED
 BSR OUTPUT OUTPUT PROMPT LETTER
 BRA QUEST PRINT QUESTION MARK
HPRMPT BSR PROMPT DO PROMPT
 BRA INBYTE GET HEX BYTE

* CARRIAGE RETURN LINE FEED ROUTINE

PCRLF PSHA SAVE A
 LDAA #$0D RETURN
 BSR OUTPUT
 LDAA #$0A LINE FEED
 BSR OUTPUT
 PULA RESTORE A
RET RTS

* I/O ROUTINES

INPUT JMP INPUT (WILL BE OVERLAYED)
QUEST LDAA #'?
OUTPUT JMP OUTPUT (WILL BE OVERLAID)

* DRIVE SELECT ROUTINE

SELECT LDX #FCB
 JSR DRIVE 
 BEQ RET RETURN IF NO ERROR

* DRIVER ERROR

ERROR BSR PCRLF
 LDAA #'E
 BSR OUTPUT
 LDAA #'=
 BSR OUTPUT
 TBA GET ERROR CODE
 BSR OUTHEX
 BRA XX START OVER

* DO SINGLE SECTOR READ

DOREAD BSR SELECT SELECT DRIVE
 LDX #BUFFER POINT TO BUFFER
 LDAA TRACK POINT TO TRACK
 LDAB SECTOR POINT TO SECTOR
 JSR READ READ THE DATA
 BNE ERROR

* DUMP DATA TO CONSOLE

DUMP LDX #BUFFER
 LDAA #16 NO OF LINES
DUMP1 PSHA SAVE NO OF LINES
 BSR PCRLF
 LDAB #16 NO OF BYTES
DUMP2 LDAA 0,X GET A BYTE
 INX
 BSR OUTHEX OUTPUT IT
 DECB DONE WITH LINE?
 BNE DUMP2
 PULA GET NO LINES
 DECA DONE WITH DUMP?
 BNE DUMP1 LOOP IF NOT
 BRA XX GET NEXT COMMAND

* INPUT HEX BYTE ROUTINE

INBYTE BSR INHEX
 ASLA
 ASLA
 ASLA
 ASLA
 STAA BYTE
 BSR INHEX
 ADDA BYTE
RETN RTS
INHEX BSR INPUT
 SUBA #$47
 BPL INERR
 ADDA #6
 BPL INH2
 ADDA #7
 BPL INERR
INH2 ADDA #10
 BPL RETN
INERR BSR QUEST PRINT A QUESTION MARK
 BRA XX GO START OVER

* OUTPUT HEX BYTE (FOLLOWED BY SPACE)

OUTHEX PSHA
 LSRA
 LSRA
 LSRA
 LSRA
 BSR OUTHR
 PULA
 BSR OUTHR
 LDAA #$20
 BRA OUTPUT
OUTHR ANDA #$0F
 ADDA #$90
 DAA
 ADCA #$40
 DAA
 BRA OUTPUT

 END
