home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / 3DGPL 1.0 / CODE / HARDWARE / 386-GCC / HARDWARE.C next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  3.8 KB  |  107 lines  |  [TEXT/MACA]

  1. /** 3DGPL *************************************************\
  2.  *  (MSDOS, i386+, VGA, DJGPP)                            *
  3.  *  Header for hardware specific stuff.                   *
  4.  *                                                        *
  5.  *  Defines:                                              *
  6.  *    HW_open_screen         opening output surface;      *
  7.  *    HW_blit                colourmap onto the screen;   *
  8.  *    HW_close_screen        closing output;              *
  9.  *                                                        *
  10.  *    HW_run_event_loop      runiing for events;          *
  11.  *    HW_quit_event_loop     quiting running.             *
  12.  *                                                        *
  13.  *  (6/1995) By Sergei Savhenko. (savs@cs.mcgill.ca).     *
  14.  *  Copyright (c) 1995 Sergei Savchenko.                  *
  15.  *  THIS SOURCE CODE CAN'T BE USED FOR COMERCIAL PURPOSES *
  16.  *  WITHOUT AUTHORISATION                                 *
  17. \**********************************************************/
  18.  
  19. #include <pc.h>                             /* kbhit() etc. */
  20. #include "../hardware/hardware.h"           /* all the defenitions */
  21.  
  22. unsigned char *HW_colourmap;                /* where drwaings go to */
  23. int HW_running;                             /* event loop running? */
  24.  
  25. /**********************************************************\
  26.  *  Opening output surface and setting the palette.       *
  27.  *                                                        *
  28.  *  RETURNS: always 1.                                    *
  29.  *  --------                                              *
  30. \**********************************************************/
  31.  
  32. int HW_open_screen(char *display_name,
  33.                    char *screen_name,
  34.                    struct HW_colour palette[256],
  35.                    unsigned char *colourmap
  36.                   )
  37. {
  38.  int i;
  39.  unsigned char r,g,b;
  40.  
  41.  HW_colourmap=colourmap;                    /* for later blits */
  42.  
  43.  asm("movb  $0x13,%%al":::"%al");           /* %al mode number */
  44.  asm("xorb  %%ah,%%ah":::"%ah");            /* function #0 */
  45.  asm("int   $0x10");
  46.  
  47.  for(i=0;i<256;i++)
  48.  {
  49.   r=(unsigned char)palette[i].hw_r;
  50.   g=(unsigned char)palette[i].hw_g;
  51.   b=(unsigned char)palette[i].hw_b;
  52.  
  53.   asm("movb  %0,%%dh":: "g" (r):"%dh");     /* Red */
  54.   asm("movb  %0,%%ch":: "g" (g):"%ch");     /* Green */
  55.   asm("movb  %0,%%cl":: "g" (b):"%cl");     /* Blue */
  56.   asm("movw  %0,%%ebx":: "g" (i):"%ebx");   /* Colour to set */
  57.   asm("movw  $0x1010,%%ax":::"%ax");        /* function 0x10 subfun 0x10 */
  58.   asm("int   $0x10");
  59.  }
  60.  return(1);
  61. }
  62.  
  63. /**********************************************************\
  64.  *  Colormap onto the screen.                             *
  65. \**********************************************************/
  66.  
  67. void HW_blit(void)
  68. {
  69.  HW_copy_int((int*)HW_colourmap,(int*)0xd0000000,HW_COLOURMAP_SIZE_INT);
  70. }
  71.  
  72. /**********************************************************\
  73.  *  Closing output surface.                               *
  74. \**********************************************************/
  75.  
  76. void HW_close_screen(void)
  77. {
  78. }
  79.  
  80. /**********************************************************\
  81.  *  Running the event loop.                               *
  82. \**********************************************************/
  83.  
  84. void HW_run_event_loop(void (*application_main)(void),
  85.                        void (*application_key_handler)(int key_code)
  86.                       )
  87. {
  88.  HW_running=1;
  89.  
  90.  while(HW_running==1)                       /* still running? hmm */
  91.  {
  92.   if(kbhit()) application_key_handler(getkey());
  93.   application_main();
  94.  }
  95. }
  96.  
  97. /**********************************************************\
  98.  *  Stoping the event loop.                               *
  99. \**********************************************************/
  100.  
  101. void HW_quit_event_loop(void)
  102. {
  103.  HW_running=0;                              /* that's it */
  104. }
  105.  
  106. /**********************************************************/
  107.