-
Notifications
You must be signed in to change notification settings - Fork 15
/
Memory.h
113 lines (97 loc) · 3.38 KB
/
Memory.h
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
/*
*--------------------------------------------------------------------
* Project: VM65 - Virtual Machine/CPU emulator programming
* framework.
*
* File: Memory.h
*
* Purpose: Prototype of Memory class and supporting data
* structures, constants, enumerations and macros.
*
* Date: 8/25/2016
*
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
*
* Contact: [email protected]
*
* License Agreement and Warranty:
This software is provided with No Warranty.
I (Marek Karcz) will not be held responsible for any damage to
computer systems, data or user's health resulting from use.
Please proceed responsibly and exercise common sense.
This software is provided in hope that it will be useful.
It is free of charge for non-commercial and educational use.
Distribution of this software in non-commercial and educational
derivative work is permitted under condition that original
copyright notices and comments are preserved. Some 3-rd party work
included with this project may require separate application for
permission from their respective authors/copyright owners.
*--------------------------------------------------------------------
*/
#ifndef MEMORY_H
#define MEMORY_H
#include "system.h"
#include "MemMapDev.h"
#define MAX_8BIT_ADDR 0xFFFF
#define MEM_PAGE_SIZE 0x100
#define ROM_BEGIN 0xD000
#define ROM_END 0xDFFF
#define MIN_ROM_BEGIN 0x0200
using namespace std;
namespace MKBasic {
class Memory
{
public:
Memory();
~Memory();
void Initialize();
unsigned char Peek8bit(unsigned short addr);
unsigned char Peek8bitImg(unsigned short addr);
unsigned short Peek16bit(unsigned short addr);
void Poke8bit(unsigned short addr, unsigned char val); // write to memory and call memory mapped device handle
void Poke8bitImg(unsigned short addr, unsigned char val); // write to memory image only
void SetCharIO(unsigned short addr, bool echo);
void DisableCharIO();
unsigned short GetCharIOAddr();
char GetCharIn();
char GetCharOut();
void EnableROM();
void DisableROM();
void SetROM(unsigned short start, unsigned short end);
void EnableROM(unsigned short start, unsigned short end);
unsigned short GetROMBegin();
unsigned short GetROMEnd();
bool IsROMEnabled();
int AddDevice(int devnum);
int DeleteDevice(int devnum);
void SetupDevice(int devnum, MemAddrRanges memranges, DevParams params);
void SetGraphDisp(unsigned short addr);
void DisableGraphDisp();
unsigned short GetGraphDispAddr();
void GraphDisp_ReadEvents();
void GraphDisp_Update();
bool GraphDispOp();
MemMapDev *GetMemMapDevPtr();
protected:
private:
unsigned char m8bitMem[MAX_8BIT_ADDR+1];
// array of device usage for each memory page
// this is performance optimization array that keeps values >= 0 under the
// indexes of memory pages where the memory mapped device is active or -1
// if there is no active device on given memory page
int mMemPageDev[MEM_PAGE_SIZE];
unsigned short mCharIOAddr;
bool mCharIOActive;
bool mIOEcho;
unsigned short mROMBegin;
unsigned short mROMEnd;
bool mROMActive;
vector<Device> mActiveDeviceVec; // active devices
MemMapDev *mpMemMapDev; // pointer to MemMapDev object
bool mGraphDispActive;
bool mDispOp;
unsigned char ReadCharKb(bool nonblock);
void PutCharIO(char c);
};
} // namespace MKBasic
#endif