| Routines

03884: THE 'EDITOR' ROUTINES

Used by the routines at MAIN_EXEC and INPUT. The editor is called on two occasions: From the main execution routine so that the user can enter a BASIC line into the system. From the INPUT command routine. First the 'error stack pointer' is saved and an alternative address provided.
EDITOR | 03884 | LD HL,(23613) | The current value of ERR-SP is saved on the machine stack.
| 03887 | PUSH HL
This entry point is used by the routine at ED_ERROR.
ED_AGAIN | 03888 | LD HL,4223 | This is ED_ERROR.
| 03891 | PUSH HL | Any event that leads to the error handling routine (see ERR-SP) being used will come back to ED_ERROR.
| 03892 | LD (23613),SP
A loop is now entered to handle each keystroke.
ED_LOOP | 03896 | CALL WAIT_KEY | Return once a key has been pressed.
| 03899 | PUSH AF | Save the code temporarily.
| 03900 | LD D,0 | Fetch the duration of the keyboard click (PIP).
| 03902 | LD E,(IY-1)
| 03905 | LD HL,200 | And the pitch.
| 03908 | CALL BEEPER | Now make the 'pip'.
| 03911 | POP AF | Restore the code.
| 03912 | LD HL,3896 | Pre-load the machine stack with the address of ED_LOOP.
| 03915 | PUSH HL
Now analyse the code obtained.
| 03916 | CP 24 | Accept all character codes, graphic codes and tokens.
| 03918 | JR NC,ADD_CHAR
| 03920 | CP 7 | Also accept ','.
| 03922 | JR C,ADD_CHAR
| 03924 | CP 16 | Jump forward if the code represents an editing key.
| 03926 | JR C,ED_KEYS
The control keys - INK to TAB - are now considered.
| 03928 | LD BC,2 | INK and PAPER will require two locations.
| 03931 | LD D,A | Copy the code to D.
| 03932 | CP 22 | Jump forward with INK and PAPER.
| 03934 | JR C,ED_CONTR
AT and TAB would be handled as follows:
| 03936 | INC BC | Three locations required.
| 03937 | BIT 7,(IY+55) | Jump forward unless dealing with 'INPUT LINE...' (bit 7 of FLAGX set).
| 03941 | JP Z,ED_IGNORE
| 03944 | CALL WAIT_KEY | Get the second code and put it in E.
| 03947 | LD E,A
The other bytes for the control characters are now fetched.
ED_CONTR | 03948 | CALL WAIT_KEY | Get another code.
| 03951 | PUSH DE | Save the previous codes.
| 03952 | LD HL,(23643) | Fetch K-CUR.
| 03955 | RES 0,(IY+7) | Signal 'K mode' (reset bit 0 of MODE).
| 03959 | CALL MAKE_ROOM | Make two or three spaces.
| 03962 | POP BC | Restore the previous codes.
| 03963 | INC HL | Point to the first location.
| 03964 | LD (HL),B | Enter first code.
| 03965 | INC HL | Then enter the second code which will be overwritten if there are only two codes - i.e. with INK and PAPER.
| 03966 | LD (HL),C
| 03967 | JR ADD_CH_1 | Jump forward.
This entry point is used by the routine at ED_SYMBOL. The address of this entry point is found in the initial channel information table. The following subroutine actually adds a code to the current EDIT or INPUT line.
ADD_CHAR | 03969 | RES 0,(IY+7) | Signal 'K mode' (reset bit 0 of MODE).
| 03973 | LD HL,(23643) | Fetch the cursor position (K-CUR).
| 03976 | CALL ONE_SPACE | Make a single space.
ADD_CH_1 | 03979 | LD (DE),A | Enter the code into the space and set K-CUR to signal that the cursor is to occur at the location after. Then return indirectly to ED_LOOP.
| 03980 | INC DE
| 03981 | LD (23643),DE
| 03985 | RET
The editing keys are dealt with as follows:
ED_KEYS | 03986 | LD E,A | The code is transferred to the DE register pair.
| 03987 | LD D,0
| 03989 | LD HL,3993 | The base address of the editing keys table.
| 03992 | ADD HL,DE | The entry is addressed and then fetched into E.
| 03993 | LD E,(HL)
| 03994 | ADD HL,DE | The address of the handling routine is saved on the machine stack.
| 03995 | PUSH HL
| 03996 | LD HL,(23643) | The HL register pair is set to K-CUR and an indirect jump made to the required routine.
| 03999 | RET