Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define USE_TI89
- #define SAVE_SCREEN
- #include <kbd.h>
- #include <system.h>
- #include <intr.h>
- #include <graph.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <vat.h>
- #include <alloc.h>
- #include "extgraph.h" // Made by TICT. Thank you TICT HQ and Lionel Debroux :)
- const unsigned char WIDTH = 160; // Replace these values.
- const unsigned char HEIGHT = 100;
- const unsigned char FPS = 10;
- void resetTimer(float* extra) {
- OSFreeTimer(USER1_TIMER);
- float toWait = (float) 311 / (float) FPS; // 20 = OSC2 / 2^9 , therefore OSC2 = 10240. 320 = 10000 / 2^5. 312.5 is how many cycles to wait for 1 second. (not exact???)
- if (*extra >= 1) { // 295, 305, 308, 309, 310: too fast.
- *extra -= 1; // 312.5: too slow.
- toWait += 1;
- }
- short shortToWait = (short) toWait;
- OSRegisterTimer(USER1_TIMER, shortToWait);
- *extra += toWait - (float) shortToWait; // Keep track of decimal time that should have been waited. (more accurate fps hopefully)
- return;
- }
- unsigned short waitForFrame(float* extra) {
- while (!OSTimerExpired(USER1_TIMER));
- if (OSCheckBreak()) { // Did you press ON
- return 54321;
- }
- resetTimer(extra);
- return kbhit();
- }
- unsigned short onFrameEnd(unsigned char* x0, unsigned char* x1, unsigned char* y0, unsigned char* currentColor, unsigned int* currentFrame, float* extra) {
- *y0 = 0;
- *x0 = 0;
- *x1 = 0;
- unsigned short key = waitForFrame(extra);
- *currentFrame = *currentFrame + 1;
- *currentColor = 0;
- return key;
- }
- short handleInput(unsigned short key, int* fileI, int totalFileI) {
- if (key == 13) { // Pause the video
- GKeyFlush();
- while (!kbhit()); // Wait for unpause keypress
- GKeyFlush();
- } else if (key == 344) { // Forward
- *fileI = min(totalFileI - 1, *fileI);
- GKeyFlush();
- return 1;
- } else if (key == 338) { // Backward
- *fileI = max(0, *fileI - 2);
- GKeyFlush();
- return 1;
- }
- GKeyFlush();
- return 0;
- }
- SYM_ENTRY* openBinVAT(char *varName) { // Quicker file reader than default fopen. Thanks Lionel
- SYM_ENTRY *symptr = DerefSym(SymFind(SYMSTR(varName)));
- if (!symptr) {
- printf("%s not found\n", varName);
- ngetchx();
- }
- return symptr;
- }
- void _main(void) {
- ClrScr();
- PRG_setRate(0); // Initial setup
- OSFreeTimer(APD_TIMER);
- OSRegisterTimer(APD_TIMER, (unsigned long) 10000000); // Is there a better way to do this. :[
- float extra = 0;
- resetTimer(&extra);
- const unsigned char TOTAL_STR = 10; // Replace these values too.
- const char *VARNAME_STRS[] = {"ba\\px1","ba\\px2","ba\\px3","ba\\px4","ba\\px5","ba\\px6","ba\\px7","ba\\px8","ba\\px9","ba\\px10",}
- // Start for file analysis
- int fileI;
- for(fileI = 0; fileI < TOTAL_STR; fileI++) { // Go through every file (We can assume frame will not be interrupted).
- unsigned char x0 = 0, x1 = 0, y0 = 0, currentColor = 0, lastByte = 0; // Initialize vars for writing
- unsigned int currentFrame = 0, i = 0;
- SYM_ENTRY *dataSymPtr = openBinVAT(VARNAME_STRS[fileI]); // Define the data using the vat
- unsigned char* data = HLock(dataSymPtr->handle);
- data+=2;
- unsigned int dataLength = 0; // Define the length of the data
- memcpy(&dataLength, data, sizeof(unsigned int));
- for (i = 2; i < dataLength; i++) { // Display data
- unsigned char nextByte = data[i];
- if (y0 == HEIGHT) {
- unsigned short key = onFrameEnd(&x0, &x1, &y0, ¤tColor, ¤tFrame, &extra);
- if (key == 54321) { // Must be broken. (on was pressed)
- fileI = TOTAL_STR;
- break;
- } else if (key) {
- if (handleInput(key, &fileI, TOTAL_STR)) { // Did you go forward or backword? then break this subloop.
- break; // Slightly scuffed, just go to the end of the chunk loop.
- }
- }
- }
- unsigned char newColor = !currentColor; // Defined here so it doesnt have to be recalculated.
- if (nextByte == 255 || (lastByte < WIDTH && nextByte < lastByte)) { // New horizontal line? Then finish the previous row.
- FastDrawHLine_R(LCD_MEM, x0, WIDTH - 1, y0, newColor);
- x0 = 0;
- y0++;
- x1 = 0;
- }
- if (nextByte < WIDTH) { // This is the normal line draw. Majority
- x1 = nextByte;
- FastDrawHLine_R(LCD_MEM, x0, x1, y0, newColor);
- currentColor = newColor;
- x0 = x1;
- } else if (nextByte == 254) { // This is if the frame has not changed. Just wait.
- waitForFrame(&extra);
- } else if (nextByte == 253) { // Draw a full black screen, and wait
- unsigned char j;
- for (j = 0; j < HEIGHT; j++) {
- FastDrawHLine_R(LCD_MEM, 0, WIDTH - 1, j, 1);
- }
- waitForFrame(&extra);
- } else if (nextByte == 252) { // Draw an empty frame, wait
- ClrScr();
- waitForFrame(&extra);
- }
- lastByte = nextByte;
- }
- HeapUnlock(dataSymPtr->handle);
- }
- // End of file analysis
- PRG_setRate(1);
- OSFreeTimer(APD_TIMER);
- OSRegisterTimer(APD_TIMER, 20 * 360);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement