You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
Dear Homebrewers: Halt!
Posted on: 3/27 4:27
VUE(xpert)
Joined 2012/12/4
415 Posts
CoderLong Time User (6 Years)
While developing a Virtual Boy emulator in Java, I finally hit critical mass where the simulation was a little more demanding than my environment could process in time. Sometimes this would happen when using breakpoints, but it came out in force after implementing audio, and that's no fun. I have an idea of what to do about it, so don't worry about me... You've got your own things to worry about!

tl;dr: if you're developing for Virtual Boy, use the HALT instruction.

When your program needs to wait for an interrupt to occur, it's common practice to check on a global variable until an interrupt handler comes along and changes that variable. This works, but is not recommended because the CPU is busy chugging away wasting time. Even worse, it's wasting power, which is kind of a deal on Virtual Boy with its six AA batteries. Worst of all, it's slowing down my emulator!

The better way to wait for interrupts is with a dedicated CPU instruction called HALT. This instruction suspends CPU activity entirely until some external component (such as the video processor) requests an interrupt, at which point the CPU comes back to life and handles the request. Power isn't consumed for spin waiting this way, and no processing takes place until the interrupt does its job.

If your development tools don't provide ready access to the HALT instruction in your programs, you can access it yourself with this simple yet janky C function:


void halt
() {
    static const 
long code 0x181F6800L;
    ((
void(*)())&code)();
}

Use the HALT instruction any place where you need to wait for an interrupt and don't have anything else to process while doing so. This will ensure better performance in emulation efforts going forward as well as make the world a better place in general...
Top

 Top   Previous Topic   Next Topic


Register To Post