Advertisement
Guest User

int attempt

a guest
Mar 7th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.37 KB | Source Code | 0 0
  1. #define USE_TI89
  2. #define SAVE_SCREEN
  3.  
  4. #include <tigcclib.h>
  5.  
  6. #include "extgraph.h" // Made by TICT. Thank you TICT HQ and Lionel Debroux :)
  7.  
  8. SYM_ENTRY* openBinVAT(char *varName) { // Quicker file reader than default fopen. Thanks Lionel
  9.     SYM_ENTRY *symptr = DerefSym(SymFind(SYMSTR(varName)));
  10.     if (!symptr) {
  11.         printf("%s not found\n", varName);
  12.         ngetchx();
  13.     }
  14.   return symptr;
  15. }
  16.  
  17. #define TOTAL_STR 12
  18.  
  19. volatile unsigned char x0 = 0, x1 = 0, y0 = 0, currentColor = 0, lastByte = 0, currentFile = 0; // Initialize vars for writing
  20. volatile unsigned int intCount = 0, i = 2;
  21.  
  22. unsigned char* datas[TOTAL_STR];
  23. unsigned int dataLengths[TOTAL_STR];
  24.  
  25. INT_HANDLER oldInt5 = NULL;
  26.  
  27. DEFINE_INT_HANDLER(DrawFrameInt) {
  28.     intCount++;
  29.     if(intCount < 26) { // ~12 hz
  30.         return;
  31.     }
  32.     intCount = 0;
  33.    
  34.     SetIntVec(AUTO_INT_5, NULL); // Disable interrupt (is this bad?), goal: prevent from interrupting itself (???)
  35.    
  36.     unsigned short *data = datas[currentFile];
  37.     unsigned int dataLength = dataLengths[currentFile];
  38.     while(i < dataLength) { // Draw a frame (essentially copied from for loop, with breaks instead of wait for frame)
  39.         unsigned char nextByte = data[i];
  40.         if (y0 == LCD_HEIGHT) {
  41.             y0 = 0;
  42.         x0 = 0;
  43.         x1 = 0;
  44.         currentColor = 0;
  45.             i++;
  46.             break;
  47.         }
  48.         unsigned char newColor = !currentColor; // Defined here so it doesnt have to be recalculated.
  49.         if (nextByte == 255 || (lastByte < LCD_WIDTH && nextByte < lastByte)) { // New horizontal line? Then finish the previous row.
  50.             FastDrawHLine_R(LCD_MEM, x0, LCD_WIDTH - 1, y0, newColor);
  51.             x0 = 0;
  52.             y0++;
  53.             x1 = 0;
  54.         }
  55.         if (nextByte < LCD_WIDTH) { // This is the normal line draw. Majority
  56.             x1 = nextByte;
  57.             FastDrawHLine_R(LCD_MEM, x0, x1, y0, newColor);
  58.             currentColor = newColor;
  59.             x0 = x1;
  60.         } else if (nextByte == 254) { // This is if the frame has not changed. Just wait.
  61.             i++;
  62.             break;
  63.         } else if (nextByte == 253) { // Draw a full black screen, and wait
  64.             unsigned char j;
  65.             for (j = 0; j < LCD_HEIGHT; j++) {
  66.                 FastDrawHLine_R(LCD_MEM, 0, LCD_WIDTH - 1, j, 1);
  67.             }
  68.             i++;
  69.             break;
  70.         } else if (nextByte == 252) { // Draw an empty frame, wait
  71.             ClrScr();
  72.             i++;
  73.             break;
  74.         }
  75.         lastByte = nextByte;
  76.         i++;
  77.     }
  78.    
  79.     SetIntVec(AUTO_INT_5, DrawFrameInt); // Re enable interrupt
  80.    
  81.     return;
  82. }
  83.  
  84. void _main(void) {
  85.     const char *VARNAME_STRS[] = {"ba\\px1","ba\\px2","ba\\px3","ba\\px4","ba\\px5","ba\\px6","ba\\px7","ba\\px8","ba\\px9","ba\\px10","ba\\px11","ba\\px12",};
  86.     SYM_ENTRY *symPtrs[TOTAL_STR];
  87.  
  88.     int fileI;
  89.     for(fileI = 0; fileI < TOTAL_STR; fileI++) {
  90.         symPtrs[fileI] = openBinVAT(VARNAME_STRS[fileI]); // Define the data using the vat
  91.         unsigned char* data = HLock(symPtrs[fileI]->handle);
  92.         data+=2;
  93.         datas[fileI] = data;
  94.        
  95.         unsigned int dataLength = 0; // Define the length of the data
  96.         memcpy(&dataLength, data, sizeof(unsigned int));
  97.         dataLengths[fileI] = dataLength;
  98.     }
  99.  
  100.     ClrScr(); // Initial setup
  101.     PRG_setRate(0);
  102.     oldInt5 = GetIntVec(AUTO_INT_5);
  103.     SetIntVec(AUTO_INT_5, DrawFrameInt);
  104.     // TODO: set APD interrupt to null temporarily (???)
  105.    
  106.   while (!kbhit()); // Wait for video to end (or input in this case) (temporary, for testing)
  107.   GKeyFlush();
  108.  
  109.   SetIntVec (AUTO_INT_5, oldInt5); // Restore the program
  110.     for(fileI = 0; fileI < TOTAL_STR; fileI++) {
  111.         HeapUnlock(symPtrs[fileI]->handle);
  112.     }
  113.     PRG_setRate(1);
  114.  
  115.     return;
  116. }
  117.  
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement