diff --git a/app-audiodemo/graphics.c b/app-audiodemo/graphics.c new file mode 100644 index 0000000..99e92b9 --- /dev/null +++ b/app-audiodemo/graphics.c @@ -0,0 +1,91 @@ + +#include "graphics.h" + +extern volatile uint32_t MISC[]; +#define MISC_REG(i) MISC[(i)/4] +extern volatile uint32_t GFXREG[]; +#define GFX_REG(i) GFXREG[(i)/4] +extern uint32_t GFXPAL[]; +extern uint32_t GFXTILES[]; +extern uint32_t GFXTILEMAPA[]; +extern uint32_t GFXTILEMAPB[]; + +//The bgnd.png image got linked into the binary of this app, and these two chars are the first +//and one past the last byte of it. +extern char _binary_bgnd_png_start; +extern char _binary_bgnd_png_end; + +//Pointer to the framebuffer memory. +uint8_t *fbmem; + +#define FB_WIDTH 512 +#define FB_HEIGHT 320 + +void button_wait(){ + //Wait until all buttons are released + while (MISC_REG(MISC_BTN_REG)) ; + //Wait until button A is pressed + while ((MISC_REG(MISC_BTN_REG) & BUTTON_A)==0) ; +} + +// End graphics stuff. + +void do_graphics(void){ + //We're running in app context. We have full control over the badge and can do with the hardware what we want. As + //soon as main() returns, however, we will go back to the IPL. + + //Blank out fb while we're loading stuff by disabling all layers. This just shows the background color. + // Blue, Green, Red + GFX_REG(GFX_BGNDCOL_REG)=0x101010; //a soft gray + GFX_REG(GFX_LAYEREN_REG)=0; //disable all gfx layers + + //First, allocate some memory for the background framebuffer. We're gonna dump a fancy image into it. The image is + //going to be 8-bit, so we allocate 1 byte per pixel. + fbmem=calloc(FB_WIDTH,FB_HEIGHT); + + //Tell the GFX hardware to use this, and its pitch. We also tell the GFX hardware to use palette entries starting + //from 0 for the frame buffer. + GFX_REG(GFX_FBPITCH_REG)=(0< +#include +#include + +#include "mach_defines.h" +#include "gfx_load.h" +#include "cache.h" + +// This is just to get the graphics out of the sound code. +// Makes it readable. +// +void do_graphics(void); +void button_wait(void); + + diff --git a/app-audiodemo/main.c b/app-audiodemo/main.c index 118cea2..2643bc5 100644 --- a/app-audiodemo/main.c +++ b/app-audiodemo/main.c @@ -6,8 +6,8 @@ #include "synth_utils.h" #include "midi_note_increments.h" #include "mach_defines.h" -#include "cache.h" #include "sdk.h" +#include "graphics.h" // A quick note on timing. Everything here is in duration counts. @@ -35,13 +35,11 @@ void wait(uint32_t duration_counts){ // All of the higher-level functions are defined in synth/synth_utils.c // And all of the lower-level registers in synth/libsynth.h - void main(int argc, char **argv) { + do_graphics(); synth_init(8); // set up 8 voices - - #if INTRO // and then the simplest way to play is just notes: // a lookup table converts MIDI note numbers to pitches: