h51455
s 00430/00000/00000
d D 1.1 83/03/15 21:23:14 tes 1 0
c date and time created 83/03/15 21:23:14 by tes
e
u
4
U
t
T
I 1
DEFCGBL	equ	0c1h			; define global in code segment
DEFDGBL	equ	0c2h			; define global in data segment
RELCGBL	equ	0c3h			; relative address of global in code
ABSCGBL	equ	0c4h			; absolute address of global in code
	cseg
dlocal	rw	0
inigraph db	38h, 28h, 2dh, 0ah, 7fh, 06h, 64h, 70h
	 db	02h, 01h, 06h, 07h, 00h, 00h, 00h, 00h
inialpha db	71h, 50h, 5ah, 0ah, 1fh, 06h, 19h, 1ch 
	 db	02h, 07h, 06h, 07h, 00h, 00h, 00h, 00h
masks	 db	80h, 40h, 20h, 10h, 08h, 04h, 02h, 01h
routines dw	0, 0, 0, 0		; jump table:setbit,orbit,xorbit,erabit
glo_adj_12	equ	$-8
glo_adj_13	equ	$-6
glo_adj_14	equ	$-4
glo_adj_15	equ	$-2
;
; diibm (mode) - initialize ibm pc for graphics or alpha
;       mode - 0 = alpha, 1 = graphics
;
diibm:
	push	bp                      ; save bp register
	mov	bp,sp			; set up for stack addressing
	push	es			; save es segment register
	push	ds			; save ds segment register
	pushf				; save flags
	push	cs
	pop	ds			; ds = cs
	cld				; set flag for autoincrement mode
	mov	dx,03d8h		; dx = addr of video mode register
					;      (03d8 hex)
	xor	al,al			; reset video
	out	dx,al
	mov	dx,03d4h		; dx = addr of video control register
					;      (03d4 hex)
	cmp	(byte ptr .4)[bp],0	; initialize graphics or alpha
	je	diibm6			; initialize alpha
	mov	al,01eh			; disable status line
	int	0e5h
	mov	es:(byte ptr .0)[bx],0
	mov	si,offset inigraph      ; si = addr of video initialization
					;      parameters
glo_adj_1	equ	$-2
	xor	bl,bl			; bl = current video register number
	mov	cx,16			; cx = # of registers to initialize
diibm1:
	mov	al,bl			; al = video register to set
	inc	bl
	out	dx,al			; select register
	inc	dx			; dx = addr of video data register
					;      (03d5 hex)
	lodsb				; al = value of video register
	out	dx,al			; initialize  register
	dec	dx			; dx = addr of video control register
	loop	diibm1			; loop if not done
	call	deibm			; erase graphics plane
	add 	dx,4			; dx = addr of mode control register
					;      (03d8 hex)
	mov	al,01eh			; set mode for 640x200 black & white
	out	dx,al
	inc	dx			; dx = addr of color control regiser
					;      (03d9 hex)
	mov	al,03fh			; set bkg color to black
	out	dx,al
	jmp	diibm15
diibm6:
	mov	al,01eh			; enable status line
	int	0e5h
	mov	es:(byte ptr .0)[bx],0ffh
	mov	si,offset inialpha      ; si = addr of video initialization
					;      parameters
glo_adj_2	equ	$-2
	xor	bl,bl			; bl = current video register number
	mov	cx,16			; cx = # of registers to initialize
diibm10:
	mov	al,bl			; al = video register to set
	inc	bl
	out	dx,al			; select register
	inc	dx			; dx = addr of video data register
					;      (03d5 hex)
	lodsb				; al = value of video register
	out	dx,al			; initialize  register
	dec	dx			; dx = addr of video control register
	loop	diibm10			; loop if not done
	call	eralpha			; clear screen
	add 	dx,4			; dx = addr of mode control register
					;      (03d8 hex)
	mov	al,029h			; set mode for 80x25 color
	out	dx,al
	inc	dx			; dx = addr of color control regiser
					;      (03d9 hex)
	mov	al,030h			; set bkg color to black
	out	dx,al
diibm15:
	popf				; restore flags
	pop	ds			; restore ds
	pop	es			; restore es
	pop	bp			; restore bp
	ret
;
; deibm () - erase graphics planes on IBM PC (set all bits to index 0)
;
deibm:
	push	es			; save es segment register
	pushf				; save flags
	cld				; set direction flag for autoincrement
     	mov	bx,0b800h		; load start address of graphics memory
	mov	es,bx
	mov	cx,8192     		; fill memory in index 0
	xor	di,di
	xor	ax,ax
  rep	stosw
	popf				; restore flags
	pop	es			; restore es segment register
	ret
;
; eralpha () - erase IBM PC for alpha (fill words with spaces in std 
;                                      attributes)
;
eralpha:
	push	es			; save es segment register
	pushf				; save flags
	cld				; set direction flag for autoincrement
     	mov	bx,0b800h		; load start address of graphics memory
	mov	es,bx
	mov	cx,8192     		; number of words in display memory
	xor	di,di
	mov	ax,' '+7*256     	; fill memory with blanks
  rep	stosw
	popf				; restore flags
	pop	es			; restore es segment register
	ret
;
; ddflin (x1, x2, y, pattern, offset, color, writing mode) -
;      fill a portion of a raster line in the given pattern, color, etc
;   x1, x2 - limits of raster line
;   y      - raster line
;   pattern- pattern in which to draw raster line
;   offset - offset of starting position in pattern
;   color  - color of pattern
;   writing mode - mode in which to draw pattern
;
X1_FILL		equ	4[bp]
X2_FILL		equ	6[bp]
Y_FILL		equ	word ptr 8[bp]
PATTERN_FILL	equ	10[bp]
PAT_OFFSET	equ	12[bp]
COLOR_FILL	equ	14[bp]
MODE_FILL	equ	word ptr 16[bp]
;
ddflin:
	push	bp			; save base pointer
	mov	bp,sp			; set up for stack access
	mov	dx,PATTERN_FILL		; get fill pattern
	mov	cl,PAT_OFFSET		; get pattern offset
	rol	dx,cl			; rotate pattern to correct start pos
					; dx = pattern
	mov	cx,X2_FILL
	mov	bx,X1_FILL		; bx = current x-coordinate
	sub	cx,bx
	inc	cx			; cx = # of rasters to cover with pat
ddflin2:
	push	cx			; save count
	push	bx			; save x-coordinate
	push	dx			; save pattern
	push	MODE_FILL		; push writing mode for bitblt
	xor	si,si			; si = background color index - 0
	mov	ah,dh			; get high byte of pattern
	and	ah,080h			; is high order bit on ?
	jz	ddflin4			; no
	mov	si,COLOR_FILL		; yes, si = fill color index
ddflin4:
	push	si			; push color index for bitblt
	push	Y_FILL			; push y-coordinate for bitblt
	push	bx			; push x-coordinate for bitblt
	call	bitblt			; turn on bit in display
	add	sp,8			; remove bitblt parameters from stack
	pop	dx			; dx = pattern
	rol	dx,1			; move next bit of pattern into high
					;    order bit
	pop	bx			; bx = x-coordinate
	inc	bx			; update x-coordinate to next raster
	pop	cx			; cx = loop count
	loop	ddflin2			; loop if not done
;
	pop	bp			; restore bp
	ret
;
; integer function rdpixel (x, y)
;   x - x-coordinate (0-639) of bit
;   y - y-coordinate (0-199) of bit (0,0) is lower left hand corner
;
;   rdpixel - the color index associated with bit
;
XCOORD		equ	4[bp]		; address of x-coordinate in stack 
YCOORD 		equ	6[bp]		; address of y-coordinate in stack
rdpixel:
	push	bp			; save base pointer
	mov	bp,sp			; set up pointer into stack
	push	ds			; save data segment pointer
	mov	ax,199			; y=0 is top of screen so map
	sub	ax,YCOORD		;    input of 199 to 0, etc.
					;    ax = adjusted y coordinate
	xor	dl,dl			; dl = 0
	mov	dh,al			; determine if y is even or odd
	and	dh,1
	shl	dh,1			; create 00 or 20h in high order byte
	shl	dh,1
	shl	dh,1
	shl	dh,1
	shl	dh,1			; dx = offset into bit map for even
					;   or odd rows (0 or 2000h)
	mov	di,dx			; di = partial byte offset
	shr	ax,1			; odd and even rows are separate
					;   in memory.  offset from start
					;   is the same for row 0 & row 1
					;   ax = adjusted row count
	shl	ax,1			; row offset = row count * 80
	shl	ax,1
	shl	ax,1
	shl	ax,1
	add	di,ax			; di = offset + rowcnt * 16
	shl	ax,1
	shl	ax,1
	add	di,ax			; di = offset + row count * 16 
					;      + row count * 64
					; di = updated byte offset
	mov	ax,XCOORD		; get x-coordinate value
	mov	si,ax			; si = x-coordinate
	shr	ax,1			; ax = x-coord / 8
	shr	ax,1
	shr	ax,1
	add	di,ax			; di = updated byte offset
	and	si,07h			; si = x-coord mod 8 = bit number
	mov	dl,cs:masks[si]		; dl = bit mask from lookup table
glo_adj_21	equ	$-2
	xor	ax,ax			; ax = output index (initially 0)
	mov	si,0b800h		; si = base address of bit plane
   	mov	ds,si			; ds = base address of plane
	mov	dh,[di]   		; get byte to be examined
	and	dh,dl			; get appropriate bit
	jz	rdpixel4		; bit is not on
	inc	al			; bit is on (function is returned in
					;   ax)
rdpixel4:
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret	
;
; bitblt (x, y, color index, writing mode)
;   x - x-coordinate (0-639) of bit
;   y - y-coordinate (0-199) of bit (0,0) is lower left hand corner
;   color index - color index associated with bit
;   writing mode - 1 = replace
;                  2 = overstrike
;                  3 = xor
;                  4 = and
;
XPARM		equ	4[bp]		; address of x-coordinate in stack 
YPARM 		equ	6[bp]		; address of y-coordinate in stack
COLORINDEX	equ	byte ptr 8[bp]	; address of color index in stack
WRITEMODE	equ	10[bp]		; address of writing mode in stack
bitblt:
	push	bp			; save base pointer
	mov	bp,sp			; set up pointer into stack
	push	ds			; save data segment pointer
	mov	ax,199			; y=0 is top of screen so map
	sub	ax,YPARM		;    input of 199 to 0, etc.
					;    ax = adjusted y coordinate
	xor	dl,dl			
	mov	dh,al			; determine if y is even or odd
	and	dh,1
	shl	dh,1			; create 00 or 20h in high order byte
	shl	dh,1
	shl	dh,1
	shl	dh,1
	shl	dh,1			; dx = offset into bit map for even
					;   or odd rows (0 or 2000h)
	mov	di,dx			; di = partial byte offset
	shr	ax,1			; odd and even rows are separate
					;   in memory.  offset from start
					;   is the same for row 0 & row 1
					;   ax = adjusted row count
	shl	ax,1			; row offset = row count * 80
	shl	ax,1
	shl	ax,1
	shl	ax,1
	add	di,ax			; di = offset + rowcnt * 16
	shl	ax,1
	shl	ax,1
	add	di,ax			; di = offset + row count * 16 
					;      + row count * 64
					; dx = updated byte offset
	mov	ax,XPARM		; get x-coordinate value
	mov	si,ax			; si = x-coordinate
	shr	ax,1			; ax = x-coord / 8
	shr	ax,1
	shr	ax,1
	add	di,ax			; di = updated byte offset
	and	si,07h			; si = x-coord mod 8 = bit number
	mov	dl,cs:masks[si]		; dl = bit mask from lookup table
glo_adj_22	equ	$-2
	mov	dh,COLORINDEX		; dh = color index
	neg	dh			; dh = 0 if color index is 0
					;      ff if color index is 1
	mov	si,WRITEMODE    	; get writing mode
					; call appropriate bit routine
	dec	si			; si = index into routine call table
					;      0 - 3
	shl	si,1
	mov	ax,0b800h		; ds = base of bit plane for bit rtns
	mov	ds,ax
	jmp 	cs:(word ptr routines)[si] ; call routine based on writing mode
glo_adj_11	equ	$-2
	pop	ds			; restore ds
	pop	bp			; restore bp
;
; setbit (byte offset in plane, bit mask, color index) - set color index of
;        bit in bitmap
;	 Input
;         ds = base of bit plane
;         di = byte offset in plane (2 bytes)
;         dl = bit mask (1 byte)
;         dh = color index mask (1 byte) 0 if index 0, else 0xff
;
setbit:
	mov	al,dl			; al = complement of bit mask
	not	al
	and	al,byte ptr [di]	; al = byte to be modified with bit clr
	and	dl,dh			; dl = 0 if index 0 else mask
	or	al,dl			; set bit in byte
	mov	[di],al			; put byte back in memory
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret	
;
; orbit (byte offset in plane, bit mask, color index) - or color index with 
;       current color index of bit in bitmap
;	Input
;         ds = base of bit plane
;         di = byte offset in plane (2 bytes)
;         dl = bit mask (1 byte)
;         dh = color index mask (1 byte) 0 if index 0, else 0xff
;
orbit:
	and	dl,dh			; dl = 0 if index 0 else mask
	or	byte ptr [di],dl	; or bit in byte with mask
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret	
;
; xorbit (byte offset in plane, bit mask, color index) - xor color index with
;        current color index of bit in bitmap
;	 Input
;         ds = base of bit plane
;         di = byte offset in plane (2 bytes)
;         dl = bit mask (1 byte)
;         dh = color index mask (1 byte) 0 if index 0, else 0xff
;
xorbit:
	and	dl,dh			; dl = 0 if index 0 else mask
	xor	byte ptr [di],dl	; xor bit in byte with mask
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret	

;
; erabit (byte offset in plane, bit mask, color index) - erase color index
;        of bit in bitmap
;	 Input
;         ds = base of bit plane
;         di = byte offset in plane (2 bytes)
;         dl = bit mask (1 byte)
;         dh = color index mask (1 byte) 0 if index 0, else 0xff
;
erabit:
	and	dl,dh			; dl = 0 if index 0 else mask
 	not	dl			; dl = complement mask to clear bit	
	and	byte ptr [di],dl	; erase bit in byte
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret	

	eseg
	dw	bitblt                  ; global defines for Computer Innov C
	db	DEFCGBL,'bitblt',0
	dw	setbit
	db	DEFCGBL,'setbit',0
	dw	orbit
	db	DEFCGBL,'orbit',0
	dw	xorbit
	db	DEFCGBL,'xorbit',0
	dw	erabit
	db	DEFCGBL,'erabit',0
	dw	rdpixel
	db	DEFCGBL,'rdpixel',0
	dw	ddflin
	db	DEFCGBL,'ddflin',0
	dw	deibm
	db	DEFCGBL,'deibm',0
	dw	diibm
	db	DEFCGBL,'diibm',0
	dw	eralpha
	db	DEFCGBL,'eralpha',0
	dw	dlocal
	db	DEFCGBL,'_dlocal',0
	dw	glo_adj_1
	db	ABSCGBL,'_dlocal',0
	dw	glo_adj_2
	db	ABSCGBL,'_dlocal',0

	dw	glo_adj_11
	db	ABSCGBL,'_dlocal',0
	dw	glo_adj_12
	db	ABSCGBL,'setbit',0
	dw	glo_adj_13
	db	ABSCGBL,'orbit',0
	dw	glo_adj_14
	db	ABSCGBL,'xorbit',0
	dw	glo_adj_15
	db	ABSCGBL,'erabit',0

	dw	glo_adj_21
	db	ABSCGBL,'_dlocal',0
	dw	glo_adj_22
	db	ABSCGBL,'_dlocal',0

	dw	0,0
	end

E 1
