Skip to content

Commit

Permalink
amiga/amigaaga.cpp: implement palette reads
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosa committed Feb 4, 2025
1 parent a7b26f0 commit f92cb92
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/mame/amiga/amiga.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ class amiga_state : public driver_device
void render_scanline(bitmap_rgb32 &bitmap, int scanline);

// AGA video helpers
void aga_palette_write(int color_reg, uint16_t data);
u16 aga_palette_read(offs_t color_reg);
void aga_palette_write(offs_t color_reg, uint16_t data);
void aga_fetch_sprite_data(int scanline, int sprite);
void aga_render_scanline(bitmap_rgb32 &bitmap, int scanline);
void aga_update_sprite_dma(int scanline, int num);
Expand Down
34 changes: 13 additions & 21 deletions src/mame/amiga/amiga_m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,17 @@ void amiga_state::ocs_map(address_map &map)
// Sprite section
// map(0x120, 0x17f).m(amiga_state::sprxpt_map));
// Color section
// map(0x180, 0x1bf).m(amiga_state::colorxx_map));
map(0x180, 0x1bf).lrw16(
NAME([this] (offs_t offset) {
return CUSTOM_REG(REG_COLOR00 + offset);
}),
NAME([this] (offs_t offset, u16 data) {
CUSTOM_REG(REG_COLOR00 + offset) = data;
data &= 0xfff;
// Extra Half-Brite
CUSTOM_REG(REG_COLOR00 + offset + 32) = (data >> 1) & 0x777;
})
);
}

void amiga_state::ecs_map(address_map &map)
Expand Down Expand Up @@ -1229,6 +1239,8 @@ void amiga_state::aga_map(address_map &map)

map(0x10e, 0x10f).w(FUNC(amiga_state::clxcon2_w));

map(0x180, 0x1bf).rw(FUNC(amiga_state::aga_palette_read), FUNC(amiga_state::aga_palette_write));

// UHRES regs
// TODO: may be shared with ECS?
// map(0x1e6, 0x1e7).w(FUNC(amiga_state::bplhmod_w));
Expand Down Expand Up @@ -1699,26 +1711,6 @@ void amiga_state::custom_chip_w(offs_t offset, uint16_t data)
data &= ~1;
break;

case REG_COLOR00: case REG_COLOR01: case REG_COLOR02: case REG_COLOR03:
case REG_COLOR04: case REG_COLOR05: case REG_COLOR06: case REG_COLOR07:
case REG_COLOR08: case REG_COLOR09: case REG_COLOR10: case REG_COLOR11:
case REG_COLOR12: case REG_COLOR13: case REG_COLOR14: case REG_COLOR15:
case REG_COLOR16: case REG_COLOR17: case REG_COLOR18: case REG_COLOR19:
case REG_COLOR20: case REG_COLOR21: case REG_COLOR22: case REG_COLOR23:
case REG_COLOR24: case REG_COLOR25: case REG_COLOR26: case REG_COLOR27:
case REG_COLOR28: case REG_COLOR29: case REG_COLOR30: case REG_COLOR31:
if (IS_AGA())
{
aga_palette_write(offset - REG_COLOR00, data);
}
else
{
data &= 0xfff;
// Extra Half-Brite
CUSTOM_REG(offset + 32) = (data >> 1) & 0x777;
}
break;

// display window start/stop
case REG_DIWSTRT:
case REG_DIWSTOP:
Expand Down
24 changes: 23 additions & 1 deletion src/mame/amiga/amigaaga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,26 @@
*
*************************************/

void amiga_state::aga_palette_write(int color_reg, uint16_t data)
u16 amiga_state::aga_palette_read(offs_t color_reg)
{
u8 pal_bank = (CUSTOM_REG(REG_BPLCON3) >> 13) & 0x07;

int color = (pal_bank * 32) + color_reg;

u8 cr = m_aga_palette[color].r();
u8 cg = m_aga_palette[color].g();
u8 cb = m_aga_palette[color].b();

// LOCT
if (BIT(CUSTOM_REG(REG_BPLCON3),9))
{
return ((cr & 0xf) << 8) | ((cg & 0xf) << 4) | ((cb & 0xf) << 0);
}

return ((cr & 0xf0) << 4) | (cg & 0xf0) | ((cb & 0xf0) >> 4);
}

void amiga_state::aga_palette_write(offs_t color_reg, uint16_t data)
{
int r,g,b;
int cr,cg,cb;
Expand All @@ -68,7 +87,9 @@ void amiga_state::aga_palette_write(int color_reg, uint16_t data)
cr = (r << 4) | r;
cg = (g << 4) | g;
cb = (b << 4) | b;
// TODO: transparency, bit 15
}

m_aga_palette[color] = rgb_t(cr, cg, cb);
// make a copy for Extra Half Brite mode
if (pal_bank == 0)
Expand Down Expand Up @@ -499,6 +520,7 @@ void amiga_state::aga_render_scanline(bitmap_rgb32 &bitmap, int scanline)
CUSTOM_REG(REG_VPOSR) ^= VPOSR_LOF;

m_copper->vblank_sync(true);
// TODO: shouldn't be raw color ...
m_ham_color = CUSTOM_REG(REG_COLOR00);
}

Expand Down

0 comments on commit f92cb92

Please sign in to comment.