SDL2 drivers for Playdate? Yes!

The device is restarted (very quickly, it takes about a second) when you select home after playing a game. So it's a fresh boot every time.

2 Likes

I didn’t realize the stack was so small! (8kb). New question, this is running in “unbounded” refresh == 0 mode, maybe that could be a cause?

1 Like

This build might actually work. I reduced some overhead and made sure that the refresh rate was actually bounded, hoping that may preserve the stack a little? I am working on a far simpler demo that should have no trouble at all.

m4kcv3.pdx.zip (606.7 KB)

2 Likes

I'm afraid this overflows the stack immediately on launch…

1 Like

Darn! Well, much progress on this will need to wait till I get my device :frowning: Don't want to keep bothering folks and this async manner of testing is quite difficult.

the repo I posted is nearly enough to reproduce the builds. I will make a separate repo with the changes I felt less comfortable including for SDL (want eventually to upstream), some of the build steps are still a bit hacky.

2 Likes

Hit me up when you get a little further, if you think this is worth merging into mainline SDL. :slight_smile:

5 Likes

I do have one question for you icculus that I am not entirely sure of the answer for. My SDL video driver automatically converts everything to a given PixelFormat which is then modified to output the dithered b&w images seen on this thread. I couldn’t tell if it was “kosher” to do such manipulation of video out. One thing I realized is I probably shouldn’t do that for all pixel formats (where artists already are in line with the PD display limits) but I also wasn’t sure if it was considered “the way” or if I should instead say no-no-no you can’t use anything but 1bpp.

The rest of the drivers are quite straightforward though I haven’t tackled audio yet.

2 Likes

I'm pretty sure you'll have to dither to 1-bit on your end of things; I don't think SDL in general supports 1-bit video.

3 Likes

It doesn’t, I just wasn’t sure if SDL video drivers took things into their own hands or raised a flag to the game saying: wait you need to use a different color palette for this system. There are pixel formats which get close to 1bpp and are meant to be used that way.

1 Like

In most cases we try to make whatever work transparently, so you're on the right course already.

3 Likes

Created a super simple snake game with SDL2, hopefully this one is lightweight enough to work :laughing: So if anyone with a device wants to give it a shot, let me know the results!

snake.pdx.zip (592.0 KB)

press the d-pad to start the snake moving.

Buttons:
d-pad: move the snake
menu: see your score
a: reset game if dead

5 Likes

This works on device. I was able to achieve a score of about 5 (I think) in the short time I played, and experienced no crashes — good job!

4 Likes

WOOOOOOOOOOOT!

you can see your score in the menu, if you die just press menu and it'll show there. obvi not a very optimized experience lool.

This is great news though, I will continue with trying to make it fit.

2 Likes

May I ask what the FPS seems like? smoothish? it's supposed to not really be 30fps in this kinda game obviously.

1 Like

It's a bit herky-jerky. I wonder if that makes some of the precise timing needed to not bonk into walls trickier, but it also feels about right for Snake!

Trying to open snake.pdx in Playdate Simulator (build 133541) to understand a best-case FPS scenario, I get an error:

dlopen([.]/snake.pdx/pdex.dylib, 0x0006):
 tried: '[.]/snake.pdx/pdex.dylib' (mach-o file,
 but is an incompatible architecture (have 'arm64',
 need 'x86_64h')), '/usr/local/lib/pdex.dylib'
 (no such file), '/usr/lib/pdex.dylib' (no such file)

Compiled on ARM, but I'm on Intel? As an aside: I haven't had a chance to do much digging on this error, but certainly can file if it's interesting!

2 Likes

This is because the simulator version was built on an M1 - it is to be expected that it won't work in x86 simulators.

I did bare minimum and adapted from a tutorial on the web heh, so it could be crappy for various reasons. I can compile a version with the FPS drawn on screen if helpful.

Edit: I get about 40fps on simulator, which isn't great. The device fps is probably like 15fps. Attached is a version where it tries to draw FPS (doesn't work great) and also sets refresh rate to be unbounded.

Edit 2: the code I used for the snake game also tries correcting for FPS so it may also be related to that. I have next to 0 SDL exp :frowning:

snakev2.pdx.zip (582.2 KB)

1 Like

Yep! You pretty much nailed it, I'm consistently seeing it report 13 in the upper left corner.

2 Likes

That is pretty terrible! lol

1 Like

I think I might have fixed the fps issue, if you wouldn't mind giving this a shot @edaw :smiley:
snek.pdx.zip (582.6 KB)

Edit: the attempted fix here is to not use the SDL delay in the update loop. I don't think it was necessary.

snek V2 (works)
snekv2.pdx.zip (582.8 KB)

ray caster demo (very slow)
raycaster.pdx.zip (592.2 KB)

arduboy (doesn't work)
arduboy.pdx.zip (201.7 KB)

arduboy v2 (doesn't work)
arduboy.pdx.zip (157.2 KB)

arduboy v2.1 (doesn't work)
arduboyv21.pdx.zip (157.5 KB)

arduboy v2.2 (doesn't work)
arduboyv22.pdx.zip (158.0 KB)
arduboyv221.pdx.zip (158.0 KB)
arduboyv222.pdx.zip (158.1 KB)

arduboy v3
arduboy_v3.pdx.zip (574.6 KB)

Chip-8
chip8.pdx.zip (66.9 KB)
chip8_v2.pdx.zip (67.2 KB)

2 Likes

I want to see Playdate SDL2 mainlined.

2 Likes