Advertisement
Caiwan

graph.cpp

Feb 20th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <bios.h>
  2.  
  3. /*
  4.  * Graphic library for DOS
  5.  * By Caiwan / Industrial Revolutioners
  6.  *
  7. */
  8.  
  9. typedef unsigned char uchar;
  10. typedef unsigned short ushort;
  11. typedef unsigned int uint;
  12.  
  13. // sets 13h video mode (320x200)
  14. void initgraph(){
  15.     asm{
  16.         mov ax, 13h
  17.         int 10h
  18.     }
  19. }
  20.  
  21. // sets 10h default mode to text
  22. void closegraph(){
  23.     asm{
  24.         mov ax, 10h
  25.         int 10h
  26.     }
  27. }
  28.  
  29. //puts a pixel to a VRAM offset
  30. void putpixel(ushort offs, uchar p){
  31.     if (offs >= 320*200) return;
  32.     asm {
  33.         mov di, offs
  34.         mov ax, 0xA000
  35.  
  36.         mov es, ax
  37.  
  38.         xor cx, cx
  39.         xor ax, ax
  40.         mov al, p
  41.  
  42.         stosb
  43.     }
  44. }
  45.  
  46. //puts a pixel to a specified xy coord
  47. void putpixel(ushort x, ushort y, uchar p){
  48.     putpixel (320*y+x, p);
  49. }
  50.  
  51. //sets a palette token to a specified RGB color
  52. void setpalette(uchar p, uchar r, uchar g, uchar b) {
  53.     asm {
  54.         xor bx, bx
  55.         xor dx, dx
  56.         xor cx, cx
  57.  
  58.         mov bl, p
  59.         mov dh, r
  60.         mov cl, g
  61.         mov ch, b
  62.  
  63.         mov ax, 1010h
  64.         int 10h
  65.     }
  66. }
  67.  
  68. /*
  69.  * MAIN FUNCTION
  70.  *
  71. */
  72.  
  73. int main(){
  74.     // init graph
  75.     initgraph();
  76.  
  77.     // generate a grazscale palette
  78.     for (uchar i=0; i<255; i++){
  79.         setpalette (i, i, i, i);
  80.     }
  81.  
  82.     ushort kesz = 0;
  83.     //...
  84.  
  85.     do {
  86.         // draw a simple XOR texture
  87.         for (ushort x = 0; x<320; x++)
  88.             for(ushort y = 0; y<200; y++)
  89.                 putpixel(x, y, x^y);
  90.  
  91.     kesz = !_bios_keybrd(_KEYBRD_READY);
  92.     } while (kesz);
  93.  
  94.     // release graphics and get back to DOS
  95.     closegraph();
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement