Create Variable.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Create a variable using functions from vat.h
  2. #define USE_TI89 // Compile for TI-89
  3. #define USE_TI92PLUS // Compile for TI-92 Plus
  4. #define USE_V200 // Compile for V200
  5. #define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
  6. #define MIN_AMS 100 // Compile for AMS 1.00 or higher
  7. #define SAVE_SCREEN // Save/Restore LCD Contents
  8. #include <tigcclib.h> // Include All Header Files
  9. HANDLE CreateFile (const char *FileName)
  10. // Returns a handle, H_NULL in case of error
  11. {
  12. HANDLE h;
  13. SYM_ENTRY *sym_entry;
  14. char str[30], *sptr = str;
  15. *sptr = 0; while ((*++sptr = *FileName++));
  16. if (!(h = HeapAlloc (HeapMax ()))) return H_NULL;
  17. if (!(sym_entry = DerefSym (SymAdd (sptr))))
  18. {
  19. HeapFree (h);
  20. return H_NULL;
  21. }
  22. *(long*) HeapDeref (sym_entry->handle = h) = 0x00010000;
  23. return h;
  24. }
  25. void AppendCharToFile (HANDLE h, unsigned char c)
  26. {
  27. char *base = HeapDeref(h);
  28. unsigned short len = *(unsigned short*)base;
  29. if (len > HeapSize(h) - 10) return;
  30. *(unsigned short*)base = len + 1;
  31. base[len+2] = c;
  32. }
  33. void AppendBlockToFile (HANDLE h, void *addr, unsigned short len)
  34. {
  35. unsigned short i;
  36. for (i = len; i; i--) AppendCharToFile (h, *((char*)addr)++);
  37. }
  38. void CloseFile (HANDLE h)
  39. {
  40. AppendCharToFile (h,0); AppendCharToFile (h,0x2D);
  41. HeapUnlock (h);
  42. HeapRealloc (h, *(unsigned short*)HeapDeref(h) + 3);
  43. }
  44. void _main(void)
  45. {
  46. static char s[] = "Hello world!";
  47. HANDLE h;
  48. h = CreateFile ("example");
  49. AppendBlockToFile (h, s, 12);
  50. CloseFile (h);
  51. }