home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / SNOWTRO.ZIP / SNOW.C < prev    next >
C/C++ Source or Header  |  1994-12-06  |  11KB  |  507 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include <fcntl.h>
  7. #include <io.h>
  8. #include <ctype.h>
  9. #include <alloc.h>
  10. #include <dir.h>
  11. #include <process.h>
  12.  
  13. extern char FUCKYOU[64768];
  14. extern char FONT[33588];
  15.  
  16. unsigned int *fontoff;
  17.  
  18. #define MAXFLAKES   3000
  19. #define SPEEDFACTOR 4
  20. #define SHIFTFACTOR 3
  21.  
  22. int SCREENTOP=130;
  23. int SCREENSTART=10;
  24.  
  25. #undef outportb
  26. #undef outp
  27. #undef inp
  28. #undef inportb
  29.  
  30. int killflakes=0;
  31.  
  32. typedef struct {
  33.     int speed;
  34.     int xloc;
  35.     int yloc;
  36.     int plotted;
  37. } flake;
  38.  
  39. flake *snow[MAXFLAKES];
  40. char *grfaddr;
  41.  
  42. int poss[100];
  43. int nposs;
  44. int wh=1;
  45.  
  46. char blank[320];
  47.  
  48. void coolcls(void);
  49.  
  50. #define prerow(firstrow) outport(0x3d4,0x08); outport(0x3d5,firstrow)
  51.  
  52. void vsync(void)
  53. {
  54.     asm mov dx,0x3da;
  55. l1:
  56.     asm in al,dx;
  57.     asm test al,8;
  58.     asm jz l1;
  59. l2:
  60.     asm in al,dx;
  61.     asm test al,8;
  62.     asm jnz l2;
  63. }
  64.  
  65. void setoff(char offsetus)
  66. {
  67.     vsync();
  68.     asm MOV DX, 0x3d4;
  69.     asm MOV AL,0x13;
  70.     asm MOV AH, offsetus;
  71.     asm OUT DX,AX;
  72. }
  73.  
  74. void maxscan(int value)
  75. {
  76.         register ptemp;
  77.  
  78.         _BX = (char) value;
  79.         asm MOV AL,9;
  80.         asm MOV AH, BL;
  81.         asm MOV ptemp, AX;
  82.         outport(0x3d4,ptemp);
  83. }
  84.  
  85. void vsync_start(void)
  86. {
  87.     asm mov dx,0x3da;
  88. l1:
  89.     asm in al,dx;
  90.     asm test al,8;
  91.     asm jz l1;
  92. }
  93.  
  94. void vsync_end(void)
  95. {
  96.     asm mov dx,0x3da;
  97. l2:
  98.     asm in al,dx;
  99.     asm test al,8;
  100.     asm jnz l2;
  101. }
  102.  
  103. void startoff(int offsetus)
  104. {
  105.     _BX = offsetus;
  106.  
  107.     asm mov al, 0xc;
  108.     asm mov ah, bh;
  109.     asm mov dx, 0x3d4
  110.     asm out dx, ax
  111.     asm mov al,0xd;
  112.     asm mov ah,bl;
  113.     asm out dx, ax
  114. }
  115.  
  116. void presetrowscan(char s)
  117. {
  118.         char tmp;
  119.  
  120.         outportb(0x3d4, 8);
  121.         tmp=inportb(0x3d5);
  122.         outportb(0x3d5, (tmp & 0xE0) | (s & 0x0F));
  123. }
  124.  
  125. void setscanstart(int i)
  126. {
  127.         vsync_end();
  128.         startoff((i / 16)*80);
  129.         vsync_start();
  130.         presetrowscan(i);
  131. }
  132.  
  133. void setsplitscan(int s)
  134. {
  135.    unsigned int i;
  136.  
  137.    if(wh) i=s; else i=(2*25*16-s);
  138.    setscanstart(i);
  139.    if(wh==1) wh=0; else wh=1;
  140. }
  141.  
  142. void init_split(void)
  143. {
  144.         int vel=1, i, n=1, fd;
  145.  
  146.         i=(25*16);
  147.    
  148.         do {
  149.                 poss[n]=i;
  150.                 i-=(vel / 5);
  151.                 vel++;
  152.                 n++;
  153.         } while( i > 0);
  154.         
  155.         nposs=(n-1);
  156. }
  157.  
  158. void splitin(char *buf)
  159. {
  160.         int i, x;
  161.  
  162.         init_split();
  163.         movedata(FP_SEG(buf), FP_OFF(buf), 0xb800,4000,4000);
  164.         startoff(2000);
  165.         for(x=0;x<4000;x++) pokeb(0xb800,x,0);
  166.         for(x=8000;x<12000;x++) pokeb(0xb800,x,0);
  167.         
  168.         for(i=1;i<nposs;i++) setsplitscan(poss[i]);
  169. }  
  170.  
  171. void splitout(char *buf)
  172. {
  173.         int i, x;
  174.  
  175.         init_split();
  176.         movedata(FP_SEG(buf), FP_OFF(buf), 0xb800,4000,4000);
  177.         for(x=0;x<4000;x++) pokeb(0xb800,x,0);
  178.         for(x=8000;x<12000;x++) pokeb(0xb800,x,0);
  179.         for(i=nposs;i>0;i--) setsplitscan(poss[i]);
  180.  
  181.         movedata(FP_SEG(buf), FP_OFF(buf), 0xb800,0,4000);
  182.         startoff(0); prerow(0);
  183.         for(x=4000;x<8000;x++) pokeb(0xb800,x,0);
  184. }        
  185.  
  186. void changecolor(int kulr, int r)
  187. {
  188.     outp(0x3c8,(char)kulr);
  189.     outp(0x3c9,(char)r);
  190.     outp(0x3c9,(char)r);
  191.     outp(0x3c9,(char)r);
  192. }
  193.  
  194. void makesnow(void)
  195. {
  196.     int x, y=0;
  197.  
  198.     for(x=0;x<MAXFLAKES;x++) snow[x]=(flake *)calloc(1, sizeof(flake));
  199.  
  200.     randomize();
  201.  
  202.     for(x=0;x<MAXFLAKES;x++) {
  203.         delay(1);
  204.         snow[x]->speed = ((rand() % SPEEDFACTOR) + 1);
  205.         snow[x]->xloc = (rand() % 320);
  206.         snow[x]->yloc = (rand() % 200);
  207.         snow[x]->plotted = 1;
  208.     }
  209.  
  210.     for(x=1;x<SPEEDFACTOR+1;x++) {
  211.         y+=(60 / SPEEDFACTOR);
  212.         changecolor((250+x),y);
  213.     }
  214. }
  215.  
  216. char _fastcall getpixel(register int x, register int y)
  217. {
  218.     return( peekb( 0xa000, ( x + (y * 320) ) ) );
  219. }
  220.  
  221. void _fastcall putpixel(register int x, register int y, char color)
  222. {
  223.     pokeb( 0xa000, ( x + (y * 320) ), color);
  224. }
  225.  
  226. void _fastcall blankline(int line)
  227. {
  228.     movedata(FP_SEG(blank), FP_OFF(blank), 0xa000, line*320, 320);
  229. }
  230.  
  231. void _fastcall drawline(int line)
  232. {
  233.     movedata(FP_SEG(FUCKYOU), FP_OFF(FUCKYOU)+(line*320), 0xa000, line*320, 320);
  234. }
  235.  
  236. void _fastcall makenewflake(register int x)
  237. {
  238.     snow[x]->speed = ((rand() % SPEEDFACTOR) + 1);
  239.     snow[x]->xloc = (rand() % 320);
  240.     snow[x]->yloc = (rand() % 200);
  241.     snow[x]->plotted = 1;
  242. }
  243.  
  244. void _fastcall top_clearflake(register int flakeno)
  245. {
  246.     register int offset;
  247.  
  248.     offset = ( snow[flakeno]->xloc + (snow[flakeno]->yloc*320) );
  249.  
  250.     grfaddr[offset]=0;
  251. }
  252.  
  253. void _fastcall top_showflake(register int x)
  254. {
  255.     register int offset;
  256.  
  257.     if(killflakes) return;
  258.  
  259.     offset = ( snow[x]->xloc + (snow[x]->yloc*320) );
  260.  
  261.     grfaddr[offset]=FUCKYOU[offset];
  262. }
  263.  
  264. void _fastcall bottom_showflake(register int x)
  265. {
  266.     register int offset;
  267.  
  268.     if(killflakes) return;
  269.  
  270.     offset = snow[x]->xloc + (snow[x]->yloc * 320);
  271.  
  272.     if( grfaddr[offset] ) {
  273.         snow[x]->plotted=0;
  274.         return;
  275.     }
  276.  
  277.     grfaddr[offset]=(250+snow[x]->speed);
  278.     snow[x]->plotted=1;
  279. }
  280.  
  281. void _fastcall bottom_clearflake(register int x)
  282. {
  283.     register int offset;
  284.  
  285.     if(!snow[x]->plotted) return;
  286.  
  287.     offset = snow[x]->xloc + (snow[x]->yloc * 320);
  288.  
  289.     if(snow[x]->yloc > SCREENSTART) grfaddr[offset]=FUCKYOU[offset];
  290.         else grfaddr[offset]=0;
  291. }
  292.  
  293. void _fastcall doflakes(void)
  294. {
  295.     register int x;
  296.  
  297.     for(x=0;x<MAXFLAKES;x++) {
  298.         if(snow[x]->yloc < SCREENTOP && snow[x]->yloc > SCREENSTART) top_clearflake(x);
  299.             else bottom_clearflake(x);
  300.  
  301.         snow[x]->xloc+=snow[x]->speed;
  302.         snow[x]->yloc+=snow[x]->speed;
  303.  
  304.         if(snow[x]->yloc > 199 || snow[x]->xloc>319) makenewflake(x);
  305.  
  306.         if(snow[x]->yloc < SCREENTOP && snow[x]->yloc > SCREENSTART) top_showflake(x);
  307.             else bottom_showflake(x);
  308.     }
  309. }
  310.  
  311. void showsnow(void)
  312. {
  313.     register int x, tempval;
  314.  
  315.     asm cli;
  316.  
  317.     while(inp(0x60) >= 0x80)  {
  318.         vsync_start();
  319.         doflakes();
  320.     }
  321.  
  322.     for(x=SCREENTOP;x<200;x++) {
  323.         vsync();
  324.         blankline(x);
  325.         SCREENTOP++;
  326.         doflakes();
  327.     }
  328.  
  329.     for(x=0;x<200;x++) {
  330.         vsync();
  331.         blankline(x);
  332.         SCREENSTART++;
  333.         doflakes();
  334.     }
  335.  
  336.     asm sti;
  337. }
  338.  
  339. void slopal(char *pal)
  340. {
  341.     register int x;
  342.  
  343.     outportb(0x3c8, 0);
  344.     for(x=0;x<768;x++) outportb(0x3c9, pal[x]);
  345. }
  346.  
  347. void fade_in(char *_pal)
  348. {
  349.         register int x, y;
  350.         char pal[768];
  351.  
  352.         for(x=0;x<768;x++) pal[x]=0;
  353.  
  354.         for(x=0;x<64;x++) {
  355.             for(y=0;y<768;y++) if(pal[y] < _pal[y]) pal[y]++;
  356.             vsync_start();
  357.             slopal(pal);
  358.         }
  359. }
  360.  
  361. void no_pal(void)
  362. {
  363.         register int x;
  364.         char pal[768];
  365.  
  366.         for(x=0;x<768;x++) pal[x]=0;
  367.         slopal(pal);
  368. }
  369.  
  370. void fadein(char temps[])
  371. {
  372.         int xxx, y;
  373.         char fuck[128];
  374.         int colorama[] = { LIGHTCYAN, LIGHTBLUE, BLUE, LIGHTBLUE, CYAN, LIGHTCYAN,
  375.                            WHITE, LIGHTGRAY };
  376.  
  377.         _setcursortype(_NOCURSOR);
  378.  
  379.         strcpy(fuck," ");
  380.         strcat(fuck, temps);
  381.         strcat(fuck,"        ");
  382.  
  383.         for(xxx=1;xxx<strlen(fuck);xxx++) {
  384.                 textcolor(colorama[0]);
  385.                 gotoxy(xxx,wherey());
  386.                 putch(fuck[xxx]);
  387.                 for(y=0;y<8;y++) {
  388.                 if(xxx>y) {
  389.                         textcolor(colorama[y]);
  390.                         gotoxy(xxx-y,wherey());
  391.                         putch(fuck[xxx-y]);
  392.                         }
  393.                 }
  394.                 delay(45);
  395.         }
  396.         if(wherey() > 24) {
  397.             gotoxy(1,1); delline();
  398.             gotoxy(1,25);
  399.         } else gotoxy(1,wherey()+1);
  400. }
  401.  
  402. void putletter(char ltr, int xval, int yval)
  403. {
  404.     unsigned int letteroff;
  405.     char xsize, ysize;
  406.     register unsigned int x, y, offset, fntoff;
  407.  
  408.     letteroff = fontoff[ltr];
  409.     ltr=FONT[letteroff];
  410.     xsize=FONT[letteroff+1];
  411.     ysize=FONT[letteroff+2];
  412.     letteroff+=3;
  413.  
  414.     for(x=0;x<(unsigned int)xsize;x++) {
  415.         for(y=0;y<(unsigned int)ysize;y++) {
  416.             offset = ( (xval + x) + ( (y + yval) * 320 ) );
  417.             fntoff = ( ( y + ( x * ysize ) ) + letteroff );
  418.             grfaddr[ offset ] = FONT[ fntoff ];
  419.         }
  420.     }
  421. }
  422.  
  423. void putstring(char *thing)
  424. {
  425.     int x;
  426.     static int off, yoff;
  427.  
  428.     for(x=0;x<strlen(thing);x++) {
  429.         if(yoff > 160) {
  430.             off = 0;
  431.             yoff = 0;
  432.             coolcls();
  433.         }
  434.         if(thing[x] == '\n') {
  435.             off = 0;
  436.             yoff += 35;
  437.             continue;
  438.         }
  439.         if(off > 280) {
  440.             off = 0;
  441.             yoff += 35;
  442.         }
  443.         putletter(thing[x], off, yoff);
  444.         off+=FONT[fontoff[thing[x]]+1];
  445.         off+=2;
  446.         delay(50);
  447.     }
  448. }
  449.  
  450. void coolcls(void)
  451. {
  452.     int x;
  453.  
  454.     delay(150);
  455.  
  456.     for(x=0;x<200;x++) {
  457.         vsync_start();
  458.         if( x % 2) movedata(FP_SEG(blank), FP_OFF(blank), 0xa000, (x*320), 320);
  459.     }
  460.     for(x=200;x>-1;x--) {
  461.         vsync_start();
  462.         if(!( x % 2)) movedata(FP_SEG(blank), FP_OFF(blank), 0xa000, (x*320), 320);
  463.     }
  464. }
  465.  
  466. void main(void)
  467. {
  468.     register unsigned int x;
  469.     int oldx, oldy;
  470.     char *buf;
  471.  
  472.     grfaddr=MK_FP(0xa000,0);
  473.     fontoff=MK_FP(FP_SEG(FONT), FP_OFF(FONT)+773);
  474.     buf = calloc(1, 4000);
  475.     oldx=wherex(); oldy=wherey();
  476.  
  477.     movedata(0xb800,0,FP_SEG(buf),FP_OFF(buf), 4000);
  478.     splitin(buf);
  479.  
  480.     textmode(19);
  481.     no_pal();
  482.     movedata(FP_SEG(FUCKYOU), FP_OFF(FUCKYOU)+3200, 0xa000, 3200, 64000-3200);
  483.     fade_in(FUCKYOU+64000);
  484.     makesnow();
  485.     for(x=0;x<48000;x++) pokeb(0xa000,x,0);
  486.     showsnow();
  487.  
  488.     coolcls();
  489.     slopal(FONT+5);
  490.     putstring("lithium\npresents a\nsmall\nintro...");
  491.     delay(1000);
  492.     putstring("coded all\nby poor\nnatas...\ncalled\nsnowtro\n");
  493.     putstring("greets to:\npatch of\navalanche\ncall our\n");
  494.     putstring("bbs at\n715-832-8325\nphantom bbs\n");
  495.     putstring("this demo\nuses the\nlithium\nadvanced\nflake\nprocessing\nunit");
  496.     putstring("\nour diskmag\nalt one issue\nfifteen\nis coming\nout soon...");
  497.     delay(2000);
  498.     coolcls();
  499.  
  500.     textmode(3);
  501.  
  502.     splitout(buf);
  503.     gotoxy(oldx, oldy);
  504.     fadein("by natas of lithium.");
  505.     fadein("hanson4@nes.nersc.gov");
  506. }
  507.