finally add the RET instruction

A Chip-8 program that does something with the display (that is skipped) which i'm using to test now actually causes a stack overflow!
This commit is contained in:
abbie 2022-02-20 18:51:55 +00:00
parent 348b764f08
commit ba22aa482c
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
3 changed files with 7 additions and 3 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]]
name = "celc8"
version = "0.1.3"
version = "0.1.4"

View file

@ -1,6 +1,6 @@
[package]
name = "celc8"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -246,7 +246,11 @@ fn execute(opcode: u16, instruction: Instruction, mut cpu: Cpu) -> Cpu {
}
}
if instruction.name == "JP_ADDR" { cpu.setpc(args[0] as u16); }
if instruction.name == "RET" {
let returnaddress = cpu.stackpop();
cpu.setpc(returnaddress);
}
else if instruction.name == "JP_ADDR" { cpu.setpc(args[0] as u16); }
else if instruction.name == "CALL_ADDR" {
cpu.incrementsp();
cpu.stackpush();