main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <errno.h>
  6. #include <unistd.h>
  7. #include <time.h>
  8. #include "reznames.h"
  9. void *RezPointers[509];
  10. void *ArtPtr;
  11. void *ASPtr;
  12. int QuitFlag = 0;
  13. char Inventory[19];
  14. int IconPic[7];
  15. int FrameStop;
  16. int GameMode;
  17. int DaelonCntr;
  18. int StatPlay;
  19. int Spell1;
  20. int Spell2;
  21. int Spell3;
  22. int ItemInhibit;
  23. int ASMode;
  24. int ATimerFlag;
  25. int BTimerFlag;
  26. int CTimerFlag;
  27. int SkylarTimerFlag;
  28. int ATimer;
  29. int BTimer;
  30. int CTimer;
  31. int SkylarTimer;
  32. int TideCntl;
  33. int MapEx;
  34. int Health;
  35. int HealthOld;
  36. int HealthTmr;
  37. int TreeEyeTimer;
  38. int TreeHGTimer;
  39. int TreeHGUPic;
  40. int TreeLeftPic;
  41. int TreeRightPic;
  42. int TreeRightSta;
  43. int TSIconOnly;
  44. int Help;
  45. int Eye;
  46. int Replay;
  47. int Pouch;
  48. int NoIFScreen;
  49. int NoMusic;
  50. int FstFwd;
  51. int GameMode;
  52. void str_toupper(char *str) {
  53. int c = 0;
  54. while (str[c]) {
  55. str[c] = toupper(str[c]);
  56. ++c;
  57. }
  58. }
  59. void* LoadAResource(int reznum) {
  60. // Weird off-by-one here?
  61. reznum--;
  62. void *p;
  63. char* path = strdup(RezNames[reznum]);
  64. str_toupper(path);
  65. printf("Loading resource: %i (%s)\n", reznum, path);
  66. if(! RezPointers[reznum]) {
  67. FILE *f = fopen(path, "rb");
  68. if(! f) {
  69. perror("Failed to open file");
  70. exit(1);
  71. }
  72. fseek(f, 0L, SEEK_END);
  73. int size = ftell(f);
  74. rewind(f);
  75. p = malloc(size);
  76. fread(p, size, 1, f);
  77. RezPointers[reznum] = p;
  78. fclose(f);
  79. }
  80. free(path);
  81. return p;
  82. }
  83. void ReleaseAResource(int reznum) {
  84. // Weird off-by-one here?
  85. reznum--;
  86. char* path = strdup(RezNames[reznum]);
  87. str_toupper(path);
  88. printf("Freeing resource: %i (%s)\n", reznum, path);
  89. free(RezPointers[reznum]);
  90. RezPointers[reznum] = NULL;
  91. free(path);
  92. }
  93. void SetupPics() {
  94. // Well, this seems to be all...
  95. ArtPtr = LoadAResource(0x97); // Pics\kingArt.art
  96. }
  97. void ShowPic(int reznum) {
  98. printf("Showing picture: %i\n", reznum);
  99. // EraseCursor()
  100. void *resource = LoadAResource(reznum);
  101. // pal = ParseLBM(resource, "CMAP")
  102. // SetPaletteRGB(pal)
  103. // body = ParseLBM(resource, "BODY")
  104. // DrawFullPicPack(body)
  105. ReleaseAResource(reznum);
  106. }
  107. void InitTools() {
  108. // GoMCGA()
  109. // InitMouse()
  110. // StartTimers()
  111. // FadeToBlack2()
  112. ShowPic(0x7C); // Pics\KLogo.lbm
  113. }
  114. void TitlePage() {
  115. // FadeToBlack2()
  116. // PlayMovie(0xC8)
  117. // FadeToBlack2()
  118. // PlayMovie(0xCE)
  119. // FadeToBlack2()
  120. // PlayMovie(0xC6)
  121. }
  122. void EnAll() {
  123. Help = 1;
  124. Eye = 1;
  125. Replay = 1;
  126. Pouch = 1;
  127. FstFwd = 1;
  128. }
  129. void InitPlay() {
  130. memset(Inventory, 0, sizeof(Inventory));
  131. memset(ArtPtr + 4, 0, 0xC6);
  132. for (int i = 0; i < 7; ++i) {
  133. IconPic[i] = 0x59 + i;
  134. }
  135. FrameStop = 0;
  136. GameMode = 0;
  137. DaelonCntr = 0;
  138. StatPlay = 0x0A;
  139. Spell1 = 0;
  140. Spell2 = 0;
  141. Spell3 = 0;
  142. ItemInhibit = 0;
  143. ASMode = 0;
  144. ATimerFlag = 0;
  145. BTimerFlag = 0;
  146. CTimerFlag = 0;
  147. SkylarTimerFlag = 0;
  148. ATimer = 0;
  149. BTimer = 0;
  150. CTimer = 0;
  151. SkylarTimer = 0;
  152. TideCntl = 0;
  153. MapEx = 0;
  154. Health = 0x0C;
  155. HealthOld = 1;
  156. HealthTmr = 0;
  157. TreeEyeTimer = 0;
  158. TreeHGTimer = 0;
  159. TreeHGUPic = 0x93;
  160. TreeLeftPic = 0;
  161. TreeRightPic = 0;
  162. TreeRightSta = 1;
  163. TSIconOnly = 0;
  164. EnAll();
  165. Pouch = 1;
  166. // Why here? Why NOT here
  167. srand(time(NULL));
  168. NoIFScreen = 1;
  169. NoMusic = 0;
  170. FstFwd = 1;
  171. free(ASPtr);
  172. ASPtr = 0;
  173. }
  174. void InitHelp() {
  175. GameMode = 0;
  176. }
  177. void GameHelp() {
  178. if (GameMode == 0)
  179. return;
  180. // Do help screen
  181. }
  182. void GPLogic1() {
  183. printf("GPLogic1()\n");
  184. if (StatPlay == 0x79) {
  185. // Switch on UserInput
  186. }
  187. }
  188. void DrawIcon(int offset, int width, void* data) {
  189. // VGA mode 0x13 encoded bitmap
  190. }
  191. int main() {
  192. chdir("game");
  193. SetupPics();
  194. InitTools();
  195. TitlePage();
  196. // while (QuitFlag == 0) {
  197. InitPlay();
  198. InitHelp();
  199. GameHelp();
  200. // if (GameMode == 0)
  201. // continue;
  202. //
  203. if (StatPlay < 0xFA)
  204. GPLogic1();
  205. // }
  206. }