forked from marcobaye/mca2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arch64.a
193 lines (174 loc) · 4.26 KB
/
arch64.a
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
;ACME 0.96.2
; architecture-specific stuff for C64
; config
MAKE_BASIC_HEADER = 1
ALLOW_CURSOR = 1
ALLOW_KEYPAD = 0
INCLUDE_CHARSET = 1
KEYBOARD_IS_PETSCII = 1
LINE_LENGTH = 40
sys_NEWLINE = 13
; libraries
!src <cbm/c64/vic.a>
!src <cbm/petscii.a>
; constants
controlcode_HOME = petscii_HOME
controlcode_CLEAR = petscii_CLEAR
controlcode_REVSON = petscii_REVSON
controlcode_REVSOFF = petscii_REVSOFF
controlcode_UP = petscii_UP
controlcode_DOWN = petscii_DOWN
controlcode_LEFT = petscii_LEFT
controlcode_RIGHT = petscii_RIGHT
; zero page
!addr cpu_port = $01
;!addr fac1 = $61 ; floating point registers could be used for temp storage
!addr z_revsflag = $c7
!addr z_quote_mode = $d4
!addr runptr = $fb ; points to next bytecode instruction (also used for inline text output and scanning of usage list)
!addr recursion_depth = $fd ; counts recursion levels
; system area
!addr currentcolor = $0286
!addr screenpage = $0288
!addr cbmshift = $0291
!addr is_PAL = $02a6 ; zero for NTSC, nonzero for PAL
; other
load_addr = $0801
!addr VICBANK = $c000
!addr SCREEN = VICBANK + $0c00 ; screen at $cc00
!addr CHARGEN = VICBANK + $1000 ; charset at $d000
; i/o
!addr cia2_port_a = $dd00
; kernal rom
!addr editor_putAX = $ea13 ; output screencode A and attribute X
!addr k_chrout = $ffd2
!addr sys_getin = $ffe4
; new color codes (because some PetSCII codes clash with the UTF8 conversion):
; vic-ii colors:
color_BLACK = colorbase + $0
color_WHITE = colorbase + $1
color_RED = colorbase + $2
color_CYAN = colorbase + $3
color_PURPLE = colorbase + $4
color_GREEN = colorbase + $5
color_BLUE = colorbase + $6
color_YELLOW = colorbase + $7
color_ORANGE = colorbase + $8
color_BROWN = colorbase + $9
color_LRED = colorbase + $a
color_GRAY1 = colorbase + $b
color_GRAY2 = colorbase + $c
color_LGREEN = colorbase + $d
color_LBLUE = colorbase + $e
color_GRAY3 = colorbase + $f
; code macros
!macro arch_basicstuff {
; nothing needed
}
!macro arch_wait_X_frames {
--- ; count down frames
- lda vic_controlv
bpl -
txa ; check for early exit (if called with A zero)
beq + ; early exit
- lda vic_controlv
bmi -
dex
bne ---
+ ; done
}
!macro arch_init {
; FIXME - fadeout!
lda #0 ; black
sta vic_cborder
sta vic_cbg
}
!macro arch_invert_title {
; invert first line for title
ldx #LINE_LENGTH - 1
lda #160 ; reverse space
-- sta SCREEN, x
dex
bpl --
; done
}
!macro arch_output_init {
; ECB + bitmap + disable => all black
lda #%.##.#.##
sta vic_controlv
; forbid cbm/shift
lda #$80
sta cbmshift
; set vic bank
lda #%#..#.### XOR (VICBANK >> 14)
sta cia2_port_a
; set screen and charset address
lda #((SCREEN & $3c00) >> 6) | ((CHARGEN & $3800) >> 10)
sta vic_ram
; copy charset
lda #$31 ; ram and charset
ldx #0
sei
sta cpu_port
--- !for i, 0, 3 {
lda charset + i * 256, x
sta CHARGEN + i * 256, x
eor #$ff ; revert
sta CHARGEN + i * 256 + $0400, x
}
inx
bne ---
lda #$36 ; ram, i/o, kernal
sta cpu_port
cli
; tell kernal where screen is
lda #>SCREEN
sta screenpage
; now CLEAR to init screen
jsr my_primm
!tx color_std, petscii_CLEAR, 0
; re-enable vic display
lda #%...##.##
sta vic_controlv
}
!macro arch_set_colors {
lda #color_border
sta vic_cborder
lda #color_background
sta vic_cbg
}
!macro arch_set_text_color_A {
; no need to convert, vic-ii only cares about lower nibble anyway
sta currentcolor ; new characters have correct color
}
!macro arch_bulk {
; copied from 128:
sys_chrout ;
pha
stx .tmp_x
sty .tmp_y
cmp #32
bcc .kernal
cmp #128
bcc .put
cmp #$e0
bcc .kernal ; CLEAR, for example
and #31
.put ldx z_revsflag
beq +
ora #$80 ; reverse
+ ldx currentcolor
jsr editor_putAX
lda #petscii_RIGHT
.kernal jsr k_chrout
pla
ldx #MODIFIED8 : .tmp_x = * - 1
ldy #MODIFIED8 : .tmp_y = * - 1
rts
}
!macro arch_check_memlimit {
;!if * >= $a000 { !error "Reached BASIC ROM. Please add code to disable it." } ; commented out, because Basic ROM is now off anyway
!if * >= SCREEN { !error "Reached screen area. Move screen up in memory!" }
!if * >= CHARGEN { !error "Reached chargen area. Move chargen up in memory!" }
!if * >= $d000 { !error "Reached I/O area. Engine must be changed to cope with this!" }
}