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

  1. ; Information
  2. ; ▀▀▀▀▀▀▀▀▀▀▀
  3. ;
  4. ;  Program Title : NASM-IDE Dazzler Demo
  5. ;  External name : DAZZLER.COM
  6. ;  Version       : 1.0
  7. ;  Start date    : 14/11/1997
  8. ;  Last update   : 14/11/1997
  9. ;  Author        : Rob Anderton
  10. ;  Description   : An example of text mode programming using NASM-IDE 1.1
  11. ;                  and NASM 0.95.
  12. ;
  13. ;  Notes         : Set output mode to 'COM executable file' and then
  14. ;                  assemble and run to be dazzled!
  15.  
  16. [BITS 16]                    ; Set 16 bit code generation
  17. [ORG 0x0100]                 ; Set code start address to 100h (COM file)
  18.  
  19. [SECTION .text]              ; Code segment
  20.  
  21. BEGIN:
  22.        mov   ax, $0001       ; Set video mode 1
  23.        int   $10
  24.        mov   ax, $0B800       ; Set ES to start of video page 0
  25.        mov   es, ax         
  26.  
  27.                              ; Put the pattern into video page 0 and 1
  28.  
  29.        mov   al, 219         ; Character is a solid block
  30.        mov   dx, 0           ; Initialize row counter
  31.  
  32. RLOOP:
  33.  
  34.        mov   di, dx          ; DI = row
  35.        mov   ah, dl          ; colour = row
  36.        mov   cl, 4           ; 2 ^ 4 = 16
  37.        sal   di, cl          ; DI = 16 * row
  38.        mov   cx, di          ; Save in CX
  39.        sal   di, 1           ; DI = 32 * row
  40.        sal   di, 1           ; DI = 64 * row
  41.        add   di, cx          ; DI = (64+16=80) * row
  42.        mov   cx, di          ; CX = 80 * row
  43.        mov   bx, 0           ; Initialise the column counter
  44.  
  45. CLOOP:
  46.  
  47.        inc   ah              ; Increment colour number
  48.        and   ah, 15          ; Valid colours are 0-15 only
  49.        mov   di, cx          ; DI = 80 * row
  50.        add   di, bx          ; DI = 80 * row + column
  51.        stosw                 ; Move word to page 0
  52.        add   di, 2046
  53.        stosw                 ; Move word to page 1
  54.        mov   di, cx          ; DI = 80 * row
  55.        add   di, 78          ; DI = 80 * row + 78
  56.        sub   di, bx          ; DI = 80 * row - column + 78
  57.        stosw                 ; Move word to page 0
  58.        add   di, 2046
  59.        stosw                 ; Move word to page 1
  60.        mov   di, cx          ; DI = 80 * row
  61.        neg   di              ; DI = -80 * row
  62.        add   di, 1920        ; DI = -80 * row + 1920
  63.        add   di, bx          ; DI = -80 * row + column + 1920
  64.        stosw                 ; Move word to page 0
  65.        add   di, 2046
  66.        stosw                 ; Move word to page 1
  67.        mov   di, cx          ; DI = 80 * row
  68.        neg   di              ; DI = -80 * row
  69.        add   di, 1998        ; DI = -80 * row + 1998
  70.        sub   di, bx          ; DI = -80 * row - column + 1998
  71.        stosw                 ; Move word to page 0
  72.        add   di, 2046
  73.        stosw                 ; Move word to page 1
  74.        add   bx, 2           ; Increment counter
  75.        cmp   bx, 40          ; Columns done?
  76.        je    CHKROW          ; Yes...check rows
  77.        jmp   CLOOP           ; No....check column
  78.  
  79. CHKROW:
  80.  
  81.        inc   dx              ; Increment row
  82.        cmp   dx, 13          ; Rows done?
  83.        je    MOVEIT          ; Yes..move the patterns
  84.        jmp   RLOOP           ; No...Next row
  85.  
  86.                              ; Increment or decrement the value of bits
  87.                              ; 0-3 for every attribute byte on alternating
  88.                              ; video pages 0 and 1 and swap active page
  89.  
  90. MOVEIT:
  91.  
  92.        mov   bx, 2049        ; BX = page offset
  93.        mov   si, 0           ; Set flag to no swap
  94.  
  95. MLOOP:
  96.  
  97.        cmp   bx, 2049        ; Page 1 displayed ?
  98.        je    PG0             ; Yes..display page 0
  99.        mov   bx, 2049        ; No..display page 1
  100.        mov   al, 1           ; Set page 1
  101.        jmp   SETPG
  102.  
  103. PG0:
  104.        mov   bx, 1           ; Set page offset
  105.        mov   al, 0           ; Set page 0
  106.  
  107. SETPG:
  108.  
  109.        mov   di, bx
  110.        mov   cx, 1000        ; 1000 bytes to move
  111.  
  112. ILOOP:
  113.  
  114.        mov   dh, BYTE[ES:DI] ; Get attribute byte
  115.        
  116. INCDEC:
  117.  
  118.        inc   dh              ; Modify attribute byte (self modifying here)
  119.        jns   NOTNEG          ; Sign is plus
  120.        mov   dh, 15          ; Sign is negative
  121.  
  122. NOTNEG:
  123.  
  124.        and   dh, 15          ; Valid values are 0-15
  125.        mov   BYTE[ES:DI], DH ; Place in the new attribute
  126.        inc   di              ; Point past the character
  127.        inc   di              ; And to the next attribute
  128.        loop  ILOOP           ; Repeat this 1000 times
  129.        mov   ah, 5           ; Set video page
  130.        int   $10
  131.        mov   CX, $0FFFF      ; Time delay (lower this value for more speed)
  132.  
  133. DELAY:
  134.  
  135.        loop  DELAY           ; And wait
  136.  
  137.                              ; Check for keypress - if a space, swap the code
  138.                              ; for inc and dec at label INCDEC - if ESC
  139.                              ; then exit.
  140.  
  141.        cmp   si, 1           ; Is flag set?
  142.        jz    SWAP            ; Yes..swap INC/DEC code
  143.        mov   ah, 6           ; ReadKeyboard function
  144.        mov   dl, $0FF        ; Set DL to read
  145.        int   $21             ; Call DOS
  146.        cmp   al, ' '         ; Space bar hit ?
  147.        jne   CHKESC          ; No...check for ESC key
  148.        cmp   bx, 2049        ; Are we displaying page 1 ?
  149.        je    SWAP            ; Yes...swap INC/DEC code
  150.        mov   si, 1           ; No...set flag
  151.        jmp   MLOOP           ; Continue
  152.  
  153. SWAP:
  154.  
  155.        mov   si, 0           ; Reset flag
  156.  
  157.        cmp   BYTE[INCDEC + 1], $0C6   ; Are we incrementing ?
  158.        je    DECIT                    ; Yes..swap functions
  159.        mov   BYTE[INCDEC + 1], $0C6   ; Change to increment
  160.        jmp   MLOOP                    ; And redo the display
  161.  
  162. DECIT:
  163.  
  164.        mov   BYTE[INCDEC + 1], $0CE   ; Change to decrement
  165.        jmp   MLOOP                    ; And redo the display
  166.  
  167. CHKESC:
  168.  
  169.        cmp   al, 27           ; ESC key pressed ?
  170.        jne   MLOOP            ; No..redo the display
  171.        mov   ax, $0003        ; Yes..set to 80 column display
  172.        int   $10              ; Call BIOS
  173.        mov   ax, $4C00        ; Prepare to exit
  174.        int   $21              ; Terminate programBad command or file name
  175.