Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Upgrate to use new gbdk 2020 #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions api/gb/cgb.go → api/gb/cgb/cgb.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package gb
package cgb

import "github.com/Akatsuki-py/gbdk-go/api/gb"

const (
RGB_RED UINT16 = iota
RGB_RED gb.UINT16 = iota
RGB_DARKRED
RGB_GREEN
RGB_DARKGREEN
Expand All @@ -23,21 +25,21 @@ const (
RGB_TEAL
)

func RGB(r, g, b UINT8) UINT16 {
func RGB(r, g, b gb.UINT8) gb.UINT16 {
return 0
}

// SetBkgPalette Set bkg palette(s).
func SetBkgPalette(firstPalette, nbPalettes UINT8, rgbData []UINT16) {}
func SetBkgPalette(firstPalette, nbPalettes gb.UINT8, rgbData []gb.UINT16) {}

// SetSpritePalette Set sprite palette(s).
func SetSpritePalette(firstPalette, nbPalettes UINT8, rgbData []UINT16) {}
func SetSpritePalette(firstPalette, nbPalettes gb.UINT8, rgbData []gb.UINT16) {}

// SetBkgPaletteEntry Set a bkg palette entry.
func SetBkgPaletteEntry(palette, entry UINT8, rgbData UINT16) {}
func SetBkgPaletteEntry(palette, entry gb.UINT8, rgbData gb.UINT16) {}

// SetSpritePaletteEntry Set a sprite palette entry.
func SetSpritePaletteEntry(palette, entry UINT8, rgbData UINT16) {}
func SetSpritePaletteEntry(palette, entry gb.UINT8, rgbData gb.UINT16) {}

// CPUSlow Set CPU speed to slow operation. Make sure interrupts are disabled before call.
func CPUSlow() {}
Expand Down
24 changes: 17 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
)

Expand Down Expand Up @@ -37,24 +38,25 @@ func Run() int {
}

assets := filepath.Join(dir, "asset", "*.go")
assetCmd := fmt.Sprintf("./go2c %s", assets)
assetCmd := fmt.Sprintf("go2c %s", assets)
fmt.Println(assetCmd)
cmd := exec.Command("/bin/sh", "-c", assetCmd)
cmd.Env = append(os.Environ(), "ASSET=true")
cmd.Output()

scripts := filepath.Join(dir, "*.go")
scriptCmd := fmt.Sprintf("./go2c %s", scripts)
scriptCmd := fmt.Sprintf("go2c %s", scripts)
fmt.Println(scriptCmd)
if _, err := exec.Command("/bin/sh", "-c", scriptCmd).Output(); err != nil {
fmt.Fprintf(os.Stderr, "compile error: %s", err)
if out, err := exec.Command("/bin/sh", "-c", scriptCmd).Output(); err != nil {
fmt.Fprintf(os.Stderr, "compile error: %s\n%s\n", err, out)
return ExitCodeError
}

zshCmd := fmt.Sprintf("gbdk2020/lcc -o %s tmp/*.c", *output)
zshCmd := fmt.Sprintf("%s -o %s tmp/*.c", path.Join(gbdkPath(), "lcc"), *output)

fmt.Println(zshCmd)
if _, err := exec.Command("/bin/sh", "-c", zshCmd).Output(); err != nil {
fmt.Fprintf(os.Stderr, "build error: %s", err)
if out, err := exec.Command("/bin/sh", "-c", zshCmd).Output(); err != nil {
fmt.Fprintf(os.Stderr, "\nbuild error: %s\n%s\n", err, out)
return ExitCodeError
}

Expand Down Expand Up @@ -91,3 +93,11 @@ Options:
-v show version
`, version)
}

func gbdkPath() string {
if p := os.Getenv("GBDKDIR"); p != "" {
return path.Join(p, "bin")
}

return ""
}
2 changes: 2 additions & 0 deletions compiler/pkg/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func include(name string) string {
switch {
case h == "gb":
return fmt.Sprintf("#include <gb/%s.h>\n", h)
case h == "cgb":
return fmt.Sprintf("#include <gb/%s.h>\n", h)
case h == "drawing":
return "#include <gb/drawing.h>\n"
case h == "str":
Expand Down
10 changes: 9 additions & 1 deletion compiler/pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ func GetCFunc(funcName string) string {
}

var GBDKPackage []string = []string{
"github.com/Akatsuki-py/gbdk-go/api/stdio", "github.com/Akatsuki-py/gbdk-go/api/gb", "github.com/Akatsuki-py/gbdk-go/api/str", "github.com/Akatsuki-py/gbdk-go/api/stdlib", "github.com/Akatsuki-py/gbdk-go/api/macro", "github.com/Akatsuki-py/gbdk-go/api/mem", "github.com/Akatsuki-py/gbdk-go/api/drawing", "github.com/Akatsuki-py/gbdk-go/api/rand",
"github.com/Akatsuki-py/gbdk-go/api/stdio",
"github.com/Akatsuki-py/gbdk-go/api/gb",
"github.com/Akatsuki-py/gbdk-go/api/gb/cgb",
"github.com/Akatsuki-py/gbdk-go/api/str",
"github.com/Akatsuki-py/gbdk-go/api/stdlib",
"github.com/Akatsuki-py/gbdk-go/api/macro",
"github.com/Akatsuki-py/gbdk-go/api/mem",
"github.com/Akatsuki-py/gbdk-go/api/drawing",
"github.com/Akatsuki-py/gbdk-go/api/rand",
}

func RemoveTypePackage(path string) string {
Expand Down
12 changes: 5 additions & 7 deletions example/move_sprite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ func main() {
gb.SHOW_SPRITES()

for {
if (gb.Joypad() & gb.J_RIGHT) > 0 {
switch gb.Joypad() {
case gb.J_RIGHT:
x++
gb.MoveSprite(0, x, y)
gb.Delay(10)
}
if (gb.Joypad() & gb.J_LEFT) > 0 {
case gb.J_LEFT:
x--
gb.MoveSprite(0, x, y)
gb.Delay(10)
}
if (gb.Joypad() & gb.J_UP) > 0 {
case gb.J_UP:
y--
gb.MoveSprite(0, x, y)
gb.Delay(10)
}
if (gb.Joypad() & gb.J_DOWN) > 0 {
case gb.J_DOWN:
y++
gb.MoveSprite(0, x, y)
gb.Delay(10)
Expand Down
7 changes: 4 additions & 3 deletions example/simple_shmup/bank3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/Akatsuki-py/gbdk-go/api/gb"
"github.com/Akatsuki-py/gbdk-go/api/gb/cgb"
"github.com/Akatsuki-py/gbdk-go/example/simple_shmup/asset"
)

Expand Down Expand Up @@ -41,10 +42,10 @@ var gamemap = []gb.UINT8{
}

var bgpal = []gb.UINT16{
gb.RGB(0, 0, 0), gb.RGB(10, 10, 10), gb.RGB(20, 20, 20), gb.RGB(30, 30, 30),
cgb.RGB(0, 0, 0), cgb.RGB(10, 10, 10), cgb.RGB(20, 20, 20), cgb.RGB(30, 30, 30),
}
var spritepal = []gb.UINT16{
gb.RGB(0, 0, 0), gb.RGB(10, 10, 10), gb.RGB(20, 20, 20), gb.RGB(30, 30, 30),
cgb.RGB(0, 0, 0), cgb.RGB(10, 10, 10), cgb.RGB(20, 20, 20), cgb.RGB(30, 30, 30),
}

func DrawTitleScreen() {
Expand All @@ -69,7 +70,7 @@ func LoadGameTiles() {

gb.SetBkgData(0, 1, asset.BGTile)
gb.SetBkgTiles(0, 0, 32, 32, gamemap)
gb.SetBkgPalette(0, 1, bgpal)
cgb.SetBkgPalette(0, 1, bgpal)
gb.SetSpriteData(0, 3, asset.SpriteTiles)
gb.SetSpriteTile(0, 0)
gb.SetSpriteTile(1, 1)
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module github.com/Akatsuki-py/gbdk-go

go 1.14

require golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe
require (
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/tools v0.1.8
)
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe h1:BT/vSbkiKG3rURL2PMNvsoVnPUqYiSv4HYQL/gVKAZw=
golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=