[Return to top]

6502 Pen plotter - Calling draw by Lee Davison
[Back]


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.

BitsDirection
3210
x0x0No movement, no use, not used.
x001Along the X axis, left.
x011Along the X axis, right.
01x0Along the Y axis, down.
0101Along the XY diagonal, down and left.
0111Along the XY diagonal, down and right.
11x0Along the Y axis, up.
1101Along the XY diagonal, up and left.
1111Along 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			;

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