mirror of
https://github.com/schibo/1964js.git
synced 2025-04-02 10:52:54 -04:00
git-svn-id: http://1964js.googlecode.com/svn/trunk@178 0378edba-076e-5dc0-2bb2-d87a714dcd81
41 lines
991 B
Dart
41 lines
991 B
Dart
library file;
|
|
|
|
import 'dart:html';
|
|
import 'stringutils.dart';
|
|
import 'memory.dart';
|
|
|
|
class RomFile {
|
|
RomFile() {}
|
|
|
|
/**
|
|
* Rewrite the ROM in big-endian byte order,
|
|
* which is how the rest of our memory is stored.
|
|
*/
|
|
static Uint8Array byteSwap(Uint8Array romFile) {
|
|
print("byte swapping...");
|
|
int fmt = Memory.getUint32(romFile, 0);
|
|
switch (fmt) {
|
|
case 0x37804012:
|
|
if ((romFile.byteLength % 2) !== 0) {
|
|
window.alert("help: support odd byte lengths for this swap");
|
|
}
|
|
int temp, k = 0;
|
|
while (k < romFile.byteLength) {
|
|
temp = romFile[k];
|
|
romFile[k] = romFile[k + 1];
|
|
romFile[k + 1] = temp;
|
|
k += 2;
|
|
}
|
|
break;
|
|
case 0x80371240:
|
|
break;
|
|
default:
|
|
print("Unhandled byte order.");
|
|
}
|
|
|
|
String res = StringUtils.dec2hex(fmt);
|
|
int len = romFile.byteLength;
|
|
print("swap done: byte order: 0x$res size=$len");
|
|
return romFile;
|
|
}
|
|
}
|