mirror of
https://github.com/shadlyd15/NesUEFI
synced 2024-11-21 20:31:23 +03:00
Indentation fixed
This commit is contained in:
parent
5a850a611d
commit
d7d4dc3f21
@ -6,11 +6,9 @@
|
||||
EFI_EVENT TimerEvent;
|
||||
|
||||
|
||||
EFIAPI void TimerHandler (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
)
|
||||
{ kernel.ticks++; }
|
||||
EFIAPI void TimerHandler ( IN EFI_EVENT Event, IN void *Context){
|
||||
kernel.ticks++;
|
||||
}
|
||||
|
||||
unsigned long long timer_ticks(){
|
||||
return kernel.ticks;
|
||||
|
@ -129,18 +129,6 @@ void setCursor(INT16 x, INT16 y) {
|
||||
/**********************************************************************/
|
||||
void setTextColor(UINT32 c) { textcolor = textbgcolor = c; }
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Set text font color with custom background color
|
||||
@param c 16-bit 5-6-5 Color to draw text with
|
||||
@param bg 16-bit 5-6-5 Color to draw background/fill with
|
||||
*/
|
||||
/**********************************************************************/
|
||||
// void setTextColor(UINT32 c, UINT32 bg) {
|
||||
// textcolor = c;
|
||||
// textbgcolor = bg;
|
||||
// }
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Set whether text that is too long for the screen width should
|
||||
|
@ -25,99 +25,98 @@
|
||||
/// minimum you can subclass and provide drawPixel(). At a maximum you can do a
|
||||
/// ton of overriding to optimize. Used for any/all Adafruit displays!
|
||||
|
||||
void adafruit_gfx_init(INT16 w, INT16 h); // Constructor
|
||||
void adafruit_gfx_init(INT16 w, INT16 h); // Constructor
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Draw to the screen/framebuffer/etc.
|
||||
Must be overridden in subclass.
|
||||
@param x X coordinate in pixels
|
||||
@param y Y coordinate in pixels
|
||||
@param color 16-bit pixel color.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void drawPixel(INT16 x, INT16 y, UINT32 color);
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Draw to the screen/framebuffer/etc.
|
||||
Must be overridden in subclass.
|
||||
@param x X coordinate in pixels
|
||||
@param y Y coordinate in pixels
|
||||
@param color 16-bit pixel color.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void drawPixel(INT16 x, INT16 y, UINT32 color);
|
||||
|
||||
// TRANSACTION API / CORE DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
void startWrite(void);
|
||||
void writePixel(INT16 x, INT16 y, UINT32 color);
|
||||
void writeFillRect(INT16 x, INT16 y, INT16 w, INT16 h,
|
||||
// TRANSACTION API / CORE DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
void startWrite(void);
|
||||
void writePixel(INT16 x, INT16 y, UINT32 color);
|
||||
void writeFillRect(INT16 x, INT16 y, INT16 w, INT16 h,
|
||||
UINT32 color);
|
||||
void writeFastVLine(INT16 x, INT16 y, INT16 h, UINT32 color);
|
||||
void writeFastHLine(INT16 x, INT16 y, INT16 w, UINT32 color);
|
||||
void writeLine(INT16 x0, INT16 y0, INT16 x1, INT16 y1,
|
||||
void writeFastVLine(INT16 x, INT16 y, INT16 h, UINT32 color);
|
||||
void writeFastHLine(INT16 x, INT16 y, INT16 w, UINT32 color);
|
||||
void writeLine(INT16 x0, INT16 y0, INT16 x1, INT16 y1,
|
||||
UINT32 color);
|
||||
void endWrite(void);
|
||||
void endWrite(void);
|
||||
|
||||
// CONTROL API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
void setRotation(UINT8 r);
|
||||
void invertDisplay(bool i);
|
||||
// CONTROL API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
void setRotation(UINT8 r);
|
||||
void invertDisplay(bool i);
|
||||
|
||||
// BASIC DRAW API
|
||||
// BASIC DRAW API
|
||||
|
||||
|
||||
void drawFastVLine(INT16 x, INT16 y, INT16 h, UINT32 color);
|
||||
void drawFastHLine(INT16 x, INT16 y, INT16 w, UINT32 color);
|
||||
void fillRect(INT16 x, INT16 y, INT16 w, INT16 h,
|
||||
void drawFastVLine(INT16 x, INT16 y, INT16 h, UINT32 color);
|
||||
void drawFastHLine(INT16 x, INT16 y, INT16 w, UINT32 color);
|
||||
void fillRect(INT16 x, INT16 y, INT16 w, INT16 h,
|
||||
UINT32 color);
|
||||
void fillScreen(UINT32 color);
|
||||
// Optional and probably not necessary to change
|
||||
void drawLine(INT16 x0, INT16 y0, INT16 x1, INT16 y1,
|
||||
void fillScreen(UINT32 color);
|
||||
// Optional and probably not necessary to change
|
||||
void drawLine(INT16 x0, INT16 y0, INT16 x1, INT16 y1,
|
||||
UINT32 color);
|
||||
void drawRect(INT16 x, INT16 y, INT16 w, INT16 h,
|
||||
void drawRect(INT16 x, INT16 y, INT16 w, INT16 h,
|
||||
UINT32 color);
|
||||
|
||||
// These exist only with Adafruit_GFX (no subclass overrides)
|
||||
void drawCircle(INT16 x0, INT16 y0, INT16 r, UINT32 color);
|
||||
void drawCircleHelper(INT16 x0, INT16 y0, INT16 r, UINT8 cornername,
|
||||
// These exist only with Adafruit_GFX (no subclass overrides)
|
||||
void drawCircle(INT16 x0, INT16 y0, INT16 r, UINT32 color);
|
||||
void drawCircleHelper(INT16 x0, INT16 y0, INT16 r, UINT8 cornername,
|
||||
UINT32 color);
|
||||
void fillCircle(INT16 x0, INT16 y0, INT16 r, UINT32 color);
|
||||
void fillCircleHelper(INT16 x0, INT16 y0, INT16 r, UINT8 cornername,
|
||||
void fillCircle(INT16 x0, INT16 y0, INT16 r, UINT32 color);
|
||||
void fillCircleHelper(INT16 x0, INT16 y0, INT16 r, UINT8 cornername,
|
||||
INT16 delta, UINT32 color);
|
||||
void drawTriangle(INT16 x0, INT16 y0, INT16 x1, INT16 y1, INT16 x2,
|
||||
void drawTriangle(INT16 x0, INT16 y0, INT16 x1, INT16 y1, INT16 x2,
|
||||
INT16 y2, UINT32 color);
|
||||
void fillTriangle(INT16 x0, INT16 y0, INT16 x1, INT16 y1, INT16 x2,
|
||||
void fillTriangle(INT16 x0, INT16 y0, INT16 x1, INT16 y1, INT16 x2,
|
||||
INT16 y2, UINT32 color);
|
||||
void drawRoundRect(INT16 x0, INT16 y0, INT16 w, INT16 h,
|
||||
void drawRoundRect(INT16 x0, INT16 y0, INT16 w, INT16 h,
|
||||
INT16 radius, UINT32 color);
|
||||
void fillRoundRect(INT16 x0, INT16 y0, INT16 w, INT16 h,
|
||||
void fillRoundRect(INT16 x0, INT16 y0, INT16 w, INT16 h,
|
||||
INT16 radius, UINT32 color);
|
||||
|
||||
void drawBitmap(INT16 x, INT16 y, UINT8 *bitmap, INT16 w, INT16 h, UINT32 color, UINT32 bg);
|
||||
void drawBitmap(INT16 x, INT16 y, UINT8 *bitmap, INT16 w, INT16 h, UINT32 color, UINT32 bg);
|
||||
|
||||
void drawXBitmap(INT16 x, INT16 y, const UINT8 bitmap[], INT16 w,
|
||||
void drawXBitmap(INT16 x, INT16 y, const UINT8 bitmap[], INT16 w,
|
||||
INT16 h, UINT32 color);
|
||||
|
||||
void drawGrayscaleBitmap(INT16 x, INT16 y, UINT8 *bitmap, UINT8 *mask, INT16 w, INT16 h);
|
||||
void drawGrayscaleBitmap(INT16 x, INT16 y, UINT8 *bitmap, UINT8 *mask, INT16 w, INT16 h);
|
||||
|
||||
void drawRGBBitmap(INT16 x, INT16 y, UINT32 *bitmap, UINT8 *mask,
|
||||
void drawRGBBitmap(INT16 x, INT16 y, UINT32 *bitmap, UINT8 *mask,
|
||||
INT16 w, INT16 h);
|
||||
|
||||
void drawChar(INT16 x, INT16 y, unsigned char c, UINT32 color,
|
||||
void drawChar(INT16 x, INT16 y, unsigned char c, UINT32 color,
|
||||
UINT32 bg, UINT8 size_x, UINT8 size_y);
|
||||
void getTextBounds(const char *string, INT16 x, INT16 y, INT16 *x1,
|
||||
void getTextBounds(const char *string, INT16 x, INT16 y, INT16 *x1,
|
||||
INT16 *y1, UINT32 *w, UINT32 *h);
|
||||
|
||||
size_t write(UINT8 c);
|
||||
void setTextSize(UINT8 s);
|
||||
void setFont(const GFXfont *f);
|
||||
size_t write(UINT8 c);
|
||||
void setTextSize(UINT8 s);
|
||||
void setFont(const GFXfont *f);
|
||||
|
||||
void setCursor(INT16 x, INT16 y);
|
||||
void setCursor(INT16 x, INT16 y);
|
||||
|
||||
void setTextColor(UINT32 c);
|
||||
// void setTextColor(UINT32 c, UINT32 bg);
|
||||
void setTextWrap(bool w);
|
||||
void cp437(bool x);
|
||||
INT16 width(void);
|
||||
INT16 height(void);
|
||||
UINT8 getRotation(void);
|
||||
INT16 getCursorX(void);
|
||||
INT16 getCursorY(void);
|
||||
void charBounds(unsigned char c, INT16 *x, INT16 *y, INT16 *minx,
|
||||
void setTextColor(UINT32 c);
|
||||
void setTextWrap(bool w);
|
||||
void cp437(bool x);
|
||||
INT16 width(void);
|
||||
INT16 height(void);
|
||||
UINT8 getRotation(void);
|
||||
INT16 getCursorX(void);
|
||||
INT16 getCursorY(void);
|
||||
void charBounds(unsigned char c, INT16 *x, INT16 *y, INT16 *minx,
|
||||
INT16 *miny, INT16 *maxx, INT16 *maxy);
|
||||
|
||||
void print(char *s);
|
||||
|
@ -19,47 +19,18 @@ ui_state_t g_ui_state = UI_STATE_SPLASH;
|
||||
static int total_roms = 0;
|
||||
static int current_rom_index = 0;
|
||||
|
||||
CHAR16 * strstr_16(CHAR16 * string, CHAR16 * substring){
|
||||
CHAR16 *a, *b;
|
||||
// https://opensource.apple.com/source/tcl/tcl-10/tcl/compat/strstr.c.auto.html
|
||||
/* First scan quickly through the two strings looking for a
|
||||
* single-character match. When it's found, then compare the
|
||||
* rest of the substring.
|
||||
*/
|
||||
CHAR16* strstr_16(CHAR16 *string, CHAR16 *substring);
|
||||
|
||||
b = substring;
|
||||
if (*b == 0) {
|
||||
return string;
|
||||
}
|
||||
for ( ; *string != 0; string += 1) {
|
||||
if (*string != *b) {
|
||||
continue;
|
||||
}
|
||||
a = string;
|
||||
while (1) {
|
||||
if (*b == 0) {
|
||||
return string;
|
||||
}
|
||||
if (*a++ != *b++) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
b = substring;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void draw_menu(CHAR16 * item_name){
|
||||
void draw_menu(CHAR16 *item_name){
|
||||
int x_offset = (kernel.graphics->Mode->Info->HorizontalResolution - 601) / 2;
|
||||
int y_offset = (kernel.graphics->Mode->Info->VerticalResolution - 573) / 2 + 495;
|
||||
fillRect( x_offset, y_offset, 573, 20, 0x0f4106);
|
||||
fillRect(x_offset, y_offset, 573, 20, 0x0f4106);
|
||||
setCursor(x_offset + 30, y_offset + 6);
|
||||
setTextColor(0xFFFFFFFF);
|
||||
setTextSize(1);
|
||||
write(17);
|
||||
print(" ");
|
||||
print_16( item_name);
|
||||
print_16(item_name);
|
||||
print(" ");
|
||||
write(16);
|
||||
}
|
||||
@ -67,32 +38,31 @@ void draw_menu(CHAR16 * item_name){
|
||||
bool load_current_nes_file(){
|
||||
bool rc = false;;
|
||||
EFI_DEVICE_PATH * dp;
|
||||
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*)&dp);
|
||||
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*) &dp);
|
||||
|
||||
EFI_FILE_HANDLE FileHandle;
|
||||
|
||||
uefi_call_wrapper(root->Open, 5, root, &FileHandle, rom_collection[current_rom_index], EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
|
||||
|
||||
UINT64 ReadSize = file_size(FileHandle);
|
||||
EFI_HANDLE * Buffer = AllocatePool(ReadSize);
|
||||
EFI_HANDLE *Buffer = AllocatePool(ReadSize);
|
||||
|
||||
uefi_call_wrapper(FileHandle->Read, 3, FileHandle, &ReadSize, Buffer);
|
||||
|
||||
|
||||
if(fce_load_rom((char*)Buffer) == 0){
|
||||
if (fce_load_rom((char*) Buffer) == 0){
|
||||
// Print(L"ROM LOADED\n\r");
|
||||
draw_menu(L"ROM LOADED");
|
||||
draw_menu(L "ROM LOADED");
|
||||
rc = true;
|
||||
} else{
|
||||
draw_menu(L"ROM LOAD ERROR");
|
||||
}
|
||||
// uefi_call_wrapper(FileHandle->Close, 0);
|
||||
else{
|
||||
draw_menu(L "ROM LOAD ERROR");
|
||||
}
|
||||
FreePool(Buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void render_menu(UINT16 key){
|
||||
switch(key){
|
||||
switch (key){
|
||||
case KEY_UP:
|
||||
case KEY_RIGHT:{
|
||||
current_rom_index++;
|
||||
@ -103,7 +73,8 @@ void render_menu(UINT16 key){
|
||||
case KEY_DOWN:
|
||||
case KEY_LEFT:{
|
||||
current_rom_index--;
|
||||
if(current_rom_index < 0){
|
||||
if (current_rom_index < 0)
|
||||
{
|
||||
current_rom_index = total_roms - 1;
|
||||
}
|
||||
break;
|
||||
@ -120,23 +91,22 @@ void render_menu(UINT16 key){
|
||||
draw_menu(rom_collection[current_rom_index]);
|
||||
}
|
||||
|
||||
void save_rom_info(EFI_FILE_INFO * info){
|
||||
// Print(L"FileName = %s\n", info -> FileName);
|
||||
if((strstr_16(info -> FileName, L".nes")) || (strstr_16(info -> FileName, L".NES"))){
|
||||
StrCpy(rom_collection[total_roms], info -> FileName);
|
||||
void save_rom_info(EFI_FILE_INFO *info){
|
||||
if ((strstr_16(info->FileName, L ".nes")) || (strstr_16(info->FileName, L ".NES"))){
|
||||
StrCpy(rom_collection[total_roms], info->FileName);
|
||||
total_roms++;
|
||||
}
|
||||
}
|
||||
|
||||
int populate_menu_items(){
|
||||
EFI_DEVICE_PATH * dp;
|
||||
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*)&dp);
|
||||
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*) &dp);
|
||||
list_directory(root, dp, save_rom_info);
|
||||
return total_roms;
|
||||
}
|
||||
|
||||
ui_state_t ui_manage_states(){
|
||||
switch(g_ui_state){
|
||||
switch (g_ui_state){
|
||||
case UI_STATE_SPLASH:{
|
||||
render_splash_screen();
|
||||
g_ui_state = UI_STATE_MENU;
|
||||
@ -148,11 +118,12 @@ ui_state_t ui_manage_states(){
|
||||
}
|
||||
|
||||
case UI_STATE_LOAD_ROM:{
|
||||
if(load_current_nes_file()){
|
||||
if (load_current_nes_file()){
|
||||
fce_init();
|
||||
graphics_clear_framebuffer(kernel.graphics);
|
||||
g_ui_state = UI_STATE_PLAY;
|
||||
} else{
|
||||
}
|
||||
else{
|
||||
g_ui_state = UI_STATE_MENU;
|
||||
}
|
||||
break;
|
||||
@ -161,7 +132,6 @@ ui_state_t ui_manage_states(){
|
||||
case UI_STATE_PLAY:{
|
||||
|
||||
fce_run();
|
||||
// hal_nes_ctrl_key_clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -171,36 +141,65 @@ ui_state_t ui_manage_states(){
|
||||
void render_splash_screen(){
|
||||
|
||||
EFI_DEVICE_PATH * dp;
|
||||
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*)&dp);
|
||||
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*) &dp);
|
||||
|
||||
CHAR16 *FileName = L"splash.bmp";
|
||||
CHAR16 *FileName = L "splash.bmp";
|
||||
EFI_FILE_HANDLE FileHandle;
|
||||
graphics_clear_framebuffer(kernel.graphics);
|
||||
/* open the file */
|
||||
/*open the file */
|
||||
uefi_call_wrapper(root->Open, 5, root, &FileHandle, FileName, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
|
||||
|
||||
/* read from the file */
|
||||
/*read from the file */
|
||||
UINT64 ReadSize = file_size(FileHandle);
|
||||
EFI_HANDLE * Buffer = AllocatePool(ReadSize);
|
||||
EFI_HANDLE *Buffer = AllocatePool(ReadSize);
|
||||
|
||||
uefi_call_wrapper(FileHandle->Read, 3, FileHandle, &ReadSize, Buffer);
|
||||
BMP_IMAGE_HEADER * bmp_header = (BMP_IMAGE_HEADER *) Buffer;
|
||||
BMP_IMAGE_HEADER *bmp_header = (BMP_IMAGE_HEADER*) Buffer;
|
||||
int x_offset = (kernel.graphics->Mode->Info->HorizontalResolution - bmp_header->PixelHeight) / 2;
|
||||
int y_offset = (kernel.graphics->Mode->Info->VerticalResolution - bmp_header->PixelWidth) / 2;
|
||||
|
||||
graphics_draw_bitmap( kernel.graphics, x_offset, y_offset, (void**)Buffer);
|
||||
// uefi_call_wrapper(FileHandle->Close, 0);
|
||||
graphics_draw_bitmap(kernel.graphics, x_offset, y_offset, (void **) Buffer);
|
||||
FreePool(Buffer);
|
||||
// WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
|
||||
}
|
||||
|
||||
|
||||
void ui_key_handler(uint32_t key){
|
||||
if(g_ui_state == UI_STATE_MENU){render_menu(key);}
|
||||
else if(g_ui_state == UI_STATE_PLAY){
|
||||
if (g_ui_state == UI_STATE_MENU){
|
||||
render_menu(key);
|
||||
}
|
||||
else if (g_ui_state == UI_STATE_PLAY){
|
||||
hal_nes_set_key(key);
|
||||
if(key == 'r'){
|
||||
if (key == 'r'){
|
||||
g_ui_state = UI_STATE_SPLASH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHAR16* strstr_16(CHAR16 *string, CHAR16 *substring){
|
||||
// https://opensource.apple.com/source/tcl/tcl-10/tcl/compat/strstr.c.auto.html
|
||||
// Modified for CHAR16
|
||||
/*First scan quickly through the two strings looking for a
|
||||
*single-character match. When it's found, then compare the
|
||||
*rest of the substring.
|
||||
*/
|
||||
CHAR16 *a, *b;
|
||||
b = substring;
|
||||
if (*b == 0){
|
||||
return string;
|
||||
}
|
||||
for (; *string != 0; string += 1){
|
||||
if (*string != *b){
|
||||
continue;
|
||||
}
|
||||
a = string;
|
||||
while (1){
|
||||
if (*b == 0){
|
||||
return string;
|
||||
}
|
||||
if (*a++ != *b++){
|
||||
break;
|
||||
}
|
||||
}
|
||||
b = substring;
|
||||
}
|
||||
return NULL;
|
||||
}
|
Loading…
Reference in New Issue
Block a user