h12699
s 00588/00000/00000
d D 1.1 83/03/18 19:50:28 bog 1 0
c date and time created 83/03/18 19:50:28 by bog
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
EXTEND_PORT	equ	03ddh		; extended graphics mode port addr
	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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
glo_adj_12	equ	$-32
glo_adj_13	equ	$-30
glo_adj_14	equ	$-28
glo_adj_15	equ	$-26
glo_adj_16	equ	$-24
glo_adj_17	equ	$-22
glo_adj_18	equ	$-20
glo_adj_19	equ	$-18
glo_adj_20	equ	$-16
glo_adj_21	equ	$-14
glo_adj_22	equ	$-12
glo_adj_23	equ	$-10
glo_adj_24	equ	$-8
glo_adj_25	equ	$-6
glo_adj_26	equ	$-4
glo_adj_27	equ	$-2
;
; diplus (mode) - initialize ibm pc with Colorplus board for graphics or alpha
;       mode - 0 = alpha, 1 = graphics
;
; **** This version is for the Digital Research version of CP/M 86   ****
; **** for the IBM PC, not the CP/M 86 sold by IBM.                  ****
;
diplus:
	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	diplus6			; initialize alpha
	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
diplus1:
	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	diplus1			; loop if not done
	add 	dx,4			; dx = addr of mode control register
					;      (03d8 hex)
	mov	al,01eh			; set mode for 640x200 black & white
	out	dx,al
	call	deplus			; erase graphics plane
	mov	dx,03d9h		; dx = addr of color control regiser
					;      (03d9 hex)
	mov	al,0h			; set bkg color to black-red,green,
					;   and yellow as foreground
	out	dx,al
	jmp	diplus15
diplus6:
	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
diplus10:
	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	diplus10		; 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
diplus15:
	popf				; restore flags
	pop	ds			; restore ds
	pop	es			; restore es
	pop	bp			; restore bp
	ret
;
; deplus () - erase graphics planes on IBM PC with Colorplus board 
;             (set all bits to index 0 on both planes)
;
deplus:
	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	al,020h			; select extended plane 0
	mov	dx,EXTEND_PORT
	out	dx,al
	mov	es,bx
	mov	cx,8192     		; fill memory in index 0
	xor	di,di
	xor	ax,ax
  rep	stosw
	mov	al,060h			; select extended plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	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 (0 - 3)
;
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	bl,cs:masks[si]		; bl = bit mask from lookup table
glo_adj_41	equ	$-2
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	xor	ah,ah			; ah = output index (initially 0)
	mov	si,0b800h		; si = base address of bit plane
	mov	cx,2			; cx = number of planes (loop count)
   	mov	ds,si			; ds = base address of plane
rdpixel2:
	shl	ah,1			; make room for next bit of color index
	mov	bh,[di]   		; get byte to be examined
	and	bh,bl			; get appropriate bit
	jz	rdpixel4		; bit is not on
	inc	ah			; bit is on - update result
rdpixel4:
	mov	al,020h			; select plane 0
	out	dx,al
	loop	rdpixel2		; branch if not done
	mov	al,ah			; return function in ax
	xor	ah,ah
	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 (0 - 3)
;   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	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	bl,cs:masks[si]		; bl = bit mask from lookup table
glo_adj_42	equ	$-2
	mov	bh,bl			; bh = complement of bit mask
	not	bh
	mov	si,WRITEMODE    	; get writing mode
					; call appropriate bit routine
	dec	si			; si = index into routine call table
					;      0 - 3
	shl	si,1			; * 2
	shl	si,1			; * 4
	add	si,COLORINDEX		; si = mode*4 + index
	shl	si,1			;      as word index
	mov	al,020h			; select plane 0
	mov	dx,EXTEND_PORT
	out	dx,al
	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
;
; 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)
;         bl = bit mask (1 byte)
;         bh = complement of bit mask (1 byte)
;
;         Upon entry output is directed to bit plane 0
;
set_0:
	and	byte ptr [di],bh        ; turn off plane 0 bit
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	and 	byte ptr [di],bh	; turn off plane 1 bit
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret	

set_1:
	or	byte ptr [di],bl	; turn on plane 0 bit
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	and	byte ptr [di],bh	; turn off plane 1 bit
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret
 
set_2:
	and	byte ptr [di],bh	; turn off plane 0 bit
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	or	byte ptr [di],bl	; turn on plane 1 bit
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret
 
set_3:
	or	byte ptr [di],bl	; turn on plane 0 bit
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	or	byte ptr [di],bl	; turn on plane 1 bit
	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)
;         bl = bit mask (1 byte)
;         bh = complement of bit mask (1 byte)
;
;         Upon entry output is directed to bit plane 0
;
or_1:
	or	byte ptr [di],bl	; turn on plane 0 bit
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret
 
or_3:	or	byte ptr [di],bl	; turn on plane 0 bit
 
or_2:
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	or	byte ptr [di],bl	; turn on plane 1 bit
 
or_0:
	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)
;         bl = bit mask (1 byte)
;         bh = complement of bit mask (1 byte)
;
;         Upon entry output is directed to bit plane 0
;
xor_1:	xor	byte ptr [di],bl	; toggle plane 0 bit
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret
 
xor_3:	xor	byte ptr [di],bl	; toggle plane 0 bit
 
xor_2:
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	xor	byte ptr [di],bl	; toggle plane 1 bit
 
xor_0:
	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)
;         bl = bit mask (1 byte)
;         bh = complement of bit mask (1 byte)
;
;         Upon entry output is directed to bit plane 0
;
erase_1:
	and	byte ptr [di],bh	; turn off plane 0 bit
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret
 
erase_3:
	and	byte ptr [di],bh	; turn off plane 0 bit
 
erase_2:
	mov	al,060h			; select plane 1
	mov	dx,EXTEND_PORT
	out	dx,al
	and	byte ptr [di],bh	; turn off plane 1 bit
 
erase_0:
	pop	ds			; restore ds
	pop	bp			; restore bp
	ret

	eseg
	dw	bitblt                  ; global defines for Computer Innov C
	db	DEFCGBL,'bitblt',0
	dw	set_0
	db	DEFCGBL,'set_0',0
	dw	set_1
	db	DEFCGBL,'set_1',0
	dw	set_2
	db	DEFCGBL,'set_2',0
	dw	set_3
	db	DEFCGBL,'set_3',0
	dw	or_0
	db	DEFCGBL,'or_0',0
	dw	or_1
	db	DEFCGBL,'or_1',0
	dw	or_2
	db	DEFCGBL,'or_2',0
	dw	or_3
	db	DEFCGBL,'or_3',0
	dw	xor_0
	db	DEFCGBL,'xor_0',0
	dw	xor_1
	db	DEFCGBL,'xor_1',0
	dw	xor_2
	db	DEFCGBL,'xor_2',0
	dw	xor_3
	db	DEFCGBL,'xor_3',0
	dw	erase_0
	db	DEFCGBL,'erase_0',0
	dw	erase_1
	db	DEFCGBL,'erase_1',0
	dw	erase_2
	db	DEFCGBL,'erase_2',0
	dw	erase_3
	db	DEFCGBL,'erase_3',0
	dw	rdpixel
	db	DEFCGBL,'rdpixel',0
	dw	deplus
	db	DEFCGBL,'deplus',0
	dw	diplus
	db	DEFCGBL,'diplus',0
	dw	eralpha
	db	DEFCGBL,'eralpha',0
	dw	ddflin
	db	DEFCGBL,'ddflin',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,'set_0',0
	dw	glo_adj_13
	db	ABSCGBL,'set_1',0
	dw	glo_adj_14
	db	ABSCGBL,'set_2',0
	dw	glo_adj_15
	db	ABSCGBL,'set_3',0
	dw	glo_adj_16
	db	ABSCGBL,'or_0',0
	dw	glo_adj_17
	db	ABSCGBL,'or_1',0
	dw	glo_adj_18
	db	ABSCGBL,'or_2',0
	dw	glo_adj_19
	db	ABSCGBL,'or_3',0
	dw	glo_adj_20
	db	ABSCGBL,'xor_0',0
	dw	glo_adj_21
	db	ABSCGBL,'xor_1',0
	dw	glo_adj_22
	db	ABSCGBL,'xor_2',0
	dw	glo_adj_23
	db	ABSCGBL,'xor_3',0
	dw	glo_adj_24
	db	ABSCGBL,'erase_0',0
	dw	glo_adj_25
	db	ABSCGBL,'erase_1',0
	dw	glo_adj_26
	db	ABSCGBL,'erase_2',0
	dw	glo_adj_27
	db	ABSCGBL,'erase_3',0

	dw	glo_adj_41
	db	ABSCGBL,'_dlocal',0
	dw	glo_adj_42
	db	ABSCGBL,'_dlocal',0

	dw	0,0
	end

E 1
