GR.C 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/2d/rcs/gr.c $
  15. * $Revision: 1.56 $
  16. * $Author: john $
  17. * $Date: 1995/05/08 11:22:47 $
  18. *
  19. * Graphical routines for setting video modes, etc.
  20. *
  21. * $Log: gr.c $
  22. * Revision 1.56 1995/05/08 11:22:47 john
  23. * Added 320x400 3dbios mode.
  24. *
  25. * Revision 1.55 1995/02/02 16:44:05 john
  26. * Again with prev.
  27. *
  28. * Revision 1.54 1995/02/02 16:42:18 john
  29. * Fixed palette with text fading out.
  30. *
  31. * Revision 1.53 1995/02/02 14:26:20 john
  32. * Made palette fades work better with gamma thingy..
  33. *
  34. * Revision 1.52 1995/02/02 14:08:59 john
  35. * Made palette gamma reset to 0 before exiting to Dos.
  36. *
  37. * Revision 1.51 1995/01/30 18:06:35 john
  38. * Added text screen fade in/out, and restored video mode properly.
  39. *
  40. * Revision 1.50 1995/01/24 17:58:16 john
  41. * Added code to return to 80x25 when graphics close.
  42. *
  43. * Revision 1.49 1994/11/30 20:16:05 john
  44. * Fixed bug that the grd_curscreen flags were never initialized.
  45. *
  46. * Revision 1.48 1994/11/24 13:24:43 john
  47. * Made sure that some rep movs had the cld set first.
  48. * Took some unused functions out.
  49. *
  50. * Revision 1.47 1994/11/18 22:50:20 john
  51. * Changed shorts to ints in parameters.
  52. *
  53. * Revision 1.46 1994/11/15 18:28:36 john
  54. * Made text screen fade in.
  55. *
  56. * Revision 1.45 1994/11/15 17:55:11 john
  57. * Made text palette fade in when game over.
  58. *
  59. * Revision 1.44 1994/11/07 12:07:30 john
  60. * Made save/restore cursor work a bit better.
  61. *
  62. * Revision 1.43 1994/11/05 12:46:44 john
  63. * Changed palette stuff a bit.
  64. *
  65. * Revision 1.42 1994/10/26 23:55:50 john
  66. * Took out roller; Took out inverse table.
  67. *
  68. * Revision 1.41 1994/10/10 13:59:50 john
  69. * *** empty log message ***
  70. *
  71. * Revision 1.40 1994/10/10 13:58:50 john
  72. * Added better VGA detection scheme.
  73. *
  74. * Revision 1.39 1994/09/29 10:09:15 john
  75. * Hacked out VGA card detection for now.
  76. *
  77. * Revision 1.38 1994/09/22 17:35:35 john
  78. * Fixed bug with palette not reloading in
  79. * gr_set_mode
  80. *
  81. * Revision 1.37 1994/09/22 16:08:42 john
  82. * Fixed some palette stuff.
  83. *
  84. * Revision 1.36 1994/09/19 11:44:23 john
  85. * Changed call to allocate selector to the dpmi module.
  86. *
  87. * Revision 1.35 1994/09/12 19:28:11 john
  88. * Fixed bug with unclipped fonts clipping.
  89. *
  90. * Revision 1.34 1994/09/12 18:20:18 john
  91. * Made text fade out
  92. *
  93. * Revision 1.33 1994/09/12 14:40:15 john
  94. * Neatend.
  95. *
  96. * Revision 1.32 1994/08/15 15:01:01 matt
  97. * Set ptr to NULL after freeing
  98. *
  99. * Revision 1.31 1994/07/27 18:30:28 john
  100. * Took away the blending table.
  101. *
  102. * Revision 1.30 1994/06/24 17:26:59 john
  103. * Made rowsizes bigger than actual screen work with SVGA.
  104. *
  105. * Revision 1.29 1994/05/12 17:33:16 john
  106. * Added circle code.
  107. *
  108. * Revision 1.28 1994/05/10 19:51:49 john
  109. * Added 320x100 mode.
  110. *
  111. * Revision 1.27 1994/05/06 12:50:23 john
  112. * Added supertransparency; neatend things up; took out warnings.
  113. *
  114. * Revision 1.26 1994/05/03 19:39:00 john
  115. * *** empty log message ***
  116. *
  117. * Revision 1.25 1994/04/08 16:59:34 john
  118. * Add fading poly's; Made palette fade 32 instead of 16.
  119. *
  120. * Revision 1.24 1994/03/14 16:56:16 john
  121. * Changed grs_bitmap structure to include bm_flags.
  122. *
  123. * Revision 1.23 1994/02/18 15:32:27 john
  124. * *** empty log message ***
  125. *
  126. * Revision 1.22 1994/01/25 11:40:44 john
  127. * Added gr_check_mode function.
  128. *
  129. * Revision 1.21 1993/12/21 19:57:48 john
  130. * added selector stuff.
  131. *
  132. * Revision 1.20 1993/12/21 11:40:32 john
  133. * *** empty log message ***
  134. *
  135. * Revision 1.19 1993/12/09 15:02:13 john
  136. * Changed palette stuff majorly
  137. *
  138. * Revision 1.18 1993/11/16 11:28:36 john
  139. * *** empty log message ***
  140. *
  141. * Revision 1.17 1993/10/26 13:17:53 john
  142. * *** empty log message ***
  143. *
  144. * Revision 1.16 1993/10/15 16:23:42 john
  145. * y
  146. *
  147. * Revision 1.15 1993/09/29 16:15:21 john
  148. * optimized
  149. *
  150. * Revision 1.14 1993/09/28 19:06:51 john
  151. * made gr_set_mode change the grd_cursreen->sc_mode variable.
  152. *
  153. * Revision 1.13 1993/09/28 12:52:12 matt
  154. * Set aspect ratio of current screen in gr_init() and gr_set_mode().
  155. *
  156. * Revision 1.12 1993/09/27 13:00:24 john
  157. * made gr_set_mode not call mode_reset on fail
  158. *
  159. * Revision 1.11 1993/09/27 12:51:27 john
  160. * fixed gr_set_mode to return values
  161. *
  162. * Revision 1.10 1993/09/26 18:59:12 john
  163. * fade in/out stuff
  164. *
  165. * Revision 1.9 1993/09/21 14:00:41 john
  166. * added code to save 43/50 line modes.
  167. *
  168. * Revision 1.8 1993/09/20 14:48:48 john
  169. * *** empty log message ***
  170. *
  171. * Revision 1.7 1993/09/16 17:27:48 john
  172. * Added code to save/restore video mode.
  173. *
  174. * Revision 1.6 1993/09/16 16:30:15 john
  175. * Made gr_close retore Mode 3 always.
  176. *
  177. * Revision 1.5 1993/09/14 18:40:07 john
  178. * Made it so that gr_setmode doesn't change curcanv font and colors.
  179. *
  180. * Revision 1.4 1993/09/14 16:27:01 matt
  181. * Changes gr_change_mode() to be gr_set_mode()
  182. * After gr_set_mode(), grd_curcanv is the canvas of the new screen
  183. * Made gr_set_mode() work with the new grd_curcanv, not the old one
  184. *
  185. * Revision 1.3 1993/09/14 13:08:37 john
  186. * Added gr_changemode
  187. *
  188. * Revision 1.2 1993/09/08 17:36:37 john
  189. * Looking for error for Yuan... Neatened the nested ifs in setmode.
  190. *
  191. * Revision 1.1 1993/09/08 11:43:51 john
  192. * Initial revision
  193. *
  194. *
  195. */
  196. #include <dos.h>
  197. #include <stdlib.h>
  198. #include <malloc.h>
  199. #include <stdio.h>
  200. #include <conio.h>
  201. #include <string.h>
  202. #include "types.h"
  203. #include "mem.h"
  204. #include "gr.h"
  205. #include "grdef.h"
  206. #include "error.h"
  207. #include "mono.h"
  208. #include "dpmi.h"
  209. #include "palette.h"
  210. #include "dpmi.h"
  211. unsigned char * gr_video_memory = (unsigned char *)0xA0000;
  212. char gr_pal_default[768];
  213. int gr_installed = 0;
  214. ubyte * pVideoMode = (volatile ubyte *)0x449;
  215. ushort * pNumColumns = (volatile ushort *)0x44a;
  216. ubyte * pNumRows = (volatile ubyte *)0x484;
  217. ushort * pCharHeight = (volatile ushort *)0x485;
  218. ushort * pCursorPos = (volatile ushort *)0x450;
  219. ushort * pCursorType = (volatile ushort *)0x460;
  220. ushort * pTextMemory = (volatile ushort *)0xb8000;
  221. typedef struct screen_save {
  222. ubyte video_mode;
  223. ubyte is_graphics;
  224. ushort char_height;
  225. ubyte width;
  226. ubyte height;
  227. ubyte cursor_x, cursor_y;
  228. ubyte cursor_sline, cursor_eline;
  229. ushort * video_memory;
  230. } screen_save;
  231. screen_save gr_saved_screen;
  232. int gr_show_screen_info = 0;
  233. void gr_set_cellheight( ubyte height )
  234. {
  235. ubyte temp;
  236. outp( 0x3d4, 9 );
  237. temp = inp( 0x3d5 );
  238. temp &= 0xE0;
  239. temp |= height;
  240. outp( 0x3d5, temp );
  241. }
  242. void gr_set_linear()
  243. {
  244. outpw( 0x3c4, 0xE04 ); // enable chain4 mode
  245. outpw( 0x3d4, 0x4014 ); // turn on dword mode
  246. outpw( 0x3d4, 0xa317 ); // turn off byte mode
  247. }
  248. void gr_16_to_256()
  249. {
  250. outpw( 0x3ce, 0x4005 ); // set Shift reg to 1
  251. inp( 0x3da ); // dummy input
  252. outp( 0x3c0, 0x30 );
  253. outp( 0x3c0, 0x61 ); // turns on PCS & PCC
  254. inp( 0x3da ); // dummy input
  255. outp( 0x3c0, 0x33 );
  256. outp( 0x3c0, 0 );
  257. }
  258. void gr_turn_screen_off()
  259. {
  260. ubyte temp;
  261. temp = inp( 0x3da );
  262. outp( 0x3c0, 0 );
  263. }
  264. void gr_turn_screen_on()
  265. {
  266. ubyte temp;
  267. temp = inp( 0x3da );
  268. outp( 0x3c0, 0x20 );
  269. }
  270. void gr_set_misc_mode( uint mode )
  271. {
  272. union REGS regs;
  273. memset( &regs, 0, sizeof(regs) );
  274. regs.w.ax = mode;
  275. int386( 0x10, &regs, &regs );
  276. }
  277. void gr_set_3dbios_mode( uint mode )
  278. {
  279. union REGS regs;
  280. memset( &regs, 0, sizeof(regs) );
  281. regs.w.ax = 0x4fd0;
  282. regs.w.bx = 0x3d00 | (mode & 0xff);
  283. int386( 0x10, &regs, &regs );
  284. }
  285. void gr_set_text_25()
  286. {
  287. union REGS regs;
  288. regs.w.ax = 3;
  289. int386( 0x10, &regs, &regs );
  290. }
  291. void gr_set_text_43()
  292. {
  293. union REGS regs;
  294. regs.w.ax = 0x1201;
  295. regs.w.bx = 0x30;
  296. int386( 0x10, &regs, &regs );
  297. regs.w.ax = 3;
  298. int386( 0x10, &regs, &regs );
  299. regs.w.ax = 0x1112;
  300. regs.w.bx = 0x0;
  301. int386( 0x10, &regs, &regs );
  302. }
  303. void gr_set_text_50()
  304. {
  305. union REGS regs;
  306. regs.w.ax = 0x1202;
  307. regs.w.bx = 0x30;
  308. int386( 0x10, &regs, &regs );
  309. regs.w.ax = 3;
  310. int386( 0x10, &regs, &regs );
  311. regs.w.ax = 0x1112;
  312. regs.w.bx = 0x0;
  313. int386( 0x10, &regs, &regs );
  314. }
  315. ubyte is_graphics_mode()
  316. {
  317. byte tmp;
  318. tmp = inp( 0x3DA ); // Reset flip-flip
  319. outp( 0x3C0, 0x30 ); // Select attr register 10
  320. tmp = inp( 0x3C1 ); // Get graphics/text bit
  321. return tmp & 1;
  322. }
  323. void gr_setcursor(ubyte x, ubyte y, ubyte sline, ubyte eline)
  324. {
  325. union REGS regs;
  326. memset( &regs, 0, sizeof(regs) );
  327. regs.w.ax = 0x0200;
  328. regs.w.bx = 0;
  329. regs.h.dh = y;
  330. regs.h.dl = x;
  331. int386( 0x10, &regs, &regs );
  332. memset( &regs, 0, sizeof(regs) );
  333. regs.w.ax = 0x0100;
  334. regs.h.ch = sline & 0xf;
  335. regs.h.cl = eline & 0xf;
  336. int386( 0x10, &regs, &regs );
  337. }
  338. void gr_getcursor(ubyte *x, ubyte *y, ubyte * sline, ubyte * eline)
  339. {
  340. union REGS regs;
  341. memset( &regs, 0, sizeof(regs) );
  342. regs.w.ax = 0x0300;
  343. regs.w.bx = 0;
  344. int386( 0x10, &regs, &regs );
  345. *y = regs.h.dh;
  346. *x = regs.h.dl;
  347. *sline = regs.h.ch;
  348. *eline = regs.h.cl;
  349. }
  350. int gr_save_mode()
  351. {
  352. int i;
  353. gr_saved_screen.is_graphics = is_graphics_mode();
  354. gr_saved_screen.video_mode = *pVideoMode;
  355. if (!gr_saved_screen.is_graphics) {
  356. gr_saved_screen.width = *pNumColumns;
  357. gr_saved_screen.height = *pNumRows+1;
  358. gr_saved_screen.char_height = *pCharHeight;
  359. gr_getcursor(&gr_saved_screen.cursor_x, &gr_saved_screen.cursor_y, &gr_saved_screen.cursor_sline, &gr_saved_screen.cursor_eline );
  360. //MALLOC(gr_saved_screen.video_memory,ushort, gr_saved_screen.width*gr_saved_screen.height );//Hack by Krb
  361. gr_saved_screen.video_memory=(ushort *)malloc((gr_saved_screen.width*gr_saved_screen.height)*sizeof(ushort));
  362. for (i=0; i < gr_saved_screen.width*gr_saved_screen.height; i++ )
  363. gr_saved_screen.video_memory[i] = pTextMemory[i];
  364. }
  365. if (gr_show_screen_info ) {
  366. printf( "Current video mode 0x%x:\n", gr_saved_screen.video_mode );
  367. if (gr_saved_screen.is_graphics)
  368. printf( "Graphics mode\n" );
  369. else {
  370. printf( "Text mode\n" );
  371. printf( "( %d columns by %d rows)\n", gr_saved_screen.width, gr_saved_screen.height );
  372. printf( "Char height is %d pixel rows\n", gr_saved_screen.char_height );
  373. printf( "Cursor of type 0x%x,0x%x is at (%d, %d)\n", gr_saved_screen.cursor_sline, gr_saved_screen.cursor_eline,gr_saved_screen.cursor_x, gr_saved_screen.cursor_y );
  374. }
  375. }
  376. return 0;
  377. }
  378. int isvga()
  379. {
  380. union REGS regs;
  381. memset( &regs, 0, sizeof(regs) );
  382. regs.w.ax = 0x1a00;
  383. int386( 0x10, &regs, &regs );
  384. if ( regs.h.al == 0x1a )
  385. return 1;
  386. return 0;
  387. }
  388. void gr_restore_mode()
  389. {
  390. int i;
  391. //gr_set_text_25();
  392. gr_palette_fade_out( gr_palette, 32, 0 );
  393. gr_palette_set_gamma(0);
  394. if ( gr_saved_screen.video_mode == 3 ) {
  395. switch( gr_saved_screen.height ) {
  396. case 43: gr_set_text_43(); break;
  397. case 50: gr_set_text_50(); break;
  398. default: gr_set_text_25(); break;
  399. }
  400. } else {
  401. gr_set_misc_mode(gr_saved_screen.video_mode);
  402. }
  403. if (gr_saved_screen.is_graphics==0) {
  404. gr_sync_display();
  405. gr_sync_display();
  406. gr_palette_read( gr_pal_default );
  407. gr_palette_clear();
  408. for (i=0; i < gr_saved_screen.width*gr_saved_screen.height; i++ )
  409. pTextMemory[i]=gr_saved_screen.video_memory[i];
  410. gr_setcursor( gr_saved_screen.cursor_x, gr_saved_screen.cursor_y, gr_saved_screen.cursor_sline, gr_saved_screen.cursor_eline );
  411. gr_palette_faded_out = 1;
  412. gr_palette_fade_in( gr_pal_default, 32, 0 );
  413. }
  414. }
  415. int gr_close()
  416. {
  417. if (gr_installed==1)
  418. {
  419. gr_installed = 0;
  420. gr_restore_mode();
  421. free(grd_curscreen);
  422. if( gr_saved_screen.video_memory ) {
  423. free(gr_saved_screen.video_memory);
  424. gr_saved_screen.video_memory = NULL;
  425. }
  426. }
  427. return 0;
  428. }
  429. int gr_vesa_setmode( int mode )
  430. {
  431. int retcode;
  432. retcode=gr_vesa_checkmode( mode );
  433. if ( retcode ) return retcode;
  434. return gr_vesa_setmodea( mode );
  435. }
  436. int gr_set_mode(int mode)
  437. {
  438. int retcode;
  439. unsigned int w,h,t,data, r;
  440. //JOHNgr_disable_default_palette_loading();
  441. switch(mode)
  442. {
  443. case SM_ORIGINAL:
  444. return 0;
  445. case 0:
  446. if (!isvga()) return 1;
  447. gr_set_misc_mode(0x13);
  448. w = 320; r = 320; h = 200; t=BM_LINEAR; data = 0xA0000;
  449. break;
  450. case SM_640x400V:
  451. retcode = gr_vesa_setmode( 0x100 );
  452. if (retcode !=0 ) return retcode;
  453. w = 640; r = 640; h = 400; t=BM_SVGA; data = 0;
  454. break;
  455. case SM_640x480V:
  456. retcode = gr_vesa_setmode( 0x101 );
  457. if (retcode !=0 ) return retcode;
  458. w = 640; r = 640; h = 480; t=BM_SVGA; data = 0;
  459. break;
  460. case SM_800x600V:
  461. retcode = gr_vesa_setmode( 0x103 );
  462. if (retcode !=0 ) return retcode;
  463. w = 800; r = 800; h = 600; t=BM_SVGA; data = 0;
  464. break;
  465. case SM_1024x768V:
  466. retcode = gr_vesa_setmode( 0x105 );
  467. if (retcode !=0 ) return retcode;
  468. w = 1024; r = 1024; h = 768; t=BM_SVGA; data = 0;
  469. break;
  470. case SM_640x480V15:
  471. retcode = gr_vesa_setmode( 0x110 );
  472. if (retcode !=0 ) return retcode;
  473. w = 640; r = 640*2; h=480; t=BM_SVGA15; data = 0;
  474. break;
  475. case SM_800x600V15:
  476. retcode = gr_vesa_setmode( 0x113 );
  477. if (retcode !=0 ) return retcode;
  478. w = 800; r = 800*2; h=600; t=BM_SVGA15; data = 0;
  479. break;
  480. case 19:
  481. if (!isvga()) return 1;
  482. gr_set_misc_mode(0x13);
  483. // {
  484. // ubyte x;
  485. // x = inp( 0x3c5 );
  486. // x |= 8;
  487. // outp( 0x3c5, x );
  488. // }
  489. gr_set_cellheight( 3 );
  490. w = 320; r = 320; h = 100; t=BM_LINEAR; data = 0xA0000;
  491. break;
  492. case 20:
  493. retcode = gr_vesa_setmode( 0x102 );
  494. //gr_enable_default_palette_loading();
  495. if (retcode !=0 ) return retcode;
  496. gr_16_to_256();
  497. gr_set_linear();
  498. //gr_set_cellheight( 1 );
  499. gr_vesa_setlogical( 400 );
  500. w = 400; r = 400; h = 600; t=BM_SVGA; data = 0;
  501. break;
  502. case 21:
  503. if (!isvga()) return 1;
  504. gr_set_misc_mode(0xd);
  505. gr_16_to_256();
  506. gr_set_linear();
  507. gr_set_cellheight( 3 );
  508. w = 160; r = 160; h = 100; t=BM_LINEAR; data = 0xA0000;
  509. break;
  510. case 22: // 3dmax 320x400
  511. if (!isvga()) return 1;
  512. gr_set_3dbios_mode(0x31);
  513. //w = 320; r = 320/4; h = 400; t=BM_MODEX; data = 0;
  514. w = 320; r = 320; h = 400; t=BM_SVGA; data = 0;
  515. break;
  516. default:
  517. if (!isvga()) return 1;
  518. w = gr_modex_setmode( mode );
  519. //gr_enable_default_palette_loading();
  520. h = w & 0xffff; w = w >> 16; r = w / 4;t = BM_MODEX; data = 0;
  521. break;
  522. }
  523. gr_palette_clear();
  524. memset( grd_curscreen, 0, sizeof(grs_screen));
  525. grd_curscreen->sc_mode = mode;
  526. grd_curscreen->sc_w = w;
  527. grd_curscreen->sc_h = h;
  528. grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
  529. grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
  530. grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
  531. grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
  532. grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
  533. grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = r;
  534. grd_curscreen->sc_canvas.cv_bitmap.bm_type = t;
  535. grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)data;
  536. gr_set_current_canvas(NULL);
  537. //gr_enable_default_palette_loading();
  538. return 0;
  539. }
  540. int gr_init(int mode)
  541. {
  542. int org_gamma;
  543. int retcode;
  544. // Only do this function once!
  545. if (gr_installed==1)
  546. return 1;
  547. if (gr_init_A0000())
  548. return 10;
  549. // Save the current text screen mode
  550. if (gr_save_mode()==1)
  551. return 1;
  552. // Save the current palette, and fade it out to black.
  553. gr_palette_read( gr_pal_default );
  554. gr_palette_faded_out = 0;
  555. org_gamma = gr_palette_get_gamma();
  556. gr_palette_set_gamma( 0 );
  557. gr_palette_fade_out( gr_pal_default, 32, 0 );
  558. gr_palette_clear();
  559. gr_palette_set_gamma( org_gamma );
  560. gr_sync_display();
  561. gr_sync_display();
  562. //MALLOC( grd_curscreen,grs_screen,1 );//Hack by KRB
  563. grd_curscreen=(grs_screen*)malloc(1*sizeof(grs_screen));
  564. memset( grd_curscreen, 0, sizeof(grs_screen));
  565. // Set the mode.
  566. if (retcode=gr_set_mode(mode))
  567. {
  568. gr_restore_mode();
  569. return retcode;
  570. }
  571. //JOHNgr_disable_default_palette_loading();
  572. // Set all the screen, canvas, and bitmap variables that
  573. // aren't set by the gr_set_mode call:
  574. grd_curscreen->sc_canvas.cv_color = 0;
  575. grd_curscreen->sc_canvas.cv_drawmode = 0;
  576. grd_curscreen->sc_canvas.cv_font = NULL;
  577. grd_curscreen->sc_canvas.cv_font_fg_color = 0;
  578. grd_curscreen->sc_canvas.cv_font_bg_color = 0;
  579. gr_set_current_canvas( &grd_curscreen->sc_canvas );
  580. if (!dpmi_allocate_selector( &gr_fade_table, 256*GR_FADE_LEVELS, &gr_fade_table_selector ))
  581. Error( "Error allocating fade table selector!" );
  582. if (!dpmi_allocate_selector( &gr_palette, 256*3, &gr_palette_selector ))
  583. Error( "Error allocating palette selector!" );
  584. // if (!dpmi_allocate_selector( &gr_inverse_table, 32*32*32, &gr_inverse_table_selector ))
  585. // Error( "Error allocating inverse table selector!" );
  586. // Set flags indicating that this is installed.
  587. gr_installed = 1;
  588. atexit(gr_close);
  589. return 0;
  590. }
  591. int gr_mode13_checkmode()
  592. {
  593. if (isvga())
  594. return 0;
  595. else
  596. return 1;
  597. }
  598. // 0=Mode set OK
  599. // 1=No VGA adapter installed
  600. // 2=Program doesn't support this VESA granularity
  601. // 3=Monitor doesn't support that VESA mode.:
  602. // 4=Video card doesn't support that VESA mode.
  603. // 5=No VESA driver found.
  604. // 6=Bad Status after VESA call/
  605. // 7=Not enough DOS memory to call VESA functions.
  606. // 8=Error using DPMI.
  607. // 9=Error setting logical line width.
  608. // 10=Error allocating selector for A0000h
  609. // 11=Not a valid mode support by gr.lib
  610. int gr_check_mode(int mode)
  611. {
  612. switch(mode)
  613. {
  614. case 19:
  615. case SM_320x200C:
  616. case SM_320x200U:
  617. case SM_320x240U:
  618. case SM_360x200U:
  619. case SM_360x240U:
  620. case SM_376x282U:
  621. case SM_320x400U:
  622. case SM_320x480U:
  623. case SM_360x400U:
  624. case SM_360x480U:
  625. case SM_360x360U:
  626. case SM_376x308U:
  627. case SM_376x564U: return gr_mode13_checkmode();
  628. case SM_640x400V: return gr_vesa_checkmode( 0x100 );
  629. case SM_640x480V: return gr_vesa_checkmode( 0x101 );
  630. case SM_800x600V: return gr_vesa_checkmode( 0x103 );
  631. case SM_1024x768V: return gr_vesa_setmode( 0x105 );
  632. case SM_640x480V15: return gr_vesa_setmode( 0x110 );
  633. case SM_800x600V15: return gr_vesa_setmode( 0x113 );
  634. }
  635. return 11;
  636. }
  637.