-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemos.cpp
1549 lines (1436 loc) · 52.4 KB
/
demos.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//============================================================================
//
// Some demo routines for Crystalfontz CFA10118 EVE accelerated displays.
//
// These routines _could_ be made into classes. But in real life, there are
// not resources available to instantiate more than one of them at a time.
// Because of this I have just kept them simple and hopefully
// more understandable.
//
// The format is:
// variables (global but limited in scope to this file)
// init()
// draw()
// move()
//
// 2020-08-05 Brent A. Crosby / Crystalfontz America, Inc.
// https://www.crystalfontz.com/products/eve-accelerated-tft-displays.php
//===========================================================================
//This is free and unencumbered software released into the public domain.
//
//Anyone is free to copy, modify, publish, use, compile, sell, or
//distribute this software, either in source code form or as a compiled
//binary, for any purpose, commercial or non-commercial, and by any
//means.
//
//In jurisdictions that recognize copyright laws, the author or authors
//of this software dedicate any and all copyright interest in the
//software to the public domain. We make this dedication for the benefit
//of the public at large and to the detriment of our heirs and
//successors. We intend this dedication to be an overt act of
//relinquishment in perpetuity of all present and future rights to this
//software under copyright law.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
//MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
//IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
//OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
//ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//OTHER DEALINGS IN THE SOFTWARE.
//
//For more information, please refer to <http://unlicense.org/>
//============================================================================
#include <Arduino.h>
#include <SPI.h>
#include <stdarg.h>
// Definitions for our circuit board and display.
#include "CFA10118_defines.h"
// Transparent Rotating Logo for this display
#include "Round_Logos.h"
#if BUILD_SD
#include <SD.h>
#endif
// The very simple EVE library files
#include "EVE_base.h"
#include "EVE_draw.h"
// Our demonstrations of various EVE functions
#include "demos.h"
//===========================================================================
#if (0 != PROGRAM_FLASH_FROM_USD)
uint16_t Initialize_Flash_From_uSD(uint16_t FWol,
uint32_t RAM_G_Unused_Start,
uint32_t *Flash_Sector)
{
uint32_t
Flash_Sector_Marble;
uint32_t
Flash_Length_Marble;
uint32_t
Flash_Sector_Splash;
uint32_t
Flash_Length_Splash;
uint32_t
Flash_Sector_Clouds;
uint32_t
Flash_Length_Clouds;
uint32_t
Flash_Sector_ICE_FPV_512x300;
uint32_t
Flash_Length_ICE_FPV_512x300;
DBG_GEEK("Writing flash BLOB to flash sector %ld . . . ",*Flash_Sector);
//Write_BLOB_to_Flash_Sector_0() needs to know where unused RAM_G
//starts so it does not overwrite anything, but only uses RAM_G
//temporarily, so it does not change RAM_G_Unused_Start.
FWol=Write_BLOB_to_Flash_Sector_0(FWol,
RAM_G_Unused_Start,
Flash_Sector);
DBG_GEEK("done.\n");
DBG_GEEK_Decode_Flash_Status(EVE_REG_Read_8(EVE_REG_FLASH_STATUS));
// I use .a4z and .a8z as a file extensions for a zlib compressed ATSC
// files. .a4z is 4x4 (higher quality, larger) and .a8z is 8x8 (lower
// quality, smaller). I typically just use the "thorough" setting in
// Eve Asset Builder.
// For this 480 x 480 display the BT817 struggles with the 4x4 block
// size. The 8x8 works fine and still looks great.
// Since ATSC is already compressed, zlib does not do much, but
// the uSD is slow and the decompression is free thanks to the EVE.
DBG_GEEK("Writing \"bluemarb.a8z\" to flash sector = %ld . . . ",*Flash_Sector);
Flash_Sector_Marble=*Flash_Sector;
//Write_uSD_File_To_Flash() needs to know where unused RAM_G
//starts so it does not overwrite anything, but only uses RAM_G
//temporarily, so it does not change RAM_G_Unused_Start.
FWol=Inflate_uSD_File_To_Flash(FWol,
"bluemarb.a8z",
RAM_G_Unused_Start,
Flash_Sector,
&Flash_Length_Marble);
DBG_GEEK("done.\n");
DBG_GEEK("Writing \"splash.a8z\" to flash sector %ld . . . ",*Flash_Sector);
Flash_Sector_Splash=*Flash_Sector;
//Write_uSD_File_To_Flash() needs to know where unused RAM_G
//starts so it does not overwrite anything, but only uses RAM_G
//temporarily, so it does not change RAM_G_Unused_Start.
FWol=Inflate_uSD_File_To_Flash(FWol,
"splash.a8z",
RAM_G_Unused_Start,
Flash_Sector,
&Flash_Length_Splash);
DBG_GEEK("done.\n");
DBG_GEEK("Writing \"cloud.a8z\" to flash sector 0x%04lX = %ld . . . ",*Flash_Sector);
Flash_Sector_Clouds=*Flash_Sector;
//Write_uSD_File_To_Flash() needs to know where unused RAM_G
//starts so it does not overwrite anything, but only uses RAM_G
//temporarily, so it does not change RAM_G_Unused_Start.
FWol=Inflate_uSD_File_To_Flash(FWol,
"cloud.a8z",
RAM_G_Unused_Start,
Flash_Sector,
&Flash_Length_Clouds);
DBG_GEEK("done.\n");
//RAM_G is only one MB, so we need to move the uncompressed file
//directly from uSD to the flash.
DBG_GEEK("Writing \"ICE_400.avi\" to flash sector 0x%04lX = %ld . . . ",*Flash_Sector);
Flash_Sector_ICE_FPV_512x300=*Flash_Sector;
//Write_uSD_File_To_Flash() needs to know where unused RAM_G
//starts so it does not overwrite anything, but only uses RAM_G
//temporarily, so it does not change RAM_G_Unused_Start.
FWol=Write_uSD_File_To_Flash(FWol,
"ICE_400.avi",
RAM_G_Unused_Start,
Flash_Sector,
&Flash_Length_ICE_FPV_512x300);
DBG_GEEK("done.\n");
// DBG_GEEK("Writing \"BBB_1024.avz\" to flash sector 0x%04lX = %ld . . . ",*Flash_Sector);
// Flash_Sector_BBB1024x600=*Flash_Sector;
// //Write_uSD_File_To_Flash() needs to know where unused RAM_G
// //starts so it does not overwrite anything, but only uses RAM_G
// //temporarily, so it does not change RAM_G_Unused_Start.
// FWol=Inflate_uSD_File_To_Flash(FWol,
// "BBB_1024.avz",
// RAM_G_Unused_Start,
// Flash_Sector,
// &Flash_Length_BBB1024x600);
// DBG_GEEK("done.\n");
//Dump the flash sectors to the console, so we can copy those into the source
//and use them to access the flash. Yes, I realize this is hokey, properly
//we could write some kind of file system or at least a directory to the flash.
DBG_STAT("\n#define FLASH_SECTOR_MARBLE (%ldUL)\n",Flash_Sector_Marble);
DBG_STAT("#define FLASH_LENGTH_MARBLE (%ldUL) // sectors: %ld\n",Flash_Length_Marble,Flash_Length_Marble>>12);
DBG_STAT("#define FLASH_SECTOR_SPLASH (%ldUL)\n",Flash_Sector_Splash);
DBG_STAT("#define FLASH_LENGTH_SPLASH (%ldUL) // sectors: %ld\n",Flash_Length_Splash,Flash_Length_Splash>>12);
DBG_STAT("#define FLASH_SECTOR_CLOUDS (%ldUL)\n",Flash_Sector_Clouds);
DBG_STAT("#define FLASH_LENGTH_CLOUDS (%ldUL) // sectors: %ld\n",Flash_Length_Clouds,Flash_Length_Clouds>>12);
DBG_STAT("#define FLASH_SECTOR_ICE_FPV_512x300 (%ldUL)\n",Flash_Sector_ICE_FPV_512x300);
DBG_STAT("#define FLASH_LENGTH_ICE_FPV_512x300 (%ldUL) // sectors: %ld\n",Flash_Length_ICE_FPV_512x300,Flash_Length_ICE_FPV_512x300>>12);
DBG_STAT("//Total sectors = 4096, free sectors = %ld\n",4096UL - (Flash_Sector_ICE_FPV_512x300+((Flash_Length_ICE_FPV_512x300+4095)>>12)));
DBG_STAT("//Total flash = 16777216, free flash = %ld\n\n",16777216UL - ((Flash_Sector_ICE_FPV_512x300+((Flash_Length_ICE_FPV_512x300+4095)>>12))<<12));
// DBG_STAT("#define FLASH_SECTOR_BBB1024x600 (%ldUL)\n",Flash_Sector_BBB1024x600);
// DBG_STAT("#define FLASH_LENGTH_BBB1024x600 (%ldUL)\n\n",Flash_Length_BBB1024x600);
//Give the updated write pointer back to the caller
return(FWol);
}
#endif //PROGRAM_FLASH_FROM_USD
//===========================================================================
#if TOUCH_DEMO
uint16_t Add_Touch_Dot_To_Display_List(uint16_t FWol,
uint16_t touch_x,
uint16_t touch_y)
{
//See if we are touched at all. Coordinates will be large if not.
if(touch_x<1200)
{
DBG_GEEK(" touch detected\n");
// Set the variable color of the touched dot to green.
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_RGB(0x00,0xFF,0x00));
// Make it solid
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_A(0xFF));
// Draw the touch dot -- a 60px point (filled circle)
FWol=EVE_Point(FWol,
touch_x*16,
touch_y*16,
60*16);
}
//Give the updated write pointer back to the caller
return(FWol);
}
#endif //TOUCH_DEMO
//===========================================================================
#if (0 != BMP_DEMO)
//For a static background image, set BMP_SCROLL to 0
//We will select the file name based on that.
//Address of the 565 bitmap image in RAM_G
//uint32_t
// Bitmap_RAM_G_Address;
//Keep track of where the background is as it slides around in a loop
int16_t
background_slide;
uint8_t
background_slide_slow;
uint8_t
background_bitmap_handle;
//---------------------------------------------------------------------------
uint16_t Initialize_Bitmap_Demo(uint16_t FWol,
//uint32_t *RAM_G_Unused_Start,
uint8_t next_bitmap_handle_available)
{
//Keep track of our bitmap handle
background_bitmap_handle=next_bitmap_handle_available;
//Start the slide at position 0.
background_slide=0;
background_slide_slow=0;
return(FWol);
}
//---------------------------------------------------------------------------
uint16_t Add_Bitmap_To_Display_List(uint16_t FWol)
{
//We have a LCD_WIDTHxLCD_HEIGHT (1026x600) ATSC image in the flash.
//The particular image we have is seemlessly tileable in x -- letting
//us make a continuous scenery wheel scroll of the background
int16_t
tile_offset;
#if (0==BMP_SCROLL) //1 for scroll, 0 for static bitmap
background_slide=LCD_WIDTH;
#endif // (0==BMP_SCROLL)
//We will loop background_slide from 0 to LCD_WIDTH-1
//The first tile starts at up to LCD_WIDTH pixels to the left of the visible
//display.
tile_offset=background_slide-LCD_WIDTH;
//First tile: pull the ASTC image from flash onto the screen
// Set the drawing color to white
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF));
//Solid color -- not transparent
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_A(255));
//Make sure the EVE has the idea of which bitmap they it
//should be working on.
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_HANDLE(background_bitmap_handle));
#if (0==BMP_SCROLL) //1 for scroll, 0 for static bitmap
FWol=FLASH_SETBITMAP(FWol,FLASH_SECTOR_SPLASH,EVE_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR,LCD_WIDTH,LCD_HEIGHT);
#else // (0==BMP_SCROLL) //1 for scroll, 0 for static bitmap
FWol=FLASH_SETBITMAP(FWol,FLASH_SECTOR_CLOUDS,EVE_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR,LCD_WIDTH,LCD_HEIGHT);
#endif // (0==BMP_SCROLL) //1 for scroll, 0 for static bitmap
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
//Render the bitmap it to the current frame
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_VERTEX2F((tile_offset)*16,0*16));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_END());
#if (1==BMP_SCROLL) //1 for scroll, 0 for static bitmap
//Second tile, move over LCD_WIDTH pixels.
tile_offset+=LCD_WIDTH;
// FWol=FLASH_SETBITMAP(FWol,FLASH_SECTOR_CLOUDS,EVE_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR,1024,600);
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
//Render the bitmap it to the current frame
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_VERTEX2F((tile_offset)*16,0*16));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_END());
//Slide the background along at 1/3 frame rate ~20Hz
if(0==background_slide_slow)
{
background_slide_slow=2;
if(background_slide < LCD_WIDTH)
{
background_slide++;
}
else
{
background_slide=0;
}
}
else
{
background_slide_slow--;
}
#endif // (1==BMP_SCROLL)
//Pass our updated offset back to the caller
return(FWol);
}
#endif // (0 != BMP_DEMO)
//===========================================================================
#if (0 != MARBLE_DEMO)
//Keep track of the Marble
int32_t
marble_x_pos;
int32_t
marble_x_vel;
int32_t
marble_y_pos;
int32_t
marble_y_vel;
int32_t
marble_rotation;
int32_t
marble_spin;
uint32_t
Marble_RAM_G_Address;
uint32_t
marble_width;
uint32_t
marble_height;
uint8_t
marble_bitmap_handle;
//---------------------------------------------------------------------------
//Requires uSD
uint16_t Initialize_Marble_Demo(uint16_t FWol,
uint32_t *RAM_G_Unused_Start,
uint8_t next_bitmap_handle_available)
{
//Keep track of our bitmap handle
marble_bitmap_handle=next_bitmap_handle_available;
//Start somewhere reasonable
marble_x_pos=LCD_WIDTH*(16/2);
marble_x_vel=48;
marble_y_pos=LCD_HEIGHT*(16/2);
marble_y_vel=-32;
marble_rotation=0;
marble_spin=0;
//5.79 CMD_FLASHREAD
//This command reads data from flash into main memory.
// void cmd_flashread(uint32_t dest,
// uint32_t src,
// uint32_t num);
// void Gpu_CoCmd_FlashRead(Gpu_Hal_Context_t *phost,uint32_t dest, uint32_t src, uint32_t num)
// {
// Gpu_CoCmd_StartFunc(phost,CMD_SIZE*4);
// Gpu_Copro_SendCmd(phost, CMD_FLASHREAD);
// Gpu_Copro_SendCmd(phost, dest);
// Gpu_Copro_SendCmd(phost, src);
// Gpu_Copro_SendCmd(phost, num);
// Gpu_CoCmd_EndFunc(phost,(CMD_SIZE*4));
// }
DBG_GEEK("Copy marble from flash to RAM_G start: %lu",*RAM_G_Unused_Start);
//Remember where the marble is.
Marble_RAM_G_Address=*RAM_G_Unused_Start;
//You have to know ahead of time how big the image is and what
//format it is in. EVE_Load_File_To_RAM_G just moves the data.
marble_width=240;
marble_height=240;
FWol=EVE_Cmd_Dat_3(FWol,
EVE_ENC_CMD_FLASHREAD,
// destination in RAM_G, must be 4-byte aligned
Marble_RAM_G_Address,
// source in flash, must be 64-byte aligned
(FLASH_SECTOR_MARBLE)<<12,
// number of bytes to write, must be 4-byte aligned
FLASH_LENGTH_MARBLE);
*RAM_G_Unused_Start+=FLASH_LENGTH_MARBLE;
DBG_GEEK(" end: %lu\n",*RAM_G_Unused_Start);
// Update the ring buffer pointer so the graphics processor starts executing
EVE_REG_Write_16(EVE_REG_CMD_WRITE, (FWol));
/*
//Since the Arduino uSD card is slow, put up a "please wait" screen.
FWol=Start_Busy_Spinner_Screen(FWol,
//clear color
EVE_ENC_CLEAR_COLOR_RGB(0x00,0x00,0xFF),
//text color
EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF),
//spinner color
EVE_ENC_COLOR_RGB(0x00,0xFF,0x00),
F("Loading \"BLUEMARB.RAW\" . . ."));
//Attempt to load our RAW bitmap file from the uSD into RAM_G
Marble_RAM_G_Address=*RAM_G_Unused_Start;
//You have to know ahead of time how big the image is and what
//format it is in. EVE_Load_File_To_RAM_G just moves the data.
marble_width=240;
marble_height=240;
//If the Marble_RAM_G_Length returned is 0, then it has probably failed.
Marble_RAM_G_Length=0;
//By the way, it appears that the SD library reports all file names
//in all upper case. So even though Windows file explorer, CMD,
//and Power Shell all report the name as lower case, we need to
//feed the SD library an all uppercase string.
EVE_Load_File_To_RAM_G(Marble_RAM_G_Address,
"BLUEMARB.RAW",
&Marble_RAM_G_Length);
//Keep track of the RAM_G memory allocation, force to 8-byte aligned
*RAM_G_Unused_Start=(*RAM_G_Unused_Start+Marble_RAM_G_Length+0x07)&0xFFFFFFF8;
FWol=Stop_Busy_Spinner_Screen(FWol,
//clear color
EVE_ENC_CLEAR_COLOR_RGB(0x00,0x00,0xFF),
//text color
EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF),
F("Done."));
*/
//Pass our updated offset back to the caller
return(FWol);
}
//---------------------------------------------------------------------------
#if TOUCH_DEMO
void Force_Marble_Position(uint32_t x,uint16_t y)
{
marble_x_pos=x;
marble_y_pos=y;
}
#endif //TOUCH_DEMO
//---------------------------------------------------------------------------
uint16_t Add_Marble_To_Display_List(uint16_t FWol)
{
//========== PUT BLUE MARBLE ON SCREEN ==========
//Make sure the EVE has the idea of which bitmap they it
//should be working on.
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_HANDLE(marble_bitmap_handle));
// Set the drawing color to white
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF));
//Solid color -- not transparent
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_A(255));
//Pull the uncompressed bitmap from RAM_G onto the screen
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BEGIN(EVE_BEGIN_BITMAPS));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_HANDLE(11));
// DBG_GEEK("Marble_RAM_G_Address: %lu\n",Marble_RAM_G_Address);
#if 1
FWol=EVE_Cmd_Dat_3(FWol,
EVE_ENC_CMD_SETBITMAP,
Marble_RAM_G_Address,
//Width (high word), Format (low word)
// ((uint32_t)marble_width << 16) | EVE_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR,
((uint32_t)marble_width << 16) | EVE_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR,
//Height (low word) (high word unused)
marble_height); //height
#else
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_SOURCE(Marble_RAM_G_Address));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_LAYOUT(
EVE_FORMAT_ARGB1555,
marble_width*2,
marble_height));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_SIZE(
EVE_FILTER_NEAREST, // EVE_FILTER_BILINEAR, //BiLinear is much more work
EVE_WRAP_BORDER,
EVE_WRAP_BORDER,
marble_width,
marble_height));
#endif
//Rotate the bitmap
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_CMD_LOADIDENTITY);
//Translate to the center
FWol=EVE_Cmd_Dat_2(FWol,
EVE_ENC_CMD_TRANSLATE,
+(to_16_16_fp(marble_width,0)/2),
+(to_16_16_fp(marble_height,0)/2));
//The actual rotate command
FWol=EVE_Cmd_Dat_1(FWol,
EVE_ENC_CMD_ROTATE,
to_16_16_fp(marble_rotation,0)/360);
//Undo the translation
FWol=EVE_Cmd_Dat_2(FWol,
EVE_ENC_CMD_TRANSLATE,
-(to_16_16_fp(marble_width,0)/2),
-(to_16_16_fp(marble_height,0)/2));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_CMD_SETMATRIX);
//Render the bitmap it to the current frame
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_VERTEX2F(
(marble_x_pos-(marble_width*(16/2))),
(marble_y_pos-(marble_height*(16/2)))));
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_END());
//Reset the matrix . . otherwise further things (like text) in this
//display list will be goofed.
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_CMD_LOADIDENTITY);
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_CMD_SETMATRIX);
return(FWol);
}
//---------------------------------------------------------------------------
void Move_Marble(void)
{
//We need the radius, not diameter, and in native x16 units
uint16_t
move_marble_width;
move_marble_width=marble_width*(16/2);
uint16_t
move_marble_height;
move_marble_height=marble_height*(16/2);
//Move X, bouncing
if(marble_x_vel < 0)
{
//Going left. OK to move again?
if(0 < (marble_x_pos-(move_marble_width)+marble_x_vel))
{
//it will be onscreen after decrease
marble_x_pos+=marble_x_vel;
}
else
{
//It would be too small, bounce.
marble_x_pos=move_marble_width+(move_marble_width-(marble_x_pos+marble_x_vel));
//Turn around.
marble_x_vel=-marble_x_vel;
marble_spin=marble_y_vel;
}
}
else
{
//Getting larger. OK to increase again?
if((marble_x_pos+(move_marble_width)+marble_x_vel) < (int32_t)LCD_WIDTH*16)
{
//it will be on screen after increase
marble_x_pos+=marble_x_vel;
}
else
{
//It would be too big, bounce.
int32_t
max_x_ctr;
max_x_ctr=(int32_t)LCD_WIDTH*16-move_marble_width;
marble_x_pos=max_x_ctr-(max_x_ctr-(marble_x_pos+marble_x_vel));
//Turn around.
marble_x_vel=-marble_x_vel;
marble_spin=-marble_y_vel;
}
}
//Move Y, bouncing
if(marble_y_vel < 0)
{
//Going left. OK to move again?
if(0 < (marble_y_pos-(move_marble_height)+marble_y_vel))
{
//it will be onscreen after decrease
marble_y_pos+=marble_y_vel;
}
else
{
//It would be too small, bounce.
marble_y_pos=move_marble_height+(move_marble_height-(marble_y_pos+marble_y_vel));
//Turn around.
marble_y_vel=-marble_y_vel;
marble_spin=-marble_x_vel;
}
}
else
{
//Getting larger. OK to increase again?
if((marble_y_pos+(move_marble_height)+marble_y_vel) < (int32_t)LCD_HEIGHT*16)
{
//it will be on screen after increase
marble_y_pos+=marble_y_vel;
}
else
{
//It would be too big, bounce.
int32_t
max_y_ctr;
max_y_ctr=(int32_t)LCD_WIDTH*16-move_marble_height;
marble_y_pos=max_y_ctr-(max_y_ctr-(marble_y_pos+marble_y_vel));
//Turn around.
marble_y_vel=-marble_y_vel;
marble_spin=marble_x_vel;
}
}
//Do the twist.
marble_rotation+=(marble_spin)/16;
if(360 < marble_rotation)
marble_rotation-=360;
else
if(marble_rotation < 0)
marble_rotation+=360;
}
#endif // (0 != MARBLE_DEMO)
//===========================================================================
#if (0 != BOUNCE_DEMO)
//Keep track of the ball
int32_t
x_position;
int32_t
x_velocity;
int32_t
y_position;
int32_t
y_velocity;
int32_t
ball_size;
int32_t
ball_delta;
//Cycle the color around
uint8_t
r;
uint8_t
g;
uint8_t
b;
uint8_t
transparency;
uint8_t
transparency_direction;
//---------------------------------------------------------------------------
void Initialize_Bounce_Demo(void)
{
//Choose some starting color
r=0xff;
g=0x00;
b=0x80;
//Start ghostly, getting more solid.
transparency=0;
transparency_direction=1;
// Define a default point x-location (1/16 anti-aliased)
x_position = (LCD_WIDTH/2 * 16);
x_velocity = 3*16;
// Define a default point y-location (1/16 anti-aliased)
y_position = (LCD_HEIGHT/2 * 16);
y_velocity = -2*16;
//Start small.
ball_size=50*1;
ball_delta=1*16;
}
//---------------------------------------------------------------------------
uint16_t Add_Bounce_To_Display_List(uint16_t FWol)
{
// Set the variable color of the bouncing ball
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_RGB(r,g,b));
// Make it transparent
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_A(transparency));
// Draw the ball -- a point (filled circle)
FWol=EVE_Point(FWol,
x_position,y_position,ball_size);
//========== RUBBER BAND TETHER ==========
//Draw the rubberband.
//Maximum stretched would be LCD_WIDTH/2 + LCD_WIDTH/2 (manhatten) make that
//1 pixels wide, make the minimum 10 pixels wide
uint16_t
rubberband_width;
uint16_t
x_distance;
if((x_position/16)<(LCD_WIDTH/2))
x_distance=(LCD_WIDTH/2)-(x_position/16);
else
x_distance=(x_position/16)-(LCD_WIDTH/2);
uint16_t
y_distance;
if((y_position/16)<(LCD_HEIGHT/2))
y_distance=(LCD_HEIGHT/2)-(y_position/16);
else
y_distance=(y_position/16)-(LCD_HEIGHT/2);
//Straight math does not make it skinny enough. This seems like it should
//underlow often, but in real life never goes below 1. Need to dissect.
rubberband_width=10-((9+1)*(x_distance+y_distance))/((LCD_WIDTH/2)+(LCD_HEIGHT/2));
//Check for underflow just in case.
if(rubberband_width&0x8000)
rubberband_width=1;
//Now that we know the rubberband width, drawing it is simple.
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_COLOR_RGB(200,0,0));
//(transparency set above still in effect)
FWol=EVE_Line(FWol,
LCD_WIDTH/2,LCD_HEIGHT/2,
x_position/16,y_position/16,
rubberband_width);
return(FWol);
}
//---------------------------------------------------------------------------
void Bounce_Ball(void)
{
//Update the colors
r++;
g--;
b+=2;
//Cycle the transparancy
if(transparency_direction)
{
//Getting more solid
if(transparency!=255)
{
transparency++;
}
else
{
transparency_direction=0;
}
}
else
{
//Getting more clear
if(128<transparency)
{
transparency--;
}
else
{
transparency_direction=1;
}
}
//========== BOUNCE THE BALL AROUND ==========
#define MIN_POINT_SIZE (10*16)
// #define MAX_POINT_SIZE (int32_t)(((LCD_WIDTH/2)-20)*16)
#define MAX_POINT_SIZE (int32_t)(((LCD_HEIGHT/2)-20)*16)
//Change the point (ball) size.
if(ball_delta < 0)
{
//Getting smaller. OK to decrease again?
if(MIN_POINT_SIZE < (ball_size+ball_delta))
{
//it will be bigger than min after decrease
ball_size+=ball_delta;
}
else
{
//It would be too small, bounce.
ball_size=MIN_POINT_SIZE+(MIN_POINT_SIZE-(ball_size+ball_delta));
//Turn around.
ball_delta=-ball_delta;
}
}
else
{
//Getting larger. OK to increase again?
if((ball_size+ball_delta) < MAX_POINT_SIZE)
{
//it will be smaller than max after increase
ball_size+=ball_delta;
}
else
{
//It would be too big, bounce.
ball_size=MAX_POINT_SIZE-(MAX_POINT_SIZE-(ball_size+ball_delta));
//Turn around.
ball_delta=-ball_delta;
}
}
//Move X, bouncing
if(x_velocity < 0)
{
//Going left. OK to move again?
if(0 < (x_position-(ball_size)+x_velocity))
{
//it will be onscreen after decrease
x_position+=x_velocity;
}
else
{
//It would be too small, bounce.
x_position=ball_size+(ball_size-(x_position+x_velocity));
//Turn around.
x_velocity=-x_velocity;
}
}
else
{
//Getting larger. OK to increase again?
if((x_position+(ball_size)+x_velocity) < (int32_t)LCD_WIDTH*16)
{
//it will be on screen after increase
x_position+=x_velocity;
}
else
{
//It would be too big, bounce.
int32_t
max_x_ctr;
max_x_ctr=(int32_t)LCD_WIDTH*16-ball_size;
x_position=max_x_ctr-(max_x_ctr-(x_position+x_velocity));
//Turn around.
x_velocity=-x_velocity;
}
}
//Move Y, bouncing
if(y_velocity < 0)
{
//Going left. OK to move again?
if(0 < (y_position-(ball_size)+y_velocity))
{
//it will be onscreen after decrease
y_position+=y_velocity;
}
else
{
//It would be too small, bounce.
y_position=ball_size+(ball_size-(y_position+y_velocity));
//Turn around.
y_velocity=-y_velocity;
}
}
else
{
//Getting larger. OK to increase again?
if((y_position+(ball_size)+y_velocity) < (int32_t)LCD_HEIGHT*16)
{
//it will be on screen after increase
y_position+=y_velocity;
}
else
{
//It would be too big, bounce.
int32_t
max_y_ctr;
max_y_ctr=(int32_t)LCD_WIDTH*16-ball_size;
y_position=max_y_ctr-(max_y_ctr-(y_position+y_velocity));
//Turn around.
y_velocity=-y_velocity;
}
}
}
#endif // (0 != BOUNCE_DEMO)
//============================================================================
#if (0 != LOGO_DEMO)
//Remember where we put the logo image data in RAM_G
uint32_t
Logo_RAM_G_Address;
//Remember how big the Logo image is.
uint32_t
Logo_Width;
uint32_t
Logo_Height;
// Keep track of the logo's orientation
uint16_t
logo_rotate_degrees;
//Used to pause the logo between spinning sesions
uint16_t
logo_rotate_pause;
uint8_t
logo_bitmap_handle;
//----------------------------------------------------------------------------
//Test code to crash coprocessor ever other time it is called --
//for testing Reset_EVE_Coprocessor()
#if (0!=DEBUG_COPROCESSOR_RESET)
uint8_t
first=0;
#endif // (0!=DEBUG_COPROCESSOR_RESET)
uint16_t Initialize_Logo_Demo(uint16_t FWol,
uint32_t *RAM_G_Unused_Start,
uint8_t next_bitmap_handle_available)
{
//Keep track of our bitmap handle
logo_bitmap_handle=next_bitmap_handle_available;
// No rotation to start.
logo_rotate_degrees=0;
// Don't spin the logo right away, delay ~8 seconds at 60 frames per second
logo_rotate_pause=8*60;
//Remember where we put the logo in RAM_G so we can access it later.
Logo_RAM_G_Address=*RAM_G_Unused_Start;
#if (0==LOGO_PNG_0_ARGB2_1)
//Load and expand our 24-bit PNG (true color, lossless, with
//transparency) into RAM_G
//An indexed PNG is smaller, but the EVE does not handle
//indexed color PNGs.
FWol=EVE_Load_PNG_to_RAM_G(FWol,
CFA480480Ex_040_PNG_LOGO,
LOGO_SIZE_PNG,
RAM_G_Unused_Start,
&Logo_Width,
&Logo_Height);
#endif // 0==LOGO_PNG_0_ARGB2_1
#if (1==LOGO_PNG_0_ARGB2_1)
//Load and INFLATE our 8-bit A2R2G2B2 (lossless) image into RAM_G
//You have to know before hand how big the logo is. The INFLATE
//is not aware of the content or format of the data.
Logo_Width=LOGO_WIDTH_ARGB2;
Logo_Height=LOGO_HEIGHT_ARGB2;
//Test code to crash coprocessor ever other time it is called --
//for testing Reset_EVE_Coprocessor()
#if (0 != DEBUG_COPROCESSOR_RESET)
if(0==first)
{
//good
FWol=EVE_Inflate_to_RAM_G(FWol,
CFA480480Ex_040_ARGB2_LOGO,
LOGO_SIZE_ARGB2,
RAM_G_Unused_Start);
DBG_GEEK("Good inflate\n");
first=1;
}
else
{
//bad
FWol=EVE_Inflate_to_RAM_G(FWol,
CFA480480Ex_040_ARGB2_LOGO+20,
LOGO_SIZE_ARGB2,
RAM_G_Unused_Start);
DBG_GEEK("Bad inflate\n");
first=0;
}
#else //(0!=DEBUG_COPROCESSOR_RESET)
FWol=EVE_Inflate_to_RAM_G(FWol,
CFA480480Ex_040_ARGB2_LOGO,
LOGO_SIZE_ARGB2,
RAM_G_Unused_Start);
#endif //(0!=DEBUG_COPROCESSOR_RESET)
#endif // 1==LOGO_PNG_0_ARGB2_1
//Pass our updated offset back to the caller
return(FWol);
}
//----------------------------------------------------------------------------
uint16_t Add_Logo_To_Display_List(uint16_t FWol)
{
//========== PUT LOGO ON SCREEN ==========
// Set the drawing color to white
FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_COLOR_RGB(0xFF,0xFF,0xFF));
//Solid color -- not transparent
FWol=EVE_Cmd_Dat_0(FWol, EVE_ENC_COLOR_A(255));
//Make sure the EVE has the idea of which bitmap they it
//should be working on.
FWol=EVE_Cmd_Dat_0(FWol,
EVE_ENC_BITMAP_HANDLE(logo_bitmap_handle));