/*
	vga13.c
	
   This example demonstrates the use of a VGA card driven by a Z104 or a
   ZISA board. Mode 13 of the VGA is used with the vga drivers	and PC/104
   memory read and write functions.

   Supports the following PC104 VGA cards:
        AMPRO PC104 VGA Card
        Trident ISA 8900D VGA Card
        Acumos ISA VGA Card
        Boca ISA VGA006

   ISA VGA Cards are supported by the ZISA card.

	Uncomment #define FINDFONT if the bios font areas are other than the
	hardware values in z104.lib. If FINDFONT is defined, the bios font
	areas are scanned from the VGA bios.

	Uncomment #define TRIDENT8x256 if your Trident8900D VGA card uses
	8x256  DRAM.
*/

#use "default.h"

#if (BOARD_TYPE!=Z104ISA)
#fatal "This program only runs on the Z104 or ZISA boards."
#endif

#define FINDFONT
//#define TRIDENT8x256

// define the data structure for mode 13
// Note: Mode 13 is not supported by the library.

struct VGADATA _vgamode13 = { 
                            0x63, 
                            
                            0x03, 0x01, 0x0f, 0x00, 0x0e,

                            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
                            0x41, 0x00, 0x0f, 0x00, 0x00,

                            0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
                            0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x9c, 0x8e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
                            0xff,

                            0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f,
                            0xff};

void  wait_demo(unsigned int delay);

main()
{
   int i,j;
   char buf[320];   
   unsigned long vaddress;
   
   if( VGAInitData(_vgamode13) == -1 ) 
   {
      printf("VGA Card Not Found or Unsupported !!!\n");
      while(1) runwatch();
   }

   printf("Proceeding with VGA Mode 13 Demo Program !!!\n");

   WritePCPort(DAC_INDX,0x00);      // set DAC INDEX to zero
   for(i=0;i<64;i++)                // set the gray scale
   {
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
      WritePCPort(DAC_DATA,i);
   }
   
   while(1)
   {
      vaddress = 0xa0000L;             
      for(i=0;i<320;i++) buf[i] = 0x00;
      for(i=0;i<200;i++)               
      {
         WritePCMem(vaddress, buf, 320);     // write all zeroes
         vaddress = vaddress+320L;
      }
      wait_demo(30000);

      vaddress = 0xa0000L;
      for(i=0;i<320;i++) buf[i] = 0xff;
      for(i=0;i<200;i++)               
      {
         WritePCMem(vaddress, buf, 320);  // write all 0xff's
         vaddress = vaddress+320L;
      }

      wait_demo(30000);
      vaddress = 0xa0000L;
      for(j=0;j<320;j++) buf[j] = j;
      for(i=0;i<200;i++)
      {
         WritePCMem(vaddress, buf, 255);   // write horizontal gray scales
         vaddress = vaddress+320L;
      }

      wait_demo(30000);
      vaddress = 0xa0000L;
      for(i=0;i<200;i++)
      {
         for(j=0;j<320;j++) buf[j] = i;
         WritePCMem(vaddress, buf, 320);  // write vertical gray scales
         vaddress = vaddress + 320L;
      }

      wait_demo(30000);
      vaddress = 0xa0000L;
      for(i=0;i<80;i++)          // create pattern
      {
         WritePCByte(vaddress++, 0x00);
         WritePCByte(vaddress++, 0x00);
         WritePCByte(vaddress++, 0x00);
         WritePCByte(vaddress++, 0x00);
         WritePCByte(vaddress++, 0xff);
         WritePCByte(vaddress++, 0xff);
         WritePCByte(vaddress++, 0xff);
         WritePCByte(vaddress++, 0xff);
      
      }
      
      // read pattern back
      vaddress = 0xa0000L;
      ReadPCMem(vaddress, buf, 320);
      for(i=0;i<200;i++)
      {
         WritePCMem(vaddress, buf, 320);
         vaddress = vaddress + 320L;
      }
      wait_demo(30000);
   }
   while(1) runwatch();
}

void wait_demo(unsigned int delay)
{
   for(delay; delay>0; delay--);
}



