CHIP8 Emulator(1)——CHIP8简介
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] |
以上就是对CHIP8的一个简单介绍,要想实现CHIP8的模拟,重点就在于对其操作码的模拟实现。
CHIP8 Emulator(1)——CHIP8简介相关推荐
- 每个程序员都应该挑战的6个项目
作者:Austin Z. Henley 编译:码农翻身 有不少学生和专业的开发人员都想做一个业余的项目,以此来锻炼提高自己的技术能力,但是他们并不清楚要做点啥. 我给大家看下这几个让我受益匪浅的项目, ...
- 手把手教你编写游戏模拟器 - Chip8篇(1)
转自 http://www.cnblogs.com/YiranXie/p/3439934.html 手把手教你编写游戏模拟器 - Chip8篇(1) 手把手教你编写游戏模拟器 - Chip8篇 翻译整 ...
- Win10安卓模拟器Visual Studio Emulator for Android使用简介(转)
Visual Studio Emulator for Android是微软官方发布的独立版本的安卓模拟器,这款软件可以让安卓应用开发者更加轻松的用Visual Studio编写Android应用,据说 ...
- Platform Builder和Embedded visual C++简介
1 Platform Builder 介绍 Platform Builder 是微软公司提供给Windows CE 开发人员进行基于Windows CE 平台下嵌入式操作系统定制的集成开发环境.它提供 ...
- 【Android 命令行工具】Android 命令行工具简介 ( 官方文档 | SDK 命令行工具 | SDK 构建工具 | SDK 平台工具 | 模拟器工具 | Jetifier 工具 )
文章目录 一.官方文档 二.Android 命令行工具简介 1.SDK 命令行工具 2.SDK 构建工具 3.SDK 平台工具 4.模拟器工具 5.Jetifier 工具 一.官方文档 Android ...
- Apache Ant 简介和配置
Apache Ant 简介 Apache Ant是目前事实上的Java应用的标准build脚本工具.使它大受欢迎的一个主要愿意是它的和灵活,允许程序员创建自己的Task来对Ant进行扩展. 本文主要内 ...
- HoloLens开发学习笔记(一):HoloLens简介
HoloLens开发学习笔记(一):HoloLens简介 一.HoloLens简介 Microsoft HoloLens是Windows Holographic的使用主要设备.HoloLens是一个W ...
- coredump简介与coredump原因总结
coredump简介与coredump原因总结 什么是coredump? 通常情况下coredmp包含了程序运行时的内存,寄存器状态,堆栈指针,内存管理信息等.可以理解为把程序工作的当前状态存储成一个 ...
- Linux 内核 3.3 和 3.4 简介
https://www.ibm.com/developerworks/cn/linux/l-33linuxkernel/ Linux 内核 3.3 和 3.4 简介 M. Tim Jones, 独立作 ...
最新文章
- eplan增加其他到工具栏_EPLAN增效之工具栏定制(十三:端子排编辑不进导航器)
- MATLAB中估算运行时间-tic、toc用法
- SpringBoot的email发送ssl协议格式
- (转)[EntLib]微软企业库5.0 学习之路——第十步、使用Unity解耦你的系统—PART2——了解Unity的使用方法(1)...
- Quick BI V4.0功能“炸弹”来袭,重磅推出即席分析、模板市场、企业微信免密登录等强势功能
- qt将光标相对于桌面的位置转换为相对于窗口的位置
- json.dumps与json.dump的区别 json.loads与json.load的区别(简洁易懂)
- 贵州大数据崛起背后的阿里云力量
- HIVE中常见文件存储格式比较
- 小程序微信支付errcode:40163问题
- ADI超声解决方案 和系统成像设计
- 开关电源初级和次级变压器之间的Y电容作用
- 数据从网卡到应用的过程
- HTML_水平线详解
- mysql怎么设置不要密码_mysql无密码怎么设置密码
- 网络安全笔记-99-渗透-渗透测试方法论
- Bootstrap(包括scss)复习
- linux命令--mkdir 与文件权限
- 基于PCI9054和LTC4240的CPCI总线接口设计
- 微型计算机接口技术4732,自考微型计算机及接口技术课程考试说明