Repository navigation
Expand file tree
/
Copy pathsram.c
More file actions
91 lines (84 loc) · 2.21 KB
/
Copy pathsram.c
File metadata and controls
91 lines (84 loc) · 2.21 KB
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
/*
* sram.c
*
* P/EMU - P/ECE Emulator
* Copyright (C) 2003 Naoyuki Sawa
*
* * Mon Apr 14 00:00:00 JST 2003 Naoyuki Sawa
* - 作成開始。
*/
#include "app.h"
/****************************************************************************
* グローバル変数
****************************************************************************/
//SRAM sram;
/****************************************************************************
* グローバル関数
****************************************************************************/
void sram_init(PIEMU_CONTEXT* context)
{
/* メモリ割り当て。 */
memset(&context->sram, 0, sizeof context->sram);
context->sram.mem_size = context->emu.sysinfo.sram_end - context->emu.sysinfo.sram_top;
context->sram.mem = (unsigned char*)calloc(context->sram.mem_size, 1);
}
int sram_read(PIEMU_CONTEXT* context, unsigned ofs, int size)
{
ofs &= context->sram.mem_size - 1;
switch (size) {
case 1:
return READ_MEM_B(context->sram.mem + ofs);
case 2:
return READ_MEM_H(context->sram.mem + ofs);
case 4:
return READ_MEM_W(context->sram.mem + ofs);
}
DIE();
return -1; /* 警告抑制 */
}
void sram_write(PIEMU_CONTEXT* context, unsigned ofs, int data, int size)
{
ofs &= context->sram.mem_size - 1;
switch (size) {
case 1:
*(char*)&context->sram.mem[ofs] = data;
return;
case 2:
*(short*)&context->sram.mem[ofs] = data;
return;
case 4:
*(int*)&context->sram.mem[ofs] = data;
return;
}
DIE();
}
IOHANDLER_R(sram, B)
{
ofs &= context->sram.mem_size - 1;
return READ_MEM_B(context->sram.mem + ofs);
}
IOHANDLER_W(sram, B)
{
ofs &= context->sram.mem_size - 1;
*(char*)&context->sram.mem[ofs] = data;
}
IOHANDLER_R(sram, H)
{
ofs &= context->sram.mem_size - 1;
return READ_MEM_H(context->sram.mem + ofs);
}
IOHANDLER_W(sram, H)
{
ofs &= context->sram.mem_size - 1;
*(short*)&context->sram.mem[ofs] = data;
}
IOHANDLER_R(sram, W)
{
ofs &= context->sram.mem_size - 1;
return READ_MEM_W(context->sram.mem + ofs);
}
IOHANDLER_W(sram, W)
{
ofs &= context->sram.mem_size - 1;
*(int*)&context->sram.mem[ofs] = data;
}