-
Notifications
You must be signed in to change notification settings - Fork 8
/
emumin.cpp
126 lines (111 loc) · 3.38 KB
/
emumin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// minimum.cpp - Minimal 6502 platform
//
// variable RAM, variable ROM, memory mapped Motorola 8250 compatible UART
//
////////////////////////////////////////////////////////////////////////////////
//
// c-simple-emu-cbm (C++ Portable Version)
// C64/6502 Emulator for Microsoft Windows Console
//
// MIT License
//
// Copyright (c) 2024 by David R. Van Wagner
// davevw.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////
#include "emucbm.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "emumin.h"
extern int main_go_num;
EmuMinimum::EmuMinimum(const char* filename, ushort serialaddr, bool line_editor)
: Emu6502(new MinimumMemory(filename, serialaddr, line_editor))
{
printf("RAM=%d ROM=%d\r\n", ((MinimumMemory*)memory)->getramsize(), ((MinimumMemory*)memory)->getromsize());
}
EmuMinimum::~EmuMinimum()
{
}
bool EmuMinimum::ExecutePatch()
{
if (main_go_num != 1)
quit = true;
return false;
}
byte EmuMinimum::GetMemory(ushort addr)
{
return memory->read(addr);
}
void EmuMinimum::SetMemory(ushort addr, byte value)
{
memory->write(addr, value);
}
MinimumMemory::MinimumMemory(const char* filename, ushort serialaddr, bool line_editor)
{
uart = new MC6850(line_editor);
this->ramsize = ramsize;
this->romsize = romsize;
this->serialaddr = serialaddr;
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
#ifdef WINDOWS
memmove_s(&ram[romaddr], romsize, ram, romsize);
#else
memmove(&ram[romaddr], ram, romsize);
#endif
ramsize = romaddr;
memset(ram, 0, ramsize);
}
MinimumMemory::~MinimumMemory()
{
delete[] ram;
}
byte MinimumMemory::read(ushort addr)
{
if (addr == serialaddr)
return uart->read_data();
if (addr == serialaddr + 1)
return uart->read_status();
return ram[addr];
}
void MinimumMemory::write(ushort addr, byte value)
{
if (addr == serialaddr)
uart->write_data(value);
else if (addr == serialaddr + 1)
uart->write_control(value);
else if (addr < ramsize)
ram[addr] = value;
else if (addr == 0xFFFF)
main_go_num = value;
}
unsigned MinimumMemory::getramsize()
{
return ramsize;
}
unsigned MinimumMemory::getromsize()
{
return romsize;
}