#include <stdio.h>
#include <3ds.h>
#include "rawr.h"
#include "draw.h"
u8* screenBottom = 0;
u8* screenTopLeft = 0;
u8* screenTopRight = 0;
void Rawr(){
TopScreen();
BottomScreen();
Render();
}
void TopText(char* Text, int x, int y, char r, char g, char b){
char a[100];
sprintf(a, Text);
drawString(a, x, y, r, g, b, screenTopLeft, GFX_LEFT);
drawString(a, x, y, r, g, b, screenTopRight, GFX_LEFT);
}
void BottomText(char* Text, int x, int y, char r, char g, char b){
char a[100];
sprintf(a, Text);
drawString(a, x, y, r, g, b, screenBottom, GFX_BOTTOM);
}
void TopScreen(){
screenTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
screenTopRight = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
clearScreen(screenTopLeft, GFX_LEFT);
clearScreen(screenTopRight, GFX_LEFT);
drawFillRect(0, 0, 400, 240, 255, 255, 255, screenTopLeft);
drawFillRect(0, 0, 400, 240, 255, 255, 255, screenTopRight);
TopText("I'm Troy!<3", 10, 180, 0, 0, 0);
TopText("Meep", 50, 50, 0, 0, 0);
}
void BottomScreen(){
screenBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
clearScreen(screenBottom, GFX_BOTTOM);
drawFillRect(0, 0, 30, 240, 255, 255, 255, screenBottom);
BottomText("Love me? I do.", 120, 100, 0, 0, 255);
BottomText("Woosh!", 20, 10, 255, 255, 255);
Notes();
}
void Notes(){
touchPosition myTouchPosition;
hidTouchRead(&myTouchPosition);
u16 posX = myTouchPosition.px;
u16 posY = myTouchPosition.py;
if((posX > 0 && posX <= 30) && (posY > 0 && posY <= 240)){
BottomText("Hehe, that tickles!", 100, 100, 255, 255, 255);
Wav = OpenWav("/canary.wav");
}
}
void Render(){
gfxFlushBuffers();
gfxSwapBuffers();
screenBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
screenTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
screenTopRight = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
};
u8* OpenWav(const char* WavFile){
Handle fileHandle;
//Open wav file
FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
FS_path filePath=FS_makePath(PATH_CHAR, WavFile);
Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
u32 magic,samplerate,bytesRead,jump,chunk=0x00000000;
FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
if (magic == 0x46464952){
u64 size;
u32 pos = 16;
while (chunk != 0x61746164){
FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
pos=pos+jump;
FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
pos=pos+4;
}
FSFILE_GetSize(fileHandle, &size);
u8* audiobuf = (u8*)linearAlloc(size-(pos+4));
FSFILE_Read(fileHandle, &bytesRead, 24, &samplerate, 4);
FSFILE_Read(fileHandle, &bytesRead, pos+4, audiobuf, size-(pos+4));
}
FSFILE_Close(fileHandle);
svcCloseHandle(fileHandle);
CSND_initialize(NULL);
CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
return audiobuf;
}