]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blame - cbios/boot.180
loop opt. (z80 code)
[z180-stamp-cpm3.git] / cbios / boot.180
CommitLineData
ea5293bb
L
1 title 'Boot loader module for CP/M 3.0'\r
2\r
3\r
4\r
5 public hwinit,?init,?ldccp,?rlccp\r
6\r
f80331a6
L
7 public f_cpu\r
8\r
d12d8b38
L
9 extrn ?boot,?conin\r
10 extrn pr.inln,pr.crlf,pr.dec,pr.decl\r
f80331a6 11 extrn ioini1l,msginit,mmuinit,intinit,cpu_frq\r
f4471ef9 12 extrn prt0ini,gs_rtc\r
ea5293bb
L
13 extrn @civec,@covec,@aivec,@aovec,@lovec\r
14 extrn @cbnk,?bnksl\r
15\r
16 include config.inc\r
17 include z180reg.inc\r
18\r
19\r
ea5293bb
L
20ccpsize equ 0c80h\r
21\r
40df51ae
L
22 ; CP/M BDOS Function Interfaces\r
23\r
24resetdsk equ 13\r
25open equ 15\r
26read equ 20\r
27setdma equ 26\r
28setmulti equ 44\r
29bdos equ 5\r
30\r
31\r
ea5293bb
L
32 if banked\r
33tpa$bank equ 1\r
34 else\r
35tpa$bank equ 0\r
36 endif\r
37\r
38\r
39 dseg ; init done from banked memory\r
40\r
41hwinit:\r
42 ld a,(INIDONE)\r
43 cp INIDONEVAL\r
44 jr z,hwini_skip\r
45 ld hl,hwini_tab\r
46 call ioini1l\r
47 ld a,0c3h\r
48 ld hl,?boot\r
49 ld (0),a\r
50 ld (1),hl\r
51hwini_skip:\r
52 call mmuinit ; setup mmu registers\r
53 call msginit\r
f80331a6 54 call cpu_frq\r
43bb4ff6
L
55 ld (f_cpu),hl\r
56 ld (f_cpu+2),de\r
ea5293bb
L
57 ret\r
58\r
59?init:\r
50f3b8f0 60 ld hl,1000000000000000b ; assign console to AVRCON:\r
ea5293bb
L
61 ld (@civec),hl\r
62 ld (@covec),hl\r
63 ld hl,0000000000000000b ; assign printer to nothing:\r
64 ld (@lovec),hl\r
65 ld hl,0100000000000000b ; assign AUX to ASCI0:\r
66 ld (@aivec),hl\r
67 ld (@aovec),hl\r
68\r
69\r
d12d8b38 70 call intinit ; setup interrupts and vectors\r
f4471ef9
L
71 call prt0ini ; init timer\r
72 ei\r
50f3b8f0
L
73 ld c,2\r
74 call gs_rtc ; get time and date\r
ea5293bb
L
75\r
76 xor a\r
d12d8b38 77 ld (@cbnk),a ; right now in bank 0\r
ea5293bb 78\r
d12d8b38
L
79 call pr.inln ; print signon message\r
80 db 13,10,13,10,'CP/M Version 3.0, Z180-Stamp BIOS',13,10,0\r
81\r
82 call pr.inln\r
50f3b8f0 83 db 'Estimated CPU clock [Hz]: ',0\r
d12d8b38 84\r
43bb4ff6
L
85 ld hl,(f_cpu)\r
86 ld de,(f_cpu+2)\r
d12d8b38
L
87 call pr.decl\r
88 call pr.crlf\r
ea5293bb
L
89 ret\r
90\r
91\r
d12d8b38 92 cseg ; boot loading must be done from resident memory\r
ea5293bb
L
93\r
94; This version of the boot loader loads the CCP from a file\r
95; called CCP.COM on the system drive (A:).\r
96\r
97\r
98?ldccp:\r
99 ; First time, load the A:CCP.COM file into TPA\r
40df51ae
L
100 ld c,resetdsk\r
101 call bdos\r
ea5293bb
L
102 xor a\r
103 ld (ccp$fcb+15),a ; zero extent\r
104 ld hl,0\r
105 ld (fcb$nr),hl ; start at beginning of file\r
106 ld de,ccp$fcb\r
40df51ae
L
107 ld c,open ; open file containing CCP\r
108 call bdos\r
ea5293bb
L
109 inc a\r
110 jp z,no$ccp ; error if no file...\r
111 ld de,0100h\r
40df51ae
L
112 ld c,setdma ; start of TPA\r
113 call bdos\r
ea5293bb 114 ld de,128\r
40df51ae
L
115 ld c,setmulti ; allow up to 16k bytes\r
116 call bdos\r
ea5293bb 117 ld de,ccp$fcb\r
40df51ae
L
118 ld c,read ; load the thing\r
119 call bdos ; read records\r
ea5293bb
L
120 ; now,\r
121 ; copy CCP to bank 0 for reloading\r
122 ld hl,0100h\r
123 ld bc,ccpsize ; clone 3K, just in case\r
124 ld a,(@cbnk)\r
125 push af ; save current bank\r
126ld$1:\r
127 ld a,tpa$bank\r
128 call ?bnksl ; select TPA\r
129 ld a,(hl)\r
130 push af ; get a byte\r
131 ld a,2\r
132 call ?bnksl ; select extra bank\r
133 pop af\r
134 ld (hl),a ; save the byte\r
40df51ae
L
135 cpi ; bump pointer, drop count\r
136 jp pe,ld$1\r
ea5293bb
L
137 pop af\r
138 call ?bnksl ; restore original bank\r
139 ret\r
140\r
141no$ccp: ; here if we couldn't find the file\r
d12d8b38
L
142 call pr.inln ; report this...\r
143 db 13,10,'BIOS Err on A: No CCP.COM file',0\r
144\r
ea5293bb
L
145 call ?conin ; get a response\r
146 jp ?ldccp ; and try again\r
147\r
148\r
149?rlccp:\r
150 ld hl,0100h\r
151 ld bc,ccpsize ; clone 3K\r
152rl$1:\r
153 ld a,2\r
154 call ?bnksl ; select extra bank\r
50f3b8f0
L
155 ld a,(hl) ; get a byte\r
156 ex af,af'\r
ea5293bb
L
157 ld a,tpa$bank\r
158 call ?bnksl ; select TPA\r
50f3b8f0 159 ex af,af'\r
ea5293bb 160 ld (hl),a ; save the byte\r
50f3b8f0
L
161 cpi ; bump pointer, drop count\r
162 jp pe,rl$1\r
ea5293bb
L
163 ret\r
164\r
165\r
ea5293bb
L
166ccp$fcb:db 1,'CCP ','COM',0,0,0,0\r
167 ds 16\r
168fcb$nr: db 0,0,0\r
169\r
170\r
f80331a6 171 dseg\r
ea5293bb
L
172hwini_tab:\r
173 db (hwini0_e-$)/2 ;count\r
174 db rcr,CREFSH ;configure DRAM refresh\r
175 db dcntl,CWAITIO ;wait states\r
176 db ccr,M_NCD ;No Clock Divide\r
177 db cmr,PHI_X2 ;X2 Clock Multiplier\r
178;TODO: db omr, ;Operation Mode Control Register\r
179hwini0_e:\r
180 db 0 ;stop mark\r
181\r
f80331a6
L
182 cseg\r
183f_cpu dw 0,0 ;detected CPU clock frequency [Hz]\r
ea5293bb
L
184\r
185 end\r