Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 977f0486cf1ea23f3fd5796a648811725a31635c
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 15:06:21 2021 +0900

    fix

commit d0e756b
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 15:03:48 2021 +0900

    fix

commit 6592774
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 14:49:31 2021 +0900

    fix

commit 28bef95
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 14:01:23 2021 +0900

    fix

commit 30cc9ae
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 12:13:49 2021 +0900

    fix

commit da0f416
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 11:35:27 2021 +0900

    wip

commit 56a2fd6
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 04:04:34 2021 +0900

    fix

commit 94e4a2d
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 03:47:42 2021 +0900

    fix

commit d79f27f
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Thu Apr 1 03:01:36 2021 +0900

    fix

commit 944826d
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Mar 31 20:35:50 2021 +0900

    wip

Squashed commit of the following:

commit e9ae6b6
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 04:51:47 2021 +0900

    fix

commit f2e4541
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 04:47:27 2021 +0900

    fix

commit c4256e2
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sat Apr 3 15:48:23 2021 +0900

    fix

commit 1d6151f
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sat Apr 3 15:43:36 2021 +0900

    fix

commit 1af8625
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sat Apr 3 12:58:49 2021 +0900

    fix

commit 93a3be6
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sat Apr 3 12:53:00 2021 +0900

    fix

commit db7483a
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sat Apr 3 10:06:37 2021 +0900

    fix

commit 95b7035
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Fri Apr 2 11:44:34 2021 +0900

    fix

commit 33f52ad
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Fri Apr 2 10:18:27 2021 +0900

    fix

commit b3e4ccb
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Fri Apr 2 10:06:28 2021 +0900

    prio

commit 40e2ca8
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Fri Apr 2 09:53:11 2021 +0900

    keyboard

Squashed commit of the following:

commit 7988181
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 13:56:12 2021 +0900

    fix

commit 13d6e48
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 07:54:13 2021 +0900

    fix

commit f198f3c
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 07:51:56 2021 +0900

    fix

commit bfdd388
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 07:47:06 2021 +0900

    fix

commit 76d502f
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 07:15:24 2021 +0900

    fix

commit 0f8b92d
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 07:03:38 2021 +0900

    fix

commit f5c46e6
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 21:27:59 2021 +0900

    bg affine

commit 1e6fabe
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 14:19:30 2021 +0900

    fix

commit 4808bf5
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 14:18:18 2021 +0900

    fix

commit afa4269
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 10:23:15 2021 +0900

    fix

commit c930e33
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 10:07:59 2021 +0900

    fix

commit 7c48ab2
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 09:57:59 2021 +0900

    fix

commit 02aa4f1
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 09:39:24 2021 +0900

    fix

commit e9deb11
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 09:35:17 2021 +0900

    fix

commit 20d730a
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 09:33:45 2021 +0900

    fix

commit 2acb82c
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 09:27:24 2021 +0900

    flip

commit 6c995e4
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 09:18:07 2021 +0900

    fix

commit 5999b78
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Sun Apr 4 06:36:52 2021 +0900

    wip

firered

Squashed commit of the following:

commit ed6e24f
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 17:52:02 2021 +0900

    update README.md

commit 841716b
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 17:47:31 2021 +0900

    fix

commit 1b21c1f
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 15:27:55 2021 +0900

    fix

commit e6e4d32
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Mon Apr 5 14:47:36 2021 +0900

    wip

Squashed commit of the following:

commit e086365
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 05:20:17 2021 +0900

    fix

commit 617efb2
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 18:20:29 2021 +0900

    fix

commit d74b2dd
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 18:12:47 2021 +0900

    fix

commit 2cb5862
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 18:00:45 2021 +0900

    window

commit b569a51
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 17:26:18 2021 +0900

    blend

commit 4713612
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 14:22:10 2021 +0900

    fix

commit ff617ff
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 13:03:00 2021 +0900

    fix

commit dcfda49
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Tue Apr 6 13:02:00 2021 +0900

    lr

Squashed commit of the following:

commit eb321e3
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:57:01 2021 +0900

    fix

commit c6d1d7d
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:56:33 2021 +0900

    fix

commit a41d657
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:43:28 2021 +0900

    fix

commit 8433a22
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:37:47 2021 +0900

    fix

commit b774156
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:33:57 2021 +0900

    fix

commit 415173a
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:30:37 2021 +0900

    fix

commit 9cd8c4a
Author: pokemium <bluejapan73+dev@gmail.com>
Date:   Wed Apr 7 06:19:25 2021 +0900

    update README.md

fix
  • Loading branch information
akatsuki105 committed Apr 6, 2021
1 parent 3026c51 commit 7299e4e
Show file tree
Hide file tree
Showing 31 changed files with 1,298 additions and 351 deletions.
22 changes: 4 additions & 18 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
MIT License
Copyright (c) 2021 Akihiro Otomo

Copyright (c) Akihiro Otomo 2021
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
# Mettaur

[![Go Report Card](https://goreportcard.com/badge/github.com/pokemium/mettaur)](https://goreportcard.com/report/github.com/pokemium/mettaur)
[![GitHub stars](https://img.shields.io/github/stars/pokemium/mettaur)](https://github.com/pokemium/mettaur/stargazers)
[![GitHub license](https://img.shields.io/github/license/pokemium/mettaur)](https://github.com/pokemium/mettaur/blob/main/LICENSE)

Mettaur is GBA emulator written in golang.

<img src="img/exe6g.png" width="320" alt="exe6g" />
**Warning: This emulator is WIP, so many ROMs don't work correctly now.**

<img src="img/exe6.png" width="320" alt="exe6g" />&nbsp;<img src="img/pokered.png" width="320" alt="pokered" />

<img src="img/exe4b.png" width="320" alt="exe4b" />&nbsp;<img src="img/dqmc.png" width="320" alt="dqmc" />

## Run

Please download latest binary from [Release](https://github.com/pokemium/mettaur/releases).

```sh
$ mettaur XXXX.gba
```

## Build

```sh
# go1.16.x
$ make build
$ ./build/darwin-amd64/mettaur XXXX.gba
```

## Key

| keyboard | game pad |
| -------------------- | ------------- |
| <kbd>&larr;</kbd> | &larr; button |
| <kbd>&uarr;</kbd> | &uarr; button |
| <kbd>&darr;</kbd> | &darr; button |
| <kbd>&rarr;</kbd> | &rarr; button |
| <kbd>X</kbd> | A button |
| <kbd>Z</kbd> | B button |
| <kbd>S</kbd> | R button |
| <kbd>A</kbd> | L button |
| <kbd>Enter</kbd> | Start button |
| <kbd>Backspace</kbd> | Select button |

## ToDo

- [ ] Sound
- [ ] SRAM Save
- [ ] Window
- [ ] Mosaic
- [ ] Blend
- [ ] GUI
- [ ] Serial communication
- [ ] BG mode5
- [ ] Debug feature
- [ ] Fix some bugs

## References

- [GBATEK](https://problemkaputt.de/gbatek.htm)
- [gba_doc_ja](https://github.com/pokemium/gba_doc_ja)
- [gdkchan/gdkGBA](https://github.com/gdkchan/gdkGBA)
Binary file removed bios.gba
Binary file not shown.
24 changes: 22 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"mettaur/pkg/gba"
"os"
"os/signal"
"path/filepath"
"syscall"

"github.com/hajimehoshi/ebiten/v2"
)
Expand Down Expand Up @@ -51,7 +53,8 @@ func main() {
// Run program
func Run() ExitCode {
var (
showVersion = flag.Bool("v", false, "show version")
showVersion = flag.Bool("v", false, "show version")
showCartInfo = flag.Bool("c", false, "show cartridge info")
)

flag.Parse()
Expand All @@ -70,11 +73,18 @@ func Run() ExitCode {
emu := &Emulator{
gba: gba.New(data),
}
if *showCartInfo {
fmt.Println(emu.gba.CartInfo())
return ExitCodeOK
}

emu.SetupCloseHandler()
emu.gba.Reset()
// emu.gba.SoftReset()

ebiten.SetWindowResizable(true)
ebiten.SetWindowTitle(title)
ebiten.SetWindowSize(240, 160)
ebiten.SetWindowSize(240*2, 160*2)
if err := ebiten.RunGame(emu); err != nil {
fmt.Fprintf(os.Stderr, "crash in emulation: %s\n", err)
}
Expand Down Expand Up @@ -121,3 +131,13 @@ func (e *Emulator) Draw(screen *ebiten.Image) {
func (e *Emulator) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return 240, 160
}

func (e *Emulator) SetupCloseHandler() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
e.gba.Exit("Ctrl+C pressed in Terminal")
os.Exit(0)
}()
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module mettaur

go 1.16

require github.com/hajimehoshi/ebiten/v2 v2.0.6
require (
github.com/anthonynsimon/bild v0.13.0 // indirect
github.com/hajimehoshi/ebiten/v2 v2.0.6
)
31 changes: 31 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/anthonynsimon/bild v0.13.0 h1:mN3tMaNds1wBWi1BrJq0ipDBhpkooYfu7ZFSMhXt1C8=
github.com/anthonynsimon/bild v0.13.0/go.mod h1:tpzzp0aYkAsMi1zmfhimaDyX1xjn2OUc1AJZK/TF0AE=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2 h1:Ac1OEHHkbAZ6EUnJahF0GKcU0FjPc/V8F1DvjhKngFE=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
Expand All @@ -10,14 +20,32 @@ github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e/go.mod
github.com/hajimehoshi/go-mp3 v0.3.1/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto v0.6.8/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jakecoffman/cp v1.0.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jfreymuth/oggvorbis v1.0.1/go.mod h1:NqS+K+UXKje0FUYUPosyQ+XTVvjmVjps1aEZH1sumIk=
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -44,6 +72,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
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/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -59,4 +88,6 @@ golang.org/x/tools v0.0.0-20201009162240-fcf82128ed91/go.mod h1:z6u4i615ZeAfBE4X
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-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Binary file added img/dqmc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/exe4b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/exe6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/exe6g.png
Binary file not shown.
Binary file added img/pokered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions pkg/cart/cart.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cart

import "fmt"

// Header represents GBA Cartridge header
type Header struct {
Entry [4]byte
Expand All @@ -17,3 +19,10 @@ func New(src []byte) *Header {
MakerCode: string(src[0xb0 : 0xb0+2]),
}
}

func (h *Header) String() string {
str := `Title: %s
GameCode: %s
MakerCode: %s`
return fmt.Sprintf(str, h.Title, h.GameCode, h.MakerCode)
}
48 changes: 41 additions & 7 deletions pkg/gba/arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ func (g *GBA) armExec(inst uint32) {
g.armSWI(inst)
case IsArmBranch(inst) || IsArmBX(inst):
g.armBranch(inst)
case IsArmStack(inst):
if util.Bit(inst, 20) {
g.armLDM(inst)
} else {
g.armSTM(inst)
}
case IsArmLDM(inst):
g.armLDM(inst)
case IsArmSTM(inst):
g.armSTM(inst)
case IsArmLDR(inst):
g.armLDR(inst)
case IsArmSTR(inst):
Expand Down Expand Up @@ -371,7 +369,7 @@ func (g *GBA) armALUOp2(inst uint32) uint32 {
rm := inst & 0b1111

salt := uint32(0)
isRegister := util.ToBool((inst >> 4) & 0b1)
isRegister := (inst>>4)&0b1 > 0
if isRegister {
g.timer(1)
is = g.R[(inst>>8)&0b1111] & 0b1111_1111
Expand Down Expand Up @@ -863,6 +861,15 @@ func (g *GBA) armLDRH(inst uint32) {
}
}
g.R[rd] = uint32(g.getRAM16(addr, false))
if !pre {
// Post-indexing
if plus := util.Bit(inst, 23); plus {
addr += ofs
} else {
addr -= ofs
}
g.R[rn] = addr // Post-indexing, write-back is ALWAYS enabled
}
if rd == 15 {
g.pipelining()
}
Expand Down Expand Up @@ -891,6 +898,15 @@ func (g *GBA) armLDRSB(inst uint32) {
}
}
g.R[rd] = uint32(int8(g.getRAM8(addr, false)))
if !pre {
// Post-indexing
if plus := util.Bit(inst, 23); plus {
addr += ofs
} else {
addr -= ofs
}
g.R[rn] = addr // Post-indexing, write-back is ALWAYS enabled
}
if rd == 15 {
g.pipelining()
}
Expand Down Expand Up @@ -919,6 +935,15 @@ func (g *GBA) armLDRSH(inst uint32) {
}
}
g.R[rd] = uint32(int16(g.getRAM16(addr, false)))
if !pre {
// Post-indexing
if plus := util.Bit(inst, 23); plus {
addr += ofs
} else {
addr -= ofs
}
g.R[rn] = addr // Post-indexing, write-back is ALWAYS enabled
}
if rd == 15 {
g.pipelining()
}
Expand Down Expand Up @@ -947,6 +972,15 @@ func (g *GBA) armSTRH(inst uint32) {
}
}
g.setRAM16(addr, uint16(g.R[rd]), false)
if !pre {
// Post-indexing
if plus := util.Bit(inst, 23); plus {
addr += ofs
} else {
addr -= ofs
}
g.R[rn] = addr // Post-indexing, write-back is ALWAYS enabled
}
g.timer(g.cycleS2N())
}

Expand Down
19 changes: 12 additions & 7 deletions pkg/gba/arm_decode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gba

import "mettaur/pkg/util"
import (
"mettaur/pkg/util"
)

// IsArmALU returns instruction is arithmetic instruction
// 27-26: 00
Expand Down Expand Up @@ -77,7 +79,7 @@ func IsArmSTR(inst uint32) bool {
// 27-25: 000
func IsArmLDRH(inst uint32) bool {
cond1 := !util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25)
cond2 := !util.Bit(inst, 11) && !util.Bit(inst, 10) && !util.Bit(inst, 9) && !util.Bit(inst, 8) && util.Bit(inst, 7)
cond2 := util.Bit(inst, 7)
cond3 := util.Bit(inst, 4)
condLDRH := util.Bit(inst, 20) && !util.Bit(inst, 6) && util.Bit(inst, 5)
return cond1 && cond2 && cond3 && condLDRH
Expand All @@ -87,7 +89,7 @@ func IsArmLDRH(inst uint32) bool {
// 27-25: 000
func IsArmLDRSB(inst uint32) bool {
cond1 := !util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25)
cond2 := !util.Bit(inst, 11) && !util.Bit(inst, 10) && !util.Bit(inst, 9) && !util.Bit(inst, 8) && util.Bit(inst, 7)
cond2 := util.Bit(inst, 7)
cond3 := util.Bit(inst, 4)
condLDRSB := util.Bit(inst, 20) && util.Bit(inst, 6) && !util.Bit(inst, 5)
return cond1 && cond2 && cond3 && condLDRSB
Expand All @@ -97,7 +99,7 @@ func IsArmLDRSB(inst uint32) bool {
// 27-25: 000
func IsArmLDRSH(inst uint32) bool {
cond1 := !util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25)
cond2 := !util.Bit(inst, 11) && !util.Bit(inst, 10) && !util.Bit(inst, 9) && !util.Bit(inst, 8) && util.Bit(inst, 7)
cond2 := util.Bit(inst, 7)
cond3 := util.Bit(inst, 4)
condLDRSH := util.Bit(inst, 20) && util.Bit(inst, 6) && util.Bit(inst, 5)
return cond1 && cond2 && cond3 && condLDRSH
Expand All @@ -107,7 +109,7 @@ func IsArmLDRSH(inst uint32) bool {
// 27-25: 000
func IsArmSTRH(inst uint32) bool {
cond1 := !util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25)
cond2 := !util.Bit(inst, 11) && !util.Bit(inst, 10) && !util.Bit(inst, 9) && !util.Bit(inst, 8) && util.Bit(inst, 7)
cond2 := util.Bit(inst, 7)
cond3 := util.Bit(inst, 4)
condSTRH := !util.Bit(inst, 20) && !util.Bit(inst, 6) && util.Bit(inst, 5)
return cond1 && cond2 && cond3 && condSTRH
Expand All @@ -117,8 +119,11 @@ func IsArmSTRH(inst uint32) bool {

// IsArmStack returns instruction is push/pop instruction
// 27-25: 100
func IsArmStack(inst uint32) bool {
return util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25) // 100
func IsArmLDM(inst uint32) bool {
return util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25) && util.Bit(inst, 20) // 100
}
func IsArmSTM(inst uint32) bool {
return util.Bit(inst, 27) && !util.Bit(inst, 26) && !util.Bit(inst, 25) && !util.Bit(inst, 20) // 100
}

// data swap
Expand Down
Loading

0 comments on commit 7299e4e

Please sign in to comment.