
PAGE 01    DAI FIRMWARE DEB8-0E015  V1.1

002                         ORG   :DEB8
003                 *
004                 *
005                 *
006                 *  ===================================
007                 *** BASIC EXECUTION / RUN-TIME MODULE ***
008                 *  ===================================
009                 *
010                 * Generally, BC is used as entry pointer to the
011                 * textbuffer.
012                 *
013                 ********************
014                 * RUN basiccmd NEW *
015                 ********************
016                 *
017                 * Sets up heap, empty textbuffer and symboltable,
018                 * sets pointers of textbuffer and symboltable
019                 * correctly. Old buffer contents is not destroyed,
020                 * (except 4 locations), but not useable.
021                 * Valid as direct command only.
022                 *
023                 * Exit: A=1, CY=1.
024                 *
025 DEB8 2A9B02     RNEW    LHLD  :029B     Get startaddr heap
026 DEBB 229F02             SHLD  :029F     Set start textbuf=start heap
027 DEBE 3600               MVI   M,:00     Store 00 in 1st addr.
028 DEC0 23                 INX   H
029 DEC1 22A102             SHLD  :02A1     Set start symtab
030 DEC4 3600               MVI   M,:00     00 in 1st addr.
031 DEC6 23                 INX   H
032 DEC7 22A302             SHLD  :02A3     Set end symtab
033                             
034                 * Entry from scratch/edit:
035                             
036 DECA 2A9D02     HRINIT  LHLD  :029D     Get heap size
037 DECD EB                 XCHG            in DE
038 DECE CD95D1             CALL  :D195     Init heap to all available
039 DED1 3E01               MVI   A,:01     Code for 'buffer crunched'
040 DED3 37                 STC 
041 DED4 C9                 RET 
042                 *
043                 *********************
044                 * RUN basiccmd CONT *
045                 *********************
046                 *
047                 * Resets step flag, decr. CONFL (error if it was
048                 * 0), restores FRAME from stack, restores stack-
049                 * pointer and continues program execution.
050                 * Valid as direct command only.
051                 *
052 DED5 AF         RCONT   XRA   A
053 DED6 321601     RCN10   STA   :0116     Reset step flag
054 DED9 212601             LXI   H,:0126   Get pntr suspended program
055 DEDC 35                 DCR   M         Update it
056 DEDD 3E19               MVI   A,:19
057 DEDF FAF5D9             JM    :D9F5     Evt. run error 'CAN'T CONT'
058 DEE2 2A2701             LHLD  :0127     Get current base stack level
059 DEE5 EB                 XCHG            in DE
060 DEE6 211500             LXI   H,:0015   FRAME length
061 DEE9 19                 DAD   D         Top of FRAME in stack
062 DEEA E5                 PUSH  H         Save it
063 DEEB 010001             LXI   B,:0100   Addr SYSBOT

PAGE 02    DAI FIRMWARE DEB8-0E015  V1.1

064 DEEE CD4FDE             CALL  :DE4F     Load FRAME from stack
065 DEF1 E1                 POP   H         Get addr FRAME top in stack
066 DEF2 222701             SHLD  :0127     Update current base stack
067                                         level
068 DEF5 F9                 SPHL            Update stackpointer
069 DEF6 2A0201             LHLD  :0102     Get start current command
070 DEF9 44                 MOV   B,H
071 DEFA 4D                 MOV   C,L       Store it in BC
072 DEFB C37FC8             JMP   :C87F     Run BASIC line
073                 *
074                 *********************
075                 * RUN basiccmd STEP *
076                 *********************
077                 *
078 DEFE 3EFF       RSTEP   MVI   A,:FF     Init value STEP flag
079 DF00 C3D6DE             JMP   :DED6     Set STEP flag and continu
080                 *
081                 *********************
082                 * RUN basiccmd STOP *
083                 *********************
084                 *
085                 * Entry: No conditions.
086                 * Exit:  A=03, CY=1. HL points after string.
087                 *
088 DF03 CDE6D7     RSTOP   CALL  :D7E6     Print 'STOPPED'
089 DF06 C9DB               DBL   :DBC9
090 DF08 3E03               MVI   A,:03     Code for 'susp. execution'
091 DF0A 37                 STC 
092 DF0B C9                 RET 
093                 *
094                 ********************
095                 * RUN basiccmd END *
096                 ********************
097                 *
098                 * Entry: No conditions.
099                 * Exit:  A=01, CY=1. HL points after string.
100                 *
101 DF0C CDE6D7     REND    CALL  :D7E6     Print 'END PROGRAM'
102 DF0F CFDB               DBL   :DBCF
103 DF11 3E01               MVI   A,:01     Code for 'stop execution'
104 DF13 37                 STC 
105 DF14 C9                 RET 
106                 *
107                 *******************
108                 * RUN basiccmd IF *
109                 *******************
110                 *
111                 * Used for IF .. GOTO <linenr> and for
112                 * IF .. THEN <linenr>.
113                 *
114                 *RIFG
115 DF15 CD63E7     RIFTL   CALL  :E763     (0) Run logical expression
116 DF18 3C                 INR   A
117 DF19 CA63DF             JZ    :DF63     Run GOTO if condition true
118                             
119                 * If condition false:
120                             
121 DF1C 03                 INX   B
122 DF1D 03                 INX   B         Skip linenr
123 DF1E B7                 ORA   A         No special action
124 DF1F C9                 RET 
125                 *

PAGE 03    DAI FIRMWARE DEB8-0E015  V1.1

126                 ***************************************
127                 * RUN basiccmd IF .. THEN <statement> *
128                 ***************************************
129                 *
130 DF20 CD63E7     RIFTC   CALL  :E763     (0) Run logical expression
131 DF23 3C                 INR   A
132 DF24 C28FE1             JNZ   :E18F     (0) Ignore rest if false
133                             
134                 * If condition true:
135                             
136 DF27 03                 INX   B         Skip length line
137 DF28 B7                 ORA   A         No special action
138 DF29 C9                 RET             Execute rest of line
139                 *
140                 ******************
141                 * basiccmd GOSUB *
142                 ******************
143                 *
144                 * Saves current program state on the interpreter
145                 * stack and branches to a named line. The running
146                 * FOR loop (if any) is saved in order to avoid
147                 * problems if any unpaired NEXT is encountered.
148                 * The stackpointer at the subroutine-entry is held
149                 * to enable breaking out of a FOR-NEXT loop.
150                 *
151 DF2A CDEDE6     RGOSUB  CALL  :E6ED     (0) Get linenr and find it
152                             
153                 * Entry from ON - GOSUB:
154                             
155 DF2D D1         RGS10   POP   D         Kill return addr
156 DF2E 221901             SHLD  :0119     Save new PC
157 DF31 CD3CE1             CALL  :E13C     (0) Save FOR loop contents
158 DF34 C5                 PUSH  B         Save program position
159 DF35 2A1901             LHLD  :0119     Get new PC
160 DF38 44                 MOV   B,H       ) Is new text position
161 DF39 4D                 MOV   C,L       )
162 DF3A 2A1301             LHLD  :0113     Get stack level last GOSUB
163 DF3D E5                 PUSH  H         Save evt link to previous
164                                         subroutine entry
165 DF3E 210000             LXI   H,:0000
166 DF41 220401             SHLD  :0104     No running loop
167 DF44 39                 DAD   SP        SP in HL
168 DF45 221301             SHLD  :0113     SP in STKGOS for return
169                             
170                 * Entry on return:
171                             
172 DF48 B7         RGS20   ORA   A         No special action
173 DF49 C38FC8             JMP   :C88F     Into Basic monitor
174                 *
175                 ***********************
176                 * RUN basiccmd RETURN *
177                 ***********************
178                 *
179                 * Reverses the effect of a previous 'GOSUB'.
180                 *
181 DF4C D1         RRET    POP   D         Kill returnaddr
182 DF4D 2A1301             LHLD  :0113     Get stack level last GOSUB
183 DF50 7C                 MOV   A,H
184 DF51 B5                 ORA   L         0 if no active call
185 DF52 3E01               MVI   A,:01
186 DF54 CAF5D9             JZ    :D9F5     Then run error 'RETURN
187                                         WITHOUT GOSUB'

PAGE 04    DAI FIRMWARE DEB8-0E015  V1.1

188 DF57 F9                 SPHL            Else: re-instate old stack
189 DF58 E1                 POP   H
190 DF59 221301             SHLD  :0113     Link back to previous
191                                         GOSUB
192 DF5C C1                 POP   B         Restore text pntr
193 DF5D CD67E1             CALL  :E167     (0) Pop FRAME
194 DF60 C348DF             JMP   :DF48     Back to Basic monitor
195                 *
196                 *********************
197                 * RUN basiccmd GOTO *
198                 *********************
199                 *
200                 * Simply transfers control to a named line.
201                 *
202                 * Entry from IF - GOTO:
203                 *
204 DF63 CDEDE6     RGOTO   CALL  :E6ED     (0) Get linenr and find it
205                             
206                 * Entry from ON - GOTO:
207                             
208 DF66 44         RGT10   MOV   B,H       ) Set textpointer to line
209 DF67 4D                 MOV   C,L       )
210 DF68 B7                 ORA   A         No special action
211 DF69 C9                 RET 
212                 *
213                 ***************************
214                 * RUN basiccmd ON .. GOTO *
215                 ***************************
216                 *
217 DF6A CD78DF     RONGT   CALL  :DF78     Process command
218 DF6D DA66DF             JC    :DF66     Use GOTO if OK
219 DF70 C9                 RET             If outside list
220                 *
221                 ****************************
222                 * RUN basiccmd ON .. GOSUB *
223                 ****************************
224                 *
225 DF71 CD78DF     RONGS   CALL  :DF78     Process command
226 DF74 DA2DDF             JC    :DF2D     Use GOSUB if OK
227 DF77 C9                 RET             If outside list
228                 *
229                 ***********************
230                 * COMMON 'ON ..' CODE *
231                 ***********************
232                 *
233                 * Exit: CY=1: OK.
234                 *       CY=0: Outside list.
235                 *
236 DF78 CD1DE7     RONFN   CALL  :E71D     ) (0) Get index of number
237 DF7B 5F                 MOV   E,A       ) in list in E
238 DF7C 0A                 LDAX  B         Get nr of linenrs in list
239 DF7D 03                 INX   B
240 DF7E 6F                 MOV   L,A
241 DF7F 2600               MVI   H,:00
242 DF81 29                 DAD   H
243 DF82 09                 DAD   B         Pointer after list
244 DF83 E5                 PUSH  H         Save pointer
245 DF84 1D                 DCR   E
246 DF85 1C                 INR   E
247 DF86 CA9BDF             JZ    :DF9B     Index of 0: outside list
248 DF89 BB                 CMP   E
249 DF8A DA9BDF             JC    :DF9B     If index too large

PAGE 05    DAI FIRMWARE DEB8-0E015  V1.1

250 DF8D 1600               MVI   D,:00
251 DF8F 1B                 DCX   D
252 DF90 EB                 XCHG
253 DF91 29                 DAD   H
254 DF92 09                 DAD   B         Pntr to reqd linenr
255 DF93 44                 MOV   B,H       ) in BC
256 DF94 4D                 MOV   C,L       )
257 DF95 CDEDE6             CALL  :E6ED     (0) Find reqd line
258 DF98 C1                 POP   B
259 DF99 37                 STC             CY=1: OK
260 DF9A C9                 RET 
261                             
262                 * If outside list:
263                             
264 DF9B C1         ROF10   POP   B
265 DF9C B7         ROF11   ORA   A         CY=0: outside list
266 DF9D C9                 RET 
267                 *
268                 ********************
269                 * RUN basiccmd RUN *
270                 ********************
271                 *
272                 * No linenumber is given.
273                 *
274                 *
275                 ***********
276                 * RUN RUN *
277                 ***********
278                 *
279                 * The sequence of the instructions is modified.
280                 * This enables RUN <linenr> to be used without
281                 * destroying the contents of heap and symtab.
282                 *
283 DF9E CD23CB     RRUN    CALL  :CB23     Empty heap and symtab
284 DFA1 2A9F02             LHLD  :029F     Get start textbuf
285 DFA4 44                 MOV   B,H       ) in BC
286 DFA5 4D                 MOV   C,L       )
287 DFA6 CD01E4             CALL  :E401     Run RESTORE
288 DFA9 210000             LXI   H,:0000
289 DFAC 221501             SHLD  :0115     Reset step/trace flag
290 DFAF AF                 XRA   A
291 DFB0 322601             STA   :0126     No suspended program
292 DFB3 3100F9             LXI   SP,:F900  Reset SP
293 DFB6 B7                 ORA   A         No special action
294 DFB7 C38FC8             JMP   :C88F     Run program
295                 *
296                 *****************************
297                 * RUN basiccmd RUN <linenr> *
298                 *****************************
299                 *
300                 * After RUN, a line number is given.
301                 *
302 DFBA CDEDE6     RRUNN   CALL  :E6ED     (0) Read linenr and find
303                                         it in textbuf
304                             
305                 * RUN <linenr> :
306                             
307 DFBD C3A4DF             JMP   :DFA4     ! Process RUN
308                 *
309                 *********************
310                 * RUN basiccmd POKE *
311                 *********************

PAGE 06    DAI FIRMWARE DEB8-0E015  V1.1

312                 *
313 DFC0 CDF8E6     RPOKE   CALL  :E6F8     (0) Get addr in HL
314                             
315                 * Entry for other modules:
316                             
317 DFC3 CD1DE7     RPEN    CALL  :E71D     (0) Get argument in A
318 DFC6 77                 MOV   M,A       Store it
319 DFC7 B7                 ORA   A         No special action
320 DFC8 C9                 RET 
321                 *
322                 ********************
323                 * RUN basiccmd OUT *
324                 ********************
325                 *
326 DFC9 CD1DE7     ROUT    CALL  :E71D     (0) Get portnr in A
327 DFCC 57                 MOV   D,A       and in D
328 DFCD CD1DE7             CALL  :E71D     (0) Get data in A
329 DFD0 5F                 MOV   E,A       and in E
330 DFD1 B7                 ORA   A
331 DFD2 C3C8D8             JMP   :D8C8     Output to DCE-bus
332                 *
333                 *********************
334                 * RUN basiccmd WAIT *
335                 *********************
336                 *
337                 * WAIT I,J,K reads the status of Real World port
338                 * I, EXOR's it with K and AND's it with J until
339                 * a result equal to J is obtained.
340                 *
341 DFD5 CD1DE7     RWAIT   CALL  :E71D     (0) Get portnr
342 DFD8 57                 MOV   D,A       in D
343 DFD9 CD1DE7             CALL  :E71D     (0) Get bits needed high
344 DFDC 67                 MOV   H,A       in H
345 DFDD 0A                 LDAX  B         Get next byte from text
346 DFDE 03                 INX   B
347 DFDF D6FF               SUI   :FF       Check if only 2 arguments
348 DFE1 00                 NOP 
349 DFE2 C4DACE             CNZ   :CEDA     If 3 arg: Get XOR mask
350 DFE5 6F                 MOV   L,A       in L
351 DFE6 CDE0D8     RWT20   CALL  :D8E0     Input from DCE-bus
352 DFE9 7B                 MOV   A,E       into A
353 DFEA AD                 XRA   L         XOR with mask
354 DFEB A4                 ANA   H         AND with bits needed high
355 DFEC BC                 CMP   H         Correct value reached?
356 DFED C8                 RZ              Then abort
357 DFEE CDA5D6             CALL  :D6A5     Check keyb for new inputs
358 DFF1 D2E6DF             JNC   :DFE6     Next DCE-input if no Break
359                             
360                 * If suspended:
361                             
362 DFF4 C312E0             JMP   :E012     (0) Quit: 'cmd broken in'
363                 *
364                 *************************
365                 * RUN basiccmd WAIT MEM *
366                 *************************
367                 *
368                 * As WAIT, but with I is a memory location.
369                 *
370 DFF7 CDF8E6     RWTEM   CALL  :E6F8     (0) Get memory addr in HL
371 DFFA CD1DE7             CALL  :E71D     (0) Get bit mask
372 DFFD 57                 MOV   D,A       in D
373 DFFE 0A                 LDAX  B         Get next byte from text

PAGE 07    DAI FIRMWARE DEB8-0E015  V1.1

374 DFFF 03                 INX   B
375 E000 D6FF               SUI   :FF       Check if only 2 arguments
376 E002 00                 NOP 
377 E003 C4DACE             CNZ   :CEDA     If 3 arg: Get XOR mask
378 E006 5F                 MOV   E,A       in E
379 E007 7B         RWM20   MOV   A,E       XOR mask in A
380 E008 AE                 XRA   M         XOR with memory
381 E009 A2                 ANA   D         AND with bit mask
382 E00A BA                 CMP   D         Correct value reached?
383 E00B C8                 RZ              Then abort
384 E00C CDA5D6             CALL  :D6A5     Check keyb for inputs
385 E00F D207E0             JNC   :E007     Cont if no Break pressed
386                             
387                 * If suspended:
388                             
389 E012 3E02       RWT30   MVI   A,:02     Code 'command broken in'
390 E014 37                 STC 
391 E015 C9                 RET 
392                 *
393                 *
394                 *
398 E016                    END 
 
***************************
* S Y M B O L   T A B L E *
***************************
 
HRINIT DECA   RCN10  DED6   RCONT  DED5   REND   DF0C   
RGOSUB DF2A   RGOTO  DF63   RGS10  DF2D   RGS20  DF48   
RGT10  DF66   RIFG   DF15   RIFTC  DF20   RIFTL  DF15   
RNEW   DEB8   ROF10  DF9B   ROF11  DF9C   RONFN  DF78   
RONGS  DF71   RONGT  DF6A   ROUT   DFC9   RPEN   DFC3   
RPOKE  DFC0   RRET   DF4C   RRUN   DF9E   RRUNN  DFBA   
RSTEP  DEFE   RSTOP  DF03   RWAIT  DFD5   RWM20  E007   
RWT20  DFE6   RWT30  E012   RWTEM  DFF7
