2068 Expanding Array

Authors

Publication

Publication Details

Date

Pages

See all articles from Sinc-Link v5 n3

If you create an array for the storage of data, the chances are that you will dimension the array to be as large as it might need to be some time in the future. In this way, data can be added as needed without having to worry about ‘outgrowing’ the array. However, if you are using tape for storage, SAVEs and LOADs will be time consuming because of the huge array which may be mostly empty. A neat solution is to use an array which starts out with only one element and which grows as needed to be only as large as it needs to be to hold the data.

How It Works

The first program to be LOADed after the main BASIC program is “opnr”, an 11 byte routine located out of the way at 65355. When it is activated in line 9998, it moves the whole BASIC program area 91 bytes higher in memory by calling the “open BC spaces” routine in ROM at 12BB hex. The “expcode” is now tucked into the spaces just created, safely out of the way of the upcoming changes in the BASIC area. The first 8 bytes of code at 26710 are used for variables needed by the other two routines.

Line 30 is interesting. The LET N$(1)-N$(1) assignment statement, which seems to be a do-nothing quirky thing, is actually an essential part of the whole routine. When a variable is assigned a value, its address is stored in the system variable called DEST. The machine code routine at 26718 uses this value to locate the first element of the array. The parameters of the array are found by following the structure given on page 257 of the manual and then stored in variables mentioned earlier.

Line 40 inputs the data into the array element and displays it on the screen. Line 50 checks for a “STOP” to terminate the inputting of data. Line 60 gets interesting again. The location of the current element of the array is put into DEST and is used by the machine code at 26754 to shift everything up in memory one array-width and to change the array parameters so that the 2068 knows that the array is one element longer.

Creating the Program

If you do not have an assembler, type in the LOADER program first. Line 10 generated the 11-byte routine that moves the BASIC area. Line 20 calls that routine. The rest of the code is now generated underneath the BASIC program. RUN the program. Any typing errors in DATA lines 82 to 89 will be flagged. GOTO 9999 will save both machine code programs. Now type in the main program with both machine code programs still in place. GOTO 999 will save all three programs. Then a GOTO 1 will call up the little menu. Option 3 will be the one to choose at this time. The prompt will permit you to create the array with any width you want. The length of the array is looked after by the program, of course.

Since the data is stored in an array, never RUN the program. Always GOTO 1 to reach the menu.

1 REM COADE LOADER FOR EXPANDING ARRAY - Larry Crawford
10 CLEAR 65354: RESTORE 81: FOR f=0 TO 10: READ a: POKE (65355+f),a: NEXT f
20 RANDOMIZE USR 65355
30 RESTORE 82: FOR F=0 TO 7: LET T=0: FOR G=0 TO 9
31 READ A: POKE (26718+10*F+G),A: LET T=T+A: NEXT: READ A: IF A<>T THEN PRINT "DATA PROBLEM IN LINE ";82+F: STOP
32 NEXT F
33 FOR F=80 TO 82: READ A: POKE 26718+F,A: NEXT F
34 STOP
81 DATA 42,83,92,43,1,91,0,205,187,18,201
82 DATA 221,42,77,92,221,34,86,104,221,102,1200
83 DATA 255,221,110,254,34,90,104,221,102,253,1644
84 DATA 221,110,252,34,88,104,221,102,250,221,1603
85 DATA 110,249,34,92,104,201,42,77,92,237,1238
86 DATA 75,90,104,9,43,205,187,18,221,42,994
86 DATA 86,104,42,92,104,237,91,90,104,25,975
88 DATA 221,116,250,221,117,249,34,92,104,42,1446
89 DATA 88,104,35,221,116,253,221,117,252,34,1441
90 DATA 88,104,201
9999 SAVE "opnr" CODE 65355,11: SAVE "expcode" CODE 26710,91

Assembly Listing

FF4B	2A533C		OPNR	LD HL,(prog)
FF4E 2B DEC HL
FF4F 015B00 LD BC,005B
FF52 CDBB12 CALL 12BB
FF55 C9 RET

6856 7E FRST LD A,(HL)
6857 6E LD L,(HL)
6858 0C LAST INC C
6859 00 NOP
685A 02 WDTH LD (BC),A
685B 00 NOP
685C 1D LNTH DEC E
685D 00 NOP
685E DD2A4D5C INIT LD IX,(dest)
6862 DD225668 LD (FRST),IX
6866 DD66FF LD H,(IX+FE)
6869 DD6EFE LD L,(IX+FE)
686C 225A68 LD (WDTH),HL
686F DD66FD LD H,(IX+FD)
6872 DD6EFC LD L,(IX+FC)
6875 225868 LD (LAST),HL
6878 DD66FA LD H,(IX+FA)
687B DD6EF9 LD L,(IX+F9)
687E 225C68 LD (LNTH),HL
6881 C9 RET
6882 2A4D5C XPND LD HL,(dest)
6885 ED4B5A68 LD BC,(WDTH)
6889 09 ADD HL,DC
688A 2B DEC HL
688B CDBB12 CALL 12BB
688E DD2A5663 LD IX,(FRST)
6892 2A5C68 LD HL,(LNTH)
6895 ED5B5A60 LD DE,(WDTH)
6899 19 ADD HL,DE
689A DD74FA LD (IX+FA),H
689D DD75F9 LD (IX+F9),L
68A0 225C68 LD (LNTH),HL
68A3 2A5868 LD HL,(LAST)
68A6 23 INC HL
68A7 DD74FD LD (IX+FD),H
68AA DD75FC LD (IX+FC),L
68AD 225868 LD (LAST),HL
68B0 C9 RET

Demo Program

1 REM An expanding array for storing data
3 REM Larry Crawford
4 REM
9 GO TO 500
10 LET X=1: INPUT "WHAT IS WIDTH OF ARRAY?";W: CLS
20 DIM N$(1,W)
30 LET N$(1)=N$(1): RANDOMIZE USR 26718: GO SUB 600
40 PRINT X;: INPUT N$(X): PRINT TAB 5;N$(X)
50 IF CODE N$(X)=226 THEN GO TO 100
60 LET N$(X)=N$(X): RANDOMIZE USR 26754: LET X=X+1: GO TO 40
100 CLS: PRINT "DATA STORED IN ARRAY"''
110 FOR I=1 TO X-1: PRINT I;TAB 5;N$(I): NEXT I
120 STOP
500 LET N$(1)=N$(1): RANDOMIZE USR 26718: BORDER 1: PAPER 1: INK 6: CLS: PRINT TAB 11;"MENU"''
510 PRINT "1: DISPLAY ARRAY TO DATE"''"2: ADD TO EXISTING ARRAY"''"3: CREATE A NEW ARRAY"''"4: SAVE TO TAPE"''"5: PRINT CONTENTS OF ARRAY"''TAB 8; FLASH 1;"ENTER CHOICE"
520 INPUT C: GO TO C+520
521 GO TO 100
522 LET X=X-1: GO SUB 600: GO TO 60
523 GO TO 10
524 GO TO 999
525 LPRINT "CONTENTS OF ARRAY"'':FOR I=1 TO X-1:LPRINT I;TAB 5;N$(I): NEXT I
600 CLS: PRINT "ENTER DATA"' "(Use STOP to terminate entries)"''
610 RETURN
9998 LOAD "opnr" CODE : RANDOMIZE USR 65355: LOAD "expcode" CODE: GO TO 500
9999 SAVE "exp" LINE 998: SAVE "opnr" CODE 65355,11: SAVE "expcode" CODE 26710,91

Products

 

Downloadable Media

 
Scroll to Top