* Given an 8-bit screen with the indicated resolution, * draw the current GUI onto it. * * Currently we only support 256x* resolutions. */
| 6704 | * Currently we only support 256x* resolutions. |
| 6705 | */ |
| 6706 | void FCEU_LuaGui(uint8 *XBuf) |
| 6707 | { |
| 6708 | if (!L/* || !luaRunning*/) |
| 6709 | return; |
| 6710 | |
| 6711 | // First, check if we're being called by anybody |
| 6712 | lua_getfield(L, LUA_REGISTRYINDEX, guiCallbackTable); |
| 6713 | |
| 6714 | if (lua_isfunction(L, -1)) { |
| 6715 | // We call it now |
| 6716 | numTries = 1000; |
| 6717 | int ret = lua_pcall(L, 0, 0, 0); |
| 6718 | if (ret != 0) { |
| 6719 | #ifdef __WIN_DRIVER__ |
| 6720 | //StopSound();//StopSound(); //mbg merge 7/23/08 |
| 6721 | MessageBox(hAppWnd, lua_tostring(L, -1), "Lua Error in GUI function", MB_OK); |
| 6722 | #else |
| 6723 | LuaPrintfToWindowConsole("Lua error in gui.register function: %s\n", lua_tostring(L, -1)); |
| 6724 | fprintf(stderr, "Lua error in gui.register function: %s\n", lua_tostring(L, -1)); |
| 6725 | #endif |
| 6726 | // This is grounds for trashing the function |
| 6727 | lua_pushnil(L); |
| 6728 | lua_setfield(L, LUA_REGISTRYINDEX, guiCallbackTable); |
| 6729 | |
| 6730 | } |
| 6731 | } |
| 6732 | |
| 6733 | // And wreak the stack |
| 6734 | lua_settop(L, 0); |
| 6735 | |
| 6736 | if (gui_used == GUI_CLEAR) |
| 6737 | return; |
| 6738 | |
| 6739 | if (gui_used == GUI_USED_SINCE_LAST_FRAME && !FCEUI_EmulationPaused()) |
| 6740 | { |
| 6741 | memset(gui_data, 0, LUA_SCREEN_WIDTH*LUA_SCREEN_HEIGHT*4); |
| 6742 | gui_used = GUI_CLEAR; |
| 6743 | return; |
| 6744 | } |
| 6745 | |
| 6746 | gui_used = GUI_USED_SINCE_LAST_FRAME; |
| 6747 | |
| 6748 | int x, y; |
| 6749 | |
| 6750 | for (y = 0; y < LUA_SCREEN_HEIGHT; y++) |
| 6751 | { |
| 6752 | for (x=0; x < LUA_SCREEN_WIDTH; x++) |
| 6753 | { |
| 6754 | const uint8 gui_alpha = gui_data[(y*LUA_SCREEN_WIDTH+x)*4+3]; |
| 6755 | if (gui_alpha == 0) |
| 6756 | { |
| 6757 | // do nothing |
| 6758 | continue; |
| 6759 | } |
| 6760 | |
| 6761 | const uint8 gui_red = gui_data[(y*LUA_SCREEN_WIDTH+x)*4+2]; |
| 6762 | const uint8 gui_green = gui_data[(y*LUA_SCREEN_WIDTH+x)*4+1]; |
| 6763 | const uint8 gui_blue = gui_data[(y*LUA_SCREEN_WIDTH+x)*4]; |
no test coverage detected