?? xpal.asm
字號:
;
; _x_set_rgb(unsigned char color, unsigned char R,unsigned char G,
; unsigned char B)
;
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_set_rgb proc
ARG ColorIndex:byte,R:byte,G:byte,B:byte
push bp ; Set up stack frame
mov bp,sp
mov al,[ColorIndex]
mov dx,DAC_WRITE_INDEX ; Tell DAC what colour index to
out dx,al ; write to
mov dx,DAC_DATA
mov al,[R] ; Set the red component
out dx,al
mov al,[G] ; Set the green component
out dx,al
mov al,[B] ; Set the blue component
out dx,al
pop bp
ret
_x_set_rgb endp
;----------------------------------------------------------------------
; Rotate annotated palette buffer entries
;
; x_rot_pal_struc(char far * pal, int direction)
;
; Direction : 0 = backward 1 = forward
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_rot_pal_struc proc
ARG PalBuff:dword,Direction:word
push bp ; Set up stack frame
mov bp,sp
push ds
push si
push di
cld
lds si,dword ptr [PalBuff] ; point ds:si to Palette buffer
lodsw ; al = colorst ot skip, ah = num colors
xor ch,ch ; Set the number of palette entries to cycle in cx
mov cl,ah ;
jmp short RotatePalEntry
_x_rot_pal_struc endp
;----------------------------------------------------------------------
; Rotate raw palette buffer
;
; x_rot_pal_raw(char far * pal, int direction, int num_colrs)
;
; Direcction : 0 = backward 1 = forward
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_rot_pal_raw proc
ARG PalBuff:dword,Direction:word,NumColors:word
push bp ; Set up stack frame
mov bp,sp
push ds
push si
push di
cld
mov cx,[NumColors] ; Set the number of palette entries to cycle
lds si,dword ptr [PalBuff] ; point ds:si to Palette buffer
RotatePalEntry:
mov ax,ds ; copy ds to es
mov es,ax
dec cx
mov bx,cx ; Multiply cx by 3
shl bx,1
add cx,bx
cmp [Direction],0 ; are we going forward ?
jne @@forward ; yes - jump (colors move one position back)
std ; no - set reverse direction
add si,cx ; set si to last byte in palette
add si,2
@@forward:
mov ax,si ; copy si to di
mov di,ax
lodsb ; load first color triplet into regs
mov dl,al
lodsb
mov dh,al
lodsb
mov bl,al
rep movsb ; move remaining triplets direction indicated
; by direction flag
mov al,dl ; write color triplet from regs to last position
stosb
mov al,dh
stosb
mov al,bl
stosb
pop di
pop si
pop ds
pop bp
ret
_x_rot_pal_raw endp
;----------------------------------------------------------------------
; Copy palette making intensity adjustment
; x_cpcontrast_pal_struc(char far *src_pal, char far *dest_pal, unsigned char Intensity)
;
; WARNING: memory for the palette buffers must all be pre-allocated
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_cpcontrast_pal_struc proc
ARG PalSrcBuff:dword,PalDestBuff:dword,Intensity:byte
push bp ; Set up stack frame
mov bp,sp
push ds
push si
push di
cld
mov bh,0ffh
sub bh,[Intensity]
and bh,07fh ; Palettes are 7 bit
lds si,dword ptr [PalSrcBuff] ; point ds:si to Source Palette buffer
les di,dword ptr [PalDestBuff] ; point ds:si to Source Palette buffer
lodsw ; al = colorst ot skip, ah = num color
stosw
xor ch,ch ; Set the number of palette entries to adjust
mov cl,ah ;
mov dx,0 ; flag set to 0 if all output palette entries zero
@@MainLoop:
lodsw
sub al,bh ; adjust intensity and copy RED
jns @@DecrementOK_R
xor al,al
@@DecrementOK_R:
sub ah,bh ; adjust intensity and copy GREEN
jns @@DecrementOK_G
xor ah,ah
@@DecrementOK_G:
or dx,ax
or dl,ah
stosw
lodsb
sub al,bh ; adjust intensity and copy BLUE
jns @@DecrementOK_B
xor al,al
@@DecrementOK_B:
or dl,al
stosb
loop @@MainLoop
mov ax,dx
pop di
pop si
pop ds
pop bp
ret
_x_cpcontrast_pal_struc endp
;----------------------------------------------------------------------
; Write DAC palette from annotated type buffer with specified intensity
; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
;
; x_put_contrast_pal_struc(char far * pal, unsigned char intensity)
;
; Designed for fading in or out a palette without using an intermediate
; working palette buffer ! (Slow but memory efficient ... OK for small
; pal strucs}
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_put_contrast_pal_struc proc
ARG CompPalBuff:dword,Intensity:byte
push bp ;preserve caller's stack frame
mov bp,sp ;point to local stack frame
push ds
push si
push di
cld
mov bh,0ffh
sub bh,[Intensity]
and bh,07fh ; Palettes are 7 bit
mov di,40 ; set the vsync check timer (Vsync
; is tested for at each di'th entry to
; prevent snow 40 is otimum for 10
; MHz 286 or greater)
lds si,[CompPalBuff] ; load the source compressed colour data
lodsb ; get the colours to skip
mov bl,al
lodsb ; get the count of colours to set
mov ah,0
mov cx,ax ; use it as a loop counter
or cx,cx
jz @@Done
WaitVsyncStart ; Wait for vert sync to start
@@MainLoop:
mov al,bl
mov dx,DAC_WRITE_INDEX ; Tell DAC what colour index to start
out dx,al ; writing from
inc dx ; == mov dx,DAC_DATA
lodsb ; Load each colour component, modify for
sub al,bh ; intensity and write to DAC H/Ware
jns @@DecrementOK_R
xor al,al
@@DecrementOK_R:
out dx,al
lodsb
sub al,bh
jns @@DecrementOK_G
xor al,al
@@DecrementOK_G:
out dx,al
lodsb
sub al,bh
jns @@DecrementOK_B
xor al,al
@@DecrementOK_B:
out dx,al
inc bl ; increment color index
dec di ; decrement vsync test flag
js @@test_vsync
loop @@MainLoop
jmp short @@Done
@@test_vsync:
mov dx,INPUT_STATUS_0
push ax ; save current colour index
@@Wait:
in al,dx ; wait for vsync leading edge pulse
test al,08h
jz @@Wait
pop ax ; restore current colour index
mov di,40 ; reset vsync test counter
loop @@MainLoop ; loop for next colour index
@@Done:
;sti
pop di
pop si
pop ds
pop bp
ret
_x_put_contrast_pal_struc endp
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -