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

  1. ; Information
  2. ; ▀▀▀▀▀▀▀▀▀▀▀
  3. ;
  4. ;  Program Title : NASM-IDE Copper Bars Demo
  5. ;  External name : BAR.COM
  6. ;  Version       : 1.0
  7. ;  Start date    : 18/12/1997
  8. ;  Last update   : 18/12/1997
  9. ;  Author        : Rob Anderton
  10. ;  Copyright     : (c)1997 Rob Anderton
  11. ;  Description   : An example of a copper bars effect programmed using
  12. ;                  NASM-IDE 1.1 and NASM 0.95.
  13. ;
  14. ;                  Based on code by Patch (hamell@rigel.cs.pdx.edu)
  15. ;                  (written using TASM) dated 4/9/93.
  16.  
  17.  
  18. [BITS 16]                    ; Set 16 bit code generation
  19. [ORG 0x0100]                 ; Set code start address to 100h (COM file)
  20.  
  21. ; Variables are at the end of this file
  22.  
  23. [SECTION .text]              ; Text section containing code 
  24.  
  25. START:   mov  ax, $0013      ; Set 320x200x256 VGA mode 13h
  26.          int  $10
  27.  
  28.          in   al, $21        ; Get IRQ mask
  29.          mov  [IRQSave], al  ; Save it
  30.          mov  al, 11111101b  ; Mask all but keyboard off
  31.          out  $21, al        ; Set new IRQ mask
  32.          in   al, $0A1       ; Get NMI mask
  33.          mov  [NMISave], al  ; Save it
  34.          mov  al, 11111111b  
  35.          out  $0A1, al       ; Set new NMI mask
  36.  
  37.          mov  dx, $03C8
  38.          mov  al, 01h
  39.          out  dx, al
  40.          xor  al, al
  41.          inc  dx
  42.          out  dx, al
  43.          out  dx, al
  44.          out  dx, al
  45.  
  46.          mov  ax, $0A000
  47.          mov  es, ax
  48.  
  49.          xor  di, di
  50.          mov  ax, $0101
  51.          mov  cx, 32000
  52.          cld
  53.          rep  stosw
  54.  
  55.          push ds
  56.          pop  es
  57.          mov  bx, BarLine
  58.  
  59. STARTBAR:
  60.  
  61.          cli                 ; Don't poll keyboard
  62.          mov  si, Palette    ; Set up pointer
  63.          mov  bp, $01        ; Bar number = 1
  64.  
  65. PALSETUP:
  66.  
  67.          push bp
  68.          mov  di, [bx]
  69.          mov  al, [SinTable + di] ; Top bar line
  70.  
  71.          mov  di, BarPal
  72.          dec  al             ; Decrement for 0th index element
  73.          xor  ah, ah         ; Clear high byte
  74.          mov  cx, ax
  75.          shl  ax, 1
  76.          add  ax, cx
  77.          add  di, ax
  78.          add  di, ax
  79.          mov  bp, BarPriority           
  80.          add  bp, cx            ; Set to proper spot in priority check
  81.          mov  cx, [BarHeight]
  82.  
  83. CHECKLINE:
  84.  
  85.          cmp    BYTE [bp], $00  ; Is the line empty?
  86.          jne    NODRAWLINE      ; If not, jump
  87.          mov    BYTE [bp], $01  ; It's full now
  88.          movsw
  89.          movsb
  90.          sub    si, 3
  91.          movsw
  92.          movsb
  93.          jmp    NEXTPRIORITY
  94.  
  95. NODRAWLINE:
  96.  
  97.          add  si, 3          ; Increment palette pointer
  98.          add  di, 6          ; Increment bar palette
  99.  
  100. NEXTPRIORITY:
  101.  
  102.          inc  bp             ; Next priority line
  103.          loop CHECKLINE
  104.  
  105. BARSPOT:
  106.  
  107.          add  WORD [bx], $03    ; Increment table index
  108.          cmp  WORD [bx], 359    ; End of table?
  109.          jle  NEXTBAR
  110.  
  111. RESETBARSPOT:
  112.  
  113.          mov  WORD [bx], $00    ; reset table index
  114.  
  115. NEXTBAR:
  116.  
  117.          pop  bp                ; Restore bar num
  118.          inc  bx                ; Next bar line address
  119.          inc  bx                ; Word size = + 2
  120.          inc  bp                ; Increment bar counter
  121.  
  122.          cmp  bp, [BarCount]    ; Bar count at max?
  123.          jle  PALSETUP          ; If <= , go back
  124.  
  125.          mov  si, BarPal
  126.          mov  cx, 400
  127.  
  128.          mov  dx, $03DA         ; Setup Input Status 1 reg
  129.  
  130. VRETRACE:
  131.  
  132.          in   al, dx
  133.          test al, 00001000b     ; Test bit 3, vertical retrace
  134.          jnz  VRETRACE          ; If active, go back
  135.  
  136. VNORETRACE:
  137.  
  138.          in   al, dx
  139.          test al, 00001000b     ; Test bit 3, vertical retrace
  140.          jz   VNORETRACE        ; If active, go back
  141.  
  142. PALDUMP:
  143.  
  144.          mov   al, $01
  145.          mov   dx, $03C8
  146.          out   dx, al
  147.          inc   dx
  148.          outsb                  ; Dump it out
  149.          outsb
  150.          mov   dx, $03DA
  151.  
  152. PUCK1:
  153.  
  154.          in   al,dx
  155.          test al, 00000001b
  156.          jz   PUCK1
  157.  
  158.          mov  dx, $03C9
  159.          outsb
  160.  
  161.          mov  dx, $03DA          ; Setup Input Status 1 reg
  162.  
  163. HRETRACE:
  164.  
  165.          in   al, dx
  166.          test al, 00000001b      ; Test bit 1, horizontal retrace
  167.          jnz  HRETRACE           ; If not active, go back
  168.  
  169. HNORETRACE:
  170.  
  171.          in   al, dx
  172.          test al, 00000001b      ; Test bit 1, horizontal retrace
  173.          jz   HNORETRACE         ; If active, go back;
  174.  
  175.          mov  dx, $03DA
  176.          loop PALDUMP
  177.  
  178.          mov  di, BarPriority
  179.          mov  cx, 100            ; 100 of them WORD sized
  180.          xor  ax, ax             ; AH = 0, AL = 0
  181.          rep  stosw              ; Zero them all out
  182.  
  183.          mov  di, BarPal
  184.          mov  cx, 600
  185.          xor  ax, ax
  186.          rep  stosw
  187.  
  188.          sub  bx, [BarCount]      ; Reset bar line address
  189.          sub  bx, [BarCount]      ; Twice for word size
  190.  
  191.          sti                      ; Poll keyboard
  192.          mov  ah, $01
  193.          int  $16
  194.          jnz  EXIT
  195.          jmp  STARTBAR
  196.  
  197. EXIT:
  198.  
  199.          mov  al, [IRQSave]       ; Get old IRQ mask
  200.          out  $21, al             ; Restore IRQ mask
  201.          mov  al, [NMISave]       ; Get old NMI mask
  202.          out  $0A1, al            ; Restore NMI mask
  203.          mov  ax, $0003
  204.          int  $10
  205.          mov  ax, $4C00
  206.          int  $21
  207.  
  208.  
  209. [SECTION .data]    ; Initialised variables
  210.  
  211. ; SinTable - holds top to bottom and bottom to top palette values
  212.  
  213. SinTable  db    1,   1,   1,   1,   1,   1,   1,   1,   1,   2,   2,   2
  214.           db    3,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8
  215.           db    8,   9,  10,  11,  11,  12,  13,  14,  14,  15,  16,  17
  216.           db   18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  29,  30
  217.           db   31,  32,  33,  35,  36,  37,  38,  40,  41,  42,  44,  45
  218.           db   46,  48,  49,  51,  52,  54,  55,  57,  58,  60,  61,  63
  219.           db   64,  66,  67,  69,  70,  72,  73,  75,  77,  78,  80,  81
  220.           db   83,  84,  86,  88,  89,  91,  93,  94,  96,  97,  99, 101
  221.           db  102, 104, 105, 107, 108, 110, 112, 113, 115, 116, 118, 119
  222.           db  121, 122, 124, 125, 127, 128, 130, 131, 133, 134, 136, 137
  223.           db  138, 140, 141, 143, 144, 145, 147, 148, 149, 150, 152, 153
  224.           db  154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166
  225.           db  167, 168, 169, 170, 171, 171, 172, 173, 174, 174, 175, 176
  226.           db  177, 177, 178, 178, 179, 179, 180, 180, 181, 181, 182, 182
  227.           db  182, 183, 183, 183, 184, 184, 184, 184, 184, 184, 184, 184
  228.           db  184, 184, 184, 184, 184, 184, 184, 184, 184, 183, 183, 183
  229.           db  182, 182, 182, 181, 181, 180, 180, 179, 179, 178, 178, 177
  230.           db  177, 176, 175, 174, 174, 173, 172, 171, 171, 170, 169, 168
  231.           db  167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 156, 155
  232.           db  154, 153, 152, 150, 149, 148, 147, 145, 144, 143, 141, 140
  233.           db  139, 137, 136, 134, 133, 131, 130, 128, 127, 125, 124, 122
  234.           db  121, 119, 118, 116, 115, 113, 112, 110, 108, 107, 105, 104
  235.           db  102, 101,  99,  97,  96,  94,  93,  91,  89,  88,  86,  84
  236.           db   83,  81,  80,  78,  77,  75,  73,  72,  70,  69,  67,  66
  237.           db   64,  63,  61,  60,  58,  57,  55,  54,  52,  51,  49,  48
  238.           db   47,  45,  44,  42,  41,  40,  38,  37,  36,  35,  33,  32
  239.           db   31,  30,  29,  27,  26,  25,  24,  23,  22,  21,  20,  19
  240.           db   18,  17,  16,  15,  14,  14,  13,  12,  11,  11,  10,   9
  241.           db    8,   8,   7,   7,   6,   6,   5,   5,   4,   4,   3,   3
  242.           db    3,   2,   2,   2,   1,   1,   1,   1,   1,   1,   1,   1
  243.  
  244. Palette         db       7, 7, 7                        ; gray bar start
  245.                 db      10,10,10
  246.                 db      13,13,13
  247.                 db      16,16,16
  248.                 db      19,19,19
  249.                 db      22,22,22
  250.                 db      25,25,25
  251.                 db      28,28,28
  252.                 db      31,31,31                        ; middle
  253.                 db      28,28,28
  254.                 db      25,25,25
  255.                 db      22,22,22
  256.                 db      19,19,19
  257.                 db      16,16,16
  258.                 db      13,13,13
  259.                 db      10,10,10
  260.                 db       7, 7, 7                        ; gray bar end
  261.                 db       7, 0, 0                        ; red bar start
  262.                 db      10, 0, 0
  263.                 db      13, 0, 0
  264.                 db      16, 0, 0
  265.                 db      19, 0, 0
  266.                 db      22, 0, 0
  267.                 db      25, 0, 0
  268.                 db      28, 0, 0
  269.                 db      31, 0, 0                        ; middle
  270.                 db      28, 0, 0
  271.                 db      25, 0, 0
  272.                 db      22, 0, 0
  273.                 db      19, 0, 0
  274.                 db      16, 0, 0
  275.                 db      13, 0, 0
  276.                 db      10, 0, 0
  277.                 db       7, 0, 0                        ; red bar end
  278.                 db       0, 7, 0                        ; green bar start
  279.                 db       0,10, 0
  280.                 db       0,13, 0
  281.                 db       0,16, 0
  282.                 db       0,19, 0
  283.                 db       0,22, 0
  284.                 db       0,25, 0
  285.                 db       0,28, 0
  286.                 db       0,31, 0                        ; middle
  287.                 db       0,28, 0
  288.                 db       0,25, 0
  289.                 db       0,22, 0
  290.                 db       0,19, 0
  291.                 db       0,16, 0
  292.                 db       0,13, 0
  293.                 db       0,10, 0
  294.                 db       0, 7, 0                        ; green bar end
  295.                 db       0, 0, 7                        ; blue bar start
  296.                 db       0, 0,10
  297.                 db       0, 0,13
  298.                 db       0, 0,16
  299.                 db       0, 0,19
  300.                 db       0, 0,22
  301.                 db       0, 0,25
  302.                 db       0, 0,28
  303.                 db       0, 0,31                        ; middle
  304.                 db       0, 0,28
  305.                 db       0, 0,25
  306.                 db       0, 0,22
  307.                 db       0, 0,19
  308.                 db       0, 0,16
  309.                 db       0, 0,13
  310.                 db       0, 0,10
  311.                 db       0, 0, 7                        ; blue bar end
  312.                 db       7, 7, 0                        ; yellow bar start
  313.                 db      10,10, 0
  314.                 db      13,13, 0
  315.                 db      16,16, 0
  316.                 db      19,19, 0
  317.                 db      22,22, 0
  318.                 db      25,25, 0
  319.                 db      28,28, 0
  320.                 db      31,31, 0                        ; middle
  321.                 db      28,28, 0
  322.                 db      25,25, 0
  323.                 db      22,22, 0
  324.                 db      19,19, 0
  325.                 db      16,16, 0
  326.                 db      13,13, 0
  327.                 db      10,10, 0
  328.                 db       7, 7, 0                        ; yellow bar end
  329.                 db       7, 0, 7                        ; purple bar start
  330.                 db      10, 0,10
  331.                 db      13, 0,13
  332.                 db      16, 0,16
  333.                 db      19, 0,19
  334.                 db      22, 0,22
  335.                 db      25, 0,25
  336.                 db      28, 0,28
  337.                 db      31, 0,31                        ; middle
  338.                 db      28, 0,28
  339.                 db      25, 0,25
  340.                 db      22, 0,22
  341.                 db      19, 0,19
  342.                 db      16, 0,16
  343.                 db      13, 0,13
  344.                 db      10, 0,10
  345.                 db       7, 0, 7                        ; purple bar end
  346.                 db       0, 7, 7                        ; cyan bar start
  347.                 db       0,10,10
  348.                 db       0,13,13
  349.                 db       0,16,16
  350.                 db       0,19,19
  351.                 db       0,22,22
  352.                 db       0,25,25
  353.                 db       0,28,28
  354.                 db       0,31,31                        ; middle
  355.                 db       0,28,28
  356.                 db       0,25,25
  357.                 db       0,22,22
  358.                 db       0,19,19
  359.                 db       0,16,16
  360.                 db       0,13,13
  361.                 db       0,10,10
  362.                 db       0, 7, 7                        ; cyan bar end
  363.                 db      18, 8, 1                        ; copper bar start
  364.                 db      23,13, 5
  365.                 db      28,18, 9
  366.                 db      33,23,13
  367.                 db      38,28,17
  368.                 db      43,33,21
  369.                 db      48,38,25
  370.                 db      53,43,29
  371.                 db      58,48,33                        ; middle
  372.                 db      53,43,29
  373.                 db      48,38,25
  374.                 db      43,33,21
  375.                 db      38,28,17
  376.                 db      33,23,13
  377.                 db      28,18, 9
  378.                 db      23,13, 5
  379.                 db      18, 8, 1                        ; copper bar end
  380.  
  381. BarLine         dw    175, 150, 125, 100, 75, 50, 25, 0
  382. BarHeight       dw    17
  383. BarCount        dw    8
  384. BarPal          times 400 * 3 db 0
  385. BarPriority     times 200 db 0
  386.  
  387.  
  388. [SECTION .bss]     ; Uninitialised variables
  389.  
  390. IRQSave resb 1
  391. NMISave resb 1
  392.  
  393.  
  394.