Let's say I want to make a 6502 cpu core, so I have to make different variables for an accumulator, registers X, Y, flag status etc. and I come down with this:
Code: Select all
while (cycles_remaining > 0)
{
instruction = read_mem(PC);
PC++;
switch (instruction)
{
case 0xA9: //LDA #NN
reg_a = read_mem(PC);
PC++;
negative_flag = (reg_a & 0x80) != 0;
zero_flag = reg_a == 0;
cycles_remaining -= 3;
case 0xAA: //TAX
reg_x = reg_a;
cycles_remaining -= 2;
case 0x8A: //TXA
reg_a = reg_x;
cycles_remaining -= 2;
case 0x8D: //STA $nnnn
address_low = read_mem(PC);
PC++;
address_high = read_mem(PC);
PC++;
address = address_low + address_high * 0x100;
write_mem(address, reg_a);
cycles_remaining -= 4;
// more instructions etc.
}
}
Then I load the rom, Starts with PC=0, and just execute the functions according to the PC?
Another thing, what system would you think would be easy to emulate for a first try?
Thanks for all your replies