--- /dev/null
+* BINARY PUNCH AND LOAD PROGRAM
+*
+*
+* LOAD
+* FIRST LOC TO A, LAST LOC TO B
+* RUN IT.
+*
+* TAPE FORMAT:
+* THE TAPE CONTAINS DATA BLOCKS.
+* EVERY BLOCK IS PREPENDED WITH THE BLOCK START CHARACTER
+* AND THE BLOCK TYPE BYTE.
+* THEN FOLLOWS THE BLOCK DATA IN 16BIT BIG ENDIAN FORMAT.
+*
+* BLOCK TYPES
+*
+* DATA BLOCK
+* THE DATA BLOCK CONTAINS USER DATA AND A CHECKSUM.
+* LAYOUT:
+* | START ADDRESS |
+* | DATA LENGTH |
+* | DATA |
+* | BLOCK CHECKSUM |
+*
+* ZERO BLOCK
+* ZERO BLOCK IS USED TO REPRESENT ZERO CORE LOCATIONS
+* LAYOUT:
+* | START ADDRESS |
+* | ZERO LENGTH |
+* | BLOCK CHECKSUM |
+*
+* START LOC BLOCK
+* A BLOCK TO SET THE START LOCATION AFTER LOAD
+* LAYOUT;
+* | START ADDRESS |
+* | CHECKSUM (HAHA)|
+*
+* GO BLOCK
+* THIS BLOCK STOPS LOADING AND JUMPS TO THE START LOCATION.
+* IF NO START LOCATION HAS BEEN CODED THE LOADER WILL
+* CONTIUNE!
+*
+* TAPE END MARK:
+* THIS BLOCK TELLS THE LOADER THAT IT SHALL STOP NOW.
+* LAYOUT:
+* NO BODY AT ALL, ONLY BLOCK START AND BLOCK TYPE :-)
+*
+************************************************************************
+*
+ SUBR LSTART,BO3S LOADER START IS GOOD TO KNOW
+*
+ REL RELOCATABLE MODE
+ ORG 0
+*
+ STA STRT
+ HLT
+ STA ALOC FIRST LOCATION TO PUNCH
+ HLT
+ STA ELOC LAST LOCATION TO PUNCH
+*
+ OCP '0002 START PUNCH (NOT NECESSARY ON MY H316)
+ JST PLDR PUNCH OUT LEADER
+ JST PS2 PUNCH SECOND STAGE LOADER
+ JST PLDR PUNCH OUT LEADER
+ JST PS3 PUNCH THIRD STAGE LOADER
+ JST PLDR PUNCH OUT LEADER
+*
+*
+LOOP CRA MAIN LOOP
+ LDA ELOC
+ SUB ALOC
+ AOA
+ STA AVAL DETERMINED AVAILABLE DATA
+ SNZ
+ JMP EDAT END OF DATA, WE ARE HAPPY
+*
+* FIRST TRY TO ESABLISH A ZERO BLOCK
+ LDA ALOC
+ JST CZER COUNT ZERO LOCATIONS - IF ANY
+ CAS ZMIN COMPARE WITH MINIMUM FOR ZERO BLOCK
+ JMP MKZE GO TO MAKE A ZERO BLOCK
+ JMP MKZE GO FOR THE ZERO BLOCK AS WELL
+ JMP FILL PREPARE CONVETIONAL BLOCK
+MKZE CAS AVAL BLOCK TOO BIG??
+ LDA AVAL YES, LIMIT BLOCK SIZE
+ NOP TIGHT FIT
+ JST ZBLK PRODUCE THE THE BLOCK
+ JMP LOOP CONTINUE IN THE MAIN LOOP
+FILL CRA STUFF A PACKET
+ STA BCNT CLEAR BLOCK SIZE
+*
+STUF LDA ALOC
+ ADD BCNT CALCULATE NEW POSITION TO LOOK AT
+ JST CFIL DETERMINE AMOUNT OF CONTIGUOUS DATA
+ ADD BCNT ADD ACTUAL BLOCK SIZE
+ CAS AVAL COMPARE THAT WITH AVAILABLE DATA
+ LDA AVAL TOO MUCH, LIMIT AND GO
+ SKP A TIGHT FIT
+ JMP FIL2 FILL MORE!
+ JST DBLK PRODUCE BLOCK
+ JMP LOOP RETURN TO MAIN LOOP
+*
+FIL2 STA BCNT UPDATE BLOCK SIZE
+ ADD ALOC MAKE NEW STARTING LOCATION
+ JST CZER COUNT FOLLOWING ZEROS
+ CAS ZMIN COMPARE WITH MINIMUM FOR A ZERO BLOCK
+ JMP BEND OK, THERE ARE ENOUGH ZEROS. BLOCK SHALL BE GOOD.
+ JMP BEND
+* NO, WE CONTINUE LOOKING
+ ADD BCNT ADD CURRENT BLOCK SIZE
+ STA BCNT AND UPDATE IT
+ JMP STUF STUFF MORE
+*
+BEND LDA BCNT
+ JST DBLK PUNCH THE BLOCK
+ JMP LOOP BACK TO MAIN LOOP
+*
+*
+* END OF DATA
+EDAT LDA STRT
+ SZE
+ JMP AUTO
+ JST SBLK MAKE STOP BLOCK
+ JMP EOT
+AUTO JST ABLK MAKE ADRESS-BLOCK
+ JST GBLK MAKE GO-BLOCK
+EOT JST PLDR END OF JOB HAS COME.
+ HLT
+ JMP *-1 NO ESCAPE
+*
+*
+AVAL DEC 0 AVAILABLE DATA SIZE
+IPTR DEC 0 IMAGINARY POINTER
+BCNT DEC 0 PACKET SIZE COUNTER
+ZMIN DEC 8 MIN AMOUNT OF ZEROS FOR A BLOCK BREAK
+STRT DEC 0 ADDRESS FOR AUTO-START
+*
+*
+*******************
+* MAKE A STOP BLOCK
+SBLK DAC **
+ LDA BSTA START CHARACTER
+ ICA
+ ADD TSTP BLOCK TYPE
+ JST SWRD PUNCH THAT
+ JMP* SBLK
+*
+*
+*******************
+* MAKE A GO BLOCK
+GBLK DAC **
+ LDA BSTA START CHARACTER
+ ICA
+ ADD TGO BLOCK TYPE
+ JST SWRD PUNCH THAT
+ JMP* GBLK
+*
+*
+******************
+* MAKE A START ADDRESS BLOCK
+ABLK DAC **
+ STA CNT SAVE THE ADDRESS
+ LDA BSTA START CHARACTER
+ ICA
+ ADD TSAD BLOCK TYPE
+ JST SWRD PUNCH THAT
+ LDA CNT
+ JST SWRD
+ JST SWRD
+ JMP* ABLK
+*
+*
+*******************
+* MAKE ZERO BLOCK
+ZBLK DAC ** PRODUCE A ZERO BLOCK
+ STA CNT STORE SIZE OF BLOCK
+ LDA BSTA START CHARACTER
+ ICA
+ ADD TZER BLOCK TYPE
+ JST SWRD PUNCH THAT
+ LDA ALOC LOAD START ADDRESS
+ JST SWRD PUNCH START ADDRESS
+ STA CSUM INIT CHECKSUM
+ LDA CNT LOAD SIZE
+ JST SWRD PUNCH SIZE
+ ADD CSUM ADD CHECKSUM
+ JST SWRD PUNCH OUT CHECKSUM
+ LDA ALOC RELOAD POINTER
+ ADD CNT CALCULATE NEW POINTER
+ STA ALOC UPDATE ALOC
+ JMP* ZBLK END
+*
+*
+********************
+* MAKE DATA BLOCK
+DBLK DAC **
+ STA CNT SAVE SIZE
+*
+ LDA BSTA START CHARACTER
+ ICA
+ ADD TDAT DATA BLOCK TYPE
+ JST SWRD PUNCH
+*
+ LDA ALOC START ADDRESS
+ JST SWRD PUNCH IT
+ STA CSUM INIT CHECKSUM
+*
+ LDA CNT PACKET SIZE
+ JST SWRD PUNCH IT
+ ADD CSUM
+ STA CSUM UPDATE CHECKSUM
+*
+ LDA CNT
+ TCA
+ STA CNT NOW WE USE IT AS NEG COUNTER
+*
+DDLP LDA* ALOC LOAD DATA
+ JST SWRD PUNCH DATA
+ ADD CSUM
+ STA CSUM UPDATE CHECKSUM
+ IRS ALOC
+ IRS CNT
+ JMP DDLP LOOP IT
+ JST SWRD PUNCH CHECKSUM
+ JMP* DBLK BLOCK DONE
+*
+*
+*
+********************
+* COUNT FILLED LOCATIONS
+CFIL DAC **
+ STA PTR STORE ADDRESS TO POINTER
+ LDA SNZ LOAD DISCRIMINATOR OPERATION
+ STA DISC STORE INTO COUNT ROUTINE
+ JST COUN GO AND COUNT IT
+ JMP* CFIL
+*
+********************
+* COUNT ZERO LOCATIONS
+CZER DAC **
+ STA PTR STORE ADDRESS TO POINTER
+ LDA SZE
+ STA DISC
+ JST COUN
+ JMP* CZER
+*
+COUN DAC ** COUNT FILLED OR EMPTY LOCATIONS
+ CRA
+ STA CNT INITIALIZE COUNTER
+CLOP LDA* PTR
+DISC SZE WILL BE DYNAMICALLY OVERWRITTEN
+ JMP ZFIN NOW OTHER KIND OF DATA
+ IRS CNT NOTE DOWN THE FIND
+ IRS PTR POINT TO NEXT LOCATION TO BE TESTED
+ SKP
+ JMP ZFIN ADDRESS OVERFLOW MUST STOP COUNTING
+ JMP CLOP COUNT ON
+ZFIN LDA CNT
+ JMP* COUN
+*
+*
+***********************
+*
+PS2 DAC ** PUNCH OUT SECOND STAGE LOADER
+ LDA B2AD LOAD START ADDRESS OF SECOND STAGE LOADER
+ JST P23 CALL PUNCH23 ROUTINE
+ JMP* PS2
+*
+PS3 DAC ** PUNCH OUT SECOND STAGE LOADER
+ LDA S3SC LOAD START CHARACTER
+ OTA 2 PUNCH START CHARACTER
+ JMP *-1
+ LDA B3AD LOAD START ADDRESS OF SECOND STAGE LOADER
+ JST P23 CALL PUNCH23 ROUTINE
+ JMP* PS3
+*
+P23 DAC ** PUNCH OUT A LOADER
+ STA PTR SAVE POINTER
+L23 LDA* PTR
+ SNZ
+ JMP* P23 RETURN
+ JST SWRD PUNCH OUT CURRENT WORD
+ IRS PTR INCREMENT POINTER
+ JMP L23 LOOP AGAIN
+*
+*
+**********************
+* PUNCH SOME LEADER
+PLDR DAC ** PUNCH LEADER
+ LDA LDRL LOAD LEADER LENGTH
+ TCA COMPLEMENT IT
+ STA CNT STORE TO LEADER COUNTER
+ CRA LEADER IS ZERO
+LLP OTA 2
+ JMP *-1
+ IRS CNT
+ JMP LLP
+ JMP* PLDR
+*
+*
+*********************
+* PUNCH ONE WORD OF DATA
+SWRD DAC **
+ ICA
+ OTA 2
+ JMP *-1
+ ICA
+ OTA 2
+ JMP *-1 WAIT
+ JMP* SWRD
+*
+*
+B2AD DAC BO2S START ADDRESS OF SECOND STAGE LOADER
+B3AD DAC BO3S START ADDRESS OF THIRD STAGE LOADER
+*
+LDRL DEC 100 LEADER LENGTH
+ALOC *** ** NEXT WORD TO BE PUNCHED OUT
+ELOC *** ** LAST WORD TO BE PUNCHED OUT
+SZE SZE INSTRUCTION FOR FILL IN
+SNZ SNZ INSTRUCTION FOR FILL IN
+*
+*
+************************************************************************
+* THIS IST THE SECOND STAGE LOADER
+*
+ ORG '317 ONLY FOR DEVELOPMENT!
+BO2S OCT '20 START ADDRESS
+ JMP '10 JUMP BACK INTO KEY-IN LOADER
+*
+*S21 OCP '001 THIS IS THE JUMP-IN LOCATION, WILL GO TO '21
+*
+ INA '1001
+ JMP '17-BO2S+*-1
+ SUB '17-BO2S+S3SC STAGE 3 START CHARACTER
+ SZE
+ JMP '17-BO2S+*-4 EAT UP ALL JUNK
+*
+ INA '1001 READ WITH CLEAR
+ JMP '17-BO2S+*-1
+* JMP '17-BO2S+* DEBUG STOP
+ ICA
+ INA '001 READ WITHOUT CLEAR
+ JMP '17-BO2S+*-1
+* JMP '17-BO2S+* DEBUG STOP
+*
+*
+*
+ STA '17-BO2S+CNT STORE START ADDRESS
+* LDA '57 LOOK FOR DEPOSITED OTHER BOOT ADDRESS
+* SZE OK, IF WE FIND SOMETHING THERE...
+* STA '17-BO2S+CNT OVERWRITE DEFAULT VALUE
+ IRS '17-BO2S+CNT CORRECT STOLEN WORD
+ LDA '17-BO2S+CNT
+* JMP '776
+*
+ LDA '17-BO2S+CNT WHERE TO LOAD NOW?
+ STA '17-BO2S+PTR INIT POINTER
+*
+LOP INA '1001 READ IN CHARACTER
+ JMP '17-BO2S+*-1
+ ICA
+ INA '001 READ OTHER CHARACTER
+ JMP '17-BO2S+*-1
+ SNZ
+ JMP* '17-BO2S+CNT JUMP INTO THIRD STAGE LOADER
+* JMP '665
+ STA* '17-BO2S+PTR STORE DATA
+ IRS '17-BO2S+PTR MOVE ON
+ JMP '17-BO2S+LOP FETCH MORE DATA
+*
+S3SC OCT '301 START CHARACTER TO RECOGNIZE STAGE3
+PTR DAC ** GENERAL PURPOSE MEMORY POINTER
+CNT DAC ** WHERE TO LOAD? CAN BE CHANGED.
+BO2E OCT 10600 ZERO-TERMINATOR
+*
+*
+************************************************************************
+* HERE COMES THE THIRD STAGE LOADER
+*
+ ORG '600
+BO3S DAC * THAT IS FOR THE SECOND STAGE LOADER
+ OCP 1 READER ON (UNNECESSARY?)
+SLOP INA '1001 CRA AND READ
+ JMP *-1
+ SUB BSTA BLOCK START?
+ SZE
+ JMP SLOP BACK TO SEARCH LOOP
+ INA '1001 READ BLOCK TYPE
+ JMP *-1
+ STA BTYP STORE BLOCK TYPE FOR LATER USE
+ CAS TSAD START ADDRESS BLOCK?
+ JMP *+2
+ JMP RSAD READ START ADDRESS BLOCK
+ NOP
+ CAS TGO GO BLOCK?
+ JMP *+2
+ JMP RGO PROCESS GO BLOCK
+ NOP
+ CAS TDAT DATA BLOCK?
+ JMP *+2
+ JMP RBLK READ DATA BLOCK
+ NOP
+ CAS TZER ZERO BLOCK?
+ JMP *+2
+ JMP RBLK READ ZERO BLOCK
+ NOP
+ CAS TSTP STOP BLOCK?
+ JMP *+2
+ JMP RSTP PROCESS STOP BLOCK
+ NOP
+ LDA '125252 ERROR BLOCK TYPE
+ CRA
+ STA *+1
+ OCT 66 THE HALT TRICK
+ JMP SLOP SEARCH FOR NEW BLOCK
+*
+********************
+* START ADDRESS BLOCK
+RSAD JST LWRD
+ STA RESA
+ JST LWRD
+ SUB RESA
+ SZE
+ JMP CERR CHECKSUM ERROR!
+ JMP SLOP LOOK FOR NEW BLOCK!
+*
+*
+RGO JMP* RESA
+*
+*********************
+* READ DATA OR ZERO BLOCK
+RBLK JST LWRD
+ STA PTR START ADDRESS
+ STA CSUM
+ JST LWRD
+ TCA TWO'S COMPLEMENT
+ STA LEN GO COUNTER
+ TCA TWO'S COMPLEMENT BACK
+ ADD CSUM
+ STA CSUM
+RLP LDA BTYPE
+ CAS TDAT DATA BLOCK?
+ JMP RZER NO
+ JMP RDAT YES
+ JMP RZER NO, CLEAR A
+RDAT JST LWRD
+ STA* PTR
+ ADD CSUM ADD TO CHECKSUM
+ STA CSUM
+EL IRS PTR POINT TO NEXT LOCATION
+ SKP
+ JMP BO3S OVERFLOW!
+ IRS LEN INCREMENT NEG COUNTER
+ JMP RLP READ ON
+*
+ JST LWRD NOW READ IN THE CHECKSUM
+ SUB CSUM
+ SNZ
+ JMP SLOP
+CERR CRA CHECKSUM ERROR HALT
+ STA *+1
+ OCT 66
+ JMP SLOP TRY A NEW BLOCK
+*
+RZER CRA
+ STA* PTR STORE ZERO
+ JMP EL USE END OF LOOP ABOVE
+*******
+* STOP BLOCK
+RSTP CRA
+ STA *+1
+ OCT 66 A TRICK - HERE WILL BE THE HLT INSTRUCTION
+ JMP* RESA JUMP TO RESTART LOCATION
+*
+***** VARIABLES
+CSUM OCT 66 CHECKSUM
+LEN OCT 66 LENGTH TO GO
+RESA DAC SLOP RESTART ADDRESS
+BTYP OCT 66 BLOCK TYPE
+*
+BSTA DEC 129 BLOCK START CHARACTER
+*
+* BLOCK TYPES:
+TSAD OCT '33
+TGO OCT '44
+TZER OCT '55
+TSTP OCT '66
+TDAT OCT '11
+*
+*
+LWRD OCT 66
+ INA '1001 CLEAR A AND INPUT
+ JMP *-1
+ ICA
+ INA '1 INPUT
+ JMP *-1 WAIT
+ JMP* LWRD
+*
+ FIN WRITE OUT LITERALS - IF ANY
+BO3E DEC 0 ZERO TERMINATOR
+*
+************************************************************
+ END