Skip to content

Commit

Permalink
scaffolding for single byte and jump instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
tnibert committed Nov 10, 2019
1 parent abf3e94 commit a7713ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
22 changes: 22 additions & 0 deletions decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,28 @@ int InstructionDecoder::decode_and_execute(uint8_t opcode)
printf("In decode and execute: op: %x, pc: %x\n", opcode, cpu->pc);

// todo: single byte instructions
if((opcode & 0x8) == 0x8) // 0b1000
{

}
else if((opcode & 0xA) == 0xA) // 0b1010
{

}

// todo: BRK, JSR abs, RTI, RTS
switch(opcode)
{
case 0x0: // BRK
break;
case 0x20: // JSR abs
break;
case 0x40: // RTI
break;
case 0x60: // RTS
break;
}


// The conditional branch instructions all have the form xxy10000
// they use relative addressing
Expand All @@ -43,6 +64,7 @@ int InstructionDecoder::decode_and_execute(uint8_t opcode)
}
}
// form aaabbbcc instruction
// todo: perhaps make this more specific than just else
else
{
decode_aaabbbcc(opcode);
Expand Down
4 changes: 1 addition & 3 deletions runrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ int main(int argc, char**argv)
// create and init state machine
Famicom * nes = new Famicom(buffer);

/* engine to iterate through buffer,
call opcode->f() for each opcode passed in */

/* so this is iterating over the prgrom, which I believe contains the instructions... */
/* so this is iterating over the prgrom */
while (nes->getpc() < PRGROMSTART+nes->cart->prgromsize)
{
//printf("%x : %x\n", nes->getpc(), fsize);
Expand Down
7 changes: 6 additions & 1 deletion tests/systemtests.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ class TestDecoder : public CppUnit::TestFixture
void setUp();
void test_branching();
void test_aaabbbcc();
void test_singlebyte();
void test_singlebyte0x8();
void test_singlebyte0xa();
void test_brk();
void test_rti();
void test_jsrabs();
void test_rts();
};

CPPUNIT_TEST_SUITE_REGISTRATION( TestDecoder );
Expand Down

0 comments on commit a7713ef

Please sign in to comment.