Advertisement
Caiwan

graph2.cpp

Feb 22nd, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 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. #include <math.h>
  74.  
  75. int main(){
  76.     // init graph
  77.     initgraph();
  78.  
  79.     // generate a grazscale palette
  80.     for (uchar i=0; i<255; i++){
  81.         setpalette (i, i >> 2, i >> 1, i);
  82.     }
  83.  
  84.     ushort kesz = 0;
  85.     float t = 0.0f;
  86.     do {
  87.         float k = 1.5f*(1.1f+sin(t));
  88.         float ca = cos(.5*k+t);
  89.         float sa = sin(.5*k+t);
  90.  
  91.         for (ushort x = 0; x<320; x++)
  92.             for(ushort y = 0; y<200; y++){
  93.  
  94.                 float _x = ((float)x-160) * k;
  95.                 float _y = ((float)y-100) * k;
  96.  
  97.                 float __x = ca * _x - sa * _y;
  98.                 float __y = sa * _x + ca * _y;
  99.  
  100.                 uchar xx = (uchar)__x;
  101.                 uchar yy = (uchar)__y;
  102.  
  103.                 uchar tx = xx^yy;
  104.  
  105.                 putpixel(x, y, tx);
  106.             }
  107.  
  108.         t += 0.1f;
  109.  
  110.         kesz = !_bios_keybrd(_KEYBRD_READY);
  111.     } while (kesz);
  112.  
  113.     // release graphics and get back to DOS
  114.     closegraph();
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement