dangermccann / dcpu16-ide

A DCPU-16 emulator and assembler written in Javascript
MIT License
30 stars 8 forks source link

Interrupts processed in wrong order. #19

Closed JeremyWildsmith closed 7 years ago

JeremyWildsmith commented 7 years ago

Sorry I am hounding these issues, I am looking for a particular reason why my interrupt handler for a game I am working on is not working and I run into these along the way :)

If you consider:

set pc, start

:interruptHandler
set a, a
set a, a
rfi a

:start
iaq 1
ias interruptHandler
int 1
int 2
iaq 0
set pc, simple

:simple
set pc, simple

The interrupt handler, if you place a breakpoint on it, will have 'a' equal to 2, and then 1. The interrupt queue is a queue (FIFO) not a stack (FILO). The error is in the below code:

step() {

        this.nextInstruction();

        // process one interrupt if we have one
        if (this.interruptQueueingEnabled == false && this.interruptQueue.length > 0) {
            this.processInterrupt(this.interruptQueue.pop());
        }

        return true;
    }

Rather than using pop, we should be using shift()

dangermccann commented 7 years ago

Thanks, I'll get it fixed.

Mind if I ask what game you're working on? Maybe it's something I can help with?

JeremyWildsmith commented 7 years ago

The game is based off of Space Station 13 (draws inspiration from it.) but the station / ships are controlled by computers that have a DCPU processor. I'm trying to get the "Station Control OS" working ( https://github.com/JeremyWildsmith/DCPUOS ) but right now I am experiencing some hiccups regarding threads getting stuck in a loop.

If you're interested, I'll let you know when I have a git repo up for the game :) I think the best I can do is just link you to an imgur page I have that describes the basics: http://imgur.com/a/20N2J

Maybe I should start a new issue and we can work on tracking down the issue with interrupts together? I've been stuck on it for about a week now but been fixing some small problems on the way to finding the source. The Kernel is written in 0x10c DevKit which, while not perfect, seems to conform the best to the standard so far (until we can get this emulator up to speed.)

dangermccann commented 7 years ago

Looks interesting...it would definitely be fun to team up. I do game development (mostly Unity) on the side and I'm looking for a new project to get involved in after publishing my first game on Steam (http://store.steampowered.com/app/499330/Lord_Mayor/). Maybe the best thing to do would be to move this conversation over to a PM thread on reddit (/u/mccannjp) or twitter (@dangermccann).

Regarding the interrupt issue, yeah open up a new ticket and we can work out the details there.

JeremyWildsmith commented 7 years ago

Sounds good. I'll hit you up on twitter and open a new issue occurring with that interrupt.

JeremyWildsmith commented 7 years ago

Hey, turns out this issue mentioned regarding interrupts in my previous comment was actually due a deadlock in my kernel... So it was my error not DCPU-IDE's