Ejemplo n.º 1
0
int main(void)
{
	char machine_code[40];
	char Username[40];
	char Serial[40];

	atexit(exitfun);
	printf("%s", Directions);
	getMachineCode(machine_code);
	printf("%s%s\n", MachineHint, machine_code);

	printf("%s", NameHint);
	scanf_s("%s", Username, sizeof(Username));

	printf("%s", SerialHint);
	scanf_s("%s", Serial, sizeof(Serial));

	switch (VerifyUsername(Username, Serial))
	{
	case ERROR_UNIDENTIFIED_ERROR:
		printf("Undefinded Failure.\n");
		break;

	default:
	case ERROR_ACCESS_DENIED:
		printf("%s\n", SerialCheckFailed);
		break;

	case ERROR_SUCCESS:
		printf("%s\n", SerialCheckPassed);
		break;
	}
	return 0;
}
Ejemplo n.º 2
0
void determineInstruction(char argument[], char instruction[]) {
    uint8_t byteInstruction;
    uint8_t byteArgument1;
    uint8_t byteArgument2 = NULL;

    int i = 0;
    char c = instruction[i];
    bool isLabel = false;

    while(c != '\0') {

        if(c == ':') {
            isLabel = true;
            instruction[i] = '\0';
            c = instruction[i];
        } else {
            c = instruction[++i];
        }

    }

    if(!isLabel) {
        int secondByteUsed = 0;
        int noArgument = 0;

        if (strlen(argument) < 1) {
            byteInstruction = getMachineCode(instruction, IMPLIED);

            noArgument = 1;
        }
            //FORMAT: LDA #$XX
        else if (argument[0] == '#') {
            char byte[3];
            char high = argument[2];
            char low = argument[3];

            byte[0] = high;
            byte[1] = low;
            byte[2] = '\0';

            byteArgument1 = stringToByte(byte);
            byteInstruction = getMachineCode(instruction, IMMEDIATE);

//        printf("Instruction used: %02x\n", byteInstruction);
//        printf("Value to load in accumulator: %02x\n\n", byteArgument1);
        }
            //FORMAT: STA $XXXX OR STA $XX
        else if (argument[0] == '$') {
            //if argument is 4 digits (0x0000)
            if(strlen(argument) > 3) {
                //need to get two memory locations here instead of just one
                char byteHigh[3];
                char byteLow[3];

                //get first part of the memory address
                char high = argument[1];
                char low = argument[2];
                byteHigh[0] = high;
                byteHigh[1] = low;

                high = argument[3];
                low = argument[4];
                byteLow[0] = high;
                byteLow[1] = low;

                byteLow[2] = '\0';
                byteHigh[2] = '\0';

                //little endian, low comes first
                byteArgument1 = stringToByte(byteLow);
                byteArgument2 = stringToByte(byteHigh);
                byteInstruction = getMachineCode(instruction, ABSOLUTE);

                secondByteUsed = 1;
            }
                //if argument is 2 digits (0x00) for zero page, etc.
            else {
                char byte[3];
                char high = argument[1];
                char low = argument[2];
                byte[0] = high;
                byte[1] = low;
                byte[2] = '\0';

                byteArgument1 = stringToByte(byte);
                byteInstruction = getMachineCode(instruction, ZEROPAGE);

                secondByteUsed = 0;
            }

        }
        else if (argument[0] == '(') {
            printf("new addressing shit pt 2\n\n");
        }
//        else if (argument[0] == 'A') {
//            printf("new addressing shit pt 3\n\n");
//        }
        else {
            //this is a label
            for(int i = 0; i < labelIterator; i++) {
                if(labels[i] == argument) {
                    uint8_t currentPC = programCounter;

                    //we have the location of where the label should start
                    //we need an offset from the next instruciton to that location
                    //so we increase programCounter by 2 (1 for this instruction, 1 for this argument)
                    //then subtract the location of the label from the program counter
                    //we now have the offset
                    //subtract offset from 256 now
                    currentPC += 2;
                    uint8_t location = labelLocations[i];
                    uint8_t offset = currentPC - location;

                    byteArgument1 = 256 - offset;
                    printf('test');
                }
            }
        }

        loadMemory(secondByteUsed, noArgument, byteInstruction, byteArgument1, byteArgument2);
    } else {
        //get the location of the next instruction to be executed
        uint8_t memoryLocation = programCounter + 1;
        labels[labelIterator] = instruction;
        labelLocations[labelIterator] = memoryLocation;
        labelIterator += 1;
    }
}