6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Nov 04, 2024 9:49 pm

All times are UTC




Post new topic Reply to topic  [ 61 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
PostPosted: Sun Nov 12, 2017 5:05 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
I've been working on an application that requires exact cycle counting and have found a small error in the Kowalski simulator.

While the WDC documents are not consistent across many versions of the W65C02 datasheet, it does elude in many that the zero page indirect Y addressing mode will add 1 clock if a page boundary is crossed while computing the target address. I confirmed this using the Visual6502 simulator.

So an LDA (zp),Y instruction will take 5 cycles to complete with no page crossing and 6 cycles if there is a page crossing. The Kowalski simulator calculates 5 cycles regardless of page crossing.

Here is my test code:
Code:
   *=   $1000
   LDA   #$E0      ; Load $02E0 into $80
   STA   $80
   LDA   #$02
   STA   $81
   LDY   #$20      ; set index to $20
   LDA   ($80),Y   ; get value at $0300 ($02E0 + $20)
   STA   $82


This is the Visual6502 trace:
Code:
12   000a   b1   1   LDA (zp),Y   000a   02   00   20   fd   nv‑BdIzc
12   000a   b1   1   LDA (zp),Y   000a   02   00   20   fd   nv‑BdIzc
13   000b   80   1                000b   02   00   20   fd   nv‑BdIzc
13   000b   80   1                000b   02   00   20   fd   nv‑BdIzc
14   0080   e0   1                000c   02   00   20   fd   nv‑BdIzc
14   0080   e0   1                000c   02   00   20   fd   nv‑BdIzc
15   0081   02   1                000c   02   00   20   fd   nv‑BdIzc
15   0081   02   1                000c   02   00   20   fd   nv‑BdIzc
16   0200   00   1                000c   02   00   20   fd   nv‑BdIzc
16   0200   00   1                000c   02   00   20   fd   nv‑BdIzc
17   0300   00   1                000c   02   00   20   fd   nv‑BdIzc
17   0300   00   1                000c   02   00   20   fd   nv‑BdIzc


I know this won't affect many projects, but wanted to share in case someone found it useful.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Last edited by 8BIT on Tue Nov 14, 2017 2:55 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 12, 2017 5:46 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8474
Location: Midwestern USA
8BIT wrote:
I've been working on an application that requires exact cycle counting and have found a small error in the Kowalski simulator...The Kowalski simulator calculates 5 cycles regardless of page crossing.

Interesting. I do use the cycle count function now and then, but never noticed this in the past.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 12, 2017 8:34 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
I took a quick look at the source code for the simulator. I'm not positive, but it may not be accounting for ANY page crossing adjustments (except for branches, which do work correctly). It may take some time, but I will try to verify each address mode against the Visual6502 to verify that.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 13, 2017 2:05 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8474
Location: Midwestern USA
8BIT wrote:
I took a quick look at the source code for the simulator. I'm not positive, but it may not be accounting for ANY page crossing adjustments (except for branches, which do work correctly). It may take some time, but I will try to verify each address mode against the Visual6502 to verify that.

Daryl

Do you have the tools necessary to build a revised version of the simulator?

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 13, 2017 2:12 am 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
BigDumbDinosaur wrote:
Do you have the tools necessary to build a revised version of the simulator?

That would be great. Maybe we could look at a few of the other bugs in it if someone can build it. Breakpoints for one don't work very well...


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 13, 2017 2:45 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
8BIT wrote:
zero page indirect Y addressing mode [will] add 1 clock if a page boundary is crossed while computing the target address
That's true for LDA ADC CMP and many of the others. But in the case of a write -- STA indirect Y -- the extra clock occurs whether or not a page crossing occurs. An important piece of trivia, especially if someone does dig in and try to fix the simulator.

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 13, 2017 3:33 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
BigDumbDinosaur wrote:
8BIT wrote:
I took a quick look at the source code for the simulator. I'm not positive, but it may not be accounting for ANY page crossing adjustments (except for branches, which do work correctly). It may take some time, but I will try to verify each address mode against the Visual6502 to verify that.

Daryl

Do you have the tools necessary to build a revised version of the simulator?


No, not unless there is a free C++ compiler somewhere I can use.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 13, 2017 3:48 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Dr Jefyll wrote:
8BIT wrote:
zero page indirect Y addressing mode [will] add 1 clock if a page boundary is crossed while computing the target address
That's true for LDA ADC CMP and many of the others. But in the case of a write -- STA indirect Y -- the extra clock occurs whether or not a page crossing occurs. An important piece of trivia, especially if someone does dig in and try to fix the simulator.


Note 1 from the instruction timing chart in the WDC 65C02 manual (2004 version) says:
"1. Add 1 cycle for indexing across page boundaries, or write. This cycle contains invalid addresses."

So yes, any write will contain the extra cycle needed to adjust the address pointer. It's just the read instructions that I can see.
So far, [LDA abs, x], [LDA abs, y], and [LDA (zp), y] all need an extra cycle if the page is crossed. [LDA (zp, x)] does not as it wraps back around within zero page. ADC, AND, BIT, CMP, EOR, LDA, LDX, LDY, ORA, SBC all need to be tested. With ADC and SBC, the decimal mode flag also needs to be considered, and I believe the Kowalski simulator adds a cycle correctly.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2017 5:15 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Druzyek wrote:
BigDumbDinosaur wrote:
Do you have the tools necessary to build a revised version of the simulator?

That would be great. Maybe we could look at a few of the other bugs in it if someone can build it. Breakpoints for one don't work very well...


I have managed to hack together a VC++ tool set and have compiled the 1.2.6 version from the sources. If a couple of you can try to run the attached in your systems, that would help me ensure the tool set is working correctly. I'm a novice with C++ and the whole Windows build environment, so I make no promises to fix anything. I will try to update the cycle counting, once I get them documented better. After that, we can work together to make other changes or enhancements.

Please let me know if this works on your system. Unzip to a any folder. Run the 6502.exe. Load the "min_mon.asm" and assemble and Simulate. Open the Output window and press RST on the tool bar. You should see the EHBASIC start screen. You may need to set the input/output window to $F000.

Daryl


Attachments:
6502.zip [538.51 KiB]
Downloaded 191 times

_________________
Please visit my website -> https://sbc.rictor.org/
Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2017 8:23 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8474
Location: Midwestern USA
8BIT wrote:
I have managed to hack together a VC++ tool set and have compiled the 1.2.6 version from the sources.

FYI, the current executable that may be downloaded from Mike Kowalski's website is version 1.2.12. This version fixes several bugs in conditional assembly, listing format and other items. I have contacted Mike via E-mail to see if the source for 1.2.12 is available.

BTW, I downloaded and tried out your compiled version. It appears to be functional and is able to assemble the firmware for POC V1.1, with the only errors coming from conditional assembly bugs that were in versions 1.2.8 and older.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2017 12:38 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
It would be great if we could get the latest source. Thanks for chasing that down!!

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2017 8:28 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
8BIT wrote:
I will try to update the cycle counting, once I get them documented better.


Be on the lookout for irregularities like this, which almost all documents omit. :!:
Quote:
Table 7-1 of the WDC datasheet [...] claims this issue has been corrected for the CMOS chip. But in fact that's only true regarding ROL ROR ASL and LSR. The fix does not apply to INC and DEC [...]

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2017 8:56 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Thanks Jeff. I was planning to use the Visual 6502 as a base reference. But, it looks like I may need to consider the 6502/65C02 differences as well when determining cycle adjustments. I will most likely create a table to document all options.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2017 11:18 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
Would it make sense to make a list of bugs we might be able to fix?


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 15, 2017 4:54 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Druzyek wrote:
Would it make sense to make a list of bugs we might be able to fix?

Sure, but lets wait to see if we can get a more recent source to start with. Some bugs may have been fixed, such as BDD's conditional assembly.

I'm hoping we can get the 1.2.12 source.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 61 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: