Import latest peanut_gb. from deltabeard (fix BG over OBJ with colour 0)

This commit is contained in:
Vincent Mistler
2022-12-18 11:41:59 +01:00
parent 4a0516a7ae
commit 1ec7701b74
2 changed files with 3865 additions and 3882 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ void i2s_init(i2s_config_t *i2s_config) {
* len: length of sample in 32 bits words
*/
void i2s_write(const i2s_config_t *i2s_config,const int16_t *samples,const size_t len) {
for(size_t i=0;i<len;i+=2) {
for(size_t i=0;i<len;i++) {
pio_sm_put_blocking(i2s_config->pio, i2s_config->sm, (uint32_t)samples[i]);
}
}
+8 -25
View File
@@ -980,8 +980,11 @@ void __gb_write(struct gb_s *gb, const uint_fast16_t addr, const uint8_t val)
return;
}
gb->hram_io[IO_STAT] = (gb->hram_io[IO_STAT] & ~0x03) | 1;
/* Set LCD to Mode 0. */
gb->hram_io[IO_STAT] = (gb->hram_io[IO_STAT] & ~0x03);
/* Set to line 0. */
gb->hram_io[IO_LY] = 0;
/* Reset LCD timer. */
gb->counter.lcd_count = 0;
}
@@ -1289,7 +1292,6 @@ static int compare_sprites(const void *in1, const void *in2)
void __gb_draw_line(struct gb_s *gb)
{
uint8_t pixels[160] = {0};
uint8_t bg_priority[20];
/* If LCD not initialised by front-end, don't render anything. */
if(gb->display.lcd_draw_line == NULL)
@@ -1350,8 +1352,6 @@ void __gb_draw_line(struct gb_s *gb)
uint16_t tile;
bg_priority[disp_x/8] = idx;
/* Select addressing mode. */
if(gb->hram_io[IO_LCDC] & LCDC_TILE_SELECT)
tile = VRAM_TILES_1 + idx * 0x10;
@@ -1381,8 +1381,6 @@ void __gb_draw_line(struct gb_s *gb)
tile += 2 * py;
t1 = gb->vram[tile];
t2 = gb->vram[tile + 1];
bg_priority[disp_x / 8] = idx;
}
/* copy background */
@@ -1549,9 +1547,6 @@ void __gb_draw_line(struct gb_s *gb)
// handle x flip
uint8_t dir, start, end, shift;
uint8_t bg_priority_tile;
uint8_t tile_has_priority;
if(OF & OBJ_FLIP_X)
{
dir = 1;
@@ -1567,9 +1562,6 @@ void __gb_draw_line(struct gb_s *gb)
shift = OX - (start + 1);
}
bg_priority_tile = bg_priority[start / 8];
tile_has_priority = OT < bg_priority_tile;
// copy tile
t1 >>= shift;
t2 >>= shift;
@@ -1582,20 +1574,12 @@ void __gb_draw_line(struct gb_s *gb)
uint8_t c = (t1 & 0x1) | ((t2 & 0x1) << 1);
// check transparency / sprite overlap / background overlap
if(c && (OF & OBJ_PRIORITY) && tile_has_priority)
{
/* Set pixel colour. */
pixels[disp_x] ^= (OF & OBJ_PALETTE)
? gb->display.sp_palette[c + 4]
: gb->display.sp_palette[c];
pixels[disp_x] = ((~pixels[disp_x]) & 0x3);
}
else if(c && !(OF & OBJ_PRIORITY && (pixels[disp_x] & 0x3)))
if(c && !(OF & OBJ_PRIORITY && !((pixels[disp_x] & 0x3) == gb->display.bg_palette[0])))
{
/* Set pixel colour. */
pixels[disp_x] = (OF & OBJ_PALETTE)
? gb->display.sp_palette[c + 4]
: gb->display.sp_palette[c];
? gb->display.sp_palette[c + 4]
: gb->display.sp_palette[c];
/* Set pixel palette (OBJ0 or OBJ1). */
pixels[disp_x] |= (OF & OBJ_PALETTE);
}
@@ -3351,8 +3335,7 @@ void __gb_step_cpu(struct gb_s *gb)
gb->counter.lcd_count += inst_cycles;
/* New Scanline */
if((gb->hram_io[IO_STAT] & STAT_MODE) & IO_STAT_MODE_VBLANK_OR_TRANSFER_MASK &&
gb->counter.lcd_count >= LCD_LINE_CYCLES)
if(gb->counter.lcd_count >= LCD_LINE_CYCLES)
{
gb->counter.lcd_count -= LCD_LINE_CYCLES;