Commit | Line | Data |
---|---|---|
1a56830d AT |
1 | #ifndef VVS_STDLIB_DEBUG |
2 | #define VVS_STDLIB_DEBUG | |
3 | ||
9f7f68e5 AT |
4 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
5 | @ Some of the subroutines in this file duplicate other stdlib subroutines. | |
6 | @ This is to avoid outside dependencies and allow debugging of stdlib code. | |
7 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
8 | ||
1a56830d | 9 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
bb21580a AT |
10 | @ Name: |
11 | @ dumpheap (111000) | |
1a56830d | 12 | @ Description: |
bb21580a | 13 | @ Dumps the heap from 'startaddr' to 'endaddr'. |
6cb31a3e AT |
14 | @ This subroutine stomps on heap[1] after printing the first heap location. |
15 | @ If you dump starting from heap[0], then heap[1] will print inaccurately. | |
16 | @ Starting the dump from any other location will work without error. | |
17 | @ TODO: Should I use heap[0] and DIE rather than RTS? | |
18 | @ At the moment, the ability to continue is too useful to me. | |
19 | @ If it's useful to me, it's probably useful to other people. | |
20 | @ For now, leave dumpheap as-is. | |
9f7f68e5 | 21 | @ Call Stack: |
1a56830d AT |
22 | @ endaddr |
23 | @ startaddr <-- TOS | |
24 | @ Return Stack: | |
25 | @ <empty> | |
26 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
27 | NSSVTTTSSSN | Mark: 111000 (dump heap) | |
28 | ||
29 | @ Prepare a numeric address and value on the stack | |
30 | SNS | DUP | |
31 | SNS | DUP | |
32 | TTT | LOAD | |
33 | SNT | SWAP | |
34 | ||
35 | @ Print output line for this memory location | |
9f7f68e5 | 36 | NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) |
1a56830d | 37 | SSSTSSTN | PUSH ASCII '\t' |
c6e2791f | 38 | SSSTTTSTSN | PUSH ASCII ':' |
1a56830d AT |
39 | TNSS | PUTC |
40 | TNSS | PUTC | |
9f7f68e5 AT |
41 | SNS | DUP |
42 | NSTTTTSTSN | JSR > 111010 (debug:printsign) | |
43 | NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) | |
1a56830d AT |
44 | SSSTSTSN | PUSH ASCII '\n' |
45 | TNSS | PUTC | |
46 | ||
47 | @ Figure out if the loop is complete. | |
bb21580a | 48 | SSSTN | PUSH 1 (ptr) |
1a56830d AT |
49 | SNT | SWAP |
50 | TTS | STORE | |
51 | SNS | DUP | |
bb21580a | 52 | SSSTN | PUSH 1 (ptr) |
1a56830d AT |
53 | TTT | LOAD |
54 | TSST | SUBTRACT | |
55 | NTSSSTTTSSSSSSSSSSSN | BRZ > 00111000 00000000 | |
bb21580a | 56 | SSSTN | PUSH 1 (ptr) |
1a56830d AT |
57 | TTT | LOAD |
58 | SSSTN | PUSH 1 | |
59 | TSSS | ADD | |
9f7f68e5 | 60 | NSNTTTSSSN | JMP > 111000 (dump heap) |
1a56830d AT |
61 | |
62 | @ Clean up and return | |
63 | NSSVSSTTTSSSSSSSSSSSN | Mark: 00111000 00000000 | |
64 | SNN | DROP | |
65 | NTN | RTS | |
66 | ||
ae1f85a1 AT |
67 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
68 | @ Name: | |
69 | @ dumpstack (111001) | |
70 | @ Description: | |
71 | @ Dumps 'count' entries from the stack. | |
72 | @ Call Stack: | |
73 | @ count <-- TOS | |
74 | @ Return Stack: | |
75 | @ <empty> | |
76 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
ae1f85a1 AT |
77 | NSSVTTTSSTN | Mark: 111001 (dump stack) |
78 | ||
9f7f68e5 AT |
79 | @ Orient the user |
80 | SSSSSSSSSN | PUSH ASCII '\0' | |
81 | SSSSSSTSTSN | PUSH ASCII '\n' | |
82 | SSSSTTTSTSN | PUSH ASCII ':' | |
83 | SSSTSTSSTTN | PUSH ASCII 'S' | |
84 | SSSTSSTTTTN | PUSH ASCII 'O' | |
85 | SSSTSTSTSSN | PUSH ASCII 'T' | |
86 | NSTTTTTSSN | JSR > 111100 (debug:printstring) | |
87 | ||
ae1f85a1 | 88 | @ Print output line for the current TOS. |
9f7f68e5 | 89 | NSSVSSTTTSSTSSSSSSSTN | Mark: 00111001 00000001 |
ae1f85a1 | 90 | SNS | DUP |
9f7f68e5 | 91 | NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) |
ae1f85a1 | 92 | SSSTSSTN | PUSH ASCII '\t' |
c6e2791f | 93 | SSSTTTSTSN | PUSH ASCII ':' |
ae1f85a1 AT |
94 | TNSS | PUTC |
95 | TNSS | PUTC | |
96 | SNT | SWAP | |
9f7f68e5 AT |
97 | SNS | DUP |
98 | NSTTTTSTSN | JSR > 111010 (debug:printsign) | |
99 | NSTTTTSTTN | JSR > 111011 (debug:printmagnitude) | |
ae1f85a1 AT |
100 | SSSTSTSN | PUSH ASCII '\n' |
101 | TNSS | PUTC | |
102 | ||
103 | @ Figure out if the loop is complete. | |
ae1f85a1 AT |
104 | SSSTN | PUSH 1 |
105 | TSST | SUBTRACT | |
63a60fe0 AT |
106 | SNS | DUP |
107 | NTSSSTTTSSTSSSSSSSSN | BRZ > 00111001 00000000 | |
9f7f68e5 | 108 | NSNSSTTTSSTSSSSSSSTN | JMP > 00111001 00000001 |
ae1f85a1 AT |
109 | |
110 | @ Clean up and return | |
111 | NSSVSSTTTSSTSSSSSSSSN | Mark: 00111001 00000000 | |
112 | SNN | DROP | |
113 | NTN | RTS | |
114 | ||
9f7f68e5 AT |
115 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
116 | @ Name: | |
117 | @ printsign (111010) | |
118 | @ Description: | |
119 | @ Prints the sign of 'number'. | |
120 | @ Call Stack: | |
121 | @ number <-- TOS | |
122 | @ Return Stack: | |
123 | @ <empty> | |
124 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
125 | NSSVTTTSTSN | Mark: 111010 (debug:printsign) | |
126 | NTTSSTTTSTSSSSSSSSTN | BMI > 00111010 00000001 | |
127 | SSSTSTSTTN | PUSH ASCII '+' | |
128 | NSNSSTTTSTSSSSSSSTSN | JMP > 00111010 00000010 | |
129 | NSSVSSTTTSTSSSSSSSSTN | Mark: 00111010 00000001 | |
130 | SSSTSTTSTN | PUSH ASCII '-' | |
131 | NSSVSSTTTSTSSSSSSSTSN | Mark: 00111010 00000010 | |
132 | TNSS | PUTC | |
133 | NTN | RTS | |
134 | ||
135 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
136 | @ Name: | |
137 | @ printmagnitude (111011) | |
138 | @ Description: | |
139 | @ Prints the magnitude of 'number'. | |
140 | @ Call Stack: | |
141 | @ number <-- TOS | |
142 | @ Return Stack: | |
143 | @ <empty> | |
144 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
145 | NSSVTTTSTTN | Mark: 111011 (debug:printmagnitude) | |
146 | ||
147 | @ Extract the magnitude of the number. | |
148 | SNS | DUP | |
149 | NTTSSTTTSTTSSSSSSSSN | BMI > 00111011 00000000 | |
150 | NSNSSTTTSTTSSSSSSSTN | JMP > 00111011 00000001 | |
151 | NSSVSSTTTSTTSSSSSSSSN | Mark: 00111011 00000000 | |
152 | SSTTN | PUSH -1 | |
153 | TSSN | MULTIPLY | |
154 | NSSVSSTTTSTTSSSSSSSTN | Mark: 00111011 00000001 | |
155 | ||
156 | @ Prepare for building a string on the stack. | |
157 | SSSSN | PUSH ASCII '\0' | |
158 | SNT | SWAP | |
159 | ||
160 | @ Pick off one digit on each pass through this loop. | |
161 | NSSVSSTTTSTTSSSSSSTSN | Mark: 00111011 00000010 | |
162 | SNS | DUP | |
163 | ||
164 | @ Mod-off a digit, convert to ASCII, store on stack as part of the string. | |
165 | SSSTSTSN | PUSH +10 | |
166 | TSTT | MODULO | |
167 | SSSTTSSSSN | PUSH ASCII '0' | |
168 | TSSS | ADD | |
169 | SNT | SWAP | |
170 | ||
171 | @ Divide down to next digit and keep looping if number != 0 yet. | |
172 | SSSTSTSN | PUSH +10 | |
173 | TSTS | DIVIDE | |
174 | SNS | DUP | |
175 | NTSSSTTTSTTSSSSSSTTN | BRZ > 00111011 00000011 | |
176 | NSNSSTTTSTTSSSSSSTSN | JMP > 00111011 00000010 | |
177 | ||
178 | @ Print the string we have built on the stack. | |
179 | NSSVSSTTTSTTSSSSSSTTN | Mark: 00111011 00000011 | |
180 | SNN | DROP | |
181 | NSTTTTTSSN | JSR > 111100 (debug:printstring) | |
182 | NTN | RTS | |
183 | ||
184 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
185 | @ Name: | |
186 | @ printstring (111100) | |
187 | @ Description: | |
188 | @ Prints a null-terminated string from the stack. | |
189 | @ Call Stack: | |
190 | @ null-terminator (ASCII '\0') | |
191 | @ char n | |
192 | @ ... | |
193 | @ char 2 | |
194 | @ char 1 <-- TOS | |
195 | @ Return Stack: | |
196 | @ <empty> | |
197 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
198 | NSSVTTTTSSN | Mark: 111100 (debug:printstring) | |
199 | SNS | DUP | |
200 | NTSSSTTTTSSSSSSSSSTN | BRZ > 00111100 00000001 | |
201 | TNSS | Print character | |
202 | NSNTTTTSSN | JMP > 111100 | |
203 | NSSVSSTTTTSSSSSSSSSTN | Mark: 00111100 00000001 | |
204 | SNN | DROP | |
205 | NTN | RTS | |
206 | ||
1a56830d | 207 | #endif |