Learning Assembly Language on the TRS-80/Tandy Color Computer - Programs #9 & #10

 

 Introduction

It's finally time for some graphics animation with programs 9 and 10 from the Inman book:

Assembly Language Graphics for the TRS-80 Color Computer - by Don Inman and Kurt Inman with Dymax

Program #9 - Draw Cylinder and Piston, Erase Piston

Program #9 draws a cylinder on the screen in graphics mode 1R, using colour set 0.  It then draws a piston in the cylinder and proceeds to erase it, then draw it - until you press the X key to exit.  It serves as a stepping stone to Program #10, which is why I grouped them together in this blog post.

I found once I had Program #9 working, I wanted to tackle Program #10 right away!  Hopefully you'll feel that way too.

Here's the listing for Program #9:

;********************************************
;* Assembly Language Graphics for the TRS-80 Color Computer *
;* by Don and Kurt Inman, 1983 *
;* Program 9 - Draw cylinder & piston . *
;* 6809 assembly language for Tandy CoCo *
;* David Kroeker, 13-Dec-2025 *
;* Draw a cylinder and a piston in graphics *
;* mode 1R using colour set 0. *
;********************************************

ORG $1E00
; PART 1--SETUP
; SET GRAPHICS MODE to 1R (128x64, 2 colours), COLOUR SET 0 (black/green)
Start LDA #$90 ; Select mode 1R (128x64, 2 colour graphics mode), colour set 0
STA $FF22 ; Set graphics mode
STA $FFC1 ; Set V0
; PART 2--CLEAR GRAPHICS SCREEN
CLRA
CLRB
LDX #$400 ; Start of graphics screen memory
Loop1 STD ,X++ ; Clear graphics screen memory
CMPX #$0800 ; Have we cleared the entire screen?
BLO Loop1 ; If not, keep clearing
; PART 3--DRAW CYLINDER
LDX #$5C7 ; Address of starting position on screen for cylinder
LDY #Table1 ; Point to cylinder data table
Down LDB #3
Right LDA ,Y+ ; Get byte from data table
STA ,X+ ; Plot byte on screen
DECB
BNE Right ; Repeat for 4 bytes across
LEAX $D,X ; Move to next line on screen
CMPX #$647 ; Have we drawn all 20 lines of cylinder?
BNE Down ; If not, keep drawing down

; PART 4--DRAW PISTON
Draw LDY #Table2 ; Point to piston data table
LDX #$598 ; Address of starting position on screen for piston
LDB #5
Pist LDA ,Y+ ; Get byte from data table
STA ,X+ ; Plot byte on screen
LEAX $F,X ; Move to next line on screen
DECB
BNE Pist ; Repeat for 6 bytes across
JSR Delay ; Wait

; PART 5--ERASE PISTON
CLRA
LDX #$598 ; Address of starting position on screen for piston
LDB #5
Erase STA ,X+ ; Clear byte on screen
LEAX $F,X ; Move to next line on screen (note mistake in book on this line)
DECB
BNE Erase ; Repeat for 6 bytes across
JSR Delay ; Wait

; PART 6--TEST FOR X KEY
LDA #$FE ; Load keyboard port
STA $FF02 ; Strobe keyboard port
LDA $FF00 ; Read keyboard data
CMPA #$F7 ; Is X key pressed?
BNE Draw ; If not, draw again

; PART 7--GO TO TEXT AND MONITOR
Text LDA #$60 ; Select text mode
LDX #$400 ; Start of screen memory
Loop2 STA ,X+ ; Clear screen memory
CMPX #$600 ; Have we cleared the entire screen?
BLO Loop2 ; If not, keep clearing
CLRA
STA $FF22 ; Set graphics mode to text
STA $FFC0 ; Turn off all VDGs
RTS ; Return from main program

; PART 8--DELAY SUBROUTINE
Delay LDX #$F000 ; Set up length of delay
Count NOP ; Do nothing (waste time: 2 CPU cycles)
NOP ; Do nothing (waste time: 2 CPU cycles)
NOP ; Do nothing (waste time: 2 CPU cycles)
LEAX -1,X ; Decrement X (or DEX if starting lwasm with -0 or --6800)
BNE Count ; Loop until X = 0
RTS ; Return from subroutine
; PART 9--DATA TABLES
Table1 FCB 1,0,$80 ; Cylinder pattern (7 rows of walls, 1 row of bottom)
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,$FF,$80 ; Bottom row of cylinder
Table2 FCB $18,$18,$18,$18,$FF ; Piston pattern

END Start

Program #10 - Animate Piston

It's finally time to move some graphics!  OK, it's just a piston pumping up and down in a cylinder, but you know this is an essential building block to moving your own graphics designs around on the screen.  It starts here!

;********************************************
;* Assembly Language Graphics for the TRS-80 Color Computer *
;* by Don and Kurt Inman, 1983 *
;* Program 10 - Moving the Piston. *
;* 6809 assembly language for Tandy CoCo *
;* David Kroeker, 14-Dec-2025 *
;* Draw a cylinder and a piston in graphics *
;* mode 1R using colour set 0. *
;* Move the piston up and down. *
;********************************************

ORG $1E00
; PART 1--SETUP
; SET GRAPHICS MODE to 1R (128x64, 2 colours), COLOUR SET 0 (black/green)
Start LDA #$90 ; Select mode 1R (128x64, 2 colour graphics mode), colour set 0
STA $FF22 ; Set graphics mode
STA $FFC1 ; Set V0
; PART 2--CLEAR GRAPHICS SCREEN
CLRA
CLRB
LDX #$400 ; Start of graphics screen memory
Loop1 STD ,X++ ; Clear graphics screen memory
CMPX #$0800 ; Have we cleared the entire screen?
BLO Loop1 ; If not, keep clearing
; PART 3--DRAW CYLINDER
LDX #$5C7 ; Address of starting position on screen for cylinder
LDY #Table1 ; Point to cylinder data table
Down LDB #3
Right LDA ,Y+ ; Get byte from data table
STA ,X+ ; Plot byte on screen
DECB
BNE Right ; Repeat for 4 bytes across
LEAX $D,X ; Move to next line on screen
CMPX #$647 ; Have we drawn all 20 lines of cylinder?
BNE Down ; If not, keep drawing down

; PART 4 & 5--DRAW AND ERASE PISTON
Draw LDX #$598 ; Address of starting position on screen for piston
JSR On ; Draw the piston
LDX #$598 ; Address of starting position on screen for piston
JSR Off ; Erase the piston
LDX #$5B8 ; Address of starting position on screen for piston
JSR On ; Draw the piston
LDX #$5B8 ; Address of starting position on screen for piston
JSR Off ; Erase the piston
LDX #$5D8 ; Address of starting position on screen for piston
JSR On ; Draw the piston
LDX #$5D8 ; Address of starting position on screen for piston
JSR Off ; Erase the piston
LDX #$5B8 ; Address of starting position on screen for piston
JSR On ; Draw the piston
LDX #$5B8 ; Address of starting position on screen for piston
JSR Off ; Erase the piston

; PART 6--TEST FOR X KEY
LDA #$FE ; Load keyboard port
STA $FF02 ; Strobe keyboard port
LDA $FF00 ; Read keyboard data
CMPA #$F7 ; Is X key pressed?
BNE Draw ; If not, draw again

; PART 7--GO TO TEXT AND MONITOR
Text LDA #$60 ; Select text mode
LDX #$400 ; Start of screen memory
Loop2 STA ,X+ ; Clear screen memory
CMPX #$600 ; Have we cleared the entire screen?
BLO Loop2 ; If not, keep clearing
CLRA
STA $FF22 ; Set graphics mode to text
STA $FFC0 ; Turn off all VDGs
RTS ; Return from main program

; PART 8--DELAY SUBROUTINE
Delay LDX #$4000 ; Set up length of delay
Count NOP ; Do nothing (waste time: 2 CPU cycles)
NOP ; Do nothing (waste time: 2 CPU cycles)
NOP ; Do nothing (waste time: 2 CPU cycles)
LEAX -1,X ; Decrement X (or DEX if starting lwasm with -0 or --6800)
BNE Count ; Loop until X = 0
RTS ; Return from subroutine

; PART 8A--DRAW THE PISTON
On LDY #Table2 ; Point to piston data table
LDB #5
Pist LDA ,Y+ ; Get byte from data table
STA ,X+ ; Plot byte on screen
LEAX $F,X ; Move to next line on screen
DECB
BNE Pist ; Repeat for 6 bytes across
JSR Delay ; Wait
RTS ; Return from subroutine

;PART 8B--ERASE THE PISTON
Off CLRA ; Load A with 0 to erase
LDB #5
Erase STA ,X+ ; Plot 0 byte on screen
LEAX $F,X ; Move to next line on screen
DECB
BNE Erase ; Repeat for 6 bytes across
RTS ; Return from subroutine

; PART 9--DATA TABLES
Table1 FCB 1,0,$80 ; Cylinder pattern (7 rows of walls, 1 row of bottom)
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,0,$80
FCB 1,$FF,$80 ; Bottom row of cylinder
Table2 FCB $18,$18,$18,$18,$FF ; Piston pattern

END Start

Here's a video showing Program #10 in action:

I hope you'll try adapting this program to move one of your own designs!
David
26-Dec-2025

Comments