Example #1
0
Chip_INIT_RESULT Chip8EOSLogicN::ChipInit(void) {
    Chip_INIT_RESULT rtn = updataFPGA();
    if( rtn == succeed ) {
        initRegs();//temp test
    }
    return rtn;
}
Example #2
0
Registers::Registers()
{
	initRegs();
	initRegsFloat();
}
Example #3
0
// STARTER SCRIPT:
// 1. load 43 ('+') to R2
// 2. print contents of R2
// 3. load 1 into R1
// 4. terminate
//                |1        |2       |3       |4
// python bc.py "[0,2,43,0, 3,2,0,0, 0,1,1,0, 0,0,0,0]." > bytecode.txt 
int main(int argc, char** argv) {
    // Local variables:
    VMContext vm;
    Reg       r[16];
    FunPtr    funs[4];
    uint32_t  i;
    uint32_t* pc;      // Program-Counter (PC)

    // Bytecode-loading helper variables:
    FILE* bytecodeFile;
    char  buffer[256];

    // Load code:
    if(argc >= 1) {
        bytecodeFile = fopen(argv[1], "rb");
    } else {
        printf("USAGE: example [FILE]\n");
        return 1; // If no bytecode provided, bail out.
    }

    if(bytecodeFile == NULL) {
        printf("Could not load bytecode file \'%s\'.\n", argv[1]);
        return 1; // If a file read error happeneded, bail out.
    }

    // fread returns the number of bytes read; we don't need 
    // that info in this demo, however.
    fread((void*)&buffer, 1, 12, bytecodeFile);
    // Close what we opened
    fclose(bytecodeFile);
    
    // Initialize funptr table:
    funs[0] = loadNToReg;
    funs[1] = addReg;
    funs[2] = subReg;
    funs[3] = printReg;

    // Initialize registers:
    initRegs(r, 16);

    // Initialize vm context:
    initVMContext(&vm, 16, 4, r, funs);

    // Set Program Counter (PC) to start of opcode buffer:
    pc = (uint32_t*) &buffer;

    // Main loop:
    i = 0;
    while(r[1].value < 1) {
        printf("Running instr: %d -> '%d', '%d', '%d', '%d'\n", i, 
            EXTRACT_B0(*pc),
            EXTRACT_B1(*pc),
            EXTRACT_B2(*pc),
            EXTRACT_B3(*pc));

        stepVMContext(&vm, &pc);
        i++;
    }

    // Return 0 to indicate normal termination.
    return 0;
}