mirror of
https://github.com/encounter/BootCtr9.git
synced 2026-03-30 11:03:49 -07:00
775dd894d8
the posibility to set a delay for checking the pressed key
96 lines
2.4 KiB
C
96 lines
2.4 KiB
C
#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 clearScreens()
|
|
{
|
|
ClearScreen(TOP_SCREEN0,0);
|
|
ClearScreen(BOT_SCREEN0,0);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
u32 DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor)
|
|
{
|
|
int i,position=0;
|
|
for (i = 0; i < strlen(str); i++)
|
|
{
|
|
if(str[i]=='\n')
|
|
{
|
|
y+=10;
|
|
position=0;
|
|
}
|
|
else
|
|
{
|
|
DrawCharacter(screen, str[i], x + position, y, color, bgcolor);
|
|
position+=8;
|
|
}
|
|
}
|
|
return y;
|
|
}
|
|
|
|
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(255, 255, 255), RGB(0, 0, 0));
|
|
}
|
|
|
|
void drawDebug(const char *format, ...)
|
|
{
|
|
char str[256];
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
|
vsnprintf(str, 256, format, va);
|
|
va_end(va);
|
|
|
|
current_y = DrawString(BOT_SCREEN0, str, 10, current_y, RGB(255, 255, 255), RGB(0, 0, 0));
|
|
|
|
current_y += 10;
|
|
}
|