NES endian (Intel or Motorola?)

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
jargon
B&: This is not your blog
Posts: 208
Joined: Fri Dec 07, 2007 11:40 pm
Location: 480/85260
Contact:

NES endian (Intel or Motorola?)

Post by jargon »

Is the NES endian:

1a. Motorola (right-endian)
Highest power of 2 bit is right-most (last in memory), right to left.

Code: Select all

1<<0
1<<1
1<<2
1<<3
1<<4
1<<5
1<<6
1<<7
1b. Intel (left-endian)
Highest power of 2 bit is left-most (first in memory), left to right.

Code: Select all

1<<7
1<<6
1<<5
1<<4
1<<3
1<<2
1<<1
1<<0
Also:
In Motorola-Endian, are words (2bytes) as follows:
2a.

Code: Select all

1<<8
1<<9
1<<10
1<<11
1<<12
1<<13
1<<14
1<<15
1<<0
1<<1
1<<2
1<<3
1<<4
1<<5
1<<6
1<<7
or:
2b.

Code: Select all

1<<0
1<<1
1<<2
1<<3
1<<4
1<<5
1<<6
1<<7
1<<8
1<<9
1<<10
1<<11
1<<12
1<<13
1<<14
1<<15
Also:
In Intel-Endian, are words (2bytes) as follows:
3a.

Code: Select all

1<<15
1<<14
1<<13
1<<12
1<<11
1<<10
1<<9
1<<8
1<<7
1<<6
1<<5
1<<4
1<<3
1<<2
1<<1
1<<0
or:
3b.

Code: Select all

1<<7
1<<6
1<<5
1<<4
1<<3
1<<2
1<<1
1<<0
1<<15
1<<14
1<<13
1<<12
1<<11
1<<10
1<<9
1<<8
I am so confused.

Also Blitz Basic, Blitz Plus, Blitz 3D seems to do it totally wrong for Intel-Endian for peeking/poking Signed Short Integers.

(signed __int16)
Cheers,
Timothy Robert Keal alias jargon

Image
Miser's House Anthology Project
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Little
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

The CPU is little-endian like Intel, but the PPU is big-endian like Moto^H^H^H^H Freescale. (See PPUADDR/$2006 byte order, and see the bitwise arrangement of pixels within CHR bitplanes.)
User avatar
MottZilla
Posts: 2835
Joined: Wed Dec 06, 2006 8:18 pm

Post by MottZilla »

If you want a 16bit value on the 6502, the first byte is the lower 8bits, the one after that is the upper 8bits.

So (Second_Byte * 256) + First_Byte = 16Bit Value. You could also use bitwise operations for the same thing.

People also would just say Least Significant Byte First.
User avatar
jargon
B&: This is not your blog
Posts: 208
Joined: Fri Dec 07, 2007 11:40 pm
Location: 480/85260
Contact:

Post by jargon »

MottZilla wrote:If you want a 16bit value on the 6502, the first byte is the lower 8bits, the one after that is the upper 8bits.

So (Second_Byte * 256) + First_Byte = 16Bit Value. You could also use bitwise operations for the same thing.

People also would just say Least Significant Byte First.
in otherwords:

as above "1b" for 8bit values and and "3a" for 16bit values for CPU.

what combo does PPU use again?
Cheers,
Timothy Robert Keal alias jargon

Image
Miser's House Anthology Project
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Byte order is relevant, bit order is not.
The only time there is anything resembling a bit order is serial communication with the controller port, expansion port, or MMC1. Then, bit order is whatever order you bank the bits in, or extract them, because you can use any type of shift you want to get bits in.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Dwedit wrote:The only time there is anything resembling a bit order is serial communication with the controller port, expansion port, or MMC1.
It's also important when handling CHR data, you must know what's left and what's right in tiles.
User avatar
jargon
B&: This is not your blog
Posts: 208
Joined: Fri Dec 07, 2007 11:40 pm
Location: 480/85260
Contact:

Post by jargon »

nobody has told me the byte order for Motorola on the PPU yet.
Cheers,
Timothy Robert Keal alias jargon

Image
Miser's House Anthology Project
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Does the PPU even have 16 bit values?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Dwedit wrote:Byte order is relevant, bit order is not.
Compare the tile formats of the Sega Genesis and Game Boy Advance.
Dwedit wrote:Does the PPU even have 16 bit values?
No, but it has a 14-bit value. Writes to PPUADDR ($2006) are most significant byte first.
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

The PPU address is still a bad example though, since it's made up of the various scrolling latches and counters.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Dwedit wrote:The PPU address is still a bad example though, since it's made up of the various scrolling latches and counters.
Which all increment linearly whenever the program reads or writes PPUDATA ($2007).
User avatar
jargon
B&: This is not your blog
Posts: 208
Joined: Fri Dec 07, 2007 11:40 pm
Location: 480/85260
Contact:

Post by jargon »

tepples wrote:
Dwedit wrote:Byte order is relevant, bit order is not.
Compare the tile formats of the Sega Genesis and Game Boy Advance.
Dwedit wrote:Does the PPU even have 16 bit values?
No, but it has a 14-bit value. Writes to PPUADDR ($2006) are most significant byte first.
if the NES PPU uses a right-endian bit order with left-endian byte order 14bit value...

how the hell do you pack the bits?
Cheers,
Timothy Robert Keal alias jargon

Image
Miser's House Anthology Project
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

jargon wrote:if the NES PPU uses a right-endian bit order with left-endian byte order 14bit value...

how the hell do you pack the bits?
The PPU addresses are 14 bits, written big-endian. The pattern table and nametable data are 8 bits, with the left pixel in the most significant bit. See the source code for any tile editor to learn how to pack pattern table data.
Post Reply