目标:
了解GameBoy的大致硬件组成和模拟器代码结构
模拟游戏卡带和基本功能与结构,加载gb游戏文件,进行初步的解析校验
了解CPU的工作流程,实现基础的CPU指令、CPU寻址模式
实现CPU的基本工作流程,实现指令的读取、分析与执行 :取opcode并解析为指令、按指令对应的寻址方式读取所需数据、运行该指令
涉及到的概念:
卡带:cartridge
总线:bus
内存:memory
内存映射:memory map
中央处理器:CPU (Central Processing Unit)
指令:instruction
寻址模式:addressing mode
操作码: opcode
寄存器:register
知识点
测试效果
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
$ gbemu/gbemu ../../roms/dmg-acid2.gb
Opened: ../../roms/dmg-acid2.gb
Cartridge Loaded:
Title : DMG-ACID2
Type : 00 ( ROM ONLY)
ROM Size : 32 KB
RAM Size : 00
LIC Code : 00 ( None)
ROM Vers : 00
Checksum : 9F ( PASSED)
Cart loaded..
SDL INIT
TTF INIT
Execute Instruction: 00 PC: 0001
Not executing yet
Execute Instruction: 00 PC: 0002
Not executing yet
Execute Instruction: 00 PC: 0003
Not executing yet
Execute Instruction: 00 PC: 0004
Not executing yet
Execute Instruction: 00 PC: 0005
Not executing yet
Execute Instruction: 00 PC: 0006
Not executing yet
Execute Instruction: 00 PC: 0007
Not executing yet
Execute Instruction: 00 PC: 0008
Not executing yet
Execute Instruction: 00 PC: 0009
Not executing yet
Execute Instruction: 00 PC: 000A
Not executing yet
Execute Instruction: 00 PC: 000B
Not executing yet
Execute Instruction: 00 PC: 000C
Not executing yet
Execute Instruction: 00 PC: 000D
Not executing yet
Execute Instruction: 00 PC: 000E
Not executing yet
Execute Instruction: 00 PC: 000F
Not executing yet
Execute Instruction: 00 PC: 0010
Not executing yet
Execute Instruction: 00 PC: 0011
Not executing yet
Execute Instruction: 00 PC: 0012
Not executing yet
Execute Instruction: 00 PC: 0013
Not executing yet
Execute Instruction: 00 PC: 0014
Not executing yet
Execute Instruction: 00 PC: 0015
Not executing yet
Execute Instruction: 00 PC: 0016
Not executing yet
Execute Instruction: 00 PC: 0017
Not executing yet
Execute Instruction: 00 PC: 0018
Not executing yet
Execute Instruction: 00 PC: 0019
Not executing yet
Execute Instruction: 00 PC: 001A
Not executing yet
Execute Instruction: 00 PC: 001B
Not executing yet
Execute Instruction: 00 PC: 001C
Not executing yet
Execute Instruction: 00 PC: 001D
Not executing yet
Execute Instruction: 00 PC: 001E
Not executing yet
Execute Instruction: 00 PC: 001F
Not executing yet
Execute Instruction: 00 PC: 0020
Not executing yet
Execute Instruction: 00 PC: 0021
Not executing yet
Execute Instruction: 00 PC: 0022
Not executing yet
Execute Instruction: 00 PC: 0023
Not executing yet
Execute Instruction: 00 PC: 0024
Not executing yet
Execute Instruction: 00 PC: 0025
Not executing yet
Execute Instruction: 00 PC: 0026
Not executing yet
Execute Instruction: 00 PC: 0027
Not executing yet
Execute Instruction: 00 PC: 0028
Not executing yet
Execute Instruction: 00 PC: 0029
Not executing yet
Execute Instruction: 00 PC: 002A
Not executing yet
Execute Instruction: 00 PC: 002B
Not executing yet
Execute Instruction: 00 PC: 002C
Not executing yet
Execute Instruction: 00 PC: 002D
Not executing yet
Execute Instruction: 00 PC: 002E
Not executing yet
Execute Instruction: 00 PC: 002F
Not executing yet
Execute Instruction: 00 PC: 0030
Not executing yet
Execute Instruction: 00 PC: 0031
Not executing yet
Execute Instruction: 00 PC: 0032
Not executing yet
Execute Instruction: 00 PC: 0033
Not executing yet
Execute Instruction: 00 PC: 0034
Not executing yet
Execute Instruction: 00 PC: 0035
Not executing yet
Execute Instruction: 00 PC: 0036
Not executing yet
Execute Instruction: 00 PC: 0037
Not executing yet
Execute Instruction: 00 PC: 0038
Not executing yet
Execute Instruction: 00 PC: 0039
Not executing yet
Execute Instruction: 00 PC: 003A
Not executing yet
Execute Instruction: 00 PC: 003B
Not executing yet
Execute Instruction: 00 PC: 003C
Not executing yet
Execute Instruction: 00 PC: 003D
Not executing yet
Execute Instruction: 00 PC: 003E
Not executing yet
Execute Instruction: 00 PC: 003F
Not executing yet
Execute Instruction: 00 PC: 0040
Not executing yet
Execute Instruction: 00 PC: 0041
Not executing yet
Execute Instruction: 00 PC: 0042
Not executing yet
Execute Instruction: 00 PC: 0043
Not executing yet
Execute Instruction: 00 PC: 0044
Not executing yet
Execute Instruction: 00 PC: 0045
Not executing yet
Execute Instruction: 00 PC: 0046
Not executing yet
Execute Instruction: 00 PC: 0047
Not executing yet
Execute Instruction: 00 PC: 0048
Not executing yet
Unkown Instruction E9
可以看到:成功加载了游戏的镜像文件,解析出了游戏相关信息,CPU的程序计数器PC在按预期自增。
这证明卡带读取、校验和数据传输功能正常,CPU结构和功能正常。如果手动调整PC从0x100开始,则可以读取到更多的正常指令,比如C3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ gbemu/gbemu ../../roms/dmg-acid2.gb
Opened: ../../roms/dmg-acid2.gb
Cartridge Loaded:
Title : DMG-ACID2
Type : 00 ( ROM ONLY)
ROM Size : 32 KB
RAM Size : 00
LIC Code : 00 ( None)
ROM Vers : 00
Checksum : 9F ( PASSED)
Cart loaded..
SDL INIT
TTF INIT
Execute Instruction: 00 PC: 0101
Not executing yet
Execute Instruction: C3 PC: 0104
Not executing yet
Unkown Instruction CE
Licensed under CC BY-NC-SA 4.0
最后更新于 Jun 25, 2025 15:02 UTC