home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 421_01 / vx.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-16  |  2.8 KB  |  167 lines

  1. // VX_C
  2.  
  3. // A class implementing a virtual 320x240x16/160x240x256 screen in mode x.
  4.  
  5. // INCLUDES
  6.  
  7. #include <dos.h>
  8. #include <stdlib.h>
  9.  
  10. #include "vx.h"
  11.  
  12. // METHODS
  13.  
  14. // CONSTRUCTOR
  15.  
  16. vx_C::vx_C()
  17. {
  18.   _AX=0x0013;
  19.   VGAINT;
  20.   asm jnc vga_ok
  21.   exit(1);
  22. vga_ok:
  23.   outport(SC_INDEX,0x0604);
  24.   outport(SC_INDEX,0x0100);
  25.   outportb(MISC_OUTPUT,0xe3);
  26.   outport(SC_INDEX,0x0300);
  27.   outportb(CRTC_INDEX,0x11);
  28.   _AL=inportb(CRTC_INDEX+1)&0x7f;
  29.   outportb(CRTC_INDEX+1,_AL);
  30.   outport(CRTC_INDEX,0x0d06);
  31.   outport(CRTC_INDEX,0x3e07);
  32.   outport(CRTC_INDEX,0x4109);
  33.   outport(CRTC_INDEX,0xea10);
  34.   outport(CRTC_INDEX,0xac11);
  35.   outport(CRTC_INDEX,0xdf12);
  36.   outport(CRTC_INDEX,0x0014);
  37.   outport(CRTC_INDEX,0xe715);
  38.   outport(CRTC_INDEX,0x0616);
  39.   outport(CRTC_INDEX,0xe317);
  40.   outport(SC_INDEX,0x0f02);
  41.   _ES=0xa000;
  42.   _AX=_DI=0;
  43.   _CX=0x8000;
  44.   asm rep stosw
  45. }
  46.  
  47. // DESTRUCTOR
  48.  
  49. vx_C::~vx_C()
  50. {
  51. }
  52.  
  53. // FRAME
  54.  
  55. void vx_C::frame(void)
  56. {
  57.   while (inportb(0x3da)&8);
  58.   while (!(inportb(0x3da)&8));
  59. }
  60.  
  61. // WRITEPIXEL
  62.  
  63. void vx_C::writepixel(word pos,byte plane, byte color)
  64. {
  65.   asm mov cl,plane
  66.   asm mov ax,0x0100+MAP_MASK
  67.   asm shl ah,cl
  68.   asm mov dx,SC_INDEX
  69.   asm out dx,ax
  70.   asm mov di,pos
  71.   asm mov ax,0xa000
  72.   asm mov es,ax
  73.   asm mov al,color
  74.   asm mov es:[di],al
  75. }
  76.  
  77. // SETOFFSET
  78.  
  79. void vx_C::setoffset(word newoffset)
  80. {
  81.   if (offset==newoffset)
  82.     return;
  83.   if ((offset&255)==(newoffset&255))
  84.   {
  85.     asm mov ax,newoffset
  86.     asm mov al,0x0c
  87.     asm mov dx,CRTC_INDEX
  88.     asm out dx,ax
  89.   }
  90.   else
  91.   {
  92.     asm mov ax,newoffset
  93.     asm mov bh,al
  94.     asm mov ch,ah
  95.     asm mov bl,0x0d
  96.     asm mov cl,0x0c
  97.     asm mov dx,CRTC_INDEX
  98.     asm mov ax,bx
  99.     asm cli
  100.     asm out dx,ax
  101.     asm mov ax,cx
  102.     asm out dx,ax
  103.     asm sti
  104.   }
  105.   offset=newoffset;
  106. }
  107.  
  108. // SETRGB
  109.  
  110. void vx_C::setrgb(byte color, byte red,byte green,byte blue)
  111. {
  112.   outportb(0x3c8,color);
  113.   outportb(0x3c9,red);
  114.   outportb(0x3c9,green);
  115.   outportb(0x3c9,blue);
  116. }
  117.  
  118. byte vx_C::getpixel(word x,word y)
  119. {
  120.   word offset_2=offset;
  121.   asm mov ax,80
  122.   asm mul y
  123.   asm mov bx,x
  124.   asm mov cx,bx
  125.   asm shr bx,1
  126.   asm shr bx,1
  127.   asm add bx,offset_2
  128.   asm add bx,ax // bx = position in VRAM
  129.   asm mov ax,0xa000
  130.   asm mov es,ax
  131.   asm mov ah,cl
  132.   asm and ah,0x03
  133.   asm mov al,READ_MAP
  134.   asm mov dx,GC_INDEX
  135.   asm out dx,ax
  136.   asm mov al,es:[bx]
  137. }
  138.  
  139. // BLOCKFILL
  140.  
  141. // Fills a strip in vram with the chosen color. Note: Positions are given
  142. // in bytes, not pixels.
  143.  
  144. void vx_C::blockfill(word start,word end,byte data)
  145. {
  146.     asm mov  dx,SC_INDEX
  147.     asm mov  al,MAP_MASK
  148.     asm out  dx,al
  149.     asm inc  dx
  150.  
  151.     asm mov  al,0x0f
  152.     asm out  dx,al
  153.  
  154.     asm mov ax,0xa000
  155.     asm mov es,ax
  156.     asm mov di,start
  157.     asm mov cx,end
  158.     asm sub cx,start
  159.     asm inc cx
  160.     asm mov al,data
  161.     asm rep stosb
  162.  
  163.     asm mov dx,GC_INDEX+1
  164.     asm mov al,0xff
  165.     asm out dx,al
  166. }
  167.