2015-08-05 11:54:00 +02:00
|
|
|
/*
|
|
|
|
* draw.c
|
2016-03-23 02:27:53 +01:00
|
|
|
* by Reisyukaku / Aurora Wright
|
|
|
|
* Code to print to the screen by mid-kid @CakesFW
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 All Rights Reserved
|
2015-08-05 11:54:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "draw.h"
|
2016-04-05 23:01:46 +02:00
|
|
|
#include "screeninit.h"
|
2015-08-05 11:54:00 +02:00
|
|
|
#include "fs.h"
|
2015-08-21 20:11:23 +02:00
|
|
|
#include "memory.h"
|
2016-03-23 02:27:53 +01:00
|
|
|
#include "font.h"
|
|
|
|
|
|
|
|
#define SCREEN_TOP_WIDTH 400
|
|
|
|
#define SCREEN_TOP_HEIGHT 240
|
2015-08-05 11:54:00 +02:00
|
|
|
|
2016-03-10 14:58:11 +01:00
|
|
|
static const struct fb {
|
|
|
|
u8 *top_left;
|
|
|
|
u8 *top_right;
|
|
|
|
u8 *bottom;
|
|
|
|
} *const fb = (struct fb *)0x23FFFE00;
|
2016-02-08 03:37:03 +01:00
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
static inline int strlen(const char *string)
|
|
|
|
{
|
2016-03-23 02:27:53 +01:00
|
|
|
char *stringEnd = (char *)string;
|
|
|
|
while(*stringEnd) stringEnd++;
|
2016-04-12 14:32:38 +02:00
|
|
|
|
2016-03-23 02:27:53 +01:00
|
|
|
return stringEnd - string;
|
2016-02-29 16:28:43 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void clearScreens(void)
|
|
|
|
{
|
2016-03-20 01:00:45 +01:00
|
|
|
memset32(fb->top_left, 0, 0x46500);
|
|
|
|
memset32(fb->top_right, 0, 0x46500);
|
|
|
|
memset32(fb->bottom, 0, 0x38400);
|
2015-08-06 07:17:10 +02:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void loadSplash(void)
|
|
|
|
{
|
2016-04-05 23:01:46 +02:00
|
|
|
initScreens();
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-03-10 03:06:18 +01:00
|
|
|
//Don't delay boot if no splash image is on the SD
|
2016-03-20 01:00:45 +01:00
|
|
|
if(fileRead(fb->top_left, "/aurei/splash.bin", 0x46500) +
|
2016-04-02 17:58:06 +02:00
|
|
|
fileRead(fb->bottom, "/aurei/splashbottom.bin", 0x38400))
|
|
|
|
{
|
2016-04-05 23:01:46 +02:00
|
|
|
u64 i = 0x1400000;
|
2016-04-02 17:58:06 +02:00
|
|
|
while(--i) __asm("mov r0, r0"); //Less Ghetto sleep func
|
2016-03-10 04:25:38 +01:00
|
|
|
}
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void drawCharacter(char character, int posX, int posY, u32 color)
|
|
|
|
{
|
2016-03-24 16:02:00 +01:00
|
|
|
u8 *const select = fb->top_left;
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
for(int y = 0; y < 8; y++)
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
char charPos = font[character * 8 + y];
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
for(int x = 7; x >= 0; x--)
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
int screenPos = (posX * SCREEN_TOP_HEIGHT * 3 + (SCREEN_TOP_HEIGHT - y - posY - 1) * 3) + (7 - x) * 3 * SCREEN_TOP_HEIGHT;
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
if ((charPos >> x) & 1)
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
select[screenPos] = color >> 16;
|
|
|
|
select[screenPos + 1] = color >> 8;
|
|
|
|
select[screenPos + 2] = color;
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
int drawString(const char *string, int posX, int posY, u32 color)
|
|
|
|
{
|
2016-03-23 02:27:53 +01:00
|
|
|
int length = strlen(string);
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
for(int i = 0, line_i = 0; i < length; i++, line_i++)
|
|
|
|
{
|
|
|
|
if(string[i] == '\n')
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
posY += SPACING_Y;
|
2016-03-23 02:27:53 +01:00
|
|
|
line_i = 0;
|
|
|
|
i++;
|
2016-04-02 18:48:31 +02:00
|
|
|
}
|
|
|
|
else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X)
|
2016-04-02 17:58:06 +02:00
|
|
|
{
|
2016-03-23 02:27:53 +01:00
|
|
|
// Make sure we never get out of the screen.
|
2016-03-29 17:43:53 +02:00
|
|
|
posY += SPACING_Y;
|
2016-03-23 02:27:53 +01:00
|
|
|
line_i = 2; // Little offset so we know the same string continues.
|
|
|
|
if(string[i] == ' ') i++; // Spaces at the start look weird
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
drawCharacter(string[i], posX + line_i * SPACING_X, posY, color);
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
return posY;
|
2015-08-05 11:54:00 +02:00
|
|
|
}
|