'=========================================================================== ' Subject: PB VGA PALETTES Date: 09-09-95 (00:00) ' Author: Morry Kapitan Code: PB ' Origin: kapitam@ttown.apci.com Packet: GRAPHICS.ABC '=========================================================================== 'Here are some routines for messing with the 256 color VGA palette. I wrote 'this early on while learning some x86 asm using PB's in-line assembler. 'This certainly can be improved upon (how about using the les opcode?). 'I compiled this into a .PBU and use it in a graphics library. ' ' ' Program: VGAPALET.BAS ' Author: Morry Kapitan ' Compiler: PowerBASIC 3.x ' Version: 0.9 ' Date: 9/9/95 ' '--------------------------------------------------------------------------- 'Routines to copy the existing VGA palette to a temprorary disk file, read 'a new palette from a disk file and load it into the palette registers, and 'reload the original palette. '--------------------------------------------------------------------------- $DYNAMIC DEFINT A-Z '--------------------------------------------------------------------------- 'Procedure: SavePal 'This routine saves the current VGA palette to a temprorary disk file '--------------------------------------------------------------------------- SUB SavePal PUBLIC DIM OldPal(767) AS BYTE ArraySegment = VARSEG(OldPal(0)) ArrayOffset = VARPTR(OldPal(0)) ! push ES ! mov AX, ArraySegment ; put address of where to store ! mov ES, AX ; register data in ES:DX ! mov DX, ArrayOffset ; ! xor BX, BX ; set BX to zero -start at 1st reg ! mov CX, 255 ; get all 256 registers ! mov AX, &h1017 ; load register data into array ! int &h10 ; ! pop ES OPEN "~OLDPAL.TMP" FOR BINARY AS #1 'Open a file in the default directory FOR posit = 0 TO 767 'Write the palette data to the file PUT #1, posit, OldPal(posit) NEXT posit CLOSE #1 END SUB '--------------------------------------------------------------------------- 'Procedure: LoadPal 'This routine loads the VGA palette with data from a file whose path and 'name is passed to the routine from the calling program '--------------------------------------------------------------------------- SUB LoadPal (palFile$) PUBLIC DIM NewPal(767) AS BYTE newArraySeg = VARSEG(NewPal(0)) newArrayOff = VARPTR(NewPal(0)) OPEN palFile$ FOR BINARY AS #1 'Open the file passed from user FOR bytePos = 0 TO 767 'Retrieve palette data from file GET #1, bytePos, NewPal(bytePos) NEXT bytePos CLOSE #1 ! push ES ! mov AX, newArraySeg ; Seg of data array... ! mov ES, AX ; in ES ! mov DX, newArrayOff ; put array offset in DX ! xor BX, BX ; set BX to 0 - start at 1st reg. ! mov CX, 255 ; load all 256 registers ! mov AX, &h1012 ; put array data into VGA ! int &h10 ; registers ! pop ES END SUB '--------------------------------------------------------------------------- 'Procedure: RestorePal 'Routine to reload the original VGA palette saved in a file in the current 'directory '--------------------------------------------------------------------------- SUB RestorePal PUBLIC DIM NewOldPal(767) AS BYTE oldArraySeg = VARSEG(NewOldPal(0)) oldArrayOff = VARPTR(NewOldPal(0)) OPEN "~OLDPAL.TMP" FOR BINARY AS #1 'Open the temporary palette file FOR bytepos = 0 TO 767 'Retrieve palette data from file GET #1, bytepos, NewOldPal(bytepos) NEXT bytepos CLOSE #1 KILL "~OLDPAL.TMP" 'Delete the temproary file ! push ES ! mov AX, oldArraySeg ; Seg of data array... ! mov ES, AX ; in ES ! mov DX, oldArrayOff ; put array offset in DX ! xor BX, BX ; set BX to 0 - start at 1st reg. ! mov CX, 255 ; load all 256 registers ! mov AX, &h1012 ; put array data into VGA ! int &h10 ; registers ! pop ES END SUB