From 56f916a7ea2beed167216e23a156754d38957402 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 20 Apr 2021 14:48:23 +0200 Subject: Add GBA button sprites and test their animations --- src/gba-buttons.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 140 +++++++++++++++++--------------- 2 files changed, 309 insertions(+), 64 deletions(-) create mode 100644 src/gba-buttons.c diff --git a/src/gba-buttons.c b/src/gba-buttons.c new file mode 100644 index 0000000..d9553a5 --- /dev/null +++ b/src/gba-buttons.c @@ -0,0 +1,233 @@ +u32 gba_buttons_tiles[224][8] = { + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x11000100, 0x01000010, 0x11000010}, + {0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001, 0x01000010, 0x01000001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x01000010, 0x11000010, 0x00000110, 0x00001100, 0x00110100, 0x11001000, 0x00110000}, + {0x01000010, 0x01000010, 0x01000001, 0x01100000, 0x00110000, 0x00101100, 0x00010011, 0x00001100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x11000100, 0x01000010}, + {0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001, 0x01000010}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000010, 0x01000010, 0x01000010, 0x11000010, 0x00000100, 0x00001100, 0x00111000, 0x11110000}, + {0x01000001, 0x01000010, 0x01000010, 0x01000001, 0x00100000, 0x00110000, 0x00011100, 0x00001111}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x10000000, 0x00000000, 0x11000100, 0x00110000, 0x00001000, 0x00000100, 0x11000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00100011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x11000010, 0x01000010, 0x01000010, 0x11000100, 0x00000100, 0x00001000, 0x00110010}, + {0x01000010, 0x01000001, 0x01000010, 0x01000010, 0x00100001, 0x00100000, 0x00010000, 0x01001100}, + {0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x10000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000010}, + {0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000001, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x11000100}, + {0x00000000, 0x10000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00111000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x11000010, 0x01000010, 0x01000010, 0x11000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000001, 0x01000010, 0x01000010, 0x00100001, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00011100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x10000000, 0x01000000, 0x00100000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x10000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000001, 0x00000010, 0x00000100, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100000, 0x01000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000010}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x11000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00001100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x11000010, 0x01000010, 0x01000010, 0x11000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000001, 0x01000010, 0x01000010, 0x00100001, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00110000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00100000, 0x00010000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00001000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x11000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x11000010, 0x01000010, 0x01000010, 0x11000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000001, 0x01000010, 0x01000010, 0x00100001, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00100000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00010000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00001000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x11000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x11000010, 0x01000010, 0x01000010, 0x11000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000001, 0x01000010, 0x01000010, 0x00100001, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x10000100, 0x01000010, 0x01000010}, + {0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001, 0x01000010, 0x01000010}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000010, 0x01000010, 0x01000010, 0x00000110, 0x00001100, 0x00110100, 0x11001000, 0x00110000}, + {0x01000011, 0x01000010, 0x01000010, 0x01100000, 0x00110000, 0x00101100, 0x00010011, 0x00001100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x10000100, 0x01000010}, + {0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001, 0x01000010}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x11000010, 0x01000010, 0x01000010, 0x00000100, 0x00001100, 0x00111000, 0x11110000}, + {0x01000010, 0x01000011, 0x01000010, 0x01000010, 0x00100000, 0x00110000, 0x00011100, 0x00001111}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x10000000, 0x00000000, 0x11000100, 0x00110000, 0x00001000, 0x00000100, 0x10000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00100011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x01000010, 0x11000010, 0x01000010, 0x01000100, 0x00000100, 0x00001000, 0x00110010}, + {0x01000010, 0x01000010, 0x01000011, 0x01000010, 0x00100010, 0x00100000, 0x00010000, 0x01001100}, + {0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x10000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000010}, + {0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000001, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x10000100}, + {0x00000000, 0x10000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00111000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x01000010, 0x11000010, 0x01000010, 0x01000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000010, 0x01000011, 0x01000010, 0x00100010, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00011100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x10000000, 0x01000000, 0x00100000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x10000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000001, 0x00000010, 0x00000100, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100000, 0x01000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000010}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x10000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00001100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x01000010, 0x11000010, 0x01000010, 0x01000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000010, 0x01000011, 0x01000010, 0x00100010, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00110000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00100000, 0x00010000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00001000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00100000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x10000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000100, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x01000010, 0x11000010, 0x01000010, 0x01000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000010, 0x01000011, 0x01000010, 0x00100010, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00100000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00010000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00001000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x00110000, 0x00001000, 0x00000100, 0x10000100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000011, 0x00001100, 0x00010000, 0x00100000, 0x00100001}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x01000010, 0x01000010, 0x11000010, 0x01000010, 0x01000100, 0x00000100, 0x00001000, 0x00110000}, + {0x01000010, 0x01000010, 0x01000011, 0x01000010, 0x00100010, 0x00100000, 0x00010000, 0x00001100}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x11000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000011, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, +}; + +// u16 palette[16] = { +// 0x7fff, 0x0000, 0x7fff, 0x7fff, +// 0x7fff, 0x7fff, 0x7fff, 0x7fff, +// 0x7fff, 0x7fff, 0x7fff, 0x7fff, +// 0x7fff, 0x7fff, 0x7fff, 0x7fff, +// }; diff --git a/src/main.c b/src/main.c index 740dbbf..d78dbe0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include "shorthand.h" #include "bd-font.c" +#include "gba-buttons.c" // // Memory sections. @@ -249,7 +250,7 @@ draw_fill_rect(int x0, int y0, int x1, int y1, Color clr) { } static inline void -wait_vsync() { +wait_vsync(void) { while(DISP_VCOUNT >= 160); while(DISP_VCOUNT < 160); } @@ -290,7 +291,7 @@ draw_fill_rect_m4(int x0, int y0, int x1, int y1, u8 col_index, vu16 *buffer) { } static inline void -flip_page() { +flip_page(void) { DISP_CTRL ^= DISP_PAGE; } @@ -323,7 +324,7 @@ flip_page() { // functions is called. Don't use if the code we are trying to profile make use // of these timers. static inline -void profile_start() { +void profile_start(void) { TIMER_DATA_2 = 0; TIMER_DATA_3 = 0; TIMER_CTRL_2 = 0; @@ -333,7 +334,7 @@ void profile_start() { } static inline -u32 profile_stop() { +u32 profile_stop(void) { TIMER_CTRL_2 = 0; return (TIMER_DATA_3 << 16) | TIMER_DATA_2; } @@ -364,7 +365,7 @@ static u16 key_curr = 0; static u16 key_prev = 0; static inline void -poll_keys() { +poll_keys(void) { key_prev = key_curr; key_curr = ~KEY_INPUTS & KEY_MASK; } @@ -388,7 +389,7 @@ key_hold(u32 key) { #define KEY_PRESSED(key) (~(KEY_INPUTS) & key) void -draw_logo() { +draw_logo(void) { int side = 60; int line = 35; int height = side * 0.5; @@ -472,20 +473,14 @@ typedef struct FontSprite { u32 pal_bank; } FontSprite; - -static u32 test_tiles[][8] = { - {0x33322111, 0x33322111, 0x33322111, 0x33322111, 0x33322111, 0x33322111, 0x33322111, 0x33322111}, - {0x00044000, 0x00044000, 0x00044000, 0x44444444, 0x44444444, 0x00044000, 0x00044000, 0x00044000}, - {0x44400444, 0x44400444, 0x44400444, 0x00000000, 0x00000000, 0x44400444, 0x44400444, 0x44400444}, - {0x11122333, 0x11122333, 0x11122333, 0x11122333, 0x11122333, 0x11122333, 0x11122333, 0x11122333}, -}; - -static u16 test_palette[16] = { - 0x0000, 0x001f, 0x03e0, 0x7c00, - 0x7fff, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000 -}; +typedef struct ButtonSprite { + int x; + int y; + int frame; + int n_frames; + u32 tile_index; + u32 pal_bank; +} ButtonSprite; int main(void) { // Configure the display in mode 0 to show OBJs, where tile memory is @@ -495,8 +490,7 @@ int main(void) { // Add colors to the sprite color palette. Tiles with color number 0 are // treated as transparent. for (size_t i = 0; i < 16; ++i) { - PAL_BUFFER_SPRITES[i] = test_palette[i]; - PAL_BUFFER_SPRITES[i + 16] = COLOR_WHITE; + PAL_BUFFER_SPRITES[i] = COLOR_WHITE; } // Initialize all attributes by disabling rendering. If we don't do this, @@ -508,45 +502,38 @@ int main(void) { size_t initial_tile = 512; Tile *tile_mem = &TILE_MEM[4][initial_tile]; - // Load bd-font as tiles. The full extended ASCII range (256 characters) - // will be available as an offset of the initial tile. For example, the - // uppercase A letter will be at tile index of 512 + 65. - copy_font_to_tile_memory(tile_mem); - // Test copying the exported tiles. - for (size_t i = 0; i < 4; ++i) { + for (size_t i = 0; i < 224; ++i) { for (size_t j = 0; j < 8; ++j) { - (tile_mem + i)->data[j] = test_tiles[i][j]; + (tile_mem + i)->data[j] = gba_buttons_tiles[i][j]; } } - // Initialize character sprites for all font chars. - FontSprite font_sprites[256] = {0}; - size_t x = 49; - size_t y = 8; - for (size_t i = 0; i < 256; ++i) { - if ((i % 16) == 0 && i != 0) { - y += 16; - x = 49; - } - font_sprites[i].x = x; - font_sprites[i].y = y; - font_sprites[i].tile_index = initial_tile + i; - font_sprites[i].animation_state = i % 56; - x += 8; - } - - // Number of characters to become sprites. - size_t n_chars = 128; - for (size_t i = 0; i < n_chars; ++i) { - OBJ_ATTR_0(i) = font_sprites[i].y; - OBJ_ATTR_1(i) = font_sprites[i].x; - if (i < 4) { - OBJ_ATTR_2(i) = font_sprites[i].tile_index; - } else { - OBJ_ATTR_2(i) = font_sprites[i].tile_index | (1 << 0xC); - } - } + // Initialize the A/B button sprites. + int buttons_x = SCREEN_WIDTH - 64 - 10; + int buttons_y = 120; + ButtonSprite btn_b = { + .x = buttons_x, + .y = buttons_y, + .frame = 0, + .n_frames = 6, + .tile_index = initial_tile, + .pal_bank = 0, + }; + OBJ_ATTR_0(0) = btn_b.y; + OBJ_ATTR_1(0) = btn_b.x | (1 << 0xF); + OBJ_ATTR_2(0) = btn_b.tile_index; + ButtonSprite btn_a = { + .x = buttons_x + 20, + .y = buttons_y - 16, + .frame = 0, + .n_frames = 6, + .tile_index = initial_tile + 16 * 7, + .pal_bank = 0, + }; + OBJ_ATTR_0(1) = btn_a.y; + OBJ_ATTR_1(1) = btn_a.x | (1 << 0xF); + OBJ_ATTR_2(1) = btn_a.tile_index; // draw_logo(); @@ -565,20 +552,45 @@ int main(void) { if (key_pressed(KEY_RIGHT) || key_hold(KEY_RIGHT)) { } if (key_pressed(KEY_B)) { + btn_b.frame = 1; + } else if (key_pressed(KEY_B) || key_hold(KEY_B)) { + // DEBUG: Slowing animation rate. What would be a better solution? + if (frame_counter++ % 3 == 0) { + if (btn_b.frame < btn_b.n_frames) { + btn_b.frame++; + } + } + } else { + if (btn_b.frame > 0 && btn_b.frame < btn_b.n_frames) { + btn_b.frame++; + } else { + btn_b.frame = 0; + } + } + if (key_pressed(KEY_A)) { + btn_a.frame = 1; + } else if (key_pressed(KEY_A) || key_hold(KEY_A)) { + // DEBUG: Slowing animation rate. What would be a better solution? + if (frame_counter++ % 3 == 0) { + if (btn_a.frame < btn_a.n_frames) { + btn_a.frame++; + } + } + } else { + if (btn_a.frame > 0 && btn_a.frame < btn_a.n_frames) { + btn_a.frame++; + } else { + btn_a.frame = 0; + } } if (key_pressed(KEY_L)) { } if (key_pressed(KEY_R)) { } - for (size_t i = 0; i < 128; ++i) { - int y = font_sprites[i].y; - y -= bouncing_animation[font_sprites[i].animation_state++]; - if (font_sprites[i].animation_state > 56) { - font_sprites[i].animation_state = 0; - } - OBJ_ATTR_0(i) = (OBJ_ATTR_0(i) & ~0xFF) | (y & 0xFF); - } + OBJ_ATTR_2(0) = btn_b.tile_index + 16 * btn_b.frame; + OBJ_ATTR_2(1) = btn_a.tile_index + 16 * btn_a.frame; + }; return 0; -- cgit v1.2.1