' Mode 13h routines for PowerBASIC ' by Dave Navarro, Jr. ' Last Revision: February 5, 1995 DEFINT A-Z 'Required for all numeric functions, forces PB to not 'include floating point in the executable SUB vMode(BYVAL bool) PUBLIC IF bool THEN 'if non-zero bool = &H13 ' set mode 13h ELSE bool = &H03 'otherwise give us text mode END IF ! push DS ; save DS for PowerBASIC ! mov AX, bool ; put the mode value in AX ! int &H10 ; call BIOS ! pop DS ; restore DS END SUB SUB vCLS(BYVAL vcolor) PUBLIC ! push DS ; save DS ! mov AX, &H0A000 ; VGA buffer at A000:0000 ! mov ES, AX ; put segment in ES ! xor DI, DI ; point DI to start of buffer ! mov CX, 32000 ; buffer is 64k, use 32k of words, they're faster ! mov AX, vcolor ; put color in AX ! mov AH, AL ; and AH ! rep stosw ; fill the whole screen ! pop DS ; restore DS END SUB SUB vPSET(BYVAL x, BYVAL y, BYVAL vcolor) PUBLIC ! push DS ; save DS for PowerBASIC ! mov AX, &H0A000 ; VGA buffer at A000:0000 ! mov DS, AX ; put segment in DS ! mov AX, y ; put Y in AX ! mov BX, 320 ; there are 320 pixels per line ! mul BX ; AX = AX * BX ! add AX, x ; add X location ! mov SI, AX ; point SI at pixel ! mov AX, vcolor ; put color in AX ! mov DS:[SI], AL ; put pixel on the screen ! pop DS ; restore DS END SUB FUNCTION vPGET(BYVAL x, BYVAL y) PUBLIC ! push DS ; save DS for PowerBASIC ! mov AX, &H0A000 ; VGA buffer at A000:0000 ! mov DS, AX ; put segment in DS ! mov AX, y ; put Y in AX ! mov BX, 320 ; there are 320 pixels per line ! mul BX ; AX = AX * BX ! add AX, x ; add X location ! mov SI, AX ; point SI at pixel ! mov AL, DS:[SI] ; get pixel from the screen ! xor AH, AH ; clear AH ! mov FUNCTION, AX ; return pixel value ! pop DS ; restore DS END FUNCTION ' "image?" must be a byte array. To calculate the array size, multiply the ' total rows by the total columns and add 4. SUB vGET(BYVAL x1, BYVAL y1, BYVAL x2, BYVAL y2, image?) PUBLIC DECR x2, x1 ' convert X2 to total columns DECR y2, y1 ' convert Y2 to total rows ! push DS ; save DS for PowerBASIC ! mov AX, &H0A000 ; VGA buffer at A000:0000 ! mov DS, AX ; put segment in DS ! les DI, image? ; point ES:DI to start of image ! mov AX, y1 ; put starting row in AX ! mov BX, 320 ; 320 pixels per line ! mul BX ; AX = AX * BX ! add AX, x1 ; add starting column to AX ! mov SI, AX ; point SI at starting location ! mov AX, x2 ; put total columns in AX ! stosw ; save it in image buffer ! mov CX, AX ; put it in CX ! mov AX, y2 ; put total rows in AX ! stosw ; save it in image buffer ! mov DX, AX ; put it in DX ! mov BX, CX ; put total columns in BX ! and BX, 1 ; isolate first bit ! shr CX, 1 ; divide CX by two GetCopyLoop: ! push CX ; save CX (total columns) ! push SI ; save SI (offset in video buffer) ! rep movsw ; copy CX words from buffer to array ! or BX, BX ; is there an odd number of columns? ! jz GetNotOdd ; no, we're done with this row ! movsb ; get that last byte GetNotOdd: ! pop SI ; restore SI ! pop CX ; restore CX ! add SI, 320 ; move to next row in buffer ! dec DX ; one less row to do ! jnz GetCopyLoop ; keep going until DX (total rows) = 0 ! pop DS ; restore DS END SUB SUB vPUT(BYVAL x, BYVAL y, image?) PUBLIC ! push DS ; save DS for PowerBASIC ! mov AX, &H0A000 ; VGA buffer at A000:0000 ! mov ES, AX ; put segment in ES ! lds SI, image? ; point DS:SI to start of image ! mov AX, y ; put starting row in AX ! mov BX, 320 ; 320 columns per line ! mul BX ; AX = AX * BX ! add AX, x ; add starting column ! mov DI, AX ; point DI at starting location ! lodsw ; get total columns from image buffer ! mov CX, AX ; save in CX ! lodsw ; get total rows from image buffer ! mov DX, AX ; save in DX ! mov BX, CX ; put total columns in BX ! and BX, 1 ; isolate first bit ! shr CX, 1 ; divide CX by two PutCopyLoop: ! push CX ; save CX (total columns) ! push DI ; save DI (offset in video buffer) ! rep movsw ; copy CX words from array to buffer ! or BX, BX ; is there an odd number of columns? ! jz PutNotOdd ; no, we're done with this row ! movsb ; put that last byte PutNotOdd: ! pop DI ; restore DI ! pop CX ; restore CX ! add DI, 320 ; move to next row in buffer ! dec DX ; one less row to do ! jnz PutCopyLoop ; keep going until DX (total rows) = 0 ! pop DS ; restore DS END SUB