1 * H316 SAFE SOFTWARE STACK, REV. 0.1
5 * PHILIPP HACHTMANN, 2007
8 * TO PROVIDE A MULTI-PURPOSE STACK MECHANISM
9 * TO PROVIDE A SPECIAL-PURPOSE STACK MECHANISM FOR RECURSIVE
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.
20 * INITIALIZING STACK POINTER:
24 * PUSHING AND POPPING THE A-REGISTER FROM AND TO THE STACK:
26 * CALL S$PUSH VALUE IN A REGISTER IS PUSHED.
27 * CALL $$PUSH VALUE FROM STACK IS POPPED INTO A-REGISTER.
29 * PUSHING AND POPPING ARBITRARY DATA FROM AND TO THE STACK:
40 ********************************************************************************
43 **** SYMBOL DECLARATIONS
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
54 ********************************************************************************
57 SSIZ EQU '1000 512 WORDS DEFAULT STACK BUFFER SIZE
59 REL RELOCATEABLE OBJECT
63 ********************************************************************************
66 **** PUSH MEMORY RANGE TO STACK
68 PUSM DAC ** ENTRY POINT TO PUSH ROUTINE
69 STA ATM1 SAVE A-REGISTER
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
78 STA CNT STORE TO COUNTER
80 PULP LDA* PTR GET DATA
82 IRS PTR INCREMENT POINTER
83 IRS CNT INCREMENT BYTE COUNTER
86 LDA ATM1 RESTORE A-REG
90 ********************************************************************************
93 **** POP MEMORY RANGE FROM STACK
95 POPM DAC ** ENTRY POINT TO PUSH ROUTINE
96 STA ATM1 SAVE A-REGISTER
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
106 TCA NEGATE WORD COUNT
107 STA CNT STORE TO COUNTER
109 POLP JST POP POP DATA FROM THE STACK
114 IRS CNT INCREMENT BYTE COUNTER
115 JMP POLP DO IT AGAIN!
121 ********************************************************************************
124 **** PUSH SINGLE WORD ONTO STACK
126 PUSH DAC ** REAL PUSH ROUTINE - PUSH AC TO STACK.
128 STA ATM2 SAVE A REGISTER
130 LDA SPTR LOAD STACK POINTER
131 SUB MAX TEST IF STACK FULL
133 JST OFLO OVERFLOW OH! OH! OH!
136 STA* SPTR NO OVERFLOW, PUT DATA ONTO STACK
137 IRS SPTR INCREMENT STACK POINTER
139 JMP* PUSH RETURN WITH A-REG UNALTERED.
142 ********************************************************************************
145 **** POP SINGLE WORD FROM STACK
147 POP DAC ** REAL POP ROUTINE - POP AC FROM STACK.
149 LDA SPTR LOAD STACK POINTER
150 SUB MIN TEST IF STACK EMPTY
152 JST UFLO UNDERFLOW OH! OH! OH!
154 LDA SPTR LOAD STACK POINTER
155 SUB =1 DECREMENT IT TO LAST USED LOCATION
156 STA SPTR SAVE IT BACK
158 LDA* SPTR LOAD VALUE FROM THE STACK
162 ********************************************************************************
167 INIT DAC ** INITIALIZE STACK POINTER
168 LDA CPTR LOAD INITIAL STACK POINTER
169 STA SPTR SET STACK POINTER
173 ********************************************************************************
176 **** ERROR HANDLING ROUTINES
178 OFLO DAC ** STACK OVERFLOW ROUTINE
179 LDA OMSP LOAD OVERFLOW MESSAGE POINTER
180 JST TYPE TYPE IT OUT.
182 HLT WHAT WE DO: HALT THE MACHINE.
183 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
186 ****************************************
189 UFLO DAC ** STACK OVERFLOW ROUTINE
190 LDA UMSP LOAD OVERFLOW MESSAGE POINTER
191 JST TYPE TYPE IT OUT.
193 HLT WHAT WE DO: HALT THE MACHINE.
194 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
197 ****************************************
201 SKS '104 TEST ASR READY
202 JMP *-1 WAIT TO BECOME READY
203 OCP '104 SET TO OUTPUT MODE
205 STA PTR STORE POINTER
207 TLOP LDA* PTR TYPE LOOP
216 SKS '104 ADDITIONAL TEST FOR READY
222 ********************************************************************************
227 SBUF BSS SSIZ THE STACK BUFFER
228 SPTR DAC SBUF THE STACK POINTER
230 PTR DEC 0 TRANSFER POINTER TO USER BUFFERS
231 CNT DEC 0 TRANSFER COUNTER
233 ATM1 DEC 0 A-REGISTER BACKUP
234 ATM2 DEC 0 A-REGISTER BACKUP
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
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
253 ********************************************************************************