![]() |
Routines |
| Prev: 0802 | Up: Map | Next: 08B6 |
|
Used by the routine at SAVE_ETC.
This routine controls the LOADing of a BASIC program, and its variables, or an array.
|
||||||||||
| LD_CONTRL | 0808 | LD E,(IX+$0B) | Fetch the 'number of bytes' as given in the 'new header'. | |||||||
| 080B | LD D,(IX+$0C) | |||||||||
| 080E | PUSH HL | Save the 'destination pointer'. | ||||||||
| 080F | LD A,H | Jump forward unless trying to LOAD a previously undeclared array. | ||||||||
| 0810 | OR L | |||||||||
| 0811 | JR NZ,LD_CONT_1 | |||||||||
| 0813 | INC DE | Add three bytes to the length - for the name, the low length and the high length of a new variable. | ||||||||
| 0814 | INC DE | |||||||||
| 0815 | INC DE | |||||||||
| 0816 | EX DE,HL | |||||||||
| 0817 | JR LD_CONT_2 | Jump forward. | ||||||||
|
Consider now if there is enough room in memory for the new data block.
|
||||||||||
| LD_CONT_1 | 0819 | LD L,(IX-$06) | Fetch the size of the existing 'program+variables or array'. | |||||||
| 081C | LD H,(IX-$05) | |||||||||
| 081F | EX DE,HL | |||||||||
| 0820 | SCF | Jump forward if no extra room will be required (taking into account the reclaiming of the presently used memory). | ||||||||
| 0821 | SBC HL,DE | |||||||||
| 0823 | JR C,LD_DATA | |||||||||
|
Make the actual test for room.
|
||||||||||
| LD_CONT_2 | 0825 | LD DE,$0005 | Allow an overhead of five bytes. | |||||||
| 0828 | ADD HL,DE | |||||||||
| 0829 | LD B,H | Move the result to the BC register pair and make the test. | ||||||||
| 082A | LD C,L | |||||||||
| 082B | CALL TEST_ROOM | |||||||||
|
Now deal with the LOADing of arrays.
|
||||||||||
| LD_DATA | 082E | POP HL | Fetch the 'pointer' anew. | |||||||
| 082F | LD A,(IX+$00) | Jump forward if LOADing a BASIC program. | ||||||||
| 0832 | AND A | |||||||||
| 0833 | JR Z,LD_PROG | |||||||||
| 0835 | LD A,H | Jump forward if LOADing a new array. | ||||||||
| 0836 | OR L | |||||||||
| 0837 | JR Z,LD_DATA_1 | |||||||||
| 0839 | DEC HL | Fetch the 'length' of the existing array by collecting the length bytes from the variables area. | ||||||||
| 083A | LD B,(HL) | |||||||||
| 083B | DEC HL | |||||||||
| 083C | LD C,(HL) | |||||||||
| 083D | DEC HL | Point to its old name. | ||||||||
| 083E | INC BC | Add three bytes to the length - one for the name and two for the 'length'. | ||||||||
| 083F | INC BC | |||||||||
| 0840 | INC BC | |||||||||
| 0841 | LD ($5C5F),IX | Save the IX register pair temporarily (in X-PTR) whilst the old array is reclaimed. | ||||||||
| 0845 | CALL RECLAIM_2 | |||||||||
| 0848 | LD IX,($5C5F) | |||||||||
|
Space is now made available for the new array - at the end of the present variables area.
|
||||||||||
| LD_DATA_1 | 084C | LD HL,($5C59) | Find the pointer to the end-marker of the variables area - the '+80-byte' (E-LINE). | |||||||
| 084F | DEC HL | |||||||||
| 0850 | LD C,(IX+$0B) | Fetch the 'length' of the new array. | ||||||||
| 0853 | LD B,(IX+$0C) | |||||||||
| 0856 | PUSH BC | Save this 'length'. | ||||||||
| 0857 | INC BC | Add three bytes - one for the name and two for the 'length'. | ||||||||
| 0858 | INC BC | |||||||||
| 0859 | INC BC | |||||||||
| 085A | LD A,(IX-$03) | 'IX+0E' of the old header gives the name of the array. | ||||||||
| 085D | PUSH AF | The name is saved whilst the appropriate amount of room is made available. In effect BC spaces before the 'new +80-byte'. | ||||||||
| 085E | CALL MAKE_ROOM | |||||||||
| 0861 | INC HL | |||||||||
| 0862 | POP AF | |||||||||
| 0863 | LD (HL),A | The name is entered. | ||||||||
| 0864 | POP DE | The 'length' is fetched and its two bytes are also entered. | ||||||||
| 0865 | INC HL | |||||||||
| 0866 | LD (HL),E | |||||||||
| 0867 | INC HL | |||||||||
| 0868 | LD (HL),D | |||||||||
| 0869 | INC HL | HL now points to the first location that is to be filled with data from the tape. | ||||||||
| 086A | PUSH HL | This address is moved to the IX register pair; the carry flag set; 'data block' is signalled; and the block LOADed. | ||||||||
| 086B | POP IX | |||||||||
| 086D | SCF | |||||||||
| 086E | LD A,$FF | |||||||||
| 0870 | JP LD_BLOCK | |||||||||
|
Now deal with the LOADing of a BASIC program and its variables.
|
||||||||||
| LD_PROG | 0873 | EX DE,HL | Save the 'destination pointer'. | |||||||
| 0874 | LD HL,($5C59) | Find the address of the end marker of the current variables area - the '+80-byte' (E-LINE). | ||||||||
| 0877 | DEC HL | |||||||||
| 0878 | LD ($5C5F),IX | Save IX temporarily (in X-PTR). | ||||||||
| 087C | LD C,(IX+$0B) | Fetch the 'length' of the new data block. | ||||||||
| 087F | LD B,(IX+$0C) | |||||||||
| 0882 | PUSH BC | Keep a copy of the 'length' whilst the present program and variables areas are reclaimed. | ||||||||
| 0883 | CALL RECLAIM_1 | |||||||||
| 0886 | POP BC | |||||||||
| 0887 | PUSH HL | Save the pointer to the program area and the length of the new data block. | ||||||||
| 0888 | PUSH BC | |||||||||
| 0889 | CALL MAKE_ROOM | Make sufficient room available for the new program and its variables. | ||||||||
| 088C | LD IX,($5C5F) | Restore the IX register pair from X-PTR. | ||||||||
| 0890 | INC HL | The system variable VARS has also to be set for the new program. | ||||||||
| 0891 | LD C,(IX+$0F) | |||||||||
| 0894 | LD B,(IX+$10) | |||||||||
| 0897 | ADD HL,BC | |||||||||
| 0898 | LD ($5C4B),HL | |||||||||
| 089B | LD H,(IX+$0E) | If a line number was specified then it too has to be considered. | ||||||||
| 089E | LD A,H | |||||||||
| 089F | AND $C0 | |||||||||
| 08A1 | JR NZ,LD_PROG_1 | Jump if 'no number'; otherwise set NEWPPC and NSPPC. | ||||||||
| 08A3 | LD L,(IX+$0D) | |||||||||
| 08A6 | LD ($5C42),HL | |||||||||
| 08A9 | LD (IY+$0A),$00 | |||||||||
|
The data block can now be LOADed.
|
||||||||||
| LD_PROG_1 | 08AD | POP DE | Fetch the 'length'. | |||||||
| 08AE | POP IX | Fetch the 'start'. | ||||||||
| 08B0 | SCF | Signal 'LOAD'. | ||||||||
| 08B1 | LD A,$FF | Signal 'data block' only. | ||||||||
| 08B3 | JP LD_BLOCK | Now LOAD it. | ||||||||
| Prev: 0802 | Up: Map | Next: 08B6 |