It is currently Sat Sep 22, 2018 2:10 pm

 All times are UTC - 7 hours

### Forum rules

• For making cartridges of your Super NES games, see Reproduction.

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: What affects the size of STZ?Posted: Sun Oct 02, 2016 5:05 pm
 Formerly Espozo

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3362
Location: Richmond, Virginia
I never thought about this before, and I guess I'm lucky I haven't ran into any problems yet, but if I'm not mistaken, STZ doesn't actually affect the accumulator, does it? By that same token, the size of the accumulator shouldn't affect this instruction, should it?

I also got to thinking, does INC affect the whole accumulator, or only what the accumulator is set to? The only reason I'm asking this is that "C" represents the whole 16 bits like TCD, but here, I imagine it's just an abbreviation for increment.

Top

 Post subject: Re: What affects the size of STZ?Posted: Sun Oct 02, 2016 5:14 pm

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3605
Location: Mountain View, CA
stz is affected by the size of the accumulator (i.e. it writes \$0000 if m=0 (16-bit), or writes \$00 if m=1 (8-bit)).

Yes, inc (e.g. inc a) obviously affects the accumulator, thus whether m=0 or m=1 affects what happens when you do inc. Written in code, to make this point crystal clear:

Code:
rep #\$20
lda #\$12ff
sep #\$20
inc
; Accumulator now holds \$1200 (\$ff+1 = \$00 (\$ff wrapped to \$00); upper byte is
; left alone because at the time of the increment, m=1).

rep #\$20
lda #\$12ff
inc
; Accumulator now holds \$1300 (\$12ff+1 = \$1300).

**All** of this is fully/clearly documented in the WDC 65816 documentation, Chapter 18 (Instruction Set).

Top

 Post subject: Re: What affects the size of STZ?Posted: Sun Oct 02, 2016 5:30 pm

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7537
Location: Seattle
The reason's it's referred to as the "M" bit is because it affects the size of Memory operations (as well as the "accumulator" )

Basically, if a given instruction could possibly support either 8 or 16-bit operands, and it's not controlled by the "X" bit, it's controlled by the "M" bit.

Top

 Post subject: Re: What affects the size of STZ?Posted: Sun Oct 02, 2016 5:37 pm

Joined: Sun Mar 27, 2016 7:56 pm
Posts: 164
The m flag also affects incrementing and decrementing memory directly.
Code:
rep #\$20        ; set m to 16-bit
lda #\$10ff
sta \$00         ; \$00 = #\$ff, \$01 = #\$10
inc \$00         ; \$00 = #\$00, \$01 = #\$11

rep #\$20        ; set m to 16-bit
lda #\$10ff
sta \$00         ; \$00 = #\$ff, \$01 = #\$10
sep #\$20        ; set m to 8-bit
inc \$00         ; \$00 = #\$00, \$01 = #\$10

This, along with stz, is why the full name of m is "Memory/Accumulator Select", and why it's m rather than a.

Top

 Post subject: Re: What affects the size of STZ?Posted: Mon Oct 03, 2016 6:00 pm

Joined: Thu Jan 19, 2006 5:08 pm
Posts: 751
Location: Shelton, Washington.
STZ is basically a smaller version of this 6502 code:

Code:
LDA #0
STA RAM_Label

When 16-bit, it equates to this 6502 code:

Code:
LDA #0
STA RAM_Label
STA RAM_Label+1

About A vs. X and Y:

A is sized depending on the M (Memory) bit, X and Y are sized via I (Index) bit, the CPU combines X and Y size bits temporarily in the I bit and therefore since the 65816's CPU manipulation/flag bits (which are set depending on opcode type) is only 8 bits, the result instead of three bits, there's two bits to use SEP and REP on,

So think of M (as in A) as a main program register, and I (as in X and Y) as your auxiliry program register(s)!

EDIT: Cleaned up, and added some missing info, and added proper stuff about the CPU manipulation (opcode flag) bits from the processors

_________________
AKA SmilyMZX/AtariHacker.

Last edited by Hamtaro126 on Sun Oct 09, 2016 3:57 am, edited 3 times in total.

Top

 Post subject: Re: What affects the size of STZ?Posted: Tue Oct 04, 2016 10:28 am

Joined: Sat Apr 25, 2015 1:47 pm
Posts: 420
Location: FL
Hamtaro126 wrote:
X and Y are actually split from the giant I register (meaning Index) and therefore instead of three regs, there's two regs to use SEP and REP on,

This is pretty misleading; are you just making this up to try to explain why there's only one size flag for both index registers?

X and Y are totally physically separate and also have different behavior for indirect addressing (i.e. they aren't interchangeable). I think the only real reason there's one flag is because anything else would have just complicated things from both a hardware and software design standpoint (and there weren't enough available bits in the 8-bit status register anyway, so how would you do it?)

Top

 Post subject: Re: What affects the size of STZ?Posted: Sun Oct 09, 2016 3:44 am

Joined: Thu Jan 19, 2006 5:08 pm
Posts: 751
Location: Shelton, Washington.
@Renevant: You are actually correct, I was actually meaning to say "X" and "Y" are still seperate registers, but the "I" bit (in a visual sense) sets up a temporary combination of "X" and "Y" bit registers due to the 6502-family CPUs having only 8 processor manipulation bits.

_________________
AKA SmilyMZX/AtariHacker.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 7 posts ]

 All times are UTC - 7 hours