Mercurial > hg > index.cgi
annotate src/progctrl.s @ 119:a6a53e5c04bd
Make a call stack implementation that is more complete and maybe cleaner.
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 29 Dec 2023 01:40:39 -0700 |
parents | e74d00ac6b79 |
children | 9d57279c900e |
rev | line source |
---|---|
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
1 *pragmapush list |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
2 *pragma list |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
4 ; The END command. |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
5 cmd_end bne SNERROR ; error out if there is an argument |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
6 ;jsr closeall ; close all files for END |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
7 clra ; flag END (clear carry) |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
8 bra cmd_stop0 ; go do the stop/end |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
9 cmd_stop bne SNERROR ; raise error if there was an argument |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
10 coma ; flag STOP - set carry |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
11 cmd_stop0 ror endflag ; set stop/end flag |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
12 cmd_stop1 clr filenum ; reset I/O to console |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ldx curline ; in immediate mode? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
14 beq cmd_stop2 ; brif so - don't save the continue pointers |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
15 stx contline ; save pointer to current line for CONT |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 ldx curstmt ; get current statement address |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 stx contstmt ; save it for CONT |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
18 cmd_stop2 rol endflag ; get STOP/END to C (1=STOP) |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
19 bcc cmd_stop3 ; brif END - don't do message |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
20 ldx #breakmsg ; do "BREAK IN" |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
21 jmp ERROR2 ; the bottom half of the error handler can deal with the details |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
22 cmd_stop3 puls x,pc ; lose return address and return to caller of interpretation loop |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
24 ; The NEW command. |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
25 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
26 ; This also includes several useful entry points: |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
27 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 ; cmd_newraw: does the whole NEW but without any syntax checks |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 ; cmd_newinptr: skips clearing the program text |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
30 ; cmd_newvars: clears variables and resets the stack and other misc state |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
31 ; cmd_newstack: just reset the stack and other misc state |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
32 cmd_new bne cmd_new0 ; brif there was an argument - don't wipe things out on syntax error |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
33 cmd_newraw ldx progtext ; point to start of program |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
34 clr -1,x ; make sure there's a NUL before the start of the program |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
35 clr ,x+ ; put a NULL pointer at the start of the program |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
36 clr ,x+ |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
37 stx vartab ; set start of variables after that |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
38 cmd_newinptr ldx progtext ;* set input pointer to the NUL before the program; this will cause the |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
39 leax -1,x ;* the interpreter to drop to immediate mode no matter what it was |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 stx inputptr ;* executing before this call if called from the main loop |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
41 cmd_newvars ldx memsize ; get top of memory |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
42 stx stringtab ; clear out string space |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
43 ldx vartab ; get start of variables |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
44 stx objecttab ; set start of large objects (arrays) there too (clear vars) |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
45 stx freestart ; set start of free memory (end of large objects) (clear arrays) |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
46 cmd_newstack ldx #stringstackend ; reset string stack (string stack counts down) |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
47 stx stringstackptr |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
48 ldx ,s ; get return address |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 lds freetop ; reset stack to top of memory |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 clr ,-s ; put a flag to stop stack searches (NEXT, RETURN) |
119
a6a53e5c04bd
Make a call stack implementation that is more complete and maybe cleaner.
William Astle <lost@l-w.ca>
parents:
74
diff
changeset
|
51 sts cstackptr ; reset pointer for call stack |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
52 clr contstmt ; clear "CONT" destination |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
53 clr contstmt+1 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
54 jmp ,x ; return to caller |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 ; REM and ' commands; also ELSE comes here since it needs to skip the rest of the line in that case. |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
57 cmd_else |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
58 cmd_apos |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
59 cmd_rem clra ; clear carry |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
60 ldx curline ; get start of current line |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
61 beq cmd_stop3 ; brif immediate mode - fall back to caller |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
62 ldx ,x ; get address of next line |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
63 leax -1,x ; move back one |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
64 stx inputptr ; put input pointer there |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
65 cmd_new0 rts |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
67 ; DATA command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
68 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
69 ; need to skip to the end of the current statement, which is either the end of the line OR a colon not included inside |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
70 ; a quoted string |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
71 cmd_data ldx inputptr ; get input pointer |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
72 cmd_data0 lda ,x+ ; get character at pointer |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
73 beq cmd_data1 ; brif end of line |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
74 cmpa #': ; end of statement? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
75 bne cmd_data2 ; brif not |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
76 cmd_data1 leax -1,x ; move back to the NUL or colon |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
77 stx inputptr ; reset input pointer for interpreter |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
78 rts |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
79 cmd_data2 cmpa #'" ; start of constant string? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
80 bne cmd_data0 ; brif not - process more characters |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
81 cmd_data3 lda ,x+ ; get next string character |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
82 beq cmd_data1 ; brif end of line |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
83 cmpa #'" ; string delimiter? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
84 bne cmd_data3 ; brif not - keep going |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
85 bra cmd_data0 ; process stuff outside string |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
87 ; RUN command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
88 cmd_run ;jsr closeall ; close all files |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
89 jsr curchar ; what do we have as an argument? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
90 bcs cmd_goto ; brif a digit - it's a line number (RUN ###); do GOTO |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
91 lbne SNERROR ; brif anything else on the line - not legit command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
92 ldx progtext ; point to start of program |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
93 bra cmd_goto0 ; go transfer control to the start of the program |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
95 ; GOTO command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
96 cmd_goto jsr parse_lineno ; parse the line number |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
97 cmd_gosub0 jsr prog_findlinecl ; go look up line number |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
98 bcc cmd_goto0 ; brif line found |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
99 ULERROR ldb #err_ul ; raise undefined line error |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
100 jmp ERROR |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
101 cmd_goto0 stx curline ; make sure we aren't flagging immediate mode |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
102 leax -1,x ; move input pointer to NUL before destination line |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
103 stx inputptr ; put input pointer there |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
104 rts ; resume interpretation at the new location |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
106 ; GOSUB command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
107 cmd_gosub jsr parse_lineno ; parse the destination line so return location is after the line number |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
108 ldd #tok_gosub*256+4 ; stack frame details |
119
a6a53e5c04bd
Make a call stack implementation that is more complete and maybe cleaner.
William Astle <lost@l-w.ca>
parents:
74
diff
changeset
|
109 jsr cstack_alloc ; make a stack frame |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
110 ldx curline ; save current line pointer |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
111 stx ,u |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
112 ldx inputptr ; save current input pointer |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
113 stx 2,u |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
114 bra cmd_gosub0 ; go finish up as a GOTO |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
116 ; RETURN command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
117 ; POP command |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
118 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
119 ; RETURN will search the call stack for the first GOSUB frame and remove all other placeholders it finds. A frame type |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
120 ; of 0 will cause it to stop. |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
121 cmd_pop skip1lda ; set nonzero for POP |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
122 cmd_return clra ; set zero for RETURN |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
123 pshs a ; save operation type |
119
a6a53e5c04bd
Make a call stack implementation that is more complete and maybe cleaner.
William Astle <lost@l-w.ca>
parents:
74
diff
changeset
|
124 jsr cstack_first ; get first entry on call stack |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
125 bne cmd_return1 ; brif there's a frame - don't error |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
126 RG_ERROR ldb #err_rg ; raise RETURN without GOSUB |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
127 jmp ERROR |
119
a6a53e5c04bd
Make a call stack implementation that is more complete and maybe cleaner.
William Astle <lost@l-w.ca>
parents:
74
diff
changeset
|
128 cmd_return0 jsr cstack_next ; move to next entry |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
129 beq RG_ERROR ; brif end of stack - raise error |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
130 cmd_return1 cmpb #tok_gosub ; do we have a GOSUB frame? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
131 bne cmd_return0 ; brif not - try again |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
132 lda ,s+ ; is it "POP"? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
133 bne cmd_return2 ; brif so - don't change flow control but clear stack frame |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
134 ldx ,u ; get back saved line pointer |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
135 stx curline |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
136 ldx 2,u ; get back saved input pointer |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
137 stx inputptr |
119
a6a53e5c04bd
Make a call stack implementation that is more complete and maybe cleaner.
William Astle <lost@l-w.ca>
parents:
74
diff
changeset
|
138 cmd_return2 jsr cstack_popto ; clean up call stack |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
139 bra cmd_data ; move to end of statement (move past any "ON GOSUB" entries |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
140 *pragmapop list |