1 ;-----------------------------------------------------------------------
\r
4 ; Palette functions all MODE X 256 Color resolutions
\r
10 ; ****** XLIB - Mode X graphics library ****************
\r
11 ; ****** ****************
\r
12 ; ****** Written By Themie Gouthas ****************
\r
14 ; egg@dstos3.dsto.gov.au
\r
15 ; teg@bart.dsto.gov.au
\r
16 ;-----------------------------------------------------------------------
\r
23 All the functions in this module operate on two variations of the
\r
24 pallete buffer, the raw and annotated buffers.
\r
26 All those functions ending in buff operate on the following palette
\r
29 BYTE:r0,g0,b0,r1,g1,b1,...rn,gn,bn
\r
31 No reference to the starting colour index or number of colours stored
\r
32 is contained in the structure.
\r
34 All those functions ending in struc operate on the following palette
\r
37 BYTE:c,BYTE:n,BYTE:r0,g0,b0,r1,g1,b1,...rn,gn,bn
\r
39 where c is the starting colour and n is the number of colours stored
\r
42 NOTE: previously interrupts were disabled for DAC reads/writes but
\r
43 they have been left enabled in this version to allow the mouse
\r
44 interrupt to be invoked.
\r
57 ;----------------------------------------------------------------------
\r
58 ; Read DAC palette into annotated type buffer with interrupts disabled
\r
59 ; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
\r
61 ; x_get_pal_struc(char far * pal, int num_colrs, int start_color)
\r
63 ; WARNING: memory for the palette buffers must all be pre-allocated
\r
65 ; Written by Themie Gouthas
\r
66 ;----------------------------------------------------------------------
\r
67 _x_get_pal_struc proc
\r
68 ;ARG PalBuff:dword,NumColors:word,StartColor:word
\r
69 push bp ; Set up stack frame
\r
75 les di,dword ptr [bp+4] ; Point es:di to palette buffer
\r
76 mov si,[bp+10] ; Store the Start Colour
\r
79 mov dx,[bp+8] ; Store the Number of Colours
\r
83 mov cx,dx ; setup regs and jump
\r
84 jmp short ReadPalEntry
\r
86 _x_get_pal_struc endp
\r
92 ;----------------------------------------------------------------------
\r
93 ; Read DAC palette into raw buffer with interrupts disabled
\r
94 ; ie BYTE r1,g1,b1,r1,g2,b2...rn,gn,bn
\r
96 ; x_get_pal_raw(char far * pal, int num_colrs, int start_index)
\r
98 ; WARNING: memory for the palette buffers must all be pre-allocated
\r
100 ; Written by Themie Gouthas
\r
101 ;----------------------------------------------------------------------
\r
102 _x_get_pal_raw proc
\r
103 ;ARG PalBuff:dword,NumColors:word,StartColor:word
\r
104 push bp ; Set up stack frame
\r
109 les di,dword ptr [bp+4] ; Point es:di to palette buffer
\r
118 mov dx,DAC_READ_INDEX
\r
120 out dx,al ; Tell DAC what colour to start reading
\r
123 mov bx,cx ; set cx to Num Colors * 3 ( size of
\r
124 shl bx,1 ; palette buffer)
\r
127 rep insb ; read the palette enntries
\r
134 _x_get_pal_raw endp
\r
138 ;----------------------------------------------------------------------
\r
139 ; Write DAC palette from annotated type buffer with interrupts disabled
\r
140 ; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
\r
142 ; x_put_pal_struc(char far * pal)
\r
144 ; Written by Themie Gouthas
\r
145 ;----------------------------------------------------------------------
\r
147 _x_put_pal_struc proc
\r
148 ARG CompPalBuff:dword
\r
149 push bp ;preserve caller's stack frame
\r
150 mov bp,sp ;point to local stack frame
\r
154 lds si,[CompPalBuff] ; load the source compressed colour data
\r
155 lodsb ; get the colours to skip
\r
157 mov bx,ax ; skip colours
\r
159 lodsb ; get the count of colours to set
\r
161 mov cx,ax ; use it as a loop counter
\r
162 jmp short WritePalEntry
\r
164 _x_put_pal_struc endp
\r
167 ;----------------------------------------------------------------------
\r
168 ; Write DAC palette from annotated type buffer with interrupts disabled
\r
169 ; starting at a new palette index
\r
171 ; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
\r
173 ; x_transpose_pal_struc(char far * pal, int StartColor)
\r
175 ; WARNING: memory for the palette buffers must all be pre-allocated
\r
177 ; Written by Themie Gouthas
\r
178 ;----------------------------------------------------------------------
\r
180 _x_transpose_pal_struc proc
\r
181 ARG CompPalBuff:dword,StartColor:word
\r
182 push bp ;preserve caller's stack frame
\r
183 mov bp,sp ;point to local stack frame
\r
187 lds si,[CompPalBuff] ; load the source compressed colour data
\r
188 mov bx,[StartColor]
\r
191 lodsb ; get the count of colours to set
\r
193 mov cx,ax ; use it as a loop counter
\r
194 jmp short WritePalEntry
\r
195 _x_transpose_pal_struc endp
\r
198 ;----------------------------------------------------------------------
\r
199 ; Write DAC palette from raw buffer with interrupts disabled
\r
200 ; ie BYTE r1,g1,b1,r1,g2,b2...rn,gn,bn
\r
202 ; _x_put_pal_raw(char far * pal, int num_colrs, int start_index)
\r
204 ; Written by Themie Gouthas
\r
205 ;----------------------------------------------------------------------
\r
206 _x_put_pal_raw proc
\r
207 ARG PalBuff:dword,NumColors:word,StartColor:word
\r
208 push bp ; Set up stack frame
\r
213 mov cx,[NumColors] ; Number of colours to set
\r
214 mov bx,[StartColor]
\r
215 lds si,[PalBuff] ; ds:si -> palette buffer
\r
221 cmp es:[_VsyncHandlerActive],TRUE
\r
222 jne @@NoVsyncHandler
\r
224 cmp es:[_VsyncPaletteCount],0
\r
228 mov di, offset _VsyncPaletteBuffer
\r
235 mov [_VsyncPaletteStart],bx
\r
236 mov [_VsyncPaletteCount],cx
\r
244 cld ; Make sure we're going the right way
\r
245 WaitVsyncStart ; Wait for vert sync to start
\r
247 mov bx,60 ; set the vsync check timer (Vsync
\r
248 ; is tested for at each bx'th entry to
\r
249 ; prevent snow 60 is otimum for 10
\r
250 ; MHz 286 or greater
\r
253 mov dx,DAC_WRITE_INDEX ; Tell DAC what colour index to start
\r
254 out dx,al ; writing from
\r
257 outsb ; Set the red component
\r
258 outsb ; Set the green component
\r
259 outsb ; Set the blue component
\r
260 inc al ; increment the colour index
\r
261 dec bx ; decrement vsync test counter
\r
262 js @@test_vsync ; ready to test for vsync again ?
\r
263 loop @@SetLoop ; No! - continue loop
\r
264 jmp short @@Done ; All colours done
\r
267 mov dx,INPUT_STATUS_0
\r
268 push ax ; save current colour index
\r
270 in al,dx ; wait for vsync leading edge pulse
\r
274 pop ax ; restore current colour index
\r
275 mov bx,60 ; reset vsync test counter
\r
276 loop @@SetLoop ; loop for next colour index
\r
284 _x_put_pal_raw endp
\r
288 ;----------------------------------------------------------------------
\r
289 ; Set the RGB setting of a vga color
\r
291 ; _x_set_rgb(unsigned char color, unsigned char R,unsigned char G,
\r
295 ; Written by Themie Gouthas
\r
296 ;----------------------------------------------------------------------
\r
298 ARG ColorIndex:byte,R:byte,G:byte,B:byte
\r
299 push bp ; Set up stack frame
\r
302 mov al,[ColorIndex]
\r
303 mov dx,DAC_WRITE_INDEX ; Tell DAC what colour index to
\r
304 out dx,al ; write to
\r
307 mov al,[R] ; Set the red component
\r
309 mov al,[G] ; Set the green component
\r
311 mov al,[B] ; Set the blue component
\r
318 ;----------------------------------------------------------------------
\r
319 ; Rotate annotated palette buffer entries
\r
321 ; x_rot_pal_struc(char far * pal, int direction)
\r
323 ; Direction : 0 = backward 1 = forward
\r
325 ; Written by Themie Gouthas
\r
326 ;----------------------------------------------------------------------
\r
327 _x_rot_pal_struc proc
\r
328 ARG PalBuff:dword,Direction:word
\r
329 push bp ; Set up stack frame
\r
336 lds si,dword ptr [PalBuff] ; point ds:si to Palette buffer
\r
337 lodsw ; al = colorst ot skip, ah = num colors
\r
339 xor ch,ch ; Set the number of palette entries to cycle in cx
\r
342 jmp short RotatePalEntry
\r
344 _x_rot_pal_struc endp
\r
348 ;----------------------------------------------------------------------
\r
349 ; Rotate raw palette buffer
\r
351 ; x_rot_pal_raw(char far * pal, int direction, int num_colrs)
\r
353 ; Direcction : 0 = backward 1 = forward
\r
355 ; Written by Themie Gouthas
\r
356 ;----------------------------------------------------------------------
\r
357 _x_rot_pal_raw proc
\r
358 ARG PalBuff:dword,Direction:word,NumColors:word
\r
359 push bp ; Set up stack frame
\r
366 mov cx,[NumColors] ; Set the number of palette entries to cycle
\r
367 lds si,dword ptr [PalBuff] ; point ds:si to Palette buffer
\r
372 mov ax,ds ; copy ds to es
\r
376 mov bx,cx ; Multiply cx by 3
\r
380 cmp [Direction],0 ; are we going forward ?
\r
381 jne @@forward ; yes - jump (colors move one position back)
\r
383 std ; no - set reverse direction
\r
384 add si,cx ; set si to last byte in palette
\r
388 mov ax,si ; copy si to di
\r
391 lodsb ; load first color triplet into regs
\r
398 rep movsb ; move remaining triplets direction indicated
\r
399 ; by direction flag
\r
401 mov al,dl ; write color triplet from regs to last position
\r
413 _x_rot_pal_raw endp
\r
415 ;----------------------------------------------------------------------
\r
416 ; Copy palette making intensity adjustment
\r
417 ; x_cpcontrast_pal_struc(char far *src_pal, char far *dest_pal, unsigned char Intensity)
\r
419 ; WARNING: memory for the palette buffers must all be pre-allocated
\r
421 ; Written by Themie Gouthas
\r
422 ;----------------------------------------------------------------------
\r
423 _x_cpcontrast_pal_struc proc
\r
424 ARG PalSrcBuff:dword,PalDestBuff:dword,Intensity:byte
\r
425 push bp ; Set up stack frame
\r
434 and bh,07fh ; Palettes are 7 bit
\r
435 lds si,dword ptr [PalSrcBuff] ; point ds:si to Source Palette buffer
\r
436 les di,dword ptr [PalDestBuff] ; point ds:si to Source Palette buffer
\r
437 lodsw ; al = colorst ot skip, ah = num color
\r
440 xor ch,ch ; Set the number of palette entries to adjust
\r
443 mov dx,0 ; flag set to 0 if all output palette entries zero
\r
446 sub al,bh ; adjust intensity and copy RED
\r
447 jns @@DecrementOK_R
\r
450 sub ah,bh ; adjust intensity and copy GREEN
\r
451 jns @@DecrementOK_G
\r
458 sub al,bh ; adjust intensity and copy BLUE
\r
459 jns @@DecrementOK_B
\r
472 _x_cpcontrast_pal_struc endp
\r
476 ;----------------------------------------------------------------------
\r
477 ; Write DAC palette from annotated type buffer with specified intensity
\r
478 ; ie BYTE colours to skip, BYTE colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
\r
480 ; x_put_contrast_pal_struc(char far * pal, unsigned char intensity)
\r
482 ; Designed for fading in or out a palette without using an intermediate
\r
483 ; working palette buffer ! (Slow but memory efficient ... OK for small
\r
486 ; Written by Themie Gouthas
\r
487 ;----------------------------------------------------------------------
\r
489 _x_put_contrast_pal_struc proc
\r
490 ARG CompPalBuff:dword,Intensity:byte
\r
491 push bp ;preserve caller's stack frame
\r
492 mov bp,sp ;point to local stack frame
\r
500 and bh,07fh ; Palettes are 7 bit
\r
501 mov di,40 ; set the vsync check timer (Vsync
\r
502 ; is tested for at each di'th entry to
\r
503 ; prevent snow 40 is otimum for 10
\r
504 ; MHz 286 or greater)
\r
505 lds si,[CompPalBuff] ; load the source compressed colour data
\r
506 lodsb ; get the colours to skip
\r
509 lodsb ; get the count of colours to set
\r
511 mov cx,ax ; use it as a loop counter
\r
515 WaitVsyncStart ; Wait for vert sync to start
\r
519 mov dx,DAC_WRITE_INDEX ; Tell DAC what colour index to start
\r
520 out dx,al ; writing from
\r
521 inc dx ; == mov dx,DAC_DATA
\r
523 lodsb ; Load each colour component, modify for
\r
524 sub al,bh ; intensity and write to DAC H/Ware
\r
525 jns @@DecrementOK_R
\r
532 jns @@DecrementOK_G
\r
539 jns @@DecrementOK_B
\r
544 inc bl ; increment color index
\r
545 dec di ; decrement vsync test flag
\r
552 mov dx,INPUT_STATUS_0
\r
553 push ax ; save current colour index
\r
555 in al,dx ; wait for vsync leading edge pulse
\r
559 pop ax ; restore current colour index
\r
560 mov di,40 ; reset vsync test counter
\r
561 loop @@MainLoop ; loop for next colour index
\r
571 _x_put_contrast_pal_struc endp
\r