coder36 / bytepusher4j

Bytepusher for java
2 stars 2 forks source link

Cannot execute more than 65536 instructions #2

Open blakewford opened 11 years ago

blakewford commented 11 years ago

Here is my version of BytePusherVM.java

Added ---> private int pc = 0; <--- public BytePusherVM(BytePusherIODriver ioDriver) { this.ioDriver = ioDriver; }

/**
 * Load ROM into memory
 * @param rom
 */
public void load(InputStream rom) throws IOException {
    for ( int i=0; i < mem.length; i++ ) {
        mem[i] = 0;
    }
    int i = 0;

<---Removed line while ((i = rom.read()) != -1) { mem[pc++] = (char)i; } Added --->
pc = getVal(2, 3); <--- }

/**
 * CPU loop, to be called every 60th of a second
 */
public void run() {
    // run 65536 instructions
    short s = ioDriver.getKeyPress();
    mem[0] = (char) ((s & 0xFF00) >> 8);
    mem[1] = (char) (s & 0xFF);

<----Removed Line int i = 0x10000; while (i-- != 0) { mem[getVal(pc + 3, 3)] = mem[getVal(pc, 3)]; pc = getVal(pc + 6, 3); }

This allows the pc to continue updating after 0x10000 instructions I have an example .bytepusher file, but I cannot find a way to attach it.

coder36 commented 11 years ago

Hi Blake... sorry for the slow replies - I'm working away and have little down time at the moment. Okay, I'm not 100% clear on what the issue is. Please could you email me the ,bytepusher file (markymiddleton@gmail.com) and I'll investigate?

Looking at the spec, the Outer loop says:

  1. Fetch the 3-byte program counter from address 2, and execute exactly 65536 instructions.

BTW if you are into writing virtual machines take a look at the programming contest: http://www.boundvariable.org/task.shtml for an awesome puzzle. This is what got me interested in the whole virtual machine thing. It's a bit awkward to do in java, but in C# I absolutely nailed it. I came up with a really elegant solution. I think a nice solution could be done in Ruby (this'll be my next challenge!). What about an android version ? or even a .bytepusher version!!!

olvws commented 11 years ago

I realized sometime later that my implementation broke the existing roms. This makes me sad, because the work I am doing with BytePusher requires a lot more code than graphics or audio resources. I want the pc to never be arbitrarily reset to 0. I am going to take this up with Javamannen and possibly fork.

blakewford commented 11 years ago

Hey man,

So I've been thinking of a way around my blocker, and I'd like the ability to do some DMA in conjunction with the standard Byte Pusher runtime. Any issues with adding a public accessor method to the VM class for the mem block?