/* framebuffer_demo1 ARM9 Code Chris Double (chris.double@double.co.nz) http://www.double.co.nz/nintendo_ds */ #include static int old_x = 0; static int old_y = 0; static int shape_x = 0; static int shape_y = 0; static int shape_width = 10; static int shape_height = 10; void draw_shape(int x, int y, uint16* buffer, uint16 color) { buffer += y * SCREEN_WIDTH + x; for(int i = 0; i < shape_height; ++i) { uint16* line = buffer + (SCREEN_WIDTH * i); for(int j = 0; j < shape_width; ++j) { *line++ = color; } } } void on_irq() { if(REG_IF & IRQ_VBLANK) { draw_shape(old_x, old_y, VRAM_A, RGB15(0, 0, 0)); draw_shape(shape_x, shape_y, VRAM_A, RGB15(31, 0, 0)); // Tell the DS we handled the VBLANK interrupt VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK; REG_IF |= IRQ_VBLANK; } else { // Ignore all other interrupts REG_IF = REG_IF; } } void InitInterruptHandler() { REG_IME = 0; IRQ_HANDLER = on_irq; REG_IE = IRQ_VBLANK; REG_IF = ~0; DISP_SR = DISP_VBLANK_IRQ; REG_IME = 1; } int main(void) { powerON(POWER_ALL); videoSetMode(MODE_FB0); vramSetBankA(VRAM_A_LCD); // Initialize and enable interrupts InitInterruptHandler(); // lcdSwap(); while(1) { old_x = shape_x; old_y = shape_y; shape_x++; if(shape_x + shape_width >= SCREEN_WIDTH) { shape_x = 0; shape_y += shape_height; if(shape_y + shape_height >= SCREEN_HEIGHT) { shape_y = 0; } } swiWaitForVBlank(); } return 0; }