-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMU.cpp
More file actions
54 lines (42 loc) · 846 Bytes
/
Copy pathMMU.cpp
File metadata and controls
54 lines (42 loc) · 846 Bytes
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
#include <iostream>
#include <vector>
#include <stdexcept>
#include <string>
#include "MMU.h"
MMU::MMU() {
memory.resize(MEM_SIZE);
stack.resize(STACK_SIZE);
sp = 0;
// load fontset
for(int i=0; i<80; i++) {
set_mem(i, chip8_fontset[i]);
}
}
unsigned short MMU::pop(){
if(sp <= 0) {
// empty stack
return -1;
}
unsigned short addr = stack[sp];
sp -= 1;
return addr;
}
void MMU::push(unsigned short address){
if(sp == STACK_SIZE - 1) {
throw std::runtime_error("Stack overflow, sp @ "+std::to_string(sp));
}
stack[sp+1] = address;
sp += 1;
}
unsigned char MMU::get_mem_at(int mem_loc){
return this -> memory[mem_loc];
}
int MMU::get_real_mem_size(){
return MEM_SIZE - 512;
}
void MMU::set_mem(int address, unsigned char value) {
this -> memory[address] = value;
}
int MMU::get_mem_start(){
return 0x200;
}