I have a SYM-1. It has a feature where it can draw text on an oscilloscope, and I'm trying to get it to work. I'm using the sample code from the manual, and I think it's buggy. But since I'm not experienced in 6502 programming, I was hoping someone could double check me.
I've attached a snapshot of the code below.
I think that the relative branch at line 0032 is wrong - it's going to jump into the middle of the instruction on line 0030. Likewise, the branch at line 0064 is wrong: it should probably be BNE *+5.
Am I right about this?
And a follow up question... in order to use this code, I need to alter some vectors that the SYM-1 monitor uses to display text. The manual explains how to do that manually from the keyboard. But if I wanted to do it programmatically, how would I? On a 16 bit processor, I'd load a register with the address of the code, then store that address in the vector location. E.g.:
LD D0,#TARGET
ST D0,VECTORLOCATION
On the 6502, I imagine I need to load the low byte of the target address, save it in the low byte of the vector, then repeat with the high byte. I'd like to do something like:
LDA #TARGET
STA VECTORLOCATION
LDA #TARGET>>8
STA VECTORLOCATION+1
But the SYM-1's assembler doesn't support shifting in expressions. It only allows addition and subtraction. Is there an elegant way to do this, or do I just need to load hexadecimal numbers, instead of using labels?
Thank you.
Is this buggy code?
Re: Is this buggy code?
The code looks fine to me.
The jump into the middle of the LDX #$EA at line 0030 works because constant $EA is also the opcode for NOP. The actual delay code is
The other the code assembled at line 0064 is D0 02, it jumps over the LDX #$CC at line 0065
With more lables in the assembler code you'd be looking at
The jump into the middle of the LDX #$EA at line 0030 works because constant $EA is also the opcode for NOP. The actual delay code is
Code: Select all
NOP
DEX
BNE nopWith more lables in the assembler code you'd be looking at
Code: Select all
LSR A
BCS LIGHT
DARK: LDX #&EC
BNE COMMON ; branch always
LIGHT: LDX #$CC
COMMON: STX PCR3Re: Is this buggy code?
rea5245 wrote:
I think that the relative branch at line 0032 is wrong - it's going to jump into the middle of the instruction on line 0030. Likewise, the branch at line 0064 is wrong: it should probably be BNE *+5.
The second branch just looks correct to me. In "*+4", the * refers to the address of this instruction, which is $0551. So *+4 is $0555, which is the STX instruction. It's loading X with a value, then jumping over the instruction that loads X with a different value.
They've missed an opportunity to save another byte here: if you replace BNE *+4 with .byte $2C, then the following LDX #$CC becomes the operand of a BIT instruction, and won't be executed as an LDX. That was also a common trick in the old days.
Quote:
LDA #TARGET
STA VECTORLOCATION
LDA #TARGET>>8
STA VECTORLOCATION+1
STA VECTORLOCATION
LDA #TARGET>>8
STA VECTORLOCATION+1
Code: Select all
LDA #>TARGET
STA VECTORLOCATION
LDA #<TARGET
STA VECTORLOCATION+1
Re: Is this buggy code?
Thank you all. It's a good thing I asked. 