Prev: 11B7 Up: Map Next: 1391
12A2: THE 'MAIN EXECUTION' LOOP
Used by the routine at MAIN_ADD.
The main loop controls the 'editing mode', the execution of direct commands and the production of reports.
MAIN_EXEC 12A2 LD (IY+$31),$02 The lower part of the screen is to be two lines in size (see DF-SZ).
12A6 CALL AUTO_LIST Produce an automatic listing.
This entry point is used by the routine at NEW.
MAIN_1 12A9 CALL SET_MIN All the areas from E-LINE onwards are given their minimum configurations.
MAIN_2 12AC LD A,$00 Channel 'K' is opened before calling the EDITOR.
12AE CALL CHAN_OPEN
12B1 CALL EDITOR The EDITOR is called to allow the user to build up a BASIC line.
12B4 CALL LINE_SCAN The current line is scanned for correct syntax.
12B7 BIT 7,(IY+$00) Jump forward if the syntax is correct (ERR-NR is +FF).
12BB JR NZ,MAIN_3
12BD BIT 4,(IY+$30) Jump forward if other than channel 'K' is being used (bit 4 of FLAGS2 is set).
12C1 JR Z,MAIN_4
12C3 LD HL,($5C59) Point to the start of the line with the error (E-LINE).
12C6 CALL REMOVE_FP Remove the floating-point forms from this line.
12C9 LD (IY+$00),$FF Reset ERR-NR and jump back to MAIN_2 leaving the listing unchanged.
12CD JR MAIN_2
The 'edit-line' has passed syntax and the three types of line that are possible have to be distinguished from each other.
MAIN_3 12CF LD HL,($5C59) Point to the start of the line (E-LINE).
12D2 LD ($5C5D),HL Set CH-ADD to the start also.
12D5 CALL E_LINE_NO Fetch any line number into BC.
12D8 LD A,B Is the line number a valid one?
12D9 OR C
12DA JP NZ,MAIN_ADD Jump if it is so, and add the new line to the existing program.
12DD RST $18 Fetch the first character of the line and see if the line is 'carriage return only'.
12DE CP $0D
12E0 JR Z,MAIN_EXEC If it is then jump back.
The 'edit-line' must start with a direct BASIC command so this line becomes the first line to be interpreted.
12E2 BIT 0,(IY+$30) Clear the whole display unless the flag (bit 0 of FLAGS2) says it is unnecessary.
12E6 CALL NZ,CL_ALL
12E9 CALL CLS_LOWER Clear the lower part anyway.
12EC LD A,$19 Set the appropriate value for the scroll counter (SCR-CT) by subtracting the second byte of S-POSN from +19).
12EE SUB (IY+$4F)
12F1 LD ($5C8C),A
12F4 SET 7,(IY+$01) Signal 'line execution' (set bit 7 of FLAGS).
12F8 LD (IY+$00),$FF Ensure ERR-NR is correct.
12FC LD (IY+$0A),$01 Deal with the first statement in the line (set NSPPC to +01).
1300 CALL LINE_RUN Now the line is interpreted. Note: the address MAIN_4 goes on to the machine stack and is addressed by ERR-SP.
After the line has been interpreted and all the actions consequential to it have been completed a return is made to MAIN_4, so that a report can be made.
MAIN_4 1303 HALT The maskable interrupt must be enabled.
1304 RES 5,(IY+$01) Signal 'ready for a new key' (reset bit 5 of FLAGS).
1308 BIT 1,(IY+$30) Empty the printer buffer if it has been used (bit 1 of FLAGS2 set).
130C CALL NZ,COPY_BUFF
130F LD A,($5C3A) Fetch the error number (ERR-NR) and increment it.
1312 INC A
This entry point is used by the routine at REPORT_G.
MAIN_G 1313 PUSH AF Save the new value.
1314 LD HL,$0000 The system variables FLAGX, X-PTR-hi and DEFADD are all set to zero.
1317 LD (IY+$37),H
131A LD (IY+$26),H
131D LD ($5C0B),HL
1320 LD HL,$0001 Ensure that stream +00 points to channel 'K' (see STRMS).
1323 LD ($5C16),HL
1326 CALL SET_MIN Clear all the work areas and the calculator stack.
1329 RES 5,(IY+$37) Signal 'editing mode' (reset bit 5 of FLAGX).
132D CALL CLS_LOWER Clear the lower screen.
1330 SET 5,(IY+$02) Signal 'the lower screen will require clearing' (set bit 5 of TV-FLAG).
1334 POP AF Fetch the report value.
1335 LD B,A Make a copy in B.
1336 CP $0A Jump forward with report numbers '0 to 9'.
1338 JR C,MAIN_5
133A ADD A,$07 Add the ASCII letter offset value.
MAIN_5 133C CALL OUT_CODE Print the report code and follow it with a 'space'.
133F LD A," "
1341 RST $10
1342 LD A,B Fetch the report value (used to identify the required report message).
1343 LD DE,$1391 Print the message.
1346 CALL PO_MSG
1349 XOR A Follow it by a 'comma' and a 'space'.
134A LD DE,$1536
134D CALL PO_MSG
1350 LD BC,($5C45) Now fetch the current line number (PPC) and print it as well.
1354 CALL OUT_NUM_1
1357 LD A,":" Follow it by a ':'.
1359 RST $10
135A LD C,(IY+$0D) Fetch the current statement number (SUBPPC) into the BC register pair and print it.
135D LD B,$00
135F CALL OUT_NUM_1
1362 CALL CLEAR_SP Clear the editing area.
1365 LD A,($5C3A) Fetch the error number (ERR-NR) again.
1368 INC A Increment it as usual.
1369 JR Z,MAIN_9 If the program was completed successfully there cannot be any 'CONTinuing' so jump.
136B CP $09 If the program halted with 'STOP statement' or 'BREAK into program' CONTinuing will be from the next statement; otherwise SUBPPC is unchanged.
136D JR Z,MAIN_6
136F CP $15
1371 JR NZ,MAIN_7
MAIN_6 1373 INC (IY+$0D)
MAIN_7 1376 LD BC,$0003 The system variables OLDPPC and OSPCC have now to be made to hold the CONTinuing line and statement numbers.
1379 LD DE,$5C70
137C LD HL,$5C44 The values used will be those in PPC and SUBPPC unless NSPPC indicates that the 'break' occurred before a 'jump' (i.e. after a GO TO statement etc.).
137F BIT 7,(HL)
1381 JR Z,MAIN_8
1383 ADD HL,BC
MAIN_8 1384 LDDR
MAIN_9 1386 LD (IY+$0A),$FF NSPPC is reset to indicate 'no jump'.
138A RES 3,(IY+$01) 'K mode' is selected (reset bit 3 of FLAGS).
138E JP MAIN_2 And finally the jump back is made but no program listing will appear until requested.
Prev: 11B7 Up: Map Next: 1391