WIP
This commit is contained in:
parent
3cb7e3a5c9
commit
69db4fa67c
35
gb/bus.go
Normal file
35
gb/bus.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package gb
|
||||||
|
|
||||||
|
// import (
|
||||||
|
// "fmt"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// type Bus struct {
|
||||||
|
// Cart *Cartridge
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func NewBus(cart *Cartridge) *Bus {
|
||||||
|
// bus := Bus{Cart: cart}
|
||||||
|
|
||||||
|
// return &bus
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (bus *Bus) Read(address uint16) (byte, error) {
|
||||||
|
// if address < 0x8000 {
|
||||||
|
// // ROM data
|
||||||
|
// return bus.Cart.Read(address), nil
|
||||||
|
// } else {
|
||||||
|
// return 0, fmt.Errorf("Reading from address %X not implemented!", address)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (bus *Bus) Write(address uint16, value byte) error {
|
||||||
|
// if address < 0x8000 {
|
||||||
|
// // ROM data
|
||||||
|
// bus.Cart.Write(address, value)
|
||||||
|
|
||||||
|
// return nil
|
||||||
|
// } else {
|
||||||
|
// return fmt.Errorf("Writing to address %X not implemented!", address)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@ -11,15 +11,19 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Console struct {
|
type Console struct {
|
||||||
|
CPU *CPU
|
||||||
Cartridge *Cartridge
|
Cartridge *Cartridge
|
||||||
front *image.RGBA
|
front *image.RGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsole(path string) (*Console, error) {
|
func NewConsole(path string) (*Console, error) {
|
||||||
cartridge := InsertCartridge(path)
|
cartridge, err := InsertCartridge(path)
|
||||||
|
if err != nil {
|
||||||
|
return &Console{}, err
|
||||||
|
}
|
||||||
buffer := image.NewRGBA(image.Rect(0, 0, ConsoleWidth, ConsoleHeight))
|
buffer := image.NewRGBA(image.Rect(0, 0, ConsoleWidth, ConsoleHeight))
|
||||||
|
|
||||||
console := Console{Cartridge: cartridge, front: buffer}
|
console := Console{Cartridge: cartridge, CPU: NewCPU(), front: buffer}
|
||||||
|
|
||||||
return &console, nil
|
return &console, nil
|
||||||
}
|
}
|
||||||
|
|||||||
45
gb/cpu.go
Normal file
45
gb/cpu.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package gb
|
||||||
|
|
||||||
|
const CPUFrequency = 4194304
|
||||||
|
|
||||||
|
type Registers struct {
|
||||||
|
A byte
|
||||||
|
F byte
|
||||||
|
B byte
|
||||||
|
C byte
|
||||||
|
D byte
|
||||||
|
E byte
|
||||||
|
H byte
|
||||||
|
L byte
|
||||||
|
PC uint16
|
||||||
|
SP uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
type CPU struct {
|
||||||
|
Regs Registers
|
||||||
|
FetchedData uint16
|
||||||
|
MemoryDestination uint16
|
||||||
|
DestinationIsMemory bool
|
||||||
|
CurrentOPcode byte
|
||||||
|
// CurrentInstruction *Instruction
|
||||||
|
Halted bool
|
||||||
|
Stepping bool
|
||||||
|
InterruptMasterEnabled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCPU() *CPU {
|
||||||
|
cpu := CPU{}
|
||||||
|
cpu.Regs = Registers{}
|
||||||
|
cpu.Stepping = true
|
||||||
|
|
||||||
|
return &cpu
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cpu *CPU) Step() bool {
|
||||||
|
if cpu.Stepping {
|
||||||
|
cpu.Stepping = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
25
main.go
25
main.go
@ -1,9 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gb-player/ui"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
// "gb-player/ui"
|
||||||
|
"gb-player/gb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var running = true
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// FIXME(m): Allow specifying rom file on command line
|
// FIXME(m): Allow specifying rom file on command line
|
||||||
// if len(os.Args) != 2 {
|
// if len(os.Args) != 2 {
|
||||||
@ -12,5 +18,20 @@ func main() {
|
|||||||
// romPath := os.Args[1]
|
// romPath := os.Args[1]
|
||||||
romPath := "./roms/dmg-acid2.gb"
|
romPath := "./roms/dmg-acid2.gb"
|
||||||
|
|
||||||
ui.Run(romPath)
|
// ui.Run(romPath)
|
||||||
|
|
||||||
|
console, err := gb.NewConsole(romPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
running := true
|
||||||
|
for running {
|
||||||
|
if !console.CPU.Step() {
|
||||||
|
fmt.Println("CPU stopped")
|
||||||
|
running = false
|
||||||
|
} else {
|
||||||
|
fmt.Println("CPU step")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,8 +22,7 @@ func (view *View) Update(dt uint64) {
|
|||||||
console := view.console
|
console := view.console
|
||||||
renderer := view.controller.renderer
|
renderer := view.controller.renderer
|
||||||
|
|
||||||
// console.StepMilliSeconds(dt)
|
console.StepMilliSeconds(dt)
|
||||||
console.StepMilliSeconds(sdl.GetTicks64())
|
|
||||||
|
|
||||||
buffer := console.Buffer()
|
buffer := console.Buffer()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user