
PAGE 01    DAI FIRMWARE C7FB-CA00  V1.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                 *
061                 *
062                 *
063                 **********************

PAGE 02    DAI FIRMWARE C7FB-CA00  V1.1

064                 * START FROM SCRATCH *
065                 **********************
066                 *
067                 * Added is the reset of all keyboard pointers at
068                 * various moments:
069                 * - When restarting the Basic interpreter.
070                 * - After command execution. Then also the output
071                 *   direction is reset to screen (to avoid a not
072                 *   useable keyboard).
073                 * - Idem before executing 'break'.
074                 * Resetting the keyboard pointers clears the key
075                 * input buffer in order to avoid keybounce.
076                 *
077 C827 CD63D5             CALL  :D563     ] Keyb. pntrs to default
078 C82A 210000             LXI   H,:0000
079 C82D 220001             SHLD  :0100
080 C830 220401             SHLD  :0104
081 C833 221301             SHLD  :0113
082 C836 7C                 MOV   A,H
083 C837 322201             STA   :0122
084                 *
085 C83A 211701             LXI   H,:0117
086 C83D 77                 MOV   M,A       No running of inputs
087 C83E 23                 INX   H
088 C83F 77                 MOV   M,A       No running of program
089 C840 CD88D9             CALL  :D988     Enable keyboard interrupt
090 C843 CDDBD9             CALL  :D9DB     Enable clock interrupt
091 C846 3A3501     ST23    LDA   :0135     Get input direction
092 C849 FE02               CPI   :02
093 C84B CC79D8             CZ    :D879     EFSW=2: input from editbuf
094 C84E D267C8             JNC   :C867     encode text line if edit
095 C851 3E2A               MVI   A,:2A     buffer not empty
096 C853 CD1ADD             CALL  :DD1A     Print '*', scan keyboard
097                                         and display characters
098                                         until Break or car.ret
099                                         (If no input is given,
100                                         the DAI remains here in a
101                                         endless loop).
102 C856 DA46C8             JC    :C846     If BREAK: new inputs
103 C859 CDD2DD             CALL  :DDD2     Get char from line, neglect
104                                         TAB and space
105 C85C FE0D               CPI   :0D
106 C85E CA46C8             JZ    :C846     If car.ret: new inputs
107 C861 CD0DDE             CALL  :DE0D     Check if char is number
108 C864 D26DC8             JNC   :C86D     If no leading nr: encode cmd
109                             
110                 * Encode program line (if 1st char is number):
111                             
112 C867 CD18C9     ST24    CALL  :C918     Encode program line, update
113                                         program
114 C86A C318C8             JMP   :C818     Get next input line; kill
115                                         any suspended program
116                             
117                 * Encode direct command (if 1st char is no number):
118                             
119 C86D 1680       ST25    MVI   D,:80     Mask for direct command
120 C86F E5                 PUSH  H         Pointer to RUNF
121 C870 213F01             LXI   H,:013F   Addr EBUF
122 C873 E5                 PUSH  H         Save it on stack
123 C874 CF                 RST   1         Encode immediate cmd line
124 C875 00                 DATA  :00
125 C876 3600               MVI   M,:00     Dummy end of program

PAGE 03    DAI FIRMWARE C7FB-CA00  V1.1

126 C878 CD5EDD             CALL  :DD5E     Print car.ret
127 C87B C1                 POP   B         Get EBUF pntr
128 C87C E1                 POP   H         Pntr to RUNF
129 C87D 36FF               MVI   M,:FF     Set flag running programs
130                             
131                 * Run a Basic line:
132                             
133 C87F 0A         ST30    LDAX  B         Get 1st byte from EBUF:
134                                         <  #80: length,
135                                         >= #80: Token.
136 C880 03         ST35    INX   B
137 C881 87                 ADD   A         Calc offset from CF00
138 C882 D2E5C8             JNC   :C8E5     Jump if length byte
139 C885 6F                 MOV   L,A       Get table address in HL
140 C886 26CF               MVI   H,:CF
141 C888 7E                 MOV   A,M       ) Get addr Basic routine
142 C889 23                 INX   H         ) from table in HL
143 C88A 66                 MOV   H,M       )
144 C88B 6F                 MOV   L,A       )
145 C88C CDA9C8             CALL  :C8A9     Perform this routine
146                             
147                 * Commands return here:
148                             
149 C88F DAAAC8     ENDCOM  JC    :C8AA     Jump if special action
150                             
151                 * If suspended:
152                             
153 C892 60                 MOV   H,B
154 C893 69                 MOV   L,C
155 C894 220201             SHLD  :0102     Remember start next cmd
156 C897 21C402             LXI   H,:02C4   ]
157 C89A 7E                 MOV   A,M       ] Get break flag
158 C89B B7                 ORA   A
159 C89C CA7FC8             JZ    :C87F
160 C89F CD63D5             CALL  :D563     ] Keyb.pntrs to default
161 C8A2 AF                 XRA   A         ]
162 C8A3 323101             STA   :0131     ] Output to screen
163 C8A6 C3C0C8             JMP   :C8C0     Handle break
164                             
165                 * Run a BASIC line:
166                             
167 C8A9 E9         DCALL   PCHL            Addr Basic routine in PC
168                             
169                 * If special end of action:
170                             
171 C8AA FE02       ST40    CPI   :02
172                 *
173 C8AC CA9FC8             JZ    :C89F     ] Keyb.pntrs to default,
174                                         output to screen
175 C8AF D2B8C8             JNC   :C8B8     If STOP (3)
176 C8B2 EA18C8             JPE   :C818     If can't continu (1)
177 C8B5 C308C9             JMP   :C908     If after LOAD (0)
178                             
179                 * If 'STOP':
180                             
181 C8B8 60         ST45    MOV   H,B
182 C8B9 69                 MOV   L,C
183 C8BA 220201             SHLD  :0102     Remember where next cmd
184 C8BD C3C5C8             JMP   :C8C5     Print 'IN LINE ..' and
185                                         handle a break
186                             
187                 * If suspended (soft Break handling):

PAGE 04    DAI FIRMWARE C7FB-CA00  V1.1

188                             
189 C8C0 CDFFDA     ST50    CALL  :DAFF     Print car.ret; 'BREAK'.
190 C8C3 C5DB               DBL   :DBC5
191 C8C5 CD75DA     ST55    CALL  :DA75     Print 'IN LINE .....'
192                                         or car.ret
193 C8C8 CA23C8             JZ    :C823     Jump if immediate cmd
194                             
195                 * Only if 'break' in program:
196                             
197 C8CB 21EBFF             LXI   H,:FFEB   Frame length
198 C8CE 39                 DAD   SP        New stack level
199 C8CF 44                 MOV   B,H
200 C8D0 4D                 MOV   C,L
201 C8D1 222701             SHLD  :0127     Set new base stack
202 C8D4 F9                 SPHL            Set stackpointer
203 C8D5 110001             LXI   D,:0100   ) Boundaries frame
204 C8D8 211501             LXI   H,:0115   )
205 C8DB CD4FDE             CALL  :DE4F     Save program status
206                                         (FRAME) on stack.
207 C8DE 212601             LXI   H,:0126
208 C8E1 34                 INR   M         Set flag existence saved
209                                         program
210 C8E2 C323C8             JMP   :C823     Run again
211                             
212                 * Length byte or end flag:
213                             
214 C8E5 CA23C8     ST60    JZ    :C823     If end immediate cmd
215                                         line or end program
216 C8E8 60                 MOV   H,B
217 C8E9 69                 MOV   L,C
218 C8EA 220001             SHLD  :0100     Store start current line
219 C8ED 2A1501             LHLD  :0115     Get trace + step flag
220 C8F0 7C                 MOV   A,H
221 C8F1 B5                 ORA   L
222 C8F2 CA00C9             JZ    :C900     If no step/trace flag
223                             
224                 * If step/trace flag set:
225                             
226 C8F5 E5                 PUSH  H
227 C8F6 C5                 PUSH  B
228 C8F7 CDA4CE             CALL  :CEA4     List current line
229 C8FA C1                 POP   B
230 C8FB F1                 POP   PSW       Get step flag
231 C8FC B7                 ORA   A         If set:
232 C8FD C4DAD6             CNZ   :D6DA     Wait for spacebar pressed
233 C900 03         ST65    INX   B
234 C901 03                 INX   B         Pnts after linenr
235 C902 DACBC8             JC    :C8CB     If Break
236 C905 C37FC8             JMP   :C87F     Run next BASIC line
237                             
238                 * Special action after LOAD:
239                             
240 C908 2A0001     ST70    LHLD  :0100     Get start current line
241 C90B 7C                 MOV   A,H
242 C90C B5                 ORA   L         Direct cmd?
243 C90D CA7FC8             JZ    :C87F     Then run Basic line
244 C910 3100F9             LXI   SP,:F900  Else: reset stackpointer
245 C913 3E87               MVI   A,:87     Simulate Token 'RUN'
246 C915 C380C8             JMP   :C880     Pretend RUN cmd
247                 *
248                 * PROGRAM INPUT:
249                 *

PAGE 05    DAI FIRMWARE C7FB-CA00  V1.1

250                 * Encodes a program line and updates the stored
251                 * program.
252                 *
253                 * Entry: C: Input count / offset.
254                 * Exit:  C: Offset after line.
255                 *        AFBDEHL preserved.
256                 *
257 C918 213F01     PROGI   LXI   H,:013F   Addr buf for encoded cmds
258 C91B CF                 RST   1         Get linenr
259 C91C 03                 DATA  :03
260 C91D CDD2DD             CALL  :DDD2     Get char from line;
261                                         neglect TAB + space
262 C920 FE0D               CPI   :0D       Car.ret ?
263 C922 CCA2C9             CZ    :C9A2     Delete old version if
264                                         only linenr given
265 C925 CA3BC9             JZ    :C93B     Jump if linenr only
266 C928 D5                 PUSH  D         Remember linenr
267 C929 1640               MVI   D,:40     Mask for 'stored cmd'
268 C92B CD3CC9             CALL  :C93C     Encode a line
269 C92E 7D                 MOV   A,L
270 C92F D63F               SUI   :3F       Length string in A
271 C931 323E01             STA   :013E     Length in EBUF
272 C934 D1                 POP   D         Get linenr
273 C935 CDA2C9             CALL  :C9A2     Delete old line
274 C938 CDBDC9             CALL  :C9BD     Insert new line
275 C93B C9         PGI20   RET 
276                 *
277                 * ENCODE A LINE:
278                 *
279                 * Exit: DE restored.
280                 *       HL points to 1st free byte in EBUF.
281                 *        C points after car.ret in input.
282                 *        A=0, F corrupted.
283                 *
284 C93C D5         ELINA   PUSH  D
285 C93D C5                 PUSH  B
286 C93E E5                 PUSH  H
287 C93F 210000             LXI   H,:0000
288 C942 39                 DAD   SP        Stackpointer in HL
289 C943 221D01             SHLD  :011D     Save stackpointer
290 C946 E1                 POP   H
291 C947 E5                 PUSH  H
292 C948 3E01               MVI   A,:01
293 C94A 322201             STA   :0122     Set encoding a stored line
294 C94D CF                 RST   1         Encode inputs
295 C94E 00                 DATA  :00
296 C94F D1                 POP   D         ) Cancel Push B,H
297 C950 D1                 POP   D         )
298 C951 AF         ELA10   XRA   A
299 C952 322201             STA   :0122     No encoding stored line
300 C955 D1                 POP   D
301 C956 C9                 RET 
302                 *
303                 **************************************
304                 * ERROR WHILE ENCODING A STORED LINE *
305                 **************************************
306                 *
307                 * Restores stackpointer, adds '***' to begin of
308                 * line, adds '?' to place of error. Line is entered
309                 * into the encoded inputbuffer (EBUF).
310                 *
311                 * Entry: B: Errorcode.

PAGE 06    DAI FIRMWARE C7FB-CA00  V1.1

312                 *        C: Place of error.
313                 *        On stack: BC points to input.
314                 *                  HL points to EBUF.
315                 *
316 C957 2A1D01     ELARS   LHLD  :011D     Get ERSSP
317 C95A F9                 SPHL            Restore stackpointer
318 C95B E1                 POP   H         Get buffer pointer
319 C95C 78                 MOV   A,B       Errorcode in A
320 C95D 51                 MOV   D,C       Place of error in D
321 C95E C1                 POP   B         Get input pointer
322 C95F 47                 MOV   B,A
323 C960 36B1               MVI   M,:B1     Token for '***' in EBUF
324 C962 23                 INX   H
325 C963 E5                 PUSH  H         Save buf pointer
326 C964 23                 INX   H
327 C965 79         ELA20   MOV   A,C       ) Place of error
328 C966 BA                 CMP   D         ) reached ?
329 C967 3E3F               MVI   A,:3F
330 C969 CC95C9             CZ    :C995     Then insert '?'
331 C96C CDE0DD             CALL  :DDE0     Get char. from line
332 C96F 0C                 INR   C         Update inputpointer
333 C970 FE0D               CPI   :0D       Line done ?
334 C972 C495C9             CNZ   :C995     Insert char in EBUF if not
335 C975 C265C9             JNZ   :C965     Next char if not ready
336 C978 7D                 MOV   A,L       Lobyte EBUF pntr in A
337 C979 D1                 POP   D         Addr after '***'
338 C97A 93                 SUB   E
339 C97B 3D                 DCR   A
340 C97C 12                 STAX  D         Store length in EBUF
341 C97D 3600               MVI   M,:00     0 after string
342 C97F C5                 PUSH  B         Save errormessage pntr
343 C980 42                 MOV   B,D       ) EBUF pntr in BC
344 C981 4B                 MOV   C,E       )
345 C982 0B                 DCX   B
346 C983 0B                 DCX   B
347 C984 0B                 DCX   B
348 C985 0B                 DCX   B         Pnts to begin EBUF
349 C986 CD5EDD             CALL  :DD5E     Print car.ret
350 C989 CDABEC             CALL  :ECAB     (0) List current line
351 C98C C1                 POP   B         Get errormessage pntr
352 C98D E5                 PUSH  H
353 C98E CD50DA             CALL  :DA50     Print errormessage
354 C991 E1                 POP   H
355 C992 C351C9             JMP   :C951     Store 0 in ERSFL, Pop D,
356                                         and ret.
357                 *
358                 * INSERT CHARACTER IN ENCODED INPUT BUFFER:
359                 *
360                 * A character is inserted in the EBUF only if
361                 * there is space available.
362                 *
363                 * Entry: HL: 1st free location in EBUF.
364                 *        A:  Character to be inserted.
365                 * Exit:  HL updated. AFBCDE preserved.
366                 *
367 C995 F5         ELAIN   PUSH  PSW
368 C996 7D                 MOV   A,L       Get lobyte of EBUF pntr
369 C997 FEBC               CPI   :BC       Buffer full ?
370 C999 CAA0C9             JZ    :C9A0     Then abort
371 C99C F1                 POP   PSW
372 C99D 77                 MOV   M,A       Char into EBUF
373 C99E 23                 INX   H         Update pntr

PAGE 07    DAI FIRMWARE C7FB-CA00  V1.1

374 C99F C9                 RET 
375                             
376                 * If EBUF full:
377                             
378 C9A0 F1         EAI10   POP   PSW       No action
379 C9A1 C9                 RET 
380                 *
381                 ********************************
382                 * DELETE OLD VERSION OF A LINE *
383                 ********************************
384                 *
385                 * A textline is deleted by moving the rest of the
386                 * textbuffer and the symboltable 'downwards'.
387                 *
388                 * Entry: DE: requested linenumber.
389                 * Exit:  DE points to linenr after deleted line.
390                 *        AFBCHL preserved.
391                 *
392 C9A2 F5         LDEL    PUSH  PSW
393 C9A3 C5                 PUSH  B
394 C9A4 E5                 PUSH  H
395 C9A5 EB                 XCHG            Linenr in HL
396 C9A6 CDF6CA             CALL  :CAF6     Addr line in textbuf in HL
397 C9A9 D2B8C9             JNC   :C9B8     Abort if not found
398 C9AC 7E                 MOV   A,M       Get line length
399 C9AD 2F                 CMA 
400 C9AE 5F                 MOV   E,A       Compl. value in E
401 C9AF 16FF               MVI   D,:FF
402 C9B1 CD39DE             CALL  :DE39     HL=HL-line length
403 C9B4 EB                 XCHG
404 C9B5 CDD1C9             CALL  :C9D1     Move program buffers
405 C9B8 EB         LDL10   XCHG
406 C9B9 E1                 POP   H
407 C9BA C1                 POP   B
408 C9BB F1                 POP   PSW
409 C9BC C9                 RET 
410                 *
411                 *********************
412                 * INSERT A NEW LINE *
413                 *********************
414                 *
415                 * Inserts a encoded line in the textbuffer.
416                 * Required space for the textline is made by
417                 * shifting the rest of the textbuffer and the
418                 * symboltable 'upwards'.
419                 *
420                 * Entry: DE: Destination address in textbuffer.
421                 *        HL: Points after string in EBUF.
422                 *        A:  Length string in EBUF.
423                 *
424 C9BD C5         LINS    PUSH  B
425 C9BE E5                 PUSH  H
426 C9BF 6F                 MOV   L,A
427 C9C0 2600               MVI   H,:00     String length in HL
428 C9C2 23                 INX   H         Required space in HEAP
429 C9C3 D5                 PUSH  D
430 C9C4 CDD1C9             CALL  :C9D1     Move program buffers
431 C9C7 C1                 POP   B
432 C9C8 E1                 POP   H
433 C9C9 113E01             LXI   D,:013E   Startaddr. EBUF
434 C9CC CD4FDE             CALL  :DE4F     Transfer data from EBUF
435                                         into textbuffer

PAGE 08    DAI FIRMWARE C7FB-CA00  V1.1

436 C9CF C1                 POP   B
437 C9D0 C9                 RET 
438                 *
439                 ************************
440                 * MOVE PROGRAM BUFFERS *
441                 ************************
442                 *
443                 * Moves a part (or the whole) textbuffer and the
444                 * whole symboltable up or down.
445                 * The startaddress of the textbuffer and the end
446                 * of the symboltable are set depending on the
447                 * heap size. The heap pointers are updated.
448                 *
449                 * Entry: DE: Address from where to update.
450                 *        HL: Length of area to be inserted/deleted.
451                 * Entry if running 'NEW' only:
452                 *        BC: 0.
453                 *        DE: startaddress Heap.
454                 *        HL: Size Heap.
455                 *        At entry, the pointers for textbuf and
456                 *        symtab are as if HEAPsize is zero.
457                 * Exit:  AFBCDE preserved.
458                 *        HL: New startaddress.
459                 *
460 C9D1 C5         PROGM   PUSH  B
461 C9D2 D5                 PUSH  D
462 C9D3 42                 MOV   B,D       ) Addr from where to
463 C9D4 4B                 MOV   C,E       ) update in BC
464 C9D5 EB                 XCHG            Length area in DE
465 C9D6 2AA302             LHLD  :02A3     Get end symtab
466 C9D9 E5                 PUSH  H
467 C9DA D5                 PUSH  D
468 C9DB 19                 DAD   D         New end symtab
469 C9DC EB                 XCHG
470 C9DD 2AA502             LHLD  :02A5     Get bottom screen RAM
471 C9E0 CD14DE             CALL  :DE14     Check for overflow
472 C9E3 EB                 XCHG            End symtab in HL
473 C9E4 DA10DA             JC    :DA10     Evt. run 'OUT OF MEMORY'
474 C9E7 22A302             SHLD  :02A3     Store end symbol table
475 C9EA D1                 POP   D
476 C9EB D5                 PUSH  D
477 C9EC 2AA102             LHLD  :02A1     Get begin symtab
478 C9EF 19                 DAD   D         New begin symtab
479 C9F0 22A102             SHLD  :02A1     Store begin symbol table
480 C9F3 E1         PRGM1   POP   H
481 C9F4 50                 MOV   D,B
482 C9F5 59                 MOV   E,C       Startaddr in DE
483 C9F6 19                 DAD   D         New startaddr
484 C9F7 44                 MOV   B,H
485 C9F8 4D                 MOV   C,L       New startaddr in BC
486 C9F9 E3                 XTHL            Get old end symtab
487 C9FA CD4FDE             CALL  :DE4F     Move textbuf + symtab
488                                         from old to new addr.
489 C9FD E1                 POP   H
490 C9FE D1                 POP   D
491 C9FF C1                 POP   B
492 CA00 C9                 RET 
493                 *
494                 *
495                 *
496 CA01                    END 
 

PAGE 09    DAI FIRMWARE C7FB-CA00  V1.1

***************************
* 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
