From 74d6b52636ecdd560995f22dff5b29a59fc62d5d Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 22 Apr 2021 17:34:38 +0200 Subject: Test background scrolling with input control --- src/background-tiles.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 72 ++++++++++-- 2 files changed, 361 insertions(+), 8 deletions(-) create mode 100644 src/background-tiles.c diff --git a/src/background-tiles.c b/src/background-tiles.c new file mode 100644 index 0000000..9d1ad15 --- /dev/null +++ b/src/background-tiles.c @@ -0,0 +1,297 @@ +const u32 bg_data[792] = { + 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + 0x08000080,0x08000080,0x0866DD80,0x08000080,0x08000080,0x08000080,0x0866DD80,0x08000080, + 0x0B000080,0x0B000080,0x0BDD6680,0x0B000080,0x0B000080,0x0B000080,0x0BDD6680,0x0B000080, + 0x00000000,0x00000000,0x00000000,0x44444400,0x77777F40,0x44447FA4,0xEEEEEFF4,0xEEEEEEF4, + 0x00000000,0x00000000,0x00000000,0x00044444,0x004F4747,0x04AF4444,0x04FFEEEE,0x04FEEEEE, + 0x00000000,0x70000000,0x00000700,0x7000DDD0,0x0000700D,0x07770000,0x00000000,0x00000000, + 0x00000077,0x00000777,0x00000707,0xD000D077,0x70000DDD,0x07770777,0x00000070,0x00000707, + 0x00000000,0x00000000,0x00000007,0x0000000D,0x000000D0,0x00000000,0x00000000,0x00000000, + + 0x00040000,0x00404000,0x04050400,0x04050400,0x004D4000,0x004D4000,0x00080000,0x000D0000, + 0xAAAAAA64,0x77FFFFF4,0xC7EEEEC4,0x44EEEEC4,0xFFEEEEC4,0xEEEEEFC4,0xCCCCCCC4,0x44444444, + 0x046AAAAA,0x04FFFFF7,0x04CEEEE4,0x04CEEEE4,0x04CEEEEF,0x04CFEEEE,0x04CCCCCC,0x04444444, + 0x00000000,0x00000000,0x70000000,0x70000000,0x70000000,0xDD000000,0x70000000,0x00000000, + 0x00000070,0x00000777,0x00000700,0x00000700,0x00D07000,0x000DD00D,0x00070000,0x00000000, + 0x55555550,0x22525555,0x25255555,0x22525525,0x22225252,0x22222222,0x22222225,0x22222225, + 0x05555555,0x22222225,0x44222222,0x42422222,0x44222222,0x44222222,0x42422222,0x44422222, + 0x55555555,0x65655656,0x55525555,0x65562255,0x22266222,0x02006662,0x22200606,0x22006666, + + 0x0B000084,0x0B000084,0x0BDD6684,0x0B000084,0x0B000084,0x0B000084,0x0BDD6684,0x0B000084, + 0x05555555,0x02665555,0x02266265,0x02262226,0x00266666,0x02066002,0x02666602,0x00606000, + 0x44222555,0x42222222,0x44222222,0x42424222,0x44442422,0x44444242,0x44444444,0x44444444, + 0x42555552,0x42252555,0x42222255,0x42222525,0x42222252,0x42222222,0x44222224,0x44442244, + 0x22222222,0x22222222,0x22222222,0x22222224,0x22222224,0x42222224,0x24242244,0x44444440, + 0x44242222,0x44424422,0x44444222,0x44442422,0x44444224,0x44442442,0x44444424,0x04444444, + 0x66606600,0x60000060,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + 0x00066600,0x00600006,0x00006006,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + + 0x22222220,0x66262222,0x62622222,0x66262262,0x66662626,0x66666666,0x66666662,0x66666662, + 0x02222222,0x66666662,0x44666666,0x46466666,0x44666666,0x44666666,0x46466666,0x44466666, + 0x46222226,0x46626222,0x46666622,0x46666262,0x46666626,0x46666666,0x44666664,0x44446644, + 0x06666666,0x66666666,0x66666660,0x66666000,0x06666006,0x00000066,0x00000066,0x00000066, + 0x00000000,0x00000000,0x00000000,0x00B0000B,0x0B00000B,0x0B0B000B,0x010B00B1,0x01010B01, + 0x00000000,0x00000000,0x00000B00,0x000000B0,0x000010B0,0x0B010010,0x01010010,0x01010001, + 0x00000000,0x00000000,0x000000B0,0x0000000B,0x0000100B,0xB0001001,0x01010001,0x01010B01, + 0x00000000,0x00000000,0x00000000,0x0B00000B,0x00B000B0,0x0B00B0B0,0x010B0001,0x01010B01, + + 0x66666666,0x66666666,0x66666666,0x66666664,0x66666664,0x46666664,0x64646644,0x44444440, + 0x44646666,0x44464466,0x44444666,0x44446466,0x44444664,0x44446446,0x44444464,0x04444444, + 0x05550555,0x02250225,0x06220622,0x06660666,0x00000000,0x06060606,0x00000000,0x00000000, + 0x05520264,0x06220666,0x06660664,0x06440644,0x00000000,0x06040604,0x00000000,0x00000000, + 0x00000000,0x00666660,0x00600060,0x00606060,0x00600060,0x00666660,0x00000000,0x00000000, + 0x06666600,0x06666660,0x06666660,0x00066660,0x60066600,0x66000000,0x66000000,0x00000000, + 0x00666000,0x06660066,0x06606666,0x00006666,0x00000660,0x06660000,0x06600666,0x00006666, + 0x00000000,0xC444444C,0xFEEEEEEF,0xCFFFFFFC,0xFEECCEEF,0xCEECCEEC,0xCEEEEEEC,0xCCCCCCCC, + + 0x43999993,0x43393999,0x43333399,0x43333939,0x43333393,0x43333333,0x44333334,0x44443344, + 0x4A33333A,0x4AA3A333,0x4AAAAA33,0x4AAAA3A3,0x4AAAAA3A,0x4AAAAAAA,0x44AAAAA4,0x4444AA44, + 0x00000000,0xEEEEEEE0,0x44444440,0x44A8AAF0,0x44A8AAF0,0x44AA8AF0,0x444AAAE0,0x44444AE0, + 0x00000000,0x0EEEEEEE,0x04444444,0x0FAAA444,0x0FA8A444,0x0FA8A444,0x0EA8A444,0x0EA8A444, + 0x0B0000D0,0x06000080,0x060066D0,0x060000D0,0x00000060,0x06000060,0x06000660,0x00000060, + 0x33333330,0xAA3A3333,0xA3A33333,0xAA3A33A3,0xAAAA3A3A,0xAAAAAAAA,0xAAAAAAA3,0xAAAAAAA3, + 0x03333333,0xAAAAAAA3,0x44AAAAAA,0x4A4AAAAA,0x44AAAAAA,0x44AAAAAA,0x4A4AAAAA,0x444AAAAA, + 0x4CCCCCCC,0x4C33333C,0x4C3CCC3C,0x4C3C3C3C,0x4C3C3C3C,0x4CCC333C,0x44CCCCCC,0x44444444, + + 0x44141111,0x44414411,0x44444111,0x44441411,0x44444114,0x44441441,0x44444414,0x04444444, + 0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0, + 0x0EA8A444,0x0EA8A444,0x0EA8A444,0x0EA8A444,0x0EA8A444,0x0EA8A444,0x0EA8A444,0x0EA8A444, + 0x99999444,0x99999494,0x99999944,0x99999944,0x99999494,0x99999944,0xA9999999,0xAAAAAAA0, + 0xAAAAAAA0,0x99A9AAAA,0x9A9AAAAA,0x99A9AA9A,0x9999A9A9,0x99999999,0x9999999A,0x9999999A, + 0x44A4AAAA,0x444A44AA,0x44444AAA,0x4444A4AA,0x44444AA4,0x4444A44A,0x444444A4,0x04444444, + 0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x444444E0,0x44444440, + 0x0EA8A444,0x0EA8A444,0x0EAAA444,0x0EAAA444,0x0EA8A444,0x0EA8A444,0x0EAAA444,0x04444444, + + 0xAAAAAAA0,0x11A1AAAA,0x1A1AAAAA,0x11A1AA1A,0x1111A1A1,0x11111111,0x1111111A,0x1111111A, + 0x0AAAAAAA,0x1111111A,0x44111111,0x41411111,0x44111111,0x44111111,0x41411111,0x44411111, + 0x00000000,0x88882D20,0x66D26602,0x0D0D080D,0xD0020602,0x88882D20,0x00000600,0x00000600, + 0x00000000,0x88888888,0x66D666D6,0x0D000D00,0xD000D000,0x88888888,0x00000000,0x00000000, + 0x00008800,0x888D8888,0x66D688D6,0x0D007700,0xD0007700,0x888D6688,0x00006600,0x00000000, + 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00200000,0x20200000,0x02000000, + 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x20000000,0x00000000,0x20000000, + 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00020000,0x00002002,0x00020220, + + 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x07070000,0x00700000,0x00700700, + 0x00100101,0x00100B0B,0xB0B00010,0xB1B000B0,0x0010B0B0,0x00BBB000,0x00000000,0x00000000, + 0x99999999,0x99999999,0x99999999,0x99999994,0x99999994,0x49999994,0x94949944,0x44444440, + 0x44949999,0x44494499,0x44444999,0x44449499,0x44444994,0x44449449,0x44444494,0x04444444, + 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAA4,0xAAAAAAA4,0x4AAAAAA4,0xA4A4AA44,0x44444440, + 0x11111111,0x11111111,0x11111111,0x11111114,0x11111114,0x41111114,0x14141144,0x44444440, + 0x00AAAA00,0x0AAA1110,0x0A111100,0x00111101,0x00000000,0x001AA000,0x01A11100,0x01100010, + 0x00024000,0x00042000,0x000D4000,0x0004D000,0x0008D000,0x000D8000,0x000D8000,0x000DD000, + + 0x02000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + 0x00000000,0x00000000,0x70000222,0x000D2200,0x0DD22000,0xDDD20000,0xD2200000,0x22000000, + 0x00000200,0x00000200,0x00022070,0x00220077,0x00220070,0x02220770,0x0222077D,0x022077DD, + 0x00077000,0x00070700,0x00070000,0x00007700,0x00000700,0x00000700,0x00000770,0x00000777, + 0x01000000,0x00100000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + 0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x20000000,0x02000000, + 0x72227DD2,0x72222222,0x72222220,0x77222220,0x07722202,0x00712222,0x00011220,0x00010202, + 0x00000077,0x00000077,0x00000077,0x00000007,0x00000000,0x00000000,0x00000000,0x00000000, + + 0x000B0010,0x010B00B0,0x010B00B0,0x011B00B0,0x00B000B0,0x00B000B0,0x00B00000,0x00B00000, + 0x00000000,0x00000000,0x00000000,0x00000000,0x11100000,0x11111000,0x21111100,0x12121110, + 0x22200000,0x02221000,0x20222100,0x22221211,0x11222111,0x11121211,0x11212121,0x00121212, + 0x00011120,0x00001012,0x00001102,0x00001010,0x00011101,0x00011011,0x00101111,0x01010100, + 0x41AAAAA1,0x411A1AAA,0x411111AA,0x41111A1A,0x411111A1,0x41111111,0x44111114,0x44441144, + 0x33333330,0xA3333333,0xAAAA3333,0xAAAAA333,0xAAAAAAA3,0xAAAAAAAA,0xAAAAAAA4,0x44444440, + 0x0AAAA333,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0x44AAAAAA,0x4444AAAA,0x4444444A,0x04444444, + 0x04AAA333,0x4AAAAAAA,0x4A4AAAAA,0x44A4AAAA,0x444A4AAA,0x4444A4A4,0x4444444A,0x04444444, + + 0x03333333,0x3333333A,0x3333AAAA,0x333AAAAA,0x3AAAAAAA,0xAAAAAAAA,0x4AAAAAA4,0x04444444, + 0x04AAAAA0,0x477AAAAA,0x47777AAA,0x47777AAA,0x477777AA,0x4777777A,0x44777774,0x04447740, + 0x44AAAAAA,0x44AAAAAA,0x444AAAAA,0x4444AAAA,0x4444AAAA,0x4444AAAA,0x444444AA,0x04444444, + 0x04333330,0x4AA33333,0x4AAAA333,0x4AAAA333,0x4AAAAA33,0x4AAAAAAA,0x44AAAAA4,0x0444AA40, + 0x080000D0,0x06000080,0x060066D0,0x060000D0,0x00000060,0x06000060,0x06000660,0x00000060, + 0x000AAAA0,0x10111AAA,0x1001111A,0x01011110,0x00000000,0x0000AA10,0x000111A1,0x00100011, + 0x00AAAAAA,0x0111AAA1,0x011A1111,0x00111111,0x00011110,0x00001100,0x00000010,0x00000000, + 0x0AAAAAA0,0x11AAA111,0x11111A11,0x01111110,0x00111100,0x00011000,0x00100000,0x00000000, + + 0x00000C00,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + 0x0000000C,0x000000C0,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, + 0x0D000000,0x00D00000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, +}; + +const u16 bg_map[1024] = { + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0001,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0002,0x0003,0x0004,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0005, + 0x0006,0x0007,0x0000,0x0000,0x0000,0x0008,0x0000,0x0000, + 0x0000,0x0002,0x0009,0x000A,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000B, + 0x000C,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0002,0x000D,0x000E,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000D, + 0x000E,0x000F,0x0010,0x000F,0x000F,0x000F,0x000F,0x0011, + 0x0012,0x0013,0x0014,0x0015,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0008,0x0000,0x0000,0x0000,0x0014, + 0x0015,0x0016,0x0002,0x0016,0x0016,0x0016,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0008,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x001C,0x001D,0x001E,0x001F,0x0013,0x0018, + 0x0019,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0020,0x0021,0x001B,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0022,0x0022,0x0012,0x001A,0x0019,0x0019,0x001A,0x0020, + 0x0021,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x001A,0x001B,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0023,0x0022,0x0022,0x0022,0x0022,0x0022, + + 0x0024,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0019, + 0x0021,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0025,0x0026,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0024,0x0000,0x0024,0x0000,0x0024,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x1027,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0008,0x0000,0x0000, + 0x0028,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0028, + 0x0029,0x0000,0x0000,0x0000,0x0000,0x002A,0x002B,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x002C,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0002,0x002D,0x002E,0x0028,0x002F, + 0x0030,0x0000,0x0000,0x0000,0x0000,0x0031,0x0032,0x0000, + + 0x001E,0x001F,0x0028,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0002,0x0033,0x0C33,0x0034,0x0035, + 0x0435,0x0000,0x0034,0x0C33,0x0000,0x0036,0x0037,0x001E, + 0x0038,0x0039,0x0035,0x0000,0x103A,0x003B,0x003C,0x043C, + 0x043B,0x043A,0x103D,0x103E,0x103F,0x1040,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x1041,0x1441, + 0x0000,0x0000,0x1042,0x1043,0x0038,0x0039,0x0044,0x0035, + + 0x0045,0x0030,0x0046,0x0000,0x0047,0x0000,0x0000,0x0000, + 0x0000,0x0047,0x1048,0x1049,0x104A,0x104B,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0045,0x0030,0x0000,0x0000, + 0x0000,0x0000,0x004C,0x0000,0x0047,0x0000,0x0000,0x0000, + 0x0000,0x0047,0x0000,0x104D,0x104E,0x104F,0x0000,0x0008, + 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0047,0x0000,0x1050,0x0000, + 0x0000,0x0047,0x1051,0x1052,0x1053,0x0000,0x0000,0x001E, + 0x001F,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x002D,0x002E,0x0029,0x0029, + 0x0C33,0x0054,0x0055,0x0056,0x002E,0x0057,0x0058,0x0055, + 0x0056,0x0401,0x0057,0x0059,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0044,0x0035,0x0000,0x1042, + 0x1043,0x1042,0x1042,0x1042,0x005A,0x0044,0x0035,0x005B, + 0x0059,0x005C,0x0044,0x0035,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x005D,0x005E,0x0000,0x005F, + 0x0046,0x0000,0x0000,0x181D,0x181E,0x181D,0x181E,0x0060, + 0x0061,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1062, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0C5C,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0801,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0801,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, +}; + +const u16 bg_palette[256] = { + 0x0000,0x0846,0x310A,0x0015,0x1062,0x4DD0,0x18A5,0x4F5E, + 0x31F2,0x007F,0x042B,0x0966,0x1D00,0x1D2D,0x1D75,0x10CF, + 0x097F,0x04A4,0x10A7,0x3580,0x36DF,0x02BF,0x0865,0x1483, + 0x2944,0x0867,0x1CE2,0x35F2,0x0886,0x0887,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, +}; diff --git a/src/main.c b/src/main.c index 0af41f8..4dd2554 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include "shorthand.h" #include "bd-font.c" #include "gba-buttons.c" +#include "background-tiles.c" // // Memory sections. @@ -46,10 +47,34 @@ #define DISP_ENABLE_SPRITES DISP_OBJ | DISP_OBJ_1D // Registers to control of BG layers. -#define BG_CTRL_0 *((vu16*)(0x04000008 + 0x0000)) -#define BG_CTRL_1 *((vu16*)(0x04000008 + 0x0002)) -#define BG_CTRL_2 *((vu16*)(0x04000008 + 0x0004)) -#define BG_CTRL_3 *((vu16*)(0x04000008 + 0x0006)) +#define BG_CTRL_0 *((vu16*)(0x04000008 + 0x0002 * 0)) +#define BG_CTRL_1 *((vu16*)(0x04000008 + 0x0002 * 1)) +#define BG_CTRL_2 *((vu16*)(0x04000008 + 0x0002 * 2)) +#define BG_CTRL_3 *((vu16*)(0x04000008 + 0x0002 * 3)) + +// Bits to control the background. +#define BG_PRIORITY_0 0x0 +#define BG_PRIORITY_1 0x1 +#define BG_PRIORITY_2 0x2 +#define BG_PRIORITY_3 0x3 +#define BG_CHARBLOCK(N) ((N) << 2) +#define BG_MOSAIC (1 << 6) +#define BG_HIGH_COLOR (1 << 7) +#define BG_SCREENBLOCK(N) ((N) << 8) +#define BG_AFFINE (1 << 0xD) +#define BG_SIZE(N) ((N) << 0xE) + +// BG registers for horizontal displacement. +#define BG_H_SCROLL_0 *((vu16*)(0x04000010 + 0x0004 * 0)) +#define BG_H_SCROLL_1 *((vu16*)(0x04000010 + 0x0004 * 1)) +#define BG_H_SCROLL_2 *((vu16*)(0x04000010 + 0x0004 * 2)) +#define BG_H_SCROLL_3 *((vu16*)(0x04000010 + 0x0004 * 3)) + +// BG registers for vertical displacement. +#define BG_V_SCROLL_0 *((vu16*)(0x04000012 + 0x0004 * 0)) +#define BG_V_SCROLL_1 *((vu16*)(0x04000012 + 0x0004 * 1)) +#define BG_V_SCROLL_2 *((vu16*)(0x04000012 + 0x0004 * 2)) +#define BG_V_SCROLL_3 *((vu16*)(0x04000012 + 0x0004 * 3)) // Screen settings. #define SCREEN_WIDTH 240 @@ -69,9 +94,11 @@ typedef struct Tile { } Tile; typedef Tile TileBlock[512]; - #define TILE_MEM ((TileBlock*) MEM_VRAM) +typedef u16 ScreenBlock[1024]; +#define SCREENBLOCK_MEM ((ScreenBlock*)MEM_VRAM) + // We can treat the screen as a HxW matrix. With the following macro we can // write a pixel to the screen at the (x, y) position using: // @@ -524,9 +551,6 @@ load_packed_sprite_data(u32 *sprite_data, size_t n_tiles, size_t n_frames) { } int main(void) { - // Configure the display in mode 0 to show OBJs, where tile memory is - // sequential. - DISP_CTRL = DISP_MODE_0 | DISP_ENABLE_SPRITES | DISP_BG_2; // Add colors to the sprite color palette. Tiles with color number 0 are // treated as transparent. @@ -543,6 +567,21 @@ int main(void) { sprite_tile_counter = 0; sprite_memory = &TILE_MEM[4][sprite_tile_counter]; + // Load background palette. + memcpy(&PAL_BUFFER_BG[0], &bg_palette, 512); + memcpy(&TILE_MEM[0][0], bg_data, 3168); + memcpy(&SCREENBLOCK_MEM[30][0], bg_map, 2048); + + // Configure BG0 to use 4bpp, 64x32 tile map in charblock 0 and screenblock + // 31. + BG_CTRL_0 = BG_CHARBLOCK(0) | BG_SCREENBLOCK(30) | BG_SIZE(0); + BG_H_SCROLL_0 = 0; + BG_V_SCROLL_0 = 0; + + // Configure the display in mode 0 to show OBJs, where tile memory is + // sequential. + DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_0 | DISP_BG_0; + // Initialize the A/B button sprites. int buttons_x = SCREEN_WIDTH / 2; int buttons_y = SCREEN_HEIGHT / 2; @@ -635,6 +674,8 @@ int main(void) { OBJ_ATTR_2(btn_r.id) = sprites[btn_r.id].tile_start; int frame_counter = 0; + int x = 0; + int y = 0; while(true) { wait_vsync(); poll_keys(); @@ -784,6 +825,19 @@ int main(void) { } } + if (key_hold(KEY_DOWN)) { + y += 3; + } + if (key_hold(KEY_UP)) { + y -= 3; + } + if (key_hold(KEY_LEFT)) { + x -= 3; + } + if (key_hold(KEY_RIGHT)) { + x += 3; + } + OBJ_ATTR_2(btn_b.id) = sprites[btn_b.id].tile_start + animation_states[btn_b.state]->tile_offsets[btn_b.frame]; OBJ_ATTR_2(btn_a.id) = sprites[btn_a.id].tile_start + animation_states[btn_a.state]->tile_offsets[btn_a.frame]; OBJ_ATTR_2(btn_up.id) = sprites[btn_up.id].tile_start + animation_states[btn_up.state]->tile_offsets[btn_up.frame]; @@ -793,6 +847,8 @@ int main(void) { OBJ_ATTR_2(btn_l.id) = sprites[btn_l.id].tile_start + animation_states[btn_l.state]->tile_offsets[btn_l.frame]; OBJ_ATTR_2(btn_r.id) = sprites[btn_r.id].tile_start + animation_states[btn_r.state]->tile_offsets[btn_r.frame]; frame_counter++; + BG_H_SCROLL_0 = x; + BG_V_SCROLL_0 = y; }; return 0; -- cgit v1.2.1