Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Apple » Apple II » False read on index mode write?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
False read on index mode write? [message #372840] Sun, 26 August 2018 02:26 Go to next message
Anonymous
Karma:
Originally posted by: John Pham

Just wondering what are some of the quirks of 6502
does this STA (someaddress),Y cause a false read
on someaddress - is the 6502 put the someaddress on the bus
and do a someaddress + y so it doesn't have to do internal addition ?

but if I do LDA (someaddress),y - there is no double read on someaddress?
False read on index mode write? [message #372845 is a reply to message #372840] Sun, 26 August 2018 10:16 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Thomas Harte

An indirect indexed STA will always take six cycles; the first four to fetch the instruction, the zero-page address, then the two-byte base from the zero page. It will then add Y to the low byte of the address and read from there — it'll read because that may or may not be the correct address and it considers a read to be harmless. It'll then correct the high byte if necessary, and do the store.

A LDA will be either five or six cycles — if the high byte was already correct it won't bother spending a cycle on reading again.

So you'll always get the false read on a store, but it may be from the wrong address — it may be a page too low, if there needs to be carry into the high byte. You'll get a false read on a load only if there needs to be carry.
Re: False read on index mode write? [message #372851 is a reply to message #372845] Sun, 26 August 2018 12:53 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: John Pham

On Sunday, August 26, 2018 at 7:16:56 AM UTC-7, Thomas Harte wrote:
> An indirect indexed STA will always take six cycles; the first four to fetch the instruction, the zero-page address, then the two-byte base from the zero page. It will then add Y to the low byte of the address and read from there — it'll read because that may or may not be the correct address and it considers a read to be harmless. It'll then correct the high byte if necessary, and do the store.
>

it's not harmless, it's a damn bug - imagine you do a sta device,Y only to read the data on device so you're missing a char every time you do a write to that device
Re: False read on index mode write? [message #372852 is a reply to message #372845] Sun, 26 August 2018 14:18 Go to previous messageGo to next message
Michael J. Mahon is currently offline  Michael J. Mahon
Messages: 1767
Registered: October 2012
Karma: 0
Senior Member
Thomas Harte <thomas.harte@gmail.com> wrote:
> An indirect indexed STA will always take six cycles; the first four to
> fetch the instruction, the zero-page address, then the two-byte base from
> the zero page. It will then add Y to the low byte of the address and read
> from there — it'll read because that may or may not be the correct
> address and it considers a read to be harmless. It'll then correct the
> high byte if necessary, and do the store.
>
> A LDA will be either five or six cycles — if the high byte was already
> correct it won't bother spending a cycle on reading again.
>
> So you'll always get the false read on a store, but it may be from the
> wrong address — it may be a page too low, if there needs to be carry into
> the high byte. You'll get a false read on a load only if there needs to be carry.
>

And the same logic applies to the absolute indexed mode, with timings of 4
and 5 cycles for non-stores and always 5 cycles for stores.

Indexed stores always do an extra read, but to the lower page if indexing
causes a page crossing.

This suggests a strategy for avoiding redundant reads from a memory mapped
I/O page: arrange for the access to cross a page boundary so the extra
read doesn’t hit the I/O page.

This is an occasionally annoying behavior which is a consequence of a
fundamental design decision in the 6502—that memory is accessed on every
cycle. This decision simplified its logic and seldom is an issue, since it
is well documented.

--
-michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
Re: False read on index mode write? [message #372855 is a reply to message #372852] Sun, 26 August 2018 14:59 Go to previous messageGo to next message
ol.sc is currently offline  ol.sc
Messages: 211
Registered: January 2013
Karma: 0
Senior Member
Hi Michael,

> This suggests a strategy for avoiding redundant reads from a memory mapped
> I/O page: arrange for the access to cross a page boundary so the extra
> read doesn’t hit the I/O page.

This is the very thing the Slinky RAM firmware does:

https://github.com/a2retrosystems/mxp/blob/master/slinky/rom /equates.inc#L77-L81

Regards,
Oliver
Re: False read on index mode write? [message #372856 is a reply to message #372855] Sun, 26 August 2018 15:24 Go to previous messageGo to next message
TomCh is currently offline  TomCh
Messages: 242
Registered: November 2012
Karma: 0
Senior Member
....and the SSC firmware does the same too.

Tom
Re: False read on index mode write? [message #372857 is a reply to message #372851] Sun, 26 August 2018 15:29 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Thomas Harte

On Sunday, 26 August 2018 12:53:11 UTC-4, John Pham wrote:
> On Sunday, August 26, 2018 at 7:16:56 AM UTC-7, Thomas Harte wrote:
>> An indirect indexed STA will always take six cycles; the first four to fetch the instruction, the zero-page address, then the two-byte base from the zero page. It will then add Y to the low byte of the address and read from there — it'll read because that may or may not be the correct address and it considers a read to be harmless. It'll then correct the high byte if necessary, and do the store.
>>
>
> it's not harmless, it's a damn bug - imagine you do a sta device,Y only to read the data on device so you're missing a char every time you do a write to that device

Right; maybe least harmful thing the 6502 designers could think of within their constraints would be more accurate?

Having double checked the 65C02's datasheet, correction of this behaviour — the 65C02 will reread the final instruction byte rather than reading from the wrong address — is described diplomatically only as an "operational enhancement", though it's the very first thing on the list. Above even elimination of the opcode that just send the original 6502 into an uninterruptible spin.
Re: False read on index mode write? [message #372906 is a reply to message #372840] Mon, 27 August 2018 15:50 Go to previous message
Anonymous
Karma:
Originally posted by: James Davis

On Saturday, August 25, 2018 at 11:26:57 PM UTC-7, John Pham wrote:
> Just wondering what are some of the quirks of 6502
> does this STA (someaddress),Y cause a false read
> on someaddress - is the 6502 put the someaddress on the bus
> and do a someaddress + y so it doesn't have to do internal addition ?
>
> but if I do LDA (someaddress),y - there is no double read on someaddress?

I suggest you download (and read):

Programming the 6502 by Rodnay Zaks.

ftp://public.asimov.net/pub/apple_II/documentation/programmi ng/6502assembly/Programming%20the%206502_OCR.pdf
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: PROLINE
Next Topic: VidHD: New 1080p HDMI video card for the AppleII
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Apr 25 11:34:18 EDT 2024

Total time taken to generate the page: 0.04053 seconds