Added JP, CALL, SNE Vx and byte instructions

- Basic ROM loading functions
This commit is contained in:
Tony Bark 2021-03-08 15:20:28 -05:00
parent ef2ed8c451
commit b6f6ffd15d
3 changed files with 52 additions and 4 deletions

View file

@ -20,6 +20,10 @@ config/description="Chip8 emulator."
run/main_scene="res://scenes/Game.tscn"
config/icon="res://icon.png"
[autoload]
SysData="*res://scripts/SysData.gd"
[rendering]
quality/driver/driver_name="GLES2"

View file

@ -93,10 +93,33 @@ func runSystem():
jump = true
_:
var addr = opcode & 0x0FFF
pc = addr
var address = opcode & 0x0FFF
pc = address
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):
pc += 2
@ -108,10 +131,28 @@ func runSystem():
$AudioStreamPlayer.play()
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.
func _ready():
pass # Replace with function body.
loadRom(SysData.Rom)
# Called every frame. 'delta' is the elapsed time since the previous frame.

3
scripts/SysData.gd Normal file
View file

@ -0,0 +1,3 @@
extends Node
var Rom: String