/SCR_File_lib.nxc
https://bitbucket.org/muntoo/scr_file_lib · Unknown · 470 lines · 349 code · 121 blank · 0 comment · 0 complexity · 5f6986d6813a23e9c9dda1782dc8e290 MD5 · raw file
- /* Program Name: "SCR_File_lib.nxc" Version: 2.0
- ** This program was created by "muntoo" on June 13, 2010
- ** Created using BricxCC (by John Hansen) and written in NXC (by John Hansen)
- ** ( http://bricxcc.sourceforge.net/ )
- Description:
- */
-
-
- #ifndef __SCR_FILE_LIB_NXC__
- #define __SCR_FILE_LIB_NXC__
- /*
- How ScreenMem[800] is arranged:
- [arridx] = {x, y, x2, y2} // where {x,y} is where the line starts,
- // and {x2,y2} is where it ends
- [0] = {0, 63, 0, 56}
- [1] = {1, 63, 1, 56}
- [2] = {2, 63, 2, 56}
- [100] = {0, 55, 0, 48}
- [101] = {1, 55, 1, 48}
- [102] = {2, 55, 2, 48}
- [700] = {0, 7, 0, 0 }
- [701] = {1, 7, 1, 0 }
- [702] = {2, 7, 2, 0 }
- [799] = {99, 7, 99, 0 }
- The first bit ((ScreenMem[arridx]>>7)&0x01) is the topmost bit on the y axis,
- and the last bit ((ScreenMem[arridx]>>7)&0x01) is the bottom bit on y axis
- If the bit is equal to true (0x01), that means there is a pixel there (black)
- If the bit is false (0x00), that means that it is clear (white/green,
- whichever one you think the LCD Display's color is)
- (X axis)
- __________________________________________________
- |[0] [99]|
- | |
- | |
- | |
- | | (Y axis)
- | |
- | |
- |[700] [799]|
- __________________________________________________
- To convert {x, y} to ScreenMem[800]:
- #define XY_To_ScreenMem(ScreenMem[], x, y, value) ScreenMem[x+((7-(y/8))*100)]=value<<(y%8)
- */
- void SaveSCRMEM(string filename, byte &ScreenMem[])
- {
- byte handle;
- unsigned long fsize = 800;
- unsigned long cnt;
- if(CreateFile(filename, fsize, handle) != LDR_SUCCESS)
- return;
- WriteBytes(handle, ScreenMem, cnt);
- CloseFile(handle);
- }
- void OpenSCRMEM(string filename, byte &ScreenMem[])
- {
- byte handle;
- unsigned long fsize;
- if(OpenFileRead(filename, fsize, handle) != LDR_SUCCESS)
- return;
- ReadBytes(handle, fsize, ScreenMem);
- CloseFile(handle);
- }
- void GetScreenMem(byte &ScreenMem[])
- {
- byte ScreenBuf[];
- int linepos = 0;
- int x = 0;
- ArrayInit(ScreenMem, 0, 800);
- ArrayInit(ScreenBuf, 0, 100);
- for(linepos = 0; linepos < 8; linepos++)
- {
- GetDisplayNormal(0, linepos, 100, ScreenBuf);
- for(x = 0; x < 100; x++)
- {
- ScreenMem[x + (linepos * 100)] = ScreenBuf[x];
- }
- }
- }
- #define DisplayScreenMem(byte &ScreenMem[]) SetDisplayNormal(0, 0, 800, ScreenMem);
-
- /*
- #define __setDisplayNormal(_x, _line, _cnt, _data) \
- compif EQ, isconst(_line+_x), TRUE \
- compchk LT, _line, 0x08 \
- compchk GTEQ, _line, 0x00 \
- SetDisplayModuleBytes(DisplayOffsetNormal(_line,_x), _cnt, _data) \
- compelse \
- acquire __displayModuleOffsetMutex \
- mul __displayModuleOffset, _line, 100 \
- add __displayModuleOffset, __displayModuleOffset, _x \
- add __displayModuleOffset, __displayModuleOffset, 119 \
- SetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
- release __displayModuleOffsetMutex \
- compend
- */
- inline void ClearScreenMem(byte &ScreenMem[], byte val = 0x00)
- {
- unsigned int ScreenMem_arrlen = ArrayLen(ScreenMem);
- ArrayInit(ScreenMem, val, ScreenMem_arrlen);
- }
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- #define DrawScreenMem(ScreenMem, FunctionName, args) { \
- unsigned long dispAddr = DisplayDisplay(); \
- SetDisplayDisplay(addressOf(ScreenMem)); \
- char result = FunctionName(args); \
- SetDisplayDisplay(dispAddr); \
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawPointScreenMem(byte &ScreenMem[], int x, int y, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = PointOut(x, y, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawLineScreenMem(byte &ScreenMem[], int x1, int y1, int x2, int y2, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = LineOut(x1, y1, x2, y2, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawRectScreenMem(byte &ScreenMem[], int x, int y, int width, int height, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = RectOut(x, y, width, height, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawCircleScreenMem(byte &ScreenMem[], int x, int y, byte radius, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = CircleOut(x, y, radius, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- /*
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawGraphicScreenMem(byte &ScreenMem[], int x, int y, string filename, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = GraphicOut(x, y, filename, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawGraphicExScreenMem(byte &ScreenMem[], int x, int y, string filename, byte vars[], unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = GraphicOutEx(x, y, filename, vars, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawGraphicArrayScreenMem(byte &ScreenMem[], int x, int y, byte data[], unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = GraphicArrayOut(x, y, data, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawGraphicArrayExScreenMem(byte &ScreenMem[], int x, int y, byte data[], byte vars[], unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = GraphicArrayOutEx(x, y, data, vars, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- */
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawEllipseScreenMem(byte &ScreenMem[], int x, int y, byte radiusX, byte radiusY, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = EllipseOut(x, y, radiusX, radiusY, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- /*
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawFontTextScreenMem(byte &ScreenMem[], int x, int y, string filename, string str, unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = FontTextOut(x, y, filename, str, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- */
- #if __FIRMWARE_VERSION >= 128
- #ifdef __ENHANCED_FIRMWARE
- inline char DrawPolyScreenMem(byte &ScreenMem[], LocationType points[], unsigned long options = DRAW_OPT_NORMAL)
- {
- unsigned long dispAddr = DisplayDisplay();
- SetDisplayDisplay(addressOf(ScreenMem));
- char result = PolyOut(points, options);
- SetDisplayDisplay(dispAddr);
- return(result);
- }
- #endif
- #endif
- void SaveSURMEM(string filename, byte &SurfaceMem[], SizeType Size)
- {
- byte handle;
- unsigned long fsize = ArrayLen(SurfaceMem) + 8;
- unsigned long cnt;
- byte writebuf[];
- ArrayInit(writebuf, 0x00, fsize);
- for(unsigned long i = 0; i < 4; ++i)
- {
- writebuf[i] = (Size.Width >> ((3 - i) * 8)) & 0xFF;
- }
- for(unsigned long i = 0; i < 4; ++i)
- {
- writebuf[i + 4] = (Size.Height >> ((3 - i) * 8)) & 0xFF;
- }
- for(unsigned long i = 8; i < fsize; ++i)
- {
- writebuf[i] = SurfaceMem[i - 8];
- }
- CreateFile(filename, fsize, handle);
- WriteBytes(handle, writebuf, cnt);
- CloseFile(handle);
- }
- void OpenSURMEM(string filename, byte &SurfaceMem[], SizeType &Size)
- {
- byte handle;
- unsigned long fsize;
- unsigned long len;
- byte readbuf[];
- OpenFileRead(filename, fsize, handle);
- ArrayInit(readbuf, 0x00, fsize);
- len = fsize;
- ReadBytes(handle, len, readbuf);
- CloseFile(handle);
- if(len < 8)
- return;
- Size.Width = 0;
- for(unsigned long i = 0; i < 4; ++i)
- {
- Size.Width |= readbuf[i] << ((3 - i) * 8);
- }
- Size.Height = 0;
- for(unsigned long i = 0; i < 4; ++i)
- {
- Size.Height |= readbuf[i + 4] << ((3 - i) * 8);
- }
- len -= 8;
- ArrayInit(SurfaceMem, 0x00, len);
- ArraySubset(SurfaceMem, readbuf, 8, len);
- }
- void GetSurfaceMem(byte &SurfaceMem[], LocationType Location, SizeType Size)
- {
- byte ScreenBuf[];
- int linepos = 0;
- int x = 0;
- ArrayInit(SurfaceMem, 0, 800);
- ArrayInit(ScreenBuf, 0, 100);
- if ((Location.X + Size.Width) > 99)
- return;
- if ((Location.Y + Size.Height) > 63)
- return;
- Size.Width++;
- Size.Height++;
- for(linepos = (7 - (Location.Y + Size.Height));
- linepos < (8 - Location.Y);
- ++linepos)
- {
- GetDisplayNormal(Location.X, linepos, Size.Width, ScreenBuf);
-
- for(x = 0; x < Size.Width; ++x)
- {
- SurfaceMem[x + (linepos * Size.Width)] = ScreenBuf[x];
- }
- }
- /*
- Size.Width--;
- Size.Height--;
- */
- }
- void DisplaySurfaceMem(byte &SurfaceMem[], LocationType Location, SizeType Size)
- {
- byte ScreenBuf[];
- int linepos = 0;
- int x = 0;
- ArrayInit(ScreenBuf, 0, 100);
- if ((Location.X + Size.Width) > 99)
- return;
- if ((Location.Y + Size.Height) > 63)
- return;
- Size.Width++;
- Size.Height++;
- for(linepos = (7 - (Location.Y + Size.Height));
- linepos < (8 - Location.Y);
- --linepos)
- {
- for(x = 0; x < Size.Width; ++x)
- {
- ScreenBuf[x] = SurfaceMem[x + (linepos * Size.Width)];
- }
- SetDisplayNormal(Location.X, linepos, Size.Width, ScreenBuf);
- }
- /*
- Size.Width--;
- Size.Height--;
- */
- }
-
-
- #endif