home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / CreativeComputers.iso / shareware / text / dvi_3.62 / source / dvisrc.lha / dvifram.c < prev    next >
C/C++ Source or Header  |  1993-10-26  |  4KB  |  199 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include "dvi.h"
  6. #include "dvidvi.h"
  7. #include "dviframe.h"
  8.  
  9.  
  10. #ifdef IBMPC
  11. static byte huge *frame_buffer;
  12. static long block_len, block_start, block_end;
  13. static const long block_max = 32700l;
  14. #else
  15. byte huge   *frame_buffer;
  16. #endif
  17.  
  18. #ifdef IBMPC
  19.  
  20. void        (*frame_or)(long a, byte x);
  21. byte        (*frame_get)(long a);
  22. void        (*frame_set)(byte huge *p, long len);
  23. void        (*frame_poke)(long a, byte x);
  24. void        (*frame_and)(long a, byte x);
  25. byte huge * (*frame_ptr)(long a);
  26. void        (*frame_clr)(void);
  27. void huge * (*frame_alloc)(long);
  28. void        (*frame_free)(void huge*,long);
  29.  
  30. extern byte huge * n_386_ptr(long);
  31. extern void n_386_init(void far *);
  32. extern void n_386_or(long a, byte x);
  33.  
  34. void huge * n_frame_alloc(long s)
  35. {
  36.     return mem_alloc(s, "Frame-Buffer");
  37. }
  38.  
  39. void n_frame_free(void huge *p, long s)
  40. {
  41.     mem_free(p, s);
  42. }
  43.  
  44. byte n_frame_get(long a)
  45. {
  46.     return *(frame_buffer+a);
  47. }
  48.  
  49. void n_frame_or(long a, byte x)
  50. {
  51.     *(frame_buffer+a) |= x;
  52. }
  53.  
  54. void n_frame_and(long a, byte x)
  55. {
  56.     *(frame_buffer+a) &= x;
  57. }
  58.  
  59. void n_frame_poke(long a, byte x)
  60. {
  61.     *(frame_buffer+a) = x;
  62. }
  63.  
  64. byte huge *n_frame_ptr(long a)
  65. {
  66.     return frame_buffer+a;
  67. }
  68.  
  69. void n_frame_clr(void)
  70. {
  71.     long size = frame_size;
  72.     byte huge *p = frame_buffer;
  73.     while(size>0x7FFFl)
  74.     {
  75.     memset((void*)p,0,0x7fff);
  76.     p += 0x7fff;
  77.     size -= 0x7fff;
  78.     }
  79.     if (size>0) memset((void*)p,0,(size_t)size);
  80. }
  81.  
  82. void n_frame_set(byte huge *p, long len)
  83. {
  84.     frame_buffer = p;
  85.     block_len = 0;
  86.     len = len;
  87.     /* n_386_init(p); */
  88. }
  89.  
  90. static void frame_swap(long a)
  91. {
  92.     movetoe(frame_buffer,block_start,block_len);
  93.     block_start = a-(block_len/2l);
  94.     if (block_start<0l) block_start = 0l;
  95.     block_end = block_start + block_len;
  96.     movefrome(frame_buffer,block_start,block_len);
  97. }
  98.  
  99. void huge * e_frame_alloc(long s)
  100. {
  101.     if (s>block_max) s = block_max;
  102.     return mem_alloc(s, "Frame-Buffer");
  103. }
  104.  
  105. void e_frame_free(void huge *p, long s)
  106. {
  107.     if (s>block_max) s = block_max;
  108.     mem_free(p, s);
  109. }
  110.  
  111. void e_frame_or(long a, byte x)
  112. {
  113.     if (a<block_start || a>=block_end) frame_swap(a);
  114.     *(frame_buffer+a-block_start) |= x;
  115. }
  116.  
  117. byte e_frame_get(long a)
  118. {
  119.     if (a<block_start || a>=block_end) frame_swap(a);
  120.     return *(frame_buffer+a-block_start);
  121. }
  122.  
  123. void e_frame_and(long a, byte x)
  124. {
  125.     if (a<block_start || a>=block_end) frame_swap(a);
  126.     *(frame_buffer+a-block_start) &= x;
  127. }
  128.  
  129. void e_frame_poke(long a, byte x)
  130. {
  131.     if (a<block_start || a>=block_end) frame_swap(a);
  132.     *(frame_buffer+a-block_start) = x;
  133. }
  134.  
  135. byte huge *e_frame_ptr(long a)
  136. {
  137.     if (a<block_start || a+frame_width>=block_end) frame_swap(a);
  138.     return frame_buffer+a-block_start;
  139. }
  140.  
  141. void e_frame_clr(void)
  142. {
  143.     long size = frame_size, pos = 0;
  144.  
  145.     memset(frame_buffer,0,(size_t)block_len);
  146.  
  147.     while(size>=block_len)
  148.     {
  149.     movetoe(frame_buffer,pos,block_len);
  150.     size -= block_len;
  151.     pos += block_len;
  152.     }
  153.     if (size>0l) movetoe(frame_buffer,pos,size);
  154.     block_start = 0l;
  155.     block_end = block_len;
  156. }
  157.  
  158. void e_frame_set(byte huge *p, long len)
  159. {
  160.     frame_buffer = p;
  161.     if (len>=block_max) block_len = block_max;
  162.     else block_len = len & ~1l;
  163.     if (block_len == 0l)
  164.     halt("Not enough memory for swapping");
  165. }
  166.  
  167. long frame_max(void)
  168. {
  169.     long s = get_extended();
  170.     if (s)
  171.     {
  172.     frame_or    = e_frame_or;
  173.     frame_get   = e_frame_get;
  174.     frame_set   = e_frame_set;
  175.     frame_poke  = e_frame_poke;
  176.     frame_and   = e_frame_and;
  177.     frame_ptr   = e_frame_ptr;
  178.     frame_clr   = e_frame_clr;
  179.     frame_alloc = e_frame_alloc;
  180.     frame_free  = e_frame_free;
  181.     }
  182.     else
  183.     {
  184.     frame_or    = n_frame_or;
  185.     frame_get   = n_frame_get;
  186.     frame_set   = n_frame_set;
  187.     frame_poke  = n_frame_poke;
  188.     frame_and   = n_frame_and;
  189.     frame_ptr   = n_frame_ptr;
  190.     frame_clr   = n_frame_clr;
  191.     frame_alloc = n_frame_alloc;
  192.     frame_free  = n_frame_free;
  193.     s = op.pixmem;
  194.     }
  195.     return s;
  196. }
  197.  
  198. #endif
  199.