added the ability for the cpu to load in an array of bytes
This commit is contained in:
parent
64fbd28610
commit
26ea82204f
26
cpu.js
26
cpu.js
|
@ -6630,22 +6630,32 @@ window.CPU_65816 = function() {
|
|||
|
||||
/**
|
||||
* Load given program into memory and prepare for execution.
|
||||
* raw_hex could either be a string of hex numbers or an array
|
||||
* of bytes.
|
||||
*/
|
||||
this.load_binary = function(raw_hex, memory_location_start, bank) {
|
||||
var byte_buffer = [];
|
||||
var byte_buffer = [],
|
||||
i = 0;
|
||||
|
||||
if(typeof bank === "undefined") {
|
||||
bank = 0;
|
||||
}
|
||||
|
||||
for(var i = 0; i < raw_hex.length; i++) {
|
||||
byte_buffer.push(raw_hex.charAt(i));
|
||||
if(byte_buffer.length===2) {
|
||||
this.mmu.store_byte_long(memory_location_start, bank,
|
||||
parseInt(byte_buffer[0]+byte_buffer[1],
|
||||
16));
|
||||
if(typeof raw_hex === 'string') {
|
||||
for(;i < raw_hex.length; i++) {
|
||||
byte_buffer.push(raw_hex.charAt(i));
|
||||
if(byte_buffer.length===2) {
|
||||
this.mmu.store_byte_long(memory_location_start, bank,
|
||||
parseInt(byte_buffer[0]+byte_buffer[1],
|
||||
16));
|
||||
memory_location_start++;
|
||||
byte_buffer = [];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(;i < raw_hex.length; i++) {
|
||||
this.mmu.store_byte_long(memory_location_start, bank, raw_hex[i]);
|
||||
memory_location_start++;
|
||||
byte_buffer = [];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,6 +26,7 @@ function run_tests() {
|
|||
test_subroutines();
|
||||
test_mvn_and_mvp();
|
||||
test_emulation_mode();
|
||||
test_cpu_load_binary();
|
||||
}
|
||||
|
||||
function test_lda() {
|
||||
|
@ -1142,3 +1143,23 @@ function test_rep() {
|
|||
"register");
|
||||
});
|
||||
}
|
||||
|
||||
function test_cpu_load_binary() {
|
||||
test("Make sure that load binary can work with hex strings", function() {
|
||||
var cpu = new CPU_65816();
|
||||
cpu.load_binary("18fb", 0x8000);
|
||||
equal(cpu.mmu.memory[cpu.r.k][0x8000], 0x18,
|
||||
"$8000 should equal 0x18");
|
||||
equal(cpu.mmu.memory[cpu.r.k][0x8001], 0xfb,
|
||||
"$8001 should equal 0xfb");
|
||||
});
|
||||
|
||||
test("Make sure that load_binary can work with arrays", function() {
|
||||
var cpu = new CPU_65816();
|
||||
cpu.load_binary([0x18, 0xfb], 0x8000);
|
||||
equal(cpu.mmu.memory[cpu.r.k][0x8000], 0x18,
|
||||
"$8000 should equal 0x18");
|
||||
equal(cpu.mmu.memory[cpu.r.k][0x8001], 0xfb,
|
||||
"$8001 should equal 0xfb");
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue