-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.s65
844 lines (793 loc) · 26.3 KB
/
reset.s65
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
.if version==350
jsr selectTerminalROM
.endif
.if version!=350
lda #~ACCCON.D
trb ACCCON
.endif
.if version<500
stz hazel.hasACCCONChanged
.endif
.if version!=350
trb $0366
.endif
cld
ldx #$FF
txs ;reset stack
stx userVIA.ddra ;port A all outputs
lda #%11001111
sta systemVIA.ddrb
.if version==350
jsr enableKeyboardScanning
jsr clearAllSoundChannelBuffers
.endif
.if version<500
ldy #RTC.a.dv32768Hz
ldx #RTC.a
jsr writeRTCByte
jsr finishRTCUpdate
.endif
.if version!=350
lda #ACCCON.Y|ACCCON.X ; page in HAZEL+shadow
tsb ACCCON
.if version>=500
stz hazel.hasACCCONChanged
jsr L8363
.elsif version>=400
jsr clearAllSoundChannelBuffers
.endif
.else
lda defaultVectorTable+0 ;what is this.
lda defaultVectorTable+0 ;what is this.
.endif
.if version==350
jsr ldaSystemVIAIER
.else
lda systemVIA.ier
.endif
asl a
pha
.if version==350
bne nonPowerOnReset
jsr resetCRTC
ldx #7
LFC34:
jsr selectROMX
ldy #$80 ; ''
sty 1
stz 0
tay
LFC3E:
sta (0),y
iny
bne LFC3E
inc 1
bit 1
bvc LFC3E
dex
cpx #4
bcs LFC34
jsr selectTerminalROM
tya
startClearRAM:
tay
LFC53:
ldx TEMPA
tya
stz 1
stz 0
LFC5A:
sta (0),y
iny
bne LFC5A
inc 1
ldy #$40 ; '@'
sty $d00
ldy 1
cpy #$E0 ; ''
tay
bcc LFC5A
stx TEMPA
lda #ACCCON.X
jsr trbACCCON
bne LFC53
jsr selectTerminalROM
.else
.if version<400
beq startClearRAM ; branch taken if power on
lda breakAndESCAPEEffect ; read BREAK action flags
; (set by *FX200)
lsr a ; divide by 2 to get the
; break action
dec a ; Z=1 if it was 1
bne nonPowerOnReset ; branch taken if break
; action says don't clear
; RAM
.else
bne nonPowerOnReset
ldx #7
jsr LF8B4
.if version==400
lda #0
.else
tya
.endif
.endif
startClearRAM:
tay ;Y=0
clearRAM:
tya ;A=0
stz $01
stz $00 ;start at $0000
clearRAMPageLoop:
sta ($00),y ;clear RAM
iny
bne clearRAMPageLoop
inc $01
ldx #$40 ;$40=RTI
stx nmiEntryPoint ;restore the RTI previously written,
;as each iteration will potentially
;overwrite it
ldx $01
cpx #$E0 ;hit the end of RAM?
bcc clearRAMPageLoop ;branch taken if still more to go
lda #ACCCON.X ;page out shadow RAM
trb ACCCON
bne clearRAM ;branch taken if shadow RAM bit
;previously set - i.e., that was the
;first iteration, and we need to go back
;to do main RAM
.if version>=400
lda $fe28
lda $fe2b
.endif
.endif
nonPowerOnReset:
.if version>=350
lda breakAndESCAPEEffect
lsr a
dec a
beq startClearRAM
.endif
lda #<emptyCommandLine
sta hazel.commandLinePointer+0
lda #>emptyCommandLine
sta hazel.commandLinePointer+1
lda #ACCCON.Y|ACCCON.X ; page in MOS ROM, page in main
; RAM
.if version==350
jsr trbACCCON
.else
trb ACCCON
.endif
lda #$0F
sta numericKeypadShiftEffect
.if version<500&&version!=350
-
dec a
sta systemVIA.orb
cmp #$09
bcs -
.endif
ldx #key_ctrl
.if version==350
jsr setTSTAndInterrogateKeyboard
.else
jsr interrogateKeyboard
.endif
cpx #$80 ;Z=0 C=1 if CTRL+BREAK
jsr updateKeyboardLEDs
stz lastBREAKType ;softBREAK
ror a
ldx #$9c ;what is this?
ldy #$8D ;what is this?
pla
beq L80AD
ldy #$7E ;what is this?
bcc L80DF
ldy #$87 ;what is this?
inc lastBREAKType
L80AD:
inc lastBREAKType
phy
.if version==350&&CFA3000
lda lastBREAKType
dec a
bne LFCBF
jsr LFB2F
LFCBF:
.endif
.if version==350
ldx #configureTable.mode.metadata-configureTable
jsr setTSTAndReadConfigurationByte
.elsif version<500
jsr readDefaultMODE ; Read configured MODE
.else
jsr L9E58
ldx #configureTable.mode.metadata-configureTable;$56
jsr readConfigurationByte
.endif
ora #CMOSBytes.defaults0.shadowMask
sta startupOptions
.if version==350
jsr setTSTAndReadDefaults3
.else
jsr readDefaults3 ; Read configured BOOT
.endif
and #CMOSBytes.defaults3.autoBootMask
lsr a ; Reset OSBYTE 255 boot bit (b3) if BOOT
trb startupOptions
.if version==350
jsr setTSTAndReadDefaultTVSettings
.else
jsr readDefaultTVSettings
.endif
sty tvOffset
stx tvInterlace
.if version==350
jsr setTSTAndReadDefaults3
.else
jsr readDefaults3
.endif
and #CMOSBytes.defaults3.protectedScrollingMask
beq L80D4
lda #VDUVariables.cursorFlags.scrollProtect
L80D4:
sta vduv.cursorFlags
jsr restoreFont32To255
ply
ldx #$92
bra initializePage2Loop
L80DF:
.if version>=500
jsr L9E58
.endif
lda #$87 ; Clear MODE bits from OSBYTE 255
trb startupOptions
lda vduv.currentScreenMODE ; Get current screen MODE b0-b2
and #$07
tsb startupOptions ; Copy to OSBYTE 255
lda #STATE.isShadowMode ; Test shadow screen bit in VDU flags
bit STATE ; Not shadow screen
beq initializePage2Loop
lda #$80 ; Set shadow screen bit in OSBYTE 255
tsb startupOptions
initializePage2Loop:
lda lastBREAKType
bne clearPage2Byte ;taken unless soft BREAK
; leave the ROM information table alone on a soft
; BREAK.
cpx #<romInformationTable+16
bcs clearPage2Byte
cpx #<romInformationTable
bcs nextPage2Byte
clearPage2Byte:
stz $0200,x
cpx #$CD
bcc nextPage2Byte
dec $0200,x ;initialize later values to $ff
nextPage2Byte:
inx
bne initializePage2Loop
.if version==350
lda TEMPA
.endif
ldx #$CF
initializeZeroPageLoop:
stz $00,x
inx
bne initializeZeroPageLoop
.if version==350
sta TEMPA
jsr selectTerminalROM
.endif
lda lastBREAKType
bne L813D ;taken if not soft BREAK
.if version!=400
lda noignoreState
pha
.endif
lda basicROMNumber
pha
lda oshwm
pha
lda spoolFileHandle
pha
ldx execFileHandle
L8130:
lda defaultVectorTable-1,y
sta vectors-1,y
dey
cpy #EVENTV+1-vectors
bcs L8130
ldy #FILEV-vectors
L813D:
lda defaultVectorTable-1,y
sta vectors-1,y
dey
bne L813D
lda lastBREAKType
bne L8164
stx execFileHandle
pla ;restore *SPOOL file handle
cmp #$04 ;is it a TAPE or ROM handle?
bcs L8155 ;taken if no - keep it
.if version==350
tya
.else
lda #$00 ;auto-close it if TAPE or ROM handle
.endif
L8155:
sta spoolFileHandle
pla
sta oshwm
pla
sta basicROMNumber
.if version!=400
pla
sta noignoreState
.endif
L8164:
.if version==350
ldx #$19
jsr setTSTAndReadRTCByte
.elsif version<500
jsr readDefaults1
.elsif version>=500
ldx #cmosBytesOffset+CMOSBytes.defaults1
jsr readRTCByte
.endif
ldx #keyboardStatusByte.shiftLockDisengaged
asl a
asl a ;N=defaultCapsLockMask
bmi gotKeyboardStatusByte ;taken if defaultCapsLock
ldx #keyboardStatusByte.shiftLockDisengaged|keyboardStatusByte.capsLockDisengaged
asl a ;N=defaultNoLockMask
bmi gotKeyboardStatusByte
ldx #keyboardStatusByte.shiftEnabled|keyboardStatusByte.shiftLockDisengaged
gotKeyboardStatusByte:
stx keyboardStatusByte
.if version==350
jsr setTSTAndResetKeyRepeat
.else
jsr selectTerminalROM
jsr resetKeyRepeat
.endif
lda lastBREAKType
beq L8196
.if version==350
ldx #cmosBytesOffset+CMOSBytes.printerIgnoreChar
jsr setTSTAndReadRTCByte
.elsif version<500
jsr readDefaultPrinterIgnoreChar
.elsif version>=500
ldx #cmosBytesOffset+CMOSBytes.printerIgnoreChar
jsr readRTCByte
.endif
sta printerIgnoreChar
.if version==350
jsr setTSTAndReadUsePrinterIgnoreChar
.elsif version<500
jsr readDefaults2
lsr a ;C=tubeOn
lsr a ;C=usePrinterIgnoreChar
.elsif version>=500
jsr readUsePrinterIgnoreChar
.endif
ror noignoreState
.if version==350
ldx #configureTable.print.metadata-configureTable
jsr setTSTAndReadConfigurationByte
.elsif version<500
jsr readDefaultFX5Settings
.elsif version>=500
ldx #configureTable.print.metadata-configureTable
jsr readConfigurationByte
.endif
sta printerDriverType
L8196:
.if version==400
ldx #1
.else
.if version==350
ldx #configureTable.data.metadata-configureTable
jsr setTSTAndReadConfigurationByte
.elsif version<500
jsr readDefaultSerialDataFormat
.elsif version>=500
ldx #configureTable.data.metadata-configureTable
jsr readConfigurationByte
.endif
asl a ;
asl a ;shift into the control registerword field
ora #ACIA.control.rtsHighTXInterruptDisabled|ACIA.control.counterDivide64
sta aciaControlRegister
.if version<500
jsr resetACIAThenRewriteControlRegister
ldx #$01
.elsif version>=500
ldx #CMOSBytes.joystick
jsr readRTCByte
sta adcConversionType
.if olivetti
ldx #CMOSBytes.country
jsr readRTCByte
sta countryFlag
.endif
ldx #$ff
L81B2:
jsr resetACIA
lda $fe08
bne L81C8
lda #$20
sta $fe08
lda $fe08
and #$f7
cmp #$82
beq L81CF
L81C8:
cmp #8
beq L81CF
stz rs423InterruptMask
L81CF:
dex
bne L81B2
jsr resetACIAThenRewriteControlRegister
inx
.endif
.endif
lda #$7F
initializeVIAInterruptsLoop:
sta systemVIA.ifr,x
sta userVIA.ifr,x
dex
bpl initializeVIAInterruptsLoop
.if version!=350
; Let through 1 IRQ.
cli
sei
; TEMPA was cleared above, so if bit 6 is set, there
; must have been an IRQ (as A=$7f).
bit TEMPA
bvc +
jsr call1MHzBusHook
+
.endif
.if version!=400
ldx #$80|VIA.irq.t1|VIA.irq.cb1|VIA.irq.ca1
.else
ldx #$80|VIA.irq.t1|VIA.irq.ca1
.endif
stx systemVIA.ier
.if version>=500
ldx #$80|VIA.irq.cb1|VIA.irq.cb2
stx userVIA.ier
.endif
ldx #VIA.pcr.cb2InputNegativeActiveEdge|VIA.pcr.cb1NegativeActiveEdge|VIA.pcr.ca2InputPositiveEdge|VIA.pcr.ca1NegativeActiveEdge
stx systemVIA.pcr
lda #VIA.acr.t1Continuous|VIA.acr.t2Timer|VIA.acr.srDisabled|VIA.acr.pbLatchDisabled|VIA.acr.paLatchDisabled
sta systemVIA.acr
lda #$0E
sta systemVIA.t1lL
sta userVIA.pcr ;VIA.pcr.cb2InputNegativeActiveEdge|VIA.pcr.cb1NegativeActiveEdge|VIA.pcr.ca2HighOutput|VIA.pcr.ca1NegativeActiveEdge
.if version==350
sta HADC.status
.elsif version<400
sta HADC.latch ;looks benign
.endif
lda #$27
sta systemVIA.t1lH
sta systemVIA.t1cH
.if version==350||version>=400
jsr clearAllSoundChannelBuffers
.else
ldx #$08
L81DD:
dex
jsr clearSoundChannelBuffer
cpx #$04
bne L81DD
.endif
.if version==350
jsr setTSTAndOSBYTE7A
.else
jsr osbyte7A
.endif
stx firstKeyPressedInternal
ldx #$00
.if version>=500
stx userVIA.ddrb
.endif
jsr purgeBuffer
.if version!=400
lda serialULARegister
and #$7F
jsr LEC89
.if version<500&&version!=350
jsr readDefaultSerialBaudRateIndex
.else
ldx #configureTable.baud.metadata-configureTable
.if version==350
jsr setTSTAndReadConfigurationByte
.else
jsr readConfigurationByte
.endif
.endif
pha
tax
jsr osbyte08
plx
lda #$07
jsr osbyte07
.endif
.if version==350
jsr setTSTAndReadDefaults3
.else
jsr readDefaults3
.endif
bit #CMOSBytes.defaults3.loudMask
bne L8211
lda #$F0
sta bellSound
L8211:
.if version!=350
jsr selectTerminalROM
.endif
ldx softKeyConsistencyFlag
beq checkResetType
jsr osbyte12
checkResetType:
lda lastBREAKType
beq romsScanned ;taken if soft BREAK
.if version==350
scanROMs:
.include "scan_roms.s65"
.else
jmp scanROMs
.endif
romsScanned:
lda startupOptions
jsr setStartupMODE
lda lastBREAKType
dec a
.if version>=510
beq powerOnReset
jmp softReset
.else
bne softReset ;taken if not power-on reset
.endif
powerOnReset:
.if version>=500
ldx #$ff
jsr i2cReadEEPROMByte
bcs checkForNVRAMReset
tya
and #$7f
.if version>=511||olivetti
cmp #$32
.else
cmp #$30
.endif
beq checkForNVRAMReset
ldx #0
ldy #0
jsr L9E99
bra resetCMOSRAM
.endif
checkForNVRAMReset:
.if version>=510
checkForEraseKey:
lda firstKeyPressedInternal
cmp #key_delete
bne checkForResetKey
jsr alwaysPrintFollowingMessage
.byte 22,7
.byte 13,10
.text "Clearing options...please wait",0
ldx #$ff
L82A9:
phx
ldy #0
jsr writeCMOSByte
plx
dex
cpx #size(CMOSBytes)
bcs L82A9
bra resetCMOSRAM
.endif
.if version<510
lda firstKeyPressedInternal
.endif
checkForResetKey:
cmp #key_r
bne softReset ;taken if R not pressed
.if version<500
.if CFA3000
jsr LFB2F
.else
; Reset CMOS RAM
resetCMOSRAM:
ldx #size(RTC.ram)-1
resetCMOSRAMLoop:
phx
ldy #$00
.if version==350
cpx #size(CMOSBytes)
bcs LFE91
ldy LFEA2-1,x
LFE91:
.endif
jsr writeCMOSByte
plx
dex
.if version==350
bne resetCMOSRAMLoop
.else
bpl resetCMOSRAMLoop
.endif
.if version!=350
; Initialize ROM insertion flags.
ldy #$FF
ldx #CMOSBytes.insertedROMs+0
jsr writeCMOSByte
ldx #CMOSBytes.insertedROMs+1
jsr writeCMOSByte
.endif
.endif
.else
resetCMOSRAM: ;82bb in MOS 5.10
ldx #size(CMOSBytes)
resetCMOSRAMLoop:
phx
dex
jsr readDefaultCMOSByte
jsr writeCMOSByte
plx
dex
bne resetCMOSRAMLoop
.endif
.if version==350
jsr LE525
.else
.if version>=500
ldx #$7f
jsr i2cReadEEPROMByte
tya
and #$80
.if version>=511||olivetti
eor #$b2
.else
eor #$b0
.endif
tay
ldx #$ff
jsr L9E99
.endif
jsr alwaysPrintFollowingMessage
.if version>=500
.byte 22,7
.endif
.text 13,10
.if version<500
.text "CMOS RAM reset"
.elsif version>=500
.text "Options reset"
.endif
.text 13,10,"Press break to continue"
.text 13,10,0
.endif
lda #$03
sta breakAndESCAPEEffect
hang:
bra hang
;-------------------------------------------------------------------------
.if version==350
LFEA2:
.byte $fe
.byte $00
.byte $eb
.byte $00
.if CFA3000
.byte $7d
.else
.byte $CD
.endif
.byte $FF
.byte $FF
.byte $15
.byte 0
.byte $17
.byte $60
.byte $32
.byte 8
.byte $A
.if CFA3000
.byte $38
.else
.byte $2D
.endif
.byte $82
.endif
;-------------------------------------------------------------------------
softReset:
.if version==350
lda #ACCCON.Y
jsr tsbACCCON
.else
jsr selectHAZEL
.endif
stz hazel.moveSrcHandle
stz hazel.moveDestHandle
ldy #$CA
.if version==350
jsr setTSTAndInsertCharacterIntoKeyboardBuffer
.else
jsr insertCharacterIntoKeyboardBuffer
.endif
.if version==350
jsr setTSTAndOSBYTE247EntryPoint
.else
jsr osbyte247EntryPoint
.endif
lda lastBREAKType
beq L829D
.if version==400
jsr LEBBF
.else
jsr LEDD0
.endif
L829D:
.if version<500
.if version==350
jsr setTSTAndReadDefaults2
.else
jsr readDefaults2
.endif
lsr a
bcc continueSoftReset
.if version==350
jsr setTSTAndReadDefaults3
.else
jsr readDefaults3
.endif
.if version==350
lsr a
lsr a
lsr a
lda #ACCCON.ITU
jsr trbACCCON
bcs L82B4
jsr tsbACCCON
.else
bit #CMOSBytes.defaults3.extTubeMask
php
lda #ACCCON.ITU
trb ACCCON
plp
bne L82B4
tsb ACCCON
.endif
L82B4:
.if version==350
jsr isSecondProcessorPresent
.else
jsr isSecondProcessorPresent
.endif
bcs foundTube
.if version==350
lda TEMPA
.else
lda ACCCON ; Toggle Internal/External Tube
.endif
eor #ACCCON.ITU
.if version==350
jsr staTEMPAAndACCCON
.else
sta ACCCON
.endif
.if version==350
jsr isSecondProcessorPresent
.else
jsr isSecondProcessorPresent
.endif
.endif