diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dc8ac0..51363a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ set(LIB_PATH "${TOOLCHAIN_PATH}/lib") set(SRC_DIR "./src") set(SRC_LCD_DIR "./src-lcd") +set(IMGUI_DIR "./imgui") set(PROJECT_NAME "Super-Sweeper-Windows") project(${PROJECT_NAME}) @@ -25,11 +26,12 @@ set(CMAKE_CXX_STANDARD 17) find_package(SDL2 REQUIRED) file(GLOB SRC_FILES "${SRC_DIR}/*.c" "${SRC_LCD_DIR}/*.c") +file(GLOB IMGUI_FILES "${IMGUI_DIR}/*.c" "${IMGUI_DIR}/*.cpp") # Create an executable -add_executable(${PROJECT_NAME} ${SRC_FILES}) +add_executable(${PROJECT_NAME} ${SRC_FILES} ${IMGUI_FILES}) -target_include_directories(${PROJECT_NAME} PUBLIC ${SRC_LCD_DIR}) +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 -Werror) +target_compile_options(${PROJECT_NAME} PUBLIC ${OPT_FLAG} -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable) target_link_libraries(${PROJECT_NAME} PUBLIC SDL2 SDL2main) diff --git a/imgui/.gitignore b/imgui/.gitignore new file mode 100644 index 0000000..8f364ce --- /dev/null +++ b/imgui/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!list.txt \ No newline at end of file diff --git a/imgui/list.txt b/imgui/list.txt new file mode 100644 index 0000000..8dd80e8 --- /dev/null +++ b/imgui/list.txt @@ -0,0 +1,19 @@ +To compile, you may need a few to all of the following files in ./imgui +The files can be obtained from the Dear Imgui github repository https://github.com/ocornut/imgui +Additionally, changing to could help if things are not working correctly. + +imconfig.h +imgui.cpp +imgui.h +imgui_demo.cpp +imgui_draw.cpp +imgui_impl_sdl2.cpp +imgui_impl_sdl2.h +imgui_impl_sdlrenderer2.cpp +imgui_impl_sdlrenderer2.h +imgui_internal.h +imgui_tables.cpp +imgui_widgets.cpp +imstb_rectpack.h +imstb_textedit.h +imstb_truetype.h diff --git a/src-lcd/x86_Render.c b/src-lcd/x86_Render.c index 82ab3f3..4726106 100644 --- a/src-lcd/x86_Render.c +++ b/src-lcd/x86_Render.c @@ -7,11 +7,9 @@ */ //#include "global.h" -#ifndef X86_RENDER_H -#define X86_RENDER_H #include "x86_Common_Def.h" - +#include "x86_Render.h" #include "x86_ti84ce.h" #define SDL_MAIN_HANDLED @@ -23,10 +21,15 @@ uint8_t scale = 2; uint8_t darkMode = 0; bool useMouseInGame = true; -#define RESX_MINIMUM (LCD_RESX) -#define RESY_MINIMUM (LCD_RESY) -#define RESX_MAXIMUM (LCD_RESX * 32) -#define RESY_MAXIMUM (LCD_RESY * 32) +bool columnMajorMode = false; + +int32_t RESX_MINIMUM = LCD_RESX; +int32_t RESY_MINIMUM = LCD_RESY; +int32_t RESX_MAXIMUM = LCD_RESX * 32; +int32_t RESY_MAXIMUM = LCD_RESY * 32; + +int32_t LCD_RESU = LCD_RESX; +int32_t LCD_RESV = LCD_RESY; uint8_t PreCalc_RGB1555[65536 * 3]; uint8_t PreCalc_BGR1555[65536 * 3]; @@ -132,6 +135,31 @@ SDL_Texture* texture; return state; } +/* Row and Column Major */ + +void resetResolutionValues(int32_t resU, int32_t resV) { + LCD_RESU = resU; + LCD_RESV = resV; + RESX_MINIMUM = resU; + RESY_MINIMUM = resV; + RESX_MAXIMUM = resU * 32; + RESY_MAXIMUM = resV * 32; + SDL_SetWindowMinimumSize(window, RESX_MINIMUM, RESY_MINIMUM); + SDL_SetWindowMaximumSize(window, RESX_MAXIMUM, RESY_MAXIMUM); +} + +void internal_SPI_Row_Major() { + columnMajorMode = false; + // resetResolutionValues(LCD_RESX,LCD_RESY); + // resizeWindow(Master.resX,Master.resY,NULL,NULL); +} + +void internal_SPI_Column_Major() { + columnMajorMode = true; + // resetResolutionValues(LCD_RESY,LCD_RESX); + // resizeWindow(Master.resY,Master.resX,NULL,NULL); +} + /* Pointers */ uint8_t _VRAM[153600]; @@ -303,6 +331,8 @@ struct keyBind keyBind2[] = { //WASD /* Keypad Numbers */ {SDL_SCANCODE_KP_0,KB_0},{SDL_SCANCODE_KP_1,KB_1},{SDL_SCANCODE_KP_2,KB_2},{SDL_SCANCODE_KP_3,KB_3},{SDL_SCANCODE_KP_4,KB_4}, {SDL_SCANCODE_KP_5,KB_5},{SDL_SCANCODE_KP_6,KB_6},{SDL_SCANCODE_KP_7,KB_7},{SDL_SCANCODE_KP_8,KB_8},{SDL_SCANCODE_KP_9,KB_9}, + {SDL_SCANCODE_0,KB_0},{SDL_SCANCODE_1,KB_1},{SDL_SCANCODE_2,KB_2},{SDL_SCANCODE_3,KB_3},{SDL_SCANCODE_4,KB_4}, + {SDL_SCANCODE_5,KB_5},{SDL_SCANCODE_6,KB_6},{SDL_SCANCODE_7,KB_7},{SDL_SCANCODE_8,KB_8},{SDL_SCANCODE_9,KB_9}, /* Arrows */ {SDL_SCANCODE_W,KB_Up},{SDL_SCANCODE_S,KB_Down},{SDL_SCANCODE_A,KB_Left},{SDL_SCANCODE_D,KB_Right}, {SDL_SCANCODE_UP,KB_Up},{SDL_SCANCODE_DOWN,KB_Down},{SDL_SCANCODE_LEFT,KB_Left},{SDL_SCANCODE_RIGHT,KB_Right}, @@ -344,7 +374,13 @@ void internal_kb_Scan() { } } -#define videoCopyArray uint8_t c = videoCopy[z] +void renderCursor(uint8_t* data) { + size_t posX = lcd_CrsrX; + size_t posY = lcd_CrsrY; + for (size_t i = 0; i < lcd_CrsrImageLen64; i++) { + + } +} void blit16bpp(uint8_t* data) { uint8_t* PreCalc16; @@ -374,8 +410,9 @@ void blit16bpp(uint8_t* data) { data[w] = PreCalc16[c + 1]; w++; data[w] = PreCalc16[c + 2]; w++; } - z++; + 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++) { @@ -388,17 +425,18 @@ void blit16bpp(uint8_t* data) { void blit8bpp(uint8_t* data) { 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++) { - videoCopyArray; + 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++; + 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++) { @@ -414,7 +452,7 @@ void blit4bpp(uint8_t* data) { size_t z = 0; for (uint32_t y = 0; y < LCD_RESY; y++) { for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { - videoCopyArray; + 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++; @@ -424,8 +462,9 @@ void blit4bpp(uint8_t* data) { data[w] = colorG[(c >> 4) & 0xF]; w++; data[w] = colorB[(c >> 4) & 0xF]; w++; } - z++; + z += columnMajorMode ? (LCD_RESY / PixelsPerByte) : 1; } + z -= columnMajorMode ? (((LCD_RESX / PixelsPerByte) * (LCD_RESY / PixelsPerByte)) - 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++) { @@ -441,7 +480,7 @@ void blit2bpp(uint8_t* data) { size_t z = 0; for (uint32_t y = 0; y < LCD_RESY; y++) { for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { - videoCopyArray; + 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++; @@ -474,7 +513,7 @@ void blit1bpp(uint8_t* data) { size_t z = 0; for (uint32_t y = 0; y < LCD_RESY; y++) { for (uint32_t x = 0; x < LCD_RESX / PixelsPerByte; x++) { - videoCopyArray; + 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++) { @@ -513,7 +552,7 @@ void copyFrame(uint8_t* data) { copyAmount = (LCD_RESX * LCD_RESY) / 2; break; case 0b011: // 8bpp - copyAmount = (LCD_RESX * LCD_RESY) * 2; + copyAmount = (LCD_RESX * LCD_RESY); break; case 0b100: // 16bpp copyAmount = (LCD_RESX * LCD_RESY) * 2; @@ -639,56 +678,74 @@ void initLCDcontroller() { } // Returns True if the window was resized. Optional: Returns new window size. -bool windowResizingCode(uint32_t* resX, uint32_t* resY) { +bool resizeWindow(int32_t resX, int32_t resY, uint32_t* resizeX, uint32_t* resizeY) { bool reVal = false; - int32_t x = 0, y = 0; static int32_t rX = 0, rY = 0; - SDL_GetWindowSize(window,&x,&y); - if ((rX != x || rY != y) && (rX != 0 && rY != 0)) { - valueLimit(x,RESX_MINIMUM,RESX_MAXIMUM); - valueLimit(y,RESY_MINIMUM,RESY_MAXIMUM); + if (rX != resX || rY != resY) { + valueLimit(resX,RESX_MINIMUM,RESX_MAXIMUM); + valueLimit(resY,RESY_MINIMUM,RESY_MAXIMUM); - if (x & 0x3) { x = x & ~0x3; } + if (resX & 0x3) { resX = resX & ~0x3; } // const fp64 MaximumAspectRatio = 1.35; - // fp64 aspectRatio = ((fp64)x / (fp64)LCD_RESX) / ((fp64)y / (fp64)LCD_RESY); + // fp64 aspectRatio = ((fp64)resX / (fp64)LCD_RESX) / ((fp64)resY / (fp64)LCD_RESY); // if (aspectRatio > MaximumAspectRatio) { - // x = (int32_t)(MaximumAspectRatio * ((fp64)y / (fp64)LCD_RESY) * (fp64)LCD_RESX); + // resX = (int32_t)(MaximumAspectRatio * ((fp64)resY / (fp64)LCD_RESY) * (fp64)LCD_RESX); // } else if (aspectRatio < 1.0 / MaximumAspectRatio) { - // y = (int32_t)(MaximumAspectRatio * ((fp64)x / (fp64)LCD_RESX) * (fp64)LCD_RESY); + // resY = (int32_t)(MaximumAspectRatio * ((fp64)resX / (fp64)LCD_RESX) * (fp64)LCD_RESY); // } - fp64 scaleVal = MIN((fp64)x / (fp64)LCD_RESX,(fp64)y / (fp64)LCD_RESY); - x = (int32_t)(scaleVal * (fp64)LCD_RESX); - y = (int32_t)(scaleVal * (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 (x & 0x3) { x = x & ~0x3; } + if (resX & 0x3) { resX = resX & ~0x3; } - // scale = MIN(x / LCD_RESX, y / LCD_RESY); - // x = LCD_RESX * scale; - // y = LCD_RESY * scale; + // scale = MIN(resX / LCD_RESX, resY / LCD_RESY); + // resX = LCD_RESX * scale; + // resY = LCD_RESY * scale; - SDL_SetWindowSize(window,x,y); - SDL_RenderSetLogicalSize(renderer, x, y); - Master.resX = x; - Master.resY = y; + Master.resX = resX; + Master.resY = resY; Master.pitch = Master.resX * 3; - Master.vram = (uint8_t*)realloc((void*)(Master.vram),Master.resX * Master.resY * 3); - if (resX != NULL) { *resX = x; } - if (resY != NULL) { *resY = y; } + 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; + } + } + SDL_SetWindowSize(window,resX,resY); + SDL_RenderSetLogicalSize(renderer, resX, resY); + 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; + } memset(Master.vram,0,Master.pitch * Master.resY); reVal = true; } - rX = x; - rY = y; + rX = resX; + rY = resY; return reVal; } +// Returns True if the window was resized. Optional: Returns new window size. +bool windowResizingCode(uint32_t* resX, uint32_t* resY) { + int32_t x = 0, y = 0; + SDL_GetWindowSize(window,&x,&y); + return resizeWindow(x,y,resX,resY); +} + void newFrame() { if (SDL_PollEvent(&event) && event.type == SDL_QUIT) { @@ -704,6 +761,4 @@ void newFrame() { SDL_RenderCopy(renderer, texture, &srcRect, &dstRect); } SDL_RenderPresent(renderer); -} - -#endif /* X86RENDER_H */ \ No newline at end of file +} \ No newline at end of file diff --git a/src-lcd/x86_Render.h b/src-lcd/x86_Render.h index c66ab61..9eafa2a 100644 --- a/src-lcd/x86_Render.h +++ b/src-lcd/x86_Render.h @@ -14,6 +14,8 @@ int terminateLCDcontroller(); uint32_t getMouseState(int32_t* posX, int32_t* posY); +bool resizeWindow(int32_t resX, int32_t resY, uint32_t* resizeX, uint32_t* resizeY); + void internal_kb_Reset(); void internal_kb_Scan(); @@ -28,4 +30,8 @@ void copyFrame(uint8_t* data); extern uint8_t darkMode; extern bool useMouseInGame; +void internal_SPI_Row_Major(); + +void internal_SPI_Column_Major(); + #endif /* X86_RENDER_H */ \ No newline at end of file diff --git a/src-lcd/x86_ti84ce.c b/src-lcd/x86_ti84ce.c index 1f7cbd5..3ddfed3 100644 --- a/src-lcd/x86_ti84ce.c +++ b/src-lcd/x86_ti84ce.c @@ -274,6 +274,10 @@ uint8_t simulated_ram[16777216]; int24_t ti_Rewind(uint8_t handle) { return ti_Seek(0, SEEK_SET, handle); } + + void* ti_GetDataPtr(uint8_t handle) { + return NULL; + } #undef RamFolderPath #undef NameSize @@ -283,4 +287,12 @@ uint8_t simulated_ram[16777216]; void resetLCDcontroller() { lcd_UpBase = 0xD40000; lcd_VideoMode = lcd_BGR16bit; +} + +void SPI_Row_Major() { + internal_SPI_Row_Major(); +} + +void SPI_Column_Major() { + internal_SPI_Column_Major(); } \ No newline at end of file diff --git a/src-lcd/x86_ti84ce.h b/src-lcd/x86_ti84ce.h index f11a9e8..efbb00b 100644 --- a/src-lcd/x86_ti84ce.h +++ b/src-lcd/x86_ti84ce.h @@ -80,6 +80,8 @@ #define LCD_RESY (240) void resetLCDcontroller(); + void SPI_Row_Major(); + void SPI_Column_Major(); #define lcd_RGB4bit 0x825 #define lcd_RGB8bit 0x827 @@ -153,5 +155,6 @@ int24_t ti_Seek(int24_t offset, uint24_t origin, uint8_t handle); uint16_t ti_GetSize(uint8_t handle); int24_t ti_Rewind(uint8_t handle); + void* ti_GetDataPtr(uint8_t handle); #endif /* X86_TI84CE_H */ \ No newline at end of file diff --git a/src/Common_Def.h b/src/Common_Def.h index de0a263..5527ecd 100644 --- a/src/Common_Def.h +++ b/src/Common_Def.h @@ -14,7 +14,7 @@ #define PROGRAM_V_MAJOR 0 #define PROGRAM_V_MINOR 81 -#define PROGRAM_V_PATCH 1 +#define PROGRAM_V_PATCH 2 //#define PLATFORM_TI84CE #define PLATFORM_X86 @@ -22,6 +22,8 @@ //#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 + #ifdef PLATFORM_TI84CE /* Disabled Functions */ #define newFrame() @@ -58,10 +60,11 @@ #define lcd_Video4bit 0x25 #define lcd_Video8bit 0x27 #define lcd_Video16bit 0x2D + + /* Disabled Functions */ + #define SPI_Row_Major() + #define SPI_Column_Major() #else - /* Disabled Functions */ - #define SPI_Row_Major() - #define SPI_Column_Major() #include "x86_Common_Def.h" #include "x86_ti84ce.h" #include "x86_Render.h" diff --git a/src/fmVideo.c b/src/fmVideo.c new file mode 100644 index 0000000..2ab2cbb --- /dev/null +++ b/src/fmVideo.c @@ -0,0 +1,55 @@ +/* +** Author: zerico2005 (2023-2024) +** Project: Super-Sweeper +** License: MIT License +** A copy of the MIT License should be included with +** this project. If not, see https://opensource.org/license/MIT +*/ + +#include "Common_Def.h" +#include "fmVideo.h" +#include "prime2D.h" +#include "primeKey.h" + + +int8_t playIntroVideo() { + /* + lcd_UpBase = 0xD40000; + lcd_VideoMode = lcd_BGR4bit; + + uint8_t prgm; + char blockName[6] = {'V','O','D','0','0','\0'}; + + while (1) { + + kb_Scan(); //Scans Keys + if (kb_Data[1] & kb_Del) { + return 1; //Quit + } //Force Quit + if ((kb_Data[6] & kb_Enter) || (kb_Data[1] & kb_2nd) || (kb_Data[2] & kb_Alpha) || (kb_Data[7])) { + return 2; //Quit + } //Skip Cutscene + + //Load AppVar + + for (uint8_t block = 0; block < 20; block++) { + blockName[4]++; + if (blockName[4] == ('9' + 1)) { + blockName[3]++; + blockName[4] = '0'; + } + prgm = ti_Open(fileName, "r"); + ti_GetDataPtr(prgm); + uint8_t blockFrameCount = + ti_Seek(offSET, SEEK_SET, prgm); //Seeks to the required data + ti_Read(&data, 3, 10584, prgm); + } + ti_Close(prgm); + } + + prgm = 0; + *frameBase = VRAM; + // *videoMode = 0x92D; //16 bit + */ + return 0; //Quits program +} \ No newline at end of file diff --git a/src/fmVideo.h b/src/fmVideo.h new file mode 100644 index 0000000..26ba9a7 --- /dev/null +++ b/src/fmVideo.h @@ -0,0 +1,16 @@ +/* +** Author: zerico2005 (2023-2024) +** Project: Super-Sweeper +** License: MIT License +** A copy of the MIT License should be included with +** this project. If not, see https://opensource.org/license/MIT +*/ + +#ifndef FMVIDEO_H +#define FMVIDEO_H + +#include "Common_Def.h" + +int8_t playIntroVideo(); + +#endif \ No newline at end of file diff --git a/src/gameMenu.c b/src/gameMenu.c index d96e20b..cb0abc9 100644 --- a/src/gameMenu.c +++ b/src/gameMenu.c @@ -16,22 +16,41 @@ #include "mineSweeper.h" void pause6x8(uint24_t xW, uint24_t yW, uint8_t lexicon) { - uint8_t* bitImage = (uint8_t*)char6x8 + (lexicon * 6); - uint8_t* fill = lcd_Ram8 + (yW * LCD_RESX + xW); - uint8_t b = 1; - uint8_t fColor = (gColor << 4) + gColor; - for (uint8_t y = 0; y < 8; y++) { - for (uint8_t x = 0; x < 6; x++) { - *fill = *bitImage & b ? fColor : *fill; - fill += (LCD_RESX / 2); - *fill = *bitImage & b ? fColor : *fill; - fill -= ((LCD_RESX / 2) - 1); - bitImage++; - } - bitImage -= 6; - fill += (LCD_RESX - 6); - b <<= 1; - } + #ifndef SWAP_X_AND_Y_CORD + uint8_t* bitImage = (uint8_t*)char6x8 + (lexicon * 6); + uint8_t* fill = lcd_Ram8 + (yW * LCD_RESX + xW + (LCD_RESY * LCD_RESX)); + uint8_t b = 0x1; + uint8_t fColor = (gColor << 4) + gColor; + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 6; x++) { + *fill = *bitImage & b ? fColor : *fill; + fill += (LCD_RESX / 2); + *fill = *bitImage & b ? fColor : *fill; + fill -= ((LCD_RESX / 2) - 1); + bitImage++; + } + bitImage -= 6; + fill += (LCD_RESX - 6); + b <<= 1; + } + #else + uint8_t* bitImage = (uint8_t*)char6x8 + (lexicon * 6); + uint8_t* fill = lcd_Ram8 + (xW * LCD_RESY + yW + (LCD_RESY * LCD_RESX)); + uint8_t b = 0x1; + uint8_t fColor = (gColor << 4) + gColor; + for (uint8_t x = 0; x < 6; x++) { + for (uint8_t y = 0; y < 8; y++) { + *fill = *bitImage & b ? fColor : *fill; + fill += (LCD_RESY / 2); + *fill = *bitImage & b ? fColor : *fill; + fill -= ((LCD_RESY / 2) - 1); + b <<= 1; + } + bitImage++; + b = 0x1; + fill += (LCD_RESY - 8); + } + #endif } void text6x8b4(uint24_t xW, uint24_t yW, uint8_t lexicon) { //Incompatibile with 0.70.Alpha and later @@ -92,15 +111,15 @@ void fadeIn() { //Fade in after setup void printStat(uint24_t n) { //Proprietary if (n > 999) { - pause6x8(127, 324, ((n / 1000) % 10)); + pause6x8(127, 84, ((n / 1000) % 10)); } if (n > 99) { - pause6x8(134, 324, ((n / 100) % 10)); + pause6x8(134, 84, ((n / 100) % 10)); } if (n > 9) { - pause6x8(141, 324, ((n / 10) % 10)); + pause6x8(141, 84, ((n / 10) % 10)); } - pause6x8(148, 324, (n % 10)); + pause6x8(148, 84, (n % 10)); } @@ -122,7 +141,7 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse gColor = 7; { uint24_t x = 8; - uint24_t y = 248; + uint24_t y = 8; uint8_t i = 0; for (uint24_t j = section[9]; j < section[10]; j++) { //Set to Win Screen text for temporary measures if (text[j] == 146) { @@ -143,13 +162,13 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse } gColor = 7; - pause6x8(148, 268, (scoreSort() % 10)); - pause6x8(148, 280, (score % 10)); - pause6x8(148, 292, (timer % 10)); + pause6x8(148, 28, (scoreSort() % 10)); + pause6x8(148, 40, (score % 10)); + pause6x8(148, 52, (timer % 10)); gColor = 0; - pause6x8(50, 304, 66); - pause6x8(57, 304, 66); - pause6x8(64, 304, 66); + pause6x8(50, 64, 66); + pause6x8(57, 64, 66); + pause6x8(64, 64, 66); option = 0; while (!(kb_Data[1] & (kb_Graph | kb_Del))) { do { @@ -163,9 +182,9 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse name[option]++; } gColor = 7; - fillRect(50 + (option * 7),304,6,8); + fillRect(50 + (option * 7),64,6,8); gColor = 0; - pause6x8(50 + (option * 7), 304, name[option]); + pause6x8(50 + (option * 7), 64, name[option]); } if (kb_Data[7] & kb_Down) { if (name[option] == 33) { @@ -174,9 +193,9 @@ void scoreScreen() { //broken //I shall fix the sorting now that I can code inse name[option]--; } gColor = 7; - fillRect(50 + (option * 7),304,6,8); + fillRect(50 + (option * 7),64,6,8); gColor = 0; - pause6x8(50 + (option * 7), 304, name[option]); + pause6x8(50 + (option * 7), 64, name[option]); } if (kb_Data[7] & kb_Left) { if (option == 0) { @@ -213,29 +232,29 @@ void timeDisplay(uint32_t input) { //systemTime - gameStartTime - gamePauseTime //_100micro = (input / 3); // 100 micro Second, 1875/2048 ~8.447e-2 accuracy } if (_1000mili > 9999) { // ~2.8 Hours - pause6x8(103, 336, ((_1000mili / 10000) % 10)); + pause6x8(103, 96, ((_1000mili / 10000) % 10)); } if (_1000mili > 999) { // ~16.7 minutes - pause6x8(110, 336, ((_1000mili / 1000) % 10)); + pause6x8(110, 96, ((_1000mili / 1000) % 10)); } if (_1000mili > 99) { // 100 Seconds - pause6x8(117, 336, ((_1000mili / 100) % 10)); + pause6x8(117, 96, ((_1000mili / 100) % 10)); } if (_1000mili > 9) { // 10 Seconds - pause6x8(124, 336, ((_1000mili / 10) % 10)); + pause6x8(124, 96, ((_1000mili / 10) % 10)); } - pause6x8(136, 336, 34); //Decimal Point - pause6x8(131, 336, (_1000mili % 10)); // 1 Second - pause6x8(141, 336, (_100mili % 10)); // 100 MiliSeconds - pause6x8(148, 336, (_10mili % 10)); // 10 MiliSeconds + pause6x8(136, 96, 34); //Decimal Point + pause6x8(131, 96, (_1000mili % 10)); // 1 Second + pause6x8(141, 96, (_100mili % 10)); // 100 MiliSeconds + pause6x8(148, 96, (_10mili % 10)); // 10 MiliSeconds } void pauseScroll() { if ((kb_Data[7] & (kb_Up | kb_Down)) && (keyReady & VERT)) { keyReset(vERT); gColor = 0; - pause6x8(8, 268 + (option * 12), 29); - pause6x8(141, 268 + (option * 12), 28); + pause6x8(8, 28 + (option * 12), 29); + pause6x8(141, 28 + (option * 12), 28); if ((kb_Data[7] & kb_Up)) { if (option == 0) { option = 3; @@ -250,8 +269,8 @@ void pauseScroll() { } } gColor = 7; - pause6x8(8, 268 + (option * 12), 29); - pause6x8(141, 268 + (option * 12), 28); + pause6x8(8, 28 + (option * 12), 29); + pause6x8(141, 28 + (option * 12), 28); } } @@ -272,7 +291,7 @@ void winScreen() { gColor = 7; { uint24_t x = 8; - uint24_t y = 248; + uint24_t y = 8; uint8_t i = 0; uint24_t j = 0; if (cheater == 1) { @@ -300,8 +319,8 @@ void winScreen() { } } - pause6x8(8, 268, 29); - pause6x8(141, 268, 28); + pause6x8(8, 28, 29); + pause6x8(141, 28, 28); option = 0; printStat(score); @@ -350,7 +369,7 @@ void gameOver() { //160x120 screen due to poor coding gColor = 7; { uint24_t x = 8; - uint24_t y = 248; + uint24_t y = 8; uint8_t i = 0; for (uint24_t j = 0; j < gameOverTextLength; j++) { if (gameOverText[j] == 33) { @@ -369,8 +388,8 @@ void gameOver() { //160x120 screen due to poor coding } } } - pause6x8(8, 268, 29); - pause6x8(141, 268, 28); + pause6x8(8, 28, 29); + pause6x8(141, 28, 28); option = 0; @@ -417,7 +436,7 @@ void pause() { gColor = 7; { uint24_t x = 8; - uint24_t y = 248; + uint24_t y = 8; uint8_t i = 0; for (uint24_t j = 0; j < pauseTextLength; j++) { if (pauseText[j] == 33) { @@ -436,8 +455,8 @@ void pause() { } } } - pause6x8(8, 268, 29); - pause6x8(141, 268, 28); + pause6x8(8, 28, 29); + pause6x8(141, 28, 28); option = 0; uint24_t clearTemp = ((sizeX) * (sizeY)) - mines - cleared; diff --git a/src/global.c b/src/global.c index a6c44b7..01a1f34 100644 --- a/src/global.c +++ b/src/global.c @@ -112,7 +112,7 @@ const uint8_t hiddenText[43] = { //SuperSweeper V:X.XX.X ZERICO2005 YYYY/MM/DD (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,1,36,0,4, /* Month Day */ + 0,2,36,1,2, /* Month Day */ }; const uint8_t hiddenTextLength = 43; @@ -148,7 +148,7 @@ const uint8_t color[28] = { uint16_t initialPalette[256] = { /*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/ /*A*/ /*B*/ /*C*/ /*D*/ /*E*/ /*F*/ -/*0*/ 0x0000,0x7C00,0x7FE0,0x03E0,0x03FF,0x001F,0x7C1F,0x7FFF,0x1CE7,0x3C00,0x3DE0,0x01E0,0x01EF,0x000F,0x3C0F,0x5EF7 +/*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 diff --git a/src/main.c b/src/main.c index 238bb85..db4b24c 100644 --- a/src/main.c +++ b/src/main.c @@ -10,9 +10,15 @@ #include "global.h" #include "prime2D.h" #include "menu.h" +#include "fmVideo.h" void init_routine() { initLCDcontroller(); + #ifndef SWAP_X_AND_Y_CORD + SPI_Row_Major(); + #else + SPI_Column_Major(); + #endif // ((void(*)(void))0x384)(); // *(volatile uint8_t*)0xF80018 = 0x08; // *(volatile uint8_t*)0xF80018 = 0x44; @@ -22,6 +28,7 @@ void init_routine() { // Timers timer_Enable(1, TIMER_32K, TIMER_NOINT, TIMER_UP); + //playIntroVideo(); // Video memcpy(lcd_Palette,initialPalette,256 * sizeof(uint16_t)); lcd_UpBase = 0xD40000; diff --git a/src/mineSweeper.c b/src/mineSweeper.c index eecfff7..90a1d7a 100644 --- a/src/mineSweeper.c +++ b/src/mineSweeper.c @@ -348,83 +348,166 @@ void glyph(int16_t space, uint8_t symbol) { gColor = 22; //Changes flag pole color to be more readable } } - switch(font) { - case FontSize_6x8: { - uint8_t* bitImage = (uint8_t*)char6x8 + (symbol * 6); - uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) * LCD_RESX + (space % marX * disX + posX + padX)); - uint8_t b = 1; - for (uint8_t y = 0; y < 8; y++) { + #ifndef SWAP_X_AND_Y_CORD + switch(font) { + case FontSize_6x8: { + uint8_t* bitImage = (uint8_t*)char6x8 + (symbol * 6); + uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) * LCD_RESX + (space % marX * disX + posX + padX)); + uint8_t b = 0x1; + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 6; x++) { + *z = *bitImage & b ? gColor : *z; + bitImage++; + z++; + } + bitImage -= 6; + z += (LCD_RESX - 6); + b <<= 1; + } + + if (symbol == gFlag) { + gColor = flagColor; + fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY + 1, 3, 3); + } else if (symbol == gMine) { + //gColor = 7; + z -= (LCD_RESX * 6) - 2; + *z = 7; // 2,2 // White + z += (LCD_RESX - 1); + *z = 7; // 1,3 // White + } + } break; + case FontSize_5x5: { + symbol <<= 1; + uint16_t bitImage0 = char5x5[symbol]; + uint16_t bitImage1 = char5x5[symbol + 1]; + // uint24_t z1 = z0 + 960; + uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) * LCD_RESX + (space % marX * disX + posX + padX)); + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 5; x++) { + if (bitImage0 & 1) { + *z = gColor; + } + z += (LCD_RESX * 3); + if (bitImage1 & 1) { + *z = gColor; + } + bitImage0 >>= 1; + bitImage1 >>= 1; + z -= (LCD_RESX * 3) - 1; + } + z += LCD_RESX - 5; + } + if (symbol == 2 * gFlag) { + gColor = flagColor; + fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); + } else if (symbol == 2 * gMine) { + //gColor = 7; + z -= (LCD_RESX * 4) - 1; + *z = 7; // 1,1 // White + } + } break; + case FontSize_3x5: { + uint16_t bitImage = char3x5[symbol]; + uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) * LCD_RESX + (space % marX * disX + posX + padX)); + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 3; x++) { + if (bitImage & 1) { + *z = gColor; + } + bitImage >>= 1; + z++; + } + z += (LCD_RESX - 3); + } + if (symbol == gFlag) { + gColor = flagColor; + fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); + } + break; + } + }; + #else + switch(font) { + case FontSize_6x8: { + uint8_t* bitImage = (uint8_t*)char6x8 + (symbol * 6); + uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) + (space % marX * disX + posX + padX) * LCD_RESY); + uint8_t b = 0x1; for (uint8_t x = 0; x < 6; x++) { - *z = *bitImage & b ? gColor : *z; + for (uint8_t y = 0; y < 8; y++) { + *z = *bitImage & b ? gColor : *z; + z++; + b <<= 1; + } bitImage++; - z++; + b = 0x1; + z += (LCD_RESY - 8); } - bitImage -= 6; - z += (LCD_RESX - 6); - b <<= 1; - } - - if (symbol == gFlag) { - gColor = flagColor; - fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY + 1, 3, 3); - } else if (symbol == gMine) { - //gColor = 7; - z -= (LCD_RESX * 6) - 2; - *z = 7; // 2,2 // White - z += (LCD_RESX - 1); - *z = 7; // 1,3 // White - } - } break; - case FontSize_5x5: { - symbol <<= 1; - uint16_t bitImage0 = char5x5[symbol]; - uint16_t bitImage1 = char5x5[symbol + 1]; - // uint24_t z1 = z0 + 960; - uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) * LCD_RESX + (space % marX * disX + posX + padX)); - for (uint8_t y = 0; y < 5; y++) { + + if (symbol == gFlag) { + gColor = flagColor; + fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY + 1, 3, 3); + } else if (symbol == gMine) { + //gColor = 7; + z -= (LCD_RESY * 4) - 2; + *z = 7; // 2,2 // White + z -= (LCD_RESY - 1); + *z = 7; // 1,3 // White + } + } break; + case FontSize_5x5: { + symbol <<= 1; + uint16_t bitImage0 = char5x5[symbol]; + uint16_t bitImage1 = char5x5[symbol + 1]; + // uint24_t z1 = z0 + 960; + uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) + (space % marX * disX + posX + padX) * LCD_RESY); for (uint8_t x = 0; x < 5; x++) { - if (bitImage0 & 1) { - *z = gColor; - } - z += (LCD_RESX * 3); - if (bitImage1 & 1) { - *z = gColor; + for (uint8_t y = 0; y < 5; y++) { + if (bitImage0 & 0x1) { + *z = gColor; + } + z += 3; + if (bitImage1 & 0x1) { + *z = gColor; + } + bitImage0 >>= 1; + bitImage1 >>= 1; + z -= 3; + z += LCD_RESY; } - bitImage0 >>= 1; - bitImage1 >>= 1; - z -= (LCD_RESX * 3) - 1; + z += 1; + z -= (LCD_RESY * 5); } - z += LCD_RESX - 5; - } - if (symbol == 2 * gFlag) { - gColor = flagColor; - fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); - } else if (symbol == 2 * gMine) { - //gColor = 7; - z -= (LCD_RESX * 4) - 1; - *z = 7; // 1,1 // White - } - } break; - case FontSize_3x5: { - uint16_t bitImage = char3x5[symbol]; - uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) * LCD_RESX + (space % marX * disX + posX + padX)); - for (uint8_t y = 0; y < 5; y++) { - for (uint8_t x = 0; x < 3; x++) { - if (bitImage & 1) { - *z = gColor; + if (symbol == 2 * gFlag) { + gColor = flagColor; + fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); + } else if (symbol == 2 * gMine) { + //gColor = 7; + z += (LCD_RESY * 1) - 4; + *z = 7; // 1,1 // White + } + } break; + case FontSize_3x5: { + uint16_t bitImage = char3x5[symbol]; + uint8_t* z = lcd_Ram8 + ((space / marX * disY + posY + padY) + (space % marX * disX + posX + padX) * LCD_RESY); + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 3; x++) { + if (bitImage & 1) { + *z = gColor; + } + bitImage >>= 1; + z += LCD_RESY; } - bitImage >>= 1; z++; + z -= (LCD_RESY * 3); } - z += (LCD_RESX - 3); - } - if (symbol == gFlag) { - gColor = flagColor; - fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); + if (symbol == gFlag) { + gColor = flagColor; + fillRect(space % marX * disX + posX + padX, space / marX * disY + posY + padY, 2, 2); + } + break; } - break; - } - }; + }; + #endif } void fillTile(int16_t space, int8_t mode) { @@ -722,20 +805,27 @@ void drawGame() { initialPalette[i] = 330; } } - for (uint24_t rY = 4; rY < LCD_RESY; rY += 32) { + uint24_t rY = 4; + for (; rY < LCD_RESY - 32; rY += 32) { for (uint24_t rX = 4; rX < LCD_RESX; rX += 32) { gColor = 18; text6x8(rX, rY, gMine); gColor = 19; text6x8(rX + 16, rY, gFlag); gColor = 20; - text6x8(rX, rY + 16, 30); + text6x8(rX, rY + 16, gKnight); gColor = 21; - text6x8(rX + 16, rY + 16, 31); //116 inverted flag + 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; + text6x8(rX, rY, gMine); + gColor = 19; + text6x8(rX + 16, rY, gFlag); + } } gColor = (15); //Fill Sqaures @@ -855,7 +945,16 @@ void drawGame() { 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 - + // for (uint24_t i = 0; i < 17; i++) { // Column Major Address/Order Test + // gColor = 1; + // plotFast(1 << i); + // gColor = 0; + // plotFast((1 << i) + 1); + // gColor = 7; + // plotFast((1 << i) + 2); + // gColor = 5; + // plotFast((1 << i) + 3); + // } } void fontCheck() { diff --git a/src/mineSweeper.h b/src/mineSweeper.h index f03b956..1f2a5bd 100644 --- a/src/mineSweeper.h +++ b/src/mineSweeper.h @@ -18,9 +18,11 @@ #define borderIndexes 2 //Graphic numbers -#define gMine 25 -#define gFlag 26 -#define gQuestion 27 +#define gMine (25) +#define gFlag (26) +#define gQuestion (27) +#define gKnight (30) +#define gInvertedMine (31) #define currentTime (systemTime - gameStartTime - gamePauseTime) void gameControl(); //Temporary May 23 diff --git a/src/prime2D.c b/src/prime2D.c index 95d2deb..2d623cf 100644 --- a/src/prime2D.c +++ b/src/prime2D.c @@ -32,106 +32,230 @@ const uint16_t char5x5[56] = { // Integer to print, length, base 2-16 //Auto adjusts for signage void printInt(int24_t in, uint8_t len, uint8_t base, uint24_t xC, uint24_t yC) { - uint8_t* off = lcd_Ram8 + (int24_t)(xC + (LCD_RESX * yC)); - uint8_t* v = off + LCD_RESX; - len *= 4; - const uint24_t x2 = 5 + len; - const uint24_t jump = (LCD_RESX - 3) - x2; - for (uint8_t dY = 1; dY < 6; dY++) { - for (uint24_t dX = 0; dX < x2; dX += 4) { + #ifndef SWAP_X_AND_Y_CORD + uint8_t* off = lcd_Ram8 + (int24_t)(xC + (LCD_RESX * yC)); + uint8_t* v = off + LCD_RESX; + len *= 4; + const uint24_t x2 = 5 + len; + const uint24_t jump = (LCD_RESX - 3) - x2; + for (uint8_t dY = 1; dY < 6; dY++) { + for (uint24_t dX = 0; dX < x2; dX += 4) { + *v = 0; + v += 4; + } + v += jump; + } + v = off; + for (uint24_t dX = 0; dX < x2; dX++) { *v = 0; - v += 4; + v++; + } + v = off + (LCD_RESX * 6); + for (uint24_t dX = 0; dX < x2; dX++) { + *v = 0; + v++; + } + + uint24_t* negSign = ((LCD_RESX * 3) + 1) + (uint24_t*)off; //Fills three pixels + *negSign = (in < 0) ? 460551 : 0; //If Negative + uint24_t j = abs(in); + uint24_t powN = 1; + for (uint24_t k = 0; k < len; k += 4) { + uint16_t bitImage = num3x5[(j / powN) % base]; + uint8_t *fill = off + (LCD_RESX + 1) + len - k; + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 3; x++) { + *fill = bitImage & 1 ? 7 : 0; //White if true + bitImage >>= 1; + fill++; + } + fill += (LCD_RESX - 3); + } + powN *= base; + } + #else + uint8_t* off = lcd_Ram8 + (int24_t)((xC * LCD_RESY) + yC); //Something about casting off to uint8_t* adds 4 more bytes + uint8_t* v = off + 1; + len *= 4; + const uint24_t x2 = 5 + len; //Can optomize out "1 + " for a saving of 8 bytes + // Using const uint24_t jump segfaults for some reason + for (uint8_t dY = 1; dY < 6; dY++) { // Draws a black outline for each character + for (uint24_t dX = 0; dX < x2; dX += 4) { + *v = 0; + v += (4 * LCD_RESY); + } + v += 1 - ((x2 + 3) * LCD_RESY); + } + v = off; + for (uint24_t dX = 0; dX < x2; dX++) { // Top Line + *v = 0; + v += LCD_RESY; + } + v = off + 6; + for (uint24_t dX = 0; dX < x2; dX++) { // Bottom Line + *v = 0; + v += LCD_RESY; + } + + // Fills area around negative sign + v = off + 1 + (1 * LCD_RESY); + for (uint8_t dY = 0; dY < 5; dY++) { + for (uint24_t dX = 0; dX < 3; dX++) { + *v = 0; + v += LCD_RESY; + } + v -= (3 * LCD_RESY) - 1; + } + + if (in < 0) { //If Negative + uint8_t* negSign = ((LCD_RESY * 1) + 3) + off; //Fills three pixels + for (uint8_t n = 0; n < 3; n++) { + *negSign = 7; + negSign += LCD_RESY; + } } - v += jump; - } - v = off; - for (uint24_t dX = 0; dX < x2; dX++) { - *v = 0; - v++; - } - v = off + (LCD_RESX * 6); - for (uint24_t dX = 0; dX < x2; dX++) { - *v = 0; - v++; - } - uint24_t* negSign = ((LCD_RESX * 3) + 1) + (uint24_t*)off; //Fills three pixels - *negSign = (in < 0) ? 460551 : 0; //If Negative - uint24_t j = abs(in); - uint24_t powN = 1; - for (uint24_t k = 0; k < len; k += 4) { - uint16_t bitImage = num3x5[(j / powN) % base]; - uint8_t *fill = off + (LCD_RESX + 1) + len - k; - for (uint8_t y = 0; y < 5; y++) { - for (uint8_t x = 0; x < 3; x++) { - *fill = bitImage & 1 ? 7 : 0; //White if true - bitImage >>= 1; + uint24_t j = abs(in); + uint24_t powN = 1; + uint8_t* fill = off + (1 + ((len + 1) * LCD_RESY)); + for (uint24_t k = 0; k < len; k += 4) { + uint16_t bitImage = num3x5[(j / powN) % base]; + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 3; x++) { + *fill = bitImage & 1 ? 7 : 0; //White if true + bitImage >>= 1; + fill += LCD_RESY; + } + fill -= (3 * LCD_RESY); fill++; } - fill += (LCD_RESX - 3); + fill -= (4 * LCD_RESY); + fill -= 5; + powN *= base; } - powN *= base; - } + #endif } // Integer to print, length, base 2-16 void printUInt(int24_t in, uint8_t len, uint8_t base, uint24_t xC, uint24_t yC) { - uint8_t* off = lcd_Ram8 + (int24_t)(xC + (LCD_RESX * yC)); //Something about casting off to uint8_t* adds 4 more bytes - uint8_t* v = off + LCD_RESX; - len *= 4; - const uint24_t x2 = 1 + len; //Can optomize out "1 + " for a saving of 8 bytes - const uint24_t jump = (LCD_RESX - 3) - x2; - for (uint8_t dY = 1; dY < 6; dY++) { - for (uint24_t dX = 0; dX < x2; dX += 4) { + #ifndef SWAP_X_AND_Y_CORD + uint8_t* off = lcd_Ram8 + (int24_t)(xC + (LCD_RESX * yC)); //Something about casting off to uint8_t* adds 4 more bytes + uint8_t* v = off + LCD_RESX; + len *= 4; + const uint24_t x2 = 1 + len; //Can optomize out "1 + " for a saving of 8 bytes + const uint24_t jump = (LCD_RESX - 3) - x2; + for (uint8_t dY = 1; dY < 6; dY++) { + for (uint24_t dX = 0; dX < x2; dX += 4) { + *v = 0; + v += 4; + } + v += jump; + } + v = off; + for (uint24_t dX = 0; dX < x2; dX++) { *v = 0; - v += 4; + v++; } - v += jump; - } - v = off; - for (uint24_t dX = 0; dX < x2; dX++) { - *v = 0; - v++; - } - v = off + (LCD_RESX * 6); - for (uint24_t dX = 0; dX < x2; dX++) { - *v = 0; - v++; - } - uint24_t powN = 1; - for (uint24_t k = 0; k < len; k += 4) { - uint16_t bitImage = num3x5[(in / powN) % base]; - uint8_t* fill = off + (LCD_RESX - 3) + len - k; - for (uint8_t y = 0; y < 5; y++) { - for (uint8_t x = 0; x < 3; x++) { - *fill = bitImage & 1 ? 7 : 0; //White if true - bitImage >>= 1; + v = off + (LCD_RESX * 6); + for (uint24_t dX = 0; dX < x2; dX++) { + *v = 0; + v++; + } + uint24_t powN = 1; + for (uint24_t k = 0; k < len; k += 4) { + uint16_t bitImage = num3x5[(in / powN) % base]; + uint8_t* fill = off + (LCD_RESX - 3) + len - k; + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 3; x++) { + *fill = bitImage & 1 ? 7 : 0; //White if true + bitImage >>= 1; + fill++; + } + fill += (LCD_RESX - 3); + } + powN *= base; + } + #else + uint8_t* off = lcd_Ram8 + (int24_t)((xC * LCD_RESY) + yC); //Something about casting off to uint8_t* adds 4 more bytes + uint8_t* v = off + 1; + len *= 4; + const uint24_t x2 = 1 + len; //Can optomize out "1 + " for a saving of 8 bytes + // Using const uint24_t jump segfaults for some reason + for (uint8_t dY = 1; dY < 6; dY++) { // Draws a black outline for each character + for (uint24_t dX = 0; dX < x2; dX += 4) { + *v = 0; + v += (4 * LCD_RESY); + } + v += 1 - ((x2 + 3) * LCD_RESY); + } + v = off; + for (uint24_t dX = 0; dX < x2; dX++) { // Top Line + *v = 0; + v += LCD_RESY; + } + v = off + 6; + for (uint24_t dX = 0; dX < x2; dX++) { // Bottom Line + *v = 0; + v += LCD_RESY; + } + uint24_t powN = 1; + uint8_t* fill = off + (1 + ((len - 3) * LCD_RESY)); + for (uint24_t k = 0; k < len; k += 4) { + uint16_t bitImage = num3x5[(in / powN) % base]; + for (uint8_t y = 0; y < 5; y++) { + for (uint8_t x = 0; x < 3; x++) { + *fill = bitImage & 1 ? 7 : 0; //White if true + bitImage >>= 1; + fill += LCD_RESY; + } + fill -= (3 * LCD_RESY); fill++; } - fill += (LCD_RESX - 3); + fill -= (4 * LCD_RESY); + fill -= 5; + powN *= base; } - powN *= base; - } + #endif } //Primatives void fillRect(uint24_t x1, uint24_t y1, uint24_t x2, uint24_t y2) { //x start, y start, x length, y length - uint8_t* fill = lcd_Ram8 + (int24_t)(x1 + (y1 * LCD_RESX)); - for (uint24_t dY = 0; dY < y2; dY++) { - memset(fill,gColor,x2); - fill += LCD_RESX; - } + #ifndef SWAP_X_AND_Y_CORD + uint8_t* fill = lcd_Ram8 + (int24_t)(x1 + (y1 * LCD_RESX)); + for (uint24_t dY = 0; dY < y2; dY++) { + memset(fill,gColor,x2); + fill += LCD_RESX; + } + #else + uint8_t* fill = lcd_Ram8 + (int24_t)(y1 + (x1 * LCD_RESY)); + for (uint24_t dX = 0; dX < x2; dX++) { + memset(fill,gColor,y2); + fill += LCD_RESY; + } + #endif } void horiz(uint24_t x1, uint24_t y, uint24_t x2) { //x start, y postion, x length - uint8_t* fill = lcd_Ram8 + (int24_t)(x1 + (y * LCD_RESX)); - memset(fill,gColor,x2); + #ifndef SWAP_X_AND_Y_CORD + uint8_t* fill = lcd_Ram8 + (int24_t)(x1 + (y * LCD_RESX)); + memset(fill,gColor,x2); + #else + uint8_t* z = lcd_Ram8 + (int24_t)(y + ((x2 + x1) * LCD_RESY)); + for (uint8_t* fill = lcd_Ram8 + (x1 * LCD_RESY) + y; fill < z; fill += LCD_RESY) { + *fill = gColor; + } + #endif } void vert(uint24_t x, uint24_t y1, uint24_t y2) { //x postion, y start, y length - uint8_t* z = lcd_Ram8 + (int24_t)(x + ((y2 + y1) * LCD_RESX)); - for (uint8_t* fill = lcd_Ram8 + (y1 * LCD_RESX) + x; fill < z; fill += LCD_RESX) { - *fill = gColor; - } + #ifndef SWAP_X_AND_Y_CORD + uint8_t* z = lcd_Ram8 + (int24_t)(x + ((y2 + y1) * LCD_RESX)); + for (uint8_t* fill = lcd_Ram8 + (y1 * LCD_RESX) + x; fill < z; fill += LCD_RESX) { + *fill = gColor; + } + #else + uint8_t* fill = lcd_Ram8 + (int24_t)(y1 + (x * LCD_RESY)); + memset(fill,gColor,y2); + #endif } void fillScreen() { //Fills buffer 0 @@ -140,29 +264,57 @@ void fillScreen() { //Fills buffer 0 //Text Engine void text6x8(uint24_t xW, uint24_t yW, uint8_t lexicon) { //x position, y position, letter index - uint8_t* bitImage = (uint8_t*)char6x8 + (lexicon * 6); - uint8_t* fill = lcd_Ram8 + (int24_t)(yW * LCD_RESX + xW); - uint8_t b = 1; - for (uint8_t y = 0; y < 8; y++) { - for (uint8_t x = 0; x < 6; x++) { - *fill = *bitImage & b ? gColor : *fill; - bitImage++; - fill++; - } - bitImage -= 6; - fill += (LCD_RESX - 6); - b <<= 1; - } + #ifndef SWAP_X_AND_Y_CORD + uint8_t* bitImage = (uint8_t*)char6x8 + (lexicon * 6); + uint8_t* fill = lcd_Ram8 + (int24_t)(yW * LCD_RESX + xW); + uint8_t b = 0x1; + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 6; x++) { + *fill = *bitImage & b ? gColor : *fill; + bitImage++; + fill++; + } + bitImage -= 6; + fill += (LCD_RESX - 6); + b <<= 1; + } + #else + uint8_t* bitImage = (uint8_t*)char6x8 + (lexicon * 6); + uint8_t* fill = lcd_Ram8 + (int24_t)(xW * LCD_RESY + yW); + uint8_t b = 0x1; + for (uint8_t x = 0; x < 6; x++) { + for (uint8_t y = 0; y < 8; y++) { + *fill = *bitImage & b ? gColor : *fill; + fill++; + b <<= 1; + } + bitImage++; + b = 0x1; + fill += (LCD_RESY - 8); + } + #endif } void fillText(uint24_t x1, uint24_t y1, uint24_t x2, uint24_t y2) { //x start, y start, x length, y length //fillRect() that does not overwrite text - uint8_t* v = lcd_Ram8 + (int24_t)(x1 + (y1 * LCD_RESX)); - const uint24_t jump = LCD_RESX - x2; - for (uint24_t dY = 0; dY < y2; dY++) { - for (uint24_t dX = 0; dX < x2; dX++) { - *v = *v ? gColor : 0; - v++; - } - v += jump; - } + #ifndef SWAP_X_AND_Y_CORD + uint8_t* v = lcd_Ram8 + (int24_t)(x1 + (y1 * LCD_RESX)); + const uint24_t jump = LCD_RESX - x2; + for (uint24_t dY = 0; dY < y2; dY++) { + for (uint24_t dX = 0; dX < x2; dX++) { + *v = *v ? gColor : 0; + v++; + } + v += jump; + } + #else + uint8_t* v = lcd_Ram8 + (int24_t)(y1 + (x1 * LCD_RESY)); + const uint24_t jump = LCD_RESY - y2; + for (uint24_t dX = 0; dX < x2; dX++) { + for (uint24_t dY = 0; dY < y2; dY++) { + *v = *v ? gColor : 0; + v++; + } + v += jump; + } + #endif } \ No newline at end of file diff --git a/src/prime2D.h b/src/prime2D.h index a110334..a7f217d 100644 --- a/src/prime2D.h +++ b/src/prime2D.h @@ -31,8 +31,15 @@ void horiz(uint24_t x1, uint24_t y, uint24_t x2); //x start, y postion, x length void vert(uint24_t x, uint24_t y1, uint24_t y2); //x postion, y start, y length -#define plot(x,y) lcd_Ram8[(x) + ((y) * 320)] = gColor +#ifndef SWAP_X_AND_Y_CORD + #define plot(x,y) lcd_Ram8[(x) + ((y) * LCD_RESX)] = gColor +#else + #define plot(x,y) lcd_Ram8[(y) + ((x) * LCD_RESY)] = gColor +#endif + +// Avoid these functions #define plotFast(z) lcd_Ram8[z] = gColor +#define plotColorFast(z,c) lcd_Ram8[z] = (c) void fillScreen(); //Fills buffer 0 diff --git a/src/primeKey.c b/src/primeKey.c index d3b4ee0..54bbef5 100644 --- a/src/primeKey.c +++ b/src/primeKey.c @@ -34,14 +34,25 @@ void shiftScreen() { //Moves the frame base around uint8_t change = 0; if (DEBUG & keyReady) { keyReset(dEBUG); - if (kb_Data[4] & kb_8) { //Up - lcd_UpBase -= 2560; - change = 1; - } - if (kb_Data[4] & kb_2) { //Down - lcd_UpBase += 2560; - change = 1; - } + #ifndef SWAP_X_AND_Y_CORD + if (kb_Data[4] & kb_8) { //Up + lcd_UpBase -= (8 * LCD_RESX); + change = 1; + } + if (kb_Data[4] & kb_2) { //Down + lcd_UpBase += (8 * LCD_RESX); + change = 1; + } + #else + if (kb_Data[4] & kb_8) { //Up + lcd_UpBase -= (8 * LCD_RESY); + change = 1; + } + if (kb_Data[4] & kb_2) { //Down + lcd_UpBase += (8 * LCD_RESY); + change = 1; + } + #endif if (kb_Data[5] & kb_6) { //Right lcd_UpBase += 8; change = 1; diff --git a/src/subMenu.c b/src/subMenu.c index 4921f84..93ce480 100644 --- a/src/subMenu.c +++ b/src/subMenu.c @@ -149,7 +149,11 @@ void drawPattern() { for (int24_t i = 0; i < offLen; i += 2) { u = order[offPos + i] * 13; //Probably more memory effeicent than an algorithm v = order[offPos + i + 1] * 13; - uint8_t *fillR = lcd_Ram8 + ((44 * 320) + 266 + (320 * v) + u); + #ifndef SWAP_X_AND_Y_CORD + uint8_t *fillR = lcd_Ram8 + ((44 * LCD_RESX) + 266 + (LCD_RESX * v) + u); + #else + uint8_t *fillR = lcd_Ram8 + (44 + (266 * LCD_RESY) + v + (u * LCD_RESY)); + #endif if (*fillR == 0) { //Draws a 3 if 2 is already there fillRect(266 + u, 44 + v , 10, 10); gColor = 0;