home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nasmide.zip / examples / FIRE.ASM < prev    next >
Assembly Source File  |  1997-12-21  |  5KB  |  189 lines

  1. ; Information
  2. ; ▀▀▀▀▀▀▀▀▀▀▀
  3. ;
  4. ;  Program Title : NASM-IDE Fire Code Demo
  5. ;  External name : FIRE.COM
  6. ;  Version       : 1.0
  7. ;  Start date    : 15/10/1997
  8. ;  Last update   : 15/10/1997
  9. ;  Author        : Rob Anderton
  10. ;  Description   : An example of a flickering fire effect programmed using
  11. ;                  NASM-IDE 1.1 and NASM 0.95.
  12. ;
  13. ;                  Based on code by Denthor of Asphyxia (written using TASM).
  14.  
  15.  
  16. [BITS 16]                    ; Set 16 bit code generation
  17. [ORG 0x0100]                 ; Set code start address to 100h (COM file)
  18.  
  19. [SECTION .data]              ; Data section (initialised variables)
  20.  
  21. FireSeed db $1234            ; Random number seed
  22.  
  23. %include "FIREPAL.INC"       ; Include 256 colour palette RGB data
  24.  
  25. ; Text message displayed at the end of the demo
  26. EndMessage db 'Fire demonstration for NASM-IDE 1.1.', 13, 10, '$'
  27.  
  28. [SECTION .bss]               ; BSS section (unitialised variables)
  29.  
  30. FireScreen resb $2300        ; Virtual screen buffer
  31.  
  32.  
  33. [SECTION .text]              ; Text section (the code to be assembled)
  34.  
  35.     jmp       START          ; Jump to main code section
  36.  
  37.  
  38. FIRE_INIT:                   ; Initialise 320x200 X mode
  39.  
  40.     mov       ax, $0013      ; Set MCGA 320x200x256 mode
  41.     int       $10
  42.  
  43.     mov       ax, $0A000
  44.     mov       es, ax
  45.     xor       di, di         ; ES:DI points to top left of screen
  46.  
  47.     cli
  48.     cld
  49.     mov       dx, $03C4
  50.     mov       ax, $0604      ; Enter unchained mode
  51.     out       dx, ax
  52.  
  53.     mov       ax, $0F02      ; Enable all planes
  54.     out       dx, ax
  55.  
  56.     xor       ax, ax
  57.     mov       cx, 32767
  58.     rep       stosw          ; Clear the screen
  59.  
  60.     mov       dx, $03D4
  61.     mov       ax, $14
  62.     out       dx, ax         ; Disable DWORD mode
  63.  
  64.     mov       ax, $0E317     ; Enable byte mode
  65.     out       dx, ax
  66.     out       dx, ax
  67.     mov       ax, $0409      ; Set cell height
  68.     out       dx, ax
  69.  
  70.     mov       si, FirePal    ; DS:SI points to palette data
  71.     mov       dx, $03C8      ; Palette write register
  72.     mov       al, 0          ; Start at colour index 0
  73.     out       dx, al
  74.     inc       dx
  75.     mov       cx, 768
  76.  
  77. .PALLOOP:
  78.  
  79.     outsb                    ; Output colour data
  80.     dec       cx
  81.     jnz       .PALLOOP
  82.  
  83.     ret
  84.  
  85. ;END FIRE_INIT
  86.  
  87.  
  88. FIRE_RANDOM:                 ; Generates psuedo-random numbers
  89.  
  90.     mov  ax, [FireSeed]      ; Use current seed to generate new number
  91.     mov  dx, $8405
  92.     mul  dx                  ; Multiply AX by DX, result in DX:AX
  93.     inc  ax
  94.     mov  [FireSeed], ax      ; Store seed
  95.     ret                      ; Return to calling address
  96.  
  97. ;END FIRE_RANDOM
  98.  
  99.  
  100. START:                                 ; Main code section
  101.  
  102.     call      FIRE_INIT                ; Initialise screen
  103.  
  104.     mov       WORD [FireSeed], $1234   ; Initialse random number seed
  105.  
  106.     mov       si, FireScreen           ; Clear virtual screen buffer
  107.     mov       cx, $2300
  108.     xor       ax, ax
  109.     rep       stosb
  110.  
  111. .MAINLOOP:
  112.  
  113.     mov       si, FireScreen
  114.     add       si, $2300
  115.     sub       si, 80
  116.     mov       cx, 80
  117.     xor       dx, dx
  118.  
  119. .NEWLINE:
  120.  
  121.     call      FIRE_RANDOM
  122.     mov       [ds:si], dl
  123.     inc       si
  124.     dec       cx
  125.     jnz       .NEWLINE
  126.  
  127.     mov       cx, $2300
  128.     sub       cx, 80
  129.     mov       si, FireScreen
  130.     add       si, 80
  131.  
  132. .FIRELOOP:
  133.  
  134.     xor       ax, ax
  135.     mov       al, [ds:si]
  136.     add       al, [ds:si + 1]
  137.     adc       ah, 0
  138.     add       al, [ds:si - 1]
  139.     adc       ah, 0
  140.     add       al, [ds:si + 80]
  141.     adc       ah, 0
  142.     shr       ax, 2
  143.     jz        .ZERO
  144.     dec       ax
  145.  
  146. .ZERO:
  147.  
  148.     mov       [ds:si - 80], al
  149.     inc       si
  150.     dec       cx
  151.     jnz       .FIRELOOP
  152.  
  153.     mov       dx, $03DA
  154.  
  155. .L1:
  156.     in        al, dx
  157.     and       al, $08
  158.     jnz       .L1
  159.  
  160. .L2:
  161.     in        al, dx
  162.     and       al, $08
  163.     jz        .L2
  164.  
  165.     mov       cx, $2300
  166.     shr       cx, 1
  167.     mov       si, FireScreen
  168.     xor       di, di
  169.     rep       movsw
  170.  
  171.     mov       ah, $01
  172.     int       $16        ; Check for keypress
  173.     jz        .MAINLOOP
  174.  
  175.     mov       ah, $00
  176.     int       $16        ; Clear input buffer
  177.  
  178.     mov       ax, $0003  ; Set 80x25 text mode
  179.     int       $10
  180.  
  181.     mov       dx, EndMessage
  182.     mov       ah, $09
  183.     int       $21        ; Display end message using DOS function call
  184.  
  185.     mov       ax, $4C00  ; This function exits the program
  186.     int       $21        ; and returns control to DOS.
  187.  
  188. ;END START
  189.