It is currently Wed Nov 22, 2017 3:18 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Thu Aug 24, 2017 6:52 pm 
Online
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1830
Location: DIGDUG
From...

http://www.6502.org/tutorials/vflag.html

"CLV clears V. Simple enough. It is most frequently used in conjunction with a BVC to simulate a forced branch (a.k.a a branch always) in relocatable routines. The 65C02 has a branch always instruction (BRA), but the 6502 does not."

Once you are sure V is clear, you can use BVC repeatedly, as long as there are no ADC,SBC,or BIT instructions. Is 1 byte shorter than JMP


Also, I've used the V flag in signed math, but I prefer not to (unsigned math is easier). I've mostly seen it for sprite zero checking, after BIT.

Edit - I couldn't find any example code where I used bvc or bvs for math. I retract that statement.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Last edited by dougeff on Fri Aug 25, 2017 4:42 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 1:38 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 256
tepples wrote:
I learned EOR-ADC-EOR-BVC, though there were several places that could have used it.
What does the EOR-ADC-EOR-BVC trick achieve?


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 4:06 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 874
Location: Sweden
I wanna know too.

rainwarrior wrote:
GradualGames wrote:
I've actually grepped every single game's code that I've adapted to make sure it's not using bvs bvc except after bit.

That... sounds like a lot more effort than it would take to just implement V. O_o
Yeah just implement it already! lol
This thread is interesting to see how people use V, but other than that, it's not much to discuss whether or not to implement it I think.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 4:24 am 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19245
Location: NE Indiana, USA (NTSC)
Oziphantom wrote:
tepples wrote:
I learned EOR-ADC-EOR-BVC, though there were several places that could have used it.
What does the EOR-ADC-EOR-BVC trick achieve?

From my previous post: "I use it to determine whether an addition or subtraction involving a signed number overflowed. This is useful for ensuring an entity's position doesn't leave the bounds of the screen or map and wrap to the other side."

It distinguishes 129 + (-2) = 127, which in this context is desirable, from 1 + (-2) = 255, which in this context needs to be clamped to 0.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 4:36 am 
Online
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1830
Location: DIGDUG
cc65 uses bvc in both icmp.s and lcmp.s for signed comparisons.

https://github.com/cc65/cc65/tree/master/libsrc/runtime

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 6:09 am 
Offline
User avatar

Joined: Sun Nov 09, 2008 9:18 pm
Posts: 987
Location: Pennsylvania, USA
Pokun wrote:
I wanna know too.

rainwarrior wrote:
GradualGames wrote:
I've actually grepped every single game's code that I've adapted to make sure it's not using bvs bvc except after bit.

That... sounds like a lot more effort than it would take to just implement V. O_o
Yeah just implement it already! lol
This thread is interesting to see how people use V, but other than that, it's not much to discuss whether or not to implement it I think.


In most cases I simply asked the developer of the game I was adapting whether they ever used bvc or bvs and delegated the task of answering that question to them, so it didn't feel like much work. I did try to implement V initially, but couldn't figure it out at that time. Plus I had no games which were exercising it anyway, and didn't feel like writing a test rom for something which I didn't know would necessarily be used. Like I said I have a lot of other things I do with my time, like making games, music, my full time job, walking for an hour every day, playing games, watching tv, etc. ggvm was something I got done over winter when I had slightly fewer things occupying my time, now I barely have any time for it. You're welcome to add support for V to the github project if you want to help out ;) It has turned out to be useful to a number of folks. That reminds me actually, I don't think I ever finished implementation of indexed indirect instructions either, I never use them and again, neither did the 10+ games I've adapted...


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 7:29 am 
Offline
User avatar

Joined: Sat Jan 09, 2016 9:21 pm
Posts: 245
Location: Central Illinois, USA
GradualGames wrote:
I don't think I ever finished implementation of indexed indirect instructions either, I never use them and again, neither did the 10+ games I've adapted...


I've read different explanations of good uses of indexed indirect instructions...but I've never once used them.

_________________
My games: http://www.bitethechili.com


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 8:29 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
The only use (for (zp,x)) I've found so far is to dereference some address when X already happens to be 0 or I don't want to destroy Y (required for (zp),y) for some reason.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 8:33 am 
Offline
User avatar

Joined: Sun Nov 09, 2008 9:18 pm
Posts: 987
Location: Pennsylvania, USA
thefox wrote:
The only use (for (zp,x)) I've found so far is to dereference some address when X already happens to be 0 or I don't want to destroy Y (required for (zp),y) for some reason.


It's so rarely used too bad we can't go back in time and tell the chip designers to get rid of indexed indirect and instead make the rest of the instruction set symmetrical. Haha. I don't know how many times I've tried to use

sty blahblah,x

thinking I could because I also did

ldy blahblah,x

...

*edit* Wait, now I'm confused. Out of curiosity I checked my printed out 6502 reference. It says zp,x is available for sty. But I'm pretty sure ca65 yells at me when I try it. Oh wait....it's ABS,x that I'm trying..that's what isn't supported.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 8:37 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10117
Location: Rio de Janeiro - Brazil
I once started a music engine where the streams for the different channels were accessed by consecutive pointers in ZP, and X was used to select one of them.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 9:42 am 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19245
Location: NE Indiana, USA (NTSC)
tokumaru wrote:
I once started a music engine where the streams for the different channels were accessed by consecutive pointers in ZP, and X was used to select one of them.

Same here. The only time I remember having actually used (dd,X) has been in my music engine Pently, where X equals 0, 4, 8, 12, or 16 for the five logical tracks (pulse 1, pulse 2, triangle, drum, attack) or the four APU PSG channels (pulse 1, pulse 2, triangle, noise). But GGVM's sampler is completely different from the 2A03's APU anyway.

I imagine that there are other uses of a pointer table on zero page. But 6502 coders who learned on Commodore 64 or Apple II won't have a lot of experience with it because Microsoft BASIC in ROM ate so much of zero page for itself.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 9:51 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10117
Location: Rio de Janeiro - Brazil
tepples wrote:
But 6502 coders who learned on Commodore 64 or Apple II won't have a lot of experience with it because Microsoft BASIC in ROM ate so much of zero page for itself.

And I guess they didn't even need ZP that much, since any absolute reference can be used as a pointer when code is running from RAM.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 10:33 am 
Online
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1830
Location: DIGDUG
I suppose you could use (zp,x) as pointers to pointers. (Or rather, to get the starting offset within a pointer table). But I would still prefer to use (zp), y or some other mode for that.

I made it pretty clear on my blog that I don't like (zp, x) mode, and don't use it.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 12:18 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5827
Location: Canada
tokumaru wrote:
tepples wrote:
But 6502 coders who learned on Commodore 64 or Apple II won't have a lot of experience with it because Microsoft BASIC in ROM ate so much of zero page for itself.

And I guess they didn't even need ZP that much, since any absolute reference can be used as a pointer when code is running from RAM.

Well, in the case of (zp,X) the point is to be able to loop through or random-access a table of pointers. Self-modifying code doesn't do that very well (requires unrolled code, altering the pointers by index no longer possible, etc.)

tepples' canonical example for something that is convenient with a table of pointers is per-channel data streams in a music engine, and that's primarily where I've used it too.


Top
 Profile  
 
PostPosted: Fri Aug 25, 2017 1:16 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7272
Location: Chexbres, VD, Switzerland
thefox wrote:
The only use (for (zp,x)) I've found so far is to dereference some address when X already happens to be 0 or I don't want to destroy Y (required for (zp),y) for some reason.

Well I use (zp,X) as a way to do a multi-channel music engine, and I also do this for a bytecode interpreter (basically improved SWEET-16). So I may use the instruction twice in the whole game code, but that particular instruction can be executed potentially hundreds of times per frame.

Quote:
I made it pretty clear on my blog that I don't like (zp, x) mode, and don't use it.

It's up to you to like it or not, but refusing to use it in one of the rare cases where it could be handful it's not very bright.

As for BVS/BVC, I use it mainly exclusively in combination with BIT, but not only with $2002. BIT is an amazing instruction when it comes to read the top two bits of any variable, I do that all the time. It's also common I have routines which returns two boolean values, one in C and one in V.


Last edited by Bregalad on Sun Aug 27, 2017 12:51 pm, edited 1 time in total.

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 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:  
Powered by phpBB® Forum Software © phpBB Group