From 035bc86a07893dcf5849c1d6351a216a2d954e03 Mon Sep 17 00:00:00 2001 From: nytpu Date: Sat, 15 Jun 2024 14:14:44 -0600 Subject: [PATCH] add keystroke programming demo --- res/tiles.ase | Bin 0 -> 423 bytes res/tiles.grit | 1 + res/tiles.png | Bin 0 -> 270 bytes src/main.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 res/tiles.ase create mode 100644 res/tiles.grit create mode 100644 res/tiles.png diff --git a/res/tiles.ase b/res/tiles.ase new file mode 100644 index 0000000000000000000000000000000000000000..8864aa810107f35ae17d4d60abe320e091c7b9de GIT binary patch literal 423 zcmZ3^$iVPmDI>!Q1`Z$uau`y87y+0W7(s$yS%fI{Sn5F2e|=;D+sXnoRt$*Q6~I;^ zSt1N%vw&R3{Qv)dARCC4Ktc-qNQyubTntW$$=T^e`K5U&XMlWG1&D(GOc0s@?9qxj zM}r-Ojwo;#|NmdYFEW{-%({AIyAp@Wq+Qpxb35GJqjAz#%t_~+umW@9+4!FMzi($g zbCP{&wnfoVOim~N@z$jGcEUz1$D407vZV)1yuI?zgUrwCY|K{|{dpVQM iUgd>}E>`E8&wcykcGrB*)4egDH@`FA$q*pV7zP0EL}?)a literal 0 HcmV?d00001 diff --git a/res/tiles.grit b/res/tiles.grit new file mode 100644 index 0000000..a2d820d --- /dev/null +++ b/res/tiles.grit @@ -0,0 +1 @@ +-g -m! -p -gB4 diff --git a/res/tiles.png b/res/tiles.png new file mode 100644 index 0000000000000000000000000000000000000000..e7ded74da8f6489e048c7ee54e694fcd524e055b GIT binary patch literal 270 zcmeAS@N?(olHy`uVBq!ia0vp^D}b1TgBeIhb-H8#DaPU;cPEB*=VV?2Ih+ALA+G=b z{|7RG_`u1z8-T3Mo-U3d7QII&I|{WLa5&HY9e<1Ul8VFMbN633={SA%T9#e=he1O= zzv`2+wW8p6c?Ds?+`TjG-{;qF7TY!9?y_2s6X%?t6z&OswD-IU@5PTQWs6Sk3==7z zCcnV!BiF8tZtNu;(oI`8YAle+wA{fN^13y9)4Tzopr06z?GlmGw# literal 0 HcmV?d00001 diff --git a/src/main.c b/src/main.c index 7761fca..2f1b08e 100644 --- a/src/main.c +++ b/src/main.c @@ -4,33 +4,114 @@ */ #include "game.h" +#include "tiles.h" #include #include -typedef void colt45; +enum LineValue { + START, + UP_ARROW, + DOWN_ARROW, + LEFT_ARROW, + RIGHT_ARROW, + NOP, + END, +}; -colt45****** shootin_iron; // got my shootin' iron loaded +enum LineValue lines[20] = { [0] = START }; +const size_t linesLen = sizeof(lines) / sizeof(lines[0]); +size_t lineSelected = 0; -bool vBlankTriggered = false; +void +redrawLines(void) +{ + size_t line = 0; + for (; line < linesLen; line++) { + const size_t baseID = line*32; + se_mem[30][baseID + 1] = ((line / 10) + 1) & 0x3ff; + se_mem[30][baseID + 2] = ((line % 10) + 1) & 0x3ff; + se_mem[30][baseID + 3] = 11; + if (line == lineSelected) se_mem[30][baseID + 4] = 12; + else se_mem[30][baseID + 4] = 0; + const size_t symbolID = baseID + 5; + se_mem[30][symbolID] = 0; + se_mem[30][symbolID+1] = 0; + switch (lines[line]) { + break; case START: + se_mem[30][symbolID] = SE_BUILD(17, 0, 0, 0); + se_mem[30][symbolID+1] = SE_BUILD(18, 0, 0, 0); + break; case UP_ARROW: se_mem[30][symbolID] = SE_BUILD(13, 0, 0, 0); + break; case DOWN_ARROW: se_mem[30][symbolID] = SE_BUILD(13, 0, 0, 1); + break; case RIGHT_ARROW: se_mem[30][symbolID] = SE_BUILD(14, 0, 0, 0); + break; case LEFT_ARROW: se_mem[30][symbolID] = SE_BUILD(14, 0, 1, 0); + break; case NOP: se_mem[30][symbolID] = SE_BUILD(15, 0, 0, 0); + break; case END: + se_mem[30][symbolID] = SE_BUILD(19, 0, 0, 0); + se_mem[30][symbolID+1] = SE_BUILD(20, 0, 0, 0); + } + if (lines[line] == END) break; + } + for (line++; line < linesLen; line++) toncset16(&se_mem[30][line*32 + 1], 0, 6); +} void -vBlankHandler(void) +delLine(void) { - key_poll(); + if (lineSelected == 0 || lineSelected >= linesLen-1 || lines[lineSelected] == END) return; + for (size_t i = lineSelected; i < linesLen - 1; i++) lines[i] = lines[i + 1]; + lines[linesLen - 1] = END; } void -init(void) +insertLine(enum LineValue val) { - irq_init(NULL); - irq_add(II_VBLANK, vBlankHandler); + if (lineSelected >= linesLen-1 || lines[lineSelected] == END) return; + lineSelected++; + for (size_t i = linesLen - 1; i > lineSelected && i > 0; i--) lines[i] = lines[i - 1]; + lines[lineSelected] = val; + lines[linesLen - 1] = END; + if (lineSelected == linesLen-1) lineSelected--; } int main(void) { + irq_init(NULL); + irq_add(II_VBLANK, NULL); + VBlankIntrWait(); + + LZ77UnCompVram(tilesTiles, &tile_mem[0][0]); + LZ77UnCompVram(tilesPal, pal_bg_mem); + + se_fill(&se_mem[31][0], SE_BUILD(0, 0, 0, 0)); + se_fill(&se_mem[30][0], SE_BUILD(0, 0, 0, 0)); + + for (size_t line = 1; line < linesLen; line++) lines[line] = END; + + // Dividing line between program area and whatever would be in the play area + for (size_t row = 0; row < 32; row++) se_mem[31][(row*32)+8] = SE_BUILD(16, 0, 0, 0); + + REG_BG0CNT = BG_CBB(0) | BG_SBB(31) | BG_4BPP | BG_REG_32x32; + REG_BG0HOFS = 0; REG_BG0VOFS = 0; + REG_BG1CNT = BG_CBB(0) | BG_SBB(30) | BG_4BPP | BG_REG_32x32; + REG_BG1HOFS = 0; REG_BG1VOFS = 0; + REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1; + while (1) { VBlankIntrWait(); + key_poll(); + if (key_hit(KEY_B)) delLine(); + else if (key_held(KEY_L)) { + if (key_hit(KEY_UP) && lineSelected > 0) lineSelected--; + else if (key_hit(KEY_DOWN) && lineSelected < linesLen-2 && lines[lineSelected+1] != END) { + lineSelected++; + } + } else if (key_hit(KEY_A)) insertLine(NOP); + else if (key_hit(KEY_UP)) insertLine(UP_ARROW); + else if (key_hit(KEY_DOWN)) insertLine(DOWN_ARROW); + else if (key_hit(KEY_LEFT)) insertLine(LEFT_ARROW); + else if (key_hit(KEY_RIGHT)) insertLine(RIGHT_ARROW); + redrawLines(); } return 0; } -- 2.45.2