[Index] [Previous] [Next]

1.9 Execution

ExecNext

Having exec'd one statement, this block moves on to the next statement in the line or the next line if there are no more statements on the current line.

Give user a chance to break the execution.
0421 CD7304 ExecNext CALL TestBreakKey
If we have a ':' then that's a statement seperator (which allows multiple statements on the same line) so we jump to Exec to run it.
0424 7E MOV A,M
0425 FE3A CPI ':'
0427 CA3E04 JZ Exec
Well it wasn't a statement seperator, therefore it must be the null byte terminating the line otherwise it's a syntax error.
042A B7 ORA A
042B C2D001 JNZ SyntaxError
The next two bytes should be the address of the next line. We can ignore this, since lines are stored consecutively, but must jump back to Main if we've reached the end of the program
042E 23 INX H
042F 7E MOV A,M
0430 23 INX H
0431 B6 ORA M
0432 23 INX H
0433 CAF901 JZ Main
Get the number of the following program line, store it in CURRENT_LINE and fall into Exec to run it.
0436 5E MOV E,M
0437 23 INX H
0438 56 MOV D,M
0439 EB XCHG
043A 226101 SHLD CURRENT_LINE
043D EB XCHG

 

Exec

Executes a statement of BASIC code pointed to by HL.

Get first character of statement.
043E D7 Exec RST NextChar
Stick address of ExecNext onto stack so we can return to it.
043F 112104 LXI D,ExecNext
0442 D5 PUSH D
Return immediately if this is an empty statement.
0443 C8 RZ
See if we lead with a keyword, ie first byte is >=0x80. If it isn't then it might be an implicit LET statement (ie where the LET has not been typed) and so we defer to the LET handler to deal with it.
0444 D680 SUI 80
0446 DA0205 JC Let
If it's not a general keyword then that's a syntax error.
0449 FE14 CPI 14
044B D2D001 JNC SyntaxError
Ok so we have a general keyword, so here we get the address of the handling function into HL, preserving the program ptr in DE.
044E 07 RLC BC = A*2
044F 4F MOV C,A
0450 0600 MVI B,00
0452 EB XCHG
0453 21D200 LXI H,KW_GENERAL_FNS
0456 09 DAD B
Read the keyword handler function address into BC.
0457 4E MOV C,M
0458 23 INX H
0459 46 MOV B,M
Stick keyword handler function address on stack, restore program ptr to HL, get the next character of the statement, and return to the keyword handler function.
045A C5 PUSH B
045B EB XCHG
045C D7 RST NextChar
045D C9 RET

 


[Index] [Previous] [Next]