home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / 3DGPL 1.0 / CODE / HARDWARE / (alt) hardware.c
Encoding:
C/C++ Source or Header  |  1997-03-08  |  4.3 KB  |  124 lines  |  [TEXT/????]

  1. /** 3DGPL *************************************************\
  2.  *  (MSDOS, i386+, VGA, DJGPPv1 or v2)                    *
  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. #if DJGPP == 2
  21. #include <sys/nearptr.h>                    /* v2  __djgpp stuff */
  22. #endif
  23. #include "../hardware/hardware.h"           /* all the defenitions */
  24.  
  25. unsigned char *G_vram;                      /* points video ram */
  26. unsigned char *HW_colourmap;                /* where drwaings go to */
  27. int HW_running;                             /* event loop running? */
  28.  
  29. /**********************************************************\
  30.  *  Opening output surface and setting the palette.       *
  31.  *                                                        *
  32.  *  RETURNS: always 1.                                    *
  33.  *  --------                                              *
  34. \**********************************************************/
  35.  
  36. int HW_open_screen(char *display_name,
  37.                    char *screen_name,
  38.                    struct HW_colour palette[256],
  39.                    unsigned char *colourmap
  40.                   )
  41. {
  42.  int i;
  43.  unsigned char r,g,b;
  44.  
  45. #if DJGPP == 1
  46.  G_vram=(unsigned char*)0xd0000000;
  47. #endif
  48. #if DJGPP == 2
  49.  G_vram=(unsigned char*)0xa0000+__djgpp_conventional_base;
  50. #endif
  51.  
  52.  HW_colourmap=colourmap;                    /* for later blits */
  53.  
  54.  asm("movb  $0x13,%%al":::"%al");           /* %al mode number */
  55.  asm("xorb  %%ah,%%ah":::"%ah");            /* function #0 */
  56.  asm("int   $0x10");
  57.  
  58.  for(i=0;i<256;i++)
  59.  {
  60.   r=(unsigned char)palette[i].hw_r;
  61.   g=(unsigned char)palette[i].hw_g;
  62.   b=(unsigned char)palette[i].hw_b;
  63.  
  64.   asm("movb  %0,%%dh":: "g" (r):"%dh");     /* Red */
  65.   asm("movb  %0,%%ch":: "g" (g):"%ch");     /* Green */
  66.   asm("movb  %0,%%cl":: "g" (b):"%cl");     /* Blue */
  67.   asm("movw  %0,%%ebx":: "g" (i):"%ebx");   /* Colour to set */
  68.   asm("movw  $0x1010,%%ax":::"%ax");        /* function 0x10 subfun 0x10 */
  69.   asm("int   $0x10");
  70.  }
  71.  return(1);
  72. }
  73.  
  74. /**********************************************************\
  75.  *  Colormap onto the screen.                             *
  76. \**********************************************************/
  77.  
  78. void HW_blit(void)
  79. {
  80. #if DJGPP == 2
  81.  __djgpp_nearptr_enable();
  82. #endif
  83.  HW_copy_int((int*)HW_colourmap,(int*)G_vram,HW_COLOURMAP_SIZE_INT);
  84. #if DJGPP == 2
  85.  __djgpp_nearptr_disable();
  86. #endif
  87. }
  88.  
  89. /**********************************************************\
  90.  *  Closing output surface.                               *
  91. \**********************************************************/
  92.  
  93. void HW_close_screen(void)
  94. {
  95. }
  96.  
  97. /**********************************************************\
  98.  *  Running the event loop.                               *
  99. \**********************************************************/
  100.  
  101. void HW_run_event_loop(void (*application_main)(void),
  102.                        void (*application_key_handler)(int key_code)
  103.                       )
  104. {
  105.  HW_running=1;
  106.  
  107.  while(HW_running==1)                       /* still running? hmm */
  108.  {
  109.   if(kbhit()) application_key_handler(getkey());
  110.   application_main();
  111.  }
  112. }
  113.  
  114. /**********************************************************\
  115.  *  Stoping the event loop.                               *
  116. \**********************************************************/
  117.  
  118. void HW_quit_event_loop(void)
  119. {
  120.  HW_running=0;                              /* that's it */
  121. }
  122.  
  123. /**********************************************************/
  124.