Learning Assembly Language on the TRS-80/Tandy Color Computer - Programs 2 & 3

Introduction

Since my first blog post I've continued to work my way through this book, program by program:

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

My Most Common Mistakes

After finally getting program #1 to work, getting the next two programs working was much, much easier, as I could apply the same principles to those.  I just found I needed to be really careful as I typed in the listings to not make mistakes such as:

  • Missing the # symbol needed by an immediate address mode argument.  I made this mistake a couple of times.
  • Misinterpreting where a branch is supposed to jump to.  Not all of the programs come with a nice flow chart illustrating this.  EDIT: I later found there are tables of forward and backward branch values in Appendices F and G of this book.  Those would have been handy for figuring these out! 

Programs 2 & 3

I'll include the assembly listings for programs 2 and 3 here.  Both of these still deal with sound, like program 1.
In program 2, you can experiment with changing the values for duration and tone and hear what happens.
For program 3, the book encourages you to experiment with different values in the notes table.  You could adjust the notes table to play a tune instead of just a scale and change how many notes are in it.  But, there isn't a way in that program to alter the duration of individual notes.

DEX or LEAX -1,X? 

You'll notice that I've replaced the command DEX in both listings below with LEAX -1,X
Both commands will decrement the X register by 1.
But, the lwasm assembler did not recognize the DEX mnemonic.  So, I altered the original program listing from the book to get it to assemble.
I later learned that the lwasm assembler actually can be made to recognize DEX if you start it with a -0 or --6800 switch.  These switches enable support in lwasm for the older Motorola 6800 instruction set, as DEX is a classic 6800 instruction.

Program 2 Listing

;********************************************
;* Assembly Language Graphics for the TRS-80 Color Computer *
;* by Don and Kurt Inman, 1983 *
;* Program 2 - sound *
;* 6809 assembly language for Tandy CoCo *
;* David Kroeker, 22-Nov-2025 *
;* Making your own sounds *
;********************************************

ORG $700

Start LDA #$3F ; Load sound byte ($3F) into register A
STA $FF23 ; Turn on sound
LDX #$0FFF ; Load duration
Duratn LDB #$2F ; Load tone byte into register B
Tone STB $FF20 ; Set tone
NOP ; Time delay
NOP ; Time delay
NOP ; Time delay
INCB ; Increment tone
BNE Tone ; Branch if B not zero
LEAX -1,X ; Decrement duration (or DEX if starting lwasm with -0 or --6800)
BNE Duratn ; Branch if X not zero
RTS
End Start

Program 3 Listing

;********************************************
;* Assembly Language Graphics for the TRS-80 Color Computer *
;* by Don and Kurt Inman, 1983 *
;* Program 3 - sound table *
;* 6809 assembly language for Tandy CoCo *
;* David Kroeker, 22-Nov-2025 *
;* Play a scale using a memory sound table *
;********************************************


ORG $0E00
Start LDA #$3F ; Load sound byte ($3F) into register A
STA $FF23 ; Turn on sound
LEAY NotesTable,PCR ; Load address of notes table into Y
LdNote LDX #$080 ; Load duration into X
LDB ,Y+ ; Load next note from table into B
CMPB #$00 ; Check for end of table
BEQ End ; If end, finish program
TFR B,A ; Transfer note to register A
Tone STB $FF20 ; Set tone
NOP ; Time delay
NOP ; Time delay
NOP ; Time delay
INCB ; Increment B (tone)
BNE Tone ; Branch if B not zero
TFR A,B ; Transfer A back to B
LEAX -1,X ; Decrement duration (or DEX if starting lwasm with -0 or --6800)
BNE Tone ; Branch if X not zero
BRA LdNote ; Load next note
End RTS ; Return from subroutine (end program)
NotesTable FCB $37 ; Note 1
FCB $40 ; Note 2
FCB $49 ; Note 3
FCB $52 ; Note 4
FCB $5B ; Note 5
FCB $64 ; Note 6
FCB $6D ; Note 7
FCB $76 ; Note 8
FCB $00 ; End of table
END Start ; Start can be any label where you want execution to begin

I hope someone out there will find this helpful!
It does feel really good to get these first few programs working and gain some momentum.
David
13-Dec-2025

Comments

Popular Posts