home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume38 / tessel / part02 / tmsmodes.c < prev    next >
C/C++ Source or Header  |  1993-06-21  |  9KB  |  260 lines

  1. /*+-----------------------------------------------------------------------+
  2.  *| The following module contains routines which access the advanced      |
  3.  *| graphics modes of a Hercules Graphics Station Card.                   |
  4.  *|                                                                       |
  5.  *| Author: Michael S. A. Robb         Version: 1.1        Date: 16/06/93 |
  6.  *+-----------------------------------------------------------------------+
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12. #include <dos.h>
  13. #include <mem.h>
  14.  
  15. #include "hardware.h"
  16. #include "colours.h"
  17. #include "tmsmodes.h"
  18.  
  19. /*+-----------------------------------------------------------------------+
  20.  *| The following variables are used to store the current dimensions of   |
  21.  *| the screen.                                                           |
  22.  *+-----------------------------------------------------------------------+
  23.  */
  24.  
  25. WORD     screen_width;     /* Stores screen pixel width    */
  26. WORD     screen_height;    /* Stores screen pixel height.  */
  27. LONG     screen_pitch;     /* Stores screen line pitch.    */
  28. LONG     screen_vramwidth; /* Stores VRAM width in pixels. */
  29.  
  30. /*+-----------------------------------------------------------------------+
  31.  *| The following data defines the 512 x 256 x 32 bit graphics mode.      |
  32.  *+-----------------------------------------------------------------------+
  33.  */
  34.  
  35. TMS34010_MODE mode512x256x32bit =
  36.   {
  37.   "512 x 256 x 32 bits",
  38.   8,   12,   76,   80,             /* Horizontal timings.   */
  39.   1,   35,  547,  548,             /* Vertical   timings.   */
  40.  
  41.   MODE_UNINTERLACED | MODE_2KBYTE, /* Display    controls.  */
  42.   0xFFFD,
  43.   0x0000,
  44.  
  45.   CLOCK_20000MHZ,                  /* External   controls.  */
  46.   PIXEL_SIZE32,
  47.   VSCAN_UNINTERLACED,
  48.   DEFAULT_24BIT,
  49.  
  50.   512, 256, 32,                    /* Screen dimensions.    */
  51.   0x4000,                          /* Display pitch - bits. */
  52.   };
  53.  
  54. /*+-----------------------------------------------------------------------+
  55.  *| The following data defines the 512 x 480 x 32 bit graphics mode.      |
  56.  *+-----------------------------------------------------------------------+
  57.  */
  58.  
  59. TMS34010_MODE mode512x480x32bit =
  60.   {
  61.   "512 x 480 x 32 bits",
  62.   8,   12,   76,   80,             /* Horizontal timings.   */
  63.   1,   35,  515,  525,             /* Vertical   timings.   */
  64.  
  65.   MODE_UNINTERLACED | MODE_2KBYTE, /* Display    controls.  */
  66.   0xFFFC,
  67.   0x0000,
  68.  
  69.   CLOCK_20000MHZ,                  /* External   controls.  */
  70.   PIXEL_SIZE32,
  71.   VSCAN_UNINTERLACED,
  72.   DEFAULT_24BIT,
  73.  
  74.   512, 480, 32,                    /* Screen dimensions.    */
  75.   0x4000,                          /* Display pitch - bits. */
  76.   };
  77.  
  78. /*+-----------------------------------------------------------------------+
  79.  *| The following data defines the 512 x 512 x 32 bit graphics mode.      |
  80.  *+-----------------------------------------------------------------------+
  81.  */
  82.  
  83. TMS34010_MODE mode512x512x32bit =
  84.   {
  85.   "512 x 512 x 32 bits",
  86.    8,  12,   76,  80,              /* Horizontal timings.   */
  87.    1,  16,  528, 544,              /* Vertical   timings.   */
  88.  
  89.   MODE_UNINTERLACED | MODE_2KBYTE, /* Display    controls.  */
  90.   0xFFFC,
  91.   0x0000,
  92.  
  93.   CLOCK_20000MHZ,                  /* External   controls.  */
  94.   PIXEL_SIZE32,
  95.   VSCAN_UNINTERLACED,
  96.   DEFAULT_24BIT,
  97.  
  98.   512, 512, 32,                    /* Screen dimensions.    */
  99.   0x4000,                          /* Display pitch - bits. */
  100.   };
  101.  
  102. /*+-----------------------------------------------------------------------+
  103.  *| The following routine is used to set the value of a TMS34010 host     |
  104.  *| interface register.                                                   |
  105.  *+-----------------------------------------------------------------------+
  106.  */
  107.  
  108. void tms34010_sethostregister( address, data )
  109.   ADDRESS   address;
  110.   WORD      data;
  111.   {
  112.   *( (WORD far *) address ) = data;
  113.   }
  114.  
  115. /*+-----------------------------------------------------------------------+
  116.  *| The following routine is used to get the value of a TMS34010 host     |
  117.  *| interface register.                                                   |
  118.  *+-----------------------------------------------------------------------+
  119.  */
  120.  
  121. WORD tms34010_gethostregister( address )
  122.   ADDRESS address;
  123.   {
  124.   return( *( (WORD far *) address) );
  125.   }
  126.  
  127. /*+-----------------------------------------------------------------------+
  128.  *| The following routine is used to set the address accessed via the     |
  129.  *| TMS34010 host registers.                                              |
  130.  *+-----------------------------------------------------------------------+
  131.  */
  132.  
  133. void tms34010_setaddress( address )
  134.   ADDRESS address;
  135.   {
  136.   tms34010_sethostregister( CPU_ADDRLO,   (WORD) ( address &  0xFFFFL ) );
  137.   tms34010_sethostregister( CPU_ADDRHI,   (WORD) ( address >> 16L     ) );
  138.   }
  139.  
  140. /*+-----------------------------------------------------------------------+
  141.  *| The following routine is used to set the value of TMS34010 registers. |
  142.  *+-----------------------------------------------------------------------+
  143.  */
  144.  
  145. void tms34010_setregister( address, data )
  146.   ADDRESS address;
  147.   WORD    data;
  148.   {
  149.   tms34010_sethostregister( CPU_ADDRLO,   (WORD) ( address &  0xFFFFL ) );
  150.   tms34010_sethostregister( CPU_ADDRHI,   (WORD) ( address >> 16L     ) );
  151.   tms34010_sethostregister( CPU_SLOWDATA, data );
  152.   }
  153.  
  154. /*+-----------------------------------------------------------------------+
  155.  *| The following routine is used to get the value of TMS34010 registers. |
  156.  *+-----------------------------------------------------------------------+
  157.  */
  158.  
  159. WORD tms34010_getregister( address )
  160.   ADDRESS address;
  161.   {
  162.   tms34010_sethostregister( CPU_ADDRLO,   (WORD) ( address &  0xFFFFL ) );
  163.   tms34010_sethostregister( CPU_ADDRHI,   (WORD) ( address >> 16L     ) );
  164.  
  165.   return( tms34010_gethostregister( CPU_SLOWDATA ) );
  166.   }
  167.  
  168. /*+-----------------------------------------------------------------------+
  169.  *| The following routine is used to set up a TMS34010 graphics mode.     |
  170.  *+-----------------------------------------------------------------------+
  171.  */
  172.  
  173. void tms34010_mode( mode )
  174.   TMS34010_MODE *mode;
  175.   {
  176.   WORD n, *data = &mode -> tms_hesync;
  177.  
  178.   tms34010_sethostregister(   CPU_CONTROL,    HOST_AUTOINCR );
  179.   tms34010_setaddress(        IO_HESYNC                   );
  180.  
  181.   for ( n = 10; n--; data++ )
  182.     tms34010_sethostregister( CPU_SLOWDATA, *data );
  183.  
  184.   tms34010_sethostregister( CPU_CONTROL,    HOST_NOINCR   );
  185.   tms34010_setregister(     IO_DPYTAP,      mode -> tms_dpytap );
  186.   tms34010_setregister(     CONFIG1_WRITE,  mode -> tms_clockbase | 0x0008 );
  187.   tms34010_setregister(     CONFIG2_WRITE,  mode -> tms_pixelsize |
  188.                                             mode -> tms_videotiming );
  189.  
  190.   tms34010_setregister(     RAMDAC_COMMAND, mode -> tms_ramdac      );
  191.   tms34010_setregister(     CONFIG1_WRITE,  mode -> tms_clockbase & 0x00F7 );
  192.   tms34010_setaddress(      NULL );
  193.  
  194.   screen_width     = mode -> tms_xmax;
  195.   screen_height    = mode -> tms_ymax;
  196.   screen_pitch     = mode -> tms_dpitch;
  197.  
  198.   screen_vramwidth = mode -> tms_dpitch / mode -> tms_psize;
  199.   }
  200.  
  201. /*+-----------------------------------------------------------------------+
  202.  *| The following routine is used to restore the VGA graphics mode.       |
  203.  *+-----------------------------------------------------------------------+
  204.  */
  205.  
  206. void tms34010_setvga( void )
  207.   {
  208.   tms34010_sethostregister( CPU_CONTROL,   HOST_AUTOINCR );
  209.  
  210.   tms34010_setregister(     CONFIG1_WRITE, 0x000A        );
  211.   tms34010_setregister(     CONFIG2_WRITE, 0x000C        );
  212.  
  213.   outportb(                 0x03C6,        0x004B );
  214.  
  215.   tms34010_setregister(     CONFIG1_WRITE, 0x0002        );
  216.   tms34010_sethostregister( CPU_CONTROL,   HOST_NOINCR   );
  217.  
  218.   textmode( 0x00 );
  219.   textmode( 0x03 );
  220.  
  221.   clrscr();
  222.   }
  223.  
  224. /*+----------------------------------------------------------------------+
  225.  *| This subroutine is used to fill a block of memory with a specific    |
  226.  *| colour.                                                              |
  227.  *+----------------------------------------------------------------------+
  228.  */
  229.  
  230. void tms34010_fillblockaddr32( base, xlo, ylo, width, height, col )
  231.   ADDRESS  base;
  232.   WORD     xlo, ylo;
  233.   WORD     width, height;
  234.   long     col;
  235.   {
  236.   WORD y, size;
  237.   WORD col_lo = col & 0xFFFFL;
  238.   WORD col_hi = col >> 16;
  239.  
  240.   ADDRESS address = (( (ADDRESS) xlo + (ADDRESS) ylo * 512 ) << 5) + base;
  241.  
  242.   tms34010_sethostregister( CPU_CONTROL, HOST_AUTOINCR  );
  243.  
  244.   for ( y = height; y--; address += 0x4000L )
  245.     {
  246.     tms34010_setaddress( address );
  247.  
  248.     for ( size = width; size--; )
  249.       {
  250.       tms34010_sethostregister( CPU_SLOWDATA, col_hi );
  251.       tms34010_sethostregister( CPU_SLOWDATA, col_lo );
  252.       }
  253.     }
  254.  
  255.   tms34010_sethostregister( CPU_CONTROL, HOST_NOINCR );
  256.   }
  257.  
  258.  
  259.  
  260.