Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/clock.asm @ 2631:442795681807
o Fixed Atari SIO DWRead to timeout longer
o Commented out call to InitVIRQ in dw3.sb for Atari due to issues
o VTIO for Atari now properly handles IRQ shadow registers
o Level 1 clock now merged to include Atari
author | Boisy Pitre <boisy.pitre@nuance.com> |
---|---|
date | Sun, 26 Feb 2012 21:39:44 -0600 |
parents | b8c7b7fbf3c9 |
children | 2ebf5e737ceb |
rev | line source |
---|---|
0 | 1 ******************************************************************** |
1927 | 2 * Clock - NitrOS-9 System Clock |
1313 | 3 * |
0 | 4 * $Id$ |
5 * | |
1287 | 6 * Edt/Rev YYYY/MM/DD Modified by |
7 * Comment | |
0 | 8 * ------------------------------------------------------------------ |
1313 | 9 * ????/??/?? |
10 * NitrOS-9 2.00 distribution. | |
1287 | 11 * |
1313 | 12 * 9r4 2003/01/01 Boisy G. Pitre |
13 * Back-ported to OS-9 Level Two. | |
1287 | 14 * |
1313 | 15 * 9r5 2003/08/18 Boisy G. Pitre |
16 * Separated clock into Clock and Clock2 for modularity. | |
17 * | |
18 * 9r6 2003/09/04 Boisy G. Pitre | |
19 * Combined Level One and Level Two sources | |
1735 | 20 * |
1742 | 21 * 9r7 2004/11/27 Phill Harvey-Smith |
1735 | 22 * Fixed bug in init routine that was causing DP and CC to |
1742 | 23 * be pulled off the stack and stored in D.Proc under Level 1 |
1735 | 24 * |
1744 | 25 * 9r7 2005/01/17 Boisy G. Pitre |
26 * Fixed incorrect value for PIA initialization. Robert indicated | |
27 * that it should be $3434, not $3435. | |
28 * | |
1794 | 29 * 9r7 2005/04/08 Phill Harvey-Smith |
30 * Made the above level dependent as having PIAs inited with $3434 | |
31 * will disable the IRQ from them, this is ok for Level 2/CoCo 3 as the | |
32 * IRQ is later enabled from the GIME, however the CoCo 1,2 and Dragon | |
33 * do not posses a GIME so anything dependent on the clock tick will | |
34 * hang. So changed to conditionaly compile based on level :- | |
35 * | |
1945 | 36 * 9r8 2005/12/04 Boisy G. Pitre |
37 * Minor code optimizations, fixed issue in Level 1 where clock ran slow | |
38 * due to improper initialization of certain system globals. | |
39 | |
1927 | 40 nam Clock |
41 ttl NitrOS-9 System Clock | |
42 | |
43 ifp1 | |
44 use defsfile | |
45 endc | |
46 | |
47 tylg set Systm+Objct | |
48 atrv set ReEnt+rev | |
1945 | 49 rev set 8 |
1927 | 50 edition set 9 |
51 | |
52 | |
1313 | 53 *------------------------------------------------------------ |
54 * | |
55 * Start of module | |
56 * | |
1927 | 57 mod len,name,tylg,atrv,init,0 |
58 | |
59 name fcs "Clock" | |
60 fcb edition | |
61 | |
62 | |
63 TkPerTS equ TkPerSec/10 ticks per time slice | |
64 | |
1313 | 65 * |
1726
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
66 * Table to set up Service Calls |
1313 | 67 * |
1927 | 68 NewSvc fcb F$Time |
69 fdb FTime-*-2 | |
70 fcb F$VIRQ | |
71 fdb FVIRQ-*-2 | |
72 fcb F$STime | |
73 fdb FSTime-*-2 | |
74 fcb $80 end of service call installation table | |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
75 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
76 |
1313 | 77 *------------------------------------------------------------ |
78 * | |
79 * Handle F$STime system call | |
80 * | |
81 * First, copy time packet from user address space to system time | |
82 * variables, then fall through to code to update RTC. | |
83 * | |
1927 | 84 FSTime equ * |
85 ldx R$X,u | |
86 ldd ,x | |
87 std <D.Year | |
88 ldd 2,x | |
89 std <D.Day | |
90 ldd 4,x | |
91 std <D.Min | |
92 lda #TkPerSec reset to start of second | |
93 sta <D.Tick | |
94 ldx <D.Clock2 get entry point to Clock2 | |
1945 | 95 clra clear carry |
1927 | 96 jmp $06,x and call SetTime entry point |
97 | |
1313 | 98 *-------------------------------------------------- |
99 * | |
100 * Clock Initialization | |
101 * | |
102 * This vector is called by the kernel to service the first F$STime | |
1742 | 103 * call. F$STime is usually called by SysGo (with a dummy argument) |
1313 | 104 * in order to initialize the clock. F$STime is re-vectored to the |
105 * service code above to handle future F$STime calls. | |
106 * | |
107 * | |
1927 | 108 |
109 Clock2 fcs "Clock2" | |
110 | |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
111 init |
1927 | 112 pshs dp,cc save DP and CC |
113 clra | |
114 tfr a,dp set DP to zero | |
115 leax <Clock2,pcr | |
116 lda #Sbrtn+Objct | |
117 os9 F$Link | |
118 bcc LinkOk | |
119 jmp >$FFFE level 1: jump to reset vector | |
120 | |
121 LinkOk | |
122 puls cc,dp ; Restore saved dp and cc | |
123 sty <D.Clock2 save entry point | |
124 InitCont | |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
125 * Do not need to explicitly read RTC during initialization |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
126 ldd #59*256+$01 last second and last tick |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
127 std <D.Sec will prompt RTC read at next time slice |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
128 ldb #TkPerSec |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
129 stb <D.TSec set ticks per second |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
130 ldb #TkPerTS get ticks per time slice |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
131 stb <D.TSlice set ticks per time slice |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
132 stb <D.Slice set first time slice |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
133 IFNE atari |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
134 * Atari gets its clock source from the NMI |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
135 leax SvcIRQ,pcr set NMI handler |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
136 stx <D.NMI |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
137 ELSE |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
138 leax SvcIRQ,pcr set IRQ handler |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
139 stx <D.IRQ |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
140 ENDC |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
141 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
142 leay NewSvc,pcr insert syscalls |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
143 os9 F$SSvc |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
144 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
145 * Call Clock2 init routine |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
146 ldy <D.Clock2 get entry point to Clock2 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
147 jsr ,y call init entry point of Clock2 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
148 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
149 * Initialize clock hardware |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
150 IFNE atari |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
151 * Atari - Tell ANTIC to assert NMI on Vertical Blank |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
152 lda #$40 |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
153 sta $D40E enable VBlank NMI |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
154 rts |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
155 ELSE |
1927 | 156 ldx #PIA0Base point to PIA0 |
157 clra no error for return... | |
158 pshs cc save IRQ enable status (and Carry clear) | |
159 orcc #IntMasks stop interrupts | |
160 | |
161 sta 1,x enable DDRA | |
162 sta ,x set port A all inputs | |
163 sta 3,x enable DDRB | |
164 coma | |
165 sta 2,x set port B all outputs | |
166 | |
1735 | 167 ; ldd #$343C [A]=PIA0 CRA contents, [B]=PIA0 CRB contents |
1927 | 168 |
169 ldd #$3435 IRQ needs to be left enabled for Level1, as no GIME generated IRQ | |
170 | |
171 sta 1,x CA2 (MUX0) out low, port A, disable HBORD high-to-low IRQs | |
172 stb 3,x CB2 (MUX1) out low, port B, disable VBORD low-to-high IRQs | |
173 | |
174 lda 2,x clear possible pending PIA0 VBORD IRQ | |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
175 puls cc,pc recover IRQ enable status and return |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
176 ENDC |
1927 | 177 |
1726
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
178 * |
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
179 * Clock IRQ Entry Point |
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
180 * |
1945 | 181 * For CoCo 1/2, called once every 16.667 milliseconds |
1927 | 182 SvcIRQ |
183 clra | |
184 tfr a,dp set direct page to zero | |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
185 IFNE atari |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
186 sta $D40F clear NMI interrupt |
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
187 ELSE |
1945 | 188 tst PIA0Base+3 get hw byte |
1927 | 189 bmi L0032 branch if sync flag on |
190 jmp [>D.SvcIRQ] else service other possible IRQ | |
1945 | 191 L0032 tst PIA0Base+2 clear interrupt |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
192 ENDC |
1927 | 193 dec <D.Tick decrement tick counter |
194 bne L007F go around if not zero | |
195 ldb <D.Sec get minutes/seconds | |
1726
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
196 * Seconds increment |
1927 | 197 incb increment seconds |
198 cmpb #60 full minute? | |
199 bcs L0079 nope... | |
1726
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
200 * |
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
201 * Call GetTime entry point in Clock2 |
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
202 * |
1927 | 203 ldx <D.Clock2 get entry point to Clock2 |
204 jsr $03,x call GetTime entry point | |
205 fcb $8C skip next 2 bytes | |
206 L0079 stb <D.Sec update sec | |
207 L007B lda <D.TSec get ticks per second value | |
208 sta <D.Tick and repopulate tick decrement counter | |
209 L007F clra clear A | |
210 pshs a and save it on the stack | |
211 ldy <D.CLTb get pointer to VIRQ Polling Entries | |
212 bra L009E go to the processing portion of the loop | |
213 L0087 ldd Vi.Cnt,x get count down counter | |
214 subd #$0001 subtract tick count | |
215 bne L009C branch if not at terminal count ($0000) | |
216 lda #$01 | |
217 sta ,s set flag on stack to 1 | |
218 lda Vi.Stat,x get status byte | |
219 beq DelEntry branch if zero (one shot, so delete) | |
220 L0096 ora #Vi.IFlag set interrupted flag | |
221 sta Vi.Stat,x save in packet | |
222 ldd Vi.Rst,x get reset count | |
223 L009C std Vi.Cnt,x save tick count back | |
224 L009E ldx ,y++ get two bytes at Y | |
225 bne L0087 if not zero, branch | |
226 lda ,s+ else get byte off stack | |
227 beq GoAltIRQ branch if zero | |
228 ldx <D.Proc else get pointer to current process descriptor | |
229 beq L00AE branch if none | |
2631
442795681807
o Fixed Atari SIO DWRead to timeout longer
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
230 tst P$State,x test process state |
1927 | 231 bpl UsrPoll branch if system state not set |
232 L00AE jsr [>D.Poll] poll ISRs | |
233 bcc L00AE keep polling until carry set | |
234 GoAltIRQ | |
235 jmp [>D.AltIRQ] jump into an alternate IRQ if available | |
236 DelEntry | |
237 bsr DelVIRQ delete the VIRQ entry | |
238 bra L0096 | |
239 | |
240 UsrPoll leay >up@,pcr point to routine to execute | |
241 jmp [>D.URtoSs] User to System | |
242 up@ jsr [>D.Poll] call polling routine | |
243 bcc up@ keep polling until carry set | |
244 ldx <D.Proc get current process descriptor | |
245 ldb P$State,x and its state | |
246 andb #^SysState turn off sysstate bit | |
247 stb P$State,x save new state | |
248 ldd <P$SWI2,x | |
249 std <D.SWI2 | |
250 ldd <D.UsrIRQ | |
251 std <D.SvcIRQ | |
252 bra GoAltIRQ | |
253 | |
254 DelVIRQ pshs y,x save off Y,X | |
255 dl@ ldx ,y++ get next entry | |
256 stx -$04,y move up | |
257 bne dl@ continue until all are moved | |
258 puls y,x restore | |
259 leay -2,y move back 2 from Y (points to last entry) | |
260 rts return | |
261 | |
1726
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
262 * Install or Remove VIRQ Entry |
1927 | 263 FVIRQ pshs cc |
264 orcc #IntMasks mask all interrupts | |
265 ldy <D.CLTb get pointer to VIRQ polling table | |
266 ldx <D.Init get pointer to init module | |
267 ldb PollCnt,x get poll count | |
268 ldx R$X,u get pointer to caller's X | |
269 beq L0118 branch if removing | |
270 tst ,y entry available? | |
271 beq L010C | |
272 subb #$02 | |
273 lslb | |
274 leay b,y | |
275 tst ,y | |
276 bne PTblFul polling table full | |
277 L0106 tst ,--y | |
278 beq L0106 | |
279 leay $02,y | |
280 L010C ldx R$Y,u | |
281 stx ,y | |
282 ldy R$D,u | |
283 sty ,x | |
284 bra L0124 | |
285 L0118 leax R$Y,u X = caller's Y | |
286 L011A tst ,y end of VIRQ table | |
287 beq L0124 branch if so | |
288 cmpx ,y++ else compare to current VIRQ entry and inc Y | |
289 bne L011A continue searching if not matched | |
290 bsr DelVIRQ else delete entry | |
291 L0124 puls cc | |
292 clrb | |
293 rts | |
294 PTblFul puls cc | |
295 comb | |
296 ldb #E$Poll | |
297 rts | |
298 | |
299 | |
300 | |
1726
043d330e2f0e
Recomposed source lines to share more common code between Level 1
boisy
parents:
1658
diff
changeset
|
301 * F$Time system call code |
1927 | 302 FTime ldx R$X,u |
303 ldd <D.Year | |
304 std ,x | |
305 ldd <D.Day | |
306 std 2,x | |
307 ldd <D.Min | |
308 std 4,x | |
309 clrb | |
310 rts | |
311 | |
312 emod | |
313 len equ * | |
314 end |