[Coco] 6309 Weirdness ??
Robert Gault
robert.gault at worldnet.att.net
Thu May 17 06:17:01 EDT 2007
Darren A. wrote:
> OK, things are even stranger than I first thought. Below is a BASIC
> program that can be used to demonstrate my new theory:
>
> 10 CLEAR 200,&H6FFF:A=&H7000
> 20 READ B$:IF B$="XX" THEN 40
> 30 POKE A,VAL("&H"+B$) :A=A+1:GOTO 20
> 40 EXEC &H7000
> 50 PRINT "X = ";HEX$(PEEK(&H600));HEX$(PEEK(&H601))
> 100 DATA 8E,FF,FD: REM LDX #-3
> 110 DATA 10,30,15: REM ADDR X,PC
> 120 DATA 12: REM NOP
> 130 DATA BF,06,00: REM STX $600
> 140 DATA 39: REM RTS
> 150 DATA XX
>
> The program pokes the following code into memory, executes it, and
> displays the value of the X register that gets saved at address $600:
>
> 7000 LDX #-3
> 7003 ADDR X,PC
> 7006 NOP
> 7007 STX $0600
> 700A RTS
>
> When I run the program I see: X = FFF2
>
> I think the actual instructions executed are:
> 7000 LDX #-3
> 7003 ADDR X,PC ; PC = $7003+3+1-3 = $7004
> 7004 LEAX -11,X ; X = -3-11 = $FFF2
> 7006 NOP
> 7007 STX $0600
> 7009 RTS
>
> Note that the instruction following ADDR is a single byte (NOP). Now
> elimintate that NOP by deleting line 120 and run the program again.
>
> This time I see: X = FFFD
>
> I think the actual instructions executed are:
> 7000 LDX #-3
> 7003 ADDR X,PC ; PC = $7003+3+3-3 = $7006
> 7006 STX $0600
> 7009 RTS
>
> Note that on this run, the size of the instruction following ADDR was 3
> bytes long (STX $600).
> Now let's insert a 2-byte instruction after ADDR by entering the following:
>
> 120 DATA 86,00 : REM LDA #0
>
> If you run the program with this change, the CPU crashes (actually
> invokes the illegal instruction trap).
> I think the actual instructions executed are:
>
> 7000 LDX #-3
> 7003 ADDR X,PC ; PC = $7003+3+2-3 = $7005
> 7005 FCB $15 ; Illegal Instruction
>
> So, given this information, my new theory (and this seems really weird)
> is that the PC value used in the ADDR instruction is having the length
> of the following instruction added to it. I know this is getting crazy,
> but I just can't stop!
>
> Darren
>
Interesting!
I can confirm some of this on my Coco3. But there is a gotcha!
org $7000
start ldx #-1
addr x,pc
nop
stx $400
rts
Word at $400=$ffff
org $7000
start ldx #-3
addr x,pc
stx $400
rts
Word at $400=$fffd.
Now if the above were true then the following should work.
org $7000
start ldx #-2
addr x,pc
bra next
next stx $400
rts
Crash!!!!! Same explanation and this code should work. Since it doesn't,
something else must be happening.
The following doesn't work either.
org $7000
start orcc #$50
ldx #-2
addr x,pc
bra next
next stx $400
andcc #$af
rts
Crash!!!!!
More information about the Coco
mailing list