/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/lib/header.s
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/lib/header.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 781 - (show annotations)
Sat Jan 21 22:33:21 2012 UTC (8 years ago) by dbug
File size: 5472 byte(s)
Updated the depot with the source code of the OSDK 0.019
1
2
3
4 #define _hires $ec33
5 #define _text $ec21
6 #define _ping $fa9f
7 #define _shoot $fab5
8 #define _zap $fae1
9 #define _explode $facb
10 #define _kbdclick1 $fb14
11 #define _kbdclick2 $fb2a
12
13 #define _cls $ccce
14 #define _lores0 $d9ed
15 #define _lores1 $d9ea
16
17
18
19 .zero
20
21 *= $50
22
23 ;
24 ; Most of the documentation/comments in this file are from 'Another Approach to Instruction Set Architecture—VAX'
25 ;
26 ap .dsb 2 ; Argument pointer - points to the base of the list of arguments or parameters in memory that are passed to the procedure
27 fp .dsb 2 ; Frame pointer - points to the base of the local variables of the procedure that are kept in memory (the stack frame)
28 sp .dsb 2 ; Stack pointer - points to the top of the stack
29
30 tmp0 .dsb 2
31 tmp1 .dsb 2
32 tmp2 .dsb 2
33 tmp3 .dsb 2
34 tmp4 .dsb 2
35 tmp5 .dsb 2
36 tmp6 .dsb 2
37 tmp7 .dsb 2
38
39 op1 .dsb 2
40 op2 .dsb 2
41
42 tmp .dsb 2
43
44 reg0 .dsb 2
45 reg1 .dsb 2
46 reg2 .dsb 2
47 reg3 .dsb 2
48 reg4 .dsb 2
49 reg5 .dsb 2
50 reg6 .dsb 2
51 reg7 .dsb 2
52
53
54 .text
55
56 osdk_start
57 ;jmp osdk_start ; Comment out to not autostart the system
58
59 ;#include "adress.tmp"
60 ;*=$800
61
62 ;
63 ; Needs to clear the BSS section
64 ;
65
66
67
68
69 tsx
70 lda #<osdk_stack
71 sta sp
72 lda #>osdk_stack
73 sta sp+1
74 ldy #0
75 stx retstack
76 jmp _main
77 retstack
78 .byt 0
79
80 /*
81 Preserving Registers Across Procedure Invocation of
82 swap
83 The VAX has a pair of instructions that preserve registers calls and ret. This
84 example shows how they work.
85 The VAX C compiler uses a form of callee convention. Examining the code
86 above, we see that the values in registers r0, r1, r2, and r3 must be saved so
87 that they can later be restored. The calls instruction expects a 16-bit mask at
88 the beginning of the procedure to determine which registers are saved: if bit i
89 is set in the mask, then register i is saved on the stack by the calls instruction.
90 In addition, calls saves this mask on the stack to allow the return instruction
91 (ret) to restore the proper registers. Thus the calls executed by the caller
92 does the saving, but the callee sets the call mask to indicate what should be
93 saved.
94 One of the operands for calls gives the number of parameters being
95 passed, so that calls can adjust the pointers associated with the stack: the argument
96 pointer (ap), frame pointer (fp), and stack pointer (sp). Of course,
97 calls also saves the program counter so that the procedure can return!
98 Thus, to preserve these four registers for swap, we just add the mask at the
99 beginning of the procedure, letting the calls instruction in the caller do all the
100 work:
101 .word ^m<r0,r1,r2,r3>; set bits in mask for 0,1,2,3
102 This directive tells the assembler to place a 16-bit constant with the proper bits
103 set to save registers r0 though r3.
104 */
105
106
107 ; Code is called this way:
108 ;
109 ; ldx #6 <- ?
110 ; lda #1 <- Sometimes "4" or "5" <- Number of registers to save?
111 ; jsr enter
112 ;
113 ; Y=The routine that calls a subfunction puts in Y the number of parameters*2 in Y. Example is CALLV_C(_drawbox,6)
114 ; X=
115 ; A=Number of registers to save (registers being adresses from 'reg0' to 'reg7'
116 enter
117 sty tmp ; Save the number of bytes reserved for parameters
118 stx tmp+1
119
120 ; Save the registers
121 asl ; Number of registers to save x2
122 sta op2 ; =number of bytes to save
123 tax
124 beq noregstosave
125 savereg
126 lda reg0-1,x
127 sta (sp),y
128 iny
129 dex
130 bne savereg
131
132 noregstosave
133 sty op2+1 ; New stack offset after the registers have been saved
134
135 ; Save the argument pointer
136 lda ap
137 sta (sp),y
138 iny
139 lda ap+1
140 sta (sp),y
141 iny
142
143 ; Save the frame pointer
144 lda fp
145 sta (sp),y
146 iny
147 lda fp+1
148 sta (sp),y
149 iny
150
151 ; Save the number of bytes saved for the registers
152 lda op2
153 sta (sp),y
154 iny
155 lda tmp ; Previously saved number of bytes for parameters
156 sta (sp),y
157
158 ; Update the argument pointer
159 ; AP=SP
160 ; FP=SP+stack offset
161 clc
162 lda sp
163 sta ap
164 adc op2+1
165 sta fp
166 lda sp+1
167 sta ap+1
168 adc #0
169 sta fp+1
170
171 ; SP=FP+X
172 lda tmp+1
173 adc fp
174 sta sp
175 lda fp+1
176 adc #0
177 sta sp+1
178 rts
179
180
181 /*
182 The return instruction undoes the work of calls. When finished, ret sets
183 the stack pointer from the current frame pointer to pop everything calls
184 placed on the stack. Along the way, it restores the register values saved by
185 calls, including those marked by the mask and old values of the fp, ap, and
186 pc.
187 To complete the procedure swap, we just add one instruction:
188 ret ; restore registers and return
189 */
190 leave
191 stx op2 ; Save X
192 sta op2+1 ; Save A
193
194 ; Restore sp from ap
195 lda ap
196 sta sp
197 lda ap+1
198 sta sp+1
199
200 ldy #4
201 lda (fp),y
202 tax
203 iny
204 lda (fp),y
205 tay
206 txa
207 beq noregstorestore
208
209 restorereg
210 lda (sp),y
211 sta reg0-1,x
212 iny
213 dex
214 bne restorereg
215
216 noregstorestore
217 ; Restore AP
218 ldy #0
219 lda (fp),y
220 sta ap
221 iny
222 lda (fp),y
223 sta ap+1
224
225 ; Restore FP
226 iny
227 lda (fp),y
228 sta tmp+0
229 tax
230 iny
231 lda (fp),y
232 sta fp+1
233 stx fp
234
235 ldx op2 ; Restore X
236 lda op2+1 ; Restore A
237 rts
238
239 jsrvect
240 jmp (0000)
241
242 _exit
243 ldx retstack
244 txs
245 rts
246
247 reterr
248 lda #$ff ; return -1
249 tax
250 rts
251
252 retzero
253 false
254 lda #0 ;return 0
255 tax
256 rts
257
258 true
259 ldx #1 ;return 1
260 lda #0
261 rts
262
263
264 #define load_acc1 $DE7B
265 #define load_acc2 $DD51
266 #define store_acc $DEAD
267 #define fadd $DB25
268 #define fsub $DB0E
269 #define fmul $DCF0
270 #define fdiv $DDE7
271 #define fneg $E271
272 #define fcomp $DF4C
273 #define cif $DF24
274
275 cfi
276 jsr $DF8C
277 ldx $D3
278 lda $D4
279 rts
280

  ViewVC Help
Powered by ViewVC 1.1.26