coding the addressing modes

This commit is contained in:
Thiago Auler 2017-11-13 17:39:10 -02:00
parent 2cb3f865a8
commit 4ced079268
3 changed files with 45 additions and 21 deletions

View File

@ -100,7 +100,6 @@ void execute()
case TXA: return txa(); case TXA: return txa();
case TXS: return txs(); case TXS: return txs();
case TYA: return tya(); case TYA: return tya();
case XXX: return xxx();
} }
switch (opcode_in_table) switch (opcode_in_table)
@ -128,7 +127,6 @@ void execute()
case STA: return sta(); case STA: return sta();
case STX: return stx(); case STX: return stx();
case STY: return sty(); case STY: return sty();
case XXX: return xxx();
} }
} }

View File

@ -53,7 +53,6 @@ typedef enum address_mode am;
am address_mode; am address_mode;
void xxx(); // invalid opcode
void adc(); // add memory to accumalator with carry void adc(); // add memory to accumalator with carry
void and(); // and memory with accumulator void and(); // and memory with accumulator
void asl(); // shift left one bit (memory on accumulator) void asl(); // shift left one bit (memory on accumulator)

View File

@ -1,43 +1,70 @@
#include "inc/opcodes.h" #include "inc/opcodes.h"
#include "inc/memory.h" #include "inc/memory.h"
db fetch_operand() dw address;
{ db operand;
db operand;
void fetch_operand()
{
switch (address_mode) switch (address_mode)
{ {
case immediate: case immediate:
operand = read_byte(pc); address = pc;
operand = read_byte(address);
pc = pc + 1; pc = pc + 1;
break; break;
case zero_page: case zero_page:
operand = read_byte(pc); address = read_byte(pc);
operand = read_byte(operand); operand = read_byte(address);
pc = pc + 1; pc = pc + 1;
break; break;
case zero_page_x: case zero_page_x:
operand = read_byte(pc); address = read_byte(pc);
operand = read_byte(operand + x); address = address + x;
operand = read_byte(address);
pc = pc + 1; pc = pc + 1;
break; break;
case zero_page_y: case zero_page_y:
operand = read_byte(pc); address = read_byte(pc);
operand = read_byte(operand + y); address = address + y;
operand = read_byte(address);
pc = pc + 1; pc = pc + 1;
break; break;
case accumulator: case accumulator:
address = pc;
operand = ac; operand = ac;
break; break;
case absolute:
address = read_word(pc)
operand = read_byte(address);
pc = pc + 2;
case absolute_x:
address = read_word(pc);
address = address + x;
operand = read_byte(address);
pc = pc + 2;
break;
case absolute_y:
address = read_word(pc);
address = address + y;
operand = read_byte(address);
pc = pc + 2;
break;
case indirect_x:
address = read_byte(pc);
address = address + x;
address = read_word(address);
operand = read_byte(address);
pc = pc + 1;
break;
case indirect_y:
address = read_byte(pc);
address = read_word(address);
address = address + y;
operand = read_byte(address);
pc = pc + 1;
break;
} }
return operand;
}
void xxx()
{
// invalid opcode
return nop();
} }
void adc() void adc()