summaryrefslogtreecommitdiffstats
path: root/src/bitmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitmap.h')
-rw-r--r--src/bitmap.h64
1 files changed, 18 insertions, 46 deletions
diff --git a/src/bitmap.h b/src/bitmap.h
index bae9b40..c839900 100644
--- a/src/bitmap.h
+++ b/src/bitmap.h
@@ -1,30 +1,8 @@
1#ifndef GBAEXP_BITMAP_H 1#ifndef GBAEXP_BITMAP_H
2#define GBAEXP_BITMAP_H 2#define GBAEXP_BITMAP_H
3 3
4// #include "bd-font.c"
5#include "common.h" 4#include "common.h"
6 5
7// Using bd-font, an 8x8 bitmap font.
8// static void
9// put_char(int x, int y, Color clr, u8 chr) {
10// for (size_t i = 0; i < 8; ++i) {
11// for (size_t j = 0; j < 8; ++j) {
12// if ((font[chr][i] >> (7 - j)) & 0x1) {
13// FRAMEBUFFER[y + i][x + j] = clr;
14// }
15// }
16// }
17// }
18
19// static void
20// put_text(int x, int y, Color clr, char *msg) {
21// int count = 0;
22// while (*msg) {
23// put_char(x + count, y, clr, *msg++);
24// count += 8;
25// }
26// }
27
28// Draws a line with the given color between (x0,y0) and (x1,y1) using the 6// Draws a line with the given color between (x0,y0) and (x1,y1) using the
29// Bresenham's line drawing algorithm using exclusively integer arithmetic. 7// Bresenham's line drawing algorithm using exclusively integer arithmetic.
30static void 8static void
@@ -146,17 +124,31 @@ draw_fill_rect(int x0, int y0, int x1, int y1, Color clr) {
146// GBA needs to meet memory alignment requirements, we can't write a u8 into 124// GBA needs to meet memory alignment requirements, we can't write a u8 into
147// memory, instead we need to read a u16 word, mask and or the corresponding 125// memory, instead we need to read a u16 word, mask and or the corresponding
148// bits and wave the updated u16. 126// bits and wave the updated u16.
149static void 127static inline void
150put_pixel_m4(int x, int y, u8 col_index, vu16 *buffer) { 128put_pixel_m4(int x, int y, u8 clr_idx, vu16 *buffer) {
151 int buffer_index = (y * SCREEN_WIDTH + x) / 2; 129 int buffer_index = (y * SCREEN_WIDTH + x) / 2;
152 vu16 *destination = &buffer[buffer_index]; 130 vu16 *destination = &buffer[buffer_index];
153 // Odd pixels will go to the top 8 bits of the destination. Even pixels to 131 // Odd pixels will go to the top 8 bits of the destination. Even pixels to
154 // the lower 8 bits. 132 // the lower 8 bits.
155 int odd = x & 0x1; 133 int odd = x & 0x1;
156 if(odd) { 134 if(odd) {
157 *destination= (*destination & 0xFF) | (col_index << 8); 135 *destination= (*destination & 0xFF) | (clr_idx << 8);
158 } else { 136 } else {
159 *destination= (*destination & ~0xFF) | col_index; 137 *destination= (*destination & ~0xFF) | clr_idx;
138 }
139}
140
141static inline void
142put_pixel_m3(int x, int y, u16 color, Scanline *buffer) {
143 buffer[y][x] = color;
144}
145
146static inline void
147clear_screen_m4() {
148 size_t size = SCREEN_WIDTH * SCREEN_HEIGHT / 8;
149 u32 *buf = backbuffer;
150 for (size_t i = 0; i < size; ++i) {
151 buf[i] = 0;
160 } 152 }
161} 153}
162 154
@@ -205,24 +197,4 @@ draw_logo(void) {
205 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); 197 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE);
206} 198}
207 199
208// void
209// copy_font_to_tile_memory(Tile *tile) {
210// // Hex to bits translation table.
211// const u32 conversion_u32[16] = {
212// 0x00000000, 0x00001000, 0x00000100, 0x00001100,
213// 0x00000010, 0x00001010, 0x00000110, 0x00001110,
214// 0x00000001, 0x00001001, 0x00000101, 0x00001101,
215// 0x00000011, 0x00001011, 0x00000111, 0x00001111,
216// };
217// for (size_t i = 0; i < 250; ++i) {
218// for (size_t j = 0; j < 8; ++j) {
219// u8 row = font[i][j];
220// u32 tile_idx = 0x00000000;
221// tile_idx = conversion_u32[row & 0xF] << 16;
222// tile_idx |= conversion_u32[(row >> 4) & 0xF];
223// (tile + i)->data[j] = tile_idx;
224// }
225// }
226// }
227
228#endif // GBAEXP_BITMAP_H 200#endif // GBAEXP_BITMAP_H