;-*-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==20 ;Set the size of the stack to 20 words. PDL: BLOCK PDLLEN ;Reserve the stack memory BPTR==440700 ;Define a byte pointer. CHTTYO==1 ;Define a channel for TTY output. 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. START: MOVE P,[-PDLLEN,,PDL-1] ;Initialize the stack. SETZM JCL ;Zero out the JCL MOVE A,[JCL,,JCL+30] BLT A,JCL+30 .OPEN CHTTYO,[.UAO,,'TTY] ;Open an output channel on the TTY. .LOSE %LSFIL ;Gobble up any errors. PUSHJ P,GETJCL ;Read the command line. MOVE A,[BPTR,,HELLO] ;Load A with a byte pointer to HELLO. PUSHJ P,OUTSTR ;Print the out string. MOVE A,[BPTR,,JCL] ;Read the parameter. PUSHJ P,PUTLN ;Print the rest of the line. JRST DONE ;Jump to the end of the program. ;Subroutine to read the JCL from DDT and get the command line parameters. ;Clobbers B, C and D. GETJCL: .BREAK 12,[..RJCL,,JCL] ;Get the JCL MOVE B,[BPTR,,JCL] ;Load the command parameters. MOVE C,[BPTR,,FNAME1] ;Set a pointer to store the first parameter. JCLL1: ILDB D,B ;Load the next character. JUMPE D,FN2 ;Exit the loop, if null. CAIN D,30 ;Jump to next parameter word, if CAIL D,140 ;Check, if the char is > 96. SUBI D,40 ;Make sure that the code is always < 96 SUBI D,40 ;Convert the char to SIXBIT. IDBP D,C ;Deposit the converter value in FNAME1. JRST JCLL1 ;Loop back to read the next character. FN2: MOVE C,[BPTR,,FNAME2] ;Load a pointer to FNAME2 into C. POPJ P, ;Return from routine. ;Subroutine to print a string of text on the output. ; Clobbers A and B. OUTSTR: 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. .IOT CHTTYO,B ;Print a character. JRST OUT ;Jump back to print the next character. OUTEX: 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. DONE: .LOGOUT 2, ;Exit point for the program. HELLO: ASCIZ /HELLO / ;Define example string. END START