diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e657ed..5a74c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(CMAKE_CXX_STANDARD 17) # Packages find_package(SDL2 REQUIRED) +# find_package(glfw3 3.0 REQUIRED) +# find_package(OpenGL REQUIRED) file(GLOB SRC_FILES "${SRC_DIR}/*.c" "${SRC_LCD_DIR}/*.c") # file(GLOB IMGUI_FILES "${IMGUI_DIR}/*.c" "${IMGUI_DIR}/*.cpp") @@ -34,5 +36,7 @@ add_executable(${PROJECT_NAME} ${SRC_FILES} ${IMGUI_FILES}) target_include_directories(${PROJECT_NAME} PUBLIC ${SRC_LCD_DIR} ${IMGUI_DIR}) # Compiler Flags Debug(-g -O0) Release(-O3) set(OPT_FLAG -g -O3) -target_compile_options(${PROJECT_NAME} PUBLIC ${OPT_FLAG} -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable) -target_link_libraries(${PROJECT_NAME} PUBLIC SDL2 SDL2main) +target_compile_options(${PROJECT_NAME} PUBLIC ${OPT_FLAG} -Wall -Wextra -Wshadow) + +# target_link_libraries(${PROJECT_NAME} PUBLIC -l:libglfw3.a -lgdi32 OpenGL::GL -lglew32 SDL2 SDL2main) +target_link_libraries(${PROJECT_NAME} PUBLIC SDL2 SDL2main) \ No newline at end of file diff --git a/src-lcd/x86_Common_Def.c b/src-lcd/x86_Common_Def.c index 1f6cd25..8165557 100644 --- a/src-lcd/x86_Common_Def.c +++ b/src-lcd/x86_Common_Def.c @@ -11,7 +11,7 @@ fp64 getDecimalTime() { struct timespec tp; if (clock_gettime(CLOCK_REALTIME, &tp) == 0) { - uint64_t nanoTime = tp.tv_sec * 1000000000 + tp.tv_nsec; + nano64_t nanoTime = tp.tv_sec * 1000000000 + tp.tv_nsec; return (fp64)nanoTime / 1.0e9; } else { perror("clock_gettime"); @@ -19,10 +19,10 @@ fp64 getDecimalTime() { } } -int64_t getNanoTime() { +nano64_t getNanoTime() { struct timespec tp; if (clock_gettime(CLOCK_REALTIME, &tp) == 0) { - int64_t nanoTime = tp.tv_sec * 1000000000 + tp.tv_nsec; + nano64_t nanoTime = tp.tv_sec * 1000000000 + tp.tv_nsec; return nanoTime; } else { perror("clock_gettime"); diff --git a/src-lcd/x86_Common_Def.h b/src-lcd/x86_Common_Def.h index 684e8f4..76c198e 100644 --- a/src-lcd/x86_Common_Def.h +++ b/src-lcd/x86_Common_Def.h @@ -33,6 +33,8 @@ typedef unsigned _BitInt(24) uint24_t; typedef float fp32; typedef double fp64; +typedef int64_t nano64_t; + /* Constants */ #define PI 3.1415926535897932384626433832795 @@ -61,7 +63,15 @@ typedef double fp64; /* Time */ - int64_t getNanoTime(); + nano64_t getNanoTime(); + + #define NANO_TO_SECONDS(t) ((fp64)(t) / 1.0e9) + #define NANO_TO_FRAMERATE(t) (1.0e9 / (fp64)(t)) + #define SECONDS_TO_NANO(s) ((nano64_t)((s) * 1.0e9)) + #define SECONDS_TO_FRAMERATE(s) (1.0 / (s)) + #define FRAMERATE_TO_NANO(f) ((nano64_t)(1.0e9 / (f))) + #define FRAMERATE_TO_SECONDS(f) (1.0 / (f)) + fp64 getDecimalTime(); #endif /* X86_COMMON_DEF_H */ \ No newline at end of file diff --git a/src-lcd/x86_Render.c b/src-lcd/x86_Render.c index 58758c7..8b6eb0d 100644 --- a/src-lcd/x86_Render.c +++ b/src-lcd/x86_Render.c @@ -15,8 +15,16 @@ #define SDL_MAIN_HANDLED #include +// #define Enable_OpenGL + +#ifdef Enable_OpenGL + #define GLEW_STATIC + #include + #include +#endif + // Integer Scaling -uint8_t scale = 2; +uint8_t init_scale = 2; uint8_t darkMode = 0; bool useMouseInGame = true; @@ -119,17 +127,45 @@ struct BufferBox { BufferBox Master; SDL_Event event; -SDL_Renderer *renderer; -SDL_Window *window; -SDL_Texture* texture; + +SDL_Window* window; + +#ifdef Enable_OpenGL + SDL_GLContext* SDL_OpenGL_context; + GLuint OpenGL_texture; +#else + SDL_Texture* texture; + SDL_Renderer *renderer; +#endif /* Mouse Handling */ uint32_t getMouseState(int32_t* posX, int32_t* posY) { - int32_t x; - int32_t y; + int32_t x, y; uint32_t state = SDL_GetMouseState(&x,&y); - x = (x * LCD_RESX) / Master.resX; - y = (y * LCD_RESY) / Master.resY; + int32_t window_ResX, window_ResY; + SDL_GetWindowSize(window, &window_ResX, &window_ResY); + + int32_t offsetX = 0; + int32_t offsetY = 0; + int32_t image_ResX = window_ResX; + int32_t image_ResY = window_ResY; + { + const fp64 LCD_AspectRatio = (fp64)LCD_RESX / (fp64)LCD_RESY; + const fp64 LCD_AspectRatio_Inverse = (fp64)LCD_RESY / (fp64)LCD_RESX; + const fp64 window_AspectRatio = (fp64)window_ResX / (fp64)window_ResY; + + if (window_AspectRatio > LCD_AspectRatio) { + image_ResX = (int32_t)((fp64)window_ResY * LCD_AspectRatio); + offsetX = (window_ResX - image_ResX) / 2; + } else if (window_AspectRatio < LCD_AspectRatio) { + image_ResY = (int32_t)((fp64)window_ResX * LCD_AspectRatio_Inverse); + offsetY = (window_ResY - image_ResY) / 2; + } + } + + x = ((x - offsetX) * LCD_RESX) / (image_ResX); + y = ((y - offsetY) * LCD_RESY) / (image_ResY); + if (posX != NULL) { *posX = x; } if (posY != NULL) { *posY = y; } return state; @@ -178,7 +214,7 @@ SDL_Event* grab_SDL2_event() { return &event; } -int32_t pitch = LCD_RESX * 3; +const int32_t pitch = LCD_RESX * 3; uint8_t videoCopy[153600]; uint16_t color16[256]; @@ -372,148 +408,351 @@ void internal_kb_Scan() { } } -void renderCursor(uint8_t* data) { - size_t posX = lcd_CrsrX; - size_t posY = lcd_CrsrY; - for (size_t i = 0; i < lcd_CrsrImageLen64; i++) { +/* Nearest Neighbor Scalers */ +/* + void blit16bpp(uint8_t* data) { + uint8_t* PreCalc16; + uint8_t colorMode = (lcd_VideoMode & 0b1110) >> 1; + switch (colorMode) { + case 0b100: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR1555 : PreCalc_RGB1555; + break; + case 0b110: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR565 : PreCalc_RGB565; + break; + case 0b111: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR444 : PreCalc_RGB444; + break; + default: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR555 : PreCalc_RGB555; + }; + size_t w = 0; + size_t z = 0; + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX; x++) { + uint32_t c = (uint32_t)((uint16_t*)videoCopy)[z]; + c *= 3; + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint8_t s = 0; s < lenX; s++) { + data[w] = PreCalc16[c]; w++; + data[w] = PreCalc16[c + 1]; w++; + data[w] = PreCalc16[c + 2]; w++; + } + z += columnMajorMode ? LCD_RESY : 1; + } + z -= columnMajorMode ? ((LCD_RESX * LCD_RESY) - 1) : 0; + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); + //w += Master.pitch - (LCD_RESX * lenY * 3); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } + void blit8bpp(uint8_t* data) { + size_t w = 0; + size_t z = 0; + for (uint32_t y = 0; y < (uint32_t)LCD_RESY; y++) { + for (uint32_t x = 0; x < (uint32_t)LCD_RESX; x++) { + uint8_t c = videoCopy[z]; + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint8_t s = 0; s < lenX; s++) { + data[w] = colorR[c]; w++; + data[w] = colorG[c]; w++; + data[w] = colorB[c]; w++; + } + z += columnMajorMode ? LCD_RESY : 1; + } + z -= columnMajorMode ? ((LCD_RESX * LCD_RESY) - 1) : 0; + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); + //w += Master.pitch - (LCD_RESX * lenY * 3); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } } -} -void blit16bpp(uint8_t* data) { - uint8_t* PreCalc16; - uint8_t colorMode = (lcd_VideoMode & 0b1110) >> 1; - switch (colorMode) { - case 0b100: - PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR1555 : PreCalc_RGB1555; - break; - case 0b110: - PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR565 : PreCalc_RGB565; - break; - case 0b111: - PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR444 : PreCalc_RGB444; - break; - default: - PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR555 : PreCalc_RGB555; - }; - size_t w = 0; - size_t z = 0; - for (uint32_t y = 0; y < LCD_RESY; y++) { - for (uint32_t x = 0; x < LCD_RESX; x++) { - uint32_t c = (uint32_t)((uint16_t*)videoCopy)[z]; - c *= 3; - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint8_t s = 0; s < lenX; s++) { + void blit4bpp(uint8_t* data) { + const uint32_t PixelsPerByte = 2; + size_t w = 0; + size_t z = 0; + if (columnMajorMode == false) { + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { + uint8_t c = videoCopy[z]; + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint8_t s = 0; s < lenX; s++) { + data[w] = colorR[c & 0xF]; w++; + data[w] = colorG[c & 0xF]; w++; + data[w] = colorB[c & 0xF]; w++; + data[w] = colorR[(c >> 4) & 0xF]; w++; + data[w] = colorG[(c >> 4) & 0xF]; w++; + data[w] = colorB[(c >> 4) & 0xF]; w++; + } + z++; + } + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); + //w += Master.pitch - (LCD_RESX * lenY * 3); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } else { + for (uint32_t x = 0; x < LCD_RESX; x++) { + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { + uint8_t c = videoCopy[z]; + for (uint32_t i = 0; i < PixelsPerByte; i++) { + uint8_t lenY = ((Master.resY * (y + i + 1)) / LCD_RESY) - ((Master.resY * (y + i)) / LCD_RESY); + for (uint32_t s = 0; s < lenX; s++) { + data[w] = colorR[c & 0xF]; w++; + data[w] = colorG[c & 0xF]; w++; + data[w] = colorB[c & 0xF]; w++; + } + w += (Master.pitch - (3 * lenX)); + w += (Master.pitch * (lenY - 1)); + c >>= 4; + } + z++; + } + w -= Master.pitch * Master.resY; + w += (3 * lenX); + } + // memcpy's lines + w = 0; + for (uint32_t y = 0; y < LCD_RESY; y++) { + w += Master.pitch; + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * (y)) / LCD_RESY); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } + } + + void blit2bpp(uint8_t* data) { + const uint32_t PixelsPerByte = 4; + size_t w = 0; + size_t z = 0; + if (columnMajorMode == false) { + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { + uint8_t c = videoCopy[z]; + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint8_t s = 0; s < lenX; s++) { + data[w] = colorR[c & 0x3]; w++; + data[w] = colorG[c & 0x3]; w++; + data[w] = colorB[c & 0x3]; w++; + data[w] = colorR[(c >> 2) & 0x3]; w++; + data[w] = colorG[(c >> 2) & 0x3]; w++; + data[w] = colorB[(c >> 2) & 0x3]; w++; + data[w] = colorR[(c >> 4) & 0x3]; w++; + data[w] = colorG[(c >> 4) & 0x3]; w++; + data[w] = colorB[(c >> 4) & 0x3]; w++; + data[w] = colorR[(c >> 6) & 0x3]; w++; + data[w] = colorG[(c >> 6) & 0x3]; w++; + data[w] = colorB[(c >> 6) & 0x3]; w++; + } + z++; + } + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); + //w += Master.pitch - (LCD_RESX * lenY * 3); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } else { + for (uint32_t x = 0; x < LCD_RESX; x++) { + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { + uint8_t c = videoCopy[z]; + for (uint32_t i = 0; i < PixelsPerByte; i++) { + uint8_t lenY = ((Master.resY * (y + i + 1)) / LCD_RESY) - ((Master.resY * (y + i)) / LCD_RESY); + for (uint32_t s = 0; s < lenX; s++) { + data[w] = colorR[c & 0x3]; w++; + data[w] = colorG[c & 0x3]; w++; + data[w] = colorB[c & 0x3]; w++; + } + w += (Master.pitch - (3 * lenX)); + w += (Master.pitch * (lenY - 1)); + c >>= 2; + } + z++; + } + w -= Master.pitch * Master.resY; + w += (3 * lenX); + } + // memcpy's lines + w = 0; + for (uint32_t y = 0; y < LCD_RESY; y++) { + w += Master.pitch; + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * (y)) / LCD_RESY); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } + } + + void blit1bpp(uint8_t* data) { + const uint32_t PixelsPerByte = 8; + size_t w = 0; + size_t z = 0; + if (columnMajorMode == false) { + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { + uint8_t c = videoCopy[z]; + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint8_t s = 0; s < lenX; s++) { + for (uint8_t b = 0; b < 8; b++) { + data[w] = colorR[(c >> b) & 0x1]; w++; + data[w] = colorG[(c >> b) & 0x1]; w++; + data[w] = colorB[(c >> b) & 0x1]; w++; + } + } + z++; + } + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); + //w += Master.pitch - (LCD_RESX * lenY * 3); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } else { + for (uint32_t x = 0; x < LCD_RESX; x++) { + uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); + for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { + uint8_t c = videoCopy[z]; + for (uint32_t i = 0; i < PixelsPerByte; i++) { + uint8_t lenY = ((Master.resY * (y + i + 1)) / LCD_RESY) - ((Master.resY * (y + i)) / LCD_RESY); + for (uint32_t s = 0; s < lenX; s++) { + data[w] = colorR[c & 0x1]; w++; + data[w] = colorG[c & 0x1]; w++; + data[w] = colorB[c & 0x1]; w++; + } + w += (Master.pitch - (3 * lenX)); + w += (Master.pitch * (lenY - 1)); + c >>= 1; + } + z++; + } + w -= Master.pitch * Master.resY; + w += (3 * lenX); + } + // memcpy's lines + w = 0; + for (uint32_t y = 0; y < LCD_RESY; y++) { + w += Master.pitch; + uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * (y)) / LCD_RESY); + for (uint8_t s = 0; s < lenY - 1; s++) { + memcpy(&data[w],&data[w - Master.pitch],Master.pitch); + w += Master.pitch; + } + } + } + } +*/ + + void blit16bpp(uint8_t* data) { + uint8_t* PreCalc16; + uint8_t colorMode = (lcd_VideoMode & 0b1110) >> 1; + switch (colorMode) { + case 0b100: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR1555 : PreCalc_RGB1555; + break; + case 0b110: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR565 : PreCalc_RGB565; + break; + case 0b111: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR444 : PreCalc_RGB444; + break; + default: + PreCalc16 = (lcd_VideoMode & 0x100) ? PreCalc_BGR555 : PreCalc_RGB555; + }; + size_t w = 0; + size_t z = 0; + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX; x++) { + uint32_t c = (uint32_t)((uint16_t*)videoCopy)[z]; + c *= 3; data[w] = PreCalc16[c]; w++; data[w] = PreCalc16[c + 1]; w++; data[w] = PreCalc16[c + 2]; w++; + z += columnMajorMode ? LCD_RESY : 1; } - z += columnMajorMode ? LCD_RESY : 1; - } - z -= columnMajorMode ? ((LCD_RESX * LCD_RESY) - 1) : 0; - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); - //w += Master.pitch - (LCD_RESX * lenY * 3); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + z -= columnMajorMode ? ((LCD_RESX * LCD_RESY) - 1) : 0; + //w += pitch - (LCD_RESX * 3); } } -} -void blit8bpp(uint8_t* data) { - size_t w = 0; - size_t z = 0; - for (uint32_t y = 0; y < (uint32_t)LCD_RESY; y++) { - for (uint32_t x = 0; x < (uint32_t)LCD_RESX; x++) { - uint8_t c = videoCopy[z]; - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint8_t s = 0; s < lenX; s++) { + void blit8bpp(uint8_t* data) { + size_t w = 0; + size_t z = 0; + for (uint32_t y = 0; y < (uint32_t)LCD_RESY; y++) { + for (uint32_t x = 0; x < (uint32_t)LCD_RESX; x++) { + uint8_t c = videoCopy[z]; data[w] = colorR[c]; w++; data[w] = colorG[c]; w++; data[w] = colorB[c]; w++; + z += columnMajorMode ? LCD_RESY : 1; } - z += columnMajorMode ? LCD_RESY : 1; - } - z -= columnMajorMode ? ((LCD_RESX * LCD_RESY) - 1) : 0; - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); - //w += Master.pitch - (LCD_RESX * lenY * 3); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + z -= columnMajorMode ? ((LCD_RESX * LCD_RESY) - 1) : 0; + //w += pitch - (LCD_RESX * lenY * 3); } } -} -void blit4bpp(uint8_t* data) { - const uint32_t PixelsPerByte = 2; - size_t w = 0; - size_t z = 0; - if (columnMajorMode == false) { - for (uint32_t y = 0; y < LCD_RESY; y++) { - for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { - uint8_t c = videoCopy[z]; - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint8_t s = 0; s < lenX; s++) { + void blit4bpp(uint8_t* data) { + const uint32_t PixelsPerByte = 2; + size_t w = 0; + size_t z = 0; + if (columnMajorMode == false) { + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { + uint8_t c = videoCopy[z]; data[w] = colorR[c & 0xF]; w++; data[w] = colorG[c & 0xF]; w++; data[w] = colorB[c & 0xF]; w++; data[w] = colorR[(c >> 4) & 0xF]; w++; data[w] = colorG[(c >> 4) & 0xF]; w++; data[w] = colorB[(c >> 4) & 0xF]; w++; + z++; } - z++; - } - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); - //w += Master.pitch - (LCD_RESX * lenY * 3); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + //w += pitch - (LCD_RESX * lenY * 3); } - } - } else { - for (uint32_t x = 0; x < LCD_RESX; x++) { - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { - uint8_t c = videoCopy[z]; - for (uint32_t i = 0; i < PixelsPerByte; i++) { - uint8_t lenY = ((Master.resY * (y + i + 1)) / LCD_RESY) - ((Master.resY * (y + i)) / LCD_RESY); - for (uint32_t s = 0; s < lenX; s++) { + } else { + for (uint32_t x = 0; x < LCD_RESX; x++) { + for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { + uint8_t c = videoCopy[z]; + for (uint32_t i = 0; i < PixelsPerByte; i++) { data[w] = colorR[c & 0xF]; w++; data[w] = colorG[c & 0xF]; w++; data[w] = colorB[c & 0xF]; w++; + w += (pitch - 3); + c >>= 4; } - w += (Master.pitch - (3 * lenX)); - w += (Master.pitch * (lenY - 1)); - c >>= 4; + z++; } - z++; - } - w -= Master.pitch * Master.resY; - w += (3 * lenX); - } - // memcpy's lines - w = 0; - for (uint32_t y = 0; y < LCD_RESY; y++) { - w += Master.pitch; - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * (y)) / LCD_RESY); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + w -= pitch * LCD_RESY; + w += 3; } } } -} -void blit2bpp(uint8_t* data) { - const uint32_t PixelsPerByte = 4; - size_t w = 0; - size_t z = 0; - if (columnMajorMode == false) { - for (uint32_t y = 0; y < LCD_RESY; y++) { - for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { - uint8_t c = videoCopy[z]; - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint8_t s = 0; s < lenX; s++) { + void blit2bpp(uint8_t* data) { + const uint32_t PixelsPerByte = 4; + size_t w = 0; + size_t z = 0; + if (columnMajorMode == false) { + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { + uint8_t c = videoCopy[z]; data[w] = colorR[c & 0x3]; w++; data[w] = colorG[c & 0x3]; w++; data[w] = colorB[c & 0x3]; w++; @@ -526,113 +765,163 @@ void blit2bpp(uint8_t* data) { data[w] = colorR[(c >> 6) & 0x3]; w++; data[w] = colorG[(c >> 6) & 0x3]; w++; data[w] = colorB[(c >> 6) & 0x3]; w++; + z++; } - z++; + //w += pitch - (LCD_RESX * 3); } - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); - //w += Master.pitch - (LCD_RESX * lenY * 3); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; - } - } - } else { - for (uint32_t x = 0; x < LCD_RESX; x++) { - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { - uint8_t c = videoCopy[z]; - for (uint32_t i = 0; i < PixelsPerByte; i++) { - uint8_t lenY = ((Master.resY * (y + i + 1)) / LCD_RESY) - ((Master.resY * (y + i)) / LCD_RESY); - for (uint32_t s = 0; s < lenX; s++) { - data[w] = colorR[c & 0x3]; w++; - data[w] = colorG[c & 0x3]; w++; - data[w] = colorB[c & 0x3]; w++; + } else { + for (uint32_t x = 0; x < LCD_RESX; x++) { + for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { + uint8_t c = videoCopy[z]; + for (uint32_t i = 0; i < PixelsPerByte; i++) { + data[w] = colorR[c & 0x3]; w++; + data[w] = colorG[c & 0x3]; w++; + data[w] = colorB[c & 0x3]; w++; + w += (pitch - 3); + c >>= 2; } - w += (Master.pitch - (3 * lenX)); - w += (Master.pitch * (lenY - 1)); - c >>= 2; + z++; } - z++; - } - w -= Master.pitch * Master.resY; - w += (3 * lenX); - } - // memcpy's lines - w = 0; - for (uint32_t y = 0; y < LCD_RESY; y++) { - w += Master.pitch; - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * (y)) / LCD_RESY); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + w -= pitch * LCD_RESY; + w += 3; } } } -} -void blit1bpp(uint8_t* data) { - const uint32_t PixelsPerByte = 8; - size_t w = 0; - size_t z = 0; - if (columnMajorMode == false) { - for (uint32_t y = 0; y < LCD_RESY; y++) { - for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { - uint8_t c = videoCopy[z]; - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint8_t s = 0; s < lenX; s++) { + void blit1bpp(uint8_t* data) { + const uint32_t PixelsPerByte = 8; + size_t w = 0; + size_t z = 0; + if (columnMajorMode == false) { + for (uint32_t y = 0; y < LCD_RESY; y++) { + for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { + uint8_t c = videoCopy[z]; for (uint8_t b = 0; b < 8; b++) { data[w] = colorR[(c >> b) & 0x1]; w++; data[w] = colorG[(c >> b) & 0x1]; w++; data[w] = colorB[(c >> b) & 0x1]; w++; } + z++; } - z++; + //w += pitch - (LCD_RESX * 3); } - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * y) / LCD_RESY); - //w += Master.pitch - (LCD_RESX * lenY * 3); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + } else { + for (uint32_t x = 0; x < LCD_RESX; x++) { + for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { + uint8_t c = videoCopy[z]; + for (uint32_t i = 0; i < PixelsPerByte; i++) { + data[w] = colorR[c & 0x1]; w++; + data[w] = colorG[c & 0x1]; w++; + data[w] = colorB[c & 0x1]; w++; + w += (pitch - 3); + c >>= 1; + } + z++; + } + w -= pitch * LCD_RESY; + w += 3; } } - } else { - for (uint32_t x = 0; x < LCD_RESX; x++) { - uint8_t lenX = ((Master.resX * (x + 1)) / LCD_RESX) - ((Master.resX * x) / LCD_RESX); - for (uint32_t y = 0; y < LCD_RESY; y += PixelsPerByte) { - uint8_t c = videoCopy[z]; - for (uint32_t i = 0; i < PixelsPerByte; i++) { - uint8_t lenY = ((Master.resY * (y + i + 1)) / LCD_RESY) - ((Master.resY * (y + i)) / LCD_RESY); - for (uint32_t s = 0; s < lenX; s++) { - data[w] = colorR[c & 0x1]; w++; - data[w] = colorG[c & 0x1]; w++; - data[w] = colorB[c & 0x1]; w++; - } - w += (Master.pitch - (3 * lenX)); - w += (Master.pitch * (lenY - 1)); - c >>= 1; + } + +// Will be optimized later on +void renderCursor(uint8_t* data) { + if (data == NULL) { return; } + // srand(1234); + // for (size_t i = 0; i < 1024; i++) { + // lcd_CrsrImage[i] = rand() % 256; + // } + const bool cursorEnabled = (lcd_CrsrCtrl & 0x1) ? true : false; + // printf("\nCursor: %s", cursorEnabled ? "true" : "false"); + // printf("\n\tPos: %hu,%hhu Clip: %hhu,%hhu %u", lcd_CrsrX, lcd_CrsrY, lcd_CrsrClipX, lcd_CrsrClipY, lcd_CrsrClip); + if (cursorEnabled == false) { return; } + const bool fullCursor = (lcd_CrsrConfig & 0x1) ? true : false; + + const uint8_t pixelsPerByte = 4; + const uint8_t bitsPerPixel = 2; + + const uint8_t cursorDim = fullCursor ? 64 : 32; + + bool use_columnMajorCursor = columnMajorMode && false; + const uint16_t cursor_PosX = use_columnMajorCursor ? lcd_CrsrY : lcd_CrsrX ; + const uint8_t cursor_PosY = use_columnMajorCursor ? lcd_CrsrX : lcd_CrsrY ; + const uint8_t cursor_ClipX = use_columnMajorCursor ? lcd_CrsrClipY : lcd_CrsrClipX; + const uint8_t cursor_ClipY = use_columnMajorCursor ? lcd_CrsrClipX : lcd_CrsrClipY; + + if (cursor_ClipX >= cursorDim || cursor_ClipY >= cursorDim) { + // printf("\nError: Everything is clipped"); + return; // Everything is clipped + } + if (cursor_PosX >= LCD_RESV || cursor_PosY >= LCD_RESY) { + // printf("\nError: Out of bounds"); + return; // Out of bounds + } + const uint16_t limitX = (cursor_PosX + cursorDim > LCD_RESV) ? ( (uint16_t)cursorDim - (( cursor_PosX + (uint16_t)cursorDim) - LCD_RESV) ) : cursorDim; + const uint16_t limitY = (cursor_PosY + cursorDim > LCD_RESY) ? ( (uint16_t)cursorDim - (((uint16_t)cursor_PosY + (uint16_t)cursorDim) - LCD_RESY) ) : cursorDim; + if (fullCursor) { + for (uint16_t y = cursor_ClipY; y < limitY; y++) { + for (uint16_t x = cursor_ClipX; x < limitX; x++) { + const size_t data_Index = 3 * ( ((size_t)((uint16_t)cursor_PosY + (uint16_t)y) * LCD_RESX) + (size_t)((uint16_t)cursor_PosX + (uint16_t)x) ); + const size_t cursor_Index = ((size_t)y * (size_t)cursorDim) + (size_t)x; + const uint8_t pixel = (lcd_CrsrImage[cursor_Index / pixelsPerByte] >> ((3 - (cursor_Index % pixelsPerByte)) * bitsPerPixel)) & 0b11; + switch (pixel) { + case 0b00: + data[data_Index + 0] = lcd_CrsrPalette0 & 0xFF; + data[data_Index + 1] = (lcd_CrsrPalette0 >> 8) & 0xFF; + data[data_Index + 2] = (lcd_CrsrPalette0 >> 16) & 0xFF; + break; + case 0b01: + data[data_Index + 0] = lcd_CrsrPalette1 & 0xFF; + data[data_Index + 1] = (lcd_CrsrPalette1 >> 8) & 0xFF; + data[data_Index + 2] = (lcd_CrsrPalette1 >> 16) & 0xFF; + break; + case 0b10: + /* Transparent */ + break; + case 0b11: + /* Invert Colors */ + data[data_Index + 0] = ~data[data_Index + 0]; + data[data_Index + 1] = ~data[data_Index + 1]; + data[data_Index + 2] = ~data[data_Index + 2]; + break; } - z++; } - w -= Master.pitch * Master.resY; - w += (3 * lenX); } - // memcpy's lines - w = 0; - for (uint32_t y = 0; y < LCD_RESY; y++) { - w += Master.pitch; - uint8_t lenY = ((Master.resY * (y + 1)) / LCD_RESY) - ((Master.resY * (y)) / LCD_RESY); - for (uint8_t s = 0; s < lenY - 1; s++) { - memcpy(&data[w],&data[w - Master.pitch],Master.pitch); - w += Master.pitch; + } else { + const size_t cursor_Offset = (size_t)((lcd_CrsrCtrl >> 4) & 0b11) * 0x100; + for (uint16_t y = lcd_CrsrClipY; y < limitY; y++) { + for (uint16_t x = lcd_CrsrClipX; x < limitX; x++) { + const size_t data_Index = 3 * ( ((size_t)((uint16_t)lcd_CrsrY + (uint16_t)y) * LCD_RESX) + (size_t)((uint16_t)lcd_CrsrX + (uint16_t)x) ); + const size_t cursor_Index = ((size_t)y * (size_t)cursorDim) + (size_t)x + cursor_Offset; + const uint8_t pixel = (lcd_CrsrImage[cursor_Index / pixelsPerByte] >> ((cursor_Index % pixelsPerByte) * bitsPerPixel)) & 0b11; + switch (pixel) { + case 0b00: + data[data_Index + 0] = lcd_CrsrPalette0 & 0xFF; + data[data_Index + 1] = (lcd_CrsrPalette0 >> 8) & 0xFF; + data[data_Index + 2] = (lcd_CrsrPalette0 >> 16) & 0xFF; + break; + case 0b01: + data[data_Index + 0] = lcd_CrsrPalette1 & 0xFF; + data[data_Index + 1] = (lcd_CrsrPalette1 >> 8) & 0xFF; + data[data_Index + 2] = (lcd_CrsrPalette1 >> 16) & 0xFF; + break; + case 0b10: + /* Transparent */ + break; + case 0b11: + /* Invert Colors */ + data[data_Index + 0] = ~data[data_Index + 0]; + data[data_Index + 1] = ~data[data_Index + 1]; + data[data_Index + 2] = ~data[data_Index + 2]; + break; + } } } } } void copyFrame(uint8_t* data) { - if (data == NULL) { - printf("ERROR | Buffer Pointer is Void \n"); fflush(stdout); - } + memcpy(color16,lcd_Palette,256 * sizeof(uint16_t)); memcpy(paletteRAM,lcd_Palette,256 * sizeof(uint16_t)); size_t copyAmount = 0; @@ -664,6 +953,7 @@ void copyFrame(uint8_t* data) { }; memcpy(videoCopy,((uint8_t*)&simulated_ram[0xD00000 | (lcd_UpBase & 0x7FFF8)]),copyAmount); + if (lcd_VideoMode & 0x100) { //Converts 1555 to 888 Color for (uint32_t i = 0; i < 256; i++) { @@ -731,15 +1021,7 @@ void copyFrame(uint8_t* data) { default: blit16bpp(data); }; - if ((lcd_VideoMode & 0xF) == 0x5) { - blit4bpp(data); - } - if ((lcd_VideoMode & 0xF) == 0x7) { - blit8bpp(data); - } - if ((lcd_VideoMode & 0xF) == 0xD) { - blit16bpp(data); - } + renderCursor(data); } /* @@ -748,28 +1030,83 @@ void copyFrame(uint8_t* data) { ** =========== */ +#ifdef Enable_OpenGL + void create_OpenGL_Texture(const uint8_t* buf, int32_t resX, int32_t resY) { + glGenTextures(1, &OpenGL_texture); + glBindTexture(GL_TEXTURE_2D, OpenGL_texture); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, resX, resY, 0, GL_RGB, GL_UNSIGNED_BYTE, buf); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, 0); + } + + void update_OpenGL_Texture(const uint8_t* buf, int32_t resX, int32_t resY) { + glBindTexture(GL_TEXTURE_2D, OpenGL_texture); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, resX, resY, GL_RGB, GL_UNSIGNED_BYTE, buf); + glBindTexture(GL_TEXTURE_2D, 0); + } +#endif + int terminateLCDcontroller() { - SDL_DestroyRenderer(renderer); + #ifdef Enable_OpenGL + glDeleteTextures(1, &OpenGL_texture); + SDL_GL_DeleteContext(SDL_OpenGL_context); + #else + SDL_DestroyRenderer(renderer); + #endif SDL_DestroyWindow(window); SDL_Quit(); return EXIT_SUCCESS; } +#ifdef Enable_OpenGL + bool initOpenGL() { + SDL_OpenGL_context = SDL_GL_CreateContext(window); + // glewExperimental = GL_TRUE; + GLenum err = glewInit(); + if (err != GLEW_OK) { + printf("\nError: Failed to initialize GLEW: %s", glewGetErrorString(err)); + + } + SDL_GL_SetSwapInterval(1); + create_OpenGL_Texture(Master.vram, Master.resX, Master.resY); + } +#endif void initLCDcontroller(const char* windowTitle) { - Master.resX = LCD_RESX * scale; - Master.resY = LCD_RESY * scale; + Master.resX = LCD_RESX; + Master.resY = LCD_RESY; Master.vram = NULL; Master.pitch = Master.resX * 3; Master.vram = calloc((size_t)Master.resY * Master.pitch, sizeof(uint8_t)); if (Master.vram == NULL) { printf("\nMaster.vram is NULL"); fflush(stdout); return; } - SDL_Init(SDL_INIT_VIDEO); - window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, LCD_RESX * scale, LCD_RESY * scale,SDL_WINDOW_RESIZABLE); - SDL_SetWindowMinimumSize(window, RESX_MINIMUM, RESY_MINIMUM); + SDL_Init(SDL_INIT_VIDEO); + + #ifdef Enable_OpenGL + window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, LCD_RESX * init_scale, LCD_RESY * init_scale, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + #else + window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, LCD_RESX * init_scale, LCD_RESY * init_scale, SDL_WINDOW_RESIZABLE); + #endif + + SDL_SetWindowMinimumSize(window, RESX_MINIMUM, RESY_MINIMUM); SDL_SetWindowMaximumSize(window, RESX_MAXIMUM, RESY_MAXIMUM); - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); - SDL_RenderClear(renderer); - texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGB24,SDL_TEXTUREACCESS_STREAMING, LCD_RESX * scale, LCD_RESY * scale); + #ifdef Enable_OpenGL + if (initOpenGL() == false) { + terminateLCDcontroller(); + return; + } + #else + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); + SDL_RenderClear(renderer); + texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGB24,SDL_TEXTUREACCESS_STREAMING, LCD_RESX * init_scale, LCD_RESY * init_scale); + #endif + Calculate16BitColor(); } @@ -791,42 +1128,52 @@ bool resizeWindow(int32_t resX, int32_t resY, uint32_t* resizeX, uint32_t* resiz // resY = (int32_t)(MaximumAspectRatio * ((fp64)resX / (fp64)LCD_RESX) * (fp64)LCD_RESY); // } - fp64 scaleVal = MIN((fp64)resX / (fp64)LCD_RESX,(fp64)resY / (fp64)LCD_RESY); - resX = (int32_t)(scaleVal * (fp64)LCD_RESX); - resY = (int32_t)(scaleVal * (fp64)LCD_RESY); - - // Sets resX to a multiple of 4 so I don't have to deal with padded and unpadded image buffers - if (resX & 0x3) { resX = resX & ~0x3; } - - // scale = MIN(resX / LCD_RESX, resY / LCD_RESY); - // resX = LCD_RESX * scale; - // resY = LCD_RESY * scale; - - Master.resX = resX; - Master.resY = resY; - Master.pitch = Master.resX * 3; - Master.vram = (uint8_t*)realloc((void*)(Master.vram),Master.pitch * Master.resY); - if (Master.vram == NULL) { - if (texture == NULL) { - printf("\nError: realloc Master.vram failed while resizing window"); - FREE(Master.vram); - terminateLCDcontroller(); - return true; + // fp64 scaleVal = MIN((fp64)resX / (fp64)LCD_RESX,(fp64)resY / (fp64)LCD_RESY); + // resX = (int32_t)(scaleVal * (fp64)LCD_RESX); + // resY = (int32_t)(scaleVal * (fp64)LCD_RESY); + + // // Sets resX to a multiple of 4 so I don't have to deal with padded and unpadded image buffers + // if (resX & 0x3) { resX = resX & ~0x3; } + + // init_scale = MIN(resX / LCD_RESX, resY / LCD_RESY); + // resX = LCD_RESX * init_scale; + // resY = LCD_RESY * init_scale; + + // Master.resX = resX; + // Master.resY = resY; + // Master.pitch = Master.resX * 3; + // Master.vram = (uint8_t*)realloc((void*)(Master.vram),Master.pitch * Master.resY); + + #ifndef Enable_OpenGL + if (Master.vram == NULL) { + if (texture == NULL) { + printf("\nError: realloc Master.vram failed while resizing window"); + FREE(Master.vram); + terminateLCDcontroller(); + return true; + } } - } + #endif SDL_SetWindowSize(window,resX,resY); - SDL_RenderSetLogicalSize(renderer, resX, resY); + #ifndef Enable_OpenGL + SDL_RenderSetLogicalSize(renderer, resX, resY); + #endif if (resizeX != NULL) { *resizeX = resX; } if (resizeY != NULL) { *resizeY = resY; } - if (texture != NULL) { - SDL_DestroyTexture(texture); - } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, (int)Master.resX, (int)Master.resY); - if (texture == NULL) { - printf("\nError: SDL_CreateTexture failed while resizing window"); - terminateLCDcontroller(); - return true; - } + #ifdef Enable_OpenGL + glDeleteTextures(1, &OpenGL_texture); + create_OpenGL_Texture(Master.vram, Master.resX, Master.resY); + #else + if (texture != NULL) { + SDL_DestroyTexture(texture); + } + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, (int)Master.resX, (int)Master.resY); + if (texture == NULL) { + printf("\nError: SDL_CreateTexture failed while resizing window"); + terminateLCDcontroller(); + return true; + } + #endif memset(Master.vram,0,Master.pitch * Master.resY); reVal = true; } @@ -844,17 +1191,63 @@ bool windowResizingCode(uint32_t* resX, uint32_t* resY) { void newFrame() { + // nano64_t startTime = getNanoTime(); if (SDL_PollEvent(&event) && event.type == SDL_QUIT) { terminateLCDcontroller(); exit(0); } windowResizingCode(NULL,NULL); copyFrame(Master.vram); - SDL_UpdateTexture(texture, NULL, Master.vram, Master.pitch); - { - SDL_Rect srcRect = {0,0,(int)Master.resX,(int)Master.resY}; - SDL_Rect dstRect = {0,0,(int)Master.resX,(int)Master.resY}; - SDL_RenderCopy(renderer, texture, &srcRect, &dstRect); - } - SDL_RenderPresent(renderer); + #ifdef Enable_OpenGL + update_OpenGL_Texture(Master.vram, Master.resX, Master.resY); + glClear(GL_COLOR_BUFFER_BIT); + + // Bind the texture and render it + glBindTexture(GL_TEXTURE_2D, OpenGL_texture); + + // Render a quad covering the entire screen + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, 1.0f); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + + // Swap the buffers + SDL_GL_SwapWindow(window); + #else + SDL_UpdateTexture(texture, NULL, Master.vram, Master.pitch); + { + // SDL_Rect srcRect = {0,0,(int)Master.resX,(int)Master.resY}; + int window_ResX, window_ResY; + SDL_GetWindowSize(window, &window_ResX, &window_ResY); + SDL_Rect dstRect = {0,0,window_ResX,window_ResY}; + + const fp64 LCD_AspectRatio = (fp64)LCD_RESX / (fp64)LCD_RESY; + const fp64 LCD_AspectRatio_Inverse = (fp64)LCD_RESY / (fp64)LCD_RESX; + const fp64 window_AspectRatio = (fp64)window_ResX / (fp64)window_ResY; + + if (window_AspectRatio > LCD_AspectRatio) { + int image_ResX = (int)((fp64)window_ResY * LCD_AspectRatio); + dstRect = (SDL_Rect){ + (window_ResX - image_ResX) / 2, 0, + image_ResX, window_ResY + }; + } else if (window_AspectRatio < LCD_AspectRatio) { + int image_ResY = (int)((fp64)window_ResX * LCD_AspectRatio_Inverse); + dstRect = (SDL_Rect){ + 0, (window_ResY - image_ResY) / 2, + window_ResX, image_ResY + }; + } + + SDL_RenderCopy(renderer, texture, NULL, &dstRect); + } + SDL_RenderPresent(renderer); + #endif + + // nano64_t endTime = getNanoTime(); + // printf("\nTime: %.3lfms | %.3lffps %lld", NANO_TO_SECONDS(endTime - startTime) * 1.0e3, NANO_TO_FRAMERATE(endTime - startTime), getNanoTime()); } \ No newline at end of file diff --git a/src-lcd/x86_ti84ce.h b/src-lcd/x86_ti84ce.h index 1caf4a9..c0d2a0c 100644 --- a/src-lcd/x86_ti84ce.h +++ b/src-lcd/x86_ti84ce.h @@ -21,6 +21,7 @@ extern uint8_t simulated_ram[16777216]; #define RAM_ADDRESS(x) ((void*)&simulated_ram[x]) + #define RAM_OFFSET(ptr) ((uint24_t)((uint8_t*)(ptr) - (uint8_t*)simulated_ram)) #define lcd_Ram ((void*)&simulated_ram[0xD40000]) #define lcd_Ram8 ((uint8_t*)&simulated_ram[0xD40000]) @@ -62,9 +63,9 @@ #define lcd_CrsrX (*(volatile uint16_t*)&simulated_ram[0xE30C10]) #define lcd_CrsrY (*(volatile uint8_t*)&simulated_ram[0xE30C12]) #define lcd_CrsrYFull (*(volatile uint16_t*)&simulated_ram[0xE30C12]) - #define lcd_CrsrClip (*(volatile uint16_t*)&simulated_ram[0xE30C04]) - #define lcd_CrsrClipX (*(volatile uint8_t*)&simulated_ram[0xE30C04]) - #define lcd_CrsrClipY (*(volatile uint8_t*)&simulated_ram[0xE30C05]) + #define lcd_CrsrClip (*(volatile uint16_t*)&simulated_ram[0xE30C14]) + #define lcd_CrsrClipX (*(volatile uint8_t*)&simulated_ram[0xE30C14]) + #define lcd_CrsrClipY (*(volatile uint8_t*)&simulated_ram[0xE30C15]) #define lcd_CrsrEnableInt (*(volatile uint8_t*)&simulated_ram[0xE30C20]) #define lcd_CrsrIntAcknowledge (*(volatile uint8_t*)&simulated_ram[0xE30C24]) #define lcd_CrsrIntStatus (*(volatile uint8_t*)&simulated_ram[0xE30C28]) diff --git a/src/Common_Def.h b/src/Common_Def.h index 8864941..a81d736 100644 --- a/src/Common_Def.h +++ b/src/Common_Def.h @@ -13,16 +13,16 @@ #include #define PROGRAM_V_MAJOR 0 -#define PROGRAM_V_MINOR 81 -#define PROGRAM_V_PATCH 5 +#define PROGRAM_V_MINOR 82 +#define PROGRAM_V_PATCH 0 -//#define PLATFORM_TI84CE +// #define PLATFORM_TI84CE #define PLATFORM_X86 //#define DEBUG_FRAMERATE_COUNTER // Shows FPS and Frame-Time //#define DEBUG_FRAME_SHIFT // Use the numberpad to move the screen around -#define SWAP_X_AND_Y_CORD +// #define SWAP_X_AND_Y_CORD #ifdef PLATFORM_TI84CE /* Disabled Functions */ @@ -41,6 +41,7 @@ //#include "spi_commands.h" /* Additional Definitions */ #define RAM_ADDRESS(x) ((void*)(x)) + #define RAM_OFFSET(ptr) ((uint24_t)(ptr)) #define LCD_RESX (320) #define LCD_RESY (240) @@ -97,7 +98,6 @@ // #endif #endif - /* Functions */ #define STR_M(x) #x @@ -118,6 +118,8 @@ #define linearInterpolation(x,x0,x1,y0,y1) ( (y0) + ( (((y1) - (y0)) * ((x) - (x0))) / ((x1) - (x0)) ) ) #define linearInterpolationClamp(x,x0,x1,y0,y1) ( ((x) <= (x0)) ? (y0) : ( ((x) >= (x1)) ? (y1) : linearInterpolation((x),(x0),(x1),(y0),(y1)) ) ) +/* SPI Macros */ + #define SPI_COMMAND(x) \ *(volatile uint8_t*)SPI_FIFO_IN_OUT = ((x) >> 6) & 0b111;\ *(volatile uint8_t*)SPI_FIFO_IN_OUT = ((x) >> 3) & 0b111;\ @@ -128,4 +130,36 @@ *(volatile uint8_t*)SPI_FIFO_IN_OUT = ((x) >> 3) & 0b111;\ *(volatile uint8_t*)SPI_FIFO_IN_OUT = (x) & 0b111; +/* Cursor Macros */ + + #define Enable_lcd_Crsr() lcd_CrsrCtrl |= 0x1; + #define Disable_lcd_Crsr() lcd_CrsrCtrl &= ~(uint8_t)0x1; + #define Toggle_lcd_Crsr() lcd_CrsrCtrl ^= 0x1; + + #ifdef SWAP_X_AND_Y_CORD + #define Initialize_lcd_Crsr()\ + Disable_lcd_Crsr();\ + lcd_CrsrClip = 0;\ + lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(320 - 1) << 16; + + #define Terminate_lcd_Crsr()\ + Disable_lcd_Crsr();\ + lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(240 - 1) << 16; + + #else + #define Initialize_lcd_Crsr()\ + Disable_lcd_Crsr();\ + lcd_CrsrClip = 0; + + #define Terminate_lcd_Crsr()\ + Disable_lcd_Crsr(); + + #endif + #define Use_lcd_CrsrImage64x64() lcd_CrsrConfig |= 0x1; + #define Use_lcd_CrsrImage32x32(i) lcd_CrsrCtrl |= ((i) & 0x3) << 4; lcd_CrsrConfig &= ~(uint8_t)0x1; + + #define Enable_lcd_CrsrFrameSync() lcd_CrsrConfig |= 0x2; + #define Disable_lcd_CrsrFrameSync() lcd_CrsrConfig &= ~(uint8_t)0x2; + #define Toggle_lcd_CrsrFrameSync() lcd_CrsrConfig ^= 0x2; + #endif /* COMMON_DEF_H */ \ No newline at end of file diff --git a/src/fmVideo.c b/src/fmVideo.c index 2ab2cbb..c13a962 100644 --- a/src/fmVideo.c +++ b/src/fmVideo.c @@ -14,7 +14,7 @@ int8_t playIntroVideo() { /* - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoMode = lcd_BGR4bit; uint8_t prgm; diff --git a/src/gameMenu.c b/src/gameMenu.c index cb0abc9..3e7a1c7 100644 --- a/src/gameMenu.c +++ b/src/gameMenu.c @@ -136,9 +136,9 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse fP -= 256; } uint8_t name[3] = {33,33,33}; - gColor = 0; + gColor = Color_Black; memset(&lcd_Ram8[LCD_RESX * LCD_RESY], gColor, LCD_RESX * LCD_RESY / 2); //Clears the screen - gColor = 7; + gColor = Color_White; { uint24_t x = 8; uint24_t y = 8; @@ -161,11 +161,11 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse } } - gColor = 7; + gColor = Color_White; pause6x8(148, 28, (scoreSort() % 10)); pause6x8(148, 40, (score % 10)); pause6x8(148, 52, (timer % 10)); - gColor = 0; + gColor = Color_Black; pause6x8(50, 64, 66); pause6x8(57, 64, 66); pause6x8(64, 64, 66); @@ -181,9 +181,9 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse name[option] = 33; name[option]++; } - gColor = 7; + gColor = Color_White; fillRect(50 + (option * 7),64,6,8); - gColor = 0; + gColor = Color_Black; pause6x8(50 + (option * 7), 64, name[option]); } if (kb_Data[7] & kb_Down) { @@ -192,9 +192,9 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse } else { name[option]--; } - gColor = 7; + gColor = Color_White; fillRect(50 + (option * 7),64,6,8); - gColor = 0; + gColor = Color_Black; pause6x8(50 + (option * 7), 64, name[option]); } if (kb_Data[7] & kb_Left) { @@ -252,7 +252,7 @@ void timeDisplay(uint32_t input) { //systemTime - gameStartTime - gamePauseTime void pauseScroll() { if ((kb_Data[7] & (kb_Up | kb_Down)) && (keyReady & VERT)) { keyReset(vERT); - gColor = 0; + gColor = Color_Black; pause6x8(8, 28 + (option * 12), 29); pause6x8(141, 28 + (option * 12), 28); if ((kb_Data[7] & kb_Up)) { @@ -268,7 +268,7 @@ void pauseScroll() { option++; } } - gColor = 7; + gColor = Color_White; pause6x8(8, 28 + (option * 12), 29); pause6x8(141, 28 + (option * 12), 28); } @@ -279,16 +279,16 @@ void winScreen() { gameFinishTime = systemTime - gameStartTime - gamePauseTime; } pauseTime = systemTime; - lcd_UpBase = 0xD40000 + (LCD_RESX * LCD_RESY * 1); + lcd_UpBase = RAM_OFFSET(lcd_Ram) + (LCD_RESX * LCD_RESY * 1); lcd_VideoBit = lcd_Video4bit; //4bit mode - gColor = 0; + gColor = Color_Black; memset(&lcd_Ram8[LCD_RESX * LCD_RESY], gColor, LCD_RESX * LCD_RESY / 2); //Clears the screen // if (scoreSort() != 99 || 1) { //Force Debug Run // scoreScreen(); // } //Do not use for now please - gColor = 7; + gColor = Color_White; { uint24_t x = 8; uint24_t y = 8; @@ -296,12 +296,12 @@ void winScreen() { uint24_t j = 0; if (cheater == 1) { j = 14; //Majic Number - for (uint8_t j = 0; j < cheatTextLength; j++) { - pause6x8(x, y, cheatText[j]); + for (uint8_t cheatTextIndex = 0; cheatTextIndex < ARRAY_LENGTH(cheatText); cheatTextIndex++) { + pause6x8(x, y, cheatText[cheatTextIndex]); x += 7; } } - for (; j < winTextLength; j++) { + for (; j < ARRAY_LENGTH(winText); j++) { if (winText[j] == 33) { x = 8; y += 12; @@ -349,29 +349,29 @@ void winScreen() { //key = 49; status = FORCEQUIT; } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoBit = lcd_Video8bit; //8bit mode break; } } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoBit = lcd_Video8bit; //8bit mode } void gameOver() { //160x120 screen due to poor coding pauseTime = systemTime; - lcd_UpBase = 0xD52C00; + lcd_UpBase = RAM_OFFSET(lcd_Ram) + (1 * LCD_RESX * LCD_RESY); lcd_VideoBit = lcd_Video4bit; //4bit mode - gColor = 0; + gColor = Color_Black; memset(&lcd_Ram8[LCD_RESX * LCD_RESY], gColor, LCD_RESX * LCD_RESY / 2); //Clears the screen - gColor = 7; + gColor = Color_White; { uint24_t x = 8; uint24_t y = 8; uint8_t i = 0; - for (uint24_t j = 0; j < gameOverTextLength; j++) { + for (uint24_t j = 0; j < ARRAY_LENGTH(gameOverText); j++) { if (gameOverText[j] == 33) { x = 8; y += 12; @@ -419,26 +419,26 @@ void gameOver() { //160x120 screen due to poor coding //key = 49; status = FORCEQUIT; } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoBit = lcd_Video8bit; //8bit mode break; } } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoBit = lcd_Video8bit; //8bit mode } void pause() { pauseTime = systemTime; - gColor = 0; + gColor = Color_Black; memset(&lcd_Ram8[LCD_RESX * LCD_RESY], gColor, LCD_RESX * LCD_RESY / 2); //Clears the screen - gColor = 7; + gColor = Color_White; { uint24_t x = 8; uint24_t y = 8; uint8_t i = 0; - for (uint24_t j = 0; j < pauseTextLength; j++) { + for (uint24_t j = 0; j < ARRAY_LENGTH(pauseText); j++) { if (pauseText[j] == 33) { x = 8; y += 12; @@ -464,7 +464,7 @@ void pause() { timeDisplay(systemTime - gameStartTime - gamePauseTime); - lcd_UpBase = 0xD52C00; + lcd_UpBase = RAM_OFFSET(lcd_Ram) + (1 * LCD_RESX * LCD_RESY); lcd_VideoBit = lcd_Video4bit; //4bit mode while (!(kb_Data[1] & (kb_Graph | kb_Del))) { @@ -486,11 +486,11 @@ void pause() { status = FORCEQUIT; //key = 49; } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoBit = lcd_Video8bit; //8bit mode break; } } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoBit = lcd_Video8bit; //8bit mode } \ No newline at end of file diff --git a/src/global.c b/src/global.c index dbe87dc..98d6eef 100644 --- a/src/global.c +++ b/src/global.c @@ -23,9 +23,9 @@ uint8_t swapRB = 0; uint24_t mines = 0; //U16 int24_t flags = 54; //S16 uint24_t cleared = 0; //U16 -uint8_t win = 1; +bool win_Available = true; uint24_t flagColor = 1; -uint8_t cheater = 0; +bool cheater = false; uint8_t autoLoss = 0; int24_t score = 0; @@ -55,7 +55,7 @@ uint8_t disY = 13; uint8_t padX = 3; uint8_t padY = 2; uint8_t font = 0; -uint8_t fontSize = 7; +uint8_t fontSize = FontPreset_3x5_6x8; /* Graphical Backend */ @@ -68,10 +68,10 @@ uint8_t autoSolver = 0; //off,manual,automatic //Video Settings uint24_t displayMode = 0; //Originally videoMode -uint8_t accessMode = 0; //Increases Readability, Disables Quake +uint8_t accessibility_Mode = false; //Increases Readability, Disables Quake uint8_t fadeEffect = 1; //off,static,dynamic //Refactor to bgEffects uint8_t fpsCounter = 1; //Debug thing -uint8_t cursorGraphic = 0; +uint8_t cursorGraphic = true; uint8_t movieIntro = 1; uint32_t FPS = (32768 / 960); //Set to 0 for unlimited @@ -83,38 +83,38 @@ uint8_t autoSaveMax = 0; /* Settings */ /* Text */ -uint8_t guideText[511] = {82,110,105,94,107,32,82,112,94,94,105,94,107,32,98,108,32,90,32,111,94,107,108,98,104,103,32,104,95,32,76,98,103,94,82,112,94,94,105,94,107,33,95,104,107,32,109,97,94,32,83,98,8,4,66,68,32,112,98,109,97,32,108,94,111,94,107,90,101,32,102,104,93,94,108,32,90,103,93,33,95,94,90,109,110,107,94,108,34,32,83,104,32,105,101,90,114,35,32,104,103,94,32,92,90,103,32,108,109,90,107,109,32,90,32,106,110,98,92,100,33,96,90,102,94,32,95,107,104,102,32,109,97,94,32,102,90,98,103,32,102,94,103,110,35,32,109,97,98,108,32,98,103,92,101,110,93,94,108,33,104,105,109,98,104,103,108,32,95,104,107,32,93,98,95,95,94,107,94,103,109,32,93,98,95,95,98,92,110,101,109,98,94,108,32,90,103,93,33,105,107,94,108,94,109,108,34,32,78,103,92,94,32,98,103,32,90,32,96,90,102,94,35,32,114,104,110,107,32,104,91,99,94,92,109,98,111,94,33,98,108,32,109,104,32,108,90,95,94,101,114,32,69,101,90,96,32,26,32,90,101,101,32,109,97,94,32,76,98,103,94,108,32,25,32,91,114,33,110,108,98,103,96,32,109,97,94,32,103,110,102,91,94,107,94,93,32,109,98,101,94,108,32,90,108,32,92,101,110,94,108,32,109,104,33,95,98,96,110,107,94,32,104,110,109,32,112,97,94,107,94,32,94,90,92,97,32,76,98,103,94,32,25,32,98,108,32,101,104,92,90,109,94,93,34,33,33,84,108,94,32,64,101,105,97,90,32,109,104,32,108,94,90,107,92,97,32,90,32,109,98,101,94,35,32,2,103,93,32,109,104,32,69,101,90,96,32,26,33,90,32,109,98,101,94,35,32,88,47,32,109,104,32,102,90,107,100,32,90,32,27,32,104,103,109,104,32,90,32,109,98,101,94,35,32,87,83,0,103,33,109,104,32,92,97,104,107,93,35,32,102,104,93,94,32,109,104,32,105,90,110,108,94,35,32,90,103,93,32,93,94,101,32,109,104,32,106,110,98,109,34,33,33,72,32,97,104,105,94,32,114,104,110,32,94,103,99,104,114,32,102,114,32,96,90,102,94,32,39,38,33}; -#define guideTextLength 511 //helpText had a naming conflict >:( - -uint8_t pauseText[84] = {79,90,110,108,94,93,39,33,81,94,108,110,102,94,32,70,90,102,94,33,81,94,108,109,90,107,109,33,76,90,98,103,32,76,94,103,110,33,68,113,98,109,32,64,105,105,101,98,92,90,109,98,104,103,33,81,94,102,90,98,103,98,103,96,32,83,98,101,94,108,39,33,83,98,102,94,32,83,90,100,94,103,39,33}; -#define pauseTextLength 84 -uint8_t gameOverText[87] = {70,90,102,94,32,78,111,94,107,48,33,81,94,108,109,90,107,109,33,76,90,98,103,32,76,94,103,110,33,81,94,108,110,102,94,32,70,90,102,94,33,68,113,98,109,32,64,105,105,101,98,92,90,109,98,104,103,33,81,94,102,90,98,103,98,103,96,32,83,98,101,94,108,39,33,83,98,102,94,32,83,90,100,94,103,39,33}; -#define gameOverTextLength 87 -uint8_t winText[81] = {70,90,102,94,32,66,104,102,105,101,94,109,94,48,33,81,94,108,110,102,94,32,70,90,102,94,33,81,94,108,109,90,107,109,33,76,90,98,103,32,76,94,103,110,33,68,113,98,109,32,64,105,105,101,98,92,90,109,98,104,103,33,82,92,104,107,94,39,33,83,98,102,94,32,83,90,100,94,103,39,33}; -#define winTextLength 81 -uint8_t cheatText[16] = {88,104,110,32,66,97,94,90,109,94,93,48,32,29,39,37}; -#define cheatTextLength 16 + + //helpText had a naming conflict >:( + const uint8_t guideText[511] = { + 82,110,105,94,107,32,82,112,94,94,105,94,107,32,98,108,32,90,32,111,94,107,108,98,104,103,32,104,95,32,76,98,103,94,82,112,94,94,105,94,107,33,95,104,107,32,109,97,94,32,83,98,8,4,66,68,32,112,98,109,97,32,108,94,111,94,107,90,101,32,102,104,93,94,108,32,90,103,93,33,95,94,90,109,110,107,94,108,34,32,83,104,32,105,101,90,114,35,32,104,103,94,32,92,90,103,32,108,109,90,107,109,32,90,32,106,110,98,92,100,33,96,90,102,94,32,95,107,104,102,32,109,97,94,32,102,90,98,103,32,102,94,103,110,35,32,109,97,98,108,32,98,103,92,101,110,93,94,108,33,104,105,109,98,104,103,108,32,95,104,107,32,93,98,95,95,94,107,94,103,109,32,93,98,95,95,98,92,110,101,109,98,94,108,32,90,103,93,33,105,107,94,108,94,109,108,34,32,78,103,92,94,32,98,103,32,90,32,96,90,102,94,35,32,114,104,110,107,32,104,91,99,94,92,109,98,111,94,33,98,108,32,109,104,32,108,90,95,94,101,114,32,69,101,90,96,32,26,32,90,101,101,32,109,97,94,32,76,98,103,94,108,32,25,32,91,114,33,110,108,98,103,96,32,109,97,94,32,103,110,102,91,94,107,94,93,32,109,98,101,94,108,32,90,108,32,92,101,110,94,108,32,109,104,33,95,98,96,110,107,94,32,104,110,109,32,112,97,94,107,94,32,94,90,92,97,32,76,98,103,94,32,25,32,98,108,32,101,104,92,90,109,94,93,34,33,33,84,108,94,32,64,101,105,97,90,32,109,104,32,108,94,90,107,92,97,32,90,32,109,98,101,94,35,32,2,103,93,32,109,104,32,69,101,90,96,32,26,33,90,32,109,98,101,94,35,32,88,47,32,109,104,32,102,90,107,100,32,90,32,27,32,104,103,109,104,32,90,32,109,98,101,94,35,32,87,83,0,103,33,109,104,32,92,97,104,107,93,35,32,102,104,93,94,32,109,104,32,105,90,110,108,94,35,32,90,103,93,32,93,94,101,32,109,104,32,106,110,98,109,34,33,33,72,32,97,104,105,94,32,114,104,110,32,94,103,99,104,114,32,102,114,32,96,90,102,94,32,39,38,33 + }; + const uint8_t pauseText[84] = { + 79,90,110,108,94,93,39,33,81,94,108,110,102,94,32,70,90,102,94,33,81,94,108,109,90,107,109,33,76,90,98,103,32,76,94,103,110,33,68,113,98,109,32,64,105,105,101,98,92,90,109,98,104,103,33,81,94,102,90,98,103,98,103,96,32,83,98,101,94,108,39,33,83,98,102,94,32,83,90,100,94,103,39,33 + }; + const uint8_t gameOverText[87] = { + 70,90,102,94,32,78,111,94,107,48,33,81,94,108,109,90,107,109,33,76,90,98,103,32,76,94,103,110,33,81,94,108,110,102,94,32,70,90,102,94,33,68,113,98,109,32,64,105,105,101,98,92,90,109,98,104,103,33,81,94,102,90,98,103,98,103,96,32,83,98,101,94,108,39,33,83,98,102,94,32,83,90,100,94,103,39,33 + }; + const uint8_t winText[81] = { + 70,90,102,94,32,66,104,102,105,101,94,109,94,48,33,81,94,108,110,102,94,32,70,90,102,94,33,81,94,108,109,90,107,109,33,76,90,98,103,32,76,94,103,110,33,68,113,98,109,32,64,105,105,101,98,92,90,109,98,104,103,33,82,92,104,107,94,39,33,83,98,102,94,32,83,90,100,94,103,39,33 + }; + const uint8_t cheatText[16] = { + 88,104,110,32,66,97,94,90,109,94,93,48,32,29,39,37 + }; + /* Text */ /* IO Handeling */ uint8_t status = 0; /* IO Handeling */ -/* Chording/Cursor */ - -uint24_t cursorAllow = 0; - -/* Chording/Cursor */ - /* Legacy */ const uint8_t hiddenText[43] = { //SuperSweeper V:X.XX.X ZERICO2005 YYYY/MM/DD 82,110,105,94,107,82,112,94,94,105,94,107,32,85,39, /* Text */ - (PROGRAM_V_MAJOR),34,((PROGRAM_V_MINOR) / 10),((PROGRAM_V_MINOR) % 10),34,PROGRAM_V_PATCH, /* Version */ + (PROGRAM_V_MAJOR),34,((PROGRAM_V_MINOR) / 10),((PROGRAM_V_MINOR) % 10),34,PROGRAM_V_PATCH, /* Version */ 32,89,68,81,72,66,78,2,0,0,5,32, /* Text */ 2,0,2,4,36, /* Year */ - 0,5,36,1,3, /* Month Day */ + 0,6,36,0,7, /* Month Day */ }; -const uint8_t hiddenTextLength = 43; const uint8_t blockLimits[6] = {8,4,8,8,6,6}; //Minus 1 // @@ -122,11 +122,41 @@ const uint8_t blockLimits[6] = {8,4,8,8,6,6}; //Minus 1 uint8_t category = 0; uint8_t names[288] = { - 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40 + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40, + 66,68,25,76,68,26,83,68,30,66,71,48,40,40,40,40,40,40 }; uint16_t leaderboard[96] = { - 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0, 1600,1100,700,400,0,0 + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0, + 1600,1100,700,400,0,0 }; //8bit Color Pallete @@ -134,36 +164,42 @@ uint16_t leaderboard[96] = { //5x5 Image and Color //Number Colors const uint8_t color[28] = { -/*0*/ 7, 5,11, 1,13, 9,12, 0 -/*1*/, 8,14,10, 6, 4, 2, 0, 8 -/*2*/, 7, 0, 0, 0, 0, 0, 0, 0 -/*3*/, 0, 0, 0,13 +/* 0 - 4 */ Color_White , Color_Blue , Color_Green, Color_Red , Color_Navy , +/* 5 - 9 */ Color_Maroon, Color_Teal , Color_Black, Color_Grey , Color_Purple, +/* 10 - 14 */ Color_Olive , Color_Fuchsia, Color_Aqua , Color_Yellow, Color_Black , +/* 15 - 19 */ Color_Grey , Color_White , Color_Black, Color_Black , Color_Black , +/* 20 - 24 */ Color_Black , Color_Black , Color_Black, Color_Black , Color_Black , +/* Mine */ Color_Black, +/* Flag */ Color_Black, +/* ? */ Color_Navy }; //Outdated Text -//const uint8_t text[1311] = {50,85,74,92,92,82,76,32,60,82,87,78,66,96,78,78,89,78,91,39,32,25,33,58,87,82,80,81,93,32,66,96,78,78,89,78,91,39,32,30,33,48,85,85,32,60,88,77,78,92,39,32,26,33,50,94,92,93,88,86,39,32,109,33,59,78,74,77,78,91,75,88,74,91,77,39,32,44,33,66,78,93,93,82,87,80,92,39,32,43,33,55,78,85,89,39,32,27,33,52,97,82,93,32,54,74,86,78,39,32,45,33,64,94,82,76,84,32,54,74,86,78,39,33,54,74,86,78,32,60,88,77,78,39,32,30,33,63,91,78,92,78,93,39,32,26,33,66,82,99,78,39,32,46,33,51,82,79,79,82,76,94,85,93,98,39,32,41,33,66,93,74,91,93,32,54,74,86,78,39,32,25,33,50,94,92,93,88,86,39,32,43,33,60,74,82,87,32,60,78,87,94,39,32,45,33,63,74,93,93,78,91,87,32,66,78,85,78,76,93,82,88,87,39,32,26,33,65,74,87,77,88,86,32,60,88,77,78,39,32,27,33,66,78,85,78,76,93,32,63,91,78,92,78,93,39,32,25,33,50,94,92,93,88,86,32,54,74,86,78,39,32,43,33,60,74,82,87,32,60,78,87,94,39,32,45,33,54,74,86,78,32,60,88,77,78,39,32,30,33,66,82,99,78,32,71,39,33,66,82,99,78,32,72,39,33,60,82,87,78,32,50,88,94,87,93,39,32,25,33,63,78,91,76,78,87,93,74,80,78,39,32,41,33,66,93,74,91,93,32,54,74,86,78,39,32,26,33,60,74,82,87,32,60,78,87,94,39,32,45,33,55,82,80,81,32,66,76,88,91,78,92,39,32,44,33,1,34,33,2,34,33,3,34,33,4,34,33,5,34,33,6,34,33,54,74,86,78,32,60,88,77,78,39,32,30,33,60,74,82,87,32,60,78,87,94,39,32,45,33,66,74,79,78,32,54,94,78,92,92,82,87,80,39,33,69,82,77,78,88,32,60,88,77,78,39,33,49,74,76,84,80,91,88,94,87,77,32,52,79,79,78,76,93,92,39,33,48,76,76,78,92,92,82,75,82,85,82,93,98,32,60,88,77,78,39,33,50,88,91,77,82,87,80,32,37,48,85,89,81,74,38,39,33,60,74,97,82,86,94,86,32,53,63,66,39,33,69,78,91,92,82,88,87,39,33,60,74,82,87,32,60,78,87,94,32,45,33,66,94,89,78,91,32,66,96,78,78,89,78,91,32,82,92,32,74,32,95,78,91,92,82,88,87,32,88,79,32,60,82,87,78,66,96,78,78,89,78,91,33,79,88,91,32,93,81,78,32,67,82,8,4,50,52,32,96,82,93,81,32,92,78,95,78,91,74,85,32,86,88,77,78,92,32,74,87,77,33,79,78,74,93,94,91,78,92,34,32,67,88,32,89,85,74,98,35,32,88,87,78,32,76,74,87,32,92,93,74,91,93,32,74,32,90,94,82,76,84,33,80,74,86,78,32,79,91,88,86,32,93,81,78,32,86,74,82,87,32,86,78,87,94,35,32,93,81,82,92,32,82,87,76,85,94,77,78,92,33,88,89,93,82,88,87,92,32,79,88,91,32,77,82,79,79,78,91,78,87,93,32,77,82,79,79,82,76,94,85,93,82,78,92,32,74,87,77,33,89,91,78,92,78,93,92,34,32,62,87,76,78,32,82,87,32,74,32,80,74,86,78,35,32,98,88,94,91,32,88,75,83,78,76,93,82,95,78,33,82,92,32,93,88,32,92,74,79,78,85,98,32,53,85,74,80,32,26,32,74,85,85,32,93,81,78,32,60,82,87,78,92,32,25,32,75,98,33,94,92,82,87,80,32,93,81,78,32,87,94,86,75,78,91,78,77,32,93,82,85,78,92,32,74,92,32,76,85,94,78,92,32,93,88,33,79,82,80,94,91,78,32,88,94,93,32,96,81,78,91,78,32,78,74,76,81,32,60,82,87,78,32,25,32,82,92,32,85,88,76,74,93,78,77,34,33,33,68,92,78,32,48,85,89,81,74,32,93,88,32,92,78,74,91,76,81,32,74,32,93,82,85,78,35,32,2,87,77,32,93,88,32,53,85,74,80,32,26,33,74,32,93,82,85,78,35,32,72,47,32,93,88,32,86,74,91,84,32,74,32,27,32,88,87,93,88,32,74,32,93,82,85,78,35,32,71,67,0,87,33,93,88,32,76,81,88,91,77,35,32,86,88,77,78,32,93,88,32,89,74,94,92,78,35,32,74,87,77,32,77,78,85,32,93,88,32,90,94,82,93,34,33,33,56,32,81,88,89,78,32,98,88,94,32,78,87,83,88,98,32,86,98,32,80,74,86,78,32,39,38,33,63,74,94,92,78,77,39,33,65,78,92,94,86,78,32,54,74,86,78,33,65,78,92,93,74,91,93,33,60,74,82,87,32,60,78,87,94,33,52,97,82,93,32,48,89,89,85,82,76,74,93,82,88,87,33,65,78,86,74,82,87,82,87,80,32,67,82,85,78,92,39,33,67,82,86,78,32,67,74,84,78,87,39,33,54,74,86,78,32,62,95,78,91,109,33,65,78,92,93,74,91,93,33,60,74,82,87,32,60,78,87,94,33,65,78,92,94,86,78,32,54,74,86,78,33,52,97,82,93,32,48,89,89,85,82,76,74,93,82,88,87,33,65,78,86,74,82,87,82,87,80,32,67,82,85,78,92,39,33,67,82,86,78,32,67,74,84,78,87,39,33,54,74,86,78,32,50,88,86,89,85,78,93,78,109,33,65,78,92,94,86,78,32,54,74,86,78,33,65,78,92,93,74,91,93,33,60,74,82,87,32,60,78,87,94,33,52,97,82,93,32,48,89,89,85,82,76,74,93,82,88,87,33,66,76,88,91,78,39,33,67,82,86,78,32,67,74,84,78,87,39,33}; +//const uint8_t text[1311] = { +// 50,85,74,92,92,82,76,32,60,82,87,78,66,96,78,78,89,78,91,39,32,25,33,58,87,82,80,81,93,32,66,96,78,78,89,78,91,39,32,30,33,48,85,85,32,60,88,77,78,92,39,32,26,33,50,94,92,93,88,86,39,32,109,33,59,78,74,77,78,91,75,88,74,91,77,39,32,44,33,66,78,93,93,82,87,80,92,39,32,43,33,55,78,85,89,39,32,27,33,52,97,82,93,32,54,74,86,78,39,32,45,33,64,94,82,76,84,32,54,74,86,78,39,33,54,74,86,78,32,60,88,77,78,39,32,30,33,63,91,78,92,78,93,39,32,26,33,66,82,99,78,39,32,46,33,51,82,79,79,82,76,94,85,93,98,39,32,41,33,66,93,74,91,93,32,54,74,86,78,39,32,25,33,50,94,92,93,88,86,39,32,43,33,60,74,82,87,32,60,78,87,94,39,32,45,33,63,74,93,93,78,91,87,32,66,78,85,78,76,93,82,88,87,39,32,26,33,65,74,87,77,88,86,32,60,88,77,78,39,32,27,33,66,78,85,78,76,93,32,63,91,78,92,78,93,39,32,25,33,50,94,92,93,88,86,32,54,74,86,78,39,32,43,33,60,74,82,87,32,60,78,87,94,39,32,45,33,54,74,86,78,32,60,88,77,78,39,32,30,33,66,82,99,78,32,71,39,33,66,82,99,78,32,72,39,33,60,82,87,78,32,50,88,94,87,93,39,32,25,33,63,78,91,76,78,87,93,74,80,78,39,32,41,33,66,93,74,91,93,32,54,74,86,78,39,32,26,33,60,74,82,87,32,60,78,87,94,39,32,45,33,55,82,80,81,32,66,76,88,91,78,92,39,32,44,33,1,34,33,2,34,33,3,34,33,4,34,33,5,34,33,6,34,33,54,74,86,78,32,60,88,77,78,39,32,30,33,60,74,82,87,32,60,78,87,94,39,32,45,33,66,74,79,78,32,54,94,78,92,92,82,87,80,39,33,69,82,77,78,88,32,60,88,77,78,39,33,49,74,76,84,80,91,88,94,87,77,32,52,79,79,78,76,93,92,39,33,48,76,76,78,92,92,82,75,82,85,82,93,98,32,60,88,77,78,39,33,50,88,91,77,82,87,80,32,37,48,85,89,81,74,38,39,33,60,74,97,82,86,94,86,32,53,63,66,39,33,69,78,91,92,82,88,87,39,33,60,74,82,87,32,60,78,87,94,32,45,33,66,94,89,78,91,32,66,96,78,78,89,78,91,32,82,92,32,74,32,95,78,91,92,82,88,87,32,88,79,32,60,82,87,78,66,96,78,78,89,78,91,33,79,88,91,32,93,81,78,32,67,82,8,4,50,52,32,96,82,93,81,32,92,78,95,78,91,74,85,32,86,88,77,78,92,32,74,87,77,33,79,78,74,93,94,91,78,92,34,32,67,88,32,89,85,74,98,35,32,88,87,78,32,76,74,87,32,92,93,74,91,93,32,74,32,90,94,82,76,84,33,80,74,86,78,32,79,91,88,86,32,93,81,78,32,86,74,82,87,32,86,78,87,94,35,32,93,81,82,92,32,82,87,76,85,94,77,78,92,33,88,89,93,82,88,87,92,32,79,88,91,32,77,82,79,79,78,91,78,87,93,32,77,82,79,79,82,76,94,85,93,82,78,92,32,74,87,77,33,89,91,78,92,78,93,92,34,32,62,87,76,78,32,82,87,32,74,32,80,74,86,78,35,32,98,88,94,91,32,88,75,83,78,76,93,82,95,78,33,82,92,32,93,88,32,92,74,79,78,85,98,32,53,85,74,80,32,26,32,74,85,85,32,93,81,78,32,60,82,87,78,92,32,25,32,75,98,33,94,92,82,87,80,32,93,81,78,32,87,94,86,75,78,91,78,77,32,93,82,85,78,92,32,74,92,32,76,85,94,78,92,32,93,88,33,79,82,80,94,91,78,32,88,94,93,32,96,81,78,91,78,32,78,74,76,81,32,60,82,87,78,32,25,32,82,92,32,85,88,76,74,93,78,77,34,33,33,68,92,78,32,48,85,89,81,74,32,93,88,32,92,78,74,91,76,81,32,74,32,93,82,85,78,35,32,2,87,77,32,93,88,32,53,85,74,80,32,26,33,74,32,93,82,85,78,35,32,72,47,32,93,88,32,86,74,91,84,32,74,32,27,32,88,87,93,88,32,74,32,93,82,85,78,35,32,71,67,0,87,33,93,88,32,76,81,88,91,77,35,32,86,88,77,78,32,93,88,32,89,74,94,92,78,35,32,74,87,77,32,77,78,85,32,93,88,32,90,94,82,93,34,33,33,56,32,81,88,89,78,32,98,88,94,32,78,87,83,88,98,32,86,98,32,80,74,86,78,32,39,38,33,63,74,94,92,78,77,39,33,65,78,92,94,86,78,32,54,74,86,78,33,65,78,92,93,74,91,93,33,60,74,82,87,32,60,78,87,94,33,52,97,82,93,32,48,89,89,85,82,76,74,93,82,88,87,33,65,78,86,74,82,87,82,87,80,32,67,82,85,78,92,39,33,67,82,86,78,32,67,74,84,78,87,39,33,54,74,86,78,32,62,95,78,91,109,33,65,78,92,93,74,91,93,33,60,74,82,87,32,60,78,87,94,33,65,78,92,94,86,78,32,54,74,86,78,33,52,97,82,93,32,48,89,89,85,82,76,74,93,82,88,87,33,65,78,86,74,82,87,82,87,80,32,67,82,85,78,92,39,33,67,82,86,78,32,67,74,84,78,87,39,33,54,74,86,78,32,50,88,86,89,85,78,93,78,109,33,65,78,92,94,86,78,32,54,74,86,78,33,65,78,92,93,74,91,93,33,60,74,82,87,32,60,78,87,94,33,52,97,82,93,32,48,89,89,85,82,76,74,93,82,88,87,33,66,76,88,91,78,39,33,67,82,86,78,32,67,74,84,78,87,39,33 +//}; //const uint24_t section[11] = {0,112,206,287,371,430,548,1059,1143,1230,1311}; /* Legacy */ uint16_t initialPalette[256] = { /*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/ /*A*/ /*B*/ /*C*/ /*D*/ /*E*/ /*F*/ -/*0*/ 0x0000,0x7C00,0xFFE0,0x83E0,0x83FF,0x001F,0x7C1F,0xFFFF,0x1CE7,0x3C00,0x3DE0,0x01E0,0x01EF,0x000F,0x3C0F,0xDEF7 -/*1*/,0x79E0,0x0210,0x0210,0x0210,0x0210,0x0210,0x1084,0x6000,0x7800,0x1400,0x0421,0x5294,0x5EE0,0x0000,0x0000,0x0000 -/*2*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*3*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*4*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*5*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*6*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*7*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*8*/,0x7800,0x1400,0x7BC0,0x14A0,0x03C0,0x00A0,0x7BDE,0x294A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*9*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*A*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*B*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*C*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*D*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*E*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 -/*F*/,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 /* Menu fade effect */ +/*0*/ 0x0000,0x7C00,0xFFE0,0x83E0,0x83FF,0x001F,0x7C1F,0xFFFF,0x1CE7,0x3C00,0x3DE0,0x01E0,0x01EF,0x000F,0x3C0F,0xDEF7, +/*1*/ 0x79E0,0x0210,0x0210,0x0210,0x0210,0x0210,0x1084,0x6000,0x7800,0x1400,0x0421,0x5294,0x5EE0, 0, 0, 0, +/*2*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*3*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*4*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*5*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*6*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*7*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*8*/ 0x7800,0x1400,0x7BC0,0x14A0,0x03C0,0x00A0,0x7BDE,0x294A, 0, 0, 0, 0, 0, 0, 0, 0, +/*9*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*A*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*B*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*C*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*D*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*E*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*F*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* Menu fade effect */ }; /* Global */ @@ -197,6 +233,8 @@ uint8_t* state = (uint8_t*)RAM_ADDRESS(0xD5F000); uint24_t* search = (uint24_t*)RAM_ADDRESS(0xD60000); uint8_t* flag = (uint8_t*)RAM_ADDRESS(0xD62000); + + uint24_t fadeSpeed = 0; const uint16_t orderPos[18] = { @@ -204,42 +242,37 @@ const uint16_t orderPos[18] = { }; //344 + 16 for buffer reasons since this keeeps being a probelmy const int8_t order[360] = { - -1,1,0,1,1,1,-1,0,1,0,-1,-1,0,-1,1,-1, - -1,2,1,2,-2,1,-2,-1,2,1,2,-1,-1,-2,1,-2, - 0,2,0,1,0,-1,0,-2,-2,0,-1,0,1,0,2,0, - -2,2,2,2,-1,1,1,1,-1,-1,1,-1,-2,-2,2,-2, - 2,2,2,-2,-2,2,-2,-2,1,0,-1,0,0,1,0,-1, - -1,2,2,1,1,-2,-2,-1,1,0,-1,0,0,1,0,-1, - 1,1,1,2,-1,-1,-1,-2,-2,1,-1,1,2,-1,1,-1, - -2,1,-1,1,2,1,1,1,-2,-1,-1,-1,2,-1,1,-1, - 1,1,1,-1,-1,1,-1,-1,2,0,1,0,-1,0,-2,0, - -1,0,1,0,0,1,0,-1, - -1,1,0,1,1,1,-1,0,1,0,-1,-1,0,-1,1,-1, -1,0,1,0,0,1,0,-1, - -1,1,0,1,1,1,-1,0,1,0,-1,-1,0,-1,1,-1, -1,-1,1,1,-1,1,1,-1, - 0,2,0,1,0,-1,0,-2,-2,0,-1,0,1,0,2,0, -2,2,2,2,-1,1,1,1,-1,-1,1,-1,-2,-2,2,-2, - -1,1,0,1,1,1,-1,0,1,0,-1,-1,0,-1,1,-1, -1,2,1,2,-2,1,-2,-1,2,1,2,-1,-1,-2,1,-2, - -1,0,1,0,0,1,0,-1, 2,2,2,-2,-2,2,-2,-2,1,0,-1,0,0,1,0,-1, - -1,0,1,0,0,1,0,-1, 0,2,0,1,0,-1,0,-2,-2,0,-1,0,1,0,2,0, - 0,2,0,1,0,1,0,-1,0,-1,0,-2, 2,0,1,0,1,0,-1,0,-1,0,-2,0, 1,1,1,-1,-1,1,-1,-1 + /* 0 */ -1, 1, 0, 1, 1, 1, -1, 0, 1, 0, -1,-1, 0,-1, 1,-1, + /* 1 */ -1, 2, 1, 2, -2, 1, -2,-1, 2, 1, 2,-1, -1,-2, 1,-2, + /* 2 */ 0, 2, 0, 1, 0,-1, 0,-2, -2, 0, -1, 0, 1, 0, 2, 0, + /* 3 */ -2, 2, 2, 2, -1, 1, 1, 1, -1,-1, 1,-1, -2,-2, 2,-2, + /* 4 */ 2, 2, 2,-2, -2, 2, -2,-2, 1, 0, -1, 0, 0, 1, 0,-1, + /* 5 */ -1, 2, 2, 1, 1,-2, -2,-1, 1, 0, -1, 0, 0, 1, 0,-1, + /* 6 */ 1, 1, 1, 2, -1,-1, -1,-2, -2, 1, -1, 1, 2,-1, 1,-1, + /* 7 */ -2, 1, -1, 1, 2, 1, 1, 1, -2,-1, -1,-1, 2,-1, 1,-1, + /* 8 */ 1, 1, 1,-1, -1, 1, -1,-1, 2, 0, 1, 0, -1, 0, -2, 0, + /* 9 */ -1, 0, 1, 0, 0, 1, 0,-1, + /* 10 */ -1, 1, 0, 1, 1, 1, -1, 0, 1, 0, -1,-1, 0,-1, 1, -1, -1, 0, 1, 0, 0, 1, 0,-1, + /* 11 */ -1, 1, 0, 1, 1, 1, -1, 0, 1, 0, -1,-1, 0,-1, 1, -1, -1,-1, 1, 1, -1, 1, 1,-1, + /* 12 */ 0, 2, 0, 1, 0,-1, 0,-2, -2, 0, -1, 0, 1, 0, 2, 0, -2, 2, 2, 2, -1, 1, 1, 1, -1,-1, 1,-1, -2,-2, 2,-2, + /* 13 */ -1, 1, 0, 1, 1, 1, -1, 0, 1, 0, -1,-1, 0,-1, 1, -1, -1, 2, 1, 2, -2, 1, -2,-1, 2, 1, 2,-1, -1,-2, 1,-2, + /* 14 */ -1, 0, 1, 0, 0, 1, 0,-1, 2, 2, 2,-2, -2, 2, -2,-2, 1, 0, -1, 0, 0, 1, 0,-1, + /* 15 */ -1, 0, 1, 0, 0, 1, 0,-1, 0, 2, 0, 1, 0, -1, 0,-2, -2, 0, -1, 0, 1, 0, 2, 0, + /* 16 */ 0, 2, 0, 1, 0, 1, 0,-1, 0,-1, 0,-2, 2, 0, 1, 0, 1, 0, -1, 0, -1, 0, -2, 0, 1, 1, 1,-1, -1, 1, -1,-1 }; -uint8_t bX[18] = {14,20,24,29,32,34, 34,36,40,47,54,56, 14,24,32,34,40,54}; //Plus 4 -uint8_t bY[18] = {14,14,16,19,20,22, 25,28,29,29,29,31, 14,16,20,25,29,29}; //Plus 4 -uint24_t bM[18] = {10,18,30,54,72,90, 108,136,180,240,300,3, 10,30,72,108,180,300}; -uint8_t bF[6] = {7,7,7,7,7,7}; +const uint8_t bX[18] = {14,20,24,29,32,34, 34,36,40,47,54,56, 14,24,32,34,40,54}; //Plus 4 +const uint8_t bY[18] = {14,14,16,19,20,22, 25,28,29,29,29,31, 14,16,20,25,29,29}; //Plus 4 +const uint24_t bM[18] = {10,18,30,54,72,90, 108,136,180,240,300,3, 10,30,72,108,180,300}; +const uint8_t bF[6] = { + FontPreset_Smallest, FontPreset_Smallest, FontPreset_Smallest, FontPreset_Smallest, FontPreset_Smallest, FontPreset_Smallest +}; ///fff uint8_t option = 0; -#define RGB4bit 0x825 -#define RGB8bit 0x827 -#define RGB16bit 0x82D -#define BGR4bit 0x925 -#define BGR8bit 0x927 -#define BGR16bit 0x92D - //Broken Functions /* uint8_t findColor1555(uint16_t c); diff --git a/src/global.h b/src/global.h index 3c244f2..041a1af 100644 --- a/src/global.h +++ b/src/global.h @@ -15,9 +15,51 @@ //#define VIDEO //Disables cutscene and saves a few bytes #define DEVBUILD -enum COLORS { //Will it be used? Or will knuckles prevail - Black,Red,Yellow,Lime,Teal,Blue,Magenta,White, - Grey,Maroon,Brown,Green,Cyan,Navy,Purple,Silver +enum Color_Enum { //Will it be used? Or will knuckles prevail + /* Standard 16 colors */ + Color_Black, Color_Red , Color_Yellow , Color_Lime , + Color_Aqua , Color_Blue , Color_Fuchsia, Color_White , + Color_Grey , Color_Maroon, Color_Olive , Color_Green , + Color_Teal , Color_Navy , Color_Purple , Color_Silver, + /* Selection Colors */ + Color_Orange, + /* Background Graphics */ + Color_Background, Color_SymbolMine, Color_SymbolFlag, Color_SymbolKnight, Color_SymbolInvertedMine, + /* Unknown */ + Color_FlagPole, Color_MineBackground, Color_UnusedBrightRed, Color_UnusedDarkRed, + Color_UnusedAlmostBlack, + /* Segment */ + Color_SegmentBorder, + /* Unknown */ + Color_TestGraphicBackground, + /* Segment Colors */ + Color_SegmentBrightRed = 0x80, Color_SegmentDarkRed , + Color_SegmentBrightYellow , Color_SegmentDarkYellow, + Color_SegmentBrightGreen , Color_SegmentDarkGreen , + Color_SegmentWhite , Color_SegmentGrey , + /* Fade Colors */ + Color_FadeStart = 0xF0, +}; + +enum GameModes { + GameMode_Classic, + GameMode_Knight, + GameMode_LongOrthogonal, + GameMode_Diagonal, + GameMode_Target, + GameMode_Clover, + GameMode_Windmill, + GameMode_XFighter, + GameMode_TyeFighter, + GameMode_NearOrthogonal, + GameMode_DoubledOrthogonal, + GameMode_DoubledDiagonal, + GameMode_ShipWheel, + GameMode_Hashtag, + GameMode_DoubledTarget, + GameMode_DoubledCenterOrthogonal, + GameMode_Taxicab, + GameMode_Count }; /* @@ -27,9 +69,9 @@ enum COLORS { //Will it be used? Or will knuckles prevail extern uint24_t mines; //U16 extern int24_t flags; //S16 extern uint24_t cleared; //U16 -extern uint8_t win; +extern bool win_Available; extern uint24_t flagColor; -extern uint8_t cheater; +extern bool cheater; extern uint8_t autoLoss; extern int24_t score; @@ -38,7 +80,6 @@ extern int24_t tile; /* Parameters */ -#define gameModeCount 17 extern uint24_t gameMode; extern uint24_t sizeX; // Board X extern uint24_t sizeY; // Board Y @@ -73,7 +114,7 @@ extern uint8_t autoSolver; //off,manual,automatic //Video Settings extern uint24_t displayMode; //Originally videoMode -extern uint8_t accessMode; //Increases Readability, Disables Quake +extern uint8_t accessibility_Mode; //Increases Readability, Disables Quake extern uint8_t fadeEffect; //off,static,dynamic //Refactor to bgEffects extern uint8_t fpsCounter; //Debug thing extern uint8_t cursorGraphic; @@ -92,17 +133,15 @@ extern uint8_t autoSaveMax; /* Settings */ /* Text */ -extern uint8_t guideText[511]; -#define guideTextLength 511 //helpText had a naming conflict >:( - -extern uint8_t pauseText[84]; -#define pauseTextLength 84 -extern uint8_t gameOverText[87]; -#define gameOverTextLength 87 -extern uint8_t winText[81]; -#define winTextLength 81 -extern uint8_t cheatText[16]; -#define cheatTextLength 16 + +//helpText had a naming conflict >:( + +extern const uint8_t guideText[511]; +extern const uint8_t pauseText[84]; +extern const uint8_t gameOverText[87]; +extern const uint8_t winText[81]; +extern const uint8_t cheatText[16]; + /* Text */ /* IO Handeling */ @@ -118,7 +157,6 @@ extern uint24_t cursorAllow; /* Legacy */ extern const uint8_t hiddenText[43]; //SuperSweeper V:X.XX.X ZERICO2005 YYYY/MM/DD -extern const uint8_t hiddenTextLength; extern const uint8_t blockLimits[6]; //Minus 1 // @@ -144,7 +182,16 @@ extern const uint8_t color[28]; extern uint16_t initialPalette[256]; //const uint8_t CLICKABLE = 0b00000100; const uint8_t SELECT1 = 0b00000001; const uint8_t SELECT2 = 0b00000010; const uint8_t SELECT3 = 0b00000011; red darkRed 0grey 1grey -enum guiType {Click = 1, Scroll = 2, Dial = 4, Direct = 8, Value = 16, Dot = 32, BoolToggle = 64, Text = 128}; +enum guiType { + Click = (1 << 0), + Scroll = (1 << 1), + Dial = (1 << 2), + Direct = (1 << 3), + Value = (1 << 4), + Dot = (1 << 5), + BoolToggle = (1 << 6), + Text = (1 << 7) +}; /* Global */ // Video @@ -183,24 +230,27 @@ extern const uint16_t orderPos[18]; //344 + 16 for buffer reasons since this keeeps being a probelmy extern const int8_t order[360]; +enum FontPreset { + FontPreset_6x8_13x13, FontPreset_6x8_11x13, FontPreset_6x8_9x11, + FontPreset_5x5_10x10, FontPreset_5x5_8x8, + FontPreset_3x5_8x10, FontPreset_3x5_8x8, FontPreset_3x5_6x8, + FontPreset_Count, + FontPreset_Largest = FontPreset_6x8_13x13, + FontPreset_Smallest = FontPreset_3x5_6x8 +}; + extern const uint8_t fontArray[40]; -extern uint8_t bX[18]; //Plus 4 -extern uint8_t bY[18]; //Plus 4 -extern uint24_t bM[18]; -extern uint8_t bF[6]; +extern const uint8_t bX[18]; //Plus 4 +extern const uint8_t bY[18]; //Plus 4 +extern const uint24_t bM[18]; +extern const uint8_t bF[6]; ///fff extern uint8_t option; -#define RGB4bit 0x825 -#define RGB8bit 0x827 -#define RGB16bit 0x82D -#define BGR4bit 0x925 -#define BGR8bit 0x927 -#define BGR16bit 0x92D //Broken Functions /* diff --git a/src/main.c b/src/main.c index 349ac56..3b0fec9 100644 --- a/src/main.c +++ b/src/main.c @@ -49,12 +49,12 @@ void SPI_Column_Major() { void init_routine() { initLCDcontroller("Super-Sweeper v" STR_N(PROGRAM_V_MAJOR) "." STR_N(PROGRAM_V_MINOR) "." STR_N(PROGRAM_V_PATCH)); - // #ifndef SWAP_X_AND_Y_CORD - // SPI_Row_Major(); - // #else - // SPI_Column_Major(); - // #endif - SPI_Column_Major(); + #ifdef SWAP_X_AND_Y_CORD + SPI_Column_Major(); + #else + SPI_Row_Major(); + #endif + // ((void(*)(void))0x384)(); // SPI_FIFO_IN_OUT8 = 0x08; // SPI_FIFO_IN_OUT8 = 0x44; @@ -67,22 +67,24 @@ void init_routine() { //playIntroVideo(); // Video memcpy(lcd_Palette,initialPalette,256 * sizeof(uint16_t)); - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoMode = lcd_BGR8bit; } void terminate_routine() { terminateLCDcontroller(); - SPI_Row_Major(); - lcd_UpBase = 0xD40000; + #ifdef SWAP_X_AND_Y_CORD + SPI_Row_Major(); + #endif + lcd_UpBase = RAM_OFFSET(lcd_Ram); lcd_VideoMode = lcd_BGR16bit; } int main() { init_routine(); - // Palette Test - // gColor = 0; + // // Palette Test + // gColor = Color_Black; // for (uint24_t y = 256; y < 400; y += 9) { // for (uint24_t x = 0; x < 144; x += 9) { // fillRect(x,y,8,8); @@ -91,7 +93,7 @@ int main() { // } fpsT = 32768 / FPS; //Sets fpsTemp for settings menu - fontSize = 7; + fontSize = FontPreset_3x5_6x8; menuLoop(); diff --git a/src/menu.c b/src/menu.c index b618052..b9bda40 100644 --- a/src/menu.c +++ b/src/menu.c @@ -54,7 +54,7 @@ void execute(); void blockText(uint8_t block, uint8_t y) { //Commonly used code - gColor = 0; + gColor = Color_Black; //uint16_t t = textIndex[boxIndex[block]]; uint8_t x = 20; @@ -92,13 +92,13 @@ uint8_t fBMax; uint8_t phase = 0; void fadeClear() { fColor = lcd_Palette; - fColor += (row + 0xF0); + fColor += (row + Color_FadeStart); *fColor = initialPalette[boxColor[row + offset]]; } #define darkMax 6 void fadeSet() { fColor = lcd_Palette; - fColor += (row + 0xF0); + fColor += (row + Color_FadeStart); fR = (*fColor >> 10) & 31; fG = (*fColor >> 5) & 31; fB = (*fColor) & 31; @@ -164,10 +164,10 @@ void setNumber(uint16_t index, uint16_t value) { void buildMenu() { - gColor = 15; + gColor = Color_Silver; fillScreen(); uint24_t j = 20; - uint8_t pColor = 0xF0; + uint8_t pColor = Color_FadeStart; for (row = 0; row < menuRows[sector]; row++) { gColor = boxColor[boxPos]; initialPalette[pColor] = initialPalette[gColor]; @@ -176,12 +176,12 @@ void buildMenu() { // if (select != 0) { // gColor = blockColor[select + offSec]; // } else { - // gColor = 16; + // gColor = Color_Orange; // } fillRect(16, j - 4, 196, 16); if (boxType[boxPos] & Value) { - gColor = 0; + gColor = Color_Black; text6x8(202, j, 29); //>> uint16_t value = getNumber(boxPos); text6x8(195, 20 + (24 * row), (value % 10)); @@ -194,9 +194,9 @@ void buildMenu() { } } if (boxType[boxPos] & BoolToggle) { - gColor = row + 0xF0; + gColor = row + Color_FadeStart; fillRect(202, j, 6, 8); - gColor = 0; + gColor = Color_Black; if (boxMax[boxPos] < 255) { if (*(uint8_t*)boxPointer[boxPos] == boxMax[boxPos]) { text6x8(202, j, 50); @@ -212,7 +212,7 @@ void buildMenu() { } } // if (blockType[select + offSec]) { - // gColor = 0; + // gColor = Color_Black; // text6x8(202, j + 4, 29); //>> // text6x8(195 - dots * 5, j + 4, 28); //<< // uint8_t dX = 202 - dots * 5; //8bit since it will be less than 255 @@ -228,7 +228,7 @@ void buildMenu() { j += 24; } row = 0; - gColor = 0; + gColor = Color_Black; blockText(sector,20); //fillRect(247,120,30,65); //Was Green @@ -253,7 +253,7 @@ void scroll() { } row--; } - // gColor = 16; + // gColor = Color_Orange; // fillText(16, 16 + (24 * select), 196, 16); } @@ -293,14 +293,14 @@ void dial(uint16_t boxOffset, uint8_t boxRow) { //uint8_t src, uint8_t des value = getNumber(box); // Keeps track of any changes made by a function } - gColor = boxRow + 0xF0; //16 + gColor = boxRow + Color_FadeStart; //16 fillRect(188, yCord, 13, 8); if (boxMax[box] > 99) { fillRect(181, yCord, 6, 8); - gColor = 0; + gColor = Color_Black; text6x8(181, yCord, ((value / 100))); //Undefined Behaviour above 2599 } - gColor = 0; + gColor = Color_Black; text6x8(195, yCord, (value % 10)); text6x8(188, yCord, ((value / 10) % 10)); } @@ -310,9 +310,9 @@ void button(uint16_t box) { } void buttonToggle(uint16_t index) { - gColor = row + 0xF0; + gColor = row + Color_FadeStart; fillRect(202, 20 + (24 * row), 6, 8); - gColor = 0; + gColor = Color_Black; if (boxMax[index] < 255) { if (*(uint8_t*)boxPointer[index] == boxMax[index]) { *(uint8_t*)boxPointer[index] = boxMin[index]; diff --git a/src/mineSweeper.c b/src/mineSweeper.c index 90a1d7a..97548ba 100644 --- a/src/mineSweeper.c +++ b/src/mineSweeper.c @@ -29,7 +29,9 @@ uint8_t maxY; }; typedef struct FontSizeData FontSizeData; - enum FontSizeList {FontSize_3x5,FontSize_5x5,FontSize_6x8}; + enum FontSizeList { + FontSize_3x5, FontSize_5x5, FontSize_6x8 + }; const FontSizeData fontSizeData[] = { {FontSize_6x8,13,13,3,2, 24,16},{FontSize_6x8,11,13,2,2, 28,16},{FontSize_6x8,9,11,1,1, 35,19}, @@ -74,14 +76,14 @@ void displaySeg7(uint24_t i, uint8_t b, struct dataSeg7* lcd) { //Number, Digits //Colors: 24/25/26/27 uint24_t x = lcd->x; uint24_t y = lcd->y; - uint8_t d = lcd->digits; + uint8_t digits = lcd->digits; uint8_t hi = lcd->onC; uint8_t lo = lcd->offC; uint24_t pow = 1; - uint24_t z = y * LCD_RESX; //Constant offset - x += (d - 1) * 9; - for (uint8_t n = 0; n < d; n++) { //Since d was decremented + const uint24_t z = y * LCD_RESX; //Constant offset + x += (digits - 1) * 9; + for (uint8_t n = 0; n < digits; n++) { //Since d was decremented uint8_t j = seg7[(i / pow) % b]; gColor = (j & 64) ? hi : lo; if (gColor != lcd_Ram8[z + x + (0 * LCD_RESX + 1)]) { // Checks for change in color @@ -138,33 +140,33 @@ uint8_t bgC, uint8_t borC, uint8_t offC, uint8_t onC) { //Number, Digits, Base, lcd->digits = digits; lcd->x = x + 2; //Offset of where the number graphic is lcd->y = y + 2; - lcd->offC = (accessMode == 1) ? 0x00 : offC; + lcd->offC = accessibility_Mode ? Color_Black : offC; lcd->onC = onC; displaySeg7(input,base,lcd); } void quake() { newFrame(); - if (accessMode == 0) { //Remove this + if (accessibility_Mode == false) { //Remove this delay32K(32768/15); //Waits 32768Hz / FPS uint24_t shake; - int8_t amount = mineCount / 3; - if (amount < 12) { - amount = 12; + int8_t mineAmount = mineCount / 3; + if (mineAmount < 12) { + mineAmount = 12; } - if (amount > 90 || mineCount > 255) { - amount = 90; + if (mineAmount > 90 || mineCount > 255) { + mineAmount = 90; } srand(timer_Get(1)); - for (uint8_t i = 0; i < amount; i++) { - shake = 0xD40000 - ((LCD_RESX * 8) * 3) - (8 * 3); + for (uint8_t i = 0; i < mineAmount; i++) { + shake = RAM_OFFSET(lcd_Ram) - ((LCD_RESX * 8) * 3) - (8 * 3); shake += 8 * (rand() % 7); shake += (LCD_RESX * 8) * (rand() % 7); lcd_UpBase = shake; newFrame(); delay32K(32768/20); } - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); newFrame(); delay32K(32768/2); } else { @@ -183,9 +185,9 @@ void expression(uint8_t e) { // Updates the smiley face currentGame = gameStartTime; currentExpression = e; if (e < 4) { //0-3 - gColor = 2; + gColor = Color_Yellow; fillRect(156, 12, 7, 3); //y2 = 3 because of chordCheck - gColor = 0; + gColor = Color_Black; switch (e) { case eHAPPY: horiz(157, 13, 5); @@ -201,16 +203,16 @@ void expression(uint8_t e) { // Updates the smiley face horiz(156, 13, 7); return; case eCHORD: - gColor = 2; + gColor = Color_Yellow; fillRect(156,12,7,2); - gColor = 0; + gColor = Color_Black; fillRect(158,12,3,3); return; }; } else if (e < 8) { //4-7 - gColor = 2; + gColor = Color_Yellow; fillRect(156, 5, 7, 4); - gColor = 0; + gColor = Color_Black; switch (e) { case eNORMAL: //Normal vert(157, 7, 2); @@ -218,9 +220,9 @@ void expression(uint8_t e) { // Updates the smiley face return; case eSHADES: //Sunglasses fillRect(156, 7, 7, 2); - gColor = 2; + gColor = Color_Yellow; plot(159, 8); - gColor = 0; + gColor = Color_Black; plot(162, 6); plot(163, 5); plot(156, 6); @@ -270,7 +272,7 @@ void flash() { //uint8_t x // Legacy Flag Counter Code void flagDraw(uint8_t symbol, uint24_t xP, uint24_t yP) { - gColor = accessMode ? 0 : color[symbol]; + gColor = accessibility_Mode ? Color_Black : color[symbol]; symbol <<= 1; uint16_t bitImage0 = char5x5[symbol]; uint16_t bitImage1 = char5x5[symbol + 1]; @@ -293,21 +295,21 @@ void flagDraw(uint8_t symbol, uint24_t xP, uint24_t yP) { } void flagCount() { - gColor = 15; + gColor = Color_Silver; for (int24_t z = 15; z <= 35; z += 10) { //Flag Counter fillRect(z, 5, 7, 7); } - gColor = 0; + gColor = Color_Black; if (flags >= 100) { flagDraw(flags / 100 % 10,17,7); } else if (flags <= -10){ - gColor = 0; + gColor = Color_Black; horiz(17, 9, 5); } if (flags >= 10 || flags <= -10) { flagDraw(abs(flags) / 10 % 10,27,7); } else if (flags < 0 && flags >= -9) { - gColor = 0; + gColor = Color_Black; horiz(27, 9, 5); } flagDraw(abs(flags) % 10,37,7); @@ -345,7 +347,7 @@ void glyph(int16_t space, uint8_t symbol) { gColor = color[symbol]; if (symbol == gFlag) { if (fontSizeData[fontSize].padY == 1 || fontSizeData[fontSize].padX == 1) { - gColor = 22; //Changes flag pole color to be more readable + gColor = Color_FlagPole; //Changes flag pole color to be more readable } } #ifndef SWAP_X_AND_Y_CORD @@ -369,11 +371,11 @@ void glyph(int16_t space, uint8_t symbol) { gColor = flagColor; fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY + 1, 3, 3); } else if (symbol == gMine) { - //gColor = 7; + //gColor = Color_White; z -= (LCD_RESX * 6) - 2; - *z = 7; // 2,2 // White + *z = Color_White; // 2,2 // White z += (LCD_RESX - 1); - *z = 7; // 1,3 // White + *z = Color_White; // 1,3 // White } } break; case FontSize_5x5: { @@ -401,7 +403,7 @@ void glyph(int16_t space, uint8_t symbol) { gColor = flagColor; fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); } else if (symbol == 2 * gMine) { - //gColor = 7; + //gColor = Color_White; z -= (LCD_RESX * 4) - 1; *z = 7; // 1,1 // White } @@ -447,7 +449,7 @@ void glyph(int16_t space, uint8_t symbol) { gColor = flagColor; fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY + 1, 3, 3); } else if (symbol == gMine) { - //gColor = 7; + //gColor = Color_White; z -= (LCD_RESY * 4) - 2; *z = 7; // 2,2 // White z -= (LCD_RESY - 1); @@ -481,7 +483,7 @@ void glyph(int16_t space, uint8_t symbol) { gColor = flagColor; fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); } else if (symbol == 2 * gMine) { - //gColor = 7; + //gColor = Color_White; z += (LCD_RESY * 1) - 4; *z = 7; // 1,1 // White } @@ -511,10 +513,10 @@ void glyph(int16_t space, uint8_t symbol) { } void fillTile(int16_t space, int8_t mode) { - gColor = 15; //grey + gColor = Color_Silver; //silver if (state[space] == sHIDDEN) { - if (mode == tSELECT) { gColor = 16; } + if (mode == tSELECT) { gColor = Color_Orange; } fillRect(space % marX * disX + 1 + posX, space / marX * disY + 1 + posY, disX - 3, disY - 3); if (flag[space] == 1) {glyph(space, gFlag);} else if (flag[space] == 2) {glyph(space, gQuestion);} @@ -522,9 +524,9 @@ void fillTile(int16_t space, int8_t mode) { if (board[space] == gMine) { autoLoss = 1; - gColor = mode == tCLEAR ? 0x17 : 0x01; //Dark red if mine is not highlighted, Bright red if mine is highlighted + gColor = mode == tCLEAR ? Color_MineBackground : Color_Red; //Dark red if mine is not highlighted, Bright red if mine is highlighted } else { - gColor = mode == tSELECT ? 0x10 : 0x0F; + gColor = mode == tSELECT ? Color_Orange : Color_Silver; } fillRect(space % marX * disX + posX, space / marX * disY + posY, disX - 1, disY - 1); //fillRect(tile % marX * disX + posX, tile / marX * disY + posY, disX - 1, disY - 1); @@ -616,7 +618,7 @@ bool mineCheck(int24_t tileM) { return true; } } - if ((gameMode == 3 || gameMode == 9) && safeGuess == 2) { + if ((gameMode == GameMode_Diagonal || gameMode == GameMode_NearOrthogonal) && safeGuess == 2) { for (uint8_t i = 0; i < 8; i++) { u = order[i]; //Probably more memory effeicent than an algorithm v = order[i + 1]; @@ -731,68 +733,95 @@ void mineGenerate() { } */ +bool chordCheck = false; + +enum Cursor_Colors { + Cursor_Palette0 = 0b00, + Cursor_Palette1 = 0b01, + Cursor_Transparent = 0b10, + Cursor_Inverted = 0b11 +}; + void chord() { - return; - lcd_CrsrX = ((tile % marX) - 2) * disX + posX; - lcd_CrsrY = ((tile / marX) - 2) * disY + posY; + if (cursorGraphic) { + lcd_CrsrX = ((tile % marX) - 2) * disX + posX; + lcd_CrsrY = ((tile / marX) - 2) * disY + posY; + } + // lcd_CrsrClipX = (lcd_CrsrX >= LCD_RESX) ? ((uint8_t)(-lcd_CrsrX)) : 0; + // lcd_CrsrClipY = (lcd_CrsrY >= LCD_RESY) ? ((uint8_t)(-lcd_CrsrY)) : 0; } + uint8_t gridType[25]; -void cursorSetup() { // Code may crash the calculator - return; // Disabled for now - //memcpy(lcd_CrsrImage, chordImage, 1024); - //uint8_t* ci = (uint8_t*)lcd_CrsrImage; - /* //Crashes calculator and maybe broken - for (uint24_t i = 0; i < 1024; i++) { - *ci = 0b10101010; //Transparent - ci++; - } - */ +void cursorSetup() { + uint32_t start_T0 = timer_Get(1); + const uint8_t Cursor_Clear = (Cursor_Transparent | (Cursor_Transparent << 2) | (Cursor_Transparent << 4) | (Cursor_Transparent << 6)); + memset( + lcd_CrsrImage, + Cursor_Clear, + lcd_CrsrImageLen64 + ); + memset(gridType, Cursor_Clear, sizeof(gridType)); + for (uint8_t i = 0; i < offLen; i += 2) { //Generates fill grid from search pattern int8_t u = order[offPos + i]; int8_t v = order[offPos + i + 1]; - gridType[12 + u + (v * 5)] = 0b00000011; - } - gridType[12] = 0b01; - - uint8_t dX = (disX * 5) - 1; - uint8_t dY = (disY * 5) - 1; - uint8_t* i = (uint8_t*)lcd_CrsrImage; - uint8_t v = 0; - for (uint8_t y = 0; y < dY; y++) { //Fills 2bit grid - if (y % disY == disY - 1) { - i += 16; - v += 5; - } else { - uint8_t u = 0; - for (uint8_t x = 0; x < 64; x += 4) { - uint8_t g = 0; - for (uint8_t z = 0; z < 4 && (z + x < dX); z++) { - if ((x + z) % disX != disX - 1) { - //g |= (gridType[((y / disY) * 5) + (x / disX)] << 5) >> z; - g |= (gridType[u + v] << 6) >> (z << 1); - } else { - u++; - } - } - *i |= g; - i++; - } - } + gridType[12 + u + (v * 5)] = Cursor_Inverted; } + gridType[(2 * 5) + 2] = Cursor_Inverted; + + + const uint8_t lenX = (disX * 5) - 1; + const uint8_t lenY = (disY * 5) - 1; + + /* Naive Implementation */ + // #define CrsrImage2bit(index, value) lcd_CrsrImage[(index) / 4] |= (value) >> (2 * ((index) % 4)); + // for (uint8_t y = 0; y < lenY; y++) { + // uint16_t index = (uint16_t)y * 64; + // for (uint8_t x = 0; x < lenX; x++) { + // if (y % disY == disY - 1 || x % disX == disX - 1) { + // CrsrImage2bit(index, Cursor_Transparent); + // } else { + // CrsrImage2bit(index, gridType[((y / disY) * 5) + (x / disX)]); + // } + // index++; + // } + // } + // #undef CrsrImage2bit + + /* Optimized */ + + uint8_t y_mod = disY - 1; + for (uint8_t y = 0; y < lenY; y++) { + uint16_t index = (uint16_t)y * 16; + uint8_t x_mod = disX - 1; + uint8_t shift = 6; + uint8_t gridPos = (y / disY) * 5; + for (uint8_t x = 0; x < lenX; x++) { + if (y_mod != 0 && x_mod != 0) { + lcd_CrsrImage[index] |= gridType[gridPos] << shift; + } + gridPos += (x_mod == 0) ? 1 : 0; + x_mod = (x_mod == 0) ? (disX - 1) : (x_mod - 1); + + index += (shift == 0) ? 1 : 0; + shift = (shift == 0) ? 6 : (shift - 2); + } + y_mod = (y_mod == 0) ? (disY - 1) : (y_mod - 1); + } - lcd_CrsrCtrl = 0x00000000; // enable cursor - lcd_CrsrPalette0 = 0x00FFBF00; //24bit 888 BGR - lcd_CrsrPalette1 = 0x000000FF; + Initialize_lcd_Crsr(); + Use_lcd_CrsrImage64x64(); + lcd_CrsrPalette0 = 0xFFBF00; //24bit 888 BGR + lcd_CrsrPalette1 = 0xAA00FF; // lcd_CrsrXY = 0; // reset cursor position chord(); - lcd_CrsrClip = 0; // reset clipping - lcd_CrsrConfig = 0x00000001; - lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(320 - 1) << 16; //Set CPL + uint32_t start_T1 = timer_Get(1); + printUInt(start_T1 - start_T0, 6, 10, 2, 20); } void drawGame() { - - gColor = 17; + uint32_t start_T0 = timer_Get(1); + gColor = Color_Background; //gColor = findColor888(0x00,0x70,0x70); //Failed test fillScreen(); //Cyan if (fadeEffect > 0) { @@ -808,65 +837,71 @@ void drawGame() { uint24_t rY = 4; for (; rY < LCD_RESY - 32; rY += 32) { for (uint24_t rX = 4; rX < LCD_RESX; rX += 32) { - gColor = 18; + gColor = Color_SymbolMine; text6x8(rX, rY, gMine); - gColor = 19; + gColor = Color_SymbolFlag; text6x8(rX + 16, rY, gFlag); - gColor = 20; + gColor = Color_SymbolKnight; text6x8(rX, rY + 16, gKnight); - gColor = 21; + gColor = Color_SymbolInvertedMine; text6x8(rX + 16, rY + 16, gInvertedMine); vert(rX + 15, rY + 16, 8); vert(rX + 22, rY + 16, 8); } } for (uint24_t rX = 4; rX < LCD_RESX; rX += 32) { - gColor = 18; + gColor = Color_SymbolMine; text6x8(rX, rY, gMine); - gColor = 19; + gColor = Color_SymbolFlag; text6x8(rX + 16, rY, gFlag); } } - gColor = (15); //Fill Sqaures + // printf("\npos(%d,%d) dis(%dx%d)",posX,posY,disX,disY); // fflush(stdout); - for (int24_t y = borderIndexes; y < marY - borderIndexes; y++) { - for (int24_t x = borderIndexes; x < marX - borderIndexes; x++) { - // printf("\n[%d,%d]: (%d,%d)(%dx%d)",x,y,x * disX + posX + 1,y * disY + posY + 1, disX - 3, disY - 3); - // fflush(stdout); - fillRect(x * disX + posX + 1, y * disY + posY + 1, disX - 3, disY - 3); - } - } + gColor = (Color_Silver); //Fill Sqaures + fillRect( + (borderIndexes * disX) + posX + 1, + (borderIndexes * disY) + posY + 1, + (sizeX * disX) - 3, + (sizeY * disY) - 3 + ); + // for (int24_t y = borderIndexes; y < marY - borderIndexes; y++) { + // for (int24_t x = borderIndexes; x < marX - borderIndexes; x++) { + // // printf("\n[%d,%d]: (%d,%d)(%dx%d)",x,y,x * disX + posX + 1,y * disY + posY + 1, disX - 3, disY - 3); + // // fflush(stdout); + // fillRect(x * disX + posX + 1, y * disY + posY + 1, disX - 3, disY - 3); + // } + // } /*for (uint24_t x = 5; x < 55; x += 10) { // Flag Squares fillRect(x, 5, 9, 9); }*/ //Don't delete me //Shaded Lines for (int24_t i = (disX * 2) + posX; i < disX * (marX - 2) + posX; i += disX) { - gColor = (7); + gColor = (Color_White); vert(i, (disY * 2) + posY, disY * (sizeY) - 1); - gColor = (0); + gColor = (Color_Black); vert(i + disX - 2, (disY * 2) + posY, disY * (sizeY) - 1); } for (int24_t i = (disY * 2) + posY; i < disY * (marY - 2) + posY; i += disY) { - gColor = (7); + gColor = (Color_White); horiz((disX * 2) + posX, i, disX * (sizeX) - 1); - gColor = (0); + gColor = (Color_Black); horiz((disX * 2) + posX, i + disY - 2, disX * (sizeX) - 1); } if (!(disX & 1)) { //% 2 - gColor = (darkMode != 0) ? 0x07 : 0x00; //Inverted Colors + gColor = (darkMode != 0) ? Color_White : Color_Black; //Inverted Colors vert(LCD_RESX - 1, 0, LCD_RESY); } //Border Lines - gColor = (8); + gColor = (Color_Grey); for (int24_t i = (disY * 2) - 1 + posY; i <= disY * (marY - 2) - 1 + posY; i += disY) { horiz((disX * 2) - 1 + posX, i, disX * (sizeX) + 1); } for (int24_t i = (disX * 2) - 1 + posX; i <= disX * (marX - 2) - 1 + posX; i += disX) { vert(i, (disY * 2) - 1 + posY, disY * (sizeY) + 1); } - /* //UI Lines //Don't delete this horiz(4, 4, 51); @@ -884,7 +919,7 @@ void drawGame() { uint24_t z1 = z0 + 960; uint24_t z2 = VRAM + (7 * LCD_RESX) + 47; uint24_t z3 = z2 + 960; - gColor = 0; + gColor = Color_Black; for (uint24_t y = 0; y < 1600; y += LCD_RESX) { for (uint24_t x = 0; x < 5; x++) { if (bitImage0 & 1) { @@ -907,14 +942,14 @@ void drawGame() { } gColor = flagColor; fillRect(7, 7, 2, 2); - gColor = 7; + gColor = Color_White; plotFast(VRAM + (LCD_RESX * 8) + 48); //x48 y8 }*/ for (uint24_t x = 154; x <= 164; x++) { for (uint24_t y = 5; y <= 15; y++) { if ((x - 159) * (x - 159) + (y - 10) * (y - 10) < 36) { - gColor = 2; + gColor = Color_Yellow; plot(x,y); } } @@ -926,35 +961,43 @@ void drawGame() { //GUI Counters flagCount(); /* Color numbers */ - buildSeg7(4912,18,&flagLCD,3,9,0,0x00,0x1B,0x81,0x80); //Flags 17^3 - 1 + buildSeg7((17*17*17 - 1), 18, &flagLCD, 3, 9, 0, + Color_Black, Color_SegmentBorder, Color_SegmentDarkRed, Color_SegmentBrightRed + ); //Flags 17^3 - 1 flagLCD.digits = 1; - gColor = 0x1B; + gColor = Color_SegmentBorder; fillRect(0,0,9,19); fillRect(39,0,9,19); flagCount(); //Manual Symbol Draw - gColor = 0x00; + gColor = Color_Black; text6x8(2,1,gMine); text6x8(40,1,gFlag); - gColor = 0x01; + gColor = Color_Red; fillRect(40,2,3,3); - gColor = 0x07; + gColor = Color_White; plot(4,3); plot(3,4); /* Color numbers */ - buildSeg7(104975,18,&timeLCD,4,224,0,0x00,0x1B,0x83,0x82); //Time 18^4 - 1 - buildSeg7(1889567,18,&scoreLCD,5,272,0,0x00,0x1B,0x85,0x84); //Score 18^5 - 1 + buildSeg7((18*18*18*18 - 1), 18, &timeLCD, 4, 224, 0, + Color_Black, Color_SegmentBorder, Color_SegmentDarkYellow, Color_SegmentBrightYellow + ); //Time 18^4 - 1 + buildSeg7((18*18*18*18*18 - 1), 18, &scoreLCD, 5, 272, 0, + Color_Black, Color_SegmentBorder, Color_SegmentDarkGreen, Color_SegmentBrightGreen + ); //Score 18^5 - 1 // for (uint24_t i = 0; i < 17; i++) { // Column Major Address/Order Test - // gColor = 1; + // gColor = Color_Red; // plotFast(1 << i); - // gColor = 0; + // gColor = Color_Black; // plotFast((1 << i) + 1); - // gColor = 7; + // gColor = Color_White; // plotFast((1 << i) + 2); - // gColor = 5; + // gColor = Color_Blue; // plotFast((1 << i) + 3); // } + uint32_t start_T1 = timer_Get(1); + printUInt(start_T1 - start_T0, 6, 10, 2, 30); } void fontCheck() { @@ -976,7 +1019,7 @@ void resetGame() { //1: Board marX = sizeX + 4; marY = sizeY + 4; - fontSize = 0; // Resets font size to the largest available before doing the font check stuff + fontSize = FontPreset_Largest; // Resets font size to the largest available before doing the font check stuff fontCheck(); //Fits font to screen size posX = 160 - (disX >> 1) * marX; //Allign game board @@ -1009,11 +1052,11 @@ void resetGame() { //2: Reset autoLoss = 0; - cheater = 0; + cheater = false; item = 0; //Resets the search pointer max = 0; //Resets the search max cleared = 0; //Resets the amount of cleared tiles - win = 1; //Enables winning again + win_Available = true; //Enables winning again score = 0; gamePauseTime = systemTime; offPos = orderPos[gameMode]; @@ -1028,8 +1071,9 @@ void resetGame() { //3: Graphics drawGame(); - //4: Cursor - if (cursorAllow) { + //4: Cursor + chordCheck = false; + if (cursorGraphic) { cursorSetup(); } @@ -1098,7 +1142,7 @@ void autoChord() { if (board[square] != 255 && state[square] != sCLEARED && flag[square] != fFLAG) { //If tile is not out of bounds and not cleared yet flag[square] = fFLAG; flags--; - gColor = 15; + gColor = Color_Silver; fillRect(square % marX * disX + 1 + posX, square / marX * disY + 1 + posY, disX - 3, disY - 3); glyph(square, gFlag); autoCheck = 1; @@ -1109,8 +1153,8 @@ void autoChord() { } void autoSolve() { - cheater = 1; - uint24_t tileAS = tile; + cheater = true; + uint24_t tileAutoSolve = tile; for (uint8_t i = 0; i < autoSolver; i++) { //Genius Right? 1 if manual, 2 if auto haha autoCheck = 0; tile = marX * borderIndexes + borderIndexes; @@ -1125,7 +1169,7 @@ void autoSolve() { i = 0; } } - tile = tileAS; + tile = tileAutoSolve; } #ifndef PLATFORM_TI84CE @@ -1163,7 +1207,6 @@ void autoSolve() { } #endif -uint8_t chordCheck = 0; void gameLoop() { //key = 99; //Prevents endless restart loop do { @@ -1174,10 +1217,9 @@ void gameLoop() { if (status == QUIT) { status = OKAY; } - if (cursorAllow) { // Resets the cursor - lcd_CrsrConfig = 0x00000000; - lcd_CrsrCtrl = 0x00000000; - lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(240 - 1) << 16; + if (cursorGraphic) { // Resets the cursor + + Terminate_lcd_Crsr(); } } @@ -1187,24 +1229,24 @@ void gameControl() { if (cleared != 0) { //Time displaySeg7(score,10,&scoreLCD); //Score - if (currentTime < 327680000) { // <10000 seconds or <2.78 Hours - displaySeg7(currentTime >> 15,10,&timeLCD); + if (currentTime < ((uint32_t)32768 * (uint32_t)1000)) { // <10000 seconds or <2.78 Hours + displaySeg7(currentTime >> 15, 10, &timeLCD); } else { //Blinks after 9999 seconds if (systemTime & 16384) { // Blinks at 2 Hertz - displaySeg7(104975,18,&timeLCD); //Time ---- 18^4 - 1 + displaySeg7((18*18*18*18 - 1), 18, &timeLCD); //Time ---- 18^4 - 1 } else { - displaySeg7(9999,10,&timeLCD); //Time 9999 + displaySeg7(9999, 10, &timeLCD); //Time 9999 } } - } else if (currentTime >= 327680000) { + } else if (currentTime >= ((uint32_t)32768 * (uint32_t)1000)) { displaySeg7(9999,10,&timeLCD); //Time 9999 } - #ifndef PLATFORM_TI84CE bool alphaClick = false; bool secondClick = false; bool chordClick = false; if (setTileToMousePosition()) { + chord(); uint32_t mouseState = getMouseState(NULL,NULL); alphaClick = mouseState & 0x1; secondClick = mouseState & 0x4; @@ -1217,13 +1259,17 @@ void gameControl() { #endif if ((kb_Data[3] & kb_GraphVar) || chordClick) { + if (cursorGraphic) { + Enable_lcd_Crsr(); + } expression(eCHORD); if (cleared != 0 && (keyReady & CHORD)) { keyReset(cHORD); autoChord(); } } else { - if (win) { + Disable_lcd_Crsr(); + if (win_Available) { expression(eHAPPY); } else { expression(eSAD); @@ -1234,31 +1280,29 @@ void gameControl() { keyReset(dEBUG); expression(eCHORD); autoSolve(); - if (win) { + if (win_Available) { expression(eHAPPY); } else { expression(eSAD); } } - if (cursorAllow) { - if (keyReady & CHORD) { - if ((kb_Data[3] & kb_GraphVar)) { - keyReset(cHORD); - //lcd_CrsrCtrl = 0x00000001; - expression(eCHORD); - chordCheck = 1; - } else if (chordCheck == 1) { - //lcd_CrsrCtrl = 0x00000000; - if (win) { - expression(eHAPPY); - } else { - expression(eSAD); - } - chordCheck = 0; - } - } - } + // if (cursorGraphic) { + // if (keyReady & CHORD) { + // if ((kb_Data[3] & kb_GraphVar)) { + // keyReset(cHORD); + // expression(eCHORD); + // chordCheck = true; + // } else if (chordCheck == true) { + // if (win_Available) { + // expression(eHAPPY); + // } else { + // expression(eSAD); + // } + // chordCheck = false; + // } + // } + // } if (kb_Data[7] && (keyReady & ARROW)) { //Checks that an arrow key was pressed keyReset(aRROW); @@ -1293,9 +1337,7 @@ void gameControl() { tile -= (marX - 5); } } - if (cursorAllow) { - chord(); - } + chord(); fillTile(tile, tSELECT); //Draws Tile } @@ -1351,9 +1393,9 @@ void gameControl() { floodFill(); flagCount(); } - if (((sizeX) * (sizeY)) - mines - cleared == 0 && win) { //Win + if (((sizeX) * (sizeY)) - mines - cleared == 0 && win_Available) { //Win expression(eSHADES); - lcd_CrsrCtrl = 0x00000000; + Disable_lcd_Crsr(); flash(); winScreen(); } @@ -1363,13 +1405,13 @@ void gameControl() { } - if (autoLoss == 1 && win == true) { + if (autoLoss == 1 && win_Available == true) { expression(eSAD); - //lcd_CrsrCtrl = 0x00000000; + Disable_lcd_Crsr(); quake(); flash(); gameOver(); - win = false; + win_Available = false; } if (((keyReady & SECOND) && (secondBind() || secondClick)) && state[tile] != sCLEARED) { //2nd @@ -1400,6 +1442,7 @@ void gameControl() { } if ((keyReady & OTHER) && (kb_Data[1] & kb_Mode)) { //Mode keyReset(oTHER); + Disable_lcd_Crsr(); pause(); } @@ -1422,7 +1465,7 @@ void gameControl() { // gameSaveFile.SizeX = sizeX; // gameSaveFile.SizeY = sizeY; // gameSaveFile.CursorPos = tile; - // gameSaveFile.GameState = ((cheater & 1) << 1) | (win & 1); + // gameSaveFile.GameState = ((cheater ? 1 : 0) << 1) | (win_Available ? 1 : 0); // gameSaveFile.GameMode = gameMode; // saveGame(&gameSaveFile,state,flag) == false; // } diff --git a/src/mineSweeper.h b/src/mineSweeper.h index c5a1a00..411ccb8 100644 --- a/src/mineSweeper.h +++ b/src/mineSweeper.h @@ -16,7 +16,7 @@ #include "gameMenu.h" //#include -#define borderIndexes 2 +#define borderIndexes (2) //Graphic numbers #define gMine (25) #define gFlag (26) @@ -25,7 +25,7 @@ #define gInvertedMine (31) #define currentTime (systemTime - gameStartTime - gamePauseTime) -void gameControl(); //Temporary May 23 +void gameControl(); //Temporary May 23 (2023) /* //legacy @@ -81,7 +81,7 @@ void flagCount(); // flagLCD.offC = color[((plags / 100) % 10)] | 8; //Slow, but its the only way to do signed flag counts for now -void flagCount(); //Add a color number mode for nostalga +// void flagCount(); //Add a color number mode for nostalga void glyph(int16_t space, uint8_t symbol); @@ -118,15 +118,12 @@ void fontCheck(); //Plus 4 void resetGame(); -//8x8: 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111 ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 ,0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111 ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 ,0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111 ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 ,0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111 ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 ,0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111 ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 ,0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111, 0b11111111,0b11111111,0b11111111,0b10111111,0b11111111,0b11111111,0b11101111,0b11111111,0b11111111,0b11111011,0b11111111,0b11111111,0b11111110,0b11111111,0b11111111,0b11111111 ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 -//New Line: ,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010,0b10101010 - extern uint8_t autoCheck; void autoChord(); void autoSolve(); -extern uint8_t chordCheck; +extern bool chordCheck; void gameLoop(); void gameControl(); diff --git a/src/primeKey.c b/src/primeKey.c index 54bbef5..62fcdca 100644 --- a/src/primeKey.c +++ b/src/primeKey.c @@ -62,7 +62,7 @@ void shiftScreen() { //Moves the frame base around change = 1; } if (kb_Data[4] & kb_5) { //Reset - lcd_UpBase = 0xD40000; + lcd_UpBase = RAM_OFFSET(lcd_Ram); change = 1; } if (change) { diff --git a/src/subMenu.c b/src/subMenu.c index 437f71d..2922deb 100644 --- a/src/subMenu.c +++ b/src/subMenu.c @@ -85,20 +85,20 @@ uint8_t sector = 0; // The following was generated from "Super CSV" void (*menuFunction[11])() = {0,buildPattern,buildPattern,buildPattern,leadChange,versionText,0,testGraphic,0,helpText,quitGame}; -uint8_t menuBack[11] = {10,0,0,0,0,0,5,5,5,0,0}; -uint16_t boxIndex[12] = {0,8,16,21,28,37,43,47,54,59,60,60}; -uint8_t menuRows[11] = {8,8,5,7,9,6,4,7,5,1,1}; +const uint8_t menuBack[11] = {10,0,0,0,0,0,5,5,5,0,0}; +const uint16_t boxIndex[12] = {0,8,16,21,28,37,43,47,54,59,60,60}; +const uint8_t menuRows[11] = {8,8,5,7,9,6,4,7,5,1,1}; -uint8_t boxType[60] = {9,9,9,9,9,9,9,9,0,22,4,4,4,1,9,9,22,1,9,9,9,22,22,22,22,22,9,9,0,0,0,0,0,0,0,22,9,65,9,9,9,0,9,52,65,52,9,54,65,52,65,65,22,9,21,1,1,1,9,9}; +const uint8_t boxType[60] = {9,9,9,9,9,9,9,9,0,22,4,4,4,1,9,9,22,1,9,9,9,22,22,22,22,22,9,9,0,0,0,0,0,0,0,22,9,65,9,9,9,0,9,52,65,52,9,54,65,52,65,65,22,9,21,1,1,1,9,9}; uint8_t boxColor[60] = {5,11,9,12,6,2,1,8,5,8,8,8,8,7,8,8,10,14,7,8,8,8,8,8,9,8,1,8,5,8,8,8,8,8,8,10,8,1,8,8,8,7,8,9,8,8,8,11,8,8,8,12,5,8,8,8,8,9,8,8}; -uint8_t boxDirect[60] = {1,1,2,3,4,5,9,0,0,0,0,0,0,0,3,0,0,0,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,8,0,0,0,0,0,5,0,0,0,0,0,0,5,0,0,0,0,5,0}; -uint16_t textIndex[61] = {0,23,41,54,64,79,91,99,112,124,137,147,155,169,183,193,206,227,242,256,271,284,297,305,313,327,341,355,368,383,386,389,392,395,398,401,414,427,446,460,475,491,500,512,526,535,547,556,567,586,605,628,647,659,668,684,701,719,734,743,755}; +const uint8_t boxDirect[60] = {1,1,2,3,4,5,9,0,0,0,0,0,0,0,3,0,0,0,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,8,0,0,0,0,0,5,0,0,0,0,0,0,5,0,0,0,0,5,0}; +const uint16_t textIndex[61] = {0,23,41,54,64,79,91,99,112,124,137,147,155,169,183,193,206,227,242,256,271,284,297,305,313,327,341,355,368,383,386,389,392,395,398,401,414,427,446,460,475,491,500,512,526,535,547,556,567,586,605,628,647,659,668,684,701,719,734,743,755}; void (*boxFunction[60])() = {modeSet,modeSet,0,0,0,0,0,quitGame,0,drawPattern,0,0,0,gameStart,0,0,drawPattern,randomMode,0,0,0,drawPattern,changeInBoardSize,changeInBoardSize,changeInMineCount,changeInPercent,gameStart,0,0,0,0,0,0,0,0,leadChange,0,swapPrimaries,0,0,0,0,0,0,0,0,0,videoUpdate,accessSet,0,0,0,fpsUpdate,0,0,0,0,0,0,0}; -void* boxPointer[60] = {0,0,0,0,0,0,0,0,0,&gameMode,0,0,0,0,0,0,&gameMode,&gameMode,0,0,0,&gameMode,&sizeX,&sizeY,&mineCount,&percent,0,0,0,0,0,0,0,0,0,&gameMode,0,&swapAlphaSecondBind,0,0,0,0,0,&safeGuess,&chording,&autoSolver,0,&displayMode,&accessMode,&fadeEffect,&cursorGraphic,&movieIntro,&fpsT,0,&autoSaveMax,0,0,0,0,0}; -uint8_t boxMin[60] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,8,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0}; -uint16_t boxMax[60] = {0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,16,0,0,0,0,16,52,27,702,50,0,0,0,0,0,0,0,0,0,16,0,1,0,0,0,0,0,2,1,2,0,3,1,2,1,1,992,0,3,0,0,0,0,0}; +void* boxPointer[60] = {0,0,0,0,0,0,0,0,0,&gameMode,0,0,0,0,0,0,&gameMode,&gameMode,0,0,0,&gameMode,&sizeX,&sizeY,&mineCount,&percent,0,0,0,0,0,0,0,0,0,&gameMode,0,&swapAlphaSecondBind,0,0,0,0,0,&safeGuess,&chording,&autoSolver,0,&displayMode,&accessibility_Mode,&fadeEffect,&cursorGraphic,&movieIntro,&fpsT,0,&autoSaveMax,0,0,0,0,0}; +const uint8_t boxMin[60] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,8,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0}; +const uint16_t boxMax[60] = {0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,16,0,0,0,0,16,52,27,702,50,0,0,0,0,0,0,0,0,0,16,0,1,0,0,0,0,0,2,1,2,0,3,1,2,1,1,992,0,3,0,0,0,0,0}; -uint8_t sourceText[755] = {66,101,90,108,108,98,92,32,76,98,103,94,82,112,94,94,105,94,107,39,32,25,33,74,103,98,96,97,109,32,82,112,94,94,105,94,107,39,32,30,33,64,101,101,32,76,104,93,94,108,39,32,26,33,66,110,108,109,104,102,39,32,48,33,75,94,90,93,94,107,91,104,90,107,93,39,32,44,33,82,94,109,109,98,103,96,108,39,32,43,33,71,94,101,105,39,32,27,33,68,113,98,109,32,70,90,102,94,39,32,45,33,80,110,98,92,100,32,70,90,102,94,39,33,70,90,102,94,32,76,104,93,94,39,32,30,33,79,107,94,108,94,109,39,32,26,33,82,98,115,94,39,32,46,33,67,98,95,95,98,92,110,101,109,114,39,32,41,33,82,109,90,107,109,32,70,90,102,94,39,32,25,33,66,110,108,109,104,102,39,32,43,33,76,90,98,103,32,76,94,103,110,39,32,45,33,79,90,109,109,94,107,103,32,82,94,101,94,92,109,98,104,103,39,32,26,33,81,90,103,93,104,102,32,76,104,93,94,39,32,27,33,80,110,98,92,100,32,70,90,102,94,39,32,25,33,66,110,108,109,104,102,32,70,90,102,94,39,32,43,33,76,90,98,103,32,76,94,103,110,39,32,45,33,70,90,102,94,32,76,104,93,94,39,32,30,33,82,98,115,94,32,87,39,33,82,98,115,94,32,88,39,33,76,98,103,94,32,66,104,110,103,109,39,32,25,33,79,94,107,92,94,103,109,90,96,94,39,32,41,33,82,109,90,107,109,32,70,90,102,94,39,32,26,33,76,90,98,103,32,76,94,103,110,39,32,45,33,71,98,96,97,32,82,92,104,107,94,108,39,32,44,33,1,34,33,2,34,33,3,34,33,4,34,33,5,34,33,6,34,33,70,90,102,94,32,76,104,93,94,39,32,30,33,76,90,98,103,32,76,94,103,110,39,32,45,33,82,112,90,105,32,64,101,105,97,90,32,90,103,93,32,2,103,93,33,70,90,102,94,32,82,94,109,109,98,103,96,108,33,85,98,93,94,104,32,82,94,109,109,98,103,96,108,33,67,90,109,90,32,76,90,103,90,96,94,102,94,103,109,33,85,94,107,108,98,104,103,39,33,76,90,98,103,32,76,94,103,110,32,45,33,82,90,95,94,32,70,110,94,108,108,98,103,96,33,66,97,104,107,93,98,103,96,33,64,110,109,104,32,82,104,101,111,94,107,33,81,94,109,110,107,103,32,45,33,85,98,93,94,104,32,76,104,93,94,33,64,92,92,94,108,108,98,91,98,101,98,109,114,32,76,104,93,94,33,65,90,92,100,96,107,104,110,103,93,32,68,95,95,94,92,109,108,33,66,110,107,108,104,107,32,70,107,90,105,97,98,92,32,37,64,101,105,97,90,38,33,68,103,90,91,101,94,32,76,104,111,98,94,32,72,103,109,107,104,33,76,90,113,98,102,110,102,32,69,79,82,33,81,94,109,110,107,103,32,45,33,64,110,109,104,32,82,90,111,94,32,66,104,110,103,109,33,66,101,94,90,107,32,64,110,109,104,32,82,90,111,94,108,33,66,101,94,90,107,32,75,94,90,93,94,107,91,104,90,107,93,33,66,101,94,90,107,32,64,101,101,32,67,90,109,90,33,81,94,109,110,107,103,32,45,33,76,90,98,103,32,76,94,103,110,32,45,33}; +const uint8_t sourceText[755] = {66,101,90,108,108,98,92,32,76,98,103,94,82,112,94,94,105,94,107,39,32,25,33,74,103,98,96,97,109,32,82,112,94,94,105,94,107,39,32,30,33,64,101,101,32,76,104,93,94,108,39,32,26,33,66,110,108,109,104,102,39,32,48,33,75,94,90,93,94,107,91,104,90,107,93,39,32,44,33,82,94,109,109,98,103,96,108,39,32,43,33,71,94,101,105,39,32,27,33,68,113,98,109,32,70,90,102,94,39,32,45,33,80,110,98,92,100,32,70,90,102,94,39,33,70,90,102,94,32,76,104,93,94,39,32,30,33,79,107,94,108,94,109,39,32,26,33,82,98,115,94,39,32,46,33,67,98,95,95,98,92,110,101,109,114,39,32,41,33,82,109,90,107,109,32,70,90,102,94,39,32,25,33,66,110,108,109,104,102,39,32,43,33,76,90,98,103,32,76,94,103,110,39,32,45,33,79,90,109,109,94,107,103,32,82,94,101,94,92,109,98,104,103,39,32,26,33,81,90,103,93,104,102,32,76,104,93,94,39,32,27,33,80,110,98,92,100,32,70,90,102,94,39,32,25,33,66,110,108,109,104,102,32,70,90,102,94,39,32,43,33,76,90,98,103,32,76,94,103,110,39,32,45,33,70,90,102,94,32,76,104,93,94,39,32,30,33,82,98,115,94,32,87,39,33,82,98,115,94,32,88,39,33,76,98,103,94,32,66,104,110,103,109,39,32,25,33,79,94,107,92,94,103,109,90,96,94,39,32,41,33,82,109,90,107,109,32,70,90,102,94,39,32,26,33,76,90,98,103,32,76,94,103,110,39,32,45,33,71,98,96,97,32,82,92,104,107,94,108,39,32,44,33,1,34,33,2,34,33,3,34,33,4,34,33,5,34,33,6,34,33,70,90,102,94,32,76,104,93,94,39,32,30,33,76,90,98,103,32,76,94,103,110,39,32,45,33,82,112,90,105,32,64,101,105,97,90,32,90,103,93,32,2,103,93,33,70,90,102,94,32,82,94,109,109,98,103,96,108,33,85,98,93,94,104,32,82,94,109,109,98,103,96,108,33,67,90,109,90,32,76,90,103,90,96,94,102,94,103,109,33,85,94,107,108,98,104,103,39,33,76,90,98,103,32,76,94,103,110,32,45,33,82,90,95,94,32,70,110,94,108,108,98,103,96,33,66,97,104,107,93,98,103,96,33,64,110,109,104,32,82,104,101,111,94,107,33,81,94,109,110,107,103,32,45,33,85,98,93,94,104,32,76,104,93,94,33,64,92,92,94,108,108,98,91,98,101,98,109,114,32,76,104,93,94,33,65,90,92,100,96,107,104,110,103,93,32,68,95,95,94,92,109,108,33,66,110,107,108,104,107,32,70,107,90,105,97,98,92,32,37,64,101,105,97,90,38,33,68,103,90,91,101,94,32,76,104,111,98,94,32,72,103,109,107,104,33,76,90,113,98,102,110,102,32,69,79,82,33,81,94,109,110,107,103,32,45,33,64,110,109,104,32,82,90,111,94,32,66,104,110,103,109,33,66,101,94,90,107,32,64,110,109,104,32,82,90,111,94,108,33,66,101,94,90,107,32,75,94,90,93,94,107,91,104,90,107,93,33,66,101,94,90,107,32,64,101,101,32,67,90,109,90,33,81,94,109,110,107,103,32,45,33,76,90,98,103,32,76,94,103,110,32,45,33}; /* Main Menu */ @@ -109,11 +109,11 @@ void modeSet() { // Randomly chooses a gameMode that is not the current gameMode void randomMode() { srand(seed); - uint24_t newGameMode = rand() % (gameModeCount); // Base 1 indexing, refactor/fix this later - gameMode = (newGameMode == gameMode) ? ((newGameMode + 1) % (gameModeCount)) : newGameMode; - gColor = 0xF0; + uint24_t newGameMode = rand() % (GameMode_Count); // Base 1 indexing, refactor/fix this later + gameMode = (newGameMode == gameMode) ? ((newGameMode + 1) % (GameMode_Count)) : newGameMode; + gColor = Color_FadeStart; fillRect(188, 20 + (0 * 24), 14, 8); //Clears characters - gColor = Black; + gColor = Color_Black; text6x8(195, 20 + (0 * 24), (gameMode % 10)); text6x8(188, 20 + (0 * 24), ((gameMode / 10) % 10)); drawPattern(); @@ -132,7 +132,7 @@ void gameStart() { } void drawPattern() { - gColor = 15; + gColor = Color_Silver; for (int24_t y = 0; y < 65; y += 13) { for (int24_t x = 0; x < 65; x += 13) { if (!(x == 26 && y == 26)) { @@ -143,7 +143,7 @@ void drawPattern() { offPos = orderPos[gameMode]; offLen = orderPos[gameMode + 1] - orderPos[gameMode]; - gColor = 16; + gColor = Color_Orange; int24_t u; int24_t v; for (int24_t i = 0; i < offLen; i += 2) { @@ -156,14 +156,14 @@ void drawPattern() { #endif if (*fillR == 0) { //Draws a 3 if 2 is already there fillRect(266 + u, 44 + v , 10, 10); - gColor = 0; + gColor = Color_Black; text6x8(268 + u, 45 + v, 3); //3 - gColor = 16; + gColor = Color_Orange; } else if (*fillR == 16) { //draws a two if a repeat is detected fillRect(266 + u, 44 + v , 10, 10); - gColor = 0; + gColor = Color_Black; text6x8(268 + u, 45 + v, 2); //2 - gColor = 16; + gColor = Color_Orange; } else { fillRect(266 + u, 44 + v , 10, 10); } @@ -172,30 +172,30 @@ void drawPattern() { void buildPattern() { //Draws it too for (int24_t i = 239; i < 304; i += 13) { - gColor = (7); + gColor = (Color_White); vert(i, 17, 64); - gColor = (0); + gColor = (Color_Black); vert(i + 11, 17, 64); } for (int24_t i = 17; i < 82; i += 13) { - gColor = (7); + gColor = (Color_White); horiz(239, i, 64); - gColor = (0); + gColor = (Color_Black); horiz(239, i + 11, 64); } for (int24_t i = 16; i < 94; i += 13) { - gColor = (8); + gColor = (Color_Grey); horiz(238, i, 66); } for (int24_t i = 238; i < 316; i += 13) { - gColor = (8); + gColor = (Color_Grey); vert(i, 16, 66); } - gColor = 1; //Draws the mine in the middle + gColor = Color_Red; //Draws the mine in the middle fillRect(266, 44, 10, 10); - gColor = 0; + gColor = Color_Black; text6x8(268,45,25); - gColor = 7; + gColor = Color_White; plot(270,47); plot(269,48); @@ -226,9 +226,9 @@ void changeInPercent() { // Sets Mine Count based on Percentage of Mines } { const uint24_t yCord = 20 + (24 * 3); - gColor = 0xF3; + gColor = Color_FadeStart + 0x03; fillRect(181, yCord, 20, 8); - gColor = 0; + gColor = Color_Black; text6x8(195, yCord, (mineCount % 10)); text6x8(188, yCord, ((mineCount / 10) % 10)); text6x8(181, yCord, ((mineCount / 100))); // Undefined above 2599 @@ -254,9 +254,9 @@ void changeInMineCount() { // Sets Percentage of Mines based on Mine Count } { const uint24_t yCord = 20 + (24 * 4); - gColor = 0xF4; + gColor = Color_FadeStart + 0x04; fillRect(188, yCord, 13, 8); - gColor = 0; + gColor = Color_Black; text6x8(195, yCord, (percent % 10)); text6x8(188, yCord, ((percent / 10) % 10)); } @@ -273,9 +273,9 @@ void leadChange() { uint8_t gameMod = 0; //using gameMode may be unsafe at this time, alas gameMod for (int24_t y = 44; y <= 16 + ((7) * 24); y += 24) { int24_t x = 20; - gColor = m + 0xF1; //0xF0 + 1 + gColor = m + (Color_FadeStart + 0x01); //0xF0 + 1 fillRect(41, 44 + (24 * m), 48, 8); - gColor = 0; + gColor = Color_Black; text6x8(x + 21, y, names[m * 3 + (gameMod * 18)]); text6x8(x + 28, y, names[m * 3 + 1 + (gameMod * 18)]); text6x8(x + 35, y, names[m * 3 + 2 + (gameMod * 18)]); @@ -295,10 +295,10 @@ void leadChange() { void fadeClear(); void fadeSet(); void swapPrimaries() { - if (boxColor[boxPos] == Red) { - boxColor[boxPos] = Blue; + if (boxColor[boxPos] == Color_Red) { + boxColor[boxPos] = Color_Blue; } else { - boxColor[boxPos] = Red; + boxColor[boxPos] = Color_Red; } fadeClear(); fadeSet(); @@ -317,22 +317,23 @@ void versionText() { } } -#define testGY 17 //Man this looks bad void testGraphic() { - gColor = Grey; // Grey + #define testGY 17 //Man this looks bad + + gColor = Color_Grey; // Grey horiz(217,testGY,98); horiz(217,testGY+13,98); vert(217,testGY+1,12); vert(314,testGY+1,12); - gColor = 0x1C; + gColor = Color_TestGraphicBackground; fillRect(218,testGY+1,96,12); - gColor = Black; + gColor = Color_Black; text6x8(220,testGY+3,gMine); text6x8(228,testGY+3,gFlag); - gColor = White; + gColor = Color_White; plot(222,testGY+5); plot(221,testGY+6); - gColor = Red; + gColor = Color_Red; fillRect(228,testGY+4,4,3); uint24_t x = 236; for (uint8_t i = 0; i < 10; i++) { @@ -340,6 +341,8 @@ void testGraphic() { text6x8(x,testGY+3,i); x += i > 1 ? 8 : 7; } + + #undef testGY } void accessSet() { @@ -377,9 +380,9 @@ void videoUpdate() { //Requires an Update } else { lcd_VideoMode = lcd_BGR8bit; } - gColor = 0xF0; + gColor = Color_FadeStart; fillRect(195, 20, 6, 8); - gColor = 0; + gColor = Color_Black; text6x8(195, 20, displayMode); delay32K(7936); //10240 - 2304 keyReset(hORIZ); @@ -397,12 +400,13 @@ void fpsUpdate() { /* Help */ void helpText() { - gColor = 0x0B; //Dark green + + gColor = Color_Green; //Dark green fillRect(12,40,296,184); - gColor = 0; + gColor = Color_Black; uint24_t x = 16; uint8_t y = 44; - for (uint16_t j = 0; j < guideTextLength; j++) { + for (uint16_t j = 0; j < ARRAY_LENGTH(guideText); j++) { if (guideText[j] == 33) { //New Line x = 16; y += 12; diff --git a/src/subMenu.h b/src/subMenu.h index 36d13ef..79cd6c5 100644 --- a/src/subMenu.h +++ b/src/subMenu.h @@ -76,20 +76,20 @@ extern uint8_t offset; //offset extern uint8_t sector; extern void (*menuFunction[11])(); -extern uint8_t menuBack[11]; -extern uint16_t boxIndex[12]; -extern uint8_t menuRows[11]; +extern const uint8_t menuBack[11]; +extern const uint16_t boxIndex[12]; +extern const uint8_t menuRows[11]; -extern uint8_t boxType[60]; +extern const uint8_t boxType[60]; extern uint8_t boxColor[60]; -extern uint8_t boxDirect[60]; -extern uint16_t textIndex[61]; +extern const uint8_t boxDirect[60]; +extern const uint16_t textIndex[61]; extern void (*boxFunction[60])(); extern void* boxPointer[60]; -extern uint8_t boxMin[60]; -extern uint16_t boxMax[60]; +extern const uint8_t boxMin[60]; +extern const uint16_t boxMax[60]; -extern uint8_t sourceText[755]; +extern const uint8_t sourceText[755]; /* Main Menu */