Skip to content

Commit

Permalink
adds screen to audio demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Williams committed Nov 14, 2019
1 parent 16142dc commit 13ec162
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 4 deletions.
91 changes: 91 additions & 0 deletions 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<<GFX_FBPITCH_PAL_OFF)|(FB_WIDTH<<GFX_FBPITCH_PITCH_OFF);
//Set up the framebuffer address
GFX_REG(GFX_FBADDR_REG)=((uint32_t)fbmem);

//Now, use a library function to load the image into the framebuffer memory. This function will also set up the palette entries,
//we tell it to start writing from entry 0.
/* int png_size=(&_binary_bgnd_png_end-&_binary_bgnd_png_start); */
/* int i=gfx_load_fb_mem(fbmem, &GFXPAL[0], 8, FB_WIDTH, &_binary_bgnd_png_start, png_size); */
/* printf("gfx_load_mem: %d\n", i); */

//Flush the memory region to psram so the GFX hw can stream it from there.
cache_flush(fbmem, fbmem+FB_WIDTH*FB_HEIGHT);

//The IPL leaves us with a tileset that has tile 0 to 127 map to ASCII characters, so we do not need to
//load anything specific for this. In order to get some text out, we can use the /dev/console device
//that will use these tiles to put text in a tilemap. It uses escape codes to do so, see
//ipl/gloss/console_out.c for more info.
FILE *f;
f=fopen("/dev/console", "w");
setvbuf(f, NULL, _IOLBF, 1024); //make console line buffered
//Note that without the setvbuf command, no characters would be printed until 1024 characters are
//buffered.
fprintf(f, "\033C"); //clear the console. Note '\033' is the escape character.
fprintf(f, "\0335X"); //set Xpos to 5
fprintf(f, "\0338Y"); //set Ypos to 8
fprintf(f, "Synth Demo\n"); // Print a nice greeting.
fprintf(f, "\0335X"); //set Xpos to 5
fprintf(f, "\0339Y"); //set Ypos to 8
fprintf(f, "To see what it's doing,\n"); // Print a nice greeting.
fprintf(f, "\0335X"); //set Xpos to 5
fprintf(f, "\03310Y"); //set Ypos to 8
fprintf(f, "read the code!\n"); // Print a nice greeting.
fprintf(f, "\0335X"); //set Xpos to 5
fprintf(f, "\03312Y"); //set Ypos to 8
fprintf(f, "No audio?\n"); // Print a nice greeting.
fprintf(f, "\0335X"); //set Xpos to 5
fprintf(f, "\03313Y"); //set Ypos to 8
fprintf(f, "Solder a speaker!\n"); // Print a nice greeting.
//Note that without the newline at the end, all printf's would stay in the buffer.
//The user can still see nothing of this graphics goodness, so let's re-enable the framebuffer and
//tile layer A (the default layer for the console). Also indicate the framebuffer we have is
//8-bit.
GFX_REG(GFX_LAYEREN_REG)=GFX_LAYEREN_FB_8BIT|GFX_LAYEREN_FB|GFX_LAYEREN_TILEA;
}
16 changes: 16 additions & 0 deletions app-audiodemo/graphics.h
@@ -0,0 +1,16 @@

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

#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);


6 changes: 2 additions & 4 deletions app-audiodemo/main.c
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 13ec162

Please sign in to comment.