Skip to content

Commit

Permalink
Fix saving and switching being buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicpkmn11 committed Oct 26, 2020
1 parent 12f248b commit b153db7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ int main(int argc, char **argv) {
} while(!pressed);

if(pressed & KEY_A) {
*(u16 *)0x4004202 &= ~0x8000;
// Wait for previous transfer to finish
while(REG_NDMA1CNT & BIT(31))
swiWaitForVBlank();

// Pause transfer
REG_CAM_CNT &= ~0x8000;
if(inner) {
fifoSendValue32(FIFO_USER_01, 2);
while(!fifoCheckValue32(FIFO_USER_02))
Expand Down Expand Up @@ -106,7 +111,8 @@ int main(int argc, char **argv) {
REG_CAM_CNT |= 0x8000; // CAM_CNT, start transfer
}
inner = !inner;
REG_CAM_CNT |= ~0x8000;
// Resume transfer
REG_CAM_CNT |= 0x8000;
} else if(fatInited && pressed & (KEY_L | KEY_R)) {
FILE *file = fopen("photo.bmp", "wb");
if(file) {
Expand All @@ -123,9 +129,12 @@ int main(int argc, char **argv) {
while(REG_NDMA1CNT & BIT(31))
swiWaitForVBlank();

// Pause transfer
REG_CAM_CNT &= ~0x8000;

// BGR -> RGB
for(int i = 0; i < 256 * 192; i++) {
buffer[i] = buffer[i] >> 10 | (buffer[i] & (0x1F << 5)) | (buffer[i] & 0x1F) << 10 | BIT(15);
buffer[i] = ((buffer[i] >> 10) & 0x1F) | (buffer[i] & (0x1F << 5)) | (buffer[i] & 0x1F) << 10;
}

// Header for a 256x192 16 bit BMP
Expand All @@ -150,11 +159,8 @@ int main(int argc, char **argv) {
// Set NDMA back to screen
REG_NDMA1DAD = (u32)bgGetGfxPtr(bg3Main); // NDMA1DAD, dest RAM/VRAM

// For some reason the camera freezes... Start data transfer again
REG_CAM_CNT |= 0x2000; // CAM_CNT, enable YUV-to-RGB555
REG_CAM_CNT = (REG_CAM_CNT & ~0x000F) | 0x0003;
REG_CAM_CNT |= 0x0020; // CAM_CNT, flush data fifo
REG_CAM_CNT |= 0x8000; // CAM_CNT, start transfer
// Resume transfer
REG_CAM_CNT |= 0x8000;
}
} else if(pressed & KEY_START) {
// Disable camera so the light turns off
Expand Down

0 comments on commit b153db7

Please sign in to comment.