W65C816 bug ?

Let's talk about anything related to the 6502 microprocessor.
Post Reply
dderny
Posts: 15
Joined: 23 Oct 2019

W65C816 bug ?

Post 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
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: W65C816 bug ?

Post 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.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
dderny
Posts: 15
Joined: 23 Oct 2019

Re: W65C816 bug ?

Post 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 :(
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: W65C816 bug ?

Post 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
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: W65C816 bug ?

Post by GARTHWILSON »

In emulation mode the bank bytes are initialized to zero, but are not stuck there.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: W65C816 bug ?

Post 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.)
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
dderny
Posts: 15
Joined: 23 Oct 2019

Re: W65C816 bug ?

Post 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
User avatar
BigDumbDinosaur
Posts: 9426
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: W65C816 bug ?

Post 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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: W65C816 bug ?

Post 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.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: W65C816 bug ?

Post 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!
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
dderny
Posts: 15
Joined: 23 Oct 2019

Re: W65C816 bug ?

Post 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
User avatar
Rob Finch
Posts: 465
Joined: 29 Dec 2002
Location: Canada
Contact:

Re: W65C816 bug ?

Post by Rob Finch »

What is the code RTS'ing to? RTS pulls the return address off the stack.
dderny
Posts: 15
Joined: 23 Oct 2019

Re: W65C816 bug ?

Post by dderny »

in fact nothing special, it just return to the caller
I was not expecting a reset while crossing $FFFF in emulation mode
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: W65C816 bug ?

Post 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?
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)
dderny
Posts: 15
Joined: 23 Oct 2019

Re: W65C816 bug ?

Post 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
Post Reply