1145
|
1 **************************************************
|
|
2 * System Call: F$Find64
|
|
3 *
|
|
4 * Function: Find a 64 byte memory block
|
|
5 *
|
|
6 * Input: X = Address of page table
|
|
7 * A = Block number
|
|
8 *
|
|
9 * Output: Y = Address of block
|
|
10 *
|
|
11 * Error: CC = C bit set; B = error code
|
|
12 *
|
|
13 FFind64 ldx R$X,u Get block tbl ptr
|
|
14 lda R$A,u get path block #
|
|
15 * Find a empty path block
|
|
16 beq L0A70 None, return error
|
|
17 clrb calculate address
|
|
18 IFNE H6309
|
|
19 lsrd (Divide by 4)
|
|
20 lsrd
|
|
21 ELSE
|
|
22 lsra
|
|
23 rorb
|
|
24 lsra
|
|
25 rorb
|
|
26 ENDC
|
|
27 lda a,x is that block allocated?
|
|
28 tfr d,x Move addr to X
|
|
29 beq L0A70 no, return error
|
|
30 tst ,x this the page table?
|
|
31 bne L0A71 no, we can use this one
|
|
32 L0A70 coma set carry & return
|
|
33 rts
|
|
34 L0A71 stx R$Y,u save address of block
|
|
35 rts return
|
|
36
|
|
37
|
|
38 **************************************************
|
|
39 * System Call: F$All64
|
|
40 *
|
|
41 * Function: Allocate a 64 byte memory block
|
|
42 *
|
|
43 * Input: X = Address of page table (0 if page table hasn't been allocated)
|
|
44 *
|
|
45 * Output: A = Block number
|
|
46 * X = Address of page table
|
|
47 * Y = Address of block
|
|
48 *
|
|
49 * Error: CC = C bit set; B = error code
|
|
50 *
|
|
51 *
|
|
52 FAll64 ldx R$X,u get base address of page table
|
|
53 bne L0A7F it's been allocated, skip ahead
|
|
54 bsr L0A89 allocate the page
|
|
55 bcs L0A88 error allocating, return
|
|
56 stx ,x save base address in page table
|
|
57 stx R$X,u save base address to caller's X
|
|
58 L0A7F bsr L0A9F find a empty spot in path table
|
|
59 bcs L0A88 couldn't find one, return error
|
|
60 sta R$A,u save block #
|
|
61 sty R$Y,u save address of block
|
|
62 L0A88 rts return
|
|
63
|
|
64 * Allocate a new base page
|
|
65 * Exit: X=Ptr to newly allocated 256 byte page
|
|
66 L0A89 pshs u preserve register stack pointer
|
|
67 IFNE H6309
|
|
68 ldq #$01000100 get block size (1 for SRqMem & 1 for TFM)
|
|
69 ELSE
|
|
70 ldd #$0100
|
|
71 ENDC
|
|
72 os9 F$SRqMem request mem for it
|
|
73 leax ,u point to it
|
|
74 ldu ,s restore register stack pointer
|
|
75 stx ,s save pointer to new page on stack
|
|
76 bcs L0A9E error on allocate, return
|
|
77 * Clear freshly allocated page to 0's
|
|
78 IFNE H6309
|
|
79 leay TFMNull,pc point to NULL byte
|
|
80 tfm y,x+
|
|
81 ELSE
|
|
82 clrb
|
|
83 AllLoop clr ,x+
|
|
84 decb
|
|
85 bne AllLoop
|
|
86 ENDC
|
|
87 L0A9E puls x,pc
|
|
88
|
|
89 IFNE H6309
|
|
90 TFMNull fcb 0 used to clear memory
|
|
91 ENDC
|
|
92
|
|
93 * Search page table for a free 64 byte block
|
|
94 * Entry: X=Ptr to base page (the one with the 64 entry page index)
|
|
95 L0A9F pshs x,u preserve base page & register stack ptrs
|
|
96 clra Index entry #=0
|
|
97 * Main search loop
|
|
98 L0AA2 pshs a Save which index entry we are checking
|
|
99 clrb Set position within page we are checking to 0
|
|
100 lda a,x Is the current index entry used?
|
|
101 beq L0AB4 no, skip ahead
|
|
102 tfr d,y Yes, Move ptr to 256 byte block to Y
|
|
103 clra Clear offset for 64 byte blocks to 0
|
|
104 L0AAC tst d,y Is this 64 byte block allocated?
|
|
105 beq L0AB6 No, skip ahead
|
|
106 addb #$40 Yes, point to next 64 byte block in page
|
|
107 bcc L0AAC If not done checking entire page, keep going
|
|
108
|
|
109 * Index entry has a totally unused 256 byte page
|
|
110 L0AB4 orcc #Carry Set flag (didn't find one)
|
|
111 L0AB6 leay d,y
|
|
112 puls a Get which index entry we were checking
|
|
113 bcc L0AE1 If we found a blank entry, go allocate it
|
|
114 inca Didn't, move to next index entry
|
|
115 cmpa #64 Done entire index?
|
|
116 blo L0AA2 no, keep looking
|
|
117
|
|
118 clra Yes, clear out to first entry
|
|
119 L0AC2 tst a,x Is this one used?
|
|
120 beq L0AD0 No, skip ahead
|
|
121 inca Increment index entry #
|
|
122 cmpa #64 Done entire index?
|
|
123 blo L0AC2 No, continue looking
|
|
124
|
|
125 comb Done all of them, exit with Path table full error
|
|
126 ldb #E$PthFul
|
|
127 puls x,u,pc
|
|
128 * Found empty page
|
|
129 L0AD0 pshs x,a Preserve index ptr & index entry #
|
|
130 bsr L0A89 Allocate & clear out new 256 byte page
|
|
131 bcs L0AF0 If error,exit
|
|
132 leay ,x Point Y to start of new page
|
|
133 tfr x,d Also copy to D
|
|
134 tfr a,b Page # into B
|
|
135 puls x,a Get back index ptr & index entry #
|
|
136 stb a,x Save page # in proper index entry
|
|
137 clrb D=index entry #*256
|
|
138
|
|
139 * D = Block Address
|
|
140 L0AE1 equ *
|
|
141 IFNE H6309
|
|
142 lsld ???Calculate 256 byte page #?
|
|
143 lsld
|
1239
|
144 tfr y,u U=Ptr to start of new page
|
|
145 ldw #$3f Clear out the 64 byte block we are using
|
|
146 leax TFMNull,pc
|
|
147 tfm x,u+
|
1145
|
148 ELSE
|
|
149 aslb
|
|
150 rola
|
|
151 aslb
|
|
152 rola
|
|
153 ldb #$3f
|
1239
|
154 ClrIt clr b,y
|
1145
|
155 decb
|
|
156 bne ClrIt
|
|
157 ENDC
|
|
158 sta ,y Save 256 byte page # as 1st byte of block
|
|
159 puls x,u,pc
|
|
160
|
|
161 L0AF0 leas 3,s
|
|
162 puls x,u,pc
|
|
163
|
|
164
|
|
165 **************************************************
|
|
166 * System Call: F$Ret64
|
|
167 *
|
|
168 * Function: Deallocate a 64 byte memory block
|
|
169 *
|
|
170 * Input: X = Address of page table
|
|
171 * A = Block number
|
|
172 *
|
|
173 * Output: None
|
|
174 *
|
|
175 * Error: CC = C bit set; B = error code
|
|
176 *
|
|
177 FRet64 lda R$A,u
|
|
178 ldx R$X,u
|
|
179 pshs u,y,x,d
|
|
180 clrb
|
|
181 tsta
|
|
182 beq L0B22
|
|
183 IFNE H6309
|
|
184 lsrd (Divide by 4)
|
|
185 lsrd
|
|
186 ELSE
|
|
187 lsra
|
|
188 rorb
|
|
189 lsra
|
|
190 rorb
|
|
191 ENDC
|
|
192 pshs a
|
|
193 lda a,x
|
|
194 beq L0B20
|
|
195 tfr d,y
|
|
196 clr ,y
|
|
197 clrb
|
|
198 tfr d,u
|
|
199 clra
|
|
200 L0B10 tst d,u
|
|
201 bne L0B20
|
|
202 addb #$40
|
|
203 bne L0B10
|
|
204 inca
|
|
205 os9 F$SRtMem
|
|
206 lda ,s
|
|
207 clr a,x
|
|
208 L0B20 clr ,s+
|
|
209 L0B22 puls pc,u,y,x,d
|