*** empty log message ***
[h316.git] / lib / hachti / src / stack.asm
1 * H316 SAFE SOFTWARE STACK, REV. 0.1
2 *
3 *
4 * AUTHOR:
5 *
6 * PHILIPP HACHTMANN, 2007
7 *
8 * VERSIONS:
9 *
10 * 0.1 - INITIAL REVISION (22.12.2007)
11 *
12 * PURPOSE:
13 *
14 * TO PROVIDE A MULTI-PURPOSE STACK MECHANISM
15 * TO PROVIDE A SPECIAL-PURPOSE STACK MECHANISM FOR RECURSIVE
16 * PROGRAM CALLS
17 *
18 * WHAT:
19 *
20 * THIS VARIANT OF THE STACK ROUTINE USES A FIXED SIZE MEMORY
21 * BUFFER FOR THE THE STACK. THE STACK USAGE IS MONITORED.
22 * ON OVERFLOW, THE COMPUTER TYPES OUT AN ERROR MESSAGE AND HALTS.
23 *
24 *
25 * USAGE:
26 *
27 * INITIALISING STACK POINTER:
28 *
29 * CALL S$INIT
30 *
31 * PUSHING AND POPPING THE A-REGISTER FROM AND TO THE STACK:
32 *
33 * CALL S$PUSH VALUE IN A REGISTER IS PUSHED.
34 * CALL $$PUSH VALUE FROM STACK IS POPPED INTO A-REGISTER.
35 *
36 * PUSHING AND POPPING ARBITRARY DATA FROM AND TO THE STACK:
37 *
38 * CALL S$PUSM
39 * DAC ADDRESS
40 * OCT SIZE
41 *
42 * CALL S$POPM
43 * DAC ADDRESS
44 * OCT SIZE
45 *
46 *
47 ********************************************************************************
48 *
49 *
50 **** SYMBOL DECLARATIONS
51 *
52 SUBR STACK,SBUF JUST A LABEL FOR THE OBJECT TAPE
53 SUBR S$INIT,INIT INITITALISATION
54 SUBR S$PUSH,PUSH SINGLE WORD PUSH
55 SUBR S$POP,POP SINGLE WORD POP
56 SUBR S$PUSM,PUSM MEMORY RANGE PUSH
57 SUBR S$POPM,POPM MEMORY RANGE POP
58 SUBR S$PTR,SPTR STACK POINTER ACCESS
59 *
60 *
61 ********************************************************************************
62 *
63 *
64 SSIZ EQU '1000 512 WORDS DEFAULT STACK BUFFER SIZE
65 *
66 REL RELOCATEABLE OBJECT
67 ORG '0
68 *
69 *
70 ********************************************************************************
71 *
72 *
73 **** PUSH MEMORY RANGE TO STACK
74 *
75 PUSM DAC ** ENTRY POINT TO PUSH ROUTINE
76 STA ATM1 SAVE A-REGISTER
77 *
78 LDA* PUSM LOAD POINTER
79 STA PTR STORE TO TRANSFER POINTER
80 IRS PUSM GO TO NEXT ARGUMENT
81 LDA* PUSM LOAD TRANSFER SIZE
82 IRS PUSM CORRECT RETURN ADDRESS
83 *
84 TCA NEGATE WORD COUNT
85 STA CNT STORE TO COUNTER
86 *
87 PULP LDA* PTR GET DATA
88 JST PUSH PUSH IT!
89 IRS PTR INCREMENT POINTER
90 IRS CNT INCREMENT BYTE COUNTER
91 JMP PULP DO IT AGAIN!
92 *
93 LDA ATM1 RESTORE A-REG
94 JMP* PUSM
95 *
96 *
97 ********************************************************************************
98 *
99 *
100 **** POP MEMORY RANGE FROM STACK
101 *
102 POPM DAC ** ENTRY POINT TO PUSH ROUTINE
103 STA ATM1 SAVE A-REGISTER
104 *
105 LDA* POPM LOAD POINTER
106 IRS POPM GO TO NEXT ARGUMENT
107 ADD* POPM ADD TRANSFER SIZE
108 SUB =1 SUBSTRACT 1 TO GET HIGH ADDRESS
109 STA PTR STORE TO TRANSFER POINTER
110 LDA* POPM LOAD TRANSFER SIZE
111 IRS POPM CORRECT RETURN ADDRESS
112 *
113 TCA NEGATE WORD COUNT
114 STA CNT STORE TO COUNTER
115 *
116 POLP JST POP POP DATA FROM THE STACK
117 STA* PTR STORE IT.
118 LDA PTR
119 SUB =1 DECREMENT
120 STA PTR WRITE BACK
121 IRS CNT INCREMENT BYTE COUNTER
122 JMP POLP DO IT AGAIN!
123 *
124 LDA ATM1
125 JMP* POPM
126 *
127 *
128 ********************************************************************************
129 *
130 *
131 **** PUSH SINGLE WORD ONTO STACK
132 *
133 PUSH DAC ** REAL PUSH ROUTINE - PUSH AC TO STACK.
134 *
135 STA ATM2 SAVE A REGISTER
136 *
137 LDA SPTR LOAD STACK POINTER
138 SUB MAX TEST IF STACK FULL
139 SNZ
140 JST OFLO OVERFLOW OH! OH! OH!
141 *
142 LDA ATM2
143 STA* SPTR NO OVERFLOW, PUT DATA ONTO STACK
144 IRS SPTR INCREMENT STACK POINTER
145 *
146 JMP* PUSH RETURN WITH A-REG UNALTERED.
147 *
148 *
149 ********************************************************************************
150 *
151 *
152 **** POP SINGLE WORD FROM STACK
153 *
154 POP DAC ** REAL POP ROUTINE - POP AC FROM STACK.
155 *
156 LDA SPTR LOAD STACK POINTER
157 SUB MIN TEST IF STACK EMPTY
158 SNZ
159 JST UFLO UNDERFLOW OH! OH! OH!
160 *
161 LDA SPTR LOAD STACK POINTER
162 SUB =1 DECREMENT IT TO LAST USED LOCATION
163 STA SPTR SAVE IT BACK
164 *
165 LDA* SPTR LOAD VALUE FROM THE STACK
166 JMP* POP RETURN.
167 *
168 *
169 ********************************************************************************
170 *
171 *
172 **** INITIALIZATION
173 *
174 INIT DAC ** INITIALIZE STACK POINTER
175 LDA CPTR LOAD INITIAL STACK POINTER
176 STA SPTR SET STACK POINTER
177 JMP* INIT
178 *
179 *
180 ********************************************************************************
181 *
182 *
183 **** ERROR HANDLING ROUTINES
184 *
185 OFLO DAC ** STACK OVERFLOW ROUTINE
186 LDA OMSP LOAD OVERFLOW MESSAGE POINTER
187 JST TYPE TYPE IT OUT.
188 *
189 HLT WHAT WE DO: HALT THE MACHINE.
190 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
191 *
192 *
193 ****************************************
194 *
195 *
196 UFLO DAC ** STACK OVERFLOW ROUTINE
197 LDA UMSP LOAD OVERFLOW MESSAGE POINTER
198 JST TYPE TYPE IT OUT.
199 *
200 HLT WHAT WE DO: HALT THE MACHINE.
201 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
202 *
203 *
204 ****************************************
205 *
206 *
207 TYPE DAC **
208 SKS '104 TEST ASR READY
209 JMP *-1 WAIT TO BECOME READY
210 OCP '104 SET TO OUTPUT MODE
211 *
212 STA PTR STORE POINTER
213 *
214 TLOP LDA* PTR TYPE LOOP
215 SNZ TEST FOR END
216 JMP* TYPE RETURN
217 ICA
218 OTA '4
219 JMP *-1
220 ICA
221 OTA '4
222 JMP *-1
223 SKS '104 ADDITIONAL TEST FOR READY
224 JMP *-1
225 IRS PTR NEXT WORD.
226 JMP TLOP
227 *
228 *
229 ********************************************************************************
230 *
231 *
232 ***** VARIABLES
233 *
234 SBUF BSS SSIZ THE STACK BUFFER
235 SPTR DAC SBUF THE STACK POINTER
236 *
237 PTR DEC 0 TRANSFER POINTER TO USER BUFFERS
238 CNT DEC 0 TRANSFER COUNTER
239 *
240 ATM1 DEC 0 A-REGISTER BACKUP
241 ATM2 DEC 0 A-REGISTER BACKUP
242 *
243 *
244 ***** CONSTANTS
245 *
246 CPTR DAC SBUF STACK POINTER CONSTANT
247 MAX DAC SBUF+SSIZ FIRST ILLEGAL SPTR LOC BEFORE PUSH
248 MIN DAC SBUF FIRST ILLEGAL SPTR LOC BEFORE POP
249 *
250 OMSP DAC OMSG POINTER TO MESSAGE
251 UMSP DAC UMSG POINTER TO MESSAGE
252 OMSG OCT '006412 CR/LF CHARACTERS
253 BCI 16,STACK OVERFLOW, YOUR'RE SCREWED!
254 DEC 0 TERMINATION CHARACTER
255 UMSG OCT '006412 CR/LF CHARACTERS
256 BCI 17,STACK UNDERFLOW, YOUR'RE SCREWED!
257 DEC 0 TERMINATION CHARACTER
258 *
259 *
260 ********************************************************************************
261 *
262 *
263 END THAT'S IT.