Prev: 11249 Up: Map Next: 11400
11266: THE 'DIM' COMMAND ROUTINE
The address of this routine is found in the parameter table.
This routine establishes new arrays in the variables area. The routine starts by searching the existing variables area to determine whether there is an existing array with the same name. If such an array is found then it is 'reclaimed' before the new array is established.
A new array will have all its elements set to zero if it is a numeric array, or to 'spaces' if it is an array of strings.
DIM 11266 CALL LOOK_VARS Search the variables area.
D_RPORT_C 11269 JP NZ,REPORT_C Give report C as there has been an error.
11272 CALL SYNTAX_Z Jump forward if in 'run time'.
11275 JR NZ,D_RUN
11277 RES 6,C Test the syntax for string arrays as if they were numeric.
11279 CALL STK_VAR Check the syntax of the parenthesised expression.
11282 CALL CHECK_END Move on to consider the next statement as the syntax was satisfactory.
An 'existing array' is reclaimed.
D_RUN 11285 JR C,D_LETTER Jump forward if there is no 'existing array'.
11287 PUSH BC Save the discriminator byte.
11288 CALL NEXT_ONE Find the start of the next variable.
11291 CALL RECLAIM_2 Reclaim the 'existing array'.
11294 POP BC Restore the discriminator byte.
The initial parameters of the new array are found.
D_LETTER 11295 SET 7,C Set bit 7 in the discriminator byte.
11297 LD B,0 Make the dimension counter zero.
11299 PUSH BC Save the counter and the discriminator byte.
11300 LD HL,1 The HL register pair is to hold the size of the elements in the array: '1' for a string array, '5' for a numeric array.
11303 BIT 6,C
11305 JR NZ,D_SIZE
11307 LD L,5
D_SIZE 11309 EX DE,HL Element size to DE.
The following loop is accessed for each dimension that is specified in the parenthesised expression of the DIM statement. The total number of bytes required for the elements of the array is built up in the DE register pair.
D_NO_LOOP 11310 RST 32 Advance CH-ADD on each pass.
11311 LD H,255 Set a 'limit value'.
11313 CALL INT_EXP1 Evaluate a parameter.
11316 JP C,REPORT_3 Give an error if 'out of range'.
11319 POP HL Fetch the dimension counter and the discriminator byte.
11320 PUSH BC Save the parameter on each pass through the loop.
11321 INC H Increase the dimension counter on each pass also.
11322 PUSH HL Restack the dimension counter and the discriminator byte.
11323 LD H,B The parameter is moved to the HL register pair.
11324 LD L,C
11325 CALL GET_HLxDE The byte total is built up in HL and then transferred to DE.
11328 EX DE,HL
11329 RST 24 Get the present character and go around the loop again if there is another dimension.
11330 CP ","
11332 JR Z,D_NO_LOOP
At this point the DE register pair indicates the number of bytes required for the elements of the new array and the size of each dimension is stacked, on the machine stack.
Now check that there is indeed a closing bracket to the parenthesised expression.
11334 CP ")" Is it a ')'?
11336 JR NZ,D_RPORT_C Jump back if not so.
11338 RST 32 Advance CH-ADD past it.
Allowance is now made for the dimension sizes.
11339 POP BC Fetch the dimension counter and the discriminator byte.
11340 LD A,C Pass the discriminator byte to the A register for later.
11341 LD L,B Move the counter to L.
11342 LD H,0 Clear the H register.
11344 INC HL Increase the dimension counter by two and double the result and form the correct overall length for the variable by adding the element byte total.
11345 INC HL
11346 ADD HL,HL
11347 ADD HL,DE
11348 JP C,REPORT_4 Give the report 'Out of memory' if required.
11351 PUSH DE Save the element byte total.
11352 PUSH BC Save the dimension counter and the discriminator byte.
11353 PUSH HL Save the overall length also.
11354 LD B,H Move the overall length to BC.
11355 LD C,L
The required amount of room is made available for the new array at the end of the variables area.
11356 LD HL,(23641) Make the HL register pair point to the '128-byte' (E-LINE-1).
11359 DEC HL
11360 CALL MAKE_ROOM The room is made available.
11363 INC HL HL is made to point to the first new location.
The parameters are now entered.
11364 LD (HL),A The letter, suitably marked, is entered first.
11365 POP BC The overall length is fetched and decreased by '3'.
11366 DEC BC
11367 DEC BC
11368 DEC BC
11369 INC HL Advance HL.
11370 LD (HL),C Enter the low length.
11371 INC HL Advance HL.
11372 LD (HL),B Enter the high length.
11373 POP BC Fetch the dimension counter.
11374 LD A,B Move it to the A register.
11375 INC HL Advance HL.
11376 LD (HL),A Enter the dimension count.
The elements of the new array are now 'cleared'.
11377 LD H,D HL is made to point to the last location of the array and DE to the location before that one.
11378 LD L,E
11379 DEC DE
11380 LD (HL),0 Enter a zero into the last location but overwrite it with 'space' if dealing with an array of strings.
11382 BIT 6,C
11384 JR Z,DIM_CLEAR
11386 LD (HL)," "
DIM_CLEAR 11388 POP BC Fetch the element byte total.
11389 LDDR Clear the array + one extra location.
The 'dimension sizes' are now entered.
DIM_SIZES 11391 POP BC Get a dimension size.
11392 LD (HL),B Enter the high byte.
11393 DEC HL Back one.
11394 LD (HL),C Enter the low byte.
11395 DEC HL Back one.
11396 DEC A Decrease the dimension counter.
11397 JR NZ,DIM_SIZES Repeat the operation until all the dimensions have been considered; then return.
11399 RET
Prev: 11249 Up: Map Next: 11400