-
Notifications
You must be signed in to change notification settings - Fork 6
/
X1INIT.ASM
584 lines (531 loc) · 7.09 KB
/
X1INIT.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
; LSX-Dodgers INIT
; X1/turbo/Z
JP START
DW MACW
DW VER
START:
DI
IM 2
LD SP,EXTSP
CALL INIT ;NZならAUTOEXECを実行
LD HL,0
PUSH HL
PUSH AF
;2HD等1セクタ1024バイトで起動時(Japan2HD)
LD A,(0FE0CH)
CP 4
JR NZ,NOT_2HD2014
LD HL,(00006H)
LD E,L
LD D,H
DEC D
DEC D
DEC D
DEC D
LD (00006H),DE
LD BC,3
LDIR
LD A,4
LD (_MAX_SEC_SZ_H),A
LD (_DTBUF),DE
NOT_2HD2014:
LD A,(_DVSW)
CALL _GETDPB
JR C,INIT1
LD A,(_DVSW)
ADD A,'A'
LD (AUTODV),A
JR INIT2
INIT1:
LD E,0
LD C,00EH
CALL SYSTEM
INIT2:
POP AF
RET Z
LD DE,AUTOD
JP _COMANL
INIT:
LD BC,1A03H
LD A,82H
OUT (C),A
LD A,01EH
OUT (0),A
LD BC,0
LD (_CTC),BC
LD BC,00A04H
CALL CHKCTC
LD BC,00704H
CALL CHKCTC
LD BC,01FA8H
CALL CHKCTC
LD BC,01FA0H
CALL CHKCTC
INISIO:
LD BC,01F91H ;INIT SIO
LD D,1
OUT (C),D
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD C,093H
OUT (C),D
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD C,099H ;INIT SIO
LD D,1
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD C,09BH
OUT (C),D
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD C,080H ;INIT DMA
LD HL,0C306H
INIDMA:
OUT (C),H
DEC L
JR NZ,INIDMA
LD A,0E4H
CALL COMOUT
XOR A
CALL OT49SB
LD A,INTVEC/256
LD I,A
LD BC,(_CTC)
DEC C
DEC C
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD A,CTC0-CPM_BOOT
OUT (C),A
INC C
LD A,047H
OUT (C),A
LD A,13 ;Baudrate 9600-13
OUT (C),A
LD A,C
SUB 010H
LD C,A
; LD (SIOAD+1),BC
; LD (SIOAD0+1),BC
; LD (SIOAD1+1),BC
LD HL,SIODATA
SINIT1:
LD A,(HL)
INC HL
CP 0FFH
JR Z,SINIT2
OUT (C),A
JR SINIT1
SINIT2:
LD A,0E4H
CALL COMOUT
LD A,INTVEC-CPM_BOOT
CALL OT49SB
;
LD BC,01FC4H
LD A,00CH
OUT (C),A
LD C,0C0H
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
INC C
LD A,40
OUT (C),A
INC C
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
INC C
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD C,0C5H
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
TEXT:
LD C,0B0H
LD A,080H
OUT (C),A
LD D,7
LD C,0B9H
LD HL,TEXTDT
TEXT1:
INC B
OUTI
INC C
DEC D
JR NZ,TEXT1
LD BC,01FB0H
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD C,0C4H
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
LD BC,01A01H
IN A,(C)
AND 8
JR Z,PRN
LD C,003H
LD A,00FH
OUT (C),A
LD BC,00A04H
PRN:
LD HL,0
LD B,05CH
DB 03EH ;LD A,??
RST 38H
CALL FILL_MEMORY
LD B,0A4H
XOR A
CALL FILL_MEMORY
LD A,(0FF87H) ;起動ドライブ
AND 06FH
CP 8
JR C,INIDRV
XOR A
INIDRV:
LD (_DVSW),A ;カレントドライブ
LD A,0C3H ;JP
LD HL,CPM_WBOOT
LD (00000H),A
LD (00001H),HL ;IPL
LD HL,BDOS
LD (00005H),A
LD (00006H),HL ;BDOS
LD HL,BIOS
LD (00019H),HL ;BIOS-ROM
LD HL,TRAP38 ;TRAP38
LD (00038H),A
LD (00039H),HL ;RST 038H
LD A,CPM_BOOT/256
LD (0000BH),A
DB 03EH ;LD A,??
JP (HL)
LD (0000FH),A
;KEY
LD A,0E6H ;キーデータ読み出し
CALL COMOUT
CALL IN49SB
PUSH AF
CALL IN49SB
POP AF
PUSH AF
AND 012H
JR NZ,KEYR
LD A,1
LD (KEYREP_SWC),A
KEYR:
POP AF
AND 3
JR Z,NON
LD BC,03FD0H
OUT (C),C
LD A,037H
OUT (0D0H),A
IN A,(C)
CP C
JR Z,TURBO
NON:
LD HL,AT_SCR1
LD DE,SCR1
LD BC,SCRNE-SCR1 ;転送先のサイズ確認用
LD BC,AT_SCRE-AT_SCR1
LDIR
LD HL,AT_DWT
LD DE,WTTRK
LD BC,DMAE-WTTRK ;転送先のサイズ確認用
LD BC,AT_CPUE-AT_DWT
LDIR
LD HL,AT_WTTRK+AT_RS
LD (_WTTRK+1),HL
LD HL,AT_DRD+AT_R
LD (_FDRD+1),HL
LD HL,AT_DWT+AT_R
LD (_FDWT+1),HL
LD HL,AT_SCRN+AT_RS
LD (_SCRN+1),HL
;ノンターボは2D/2HD切り替えを行わない
LD IX,_DEVICE
RES 7,(IX+DPB_DEVICE) ;Aドライブ
RES 7,(IX+DPB_DEVICE+32) ;Bドライブ
RES 7,(IX+DPB_DEVICE+32*2) ;Cドライブ
RES 7,(IX+DPB_DEVICE+32*3) ;Dドライブ
LD HL,0
LD (X1PAT),HL
JP NOBANK
TURBO:
DI ;Check BIOS
LD B,01DH
OUT (C),A ;BIOS ON
LD A,(02F51H)
INC B ;B=01EH
OUT (C),A ;BIOS OFF
EI
CP 0C9H
JR Z,BIOSOK
JR NOBIOS
BIOSOK:
LD A,0C3H ;JP
LD (00018H),A
NOBIOS:
LD A,01FH ;スタートポート
IN A,(0F0H)
RRCA
JR C,CRT1
LD HL,_C8025H
LD DE,CRTCD
LD BC,16
LDIR
CRT1:
LD A,(0FF8CH) ;IPL DEVICE (0:2D/1:2DD/2:2HD)
SUB 2
JR NZ,BANK
; XOR A ;すでに0のハズ
TZ1: ;DPBのモードを2HDにしておく
PUSH AF
CALL _GETDPB
LD A,(IX+DPB_DEVICE)
AND 08FH
CP 087H ;フロッピーで切り替えがON
JR NZ,TZ2
RES 0,(IX+DPB_FDMODE)
TZ2:
POP AF
INC A
CP 8
JR C,TZ1
BANK:
LD BC,00B00H
LD HL,07F00H
DI
OUT (C),L
LD A,(0)
CP 0EBH
JR NZ,BANK1
LD A,02BH
LD (BANKDV),A
BANK1:
OUT (C),L
LD E,(HL)
LD A,E
ADD A,0A5H
LD (HL),A
CP (HL)
LD (HL),E
JR NZ,BANK2
INC L
BIT 4,L
JR Z,BANK1
BANK2:
LD A,010H
OUT (C),A
LD A,L
OR A
JR Z,NOBANK
LD H,0
ADD HL,HL ;*2
ADD HL,HL ;*4
ADD HL,HL ;*8
ADD HL,HL ;*16
ADD HL,HL ;*32
DEC HL ;-1
DEC HL ;-2
DEC HL ;-3
LD (BANKCL),HL
CALL CALC_FATLN
LD (BANKFL),A
NOBANK:
EMM:
LD IX,EMMFL
CALL EADR0
IN A,(C)
PUSH AF
LD DE,0
ECHECK1:
INC DE
CALL EADRX
IN H,(C)
CALL EADRX
LD A,H
ADD A,0E5H
OUT (C),A
INC A
CALL EADR0
OUT (C),A
DEC A
CALL EADRX
IN L,(C)
CALL EADRX
OUT (C),H
CP L
JR NZ,ECHECK2
BIT 3,D
JR Z,ECHECK1
ECHECK2:
CALL EADR0
POP AF
OUT (C),A
CP 0EBH
JR Z,EMM_BPB
LD (IX+DPB_MAXSEC),2 ;BPBが512バイト目から始まる場合を調べる
CALL EADR0
IN A,(C)
CP (IX+DPB_FATID)
JR Z,EMM_NOBPB
LD (IX+DPB_DEVICE),026H ;BPBを使う
LD HL,0-11
JR EMM_BPB1
EMM_BPB:
LD (IX+DPB_DEVICE),026H ;BPBを使う
EMM_NOBPB:
LD (IX+DPB_MAXSEC),0
LD HL,0-9
EMM_BPB1:
ADD HL,DE
JR NC,NOEMM
LD (EMMCL),HL
CALL CALC_FATLN
LD (EMMFL),A
NOEMM:
LD A,000H
KEYREP_SWC EQU $-1
OR A
JR Z,KEYR1
LD BC,0
LD (_CTC),BC
KEYR1:
CALL SETCRTC
LD BC,0-80*25
LD HL,(_PAGE_MINUS)
LD (_PAGE_MINUS),BC
LD E,00CH
CALL _PRINT
LD (_PAGE_MINUS),HL
LD HL,INIMES
CALL MSX
DI
LD L,0-2 ;CALLのスタック分減らす
ADD HL,SP
LD DE,0FF00H
LD B,L
CALL ZERO_MEMORY_DE
LD HL,EXTBIO
LD (HL),0C9H ;RET
INC HL
LD B,TRAP38-EXTBIO-1
DB 03EH ;LD A,??
RST 38H
CALL FILL_MEMORY
LD HL,AT_TRAP38
LD DE,TRAP38
LD BC,AT_TRAPE-AT_TRAP38
LDIR
LD A,0E6H ;キーデータ読み出し
CALL COMOUT
CALL IN49SB
CALL IN49SB
CP 01BH
RET
EADR0:
PUSH DE
LD DE,0
CALL EADRX
POP DE
RET
EADRX:
PUSH AF
CALL EADR
POP AF
RET
CHKCTC:
PUSH BC
LD DE,04703H
INICTC1:
INC C
OUT (C),D
DB 0EDH,071H ;OUT (C),0 Z80未定義命令
DEC E
JR NZ,INICTC1
POP BC
LD DE,007FAH
OUT (C),D
OUT (C),E
IN A,(C)
CP E
RET NZ
OUT (C),D
OUT (C),D
IN A,(C)
CP D
RET NZ
INC C
INC C
LD (_CTC),BC
RET
SETCRTC:
LD HL,CRTCD
XOR A
SETCRT1:
LD BC,01800H
OUT (C),A
INC C
INC B
OUTI
INC A
CP 12
JR NZ,SETCRT1
INC HL
INC HL
LD BC,01A03H+00100H
OUTI
LD BC,01FD0H+00100H
OUTI
RET
CALC_FATLN: ;FAT12のクラスタ数から必要なFATサイズを求める(セクタサイズ512)
LD E,L
LD D,H
ADD HL,HL ;*2
ADD HL,DE ;*3
SRL H ;/2
RR L ;1クラスタ辺り1.5バイト必要
LD DE,511 ;切り上げる
ADD HL,DE
LD A,H
SRL A
RET
AUTOD: DB "AUTOEXEC "
AUTODV: DB "A:",0
INIMES: DB "LSX-Dodgers for X1/turbo version "
DB 030H + VER_1, '.'
DB 030H + VER_2 ,030H + VER_3
DB 'b'
DB " Gaku",0DH,0AH
DB 0
_C8025H:
DB 06BH,050H,059H,088H,01BH,000H,019H,01AH
DB 000H,00FH
DW 0-80*LINE,0-80
DB 00CH,023H
TEXTDT: DB 003H,00CH,00FH,030H,033H,03CH,03FH
SIODATA:
DB 018H
DB 1,0
DB 2,0
DB 3,0C1H
DB 4,044H
DB 5,0E8H
DB 0FFH
AT_TRAP38:
LD HL,0
EX (SP),HL
LD A,'$'
CALL MSG_A
DEC HL
LD A,H
CALL PRHX+AT_RT
LD A,L
PRHX:
PUSH AF
RLCA
RLCA
RLCA
RLCA
CALL PRHX2+AT_RT
POP AF
PRHX2:
AND 00FH
CP 10
CCF
ADC A,'0'
DAA
JP MSG_A
DS 4
AT_TRAPE: