CHIP8 Emulator(1)——CHIP8简介
2015-06-17 13:50
309 查看
CHIP8简介
对CHIP8一个简单的介绍,参考资料来自于CHIP8的Wiki。CHIP8是什么?
我开始一直以为CHIP8是什么单片机的一种,后来才发现CHIP8是一种解释性的编程语言。对,是语言!最初被应用是在1970年代中期。CHIP8的程序运行在CHIP8虚拟机中,它的出现让电子游戏编程变得简单些了(相对于那个年代来说)。用CHIP8实现的电子游戏不少,比如小蜜蜂,俄罗斯方块,吃豆人等。CHIP8还有个后代叫做SCHIP8(Super Chip8),它的出现让游戏编程相对于CHIP8来说更加简单了,因为它多了很多的操作码。它们两个在很多平台上都实现了相应的模拟器,也有纯硬件实现,比如用FPGA。
CHIP8虚拟机介绍
上文提到了运行CHIP8的程序是在CHIP8的虚拟机中,那么作为一个能运行CHIP8的虚拟机,具备了哪些要素呢?内存
CHIP8基本是在一个有4K内存的系统上实现,也就是4096个字节。前512字节由CHIP8的解释器占据。所以CHIP8的程序都是从0x200地址开始的。最顶上的256个字(0xF00-0xFFF) 用于显示刷新,在这下面的96个字节 (0xEA0-0xEFF) 用于栈, 内部使用或者其他变量。发展到今天,CHIP8的实现的话不需要使用的空间都可以不使用,也就是不用完全那么按照上面来。但是通常还是要在低512字节 (0x000-0x200)存放字体数据。
寄存器
CHIP8的话有16个数据寄存器,V0~VF。VF寄存器存放进位标识。还有一个地址寄存器叫做I,2个字节的长度。栈
栈用于存放函数返回的地址值和保存一些数据,现在CHIP8的栈实现一般有16级。定时器
CHIP8有两个定时器,一个延时计时器,一个声音计时器。延时计时器一般处理用户游戏事件,可读可写。声音计时器顾名思义,用于发出声音的,当其值非零,就会发出一个声音。输入
输入是一个十六进制的键盘,其中有16个键值,0~F。“8”“6”“4”“2”一般用于方向输入。有三个操作码用来处理输入,其中一个是当键值按下则执行下一个指令,对应的是另外一个操作码处理指定键值没有按下则调到下一个指令。第三个操作码是等待一个按键按下,然后将其存放一个寄存器里。图像和声音
显示分辨率是64X32的像素,并且是单色的。某像素点为1则屏幕上显示相应像素点,为0则不显示。但某个像素点由有到无则进位标识被设置为1,可以用来进行冲撞检测。操作码
这是CHIP8的重点,CHIP8一共有35个操作码。每个操作码都是两个字节长。最高字节首先被存放。下面是操作码表和其代表的意义:NNN: address
NN: 8-bit constant
N: 4-bit constant
X and Y: 4-bit register identifier
Opcode | Explanation |
0NNN | Calls RCA 1802 program at address NNN. |
00E0 | Clears the screen. |
00EE | Returns from a subroutine. |
1NNN | Jumps to address NNN. |
2NNN | Calls subroutine at NNN. |
3XNN | Skips the next instruction if VX equals NN. |
4XNN | Skips the next instruction if VX doesn’t equal NN. |
5XY0 | Skips the next instruction if VX equals VY. |
6XNN | Sets VX to NN. |
7XNN | Adds NN to VX. |
8XY0 | Sets VX to the value of VY. |
8XY1 | Sets VX to VX or VY. |
8XY2 | Sets VX to VX and VY. |
8XY3 | Sets VX to VX xor VY. |
8XY4 | Adds VY to VX. VF is set to 1 when there’s a carry, and to 0 when there isn’t. |
8XY5 | VY is subtracted from VX. VF is set to 0 when there’s a borrow, and 1 when there isn’t. |
8XY6 | Shifts VX right by one. VF is set to the value of the least significant bit of VX before the shift.[2] |
8XY7 | Sets VX to VY minus VX. VF is set to 0 when there’s a borrow, and 1 when there isn’t. |
8XYE | Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.[2] |
9XY0 | Skips the next instruction if VX doesn’t equal VY. |
ANNN | Sets I to the address NNN. |
BNNN | Jumps to the address NNN plus V0. |
CXNN | Sets VX to a random number, masked by NN. |
DXYN | Sprites stored in memory at location in index register (I), maximum 8bits wide. Wraps around the screen. If when drawn, clears a pixel, register VF is set to 1 otherwise it is zero. All drawing is XOR drawing (i.e. it toggles the screen pixels) |
EX9E | Skips the next instruction if the key stored in VX is pressed. |
EXA1 | Skips the next instruction if the key stored in VX isn’t pressed. |
FX07 | Sets VX to the value of the delay timer. |
FX0A | A key press is awaited, and then stored in VX. |
FX15 | Sets the delay timer to VX. |
FX18 | Sets the sound timer to VX. |
FX1E | Adds VX to I.[3] |
FX29 | Sets I to the location of the sprite for the character in VX. Characters 0-F (in hexadecimal) are represented by a 4x5 font. |
FX33 | Stores the Binary-coded decimal representation of VX, with the most significant of three digits at the address in I, the middle digit at I plus 1, and the least significant digit at I plus 2. (In other words, take the decimal representation of VX, place the hundreds digit in memory at location in I, the tens digit at location I+1, and the ones digit at location I+2.) |
FX55 | Stores V0 to VX in memory starting at address I.[4] |
FX65 | Fills V0 to VX with values from memory starting at address I.[4] |
相关文章推荐
- EF框架 完整项目记录
- windows server 2012将计算机、回收站、文档等图标添加到桌面
- 收藏:SQL重复记录查询 .
- linux 命令——38 cal (转)
- Linux系统编程——进程间通信:管道(pipe)
- CentOS7系统常用命令
- 数据引擎--LSM树与B+数
- Hibernate多对多中间表有多个字段字段的注解配置方式(一)
- 僵尸进程回收signal(SIGCHLD, SIG_IGN)和signal(SIGPIPE, SIG_IGN); .
- Dart的文件、目录和链接(1)
- 返回一个二维整数数组中最大联通子数组的和
- 黑马程序员-------IO流
- js请求的几种方式
- IntelliJ IDEA 13.0使用
- Linux系统编程——进程间通信:信号中断处理
- maven环境快速搭建
- 决策树建模
- 无线路由器的一些高级参数
- 关于:HTTP Header -> Content-Type: text/plain Cache-Control: no-cache IE浏览器弹出错误下载对话
- linux 命令——37 date (转)