118 lines
5.9 KiB
Plaintext
118 lines
5.9 KiB
Plaintext
;-*-MIDAS-*-
|
|
TITLE SUDOKU SOLVER
|
|
|
|
A=1 ;Define ACs as universal registers
|
|
B=2 ;from A to E
|
|
C=3
|
|
D=4
|
|
E=5
|
|
X=10 ;X and Y are used for indexing
|
|
Y=11 ;loops etc.
|
|
P=17 ;Define P as the stack pointer.
|
|
|
|
PDLLEN==30 ;Set the size of the stack to 30 words.
|
|
PDL: BLOCK PDLLEN ;Reserve the stack memory
|
|
BPTR==440700 ;Define a byte pointer.
|
|
|
|
CHTTYO==1 ;Define a channel for TTY output.
|
|
CHDSKI==2 ;Read channel for disk input.
|
|
|
|
JCL: BLOCK 30 ;Reserve space for the command line.
|
|
FNAME1: BLOCK 15 ;The first part of the file name.
|
|
FNAME2: BLOCK 15 ;The second file name.
|
|
FIELD: BLOCK 9 ;Reserve 9 words to store the grid.
|
|
|
|
;Print flags
|
|
;Allows to change the beavihour of the OUTSTR and PUTLN subroutines.
|
|
;The different bits in the word have different meanings.
|
|
;Flags:
|
|
; 001 - SIXBIT: Prints the next character as a SIXBIT char, instead of ASCII, if set.
|
|
PFLAGS: BLOCK 1
|
|
|
|
START: MOVE P,[-PDLLEN,,PDL-1] ;Initialize the stack.
|
|
.OPEN CHTTYO,[.UAO,,'TTY] ;Open an output channel on the TTY.
|
|
.LOSE %LSFIL ;Gobble up any errors.
|
|
MOVEI A,000 ;Initialize the print flag
|
|
MOVEM A,PFLAGS ;to print ASCII
|
|
MOVE A,[BPTR,,WELCOME] ;Print the welcome message
|
|
PUSHJ P,PUTLN
|
|
PUSHJ P,GETJCL ;Read the command line.
|
|
MOVE A,[BPTR,,LOADING] ;Print the loading message
|
|
PUSHJ P,OUTSTR
|
|
MOVEI A,FNAME1 ;Store the first file name in A
|
|
MOVEI B,FNAME2 ;Store the second file name in B
|
|
MOVEI C.FIELD ;Store the address of field in C
|
|
PUSHJ P,IMPRTF ;Load the file
|
|
|
|
JRST DONE ;Jump to the end of the program.
|
|
|
|
;Subroutine to read the JCL from DDT and get the command line parameters.
|
|
GETJCL: PUSH P,A ;Save the register A.
|
|
PUSH P,B ;Save the register B.
|
|
SETZM JCL ;Zero out the JCL
|
|
MOVE A,[JCL,,JCL+30]
|
|
BLT A,JCL+30
|
|
.BREAK 12,[..RJCL,,JCL] ;Request the JCL.
|
|
MOVE A,[BPTR,,JCL] ;Load the command parameters into A.
|
|
MOVE B,[BPTR,,FNAME1] ;Pointer to the first file name.
|
|
PUSHJ P,TOSIXB ;Transfer the first word into FNAME1
|
|
MOVE B,[BPTR,,FNAME2] ;Pointer to the second file name.
|
|
PUSHJ P,TOSIXB ;Transfer the second word into FNAME2
|
|
POP P,B ;Restore the B register.
|
|
POP P,A ;Restore the A register.
|
|
POPJ P, ;Return from routine.
|
|
|
|
;Subroutine to convert an ASCII string into SIXBIT. Takes a byte
|
|
;pointer in A and B, where A is the source and B is the destination.
|
|
TOSIXB: PUSH P,D ;Store the contents of register D.
|
|
TOSLP: ILDB D,A ;Load the next character from A.
|
|
JUMPE D,TOSEN ;Exit the loop, if charachter is null.
|
|
CAIN D,40 ;If the character is a whitespace,
|
|
JUMPA TOSEN ;exit the loop.
|
|
CAIL D,140 ;If the character is > 96,
|
|
SUBI D,40 ;then cut it down, so it's in range.
|
|
SUBI D,40 ;Convert 32..95 to 0..63
|
|
IDPB D,B ;Deposit the character in the destination.
|
|
JRST TOSLP ;Repeat with next character.
|
|
TOSEN: POP P,D ;Restore the D register.
|
|
POPJ P, ;Return from function.
|
|
|
|
;Subroutine to print a string of text on the output.
|
|
;Clobbers A.
|
|
OUTSTR: PUSH P,B ;Save register B.
|
|
PUSH P,D ;Save register D.
|
|
HRLI A,BPTR ;Ensure, A is a byte pointer.
|
|
OUT: ILDB B,A ;Load the next byte from A.
|
|
JUMPE B,OUTEX ;Exit the routine, if all bytes are done.
|
|
MOVE D,PFLAGS ;Load the print flags.
|
|
TRNE D,001 ;Test, if the SIXBIT flag is set.
|
|
ADDI B,40 ;Convert SIXBIT to ASCII.
|
|
.IOT CHTTYO,B ;Print a character.
|
|
JRST OUT ;Jump back to print the next character.
|
|
OUTEX: POP P,D ;Restore D to its original value.
|
|
POP P,B ;Restore B to its original value.
|
|
POPJ P, ;Return from the output routine.
|
|
|
|
;Subroutine to print an entire line of text, including a line break.
|
|
;Clobbers A and B.
|
|
PUTLN: PUSHJ P,OUTSTR ;Calls the OUTSTR subroutine
|
|
.IOT CHTTYO,[^M] ;Print a carriage return
|
|
.IOT CHTTYO,[^J] ;and a new line
|
|
POPJ P, ;before returning.
|
|
|
|
;Subroutine that reads the contents of the file into the buffer at FIELD
|
|
IMPRTF: .CALL [SETZ ? SIXBIT/OPEN/
|
|
[.UAI,,CHDSKI] ? A ? B ((SETZ))]
|
|
.LOSE %LSFIL ;Handle errors after opening the file
|
|
.CALL [SETZ ? SIXBIT/SIOT/
|
|
[,,CHDSKI] ? [BPTR,,C] ? [,,33] ((SETZ))]
|
|
.LOSE %LSFIL
|
|
.CALL [SETZ ? SIXBIT/CLOSE/
|
|
[,,CHDSKI] ((SETZ))]
|
|
.LOSE %LSFIL
|
|
POPJ P ;Return from the input subroutine,
|
|
DONE: .LOGOUT 2, ;Exit point for the program.
|
|
WELCOME:ASCIZ /SUDOKU SOLVER v0.1/ ;Text of the welcome banner.
|
|
LOADING:ASCIZ /LOADING / ;Load message.
|
|
END START
|