How common is it to use V flag after adc, sbc, cmp, vs. bit?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: How common is it to use V flag after adc, sbc, cmp, vs.

Post by Myask »

BIT $2002, BIT $BUTTON_STATE for B in V; a few "branch always" or otherwise wanting a flag that doesn't need a refresh instruction through some routine. Not used much signed arithmetic yet for the other purpose.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: How common is it to use V flag after adc, sbc, cmp, vs.

Post by Garth »

I am very, very glad (zp,X) is there. It is used all the time in situations where you have a data stack in ZP, as stack cells may contain addresses (often calculated) to use as pointers. This is done constantly in the Forth programming language, but you can do the same kind of thing in assembly too, and some other HLLs use it as well. X becomes the data stack pointer. Anticipating a couple of objections: It may initially seem like that's too big of an expense; but when you do it this way, many of the usual needs for X go away. The few times it is needed for something else, it can be saved and restored. Taking space in ZP for a data stack may also seem unrealistic when ZP space is in such high demand; but when you do it this way, many of the ZP variables will no longer be needed. It really does work out well. I discuss it in chapters 4 through 8 of my 6502 stacks treatise.
http://WilsonMinesCo.com/ lots of 6502 resources
User avatar
dustmop
Posts: 136
Joined: Wed Oct 16, 2013 7:55 am

Re: How common is it to use V flag after adc, sbc, cmp, vs.

Post by dustmop »

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?
I wrote a blog post about this explaining its usefulness in detail: http://www.dustmop.io/blog/2015/05/20/s ... detection/
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: How common is it to use V flag after adc, sbc, cmp, vs.

Post by Oziphantom »

tepples wrote:
tokumaru wrote: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.
Maybe on the Apple ][ but on the C64 only beginner programmers would suffer the issue. You can bank out all ROM, or just BASIC on a C64 allowing you to get all 64K of RAM and all of ZP ( minus 0,1) for your own uses. Most early games for the C64 keep the KERNAL in but not the BASIC ROM, later games tend to ditch both for the most part.

For other uses of (zp,x) see http://csdb.dk/forums/index.php?roomid= ... allposts=1 kefren bars seems to be common use case, as does Audio Engines, Ray casters and Forth.
Post Reply