What's new

best byteswap?

huhhuh2000

New member
i know the pj64 help says the byte order of a rom doesnt matter, but which, in your opinion loads fastest or is best
 

Clements

Active member
Moderator
You really don't need to do this at all and you will see no improvement whatsoever, but if you insist... I'd say the "best" format would be byteswapped (v64) format because it is the most common format. Make sure you make back-ups, as you could potentially ruin your roms in the attempt of converting.
 

Allnatural

New member
Moderator
The only instance I know of where byte order would be of concern is when patching. Maybe when using old (read: outdated) emulators as well. The difference in load time, if any, is inconsequential.
 

AlphaWolf

I prey, not pray.
Saying "byteswapped" is a bit ambiguous, don't you think?...its either big endian (e.g. most risc CPUs), or little endian (e.g. intel CPUs). Byteswap just means you are switching from one endian to the other :p

I would figure though, that in the case of a dynarec engine, it would be better to match the endian-ness of the host CPU?
 
Last edited:
OP
H

huhhuh2000

New member
another aspect is if u assume that project64 does something like

check to see which format its in
convert to x format
work with x format

namely it is only coded to handle one format and just converts to that format before doing anything else.. so i wonder what the default format is?


..a reminder this discussion is just for the heck of it :D
 
OP
H

huhhuh2000

New member
yup, heeere we go!

i d/lded the source code for 1.4 to confirm it..
Code:
void ByteSwapRom (void) {
	DWORD count;

	SendMessage( hStatusWnd, SB_SETTEXT, 0, (LPARAM)"Byte swapping image" );
	switch (*((DWORD *)&ROM[0])) {
	case 0x12408037:
		for( count = 0 ; count < RomFileSize; count += 4 ) {
			ROM[count] ^= ROM[count+2];
			ROM[count + 2] ^= ROM[count];
			ROM[count] ^= ROM[count+2];			
			ROM[count + 1] ^= ROM[count + 3];
			ROM[count + 3] ^= ROM[count + 1];
			ROM[count + 1] ^= ROM[count + 3];			
		}
		break;
	case 0x40123780:
		for( count = 0 ; count < RomFileSize; count += 4 ) {
			ROM[count] ^= ROM[count+3];
			ROM[count + 3] ^= ROM[count];
			ROM[count] ^= ROM[count+3];			
			ROM[count + 1] ^= ROM[count + 2];
			ROM[count + 2] ^= ROM[count + 1];
			ROM[count + 1] ^= ROM[count + 2];			
		}
		break;
	case 0x80371240: 
                          break;

	default:
		DisplayError("ByteSwapRom: %X",ROM[0]);
	}
}

see how case is used 3 times, one for each type.. now for 2 types it converts them and for 1 it leaves it.. so which is which? i added code so a message box would popup saying so
Code:
void ByteSwapRom (void) {
	DWORD count;

	SendMessage( hStatusWnd, SB_SETTEXT, 0, (LPARAM)"Byte swapping image" );
	switch (*((DWORD *)&ROM[0])) {
	case 0x12408037:
		for( count = 0 ; count < RomFileSize; count += 4 ) {
			ROM[count] ^= ROM[count+2];
			ROM[count + 2] ^= ROM[count];
			ROM[count] ^= ROM[count+2];			
			ROM[count + 1] ^= ROM[count + 3];
			ROM[count + 3] ^= ROM[count + 1];
			ROM[count + 1] ^= ROM[count + 3];			
		}
                          MessageBox(NULL,"1","here",MB_OK);
		break;
	case 0x40123780:
		for( count = 0 ; count < RomFileSize; count += 4 ) {
			ROM[count] ^= ROM[count+3];
			ROM[count + 3] ^= ROM[count];
			ROM[count] ^= ROM[count+3];			
			ROM[count + 1] ^= ROM[count + 2];
			ROM[count + 2] ^= ROM[count + 1];
			ROM[count + 1] ^= ROM[count + 2];			
		}
                          MessageBox(NULL,"2","here",MB_OK);
		break;
	case 0x80371240: 
	             MessageBox(NULL,"3","here",MB_OK);
		break;

	default:
		DisplayError("ByteSwapRom: %X",ROM[0]);
	}
}
long story short, project64 does not convert the .rom (also .n64?) type, so that type should load a little faster
 

ShadowPrince

Moderator
AlphaWolf said:
Saying "byteswapped" is a bit ambiguous, don't you think?...its either big endian (e.g. most risc CPUs), or little endian (e.g. intel CPUs). Byteswap just means you are switching from one endian to the other :p

I would figure though, that in the case of a dynarec engine, it would be better to match the endian-ness of the host CPU?

Not totally correct.There are 4 DWORD formats :
Big Endian which mainframe computers using, Byteswapped, Little Endian (mostly PCs) and Wordswapped.

N64 emulators ,at least starting from uhle, disregard rom extension,and determine rom format by the first 4 bytes of the rom :
0x80371240 Big endian (z64)
0x37804012 Byteswapped (v64)
0x40123780 Little endian
0x12408037 Word swapped

When loading a rom,emulator converts it to big endian format.So in this aspect it's better to keep roms in big endian (z64 default),so that loading time will be minimized (by fractions of second in the best case ) .
 
OP
H

huhhuh2000

New member
well, not quite-- ive only heard of 3 formats, and pj64 only checks for 3, they are

0x12408037 Byteswapped (v64)
0x40123780 not byteswapped, Big endian (z64)
0x80371240 Word swapped, Little endian (rom n64)
 

nephalim

Psychic Vampire
The "manual" for making a ROM library suggests the best one, I think mostly because of comatibility...it's the link in Doomulation's Sig...
 

ShadowPrince

Moderator
I was refering to byte sequences and not actual DWORD values,as it's different on each machine depending of it's endianess :
instead of 0x80371240 Big endian (z64)
should be 80 37 12 40,if it's what you mean.
 

AlphaWolf

I prey, not pray.
ShadowPrince said:
Not totally correct.There are 4 DWORD formats :
Big Endian which mainframe computers using, Byteswapped, Little Endian (mostly PCs) and Wordswapped.

N64 emulators ,at least starting from uhle, disregard rom extension,and determine rom format by the first 4 bytes of the rom :
0x80371240 Big endian (z64)
0x37804012 Byteswapped (v64)
0x40123780 Little endian
0x12408037 Word swapped

Well, it's still just big endian or little endian. The difference you're seeing is the register size of the target hardware.
 

Top