Indentation fixed

This commit is contained in:
shadlyd15 2022-05-07 22:40:11 +02:00
parent 5a850a611d
commit d7d4dc3f21
6 changed files with 269 additions and 285 deletions

View File

@ -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;

View File

@ -49,8 +49,8 @@ To port this project, replace the following functions by your own:
// fill the screen with background color
void nes_set_bg_color(int c){
nes_set_bg(nes_color_palette(c));
// nes_flip_display();
nes_set_bg(nes_color_palette(c));
// nes_flip_display();
}
// flush pixel buffer to frame buffer
@ -70,7 +70,7 @@ void nes_hal_init(){
// display and empty the current frame buffer
void nes_flip_display(){
nes_gfx_swap();
nes_gfx_swap();
}
// query key-press status

View File

@ -8,66 +8,66 @@
bool _key_state[10];
void hal_nes_key_clear(){
memset(_key_state, 0x00, sizeof(_key_state));
memset(_key_state, 0x00, sizeof(_key_state));
}
void hal_nes_ctrl_key_clear(){
_key_state[NES_KEY_UP] = false;
_key_state[NES_KEY_LEFT] = false;
_key_state[NES_KEY_DOWN] = false;
_key_state[NES_KEY_RIGHT] = false;
_key_state[NES_KEY_SELECT] = false;
_key_state[NES_KEY_START] = false;
// _key_state[NES_KEY_B] = false; // Otherwise Mario will not jump long
_key_state[NES_KEY_A] = false;
_key_state[NES_KEY_REBOOT] = false;
_key_state[NES_KEY_UP] = false;
_key_state[NES_KEY_LEFT] = false;
_key_state[NES_KEY_DOWN] = false;
_key_state[NES_KEY_RIGHT] = false;
_key_state[NES_KEY_SELECT] = false;
_key_state[NES_KEY_START] = false;
// _key_state[NES_KEY_B] = false; // Otherwise Mario will not jump long
_key_state[NES_KEY_A] = false;
_key_state[NES_KEY_REBOOT] = false;
}
void hal_nes_set_key(uint32_t key){
hal_nes_key_clear();
switch(key){
case KEY_UP:
_key_state[NES_KEY_UP] = true;
break;
hal_nes_key_clear();
switch(key){
case KEY_UP:
_key_state[NES_KEY_UP] = true;
break;
case KEY_LEFT:
_key_state[NES_KEY_LEFT] = true;
break;
case KEY_LEFT:
_key_state[NES_KEY_LEFT] = true;
break;
case KEY_DOWN:
_key_state[NES_KEY_DOWN] = true;
break;
case KEY_DOWN:
_key_state[NES_KEY_DOWN] = true;
break;
case KEY_RIGHT:
_key_state[NES_KEY_RIGHT] = true;
break;
case KEY_RIGHT:
_key_state[NES_KEY_RIGHT] = true;
break;
case KEY_SELECT:
_key_state[NES_KEY_SELECT] = true;
break;
case KEY_SELECT:
_key_state[NES_KEY_SELECT] = true;
break;
case KEY_START:
_key_state[NES_KEY_START] = true;
break;
case KEY_START:
_key_state[NES_KEY_START] = true;
break;
case KEY_B:
_key_state[NES_KEY_B] = true;
break;
case KEY_B:
_key_state[NES_KEY_B] = true;
break;
case KEY_A:
_key_state[NES_KEY_A] = true;
break;
case KEY_A:
_key_state[NES_KEY_A] = true;
break;
case KEY_REBOOT:
_key_state[NES_KEY_REBOOT] = true;
break;
case KEY_REBOOT:
_key_state[NES_KEY_REBOOT] = true;
break;
default:
break;
}
default:
break;
}
}
bool hal_nes_get_key(uint16_t key){
if(!key) return true; // Power default on
return _key_state[key];
if(!key) return true; // Power default on
return _key_state[key];
}

View File

@ -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

View File

@ -25,100 +25,99 @@
/// 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,
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,
// 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 endWrite(void);
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);
// 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,
UINT32 color);
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,
UINT32 color);
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,
UINT32 color);
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,
UINT32 color);
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,
INT16 y2, UINT32 color);
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,
INT16 radius, UINT32 color);
void fillRoundRect(INT16 x0, INT16 y0, INT16 w, INT16 h,
INT16 radius, 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,
UINT32 color);
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,
INT16 y2, UINT32 color);
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,
INT16 radius, UINT32 color);
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,
INT16 h, UINT32 color);
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,
INT16 w, INT16 h);
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,
UINT32 bg, UINT8 size_x, UINT8 size_y);
void getTextBounds(const char *string, INT16 x, INT16 y, INT16 *x1,
INT16 *y1, UINT32 *w, UINT32 *h);
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,
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,
INT16 *miny, INT16 *maxx, INT16 *maxy);
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);
void print_16(UINT16 *s);

View File

@ -19,188 +19,187 @@ 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){
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);
setCursor(x_offset + 30, y_offset + 6);
setTextColor(0xFFFFFFFF);
setTextSize(1);
write(17);
print(" ");
print_16( item_name);
print(" ");
write(16);
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);
setCursor(x_offset + 30, y_offset + 6);
setTextColor(0xFFFFFFFF);
setTextSize(1);
write(17);
print(" ");
print_16(item_name);
print(" ");
write(16);
}
bool load_current_nes_file(){
bool rc = false;;
EFI_DEVICE_PATH * dp;
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*)&dp);
bool rc = false;;
EFI_DEVICE_PATH * dp;
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*) &dp);
EFI_FILE_HANDLE FileHandle;
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);
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);
UINT64 ReadSize = file_size(FileHandle);
EFI_HANDLE *Buffer = AllocatePool(ReadSize);
uefi_call_wrapper(FileHandle->Read, 3, FileHandle, &ReadSize, Buffer);
uefi_call_wrapper(FileHandle->Read, 3, FileHandle, &ReadSize, Buffer);
if(fce_load_rom((char*)Buffer) == 0){
// Print(L"ROM LOADED\n\r");
draw_menu(L"ROM LOADED");
rc = true;
} else{
draw_menu(L"ROM LOAD ERROR");
}
// uefi_call_wrapper(FileHandle->Close, 0);
FreePool(Buffer);
return rc;
if (fce_load_rom((char*) Buffer) == 0){
// Print(L"ROM LOADED\n\r");
draw_menu(L "ROM LOADED");
rc = true;
}
else{
draw_menu(L "ROM LOAD ERROR");
}
FreePool(Buffer);
return rc;
}
void render_menu(UINT16 key){
switch(key){
case KEY_UP:
case KEY_RIGHT:{
current_rom_index++;
current_rom_index = current_rom_index % total_roms;
break;
}
switch (key){
case KEY_UP:
case KEY_RIGHT:{
current_rom_index++;
current_rom_index = current_rom_index % total_roms;
break;
}
case KEY_DOWN:
case KEY_LEFT:{
current_rom_index--;
if(current_rom_index < 0){
current_rom_index = total_roms - 1;
}
break;
}
case KEY_DOWN:
case KEY_LEFT:{
current_rom_index--;
if (current_rom_index < 0)
{
current_rom_index = total_roms - 1;
}
break;
}
case KEY_START:{
g_ui_state = UI_STATE_LOAD_ROM;
break;
}
case KEY_START:{
g_ui_state = UI_STATE_LOAD_ROM;
break;
}
default:
break;
}
draw_menu(rom_collection[current_rom_index]);
default:
break;
}
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);
total_roms++;
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);
list_directory(root, dp, save_rom_info);
return total_roms;
EFI_DEVICE_PATH * 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){
case UI_STATE_SPLASH:{
render_splash_screen();
g_ui_state = UI_STATE_MENU;
break;
}
switch (g_ui_state){
case UI_STATE_SPLASH:{
render_splash_screen();
g_ui_state = UI_STATE_MENU;
break;
}
case UI_STATE_MENU:{
break;
}
case UI_STATE_MENU:{
break;
}
case UI_STATE_LOAD_ROM:{
if(load_current_nes_file()){
fce_init();
graphics_clear_framebuffer(kernel.graphics);
g_ui_state = UI_STATE_PLAY;
} else{
g_ui_state = UI_STATE_MENU;
}
break;
}
case UI_STATE_LOAD_ROM:{
if (load_current_nes_file()){
fce_init();
graphics_clear_framebuffer(kernel.graphics);
g_ui_state = UI_STATE_PLAY;
}
else{
g_ui_state = UI_STATE_MENU;
}
break;
}
case UI_STATE_PLAY:{
case UI_STATE_PLAY:{
fce_run();
// hal_nes_ctrl_key_clear();
break;
fce_run();
break;
}
}
}
return g_ui_state;
return g_ui_state;
}
void render_splash_screen(){
EFI_DEVICE_PATH * dp;
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*)&dp);
EFI_DEVICE_PATH * dp;
EFI_FILE_HANDLE root = get_volume(kernel.image_handle, (void*) &dp);
CHAR16 *FileName = L"splash.bmp";
EFI_FILE_HANDLE FileHandle;
graphics_clear_framebuffer(kernel.graphics);
/* 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);
CHAR16 *FileName = L "splash.bmp";
EFI_FILE_HANDLE FileHandle;
graphics_clear_framebuffer(kernel.graphics);
/*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 */
UINT64 ReadSize = file_size(FileHandle);
EFI_HANDLE * Buffer = AllocatePool(ReadSize);
/*read from the file */
UINT64 ReadSize = file_size(FileHandle);
EFI_HANDLE *Buffer = AllocatePool(ReadSize);
uefi_call_wrapper(FileHandle->Read, 3, FileHandle, &ReadSize, 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;
uefi_call_wrapper(FileHandle->Read, 3, FileHandle, &ReadSize, 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);
FreePool(Buffer);
// WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
graphics_draw_bitmap(kernel.graphics, x_offset, y_offset, (void **) Buffer);
FreePool(Buffer);
}
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){
hal_nes_set_key(key);
if(key == 'r'){
g_ui_state = UI_STATE_SPLASH;
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'){
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;
}