home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / CDMP16.ZIP / SOURCE.ZIP / FRAME.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-01-30  |  15.4 KB  |  658 lines

  1. ;[]------------------------------------------------------------------------[]
  2. ;|                                                                          |
  3. ;| (c) 1993,1994 by Marc van Shaney , aka Kaya Memisoglu                    |
  4. ;|                                                                          |
  5. ;| Dieser Assembler-Source-Code unterliegt dem Urheberrecht von Kaya        |
  6. ;| Memisoglu und darf auch nur mit seiner schriftlichen Genehmigung         |
  7. ;| in kommerziellen Programmen verwendet werden.                            |
  8. ;| Ich übernehme keinerlei Verantwortung für eventuelle Schäden,die dieses  |
  9. ;| Programm verursacht.                                                     |
  10. ;|                                                                          |
  11. ;|                                                                          |
  12. ;| 18.1.1994 Kaya Memisoglu                                                 |
  13. ;|                                                                          |
  14. ;[]------------------------------------------------------------------------[]
  15.  
  16.  
  17.  
  18. P386
  19.  
  20. LOCALS
  21. VGA_Width         equ  320
  22. VGA_Height        equ  200
  23. Font_Width      equ  8
  24. Font_Height      equ  12
  25. Black             equ  240
  26. Background        equ  0
  27. TRUE              equ  1
  28. FALSE             equ  -1
  29.  
  30.  
  31. .MODEL USE16 LARGE
  32. .Code
  33.  
  34.  
  35.  
  36. PUBLIC C Clear_Frame
  37. Clear_Frame PROC FAR
  38.       ARG frame:dword,farbe:byte
  39.       push bp
  40.       mov bp,sp
  41.       push di
  42.  
  43.       les di,frame
  44.       mov ah,[farbe]
  45.       mov al,ah                 ;Farbe einladen
  46.       rol eax,16
  47.       mov al,[farbe]
  48.       mov ah,al
  49.       mov cx,03e80h             ;Bank löschen (DoppelWortweise !!!)
  50.       rep stosd
  51.  
  52.       pop di
  53.       pop bp
  54.       retf
  55. Clear_Frame ENDP
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. PUBLIC C FDraw_Text
  66. FDraw_Text PROC FAR
  67.       ARG frame:dword,x:word,y:word,string:dword,farbe:byte
  68.       push bp
  69.       mov bp,sp
  70.       push si
  71.       push di
  72.  
  73.       les di,[frame]              ;Frame in ES:DI
  74.       mov dl,[farbe]
  75.       mov cx,[y]
  76.       fastimul bx,cx,VGA_Width
  77.       add di,bx                 ;ES:DI points to destination
  78.       add di,[x]
  79.       lgs bp,[string]
  80.  
  81. @@Schleife212:                          ;Buchstabenschleife
  82.     movzx ax,byte ptr gs:[bp]     ;AX=Zeichen
  83.         or al,al
  84.     jz short @@Font_End
  85.         fastimul si,ax,Font_Height
  86.         add si,OFFSET STDFONT
  87.  
  88.     mov dh,Font_Height
  89.   @@Font_V_Loop:                        ;Zeilenschleife
  90.       lods byte ptr cs:[si]       ;Bitmuster in AL geladen
  91.       mov cx,Font_Width-1
  92.     @@Font_H_Loop:                      ;Punktschleife
  93.         bt ax,cx
  94.         jnc short @@Weiter233
  95.         mov [es:di],dl            ;Punkt setzen
  96.       @@Weiter233:
  97.         inc di
  98.         inc dl
  99.     dec cx
  100.     jns short @@Font_H_Loop
  101.  
  102.       sub dl,Font_Width-1
  103.       add di,VGA_Width-Font_Width
  104.   dec dh
  105.   jnz short @@Font_V_Loop
  106.  
  107.     sub di,Font_Height*VGA_Width-Font_Width
  108.     sub dl,Font_Height
  109.     inc bp
  110. jmp short @@Schleife212
  111.  
  112. @@Font_End:
  113.       pop di
  114.       pop si
  115.       pop bp
  116.       retf
  117. FDraw_Text ENDP
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. PUBLIC C FDraw_Scroller
  126. FDraw_Scroller PROC FAR
  127.       ARG frame:dword,y:word,string:dword,farbe:byte,pos:word
  128.       push bp
  129.       mov bp,sp
  130.       push di
  131.       push si
  132.  
  133.       les di,[frame]              ;Frame in ES:DI
  134.       mov ax,[pos]
  135.       xor dx,dx
  136.       mov ax,[pos]
  137.       mov bx,Font_Width
  138.       idiv bx                   ;AX holds first char to draw
  139.                       ;DX holds pixels to draw from this char
  140.       mov bx,0              ;BX holds screen-row
  141.       sub bx,dx            ;We are in the negative
  142.       mov cx,[y]
  143.       fastimul si,cx,VGA_Width
  144.       add di,si                 ;ES:DI points to destination
  145.       sub di,dx
  146.       mov dl,[farbe]
  147.       lgs bp,[string]
  148.       add bp,ax            ;GS:BP points to first char to draw
  149.  
  150.  
  151. Schleife212:                      ;Buchstabenschleife
  152.     movzx ax,byte ptr gs:[bp] ;AX=Zeichen
  153.         or al,al
  154.         jz short Font_End
  155.         fastimul si,ax,Font_Height
  156.         add si,OFFSET STDFONT
  157.  
  158.         mov dh,Font_Height
  159.   Font_V_Loop:                    ;Zeilenschleife
  160.       lods byte ptr cs:[si]   ;Bitmuster in AL geladen
  161.       mov cx,Font_Width-1
  162.     Font_H_Loop:                  ;Punktschleife
  163.             cmp bx,VGA_Width-1
  164.             ja short Weiter233
  165.         bt ax,cx
  166.         jnc short Weiter233
  167.         mov [es:di],dl        ;Punkt setzen
  168.       Weiter233:
  169.         inc di
  170.             inc dl
  171.             inc bx
  172.     dec cx
  173.     jns short Font_H_Loop
  174.  
  175.           sub dl,Font_Width-1
  176.       add di,VGA_Width-Font_Width
  177.           sub bx,Font_Width
  178.   dec dh
  179.   jnz short Font_V_Loop
  180.  
  181.     sub di,Font_Height*VGA_Width-Font_Width
  182.         sub dl,Font_Height
  183.         add bx,Font_Width
  184.     cmp bx,VGA_Width
  185.         ja short Font_End
  186.     inc bp
  187. jmp short Schleife212
  188.  
  189. Font_End:
  190.       pop si
  191.       pop di
  192.       pop bp
  193.       retf
  194. FDraw_Scroller ENDP
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PUBLIC C FPut_Sprite
  203. FPut_Sprite PROC FAR
  204.       ARG frame:dword,x1:word,y1:word,mem:dword
  205.       push bp
  206.       mov bp,sp
  207.       push si
  208.       push di
  209.  
  210.       les di,frame
  211.       lfs si,mem                ;Startadresse des Spritespeichers in FS:SI
  212.  
  213.       mov ax,[y1]               ;ax=y1
  214.       mov bx,VGA_Width
  215.       mul bx
  216.       add ax,[x1]
  217.       add di,ax                 ;Startadresse jetzt in BX:DI
  218.  
  219.       mov dx,[fs:si]            ;x2 Laden
  220.       sub bx,dx                 ;diff=VGA_Width-Breite
  221.       shr dx,2                  ;Breite/4 jetzt in DX
  222.       mov cx,[fs:si+2]          ;Höhe in CX Laden
  223.       add si,16                 ;2 Bytes weiter
  224.  
  225. Schleife767:
  226.     push cx                 ;CX sichern
  227.     mov cx,dx               ;Breite/4 in CX
  228.    Schleife742:
  229.          lods dword ptr [fs:si] ;In EAX FS:SI einladen
  230.          cmp al,Background
  231.          je short Weiter747
  232.          mov [es:di],al
  233.  
  234.      Weiter747:
  235.          cmp ah,Background
  236.      je short Weiter748
  237.          mov [es:di+1],ah
  238.  
  239.      Weiter748:
  240.          rol eax,16
  241.          cmp al,Background
  242.          je short Weiter749
  243.          mov [es:di+2],al
  244.  
  245.      Weiter749:
  246.          cmp ah,Background
  247.          je short Weiter750
  248.          mov [es:di+3],ah
  249.  
  250.      Weiter750:
  251.          add di,4
  252.    loop Schleife742
  253.  
  254. End_Put_Sprite:
  255.     pop cx                  ;In CX wieder Höhe holen
  256.     add di,bx
  257. loop Schleife767
  258.  
  259.       pop di
  260.       pop si
  261.       pop bp
  262.       retf
  263. FPut_Sprite ENDP
  264.  
  265.  
  266.  
  267.  
  268.  
  269. PUBLIC C FPut_Image
  270. FPut_Image PROC FAR
  271.       ARG frame:dword,x1:word,y1:word,mem:dword
  272.       push bp
  273.       mov bp,sp
  274.       push si
  275.       push di
  276.  
  277.       les di,frame
  278.       lfs si,mem                ;Startadresse des Spritespeichers in FS:SI
  279.  
  280.       mov ax,[y1]               ;ax=y1
  281.       mov bx,VGA_Width
  282.       mul bx
  283.       add ax,[x1]
  284.       add di,ax                 ;Startadresse jetzt in ES:DI
  285.  
  286.       mov dx,[fs:si]            ;x2 Laden
  287.       sub bx,dx                 ;BX=VGA_Width-Breite
  288.       shr dx,2                  ;Breite/4 jetzt in DX
  289.       mov ax,[fs:si+2]          ;Höhe in CX Laden
  290.       add si,16                 ;2 Bytes weiter
  291.  
  292. Schleife752:
  293.     mov cx,dx               ;Breite/4 in CX
  294.         rep movs dword ptr [es:di],[fs:si]
  295.     add di,bx
  296. dec ax
  297. jnz short Schleife752
  298.  
  299.       pop di
  300.       pop si
  301.       pop bp
  302.       retf
  303. FPut_Image ENDP
  304.  
  305.  
  306.  
  307.  
  308.  
  309. Row_Size    dw    ?
  310. PUBLIC C FZoom_Sprite
  311. FZoom_Sprite PROC FAR
  312.           ARG frame:dword,x1:word,y1:word,x2:word,y2:word,mem:dword
  313.           push bp
  314.           mov bp,sp
  315.         push si
  316.         push di
  317.  
  318.           cld
  319.           les di,[frame]            ;Framebuffer
  320.           lfs si,[mem]              ;Startadresse des Spritespeichers in FS:SI
  321.  
  322.         movzx ebx,[y2]
  323.         sub bx,[y1]
  324.     inc bx                  ;Final Height in EBX
  325.           fastimul cx,[y1],VGA_Width
  326.           add cx,[x1]
  327.           add di,cx                     ;Startadresse jetzt in ES:DI
  328.  
  329.           movzx ecx,[x2]
  330.           sub cx,[x1]
  331.           inc cx                        ;Final Width
  332.     mov cs:[Row_Size],cx
  333.         push ecx            ;Save Final width for later...
  334.         sub cx,VGA_Width
  335.         neg cx
  336.         mov word ptr cs:[@@4-2],cx    ;Save in code
  337.  
  338.         pop ecx
  339.           xor edx,edx
  340.           mov ax,word ptr fs:[si]        ;Source width
  341.     shl eax,16            ;Fixed-point shift
  342.         div ecx
  343.     mov word ptr cs:[@@5-2],ax      ;Save fractional part
  344.         shr eax,16
  345.         mov word ptr cs:[@@6-2],ax    ;Save integer part
  346.  
  347.         xor edx,edx
  348.           mov ax,word ptr fs:[si+2]    ;Now comes the height
  349.         shl eax,16
  350.         div ebx                ;Divide by final height
  351.         mov word ptr cs:[@@2-2],ax    ;Fractional part
  352.         shr eax,16
  353.         mov cx,fs:[si]                ;AX*Width
  354.         mul cx
  355.         mov word ptr cs:[@@1-2],ax
  356.         mov word ptr cs:[@@3-2],cx
  357.  
  358.           add si,16                     ;Skip over header
  359.     xor dx,dx
  360.   Zoom_Y_Loop:
  361.       push si
  362.         mov cx,cs:[Row_Size]
  363.         xor bp,bp
  364.     Zoom_X_Loop:
  365.             mov al,fs:[si]        ;Get one byte
  366.                 add bp,1234h        ;Fractional part of x in BP
  367.        @@5: adc si,1234h
  368.            @@6: cmp al,0
  369.                je short No_Pixel
  370.                 mov es:[di],al
  371.     No_Pixel:    inc di
  372.         dec cx            ;CX ist x-counter
  373.     jnz short Zoom_X_Loop
  374.  
  375.         pop si
  376.     add si,1234h            ;Row-Increment
  377.    @@1: add dx,1234h            ;Fractional part of y in DX
  378.    @@2: jnc @@3
  379.        add si,1234h            ;Add one row
  380.    @@3: add di,1234h            ;Next scan-line
  381.    @@4: dec bx                ;BX is y-counter
  382.   jnz short Zoom_Y_Loop
  383.  
  384.         pop di
  385.         pop si
  386.           pop bp
  387.           retf
  388. FZoom_Sprite ENDP
  389.  
  390.  
  391.  
  392.  
  393. ;============================================================================
  394. ;=                                                                          =
  395. ;=                                                                          =
  396. ;=                 Hier sind alle Special-effects                           =
  397. ;=                                                                          =
  398. ;=                                                                          =
  399. ;=                                                                          =
  400. ;=                                                                          =
  401. ;=                                                                          =
  402. ;============================================================================
  403.  
  404.  
  405.  
  406.  
  407. Noise        dd    1
  408. MULTIPLIER      equ    015a4e35h
  409. INCREMENT       equ    1
  410.  
  411. RAND MACRO
  412.     mov eax,cs:[Noise]
  413.     mov edx,MULTIPLIER
  414.         mul edx
  415.         shrd eax,edx,16
  416.         add eax,INCREMENT
  417.         mov cs:[Noise],eax
  418.      ENDM
  419.  
  420.  
  421. SinTable  db   0, 24, 49, 74, 97,120,141,161,180,197,212,224,235,244
  422.       db 250,253,255,253,250,244,235,224,212,197,180,161,141,120
  423.       db  97, 74, 49, 24
  424. Water_Pos    dw    0
  425. PUBLIC C FDraw_Water
  426. FDraw_Water PROC FAR
  427.       ARG frame:dword,y:word,len:word
  428.       push bp
  429.       mov bp,sp
  430.       push si
  431.       push di
  432.  
  433.       les di,[frame]
  434.       lfs si,[frame]
  435.       mov bx,cs:[Water_Pos]
  436.  
  437.       mov ax,[y]
  438.       fastimul cx,ax,VGA_Width
  439.       add di,cx
  440.       add si,cx
  441.       sub si,VGA_Width
  442.  
  443.       mov bp,[len]
  444.  Schleife971:
  445.        movzx ax,cs:[bx+ OFFSET SinTable]
  446.        sub ax,127
  447.        sar ax,4
  448.        add si,ax
  449.        mov cx,VGA_Width/4
  450.        rep movs dword ptr [es:di],[fs:si]
  451.        sub si,ax
  452.        sub si,3*VGA_Width
  453.        inc bx
  454.        and bx,1fh
  455.  dec bp
  456.  jnz short Schleife971
  457.  
  458.       inc cs:[Water_Pos]
  459.       and cs:[Water_Pos],1fh
  460.       pop di
  461.       pop si
  462.       pop bp
  463.       retf
  464. FDraw_Water ENDP
  465.  
  466.  
  467.  
  468.  
  469.  
  470. PUBLIC C FMove_Fire
  471. FMove_Fire PROC
  472.     ARG Fire:dword
  473.         push bp
  474.         mov bp,sp
  475.         cld
  476.         push si
  477.         push di
  478.  
  479.         les di,[Fire]
  480.         mov bp,es:[di+2]    ;Height in BP
  481.     push di            ;Save for later
  482.         add di,16        ;Jump over Header+ 1 byte
  483.  
  484. ;        sub bp,2
  485.       shr bp,1        ;Only each second row will be processed
  486.   Fire_HLoop:
  487.         mov cx,160        ;2*2 pixel blocks are used
  488.   Fire_WLoop:
  489.               movzx ax,es:[di]
  490.                 movzx dx,es:[di+2]
  491.                 add ax,dx
  492.                 mov dl,es:[di-2]
  493.                 add ax,dx
  494.                 mov dl,es:[di+2*320]
  495.                 add ax,dx
  496.                 mov dl,es:[di+2*320-2]
  497.                 add ax,dx
  498.                 mov dl,es:[di+2*320+2]
  499.         add ax,dx
  500.                 mov dl,es:[di+4*320]
  501.                 add ax,dx
  502.                 add ax,dx
  503.                 shr ax,3
  504.                 jz short No_Decrement
  505.                 dec al
  506.               No_Decrement:
  507.         mov ah,al
  508.                 mov es:[di+320],ax
  509.                   stosw
  510.   dec cx
  511.   jnz short Fire_WLoop
  512.  
  513.           add di,320    ;Skip one line
  514.   dec bp
  515.   jnz short Fire_HLoop
  516.  
  517.         pop di            ;ES:DI points again to header
  518.     mov cx,es:[di+2]    ;Height of Flames
  519.         fastimul ax,cx,320    ;AX holds size of bitmap
  520.         add di,ax        ;This is the last pixel
  521.         sub di,640-16          ;ES:DI points to last line
  522.         push di
  523.         mov cx,160
  524.   New_Line:
  525.                 RAND
  526.                 and ax,7f7fh
  527.                 mov es:[di+320],ax
  528.                 stosw
  529.   dec cx
  530.   jnz short New_Line
  531.       pop di                 ;ES:DI points again to last Line
  532.         mov cx,40
  533.   New_Fire:
  534.         RAND
  535.                 and eax,0ffffh
  536.                 fastimul ebx,eax,320
  537.                 shr ebx,16
  538.                 mov dword ptr es:[di+bx-2],09f9f9f9fh
  539.                 mov word ptr es:[di+bx+2],09f9fh
  540.   dec cx
  541.   jnz short New_Fire
  542.  
  543.  
  544.     pop di
  545.         pop si
  546.         pop bp
  547.         retf
  548. FMove_Fire ENDP
  549.  
  550.  
  551.  
  552.  
  553.  
  554. PUBLIC C FWrite_in_Fire
  555. FWrite_in_Fire PROC FAR
  556.     ARG fire:dword,x:word,y:word,string:dword,farbe:byte
  557.         push bp
  558.         mov bp,sp
  559.         push di
  560.         push si
  561.  
  562.           les di,[fire]                  ;Frame in ES:DI
  563.           mov dl,[farbe]
  564.         mov dh,dl
  565.           mov cx,[y]
  566.           fastimul bx,cx,2*VGA_Width
  567.           add di,bx                     ;ES:DI points to destination
  568.         add di,[x]
  569.     add di,[x]
  570.         add di,16            ;Skip header
  571.           lgs bp,[string]
  572.  
  573. @@Schleife212:                          ;Buchstabenschleife
  574.     movzx ax,byte ptr gs:[bp]     ;AX=Zeichen
  575.         or al,al
  576.         jz short @@Font_End
  577.         fastimul si,ax,Font_Height
  578.         add si,OFFSET STDFONT
  579.  
  580.         mov ah,Font_Height
  581.   @@Font_V_Loop:                        ;Zeilenschleife
  582.       lods byte ptr cs:[si]       ;Bitmuster in AL geladen
  583.       mov cx,Font_Width-1
  584.     @@Font_H_Loop:                      ;Punktschleife
  585.         bt ax,cx
  586.         jnc short @@Weiter233
  587.         mov [es:di],dx            ;Punkt setzen
  588.         mov [es:di+VGA_Width],dx
  589.       @@Weiter233:
  590.         add di,2
  591.             add dx,0101h
  592.     dec cx
  593.     jns short @@Font_H_Loop
  594.  
  595.       add di,2*VGA_Width-2*Font_Width
  596.           sub dx,(Font_Width-1)*0101h
  597.   dec ah
  598.   jnz short @@Font_V_Loop
  599.  
  600.     sub di,2*Font_Height*VGA_Width-2*Font_Width
  601.         sub dx,Font_Height*0101h
  602.     inc bp
  603. jmp short @@Schleife212
  604.  
  605. @@Font_End:
  606.         pop si
  607.     pop di
  608.     pop bp
  609.         retf
  610. FWrite_in_Fire ENDP
  611.  
  612.  
  613.  
  614.  
  615.  
  616. PUBLIC C FDraw_Oscilloscope
  617. FDraw_Oscilloscope PROC FAR
  618.       ARG frame:dword,x:word,y:word,len:word,mem:dword,farbe:byte
  619.       push bp
  620.       mov bp,sp
  621.       push di
  622.       push si
  623.  
  624.       les di,frame         ;In ES:DI ist der Puffer
  625.       lfs si,mem           ;In FS:SI sind die Daten
  626.  
  627.       mov ax,[y]
  628.       fastimul bx,ax,VGA_Width
  629.       add bx,[x]
  630.       add di,bx            ;In ES:DI ist jetzt die mittlere Koordinate
  631.       mov al,[farbe]
  632.  
  633.       mov cx,len
  634.  Schleife851:
  635.        movsx dx,[FS:SI]
  636.        xor dx,01111111b    ;Es muß umgedreht werden !
  637.        sar dx,2
  638.        fastimul bx,dx,VGA_Width
  639.        mov byte ptr [es:di+bx],al
  640.        inc di
  641.        inc si
  642.  loop Schleife851
  643.  
  644.       pop si
  645.       pop di
  646.       pop bp
  647.       retf
  648. FDraw_Oscilloscope ENDP
  649.  
  650.  
  651.  
  652.  
  653.  
  654. include 8x12font.inc
  655. END
  656.  
  657.  
  658.