PAGE 01 DAI FIRMWARE CA01-CBBE V1.1 002 ORG :CA01 003 * 004 * 005 * 006 ***************************** 007 * MEMORY MANAGEMENT ROUTINE * 008 ***************************** 009 * 010 * This routine is used to obtain and release 011 * memory for its display, as the mode changes. 012 * 013 * Entry: HL: Lowest screen RAM byte required. 014 * CY=1: Space to this point at least is 015 * now required. Additional space 016 * may not be released. 017 * CY=0: Space is held to or below this 018 * point. Any space held below this 019 * point is no longer required. 020 * Exit: CY=1: O.K. 021 * CY=0: No space available. 022 * AFBCDE preserved. 023 * 024 *ASKRM 025 CA01 00 SMKRM NOP 026 CA02 F5 PUSH PSW 027 CA03 D5 PUSH D 028 CA04 D21BCA JNC :CA1B If space not reqd anymore 029 CA07 EB XCHG Lowest byte in DE 030 CA08 2AA502 LHLD :02A5 Get bottom screen RAM 031 CA0B CD14DE CALL :DE14 Check for overflow 032 CA0E DA1ECA JC :CA1E If OK 033 CA11 2AA302 LHLD :02A3 Get begin free RAM 034 CA14 EB XCHG and store it in DE 035 CA15 CD14DE CALL :DE14 Still free RAM available? 036 CA18 DA21CA JC :CA21 If not 037 CA1B 22A502 ASR10 SHLD :02A5 Update bottom screen RAM 038 CA1E C3ADCE ASR20 JMP :CEAD Return, set CY=1 039 040 * If no RAM space available: 041 042 CA21 D1 ASR30 POP D 043 CA22 C3B1CE JMP :CEB1 Return, set CY=0 044 * 045 ******************************************* 046 * EMERGENCY STOP ROUTINE (Graphics modes) * 047 ******************************************* 048 * 049 * This routine is used if no sufficient space for 050 * a A-mode is available. 051 * 052 * 053 ************************** 054 * EMERGENCY STOP ROUTINE * 055 ************************** 056 * 057 * No change in execution, only using a new entry on 058 * 'Run NEW'. 059 * 060 CA25 CDB1DE EMSTP CALL :DEB1 Run NEW with default heap 061 CA28 3EFF MVI A,:FF 062 CA2A EF RST 5 Change to mode 0 063 CA2B 18 DATA :18 PAGE 02 DAI FIRMWARE CA01-CBBE V1.1 064 CA2C CDE4CE CALL :CEE4 Select ROM-bank 0; Run error 065 CA2F 89DB DBL :DB89 'OUT OF SPACE FOR MODE' 066 CA31 C318C8 JMP :C818 Return to BASIC monitor 067 * 068 ****************************************** 069 * FIND STRING BASIC INSTRUCTION IN TABLE * 070 ****************************************** 071 * 072 * Looks for table entry whose name is the initial 073 * string of input, beginning at C'th position. 074 * REMARK: Variables, beginning with a reserved 075 * string are not allowed. 076 * 077 * Entry: HL: Startaddress table. 078 * C : Position char on current line. 079 * E : Number of info bytes -1. 080 * Exit: If found: CY=1: 081 * HL: Address in table where string 082 * can be found. 083 * C : Position on current line after 084 * last char. 085 * A : Last byte of string typed in. 086 * BE preserved, D=0. 087 * If not found: CY=0: 088 * C : Points to next char. 089 * HL: Points after end of table. 090 * BE preserved. A,D=0. 091 * 092 CA34 CDD2DD LOOKC CALL :DDD2 Get char from line, 093 neglect TAB and space 094 CA37 56 LKC10 MOV D,M Get length byte of string 095 CA38 23 INX H Points to 1st stringchar. 096 CA39 7A MOV A,D 097 CA3A B7 ORA A Is length zero? 098 CA3B C8 RZ Then abort 099 CA3C C5 PUSH B Save position of 1st char 100 CA3D CDE0DD LKC20 CALL :DDE0 Get char from line 101 CA40 0C INR C Points to next char on line 102 CA41 BE CMP M Is it identical to the 103 one in table? 104 CA42 23 INX H Points to next char in table 105 CA43 C24ECA JNZ :CA4E If not identical 106 CA46 15 DCR D Else: decr string length 107 CA47 C23DCA JNZ :CA3D Get evt. next byte to check 108 CA4A E3 XTHL cancell PUSH B 109 CA4B E1 POP H 110 CA4C 37 STC CY=1 111 CA4D C9 RET 112 113 * If strings not identical: 114 115 CA4E 7A LKC30 MOV A,D Get string length 116 CA4F 83 ADD E Add 2 117 CA50 CD30DE CALL :DE30 Add A to HL; HL points now 118 to next string in table. 119 CA53 C1 POP B Restore C=1 120 CA54 C337CA JMP :CA37 Start check on next string 121 * 122 ***************** 123 * TABLE LOOK UP * 124 ***************** 125 * PAGE 03 DAI FIRMWARE CA01-CBBE V1.1 126 * Finds an entry in a look-up table. 127 * LOOK used for symboltable, LOOKX for table of 128 * Basic functions (CFE6). 129 * 130 * Table format: 131 * [type/length][name][type/length][info] 132 * 133 * Entry: B: Points to start name in input. 134 * D: Type/length of name in input 135 * high nibble: type; low nibble: length. 136 * HL: Startaddress look-up table. 137 * Exit: If not found: CY=0: 138 * HL points to 0 byte at table end. 139 * ABCD preserved, E corrupted. 140 * If found: CY=1: 141 * HL points to T/L of entry found. 142 * E indicates how manyth entry. 143 * ABC preserved. 144 * 145 CA57 2AA102 LOOK LHLD :02A1 Get startaddr symtab 146 * 147 CA5A 37 LOOKX STC CY=1 148 CA5B F5 PUSH PSW 149 CA5C C5 PUSH B 150 CA5D 1EFF MVI E,:FF 151 CA5F 1C LK10 INR E Entry count 152 CA60 7E MOV A,M Get T/L name in table 153 CA61 B7 ORA A 154 CA62 CA8BCA JZ :CA8B Abort if end table reached 155 CA65 BA CMP D Compare with wanted T/L 156 CA66 CA6FCA JZ :CA6F Jump if found 157 CA69 CDAECA LK15 CALL :CAAE Calc addr next entry 158 CA6C C35FCA JMP :CA5F Check next entry 159 160 * If T/L of name O.K.: 161 162 CA6F C1 LK20 POP B 163 CA70 C5 PUSH B 164 CA71 48 MOV C,B 165 CA72 D5 PUSH D 166 CA73 7A MOV A,D Get wanted T/L of name 167 CA74 E60F ANI :0F Length name only 168 CA76 57 MOV D,A in D 169 CA77 E5 PUSH H Save begin table entry 170 CA78 23 LK30 INX H 171 CA79 CDE0DD CALL :DDE0 Get char from line 172 CA7C BE CMP M Compare char of name 173 CA7D C28FCA JNZ :CA8F If not correct name 174 175 * If char. identical: 176 177 CA80 0C INR C Points to next char 178 CA81 15 DCR D Decr length 179 CA82 C278CA JNZ :CA78 Check next char if not 180 ready 181 CA85 23 INX H Points after name in table 182 CA86 D1 POP D 183 CA87 D1 POP D 184 CA88 C1 POP B 185 CA89 F1 POP PSW CY=1: Entry found 186 CA8A C9 RET 187 PAGE 04 DAI FIRMWARE CA01-CBBE V1.1 188 * If end of look-up table reached: 189 190 CA8B C1 LK40 POP B 191 CA8C F1 POP PSW 192 CA8D 3F CMC CY=0: No entry found 193 CA8E C9 RET 194 195 * If characters not identical: 196 197 CA8F E1 LK50 POP H 198 CA90 D1 POP D 199 CA91 7A MOV A,D Length in A 200 CA92 C369CA JMP :CA69 Look further 201 * 202 ************************************** 203 * FIND A VARIABLE IN THE SYMBOLTABLE * 204 ************************************** 205 * 206 * Routine skips through successive symtab entries 207 * from beginning till past the place pointed by HL. 208 * 209 * Entry: HL points to 1st byte required variable. 210 * Exit: HL points to (if found) or past (if not 211 * found) address required in symbol table. 212 * AFBCDE preserved. 213 * 214 CA95 F5 FNAME PUSH PSW 215 CA96 D5 PUSH D 216 CA97 EB XCHG Reqd addr in DE 217 CA98 2AA102 LHLD :02A1 Get startaddr symtab 218 CA9B E5 FNM10 PUSH H 219 CA9C CDAECA CALL :CAAE Calc addr next variable 220 CA9F CD14DE CALL :DE14 Reqd variable reached ? 221 CAA2 D2AACA JNC :CAAA Quit if true 222 CAA5 33 INX SP ) Cancel Push H 223 CAA6 33 INX SP ) 224 CAA7 C39BCA JMP :CA9B Skip next variable 225 CAAA E1 FNM20 POP H 226 CAAB D1 POP D 227 CAAC F1 POP PSW 228 CAAD C9 RET 229 * 230 ************************************************** 231 * CALCULATE ADDRESS NEXT VARIABLE IN SYMBOLTABLE * 232 ************************************************** 233 * 234 * Adds length of name of variable + length of value 235 * of variable to beginaddress. 236 * 237 * DADD: variable = length/name/length/value. 238 * DADR: variable = length/name. 239 * 240 * Entry: HL points to 1st byte of current variable. 241 * Exit: HL points to next variable in symtab. 242 * 243 CAAE CDB1CA DADD CALL :CAB1 Add length name to HL 244 CAB1 7E DADR MOV A,M Get info T/L byte 245 CAB2 23 INX H Add 1 246 CAB3 E60F ANI :0F Length only 247 CAB5 C330DE JMP :DE30 Add length info to HL 248 * 249 ********************************************** PAGE 05 DAI FIRMWARE CA01-CBBE V1.1 250 * INSERT A VARIABLE NAME IN THE SYMBOL TABLE * 251 ********************************************** 252 * 253 * Entry: HL points to end symtab. 254 * B points to start of name in input. 255 * E number of bytes of info to reserve. 256 * D T/L byte of name. 257 * Exit: HL points to info T/L byte. 258 * AFBCDE preserved. 259 * 260 CAB8 F5 LOOKI PUSH PSW 261 CAB9 C5 PUSH B 262 CABA 48 MOV C,B Input pos. in C 263 CABB D5 PUSH D 264 CABC D5 PUSH D 265 CABD E5 PUSH H 266 CABE 7A MOV A,D T/L name in A 267 CABF E60F ANI :0F Name length only 268 CAC1 83 ADD E Add length info 269 CAC2 3C INR A 270 CAC3 3C INR A +2 (length new entry) 271 CAC4 CD30DE CALL :DE30 Calc new end symtab -1 272 CAC7 EB XCHG 273 CAC8 2AA502 LHLD :02A5 Get bottom screen RAM 274 CACB EB XCHG 275 CACC CD14DE CALL :DE14 Compare DE-HL 276 CACF 3E1B MVI A,:1B 277 CAD1 D2F5D9 JNC :D9F5 Run 'OUT OF MEMORY' if 278 not sufficient free RAM 279 CAD4 3600 MVI M,:00 New 'end table' flag 280 CAD6 23 INX H HL is new end symtab 281 CAD7 22A302 SHLD :02A3 Store end symtab 282 CADA E1 POP H Get old end symtab 283 CADB D1 POP D Get T/L info 284 CADC 72 MOV M,D Into symtab 285 CADD 23 INX H 286 CADE 7A MOV A,D 287 CADF E670 ANI :70 Get type only 288 CAE1 B3 ORA E Set low nibble for length 289 CAE2 5F MOV E,A 290 CAE3 7A MOV A,D Get length name 291 CAE4 E60F ANI :0F Max. 15 bytes 292 CAE6 57 MOV D,A Length in D for count 293 CAE7 CDE0DD LKI10 CALL :DDE0 Get char from line 294 CAEA 77 MOV M,A Char into symtab 295 CAEB 0C INR C Pnts to next char on line 296 CAEC 23 INX H Next pos in symtab 297 CAED 15 DCR D Decr length name 298 CAEE C2E7CA JNZ :CAE7 Next char if not ready 299 CAF1 73 MOV M,E Info T/L into symtab 300 CAF2 D1 POP D 301 CAF3 C1 POP B 302 CAF4 F1 POP PSW 303 CAF5 C9 RET 304 * 305 ********************************* 306 * FIND LINENUMBER IN TEXTBUFFER * 307 ********************************* 308 * 309 * Entry: HL: requested linenumber. 310 * Exit: ABCDE preserved. F corrupted. 311 * CY=1: Linenr found: PAGE 06 DAI FIRMWARE CA01-CBBE V1.1 312 * HL points to address textline. 313 * CY=0: Not found: 314 * Z=0: HL points to address textline 315 * with next higher linenumber. 316 * Z=1: End of textbuffer reached. 317 * 318 CAF6 C5 FINDL PUSH B 319 CAF7 F5 PUSH PSW 320 CAF8 D5 PUSH D 321 CAF9 0600 MVI B,:00 322 CAFB EB XCHG Req. linenr in DE 323 CAFC 2A9F02 LHLD :029F Get startaddr textbuf 324 CAFF 48 FDL05 MOV C,B Length prev. instr in C 325 CB00 0600 MVI B,:00 326 CB02 09 DAD B Add this length to beginaddr 327 CB03 46 FDL10 MOV B,M Get length current instr 328 CB04 78 MOV A,B in A 329 CB05 B7 ORA A 330 CB06 23 INX H Pnts to hibyte linenr 331 CB07 CA1DCB JZ :CB1D Abort if at end textbuf 332 CB0A 7A MOV A,D Get hibyte reqd linenr. 333 CB0B BE CMP M Test high order bits 334 CB0C DA1CCB JC :CB1C Abort if reqd nr lower than 335 current one (nr > reqd) 336 CB0F C2FFCA JNZ :CAFF Next textline (nr < reqd) 337 CB12 23 INX H Pnts to lobyte linenr 338 CB13 7B MOV A,E Get lobyte reqd linenr 339 CB14 BE CMP M 340 CB15 2B DCX H 341 CB16 DA1CCB JC :CB1C Abort if reqd nr lower than 342 current one (nr > reqd) 343 CB19 C2FFCA JNZ :CAFF Next textline if not found 344 (nr < reqd) 345 CB1C 3F FDL20 CMC Line found: CY=1 346 CB1D 2B FDL30 DCX H 347 CB1E D1 POP D 348 CB1F C1 POP B 349 CB20 78 MOV A,B 350 CB21 C1 POP B 351 CB22 C9 RET 352 * 353 ****************************** 354 * EMPTY SYMBOLTABLE AND HEAP * 355 ****************************** 356 * 357 * Zeroes all variables, all pointers in the symtab, 358 * kill all arrays, strings or stringarrays (zero the 359 * pointers) referenced by the symtab by setting the 360 * msb of the sizebit =1. Basic program is moved to a 361 * location corresponding to the Heapsize. 362 * 363 * Exit: All registers preserved. 364 * 365 CB23 F5 SCRATC PUSH PSW 366 CB24 C5 PUSH B 367 CB25 D5 PUSH D 368 CB26 E5 PUSH H 369 CB27 2AA102 LHLD :02A1 Get startaddr symtab 370 CB2A 7E SCT10 MOV A,M ) get name length 371 CB2B E60F ANI :0F ) 372 CB2D CA53CB JZ :CB53 Abort if at end symtab 373 CB30 CDB1CA CALL :CAB1 HL pnts to info length byte PAGE 07 DAI FIRMWARE CA01-CBBE V1.1 374 CB33 7E MOV A,M ) Get type 375 CB34 E6F0 ANI :F0 ) 376 CB36 FE40 CPI :40 377 CB38 D24DCB JNC :CB4D If array 378 CB3B 23 INX H 379 CB3C FE20 CPI :20 380 CB3E CA47CB JZ :CB47 If string 381 382 * If numeric variable: 383 384 CB41 CD9ECB CALL :CB9E Set value is 0 (4 bytes) 385 CB44 C32ACB JMP :CB2A Next entry 386 387 * If string variable: 388 389 CB47 CDA8CB SCT30 CALL :CBA8 Erase string reference in 390 symbtab and Heap 391 CB4A C32ACB JMP :CB2A Next entry 392 393 * If array: 394 395 CB4D CD5BCB SCT40 CALL :CB5B Erase array 396 CB50 C32ACB JMP :CB2A Next entry 397 398 * If ready: 399 400 CB53 CDCADE SCT90 CALL :DECA Organise HEAP + buffers 401 CB56 E1 LC188 POP H 402 CB57 D1 POP D 403 CB58 C1 POP B 404 CB59 F1 POP PSW 405 CB5A C9 RET 406 * 407 *************** 408 * ERASE ARRAY * 409 *************** 410 * 411 * The pointer is zeroed, the array size is erased 412 * (msb=1). For stringarrays: zeroes all pointers 413 * in the array and erase the string in the Heap. 414 * 415 * Entry: HL points to T/L byte of info after a 416 * symtab name of an array. 417 * Exit: HL points to next symtab entry. 418 * AFBCDE preserved. 419 * 420 CB5B D5 EARRAY PUSH D 421 CB5C C5 PUSH B 422 CB5D F5 PUSH PSW 423 CB5E 7E MOV A,M Get type info 424 CB5F E630 ANI :30 425 CB61 F5 PUSH PSW Save type only 426 CB62 CD51CE CALL :CE51 ) Get addr of array in 427 CB65 23 INX H ) Heap in DE, 428 CB66 56 MOV D,M ) Kill pointer in the 429 CB67 3600 MVI M,:00 ) symboltable 430 CB69 23 INX H Pnts after symtab entry 431 CB6A 7A MOV A,D 432 CB6B B3 ORA E 433 CB6C CA99CB JZ :CB99 Abort if entry was already 0 434 CB6F EB XCHG Arrayaddr in HL 435 CB70 2B DCX H PAGE 08 DAI FIRMWARE CA01-CBBE V1.1 436 CB71 2B DCX H Pnts to 1st byte Heap entry 437 CB72 46 MOV B,M Get 1st byte 438 CB73 CD36D2 CALL :D236 Clear heap entry by msb=1 439 CB76 F1 POP PSW Get type info 440 CB77 F5 PUSH PSW 441 CB78 FE20 CPI :20 String ? 442 CB7A D5 PUSH D Save stringpointer 443 CB7B C298CB JNZ :CB98 Abort if not string 444 445 * If string array: 446 447 CB7E 23 INX H 448 CB7F 4E MOV C,M Get length Heap entry 449 CB80 23 INX H 450 CB81 5E MOV E,M Get dimension 451 CB82 1C INR E 452 CB83 7B MOV A,E 453 CB84 CD30DE CALL :DE30 Calc beginaddr stringpntrs 454 CB87 79 MOV A,C 455 CB88 93 SUB E Calc length pntr area 456 CB89 4F MOV C,A in C 457 CB8A D28ECB JNC :CB8E 458 CB8D 05 DCR B 459 CB8E CDA8CB EAR10 CALL :CBA8 Erase stringreference in 460 symtab and Heap 461 CB91 0B DCX B 462 CB92 0B DCX B Update length pntr area 463 CB93 78 MOV A,B 464 CB94 B1 ORA C 465 CB95 C28ECB JNZ :CB8E Next string if not ready 466 467 * If ready: 468 469 CB98 E1 EAR20 POP H Get symtab pntr 470 CB99 F1 EAR30 POP PSW 471 CB9A F1 POP PSW 472 CB9B C1 POP B 473 CB9C D1 POP D 474 CB9D C9 RET 475 * 476 *********************************************** 477 * CLEAR A NUMERIC VARIABLE IN THE SYMBOLTABLE * 478 *********************************************** 479 * 480 * Loads '0' into 4 consecutive memory locations. 481 * 482 * Entry: Startaddress in HL. 483 * Exit: A=0, HL points to next byte. 484 * BCDEF preserved. 485 * 486 CB9E AF ZFPINT XRA A 487 CB9F 77 MOV M,A 488 CBA0 23 INX H 489 CBA1 77 MOV M,A 490 CBA2 23 INX H 491 CBA3 77 MOV M,A 492 CBA4 23 INX H 493 CBA5 77 MOV M,A 494 CBA6 23 INX H 495 CBA7 C9 RET 496 * 497 ******************************************** PAGE 09 DAI FIRMWARE CA01-CBBE V1.1 498 * ERASE STRINGREFERENCE IN HEAP AND SYMTAB * 499 ******************************************** 500 * 501 * The pointer in the symtab is set to '0', the 502 * msb of the sizebyte of the Heap entry is set 503 * to 1. 504 * 505 * Entry: HL points to stringpointer in symtab. 506 * Exit: HL points after this pointer. 507 * DE stringpointer. 508 * BC preserved, AF corrupted 509 * 510 CBA8 5E RSVHL MOV E,M ) Stringpointer 511 CBA9 3600 MVI M,:00 ) in DE and then 512 CBAB 23 INX H ) erased. 513 CBAC 56 MOV D,M ) 514 CBAD 3600 MVI M,:00 ) 515 CBAF 23 INX H 516 CBB0 E5 PUSH H 517 CBB1 2A9F02 LHLD :029F Get startaddr textbuf 518 CBB4 EB XCHG in DE; stringpntr in HL 519 CBB5 7C MOV A,H 520 CBB6 B5 ORA L Stringpntr is already 0 ? 521 CBB7 C414DE CNZ :DE14 If not: test if end of 522 heap reached 523 CBBA DC87D1 CC :D187 If not: clear heap entry 524 CBBD E1 POP H 525 CBBE C9 RET 526 * 527 * 528 * 532 CBBF END *************************** * S Y M B O L T A B L E * *************************** ASKRM CA01 ASR10 CA1B ASR20 CA1E ASR30 CA21 DADD CAAE DADR CAB1 EAR10 CB8E EAR20 CB98 EAR30 CB99 EARRAY CB5B EMSTP CA25 FDL05 CAFF FDL10 CB03 FDL20 CB1C FDL30 CB1D FINDL CAF6 FNAME CA95 FNM10 CA9B FNM20 CAAA LC188 CB56 LK10 CA5F LK15 CA69 LK20 CA6F LK30 CA78 LK40 CA8B LK50 CA8F LKC10 CA37 LKC20 CA3D LKC30 CA4E LKI10 CAE7 LOOK CA57 LOOKC CA34 LOOKI CAB8 LOOKX CA5A RSVHL CBA8 SCRATC CB23 SCT10 CB2A SCT30 CB47 SCT40 CB4D SCT90 CB53 SMKRM CA01 ZFPINT CB9E