M EQU Byte Ptr 0[BX] TITLE 'GETADDR - COMPUTE THE ADDRESS FOR PIXEL AT POSITION X,Y' ;----------------------------------------------------------------------------+ ; REVISION : Dec. 21, 1983 FILE "GETADDR.A86" + ; Use Allocated Bitmap Memory if running under DOS 2.0, Setup ES for + ; Base Segment address of Bitmap buffer ( instead of DS ) + ;----------------------------------------------------------------------------+ PUBLIC SBIT, GETADR, ADDRXY, SETBIT EXTRN FILTER:near EXTRN SUBDH:near, MIDH:near dseg EXTRN BITMAP:word, MPTY:word, NBYT:word, NBIT:byte EXTRN TOPY:word, BOTTY:word, XW:word EXTRN X0:word, Y0:word, XMAX:word Extrn Bitmap_offset:word ; 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/set clear mode : ritflg = 1, and operation ; with bit mask = 11111110b ; if color = 0, xor mode = xor, bit mask = 00000001b 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 CALL GETADR ;Returns = nbyt, = nbit 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 ; = NBIT GETADR: ; Get the address of x,y relative to the start of bitmap CALL ADDRXY ;Returns = nbyt ; = nbit ; Add byte address to the base address CALL CORADR ;Get the base address of ;the corresponding color ;bitmap buffer, returns the Base ;Address + NBYT in MOV Word Ptr NBYT,BX ;STORE pixel bitmap address MOV Byte Ptr NBIT,CH RET ;----------------------------------------------------------------------------; ; CORADR - Add the byte address of the Pixel to the Base address of ; ; the Current Color Bitmap Buffer ; ;----------------------------------------------------------------------------; ; CALL CORADR ; ; = NBYT ; ; RET ; ; = new NBYT ; ;----------------------------------------------------------------------------; CORADR: ;;;;;;; MOV DX,(Offset BITMAP) ;Get the Base address ; Get the base Address Mov Dx, Word Ptr Bitmap_offset ; add to the relative byte address in ADD BX,DX RET EJECT ; **************************************************************************** ; * * ; * 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 | ;+----------------------------------------------------------------------+ ; * ; Output : None * ; * ;-----------------------------------------------------------------------+ ; + ; CALL SETBIT + ; = NBYT + ; = NBIT + ; RET + ; Unchanged + ; Uses + ;-----------------------------------------------------------------------+ SETBIT: PUSH CX MOV AL,bitmask ; Rotate bit mask to appropriate bit position ROTA: ROR AL,1 DEC CH JNS ROTA ; = bit mask in correct bit position cmp ritflg, 0 ;check the writing flag : -1,0,1 = xor,or,and je orbit ; 0 = OR mode js xorbit ; -1 = XOR mode and Es:m,al ; 1 = AND mode jmp gotbit ; new data = old data AND bitmask xorbit: xor Es:m,al jmp gotbit orbit: or Es:m,al ; new data = old data OR bitmask gotbit: ; got the new data byte POP CX ;Restore nbit RET end