aboutsummaryrefslogtreecommitdiff
path: root/include/memory.h
blob: e7b97ee23e3817024b04d6b5c8d743bb321ea005 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* @file memory.h
* @author Paul Oliver
*
* This module gives access to Salis memory. You can check the state of each
* byte (instruction and flags) at any time and also perform manual memory
* manipulations.
*/

#ifndef SALIS_MEMORY_H
#define SALIS_MEMORY_H

#define IP_FLAG 0x80
#define BLOCK_START_FLAG 0x40
#define ALLOCATED_FLAG 0x20
#define INSTRUCTION_MASK 0x1f

void _sal_mem_init(uint32 order);
void _sal_mem_quit(void);
void _sal_mem_load_from(FILE *file);
void _sal_mem_save_into(FILE *file);

/** Get memory order.
* @return Order of memory (memory_size == 1 << order)
*/
SALIS_API uint32 sal_mem_get_order(void);

/** Get memory size.
* @return Size of memory (memory_size == 1 << order)
*/
SALIS_API uint32 sal_mem_get_size(void);

/** Get amount of addresses with the IP flag set on them.
* @return Amount of addresses with the IP flag set
*/
SALIS_API uint32 sal_mem_get_ip_count(void);

/** Get amount of addresses with the memory-block-start flag set on them.
* @return Amount of addresses with the memory-block-start flag set
*/
SALIS_API uint32 sal_mem_get_block_start_count(void);

/** Get amount of addresses with the allocated flag set on them.
* @return Amount of addresses with the allocated flag set
*/
SALIS_API uint32 sal_mem_get_allocated_count(void);

/** Get memory capacity.
* @return Memory capacity (capacity == size / 2)
*/
SALIS_API uint32 sal_mem_get_capacity(void);

/** Get amount of addresses with a given instruction written on them.
* @param inst Instruction whose amount we want to count
* @return Amount of addresses with given instruction
*/
SALIS_API uint32 sal_mem_get_inst_count(uint8 inst);

/** Determine if memory is above its capacity.
* @return Memory is above capacity
*/
SALIS_API boolean sal_mem_is_over_capacity(void);

/** Check validity of address.
* @param address Address being queried
* @return Validity of address (validity == address < size)
*/
SALIS_API boolean sal_mem_is_address_valid(uint32 address);

/** Check if given address has the IP flag set.
* @param address Address being queried
* @return IP flag is set on this address
*/
SALIS_API boolean sal_mem_is_ip(uint32 address);

/** Check if given address has the memory-block-start flag set.
* @param address Address being queried
* @return Memory-block-start flag is set on this address
*/
SALIS_API boolean sal_mem_is_block_start(uint32 address);

/** Check if given address has the allocated flag set.
* @param address Address being queried
* @return Allocated flag is set on this address
*/
SALIS_API boolean sal_mem_is_allocated(uint32 address);

void _sal_mem_set_ip(uint32 address);
void _sal_mem_set_block_start(uint32 address);
void _sal_mem_set_allocated(uint32 address);
void _sal_mem_unset_ip(uint32 address);
void _sal_mem_unset_block_start(uint32 address);
void _sal_mem_unset_allocated(uint32 address);

/** Get currently set flags at given address.
* @param address Address being queried
* @return Byte containing set flag bits
*/
SALIS_API uint8 sal_mem_get_flags(uint32 address);

/** Get current instruction at address.
* @param address Address being queried
* @return Instruction currently written at address
*/
SALIS_API uint8 sal_mem_get_inst(uint32 address);

/** Write instruction into address.
* @param address Address being set
* @param inst Instruction to write at given address
*/
SALIS_API void sal_mem_set_inst(uint32 address, uint8 inst);

/** Get current byte at address.
* @param address Address being queried
* @return Byte currently written at address (includes bit flags & instruction)
*/
SALIS_API uint8 sal_mem_get_byte(uint32 address);

/** Render a 1D image of a given block of memory. This is useful, as rendering
* directly in python would be too slow. We use openmp for multi-threaded image
* generation.
*
* @param origin Low bound of rendered image
* @param cell_size Amount of bytes per rendered pixel (cell)
* @param buff_size Amount of pixels (cells) to be generated
* @param buffer Pre-allocated buffer to store the rendered pixels into
*/
SALIS_API void sal_mem_render_image(
	uint32 origin, uint32 cell_size, uint32 buff_size, uint8_p buffer
);

void _sal_mem_cycle(void);

#endif