代码之家  ›  专栏  ›  技术社区  ›  butchtiki

确定中断例程何时结束Gameboy GB仿真

  •  1
  • butchtiki  · 技术社区  · 7 年前

    因此,关于背景,我想让你们知道到目前为止我所了解的情况:

    • 中断处理由几个“中断例程”组成(对于gameboy,它有Vblank、LCD stat、计时器、操纵台和串行)。

    • 中断程序有优先权(与我的问题无关)。

    • 必须有 开始和结束

    中断例程的结束,在处理中断之前,该例程应弹出下一条指令的地址。

    我想知道:

    • 只有

    • 它使用REI而不是ret,因为我们希望断言ime标志仍处于启用状态,因此可以继续检查是否需要提供任何其他中断,

    编辑:

    所以为了给我的问题提供更多的背景,我决定发布我的指令周期代码。

    #include "InteruptHandler.c"
    void main(){
        while(){ //No proper argument yet. for fetch-decode-execute cycle
        opcode = fetchInstruction();
        decodeandExecuteInstruction(opcode); //Lets say an instruction is executed and it enabled the IME_flag. that is IME_flag = ENABLED
    
        //Check if ime_flag is enabled. processInterupt if true.
        isInteruptEnabled() ? processInterupts(): 0; //This would fall true.
        }
    }
    

    在InteruptHandler.c中

    processInterupts(){
    
        opcode;
        bitmask = 0x01;
    
        //Check each bit for interupt. Bitmask will go 0x00 if the value 0x80 is shifted by 1
        for(; bitmask ; bitmask = bitmask << 1){
    
            //CHeck if IE and IF flag for corresponding interupt is set. process interupt if set
            IE_flag & bitmask ? (IF_flag & bitmask ? determineInterupt(bitmask) : 0) : 0; 
        }
    }
    
    determineInterupt(bitmask){
    
        //push the next instruction address to stack pointer
        push(PC);
    
        //Set PC into corresponding interupt address
    
    //code below is my problem. I stumbled upon how would I end this function and I came up to determining when an interupt routine ends. 
    //I came up with the reti function. 
    //But after realizing that I already set the PC somewhere above this code, I just need to discard this code and let the main function do its instruction cycling. 
    //Thanks to @duskwuff for pointing that out. 
    //I just added some code to end the bitmask checking when it sees 1 interupt request and is most priotiry. 
    //Also thanks to @Ped7g for giving me more information about the complexity of interupt handling. I'm not yet seeing where I should implement those. There are still so many thing to implement and yet to know when this excatly can happen.
    //My question has been answered nevertheless, which is to end a function code blocks that I discarded at the end :)
    
    //process the corresponding interupt
        do{
            opcode = fetchInstruction();
            decodeandexecuteInstruction(opcode);
        }while (opcode != RETI)
    }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   user149341 user149341    7 年前

    这不是真的。您不应该对内存中的代码布局做出任何假设——只需运行遇到的指令。

    之前 返回以允许同时处理另一个中断。您的设计应该考虑到这一点。

    不。REI指令在返回时可重入中断——它实际上是EI和RET的组合。不涉及断言。

    推荐文章