[Index] [Previous] [Next]

1.15 INPUT & READ Handlers

Input

Let user input a number at a '?' prompt.

05E4 E5 Input PUSH H
Error out if in direct mode (ie not in a program). To do this we get the current line number + 1. If it's zero, then we're in direct mode.
05E5 2A6101 LHLD CURRENT_LINE
05E8 1E16 MVI E,16
05EA 23 INX H
05EB 7D MOV A,L
05EC B4 ORA H
05ED CAD501 JZ Error
Get the input from the user and jump to Read+5.
05F0 CDC202 CALL InputLineWith'?'
05F3 C3FB05 JMP 05FB

 

Read

05F6 E5 Read PUSH H
05F7 2A6D01 LHLD DATA_PROG_PTR
05FA F6AF ORI AF
05FB AF  XRA A
05FC 325C01 STA INPUT_OR_READ
Preserve data prog ptr on stack and restore prog ptr to HL. This should point to the name of the variable to read data into. Note we also LXI over the syntax check for a comma that's done on subsequent reads.
05FF E3 XTHL
0600 01.... LXI B,....
0601 CF ReadNext RST SyntaxCheck
0602 2C ','
Get variable value address in DE.
0603 CD1B07 CALL GetVar
Preserve prog ptr and get data prog ptr into HL.
0606 E3 XTHL
Preserve variable value address on stack.
0607 D5 PUSH D
Get byte of data part of program. If this is a comma seperator then we've found our data item and can jump ahead to GotDataItem
0608 7E MOV A,M
0609 FE2C CPI ','
060B CA2006 JZ GotDataItem
If the next byte of data is not a null byte terminating the line then syntax error out.
060E B7 ORA A
060F C2D001 JNZ SyntaxError
If we're READ'ing data then jump ahead to find the next DATA statement.
0612 3A5C01 LDA INPUT_OR_READ
0615 B7 ORA A
0616 23 INX H
0617 C23606 JNZ NextDataLine+1
We've been called by the INPUT handler, and we have more inputs to take - the interpreter allows 'INPUT A,B,C' -type statement. So here we get the next input, only Bill has made a mistake here - he prints an unnecessary '?' , so the user gets two question marks for all inputs after the first one.
061A 3E3F MVI A,'?'
061C DF RST OutChar
061D CDC202 CALL InputLineWith'?'
Restore variable address, advance the data ptr so it points to the start of the next data item, and assign the data item to the variable.
0620 D1 GotDataItem POP D
0621 23 INX H
0622 CD0705 CALL AssignVar
Get prog ptr off stack, and push data prog ptr, decrement prog ptr because AssignVar automatically advanced it, which we don't want.
0625 E3 XTHL
0626 2B DCX H
Get next char of READ statement and jump back to ReadNext if the end of the line has not been reached.
0627 D7 RST NextChar
0628 C20106 JNZ ReadNext
End of READ statement reached.
062B D1 POP D
062C 3A5C01 LDA INPUT_OR_READ
062F B7 ORA A
0630 C8 RZ
0631 EB XCHG
0632 C26E04 JNZ 046E
Loop to find the next DATA line. Here we get the data prog ptr off the stack, and PushNextWord so the address of the next line is on the stack.
0635 E1 NextDataLine POP H
0636 F7 RST PushNextWord
PushNextWord has pushed the address of the next line on the stack, but it has also left this address in BC. Here we test to see if this address is null (ie the null line at the end of the program has been reached) and if so then 'Out of Data' (OD) error.
0637 79 MOV A,C
0638 B0 ORA B
0639 1E06 MVI E,06
063B CAD501 JZ Error
Get the first character of the line. If it's not the DATA keyword ID then loop back to try the next line.
063E 23 INX H
063F D7 RST NextChar
0640 FE83 CPI KWID_DATA  
0642 C23506 JNZ NextDataLine
Found a DATA line. We remove the prog ptr to the beginning of the line from the stack (we don't need it - we have the ptr in HL) and jump up to GotDataItem.
0645 C1 POP B
0646 C32006 JMP GotDataItem

 


[Index] [Previous] [Next]