//DS Test App 3 ARM9 Code
#include "main.h"
/*
Entry Point
CPU: ARM9
Inputs:
-argc: Number of arguments
-argv: Pointer to arguments
Returns: Program return code
*/
int main(int argc, char** argv)
{
powerON(POWER_ALL_2D); //Turn stuff on (required for some flash cards)
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_LCD, VRAM_C_SUB_BG_0x6200000, VRAM_D_LCD);
BG1_CR = BG_BMP16_256x256;
BG1_X0 = 0;
BG1_Y0 = 0;
BG3_CR = BG_BMP16_256x256;
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
BG3_CX = 0;
BG3_CY = 0;
SUB_BG3_CR = BG_BMP16_256x256;
SUB_BG3_XDX = 1 << 8;
SUB_BG3_XDY = 0;
SUB_BG3_YDX = 0;
SUB_BG3_YDY = 1 << 8;
SUB_BG3_CX = 0;
SUB_BG3_CY = 0;
//Init interrupts
REG_IME = 0; //Disable interrupts while changing them
IRQ_HANDLER = Interrupt; //Set handler callback
REG_IE = IRQ_VBLANK; //Interrupt on vblank only
REG_IF = ~0;
DISP_SR = DISP_VBLANK_IRQ;
REG_IME = 1; //Enable interrupts
while(true)
{
int i, x, tk1=KeysPressed, tk2=KeysHeld;
char Text[1024], PKeyBits[21], HKeyBits[21], AuxBits[21];
int A = IPC->aux;
static int FC = 0, FPS = 0, FS = IPC->rtc_seconds;
//Temperature is a 20.12-bit value, which means the first 20 bits are before the decimal,
//and the last 12 are after. (Value is in Celcius, because Metric rocks.)
int IPC_temp = IPC->temperature; //Just in case
int temp1 = (IPC_temp & 0xFFFFF000) >> 12; //Before decimal
int temp2 = (IPC_temp & 0x00000FFF); //after
temp2 = (int)((double)temp2 / 409.6); //4096ths -> 10ths
x = 0;
uint16 bit = 0x8000;
for(i=1;i<=16;i++)
{
PKeyBits[x] = (tk1 & bit) ? '1' : '0';
HKeyBits[x] = (tk2 & bit) ? '1' : '0';
AuxBits[x] = (A & bit) ? '1' : '0';
if(!(i % 4))
{
x++;
PKeyBits[x] = ' ';
HKeyBits[x] = ' ';
AuxBits[x] = ' ';
}
x++;
bit >>= 1;
}
x--;
PKeyBits[x] = 0;
HKeyBits[x] = 0;
AuxBits[x] = 0;
FillRect((uint16*)DispBuf,0,0,SCREEN_WIDTH,26,RGB15(0,0,8) | 0x8000);
sprintf(Text,"Touch:\t%3d %3d\tFPS: %d\nKeys:\t%s\nTime:\t%02d/%02d/%02d %02d:%02d:%02d i=%d c=%d\nTemp:\t%d.%d C\tAux: %d (0x%X)", IPC->touchXpx, IPC->touchYpx, FPS, HKeyBits, IPC->rtc_day, IPC->rtc_month, IPC->rtc_year, IPC->rtc_hours, IPC->rtc_minutes, IPC->rtc_seconds, IPC->rtc_incr, IPC->rtc_command, temp1, temp2, IPC->aux, IPC->aux);
printxy((uint16*)DispBuf,Text,0,0);
//Draw a pixel wherever the touch screen is touched.
/* Note: Removing the KeysPressed check might improve accuracy, but will only
register touches that last for more than one frame, making it bad for things
like buttons and keyboards but good for drawing. */
if((KeysHeld & KEY_TOUCH) || (KeysPressed & KEY_TOUCH))
DispBuf[IPC->touchYpx][IPC->touchXpx] = RGB15(0,0,31) | 0x8000;
//DrawPixel((uint16*)DispBuf,IPC->touchXpx,IPC->touchYpx,RGB15(0,0,31));
//Measure frame count
FC++;
if(IPC->rtc_seconds != FS)
{
FS = IPC->rtc_seconds;
FPS = FC;
FC = 0;
}
swiFastCopy((uint16*)DispBuf,BG_GFX,SCREEN_WIDTH*SCREEN_HEIGHT);
printxy(BG_GFX_SUB,"woot",0,0);
//printxy(VRAM_B,"VRAM B",0,0);
//swiWaitForVBlank();
}
return 0;
}
/*
Interrupt handler
CPU: ARM9
*/
void Interrupt()
{
if(REG_IF & IRQ_VBLANK) //VBlank interrupt
{
KeysPressed = IPC->buttons_pressed; //Best to keep a local copy, since the ARM7 may modify it
KeysHeld = IPC->buttons_held;
if(KeysPressed & KEY_SELECT)
lcdSwap();
if(KeysPressed & KEY_START)
{
if(FontColour == RGB15(31,0,0))
FontColour = RGB15(0,31,0);
else if(FontColour == RGB15(0,31,0))
FontColour = RGB15(0,0,31);
else if(FontColour == RGB15(0,0,31))
FontColour = RGB15(31,0,0);
}
if(KeysPressed & KEY_A)
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
else if(KeysPressed & KEY_B)
videoSetMode(MODE_5_2D | DISPLAY_BG1_ACTIVE);
VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK; //Signal that vblank interrupt has been processed
REG_IF |= IRQ_VBLANK; //Dunno what this is for...
}
} |