home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / disk22 / modosx / modox.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-23  |  6.2 KB  |  150 lines

  1. /*
  2. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒C▒O▒M▒P▒I▒L▒E▒R▒▒▒▒▒▒▒▒▒▒▒S▒O▒F▒T▒W▒A▒R▒E▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  3. ▒▒                                                                      ▒▒
  4. ▒▒  MODOX.h                                                             ▒▒
  5. ▒▒                                                                      ▒▒
  6. ▒▒  Esta librería es introductoria y a partir del próximo número estará ▒▒
  7. ▒▒  completamente  optimizada para  286+  usando assembler en  su mayor ▒▒
  8. ▒▒  parte. Para usarla en tus programas debe estar en el directorio ac- ▒▒
  9. ▒▒  tual en el momento de la compilación e incluir la línea:            ▒▒
  10. ▒▒                                                                      ▒▒
  11. ▒▒  #include "MODOX.h"                                                  ▒▒
  12. ▒▒                                                                      ▒▒
  13. ▒▒  1996 Compiler SoftWare. Para dudas y contactos leer el fichero de   ▒▒
  14. ▒▒  texto COMPILER.NFO                                                  ▒▒
  15. ▒▒                                                                      ▒▒
  16. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  17. */
  18.  
  19. #include <dos.h>                              /* outport */
  20.  
  21. #define SEQU_ADDR 0x3c4
  22. #define CRTC_ADDR 0x3d4
  23. #define GRAC_ADDR 0x3ce
  24.  
  25. /*
  26. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  27. ▒▒                       DECLARACIONES DE FUNCIONES                     ▒▒
  28. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  29. */
  30.  
  31. void Set_320x200X ( void );
  32. void Set_320x240X ( void );
  33. void PutPixelX( int, int, char ); 
  34. unsigned char GetPixelX( int, int );
  35.  
  36. /*
  37. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  38. ▒▒ Set_320x200X();                                                      ▒▒
  39. ▒▒                                                                      ▒▒
  40. ▒▒ Inicializa el Modo 13X de 320x200 a 256 colores en sistema 1x4.      ▒▒
  41. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  42. */
  43.  
  44. void Set_320x200X ( )            
  45.   {
  46.     asm  mov ax , 13h                          /* inicializamos modo 13h estándar */
  47.     asm  int 10h
  48.         
  49.         outport( SEQU_ADDR , 0x0604 );       /* ponemos el bit CHAIN-4 a 0 */
  50.         outport( CRTC_ADDR , 0xE317);        /* ajuste del modo de palabras */
  51.         outport( CRTC_ADDR , 0x0014);        /* ajuste del modo de dobles palabras */
  52.         outport( SEQU_ADDR , 0x0F02);        /* seleccionar los cuatro planos para...*/
  53.  
  54.     asm {                                    /* ...borrar la pantalla */
  55.          mov ax , 0xA000 
  56.          mov es , ax
  57.          xor di , di
  58.          xor ax , ax
  59.          mov cx , 0x8000
  60.          rep stosw
  61.         }                                                  
  62.   }
  63.  
  64.  
  65. /*
  66. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  67. ▒▒ Set_320x240X();                                                      ▒▒
  68. ▒▒                                                                      ▒▒
  69. ▒▒ Inicializa el Modo X de 320x240 a 256 colores en sistema 1x4.        ▒▒
  70. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  71. */
  72.  
  73. void Set_320x240X( )
  74.         {
  75.  
  76.         Set_320x200X( );       /* primero inicializamos 13X */
  77.  
  78.         outportb(0x3C2, 0xE3);  
  79.         outport(CRTC_ADDR, 0x2C11);         /* permitir escritura */
  80.         outport(CRTC_ADDR, 0x0D06);         /* Total vertical */
  81.         outport(CRTC_ADDR, 0x3E07);         /* Overflow Register */
  82.         outport(CRTC_ADDR, 0xEA10);         /* Vertical retrace start */
  83.         outport(CRTC_ADDR, 0xAC11);         /* Vertical retrace end y Write prot. */
  84.         outport(CRTC_ADDR, 0xDF12);         /* Vertical display enable end */
  85.         outport(CRTC_ADDR, 0xE715);         /* Start vertical blanking */
  86.         outport(CRTC_ADDR, 0x0616);         /* End vertical blanking */
  87.  
  88.         }
  89.  
  90.  
  91. /*
  92. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  93. ▒▒ PutPixelX();                                                         ▒▒
  94. ▒▒                                                                      ▒▒
  95. ▒▒ Coloca un punto en la primera página en (X,Y) de color color.        ▒▒
  96. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  97. */
  98.  
  99. void PutPixelX( int x, int y, char color ) 
  100. {
  101. unsigned int offs;
  102.  
  103. outportb( SEQU_ADDR , 0x02 );                  /* función seleccionar plano */
  104. outportb( SEQU_ADDR+1, 0x01 << ( x & 3 ) );    /* esto calcula automáticamente 
  105.                                                   el plano a partir de los 2 
  106.                                                   últimos bits de la coord.x*/
  107.  
  108. offs = (y<<6) + (y<<4) + (x>>2);                 /* calculamos el offset */
  109.                                                  /* esta línea equivale a
  110.                                                     off = (80*y) + (x/4) ; 
  111.                                                    pero es MUCHO más rápida.*/
  112. asm {
  113.         mov ax , 0xa000
  114.         mov es , ax
  115.         mov di , offs
  116.         mov al , color
  117.         stosb                                      /* ponemos el punto */
  118.     }
  119. }
  120.  
  121. /*
  122. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  123. ▒▒ GetPixelX();                                                         ▒▒
  124. ▒▒                                                                      ▒▒
  125. ▒▒ Devuelve el color de un pixel en (X,Y) en sistema 1x4.               ▒▒
  126. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  127. */
  128.  
  129. unsigned char GetPixelX(int x, int y)
  130.         {
  131. unsigned int offs;
  132.  
  133.         outport(GRAC_ADDR, 0x04);
  134.         outport(GRAC_ADDR+1, x & 3 );     /* nº de plano */
  135.  
  136. offs = (y<<6) + (y<<4) + (x>>2);                 /* calculamos el offset */
  137.                                                  /* esta línea equivale a
  138.                                                    off = (80*y) + (x/4) ; 
  139.                                                    pero es MUCHO más rápida.*/
  140. asm {
  141.         mov ax , 0xa000
  142.         mov es , ax
  143.         mov di , offs                          /* lo leemos */
  144.         mov al, es:[di]
  145.     }
  146.  
  147.    return( _AL );                              /* y lo devolvemos */
  148. }
  149.  
  150.