// written 2004 Mirko Roller mirko@mirkoroller.de
#include "gp32.h"
extern unsigned char modfile1[];
extern unsigned char modfile2[];
extern unsigned char sample1[];
extern unsigned char sample2[];
static volatile int t3=0;
__irq static void timer3_isr( void ) //should be called @50Hz
{
t3++;
}
void InstallTicker( void )
{
unsigned long count;
u32 rtcon=rTCON;
count=gp_getPCLK(); //==PCLK Mhz/8bit prescaler+1/4bit divier/target freq 50Hz
count/=256;
count/=16;
count/=50;
gp_disableIRQ();
rTCNTB3 = count;
rTCFG0 |= (0xFF<<8);//255+1
rTCFG1 |= (0x3<<12);//16
rTCON |= (0x5<<17); //auto reload=1 + maunal update=1
rTCON = rtcon |(0x9<<16); //auto-reload=1 + manual update=0 +start=1
gp_installSWIIRQ(13,timer3_isr); //13=ISR for timer3
gp_enableIRQ();
}
int main() {
char time[20];
int t;
u16* framebuffer = (u16*) FRAMEBUFFER;
// If you get clicky sound, disable cache on framebuffer
gp_setMMU ( framebuffer, framebuffer+(320*240*2)-1, 0xFF2 );
gp_setCpuspeed(33);
gp_initFramebuffer(framebuffer,16,85);
//gp_startmod(modfile);
gp_startSoundmixer(22050,16); // start IRQ modfile
gp_clearFramebuffer16 ( framebuffer, 0xFFFF );
gp_drawString ( 1, 10, 35,"Mr.Mirko Mod/Mixer running @33Mhz ", 0xF800, framebuffer );
gp_drawString ( 20, 30, 25,"L = Play Sample1 ", 0xF800, framebuffer );
gp_drawString ( 20, 40, 25,"R = Play Sample2 ", 0xF800, framebuffer );
gp_drawString ( 20, 50, 25,"START = Start Modfile1 ", 0xF800, framebuffer );
gp_drawString ( 20, 60, 25,"SELECT= Start Modfile2 ", 0xF800, framebuffer );
gp_drawString ( 20, 70, 25,"A = RESET ", 0xF800, framebuffer );
gp_drawString ( 20, 80, 25,"B = Stop Soundmixer ", 0xF800, framebuffer );
gp_drawString ( 20, 90, 25,"UP = Start Soundmixer ", 0xF800, framebuffer );
atexit(gp_stopSoundmixer());
InstallTicker();
while (1) {
if (gp_getButton()&BUTTON_A) exit(1);
if (gp_getButton()&BUTTON_START) gp_startModfile(modfile1);
if (gp_getButton()&BUTTON_B) gp_stopSoundmixer();
if (gp_getButton()&BUTTON_SELECT) gp_startModfile(modfile2);
if (gp_getButton()&BUTTON_L) gp_addSample( (u16*)sample1,22050,GP32_STEREO,0,100800);
if (gp_getButton()&BUTTON_R) gp_addSample( (u16*)sample2,22050,GP32_STEREO,0,148160);
if (gp_getButton()&BUTTON_UP) gp_startSoundmixer(22050,16);
gp_clearFramebuffer16(framebuffer,0xffff);
t=gp_getRTC();
sprintf(time,"%d",t3);
gp_drawString(20,100,strlen(time),time,0xF800,framebuffer);
t+=64;//1sec
while(t>gp_getRTC());
}
}