Skip to content

Commit 074a5ea

Browse files
committed
Tic-Tac-Toe now complete!
1 parent 20258a9 commit 074a5ea

File tree

2 files changed

+147
-1
lines changed

2 files changed

+147
-1
lines changed

bootloader/load.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENTRY(_start)
55
MEMORY {
66

77
vram : ORIGIN = 0x06000000, LENGTH = 256K
8-
arm9ram : ORIGIN = 0x023FB800, LENGTH = 8K /* Used for the ARM9's functions */
8+
arm9ram : ORIGIN = 0x023FA800, LENGTH = 10K /* Used for the ARM9's functions */
99
}
1010

1111
__vram_start = ORIGIN(vram);

bootloader/source/main.arm9.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,57 @@ static u16 ttt_selColor = 0x03A0;
821821

822822
//static bool ttt_keypressed = false;
823823

824+
static int ttt_drawXpos = 0;
825+
static int ttt_drawYpos = 0;
826+
827+
static void ttt_drawN (void) {
828+
// 1st h line
829+
for (y = ttt_drawYpos+0; y <= ttt_drawYpos+39; y++) {
830+
for (k = ttt_drawXpos+0; k <= ttt_drawXpos+7; k++) {
831+
VRAM_A[y*256+k] = 0x0000;
832+
}
833+
}
834+
// 2nd h line
835+
for (y = ttt_drawYpos+8; y <= ttt_drawYpos+15; y++) {
836+
for (k = ttt_drawXpos+8; k <= ttt_drawXpos+15; k++) {
837+
VRAM_A[y*256+k] = 0x0000;
838+
}
839+
}
840+
// 3rd h line
841+
for (y = ttt_drawYpos+16; y <= ttt_drawYpos+23; y++) {
842+
for (k = ttt_drawXpos+16; k <= ttt_drawXpos+23; k++) {
843+
VRAM_A[y*256+k] = 0x0000;
844+
}
845+
}
846+
// 4th h line
847+
for (y = ttt_drawYpos+24; y <= ttt_drawYpos+31; y++) {
848+
for (k = ttt_drawXpos+24; k <= ttt_drawXpos+31; k++) {
849+
VRAM_A[y*256+k] = 0x0000;
850+
}
851+
}
852+
// 5th h line
853+
for (y = ttt_drawYpos+0; y <= ttt_drawYpos+39; y++) {
854+
for (k = ttt_drawXpos+32; k <= ttt_drawXpos+39; k++) {
855+
VRAM_A[y*256+k] = 0x0000;
856+
}
857+
}
858+
}
859+
860+
static void ttt_drawT (void) {
861+
// Top
862+
for (y = ttt_drawYpos+0; y <= ttt_drawYpos+7; y++) {
863+
for (k = ttt_drawXpos+0; k <= ttt_drawXpos+39; k++) {
864+
VRAM_A[y*256+k] = 0x0000;
865+
}
866+
}
867+
// Bottom
868+
for (y = ttt_drawYpos+8; y <= ttt_drawYpos+39; y++) {
869+
for (k = ttt_drawXpos+16; k <= ttt_drawXpos+23; k++) {
870+
VRAM_A[y*256+k] = 0x0000;
871+
}
872+
}
873+
}
874+
824875
static void arm9_ttt (void) {
825876
if(!drawnStuff) {
826877
REG_POWERCNT = (u16)(POWER_LCD | POWER_2D_A);
@@ -972,6 +1023,101 @@ static void arm9_ttt (void) {
9721023
//ttt_keypressed = true;
9731024
}
9741025

1026+
if(REG_KEYINPUT & (KEY_L)) {} else {
1027+
if(ttt_selected[ttt_highlighted] == 0){
1028+
ttt_selected[ttt_highlighted] = 1; // N
1029+
// Set X position
1030+
switch(ttt_highlighted) {
1031+
case 0:
1032+
case 3:
1033+
case 6:
1034+
default:
1035+
ttt_drawXpos = 20;
1036+
break;
1037+
case 1:
1038+
case 4:
1039+
case 7:
1040+
ttt_drawXpos = 108;
1041+
break;
1042+
case 2:
1043+
case 5:
1044+
case 8:
1045+
ttt_drawXpos = 196;
1046+
break;
1047+
}
1048+
// Set Y position
1049+
switch(ttt_highlighted) {
1050+
case 0:
1051+
case 1:
1052+
case 2:
1053+
default:
1054+
ttt_drawYpos = 8;
1055+
break;
1056+
case 3:
1057+
case 4:
1058+
case 5:
1059+
ttt_drawYpos = 76;
1060+
break;
1061+
case 6:
1062+
case 7:
1063+
case 8:
1064+
ttt_drawYpos = 144;
1065+
break;
1066+
}
1067+
ttt_drawN();
1068+
}
1069+
}
1070+
if(REG_KEYINPUT & (KEY_R)) {} else {
1071+
if(ttt_selected[ttt_highlighted] == 0){
1072+
ttt_selected[ttt_highlighted] = 2; // T
1073+
// Set X position
1074+
switch(ttt_highlighted) {
1075+
case 0:
1076+
case 3:
1077+
case 6:
1078+
default:
1079+
ttt_drawXpos = 20;
1080+
break;
1081+
case 1:
1082+
case 4:
1083+
case 7:
1084+
ttt_drawXpos = 108;
1085+
break;
1086+
case 2:
1087+
case 5:
1088+
case 8:
1089+
ttt_drawXpos = 196;
1090+
break;
1091+
}
1092+
// Set Y position
1093+
switch(ttt_highlighted) {
1094+
case 0:
1095+
case 1:
1096+
case 2:
1097+
default:
1098+
ttt_drawYpos = 8;
1099+
break;
1100+
case 3:
1101+
case 4:
1102+
case 5:
1103+
ttt_drawYpos = 76;
1104+
break;
1105+
case 6:
1106+
case 7:
1107+
case 8:
1108+
ttt_drawYpos = 144;
1109+
break;
1110+
}
1111+
ttt_drawT();
1112+
}
1113+
}
1114+
1115+
if(REG_KEYINPUT & (KEY_START)) {} else {
1116+
// Clear all marks
1117+
drawnStuff = false;
1118+
for(i = 0; i < 9; i++) ttt_selected[i] = 0;
1119+
}
1120+
9751121
if(ttt_highlighted == 0) {
9761122
ttt_rectColor[0] = ttt_selColor;
9771123
} else {

0 commit comments

Comments
 (0)