11.6 C
New York
Friday, March 14, 2025

second – How do I make my chip-8 emulator replace on the meant price?


I am making an emulator/interpreter for an previous console referred to as the chip-8 In Godot 4.3 steady, It is going actually good thus far, I mainly simply load an exterior ROM right into a digital RAM (8BitPackedArray) and execute its every operations code like this for instance

0x3000: # 1st nibble is '3':
        # 3XNN: Skips the following instruction if VX equals NN.
        if registers[opcode >> 8 & 0x0F] == opcode & 0x00FF:
            program_counter += 2

My present subject is that I wanna run the emulator on the identical pace because the OG console, I first tried having a for loop within the _ready() perform that executes all of the opcodes, however it ended up operating the whole lot earlier than the sport even begins.

So subsequent I attempted executing the opcodes within the _process() perform, And it labored however it was very gradual in comparison with how the quick the console is supposed to run. I wished to extend what number of instances _process() would run each second however I could not work out how. So I got here up with a humorous resolution; have a for loop run 10 instances in _process(). This could make _process() run 10 instances quicker. And yeah it labored however this resolution appears very harmful? I imply how is that this gonna run constantly? Is it gonna run on the identical price on my PC and in addition stronger/weaker PCs? And likewise when there’s motion taking place the body price dropped to 45?

func _process(delta: float) -> void:
        for i: int in vary(10):
            execute_opcode()
            program_counter += 2
        queue_redraw()

So subsequent I attempted utilizing _physics_process(). It is meant to run extra constantly and I managed to alter how typically it is run by rising the “physics tics per second” choice. I attempted rising from 60 to 1000 however my sport continues to be not operating quick sufficient.

# Even when 'physics tics per second' is 1000: It is nonetheless too gradual.
func _physics_process(delta: float) -> void:
        execute_opcode()
        program_counter += 2
        queue_redraw()

Subsequent I attempted returning the “physics tics per second” again to 60. However I added a for loop that might run 5 instances. It resulted within the sport being very uneven and gradual:

# Very uneven and gradual
func _physics_process(delta: float) -> void:
    for i: int in vary(5):
        execute_opcode()
        program_counter += 2
    queue_redraw()

So yeah I assume I am confused and do not know learn how to clear up this subject.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles