deltabeard / Peanut-GB

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

core: lcd_mode enum type as signed int #46

Closed Ryzee119 closed 4 years ago

Ryzee119 commented 4 years ago

On some compilers lcd_mode enum is assumed int (I dont know why?) and not unsigned int. Therefore the bitfield should be large enough to encompass the sign bit

https://github.com/deltabeard/Peanut-GB/blob/1ad02b57cd93600ea7899ec416ae95635b4160a6/peanut_gb.h#L376-L382

lcd_mode : 2 should be lcd_mode : 3?

Currently I get warnings like this warning: implicit truncation from 'int' to bit-field changes value from 3 to -1 [-Wbitfield-constant-conversion] gb->lcd_mode = LCD_TRANSFER; and the screen is not rendered

deltabeard commented 4 years ago

I think the underlying type of enum in C is int, so I guess your compiler isn't wrong. I think a good solution is to keep the definition as lcd_mode : 2, but change the enum declaration to defines instead.

deltabeard commented 4 years ago

Would you be able to test this potential fix for me please? https://github.com/deltabeard/Peanut-GB/compare/bug/lcd_bitfields I tested it working with Pokemon Gold with the SDL2 example. Many thanks.

Ryzee119 commented 4 years ago

I can confirm that this fix works Thank you!