diff --git a/src/sudoku.s b/src/sudoku.s index 0720c13..ecb843a 100644 --- a/src/sudoku.s +++ b/src/sudoku.s @@ -101,16 +101,27 @@ PUTLN: PUSHJ P,OUTSTR ;Calls the OUTSTR subroutine POPJ P, ;before returning. ;Subroutine that reads the contents of the file into the buffer at FIELD -IMPRTF: .CALL [SETZ ? SIXBIT/OPEN/ +IMPRTF: PUSH P,A ;Save the A register. + PUSH P,X ;Save the index register. + MOVE X,[440400,,FIELD] ;Init a 4-bit byte pointer to FIELD. + .CALL [SETZ ? SIXBIT/OPEN/ ;Open a file descriptor. [.UAI,,CHDSKI] ? [SIXBIT/DSK/] ;Mode, channel and device name 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/ +IMPRD: .IOT CHDSKI,A ;Read an ascii char into A. + JUMPE A,IMPREX ;If there was nothing read, exit. + CAIGE A,060 ;Is A >= '0' then skip, + JUMPA IMPRD ;else read the next char. + CAILE A,071 ;If A <= '9', then skip. + JUMPA IMPRD ;else, read the next char. + SUBI A,060 ;Convert A from the num char into int. + IDPB A,X ;Store the byte and increment. + JUMPA IMPRD ;Jump back to read the next byte. +IMPREX: .CALL [SETZ ? SIXBIT/CLOSE/ ;Close the file, before returning. [,,CHDSKI] ((SETZ))] .LOSE %LSFIL + POP P,X ;Restore the X register. + POP P,A ;Restore the A register. 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.