-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfx.s
210 lines (179 loc) · 5.12 KB
/
gfx.s
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
; Copyright 2024 Jean-Baptiste M. "JBQ" "Djaybee" Queru
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as
; published by the Free Software Foundation, either version 3 of the
; License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
;
; SPDX-License-Identifier: AGPL-3.0-or-later
; See main.s for more information
; #############################################################################
; #############################################################################
; #### ####
; #### ####
; #### Handling of graphics hardware ####
; #### ####
; #### ####
; #############################################################################
; #############################################################################
.text
; ###########################
; ###########################
; ## ##
; ## Public interfaces ##
; ## ##
; ###########################
; ###########################
; GfxSetup:
; * Saves state of graphics hardware
; * Sets up resolution and refresh rate
; GfxReset:
; * Restores state of graphics hardware
; #####################################
; #####################################
; ## ##
; ## Set up graphics environment ##
; ## ##
; #####################################
; #####################################
GfxSetup:
; Enable interrupts, we'll need those when waiting for a VBL
move.w #$2300, sr
; Save framebuffer address registers, compute framebuffer address
moveq.l #0, d0
move.b GFX_VBASE_HIGH.w, d0
move.b d0, _gfx_save_vbase_high.l
lsl.l #8, d0
move.b GFX_VBASE_MID.w, d0
move.b d0,_gfx_save_vbase_mid.l
lsl.l #8, d0
move.l d0, gfx_os_fb.l
move.l d0, gfx_fb_front.l
; Prepare second framebuffer
move.l #_gfx_fb + 255, d0
clr.b d0
move.l d0, gfx_demo_fb.l
move.l d0, gfx_fb_back.l
; Save other graphics registers
move.b GFX_SYNC.w, _gfx_save_sync.l
move.b GFX_MODE.w, _gfx_save_mode.l
lea.l GFX_PALETTE.w, a0
lea.l _gfx_save_palette.l, a1
moveq.l #15, d7
.SavePalette:
move.w (a0)+, (a1)+
dbra.w d7, .SavePalette.l
; Wait for a VBL before making visible changes
lea.l vbl_count.l, a0
move.w (a0), d0
.WaitVbl:
cmp.w (a0), d0
bne.s .WaitVbl.l
; Switch to mode 0, 50 Hz
move.b #GFX_SYNC_INTERN | GFX_SYNC_50HZ, GFX_SYNC.w
move.b #GFX_MODE_COLOW, GFX_MODE.w
; Erase palette
moveq.l #0, d0
lea.l GFX_PALETTE.w, a0
moveq.l #15, d7
.ClearPalette:
move.w d0, (a0)+
dbra.w d7, .ClearPalette.l
; Erase framebuffer
moveq.l #0, d0
movea.l gfx_os_fb.l, a0
move.w #1999, d7
.ClearScreen:
move.l d0, (a0)+
move.l d0, (a0)+
move.l d0, (a0)+
move.l d0, (a0)+
dbra.w d7, .ClearScreen.l
rts
; ######################################
; ######################################
; ## ##
; ## Restore graphics environment ##
; ## ##
; ######################################
; ######################################
GfxReset:
; Wait for a VBL before making visible changes
lea.l vbl_count.l, a0
move.w (a0), d0
.WaitVbl1:
cmp.w (a0), d0
bne.s .WaitVbl1.l
; Erase palette
moveq.l #0, d0
lea.l GFX_PALETTE.w, a0
moveq.l #15, d7
.ClearPalette:
move.w d0, (a0)+
dbra.w d7, .ClearPalette.l
; Erase framebuffer
moveq.l #0, d0
movea.l gfx_os_fb.l, a0
move.w #1999, d7
.ClearScreen:
move.l d0, (a0)+
move.l d0, (a0)+
move.l d0, (a0)+
move.l d0, (a0)+
dbra.w d7, .ClearScreen.l
move.b _gfx_save_vbase_high.l, GFX_VBASE_HIGH.w
move.b _gfx_save_vbase_mid.l, GFX_VBASE_MID.w
; Wait for a VBL before making visible changes
lea.l vbl_count.l, a0
move.w (a0), d0
.WaitVbl2:
cmp.w (a0), d0
bne.s .WaitVbl2.l
; Restore palette
lea.l _gfx_save_palette.l, a0
lea.l GFX_PALETTE.w, a1
moveq.l #15, d7
.RestorePalette:
move.w (a0)+, (a1)+
dbra.w d7, .RestorePalette.l
; Restore mode / sync
move.b _gfx_save_sync.l, GFX_SYNC.w
move.b _gfx_save_mode.l, GFX_MODE.w
rts
; ###################
; ###################
; ## ##
; ## Variables ##
; ## ##
; ###################
; ###################
.bss
.even
_gfx_save_palette:
.ds.w 16
gfx_os_fb:
.ds.l 1
gfx_demo_fb:
.ds.l 1
gfx_fb_front:
.ds.l 1
gfx_fb_back:
.ds.l 1
_gfx_save_vbase_high:
.ds.b 1
_gfx_save_vbase_mid:
.ds.b 1
_gfx_save_sync:
.ds.b 1
_gfx_save_mode:
.ds.b 1
_gfx_fb:
.ds.b 32255