![]() |
Routines |
| Prev: 0808 | Up: Map |
|
Used by the routine at SAVE_ETC.
There are three main parts to this routine.
Start therefore with the loading of the data block.
|
||||||||||
| ME_CONTRL | 08B6 | LD C,(IX+$0B) | Fetch the 'length' of the data block. | |||||||
| 08B9 | LD B,(IX+$0C) | |||||||||
| 08BC | PUSH BC | Save a copy of the 'length'. | ||||||||
| 08BD | INC BC | Now make 'length+1' locations available in the work space. | ||||||||
| 08BE | RST $30 | |||||||||
| 08BF | LD (HL),$80 | Place an end marker in the extra location. | ||||||||
| 08C1 | EX DE,HL | Move the 'start' pointer to the HL register pair. | ||||||||
| 08C2 | POP DE | Fetch the original 'length'. | ||||||||
| 08C3 | PUSH HL | Save a copy of the 'start'. | ||||||||
| 08C4 | PUSH HL | Now set the IX register pair for the actual load. | ||||||||
| 08C5 | POP IX | |||||||||
| 08C7 | SCF | Signal 'LOAD'. | ||||||||
| 08C8 | LD A,$FF | Signal 'data block only'. | ||||||||
| 08CA | CALL LD_BLOCK | Load the data block. | ||||||||
|
The lines of the new program are merged with the lines of the old program.
|
||||||||||
| 08CD | POP HL | Fetch the 'start' of the new program. | ||||||||
| 08CE | LD DE,($5C53) | Initialise DE to the 'start' of the old program (PROG). | ||||||||
|
Enter a loop to deal with the lines of the new program.
|
||||||||||
| ME_NEW_LP | 08D2 | LD A,(HL) | Fetch a line number and test it. | |||||||
| 08D3 | AND $C0 | |||||||||
| 08D5 | JR NZ,ME_VAR_LP | Jump when finished with all the lines. | ||||||||
|
Now enter an inner loop to deal with the lines of the old program.
|
||||||||||
| ME_OLD_LP | 08D7 | LD A,(DE) | Fetch the high line number byte and compare it. Jump forward if it does not match but in any case advance both pointers. | |||||||
| 08D8 | INC DE | |||||||||
| 08D9 | CP (HL) | |||||||||
| 08DA | INC HL | |||||||||
| 08DB | JR NZ,ME_OLD_L1 | |||||||||
| 08DD | LD A,(DE) | Repeat the comparison for the low line number bytes. | ||||||||
| 08DE | CP (HL) | |||||||||
| ME_OLD_L1 | 08DF | DEC DE | Now retreat the pointers. | |||||||
| 08E0 | DEC HL | |||||||||
| 08E1 | JR NC,ME_NEW_L2 | Jump forward if the correct place has been found for a line of the new program. | ||||||||
| 08E3 | PUSH HL | Otherwise find the address of the start of the next old line. | ||||||||
| 08E4 | EX DE,HL | |||||||||
| 08E5 | CALL NEXT_ONE | |||||||||
| 08E8 | POP HL | |||||||||
| 08E9 | JR ME_OLD_LP | Go round the loop for each of the 'old lines'. | ||||||||
| ME_NEW_L2 | 08EB | CALL ME_ENTER | Enter the 'new line' and go round the outer loop again. | |||||||
| 08EE | JR ME_NEW_LP | |||||||||
|
In a similar manner the variables of the new program are merged with the variables of the old program.
|
||||||||||
| ME_VAR_LP | 08F0 | LD A,(HL) | Fetch each variable name in turn and test it. | |||||||
| 08F1 | LD C,A | |||||||||
| 08F2 | CP $80 | Return when all the variables have been considered. | ||||||||
| 08F4 | RET Z | |||||||||
| 08F5 | PUSH HL | Save the current new pointer. | ||||||||
| 08F6 | LD HL,($5C4B) | Fetch VARS (for the old program). | ||||||||
|
Now enter an inner loop to search the existing variables area.
|
||||||||||
| ME_OLD_VP | 08F9 | LD A,(HL) | Fetch each variable name and test it. | |||||||
| 08FA | CP $80 | |||||||||
| 08FC | JR Z,ME_VAR_L2 | Jump forward once the end marker is found. (Make an 'addition'.) | ||||||||
| 08FE | CP C | Compare the names (first bytes). | ||||||||
| 08FF | JR Z,ME_OLD_V2 | Jump forward to consider it further, returning here if it proves not to match fully. | ||||||||
| ME_OLD_V1 | 0901 | PUSH BC | Save the new variable's name whilst the next 'old variable' is located. | |||||||
| 0902 | CALL NEXT_ONE | |||||||||
| 0905 | POP BC | |||||||||
| 0906 | EX DE,HL | Restore the pointer to the DE register pair and go round the loop again. | ||||||||
| 0907 | JR ME_OLD_VP | |||||||||
|
The old and new variables match with respect to their first bytes but variables with long names will need to be matched fully.
|
||||||||||
| ME_OLD_V2 | 0909 | AND $E0 | Consider bits 7, 6 and 5 only. | |||||||
| 090B | CP $A0 | Accept all the variable types except 'long named variables'. | ||||||||
| 090D | JR NZ,ME_VAR_L1 | |||||||||
| 090F | POP DE | Make DE point to the first character of the 'new name'. | ||||||||
| 0910 | PUSH DE | |||||||||
| 0911 | PUSH HL | Save the pointer to the 'old name'. | ||||||||
|
Enter a loop to compare the letters of the long names.
|
||||||||||
| ME_OLD_V3 | 0912 | INC HL | Update both the 'old' and the 'new' pointers. | |||||||
| 0913 | INC DE | |||||||||
| 0914 | LD A,(DE) | Compare the two letters. | ||||||||
| 0915 | CP (HL) | |||||||||
| 0916 | JR NZ,ME_OLD_V4 | Jump forward if the match fails. | ||||||||
| 0918 | RLA | Go round the loop until the 'last character' is found. | ||||||||
| 0919 | JR NC,ME_OLD_V3 | |||||||||
| 091B | POP HL | Fetch the pointer to the start of the 'old' name and jump forward - successful. | ||||||||
| 091C | JR ME_VAR_L1 | |||||||||
| ME_OLD_V4 | 091E | POP HL | Fetch the pointer and jump back - unsuccessful. | |||||||
| 091F | JR ME_OLD_V1 | |||||||||
|
Come here if the match was found.
|
||||||||||
| ME_VAR_L1 | 0921 | LD A,$FF | Signal 'replace' variable. | |||||||
|
And here if not. (A holds +80 - variable to be 'added'.)
|
||||||||||
| ME_VAR_L2 | 0923 | POP DE | Fetch pointer to 'new' name. | |||||||
| 0924 | EX DE,HL | Switch over the registers. | ||||||||
| 0925 | INC A | The zero flag is to be set if there is to be a 'replacement', reset for an 'addition'. | ||||||||
| 0926 | SCF | Signal 'handling variables'. | ||||||||
| 0927 | CALL ME_ENTER | Now make the entry. | ||||||||
| 092A | JR ME_VAR_LP | Go round the loop to consider the next new variable. | ||||||||
| Prev: 0808 | Up: Map |