Skip to content

Commit

Permalink
Merge pull request #11 from shuichitakano/feature/scale8_7
Browse files Browse the repository at this point in the history
8:7スケール対応
  • Loading branch information
shuichitakano authored Jan 2, 2022
2 parents ae4003c + 46b5b65 commit 5a9b940
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 132 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pico_sdk_init()
add_executable(picones
main.cpp
hid_app.cpp
gamepad.cpp
tar.cpp
)

Expand All @@ -38,6 +39,7 @@ PRIVATE
pico_multicore
hardware_dma
hardware_pio
hardware_i2c
hardware_interp
hardware_timer
hardware_clocks
Expand Down
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
# pico-infones

This software is a port of InfoNES, a NES emulator, for the Raspberry Pi Pico, and supports video and audio output over HDMI.
The code for HDMI output is based on [PicoDVI](https://github.com/Wren6991/PicoDVI).

## How to use.
The ROM should be placed in some way from 0x10080000, and can be easily transferred using picotool.
## Wiring
The default pinout of the HDMI connector follows the [Pico-DVI-Sock](https://github.com/Wren6991/Pico-DVI-Sock).

The controller should be connected to the micro USB port of the Raspberry Pi Pico via an OTG adapter.

Supply +5V to VBUS (pin 40) as power source. Be careful not to connect the power supply at the same time as the PC connection, for example when writing programs or ROMs.

## ROM
The ROM should be placed in some way from 0x10080000, and can be easily transferred using [picotool](https://github.com/raspberrypi/picotool).
```
picotool load foo.nes -t bin -o 0x10080000
```

You can either place the .nes files directly or place a tar file containing multiple .nes files. The maximum file size that can be used is 1.5 MiB for the standard Raspberry Pi Pico.

## Wiring
The code for HDMI output is based on [PicoDVI](https://github.com/Wren6991/PicoDVI), please refer to the circuit of the HDMI part of PicoDVI for wiring.
## Controller
The following controllers are supported.

- BUFFALO BGC-FC801
- SONY DUALSHOCK 4
- SONY DualSense

There are several special functions assigned to button combinations.

| Buttton | Function |
| -- | -- |
| SELECT + START | Reset the emulator |
| SELECT + LEFT / RIGHT | Select the next ROM |
| SELECT + UP / DOWN | Switch the screen mode |
| SELECT + A / B | Toggle rapid-fire |

## Battery backed SRAM
If there is a game with battery-backed memory, 8K bytes per title will be allocated from address 0x10080000 in the reverse direction.
Writing to Flash ROM is done at the timing when reset or ROM selection is made.


66 changes: 66 additions & 0 deletions gamepad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* author : Shuichi TAKANO
* since : Sun Jan 02 2022 18:19:28
*/

#include "gamepad.h"

#include <stdio.h>

namespace io
{
namespace
{
GamePadState currentGamePad_[2];
}

GamePadState &getCurrentGamePadState(int i)
{
return currentGamePad_[i];
}

void
GamePadState::convertButtonsFromAxis(int axisX, int axisY)
{
int x = axis[axisX];
int y = axis[axisY];

if (x < 64)
{
buttons |= Button::LEFT;
}
else if (x > 192)
{
buttons |= Button::RIGHT;
}

if (y < 64)
{
buttons |= Button::UP;
}
else if (y > 192)
{
buttons |= Button::DOWN;
}
}

void
GamePadState::convertButtonsFromHat()
{
static constexpr int table[] = {
Button::UP,
Button::UP | Button::RIGHT,
Button::RIGHT,
Button::DOWN | Button::RIGHT,
Button::DOWN,
Button::LEFT | Button::DOWN,
Button::LEFT,
Button::LEFT | Button::UP,
};
auto i = static_cast<int>(hat);
if (i < 8)
{
buttons |= table[i];
}
}
}
35 changes: 33 additions & 2 deletions gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,42 @@ namespace io
{
struct GamePadState
{
struct Button
{
inline static constexpr int A = 1 << 0;
inline static constexpr int B = 1 << 1;
inline static constexpr int SELECT = 1 << 6;
inline static constexpr int START = 1 << 7;

inline static constexpr int LEFT = 1 << 31;
inline static constexpr int RIGHT = 1 << 30;
inline static constexpr int UP = 1 << 29;
inline static constexpr int DOWN = 1 << 28;
};

enum class Hat
{
N,
NE,
E,
SE,
S,
SW,
W,
NW,
RELEASED,
};

uint8_t axis[3]{0x80, 0x80, 0x80};
uint8_t buttons{};
Hat hat{Hat::RELEASED};
uint32_t buttons{0};

public:
void convertButtonsFromAxis(int axisX, int axisY);
void convertButtonsFromHat();
};

const GamePadState &getCurrentGamePadState(int i);
GamePadState &getCurrentGamePadState(int i);
}

#endif /* _510036F3_0134_6411_4376_A918ACA8AC4C */
Loading

0 comments on commit 5a9b940

Please sign in to comment.