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