6502 Pen plotter - Calling draw By Lee Davison.

Calling draw.

The most basic command that the plotter has is the drawm (WriteSeg) command. This command allows the movement of the mechanism in one of eight directions, with the pen up or down, for up to 65535 steps. It is from these straight lines that all other lines and curves are constructed.

Before draw is called there are four variables that need to be set up ..

VariableSizeUse
LcntlWordNumber of steps for this line
DirbyteByteBits 1 and 3 control X and Y direction
StepbyteByteBits 0 and 2 control X and Y stepping
PenflagByteBit 7 controls the pen state

The combination of direction bits and step bits gives the eight directions that the plotter can move when combined.

Bits Direction
32 10
x0x 0No movement, no use, not used.
x00 1Along the X axis, left.
x01 1Along the X axis, right.
01x 0Along the Y axis, down.
010 1Along the XY diagonal, down and left.
011 1Along the XY diagonal, down and right.
11x 0Along the Y axis, up.
110 1Along the XY diagonal, up and left.
111 1Along the XY diagonal, up and right.
x = don't care.

Once these variables are set-up a call to the draw routine does the following.

First the buffer is checked to see if there is room for the command plus 1 byte. The additional byte is to ensure that the buffer doesn't overflow without the need for an extra flag byte and more code. If there is no room then the routine loops until room is available.

WriteSeg
	LDA	BRindx		; get read index
	SEC			; set carry for subtract
	SBC	BWindx		; subtract write index
	BEQ	Dowrite		; if equal then buffer empty so do write

	CMP	#$05		; need at least 5 bytes
	BCC	WriteSeg	; loop if no space

Once there is room the draw command bytes are constructed from the step, direction and pen bytes and saved to the buffer.

				; construct and write data to buffer
Dowrite
	LDY	BWindx		; get write index

	LDA	Lcntl		; get count low byte
	STA	LBuffer,Y	; save it
	INY			; increment index to count high byte

	LDA	Lcnth		; get count high byte
	STA	LBuffer,Y	; save it
	INY			; increment index to negative latch byte

	LDA	#$20		; set mode byte (half step)
	ORA	Penflag		; OR pen down flag
	ORA	Dirbyte		; OR direction byte
	STA	LBuffer,Y	; save it
	INY			; increment index to positive latch byte

	ORA	Stepbyte	; OR step byte
	STA	LBuffer,Y	; save it
	INY			; increment index to next entry

	STY	BWindx		; save new write index byte

Finally all that remains is to check if drawing is already in progress. If the routine is called by a software interrupt (BRK).

	LDA	Drawf		; get draw flag
	BNE	Doingit		; skip call if running

	BRK			; software call to interrupt routine
	NOP			; need this as return is +1 byte!
	CLI			; enable the interrupts
Doingit
	RTS			;


Last page update: 2nd May, 2002. e-mail me