Advertisement
Guest User

int working

a guest
Mar 8th, 2023
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.94 KB | Source Code | 0 0
  1. #define USE_TI89
  2. #define SAVE_SCREEN
  3.  
  4. #include <tigcclib.h>
  5. #include "extgraph.h" // Made by TICT. Thank you TICT HQ and Lionel Debroux :)
  6.  
  7. #define WIDTH 160
  8. #define HEIGHT 100
  9. #define FPS 16
  10. #define TOTAL_STR 16
  11.  
  12. SYM_ENTRY* openBinVAT(char *varName) { // Quicker file reader than default fopen. Thanks Lionel
  13.     SYM_ENTRY *symptr = DerefSym(SymFind(SYMSTR(varName)));
  14.     if (!symptr) {
  15.         printf("%s not found\n", varName);
  16.         ngetchx();
  17.     }
  18.   return symptr;
  19. }
  20.  
  21. volatile unsigned int i = 0, currentFile = 0;
  22. unsigned char* datas[TOTAL_STR];
  23. unsigned int dataLengths[TOTAL_STR];
  24.  
  25. DEFINE_INT_HANDLER(DrawFrameInt) {
  26.     unsigned char x0 = 0, x1 = 0, y0 = 0, currentColor = 0, lastByte = 0; // Initialize vars for writing
  27.     unsigned char *data = datas[currentFile];
  28.     unsigned int dataLength = dataLengths[currentFile];
  29.     while(i < dataLength) { // Draw a frame (essentially copied from for loop, with breaks instead of wait for frame)
  30.         unsigned char nextByte = data[i];
  31.         if (y0 == HEIGHT) {
  32.             y0 = 0;
  33.         x0 = 0;
  34.         x1 = 0;
  35.         currentColor = 0;
  36.             break;
  37.         }
  38.         unsigned char newColor = !currentColor; // Defined here so it doesnt have to be recalculated.
  39.         if (nextByte == 255 || (lastByte < WIDTH && nextByte < lastByte)) { // New horizontal line? Then finish the previous row.
  40.             FastDrawHLine_R(LCD_MEM, x0, WIDTH - 1, y0, newColor);
  41.             x0 = 0;
  42.             y0++;
  43.             x1 = 0;
  44.         }
  45.         if (nextByte < WIDTH) { // This is the normal line draw. Majority
  46.             x1 = nextByte;
  47.             FastDrawHLine_R(LCD_MEM, x0, x1, y0, newColor);
  48.             currentColor = newColor;
  49.             x0 = x1;
  50.         } else if (nextByte == 254) { // This is if the frame has not changed. Just wait.
  51.             i++;
  52.             break;
  53.         } else if (nextByte == 253) { // Draw a full black screen, and wait
  54.             unsigned char j;
  55.             for (j = 0; j < HEIGHT; j++) {
  56.                 FastDrawHLine_R(LCD_MEM, 0, WIDTH - 1, j, 1);
  57.             }
  58.             i++;
  59.             break;
  60.         } else if (nextByte == 252) { // Draw an empty frame, wait
  61.             ClrScr();
  62.             i++;
  63.             break;
  64.         }
  65.         lastByte = nextByte;
  66.         i++;
  67.     }
  68.     short row = _rowread(0x0000);
  69.     if(i >= dataLength || row == 8) {
  70.         currentFile++;
  71.         i = 0;
  72.     } else if(row == 2) {
  73.         currentFile--;
  74.         i = 0;
  75.     }
  76. }
  77.  
  78. DEFINE_INT_HANDLER(BreakDrawInt) {
  79.     currentFile = -1;
  80. }
  81.  
  82. void _main(void) {
  83.     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","ba\\px13","ba\\px14","ba\\px15","ba\\px16",};
  84.     SYM_ENTRY *symPtrs[TOTAL_STR];
  85.  
  86.     int fileI;
  87.     for(fileI = 0; fileI < TOTAL_STR; fileI++) { // alloc
  88.         symPtrs[fileI] = openBinVAT(VARNAME_STRS[fileI]); // Define the data using the vat
  89.         unsigned char* data = HLock(symPtrs[fileI]->handle);
  90.         data+=2; // Offset from VAT length data
  91.        
  92.         unsigned int dataLength = 0; // Define the length of the data
  93.         memcpy(&dataLength, data, sizeof(unsigned int));
  94.        
  95.         data+=2; // Offset from real length data
  96.         datas[fileI] = data;
  97.         dataLengths[fileI] = dataLength;
  98.     }
  99.  
  100.     ClrScr(); // Initial setup
  101.    
  102.     i = 0; // It seems volatile is persistent between program runs (or maybe only on tiemu?)
  103.     currentFile = 0; // ^
  104.    
  105.     INT_HANDLER oldInt5 = GetIntVec(AUTO_INT_5); // Save default stuff
  106.     INT_HANDLER onInt = GetIntVec(INT_VEC_ON_KEY_PRESS);
  107.     unsigned char oldStart = PRG_getStart();
  108.    
  109.     asm volatile("move.w #0x0200,%d0; trap #1"); // Set defaults to new stuff
  110.     SetIntVec(AUTO_INT_5, DrawFrameInt);
  111.     SetIntVec(INT_VEC_ON_KEY_PRESS, BreakDrawInt);
  112.     //start = 255 - ((8192 / 2^9) * 59 / FPS); (59 is a constant that i calculated: f2solve: 255 - ((8192 / 2^9) * x / 16) = 196, where 196 is known to work)
  113.     PRG_setStart(196);
  114.    
  115.     while(currentFile < TOTAL_STR);
  116.     GKeyFlush();
  117.  
  118.   asm volatile("move.w #0x0000,%d0; trap #1"); // Restore the program / defaults
  119.     SetIntVec(AUTO_INT_5, oldInt5);
  120.     SetIntVec(INT_VEC_ON_KEY_PRESS, onInt);
  121.     PRG_setStart(oldStart);
  122.    
  123.     for(fileI = 0; fileI < TOTAL_STR; fileI++) { // dealoc
  124.         HeapUnlock(symPtrs[fileI]->handle);
  125.     }
  126.    
  127.     return;
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement