PAGE 01 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 002 ORG :C7FB 003 * 004 * 005 * 006 ********************************* 007 * CHECK FOR HIGHEST RAM ADDRESS * 008 ********************************* 009 * 010 * Entry: No conditions. 011 * Exit: HL points after RAM. 012 * BC preserved, ADEF corrupted. 013 * 014 C7FB 110010 MEMCHK LXI D,:1000 015 C7FE 210000 LXI H,:0000 Start at 0000 016 C801 19 MCK10 DAD D Incr. with #1000 017 C802 7E MOV A,M Get what is in memory 018 C803 2F CMA Take its complement 019 C804 77 MOV M,A and store it back 020 C805 BE CMP M Then compare 021 C806 2F CMA 022 C807 77 MOV M,A Restore original value 023 C808 CA01C8 JZ :C801 Next block if still RAM 024 C80B C9 RET 025 * 026 ********************** 027 * START FROM SCRATCH * 028 ********************** 029 * 030 * Entry to Basic monitor. 031 * 032 033 * If out of a Hard BREAK: 034 035 C80C 3100F9 RSTART LXI SP,:F900 Reset stackpointer 036 C80F CDE4CE CALL :CEE4 Select ROM bank 0, 037 C812 B8DB DBL :DBB8 print '*** BREAK' 038 039 * Re-enter Basic after run-time error, 040 * except on input: 041 042 C814 AF START XRA A 043 C815 323501 STA :0135 Input from keyb/DINC 044 045 * Entry on reset, after encoding program line, 046 * after END: 047 048 C818 2100F9 ST10 LXI H,:F900 049 C81B 222701 SHLD :0127 Reset current base stack 050 C81E F9 SPHL Reset stackpointer 051 C81F AF XRA A 052 C820 322601 STA :0126 No suspended program 053 054 * Restart interpreter; entry after end of program, 055 * after direct command, after soft BREAK, after 056 * direct command error, after STOP: 057 058 C823 2A2701 ST20 LHLD :0127 Get saved stackpointer 059 C826 F9 SPHL Set it to saved value 060 C827 210000 LXI H,:0000 061 C82A 220001 SHLD :0100 Reset current line nr. 062 C82D 220401 SHLD :0104 No running loops 063 C830 221301 SHLD :0113 No active subroutine call PAGE 02 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 064 C833 7C MOV A,H 065 C834 322201 STA :0122 No encoding of stored line 066 C837 00 NOP 067 C838 00 NOP 068 C839 00 NOP 069 C83A 211701 LXI H,:0117 070 C83D 77 MOV M,A No running of inputs 071 C83E 23 INX H 072 C83F 77 MOV M,A No running of program 073 C840 CD88D9 CALL :D988 Enable keyboard interrupt 074 C843 CDDBD9 CALL :D9DB Enable clock interrupt 075 C846 3A3501 ST23 LDA :0135 Get input direction 076 C849 FE02 CPI :02 077 C84B CC79D8 CZ :D879 EFSW=2: input from editbuf 078 C84E D267C8 JNC :C867 encode text line if edit 079 C851 3E2A MVI A,:2A buffer not empty 080 C853 CD1ADD CALL :DD1A Print '*', scan keyboard 081 and display characters 082 until Break or car.ret 083 (If no input is given, 084 the DAI remains here in a 085 endless loop). 086 C856 DA46C8 JC :C846 If BREAK: new inputs 087 C859 CDD2DD CALL :DDD2 Get char from line, neglect 088 TAB and space 089 C85C FE0D CPI :0D 090 C85E CA46C8 JZ :C846 If car.ret: new inputs 091 C861 CD0DDE CALL :DE0D Check if char is number 092 C864 D26DC8 JNC :C86D If no leading nr: encode cmd 093 094 * Encode program line (if 1st char is number): 095 096 C867 CD18C9 ST24 CALL :C918 Encode program line, update 097 program 098 C86A C318C8 JMP :C818 Get next input line; kill 099 any suspended program 100 101 * Encode direct command (if 1st char is no number): 102 103 C86D 1680 ST25 MVI D,:80 Mask for direct command 104 C86F E5 PUSH H Pointer to RUNF 105 C870 213F01 LXI H,:013F Addr EBUF 106 C873 E5 PUSH H Save it on stack 107 C874 CF RST 1 Encode immediate cmd line 108 C875 00 DATA :00 109 C876 3600 MVI M,:00 Dummy end of program 110 C878 CD5EDD CALL :DD5E Print car.ret 111 C87B C1 POP B Get EBUF pntr 112 C87C E1 POP H Pntr to RUNF 113 C87D 36FF MVI M,:FF Set flag running programs 114 115 * Run a Basic line: 116 117 C87F 0A ST30 LDAX B Get 1st byte from EBUF: 118 < #80: length, 119 >= #80: Token. 120 C880 03 ST35 INX B 121 C881 87 ADD A Calc offset from CF00 122 C882 D2E5C8 JNC :C8E5 Jump if length byte 123 C885 6F MOV L,A Get table address in HL 124 C886 26CF MVI H,:CF 125 C888 7E MOV A,M ) Get addr Basic routine PAGE 03 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 126 C889 23 INX H ) from table in HL 127 C88A 66 MOV H,M ) 128 C88B 6F MOV L,A ) 129 C88C CDA9C8 CALL :C8A9 Perform this routine 130 131 * Commands return here: 132 133 C88F DAAAC8 ENDCOM JC :C8AA Jump if special action 134 135 * If suspended: 136 137 C892 60 MOV H,B 138 C893 69 MOV L,C 139 C894 220201 SHLD :0102 Remember start next cmd 140 C897 3AC402 LDA :02C4 141 C89A B7 ORA A BREAK flag set? 142 C89B CA7FC8 JZ :C87F Run Basic line if not 143 C89E 00 NOP 144 C89F 00 NOP 145 C8A0 00 NOP 146 C8A1 3EFF MVI A,:FF 147 C8A3 32C402 STA :02C4 Set BREAK flag 'serviced' 148 C8A6 C3C0C8 JMP :C8C0 Handle break 149 150 * Run a BASIC line: 151 152 C8A9 E9 DCALL PCHL Addr Basic routine in PC 153 154 * If special end of action: 155 156 C8AA FE02 ST40 CPI :02 157 C8AC CAC0C8 JZ :C8C0 If soft break (2) 158 C8AF D2B8C8 JNC :C8B8 If STOP (3) 159 C8B2 EA18C8 JPE :C818 If can't continu (1) 160 C8B5 C308C9 JMP :C908 If after LOAD (0) 161 162 * If 'STOP': 163 164 C8B8 60 ST45 MOV H,B 165 C8B9 69 MOV L,C 166 C8BA 220201 SHLD :0102 Remember where next cmd 167 C8BD C3C5C8 JMP :C8C5 Print 'IN LINE ..' and 168 handle a break 169 170 * If suspended (soft Break handling): 171 172 C8C0 CDFFDA ST50 CALL :DAFF Print car.ret; 'BREAK'. 173 C8C3 C5DB DBL :DBC5 174 C8C5 CD75DA ST55 CALL :DA75 Print 'IN LINE .....' 175 or car.ret 176 C8C8 CA23C8 JZ :C823 Jump if immediate cmd 177 178 * Only if 'break' in program: 179 180 C8CB 21EBFF LXI H,:FFEB Frame length 181 C8CE 39 DAD SP New stack level 182 C8CF 44 MOV B,H 183 C8D0 4D MOV C,L 184 C8D1 222701 SHLD :0127 Set new base stack 185 C8D4 F9 SPHL Set stackpointer 186 C8D5 110001 LXI D,:0100 ) Boundaries frame 187 C8D8 211501 LXI H,:0115 ) PAGE 04 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 188 C8DB CD4FDE CALL :DE4F Save program status 189 (FRAME) on stack. 190 C8DE 212601 LXI H,:0126 191 C8E1 34 INR M Set flag existence saved 192 program 193 C8E2 C323C8 JMP :C823 Run again 194 195 * Length byte or end flag: 196 197 C8E5 CA23C8 ST60 JZ :C823 If end immediate cmd 198 line or end program 199 C8E8 60 MOV H,B 200 C8E9 69 MOV L,C 201 C8EA 220001 SHLD :0100 Store start current line 202 C8ED 2A1501 LHLD :0115 Get trace + step flag 203 C8F0 7C MOV A,H 204 C8F1 B5 ORA L 205 C8F2 CA00C9 JZ :C900 If no step/trace flag 206 207 * If step/trace flag set: 208 209 C8F5 E5 PUSH H 210 C8F6 C5 PUSH B 211 C8F7 CDA4CE CALL :CEA4 List current line 212 C8FA C1 POP B 213 C8FB F1 POP PSW Get step flag 214 C8FC B7 ORA A If set: 215 C8FD C4DAD6 CNZ :D6DA Wait for spacebar pressed 216 C900 03 ST65 INX B 217 C901 03 INX B Pnts after linenr 218 C902 DACBC8 JC :C8CB If Break 219 C905 C37FC8 JMP :C87F Run next BASIC line 220 221 * Special action after LOAD: 222 223 C908 2A0001 ST70 LHLD :0100 Get start current line 224 C90B 7C MOV A,H 225 C90C B5 ORA L Direct cmd? 226 C90D CA7FC8 JZ :C87F Then run Basic line 227 C910 3100F9 LXI SP,:F900 Else: reset stackpointer 228 C913 3E87 MVI A,:87 Simulate Token 'RUN' 229 C915 C380C8 JMP :C880 Pretend RUN cmd 230 * 231 * PROGRAM INPUT: 232 * 233 * Encodes a program line and updates the stored 234 * program. 235 * 236 * Entry: C: Input count / offset. 237 * Exit: C: Offset after line. 238 * AFBDEHL preserved. 239 * 240 C918 213F01 PROGI LXI H,:013F Addr buf for encoded cmds 241 C91B CF RST 1 Get linenr 242 C91C 03 DATA :03 243 C91D CDD2DD CALL :DDD2 Get char from line; 244 neglect TAB + space 245 C920 FE0D CPI :0D Car.ret ? 246 C922 CCA2C9 CZ :C9A2 Delete old version if 247 only linenr given 248 C925 CA3BC9 JZ :C93B Jump if linenr only 249 C928 D5 PUSH D Remember linenr PAGE 05 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 250 C929 1640 MVI D,:40 Mask for 'stored cmd' 251 C92B CD3CC9 CALL :C93C Encode a line 252 C92E 7D MOV A,L 253 C92F D63F SUI :3F Length string in A 254 C931 323E01 STA :013E Length in EBUF 255 C934 D1 POP D Get linenr 256 C935 CDA2C9 CALL :C9A2 Delete old line 257 C938 CDBDC9 CALL :C9BD Insert new line 258 C93B C9 PGI20 RET 259 * 260 * ENCODE A LINE: 261 * 262 * Exit: DE restored. 263 * HL points to 1st free byte in EBUF. 264 * C points after car.ret in input. 265 * A=0, F corrupted. 266 * 267 C93C D5 ELINA PUSH D 268 C93D C5 PUSH B 269 C93E E5 PUSH H 270 C93F 210000 LXI H,:0000 271 C942 39 DAD SP Stackpointer in HL 272 C943 221D01 SHLD :011D Save stackpointer 273 C946 E1 POP H 274 C947 E5 PUSH H 275 C948 3E01 MVI A,:01 276 C94A 322201 STA :0122 Set encoding a stored line 277 C94D CF RST 1 Encode inputs 278 C94E 00 DATA :00 279 C94F D1 POP D ) Cancel Push B,H 280 C950 D1 POP D ) 281 C951 AF ELA10 XRA A 282 C952 322201 STA :0122 No encoding stored line 283 C955 D1 POP D 284 C956 C9 RET 285 * 286 ************************************** 287 * ERROR WHILE ENCODING A STORED LINE * 288 ************************************** 289 * 290 * Restores stackpointer, adds '***' to begin of 291 * line, adds '?' to place of error. Line is entered 292 * into the encoded inputbuffer (EBUF). 293 * 294 * Entry: B: Errorcode. 295 * C: Place of error. 296 * On stack: BC points to input. 297 * HL points to EBUF. 298 * 299 C957 2A1D01 ELARS LHLD :011D Get ERSSP 300 C95A F9 SPHL Restore stackpointer 301 C95B E1 POP H Get buffer pointer 302 C95C 78 MOV A,B Errorcode in A 303 C95D 51 MOV D,C Place of error in D 304 C95E C1 POP B Get input pointer 305 C95F 47 MOV B,A 306 C960 36B1 MVI M,:B1 Token for '***' in EBUF 307 C962 23 INX H 308 C963 E5 PUSH H Save buf pointer 309 C964 23 INX H 310 C965 79 ELA20 MOV A,C ) Place of error 311 C966 BA CMP D ) reached ? PAGE 06 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 312 C967 3E3F MVI A,:3F 313 C969 CC95C9 CZ :C995 Then insert '?' 314 C96C CDE0DD CALL :DDE0 Get char. from line 315 C96F 0C INR C Update inputpointer 316 C970 FE0D CPI :0D Line done ? 317 C972 C495C9 CNZ :C995 Insert char in EBUF if not 318 C975 C265C9 JNZ :C965 Next char if not ready 319 C978 7D MOV A,L Lobyte EBUF pntr in A 320 C979 D1 POP D Addr after '***' 321 C97A 93 SUB E 322 C97B 3D DCR A 323 C97C 12 STAX D Store length in EBUF 324 C97D 3600 MVI M,:00 0 after string 325 C97F C5 PUSH B Save errormessage pntr 326 C980 42 MOV B,D ) EBUF pntr in BC 327 C981 4B MOV C,E ) 328 C982 0B DCX B 329 C983 0B DCX B 330 C984 0B DCX B 331 C985 0B DCX B Pnts to begin EBUF 332 C986 CD5EDD CALL :DD5E Print car.ret 333 C989 CDABEC CALL :ECAB (0) List current line 334 C98C C1 POP B Get errormessage pntr 335 C98D E5 PUSH H 336 C98E CD50DA CALL :DA50 Print errormessage 337 C991 E1 POP H 338 C992 C351C9 JMP :C951 Store 0 in ERSFL, Pop D, 339 and ret. 340 * 341 * INSERT CHARACTER IN ENCODED INPUT BUFFER: 342 * 343 * A character is inserted in the EBUF only if 344 * there is space available. 345 * 346 * Entry: HL: 1st free location in EBUF. 347 * A: Character to be inserted. 348 * Exit: HL updated. AFBCDE preserved. 349 * 350 C995 F5 ELAIN PUSH PSW 351 C996 7D MOV A,L Get lobyte of EBUF pntr 352 C997 FEBC CPI :BC Buffer full ? 353 C999 CAA0C9 JZ :C9A0 Then abort 354 C99C F1 POP PSW 355 C99D 77 MOV M,A Char into EBUF 356 C99E 23 INX H Update pntr 357 C99F C9 RET 358 359 * If EBUF full: 360 361 C9A0 F1 EAI10 POP PSW No action 362 C9A1 C9 RET 363 * 364 ******************************** 365 * DELETE OLD VERSION OF A LINE * 366 ******************************** 367 * 368 * A textline is deleted by moving the rest of the 369 * textbuffer and the symboltable 'downwards'. 370 * 371 * Entry: DE: requested linenumber. 372 * Exit: DE points to linenr after deleted line. 373 * AFBCHL preserved. PAGE 07 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 374 * 375 C9A2 F5 LDEL PUSH PSW 376 C9A3 C5 PUSH B 377 C9A4 E5 PUSH H 378 C9A5 EB XCHG Linenr in HL 379 C9A6 CDF6CA CALL :CAF6 Addr line in textbuf in HL 380 C9A9 D2B8C9 JNC :C9B8 Abort if not found 381 C9AC 7E MOV A,M Get line length 382 C9AD 2F CMA 383 C9AE 5F MOV E,A Compl. value in E 384 C9AF 16FF MVI D,:FF 385 C9B1 CD39DE CALL :DE39 HL=HL-line length 386 C9B4 EB XCHG 387 C9B5 CDD1C9 CALL :C9D1 Move program buffers 388 C9B8 EB LDL10 XCHG 389 C9B9 E1 POP H 390 C9BA C1 POP B 391 C9BB F1 POP PSW 392 C9BC C9 RET 393 * 394 ********************* 395 * INSERT A NEW LINE * 396 ********************* 397 * 398 * Inserts a encoded line in the textbuffer. 399 * Required space for the textline is made by 400 * shifting the rest of the textbuffer and the 401 * symboltable 'upwards'. 402 * 403 * Entry: DE: Destination address in textbuffer. 404 * HL: Points after string in EBUF. 405 * A: Length string in EBUF. 406 * 407 C9BD C5 LINS PUSH B 408 C9BE E5 PUSH H 409 C9BF 6F MOV L,A 410 C9C0 2600 MVI H,:00 String length in HL 411 C9C2 23 INX H Required space in HEAP 412 C9C3 D5 PUSH D 413 C9C4 CDD1C9 CALL :C9D1 Move program buffers 414 C9C7 C1 POP B 415 C9C8 E1 POP H 416 C9C9 113E01 LXI D,:013E Startaddr. EBUF 417 C9CC CD4FDE CALL :DE4F Transfer data from EBUF 418 into textbuffer 419 C9CF C1 POP B 420 C9D0 C9 RET 421 * 422 ************************ 423 * MOVE PROGRAM BUFFERS * 424 ************************ 425 * 426 * Moves a part (or the whole) textbuffer and the 427 * whole symboltable up or down. 428 * The startaddress of the textbuffer and the end 429 * of the symboltable are set depending on the 430 * heap size. The heap pointers are updated. 431 * 432 * Entry: DE: Address from where to update. 433 * HL: Length of area to be inserted/deleted. 434 * Entry if running 'NEW' only: 435 * BC: 0. PAGE 08 DAI FIRMWARE C7FB-CA00 V1.0 Rev.1 436 * DE: startaddress Heap. 437 * HL: Size Heap. 438 * At entry, the pointers for textbuf and 439 * symtab are as if HEAPsize is zero. 440 * Exit: AFBCDE preserved. 441 * HL: New startaddress. 442 * 443 C9D1 C5 PROGM PUSH B 444 C9D2 D5 PUSH D 445 C9D3 42 MOV B,D ) Addr from where to 446 C9D4 4B MOV C,E ) update in BC 447 C9D5 EB XCHG Length area in DE 448 C9D6 2AA302 LHLD :02A3 Get end symtab 449 C9D9 E5 PUSH H 450 C9DA D5 PUSH D 451 C9DB 19 DAD D New end symtab 452 C9DC EB XCHG 453 C9DD 2AA502 LHLD :02A5 Get bottom screen RAM 454 C9E0 CD14DE CALL :DE14 Check for overflow 455 C9E3 EB XCHG End symtab in HL 456 C9E4 DA10DA JC :DA10 Evt. run 'OUT OF MEMORY' 457 C9E7 22A302 SHLD :02A3 Store end symbol table 458 C9EA D1 POP D 459 C9EB D5 PUSH D 460 C9EC 2AA102 LHLD :02A1 Get begin symtab 461 C9EF 19 DAD D New begin symtab 462 C9F0 22A102 SHLD :02A1 Store begin symbol table 463 C9F3 E1 PRGM1 POP H 464 C9F4 50 MOV D,B 465 C9F5 59 MOV E,C Startaddr in DE 466 C9F6 19 DAD D New startaddr 467 C9F7 44 MOV B,H 468 C9F8 4D MOV C,L New startaddr in BC 469 C9F9 E3 XTHL Get old end symtab 470 C9FA CD4FDE CALL :DE4F Move textbuf + symtab 471 from old to new addr. 472 C9FD E1 POP H 473 C9FE D1 POP D 474 C9FF C1 POP B 475 CA00 C9 RET 476 * 477 * 478 * 479 CA01 END *************************** * S Y M B O L T A B L E * *************************** DCALL C8A9 EAI10 C9A0 ELA10 C951 ELA20 C965 ELAIN C995 ELARS C957 ELINA C93C ENDCOM C88F LDEL C9A2 LDL10 C9B8 LINS C9BD MCK10 C801 MEMCHK C7FB PGI20 C93B PRGM1 C9F3 PROGI C918 PROGM C9D1 RSTART C80C ST10 C818 ST20 C823 ST23 C846 ST24 C867 ST25 C86D ST30 C87F ST35 C880 ST40 C8AA ST45 C8B8 ST50 C8C0 ST55 C8C5 ST60 C8E5 ST65 C900 ST70 C908 START C814