1 * H316 SAFE SOFTWARE STACK, REV. 0.1
6 * PHILIPP HACHTMANN, 2007
10 * 0.1 - INITIAL REVISION (22.12.2007)
14 * TO PROVIDE A MULTI-PURPOSE STACK MECHANISM
15 * TO PROVIDE A SPECIAL-PURPOSE STACK MECHANISM FOR RECURSIVE
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.
27 * INITIALISING STACK POINTER:
31 * PUSHING AND POPPING THE A-REGISTER FROM AND TO THE STACK:
33 * CALL S$PUSH VALUE IN A REGISTER IS PUSHED.
34 * CALL $$PUSH VALUE FROM STACK IS POPPED INTO A-REGISTER.
36 * PUSHING AND POPPING ARBITRARY DATA FROM AND TO THE STACK:
47 ********************************************************************************
50 **** SYMBOL DECLARATIONS
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
61 ********************************************************************************
64 SSIZ EQU '1000 512 WORDS DEFAULT STACK BUFFER SIZE
66 REL RELOCATEABLE OBJECT
70 ********************************************************************************
73 **** PUSH MEMORY RANGE TO STACK
75 PUSM DAC ** ENTRY POINT TO PUSH ROUTINE
76 STA ATM1 SAVE A-REGISTER
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
85 STA CNT STORE TO COUNTER
87 PULP LDA* PTR GET DATA
89 IRS PTR INCREMENT POINTER
90 IRS CNT INCREMENT BYTE COUNTER
93 LDA ATM1 RESTORE A-REG
97 ********************************************************************************
100 **** POP MEMORY RANGE FROM STACK
102 POPM DAC ** ENTRY POINT TO PUSH ROUTINE
103 STA ATM1 SAVE A-REGISTER
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
113 TCA NEGATE WORD COUNT
114 STA CNT STORE TO COUNTER
116 POLP JST POP POP DATA FROM THE STACK
121 IRS CNT INCREMENT BYTE COUNTER
122 JMP POLP DO IT AGAIN!
128 ********************************************************************************
131 **** PUSH SINGLE WORD ONTO STACK
133 PUSH DAC ** REAL PUSH ROUTINE - PUSH AC TO STACK.
135 STA ATM2 SAVE A REGISTER
137 LDA SPTR LOAD STACK POINTER
138 SUB MAX TEST IF STACK FULL
140 JST OFLO OVERFLOW OH! OH! OH!
143 STA* SPTR NO OVERFLOW, PUT DATA ONTO STACK
144 IRS SPTR INCREMENT STACK POINTER
146 JMP* PUSH RETURN WITH A-REG UNALTERED.
149 ********************************************************************************
152 **** POP SINGLE WORD FROM STACK
154 POP DAC ** REAL POP ROUTINE - POP AC FROM STACK.
156 LDA SPTR LOAD STACK POINTER
157 SUB MIN TEST IF STACK EMPTY
159 JST UFLO UNDERFLOW OH! OH! OH!
161 LDA SPTR LOAD STACK POINTER
162 SUB =1 DECREMENT IT TO LAST USED LOCATION
163 STA SPTR SAVE IT BACK
165 LDA* SPTR LOAD VALUE FROM THE STACK
169 ********************************************************************************
174 INIT DAC ** INITIALIZE STACK POINTER
175 LDA CPTR LOAD INITIAL STACK POINTER
176 STA SPTR SET STACK POINTER
180 ********************************************************************************
183 **** ERROR HANDLING ROUTINES
185 OFLO DAC ** STACK OVERFLOW ROUTINE
186 LDA OMSP LOAD OVERFLOW MESSAGE POINTER
187 JST TYPE TYPE IT OUT.
189 HLT WHAT WE DO: HALT THE MACHINE.
190 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
193 ****************************************
196 UFLO DAC ** STACK OVERFLOW ROUTINE
197 LDA UMSP LOAD OVERFLOW MESSAGE POINTER
198 JST TYPE TYPE IT OUT.
200 HLT WHAT WE DO: HALT THE MACHINE.
201 JMP *-1 YOU CANNOT SIMPLY LEAVE THIS, IT'S SERIOUS!
204 ****************************************
208 SKS '104 TEST ASR READY
209 JMP *-1 WAIT TO BECOME READY
210 OCP '104 SET TO OUTPUT MODE
212 STA PTR STORE POINTER
214 TLOP LDA* PTR TYPE LOOP
223 SKS '104 ADDITIONAL TEST FOR READY
229 ********************************************************************************
234 SBUF BSS SSIZ THE STACK BUFFER
235 SPTR DAC SBUF THE STACK POINTER
237 PTR DEC 0 TRANSFER POINTER TO USER BUFFERS
238 CNT DEC 0 TRANSFER COUNTER
240 ATM1 DEC 0 A-REGISTER BACKUP
241 ATM2 DEC 0 A-REGISTER BACKUP
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
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
260 ********************************************************************************