 IDENT SRMD0
* SEARCH DISK IMAGES ON THE SD-CARD.
* THE SD-CARD HAS TO BE LOADED WITH A FILE WITH
* 4 X1215 DISK IMAGES AND THE FILE MUST BE HAVE
* THE SDM FORMAT: HEADER 4*SDI TRAILER.
 AORG /10
**********************
**********************
* LOOK FOR HEADER
* CLEAR BUFFER
 INH
 LDK A1,0
 LDKL A2,/600 BUFFER START
LC STR A1,A2
 ADK A2,2
 RB(4) LC
 LDKL A14,STKA14
 LDKL A15,STKA15
 LDKL A13,0 RESULT (0 => NOT OK)
 ST A1,OFFSET START
 CF A14,SEEK0 => CYL == 0
*
SO LDR A5,A1 OFFSET
 ANK A5,/1F SECTOR IN CYLINDER
 ST A5,SECNBR
 SRL A1,5
 ST A1,CYL SET CYLINDER
 CWK A1,203
 RF(5) *+6
 HLT  CYL TOO BIG; STOP
 RB *-2
 LDR A1,A1
 RF(0) NS WE ARE ON ZERO
 CF A14,SEEK
*
NS CF A14,RSEC READ SECTOR FROM DISK 0 => /600
 LD A1,/600
 CWK A1,/AA00 AA000000
 RF(4) CONT
 LD A1,/602
 RF(4) CONT
 LD A1,/604
 CWK A1,/5038 P8
 RF(4) CONT
 LD A1,/606
 CWK A1,/3030 00
 RF(4) CONT
 LD A1,/608
 CWK A1,/4649 FI
 RF(4) CONT
 LD A1,/60A
 CWK A1,/4C45 LE
 RF(4) CONT
 LD A1,/60C
 CWK A1,/4845 HE
 RF(4) CONT
* HEADER SECTOR FOUND
 CF A14,PROFF PRINT OFFSET
 CF A14,PRSECS PRINT SECTOR HEADER
* SET RESULT: A13 = SECTOR NUMBER HEADER
 LD A13,OFFSET
 HLT
 RB *-2
**********************
**********************
CONT LD A1,OFFSET
 ADK A1,1
 ST A1,OFFSET
 RB SO
**********************
**********************
* LOOK FOR TRAILER
 INH
 LDK A1,0
 LDKL A2,/600 BUFFER START
 LDKL A14,STKA14
 LDKL A15,STKA15
 LDKL A13,/FFFF RESULT (FFFF => NOT OK)
 ST A1,OFFSET
 ST A1,SECNBR
 CF A14,SEEK0 => CYL == 0
 LDR A5,A1
 CF A14,RSEC READ SECTOR FROM DISK 0 => /600
 LD A1,/600
 CWK A1,/AA00 AA000000
 RF(4) CONT1
 LD A1,/602
 RF(4) CONT1
 LD A1,/604
 CWK A1,/5038 P8
 RF(4) CONT1
 LD A1,/606
 CWK A1,/3030 00
 RF(4) CONT1
 LD A1,/608
 CWK A1,/4649 FI
 RF(4) CONT1
 LD A1,/60A
 CWK A1,/4C45 LE
 RF(4) CONT1
 LD A1,/60C
 CWK A1,/5452 TR
 RF(4) CONT1
* TRAILER SECTOR FOUND
 CF A14,PROFF PRINT OFFSET
 CF A14,PRSECS PRINT SECTOR HEADER
 LDKL A13,0
* RESULT: A13 = 0 (OK, TRAILER FOUND)
 HLT
 RB *-2 
**********************
**********************
* THE EXPECTED TRAILER IS NOT THERE
CONT1 HLT  A13=FFFF
 RB *-2
**********************
**********************
* 
* UNIT 0 TO CYLINDER 0
SEEK0 EQU *
 LDK A1,3
 CIO A1,1,/02 SEEK0
 RB(4) *-2
 SST A7,/02
 RB(4) *-2
 CWK A7,/0400 ON CYLINDER ?
 RF(0) *+6
 HLT  SEEK ERROR; STOP
 RB *-2
 LDK A1,0
 ST A1,CYL SET CYLINDER 0
 RTN A14
*
* UNIT 0 TO CYLINDER X (A1=CYL)
SEEK EQU *
 SLL A1,3 SET CYL
 ADK A1,2 ADD SEEK COMMAND
 CIO A1,1,/02 SEEK
 RB(4) *-2
 SST A7,/02
 RB(4) *-2
 CWK A7,/0400 ON CYLINDER ?
 RF(0) *+6
 HLT  SEEK ERROR; STOP
 RB *-2
 RTN A14
*
* ROUTINE TO READ A SECTOR FROM UNIT 0 DRIVE 0
* A5 = SECTOR NUMBER 0..31
RSEC EQU *
 LDKL A1,/80CD WORD TRANSFER,READ,LENGTH
 WER A1,4 WORD 1
 LDKL A1,/600
 WER A1,5 WORD 2 (BUFFER)
 LDR A1,A5 PHYSICAL SECTOR TO READ
 SLL A1,2
 CIO A1,1,/2 START READING
 RB(4) *-2
 SST A7,/02
 RB(4) *-2
 CWK A7,/0000 OK?
 RF(0) *+6
 HLT
 RB *-2
 RER A1,4
 ANKL A1,/0FFF LENGTH 0 ?
 RF(0) *+6
 HLT  CHANNEL ERROR
 RB *-2
 RTN A14
*
* ROUTINE TO PRINT A SECTOR (HEX) SHORT
* 205 WORDS FROM BUFFER AT /600
PRSECS EQU *
 LD A1,/600
 CF A14,HEXOUT WORD 1
 LD A1,/602
 CF A14,HEXOUT WORD 2
 CF A14,NLCR 
* 1 LINE OF 10 WORDS 
 LDK A2,0 WORD COUNTER
 LDKL A10,/604
 LDR A12,A10 SAVE A10
* HEX
L01 LDR* A1,A10
 CF A14,HEXOUT
 ADKL A10,2 NEXT WORD
 ADK A2,1
 CWK A2,10
 RB(4) L01
* TEXT
 LDK A6,/20
 CF A14,ASCOUT
 LDK A2,0
 LDR A10,A12
L02 LCR A6,A10
 ANK A6,/FF
 CWK A6,/20
 RF(2) P01
 CWK A6,/5F
 RF(5) P02
P01 LDK A6,'.'
P02 CF A14,ASCOUT
 ADKL A10,1
 LCR A6,A10
 ANK A6,/FF
 CWK A6,/20
 RF(2) P03
 CWK A6,/5F
 RF(5) P04
P03 LDK A6,'.'
P04 CF A14,ASCOUT
 ADKL A10,1 
 ADK A2,1
 CWK A2,10
 RB(4) L02
 CF A14,NLCR
 RTN A14
*
* ROUTINE TO PRINT A COMPLETE SECTOR (HEX)
* 205 WORDS FROM BUFFER AT /600
PRSECL EQU *
 LD A1,/600
 CF A14,HEXOUT WORD 1
 LD A1,/602
 CF A14,HEXOUT WORD 2
 CF A14,NLCR
* 20 LINES OF 10 WORDS
 LDK A2,0 WORD COUNTER
 LDK A3,0 LINE COUNTER
 LDKL A10,/604
L0 LDR A12,A10 SAVE A10
* HEX
L1 LDR* A1,A10
 CF A14,HEXOUT
 ADKL A10,2 NEXT WORD
 ADK A2,1
 CWK A2,10
 RB(4) L1
* TEXT
 LDK A6,/20
 CF A14,ASCOUT
 LDK A2,0
 LDR A10,A12
L2 LCR A6,A10
 ANK A6,/FF
 CWK A6,/20
 RF(2) P1
 CWK A6,/5F
 RF(5) P2
P1 LDK A6,'.'
P2 CF A14,ASCOUT
 ADKL A10,1
 LCR A6,A10
 ANK A6,/FF
 CWK A6,/20
 RF(2) P3
 CWK A6,/5F
 RF(5) P4
P3 LDK A6,'.'
P4 CF A14,ASCOUT
 ADKL A10,1 
 ADK A2,1
 CWK A2,10
 RB(4) L2
 CF A14,NLCR
* NEXT LINE
 LDK A2,0
 ADK A3,1
 CWK A3,20
 RB(4) L0
* LAST 3 WORDS
 LDR* A1,A10
 CF A14,HEXOUT
 ADKL A10,2
 LDR* A1,A10
 CF A14,HEXOUT
 ADKL A10,2
 LDR* A1,A10
 CF A14,HEXOUT
 CF A14,NLCR
 RTN A14
*
* PRINT OFFSET
PROFF EQU *
 CF A14,NLCR 
 LDKL A6,'OF'
 CF A14,PASC2
 LDKL A6,'FS'
 CF A14,PASC2
 LDKL A6,'ET'
 CF A14,PASC2
 LDKL A6,': '
 CF A14,PASC2
 LD A1,OFFSET
 CF A14,HEXOUT
 LDKL A6,' C'
 CF A14,PASC2 
 LD A1,CYL
 CF A14,HEXOUT
 LDKL A6,' S'
 CF A14,PASC2
 LD A1,SECNBR
 CF A14,HEXOUT  
 CF A14,NLCR
 RTN A14
*
* ASSIGNMENTS
ASR\EQU\/10\DEV ADDR
S\EQU\1\START
H\EQU\0\HALT
*
* HEXOUT--PRINT A1 HEX ON TELETYPE
*         RETURN: A6,A7 UNDEFINED, A1 UNCHANGED
*
HEXOUT\LDKL\A6,/20
\CF\A14,ASCOUT\ /
\STR\A4,A15\SAVE A4
\LDK\A4,4\4 DIGITS
SDIG\LDK\A7,12
\SRC\A1,1\SRC A1,12
\SUK\A7,1
\RB(1)\*-4
\LDK\A6,/F
\ANR\A6,A1\MASK DIGIT
\ADK\A6,/30
\CWK\A6,/3A
\RF(2)\*+4\0-9
\ADK\A6,7\A-F
\CF\A14,ASCOUT\PRINT DIGIT
\SUK\A4,1
\RB(4)\SDIG
\LDR*\A4,A15\RESTORE A4
\RTN\A14
*
* HEXIN--INPUT HEX NUMBER TO A1 FROM TELETYPE KEYBOARD
*        RETURN: A6,A7 UNDEFINED
*
HEXIN\LDK\A6,/2F\PRINT /
\CF\A14,ASCOUT
\LDK\A1,0\NUM = 0
NDIG\CF\A14,ASCIN\READ CHARACTER
\SUK\A6,/30
\RF(2)\NOHEX
\CWK\A6,/A
\RF(2)\HEX\LT A
\SUK\A6,7
\CWK\A6,/A
\RF(2)\NOHEX
\CWK\A6,/F
\RF(1)\NOHEX
HEX\SLL\A1,1
\SLL\A1,1
\SLL\A1,1
\SLL\A1,1
\ORR\A1,A6
\RB\NDIG
NOHEX\RTN\A14
*
* PASC2--PRINT 2 CHARACTERS FROM A6 ON TELETYPE
*        RETURN: A6 NOT CHANGED
*
PASC2\ECR\A6,A6
\CF\A14,ASCOUT
\ECR\A6,A6
\CF\A14,ASCOUT
\RTN\A14
*
* NLCR--PRINT NLCR ON TELETYPR
*
NLCR\LDKL\A6,/0D0A\NLCR
\CF\A14,PASC2
\RTN\A14
*
*
* ASCOUT--OUTPUT ASCII FROM A6 ON TELETYPE
*         STATUS TO A7, A6 NOT CHANGED
*
ASCOUT\LDK\A7,0\OUTPUT MODE
\CIO\A7,S,ASR
\RB(4)\*-2
\OTR\A6,0,ASR\OUTPUT CHAR
\RB(4)\*-2
\CIO\A7,H,ASR\STOP
\SST\A7,ASR
\RB(4)\*-2
\RTN\A14
*
* ASCIN--INPUT ASCII TO A6 FROM TELETYPE
*        STATUS TO A7
*
ASCIN\LDK\A7,1\INPUT MODE
\CIO\A7,S,ASR
\RB(4)\*-2
\INR\A6,0,ASR\INPUT CHAR
\RB(4)\*-2
\ANK\A6,/7F\MASK 7 BITS
\CIO\A7,H,ASR\STOP
\SST\A7,ASR
\RB(4)\*-2
\RTN\A14
*
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
 DATA 0
STKA14 EQU *-2
 DATA 0
 DATA 0
 DATA 0
 DATA 0
STKA15 EQU *-2
OFFSET DATA 0 IMAGE OFFSET
SECNBR DATA 0 SECTOR NUMBER
CYL DATA 0
 END