Skip to content

Commit

Permalink
Merge pull request #1 from maxfierke/mf-rendering
Browse files Browse the repository at this point in the history
Stub-out a GUI mode
  • Loading branch information
maxfierke authored May 21, 2024
2 parents 47c03ff + fd95e5d commit 698ebad
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 135 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ jobs:

build:
runs-on: ubuntu-latest
env:
DISPLAY: ':99.0'

steps:
- name: Install ebiten build dependencies
run: |
sudo apt install gcc libc6-dev libgl1-mesa-dev libxcursor-dev \
libxi-dev libxinerama-dev libxrandr-dev \
libxxf86vm-dev libasound2-dev pkg-config
- name: Run Xvfb for ebitin
run: |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- uses: actions/checkout@v3
with:
submodules: true
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- name: Install ebiten build dependencies
run: |
sudo apt install gcc libc6-dev libgl1-mesa-dev libxcursor-dev \
libxi-dev libxinerama-dev libxrandr-dev \
libxxf86vm-dev libasound2-dev pkg-config
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
run:
modules-download-mode: mod
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ help:

.PHONY: tidy
tidy:
go fmt ./...
go fmt -mod=mod ./...
go mod tidy -v

.PHONY: build
Expand All @@ -29,15 +29,15 @@ clean:

.PHONY: run
run:
$(GO) run .
$(GO) run -mod=mod .

.PHONY: test
test:
$(GO) test -v ./...
$(GO) test -mod=mod -v ./...

.PHONY: bin/gogo-gb # This does exist, but we're not tracking its dependencies. Go is
bin/gogo-gb:
$(GO) build -o bin/gogo-gb .
$(GO) build -mod=mod -o bin/gogo-gb .

.PHONY: cpu_instrs
cpu_instrs: bin/gogo-gb vendor/gameboy-doctor/gameboy-doctor vendor/gb-test-roms/cpu_instrs/individual/*.gb
Expand Down
53 changes: 0 additions & 53 deletions devices/host.go

This file was deleted.

12 changes: 12 additions & 0 deletions devices/host_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package devices

import "image"

type HostInterface interface {
Framebuffer() chan<- image.Image
Log(msg string, args ...any)
LogErr(msg string, args ...any)
LogWarn(msg string, args ...any)
Exited() <-chan bool
SerialCable() SerialCable
}
17 changes: 16 additions & 1 deletion devices/lcd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package devices

import "github.com/maxfierke/gogo-gb/mem"
import (
"image"
"image/color"

"github.com/maxfierke/gogo-gb/mem"
)

const (
REG_LCD_LY = 0xFF44
Expand All @@ -13,6 +18,16 @@ func NewLCD() *LCD {
return &LCD{}
}

func (lcd *LCD) Draw() image.Image {
image := image.NewPaletted(
image.Rect(0, 0, 160, 144),
color.Palette{color.Black, color.Gray{Y: 96}, color.Gray16{Y: 128}, color.White},
)
image.Set(80, 77, color.Gray{Y: 96})

return image
}

func (lcd *LCD) OnRead(mmu *mem.MMU, addr uint16) mem.MemRead {
return mem.ReadPassthrough()
}
Expand Down
28 changes: 13 additions & 15 deletions devices/serial_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,23 @@ func (sc *SerialCtrl) SetClockInternal(enabled bool) {
}

type SerialPort struct {
clk uint
ctrl SerialCtrl
recv byte
buf byte
host HostContext
clk uint
ctrl SerialCtrl
recv byte
buf byte
cable SerialCable
}

func NewSerialPort(host HostContext) *SerialPort {
func NewSerialPort() *SerialPort {
return &SerialPort{
host: host,
cable: &NullSerialCable{},
}
}

func (sp *SerialPort) AttachCable(cable SerialCable) {
sp.cable = cable
}

func (sp *SerialPort) Step(cycles uint8, ic *InterruptController) {
if !sp.ctrl.IsTransferEnabled() {
return
Expand Down Expand Up @@ -122,18 +126,12 @@ func (sp *SerialPort) OnWrite(mmu *mem.MMU, addr uint16, value byte) mem.MemWrit
sp.ctrl.Write(value)

if sp.ctrl.IsTransferEnabled() && sp.ctrl.IsClockInternal() {
cable := sp.host.SerialCable()
logger := sp.host.Logger()

// TODO(GBC): derive this somehow and factor in GBC speeds when relevant
sp.clk = 8192

err := cable.WriteByte(sp.buf)
if err != nil {
logger.Printf("Unable to write 0x%02X to serial cable: %v\n", value, err)
}
_ = sp.cable.WriteByte(sp.buf)

recvVal, err := cable.ReadByte()
recvVal, err := sp.cable.ReadByte()
if err != nil {
sp.recv = 0xFF
} else {
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
module github.com/maxfierke/gogo-gb

go 1.22.0

require github.com/hajimehoshi/ebiten/v2 v2.7.3

require (
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 // indirect
github.com/ebitengine/hideconsole v1.0.0 // indirect
github.com/ebitengine/purego v0.7.0 // indirect
github.com/jezek/xgb v1.1.1 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 h1:5e8X7WEdOWrjrKvgaWF6PRnDvJicfrkEnwAkWtMN74g=
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8/go.mod h1:tWboRRNagZwwwis4QIgEFG1ZNFwBJ3LAhSLAXAAxobQ=
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/purego v0.7.0 h1:HPZpl61edMGCEW6XK2nsR6+7AnJ3unUxpTZBkkIXnMc=
github.com/ebitengine/purego v0.7.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/hajimehoshi/ebiten/v2 v2.7.3 h1:lDpj8KbmmjzwD19rsjXNkyelicu0XGvklZW6/tjrgNs=
github.com/hajimehoshi/ebiten/v2 v2.7.3/go.mod h1:1vjyPw+h3n30rfTOpIsbWRXSxZ0Oz1cYc6Tq/2DKoQg=
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15 changes: 15 additions & 0 deletions hardware/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hardware

import (
"github.com/maxfierke/gogo-gb/cart"
"github.com/maxfierke/gogo-gb/debug"
"github.com/maxfierke/gogo-gb/devices"
)

type Console interface {
AttachDebugger(debugger debug.Debugger)
DetachDebugger()
LoadCartridge(r *cart.Reader) error
Step() error
Run(host devices.HostInterface) error
}
Loading

0 comments on commit 698ebad

Please sign in to comment.