Day 15: CTC Subroutines

lets make a subroutine that can set or clear a selected bit in the CTC control register.  To call the routine, we need to tell it:
– The CTC channel
– Which bit we’re adjusting
– If we’re setting or clearing the bit

Lets put the CTC channel’s port on the B register, the bit we’re adjusting in the C register, and…. do we use a register or a flag for setting or changing?   Lets use the zero flag and see what trouble that gets us into.

Oh snap, there’s bit setting instructions, and they work with any register!  set n,A would set the n’th bit.  Can the n be derived from the value of a register?  Lets assume not.

Actually, before we do any of that, lets see if we can get relative jumps working correctly.  Maybe we can get the number of jumps from the B register, and have a series of SET instructions

Using JR 01, I’m getting a compiler error “Byte out of range”.  When I look at the listing, I see the offset listed as EE, which doesn’t make sense… AH – The assembler automatically subtracts 2 to make up for the fact that the PC has already incremented by 2! So when I was trying 1 or 2, it would fail!  OK, but 4 fails too…

There’s something about how this assembler handles JR that I don’t understand.
OK – it looks like you can only use JR with a label in assembler.  Oh wait,  you can’t do what I was originally thinking – you can’t get the offset of a Jump from a register??

From :
“There is no variable indexing (like the 6502’s LDA (ptr), Y addressing mode) at all. The index registers support a constant -128..127 displacement only.”


OK, well THAT’S Stupid.  Damn.  I thought even the lowly 6802 did that…

so can we
1 – modify the operand byte after the JR Instruction?
2 – use one of the index registers? Does this mean 16 bit addition?

What if you…
1 – jumped to a routine
2 – set IX to the next address
3 – add C  to the IX
4 – JP(IX)

This entry was posted in Blinking Lights. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *