PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Pristine/CROP/GFX.C

http://github.com/AnimatorPro/Animator-Pro
C | 224 lines | 170 code | 40 blank | 14 comment | 8 complexity | cdde6304563a26cc7f4751fc7c8df675 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /* gfx.c - low level PC - VGA graphics routines. Some fixed point
  2. arithmetic helpers too. */
  3. /* Some VGA specific 320x200x256 graphics routines. */
  4. #include "jimk.h"
  5. /* a table for RIF and ANIM decompression */
  6. unsigned WORD ytable[YMAX];
  7. /* Poke the background color with an rgb value. Handy for debugging
  8. sometimes. */
  9. poke_bg(p)
  10. char *p;
  11. {
  12. jset_colors(0,1,p);
  13. }
  14. /* Set the background color back to what it should be. */
  15. restore_bg()
  16. {
  17. jset_colors(0,1,sys_cmap);
  18. }
  19. /* Wait for Vsync and feed hardware the current color palette */
  20. see_cmap()
  21. {
  22. wait_sync();
  23. jset_colors(0, COLORS, vf.cmap);
  24. }
  25. /* Flash the background color briefly. */
  26. flash_bg(p)
  27. char *p;
  28. {
  29. poke_bg(p);
  30. wait_a_jiffy(4);
  31. restore_bg();
  32. }
  33. #ifdef SLUFFED
  34. flash_green()
  35. {
  36. flash_bg(pure_green);
  37. }
  38. #endif /* SLUFFED */
  39. flash_red()
  40. {
  41. flash_bg(pure_red);
  42. }
  43. #ifdef SLUFFED
  44. flash_blue()
  45. {
  46. flash_bg(pure_blue);
  47. }
  48. #endif /* SLUFFED */
  49. copy_form(s, d)
  50. Video_form *s, *d;
  51. {
  52. copy_words(s->p, d->p, 32000);
  53. copy_cmap(s->cmap, d->cmap);
  54. }
  55. #ifdef SLUFFED
  56. exchange_form(s, d)
  57. Video_form *s, *d;
  58. {
  59. exchange_words(s->p, d->p, 32000);
  60. exchange_words(s->cmap, d->cmap, COLORS/2*3);
  61. }
  62. #endif /* SLUFFED */
  63. #ifdef SLUFFED
  64. /* Set a screen sized form to a solid color */
  65. color_form(f,color)
  66. Video_form *f;
  67. WORD color;
  68. {
  69. color += (color<<8); /* Do it 2 bytes at a time */
  70. stuff_words(color, f->p, f->bpr*f->h/sizeof(WORD));
  71. }
  72. #endif /* SLUFFED */
  73. zero_bytes(pt, count)
  74. register char *pt;
  75. int count;
  76. {
  77. while (--count >= 0)
  78. *pt++ = 0;
  79. }
  80. copy_lots(s, d, count)
  81. register long *s, *d;
  82. register long count;
  83. {
  84. count /= sizeof(long);
  85. while (--count >= 0)
  86. *d++ = *s++;
  87. }
  88. zero_lots(pt, size)
  89. register char *pt;
  90. long size;
  91. {
  92. int lsize;
  93. size >>=1; /* convert to word count */
  94. while (size > 0)
  95. {
  96. if (size > 32000)
  97. lsize = 32000;
  98. else
  99. lsize = size;
  100. stuff_words(0, pt, lsize);
  101. pt = norm_pointer(pt+lsize);
  102. pt = norm_pointer(pt+lsize);
  103. size -= lsize;
  104. }
  105. }
  106. clear_form(f)
  107. Video_form *f;
  108. {
  109. zero_lots(f->p, (long)f->bpr*f->h);
  110. }
  111. draw_frame(color, x0, y0, x1, y1)
  112. int color, x0, y0, x1, y1;
  113. {
  114. int w, h;
  115. w = x1-x0;
  116. h = y1-y0-2;
  117. chli(vf.p, x0, y0, w, color);
  118. chli(vf.p, x0, y1-1, w, color);
  119. cvli(vf.p, x0, y0+1, h, color);
  120. cvli(vf.p, x1-1, y0+1, h, color);
  121. }
  122. #ifdef SLUFFED
  123. /* Little routine I should put into assembler someday. Does x*p/q on
  124. some ints without blowing up if x*p is > 64K provided q will bring it
  125. back into range. Sscale_by if for 'signed scale by' */
  126. sscale_by(x,p,q)
  127. int x,p,q;
  128. {
  129. long l;
  130. l = x;
  131. l *= p;
  132. l /= q;
  133. return(l);
  134. }
  135. #endif /* SLUFFED */
  136. uscale_by(x, p, q)
  137. unsigned x, p, q;
  138. {
  139. long l;
  140. l = x;
  141. l *= p;
  142. l /= q;
  143. return(l);
  144. }
  145. /* round and scale */
  146. rscale_by(x,p,q)
  147. int x,p,q;
  148. {
  149. long l;
  150. int sign;
  151. sign = 1;
  152. if (x < 0)
  153. sign = -sign;
  154. if (p < 0)
  155. sign = -sign;
  156. l = x;
  157. l *= p;
  158. if (sign > 0)
  159. l += (q/2);
  160. else
  161. l -= (q/2);
  162. l /= q;
  163. return(l);
  164. }
  165. itmult(trig, x)
  166. WORD trig,x;
  167. {
  168. long result;
  169. result = trig;
  170. result *= x;
  171. return(result/(1<<14));
  172. }
  173. exchange_bytes(a, b, count)
  174. char *a, *b;
  175. int count;
  176. {
  177. char swap;
  178. while (--count >= 0)
  179. {
  180. swap = *a;
  181. *a++ = *b;
  182. *b++ = swap;
  183. }
  184. }