Git Product home page Git Product logo

pokegb's Introduction

pokegb

A gameboy emulator that only plays Pokemon Blue, in ~50 lines of c++.

See the technical write-up.

Features

Plays Pokemon Blue (and Red).

Screenshots

1 2 3 4 5 6 7 8 9 10 11

Source Code

Building

Only builds on Linux and macOS AFAIK.

$ make

On macOS, you'll need to create a save file too (just the first time):

$ make rom.sav

Running

Get a Pokemon Blue (or Pokemon Red) ROM file. The files that are known to work have the following sha1s:

Name sha1
Pokemon - Blue Version (USA, Europe) (SGB Enhanced).gb d7037c83e1ae5b39bde3c30787637ba1d4c48ce2
Pokemon - Red Version (USA, Europe) (SGB Enhanced).gb ea9bcae617fdf159b045185467ae58b2e4a48b9a

Others might work too, but these are the ones that I've tried.

Rename the file to rom.gb and put it in the current directory. Then run:

$ ./pokegb

The save file is written to rom.sav.

Keys:

Action Key
DPAD-UP
DPAD-DOWN
DPAD-LEFT
DPAD-RIGHT
B Z
A X
START Enter
SELECT Tab

Updating keys

Look for line 24 the source. The following table shows which numbers map to which keyboard keys:

number default key gameboy button
27 X A Button
29 Z B Button
43 Tab Select Button
40 Return Start Button
79 Arrow Right DPAD Right
80 Arrow Left DPAD Left
81 Arrow Down DPAD Down
82 Arrow Up DPAD Up

Replace the numbers on this line with one from the SDL scancode list.

pokegb's People

Contributors

binji avatar horki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pokegb's Issues

Segmentation fault upon launch

System Information

Operating System

$ uname --all
Linux foobar 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux

Application

9c03ea4

Actual Behaviour

After successful build, the program crashes with a segmentation fault after (very) briefly rendering a (blank) window:

$ sudo apt-get install libsdl2-dev
$ make
cc -O2 -Wall -Wno-return-type -Wno-misleading-indentation -lSDL2 -o pokegb pokegb.cc
$ ./pokegb
Segmentation fault

Expected Behaviour

No segmentation fault.

crash on Arch

What happen

I try to run this on my lattop, clone and build is ok. When try to run, it just went wrong.

How it happen

[kearney@arch c]$ git clone [email protected]:binji/pokegb.git
正克隆到 'pokegb'...
remote: Enumerating objects: 154, done.
remote: Counting objects: 100% (154/154), done.
remote: Compressing objects: 100% (84/84), done.
remote: Total 154 (delta 81), reused 128 (delta 65), pack-reused 0
接收对象中: 100% (154/154), 49.01 KiB | 44.00 KiB/s, 完成.
处理 delta 中: 100% (81/81), 完成.
[kearney@arch c]$ cd pokegb/
[kearney@arch pokegb]$ make
cc -O2 -Wall -Wno-return-type -Wno-misleading-indentation -Wno-parentheses -o pokegb pokegb.cc -lSDL2
[kearney@arch pokegb]$ ./pokegb 
段错误 (核心已转储)

[kearney@arch pokegb]$ uname -a
Linux arch 5.12.10-arch1-1 #1 SMP PREEMPT Thu, 10 Jun 2021 16:34:50 +0000 x86_64 GNU/Linux
[kearney@arch pokegb]$ ldd ./pokegb
        linux-vdso.so.1 (0x00007ffcd2fdc000)
        libSDL2-2.0.so.0 => /usr/lib/libSDL2-2.0.so.0 (0x00007f7f9ce12000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f7f9cc46000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f7f9cb02000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f7f9cafb000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f7f9cada000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f7f9d005000)

Did I forget something undone? Little confused aboout "Put Pokemon Blue in rom.gb"

Crash on macOS 11.4

pokegb_2021-06-05-175518_zhaoruideMac-mini.crash.zip

Process: pokegb [22344]
Path: /Users/USER/*/pokegb
Identifier: pokegb
Version: 0
Code Type: X86-64 (Native)
Parent Process: zsh [21593]
Responsible: Terminal [9659]
User ID: 501

Date/Time: 2021-06-05 17:55:18.291 +0800
OS Version: macOS 11.4 (20F71)
Report Version: 12
Bridge OS Version: 5.4 (18P4663)
Anonymous UUID: 496C124E-0C6B-6D7D-8520-206563EAFAC8

Time Awake Since Boot: 690000 seconds

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000000000ff
Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [22344]

VM Regions Near 0xff:
-->
__TEXT 10ccc0000-10ccc4000 [ 16K] r-x/r-x SM=COW /Users/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 pokegb 0x000000010ccc1a03 me(unsigned short, unsigned char, int) + 163
1 pokegb 0x000000010ccc23e4 main + 1764
2 libdyld.dylib 0x00007fff204b2f5d start + 1

Thread 1:
0 libsystem_pthread.dylib 0x00007fff20493420 start_wqthread + 0

Thread 2:
0 libsystem_pthread.dylib 0x00007fff20493420 start_wqthread + 0

Thread 0 crashed with X86 Thread State (64-bit):
rax: 0xffffffffffffffff rbx: 0x0000000000000000 rcx: 0x0000000000000100 rdx: 0x0000000000000000
rdi: 0x0000000000000100 rsi: 0x0000000000000000 rbp: 0x00007ffee2f3f940 rsp: 0x00007ffee2f3f910
r8: 0x0000000000002859 r9: 0x0000000000000001 r10: 0x0000000000000001 r11: 0x000000010cd012b4
r12: 0x0000000000000000 r13: 0x0000000000000100 r14: 0x0000000000000000 r15: 0x0000000000000000
rip: 0x000000010ccc1a03 rfl: 0x0000000000010203 cr2: 0x00000000000000ff

Logical CPU: 1
Error Code: 0x00000004 (no mapping for user data read)
Trap Number: 14

Thread 0 instruction stream:
d2 74 1d 44 88 34 08 e9-6d 01 00 00 41 0f b7 c5 .t.D.4..m...A...
25 ff 1f 00 00 48 8d 0d-21 6a 00 00 85 d2 75 e3 %....H..!j....u.
44 8a 34 08 e9 50 01 00-00 85 d2 74 28 44 89 f0 D.4..P.....t(D..
24 3f 45 84 f6 0f b6 c0-b9 01 00 00 00 0f 45 c8 $?E...........E.
0f b6 c1 48 c1 e0 0e 48-03 05 d7 67 00 00 48 89 ...H...H...g..H.
05 d8 67 00 00 48 8b 05-c9 67 00 00 41 0f b7 cd ..g..H...g..A...
[44]8a 34 08 e9 10 01 00-00 41 80 fe 03 77 1a 85 D.4......A...w.. <==
d2 74 16 41 0f b6 c6 48-c1 e0 0d 48 03 05 bb c9 .t.A...H...H....
00 00 48 89 05 bc c9 00-00 48 8b 05 9d 67 00 00 ..H......H...g..
41 81 e5 ff 3f 00 00 46-8a 34 28 e9 d9 00 00 00 A...?..F.4(.....
41 0f b7 c5 25 ff 1f 00-00 85 d2 0f 84 ba 00 00 A...%...........
00 48 8b 0d 8d c9 00 00-44 88 34 01 e9 ad 00 00 .H......D.4.....

Thread 0 last branch register state not available.

Make configurable the A/B buttons

Current Behaviour

Currently, the buttons are set as "B Button"=Z, "A Button"=X.
The problem is that for german keyboards (QWERTZ) the Z and the X are really far away. Instead, next to the X is the Y.

Acceptance Criteria

Make configurable the A/B buttons, so they can be chosen at compile time via an argument/option .

Alternative easier/temporal solution: explain (in the docu) where to change it in the code.

Build error

when building I get this error:

/usr/bin/ld: /tmp/ccloiK2Y.o: in function `main':
pokegb.cc:(.text.startup+0xe3): undefined reference to `SDL_Init'
/usr/bin/ld: pokegb.cc:(.text.startup+0x104): undefined reference to `SDL_CreateWindow'
/usr/bin/ld: pokegb.cc:(.text.startup+0x116): undefined reference to `SDL_CreateRenderer'
/usr/bin/ld: pokegb.cc:(.text.startup+0x138): undefined reference to `SDL_CreateTexture'
/usr/bin/ld: pokegb.cc:(.text.startup+0x144): undefined reference to `SDL_GetKeyboardState'
/usr/bin/ld: pokegb.cc:(.text.startup+0x2a4): undefined reference to `SDL_LockTexture'
/usr/bin/ld: pokegb.cc:(.text.startup+0x32c): undefined reference to `SDL_UnlockTexture'
/usr/bin/ld: pokegb.cc:(.text.startup+0x340): undefined reference to `SDL_RenderCopy'
/usr/bin/ld: pokegb.cc:(.text.startup+0x348): undefined reference to `SDL_RenderPresent'
/usr/bin/ld: pokegb.cc:(.text.startup+0x362): undefined reference to `SDL_PollEvent'
collect2: error: ld returned 1 exit status

I have libsdl2-dev installed, I'm not sure why it's not working

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.