Launcher.c 904 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Launcher for program called "example"
  2. #define USE_TI89
  3. #define USE_TI92PLUS
  4. #define USE_V200
  5. #include <tigcclib.h>
  6. #define fatal(s) ({ST_showHelp (s); return;})
  7. void _main (void)
  8. {
  9. char *fptr, *cptr;
  10. unsigned short plen;
  11. SYM_ENTRY *SymPtr = DerefSym (SymFind (SYMSTR ("example")));
  12. HANDLE h;
  13. if (!SymPtr) fatal ("Program not found");
  14. h = SymPtr->handle;
  15. if (HeapGetLock (h))
  16. {
  17. cptr = fptr = HeapDeref (h);
  18. h = 0;
  19. }
  20. else
  21. {
  22. cptr = fptr = HLock (h);
  23. }
  24. plen = *(short*)(cptr) + 3;
  25. if (SymPtr->flags.bits.archived)
  26. {
  27. if (!(cptr = malloc (plen)))
  28. {
  29. if (h) HeapUnlock (h);
  30. fatal ("Out of memory");
  31. }
  32. memcpy (cptr, fptr, plen);
  33. }
  34. enter_ghost_space ();
  35. EX_patch (cptr + 0x40002, cptr + plen + 0x3FFFE);
  36. ASM_call (cptr + 0x40002);
  37. if (h) HeapUnlock (h);
  38. if (cptr != fptr) free (cptr);
  39. }