-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpu_mos6502_io_mem.h
80 lines (65 loc) · 2.37 KB
/
cpu_mos6502_io_mem.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
/**
* Copyright (C) 2016. Joo, Young Jin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/**
* Project Name : KIM-1 on Arduino (clone of KIM Uno)
*
* Project Description :
*
* Comments : tabstop = 8, shiftwidth = 8, noexpandtab
*/
/**
* File Name : cpu_mos6502_io_mem.h
*
* File Description :
*
* Author : Joo, Young Jin <[email protected]>
* Dept : Raccoon's Cave
* Created Date : 18/Sep/2016
* Version : Baby-Raccoon
*/
#ifndef __CPU_MOS6502_IO_MEM_H__
#define __CPU_MOS6502_IO_MEM_H__
#define __cpu_mos6502_io_mem_if_in(__base, __size, __addr) \
if (((__addr) >= (__base)) && \
((__addr) <= ((__base) + ((__size) - 1))))
#define __cpu_mos6502_io_mem_read_pgm(__base, __ptr, __addr) \
pgm_read_byte((const uint8_t *)__ptr + ((__addr) - (__base)))
#define __cpu_mos6502_io_mem_read_pgm_if_in(__base, __size, __ptr, __addr) \
do { \
__cpu_mos6502_io_mem_if_in((__base), (__size), (__addr)) \
return __cpu_mos6502_io_mem_read_pgm(__base, __ptr, __addr); \
} while (0)
#define __cpu_mos6502_io_mem_write_pgm(__base, __ptr, __addr, __data)
#define __cpu_mos6502_io_mem_write_pgm_if_in(__base, __size, __ptr, __addr, \
__data) \
do { \
__cpu_mos6502_io_mem_if_in((__base), (__size), (__addr)) { \
__cpu_mos6502_io_mem_write_pgm(__base, __ptr, __addr, __data); \
return; \
} \
} while (0)
#define __cpu_mos6502_io_mem_read_ram(__base, __ptr, __addr) \
((uint8_t *)(__ptr))[((__addr) - (__base))]
#define __cpu_mos6502_io_mem_read_ram_if_in(__base, __size, __ptr, __addr)\
do { \
__cpu_mos6502_io_mem_if_in((__base), (__size), (__addr)) \
return __cpu_mos6502_io_mem_read_ram(__base, __ptr, __addr); \
} while (0)
#define __cpu_mos6502_io_mem_write_ram(__base, __ptr, __addr, __data) \
((uint8_t *)(__ptr))[((__addr) - (__base))] = __data
#define __cpu_mos6502_io_mem_write_ram_if_in(__base, __size, __ptr, __addr, \
__data) \
do { \
__cpu_mos6502_io_mem_if_in((__base), (__size), (__addr)) { \
__cpu_mos6502_io_mem_write_ram(__base, __ptr, __addr, __data); \
return; \
} \
} while (0)
uint8_t cpu_mos6502_read_io_mem(uint16_t addr);
void cpu_mos6502_write_io_mem(uint16_t addr, uint8_t data);
#endif /* __CPU_MOS6502_IO_MEM_H__ */