From a156a8763dc7c1e36bd6193d2d3c7938aace9102 Mon Sep 17 00:00:00 2001 From: paoda Date: Mon, 8 Aug 2022 14:41:48 +0200 Subject: [PATCH] fix: 8-bit writes to WIN PPU registers Advance Wars depends on these registers similar to Mario Kart's 8-bit writes to Affine Background registers: --- src/core/bus/io.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/bus/io.zig b/src/core/bus/io.zig index 7e9e535..4736d2f 100644 --- a/src/core/bus/io.zig +++ b/src/core/bus/io.zig @@ -424,8 +424,12 @@ pub const BldY = extern union { raw: u16, }; +const u8WriteKind = enum { Hi, Lo }; + /// Write-only pub const WinH = extern union { + const Self = @This(); + x2: Bitfield(u16, 0, 8), x1: Bitfield(u16, 8, 8), raw: u16, @@ -433,9 +437,18 @@ pub const WinH = extern union { /// Write-only pub const WinV = extern union { + const Self = @This(); + y2: Bitfield(u16, 0, 8), y1: Bitfield(u16, 8, 8), raw: u16, + + pub fn set(self: *Self, comptime K: u8WriteKind, value: u8) void { + self.raw = switch (K) { + .Hi => (@as(u16, value) << 8) | self.raw & 0xFF, + .Lo => (self.raw & 0xFF00) | value, + }; + } }; pub const WinIn = extern union {