void test6502_65c02Instruction(const char* pInstruction, const char* pInstructionTableEntry)
    {
        m_switchTo65c02 = FALSE;
        testInstruction(pInstruction, pInstructionTableEntry);

        m_switchTo65c02 = TRUE;
        testInstruction(pInstruction, pInstructionTableEntry);
    }
    void test65c02OnlyInstruction(const char* pInstruction, const char* pInstructionTableEntry)
    {
        m_isInvalidInstruction = TRUE;
        m_switchTo65c02 = FALSE;
        testInstruction(pInstruction, pInstructionTableEntry);

        m_isInvalidInstruction = FALSE;
        m_switchTo65c02 = TRUE;
        testInstruction(pInstruction, pInstructionTableEntry);
    }
Esempio n. 3
0
void main(int argc, char *argv[]){

    char *filename = argv[1];
    FILE *fp;

    if(strcmp(filename, "-s") == 0){
        testStack();
        exit(0);
    }
    if(strcmp(filename, "-t") == 0){
        testTable();
        exit(0);
    }
    if(strcmp(filename, "-i") == 0){
        testInstruction();
        exit(0);
    }


    if(argc == 1){
        printf("Proper use: wi <filename.wic>\n");
        exit(0);
    }
    else if((fp = fopen(filename, "r")) == NULL)
    {
        printf("Error opening file.  File doesn't exist.\n");
        exit(0);
    }
    
    initialize();

    char opcode[OPCODE_SIZE];
    char operand[OPERAND_SIZE];
    int address = 0;
    while(fscanf(fp, "%s", opcode) != EOF){
        if(hasOperand(opcode)){
            if(fscanf(fp, "%s", operand) == EOF){
                insertInstruction(address, opcode, operand);
                address++;
                break;
            }
        }
        if(!validOp(opcode)){
            if(fscanf(fp, "%s", operand) != EOF && strcmp(operand, "label") == 0){
                char temp[OPERAND_SIZE];
                strcpy(temp, operand);
                strcpy(operand, opcode);
                strcpy(opcode, temp);
            }
            else{
                printf("Invalid opcode: %s\n", opcode);
                exit(0);
            }
        }
        else if(hasOperand(opcode) == 0){
            strcpy(operand, "");
        }
        insertInstruction(address, opcode, operand);
        address++;
        //discard the rest of the line
        while(fgetc(fp) != '\n'){};
    }
    fclose(fp);

    runProgram();
}