VIDEO.CPP 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <graph.h>
  5. #include <i86.h>
  6. #include <dos.h>
  7. #include <conio.h>
  8. #include <float.h>
  9. #include <time.h>
  10. #include <math.h>
  11. #include <string.h>
  12. #include "defines.h"
  13. #include "3deng.h"
  14. #include "video.h"
  15. #include "gamedata.h"
  16. int gdv_gran;
  17. extern int winrange,Vbytesperline;
  18. #ifndef min
  19. #define min(a,b) (((a) < (b)) ? (a) : (b))
  20. #endif
  21. #ifndef abs
  22. #define abs(a) (((a) < 0) ? -(a) : (a))
  23. #endif
  24. struct RMI
  25. {
  26. long EDI;
  27. long ESI;
  28. long EBP;
  29. long reserved;
  30. long EBX;
  31. long EDX;
  32. long ECX;
  33. long EAX;
  34. short flags;
  35. short ES, DS, FS, GS, IP, CS, SP, SS;
  36. };
  37. struct
  38. {
  39. unsigned short attributes;
  40. unsigned char win_a_attr;
  41. unsigned char win_b_attr;
  42. unsigned short win_granularity;
  43. unsigned short win_size;
  44. unsigned short win_a_segment;
  45. unsigned short win_b_segment;
  46. unsigned long win_windor;
  47. unsigned short bytes_per_scanline;
  48. unsigned short x_resolution;
  49. unsigned short y_resolution;
  50. unsigned char x_char_size;
  51. unsigned char y_char_size;
  52. unsigned char mem_planes;
  53. unsigned char bits_per_pixel;
  54. unsigned char number_banks;
  55. unsigned char mem_model;
  56. unsigned char bank_size;
  57. unsigned char number_images;
  58. unsigned char reserved0;
  59. unsigned char red_mask_size;
  60. unsigned char red_field_pos;
  61. unsigned char green_mask_size;
  62. unsigned char green_field_pos;
  63. unsigned char blue_mask_size;
  64. unsigned char blue_field_pos;
  65. unsigned char rsvd_mask_size;
  66. unsigned char reserved1[216];
  67. } ModeInfo;
  68. int win_range;
  69. void blank_pallette()
  70. {
  71. outp( 0x3c8, 0 );
  72. for ( short loop = 0 ; loop < 768 ; loop++ )
  73. outp( 0x3c9, 0 );
  74. }
  75. void set_pallette( unsigned char *pallette )
  76. {
  77. outp( 0x3c8, 0 );
  78. for ( short loop = 0 ; loop < 768 ; loop++ )
  79. outp( 0x3c9, pallette[loop] >> 3);
  80. }
  81. void set_pallette_entry( unsigned char color, unsigned char red, unsigned
  82. char blue, unsigned char green )
  83. {
  84. outp( 0x3c8, color );
  85. outp( 0x3c9, red );
  86. outp( 0x3c9, green );
  87. outp( 0x3c9, blue );
  88. }
  89. //int set_vesa_mode( unsigned short mode_no, int checks )
  90. //{
  91. //
  92. // if ( match_info.menu_res==HI )
  93. // {
  94. //
  95. // REGS regs;
  96. // SREGS sregs;
  97. // short segment, off, result, selector;
  98. // char far *ptr;
  99. // RMI real_mode;
  100. //
  101. // if (checks)
  102. // {
  103. // // Create a temporary working space for real mode interrupts...
  104. // memset( &sregs, 0, sizeof( SREGS ) );
  105. //
  106. // // Call the DPMI function to allocate 256 bytes of DOS memory
  107. // regs.w.ax = 0x0100;
  108. // regs.w.bx = (sizeof(ModeInfo) / 16) + 1;
  109. // int386x( 0x31, &regs, &regs, &sregs );
  110. //
  111. // segment = regs.w.ax;
  112. // selector = regs.w.dx;
  113. //
  114. // // Make use a far pointer to the base memory so we can reference it
  115. // ptr = (char far *) MK_FP( selector, 0 );
  116. //
  117. // memset( &real_mode, 0, sizeof( RMI ) );
  118. // real_mode.EAX = 0x4f01;
  119. // real_mode.ECX = mode_no;
  120. // real_mode.EDI = 0;
  121. // real_mode.ES = segment;
  122. //
  123. // regs.w.ax = 0x0300;
  124. // regs.h.bl = 0x10;
  125. // regs.h.bh = 0;
  126. // regs.w.cx = 0;
  127. // sregs.es = FP_SEG( &real_mode );
  128. // regs.x.edi = FP_OFF( &real_mode );
  129. //
  130. // int386x( 0x31, &regs, &regs, &sregs );
  131. //
  132. // _fmemcpy( &ModeInfo, ptr, sizeof( ModeInfo ) );
  133. //
  134. // // Free the 256 byte base memory
  135. // regs.w.ax = 0x101;
  136. // regs.w.dx = selector;
  137. // int386( 0x31, &regs, &regs );
  138. //
  139. // result = (short) real_mode.EAX;
  140. //
  141. // if (result != 0x004f)
  142. // return VESA_MODE_NOT_SUPPORTED;
  143. //
  144. // // Mode was ok to get info, so lets continue to actually set the mode...
  145. // }
  146. //
  147. // regs.w.ax = 0x4f02;
  148. // regs.w.bx = mode_no;
  149. // int386( 0x10, &regs, &regs );
  150. //
  151. // // last ditch effort
  152. //
  153. // if (regs.h.ah != 0)
  154. // {
  155. // regs.h.ah = 0;
  156. // regs.h.al = (char) mode_no;
  157. // int386( 0x10, &regs, &regs );
  158. // }
  159. //
  160. // // Make sure the Window A pointer is set to 0
  161. //
  162. // if (checks)
  163. // {
  164. // regs.w.ax = 0x4f05;
  165. // regs.w.bx = 0x0000;
  166. // regs.w.dx = 0x0000;
  167. // int386( 0x10, &regs, &regs );
  168. // }
  169. //
  170. // win_range = (ModeInfo.win_granularity * 1024 );
  171. // }
  172. // return VESA_MODE_OK;
  173. //}
  174. void svgacopy(unsigned char *buffpt,short x,short y,short w,short h, short buff_wid)
  175. {
  176. win_range = winrange;
  177. ModeInfo.bytes_per_scanline = Vbytesperline;
  178. if ( match_info.menu_res==HI )
  179. {
  180. union REGS regs;
  181. short i,co;
  182. char *scrpt;
  183. int scrdisp=x +ModeInfo.bytes_per_scanline * y;
  184. char bank=scrdisp / win_range;
  185. scrdisp%=win_range;
  186. scrpt=(char *)0xa0000+scrdisp;
  187. regs.x.eax=0x4f05;
  188. regs.x.ebx=0;
  189. regs.x.edx=bank;
  190. int386(16,&regs,&regs);
  191. do
  192. {
  193. co=min((win_range-scrdisp)/ModeInfo.bytes_per_scanline,h);
  194. for (i=0;i<co;i++)
  195. {
  196. memcpy(scrpt,buffpt,w);
  197. scrpt+=ModeInfo.bytes_per_scanline;
  198. buffpt+= buff_wid;
  199. h--;
  200. }
  201. if (h)
  202. {
  203. scrdisp=(scrdisp+(co+1)*ModeInfo.bytes_per_scanline)%win_range;
  204. co=min(ModeInfo.bytes_per_scanline-scrdisp,w);
  205. memcpy(scrpt,buffpt,co);
  206. bank++;
  207. regs.x.eax=0x4f05;
  208. regs.x.ebx=0;
  209. regs.x.edx=bank;
  210. int386(16,&regs,&regs);
  211. if (co!=w)
  212. memcpy((char *)0xa0000,buffpt+co,w-co);
  213. scrpt=(char *)0xa0000+scrdisp;
  214. buffpt+=buff_wid;
  215. h--;
  216. }
  217. } while (h);
  218. regs.x.eax=0x4f05;
  219. regs.x.ebx=0;
  220. regs.x.edx=0;
  221. int386(16,&regs,&regs);
  222. }
  223. // else
  224. //
  225. // {
  226. // SVGAxpos = x;
  227. // SVGAypos = y;
  228. // SVGAwidth = w;
  229. // SVGAheight = h;
  230. // svgacopy_LO();
  231. // }
  232. }
  233. void svgaread(char *buffpt,short x,short y,short w,short h, short buff_wid)
  234. {
  235. union REGS regs;
  236. short i,co;
  237. char *scrpt;
  238. int scrdisp=x + ModeInfo.bytes_per_scanline * y;
  239. char bank=scrdisp / win_range;
  240. scrdisp%=win_range;
  241. scrpt=(char *)0xa0000+scrdisp;
  242. regs.x.eax=0x4f05;
  243. regs.x.ebx=1;
  244. regs.x.edx=bank;
  245. int386(16,&regs,&regs);
  246. do
  247. {
  248. co=min((win_range-scrdisp)/ModeInfo.bytes_per_scanline,h);
  249. for (i=0;i<co;i++)
  250. {
  251. memcpy(buffpt,scrpt,w);
  252. scrpt+=ModeInfo.bytes_per_scanline;
  253. buffpt+= buff_wid;
  254. h--;
  255. }
  256. if (h)
  257. {
  258. scrdisp=(scrdisp+(co+1)*ModeInfo.bytes_per_scanline)%win_range;
  259. co=min(ModeInfo.bytes_per_scanline-scrdisp,w);
  260. memcpy(buffpt,scrpt,co);
  261. bank++;
  262. regs.x.eax=0x4f05;
  263. regs.x.ebx=1;
  264. regs.x.edx=bank;
  265. int386(16,&regs,&regs);
  266. if (co!=w)
  267. memcpy(buffpt+co,(char *)0xa0000,w-co);
  268. scrpt=(char *)0xa0000+scrdisp;
  269. buffpt+=buff_wid;
  270. h--;
  271. }
  272. } while (h);
  273. regs.x.eax=0x4f05;
  274. regs.x.ebx=1;
  275. regs.x.edx=0;
  276. int386(16,&regs,&regs);
  277. }
  278. short get_curr_vmode()
  279. {
  280. REGS regs;
  281. regs.x.eax = 0x4f03;
  282. int386( 0x10, &regs, &regs );
  283. if (regs.w.ax == 0x004f)
  284. return regs.w.bx;
  285. return 0;
  286. }
  287. void draw_line( short x1, short y1,
  288. short x2, short y2,
  289. char col, buff_info *buffer )
  290. {
  291. int x, y, deltax, deltay, i, numpixels;
  292. int d, dinc1, dinc2, xinc1, xinc2, yinc1, yinc2;
  293. deltax = abs(x2 - x1);
  294. deltay = abs(y2 - y1);
  295. if (deltax >= deltay)
  296. {
  297. numpixels = deltax + 1;
  298. d = (deltay << 1) - deltax;
  299. dinc1 = deltay << 1;
  300. dinc2 = (deltay - deltax) << 1;
  301. xinc1 = 1;
  302. xinc2 = 1;
  303. yinc1 = 0;
  304. yinc2 = 1;
  305. }
  306. else
  307. {
  308. numpixels = deltay + 1;
  309. d = (deltax << 1) - deltay;
  310. dinc1 = deltax << 1;
  311. dinc2 = (deltax - deltay) << 1;
  312. xinc1 = 0;
  313. xinc2 = 1;
  314. yinc1 = 1;
  315. yinc2 = 1;
  316. }
  317. if (x1 > x2)
  318. {
  319. xinc1 = -xinc1;
  320. xinc2 = -xinc2;
  321. }
  322. if (y1 > y2)
  323. {
  324. yinc1 = -yinc1;
  325. yinc2 = -yinc2;
  326. }
  327. x = x1;
  328. y = y1;
  329. for ( i = 0; i < numpixels; i++ )
  330. {
  331. if ((x >= 0) && (x < buffer->clip_wid) &&
  332. (y >= 0) && (y < buffer->clip_hgt))
  333. {
  334. *(buffer->buff_start + (y * buffer->buff_wid) + x) = col;
  335. }
  336. if ( d < 0 )
  337. {
  338. d += dinc1;
  339. x += xinc1;
  340. y += yinc1;
  341. }
  342. else
  343. {
  344. d += dinc2;
  345. x += xinc2;
  346. y += yinc2;
  347. }
  348. }
  349. }