mirror of
https://github.com/tonytins/retro8.git
synced 2025-03-21 15:21:20 +00:00
Added JP, CALL, SNE Vx and byte instructions
- Basic ROM loading functions
This commit is contained in:
parent
ef2ed8c451
commit
b6f6ffd15d
3 changed files with 52 additions and 4 deletions
|
@ -20,6 +20,10 @@ config/description="Chip8 emulator."
|
||||||
run/main_scene="res://scenes/Game.tscn"
|
run/main_scene="res://scenes/Game.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
SysData="*res://scripts/SysData.gd"
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
quality/driver/driver_name="GLES2"
|
quality/driver/driver_name="GLES2"
|
||||||
|
|
|
@ -93,10 +93,33 @@ func runSystem():
|
||||||
jump = true
|
jump = true
|
||||||
|
|
||||||
_:
|
_:
|
||||||
var addr = opcode & 0x0FFF
|
var address = opcode & 0x0FFF
|
||||||
pc = addr
|
pc = address
|
||||||
jump = true
|
jump = true
|
||||||
|
0x1000: # JP
|
||||||
|
var address = opcode & 0x0FFF
|
||||||
|
pc = address
|
||||||
|
jump = true
|
||||||
|
|
||||||
|
0x2000: # CALL
|
||||||
|
var address = opcode & 0x0FFF
|
||||||
|
stack[sp] = pc
|
||||||
|
sp += 1
|
||||||
|
|
||||||
|
pc = address
|
||||||
|
|
||||||
|
0x3000: # SNE Vx, byte
|
||||||
|
var vx = (opcode & 0x0F00) > 8
|
||||||
|
var byte = (opcode & 0x00FF)
|
||||||
|
|
||||||
|
if (registers[vx] != byte):
|
||||||
|
pc += 2
|
||||||
|
|
||||||
|
if (registers[vx] != byte):
|
||||||
|
pc += 2
|
||||||
|
_:
|
||||||
|
print("Unsopported opcode: %X", opcode)
|
||||||
|
|
||||||
if (jump == false):
|
if (jump == false):
|
||||||
pc += 2
|
pc += 2
|
||||||
|
|
||||||
|
@ -108,10 +131,28 @@ func runSystem():
|
||||||
$AudioStreamPlayer.play()
|
$AudioStreamPlayer.play()
|
||||||
|
|
||||||
soundTimer -= 1
|
soundTimer -= 1
|
||||||
|
|
||||||
|
func loadRom(rom):
|
||||||
|
var file = File.new()
|
||||||
|
|
||||||
|
if (file.file_exists(rom)):
|
||||||
|
initSystem()
|
||||||
|
file.open(rom, File.READ)
|
||||||
|
|
||||||
|
var offset = 0
|
||||||
|
|
||||||
|
while (!file.eof_reached()):
|
||||||
|
memory[0x200 + offset] = file.get_8()
|
||||||
|
canRun = true
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
print("Rom loaded.")
|
||||||
|
else:
|
||||||
|
print("Rom not found")
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
loadRom(SysData.Rom)
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
|
3
scripts/SysData.gd
Normal file
3
scripts/SysData.gd
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var Rom: String
|
Loading…
Add table
Reference in a new issue