A86: box routine


[Prev][Next][Index][Thread]

A86: box routine




i don't know if anybody will ever have a use for this, but this is a box
drawing routine that i wrote (for a game i made).  it draws a box of width 1-8
and variable height anywhere on the screen.


DrawBox:
	;by Jonah Cohen <ComAsYuAre@aol.com>
	;input:
	;	define columns as two bytes
	;	d=y coordinate
	;	e=x coordinate
	;	h=width,  8 max
	;	l=height
	;output:
	;	draws xor-ed box at (e,d), h pixels wide and l pixels down

	push hl

;modified findpixel by Dan Eble and James Yopp
	ld a,e
	and $07			; a = bit offset
	cpl
	add a,10			; a = 8-a
	ld c,a			; c = bitmask
	ld hl,FP_RLD
	ld (hl),d
	ld a,e			; a = x/8 (byte offset within row)
	rrca
	rrca
	rrca
	rld
	or $FC
	ld e,(hl)
	ld d,a
;c=mask
;de=video mem offset


	pop hl
	push de			;save video mem
	ld b,h			;get width
	xor a
mask_loop:
	.db $cb,$37		;sl1 a
	djnz mask_loop

	ld b,c
	ld c,a			;c=new mask
	push bc
	ld a,b
	add a,7
	sub h			;a=number of left shifts
	pop bc			;retrieve mask
	ld b,a

	ld e,0
shift:
	sla c				;all overlapping bits from this
	rl e				;get moved into this
	djnz shift

	ld a,e
	ld (columns),a
	ld a,c
	ld (columns+1),a

	ld a,l				;a=height
	ld b,a
	ld a,c
	pop hl			;retrieve video mem
	ld de,15
draw_lines:
	ld a,(columns)
	xor (hl)			;xor with video mem.  can be changed to or if necessary
	ld (hl),a
	inc hl
	ld a,(columns+1)
	xor (hl)			;change this to or as well if you want
	ld (hl),a
	add hl,de
	djnz draw_lines
	ret