From c0f1e2c6961575166cc437fa9bf133b1b40480dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Jos=C3=A9=20de=20Oliveira?= Date: Mon, 1 Jan 2024 10:14:02 -0300 Subject: [PATCH] refactor(cpu): move and rename CPU constants --- core/chip8.go | 2 +- core/cpu/cpu.go | 9 +-------- core/cpu/opcode.go | 9 +++++++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/chip8.go b/core/chip8.go index 7281626..17f706e 100644 --- a/core/chip8.go +++ b/core/chip8.go @@ -17,7 +17,7 @@ type Chip8 struct { } func (c8 *Chip8) Update() error { - for i := 0; i < int(cpu.FREQUENCY/60); i++ { + for i := 0; i < cpu.SPEED; i++ { for key, value := range input.Keypad { if ebiten.IsKeyPressed(key) { c8.cpu.Keys[value] = 0x01 diff --git a/core/cpu/cpu.go b/core/cpu/cpu.go index 53d5e95..4517322 100644 --- a/core/cpu/cpu.go +++ b/core/cpu/cpu.go @@ -11,14 +11,7 @@ import ( ) const ( - FREQUENCY = 700 // Instructions per second - - INSTRUCTION_BITMASK = 0xF000 - X_BITMASK = 0x0F00 - Y_BITMASK = 0x00F0 - N_BITMASK = 0x000F - NN_BITMASK = 0x00FF - NNN_BITMASK = 0x0FFF + SPEED = int(700 / 60) // Instructions per second ) type CPU struct { diff --git a/core/cpu/opcode.go b/core/cpu/opcode.go index bba722c..74eb65c 100644 --- a/core/cpu/opcode.go +++ b/core/cpu/opcode.go @@ -1,5 +1,14 @@ package cpu +const ( + INSTRUCTION_BITMASK = 0xF000 + X_BITMASK = 0x0F00 + Y_BITMASK = 0x00F0 + N_BITMASK = 0x000F + NN_BITMASK = 0x00FF + NNN_BITMASK = 0x0FFF +) + type opcode struct { instruction uint16 registerX uint8