-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccess.asm
717 lines (595 loc) · 15.5 KB
/
access.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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
.model small
.8086
.code
A9WControlRW equ 0002h
A9RControl record A9MFrc2Is512KHzOr1KHz:1,A9MFrc2PreScale:1,\
A9MFrc1Is512KHzOr1Hz:1,A9MFrc1PreScale:1,\
A9MSoundEnable:1,A9MLcdEnable:1,\
A9MLowBatNMIEnable:1,A9MDoorNMIEnable:1,\
A9MZeroIsGrayMode:1,A9MArmStandBy:1,\
A9MDisableDMADivide:1,A9MRamDeviceSize:2,\
A9MDisableMemWait:1,A9MDisableIoWait:1,\
A9MDisableClockDivide:1
A9VRam256KBits equ (0 shl A9MRamDeviceSize)
A9VRam1MBits equ (1 shl A9MRamDeviceSize)
A9VRam4MBits equ (2 shl A9MRamDeviceSize)
A9VRam16MBits equ (3 shl A9MRamDeviceSize)
A9XRamDeviceSizeMask equ (3 shl A9MRamDeviceSize)
A9WStatusR equ 0004h
A9RStatus record A9MCold:1,A9MPowerFail:1,\
A9MReset:1,A9MNoBattery:1,\
A9MFifoFull:1,A9MSlaveOverrun:1,\
A9MSlaveControlFrame:1,A9MSlaveDataValid:1,\
A9MKeyboard:1,A9MSlaveClock:1,\
A9MMainsPresent:1,A9MDoorSwitch:1,\
A9MLowBatNMI:1,A9MDoorNMI:1,\
A9MProtectedModeNMI:1,A9MWatchDogNMI:1
A9MLcdType equ 8
A9XLcdType equ 0000111100000000b
A9WLcdSizeW equ 0004h
A9RLcdSize record A9MLcdLineLength:5,A9MLcdNumberOfPixels:11
A9WLcdControlW equ 0006h
A9RLcdControl record A9MLcdMode:2,A9MLcdACLineRate:5,A9MLcdPixelRate:5
A9VSinglePage1 equ (0 shl A9MLcdMode)
A9VSinglePage2 equ (1 shl A9MLcdMode)
A9VSinglePage1And2 equ (2 shl A9MLcdMode)
A9VDualPage1And2 equ (3 shl A9MLcdMode)
A9BInterruptStatusR equ 0006h
A9BInterruptMaskRW equ 0008h
A9RInterrupts record A9MFrc2:1,A9MFrc1:1,\
A9MExpIntB:1,A9MExpIntA:1,A9MExpIntC:1,\
A9MSlave:1,A9MTimer:1,A9MSound:1
A9BNmiClearW equ 0009h
A9BNonSpecificEoiW equ 000ah
A9BStartFlagClearW equ 000bh
A9BTimerEoiW equ 000ch
A9BSerialSlaveEoiW equ 000dh
A9BFrc1EoiW equ 000eh
A9BFrc2EoiW equ 000fh
A9WResetWatchDogW equ 0010h
A9WFrc1DataRW equ 0012h
A9BProtectionOnW equ 0014h
A9BProtectionOffR equ 0014h
A9BProtectionOffW equ 0015h
A9WProtectionUpperW equ 0016h
A9WProtectionLowerW equ 0018h
A9BSoundDataRW equ 001ah
A9BSoundEoiW equ 001ch
A9WFrc2DataRW equ 001eh
A9WPortABDataRW equ 0020h
A9RPortABData record A9MKeyIdX2:1,A9MNiCdDetect:1,\
A9MBatLevel2:1,A9MBatLevel1:1,A9MLiBatLevel:1,\
A9MKeyIdX1:1,A9MKeyIdX0:0,A9MKeyRowX8:1,\
A9MCradle:1,A9MKeyRowX:7
A9BPortADataRW equ 0020h
A9BPortBDataRW equ 0021h
A9WPortABDDRRW equ 0022h
A9VPortABDDR equ 0000000000000000b
A9BPortADDRRW equ 0022h
A9BPortBDDRRW equ 0023h
A9WPortCDDataRW equ 0024h
A9RPortCDData record A9MVccPacksEnable:1,A9MCodecEnable:1,\
A9MVccLcdEnable:1,A9MLcdPanelEnable:1,\
A9MLcdContrast:4,A9MVolume:2,\
A9MReproEnable:1,A9MAltDoorNMIEnable:1,\
A9MAmplifierEnable:1,A9MKeyIdEnable:1,\
A9MBuzVolX:1,A9MBacklightEnableX:1
A9VVolumeLow equ (mask A9MVolume)
A9VPortCDData equ 0000111100000000b
A9VPortCDDDR equ not (1111000011111111b)
A9BPortCDataRW equ 0024h
A9BPortDDataRW equ 0025h
A9WPortCDDDRRW equ 0026h
A9BPortCDDRRW equ 0026h
A9BPortDDDRRW equ 0027h
A9BPageSelect6000RW equ 0028h
A9BPageSelect7000RW equ 0029h
A9BPageSelect8000RW equ 002ah
A9BPageSelect9000RW equ 002bh
A9RControlExtraRW record A9MSlaveIntEnable:1,A9MClkDiv:2,\
A9MClockEnable5:1,A9MClockEnable4:1,\
A9MClockEnable3:1,A9MClockEnable2:1,\
A9MClockEnable1:1,A9MSoundDir:1,\
A9MExonDisable:1,A9MBuzzFromFrc1OrTog:1,\
A9MBuzzTog:1,A9MKeyCol:4
A9VKeyColHigh equ 0
A9VKeyColLow equ 1
A9VKeyCol0 equ 8
A9VClkDiv1 equ (3 shl A9MClkDiv)
A9VClkDiv2 equ (2 shl A9MClkDiv)
A9VClkDiv3 equ (1 shl A9MClkDiv)
A9VClkDiv4 equ (0 shl A9MClkDiv)
A9WPumpControlRW equ 002eh
A9RPumpControl record A9MVhPumpDc:4,A9MVhPumpBat:4,\
A9MLcdPump:4,A9MPump2:4
A9VVhPumpBat equ (14 shl A9MVhPumpBat)
A9VVhPumpBatSoft equ (4 shl A9MVhPumpBat)
A9VVhPumpBatMedium equ (8 shl A9MVhPumpBat)
A9VVhPumpDC equ (2 shl A9MVhPumpDc)
A9VVhPumpDCSoft equ (1 shl A9MVhPumpDc)
A9VLcdPump equ (7 shl A9MLcdPump)
A9VLcdPumpSoft equ (1 shl A9MLcdPump)
A9VPacksPumpSoft equ (15 shl A9MPump2)
A9VVhPumpDelay equ 100 ; Milliseconds
A9VLcdPumpDelay equ 5 ; Milliseconds
A9VCC3OnDelay equ 1 ; Milliseconds
A9VCCPacksDelay equ 20 ; Milliseconds
A9VCC2Delay equ 10 ; Milliseconds
A9WRtcLSWRW equ 0080h
A9WRtcMSWRW equ 0082h
A9WNullFrameW equ 0084h
A9BSlaveDataR equ 0088h
A9BSerialDataRW equ 008ah
A9BSerialControlW equ 008ch
A9BChannelSelectRW equ 008eh
A9RChannelSelect record A9MMultiplexEnable:1,A9MSerialClockRate:2,\
A9MPack5Enable:1,A9MPack4Enable:1,\
A9MPack3Enable:1,A9MPack2Enable:1,\
A9MPack1Enable:1
A9VSClkRateMedium equ (0 shl A9MSerialClockRate)
A9VSClkRateSpecial equ (1 shl A9MSerialClockRate)
A9VSClkRateSlow equ (2 shl A9MSerialClockRate)
A9VSClkRateFast equ (3 shl A9MSerialClockRate)
;
; Asic9 Dependent constants
;
ResetWatchDog equ A9WResetWatchDogW
SelectChannel1 equ (mask A9MPack1Enable)
SelectChannel2 equ (mask A9MPack2Enable)
SelectChannel3 equ (mask A9MPack3Enable)
SelectChannel4 equ (mask A9MPack4Enable)
SelectChannel5 equ (mask A9MPack5Enable)
;
public _access
public _memcpy
public _getpsel0
public _setpsel0
public _getpsel1
public _setpsel1
public _getpsel2
public _setpsel2
public _memcpypsel0
public _memcpypsel1
public _memcpypsel2
public _getcs
public _getds
public _getA9RCtrl
public _getA9RStat
_getA9RCtrl proc near
cli
push cx
xor cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
in ax,A9WControlRW ; A9WControlRW
test cl,cl
jz dontundo_a9rctrl
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_a9rctrl:
pop cx
sti
retn
_getA9RCtrl endp
_getA9RStat proc near
cli
push cx
xor cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
in ax,A9WStatusR
test cl,cl
jz dontundo_a9rstat
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_a9rstat:
pop cx
sti
retn
_getA9RStat endp
_getcs proc near
push cs
pop ax
retn
_getcs endp
_getds proc near
push ds
pop ax
retn
_getds endp
; Thanks to Patrick for memcpy :-)
; Thanks to Simon for the values of PSEL0..3 ;-)
;;; PSEL0
_getpsel0 proc near
cli
push cx
sub cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
in al,A9BPageSelect6000RW ; Get PSEL0
and ax,00ffh
test cl,cl
jz dontundo_gp0
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_gp0:
pop cx
sti
retn
_getpsel0 endp
_setpsel0 proc near
cli
push cx
sub cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
and ax,00ffh
out A9BPageSelect6000RW,al ; Set PSEL0
test cl,cl
jz dontundo_sp0
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_sp0:
pop cx
sti
retn
_setpsel0 endp
;;; PSEL1
_getpsel1 proc near
cli
push cx
sub cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
in al,A9BPageSelect7000RW ; Get PSEL1
and ax,00ffh
test cl,cl
jz dontundo_gp1
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_gp1:
pop cx
sti
retn
_getpsel1 endp
_setpsel1 proc near
cli
push cx
sub cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
and ax,00ffh
out A9BPageSelect7000RW,al ; Set PSEL1
test cl,cl
jz dontundo_sp1
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_sp1:
pop cx
sti
retn
_setpsel1 endp
;;; PSEL2
_getpsel2 proc near
cli
push cx
sub cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
in al,A9BPageSelect8000RW ; Get PSEL2
and ax,00ffh
test cl,cl
jz dontundo_gp2
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_gp2:
pop cx
sti
retn
_getpsel2 endp
_setpsel2 proc near
cli
push cx
sub cl,cl
xchg cl,[ss:20h]
out A9BProtectionOffW,al ; Disable memory protection (any value will do)
and ax,00ffh
out A9BPageSelect8000RW,al ; Set PSEL2
test cl,cl
jz dontundo_sp2
out A9BProtectionOnW,al ; Enable memory protection (any value will do)
dontundo_sp2:
pop cx
sti
retn
_setpsel2 endp
; Old notes (after out A9BPageSelect8000RW):
; may need out 14h,al to re-enable memory protection?
; that's what HwRomBankSet does after out 0x2b,al (PSEL3)
; HwRomBankSet doesn't touch the watchdog, and HwRomBankGet
; doesn't in 0x2b - HwRomBankSet stores whatever it had written
; into the OS data segment; HwRomBankGet returns this value.
; You'd think that PSELx are write-only, but their name in OSSIBO.INC
; is A9BPageSelectx000RW ...
; No, A000:6251 is an IN AX,2A. A000:61F7 could be a memory
; copy routine. It does an out 0fh,al first (???)
; 0f = A9BFrc2EoiW
; Also A000:63BA routine outs to 18, 16, 2a
; 16 = A9WProtectionUpperW, 18 = A9WProtectionLowerW
; A000:F971 ins from 2C, ands this with CF and outs it to port 10 (?!?)
; (A9WResetWatchDogW)
; xors that with 10 and outs that to 2C (repeated, to toggle bit 4)
; Here is HwRomBankSet:
;>00000000 1E push ds
;>00000001 53 push bx
;>00000002 51 push cx
;>00000003 2AC9 sub cl,cl
;>00000005 36860E2000 xchg cl,[ss:0x20]
;>0000000A BBB004 mov bx,0x4b0
;>0000000D 8EDB mov ds,bx
;>0000000F E615 out 0x15,al ; A9BProtectionOffW
;>00000011 8B1E0004 mov bx,[0x400]
;>00000015 8AE0 mov ah,al
;>00000017 86673D xchg ah,[bx+0x3d]
;>0000001A E62B out 0x2b,al ; A9BPageSelect9000RW
;>0000001C 86C4 xchg al,ah
;>0000001E 2AE4 sub ah,ah
;>00000020 36880E2000 mov [ss:0x20],cl
;>00000025 84C9 test cl,cl
;>00000027 7402 jz 0x2b
;>00000029 E614 out 0x14,al ; A9BProtectionOnW
; aka A9BProtectionOffR
;>0000002B 59 pop cx
;>0000002C 5B pop bx
;>0000002D 1F pop ds
;>0000002E CF iret
; original
;_access proc near
;
; push es
; push ax
; cli
; pop es
; mov al,es:[bx]
; pop es
; sti
; retn
;_access endp
_access proc near
push cx
sub cl,cl
xchg cl,[ss:20h]
out 15h,al ; A9BProtectionOffW
push es
push ax
cli
pop es
mov al,es:[bx]
pop es
test cl,cl
jz dontundo
out 14h,al ; A9BProtectionOnW
dontundo:
pop cx
sti
retn
_access endp
; end _access
_memcpy proc near
push si
push di ; save these
push es
push ds
push dx
push cx
push bx
push ax
push cx ; save cx
mov cl,4
shl ax,cl ; ax = segment / 4, so mult by 4
pop cx ; restore cx, the number of bytes to copy
push bx ; si=bx = offset to read
pop si
push dx ; di=dx = destination buffer
pop di
; Patrick clears decimal here, not sure why :-~
cld
cli
push ds
pop es ; es=ds = process's normal ds
push ax ; ds=ax = source segment
pop ds
rep movsb ; memcpy(ds:si, es:di, cx)
pop ax
pop bx
pop cx
pop dx
pop ds
pop es
pop di ; save these
pop si
sti
retn
_memcpy endp
_memcpypsel0 proc near
push si
push di ; save these
push es
; save parameters
push ds ; DEST SEGMENT (PROCESS NORMAL DS)
push dx ; DEST OFFSET
push cx ; LENGTH
push bx ; SOURCE OFFSET
push ax ; PSEL0
push bx ; si=bx = offset to read
pop si
push dx ; di=dx = destination buffer offset
pop di
; Patrick clears decimal here, not sure why :-~
; cld
cli
push ds ; es=ds = process's normal ds
pop es ; (should be this anyway)
; setup psel0=al
; save old SS:20 (memory protection status)
push cx ; save count
sub cl,cl
xchg cl,[ss:20h]
mov ss20,cx
out 15h,al ; A9BProtectionOffW
pop cx ; restore count
push ax ; save current PSEL2
in al,28h ; A9BPageSelect6000
mov oldpsel0,ax
pop ax
; set new PSEL0
and ax,00ffh
out 28h,al ; A9BPageSelect6000
push ds ; save process DS
push 6000h ; source segment (ds) is always 6000
pop ds
rep movsb ; memcpy(6000:si, es:di, cx)
pop ds ; restore process DS
push ax ; restore old PSEL0
mov ax,oldpsel0
out 28h,al ; A9BPageSelect6000
pop ax
push cx
mov cx,ss20
test cl,cl
jz dontundo_mp0
out 14h,al ; A9BProtectionOnW
dontundo_mp0:
pop cx
pop ax
pop bx
pop cx
pop dx
pop ds
pop es
pop di ; save these
pop si
sti
retn
_memcpypsel0 endp
_memcpypsel1 proc near
push si
push di ; save these
push es
; save parameters
push ds ; DEST SEGMENT (PROCESS NORMAL DS)
push dx ; DEST OFFSET
push cx ; LENGTH
push bx ; SOURCE OFFSET
push ax ; PSEL1
push bx ; si=bx = offset to read
pop si
push dx ; di=dx = destination buffer offset
pop di
; Patrick clears decimal here, not sure why :-~
; cld
cli
push ds ; es=ds = process's normal ds
pop es ; (should be this anyway)
; setup psel1=al
; save old SS:20 (memory protection status)
push cx ; save count
sub cl,cl
xchg cl,[ss:20h]
mov ss20,cx
out 15h,al ; A9BProtectionOffW
pop cx ; restore count
push ax ; save current PSEL1
in al,29h ; A9BPageSelect7000
mov oldpsel1,ax
pop ax
; set new PSEL1
and ax,00ffh
out 29h,al ; A9BPageSelect7000
push ds ; save process DS
push 7000h ; source segment (ds) is always 7000
pop ds
rep movsb ; memcpy(7000:si, es:di, cx)
pop ds ; restore process DS
push ax ; restore old PSEL1
mov ax,oldpsel1
out 29h,al ; A9BPageSelect7000
pop ax
push cx
mov cx,ss20
test cl,cl
jz dontundo_mp1
out 14h,al ; A9BProtectionOnW
dontundo_mp1:
pop cx
pop ax
pop bx
pop cx
pop dx
pop ds
pop es
pop di ; save these
pop si
sti
retn
_memcpypsel1 endp
_memcpypsel2 proc near
push si
push di ; save these
push es
; save parameters
push ds ; DEST SEGMENT (PROCESS NORMAL DS)
push dx ; DEST OFFSET
push cx ; LENGTH
push bx ; SOURCE OFFSET
push ax ; PSEL2
push bx ; si=bx = offset to read
pop si
push dx ; di=dx = destination buffer offset
pop di
; Patrick clears decimal here, not sure why :-~
; cld
cli
push ds ; es=ds = process's normal ds
pop es ; (should be this anyway)
; setup psel2=al
; save old SS:20 (memory protection status)
push cx ; save count
sub cl,cl
xchg cl,[ss:20h]
mov ss20,cx
out 15h,al ; A9BProtectionOffW
pop cx ; restore count
push ax ; save current PSEL2
in al,2ah ; A9BPageSelect8000
mov oldpsel2,ax
pop ax
; set new PSEL2
and ax,00ffh
out 2ah,al ; A9BPageSelect8000
push ds ; save process DS
push 8000h ; source segment (ds) is always 8000
pop ds
rep movsb ; memcpy(8000:si, es:di, cx)
pop ds ; restore process DS
push ax ; restore old PSEL2
mov ax,oldpsel2
out 2ah,al ; A9BPageSelect8000
pop ax
push cx
mov cx,ss20
test cl,cl
jz dontundo_mp2
out 14h,al ; A9BProtectionOnW
dontundo_mp2:
pop cx
pop ax
pop bx
pop cx
pop dx
pop ds
pop es
pop di ; save these
pop si
sti
retn
_memcpypsel2 endp
.data
ss20 dw 0
oldpsel0 dw 0
oldpsel1 dw 0
oldpsel2 dw 0
end