From 14b6393b51a3e8ea38e83d2bef8c30db7d83cae2 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 1 Oct 2014 02:50:10 -0700 Subject: [PATCH] Replace BGCNT with bitfield --- src/gba/gba-video.h | 21 ++++++++------------- src/gba/renderers/video-software.c | 15 +++++++-------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/gba/gba-video.h b/src/gba/gba-video.h index f2d8e5287..674c4402c 100644 --- a/src/gba/gba-video.h +++ b/src/gba/gba-video.h @@ -141,19 +141,14 @@ DECL_BIT(GBARegisterDISPSTAT, HblankIRQ, 4); DECL_BIT(GBARegisterDISPSTAT, VcounterIRQ, 5); DECL_BITS(GBARegisterDISPSTAT, VcountSetting, 8, 8); -union GBARegisterBGCNT { - struct { - unsigned priority : 2; - unsigned charBase : 2; - unsigned : 2; - unsigned mosaic : 1; - unsigned multipalette : 1; - unsigned screenBase : 5; - unsigned overflow : 1; - unsigned size : 2; - }; - uint16_t packed; -}; +DECL_BITFIELD(GBARegisterBGCNT, uint16_t); +DECL_BITS(GBARegisterBGCNT, Priority, 0, 2); +DECL_BITS(GBARegisterBGCNT, CharBase, 2, 2); +DECL_BIT(GBARegisterBGCNT, Mosaic, 6); +DECL_BIT(GBARegisterBGCNT, 256Color, 7); +DECL_BITS(GBARegisterBGCNT, ScreenBase, 8, 5); +DECL_BIT(GBARegisterBGCNT, Overflow, 13); +DECL_BITS(GBARegisterBGCNT, Size, 14, 2); struct GBAVideoRenderer { void (*init)(struct GBAVideoRenderer* renderer); diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 012de3e2d..407d2a8c4 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -532,14 +532,13 @@ static void GBAVideoSoftwareRendererUpdateDISPCNT(struct GBAVideoSoftwareRendere static void GBAVideoSoftwareRendererWriteBGCNT(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* bg, uint16_t value) { UNUSED(renderer); - union GBARegisterBGCNT reg = { .packed = value }; - bg->priority = reg.priority; - bg->charBase = reg.charBase << 14; - bg->mosaic = reg.mosaic; - bg->multipalette = reg.multipalette; - bg->screenBase = reg.screenBase << 11; - bg->overflow = reg.overflow; - bg->size = reg.size; + bg->priority = GBARegisterBGCNTGetPriority(value); + bg->charBase = GBARegisterBGCNTGetCharBase(value) << 14; + bg->mosaic = GBARegisterBGCNTGetMosaic(value); + bg->multipalette = GBARegisterBGCNTGet256Color(value); + bg->screenBase = GBARegisterBGCNTGetScreenBase(value) << 11; + bg->overflow = GBARegisterBGCNTGetOverflow(value); + bg->size = GBARegisterBGCNTGetSize(value); } static void GBAVideoSoftwareRendererWriteBGPA(struct GBAVideoSoftwareBackground* bg, uint16_t value) {