-
Notifications
You must be signed in to change notification settings - Fork 3
/
background.asm
231 lines (205 loc) · 3.81 KB
/
background.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
; background routines
const BACKGROUND_FRAMEBUFFER: 0x02000000 ; base address of background framebuffer
; fill the whole background with a color
; inputs:
; r0: color
; outputs:
; none
fill_background:
push r1
push r31
mov r1, BACKGROUND_FRAMEBUFFER
mov r31, 0x0004B000 ; 640*480
fill_background_loop:
mov [r1], r0
add r1, 4
loop fill_background_loop
pop r31
pop r1
ret
; draw a pixel to the background
; inputs:
; r0: X coordinate
; r1: Y coordinate
; r2: color
; outputs:
; none
draw_pixel_to_background:
push r5
push r6
mov r3, BACKGROUND_FRAMEBUFFER
mov r4, 640
call draw_pixel_generic
pop r6
pop r5
ret
; draw a filled rectangle to the background
; inputs:
; r0: X coordinate of top-left
; r1: Y coordinate of top-left
; r2: X size
; r3: Y size
; r4: color
; outputs:
; none
draw_filled_rectangle_to_background:
push r5
push r6
mov r5, BACKGROUND_FRAMEBUFFER
mov r6, 640
call draw_filled_rectangle_generic
pop r6
pop r5
ret
; draw a single tile to the background
; inputs:
; r0: tile number
; r1: X coordinate
; r2: Y coordinate
; outputs:
; none
draw_tile_to_background:
push r8
push r9
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_tile_generic
pop r9
pop r8
ret
; draw a single font tile to the background
; inputs:
; r0: tile number
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; outputs:
; none
draw_font_tile_to_background:
push r5
push r6
push r7
push r8
push r9
mov r5, [FONT_PTR]
movz.16 r6, [r5]
movz.16 r7, [r5+2]
inc r5, 4
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_font_tile_generic
pop r9
pop r8
pop r7
pop r6
pop r5
ret
; draw text to the background, using printf-style formatting
; inputs:
; r0: pointer to null-terminated string
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; r10-r15: optional format values
; outputs:
; r1: X coordinate of end of text
draw_format_str_to_background:
push r5
push r6
push r7
push r8
push r9
mov r5, [FONT_PTR]
movz.16 r6, [r5]
movz.16 r7, [r5+2]
inc r5, 4
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_format_str_generic
pop r9
pop r8
pop r7
pop r6
pop r5
ret
; draw text to the background
; inputs:
; r0: pointer to null-terminated string
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; outputs:
; r1: X coordinate of end of text
draw_str_to_background:
push r0
push r5
mov r5, r0
draw_str_to_background_loop:
movz.8 r0, [r5]
call draw_font_tile_to_background
inc r5
add r1, 8
cmp.8 [r5], 0x00
ifnz jmp draw_str_to_background_loop
pop r5
pop r0
ret
; draw a decimal value to the background
; inputs:
; r0: value
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; outputs:
; r1: X coordinate of end of text
draw_decimal_to_background:
push r5
push r6
push r7
push r8
push r9
mov r5, [FONT_PTR]
movz.16 r6, [r5]
movz.16 r7, [r5+2]
inc r5, 4
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_decimal_generic
pop r9
pop r8
pop r7
pop r6
pop r5
ret
; draw a hex value to the background
; inputs:
; r0: value
; r1: X coordinate
; r2: Y coordinate
; r3: foreground color
; r4: background color
; outputs:
; r1: X coordinate of end of text
draw_hex_to_background:
push r5
push r6
push r7
push r8
push r9
mov r5, [FONT_PTR]
movz.16 r6, [r5]
movz.16 r7, [r5+2]
inc r5, 4
mov r8, BACKGROUND_FRAMEBUFFER
mov r9, 640
call draw_hex_generic
pop r9
pop r8
pop r7
pop r6
pop r5
ret