Asm Fader/fix 1

 BBS: Inland Empire Archive
Date: 11-21-92 (23:08)             Number: 346
From: RICH GELDREICH               Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: Asm Fader/fix 1                Conf: (2) Quik_Bas
Ooops! After looking back at the ASM fader I posted a few days ago, I
discovered that I posted the wrong one! Duh! Well, here is the one I
originally wanted to post. The ASM code follows. Next message has OBJ
and test program.

;Noiseless VGA DAC fading routines for QB4.5/PDS(works on 286's and up)
;By Rich Geldreich 1992
;Assembled with TASM v2.0
.286
IDEAL
MODEL SMALL
DATASEG
Palette    db 768 dup (?)
NewPalette db 768 dup (?)
CODESEG
PUBLIC GetPalette, SetPalette
EVEN
PROC    SetPalette              ;Sets the pallette retrieved by
                                ;GetPalette to a specified brightness
;DECLARE SUB SetPalette (BYVAL Brigtness, BYVAL Start, BYVAL Num)
Brightness EQU [ss:bp+10] ;0-128
Start      EQU [ss:bp+08] ;0-255
Num        EQU [ss:bp+06] ;1-256
Parameters = 3
        Push    bp              ;set us up a stack frame
        Mov     bp, sp
        Push    es ds si di     ;lets not get QB mad now
        Mov     ax, @data       ;get access to palette buffers
        Mov     ds, ax
        Mov     es, ax
        Xor     ax, ax
        Mov     al, Start       ;get start color
        Mov     dx, 03C7h       ;tell the VGA some DAC values will
        Out     dx, al          ;be coming
        Inc     dx
        Out     dx, al
        Inc     dx              ;dh=3
        Mov     si, ax          ;add start*3 to the palette offset
        Shl     si, 1
        Add     si, ax
        Add     si, offset Palette
        Mov     bl, Brightness
        Cmp     bl, 128         ;limit brightness if too high
        Jna     @@Ok1
        Mov     bl, 128
@@Ok1:
        Mov     cx, Num         ;CX=# of registers to change
        Jcxz    @@Done          ;if no registers to change then exit
        Add     ax, cx          ;calculate the last register to change
        Sub     ax, 256         ;if too many then limit
        Jna     @@OK2
        Sub     cx, ax
@@OK2:
        Mov     di, offset NewPalette
        Mov     bp, cx          ;save cx for later
EVEN                            ;color precalculation loop
@@10:   REPT    3               ;repeat 3 times(for Red, Green, & Blue)
        Lodsb                   ;
        Mul     bl              ;new=old*brightness
        Shl     ax, 1           ;new=(new*2)\256 or new=new\128
        Mov     al, ah
        Stosb
        ENDM
        Loop    @@10
        Mov     cx, bp          ;multiply number of colors by 3
        Shl     cx, 1
        Add     cx, bp
        Mov     si, offset NewPalette
        Mov     dl, 0DAh        ;wait for vertical retrace
@@15:   In      al, dx          ;wait for end of vertical retrace
        Test    al, 8           ;(for very fast machines)
        Jnz     @@15
@@20:   In      al, dx          ;now wait for start of vertical
        Test    al, 8           ;retrace
        Jz      @@20
        Mov     dl, 0C9h        ;dx=03C9h
        Rep     Outsb           ;output the new colors
@@Done:
        Pop     di si ds es bp
        Retf    Parameters*2    ;bye bye
ENDP    SetPalette
PROC    GetPalette              ;Must call this routine before
;DECLARE SUB GetPalette ()      ;SetPalette!
        Push    es
        Mov     ax, @data
        Mov     es, ax
        Mov     dx, offset Palette ;es:dx addresses palette
        Mov     cx, 256
        Xor     bx, bx
        Mov     ax, 01017h
        Int     010h
        Pop     es
        Retf    0
ENDP    GetPalette
END

--- MsgToss 2.0b
 * Origin: Computer Co-Op - Voorhees, NJ | Ted Hare (1:266/29)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET