ideal
model large
p386n
stack 256

assume cs:plasma 

segment  plasma

;---------------------------------------------
start1:       mov ax,data1
              mov ds,ax
              assume ds:data1
              ;
              mov ax,0003h
              int 10h
              ;
              mov ah,09h
              mov dx,offset textpage
              int 21h
              ;
warte_ab:     mov ah,06h
              mov dl,255
              int 21h
              cmp al," "
              jne warte_ab
              ;
              call init80x200
              ;
              call set_blue 
              ;
              call set_values
              ;
              mov [ds:source_table],offset c_table1
              ;
askkey1:      mov di,4000h
              mov dx,03c4h
              mov ax,0a02h
              out dx,ax
              ;
              call hretrace
              ;
              mov dx,03c8h
              xor al,al
              out dx,al
              inc dx
              mov al,44h
              out dx,al
              out dx,al
              out dx,al
              ;
              call plasma_loop
              ;
              call hretrace
              ;
              mov dx,03c8h
              xor al,al
              out dx,al
              inc dx
              out dx,al
              out dx,al
              out dx,al
              ;
              mov dx,03d4h
              mov ax,400ch
              out dx,ax
              mov ax,1e08h
              out dx,ax
              mov dx,03c0h
              mov al,33
              out dx,al
              mov al,01
              out dx,al
              call waitborder
              ;
              mov di,4000h
              mov dx,03c4h
              mov ax,0502h
              out dx,ax
              ;
              call plasma_loop2
              ;
              mov dx,03d4h
              mov ax,400ch
              out dx,ax
              mov ax,1f08h
              out dx,ax
              mov dx,03c0h
              mov al,33
              out dx,al
              mov al,00 
              out dx,al
              call waitborder
              ;
              mov ah,06h
              xor al,al
              mov dl,255
              int 21h
              ;
              cmp al,"a"
              je inc_xinc
              cmp al,"b"
              je dec_xinc
              ;
              cmp al,"c"
              je inc_yinc
              cmp al,"d"
              je dec_yinc
              ;
              cmp al,"e"
              je inc_zinc
              cmp al,"f"
              je dec_zinc
              ;
              cmp al," "
              je end_it
              ;
              cmp al,"g"
              je inc_xinc2
              cmp al,"h"
              je dec_xinc2
              ;
              cmp al,"i"
              je inc_yinc2
              cmp al,"j"
              je dec_yinc2
              ;
              cmp al,"k"
              je inc_zinc2
              cmp al,"l"
              je dec_zinc2
              ;
              cmp al,"m"
              je inc_xinc3
              cmp al,"n"
              je dec_xinc3
              ;
              cmp al,"o"
              je inc_yinc3
              cmp al,"p"
              je dec_yinc3
              ;
              cmp al,"q"
              je inc_zinc3
              cmp al,"r"
              je dec_zinc3
              ;
              jmp askkey1
              ;
end_it:       jmp exit
              ;
inc_xinc:     inc [ds:xinc]
              jmp askkey1
dec_xinc:     dec [ds:xinc]
              jmp askkey1
inc_yinc:     inc [ds:yinc]
              jmp askkey1
dec_yinc:     dec [ds:yinc]
              jmp askkey1
inc_zinc:     inc [ds:zinc]
              jmp askkey1
dec_zinc:     dec [ds:zinc]
              jmp askkey1
inc_xinc2:    inc [ds:xinc2]
              jmp askkey1
dec_xinc2:    dec [ds:xinc2]
              jmp askkey1
inc_yinc2:    inc [ds:yinc2]
              jmp askkey1
dec_yinc2:    dec [ds:yinc2]
              jmp askkey1
inc_zinc2:    inc [ds:zinc2]
              jmp askkey1
dec_zinc2:    dec [ds:zinc2]
              jmp askkey1
inc_xinc3:    inc [ds:xinc3]
              jmp askkey1
dec_xinc3:    dec [ds:xinc3]
              jmp askkey1
inc_yinc3:    inc [ds:yinc3]
              jmp askkey1
dec_yinc3:    dec [ds:yinc3]
              jmp askkey1
inc_zinc3:    inc [ds:zinc3]
              jmp askkey1
dec_zinc3:    dec [ds:zinc3]
              jmp askkey1
;-----------------------------------------------------------------------------
;init an 80x200 grafixmode with 256 colors
;
init80x200:   mov ax,0013h
              int 10h
              ;
              mov dx,03c4h
              mov al,04h
              out dx,al
              inc dx
              in al,dx
              and al,11110111b
              out dx,al
              dec dx
              ;
              mov ax,0f02h
              out dx,ax
              ;
              mov dx,03d4h
              mov al,14h
              out dx,al
              inc dx
              in al,dx
              and al,10111111b
              out dx,al
              dec dx
              mov al,17h
              out dx,al
              inc dx
              in al,dx
              or al,01000000b
              out dx,al
              ;
              mov ax,0a000h
              mov es,ax
              assume es:0a000h
              ;
              mov cx,8000h
              xor di,di
              xor ax,ax
              cld
              rep stosw
              ;
              retn
;-------------------------------------------
; checks your pc for cpu-type
;
askcpu:      pushf
             xor bx,bx
             push bx
             popf
             pushf
             pop bx
             and bx,0f000h
             cmp bx,0f000h
             je less286
             mov bx,07000h
             push bx
             popf
             pushf
             pop bx
             and bx,07000h
             jne cpu386
             mov [ds:cpu_type],1
             popf
             retn
cpu386:      mov [ds:cpu_type],2
             popf
             retn
less286:     mov [ds:cpu_type],0
             popf
             retn
;-------------------------------------------
; checks your pc for co-cpu-type
;
askco:       mov [byte cs:check1],90h
             mov [byte cs:check2],90h         
check1:      finit             
             mov [byte ds:cpz+1],0
check2:      fstcw [word ds:cpz]
             mov ah,[byte ds:cpz+1]
             cmp ah,03h
             jne no_co
             and [ds:cpz],0ff7fh
             fldcw [word ds:cpz]
             fdisi
             fstcw [word ds:cpz]
             test [ds:cpz],80h
             jne co087
             finit
             fld1
             fldz
             fdivp st(1),st
             fld st(0)
             fchs
             fcompp st(1)
             fstcw [word ds:cpz]
             mov ax,[ds:cpz]
             sahf
             je co287
             mov [ds:co_type],3
             retn
co087:       mov [ds:co_type],1
             retn
co287:       mov [ds:co_type],2
             retn
no_co:       mov [ds:co_type],0
             retn
;-------------------------------------------
; checks for an installed v86-driver
;
askv86:      mov ax,3567h
             int 21h
             mov si,offset sign
             mov di,000ah
             mov al,[ds:si]
             cmp al,[es:di]
             jne nov86
             mov al,[ds:si+1]
             cmp al,[es:di+1]
             jne nov86
             mov al,[ds:si+2]
             cmp al,[es:di+2]
             jne nov86
             mov [ds:is_v86],1
             retn
nov86:       mov [ds:is_v86],0
             retn
;----------------------------------------------
; Waits till the rasterline is in the border
;
waitborder:   mov dx,03dah
wb1:          in al,dx
              test al,08h
              jne wb1
wb2:          in al,dx
              test al,08h
              je wb2
              ret 
hretrace:     mov dx,03dah
hr1:          in al,dx
              test al,01h
              jne hr1
hr2:          in al,dx
              test al,01h
              je hr2
              retn
;---------------------------------------------
; - DS:DI = Offset of colortable in RAM
;
setpal:         assume ds:data1
                mov dx,3C8h                 
                xor al,al   
                out dx,al
                cli
                inc dx
                mov cx,256
setpal2:        mov al,[ds:di]
                out dx,al
                mov al,[ds:di+1]
                out dx,al
                mov al,[ds:di+2]
                out dx,al
                add di,03h
                loop setpal2
                sti
                retn
;-------------------------------------------
exit:          mov ax,0003h
               int 10h
               ;
               mov ax,4c00h
               int 21h
               ;
;-------------------------------------------
set_plasma:    mov cx,80
set_loop1:     xor ah,ah
               mov bx,offset sinus_table
               mov si,[ds:xpos]  
               mov al,[ds:bx+si]
               mov si,[ds:ypos]   
              ; mov bx,offset cosinus_table
               add al,[ds:bx+si]
               mov si,[ds:zpos]
               shr al,1
               add al,[ds:bx+si]
               ;
               mov si,ax
               mov bx,[ds:source_table]
               ;
               mov al,[ds:bx+si]
               mov [es:di],al
               ;
               clc
               mov al,[byte ds:xpos]
               adc al,[ds:xinc]
               mov [byte ds:xpos],al
               ;
               clc
               mov al,[byte ds:ypos]
               adc al,[ds:yinc]
               mov [byte ds:ypos],al
               ;
               clc
               mov al,[byte ds:zpos]
               adc al,[ds:zinc]
               mov [byte ds:zpos],al
               ;
               inc di
               loop set_loop1
               retn
;--------------------------------------------
plasma_loop:   mov cx,200
set_loop2:     push cx
               call set_plasma
               pop cx
               ;
               clc
               mov al,[ds:xdist]
               adc al,[ds:xinc2]
               mov [ds:xdist],al
               mov [byte ds:xpos],al
               ;
               clc
               mov al,[ds:ydist]
               adc al,[ds:yinc2]
               mov [ds:ydist],al
               mov [byte ds:ypos],al
               ;
               clc
               mov al,[ds:zdist]
               adc al,[ds:zinc2]
               mov [ds:zdist],al
               mov [byte ds:zpos],al
               ;
               loop set_loop2
               ;
               clc
               mov al,[ds:xteq]
               adc al,[ds:xinc3]
               mov [ds:xteq],al
               mov [ds:xdist],al
               mov [byte ds:xpos],al
               ;
               clc
               mov al,[ds:yteq]
               adc al,[ds:yinc3]
               mov [ds:yteq],al
               mov [ds:ydist],al
               mov [byte ds:ypos],al
               ;
               clc
               mov al,[ds:zteq]
               adc al,[ds:zinc3]
               mov [ds:zteq],al
               mov [ds:zdist],al
               mov [byte ds:zpos],al
               ;
               retn
;--------------------------------------------
set_plasma2:    mov cx,80
set_loop21:     xor ah,ah
               mov bx,offset sinus_table
               mov si,[ds:xposa]  
               mov al,[ds:bx+si]
               mov si,[ds:yposa]   
              ; mov bx,offset cosinus_table
               add al,[ds:bx+si]
               mov si,[ds:zposa]
               shr al,1
               add al,[ds:bx+si]
               ;
               mov si,ax
               mov bx,[ds:source_table]
               ;
               mov al,[ds:bx+si]
               add al,64
               mov [es:di],al
               ;
               clc
               mov al,[byte ds:xposa]
               adc al,[ds:xinca]
               mov [byte ds:xposa],al
               ;
               clc
               mov al,[byte ds:yposa]
               adc al,[ds:yinca]
               mov [byte ds:yposa],al
               ;
               clc
               mov al,[byte ds:zposa]
               adc al,[ds:zinca]
               mov [byte ds:zposa],al
               ;
               inc di
               loop set_loop21
               retn
;--------------------------------------------
plasma_loop2:   mov cx,200
set_loop22:     push cx
               call set_plasma2
               pop cx
               ;
               clc
               mov al,[ds:xdista]
               adc al,[ds:xinc2a]
               mov [ds:xdista],al
               mov [byte ds:xposa],al
               ;
               clc
               mov al,[ds:ydista]
               adc al,[ds:yinc2a]
               mov [ds:ydista],al
               mov [byte ds:yposa],al
               ;
               clc
               mov al,[ds:zdista]
               adc al,[ds:zinc2a]
               mov [ds:zdista],al
               mov [byte ds:zposa],al
               ;
               loop set_loop22
               ;
               clc
               mov al,[ds:xteqa]
               adc al,[ds:xinc3a]
               mov [ds:xteqa],al
               mov [ds:xdista],al
               mov [byte ds:xposa],al
               ;
               clc
               mov al,[ds:yteqa]
               adc al,[ds:yinc3a]
               mov [ds:yteqa],al
               mov [ds:ydista],al
               mov [byte ds:yposa],al
               ;
               clc
               mov al,[ds:zteqa]
               adc al,[ds:zinc3a]
               mov [ds:zteqa],al
               mov [ds:zdista],al
               mov [byte ds:zposa],al
               ;
               retn
;--------------------------------------------
set_blue:      mov dx,03c8h
               mov si,offset colorpal
               xor al,al
               out dx,al
               inc dx
               mov cx,64
               xor ah,ah
set_loop3:     xor al,al
               out dx,al
               mov [ds:si],al
               out dx,al
               mov [ds:si+1],al
               mov al,ah
               out dx,al
               mov [ds:si+2],al
               inc ah
               add si,03h
               loop set_loop3
               mov cx,64
               xor ah,ah
set_loop4:     mov al,ah
               out dx,al
               mov [ds:si],al
               xor al,al
               out dx,al
               mov [ds:si+1],al
               out dx,al
               mov [ds:si+2],al
               inc ah
               add si,03h
               loop set_loop4
               retn
;-------------------------------------------
set_values:    mov cx,21
               mov si,offset values
               mov di,offset xpos
set_val:       mov al,[ds:si]
               mov [ds:di],al
               inc si
               loop set_val
               retn
;--------------------------------------------
ends  plasma
               
segment  data1

cpz          dw 0000
cpu_type     db 00
co_type      db 00
sign         db "EMM"
is_v86       db 00

xpos         dw 00
ypos         dw 00
zpos         dw 00

xinc         db 02
yinc         db 02
zinc         db 01

xdist        db 00
ydist        db 00
zdist        db 00

xinc2        db 01 
yinc2        db 255
zinc2        db 02

xteq         db 00
yteq         db 00
zteq         db 00

xinc3        db 02
yinc3        db 01 
zinc3        db 255

xposa         dw 01
yposa         dw 02
zposa         dw 01

xinca         db 01
yinca         db 02
zinca         db 02

xdista        db 01
ydista        db 02
zdista        db 01

xinc2a        db 254
yinc2a        db 01 
zinc2a        db 02

xteqa         db 01
yteqa         db 02
zteqa         db 01

xinc3a        db 255
yinc3a        db 01 
zinc3a        db 02  

source_table dw 0000

filename     db "values.dat",0

fadepal      db 256*3 dup (0)
colorpal     db 256*3 dup (0)

sinus_table  db 00,00,01,01,02,02,03,03,04,04,05,05,06,06,07,07
             db 08,08,09,09,10,10,11,11,12,12,13,13,14,14,15,15
             db 16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23
             db 24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31
             db 32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39
             db 40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47
             db 48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55
             db 56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63
             db 64,64,65,65,66,66,67,67,68,68,69,69,70,70,71,71
             db 72,72,73,73,74,74,75,75,76,76,77,77,78,78,79,79
             db 79,79,78,78,77,77,76,76,75,75,74,74,73,73,72,72
             db 71,71,70,70,69,69,68,68,67,67,66,66,65,65,64,64
             db 63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48
             db 47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32
             db 31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16
             db 15,14,13,12,11,10,09,08,07,06,05,04,03,02,01,00

c_table1     db 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16
             db 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
             db 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48
             db 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,63
             db 63,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49
             db 48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33
             db 32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17
             db 16,15,14,13,12,11,10,09,08,07,06,05,04,03,02,01
             db 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16
             db 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
             db 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48
             db 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,63
             db 63,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49
             db 48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33
             db 32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17
             db 16,15,14,13,12,11,10,09,08,07,06,05,04,03,02,01

include 'values.db'             

textpage     db "PLASMA-ROUTINE V1.0 (d) may 1994 by Capella/Escape Cooperation",13,10
             db "Released on 11.12.1994",13,10
             db "(use this only to learn out of it......)",13,10,10
             db 13,10," FUNCTION-KEYS IN THIS LITTLE PLASMA-ROUTINE",13,10,10
             db "A/B    - inc/dec X-position of blue plasma",13,10
             db "C/D    - inc/dec Y-position of blue plasma",13,10
             db "E/F    - inc/dec Z-position of blue plasma",13,10,10
             db "G/H    - inc/dec X-distance of blue plasma",13,10
             db "I/J    - inc/dec Y-distance of blue plasma",13,10
             db "K/L    - inc/dec Z-distance of blue plasma",13,10,10
             db "M/N    - inc/dec X-speed of blue plasma",13,10
             db "O/P    - inc/dec Y-speed of blue plasma",13,10
             db "Q/R    - inc/dec Z-speed of blue plasma",13,10,10,10
             db "Press 'space' now to go on and press it again to leave....",13,10,"$"

ends  data1

end start1




