Debugc.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. #include "include.hpp"
  2. #include "deb_comp.hpp"
  3. #ifdef DEBUG_C
  4. int debug_flag=0;
  5. /* A hugely complicated debug routine */
  6. #define ITEM_SECTIONS 7
  7. int open_for_write(char *);
  8. st_compact_item compact_items[] = { {0,1,"joey",C_MEGA_SET},
  9. {0,3,"foster",C_MEGA_SET},
  10. {0,16,"lamb",C_MEGA_SET},
  11. {0,23,"Text 1",C_FLAG},
  12. {0,44,"Talk 1",C_MEGA_SET},
  13. {0,45,"Talk 2",C_MEGA_SET},
  14. {0,46,"menu bar",C_FRAME},
  15. {0,47,"left_arrow",C_MEGA_SET},
  16. {0,66,"joeyb_menu",C_MEGA_SET},
  17. {0,67,"low_floor",C_MEGA_SET},
  18. {0,69,"stairs",C_MEGA_SET},
  19. {0,85,"bar",C_ACTION_SCRIPT},
  20. {0,90,"door",C_ACTION_SCRIPT},
  21. {0,105,"small_door",C_ACTION_SCRIPT},
  22. {0,111,"right_exit0",C_ACTION_SCRIPT},
  23. {0,122,"cancel_button",C_MEGA_SET},
  24. {0,136,"monitor 9",C_MEGA_SET},
  25. {1,4,"Mini_so",C_MEGA_SET},
  26. {1,6,"fan1",C_BASE_SUB},
  27. {1,15,"lazer",C_BASE_SUB},
  28. {1,20,"top_lift",C_ACTION_SCRIPT},
  29. {1,22,"liftbit",C_ACTION_SCRIPT},
  30. {1,23,"hole",C_ACTION_SCRIPT},
  31. {1,24,"top_barrel",C_ACTION_SCRIPT},
  32. {1,25,"loader",C_ACTION_SCRIPT},
  33. {1,26,"Jobsworth",C_MEGA_SET},
  34. {1,31,"panel",C_BASE_SUB},
  35. {1,32,"alarm_flash",C_BASE_SUB},
  36. {1,37,"dead_loader",C_BASE_SUB},
  37. {1,42,"steve_watch",C_BASE_SUB},
  38. {1,85,"screen0_low_logic",C_MEGA_SET},
  39. {1,207,"fan2",C_BASE_SUB},
  40. {1,209,"fan3",C_BASE_SUB},
  41. {1,211,"fan4",C_BASE_SUB},
  42. {1,213,"fan5",C_BASE_SUB},
  43. {1,215,"fan6",C_BASE_SUB},
  44. {1,217,"fan7",C_BASE_SUB},
  45. {1,225,"press",C_MEGA_SET},
  46. {2,19,"son 9",C_BASE_SUB},
  47. {2,100,"fans 9",0},
  48. {2,106,"scanner 9",C_BASE_SUB},
  49. {2,109,"dad 9",C_MEGA_SET},
  50. {2,117,"skorl_guard",C_MEGA_SET},
  51. {2,185,"anita",C_MEGA_SET},
  52. {2,193,"anita_spy",C_MEGA_SET},
  53. {3,93,"helga",C_ACTION_SCRIPT},
  54. {3,119,"burke",C_MEGA_SET},
  55. {4,57,"danielle",C_MEGA_SET},
  56. {5,332,"galagher",C_MEGA_SET},
  57. {0,0,"",0}
  58. };
  59. char *logic_list[] = { "return","l_script","l_ar","l_ar_anim","(none)","l_alt","l_anim","l_turning","(none)",
  60. "l_talk","l_listen","(none)","(none)","l_frames","l_pause","l_wait_sync","l_simple_anim",
  61. "(none)","(none)","(none)"};
  62. char * fetch_item_section(int);
  63. int initialise_file(void);
  64. void out(char *format,...);
  65. int file=0,entry_count=0;
  66. void debug_compact(char *compact_esi,char *message,char *compact_to_debug)
  67. {
  68. char *section;
  69. int count,section_no,item_no,found;
  70. st_compact compact;
  71. if (initialise_file() < 0)
  72. return;
  73. if ((int)(compact_to_debug))
  74. if (compact_to_debug!=compact_esi)
  75. return;
  76. /* List out the details of the current compact */
  77. /* First find out the name and number of this compact */
  78. found=0;
  79. for (section_no=0;(section_no<ITEM_SECTIONS)&&(!found);)
  80. { char *pointer;
  81. section=pointer=fetch_item_section(section_no);
  82. for (item_no=0;(*((int *)pointer)!=0x12345678)&&(!found)&&(item_no<1000);pointer+=4)
  83. if (*((int *)pointer)==(int)compact_esi)
  84. found=1;
  85. else item_no++;
  86. if (!found)
  87. section_no++;
  88. }
  89. for (found=count=0;(found==0)&&(compact_items[count].name[0]);)
  90. { if ((compact_items[count].section==section_no) && (compact_items[count].number==item_no))
  91. found=1;
  92. else count++;
  93. }
  94. if (!compact_items[count].name[0])
  95. out("**????????** (%s), address %x section %d entry %d ---> entry %d\r\n",message,compact_esi,
  96. section_no,item_no,entry_count++);
  97. else
  98. { if (compact_items[count].range == 0)
  99. return;
  100. out("**%s** (%s), address %x section %d entry %d ---> entry %d\r\n",compact_items[count].name,message,compact_esi,
  101. section_no,item_no,entry_count++);
  102. }
  103. /* Convert the compact to an internal c structure */
  104. compact.c_logic=*((short *)(compact_esi+C_LOGIC));
  105. compact.c_status=*((short *)(compact_esi+C_STATUS));
  106. compact.c_sync=*((short *)(compact_esi+C_SYNC));
  107. compact.c_screen=*((short *)(compact_esi+C_SCREEN));
  108. compact.c_place=*((short *)(compact_esi+C_PLACE));
  109. compact.c_get_to_table=(char *) *((int *)(compact_esi+C_GET_TO_TABLE));
  110. compact.c_xcood=*((short *)(compact_esi+C_XCOOD));
  111. compact.c_ycood=*((short *)(compact_esi+C_YCOOD));
  112. compact.c_frame=*((short *)(compact_esi+C_FRAME));
  113. compact.c_up_flag=*((short *)(compact_esi+C_UP_FLAG));
  114. compact.c_down_flag=*((short *)(compact_esi+C_DOWN_FLAG));
  115. compact.c_get_to_flag=*((short *)(compact_esi+C_GET_TO_FLAG));
  116. compact.c_flag=*((short *)(compact_esi+C_FLAG));
  117. compact.c_grafix_prog=*((int *)(compact_esi+C_GRAFIX_PROG));
  118. compact.c_offset=*((short *)(compact_esi+C_OFFSET));
  119. compact.c_mode = *((short *)(compact_esi+C_MODE));
  120. compact.c_base_sub = *((short *)(compact_esi+C_BASE_SUB));
  121. compact.c_base_sub_off = *((short *)(compact_esi+C_BASE_SUB+2));
  122. compact.c_action_sub = *((short *)(compact_esi+C_ACTION_SUB));
  123. compact.c_action_sub_off = *((short *)(compact_esi+C_ACTION_SUB+2));
  124. compact.c_get_to_sub = *((short *)(compact_esi+C_GET_TO_SUB));
  125. compact.c_get_to_sub_off = *((short *)(compact_esi+C_GET_TO_SUB+2));
  126. compact.c_extra_sub = *((short *)(compact_esi+C_EXTRA_SUB));
  127. compact.c_extra_sub_off = *((short *)(compact_esi+C_EXTRA_SUB+2));
  128. compact.c_dir = *((short *)(compact_esi+C_DIR));
  129. compact.c_request = *((short *)(compact_esi+C_REQUEST));
  130. compact.c_sp_col = *((short *)(compact_esi+C_SP_COL));
  131. compact.c_sp_text_id = *((short *)(compact_esi+C_SP_TEXT_ID));
  132. compact.c_waiting_for = *((short *)(compact_esi+C_WAITING_FOR));
  133. compact.c_anim_scratch = *((int *)(compact_esi+C_ANIM_SCRATCH));
  134. compact.c_mega_set = *((short *)(compact_esi+C_MEGA_SET));
  135. //if (compact.c_logic == 14) // l_pause
  136. // out("logic\t\t%s (%d)\r\n",logic_list[compact.c_logic],compact.c_flag);
  137. //else out("logic\t\t%s\r\n",logic_list[compact.c_logic]);
  138. //out("status\t\t%x\r\n",compact.c_status);
  139. //out("sync\t\t%x\r\n",compact.c_sync);
  140. //out("c_screen\t%d\r\n",compact.c_screen);
  141. out("c_place\t\t%d\r\n",compact.c_place);
  142. //out("get_to_table\t%x\r\n",compact.c_get_to_table);
  143. out("Coords\t\t%d,%d (%d,%d)\r\n",compact.c_xcood,compact.c_ycood,compact.c_xcood-128,compact.c_ycood-136);
  144. //out("Frame\t\t%d (set %d)\r\n",compact.c_frame&63,compact.c_frame>>6);
  145. if (compact_items[count].range>C_ACTION_SCRIPT)
  146. { //out("Up flag\t\t%d\r\n",compact.c_up_flag);
  147. //out("Down flag\t%d\r\n",compact.c_down_flag);
  148. //out("Get to flag\t%d\r\n",compact.c_get_to_flag);
  149. //out("Flag\t\t%d\r\n",compact.c_flag);
  150. }
  151. if (compact_items[count].range>C_FLAG)
  152. { //out("Offset\t\t%d (set %d)\r\n",compact.c_offset,compact.c_offset>>6);
  153. //out("Grafix prog\t%x",compact.c_grafix_prog);
  154. //out(" (%x) ",compact.c_grafix_prog?*((short *)(compact.c_grafix_prog)):0);
  155. //out(" (%x)\r\n",compact.c_grafix_prog?*((short *)(compact.c_grafix_prog+2)):0);
  156. out("mode\t\t%d\r\n",compact.c_mode);
  157. out("base sub\t%.4x (%.4x)\r\n",compact.c_base_sub,compact.c_base_sub_off);
  158. }
  159. if (compact_items[count].range>C_BASE_SUB)
  160. { out("action sub\t%.4x (%.4x)\r\n",compact.c_action_sub,compact.c_action_sub_off);
  161. out("get to sub\t%.4x (%.4x)\r\n",compact.c_get_to_sub,compact.c_get_to_sub_off);
  162. //out("extra sub\t%.4x (%.4x)\r\n",compact.c_extra_sub,compact.c_extra_sub_off);
  163. //out("Dir\t\t%x\r\n",compact.c_dir);
  164. //out("Request\t\t%x\r\n",compact.c_request);
  165. //out("Col\t\t%x\r\n",compact.c_sp_col);
  166. //out("Speech text id\t%x\r\n",compact.c_sp_text_id);
  167. //out("Waiting for\t%x\r\n",compact.c_waiting_for);
  168. //out("Anim scratch\t%x\r\n",compact.c_anim_scratch);
  169. //out("Mega set\t%x\r\n",compact.c_mega_set);
  170. }
  171. out("\r\n-------------------------------------------------------------\r\n");
  172. }
  173. int initialise_file()
  174. {
  175. char dfname[200];
  176. if (debug_flag >= 0) // if top bit clear, don't write anything. Bit 31 set after announces made
  177. return(-1); // This stops debug files being made when sky game run by mistake
  178. if (!file)
  179. { unlink(".\\debug");
  180. file = open_for_write(".\\debug");
  181. if (file<0)
  182. debug_flag &= 0x7ffffff;
  183. }
  184. return(1);
  185. }
  186. void out(char *format,...)
  187. {
  188. va_list arg_ptr;
  189. char buffer[200];
  190. va_start(arg_ptr,format);
  191. vsprintf(buffer,format,arg_ptr);
  192. write(file,buffer,strlen(buffer));
  193. flushall();
  194. }
  195. void debug_printf(char *format,...)
  196. {
  197. va_list arg_ptr;
  198. char buffer[200];
  199. va_start(arg_ptr,format);
  200. vsprintf(buffer,format,arg_ptr);
  201. if (initialise_file() < 0)
  202. return;
  203. write(file,buffer,strlen(buffer));
  204. write(file,"\r\n",2);
  205. flushall();
  206. }
  207. #define GRID_W 42
  208. #define GRID_H 26
  209. #define BLOCK_SIZE 5
  210. //extern int debug_flag;
  211. void dump_file(char *name,char *data,int len)
  212. {
  213. int file;
  214. file = open(name,O_WRONLY|O_CREAT|O_TRUNC,0666);
  215. write(file,data,len);
  216. close(file);
  217. }
  218. //void voc_chick_file(int number,char * addr,int size)
  219. //{
  220. //
  221. //char buffer[20];
  222. //
  223. //sprintf(buffer,"vocchick.%d",number);
  224. //
  225. //int file = open(buffer,O_WRONLY|O_CREAT|O_TRUNC,0666);
  226. //if (file<0)
  227. //{ printf("guuuuurgggh\r\n");
  228. // exit(22);
  229. //}
  230. //write(file,addr,size);
  231. //close(file);
  232. //
  233. //}
  234. #endif
  235. //;--------------------------------------------------------------------------------------------------
  236. #ifdef FILE_ORDER_CHK
  237. #define DONT_SHOW_ALL // When not set, show all loaded files (for sorting)
  238. // When set show jump files (checking)
  239. //#define JUST_LOADERS // show just what we are loading
  240. // Show what files are loaded and in what order
  241. int *loaded_list = NULL;
  242. int max_loaded_file;
  243. int file_position = 0;
  244. int current_file=0,last_file,on_room_change = 0,current_game_room = 0,next_file_is_repeatable = 0,repeated_file;
  245. char *file_with_set(int);
  246. void this_file_loaded(int file)
  247. {
  248. int count;
  249. debug_printf("Load %s",file_with_set(file));
  250. last_file = current_file;
  251. current_file = file;
  252. if (on_room_change)
  253. debug_printf("*>Room change to %d with file %s",current_game_room,file_with_set(file));
  254. if (loaded_list)
  255. { if (file >= max_loaded_file)
  256. { loaded_list = realloc(loaded_list,(file+1)*sizeof(int));
  257. for (count = max_loaded_file; count <= file; count++)
  258. loaded_list[count] = 0;
  259. max_loaded_file = file;
  260. }
  261. }
  262. else
  263. { loaded_list = malloc((file+1)*sizeof(int));
  264. for (count = 0; count <= file; count++)
  265. loaded_list[count] = 0;
  266. max_loaded_file = file;
  267. }
  268. switch(loaded_list[file])
  269. { case 0:
  270. loaded_list[file] = 1;
  271. repeated_file = 0;
  272. break;
  273. case 1:
  274. if (!next_file_is_repeatable)
  275. if ( (current_file < 60000) || (current_file > 60069) ) // Grids are often reloaded
  276. debug_printf("Repeated file %s",file_with_set(current_file));
  277. loaded_list[file] = 2;
  278. // no break;
  279. default:
  280. repeated_file = 1;
  281. break;
  282. }
  283. next_file_is_repeatable = 0;
  284. }
  285. void position_file(int new_position)
  286. {
  287. // Game is lseeking
  288. // Show up file if a jump is necessary or if we haven't sorted the files
  289. #ifndef JUST_LOADERS
  290. #ifdef DONT_SHOW_ALL
  291. if (new_position != file_position)
  292. #endif
  293. // Repeated files have been mentioned elsewhere
  294. { if ( (!on_room_change) && (!repeated_file) )
  295. debug_printf("Move : %s (after %s)",
  296. file_with_set(current_file),file_with_set(last_file));
  297. file_position = new_position;
  298. }
  299. #endif
  300. on_room_change = 0;
  301. }
  302. void load_file_data(int size)
  303. {
  304. // game is loading file
  305. file_position += size;
  306. }
  307. void lseek_allowed(int new_room) // lseek allowed on room changes
  308. {
  309. current_game_room = new_room;
  310. on_room_change = 1;
  311. }
  312. void next_file_repeatable()
  313. {
  314. next_file_is_repeatable = 1;
  315. }
  316. char *file_with_set(int file)
  317. {
  318. static char fred1[20];
  319. static char fred2[20];
  320. static int char_switch = 0;
  321. char *jon;
  322. if (char_switch)
  323. jon = fred1;
  324. else jon = fred2;
  325. char_switch = 1-char_switch;
  326. if (file < 50000)
  327. sprintf(jon,"%d,%d",file/2048,file%2048);
  328. else sprintf(jon,"%d",file);
  329. return(jon);
  330. }
  331. #endif
  332.