Page 1 of 1

W65C816 bug ?

Posted: Sat Oct 26, 2019 4:09 pm
by dderny
I'm playing with a w65c816sxb board
I had many problems with this board but I've been able to use it by replacing WDC firmware by my monitor
(my monitor works on 3 machines on the real 6502 the following code works

0400 LDA #$FE
0402 STA $04
0404 LDA #$FF
0406 STA $05
0408 LDY #$02
040A LDA ($04),Y
040C RTS

in both case it AC should contains 00
the location $00 and $01 contains the top address in ram
$8000 on replica 1 and $7F00 on w65c816sxb

when I run this code on the replica 1 it works I get the content of the memory at FFFE +2
Image
in this case, after the execution it returns to the registers it's normal

when I run this code on the w65c816sxb in emulation mode, I get a reset of the board
Image
in this case it shows the free memory, the banner and the registers
to get that it is necessary to call the cold start routine

not the display of registers is not complete in my monitor PC and IRQ are wrong
other registers are ok

already seen this problem ?
any idea ?

thanks

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 4:46 pm
by BitWise
The 816SXB resets when you access unimplemented memory areas.

Your pointer at $04/05 contains $fffe and Y is $02 so the address being accessed is $fffe + $02 = $01:0000 rather than $00:0000.

A 65(C)02 can only access 65K so the access wraps round. Indexed modes on the 816 can cross bank boundaries.

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 6:49 pm
by dderny
in emulation mode, it should wrap like a 6502/65c02...

do you know if it's a problem specific to this board
or generic to a w65c816 processors...

I have more and more doubts about this processor or at least the emulation mode :(

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 7:32 pm
by Dr Jefyll
dderny wrote:
in emulation mode, it should wrap like a 6502/65c02...
True. And yet the behavior suggests it's not in Emulation Mode. (If the access truly were to 00:0000, as per Emulation Mode, then why the reset?)

Just for luck, try starting your routine with code to explicitly enter Emulation Mode. :wink: I believe the necessary incantation is simply...
Quote:
SEC
XCE
-- Jeff

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 7:51 pm
by GARTHWILSON
In emulation mode the bank bytes are initialized to zero, but are not stuck there.

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 8:19 pm
by Dr Jefyll
GARTHWILSON wrote:
In emulation mode the bank bytes are initialized to zero, but are not stuck there.
Good point... implying that maybe the wrap does occur, but not in Bank 00.

And again, it's easy to remove any doubt:

Code: Select all

LDA# 0
PHA
PLB    ;data bank register is now zero
(And yes, PLB and quite a few other '816 instructions do work normally in Emulation Mode.)

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 8:37 pm
by dderny
thanks All, it works

but now the problem is to understand how he left the emulation mode, I never explicitly set the native mode
is there a set of instructions to detect the mode native / emulation ?

something like:
XCE
PHP
XCE
PLP
BCC/BCS ?


or do I have to take the logic analyzer and use a trigger on E ?

thanks

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 8:41 pm
by BigDumbDinosaur
dderny wrote:
I'm playing with a w65c816sxb board
I had many problems with this board but I've been able to use it by replacing WDC firmware by my monitor
(my monitor works on 3 machines on the real 6502 the following code works

Code: Select all

0400 LDA #$FE
0402 STA $04
0404 LDA #$FF
0406 STA $05
0408 LDY #$02
040A LDA ($04),Y
040C RTS
in both case it AC should contains 00, the location $00 and $01 contains the top address in ram, $8000 on replica 1 and $7F00 on w65c816sxb.
As others noted, it isn't clear if the '816 is in emulation or native mode. If the latter, what is the setting of the m bit in SR? If m is 0 your instruction at $0400 is grabbing $FE followed by the opcode at $0402, which would be $85. As that would constitute a 16-bit load, PC would advance to $0403, not $0402.
Quote:
when I run this code on the replica 1 it works I get the content of the memory at FFFE +2
Image
in this case, after the execution it returns to the registers it's normal
Unless your monitor's register dump displays the full values of the registers, i.e., 16-bit values instead of 8-bit values, you will not be seeing the complete picture. In Supermon 816, a register dump appears as follows:

Code: Select all

  PB  PC   NVmxDIZC  .C   .X   .Y   SP   DP  DB
; xx 0000  00000000 0000 0000 0000 xxxx 0000 00
That will give you the complete picture.

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 9:01 pm
by BitWise
I don't think emulation mode affects indexing across banks on the 816 when using abs,x abs,y or (ind),y. Only direct page indexing is wrapped (to the page when E=1 and to the bank when E=0).

I found this on page 98 following figure 7-5
Quote:
On the 6502, 65C02, and 65802, if an index plus its base would exceed $FFFF, it wraps to continue
from the beginning of the 64K bank zero; that is, when index is added to base, any carry out of the low-order sixteen bits lost. (See Figure 7.5.)

On the 65816, the same is true of direct page indexing: because the direct page is always located in
bank zero, any time the direct page, plus an offset into the direct page, plus an index exceeds $FFFF, the address wraps to remain in bank zero.

But as Figure 7.5 shows, whenever a 65816 base is specified by a 24-bit (long) address, or the base is specified by sixteen bits and assumes the data bank as its bank, then, if an index plus the low-order sixteen bits of its base exceeds $FFFF, it will temporarily (just for the current instruction) increment the bank. The 65816 assumes that the array being accessed extends into the next bank.

Re: W65C816 bug ?

Posted: Sat Oct 26, 2019 10:07 pm
by GARTHWILSON
BitWise wrote:
I found this on page 98 following figure 7-5
To remove any mystery, that's in the "Programming the 65816—Including the 6502, 65C02 and 65802" 6502/65816 programmer's manual by David Eyes and Ron Lichty, the best 65xx programming manual available, and a must-have for every 65xx programmer!

Re: W65C816 bug ?

Posted: Sun Oct 27, 2019 12:39 pm
by dderny
in fact I was wrong yesterday, it was not working
in my test, either in emulation or native,I get a reset

Image

I tested both native and emulation
(my mini assembler has no support for 65c816 so I code a nop then change the nop into XCE manually (FB)

I also added the display of the mode '-' for native and 'E' for emulation
in both case I got the display of the top memory and the banner from the reset code

Re: W65C816 bug ?

Posted: Sun Oct 27, 2019 12:46 pm
by Rob Finch
What is the code RTS'ing to? RTS pulls the return address off the stack.

Re: W65C816 bug ?

Posted: Sun Oct 27, 2019 5:53 pm
by dderny
in fact nothing special, it just return to the caller
I was not expecting a reset while crossing $FFFF in emulation mode

Re: W65C816 bug ?

Posted: Mon Oct 28, 2019 1:32 am
by barrym95838
It might be nothing, but the only thing that strikes me as somewhat strange is the reported value of PC after your "RTS" to the monitor in both cases. What would happen if you replaced the RTS with a BRK and retested?

Re: W65C816 bug ?

Posted: Mon Oct 28, 2019 9:12 pm
by dderny
My monitor is still in development
PC is wrong
IRQ is forced to 0000 in the display
the other registers are OK
disassembler/assembler/load & save hexa are working
I'm about to start on the trace