Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patch to fix rendering on 4.8 inch devices #23

Open
wants to merge 2 commits into
base: main
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ A pongoOS module for running the BRIX game, featuring rendering code I wrote at
## Compatibility

Currently supported devices:

- iPhone 7 GSM (iPhone9,3)
- iPad Pro 10.5-inch WiFi/Cellular (iPad7,4)
- iPad 10.2-inch 7th Gen WiFi/Cellular (iPad7,12)
- iPod Touch 6th Gen (iPod7,1)
- iPod Touch 6th Gen (iPod7,1) ([requires extra patching](#48-inch-devices))

If your device is already supported, great! You won't have to modify the code. You can skip to [running BRIX](#running-brix). If your device isn't supported, adding support for your own device shouldn't be hard.

Expand Down Expand Up @@ -58,6 +59,14 @@ Address: 0x20f1000a0
1. Run `make load_brix`. This will compile the module and load it in pongoOS.
2. Run `brix` in the pongoOS shell. Your device should now be running BRIX.

### 4.8-inch devices

For devices with a 4.8-inch screen, a different method for rendering is required. Before building `brix`, make sure to apply the patch in `fix-rendering.patch`.

```
$ git apply -v fix-rendering.patch
```

## Controls

- **Movement:** vol+, vol-
Expand Down
33 changes: 33 additions & 0 deletions fix-rendering.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Fix rendering for the following devices:

* iPod Touch (all supported models)
* iPhone 5s (iPhone6,2)
* Any supported device with a 4.8 inch screen

=================================================
diff -urN a/main.c b/main.c
--- a/main.c 2023-06-02 02:06:31.000000000 +0200
+++ b/main.c 2023-06-02 00:49:29.000000000 +0200
@@ -137,17 +137,17 @@
void redraw_screen(chip8_t *self, chip8_event_t event) {
const uint32_t scale = game_scale;
const uint8_t flip = device->home_button_at_right;
- const uint32_t yOffset = (gHeight - (CHIP8_SCREEN_WIDTH * scale)) / 2;
- const uint32_t xOffset = (gWidth - (CHIP8_SCREEN_HEIGHT * scale)) / 2;
- for (uint32_t y=event.redraw_event.y; y<event.redraw_event.y + event.redraw_event.height; y++) {
- for (uint32_t x=event.redraw_event.x; x<event.redraw_event.x + event.redraw_event.width; x++) {
+ const uint32_t y_offset = (gHeight - (CHIP8_SCREEN_WIDTH * scale)) / 2;
+ const uint32_t x_offset = (gWidth - (CHIP8_SCREEN_HEIGHT * scale)) / 2;
+ for (uint32_t y = 0; y < CHIP8_SCREEN_HEIGHT; y++) {
+ for (uint32_t x = 0; x < CHIP8_SCREEN_WIDTH; x++) {
uint32_t rx = x % CHIP8_SCREEN_WIDTH;
uint32_t ry = y % CHIP8_SCREEN_HEIGHT;
uint32_t tx = (flip ? rx : (CHIP8_SCREEN_WIDTH - rx - 1));
uint32_t ty = (flip ? (CHIP8_SCREEN_HEIGHT - ry - 1) : ry);
for (uint32_t sx = ty * scale; sx < (ty + 1) * scale; sx++) {
for (uint32_t sy = tx * scale; sy < (tx + 1) * scale; sy++) {
- gFramebuffer[gRowPixels * (sy + yOffset) + (sx + xOffset)] = self->framebuffer[rx][ry] ? 0xFFFFFFFF : 0x0;
+ gFramebuffer[gRowPixels * (sy + y_offset) + (sx + x_offset)] = self->framebuffer[rx][ry] ? 0xFFFFFFFF : 0x0;
}
}
}