Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed RESET functionality to emulate CPU behavior. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions 6502/6502Lib/src/private/m6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,23 +1139,18 @@ m6502::Word m6502::CPU::AddrIndirectY_6( s32& Cycles, const Mem& memory )
}


m6502::Word m6502::CPU::LoadPrg( const Byte* Program, u32 NumBytes, Mem& memory ) const
void m6502::CPU::LoadPrg( const Word LoadAddress, const Byte* Program, u32 NumBytes, Mem& memory ) const
{
Word LoadAddress = 0;
if ( Program && NumBytes > 2 )
{
u32 At = 0;
const Word Lo = Program[At++];
const Word Hi = Program[At++] << 8;
LoadAddress = Lo | Hi;
for ( Word i = LoadAddress; i < LoadAddress+NumBytes-2; i++ )
{
//TODO: mem copy?
memory[i] = Program[At++];
for ( Word i = 0; i < NumBytes; i++ )
{
memory[LoadAddress + i] = Program[i];
}
}

return LoadAddress;
// Set up the RESET vector
memory[0xFFFC] = LoadAddress & 0xFF;
memory[0xFFFD] = LoadAddress >> 8;
}

void m6502::CPU::PrintStatus() const
Expand Down
12 changes: 4 additions & 8 deletions 6502/6502Lib/src/public/m6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ struct m6502::CPU

void Reset( Mem& memory )
{
Reset( 0xFFFC, memory );
}

void Reset( Word ResetVector, Mem& memory )
{
PC = ResetVector;
Word StartAddress = memory[0xFFFC] | memory[0xFFFD] << 8;
PC = StartAddress;
SP = 0xFF;
Flag.C = Flag.Z = Flag.I = Flag.D = Flag.B = Flag.V = Flag.N = 0;
A = X = Y = 0;
Expand Down Expand Up @@ -418,8 +414,8 @@ struct m6502::CPU
Flag.N = (Register & NegativeFlagBit) > 0;
}

/** @return the address that the program was loading into, or 0 if no program */
Word LoadPrg( const Byte* Program, u32 NumBytes, Mem& memory ) const;
/** Load a Program into memory at the given LoadAddress and set up the RESET vector to that location. */
void LoadPrg( const Word LoadAddress, const Byte* Program, u32 NumBytes, Mem& memory ) const;

/** printf the registers, program counter etc */
void PrintStatus() const;
Expand Down
Loading