2015-05-12 11:15:16 +12:00
|
|
|
// Copyright 2013 Normmatt
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-05-04 15:32:23 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "font.h"
|
|
|
|
#include "draw.h"
|
|
|
|
|
2016-06-07 23:15:14 -04:00
|
|
|
u8 *TOP_SCREEN0;
|
|
|
|
u8 *TOP_SCREEN1;
|
|
|
|
u8 *BOT_SCREEN0;
|
|
|
|
u8 *BOT_SCREEN1;
|
|
|
|
|
2016-06-07 02:30:30 -04:00
|
|
|
size_t current_y = 0;
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2016-06-07 23:15:14 -04:00
|
|
|
void DrawInit(void)
|
|
|
|
{
|
|
|
|
#ifdef BRAHMA
|
|
|
|
TOP_SCREEN0 = (u8*)(0x20000000);
|
|
|
|
TOP_SCREEN1 = (u8*)(0x20046500);
|
|
|
|
BOT_SCREEN0 = (u8*)(0x2008CA00);
|
|
|
|
BOT_SCREEN1 = (u8*)(0x200C4E00);
|
|
|
|
#elif A9LH
|
|
|
|
TOP_SCREEN0 = (u8*)(*(u32*)0x23FFFE00);
|
|
|
|
TOP_SCREEN1 = (u8*)(*(u32*)0x23FFFE00);
|
|
|
|
BOT_SCREEN0 = (u8*)(*(u32*)0x23FFFE08);
|
|
|
|
BOT_SCREEN1 = (u8*)(*(u32*)0x23FFFE08);
|
|
|
|
#else
|
|
|
|
#error "BRAHMA or A9LH must be defined!"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-04 15:32:23 -07:00
|
|
|
void ClearScreen(unsigned char *screen, int color)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *screenPos = screen;
|
|
|
|
for (i = 0; i < (SCREEN_HEIGHT * SCREEN_WIDTH); i++) {
|
|
|
|
*(screenPos++) = color >> 16; // B
|
|
|
|
*(screenPos++) = color >> 8; // G
|
|
|
|
*(screenPos++) = color & 0xFF; // R
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:30:30 -04:00
|
|
|
void DrawCharacter(unsigned char *screen, int character, size_t x, size_t y, int color, int bgcolor)
|
2015-05-04 15:32:23 -07:00
|
|
|
{
|
2016-06-07 02:30:30 -04:00
|
|
|
for (size_t yy = 0; yy < 8; yy++) {
|
|
|
|
size_t xDisplacement = (x * BYTES_PER_PIXEL * SCREEN_WIDTH);
|
|
|
|
size_t yDisplacement = ((SCREEN_WIDTH - (y + yy) - 1) * BYTES_PER_PIXEL);
|
2016-06-07 23:15:14 -04:00
|
|
|
|
|
|
|
unsigned char *screenPos = screen + xDisplacement + yDisplacement;
|
2016-06-07 02:30:30 -04:00
|
|
|
unsigned char charPos = font[(size_t)character * 8 + yy];
|
|
|
|
for (int xx = 7; xx >= 0; xx--) {
|
2015-05-04 15:32:23 -07:00
|
|
|
if ((charPos >> xx) & 1) {
|
|
|
|
*(screenPos + 0) = color >> 16; // B
|
|
|
|
*(screenPos + 1) = color >> 8; // G
|
|
|
|
*(screenPos + 2) = color & 0xFF; // R
|
|
|
|
} else {
|
|
|
|
*(screenPos + 0) = bgcolor >> 16; // B
|
|
|
|
*(screenPos + 1) = bgcolor >> 8; // G
|
|
|
|
*(screenPos + 2) = bgcolor & 0xFF; // R
|
|
|
|
}
|
|
|
|
screenPos += BYTES_PER_PIXEL * SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:30:30 -04:00
|
|
|
void DrawString(unsigned char *screen, const char *str, size_t x, size_t y, int color, int bgcolor)
|
2015-05-04 15:32:23 -07:00
|
|
|
{
|
2015-05-11 10:33:33 -04:00
|
|
|
const size_t string_len = strlen(str);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < string_len; i++)
|
2015-05-04 15:32:23 -07:00
|
|
|
DrawCharacter(screen, str[i], x + i * 8, y, color, bgcolor);
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:30:30 -04:00
|
|
|
void DrawStringF(size_t x, size_t y, const char *format, ...)
|
2015-05-04 15:32:23 -07:00
|
|
|
{
|
|
|
|
char str[256];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, format);
|
|
|
|
vsnprintf(str, 256, format, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
DrawString(TOP_SCREEN0, str, x, y, RGB(0, 0, 0), RGB(255, 255, 255));
|
|
|
|
DrawString(TOP_SCREEN1, str, x, y, RGB(0, 0, 0), RGB(255, 255, 255));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debug(const char *format, ...)
|
|
|
|
{
|
2016-06-07 02:30:30 -04:00
|
|
|
char str[51];
|
|
|
|
const char* spaces = " X";
|
2015-05-04 15:32:23 -07:00
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, format);
|
2015-05-15 19:29:31 -03:00
|
|
|
vsnprintf(str, sizeof(str), format, va);
|
2015-05-04 15:32:23 -07:00
|
|
|
va_end(va);
|
2015-05-15 19:29:31 -03:00
|
|
|
snprintf(str, sizeof(str), "%s%s", str, spaces);
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2016-06-07 02:30:30 -04:00
|
|
|
DrawString(TOP_SCREEN0, str, 0u, current_y, RGB(255, 0, 0), RGB(255, 255, 255));
|
|
|
|
DrawString(TOP_SCREEN0, spaces, 0u, current_y + 10, RGB(255, 0, 0), RGB(255, 255, 255));
|
|
|
|
DrawString(TOP_SCREEN1, str, 0u, current_y, RGB(255, 0, 0), RGB(255, 255, 255));
|
|
|
|
DrawString(TOP_SCREEN1, spaces, 0u, current_y + 10, RGB(255, 0, 0), RGB(255, 255, 255));
|
2015-05-04 15:32:23 -07:00
|
|
|
|
|
|
|
current_y += 10;
|
2015-05-15 19:29:31 -03:00
|
|
|
if (current_y >= 240) {
|
|
|
|
current_y = 0;
|
|
|
|
}
|
2015-05-04 15:32:23 -07:00
|
|
|
}
|