PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  6Description:
  7
  8*/
  9
 10
 11#ifndef __SCR_FILE_LIB_NXC__
 12#define __SCR_FILE_LIB_NXC__
 13
 14
 15/*
 16	How ScreenMem[800] is arranged:
 17
 18	[arridx] = {x,  y,  x2, y2}   // where {x,y} is where the line starts,
 19		// and {x2,y2} is where it ends
 20
 21	[0]      = {0,  63, 0,  56}
 22	[1]      = {1,  63, 1,  56}
 23	[2]      = {2,  63, 2,  56}
 24	[100]    = {0,  55, 0,  48}
 25	[101]    = {1,  55, 1,  48}
 26	[102]    = {2,  55, 2,  48}
 27	[700]    = {0,  7,  0,  0 }
 28	[701]    = {1,  7,  1,  0 }
 29	[702]    = {2,  7,  2,  0 }
 30	[799]    = {99, 7,  99, 0 }
 31
 32	The first bit ((ScreenMem[arridx]>>7)&0x01) is the topmost bit on the y axis,
 33	and the last bit ((ScreenMem[arridx]>>7)&0x01) is the bottom bit on y axis
 34
 35	If the bit is equal to true (0x01), that means there is a pixel there (black)
 36	If the bit is false (0x00), that means that it is clear (white/green,
 37	whichever one you think the LCD Display's color is)
 38
 39
 40	 (X axis)
 41	__________________________________________________
 42	|[0]                                         [99]|
 43	|                                                |
 44	|                                                |
 45	|                                                |
 46	|                                                |    (Y axis)
 47	|                                                |
 48	|                                                |
 49	|[700]                                      [799]|
 50	__________________________________________________
 51
 52
 53	To convert {x, y} to ScreenMem[800]:
 54	#define XY_To_ScreenMem(ScreenMem[], x, y, value) ScreenMem[x+((7-(y/8))*100)]=value<<(y%8)
 55*/
 56
 57
 58void SaveSCRMEM(string filename, byte &ScreenMem[])
 59{
 60	byte handle;
 61	unsigned long fsize = 800;
 62	unsigned long cnt;
 63
 64	if(CreateFile(filename, fsize, handle) != LDR_SUCCESS)
 65		return;
 66
 67	WriteBytes(handle, ScreenMem, cnt);
 68
 69	CloseFile(handle);
 70}
 71
 72
 73void OpenSCRMEM(string filename, byte &ScreenMem[])
 74{
 75	byte handle;
 76	unsigned long fsize;
 77
 78	if(OpenFileRead(filename, fsize, handle) != LDR_SUCCESS)
 79		return;
 80
 81	ReadBytes(handle, fsize, ScreenMem);
 82
 83	CloseFile(handle);
 84}
 85
 86
 87void GetScreenMem(byte &ScreenMem[])
 88{
 89	byte ScreenBuf[];
 90	int linepos = 0;
 91	int x = 0;
 92
 93	ArrayInit(ScreenMem, 0, 800);
 94	ArrayInit(ScreenBuf, 0, 100);
 95
 96	for(linepos = 0; linepos < 8; linepos++)
 97	{
 98		GetDisplayNormal(0, linepos, 100, ScreenBuf);
 99		for(x = 0; x < 100; x++)
100		{
101			ScreenMem[x + (linepos * 100)] = ScreenBuf[x];
102		}
103	}
104}
105
106
107#define DisplayScreenMem(byte &ScreenMem[]) SetDisplayNormal(0, 0, 800, ScreenMem);
108
109/*
110#define __setDisplayNormal(_x, _line, _cnt, _data) \
111	compif EQ, isconst(_line+_x), TRUE \
112		compchk LT, _line, 0x08 \
113		compchk GTEQ, _line, 0x00 \
114		SetDisplayModuleBytes(DisplayOffsetNormal(_line,_x), _cnt, _data) \
115	compelse \
116		acquire __displayModuleOffsetMutex \
117		mul __displayModuleOffset, _line, 100 \
118		add __displayModuleOffset, __displayModuleOffset, _x \
119		add __displayModuleOffset, __displayModuleOffset, 119 \
120		SetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
121		release __displayModuleOffsetMutex \
122	compend
123*/
124
125
126inline void ClearScreenMem(byte &ScreenMem[], byte val = 0x00)
127{
128	unsigned int ScreenMem_arrlen = ArrayLen(ScreenMem);
129	ArrayInit(ScreenMem, val, ScreenMem_arrlen);
130}
131
132
133#if __FIRMWARE_VERSION >= 128
134#ifdef __ENHANCED_FIRMWARE
135
136#define DrawScreenMem(ScreenMem, FunctionName, args) { \
137	unsigned long dispAddr = DisplayDisplay(); \
138	SetDisplayDisplay(addressOf(ScreenMem)); \
139	char result = FunctionName(args); \
140	SetDisplayDisplay(dispAddr); \
141}
142
143#endif
144#endif
145
146
147#if __FIRMWARE_VERSION >= 128
148#ifdef __ENHANCED_FIRMWARE
149inline char DrawPointScreenMem(byte &ScreenMem[], int x, int y, unsigned long options = DRAW_OPT_NORMAL)
150{
151	unsigned long dispAddr = DisplayDisplay();
152	SetDisplayDisplay(addressOf(ScreenMem));
153
154	char result = PointOut(x, y, options);
155
156	SetDisplayDisplay(dispAddr);
157	return(result);
158}
159#endif
160#endif
161
162
163#if __FIRMWARE_VERSION >= 128
164#ifdef __ENHANCED_FIRMWARE
165inline char DrawLineScreenMem(byte &ScreenMem[], int x1, int y1, int x2, int y2, unsigned long options = DRAW_OPT_NORMAL)
166{
167	unsigned long dispAddr = DisplayDisplay();
168	SetDisplayDisplay(addressOf(ScreenMem));
169
170	char result = LineOut(x1, y1, x2, y2, options);
171
172	SetDisplayDisplay(dispAddr);
173	return(result);
174}
175#endif
176#endif
177
178
179#if __FIRMWARE_VERSION >= 128
180#ifdef __ENHANCED_FIRMWARE
181inline char DrawRectScreenMem(byte &ScreenMem[], int x, int y, int width, int height, unsigned long options = DRAW_OPT_NORMAL)
182{
183	unsigned long dispAddr = DisplayDisplay();
184	SetDisplayDisplay(addressOf(ScreenMem));
185
186	char result = RectOut(x, y, width, height, options);
187
188	SetDisplayDisplay(dispAddr);
189	return(result);
190}
191#endif
192#endif
193
194
195#if __FIRMWARE_VERSION >= 128
196#ifdef __ENHANCED_FIRMWARE
197inline char DrawCircleScreenMem(byte &ScreenMem[], int x, int y, byte radius, unsigned long options = DRAW_OPT_NORMAL)
198{
199	unsigned long dispAddr = DisplayDisplay();
200	SetDisplayDisplay(addressOf(ScreenMem));
201
202	char result = CircleOut(x, y, radius, options);
203
204	SetDisplayDisplay(dispAddr);
205	return(result);
206}
207#endif
208#endif
209
210
211/*
212#if __FIRMWARE_VERSION >= 128
213#ifdef __ENHANCED_FIRMWARE
214inline char DrawGraphicScreenMem(byte &ScreenMem[], int x, int y, string filename, unsigned long options = DRAW_OPT_NORMAL)
215{
216	unsigned long dispAddr = DisplayDisplay();
217	SetDisplayDisplay(addressOf(ScreenMem));
218
219	char result = GraphicOut(x, y, filename, options);
220
221	SetDisplayDisplay(dispAddr);
222	return(result);
223}
224#endif
225#endif
226
227
228#if __FIRMWARE_VERSION >= 128
229#ifdef __ENHANCED_FIRMWARE
230inline char DrawGraphicExScreenMem(byte &ScreenMem[], int x, int y, string filename, byte vars[], unsigned long options = DRAW_OPT_NORMAL)
231{
232	unsigned long dispAddr = DisplayDisplay();
233	SetDisplayDisplay(addressOf(ScreenMem));
234
235	char result = GraphicOutEx(x, y, filename, vars, options);
236
237	SetDisplayDisplay(dispAddr);
238	return(result);
239}
240#endif
241#endif
242
243
244#if __FIRMWARE_VERSION >= 128
245#ifdef __ENHANCED_FIRMWARE
246inline char DrawGraphicArrayScreenMem(byte &ScreenMem[], int x, int y, byte data[], unsigned long options = DRAW_OPT_NORMAL)
247{
248	unsigned long dispAddr = DisplayDisplay();
249	SetDisplayDisplay(addressOf(ScreenMem));
250
251	char result = GraphicArrayOut(x, y, data, options);
252
253	SetDisplayDisplay(dispAddr);
254	return(result);
255}
256#endif
257#endif
258
259
260#if __FIRMWARE_VERSION >= 128
261#ifdef __ENHANCED_FIRMWARE
262inline char DrawGraphicArrayExScreenMem(byte &ScreenMem[], int x, int y, byte data[], byte vars[], unsigned long options = DRAW_OPT_NORMAL)
263{
264	unsigned long dispAddr = DisplayDisplay();
265	SetDisplayDisplay(addressOf(ScreenMem));
266
267	char result = GraphicArrayOutEx(x, y, data, vars, options);
268
269	SetDisplayDisplay(dispAddr);
270	return(result);
271}
272#endif
273#endif
274*/
275
276
277#if __FIRMWARE_VERSION >= 128
278#ifdef __ENHANCED_FIRMWARE
279inline char DrawEllipseScreenMem(byte &ScreenMem[], int x, int y, byte radiusX, byte radiusY, unsigned long options = DRAW_OPT_NORMAL)
280{
281	unsigned long dispAddr = DisplayDisplay();
282	SetDisplayDisplay(addressOf(ScreenMem));
283
284	char result = EllipseOut(x, y, radiusX, radiusY, options);
285
286	SetDisplayDisplay(dispAddr);
287	return(result);
288}
289#endif
290#endif
291
292
293/*
294#if __FIRMWARE_VERSION >= 128
295#ifdef __ENHANCED_FIRMWARE
296inline char DrawFontTextScreenMem(byte &ScreenMem[], int x, int y, string filename, string str, unsigned long options = DRAW_OPT_NORMAL)
297{
298	unsigned long dispAddr = DisplayDisplay();
299	SetDisplayDisplay(addressOf(ScreenMem));
300
301	char result = FontTextOut(x, y, filename, str, options);
302
303	SetDisplayDisplay(dispAddr);
304	return(result);
305}
306#endif
307#endif
308*/
309
310
311#if __FIRMWARE_VERSION >= 128
312#ifdef __ENHANCED_FIRMWARE
313inline char DrawPolyScreenMem(byte &ScreenMem[], LocationType points[], unsigned long options = DRAW_OPT_NORMAL)
314{
315	unsigned long dispAddr = DisplayDisplay();
316	SetDisplayDisplay(addressOf(ScreenMem));
317
318	char result = PolyOut(points, options);
319
320	SetDisplayDisplay(dispAddr);
321	return(result);
322}
323#endif
324#endif
325
326
327void SaveSURMEM(string filename, byte &SurfaceMem[], SizeType Size)
328{
329	byte handle;
330	unsigned long fsize = ArrayLen(SurfaceMem) + 8;
331	unsigned long cnt;
332	byte writebuf[];
333
334	ArrayInit(writebuf, 0x00, fsize);
335
336	for(unsigned long i = 0; i < 4; ++i)
337	{
338		writebuf[i] = (Size.Width >> ((3 - i) * 8)) & 0xFF;
339	}
340
341	for(unsigned long i = 0; i < 4; ++i)
342	{
343		writebuf[i + 4] = (Size.Height >> ((3 - i) * 8)) & 0xFF;
344	}
345
346	for(unsigned long i = 8; i < fsize; ++i)
347	{
348		writebuf[i] = SurfaceMem[i - 8];
349	}
350
351	CreateFile(filename, fsize, handle);
352
353	WriteBytes(handle, writebuf, cnt);
354
355	CloseFile(handle);
356}
357
358
359void OpenSURMEM(string filename, byte &SurfaceMem[], SizeType &Size)
360{
361	byte handle;
362	unsigned long fsize;
363	unsigned long len;
364	byte readbuf[];
365
366	OpenFileRead(filename, fsize, handle);
367
368	ArrayInit(readbuf, 0x00, fsize);
369
370	len = fsize;
371	ReadBytes(handle, len, readbuf);
372
373	CloseFile(handle);
374
375	if(len < 8)
376		return;
377
378	Size.Width = 0;
379	for(unsigned long i = 0; i < 4; ++i)
380	{
381		Size.Width |= readbuf[i] << ((3 - i) * 8);
382	}
383
384	Size.Height = 0;
385	for(unsigned long i = 0; i < 4; ++i)
386	{
387		Size.Height |= readbuf[i + 4] << ((3 - i) * 8);
388	}
389
390	len -= 8;
391	ArrayInit(SurfaceMem, 0x00, len);
392	ArraySubset(SurfaceMem, readbuf, 8, len);
393}
394
395
396void GetSurfaceMem(byte &SurfaceMem[], LocationType Location, SizeType Size)
397{
398	byte ScreenBuf[];
399	int linepos = 0;
400	int x = 0;
401
402	ArrayInit(SurfaceMem, 0, 800);
403	ArrayInit(ScreenBuf, 0, 100);
404
405	if ((Location.X + Size.Width) > 99)
406		return;
407
408	if ((Location.Y + Size.Height) > 63)
409		return;
410
411
412	Size.Width++;
413	Size.Height++;
414
415	for(linepos = (7 - (Location.Y + Size.Height));
416	    linepos < (8 - Location.Y);
417	    ++linepos)
418	{
419		GetDisplayNormal(Location.X, linepos, Size.Width, ScreenBuf);
420		
421		for(x = 0; x < Size.Width; ++x)
422		{
423			SurfaceMem[x + (linepos * Size.Width)] = ScreenBuf[x];
424		}
425	}
426
427	/*
428	Size.Width--;
429	Size.Height--;
430	*/
431}
432
433
434void DisplaySurfaceMem(byte &SurfaceMem[], LocationType Location, SizeType Size)
435{
436	byte ScreenBuf[];
437	int linepos = 0;
438	int x = 0;
439
440	ArrayInit(ScreenBuf, 0, 100);
441
442	if ((Location.X + Size.Width) > 99)
443		return;
444
445	if ((Location.Y + Size.Height) > 63)
446		return;
447
448	Size.Width++;
449	Size.Height++;
450
451	for(linepos = (7 - (Location.Y + Size.Height));
452	    linepos < (8 - Location.Y);
453	    --linepos)
454	{
455		for(x = 0; x < Size.Width; ++x)
456		{
457			ScreenBuf[x] = SurfaceMem[x + (linepos * Size.Width)];
458		}
459
460		SetDisplayNormal(Location.X, linepos, Size.Width, ScreenBuf);
461	}
462
463	/*
464	Size.Width--;
465	Size.Height--;
466	*/
467}
468
469
470#endif