| Spectrum ROM | Routines |
| Prev: 04535 | Up: Map |
|
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 | 04770 | LD (IY+49),2 | The lower part of the screen is to be two lines in size. | ||||
| 04774 | CALL AUTO_LIST | Produce an automatic listing. | |||||
|
This entry point is used by the routine at NEW.
|
|||||||
| MAIN_1 | 04777 | CALL SET_MIN | All the areas from E-LINE onwards are given their minimum configurations. | ||||
| MAIN_2 | 04780 | LD A,0 | Channel 'K' is opened before calling the EDITOR. | ||||
| 04782 | CALL CHAN_OPEN | ||||||
| 04785 | CALL EDITOR | The EDITOR is called to allow the user to build up a BASIC line. | |||||
| 04788 | CALL LINE_SCAN | The current line is scanned for correct syntax. | |||||
| 04791 | BIT 7,(IY+0) | Jump forward if the syntax is correct. | |||||
| 04795 | JR NZ,MAIN_3 | ||||||
| 04797 | BIT 4,(IY+48) | Jump forward if other than channel 'K' is being used. | |||||
| 04801 | JR Z,MAIN_4 | ||||||
| 04803 | LD HL,(23641) | Point to the start of the line with the error (E-LINE). | |||||
| 04806 | CALL REMOVE_FP | Remove the floating-point forms from this line. | |||||
| 04809 | LD (IY+0),255 | Reset ERR-NR and jump back to MAIN_2 leaving the listing unchanged. | |||||
| 04813 | 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 | 04815 | LD HL,(23641) | Point to the start of the line (E-LINE). | ||||
| 04818 | LD (23645),HL | Set CH-ADD to the start also. | |||||
| 04821 | CALL E_LINE_NO | Fetch any line number into BC. | |||||
| 04824 | LD A,B | Is the line number a valid one? | |||||
| 04825 | OR C | ||||||
| 04826 | JP NZ,MAIN_ADD | Jump if it is so, and add the new line to the existing program. | |||||
| 04829 | RST 24 | Fetch the first character of the line and see if the line is 'carriage return only'. | |||||
| 04830 | CP 13 | ||||||
| 04832 | 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.
|
|||||||
| 04834 | BIT 0,(IY+48) | Clear the whole display unless the flag says it is unnecessary. | |||||
| 04838 | CALL NZ,CL_ALL | ||||||
| 04841 | CALL CLS_LOWER | Clear the lower part anyway. | |||||
| 04844 | LD A,25 | Set the appropriate value for the scroll counter (SCR-CT). | |||||
| 04846 | SUB (IY+79) | ||||||
| 04849 | LD (23692),A | ||||||
| 04852 | SET 7,(IY+1) | Signal 'line execution'. | |||||
| 04856 | LD (IY+0),255 | Ensure ERR-NR is correct. | |||||
| 04860 | LD (IY+10),1 | Deal with the first statement in the line. | |||||
| 04864 | 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 | 04867 | HALT | The maskable interrupt must be enabled. | ||||
| 04868 | RES 5,(IY+1) | Signal 'ready for a new key'. | |||||
| 04872 | BIT 1,(IY+48) | Empty the printer buffer if it has been used. | |||||
| 04876 | CALL NZ,COPY_BUFF | ||||||
| 04879 | LD A,(23610) | Fetch the error number and increment it. | |||||
| 04882 | INC A | ||||||
|
This entry point is used by the routine at REPORT_G.
|
|||||||
| MAIN_G | 04883 | PUSH AF | Save the new value. | ||||
| 04884 | LD HL,0 | The system variables FLAGX, X-PTR-hi and DEFADD are all set to zero. | |||||
| 04887 | LD (IY+55),H | ||||||
| 04890 | LD (IY+38),H | ||||||
| 04893 | LD (23563),HL | ||||||
| 04896 | LD HL,1 | Ensure that stream +00 points to channel 'K'. | |||||
| 04899 | LD (23574),HL | ||||||
| 04902 | CALL SET_MIN | Clear all the work areas and the calculator stack. | |||||
| 04905 | RES 5,(IY+55) | Signal 'editing mode'. | |||||
| 04909 | CALL CLS_LOWER | Clear the lower screen. | |||||
| 04912 | SET 5,(IY+2) | Signal 'the lower screen will require clearing'. | |||||
| 04916 | POP AF | Fetch the report value. | |||||
| 04917 | LD B,A | Make a copy in B. | |||||
| 04918 | CP 10 | Jump forward with report numbers '0 to 9'. | |||||
| 04920 | JR C,MAIN_5 | ||||||
| 04922 | ADD A,7 | Add the ASCII letter offset value. | |||||
| MAIN_5 | 04924 | CALL OUT_CODE | Print the report code and follow it with a 'space'. | ||||
| 04927 | LD A," " | ||||||
| 04929 | RST 16 | ||||||
| 04930 | LD A,B | Fetch the report value (used to identify the required report message). | |||||
| 04931 | LD DE,5009 | Print the message. | |||||
| 04934 | CALL PO_MSG | ||||||
| 04937 | XOR A | Follow it by a 'comma' and a 'space'. | |||||
| 04938 | LD DE,5430 | ||||||
| 04941 | CALL PO_MSG | ||||||
| 04944 | LD BC,(23621) | Now fetch the current line number (PPC) and print it as well. | |||||
| 04948 | CALL OUT_NUM_1 | ||||||
| 04951 | LD A,":" | Follow it by a ':'. | |||||
| 04953 | RST 16 | ||||||
| 04954 | LD C,(IY+13) | Fetch the current statement number into the BC register pair and print it. | |||||
| 04957 | LD B,0 | ||||||
| 04959 | CALL OUT_NUM_1 | ||||||
| 04962 | CALL CLEAR_SP | Clear the editing area. | |||||
| 04965 | LD A,(23610) | Fetch the error number again. | |||||
| 04968 | INC A | Increment it as usual. | |||||
| 04969 | JR Z,MAIN_9 | If the program was completed successfully there cannot be any 'CONTinuing' so jump. | |||||
| 04971 | CP 9 | If the program halted with 'STOP statement' or 'BREAK into program' CONTinuing will be from the next statement; otherwise SUBPPC is unchanged. | |||||
| 04973 | JR Z,MAIN_6 | ||||||
| 04975 | CP 21 | ||||||
| 04977 | JR NZ,MAIN_7 | ||||||
| MAIN_6 | 04979 | INC (IY+13) | |||||
| MAIN_7 | 04982 | LD BC,3 | The system variables OLDPPC and OSPCC have now to be made to hold the CONTinuing line and statement numbers. | ||||
| 04985 | LD DE,23664 | ||||||
| 04988 | LD HL,23620 | 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.). | |||||
| 04991 | BIT 7,(HL) | ||||||
| 04993 | JR Z,MAIN_8 | ||||||
| 04995 | ADD HL,BC | ||||||
| MAIN_8 | 04996 | LDDR | |||||
| MAIN_9 | 04998 | LD (IY+10),255 | NSPPC is reset to indicate 'no jump'. | ||||
| 05002 | RES 3,(IY+1) | 'K mode' is selected. | |||||
| 05006 | JP MAIN_2 | And finally the jump back is made but no program listing will appear until requested. | |||||
| Prev: 04535 | Up: Map |