deltabeard / Peanut-GB

A Game Boy (DMG) emulator single header library written in C99. Performance is prioritised over accuracy.
https://projects.deltabeard.com/peanutgb/
276 stars 35 forks source link

Graphics glitches in wasm32 target #98

Closed lesleyrs closed 4 months ago

lesleyrs commented 4 months ago

Hi I tried porting this to wasm without using emscripten (gone wrong) and other than image-rendering: pixelated; not being as good as I hoped, there is also another issue with graphics being really glitchy at specific times.

https://github.com/lesleyrs/Peanut-WASM

I included 2 gb rom headers, tobudx has almost no graphics glitches but pokered is quite bad. It looks like it crashes if you don't press any keys on titlescreen. But gb_error doesn't print any errors to console and you can still reset, although nothing happens after white screen. In the overworld it works again but in battles it goes crazy. Any clue why this would happen? It's really bad.

lesleyrs commented 4 months ago

Never mind I forgot to allocate memory for cart_ram. Fixed now it works :D

deltabeard commented 4 months ago

Nice to hear you got it working! Whilst your repo isn't available/public anymore (I was interested in the WASM implementation without emscripten...) be careful not to include non-redistributable ROMs (like Pokemon Red) in your repo. You can use open source ROMs instead to prove your implementation. 😃

lesleyrs commented 4 months ago

@deltabeard I'll leave a message here once I make it public again, just trying to finish it up. Not sure if it meets your expectations because I haven't worked out how to optimally interact with wasm in JS (I just turned every interaction into a function for simplicity, but I guess you should be able to change variables etc directly).

It's working well though which is my goal, the pixel scaling with image-rendering: pixelated; was fixed by this issue too.

lesleyrs commented 4 months ago

It turns out you actually can't use variables from wasm in js, only call functions and access memory directly. Took longer than expected because I end up implementing almost all features, behold: https://github.com/lesleyrs/web-gbc. I'm quite happy with the results, I actually just let the main function in wasm exit and just call the 2 required functions in JS loop.

BTW using your cgb branch shows this warning message in polished crystal about emulator bugs: https://github.com/Rangi42/polishedcrystal/blob/3c769991deb0a0756d7e9accd3f6a496003c7689/data/text/common.asm#L3340

Code here: https://github.com/Rangi42/polishedcrystal/blob/master/home/vba.asm Is this a hard or easy fix to avoid the warning?