/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

  1. /* Program Name: "SCR_File_lib.nxc" Version: 2.0
  2. ** This program was created by "muntoo" on June 13, 2010
  3. ** Created using BricxCC (by John Hansen) and written in NXC (by John Hansen)
  4. ** ( http://bricxcc.sourceforge.net/ )
  5. Description:
  6. */
  7. #ifndef __SCR_FILE_LIB_NXC__
  8. #define __SCR_FILE_LIB_NXC__
  9. /*
  10. How ScreenMem[800] is arranged:
  11. [arridx] = {x, y, x2, y2} // where {x,y} is where the line starts,
  12. // and {x2,y2} is where it ends
  13. [0] = {0, 63, 0, 56}
  14. [1] = {1, 63, 1, 56}
  15. [2] = {2, 63, 2, 56}
  16. [100] = {0, 55, 0, 48}
  17. [101] = {1, 55, 1, 48}
  18. [102] = {2, 55, 2, 48}
  19. [700] = {0, 7, 0, 0 }
  20. [701] = {1, 7, 1, 0 }
  21. [702] = {2, 7, 2, 0 }
  22. [799] = {99, 7, 99, 0 }
  23. The first bit ((ScreenMem[arridx]>>7)&0x01) is the topmost bit on the y axis,
  24. and the last bit ((ScreenMem[arridx]>>7)&0x01) is the bottom bit on y axis
  25. If the bit is equal to true (0x01), that means there is a pixel there (black)
  26. If the bit is false (0x00), that means that it is clear (white/green,
  27. whichever one you think the LCD Display's color is)
  28. (X axis)
  29. __________________________________________________
  30. |[0] [99]|
  31. | |
  32. | |
  33. | |
  34. | | (Y axis)
  35. | |
  36. | |
  37. |[700] [799]|
  38. __________________________________________________
  39. To convert {x, y} to ScreenMem[800]:
  40. #define XY_To_ScreenMem(ScreenMem[], x, y, value) ScreenMem[x+((7-(y/8))*100)]=value<<(y%8)
  41. */
  42. void SaveSCRMEM(string filename, byte &ScreenMem[])
  43. {
  44. byte handle;
  45. unsigned long fsize = 800;
  46. unsigned long cnt;
  47. if(CreateFile(filename, fsize, handle) != LDR_SUCCESS)
  48. return;
  49. WriteBytes(handle, ScreenMem, cnt);
  50. CloseFile(handle);
  51. }
  52. void OpenSCRMEM(string filename, byte &ScreenMem[])
  53. {
  54. byte handle;
  55. unsigned long fsize;
  56. if(OpenFileRead(filename, fsize, handle) != LDR_SUCCESS)
  57. return;
  58. ReadBytes(handle, fsize, ScreenMem);
  59. CloseFile(handle);
  60. }
  61. void GetScreenMem(byte &ScreenMem[])
  62. {
  63. byte ScreenBuf[];
  64. int linepos = 0;
  65. int x = 0;
  66. ArrayInit(ScreenMem, 0, 800);
  67. ArrayInit(ScreenBuf, 0, 100);
  68. for(linepos = 0; linepos < 8; linepos++)
  69. {
  70. GetDisplayNormal(0, linepos, 100, ScreenBuf);
  71. for(x = 0; x < 100; x++)
  72. {
  73. ScreenMem[x + (linepos * 100)] = ScreenBuf[x];
  74. }
  75. }
  76. }
  77. #define DisplayScreenMem(byte &ScreenMem[]) SetDisplayNormal(0, 0, 800, ScreenMem);
  78. /*
  79. #define __setDisplayNormal(_x, _line, _cnt, _data) \
  80. compif EQ, isconst(_line+_x), TRUE \
  81. compchk LT, _line, 0x08 \
  82. compchk GTEQ, _line, 0x00 \
  83. SetDisplayModuleBytes(DisplayOffsetNormal(_line,_x), _cnt, _data) \
  84. compelse \
  85. acquire __displayModuleOffsetMutex \
  86. mul __displayModuleOffset, _line, 100 \
  87. add __displayModuleOffset, __displayModuleOffset, _x \
  88. add __displayModuleOffset, __displayModuleOffset, 119 \
  89. SetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
  90. release __displayModuleOffsetMutex \
  91. compend
  92. */
  93. inline void ClearScreenMem(byte &ScreenMem[], byte val = 0x00)
  94. {
  95. unsigned int ScreenMem_arrlen = ArrayLen(ScreenMem);
  96. ArrayInit(ScreenMem, val, ScreenMem_arrlen);
  97. }
  98. #if __FIRMWARE_VERSION >= 128
  99. #ifdef __ENHANCED_FIRMWARE
  100. #define DrawScreenMem(ScreenMem, FunctionName, args) { \
  101. unsigned long dispAddr = DisplayDisplay(); \
  102. SetDisplayDisplay(addressOf(ScreenMem)); \
  103. char result = FunctionName(args); \
  104. SetDisplayDisplay(dispAddr); \
  105. }
  106. #endif
  107. #endif
  108. #if __FIRMWARE_VERSION >= 128
  109. #ifdef __ENHANCED_FIRMWARE
  110. inline char DrawPointScreenMem(byte &ScreenMem[], int x, int y, unsigned long options = DRAW_OPT_NORMAL)
  111. {
  112. unsigned long dispAddr = DisplayDisplay();
  113. SetDisplayDisplay(addressOf(ScreenMem));
  114. char result = PointOut(x, y, options);
  115. SetDisplayDisplay(dispAddr);
  116. return(result);
  117. }
  118. #endif
  119. #endif
  120. #if __FIRMWARE_VERSION >= 128
  121. #ifdef __ENHANCED_FIRMWARE
  122. inline char DrawLineScreenMem(byte &ScreenMem[], int x1, int y1, int x2, int y2, unsigned long options = DRAW_OPT_NORMAL)
  123. {
  124. unsigned long dispAddr = DisplayDisplay();
  125. SetDisplayDisplay(addressOf(ScreenMem));
  126. char result = LineOut(x1, y1, x2, y2, options);
  127. SetDisplayDisplay(dispAddr);
  128. return(result);
  129. }
  130. #endif
  131. #endif
  132. #if __FIRMWARE_VERSION >= 128
  133. #ifdef __ENHANCED_FIRMWARE
  134. inline char DrawRectScreenMem(byte &ScreenMem[], int x, int y, int width, int height, unsigned long options = DRAW_OPT_NORMAL)
  135. {
  136. unsigned long dispAddr = DisplayDisplay();
  137. SetDisplayDisplay(addressOf(ScreenMem));
  138. char result = RectOut(x, y, width, height, options);
  139. SetDisplayDisplay(dispAddr);
  140. return(result);
  141. }
  142. #endif
  143. #endif
  144. #if __FIRMWARE_VERSION >= 128
  145. #ifdef __ENHANCED_FIRMWARE
  146. inline char DrawCircleScreenMem(byte &ScreenMem[], int x, int y, byte radius, unsigned long options = DRAW_OPT_NORMAL)
  147. {
  148. unsigned long dispAddr = DisplayDisplay();
  149. SetDisplayDisplay(addressOf(ScreenMem));
  150. char result = CircleOut(x, y, radius, options);
  151. SetDisplayDisplay(dispAddr);
  152. return(result);
  153. }
  154. #endif
  155. #endif
  156. /*
  157. #if __FIRMWARE_VERSION >= 128
  158. #ifdef __ENHANCED_FIRMWARE
  159. inline char DrawGraphicScreenMem(byte &ScreenMem[], int x, int y, string filename, unsigned long options = DRAW_OPT_NORMAL)
  160. {
  161. unsigned long dispAddr = DisplayDisplay();
  162. SetDisplayDisplay(addressOf(ScreenMem));
  163. char result = GraphicOut(x, y, filename, options);
  164. SetDisplayDisplay(dispAddr);
  165. return(result);
  166. }
  167. #endif
  168. #endif
  169. #if __FIRMWARE_VERSION >= 128
  170. #ifdef __ENHANCED_FIRMWARE
  171. inline char DrawGraphicExScreenMem(byte &ScreenMem[], int x, int y, string filename, byte vars[], unsigned long options = DRAW_OPT_NORMAL)
  172. {
  173. unsigned long dispAddr = DisplayDisplay();
  174. SetDisplayDisplay(addressOf(ScreenMem));
  175. char result = GraphicOutEx(x, y, filename, vars, options);
  176. SetDisplayDisplay(dispAddr);
  177. return(result);
  178. }
  179. #endif
  180. #endif
  181. #if __FIRMWARE_VERSION >= 128
  182. #ifdef __ENHANCED_FIRMWARE
  183. inline char DrawGraphicArrayScreenMem(byte &ScreenMem[], int x, int y, byte data[], unsigned long options = DRAW_OPT_NORMAL)
  184. {
  185. unsigned long dispAddr = DisplayDisplay();
  186. SetDisplayDisplay(addressOf(ScreenMem));
  187. char result = GraphicArrayOut(x, y, data, options);
  188. SetDisplayDisplay(dispAddr);
  189. return(result);
  190. }
  191. #endif
  192. #endif
  193. #if __FIRMWARE_VERSION >= 128
  194. #ifdef __ENHANCED_FIRMWARE
  195. inline char DrawGraphicArrayExScreenMem(byte &ScreenMem[], int x, int y, byte data[], byte vars[], unsigned long options = DRAW_OPT_NORMAL)
  196. {
  197. unsigned long dispAddr = DisplayDisplay();
  198. SetDisplayDisplay(addressOf(ScreenMem));
  199. char result = GraphicArrayOutEx(x, y, data, vars, options);
  200. SetDisplayDisplay(dispAddr);
  201. return(result);
  202. }
  203. #endif
  204. #endif
  205. */
  206. #if __FIRMWARE_VERSION >= 128
  207. #ifdef __ENHANCED_FIRMWARE
  208. inline char DrawEllipseScreenMem(byte &ScreenMem[], int x, int y, byte radiusX, byte radiusY, unsigned long options = DRAW_OPT_NORMAL)
  209. {
  210. unsigned long dispAddr = DisplayDisplay();
  211. SetDisplayDisplay(addressOf(ScreenMem));
  212. char result = EllipseOut(x, y, radiusX, radiusY, options);
  213. SetDisplayDisplay(dispAddr);
  214. return(result);
  215. }
  216. #endif
  217. #endif
  218. /*
  219. #if __FIRMWARE_VERSION >= 128
  220. #ifdef __ENHANCED_FIRMWARE
  221. inline char DrawFontTextScreenMem(byte &ScreenMem[], int x, int y, string filename, string str, unsigned long options = DRAW_OPT_NORMAL)
  222. {
  223. unsigned long dispAddr = DisplayDisplay();
  224. SetDisplayDisplay(addressOf(ScreenMem));
  225. char result = FontTextOut(x, y, filename, str, options);
  226. SetDisplayDisplay(dispAddr);
  227. return(result);
  228. }
  229. #endif
  230. #endif
  231. */
  232. #if __FIRMWARE_VERSION >= 128
  233. #ifdef __ENHANCED_FIRMWARE
  234. inline char DrawPolyScreenMem(byte &ScreenMem[], LocationType points[], unsigned long options = DRAW_OPT_NORMAL)
  235. {
  236. unsigned long dispAddr = DisplayDisplay();
  237. SetDisplayDisplay(addressOf(ScreenMem));
  238. char result = PolyOut(points, options);
  239. SetDisplayDisplay(dispAddr);
  240. return(result);
  241. }
  242. #endif
  243. #endif
  244. void SaveSURMEM(string filename, byte &SurfaceMem[], SizeType Size)
  245. {
  246. byte handle;
  247. unsigned long fsize = ArrayLen(SurfaceMem) + 8;
  248. unsigned long cnt;
  249. byte writebuf[];
  250. ArrayInit(writebuf, 0x00, fsize);
  251. for(unsigned long i = 0; i < 4; ++i)
  252. {
  253. writebuf[i] = (Size.Width >> ((3 - i) * 8)) & 0xFF;
  254. }
  255. for(unsigned long i = 0; i < 4; ++i)
  256. {
  257. writebuf[i + 4] = (Size.Height >> ((3 - i) * 8)) & 0xFF;
  258. }
  259. for(unsigned long i = 8; i < fsize; ++i)
  260. {
  261. writebuf[i] = SurfaceMem[i - 8];
  262. }
  263. CreateFile(filename, fsize, handle);
  264. WriteBytes(handle, writebuf, cnt);
  265. CloseFile(handle);
  266. }
  267. void OpenSURMEM(string filename, byte &SurfaceMem[], SizeType &Size)
  268. {
  269. byte handle;
  270. unsigned long fsize;
  271. unsigned long len;
  272. byte readbuf[];
  273. OpenFileRead(filename, fsize, handle);
  274. ArrayInit(readbuf, 0x00, fsize);
  275. len = fsize;
  276. ReadBytes(handle, len, readbuf);
  277. CloseFile(handle);
  278. if(len < 8)
  279. return;
  280. Size.Width = 0;
  281. for(unsigned long i = 0; i < 4; ++i)
  282. {
  283. Size.Width |= readbuf[i] << ((3 - i) * 8);
  284. }
  285. Size.Height = 0;
  286. for(unsigned long i = 0; i < 4; ++i)
  287. {
  288. Size.Height |= readbuf[i + 4] << ((3 - i) * 8);
  289. }
  290. len -= 8;
  291. ArrayInit(SurfaceMem, 0x00, len);
  292. ArraySubset(SurfaceMem, readbuf, 8, len);
  293. }
  294. void GetSurfaceMem(byte &SurfaceMem[], LocationType Location, SizeType Size)
  295. {
  296. byte ScreenBuf[];
  297. int linepos = 0;
  298. int x = 0;
  299. ArrayInit(SurfaceMem, 0, 800);
  300. ArrayInit(ScreenBuf, 0, 100);
  301. if ((Location.X + Size.Width) > 99)
  302. return;
  303. if ((Location.Y + Size.Height) > 63)
  304. return;
  305. Size.Width++;
  306. Size.Height++;
  307. for(linepos = (7 - (Location.Y + Size.Height));
  308. linepos < (8 - Location.Y);
  309. ++linepos)
  310. {
  311. GetDisplayNormal(Location.X, linepos, Size.Width, ScreenBuf);
  312. for(x = 0; x < Size.Width; ++x)
  313. {
  314. SurfaceMem[x + (linepos * Size.Width)] = ScreenBuf[x];
  315. }
  316. }
  317. /*
  318. Size.Width--;
  319. Size.Height--;
  320. */
  321. }
  322. void DisplaySurfaceMem(byte &SurfaceMem[], LocationType Location, SizeType Size)
  323. {
  324. byte ScreenBuf[];
  325. int linepos = 0;
  326. int x = 0;
  327. ArrayInit(ScreenBuf, 0, 100);
  328. if ((Location.X + Size.Width) > 99)
  329. return;
  330. if ((Location.Y + Size.Height) > 63)
  331. return;
  332. Size.Width++;
  333. Size.Height++;
  334. for(linepos = (7 - (Location.Y + Size.Height));
  335. linepos < (8 - Location.Y);
  336. --linepos)
  337. {
  338. for(x = 0; x < Size.Width; ++x)
  339. {
  340. ScreenBuf[x] = SurfaceMem[x + (linepos * Size.Width)];
  341. }
  342. SetDisplayNormal(Location.X, linepos, Size.Width, ScreenBuf);
  343. }
  344. /*
  345. Size.Width--;
  346. Size.Height--;
  347. */
  348. }
  349. #endif