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