PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Pristine/PLAY/VIEW.C

http://github.com/AnimatorPro/Animator-Pro
C | 577 lines | 447 code | 103 blank | 27 comment | 85 complexity | 1f007fff30ed7a37a93376c35bd4582e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #include <time.h> /* for time functions */
  2. #ifndef SLUFF
  3. #include <dos.h> /* for sound test */
  4. #endif SLUFF
  5. #include "jimk.h"
  6. #include "fli.h"
  7. #include "flicmenu.h"
  8. #include "prjctor.h"
  9. extern char cbrk_hit;
  10. struct fli_head fh;
  11. long frame1off;
  12. int cur_frame_num;
  13. int user_defined_speed;
  14. int orig_speed;
  15. char is_gif;
  16. extern char notice_keys;
  17. extern char stop_bat;
  18. extern int sys5;
  19. extern int frame_val;
  20. extern char file_is_loaded;
  21. extern Video_form alt_vf;
  22. extern unsigned char alt_cmap[COLORS*3];
  23. extern int loaded_file_fd;
  24. extern char global_file_name[];
  25. extern struct qslider speed_sl;
  26. extern long get80hz();
  27. extern WORD mouse_connected;
  28. char ctrl_hit;
  29. int ascii_value;
  30. int ctrl_lock;
  31. #define CTRL 0x0004
  32. long clock1;
  33. view_fli_loop(name, screen, num_loops)
  34. char *name;
  35. Video_form *screen;
  36. int num_loops;
  37. {
  38. int fd;
  39. int i, k, last_loop=0;
  40. /* screen->p = VGA_SCREEN; */ /* test */
  41. if (num_loops >= INFINITE_LOOP) num_loops=INFINITE_LOOP;
  42. if ((fd = read_fli_head(name, &fh)) == 0)
  43. return(0);
  44. clock1 = get80hz();
  45. mouse_on = 0;
  46. if (!read_next_frame(name,fd,screen,1)) /* read in frame 0 */
  47. goto END;
  48. /* non-seek just to get position */
  49. frame1off = jseek(fd, 0L, 1/*from current position*/);
  50. orig_speed = fh.speed;
  51. if (user_defined_speed!=USE_SET_SPEED) fh.speed=user_defined_speed;
  52. k=0;
  53. for (;;)
  54. {
  55. if (num_loops!=INFINITE_LOOP)
  56. {
  57. last_loop = (k==num_loops-1) ? 1:0;
  58. if (k >= num_loops) break;
  59. k++;
  60. }
  61. if (jseek(fd, frame1off, 0) == -1) /* seek to frame 1 */
  62. break;
  63. for (i=1; i<=fh.frame_count; i++)
  64. {
  65. if (last_loop && i==fh.frame_count) continue; /* dont end on first frame */
  66. if (!read_next_frame(name,fd,screen,1))
  67. goto END; /*break; */
  68. clock1 += fh.speed;
  69. if (!wait_til2(clock1))
  70. goto END; /* break; */
  71. /* in case we took longer than fh.speed ticks to load and
  72. display it, need next line so don't try to rush next frame
  73. to make up for it... */
  74. if (clock1 > get80hz())
  75. clock1 = get80hz();
  76. }
  77. }
  78. END:
  79. jclose(fd);
  80. mouse_on = 1;
  81. }
  82. #ifndef EVER
  83. #define UP 0
  84. #define ZEROFLAG 64
  85. get_key()
  86. {
  87. union regs r;
  88. key_hit = 0;
  89. r.b.ah = 0x1;
  90. if (!(sysint(0x16,&r,&r)&ZEROFLAG))
  91. {
  92. key_hit = 1;
  93. r.b.ah = 0;
  94. sysint(0x16,&r,&r);
  95. key_in = r.w.ax;
  96. }
  97. /** ldg */
  98. /* function 16H ah=2; returns in al the ROM BIOS keyobard flags */
  99. ctrl_hit=UP; /* ldg ????????????????? */
  100. r.b.ah = 0x02;
  101. sysint(0x16, &r, &r);
  102. ctrl_hit = (r.b.al & 0x04) ? 1: 0;
  103. }
  104. #endif EVER
  105. wait_til2(time)
  106. long time;
  107. {
  108. for (;;)
  109. {
  110. check_button();
  111. if (notice_keys && RJSTDN)
  112. return(0);
  113. get_key();
  114. if (key_hit) /* a keystroke is waiting */
  115. {
  116. ctrl_hit = (bioskey(2) & CTRL); /* if was control key */
  117. ascii_value = ((key_in<<8)>>8);
  118. /* REPALCXE BIOSKEY 2 */
  119. return(key_effect(key_in));
  120. }
  121. else key_hit=0;
  122. if (get80hz() >= time)
  123. return(1);
  124. }
  125. }
  126. key_effect(key)
  127. int key; /* scancode of key hit */
  128. {
  129. /* interrupt if the ctrl key is held down with keystroke */
  130. if (notice_keys && (key==BREAK_PROCESS))
  131. {
  132. stop_bat=1;
  133. return(0);
  134. }
  135. if (ctrl_hit && 1<=ascii_value && ascii_value<=26)
  136. {
  137. /* DUMPINT("ctrl hit of key in range of A to Z",0); */
  138. if (notice_keys)
  139. {
  140. ctrl_lock=key;
  141. /* DUMPINT("ctrl lock set to keystroke--no notice keys",ctrl_lock); */
  142. notice_keys=0;
  143. }
  144. else /* dont notice keys is effective */
  145. {
  146. /* DUMPINT("DONT notice keys is in effect--",0); */
  147. if (key==ctrl_lock)
  148. {
  149. notice_keys=1;
  150. /* DUMPINT("... but the key hit makes us agaion notice keys",0); */
  151. }
  152. else
  153. {
  154. /* DUMPINT("returing 0 here",0); */
  155. return(1); /* return(0); */
  156. }
  157. }
  158. return(1);
  159. }
  160. if (notice_keys)
  161. {
  162. /* DUMPINT("its notice keys II",0); */
  163. if (key==BACKSPACE)
  164. {
  165. freeze_frame();
  166. return(1);
  167. }
  168. if (!is_gif)
  169. {
  170. if (is_funckey(key) || IS_PLUS(key) || IS_MINUS(key) )
  171. {
  172. do_speed_change(key);
  173. return(1);
  174. }
  175. else return(0);
  176. }
  177. else return(0);
  178. }
  179. return(1);
  180. }
  181. break_key()
  182. {
  183. check_button();
  184. if (notice_keys && RDN)
  185. return(0);
  186. if (bioskey(1)) /* a keystroke is waiting */
  187. {
  188. key_hit=1;
  189. key_in=bioskey(0); /* get the key */
  190. ctrl_hit = (bioskey(2) & CTRL); /* if was control key */
  191. ascii_value = ((key_in<<8)>>8);
  192. return(key_effect(key_in));
  193. }
  194. else
  195. {
  196. key_hit=0;
  197. return(1);
  198. }
  199. }
  200. freeze_frame()
  201. {
  202. int old_state = mouse_on;
  203. if (mouse_connected) mouse_on=0;
  204. wait_click();
  205. clock1 = get80hz();
  206. mouse_on=old_state;
  207. }
  208. do_speed_change(key)
  209. int key;
  210. {
  211. switch(key)
  212. {
  213. case PLUS_KEY:
  214. case NUM_PLUS_KEY:
  215. fh.speed =( (fh.speed+1 < speed_sl.max) ? fh.speed+1: speed_sl.max);
  216. break;
  217. case MINUS_KEY:
  218. case NUM_MINUS_KEY:
  219. fh.speed =( (fh.speed-1 > speed_sl.min) ? fh.speed-1: speed_sl.min);
  220. break;
  221. case F1:
  222. fh.speed = 0;
  223. break;
  224. case F2:
  225. fh.speed = 3;
  226. break;
  227. case F3:
  228. fh.speed = 6;
  229. break;
  230. case F4:
  231. fh.speed = 9;
  232. break;
  233. case F5:
  234. fh.speed = 12;
  235. break;
  236. case F6:
  237. fh.speed = 18;
  238. break;
  239. case F7:
  240. fh.speed = 24;
  241. break;
  242. case F8:
  243. fh.speed = 36;
  244. break;
  245. case F9:
  246. fh.speed = 48;
  247. break;
  248. case F10:
  249. fh.speed = orig_speed;
  250. break;
  251. default:
  252. break;
  253. }
  254. }
  255. play_gif(gif_name,pause_val,trans_in,trans_out)
  256. char gif_name[];
  257. double pause_val;
  258. int trans_in, trans_out;
  259. {
  260. long start_time, cur_time;
  261. if (pause_val==0) pause_val=DEFAULT_GIF_PAUSE;
  262. load_gif(gif_name,&vf); /* was alt_vf */
  263. time(&start_time);
  264. cur_time=start_time;
  265. is_gif=1; /* global flag for changing break_key behavior */
  266. while ( difftime(cur_time, start_time) < pause_val)
  267. {
  268. if (!break_key()) break;
  269. time(&cur_time);
  270. }
  271. if (trans_out==R_FADEOUT) transit_to_white(DEFAULT_TRANSIT_CYCLE,2);
  272. return(0);
  273. }
  274. play_pic(pic_file,speed1,pause1,num_loops,trans_in,trans_out, use_defs)
  275. char pic_file[];
  276. int use_defs; /* if 1 then use default valuse */
  277. int speed1,pause1,num_loops,trans_in,trans_out;
  278. {
  279. if (suffix_in(pic_file, ".GIF"))
  280. {
  281. if (use_defs)
  282. play_gif(pic_file,(double)DEFAULT_PAUSE, DEFAULT_IN_TRANS,
  283. DEFAULT_OUT_TRANS);
  284. else
  285. play_gif(pic_file,(double)pause1,trans_in,trans_out);
  286. }
  287. else if (suffix_in(pic_file, ".FLI"))
  288. {
  289. /* notice_keys=1; */
  290. if (use_defs)
  291. play_fli(pic_file,DEFAULT_SPEED,(double)DEFAULT_PAUSE,
  292. INFINITE_LOOP,DEFAULT_IN_TRANS,DEFAULT_OUT_TRANS);
  293. else
  294. play_fli(pic_file,speed1,(double)pause1,num_loops, trans_in, trans_out);
  295. }
  296. else return(0);
  297. return(1);
  298. }
  299. load_frame1(name,screen,hdware_update,close_f)
  300. Video_form *screen;
  301. char *name;
  302. int hdware_update;
  303. int close_f; /* if 1 then close the file after loading */
  304. {
  305. if (file_is_loaded) close_file();
  306. if ((loaded_file_fd = read_fli_head(name, &fh)) == 0)
  307. return(0);
  308. file_is_loaded=1;
  309. if (!read_next_frame(name,loaded_file_fd,screen,hdware_update)) /* read in frame 0 */
  310. goto END;
  311. frame1off = jseek(loaded_file_fd, 0L, 1/*from current position*/);
  312. if (jseek(loaded_file_fd, frame1off, 0) == -1) /* seek to frame 1 */
  313. goto END;
  314. set_frame_val(1);
  315. if (close_f) close_file();
  316. return(1); /* a good load */
  317. END:;
  318. close_file();
  319. return(0);
  320. }
  321. advance_frame(screen,hdware_update)
  322. Video_form *screen;
  323. int hdware_update;
  324. {
  325. /*notice_keys=0; */
  326. if (cur_frame_num < fh.frame_count)
  327. {
  328. if (!read_next_frame(global_file_name,loaded_file_fd,screen,
  329. hdware_update))
  330. return(0);
  331. set_frame_val(cur_frame_num+1);
  332. }
  333. else /* loops around */
  334. {
  335. set_frame_val(1);
  336. read_next_frame(global_file_name,loaded_file_fd,screen,hdware_update);
  337. jseek(loaded_file_fd, frame1off, 0); /* seek to frame 1 */
  338. }
  339. return(1);
  340. }
  341. goto_frame(old_val,new_val)
  342. int old_val;
  343. int new_val;
  344. {
  345. int i;
  346. int val;
  347. if (!file_is_loaded) return;
  348. if (new_val < 0 || new_val+1==cur_frame_num) return;
  349. if (new_val==old_val+1) /* optimize--case where its a single advance */
  350. {
  351. advance_frame(&vf,1);
  352. return;
  353. }
  354. new_val++;
  355. copy_form(&vf, &alt_vf);
  356. #ifdef OLDWAY
  357. copy_cmap(vf.cmap,alt_vf.cmap);
  358. copy_structure(vf.p, alt_vf.p, SCREEN_SIZE);
  359. #endif OLDWAY
  360. if (new_val > cur_frame_num)
  361. {
  362. val=new_val - cur_frame_num;
  363. for (i=1; i<= val; i++)
  364. advance_frame(&alt_vf,0);
  365. /* advance_frame(&alt_vf); */
  366. wait_vblank();
  367. copy_form(&alt_vf,&vf);
  368. see_cmap();
  369. }
  370. else /* (new_val < cur_frame_num) so go backwards */
  371. {
  372. val=fh.speed;
  373. close_file();
  374. load_frame1(global_file_name,&alt_vf,0,0);
  375. for (i=1; i< new_val; i++)
  376. advance_frame(&alt_vf,0);
  377. wait_vblank();
  378. copy_form(&alt_vf, &vf);
  379. see_cmap();
  380. #ifdef OLDWAY
  381. copy_structure(alt_vf.p,vf.p, SCREEN_SIZE);
  382. #endif OLDWAY
  383. fh.speed=val;
  384. }
  385. }
  386. prev_frame()
  387. {
  388. int new_val;
  389. int old_val;
  390. if (!file_is_loaded) return;
  391. old_val=frame_val;
  392. if (frame_val-1 < 0)
  393. new_val=fh.frame_count-1;
  394. else
  395. new_val=frame_val-1;
  396. hide_mp();
  397. goto_frame(old_val,new_val);
  398. draw_mp();
  399. }
  400. play_fli(pic_file,speed1,pause1,num_loops,trans_in,trans_out)
  401. char pic_file[];
  402. int speed1,num_loops,trans_in,trans_out;
  403. double pause1;
  404. {
  405. long start_time, cur_time;
  406. user_defined_speed=speed1;
  407. if (trans_in==R_FADEIN) transit_from_white(pic_file,DEFAULT_TRANSIT_CYCLE,2);
  408. view_fli_loop(pic_file, &vf,num_loops);
  409. if (pause1)
  410. {
  411. time(&start_time);
  412. cur_time=start_time;
  413. is_gif=0;
  414. while ( difftime(cur_time, start_time) < pause1)
  415. {
  416. if (!break_key()) break;
  417. time(&cur_time);
  418. }
  419. }
  420. if (trans_out==R_FADEOUT) transit_to_white(DEFAULT_TRANSIT_CYCLE,2);
  421. }
  422. transit_from_white(file_name, cycles, wait_time)
  423. char *file_name;
  424. int cycles;
  425. int wait_time;
  426. {
  427. UBYTE *d, *s;
  428. int i, k;
  429. d=vf.cmap;
  430. for (i=0; i < COLORS * 3; i++) *d++ = 63; /* set screen to white */
  431. wait_sync();
  432. jset_colors(0, COLORS, vf.cmap);
  433. load_frame1(file_name,&alt_vf,0,1);
  434. copy_structure(alt_vf.p,vf.p, SCREEN_SIZE); /* copy picture to screen */
  435. for (k=cycles; k >= 1; k--)
  436. {
  437. s=vf.cmap; /* start map & map that goes to screen each cycle */
  438. d=alt_cmap; /* destination of color transition */
  439. for (i=0; i < COLORS * 3; i++, s++, d++) *s = *s - (*s - *d )/k;
  440. delay(wait_time);
  441. wait_sync();
  442. jset_colors(0, COLORS, vf.cmap);
  443. }
  444. }
  445. transit_to_white(cycle,wait_time)
  446. /* take the vf.cmp and graduate to white (= 63,63,63) */
  447. int wait_time; /* # of milliseconds to wait between transitions */
  448. int cycle; /* the number of cycles over which to make the transition */
  449. {
  450. UBYTE *d;
  451. int i,k;
  452. copy_cmap(vf.cmap,alt_cmap);
  453. for (k=cycle; k >= 1; k--)
  454. {
  455. d=alt_cmap;
  456. for (i=0; i < COLORS * 3; i++) *d++ = *d + (63 - *d )/k;
  457. delay(wait_time);
  458. wait_sync();
  459. jset_colors(0, COLORS, alt_cmap);
  460. }
  461. }
  462. /*
  463. beep()
  464. {
  465. sound(70);
  466. delay(1500);
  467. nosound();
  468. }
  469. */
  470. close_file()
  471. {
  472. file_is_loaded=0;
  473. jclose(loaded_file_fd);
  474. }