[net.micro.apple] Graphics routines for Aztec C

richard@islenet.UUCP (Richard Foulk) (12/14/84)

Several people have asked for graphics routines for use with the Aztec C
compiler on the Apple 2.  I promised to send these to someone a while
back but I seem to have lost their address.

Anyway, here they are.  I haven't used this stuff in quite some time so
my recollection of it is a bit vague but I'm pretty sure everything works.
At least on an Apple 2e with Aztec C version 1.05B (probably not the current
version).  These routines should have been put into separate files and built
into a library, I just never got around to it.  The formatting of the code
probably looks a bit strange since the Aztec editor has tab stops every
four columns instead of every eight.

If you can't figure out what each routine does just check your Applesoft
manual, most of the names are the same.

My having created and posted these routines should in no way be construed
as an endorsement of Apple computers or as a statement that Apple computers
are suitable for any purpose whatsoever.

These routines are Copyleft 1984 by Me.  Enjoy.


Richard Foulk
-------------------------------cut here--------------------------------------
		public	hgr_		hgr(page);
		public	text_		text();
		public	rot_		rot(rotation);
		public	scale_		scale(scale_factor);
		public	xdraw_		xdraw(shape_no, x, y);
		public	draw_		draw(shape_no, x, y);
		public	hcolor_		hcolor(color);
		public	pdl_		pdl(paddle_no);
		public	plotline	plotline(x, y, x2, y2);
		public	plot_		plot(x, y);		plot a point
		public	plotto_		plotto(x, y);	plot a line from the current loc
		public	clear_		clear();		clear hires screen
		public	peek_		peek(ad);
		public	poke_		poke(ad, byte);

sp		equ		2
r0		equ		8
flag	equ		0
temp	equ		0

shapel	equ		$1a
shapeh	equ		$1b
shapepnt equ	$e8			pointer to shape table
rotz	equ		$f9			shape rotation value is stored here
scalez	equ		$e7

hgr		equ		$f3e2
hgr2	equ		$f3d8
rombyte equ		$e000		this location holds a $4c if roms are enabled
selram	equ		$c080		select ram card
selrom	equ		$c081		select roms

hgr_	jsr		romcheck	check if rom selected and select if not
		ldy		#0
		lda		(sp),y
		and		#1
		beq		two
		jsr		hgr
		jmp		done
two		jsr		hgr2

done	lda		flag		master exit, reselects ram-card if necessary
		bne		rts1
		sta		selram		re-select ram card
rts1	rts

text_	lda		$c051		turn on text mode
		lda		$c052		nomix
		lda		$c054		primary page
		rts

pdl_	ldy		#0
		lda		(sp),y
		tax
		jsr		$fb1e		go read paddle(x)
		sty		r0			val returned in y
		lda		#0
		sta		r0+1
		rts

rot_	ldy		#0
		lda		(sp),y
		sta		rotz
		rts

scale_	ldy		#0
		lda		(sp),y
		sta		scalez
		rts

hcolor_	jsr		romcheck
		ldy		#0
		lda		(sp),y
		tax
		jsr		$f6f0
		jmp		done

plotline					*	plotline(x1, y1, x2, y2);
		jsr		romcheck
		jsr		plt			plot a dot at x1 y1
		jsr		pltto
		jmp		done

plotto_
		jsr		romcheck
		ldy		#0
		jsr		pltto2
		jmp		done

pltto	ldy		#4
pltto2	lda		(sp),y
		pha					x2 low
		iny
		lda		(sp),y
		tax					x2 high
		iny
		lda		(sp),y
		tay					y2
		pla
		jsr		$f53a		plot from current loc to x2 y2
		rts

plot_	jsr		romcheck	plot(x, y);
		jsr		plt
		jmp		done

plt		ldy		#0
		lda		(sp),y
		tax					x1 low
		iny
		lda		(sp),y
		sta		flag		x1 high, save temporarily
		iny
		lda		(sp),y		y1
		ldy		flag
		jsr		$f457		plot a point
		rts
		
romcheck
		lda		rombyte		check if basic is "up" (ROMs)
		sta		flag		init flag as no toggle necessary to call roms
		cmp		#$4c
		beq		ret
		lda		#0
		sta		selrom		turn on roms
		sta		flag		and set flag
ret		rts

xdraw_	jsr		romcheck
		jsr		drsetup
		jsr		$f661		xdraw routine
		jmp		done

draw_	jsr		romcheck
		jsr		drsetup
		jsr		$f605		draw routine
		jmp		done

drsetup	ldy		#0
		lda		(sp),y		get shape number
		tax
		jsr		setshp
		ldy		#4
		lda		(sp),y		Y location
		sta		$e2
		dey
		lda		(sp),y		X high
		sta		$e1
		dey
		lda		(sp),y		X low
		sta		$e0
		tax					setup registers for call
		ldy		$e1
		lda		$e2
		jsr		$f417		set position
		lda		rotz
		rts

setshp	lda		shapepnt
		sta		shapel
		lda		shapepnt+1
		sta		shapeh
		txa
dp1		asl		a
		bcc		dp2
		inc		shapeh
		clc
dp2		tay
		lda		(shapel),y
		adc		shapel
		tax
		iny
		lda		(shapel),y
		adc		shapepnt+1
		sta		shapeh
		stx		shapel
		rts

clear_	lda		#$20
		sta		temp+1
		lda		#0
		sta		temp
		tay
		ldx		#$20
cloop	sta		(temp),y
		iny
		bne		cloop
		inc		temp+1
		dex
		bne		cloop
		rts

peek_	ldy		#1
		lda		(sp),y
		sta		temp+1
		dey
		lda		(sp),y
		sta		temp
		lda		(temp),y
		sta		r0
		lda		#0
		sta		r0+1
		rts

poke_	ldy		#0
		lda		(sp),y
		sta		temp
		iny
		lda		(sp),y
		sta		temp+1
		iny
		lda		(sp),y
		ldy		#0
		sta		(temp),y
		rts

		end

-- 
Richard Foulk		...{dual,vortex,ihnp4}!islenet!richard
Honolulu, Hawaii