Skip to content

Commit

Permalink
prompt for minimum firmware file, dynamic rom size
Browse files Browse the repository at this point in the history
  • Loading branch information
davervw committed May 11, 2024
1 parent eedfc86 commit 4cce368
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
9 changes: 5 additions & 4 deletions emucbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool EmuCBM::ExecuteJSR(ushort addr)
return true; // return value for ExecutePatch so will reloop execution to allow berakpoint/trace/ExecutePatch/etc.
}

void EmuCBM::File_ReadAllBytes(byte* bytes, unsigned int size, const char* filename)
unsigned EmuCBM::File_ReadAllBytes(byte* bytes, unsigned long size, const char* filename)
{
int file;
#ifdef WINDOWS
Expand All @@ -172,12 +172,13 @@ void EmuCBM::File_ReadAllBytes(byte* bytes, unsigned int size, const char* filen
exit(1);
}
#ifdef WINDOWS
_read(file, bytes, size);
unsigned bytes_read = _read(file, bytes, size);
_close(file);
#else
read(file, bytes, size);
unsigned bytes_read = read(file, bytes, size);
close(file);
#endif
#endif
return bytes_read;
}

static byte* OpenRead(const char* filename, int* p_ret_file_len)
Expand Down
2 changes: 1 addition & 1 deletion emucbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EmuCBM : public Emu6502

public:
static const char* StartupPRG;
static void File_ReadAllBytes(byte* bytes, unsigned int size, const char* filename);
static unsigned File_ReadAllBytes(byte* bytes, unsigned long size, const char* filename);

protected:
bool ExecutePatch();
Expand Down
27 changes: 21 additions & 6 deletions emumin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@

#include "emumin.h"

EmuMinimum::EmuMinimum(const char* filename, ushort ramsize, ushort romsize, ushort serialaddr)
: Emu6502(new MinimumMemory(filename, ramsize, romsize, serialaddr))
EmuMinimum::EmuMinimum(const char* filename, ushort serialaddr)
: Emu6502(new MinimumMemory(filename, serialaddr))
{
step = true;
printf("RAM=%d ROM=%d\n", ((MinimumMemory*)memory)->getramsize(), ((MinimumMemory*)memory)->getromsize());
}

EmuMinimum::~EmuMinimum()
Expand All @@ -65,15 +66,19 @@ void EmuMinimum::SetMemory(ushort addr, byte value)
memory->write(addr, value);
}

MinimumMemory::MinimumMemory(const char* filename, ushort ramsize, ushort romsize, ushort serialaddr)
MinimumMemory::MinimumMemory(const char* filename, ushort serialaddr)
{
this->ramsize = ramsize;
this->romsize = romsize;
this->serialaddr = serialaddr;
ram = new unsigned char[0x100000]; // allocate full 64K
memset(ram, 0, ramsize);
unsigned maxram = 0x10000;
ram = new unsigned char[maxram]; // allocate full 64K
memset(ram, 0, maxram);
romsize = EmuCBM::File_ReadAllBytes(ram, maxram, filename);
romaddr = (ushort)(0x10000 - romsize); // rom loads from end of memory, assumes sized correctly
EmuCBM::File_ReadAllBytes(&ram[romaddr], romsize, filename);
memmove_s(&ram[romaddr], romsize, ram, romsize);
ramsize = romaddr;
memset(ram, 0, ramsize);
}

MinimumMemory::~MinimumMemory()
Expand All @@ -99,3 +104,13 @@ void MinimumMemory::write(ushort addr, byte value)
else if (addr < ramsize)
ram[addr] = value;
}

unsigned MinimumMemory::getramsize()
{
return ramsize;
}

unsigned MinimumMemory::getromsize()
{
return romsize;
}
6 changes: 4 additions & 2 deletions emumin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class EmuMinimum : public Emu6502
{
public:
EmuMinimum(const char* filename, ushort ramsize, ushort romsize, ushort serialaddr);
EmuMinimum(const char* filename, ushort serialaddr);
virtual ~EmuMinimum();

protected:
Expand All @@ -24,10 +24,12 @@ class EmuMinimum : public Emu6502
class MinimumMemory : public Emu6502::Memory
{
public:
MinimumMemory(const char* filename, ushort ramsize, ushort romsize, ushort serialaddr);
MinimumMemory(const char* filename, ushort serialaddr);
virtual ~MinimumMemory();
virtual byte read(ushort addr);
virtual void write(ushort addr, byte value);
unsigned getramsize();
unsigned getromsize();

private:
byte* ram;
Expand Down
9 changes: 8 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ int main(int argc, char* argv[])
else if (main_go_num == -1)
emu = new EmuTest(EmuCBM::StartupPRG);
else if (main_go_num == 1)
emu = new EmuMinimum(EmuCBM::StartupPRG, 60 * 1024, 4096, 0xFFF8);
{
char buffer[256];

puts("Filename? ");
gets_s(buffer);

emu = new EmuMinimum(buffer, 0xFFF8);
}
else
emu = new EmuC64(64 * 1024);

Expand Down

0 comments on commit 4cce368

Please sign in to comment.