home *** CD-ROM | disk | FTP | other *** search
/ Home Entertainment Cube …hildren's Shareware Games / CHILDREN.ISO / firework / expa.asm < prev    next >
Assembly Source File  |  1990-01-20  |  16KB  |  843 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; expa.asm - support routines for EXPLOD.C.  Compile with "masm /mx expa ;".
  3. ;
  4. ; NOTE:
  5. ;   Make sure one of DLC or TURBOC is defined below.  C compilers other 
  6. ;   than Datalight C and Turbo C will probably require changes to the 
  7. ;   segment naming.  This file has been tested with the Arrowsoft Assembler 
  8. ;   1.00d and MASM 5.0.
  9. ;
  10. ; (C) 1989 Dennis Lo
  11. ; You are free to use and distribute this source code, provided that the
  12. ; authors' names remain in the code, and that modified versions are clearly 
  13. ; distinguished from the original.
  14. ;
  15. ; 89/06/24 Dennis Lo        (V1.0) Initial release. 
  16. ; 89/07/03 Dennis Lo        (V1.1) Added ifdefs for linking with Turbo C.
  17. ; 89/07/26 Erik Liljencrantz    Added EGA support with autodetection
  18. ;                Restores previous CRT textmode on exit
  19. ; 89/08/22 Dennis Lo        (V1.2) Allow frame buffer to be in any segment
  20. ;                Optimized HGC/CGA frame draw loop
  21. ;                Restricted EGA colours to only the bright ones
  22. ;                 to get rid of the flickering effect.
  23. ; 89/09/03 Erik Liljencrantz    Added VGA support with autodetection
  24. ; 89/09/23 Dennis Lo        Added DOS memory allocation routines
  25. ;                Cosmetic changes.
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27.  
  28. ;------------------------------------------------------------------
  29. ;        *** IMPORTANT: Uncomment one of the following ***
  30. ;
  31. ; uncomment this for Datalight C *******
  32. ;DLC     equ     1
  33. ;
  34. ; uncomment this for Turbo C ********
  35. TURBOC    equ    1
  36. ;
  37. ;------------------------------------------------------------------
  38.  
  39.  
  40. ;;;;;;;;;;;;;;;;;;;;;;;;; SEGMENT NAMES ;;;;;;;;;;;;;;;;;;;;;;;;;
  41. ;segment names for Datalight C
  42. ifdef DLC
  43. pgroup        group    prog
  44. prog        segment byte public 'prog'
  45.         assume    cs:pgroup
  46. prog        ends
  47. dgroup        group    data
  48. data        segment word public 'data'
  49.         assume ds:dgroup
  50. data        ends
  51. endif
  52.  
  53. ;segment names for Turbo C
  54. ifdef TURBOC
  55.         name    t
  56. _TEXT        segment byte public 'CODE'
  57. DGROUP        group    _DATA,_BSS
  58.         assume    cs:_TEXT,ds:DGROUP,ss:DGROUP
  59. _TEXT        ends
  60. _DATA        segment word public 'DATA'
  61. _d@        label    byte
  62. _DATA        ends
  63. _BSS        segment word public 'BSS'
  64. _b@        label    byte
  65. _BSS        ends
  66. endif
  67.  
  68.  
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CONST ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. ;    HGC port addresses
  71. config        equ    03bfh
  72. index        equ    03b4h
  73. cntrl        equ    03b8h
  74. ;    HGC control codes
  75. scrn_on        equ    8
  76. grph        equ    2
  77. text        equ    20h
  78.  
  79. par        equ    4        ;stack offset of 1st C call parameter
  80. DEADPOINT    equ    32767        ;flag for dead point in frame table
  81.  
  82.  
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84. ifdef DLC
  85. data        segment word public 'data'
  86. endif
  87. ifdef TURBOC
  88. _DATA        segment word public 'DATA'
  89. endif
  90.  
  91. Vidtype     db    ?        ;video card type
  92. Vidseg        dw    ?        ;video mem segment
  93. Vidsize     dw    ?        ;video mem size
  94. SaveMode    DB    ?        ;Save video text mode
  95. Color        db    ?        ;Current frame colour (for EGA)
  96.  
  97. ;    Table of bit values for plotting points
  98. ;masktable    db    128,64,32,16,8,4,2,1    ;1-pixel wide points
  99. masktable    db    192,96,48,24,12,6,3,1    ;2-pixel wide points
  100.  
  101. ;    HGC 6845 config tables 
  102. hgc_gtable    db    35h,2dh,2eh,07h
  103.         db    5bh,02h,57h,57h
  104.         db    02h,03h,00h,00h
  105. hgc_ttable    db    61h,50h,52h,0fh
  106.         db    19h,06h,19h,19h
  107.         db    02h,0dh,0bh,0ch
  108.  
  109. ;    Palette register table for EGA
  110. ;    Consists of colour values for registers 0-15, plus border colour
  111. palette        db    00h,07h,3ah,3bh,3ch,3eh,3fh,07h
  112.         db    3ah,3bh,3ch,3eh,07h,3ah,3bh,3ch,00h
  113.  
  114. ifdef DLC
  115. data        ends
  116. endif
  117. ifdef TURBOC
  118. _DATA        ends
  119. endif
  120.  
  121.  
  122. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  123. ifdef DLC
  124. prog        segment byte public 'prog'
  125. endif
  126. ifdef TURBOC
  127. _TEXT        segment byte public 'CODE'
  128. endif
  129.  
  130.  
  131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  132. ; Return the number of paragraphs of memory available.
  133. ; int num_para = DosMemLeft ();
  134. ;
  135.         public    _DosMemLeft
  136. _DosMemLeft    proc    near
  137.         push    bp
  138.         mov    bp,sp
  139.         push    es
  140.  
  141.         mov    bx,0f000h    ;Call DOS malloc with a request for
  142.         mov    ah,48h        ; 960K to make sure it fails
  143.         int    21h
  144.         jc    memleft_cont
  145.  
  146.         xor    ax,ax        ;Error: DOS malloc() succeeded!
  147.         jmp    memleft_end    ;Return 0
  148.  
  149. memleft_cont:
  150.         mov    ax,bx        ;Return mem size remaining
  151.  
  152. memleft_end:
  153.         pop    es
  154.         pop    bp
  155.         ret
  156. _DosMemLeft    endp
  157.  
  158.  
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ; Allocate a block of memory 
  161. ; int segment_addr = DosAlloc (size_in_paragraphs);
  162. ; Returns 0 if unsucessful.
  163. ;
  164.         public    _DosAlloc
  165. _DosAlloc    proc    near
  166.         push    bp
  167.         mov    bp,sp
  168.         push    es
  169.  
  170.         mov    bx,par[bp]    ;get # paragraphs requested
  171. ;        add    bx,15        ;# paragraphs = (# bytes + 15) / 16
  172. ;        shr    bx,1
  173. ;        shr    bx,1
  174. ;        shr    bx,1
  175. ;        shr    bx,1
  176.         mov    ah,48h        ;call DOS malloc
  177.         int    21h
  178.         jnc    alloc_end
  179.         xor    ax,ax        ;if failure then return 0
  180. alloc_end:
  181.         pop    es
  182.         pop    bp
  183.         ret
  184. _DosAlloc    endp
  185.  
  186.  
  187. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  188. ; Free a block of memory allocated by DosAlloc
  189. ; DosFree (int segment_addr);
  190. ; Returns 0 if successful, 1 if not.
  191. ;
  192.         public    _DosFree
  193. _DosFree    proc    near
  194.         push    bp
  195.         mov    bp,sp
  196.         push    es
  197.  
  198.         mov    ax,par[bp]    ;get segment address to free at
  199.         mov    es,ax
  200.         mov    ah,49h        ;call DOS free
  201.         int    21h
  202.  
  203.         jc    free_end    ;if error then return DOS err code
  204.         xor    ax,ax        ;else return 0
  205. free_end:
  206.         pop    es
  207.         pop    bp
  208.         ret
  209. _DosFree    endp
  210.  
  211.  
  212. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  213. ; Nonblocking keyboard read - returns ASCII char
  214. ; int key = ChkKey();
  215. ;
  216.         public    _ChkKey
  217. _ChkKey        proc    near
  218.         push    si
  219.         push    di
  220.  
  221.         mov    ah,1
  222.         int    16h
  223.         jz    nokey        ;if no key then return
  224.         mov    ax,0        ;else get the key out of the buffer
  225.         int    16h
  226.         mov    ah,0
  227.         jmp    chkret
  228. nokey:
  229.         mov    ax,0
  230. chkret:
  231.         pop    di
  232.         pop    si
  233.         ret
  234. _ChkKey        endp
  235.  
  236.  
  237. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  238. ; Guess video card type.  Returns 'h', 'c', 'e', or 'v'.
  239. ; int card = gr_card();
  240. ;
  241.         public    _gr_card
  242. _gr_card    proc     near
  243.         push    bp
  244.         push    si
  245.         push    di
  246.     
  247.         mov    ah,0Fh
  248.         int    10h
  249.         MOV    SaveMode,AL    ;Save textmode to restore later...
  250.         MOV    BL,AL
  251.         mov    ax,'h'        ; Mono, assume HGC
  252.         cmp    bl,07h        ;
  253.         je    card_done    ;
  254.         MOV    AX,1200h
  255.         MOV    BX,0FF10h
  256.         MOV    CX,00FFh
  257.         INT    10h
  258.         CMP    CL,12       ;CL<12
  259.         JAE    Card_CGA
  260.         CMP    BH,1       ;BH<=1
  261.         JA    Card_CGA
  262.         CMP    BL,3       ;BL<=3
  263.         JA    Card_CGA
  264. ;OK, either EGA or VGA
  265. ;Use INT 10/AH=1A00 to determine which one...
  266.         MOV    AX,1A00h
  267.         INT    10h
  268.         CMP    AL,1Ah        ;Returns AL=1Ah if function supported
  269.         JNE    Card_EGA
  270.         CMP    BL,08h        ;VGA with analog color display
  271.         JNE    Card_EGA
  272.         MOV    AX,'v'        ;Assume VGA
  273.         JMP SHORT Card_Done
  274. Card_EGA:
  275.         MOV    AX,'e'        ;Assume EGA
  276.         JMP SHORT Card_Done
  277. Card_CGA:
  278.         MOV    AX,'c'        ;Assume CGA
  279. Card_Done:
  280.         pop    di
  281.         pop    si
  282.         pop    bp
  283.         ret
  284. _gr_card endp
  285.  
  286.  
  287. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  288. ; Set video card type
  289. ; gr_setcard (char video_card);
  290. ;
  291.         public    _gr_setcard
  292. _gr_setcard    proc    near
  293.         push    bp
  294.         mov    bp,sp
  295.     
  296.         mov    ax,par[bp]    ;get video_card parameter
  297.         mov    Vidtype,al
  298.  
  299.     ;Set video mem segment
  300.         cmp    al,'h'        
  301.         jne    not_herc
  302.         mov    ax,0b000h    ;Hercules
  303.         mov    cx,8000h    ; 32K bytes
  304.         jmp    s_end
  305. not_herc:
  306.         cmp    al,'e'        
  307.         jne    not_ega
  308.         mov    ax,0A000h    ;EGA
  309.         mov    cx,6D60h    ; 28000 bytes (but in four planes)
  310.         jmp    s_end
  311. not_ega:
  312.         cmp    al,'v'
  313.         jne    not_vga
  314.         mov    ax,0A000h    ;VGA
  315.         mov    cx,9600h    ; 38400 bytes (but in four planes)
  316.         jmp    s_end
  317. not_vga:
  318.         mov    ax,0b800h    ;CGA
  319.         mov    cx,4000h    ; 16K bytes
  320. s_end:
  321.         mov    Vidseg,ax
  322.         mov    Vidsize,cx
  323.  
  324.         pop    bp
  325.         ret
  326. _gr_setcard endp
  327.  
  328.  
  329. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  330. ; Set video card for graphics mode
  331. ; gr_gmode();
  332. ;
  333.         public    _gr_gmode
  334. _gr_gmode    proc    near
  335.         push    bp
  336.         push    es
  337.         push    ds
  338.         push    si
  339.  
  340.         mov    al,Vidtype
  341.         cmp    al,'h'
  342.         jne    NotHerc
  343.         call    hgc_gmode      ;HGC
  344.         jmp    g_end
  345. NotHerc:
  346.         cmp    al,'e'
  347.         jne    NotEga
  348.         call    ega_gmode      ;EGA
  349.         jmp    g_end
  350. NotEga:
  351.         cmp    al,'v'
  352.         jne    NotVga
  353.         call    vga_gmode      ;VGA
  354.         jmp    g_end
  355. NotVga:
  356.         call    cga_gmode      ;CGA
  357. g_end:
  358.         pop    si
  359.         pop    ds
  360.         pop    es
  361.         pop    bp
  362.         ret
  363. _gr_gmode    endp
  364.  
  365.  
  366. ;Set HGC graphics mode, page 0
  367. hgc_gmode:
  368.         mov    dx,config
  369.         mov    al,3
  370.         out    dx,al
  371.  
  372.         mov    al,grph
  373.         lea    si,hgc_gtable
  374.         mov    bx,0
  375.         mov    cx,4000h
  376.         call    hgc_setmd
  377.         ret
  378.  
  379.  
  380. ;Set EGA graphics mode
  381. ega_gmode:
  382.         mov    ah,00h        ;Set 640x350 16-colour mode
  383.         mov    al,10h        ;Probably one of the few changes for VGA
  384.         int    10h        ;640x480 resolution
  385.  
  386.         mov    ax,ds        ;set colour palette
  387.         mov    es,ax
  388.         lea    dx,palette
  389.         mov    ax,1002h
  390.         int    10h
  391.         ret
  392.  
  393. ;Set VGA graphics mode
  394. vga_gmode:
  395.         mov    ah,00h        ;Set 640x350 16-colour mode
  396.         mov    al,12h        ;Mode 12h: 640x480 in 16 colours
  397.         int    10h        
  398.  
  399.         mov    ax,ds        ;set colour palette
  400.         mov    es,ax
  401.         lea    dx,palette
  402.         mov    ax,1002h
  403.         int    10h
  404.         ret
  405.  
  406. ;Set CGA graphics mode
  407. cga_gmode:
  408.         mov    ah,00h        ;set 320x200 4-colour mode
  409.         mov    al,04h
  410.         int    10h
  411.  
  412.         mov    ah,0bh        ;set green-red-brown colour palette
  413.         mov    bx,0100h
  414.         int    10h
  415.         ret
  416.  
  417.  
  418. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  419. ; Set text mode.
  420. ; gr_tmode();
  421.         public    _gr_tmode
  422. _gr_tmode    proc  near
  423.         push    bp
  424.         push    es
  425.         push    ds
  426.         push    si
  427.  
  428.         mov    al,Vidtype
  429.         cmp    al,'h'
  430.         jne    t_cga
  431. t_hgc:        call    hgc_tmode
  432.         jmp    t_end
  433. t_cga:        call    cga_tmode      ;for CGA, EGA, & VGA
  434. t_end:
  435.         pop    si
  436.         pop    ds
  437.         pop    es
  438.         pop    bp
  439.         ret
  440. _gr_tmode    endp
  441.  
  442.  
  443. ;Set HGC text mode
  444. hgc_tmode:
  445.         mov    dx,config
  446.         mov    al,0
  447.         out    dx,al
  448.  
  449.         mov    al,text
  450.         lea    si,hgc_ttable
  451.         mov    bx,720h
  452.         mov    cx,2000h
  453.         call    hgc_setmd
  454.         ret
  455.  
  456.  
  457. ;Set CGA & EGA & VGA text mode
  458. cga_tmode:
  459.         mov    ah,00h
  460.         mov    al,SaveMode   ;Restore previous textmode
  461.         int    10h
  462.         ret
  463.  
  464.  
  465. ;;;;;;;;;;;;;;;;;;;;;;;;; hgc_setmd (Hercules support)
  466. ; Set display mode to graphics or text.  Local.
  467. ; params:
  468. ;    al = value to be output to 6845 control port
  469. ;    si = 6845 param table
  470. ;    cx = # of words to be cleared
  471. ;    bx = blank value
  472. hgc_setmd    proc    near
  473.         push    di
  474.         push    ds
  475.         push    es
  476.         push    ax
  477.         push    bx
  478.         push    cx
  479.  
  480. ;    change mode but without scrn_on
  481.         mov    dx,cntrl
  482.         out    dx,al
  483.  
  484. ;    initialize the 6845
  485.         mov    ax,ds
  486.         mov    es,ax        ;also point es:si to param table
  487.     
  488.         mov    dx,index
  489.         mov    cx,12        ;12 params to be output
  490.         xor    ah,ah        ;starting from reg. 0
  491. parms:
  492.         mov    al,ah
  493.         out    dx,al        ;output 6845 reg. index
  494.     
  495.         inc    dx
  496.         lodsb
  497.         out    dx,al        ;output 6845 reg. data
  498.     
  499.         inc    ah
  500.         dec    dx
  501.         loop    parms
  502.  
  503. ;        clear the display buffer
  504.         pop    cx
  505.         mov    ax,0b000h
  506.         cld
  507.  
  508.         mov    es,ax
  509.         xor    di,di
  510.         pop    ax
  511.         rep    stosw
  512.  
  513. ;        scrn_on, page 0
  514.         mov    dx,cntrl
  515.         pop    ax
  516.         add    al,scrn_on
  517.         out    dx,al
  518.  
  519.         pop    es
  520.         pop    ds
  521.         pop    di
  522.         ret
  523. hgc_setmd    endp
  524.  
  525.  
  526. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  527. ; Returns video mem addr of a (x,y) point
  528. ; int video_addr = gr_addr (int x, int y);
  529. ;
  530. par_x        equ    par    ;in:  x
  531. par_y        equ    2+par    ;in:  y
  532.  
  533.         public    _gr_addr
  534. _gr_addr    proc   near
  535.         push    bp
  536.         mov    bp,sp
  537.         push    si
  538.         push    di
  539.  
  540.         mov    bx,par_x[bp]
  541.         mov    cx,par_y[bp]
  542.         call    graddr
  543.  
  544.         pop    di
  545.         pop    si
  546.         pop    bp
  547.         ret
  548. _gr_addr    endp
  549.  
  550.  
  551. ;
  552. ;Local routine to calculate video address.
  553. ;On entry, BX=x, CX=y.    Returns addr in AX.
  554. ;
  555. graddr        proc    near
  556.         mov    al,Vidtype
  557.         cmp    al,'h'
  558.         je    hgc_addr
  559.         cmp    al,'e'
  560.         je    ega_addr
  561.         cmp    al,'v'
  562.         je    vga_addr
  563.         jmp    cga_addr
  564. graddr        endp
  565.  
  566. ;Calc HGC addr = 90 * (y / 4)  +  2000h * (y & 3)  +  x / 8
  567. hgc_addr:
  568.         ;loc = (y / 4) * 90
  569.         mov    ax,cx
  570.         shr    ax,1
  571.         shr    ax,1
  572.  
  573.         ;ax * 90 = ax*2 + ax*8 + ax*16 + ax*64
  574.         shl    ax,1            ;*2
  575.         mov    dx,ax
  576.         shl    ax,1            ;*4
  577.         shl    ax,1            ;*8
  578.         add    dx,ax
  579.         shl    ax,1            ;*16
  580.         add    dx,ax
  581.         shl    ax,1            ;*32
  582.         shl    ax,1            ;*64
  583.         add    ax,dx
  584.         MOV    DI,AX            ;store sum in DI
  585.  
  586.         ;loc += (y & 3) * 2000H
  587.         AND    CX,3
  588.         MOV    AX,2000H
  589.         MUL    CX            ;(msb ignored)
  590.         ADD    DI,AX
  591.  
  592.         ;loc += (x / 8)
  593.         mov    ax,bx
  594.         shr    ax,1
  595.         shr    ax,1
  596.         shr    ax,1
  597.         add    ax,di
  598.         ret
  599.  
  600.  
  601. ;Calc EGA addr = 80 * y + x / 8
  602. ega_addr:
  603. vga_addr:
  604.         MOV    AX,cx
  605.         SHL    AX,1
  606.         SHL    AX,1
  607.         SHL    AX,1
  608.         SHL    AX,1
  609.         MOV    DX,AX
  610.         SHL    AX,1
  611.         SHL    AX,1
  612.         ADD    DX,AX
  613.         MOV    AX,bx
  614.         SHR    AX,1
  615.         SHR    AX,1
  616.         SHR    AX,1
  617.         ADD    AX,DX
  618.         RET
  619.  
  620.  
  621. ;Calc CGA addr = 80 * (y / 4)  +  2000h * (y & 3)  +  x / 8
  622. cga_addr:
  623.         ;loc = (y / 2) * 80
  624.         MOV    AX,cx
  625.         SHR    AX,1
  626.     
  627.         MOV    DL,80
  628.         MUL    DL
  629.         MOV    DI,AX            ;store sum in DI
  630.  
  631.         ;loc += (y & 1) * 2000H
  632.         MOV    AX,2000H
  633.         AND    CX,1
  634.         jz    ca_noadd
  635.         ADD    DI,AX
  636. ca_noadd:
  637.         ;loc += (x / 8)
  638.         MOV    AX,bx
  639.         shr    ax,1
  640.         shr    ax,1
  641.         shr    ax,1
  642.         ADD    ax,di
  643.         ret
  644.  
  645. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  646. ; Returns video mem addr of a (x,y) point
  647. ; int video_addr = gr_addr (int x, int y);
  648. ;
  649.         public    _gr_value
  650. _gr_value proc    near
  651.         push    bp
  652.         mov    bp,sp
  653.         mov    bx,par_x[bp]
  654.         call    grvalue
  655.         pop    bp
  656.         ret
  657. _gr_value endp
  658.  
  659. ;
  660. ; Local: returns the byte value of a (x,y) point in AL
  661. ; Input: BX=x
  662. ; Output: AL = 2 << [7 - (x & 7)]
  663. ;
  664. grvalue        proc   near
  665.         and    bx,7
  666.         mov    al,masktable[bx]
  667.         ret
  668. grvalue endp
  669.  
  670.  
  671. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  672. ; gr_store_pt (x, y, dest_seg, dest_ofs, centre_addr)
  673. ;
  674. dest_seg    equ    par+4
  675. dest_ofs    equ    par+6
  676. cent_addr    equ    par+8 
  677.  
  678.         public    _gr_store_pt
  679. _gr_store_pt    proc    near
  680.         push    bp
  681.         mov    bp,sp
  682.         push    es
  683.         push    si
  684.         push    di
  685.     
  686.         mov    bx,par_x[bp]        ;get addr
  687.         cmp    bx,DEADPOINT
  688.         je    store_dead
  689.         mov    cx,par_y[bp]
  690.         call    graddr
  691.         sub    ax,cent_addr[bp]
  692.         mov    dx,ax
  693.     
  694.         mov    bx,par_x[bp]        ;get value
  695.         call    grvalue
  696.         mov    cl,al
  697. store_pt:    
  698.         mov    bx,dest_ofs[bp]      ;get dest addr
  699.         mov    ax,dest_seg[bp]
  700.         mov    es,ax
  701.         mov    es:[bx],dx        ;store addr in dest
  702.         mov    es:[bx+2],cl        ;store value in dest
  703.     
  704.         pop    di
  705.         pop    si
  706.         pop    es
  707.         pop    bp
  708.         ret
  709. _gr_store_pt    endp
  710.  
  711. store_dead:    mov    dx,bx
  712.         jmp    store_pt
  713.  
  714. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  715. ; Plot one frame of 3-byte (offset, value) point records.
  716. ; gr_frplot (num_points, frame_seg, frame_offset, centre_addr, draw_or_erase)
  717. ;
  718. fpar_nump    equ    par        ;No. of points per frame
  719. fpar_frm_seg    equ    par+2        ;frame segment
  720. fpar_frm_ofs    equ    par+4        ;frame offset
  721. fpar_centre    equ    par+6        ;video addr of explosion's centre
  722. fpar_mode    equ    par+8        ;for EGA: 0 means erase, 1 means draw
  723.  
  724.         public    _gr_frplot
  725. _gr_frplot proc near
  726.         push    bp
  727.         mov    bp,sp
  728.         push    ds
  729.         push    es
  730.         push    si
  731.         push    di
  732.  
  733.         mov    cx,fpar_nump[bp]
  734.         mov    si,fpar_frm_ofs[bp]
  735.         mov    dx,fpar_centre[bp]
  736.         mov    di,3
  737.         cmp    VidType,'e'
  738.         je    fr_ega
  739.         cmp    VidType,'v'
  740.         je    fr_vga
  741.  
  742. ;Plot frame on HGC or CGA
  743. fr_cga_hgc:
  744.         mov    ax,Vidseg        ;get video segment 
  745.         mov    es,ax
  746.         mov    ax,fpar_frm_seg[bp]    ;get frame table segment
  747.         mov    ds,ax
  748. frloop:
  749.         mov    bx,[si]         ;get point offset
  750.         add    bx,dx            ;add centre to offset
  751.         mov    al,[si+2]        ;get point's byte value
  752.         xor    es:[bx],al
  753. frnext:
  754.         add    si,di
  755.         loop    frloop
  756. fr_end:
  757.         pop    di
  758.         pop    si
  759.         pop    es
  760.         pop    ds
  761.         pop    bp
  762.         ret
  763.  
  764. ;Plot frame on EGA
  765. fr_vga:
  766. fr_ega:
  767.         MOV    BL,fpar_mode[BP]
  768.         MOV    AX,00F02H
  769.         push    dx
  770.         MOV    DX,03C4H      ;3C4
  771.         OUT    DX,AX          ;Map Mask = enable write in all planes
  772.         MOV    DX,03CEH
  773.         MOV    AX,0FF01H
  774.         OUT    DX,AX
  775.         MOV    AX,00005H
  776.         OUT    DX,AX          ;Mode register
  777.         CMP    BL,0
  778.         JE    fr_Clear
  779.         MOV    AX,01803H
  780.         OUT    DX,AX            ;Select XOR of data
  781.     
  782.         INC    Color            ;Increment colorcounter
  783.         MOV    AH,Color
  784.     
  785. ;Alternative coloring of the explosion...
  786. ;        MOV      AX,40h          ;Get color from timer...!
  787. ;        MOV      ES,AX           ;
  788. ;        MOV      AH,ES:[06Ch]          ;
  789.  
  790. ;Alternative explosion colouring using "random" numbers from ROM
  791. ;        inc    Colour
  792. ;        mov    ax,0f000h
  793. ;        mov    es,ax
  794. ;        mov    bl,Color
  795. ;        xor    bh,bh
  796. ;        mov    ah,es:[bx]
  797. ;        or    ah,ah
  798. ;        and    ah,15
  799. ;        jne    notblack
  800. ;        inc    ah
  801. ;notblack:    
  802.                     ;here ah should contain colour byte
  803.         JMP SHORT fr_cont
  804. fr_Clear:
  805.         MOV    AX,00003H
  806.         OUT    DX,AX            ;Select unmodified data
  807.         XOR    AH,AH
  808. fr_cont:
  809.         XOR    AL,AL
  810.         OUT    DX,AX
  811.         MOV    AL,08
  812.         OUT    DX,AL            ; Select register 8 again
  813.         INC    DX
  814.  
  815.         mov    ax,Vidseg        ;get video segment
  816.         mov    es,ax
  817.         mov    ax,fpar_frm_seg[bp]    ;get frame table segment
  818.         mov    ds,ax
  819.         pop    bp            ;get centre addr pushed earlier
  820. egaloop:
  821.         mov    bx,[si]         ;get point offset
  822.         cmp    bx,DEADPOINT        ;check if point is dead
  823.         je    eganext
  824.         add    bx,BP            ;add centre to offset 
  825.         mov    al,[si+2]        ;get point's byte value
  826.         OUT    DX,AL
  827.         XCHG    AL,ES:[BX]
  828. eganext:
  829.         add    si,di
  830.         loop    egaloop
  831.         JMP    fr_end
  832.  
  833. _gr_frplot    endp
  834.  
  835.  
  836. ifdef DLC
  837. prog        ends
  838. endif
  839. ifdef TURBOC
  840. _TEXT        ends
  841. endif
  842.     end
  843.