Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified arm9/data/font.nftr
Binary file not shown.
8 changes: 3 additions & 5 deletions arm9/source/gui/fileBrowse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void showDirectoryContents(const std::vector<DirEntry>& dirContents, const std::

// Print path
drawImageSection(0, 0, 256, 17, fileBrowseBgBitmap, 256, 0, 0, 16);
printTextMaxW(path, 250, 1, 0, 3, 0);
printTextMaxW(path, 250, 1, 0, 3, 1);

// Print directory listing
for(int i=0;i < ENTRIES_PER_SCREEN; i++) {
Expand Down Expand Up @@ -155,15 +155,13 @@ void showDirectoryContents(const std::vector<DirEntry>& dirContents, const std::
}
}

printText(name, 1, 1, !(startRow+i == selection) + (watched*2), 3, i*16+16);
printText(name, 1, 1, !(startRow+i == selection) + (watched*2), 3, i * 16 + 17);
}
}
}

std::string browseForFile(const std::vector<std::string>& extensionList) {
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
vramSetBankC(VRAM_C_SUB_BG);
bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);

int pressed = 0, held = 0, screenOffset = 0, fileOffset = 0;
touchPosition touch;
Expand Down Expand Up @@ -238,7 +236,7 @@ std::string browseForFile(const std::vector<std::string>& extensionList) {
touchRead(&touch);
for(int i=0;i<std::min(ENTRIES_PER_SCREEN, (int)dirContents.size());i++) {
if(touch.py > (i+1)*16 && touch.py < (i+2)*16) {
fileOffset = i;
fileOffset = screenOffset + i;
goto selection;
}
}
Expand Down
44 changes: 24 additions & 20 deletions arm9/source/gui/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,37 @@
#include "font_nftr.h"
#include "fileBrowseBg.h"

std::vector<u8> fontTiles;
std::vector<u8> fontWidths;
u8 *fontTiles;
const u8 *fontWidths;
std::vector<u16> fontMap;
u16 tileSize, tileWidth, tileHeight;

void loadPalettes(void) {
u16 palette[] = {0, 0xFBDE, 0xBDEF, // Light
0, 0xD294, 0xA529, // Darker
0, (u16)(palettes[PersonalData->theme][0] & 0xFBDE), (u16)(palettes[PersonalData->theme][0] & 0xBDEF), // Light colored
0, (u16)(palettes[PersonalData->theme][0] & 0xD294), (u16)(palettes[PersonalData->theme][0] & 0xA529)}; // Darker colored
u16 palette[] = {0x0000, 0xFFFF, 0xD6B5, 0xB9CE, // White
0x0000, 0xDEF7, 0xC631, 0xA94A, // Black
0x0000, (u16)(palettes[PersonalData->theme][1] & 0xFFFF), (u16)(palettes[PersonalData->theme][1] & 0xDEF7), (u16)(palettes[PersonalData->theme][1] & 0xCE73), // Light colored
0x0000, (u16)(palettes[PersonalData->theme][1] & 0xD6B5), (u16)(palettes[PersonalData->theme][1] & 0xCA52), (u16)(palettes[PersonalData->theme][1] & 0xC210)}; // Darker colored
tonccpy(BG_PALETTE_SUB, &palette, sizeof(palette));
tonccpy(BG_PALETTE_SUB+0x10, &fileBrowseBgPal, fileBrowseBgPalLen/2);
tonccpy(BG_PALETTE_SUB+0x13, &palettes[PersonalData->theme], sizeof(palettes[PersonalData->theme]));
}

void loadFont(void) {
// Load font info
u32 chunkSize = *(u32*)(font_nftr+0x30);
tileWidth = *(font_nftr+0x34);
tileHeight = *(font_nftr+0x35);
tileSize = *(u16*)(font_nftr+0x36);
// consoleDemoInit();
// Get glyph start
u8 glyphOfs = font_nftr[0x14] + 0x14;

// Load glyph info
u32 chunkSize = *(u32*)(font_nftr+glyphOfs);
tileWidth = font_nftr[glyphOfs+4];
tileHeight = font_nftr[glyphOfs+5];
tileSize = *(u16*)(font_nftr+glyphOfs+6);
// printf("%d\n%d\n%d\n", tileWidth, tileHeight, tileSize);
// while(1)swiWaitForVBlank();

// Load character glyphs
int tileAmount = ((chunkSize-0x10)/tileSize);
fontTiles = std::vector<u8>(tileSize*tileAmount);
memcpy(fontTiles.data(), font_nftr+0x3C, tileSize*tileAmount);
fontTiles = (u8*)font_nftr+glyphOfs+0xC;

// Fix top rows
for(int i=0;i<tileAmount;i++) {
Expand All @@ -43,8 +48,7 @@ void loadFont(void) {
// Load character widths
u32 locHDWC = *(u32*)(font_nftr+0x24);
chunkSize = *(u32*)(font_nftr+locHDWC-4);
fontWidths = std::vector<u8>(3*tileAmount);
memcpy(fontWidths.data(), font_nftr+locHDWC+8, 3*tileAmount);
fontWidths = font_nftr+locHDWC+8;

// Load character maps
fontMap = std::vector<u16>(tileAmount);
Expand Down Expand Up @@ -193,7 +197,7 @@ void printText(std::string text, double scaleX, double scaleY, int palette, int
void printText(std::u16string text, double scaleX, double scaleY, int palette, int xPos, int yPos) {
int x=xPos;
for(unsigned c=0;c<text.size();c++) {
if(text[c] == 0x00BB) { // » makes a new line currently, may change this
if(text[c] == '\n') {
x = xPos;
yPos += tileHeight;
continue;
Expand All @@ -202,10 +206,10 @@ void printText(std::u16string text, double scaleX, double scaleY, int palette, i
int t = getCharIndex(text[c]);
unsigned char image[tileSize * 4];
for(int i=0;i<tileSize;i++) {
image[(i*4)] = (palette*3 + (fontTiles[i+(t*tileSize)]>>6 & 3));
image[(i*4)+1] = (palette*3 + (fontTiles[i+(t*tileSize)]>>4 & 3));
image[(i*4)+2] = (palette*3 + (fontTiles[i+(t*tileSize)]>>2 & 3));
image[(i*4)+3] = (palette*3 + (fontTiles[i+(t*tileSize)] & 3));
image[(i*4)] = (palette*4 + (fontTiles[i+(t*tileSize)]>>6 & 3));
image[(i*4)+1] = (palette*4 + (fontTiles[i+(t*tileSize)]>>4 & 3));
image[(i*4)+2] = (palette*4 + (fontTiles[i+(t*tileSize)]>>2 & 3));
image[(i*4)+3] = (palette*4 + (fontTiles[i+(t*tileSize)] & 3));
}

x += fontWidths[t*3];
Expand Down
47 changes: 28 additions & 19 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void aac_initQueue()
DC_FlushRange(&sAACQueue, (sizeof(sAACQueue) + 31) & ~31);
}

ITCM_CODE void PlayVideo()
ITCM_CODE void PlayVideo(const char *fileName)
{
printf("PlayVideo\n");
stopVideo = FALSE;
Expand Down Expand Up @@ -185,15 +185,14 @@ ITCM_CODE void PlayVideo()
mVideoHeader = (uint8_t*)malloc(SWAP_CONSTANT_32(header_size));
mRingBufferHttpStream->Read(mVideoHeader + 4, SWAP_CONSTANT_32(header_size) - 4);
#else
std::string fileName = browseForFile({"mp4"});
FILE* video = fopen(fileName.c_str(), "rb");
FILE* video = fopen(fileName, "rb");

// Clear the screen
printf("\x1b[2J");
drawRectangle(0, 0, 256, 192, 0);

// Draw progress bar background
drawRectangle(35, 6, 185, 7, 5);
drawRectangle(36, 5, 184, 7, 7);

printf("Opened file: %p\n", video);
//find the moov atom
Expand Down Expand Up @@ -414,7 +413,7 @@ ITCM_CODE void PlayVideo()
skip = 0;
continue;
}

if(pauseVideo) continue;
if(frame < nrframes)
{
Expand Down Expand Up @@ -649,10 +648,10 @@ ITCM_CODE void VBlankProc()
nrFramesInQueue--;
} else {
// Update time & progress if not copying a frame
drawRectangle(36, 7, (int)(((float)frame/nrframes)*184), 5, 4);
drawRectangle(37, 6, (int)(((float)frame/nrframes)*183), 5, 5);
char time[14];
snprintf(time, sizeof(time), "%.02d:%.02d", frame/(mTimeScale/1000)/60, (frame/(mTimeScale/1000))-((frame/(mTimeScale/1000)/60)*60));
drawRectangle(3, 1, 30, 16, 0);
drawRectangle(3, 1, 32, 16, 0);
printText(time, 1, 1, 1, 3, 1);
}
}
Expand All @@ -674,23 +673,23 @@ ITCM_CODE void VBlankProc()
} else if(held & KEY_LEFT) {
skip = -24*5;
drawBar:
drawRectangle(35, 6, 185, 7, 5);
drawRectangle(36, 7, (int)(((float)frame/nrframes)*184), 5, 4);
drawRectangle(36, 5, 184, 7, 7);
drawRectangle(37, 6, (int)(((float)frame/nrframes)*183), 5, 5);
} else if(held & KEY_TOUCH) {
touchPosition touch;
touchRead(&touch);
if(touch.py < 16 && touch.px > 35 && touch.px < 220) {
int newpos = nrframes*((float)(touch.px-35)/183);
if(touch.py < 16 && touch.px > 36 && touch.px < 220) {
int newpos = nrframes*((float)(touch.px-37)/182);
skip = newpos-frame;
goto drawBar; // overflowed itcm with it copied
goto drawBar; // overflowed itcm with it copied
}
}
}
else
mKeyTimer = 0;
}

int main()
int main(int argc, char *argv[])
{
mpu_enableVramCache();
defaultExceptionHandler();
Expand All @@ -699,12 +698,13 @@ int main()
mUpscalingEnabled = FALSE;
if(!fatInitDefault())
nitroFSInit(NULL);
//defaultExceptionHandler();
//consoleDemoInit();

videoSetMode(MODE_0_2D);
videoSetModeSub(MODE_0_2D);
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
vramSetBankH(VRAM_H_SUB_BG);

bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);

loadFont();
loadPalettes();

Expand Down Expand Up @@ -837,7 +837,6 @@ int main()
setBrightness(2, (bright + 1) / 2);
swiWaitForVBlank();
}*/
idle_loop:
#ifdef USE_WIFI
while(1)
{
Expand All @@ -863,7 +862,17 @@ int main()
mRingBufferHttpStream = new RingBufferHttpStream(url);
free(url);
#endif*/
PlayVideo();
goto idle_loop;

if(argc > 1) {
PlayVideo(argv[1]);
} else {
while(1) {
PlayVideo(browseForFile({"mp4"}).c_str());
}
}

printTextCentered("Please turn off your DS.", 1, 1, 0, 0, 32);
printTextCentered("(This will hopefully be fixed soon)", 1, 1, 0, 0, 48);

return 0;
}