annotate src/init.s @ 119:a6a53e5c04bd

Make a call stack implementation that is more complete and maybe cleaner.
author William Astle <lost@l-w.ca>
date Fri, 29 Dec 2023 01:40:39 -0700
parents 2d52cd154ed1
children c7f2f63cbcfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
1 *pragmapush list
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
2 *pragma list
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
3 START orcc #0x50 ; make sure interrupts are disabled if we come here in an unusual way
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
4 ifdef COCO3
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
5 ldu #gime_inite ; point to end of GIME initializer
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
6 ldx #GIME.INIT0+(gime_inite-gime_init) ; point to end of GIME registers
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
7 ldb #gime_inite-gime_init ; number of bytes to transfer
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
8 initc0 lda ,-u ; copy byte to GIME (count down so we init MMU before turning it on)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
9 sta ,-x
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
10 decb ; done?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
11 bne initc0 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
12 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
13 ldd #0xff34 ; initizer for below
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
14 tfr a,dp ; set DP to I/O page
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
15 setdp 0xff ; tell assembler about DP value
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
16 clr PIA0.CA ; set PIA0 A to direction mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
17 clr PIA0.CB ; set PIA0 B to direction mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
18 clr PIA0.DA ; set PIA0 A to all inputs (comparator, keyboard rows)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
19 sta PIA0.DB ; set PIA0 B to all outputs (keyboard columns)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
20 stb PIA0.CA ; set PIA0 A to data mode, interrupt disabled, MUX to source 0
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
21 stb PIA0.CB ; set PIA0 B to data mode, interrupt disabled, MUX to source 0
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
22 clr PIA1.CA ; set PIA1 A to direction mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
23 clr PIA1.CB ; set PIA1 B to direction mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
24 deca ; set PIA1 A bits 7-1 output (DAC, RS232), 0 input (cassette)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
25 sta PIA1.DA
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
26 lda #0xf8 ;* set PIA1 B bits 7-3 output (VDG stuff), 2-0 input (single bit sound,
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
27 sta PIA1.DB ;* RS232 input, ram size input)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
28 stb PIA1.CA ; set PIA1 A to data mode, interrupt disabled, cassette motor off
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
29 stb PIA1.CB ; set PIA1 B to data mode, interrupt disabled, sound off
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
30 lda #2 ; set RS232 output to "marking" (stop bit)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
31 sta PIA1.DA
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
32 lda #16 ; clear 16 SAM register bits
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
33 ldu #SAMREG ; point to SAM register bits
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
34 init0 sta ,u++ ; clear SAM bit
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
35 deca ; done all?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
36 bne init0 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
37 ; set the SAM to point to the text screen, which the code will handle at any
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
38 ; arbitrary 512 byte aligned address in memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
39 ifne (textscreen)&0x200
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
40 sta SAM.F0SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
41 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
42 ifne (textscreen)&0x400
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
43 sta SAM.F1SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
44 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
45 ifne (textscreen)&0x800
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
46 sta SAM.F2SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
47 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
48 ifne (textscreen)&0x1000
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
49 sta SAM.F3SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
50 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
51 ifne (textscreen)&0x2000
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
52 sta SAM.F4SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
53 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
54 ifne (textscreen)&0x4000
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
55 sta SAM.F5SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
56 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
57 ifne (textscreen)&0x8000
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
58 sta SAM.F6SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
59 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
60 ifdef COCO2B
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
61 ; The following SAM configuration sequence is different from the one in the usual
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
62 ; one used by the earlier models of the Coco because the Coco2B has the '785 variant
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
63 ; of the SAM instead of the '783 variant. The '785 variant supports 16Kx4 RAMs which
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
64 ; are used in Coco2B systems. Hence why there is a different version of this ROM
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
65 ; just for the Coco2B.
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
66 clr PIA0.DB ; strobe RAM size low
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
67 ldb #4 ; is input low?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
68 bitb PIA1.DB
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
69 beq init1 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
70 sta SAM.M0SET ; program SAM for 16Kx4 RAMs
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
71 sta SAM.P1SET
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
72 skip2
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
73 init1 sta SAM.M1SET ; program SAM for 64Kx1 RAMs
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
74 else
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
75 ifndef COCO3
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
76 ; Detect the installed memory size so the SAM ('783 variant) can be correctly
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
77 ; programmed for the installed memory. Note that this sequence is replaced with
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
78 ; a different one for the Coco2B which has the '785 variant of the SAM.
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
79 ldb #0xff ; strobe RAM size high
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
80 stb PIA0.DB
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
81 ldb #4 ; mask for ram size check
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
82 bitb PIA1.DB ; is the bit set on ram size input?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
83 beq init2 ; brif not - 4Kx1 RAMs
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
84 sta PIA0.DB ; clear RAM size output to see what happens (A is 0 from above)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
85 bitb PIA1.DB ; is it set now?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
86 beq init1 ; brif not - 64Kx1 RAMs
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
87 leau -2,u ; adjust pointer so we set the other RAM size bit for the SAM (16Kx1)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
88 init1 sta -3,u ; set M0 (16Kx1) or M1 (64Kx1)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
89 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
90 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
91 init2 tfr a,dp ; set DP to bottom of memory (A is 0 from above)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
92 setdp 0 ; tell assembler about it
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
93 lds #textscreen ; put the stack just below the text screen
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
94 ifdef COCO3
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
95 ; Check if we need to do a ROM/RAM copy, which will happen if the interrupt vectors are
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
96 ; not flagged valid OR the reset vector isn't valid
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
97 ldb INT.FLAG ; are the bounce vectors valid?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
98 cmpb #0x55
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
99 bne initc4 ; brif not - do ROM/RAM copy
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
100 ldb RSTFLG ; is reset vector valid?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
101 bne initc2 ; brif not - check secondary location
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
102 ldx RSTVEC ; get reset vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
103 ldb ,x ; is it valid?\
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
104 cmpb #0x12
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
105 bne initc2 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
106 initc1 jmp ,x ; transfer control to warm start routine
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
107 initc2 clr GIME.MMU0 ; check again with block 0 in the direct page
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
108 ldb RSTFLG ; get new RSTFLG
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
109 cmpb #0x55 ; valid?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
110 bne initc3 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
111 ldx RSTVEC ; get new RSTVEC
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
112 ldb ,x ; is it valid?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
113 cmpb #0x12
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
114 beq initc1 ; brif so - transfer control
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
115 initc3 ldb #0x38 ; restore MMU
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
116 stb GIME.MMU0
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
117 initc4 ldx #initc6 ; point to helper
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
118 ldu #textscreen ; point to text screen
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
119 ldb #initc7-initc6 ; bytes to copy
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
120 initc5 lda ,x+ ; copy byte
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
121 sta ,u+
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
122 decb ; done?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
123 bne initc5 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
124 ldu #0x8000 ; point to start of ROM
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
125 jmp textscreen ; transfer control to helper in RAM
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
126 initc6 sta SAM.TYCLR ; drop to ROM mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
127 pulu d,x,y,s ; grab 8 bytes
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
128 sta SAM.TYSET ; go to RAM mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
129 pshu d,x,y,s ; stick the bytes in RAM
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
130 leau 8,u ; move to next 8 bytes
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
131 cmpu #0xfe00 ; end of stuff to copy?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
132 blo initc6 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
133 jmp initc7 ; go back to mainline
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
134 initc7 lds #textscreen ; reset stack to somewhere safe
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
135 lda #0x12 ; activate ROM warm start handler
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
136 sta warmstart
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
137 ldx #INT.FLAG ; point to bounce vector destination
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
138 ldu #int_init ; point to initializer for bounce vectors
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
139 ldb #int_inite-int_init ; number of bytes to copy
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
140 initc8 lda ,u+ ; copy byte
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
141 sta ,x+
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
142 decb ; done?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
143 bne initc8 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
144 ; now recheck for warm start in case ROM/RAM copy made things valid
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
145 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
146 ldb RSTFLG ; is the reset vector valid?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
147 cmpb #0x55
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
148 bne coldstart ; brif not - do cold start
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
149 ldx RSTVEC ; get warm start routine pointer
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
150 ldb ,x ; does it start with NOP?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
151 cmpb #0x12
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
152 bne coldstart ; brif not - do cold start
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
153 jmp ,x ; transfer control to warm start routine
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
154 ifdef COCO3
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
156 ; GIME register initializer
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
157 gime_init fcb GIME_COCO|GIME_MMUEN|GIME_FExx|GIME_SCS|GIME_ROMI32 ; enable MMU, SCS, constant page, internal ROM
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
158 fcb GIME_TASK0 ; use MMU task 0
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
159 fcb 0 ; do not enable IRQ sources
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
160 fcb 0 ; do not enable FIRQ sources
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
161 fdb 0xfff ; set timer to max value
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
162 fdb 0 ; *reserved placeholder*
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
163 fcb 0,0,0,0 ; SG4 screen settings with black border
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
164 fcb 0x0f,0xe0,0x00,0x00 ; (puts screen in bottom 64K of memory)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
165 fcb 0x38,0x39,0x3a,0x3b ; MMU task 0 (bottom of top 64K of RAM)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
166 fcb 0x3c,0x3d,0x3e,0x3f ; (ROM shadow must be in 3c...3f)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
167 fcb 0x38,0x39,0x3a,0x3b ; MMU task 1 (copy of task 0)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
168 fcb 0x3c,0x3d,0x3e,0x3f
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
169 fcb 18,54,9,36,63,27,45,38 ; palette values (RGB)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
170 fcb 0,18,0,63,0,18,0,38
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
171 gime_inite equ *
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
172 int_init fcb 0x55 ; vectors valid flag
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
173 jmp SW3VEC ; bounce to stock ROM compatibility vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
174 jmp SW2VEC ; bounce to stock ROM compatibility vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
175 jmp FRQVEC ; bounce to stock ROM compatibility vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
176 jmp IRQVEC ; bounce to stock ROM compatibility vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
177 jmp SWIVEC ; bounce to stock ROM compatibility vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
178 jmp NMIVEC ; bounce to stock ROM compatibility vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
179 int_inite equ *
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
180 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
182 ; Cold start handling
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
183 coldstart ldx #dpstart ; point to start of direct page
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
184 ldd #0 ; set up for blanking
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
185 coldstart0 std ,x++ ; blank a couple of bytes
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
186 cmpx #textscreen ; end of low memory?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
187 blo coldstart0 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
188 ifndef COCO3
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
189 ; This is the memory size detection sequence. This runs through memory starting at the bottom of memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
190 ; and stops when it reaches something that can't be modified successfully. This is basically the same
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
191 ; algorithm used by the stock ROM. It takes less space than doing a more pointed set of probes. The end
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
192 ; result will be X pointing to the byte one below the top of RAM. This is intentional to ensure there
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
193 ; is one writeable byte at the top of string space. Note that X will point to the byte after the end
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
194 ; of the text screen when we get here.
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
195 ldx #heapstart ; point to start of heap
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
196 coldstart1 lda 2,x ; get original value at test location
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
197 coma ; invert all bits
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
198 sta 2,x ; write it to the memory location
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
199 cmpa 2,x ; did it take?
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
200 bne coldstart2 ; brif not
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
201 com 2,x ; restore memory byte
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
202 leax 1,x ; move pointer forward
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
203 bra coldstart1 ; go check next byte
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
204 else
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
205 ; For the Coco3, we do not need to concern ourselves about where the top actual memory is so we don't
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
206 ; bother doing a memory scan in the default 64K memory map. Because we always run from RAM, we can actually
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
207 ; set the top of memory to the actual top of the 32K space without having to ensure there is an extra byte
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
208 ; available above the string space.
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
209 ldx #ROMSTART-1 ; point to top of memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
210 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
211 coldstart2 stx memtop ; save absolute top of memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
212 stx memsize ; save top of unreserved memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
213 stx stringtab ; mark string space as empty
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
214 leax -200,x ; allocate 200 bytes of string space
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
215 stx freetop ; save top of free memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
216 clr ,-x ; make a hole for the "end of call stack" flag
119
a6a53e5c04bd Make a call stack implementation that is more complete and maybe cleaner.
William Astle <lost@l-w.ca>
parents: 73
diff changeset
217 stx cstackptr ; save the new call stack pointer
73
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
218 leas ,x ; put the actual stack below the above
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
219 ldx #heapstart ; point to start of free memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
220 clr ,x+ ; put a NUL before the start of the program
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
221 stx progtext ; put the start of the program there
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
222 clr ,x+ ; put a NULL pointer to mark end of program
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
223 clr ,x+
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
224 stx vartab ; put start of integer variables at end of program
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
225 stx objecttab ; also put the start of large objects there
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
226 stx freestart ; mark the start of free memory
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
227 lda #keyb_caps ; enable caps lock but disable all other shift states
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
228 sta keyb_flags
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
229 ldx #warmstart ; set up warm start handler
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
230 stx RSTVEC
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
231 lda #0x55 ; activate warm start handler
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
232 sta RSTFLG
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
233 ldd #0x7e3b ; opcodes for JMP extended and RTI
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
234 ldx #irqhandler ; enable IRQ handler with a JMP at the vector
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
235 sta IRQVEC
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
236 stx IRQVEC+1
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
237 sta FRQVEC ; initialize FIRQ handler with JMP
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
238 ldx #firqhandler
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
239 stx FRQVEC+1
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
240 stb NMIVEC ; initialize NMI to RTI
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
241 stb SW3VEC ; initialize SWI3 to RTI
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
242 stb SW2VEC ; initialize SWI2 to RTI
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
243 stb SWIVEC ; initialize SWI to RTI
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
244 ldx #greeting ; display greeting
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
245 jsr console_outstr
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
246 bra warmstartb ; finish up initialization
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
248 ; Warm start handling
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
249 ifdef COCO3
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
250 warmstart fcb 0xff ; set to 0xff to force ROM/RAM copy on reset
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
251 else
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
252 warmstart nop ; flag warm start routine as valid
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
253 endc
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
254 jsr console_clear ; clear screen
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
255 clr filenum ; reset I/O channel to the screen
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
256 warmstartb jsr keyb_reset ; reset the keyboard
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
257 lda #0x35 ; enable VSYNC interrupt in PIA
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
258 sta PIA0.CB
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
259 andcc #0xaf ; enable interrupts at the cpu
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
260 jmp immediate ; go start immediate mode
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
262 ; System startup message
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
263 ; (start with form feed to clear screen; saves 2 bytes over 'jsr console_clear' in cold start)
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
264 greeting fcc '\fLWBASIC VERSION 2022.0\r\n'
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
265 fcc 'COPYRIGHT (C) 2022 BY LOST\r\n'
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
266 fcc 'WIZARD ENTERPRISES INC.\r\n'
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
267 fcn '\n'
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents:
diff changeset
268 *pragmapop list