M EQU Byte Ptr 0[BX] TITLE 'Set color Bitmap PIXEL' ;----------------------------------------------------------------------------+ ; REVISION : Jan. 12, 1984 FILE "GETADRC.A86" GSX-86 V1.3 1-1 + ;----------------------------------------------------------------------------+ PUBLIC SBIT, GETADR, ADDRXY, SETBIT EXTRN FILTER:near EXTRN SUBDH:near, MIDH:near dseg Extrn Bitmap_Offset:word EXTRN Cormap_size:word EXTRN BITMAP:word, MPTY:word, NBYT:word, NBIT:byte EXTRN TOPY:word, BOTTY:word, XW:word, COLORBIT:byte EXTRN X0:word, Y0:word, XMAX:word TMP rs 02 BMASK rs 02 ;-----------------------------------------------------------------------+ ; ; logical op flag : ritflg, 0 = OR : replace/set mode ; 1 = AND : replace/clear mode ; -1 = xor mode ; if color = 1 ; o replace and set mode : ritflg = 0, bit mask = 00000001b ; o clear mode : ritflg = 1, bit mask = 11111110b ; o xor mode : ritflg = -1,bit mask = 00000001b ; if color = 0, replace mode : ritflg = 1, bit mask = 11111110b ; if color = 0, replace/set and clear mode same as clear mode in ; color 1: ritflg = 1, bit mask = 11111110b ;-----------------------------------------------------------------------+ EXTRN RITFLG:byte, BITMASK:byte, NOPFLG:byte cseg ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; SBIT ; ; FILTER Y TO WITH IN THE CURRENT PLOT STRIP, IF INSIDE THEN ; ; SET THE BIT AT ADDRESS X, Y IN THE BITMAP BUFFER ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; * ; Process : * ; * ; FILTER (y ,flag1) ;Determine the relative position of the point * ; flag (bit 2) = sign bit of (topy - y) * ; flag (bit 1) = sign bit of (y - boty) * ; * ; REJECT (flag1) ;Test to see if the POINT outside strip * ; for rejection * ; if inside then * ; * ; ADDRXY (x, y, nbyt, nbit) ;Computer the BITMAP address * ; * ; SETBIT (nbyt, nbit) ;Set the bit in BITMAP * ; * ; FILTER returns * ; flag (bit 2) = sign bit of (topy - y) * ; flag (bit 1) = sign bit of (y - boty) * ; position flag bit 2 | 1 | * ; ------------ * ; point above 1 | 0 | * ; ------------ top y edge of strip * ; point inside 0 | 0 | * ; ------------ bottom y edge of strip * ; point below 0 | 1 | * ; * ;----------------------------------------------------------------------------* ; + ; CALL SBIT + ; X ,Y , TOPY,BOTY passed in meory + ; RET + SBIT: ;----------------------------------------------------------------------------+ ; Filter x-coordinate against Plot Extent + ;----------------------------------------------------------------------------+ MOV BX,Word Ptr X0 OR BH, BH ; NEGATIVE X : OUT OF BOUND JS SBIT90 CMP BX, WORD PTR XMAX JG SBIT90 ; X OUT OF BOUND ;----------------------------------------------------------------------------+ ; Filter y-coordinate against strip + ;----------------------------------------------------------------------------+ MOV BX, WORD PTR Y0 CALL FILTER ;Returns position flag flg1 in ;flg1 : 0 = boty < y < topy ; >0 = y above or below strip ; zero = on, point inside ; = off,point rejected (lies outside window) ;----------------------------------------------------------------------------+ ; Test : Y lies entirely outside strip & can be trivially rejected ? + ;----------------------------------------------------------------------------+ XOR AL,AL ;reject Y if fg1 NOT= 0 OR AL,CH ; = flg1 ; TRIVIALLY REJECT POINT JZ L@1 RET ;Zero flag off indicating line rejected L@1: ;----------------------------------------------------------------------------+ ; POINT inside Plot Strip + ; Get bitmap address for first pixel x1,ystrt + ;----------------------------------------------------------------------------+ MOV DX,Word Ptr Y0 MOV BX,Word Ptr X0 ; = x ; 4 Print Pass Color Plane Overlay support ; Depending on the color index, COLOR BIT is either set to 1 for ; Set bit or 0 for Clear bit, all four bitmap planes ; need to be set. ; Compute Relative Bitmap address for X0, Y0 CALL GETADR ;Returns = nbyt, = nbit ; Check Color Bit for each Color Plane and 'SET' the bit CALL SETBIT SBIT90: RET ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; ; ; GETADR : Get the Bitmap Address for the Pixel (X,Y) ; ; ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Getadr (x, y, nbyt, nbit) ; ; ; ; Function : Compute the bitmap address ; ; ; ; Input : BITMAP - Start Byte address of the BITMAP Buffer ; ; X, Y Pixel coord. ; ; Output : ; ; NBYT - Pixel address pointer (byte position : y coordinate) ; ; NBIT - Pixel address pointer (bit position : x coordinate) ; ; ; ; Calls : ADDRXY - Compute pixel address relative to the start of BITMAP ; ; ; ;----------------------------------------------------------------------------; ; CALL GETADR ; = X ; = Y ; RET ; = NBYT ; = nbyt ; = nbit MOV Word Ptr NBYT,BX ;STORE pixel bitmap address MOV Byte Ptr NBIT,CH RET ; **************************************************************************** ; * * ; * ADDRXY : DETERMINE THE BITMAP ADDRESS AT WHICH THE PIXEL X,Y SHOULD * ; * BE STORED * ; * * ; **************************************************************************** ; * ; Addrxy (x, y, nbyt, nbit) * ; * ; Function : Set BITMAP USED indicator : MPTY * ; Maps pixel location x,y to BITMAP address nbyt,nbit * ; topy is mapped to end of bitmap buffer * ; botty is mapped to start of bitmap buffer * ; adjust y to address within bitmap boundary * ; y = y - botty * ; nbyt = y*xw + x/8 ;the byte position in bitmap for * ; the x,y coord., xw = (No. of * ; pixels per print line)/8 * ; nbit = x mod 8 ;the bit position in nbyt for x coord. * ; * ; Input : X, Y * ; * ; Output : nbyt - address pointer to the byte location in bitmap * ; nbit - bit location in nbyt for pixel x,y * ; * ; Calls : MIDH - 16-bit integer multiply routine * ; * ;----------------------------------------------------------------------------* ; ; ; CALL ADDRXY ; ; = X ; ; = Y ; ; RET ; ; = NBYT ; ; = NBIT ; ;----------------------------------------------------------------------------; ADDRXY: ;----------------------------------------------------------------------------+ ; Nbit = x mod 8 + ;----------------------------------------------------------------------------+ MOV AL,07H MOV Byte Ptr MPTY,AL ;Set BITMAP BUFFER Used Indicator AND AL,BL ;A=nbit ;Save nbit PUSH AX ;----------------------------------------------------------------------------+ ; Nbyt = Y*XW + X div 8 + ;----------------------------------------------------------------------------+ MOV CH,3 ;X div 8 (Shift right 3 times) ADDL01: XOR AL,AL ;clear carry MOV AL,BH RCR AL,1 MOV BH,AL ;Double register shift MOV AL,BL RCR AL,1 MOV BL,AL DEC CH JNZ ADDL01 ;Shift 3 times ;----------------------------------------------------------------------------+ ; Adjust y to current Plot strip bottom y = BITMAP base address + ;----------------------------------------------------------------------------+ ;y = y - current bottom edge (botty) SUB DX,Word Ptr Botty ; = y - botty MOV AX,Word Ptr XW ;Put into MUL DX ; = (Y-BOTTY) * XW ADD BX,AX ; = NBYT POP CX XCHG CL,CH ; = NBIT ADDR90: RET ; *********************************************************************** ; * * ; * SETBIT : 'SET' THE BIT AT THE BITMAP BUFFER ADDRESS NBYT,NBIT * ; * * ; *********************************************************************** ; * ; Setbit (nbyt, nbit) * ; * ; Function : 'SET' a bit in BITMAP buffer, use nbyt and nbit as address* ; pointer * ; * ; Input : NBYT - Byte address * ; NBIT - bit position in nbyt to 'SET', * ; nbit = 0 1 2 3 4 5 6 7 * ;-----------------------------------------------------------------------+ ; Clear or Set the bit in nbyt according to logical op flag: ritflg ; ritflg is both color and writing mode dependant ;+----------------------------------------------------------------------+ ;| mode 1 2 3 4 | ;+----------------------------------------------------------------------+ ;| replace set xor clear | ;+----------------------------------------------------------------------+ ;| carry = color AND linestyle | ;+----------------------------------------------------------------------+ ;| 0 0 nop nop nop | ;+----------------------------------------------------------------------+ ;| 1 1 1 not (data) 0 | ;+----------------------------------------------------------------------+ ; + ; CALL SETBIT + ; = NBYT + ; = NBIT + ; RET + ; Unchanged + ; Uses + ;-----------------------------------------------------------------------+ SETBIT: PUSH Cx Push Bx ; address pointer = base address + offset in Add Bx, Word Ptr Bitmap_offset ;;;;; Add Bx, (Offset Bitmap) ; Offset + Base address of ; Color Plane 0 MOV AL,bitmask ; Rotate bit mask to appropriate bit position ROTA: ROR AL,1 DEC CH JNS ROTA ; = bit mask in correct bit position Mov Byte Ptr BMASK, Al ; Save Mask FCOLOR: ; For Each Color BitPlane, Check Color Bit, Clear or Set the Bit ; accordingly. ; Get Next Color Bit cmp ritflg, 0 js xormode ; Handle XOR mode seperately Mov Ch, 4 Mov Dl, Byte Ptr COLORBIT next_plane: Push Cx ; Stack loop count Push Bx ; Stack Byte Address Mov Al, Byte Ptr BMASK MASKBIT: cmp ritflg, 0 ;check the writing flag : -1,0,1 = xor,or,and je orbit ; 0 = OR mode js xorbit ; -1 = XOR mode Jmp andbit notbit: Not al andbit: and Es:m,al ; 1 = AND mode jmp gotbit ; new data = old data AND bitmask xorbit: xor Es:m,al jmp gotbit orbit: Rcr Dl, 1 ; Set or Clear for this color plane ? Jnc notbit ; Not Mask AND old data if clear color bit or Es:m,al ; new data = old data OR bitmask gotbit: ; got the new data byte Pop Bx Pop Cx Dec Ch Jz Done Add Bx, Word Ptr Cormap_size ; Byte Address of next Color Plane Jmp Next_plane xormode: ; Check Old Data bits in each Color Plane ; Case 1 : Old Data = 0 in all 3 color plane, Xor only the black ; plane. ; Case 2 : Old Data not all 0's, Xor the 3 color plane and not the ; black plane. Mov Word Ptr Tmp, Bx ; Save byte address Mov ch, 3 Ck_nxt: Mov dl, BMASK Add Bx, Word Ptr Cormap_size ; Point to next color plane And dl, Es:m Jnz three_plane Dec ch Jnz Ck_nxt ; 0 old data Bit in all 3 Planes, must xor only the Black Plane. Mov Al, BMASK Mov Bx, Word Ptr Tmp Xor Es:M, al Jmp Done Three_plane: ; None 0 old data bit, xor the three color planes but ; leave the black plane alone Mov Ch, 3 Mov Bx, word Ptr Tmp Add Bx, Word Ptr Cormap_size ; Point to Red plane Mov Dl, COLORBIT Rcr Dl, 1 ; Skip black color bit Jmp Next_plane ; Xor on three color planes done: Pop Bx ; Restore nbyt POP CX ; Restore nbit RET end