-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory.h
56 lines (39 loc) · 1.23 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
/* mem_c64.h - memory interface for C64 emulator */
/* by Brian Huffman 11-30-00 */
/* memory management is described on page 260 of the C64 PRG */
#ifndef MEMORY_H
#define MEMORY_H
#include <Arduino.h>
#define RAM_SIZE 1024
extern byte ram[RAM_SIZE];
#define mkWord(hi,lo) (((word)(hi) << 8) | (word)(lo))
/***************************************/
/* static inline function declarations */
/***************************************/
inline static byte mem_read_zero_page(byte address) {
return ram[address];
}
inline static word mem_read_zero_page_16(byte address) {
return mkWord(ram[address + 1], ram[address]);
}
inline static void mem_write_zero_page(byte address, byte value) {
ram[address] = value;
}
inline static byte stack_read(byte address) {
return (ram + 256)[address];
}
inline static word stack_read_16(byte address) {
return mkWord(stack_read(address + 1), stack_read(address));
}
inline static void stack_write(byte address, byte value) {
(ram+256)[address] = value;
}
/*****************************/
/* other function prototypes */
/*****************************/
extern void mem_reset();
// RAM: 0000 0xxx xxxx xxxx
// VIA1: 0001 1000 0000 xxxx
// VIA2: 0001 1100 0000 xxxx
// ROM: 11xx xxxx xxxx xxxx
#endif