Mercurial > hg > Members > kono > nitros9-code
comparison 3rdparty/utils/fpgarom/test.asm @ 3148:ffa4b0273cc7
3rdparty/utils/fpgarom: Utilities for CoCo3FPGA booting
Includes Brett Gordon's CocoFPGA Boot ROM.
author | Bill Pierce <merlinious999@gmail.com> |
---|---|
date | Sat, 04 Feb 2017 18:54:49 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3147:067978160b7e | 3148:ffa4b0273cc7 |
---|---|
1 ;;; | |
2 ;;; Boot OS9 via CoCoBoot interface | |
3 ;;; | |
4 ;;; | |
5 | |
6 CR equ 13 | |
7 SP equ 32 | |
8 | |
9 DBUF0 equ $600 ; we'll borrow some memory from basic | |
10 DBUF1 equ $700 ; another buffer | |
11 SCRPTR equ $0002 ; point to the os screen pointer | |
12 | |
13 DD.BIT equ $6 ; 2B no of sectors per cluster | |
14 DD.NAM equ $1f ; 32B volume name field | |
15 DD.DIR equ $8 ; 3B descriptor cluster for root dir | |
16 | |
17 FD.SIZ equ $9 ; 4B size of file in bytes | |
18 | |
19 | |
20 ;;; | |
21 ;;; | |
22 ;;; Low Ram Variables | |
23 ;;; | |
24 ;;; | |
25 org $2000 | |
26 RAM equ * | |
27 root rmb 3 ; 3b lsn of root dir | |
28 ;; FCB - vars needed to control file access. | |
29 sptr rmb 2 ; ptr to current segment | |
30 dptr rmb 2 ; ptr to data buffer | |
31 bcount rmb 2 ; number of bytes left in buffer | |
32 fcounth rmb 2 ; number of bytes left in file (high word) | |
33 fcount rmb 2 ; number of bytes left in file (low word) | |
34 ;; and a buffer for directory entries | |
35 dirbuf rmb 32 ; | |
36 ksize rmb 2 ; "stacked" size of os9 boot file | |
37 stack rmb 64 | |
38 stackb ; bottom of stack | |
39 | |
40 ;;; | |
41 ;;; | |
42 ;;; Code | |
43 ;;; | |
44 ;;; | |
45 | |
46 | |
47 org $c000 ; sit low | |
48 prestart | |
49 jmp start ; me first, but jump over DATA | |
50 | |
51 | |
52 BOOT fcn "OS9Boot" | |
53 KRN fcn "ccbkrn" | |
54 str0 fcn "Loading OS9Boot" | |
55 str1 fcn "Loading ccbkrn" | |
56 str2 fcn "Xfr Control to KRN..." | |
57 str3 fcn "CoCoBoot SDIO" | |
58 str4 fcn "Vol Name: " | |
59 | |
60 start | |
61 orcc #$50 ; shut off interrupts | |
62 lds #stackb ; set stack | |
63 ;; clear RAM vars | |
64 ldx #RAM | |
65 ldb #stack-RAM | |
66 jsr memz | |
67 ;; | |
68 ldx #$ff90 ; setup gimme | |
69 jsr gime ; | |
70 clr $ffa0 ; set mmu bank 0 to phys 0 | |
71 * clr $ffdf ; set SAM RAM mode | |
72 ;; setup screen | |
73 jsr scrSetup ; setup screen | |
74 ldx #str3 ; print banner | |
75 jsr putscr ; | |
76 x@ bra x@ | |
77 ;; init SD card | |
78 jsr ll_init | |
79 lbcs initerr | |
80 ;; get LSN0 | |
81 ldx #DBUF0 ; set disk arg | |
82 stx DPTR | |
83 clr LSN | |
84 clr LSN+1 | |
85 clr LSN+2 | |
86 ;; Test for CCPT here !!!! | |
87 jsr ccpttest | |
88 ;; try to mount os9 filesystem | |
89 jsr getlsn | |
90 ;; print volume name | |
91 ldx #str4 | |
92 jsr puts | |
93 ldx #DBUF0+DD.NAM | |
94 jsr putscr | |
95 ;; get root dir's lsn | |
96 ldx #DBUF0+DD.DIR | |
97 ldu #root | |
98 jsr cpy3 | |
99 ;; open boot file | |
100 ldx #str0 | |
101 jsr puts | |
102 ldx #BOOT | |
103 jsr nopen | |
104 lbcs fnferr | |
105 ldx #dirbuf+$1d ; !!! replace with constant | |
106 ldu #LSN ; | |
107 jsr cpy3 ; set LSN = lsn of dirent | |
108 jsr open ; and open the file | |
109 ldd fcounth ; check size | |
110 lbne toobig ; | |
111 ;; calculate start address | |
112 ldd fcount ; save os9 size for passing to KRN | |
113 std ksize ; | |
114 ldd #$f000 ; f000 - fcount = start address | |
115 subd fcount ; | |
116 clrb ; and round it down | |
117 tfr d,x ; X = cpu load address | |
118 cmpx #$4000 ; cant go lower | |
119 lblo toobig | |
120 ;; set mmu | |
121 lsra | |
122 lsra | |
123 lsra | |
124 lsra | |
125 lsra ; A = mmu bank no | |
126 ldy #$ffa0 | |
127 leay a,y ; Y = beginning mmu | |
128 ldb #1 ; 1 is first os9 system block | |
129 a@ stb ,y+ ; store bank no in mmu | |
130 cmpy #$ffa7 ; did we move to the last mmu block | |
131 beq b@ ; yes, then quit looping | |
132 incb ; increment bank no | |
133 bra a@ ; repeat | |
134 ;; copy os9boot into memory | |
135 b@ jsr fload ; load os9boot into memory | |
136 jsr putCR | |
137 ;; open krn file | |
138 ldx #str1 | |
139 jsr puts | |
140 ldx #KRN | |
141 jsr nopen | |
142 bcs fnferr | |
143 ldx #dirbuf+$1d ; !!! replace with constant | |
144 ldu #LSN ; | |
145 jsr cpy3 ; set LSN = lsn of dirent | |
146 jsr open ; and open the file | |
147 ldx fcounth ; check size of krn file | |
148 lbne krnsize ; is way too big | |
149 ldx fcount ; | |
150 cmpx #$f00 ; | |
151 lbne krnsize ; wrong size | |
152 ;; copy krn file into memory | |
153 ldx #$f000 | |
154 jsr fload ; load ccbkrn into memory | |
155 jsr putCR | |
156 ;; clear out DP page | |
157 ldx #0 | |
158 clrb | |
159 jsr memz | |
160 ;; set dp | |
161 tfr b,dp | |
162 ;; set gime mirror | |
163 ldx #$90 | |
164 jsr gime | |
165 ;; jump to OS9 | |
166 ldx #str2 | |
167 jsr putscr | |
168 ldx $f009 ; KRN relative start address | |
169 leax $f000,x ; make it absolute | |
170 ldu #ksize ; U = ptr to os9boot size | |
171 orcc #$50 | |
172 jmp ,x ; jump to kernel (bye!) | |
173 | |
174 iloop bra iloop | |
175 | |
176 | |
177 fnferr ldx #p0@ | |
178 jsr puts | |
179 a@ bra a@ | |
180 p0@ fcn ": FNF Error!" | |
181 | |
182 initerr ldx #p0@ | |
183 jsr puts | |
184 a@ bra a@ | |
185 p0@ fcn "Driver Init Error!" | |
186 | |
187 mnterr ldx #p0@ | |
188 jsr puts | |
189 a@ bra a@ | |
190 p0@ fcn "LSN0: bad format!" | |
191 | |
192 toobig ldx #p0@ | |
193 jsr puts | |
194 a@ bra a@ | |
195 p0@ fcn "Too Big!" | |
196 | |
197 krnsize | |
198 ldx #p0@ | |
199 jsr puts | |
200 a@ bra a@ | |
201 p0@ fcn "Wrong Size!" | |
202 | |
203 | |
204 ;;; Test for presence of CCPT partitioning | |
205 ccpttest | |
206 pshs d,x | |
207 ldd DBUF0 ; get magic | |
208 cmpd #$4343 ; check for "CC" | |
209 lbne no@ | |
210 ldd DBUF0+2 ; check for "PT" | |
211 cmpd #$5054 | |
212 lbne no@ ; | |
213 no@ ldx #p0@ | |
214 jsr putscr | |
215 puls d,x,pc | |
216 p0@ fcn "CCPT not found." | |
217 | |
218 | |
219 ;;; Setup Screen for os9 (sigh) | |
220 scrSetup | |
221 pshs d,x | |
222 ;; set colors: green on black | |
223 ldb #$12 | |
224 stb $ffbc | |
225 ldb #0 | |
226 stb $ffbd | |
227 ;; clear a screen's worth of video memory | |
228 ldb #$3b | |
229 stb $ffa0 | |
230 ldx #$0000 | |
231 ldd #$2020 | |
232 a@ std ,x++ | |
233 cmpx #$0400 | |
234 bne a@ | |
235 ;; set screen pointer up | |
236 ldd #8 | |
237 std SCRPTR | |
238 clr $ffa0 | |
239 puls d,x,pc | |
240 | |
241 | |
242 ;;; Setup memory with gimme setting, aka Do os9's work :( | |
243 ;;; takes: X = address | |
244 ;;; returns: nothing | |
245 ;;; modifies: nothing | |
246 gime | |
247 pshs d,x,u | |
248 ldu #table@ | |
249 lda #16 | |
250 a@ ldb ,u+ | |
251 stb ,x+ | |
252 deca | |
253 bne a@ | |
254 puls d,x,u,pc | |
255 table@ .dw $6c00 | |
256 .dw $0000 | |
257 .dw $0900 | |
258 .dw $0000 | |
259 .dw $0320 | |
260 .dw $0000 | |
261 .db $00 | |
262 .dw $ec01 | |
263 .db $00 | |
264 | |
265 | |
266 | |
267 ;;; Read file into memory | |
268 ;;; takes: X = address to load, file opened. | |
269 ;;; modifies: nothing | |
270 fload pshs b,x | |
271 a@ jsr readb | |
272 bcs done@ | |
273 stb ,x+ | |
274 bra a@ | |
275 done@ puls b,x,pc | |
276 | |
277 | |
278 | |
279 ;;; open a file via a name | |
280 ;;; takes: X = filename (zero termed) | |
281 ;;; returns: dirbuf set to file's FD, C set on error. | |
282 nopen | |
283 pshs d,x,u | |
284 ;; open root directory | |
285 ldx #root | |
286 ldu #LSN | |
287 jsr cpy3 | |
288 jsr open | |
289 ;; get a dirent into buffer | |
290 ldu 2,s ; U = filename | |
291 b@ lda #32 | |
292 ldx #dirbuf | |
293 a@ jsr readb | |
294 bcs nfound@ | |
295 stb ,x+ | |
296 deca | |
297 bne a@ | |
298 jsr os9toz | |
299 ldx #dirbuf | |
300 jsr strcmp | |
301 bcc found@ | |
302 bra b@ | |
303 nfound@ coma | |
304 puls d,x,u,pc | |
305 found@ clra | |
306 puls d,x,u,pc | |
307 | |
308 | |
309 ;;; zero mem | |
310 ;;; takes: X = ptr, B = number of byte to zero | |
311 ;;; returns: nothing | |
312 ;;; modifies: nothing | |
313 memz | |
314 pshs b,x | |
315 a@ clr ,x+ | |
316 decb | |
317 bne a@ | |
318 puls b,x,pc | |
319 | |
320 | |
321 | |
322 ;;; strcmp | |
323 ;;; takes: X = zstring, U = zstring | |
324 ;;; returns: C clear if equal | |
325 strcmp | |
326 pshs b,x,u | |
327 a@ ldb ,x+ | |
328 cmpb ,u+ | |
329 bne ne@ ; not equal | |
330 tstb | |
331 beq e@ ; equal | |
332 bra a@ ; loop | |
333 e@ clrb | |
334 puls b,x,u,pc | |
335 ne@ comb | |
336 puls b,x,u,pc | |
337 | |
338 ;;; change dirbuf's name to a z-string | |
339 os9toz | |
340 pshs b,x | |
341 ldx #dirbuf | |
342 tst ,x | |
343 beq out@ | |
344 a@ ldb ,x+ | |
345 bpl a@ | |
346 andb #$7f | |
347 stb -1,x | |
348 clr ,x | |
349 out@ puls b,x,pc | |
350 | |
351 | |
352 ;;; Open file | |
353 ;;; takes: LSN = lsn of file's FD | |
354 ;;; returns: nothing | |
355 open | |
356 pshs d,x | |
357 ldx #DBUF1 ; load dbuf1 with file's FD | |
358 stx DPTR | |
359 jsr getlsn | |
360 ldd #DBUF1+$10 ; first segment | |
361 std sptr ; save ptr | |
362 jsr fill ; and get first sector | |
363 ;; set fcount | |
364 ldd DBUF1+FD.SIZ | |
365 std fcounth | |
366 ldd DBUF1+FD.SIZ+2 | |
367 std fcount | |
368 puls d,x,pc | |
369 | |
370 ;;; get one byte from file | |
371 ;;; takes: nothing, | |
372 ;;; returns: B = byte, C set on EOF | |
373 readb | |
374 pshs a,x | |
375 ldd fcount ; is the entire file out of bytes? | |
376 beq eof@ | |
377 ldd bcount | |
378 bne a@ ; if left don't refill | |
379 ;; refill file's data buffer | |
380 jsr fill | |
381 ;; | |
382 a@ ldd fcount | |
383 subd #1 | |
384 std fcount | |
385 ldd bcount | |
386 subd #1 | |
387 std bcount | |
388 ldx dptr | |
389 ldb ,x+ | |
390 stx dptr | |
391 clra | |
392 puls a,x,pc | |
393 eof@ coma | |
394 puls a,x,pc | |
395 | |
396 | |
397 fill | |
398 pshs d,x,u ; save regs | |
399 jsr spin1 | |
400 ldx sptr | |
401 ldd 3,x ; get sector count | |
402 bne a@ ; no more secs left in seg? | |
403 ;; get next segment | |
404 ldx sptr | |
405 leax 5,x | |
406 stx sptr | |
407 ;; fill buffer | |
408 a@ ldx sptr ; copy segment's LSN to args | |
409 ldu #LSN ; | |
410 jsr cpy3 ; | |
411 ldx #DBUF0 ; set data buffer | |
412 stx DPTR ; | |
413 jsr getlsn ; and get the sector | |
414 ;; increment segment | |
415 ldx sptr ; increment segment's LSN | |
416 jsr inc3 ; | |
417 ldd 3,x ; decrement segment's sector count | |
418 subd #1 ; | |
419 std 3,x ; | |
420 ;; set file dirs | |
421 ldd #256 | |
422 std bcount | |
423 ldd #DBUF0 | |
424 std dptr | |
425 puls d,x,u,pc ; return | |
426 | |
427 | |
428 ;;; Spin the ticker | |
429 ;;; takes: nothing | |
430 ;;; returns: nothing | |
431 ;;; modifies: nothing | |
432 spin1 | |
433 pshs b | |
434 ldb #'. | |
435 jsr putc | |
436 puls b,pc | |
437 | |
438 | |
439 ;;; Copy 3 bytes value | |
440 ;;; take: X = src ptr, U = dst ptr | |
441 ;;; modifies: nothing | |
442 cpy3 | |
443 pshs d,x,u | |
444 ldd ,x++ | |
445 std ,u++ | |
446 ldb ,x | |
447 stb ,u | |
448 puls d,x,u,pc | |
449 | |
450 | |
451 ;;; increment 3 byte value by one | |
452 ;;; takes: X = ptr to 3 bytes | |
453 ;;; returns: nothing | |
454 inc3 | |
455 pshs d,x | |
456 ldd 1,x | |
457 addd #1 | |
458 std 1,x | |
459 ldb ,x | |
460 adcb #0 | |
461 stb ,x | |
462 puls d,x,pc | |
463 | |
464 | |
465 ;;; deblocker to translate 256B LSN to a 512B LSN | |
466 ;;; takes: args in LSN/DPTR | |
467 ;;; modifies: nothing | |
468 getlsn | |
469 pshs b,x | |
470 ldx #LSN ; get pointer | |
471 lsr ,x+ | |
472 ror ,x+ | |
473 ror ,x+ | |
474 ldb #1 ; 256b lower read | |
475 bcc a@ | |
476 negb | |
477 a@ stb SMALL | |
478 jsr ll_read | |
479 puls b,x,pc | |
480 | |
481 | |
482 | |
483 ;;; Dump 128 byte to screen | |
484 ;;; takes: X = ptr to data | |
485 ;;; modifies: nothing | |
486 dump | |
487 pshs d,x | |
488 jsr putCR | |
489 lda #8 | |
490 pshs a ; put row counter | |
491 b@ lda #8 ; column counter | |
492 pshs x | |
493 a@ ldb ,x+ | |
494 jsr putb | |
495 jsr putSP | |
496 deca | |
497 bne a@ | |
498 puls x | |
499 clr 8,x | |
500 jsr putscr | |
501 dec ,s | |
502 bne b@ | |
503 leas 1,s | |
504 puls d,x,pc | |
505 | |
506 ;;; Print a Space | |
507 putSP | |
508 pshs b | |
509 ldb #SP | |
510 jsr putc | |
511 puls b,pc | |
512 | |
513 | |
514 ;;; Print a CR | |
515 putCR | |
516 pshs d | |
517 ldb #$3b | |
518 stb $ffa0 | |
519 ldd SCRPTR | |
520 addd #32-8 | |
521 andb #~$1f | |
522 addd #8 | |
523 std SCRPTR | |
524 clr $ffa0 | |
525 puls d,pc | |
526 | |
527 | |
528 ;;; Print a Z string | |
529 ;;; takes: X = ptr to string | |
530 ;;; modifies: nothing | |
531 puts | |
532 pshs b,x | |
533 a@ ldb ,x+ | |
534 beq done@ | |
535 jsr putc | |
536 bra a@ | |
537 done@ puls b,x,pc | |
538 | |
539 ;;; Print a 3 byte value ( in hex ) | |
540 ;;; takes: X = ptr to value | |
541 ;;; modifies: nothing | |
542 put3 | |
543 pshs d,x | |
544 ldd ,x++ | |
545 jsr putw | |
546 ldb ,x | |
547 jsr putb | |
548 puls d,x,pc | |
549 | |
550 | |
551 ;;; Print a word ( in hex) | |
552 ;;; takes: D = word | |
553 ;;; modifies: nothing | |
554 putw | |
555 pshs b | |
556 tfr a,b | |
557 bsr putb | |
558 puls b | |
559 bsr putb | |
560 rts | |
561 | |
562 ;;; Print a byte (in hex) | |
563 ;;; takes: B = byte | |
564 ;;; modifies: nothing | |
565 putb | |
566 pshs d | |
567 lsrb | |
568 lsrb | |
569 lsrb | |
570 lsrb | |
571 bsr putn | |
572 ldb 1,s | |
573 bsr putn | |
574 puls d,pc | |
575 | |
576 ;;; Print a Char | |
577 ;;; takes: B = charactor | |
578 ;;; modifies: nothing | |
579 putc | |
580 pshs d,x | |
581 lda #$3b ; put 3b in bank 0 | |
582 sta $ffa0 | |
583 ldx SCRPTR | |
584 stb ,x+ | |
585 stx SCRPTR | |
586 clr $ffa0 ; put 0 in bank 0 | |
587 puls d,x,pc | |
588 | |
589 | |
590 ;;; Print a nibble | |
591 ;;; takes: B = nibble | |
592 ;;; modifies: nothing | |
593 putn | |
594 pshs b | |
595 andb #$f | |
596 addb #$30 | |
597 cmpb #$39 | |
598 bls a@ | |
599 addb #7 | |
600 a@ jsr putc | |
601 puls b,pc | |
602 | |
603 | |
604 ;;; Print a string followed by a CR | |
605 ;;; takes: X = zero termed string | |
606 ;;; returns: nothing | |
607 ;;; modifies: nothing | |
608 putscr | |
609 jsr puts | |
610 jsr putCR | |
611 rts | |
612 | |
613 | |
614 | |
615 include "sd.asm" | |
616 | |
617 ende equ * | |
618 | |
619 | |
620 end prestart |