Mercurial > hg > Members > kono > nitros9-code
annotate level2/modules/rammer.asm @ 1631:ec6fb5543b22
Robert Gault's modifications for correcting timing errors
author | boisy |
---|---|
date | Mon, 12 Jul 2004 01:38:08 +0000 |
parents | 46c68f878889 |
children | f77ac3ae8a43 |
rev | line source |
---|---|
732 | 1 ******************************************************************** |
1424
32f1dae476b7
Fixed references in source from OS-9 to NitrOS-9 where appropriate
boisy
parents:
1348
diff
changeset
|
2 * Rammer - NitrOS-9 Level 2 RAM Disk |
732 | 3 * |
4 * $Id$ | |
5 * | |
6 * Alan DeKok's version of RAMMER - Based on original Keving Darling version | |
7 * | |
8 * NOTE: For some reason, when DEINIZing /r0, the INIT routine gets called... | |
9 * but it still deallocates memory! | |
1348 | 10 * |
11 * Edt/Rev YYYY/MM/DD Modified by | |
12 * Comment | |
13 * ------------------------------------------------------------------ | |
14 * 4 ????/??/?? ??? | |
15 * Original Kevin Darling Version. | |
16 * | |
17 * 5 2000/03/14 L. Curtis Boyle | |
18 * Several changes | |
19 * | |
20 * 5r2 2000/05/09 L. Curtis Boyle | |
21 * Allowed driver to go past 400K, attempted some fixes for handling /MD, | |
22 * so that setting vfy=0 on /R0 would not completely crash the system. | |
23 * Fixed some error reporting bugs that would crash the system, and | |
24 * moved entry table to between READ/WRITE to allow short branches to both. | |
25 | |
732 | 26 |
27 * Following CAN be set higher, but will take another page of system RAM then. | |
28 * 200 will allow maximum of 1,638,400 byte RAM drive. | |
29 MAXBLOCK set 201 Maximum # of MMU blocks allowed in RAM drive | |
30 | |
31 nam Rammer | |
1424
32f1dae476b7
Fixed references in source from OS-9 to NitrOS-9 where appropriate
boisy
parents:
1348
diff
changeset
|
32 ttl NitrOS-9 Level 2 RAM Disk |
732 | 33 |
34 ifp1 | |
35 use defsfile | |
36 endc | |
37 | |
38 tylg set Drivr+Objct | |
39 atrv set ReEnt+rev | |
40 rev set $02 | |
41 edition set 5 | |
42 | |
43 mod eom,name,tylg,atrv,start,size | |
44 | |
45 * Device mem stuff - can make MMUTable bigger, but will take 2 pages of system | |
46 * RAM then for device memory | |
47 u0000 rmb DRVBEG+DRVMEM Reserve room for 1 entry drive table | |
48 MDFlag rmb 1 0=R0 descriptor, <>0=MD descriptor | |
49 numofBlk rmb 1 # of MMU blocks allocated for RAM drive | |
50 MMUTable rmb MAXBLOCK Table of MMU Block #'s being used. | |
51 size equ . | |
52 | |
53 fcb DIR.+SHARE.+PREAD.+PWRIT.+PEXEC.+READ.+WRITE.+EXEC. | |
54 | |
55 name fcs /Rammer/ | |
56 fcb edition | |
57 | |
58 * Terminate routine - deallocates RAM | |
59 L0024 lda <numofBlk,u Get # blocks we had allocated | |
60 beq L003D If none, exit | |
61 leay <MMUTable,u Point to MMU block table | |
62 IFNE H6309 | |
63 clre Hi byte of block # to allocate (always 0) | |
64 L002E ldf ,y Get block # | |
65 ELSE | |
66 L002E ldb ,y | |
67 ENDC | |
68 clr ,y+ Zero it out in table | |
69 IFNE H6309 | |
70 tfr w,x Block # to deallocate | |
71 ELSE | |
72 pshs a | |
73 clra | |
74 tfr d,x | |
75 puls a | |
76 ENDC | |
77 ldb #$01 1 block to deallocate | |
78 os9 F$DelRAM Deallocate the block | |
79 deca Dec # of blocks to clean out | |
80 bne L002E Do until entire RAM drive is deallocated | |
81 L003D clrb Exit w/o error | |
82 rts | |
83 | |
84 * Deallocate RAM allocated so far, exit with no RAM error | |
85 L003F bsr L0024 Deallocate all RAM Drive ram blocks | |
86 L0041 comb Exit no RAM left error | |
87 ldb #E$MemFul | |
88 rts | |
89 | |
90 * Init routine - only gets called once per driver inited. | |
91 * Called if you INIZ the device as well | |
92 * Entry: Y=Address of device descriptor | |
93 * U=Device mem area | |
94 * NOTE: All of device mem (Except V.PORT) is cleared to 0's | |
95 Init lda #1 | |
96 sta V.NDRV,u only can handle 1 drive descriptor | |
97 leax DRVBEG,u Point to start of drive table | |
98 sta DD.TOT+2,x Set DD.TOT to non 0 value | |
99 lda <M$Opt,y Get # of bytes in device descriptor table | |
100 deca | |
101 * Following is if 1st access to RAMMER is on /MD | |
102 beq GetStat 0 (/MD desciptor), then exit w/o error | |
103 ldb <IT.CYL+1,y Get LSB of # of cylinders | |
104 lda <IT.SID,y Get # of heads | |
105 mul Calculate # head/cyls total | |
106 lda <IT.SCT+1,y Get # of sectors/track | |
107 mul Calculate # of sectors for RAM drive | |
108 subd <IT.SCT,y Subtract 1 tracks worth | |
109 addd <IT.T0S,y Add in the special track 0's # sectors/track | |
110 std DD.TOT+1,x Save as # sectors on drive | |
111 addd #$001F Round up to nearest 8K block | |
112 IFNE H6309 | |
113 rold Shift # of 8K blocks needed into A | |
114 rold | |
115 rold | |
116 ELSE | |
117 rolb | |
118 rola | |
119 rolb | |
120 rola | |
121 rolb | |
122 rola | |
123 ENDC | |
124 cmpa #MAXBLOCK If higher than max, exit with mem full error | |
125 bhi L0041 | |
126 leax <MMUTable,u Point to RAM block table | |
127 IFNE H6309 | |
128 tfr a,e # blocks left to allocate | |
129 ENDC | |
130 L0078 ldb #$01 Try to allocate 1 8K RAM block | |
131 IFEQ H6309 | |
132 pshs a | |
133 ENDC | |
134 os9 F$AllRAM | |
135 IFEQ H6309 | |
136 puls a | |
137 ENDC | |
138 bcs L003F If error, deallocate RAM, and exit | |
139 inc <numofBlk,u Bump up # of blocks allocated | |
140 stb ,x+ Save MMU block # allocated in table | |
141 IFNE H6309 | |
142 dece Do until done all blocks requested | |
143 ELSE | |
144 deca | |
145 ENDC | |
146 bne L0078 | |
147 clrb No error & return | |
148 rts | |
149 | |
150 * Entry: B:X=LSN to read (only X will be used, even with 2 MB) | |
151 * Y=Path dsc. ptr | |
152 * U=Device mem ptr | |
153 Read pshs y,x Preserve path & device mem ptrs | |
154 bsr L00C8 Calculate MMU block & offset for sector | |
155 bcs L00A5 Error, exit with it | |
156 bsr L00AE Transfer sector from RAM drive to PD.BUF | |
157 puls y,x Restore ptrs | |
158 leax ,x Sector 0? | |
159 bne GetStat No, exit without error | |
160 ldx PD.BUF,y Get buffer ptr | |
161 leay DRVBEG,u Point to start of drive table | |
162 IFNE H6309 | |
163 ldw #DD.SIZ Copy the info we need into drive table | |
164 tfm x+,y+ | |
165 ELSE | |
166 ldb #DD.SIZ Copy the info we need into drive table | |
167 ReadLp lda ,x+ | |
168 sta ,y+ | |
169 decb | |
170 bne ReadLp | |
171 ENDC | |
172 * GetStat/SetStat - no calls, just exit w/o error | |
173 GetStat clrb | |
174 L00A7 rts | |
175 | |
176 L00A5 puls y,x,pc | |
177 | |
178 start bra Init | |
179 nop | |
180 bra Read | |
181 nop | |
182 bra Write | |
183 nop | |
184 bra GetStat | |
185 nop | |
186 bra GetStat Actually SetStat (no calls, so same routine) | |
187 nop | |
188 lbra L0024 Terminate (returns memory) | |
189 | |
190 * Entry: B:X = LSN to write | |
191 * Y=Path dsc. ptr | |
192 * U=Device mem ptr | |
193 Write bsr L00C8 Calculate MMU Block & offset for sector | |
194 bcs L00A7 Error,exit with it | |
195 exg x,y X=Sector buffer ptr, Y=Offset within MMU block | |
196 * Transfer between RBF sector buffer & RAM drive image sector buffer | |
197 * Called by both READ and WRITE (with X,Y swapping between the two) | |
198 L00AE orcc #IntMasks Shut IRQ's off | |
199 pshs x Preserve X | |
200 ldx <D.SysDAT Get ptr to system DAT image | |
201 ldb 1,x Get original System MMU block #0 | |
202 puls x Get X back | |
203 sta >$FFA0 Map in RAM drive block into block #0 | |
204 IFNE H6309 | |
205 ldw #$0100 256 byte transfer | |
206 tfm x+,y+ Copy between the two buffers | |
207 ELSE | |
208 clrb | |
209 WriteLp lda ,x+ | |
210 sta ,y+ | |
211 decb | |
212 bne WriteLp | |
213 ENDC | |
214 stb >$FFA0 Remap in system block 0 | |
215 andcc #^(IntMasks+Carry) Turn IRQ's back on & no error | |
216 rts | |
217 | |
218 * Subroutine to calculate MMU block # and offset based on sector # requested | |
219 * Entry: Y=path dsc. ptr | |
220 * U=device mem ptr | |
221 * B:X=LSN to calculate for | |
222 * Exit: A=MMU block # we need to map in | |
223 * X=offset within MMU block to get sector from (always <8K) | |
224 * Y=Sector buffer ptr for RBF | |
225 * MDFlag,u=0 if NOT MD, else MD | |
226 L00C8 clr MDFlag,u Flag that we are on "real" RAM Drive | |
227 IFNE H6309 | |
228 ldw PD.DEV,y Get our Device table entry ptr | |
229 ldw V$DESC,w Get device descriptor ptr | |
230 lda M$Opt,w Get size of options table | |
231 ELSE | |
232 pshs x | |
233 ldx PD.DEV,y Get our Device table entry ptr | |
234 ldx V$DESC,x Get device descriptor ptr | |
235 lda M$Opt,x Get size of options table | |
236 puls x | |
237 ENDC | |
238 deca | |
239 bne L00DB Not MD, skip ahead | |
240 inc MDFlag,u Flag we are on MD | |
241 sta <PD.SIZ,y | |
242 sta <PD.SIZ+3,y | |
243 sta <PD.SSZ,y | |
244 ldd <D.BlkMap+2 Get end of block memory ptr | |
245 subd <D.BlkMap Calc # of blocks of RAM | |
246 lda #32 * 32 for # of 'sectors' | |
247 mul | |
248 std <PD.SIZ+1,y Save as middle word of file size | |
249 std <PD.SSZ+1,y Save as segment size | |
250 bra L00DE Skip ahead (sector # will allow all 2 MB) | |
251 | |
252 L00DB tstb Test MSB of sector # | |
253 bne L010F <>0, exit with Sector error | |
254 L00DE pshs x Preserve LSW of sector # | |
255 ldd ,s Load it again into D | |
256 tst MDFlag,u We on MD? | |
257 bne L00EE Yes, skip ahead | |
258 leax DRVBEG,u Point to drive table | |
259 cmpd DD.TOT+1,x LSW of sector compared to table's # of sectors | |
260 bhs L010E Sector # too large, exit with error | |
261 L00EE equ * | |
262 IFNE H6309 | |
263 rold A=MMU block offset in RAM drive image | |
264 rold | |
265 rold | |
266 ELSE | |
267 rolb | |
268 rola | |
269 rolb | |
270 rola | |
271 rolb | |
272 rola | |
273 ENDC | |
274 tst MDFlag,u We on /MD? | |
275 bne L0100 Yup, skip calculating MMU stuff | |
276 leax <MMUTable,u Point to MMU table | |
277 lda a,x Get MMU block # we want | |
278 beq L010E If 0, exit with sector error | |
279 L0100 pshs a Save block # | |
280 clrb Calculate offset within 8k block we want | |
281 lda 2,s | |
282 anda #$1F Mask out all but within 8K address offset | |
283 std 1,s Save offset | |
284 ldy PD.BUF,y Get sector buffer address | |
285 puls x,a,pc Get offset, MMU block & return | |
286 | |
287 L010E leas 2,s Eat X on stack | |
288 L010F comb Exit with bad sector # | |
289 ldb #E$Sect | |
290 rts | |
291 | |
292 emod | |
293 eom equ * | |
294 end |