Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > SHX/SHY
2012-11-26 14:30
Oswald

Registered: Apr 2002
Posts: 5017
SHX/SHY

I cant seem to get them working. I'm not sure wether the value for the AND comes from the PC counter or from the destination address, anyway neither running code at $ff00 or storing to $ff00 does work. maybe vice does not support this illegal?

edit: vice 2.2 unstable, x64 on win7.
2012-11-26 14:43
chatGPZ

Registered: Dec 2001
Posts: 11108
2.2 o_O i wouldnt expect that to work quite right =P

that said, SHX/SHY are both unstable, and have funny side effects when used in a badline/during DMA. (the bank the value is stored can turn into the value stored). i wouldnt use it at all in code that i want to run reliably on real c64s =)
2012-11-26 15:32
Endurion

Registered: Mar 2007
Posts: 72
Couldn't Vice emulate the instability of illegal opcodes as well, so coders aren't tempted in the first case? :)
2012-11-26 15:42
chatGPZ

Registered: Dec 2001
Posts: 11108
it could (and should and will) once the behaviour is exactly known :) - and it DOES emulate at least some of it (some "emulamer" thingy required it - which doesnt run reliably on all real C64s, btw)
2012-11-26 15:46
Fresh

Registered: Jan 2005
Posts: 101
Try using $fe00: SHX/Y => save [X/Y & (PCH+1)]
Some more info in this thread:
http://noname.c64.org/csdb/forums/index.php?roomid=11&topicid=3..

Edit:
:BasicUpstart2(start)
.pc=$0900
start:
	shx $fe00,y
	dex
	iny
	bne start
	dex
	jmp start

Execute and use vice monitor to look at the ram behind $fe00 (bank ram).
2012-11-26 17:18
Oswald

Registered: Apr 2002
Posts: 5017
Thanks for the help. The mistake is on Graham's page: "{adr}:=X&H" which leaves me anding with #$00 when running the code :P
2012-11-26 17:40
Cruzer

Registered: Dec 2001
Posts: 1048
As far as I know SHX/SHY have been emulated correctly in Vice for a long time, including the instabilities. And yes, it's hi-byte of the destination address + 1.

The instability is only that the and'ing sometimes is skipped, so e.g. if you have shy $7e00,x and expected it be anded by $7f, it sometimes isn't anded at all. But for $fe00 there's no problem, since anding with $ff is the same as not anding. And if your values don't mind whether they are anded, e.g. if they are all $00-$7f for shy $7e00,x, there is also no difference whether the and works or not.
2012-11-26 18:50
chatGPZ

Registered: Dec 2001
Posts: 11108
"The instability is only that the and'ing sometimes is skipped"
there is another problem when indexing crosses a page boundary, then the page the value is stored might be the same as the value itself.
2012-11-26 21:09
Cruzer

Registered: Dec 2001
Posts: 1048
Groepaz: Interesting, guess I haven't tried crossing page boundaries.
2012-11-27 04:51
Oswald

Registered: Apr 2002
Posts: 5017
"it could (and should and will) once the behaviour is exactly known :)"

why isnt it known? every single transistor has been reverse engineered. visual6502 anyone ?
2012-11-27 09:47
Ninja

Registered: Jan 2002
Posts: 404
It is known. I somewhere have a test-program which reliably does SHX/Y with no AND happening because it waits for the VIC to take over the bus. I intended to make that a bit more robust and write an VN article about it, but well, -EBUSY. I seem to recall that idea was later mentioned in this forum, too.
2012-11-27 09:49
Ninja

Registered: Jan 2002
Posts: 404
Oh, and visual6502 won't help you since you need interaction with VIC. Note, that XL and AppleII users never noticed dropping off the AND (as far as I found out).
2012-11-27 12:35
Frantic

Registered: Mar 2003
Posts: 1627
Whoever feels like it, please go ahead and write a few lines about SHX/SHY and put it in the following section of Codebase64:

http://codebase64.org/doku.php?id=base:6502_6510_coding#illegal..

:)
2012-11-27 13:26
chatGPZ

Registered: Dec 2001
Posts: 11108
"It is known. I somewhere have a test-program which reliably does SHX/Y with no AND happening because it waits for the VIC to take over the bus."
thing is that fiddling with BA does _not_ explain that behaviour in any way. so while it is known that the behaviour is somehow connected to DMA, it is not known what exactly happens =)
2012-11-27 14:57
Cruzer

Registered: Dec 2001
Posts: 1048
Ahh, the inexplicable mysteries of the C64, isn't that what makes it magic.
2012-11-27 15:26
Zyron

Registered: Jan 2002
Posts: 2381
That's where its soul is.
2017-11-17 17:16
Cruzer

Registered: Dec 2001
Posts: 1048
Quoting Frantic
Whoever feels like it, please go ahead and write a few lines about SHX/SHY and put it in the following section of Codebase64
I felt like it the other day. :)

Btw, I also tried what happens with page crossing, and it turned out much weirder than expected, since it stores the value to a completely different page. Double confirmed on VICE and real hardware. Gotta do some more testing before I can figure out the logic behind which page it ends up on, since I can't find anything online. But since VICE emulates it, I guess the knowledge has to be out there somewhere. :)
2017-11-17 17:41
Frantic

Registered: Mar 2003
Posts: 1627
Quote: Quoting Frantic
Whoever feels like it, please go ahead and write a few lines about SHX/SHY and put it in the following section of Codebase64
I felt like it the other day. :)

Btw, I also tried what happens with page crossing, and it turned out much weirder than expected, since it stores the value to a completely different page. Double confirmed on VICE and real hardware. Gotta do some more testing before I can figure out the logic behind which page it ends up on, since I can't find anything online. But since VICE emulates it, I guess the knowledge has to be out there somewhere. :)


Nice :)
2017-11-17 17:49
Krill

Registered: Apr 2002
Posts: 2839
Quoting Cruzer
Double confirmed on VICE and real hardware. Gotta do some more testing before I can figure out the logic behind which page it ends up on, since I can't find anything online. But since VICE emulates it, I guess the knowledge has to be out there somewhere. :)
So, why don't you simply take a look at the VICE source code? Avoiding confirmation bias and expecting to come up with different results? :)
2017-11-17 20:39
chatGPZ

Registered: Dec 2001
Posts: 11108
or why not just read No More Secrets v0.91 ? :)
2017-11-17 20:54
Cruzer

Registered: Dec 2001
Posts: 1048
Because experimenting is fun. :) And I guess I could have just read Groepaz' earlier comment saying that the page becomes the value stored. I.e. for SHX: Page = (H + 1) & X and for SHY: Page = (H + 1) & Y. Codebase article updated.
2017-11-17 22:26
Copyfault

Registered: Dec 2001
Posts: 466
Both the No more secrets-document and the codebase entry still have some vague phrasing so I dare to ask:

1. Does
Sometimes the AND "#<adr_hi>+1" drops off
actually mean
iff the write-cycle of the SH*-command is processed during an "X"-cycle (DMA-bus-overtake-cycle), the AND drops off?
Or are there more dependencies for the AND to drop off?


2. My understanding is that
The page where the value is stored may be equal to the value stored
actually means
iff there is a page break, the page where the value is stored is (<adr_hi> + 1) & y (ex. for SHY).
Or are there other occasions where the page is miscalculated?


3. Does the page miscalculation as described under 2. also happen on an "X"-cycle? My C64-intuition would say that also the page break fixup works normally on those "X"-cycles, but I did not test anything so far...


@Cruzer: Hurray for doing the tests and for feeding insights to codebase!!!
2017-11-17 22:31
chatGPZ

Registered: Dec 2001
Posts: 11108
1) yes. see the test programs
2) this seems to be unstable behaviour and it didnt happen at all on any of my C64s :) hence - please provide a proper testprogram for this behaviour, so it can be tested and verified further.

(i'll also have to update the ANE behaviour... found one CPU where it doesnt work as advertised. blarg)
2017-11-19 17:58
Bitbreaker

Registered: Oct 2002
Posts: 500
Seems like i also got this wrong with the page cross, thought it just drops off the +1 component on the highbyte. But then however this resolves to a pretty powerful opcode that might be misused in funny ways?

Means i could do stuff like sty yy00,x-1 by doing a shy $00ff,x with x being 1. I'm curious if this could be misused for something funky, usually you could only influence the highbyte easily when doing indirect adressing, what could be done faster that way when it is to set highbyte only (and it is okay to live with the given y-value)

As for normal Hi+1-behaviour, i had used shx + shy heavily in one of the carpet effects.
2017-11-19 18:58
Cruzer

Registered: Dec 2001
Posts: 1048
Quoting Bitbreaker
I'm curious if this could be misused for something funky
Yes, if you have a funky idea where you only need to store $00 in page $00, $01 in page $01 ... $ff in page $ff. Just can't think of a usecase right now.
2017-11-19 20:29
Copyfault

Registered: Dec 2001
Posts: 466
Maybe some funny way to initialize sprite pointers? Could even save some LDA's (depends on the no. of different spr-pointers used) ;)
2019-09-25 05:15
ChristopherJam

Registered: Aug 2004
Posts: 1378
Quoting Copyfault
Both the No more secrets-document and the codebase entry still have some vague phrasing so I dare to ask:

1. Does
Sometimes the AND "#<adr_hi>+1" drops off
actually mean
iff the write-cycle of the SH*-command is processed during an "X"-cycle (DMA-bus-overtake-cycle), the AND drops off?
Or are there more dependencies for the AND to drop off?


I think your timing's slightly off (the instruction needs to be paused after its 3rd cycle for the drop off to occur), but otherwise yes.


Quote:
2. ...
The page where the value is stored may be equal to the value stored


That "may be" is technically true; - read on :)

Quote:
iff there is a page break, the page where the value is stored is (<adr_hi> + 1) & y (ex. for SHY).


This is correct - hence the page is only equal to the value stored if the &(h+1) drop off you mentioned in (1) does not occur.


Quote:
3. Does the page miscalculation as described under 2. also happen on an "X"-cycle? My C64-intuition would say that also the page break fixup works normally on those "X"-cycles, but I did not test anything so far...


The page miscalculation occurs regardless of whether/when the instruction is interrupted by a DMA.

So, the good news is an unexpected DMA won't result in you trashing an unexpected address, it'll just change the value you write to it.

The above behavior has been implemented in VICE for quite some time now, and mostly covered by the test code in

https://svn.code.sf.net/p/vice-emu/code/testprogs/CPU

I added a couple of tests a few days ago to have a closer look at how the &(H+1) drop off compares to cycle stealing; check out *5.s in the shs and shxy subdirectories of the above.


tl;dr:


high byte of address written to, when:
 +--------+------------------+---------------+
 |        | no DMA on cycleN | DMA on cycleN |
 +--------+------------------+---------------+
 |page    |                  |               |
 |not     |        H         |       H       |
 |crossed |                  |               |
 +--------+------------------+---------------+
 |page    |                  |               |
 |crossed |     Y&(H+1)      |   Y&(H+1)     |
 |        |                  |               |
 +--------+------------------+---------------+

value written, when:
 +--------+------------------+---------------+
 |        | no DMA on cycleN | DMA on cycleN |
 +--------+------------------+---------------+
 |page    |                  |               |
 |not     |     Y&(H+1)      |       Y       |
 |crossed |                  |               |
 +--------+------------------+---------------+
 |page    |                  |               |
 |crossed |     Y&(H+1)      |       Y       |
 |        |                  |               |
 +--------+------------------+---------------+
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
csabanw
Guests online: 125
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Graphicians
1 Sulevi  (10)
2 Mirage  (9.8)
3 Lobo  (9.7)
4 Mikael  (9.7)
5 Archmage  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.088 sec.