/* Plasma by Jan M›ller & Erik Hansen. It was compiled in Borland c++, in ANSI mode, using the HUGE memory model. Feel free to use it as you desire, you may even name it after your grandmother. We don't care. The reason why we made it? Well... First of all we wanted to make some plasma, just for fun. But when we had finished it turned out to be much faster than the plasma we have seen in intros, demos etc... Normally the color-cells are 2x4 4x4 or even larger, the 2x4 cell-plasma was awfully slow, bot ours ain't, even though it is 2x2 cells. Well how can that be??? ^^^^^^^^^ Our secret lies in the plasma-calculation! (I assume you have guessed that part already) We simply calculate as much as possible before we start showing the goddies. The table 'Tab1' is a simple table (320x200 yields 64k) with the distance from (x,y) to the center (rounded off to char by simple overflow). The second table 'Tab2' is similar to 'Tab1', except we molested it with sine. In the mainloop we calculate a body (160x100) by accessing the two tables with different pairs of (x,y) and add them. (see for yourself in 'CalculateBody') And KaPoW. We have the fastest plasma... (i.e. the fastest we have ever seen.(on a 486)) If I am not correct then please notify me. If you have any questions, comments or whips, then we would be happy to answer. Contact us trough E-Mail: fwiffo@daimi.aau.dk or martino@daimi.aau.dk (If you can optimize it (e.g. write it in asm) we would be very interested to see the results!) */ #include #include #include #include #include #include #include #include #define uchar unsigned char #define ulong unsigned long #define uint unsigned int #define PEL_write 0x3c8 #define PEL_read 0x3c7 #define PEL_data 0x3c9 #define box_w 160 #define box_h 100 #define pi 3.1415926L //#define max(a,b) ((a) > (b) ? (a) : (b)) //------------------------------------------------- uchar body[box_w*box_h]; // buffer for the bitmap body uchar colors[256]; // color table uchar tab1[64000]; // table one for thr plasma uchar tab2[64000]; // table two for the plasma //------------------------------------------------- //********************************************************** //******************* ASM SOURCES ************************ //********************************************************** void OnVideo(void) { asm mov bl,0x36 asm mov ax,0x1200 asm int 0x10 } void OffVideo(void) { asm mov bl,0x36 asm mov ax,0x1201 asm int 0x10 } void SetMode(char mode) { asm mov ah,0x00 asm mov al,mode asm int 0x10 } char GetMode() { char mode; asm mov ah,0x0f asm int 0x10 asm mov mode,al return (mode); } void WaitRast() { asm mov dx,0x3da bra1: asm in al,dx asm and al,8 asm jnz bra1 bra2: asm in al,dx asm and al,8 asm jz bra2 } void SetBank(unsigned char wbank, unsigned char rbank) { unsigned char n=rbank<<4|wbank; asm mov al,n asm mov dx,0x3cd // Point to memory segment register asm out dx,al // Set it. } void SetDisplayStart(int adsr) { // This part uses standard VGA DisplayStart registers asm mov bx,adsr // Load start adress asm mov dx,0x3d0 // color register (mono = 0x3b0 asm add dx,4 asm mov al,0x0d asm out dx,al asm inc dx asm mov al,bl asm out dx,al asm dec dx asm mov al,0x0c asm out dx,al asm inc dx asm mov al,bh asm out dx,al // Listing 14.32 } void DubImage(int off, unsigned char buf[], int nbyte, int nrow) { asm push es asm mov ax,0xa000 asm mov es,ax asm mov di,off asm lds si,buf asm xor dx,dx asm mov bx,320 asm sub bx,nbyte asm sub bx,nbyte asm mov cx,nrow asm xor ch,ch asm mov ah,[bp+10] loop1: asm mov dx,nbyte loop2: asm mov al,[si] asm mov ah,al asm mov es:[di],ax asm inc di asm inc di asm inc si asm dec dx asm jg loop2 asm add di,bx asm sub si,nbyte asm mov dx,nbyte loop3: asm mov al,[si] asm mov ah,al asm mov es:[di],ax asm inc di asm inc di asm inc si asm dec dx asm jg loop3 asm add di,bx asm loop loop1 asm pop es } void SetPal(uchar col, uchar red, uchar gre, uchar blu) { asm mov al,col // load palette asm mov dx,PEL_write // Ignite write mode asm out dx,al // store it asm mov dx,PEL_data // Initialize color data asm mov al,red // red color asm out dx,al // store it asm mov al,gre // green color asm out dx,al // store it asm mov al,blu // blue color asm out dx,al // and store it } void CalcTab1() // calculate table 1 for plasma { long i=0,j=0; while(i