-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmemdump.cpp
108 lines (95 loc) · 2.58 KB
/
memdump.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
//------------------------------------------------------------------
// Dump VCC memory for debugging purposes
// E J Jaquay 27sep24
//
// This file is part of VCC (Virtual Color Computer).
//
// VCC (Virtual Color Computer) is free software: you can redistribute
// it and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// VCC (Virtual Color Computer) is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VCC (Virtual Color Computer). If not, see
// <http://www.gnu.org/licenses/>.
//
//------------------------------------------------------------------
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include "defines.h"
#include "tcc1014mmu.h"
#include "memdump.h"
//---------------- private --------------------
// Path for dump file
char DumpFilePath[MAX_PATH]="VccDump";
// Get size of physical memory
int GetMemSize()
{
int MemSize[4]={0x20000,0x80000,0x200000,0x800000};
return MemSize[EmuState.RamSize & 3];
}
// Get current MMU registors
std::array<int,8> GetMmuRegs()
{
VCC::MMUState mmu = GetMMUState();
if (mmu.ActiveTask == 0)
return mmu.Task0;
else
return mmu.Task1;
// TODO adjust regs for ROM map
}
// Open dump file
int OpenDumpFile()
{
int oflag = _O_CREAT | _O_TRUNC | _O_RDWR | _O_BINARY;
int pmode = _S_IREAD | _S_IWRITE;
return _open(DumpFilePath,oflag,pmode);
}
// Get size of physical memory
// Dump some memory to file
void blockdump(int fd, unsigned char * ptr, int siz)
{
while (siz > 0) {
int cnt = _write(fd,ptr,siz);
if (cnt <= 0) break;
ptr += cnt;
siz -= cnt;
}
}
//---------------- public --------------------
// Set dump file path
void SetDumpPath(char * dumpfile)
{
if (strlen(dumpfile) > MAX_PATH) return;
strncpy(DumpFilePath,dumpfile,MAX_PATH);
return;
}
// Dump real memory
void MemDump(void)
{
int fd = OpenDumpFile();
unsigned char * ptr = Get_mem_pointer();
int siz = GetMemSize();
blockdump(fd,ptr,siz);
_close(fd);
}
// Dump CPU memory
void CpuDump(void)
{
std::array<int,8> regs = GetMmuRegs();
unsigned char * pmem = Get_mem_pointer();
int blk;
int fd = OpenDumpFile();
for (blk=0; blk<8; blk++) {
unsigned char * ptr = pmem + regs[blk] * 0x2000;
int siz = 0x2000;
blockdump(fd,ptr,siz);
}
_close(fd);
}