6502 Pen plotter - Calling draw By Lee Davison. |
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 ..
Variable Size Use Lcntl Word Number of steps for this line Dirbyte Byte Bits 1 and 3 control X and Y direction Stepbyte Byte Bits 0 and 2 control X and Y stepping Penflag Byte Bit 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 3 2 1 0 x 0 x 0 No movement, no use, not used. x 0 0 1 Along the X axis, left. x 0 1 1 Along the X axis, right. 0 1 x 0 Along the Y axis, down. 0 1 0 1 Along the XY diagonal, down and left. 0 1 1 1 Along the XY diagonal, down and right. 1 1 x 0 Along the Y axis, up. 1 1 0 1 Along the XY diagonal, up and left. 1 1 1 1 Along 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 spaceOnce 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 byteFinally 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 |