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"
|
|
|
|
|
|
|
|
int current_y = 0;
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor)
|
|
|
|
{
|
|
|
|
int yy, xx;
|
|
|
|
for (yy = 0; yy < 8; yy++) {
|
|
|
|
int xDisplacement = (x * BYTES_PER_PIXEL * SCREEN_WIDTH);
|
|
|
|
int yDisplacement = ((SCREEN_WIDTH - (y + yy) - 1) * BYTES_PER_PIXEL);
|
|
|
|
unsigned char *screenPos = screen + xDisplacement + yDisplacement;
|
|
|
|
|
|
|
|
unsigned char charPos = font[character * 8 + yy];
|
|
|
|
for (xx = 7; xx >= 0; xx--) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawStringF(int x, int y, const char *format, ...)
|
|
|
|
{
|
|
|
|
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, ...)
|
|
|
|
{
|
2015-05-15 19:29:31 -03:00
|
|
|
char str[50];
|
|
|
|
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
|
|
|
|
|
|
|
DrawString(TOP_SCREEN0, str, 10, current_y, RGB(255, 0, 0), RGB(255, 255, 255));
|
2015-05-15 19:29:31 -03:00
|
|
|
DrawString(TOP_SCREEN0, spaces, 10, current_y + 10, RGB(255, 0, 0), RGB(255, 255, 255));
|
2015-05-04 15:32:23 -07:00
|
|
|
DrawString(TOP_SCREEN1, str, 10, current_y, RGB(255, 0, 0), RGB(255, 255, 255));
|
2015-05-15 19:29:31 -03:00
|
|
|
DrawString(TOP_SCREEN1, spaces, 10, 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
|
|
|
}
|