⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpal.asm

📁 视频游戏开发C语言源程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;-----------------------------------------------------------------------
; MODULE XPAL
;
; Palette functions all MODE X 256 Color resolutions
;
; Compile with Tasm.
; C callable.
;
;
; ****** XLIB - Mode X graphics library                ****************
; ******                                               ****************
; ****** Written By Themie Gouthas                     ****************
;
; egg@dstos3.dsto.gov.au
; teg@bart.dsto.gov.au
;-----------------------------------------------------------------------


COMMENT	$



    All the functions in this module operate on two variations of the
    pallete buffer, the raw and annotated buffers.

    All those functions ending in buff operate on the following palette
    structure:

       BYTE:r0,g0,b0,r1,g1,b1,...rn,gn,bn

    No reference to the starting colour index or number of colours stored
    is contained in the structure.

    All those functions ending in struc operate on the following palette
    structure:

       BYTE:c,BYTE:n,BYTE:r0,g0,b0,r1,g1,b1,...rn,gn,bn

    where c is the starting colour and n is the number of colours stored


    NOTE: previously interrupts were disabled for DAC reads/writes but
	  they have been left enabled in this version to allow the mouse
	  interrupt to be invoked.

$




include xlib.inc
include xpal.inc

.code


;----------------------------------------------------------------------
; Read DAC palette into annotated type buffer with interrupts disabled
; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
;
; x_get_pal_struc(char far * pal, int num_colrs, int start_color)
;
; WARNING: memory for the palette buffers must all be pre-allocated
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_get_pal_struc  proc
ARG  PalBuff:dword,NumColors:word,StartColor:word
     push  bp		; Set up stack frame
     mov   bp,sp
     push  di
     push  si
     cld

     les   di,dword ptr [PalBuff]  ; Point es:di to palette buffer
     mov   si,[StartColor]         ; Store the Start Colour
     mov   ax,si
     stosb
     mov   dx,[NumColors]          ; Store the Number of Colours
     mov   al,dl
     stosb

     mov   cx,dx                   ; setup regs and jump
     jmp   short ReadPalEntry

_x_get_pal_struc endp





;----------------------------------------------------------------------
; Read DAC palette into raw buffer with interrupts disabled
; ie BYTE r1,g1,b1,r1,g2,b2...rn,gn,bn
;
; x_get_pal_raw(char far * pal, int num_colrs, int start_index)
;
; WARNING: memory for the palette buffers must all be pre-allocated
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_get_pal_raw	proc
ARG  PalBuff:dword,NumColors:word,StartColor:word
     push  bp		; Set up stack frame
     mov   bp,sp
     push  di
     push  si

     les   di,dword ptr [PalBuff]  ; Point es:di to palette buffer

     mov  si,[StartColor]
     mov  cx,[NumColors]

ReadPalEntry:
     cld
     WaitVsyncStart
     mov  ax,si
     mov  dx,DAC_READ_INDEX
     ;cli
     out  dx,al                    ; Tell DAC what colour to start reading
     mov  dx,DAC_DATA

     mov  bx,cx                    ; set cx to Num Colors * 3 ( size of
     shl  bx,1                     ; palette buffer)
     add  cx,bx

     rep  insb                     ; read the palette enntries

     ;sti
     pop  si
     pop  di
     pop  bp
     ret
_x_get_pal_raw endp



;----------------------------------------------------------------------
; Write DAC palette from annotated type buffer with interrupts disabled
; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
;
; x_put_pal_struc(char far * pal)
;
; Written by Themie Gouthas
;----------------------------------------------------------------------

_x_put_pal_struc proc
ARG     CompPalBuff:dword
        push    bp      ;preserve caller's stack frame
	mov     bp,sp   ;point to local stack frame
	push    ds
	push    si
	cld
	lds     si,[CompPalBuff]   ; load the source compressed colour data
	lodsb			   ; get the colours to skip
	mov     ah,0
	mov     bx,ax              ; skip colours

	lodsb			   ; get the count of colours to set
	mov     ah,0
	mov	cx,ax              ; use it as a loop counter
	jmp     short WritePalEntry

_x_put_pal_struc  endp


;----------------------------------------------------------------------
; Write DAC palette from annotated type buffer with interrupts disabled
; starting at a new palette index
;
; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
;
; x_transpose_pal_struc(char far * pal, int StartColor)
;
; WARNING: memory for the palette buffers must all be pre-allocated
;
; Written by Themie Gouthas
;----------------------------------------------------------------------

_x_transpose_pal_struc proc
ARG     CompPalBuff:dword,StartColor:word
        push    bp      ;preserve caller's stack frame
	mov     bp,sp   ;point to local stack frame
	push    ds
	push    si
	cld
	lds     si,[CompPalBuff]   ; load the source compressed colour data
	mov     bx,[StartColor]
	mov     [si],bl
	inc     si
	lodsb			   ; get the count of colours to set
	mov     ah,0
	mov	cx,ax              ; use it as a loop counter
	jmp     short WritePalEntry
_x_transpose_pal_struc endp


;----------------------------------------------------------------------
; Write DAC palette from raw buffer with interrupts disabled
; ie BYTE r1,g1,b1,r1,g2,b2...rn,gn,bn
;
; _x_put_pal_raw(char far * pal, int num_colrs, int start_index)
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_put_pal_raw  proc
ARG  PalBuff:dword,NumColors:word,StartColor:word
		push bp		; Set up stack frame
		mov  bp,sp
		push ds
		push si

		mov  cx,[NumColors]      ; Number of colours to set
		mov  bx,[StartColor]
		lds  si,[PalBuff]        ; ds:si -> palette buffer


WritePalEntry:
                mov  ax,@data
		mov  es,ax
		cmp  es:[_VsyncHandlerActive],TRUE
		jne  @@NoVsyncHandler
@@WaitForLast:
		cmp  es:[_VsyncPaletteCount],0
		jne  @@WaitForLast
		push cx
		push es
		mov  di, offset _VsyncPaletteBuffer
		mov  ax,3
		mul  cx
		mov  cx,ax
		rep  movsb
		pop  ds
		pop  cx
		mov  [_VsyncPaletteStart],bx
		mov  [_VsyncPaletteCount],cx
		jmp  short @@Done
@@NoVsyncHandler:


		or   cx,cx
		jz   @@Done
		;cli
		cld                      ; Make sure we're going the right way
		WaitVsyncStart           ; Wait for vert sync to start
                mov  ax,bx
		mov  bx,60               ; set the vsync check timer (Vsync
                			 ; is tested for at each bx'th entry to
					 ; prevent snow 60 is otimum for 10
					 ; MHz 286 or greater

@@SetLoop:
		mov  dx,DAC_WRITE_INDEX  ; Tell DAC what colour index to start
		out  dx,al               ; writing from
		mov  dx,DAC_DATA

		outsb                    ; Set the red component
		outsb                    ; Set the green component
		outsb                    ; Set the blue component
		inc  al                  ; increment the colour index
		dec  bx                  ; decrement vsync test counter
		js   @@test_vsync        ; ready to test for vsync again ?
		loop @@SetLoop           ; No! - continue loop
		jmp  short @@Done        ; All colours 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     bx,60            ; reset vsync test counter
		loop @@SetLoop           ; loop for next colour index

@@Done:
		;sti
		pop  si
		pop  ds
		pop  bp
		ret
_x_put_pal_raw endp



;----------------------------------------------------------------------
; Set the RGB setting of a vga color

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -