summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-06 13:40:20 +0200
committerBad Diode <bd@badd10de.dev>2021-05-06 13:40:20 +0200
commita170d44a34b03a4d0d475c38aac9651fbe666b33 (patch)
tree70d66b7d668ecc86d19194132fb6589f24d2d1ee
parent089f9ec86e90368c391c1c89e45301310cc7725a (diff)
downloadgba-experiments-a170d44a34b03a4d0d475c38aac9651fbe666b33.tar.gz
gba-experiments-a170d44a34b03a4d0d475c38aac9651fbe666b33.zip
Test drawing a wave pattern to the screen
-rw-r--r--src/bitmap.h80
-rw-r--r--src/main.c2
-rw-r--r--src/sequencer.c57
-rw-r--r--src/sprites.h1
4 files changed, 97 insertions, 43 deletions
diff --git a/src/bitmap.h b/src/bitmap.h
index 0befe5d..bae9b40 100644
--- a/src/bitmap.h
+++ b/src/bitmap.h
@@ -1,29 +1,29 @@
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" 4// #include "bd-font.c"
5#include "common.c" 5#include "common.h"
6 6
7// Using bd-font, an 8x8 bitmap font. 7// Using bd-font, an 8x8 bitmap font.
8static void 8// static void
9put_char(int x, int y, Color clr, u8 chr) { 9// put_char(int x, int y, Color clr, u8 chr) {
10 for (size_t i = 0; i < 8; ++i) { 10// for (size_t i = 0; i < 8; ++i) {
11 for (size_t j = 0; j < 8; ++j) { 11// for (size_t j = 0; j < 8; ++j) {
12 if ((font[chr][i] >> (7 - j)) & 0x1) { 12// if ((font[chr][i] >> (7 - j)) & 0x1) {
13 FRAMEBUFFER[y + i][x + j] = clr; 13// FRAMEBUFFER[y + i][x + j] = clr;
14 } 14// }
15 } 15// }
16 } 16// }
17} 17// }
18 18
19static void 19// static void
20put_text(int x, int y, Color clr, char *msg) { 20// put_text(int x, int y, Color clr, char *msg) {
21 int count = 0; 21// int count = 0;
22 while (*msg) { 22// while (*msg) {
23 put_char(x + count, y, clr, *msg++); 23// put_char(x + count, y, clr, *msg++);
24 count += 8; 24// count += 8;
25 } 25// }
26} 26// }
27 27
28// Draws a line with the given color between (x0,y0) and (x1,y1) using the 28// 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. 29// Bresenham's line drawing algorithm using exclusively integer arithmetic.
@@ -205,24 +205,24 @@ draw_logo(void) {
205 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); 205 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE);
206} 206}
207 207
208void 208// void
209copy_font_to_tile_memory(Tile *tile) { 209// copy_font_to_tile_memory(Tile *tile) {
210 // Hex to bits translation table. 210// // Hex to bits translation table.
211 const u32 conversion_u32[16] = { 211// const u32 conversion_u32[16] = {
212 0x00000000, 0x00001000, 0x00000100, 0x00001100, 212// 0x00000000, 0x00001000, 0x00000100, 0x00001100,
213 0x00000010, 0x00001010, 0x00000110, 0x00001110, 213// 0x00000010, 0x00001010, 0x00000110, 0x00001110,
214 0x00000001, 0x00001001, 0x00000101, 0x00001101, 214// 0x00000001, 0x00001001, 0x00000101, 0x00001101,
215 0x00000011, 0x00001011, 0x00000111, 0x00001111, 215// 0x00000011, 0x00001011, 0x00000111, 0x00001111,
216 }; 216// };
217 for (size_t i = 0; i < 250; ++i) { 217// for (size_t i = 0; i < 250; ++i) {
218 for (size_t j = 0; j < 8; ++j) { 218// for (size_t j = 0; j < 8; ++j) {
219 u8 row = font[i][j]; 219// u8 row = font[i][j];
220 u32 tile_idx = 0x00000000; 220// u32 tile_idx = 0x00000000;
221 tile_idx = conversion_u32[row & 0xF] << 16; 221// tile_idx = conversion_u32[row & 0xF] << 16;
222 tile_idx |= conversion_u32[(row >> 4) & 0xF]; 222// tile_idx |= conversion_u32[(row >> 4) & 0xF];
223 (tile + i)->data[j] = tile_idx; 223// (tile + i)->data[j] = tile_idx;
224 } 224// }
225 } 225// }
226} 226// }
227 227
228#endif // GBAEXP_BITMAP_H 228#endif // GBAEXP_BITMAP_H
diff --git a/src/main.c b/src/main.c
index 48538fb..05bfa26 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,7 +18,7 @@
18int main(void) { 18int main(void) {
19 // Configure the display in mode 0 to show OBJs, where tile memory is 19 // Configure the display in mode 0 to show OBJs, where tile memory is
20 // sequential. 20 // sequential.
21 DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_0 | DISP_BG_0; 21 DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_3 | DISP_BG_2;
22 22
23 // Initialize text engine. 23 // Initialize text engine.
24 // txt_init(0, COLOR_RED, 0); 24 // txt_init(0, COLOR_RED, 0);
diff --git a/src/sequencer.c b/src/sequencer.c
index 1447056..fccc42a 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -1,3 +1,5 @@
1#include "bitmap.h"
2
1// Positioning parameters. 3// Positioning parameters.
2#define SEQ_TRIG_POS_X 45 4#define SEQ_TRIG_POS_X 45
3#define SEQ_TRIG_POS_Y 50 5#define SEQ_TRIG_POS_Y 50
@@ -493,7 +495,53 @@ init_sequencer_sprites(void) {
493 init_sprite_pal(16, COLOR_CYAN); 495 init_sprite_pal(16, COLOR_CYAN);
494 init_sprite_pal(32, COLOR_RED); 496 init_sprite_pal(32, COLOR_RED);
495 init_sprite_pal(48, COLOR_GREY); 497 init_sprite_pal(48, COLOR_GREY);
496 init_sprites(0); 498 init_sprites(512);
499
500 // draw_rect(SEQ_ENV_POS_X-1,
501 // SEQ_ENV_POS_Y-1,
502 // SEQ_ENV_POS_X + 62 + 1,
503 // SEQ_ENV_POS_Y + 16 + 1,
504 // COLOR_WHITE);
505
506 // Clear wave drawing
507 draw_fill_rect(SEQ_ENV_POS_X,
508 SEQ_ENV_POS_Y,
509 SEQ_ENV_POS_X + 62,
510 SEQ_ENV_POS_Y + 16,
511 COLOR_BLACK);
512
513 // DEBUG: Testing line drawing
514 // draw_line(
515 // SEQ_ENV_POS_X,
516 // SEQ_ENV_POS_Y,
517 // SEQ_ENV_POS_X + 62,
518 // SEQ_ENV_POS_Y + 16,
519 // COLOR_RED);
520
521 // NOTE: Trying to draw this pattern.
522 // 0xEFDEBC89
523 // 0x98CBEDFE
524 // 0x10214376
525 // 0x67341201
526 u8 sine_wave[] = {
527 0x89, 0xBC, 0xDE, 0xEF,
528 0xFE, 0xED, 0xCB, 0x98,
529 0x76, 0x43, 0x21, 0x10,
530 0x01, 0x12, 0x34, 0x67,
531 };
532 // DEBUG: Drawing each byte.
533 int x = SEQ_ENV_POS_X;
534 int y = SEQ_ENV_POS_Y + 16;
535 for (size_t i = 0; i < 16; ++i) {
536 u8 byte = sine_wave[i];
537 u8 first = (byte >> 4) & 0xF;
538 u8 second = byte & 0xF;
539 FRAMEBUFFER[y - first][x + i * 4] = COLOR_RED;
540 FRAMEBUFFER[y - first][x + i * 4 + 1] = COLOR_RED;
541 FRAMEBUFFER[y - second][x + i * 4 + 2] = COLOR_RED;
542 FRAMEBUFFER[y - second][x + i * 4 + 3] = COLOR_RED;
543 }
544
497 545
498 // Sprite note names. 546 // Sprite note names.
499 size_t sprite_id = load_packed_sprite_data(&sprite_note_names, 2, 73); 547 size_t sprite_id = load_packed_sprite_data(&sprite_note_names, 2, 73);
@@ -828,7 +876,7 @@ update_sequencer_sprites(void) {
828 // 000-015: Step note names. 876 // 000-015: Step note names.
829 for (size_t i = 0; i < 16; ++i) { 877 for (size_t i = 0; i < 16; ++i) {
830 // Each note name is made of 2 8x8 tiles (16x8). 878 // Each note name is made of 2 8x8 tiles (16x8).
831 size_t base_tile = sequences[channel_selection_loc][i].note * 2; 879 size_t base_tile = seq_sprites[i].base_tile + sequences[channel_selection_loc][i].note * 2;
832 880
833 // TODO: Show the note name if is within the duration, hide when trigger 881 // TODO: Show the note name if is within the duration, hide when trigger
834 // is off or duration of previous note was cut short. If not triggered 882 // is off or duration of previous note was cut short. If not triggered
@@ -964,6 +1012,11 @@ update_sequencer_sprites(void) {
964 seq_sprites[56].obj_attr_2 = base_tile | OBJ_PAL_BANK(3); 1012 seq_sprites[56].obj_attr_2 = base_tile | OBJ_PAL_BANK(3);
965 } 1013 }
966 } 1014 }
1015
1016 // DEBUG: Hide all parameter control sprites for now.
1017 for (size_t i = 34; i <= 50; ++i) {
1018 seq_sprites[i].obj_attr_0 = seq_sprites[i].obj_attr_0 | OBJ_HIDDEN;
1019 }
967} 1020}
968 1021
969void 1022void
diff --git a/src/sprites.h b/src/sprites.h
index 0b55f0d..a64b784 100644
--- a/src/sprites.h
+++ b/src/sprites.h
@@ -64,6 +64,7 @@ init_sprites(size_t starting_tile) {
64 sprite_counter = 0; 64 sprite_counter = 0;
65 // Prepare global sprite_memory address. 65 // Prepare global sprite_memory address.
66 sprite_memory = &TILE_MEM[4][starting_tile]; 66 sprite_memory = &TILE_MEM[4][starting_tile];
67 sprite_tile_counter = starting_tile;
67} 68}
68 69
69void 70void