paavohtl commited on
Commit
8300566
·
1 Parent(s): 902aa11

refactor: type DisplayGfx +0x3DA8..0x3DD4 as embedded BitGrid

Browse files

Replaces the scattered bitgrid_vtable / layer_active / _unknown_3db0 /
bit_depth / _unknown_3db8 fields with a single `BitGrid` sub-object.

Confirmed by `DisplayGfx::DestructorImpl` (0x56A010) which rebinds
+0x3DA8 to &BitGrid__vtable and conditionally frees +0x3DB0 (data)
based on +0x3DAC (external_buffer) — the textbook BitGrid destructor
pattern. The constructor's writes (`*+0x3DAC = 1`, `*+0x3DB4 = 8`)
also match BitGrid's external_buffer / cells_per_unit fields.

This is the fourth BitGrid in DisplayGfx, distinct from the three
heap-allocated layer pointers at +0x3D9C/+0x3DA0/+0x3DA4.

Pre-work for porting DisplayGfx::Destructor (slot 0).

crates/openwa-core/src/render/display/gfx.rs CHANGED
@@ -1,8 +1,7 @@
1
  use super::base::DisplayBase;
2
  use super::vtable::DisplayGfxVtable;
3
- use crate::bitgrid::DisplayBitGrid;
4
  use crate::render::sprite::sprite::{CBitmap, LayerSprite};
5
- use core::ffi::c_void;
6
 
7
  /// DisplayGfx — full display/graphics subsystem (derived from DisplayBase).
8
  ///
@@ -119,16 +118,15 @@ pub struct DisplayGfx {
119
  pub layer_1: *mut DisplayBitGrid,
120
  /// 0x3DA4: Layer 2 — same layout, but also initialized via BitGrid::Init(8, 128, 128).
121
  pub layer_2: *mut DisplayBitGrid,
122
- /// 0x3DA8: BitGrid vtable pointer (0x664144). Set in constructor.
123
- pub bitgrid_vtable: *const c_void,
124
- /// 0x3DAC: Layer active flag (init 1)
125
- pub layer_active: u32,
126
- /// 0x3DB0: Unknown (init 0)
127
- pub _unknown_3db0: u32,
128
- /// 0x3DB4: Bit depth (init 8 in constructor — 8bpp paletted mode)
129
- pub bit_depth: u32,
130
- /// 0x3DB8 - 0x3DD3: Unknown fields (all init 0 in constructor)
131
- pub _unknown_3db8: [u8; 0x3DD4 - 0x3DB8],
132
 
133
  // =========================================================================
134
  // Sprite/bitmap table (0x3DD4 - 0x4DD7)
@@ -190,6 +188,8 @@ pub struct DisplayGfx {
190
  }
191
 
192
  const _: () = assert!(core::mem::size_of::<DisplayGfx>() == 0x24E28);
 
 
193
  const _: () = assert!(core::mem::offset_of!(DisplayGfx, tile_bitmap_sets) == 0x4DD4);
194
  const _: () = assert!(core::mem::offset_of!(DisplayGfx, tile_total_width) == 0x4DDC);
195
  const _: () = assert!(core::mem::offset_of!(DisplayGfx, tile_total_height) == 0x4DE0);
 
1
  use super::base::DisplayBase;
2
  use super::vtable::DisplayGfxVtable;
3
+ use crate::bitgrid::{BitGrid, BitGridBaseVtable, DisplayBitGrid};
4
  use crate::render::sprite::sprite::{CBitmap, LayerSprite};
 
5
 
6
  /// DisplayGfx — full display/graphics subsystem (derived from DisplayBase).
7
  ///
 
118
  pub layer_1: *mut DisplayBitGrid,
119
  /// 0x3DA4: Layer 2 — same layout, but also initialized via BitGrid::Init(8, 128, 128).
120
  pub layer_2: *mut DisplayBitGrid,
121
+ /// 0x3DA8 - 0x3DD3: Embedded `BitGrid` sub-object (0x2C bytes).
122
+ ///
123
+ /// A BitGrid allocated INLINE in DisplayGfx, distinct from the three
124
+ /// heap-allocated layer pointers above. Confirmed by `DisplayGfx::DestructorImpl`
125
+ /// (0x56A010), which rebinds `+0x3DA8` to `&BitGrid__vtable` and frees
126
+ /// `+0x3DB0` (= BitGrid::data) if `+0x3DAC` (= BitGrid::external_buffer) is 0.
127
+ /// The constructor sets `+0x3DAC = 1` (external_buffer) and `+0x3DB4 = 8`
128
+ /// (cells_per_unit), matching the standard BitGrid layout exactly.
129
+ pub embedded_bitgrid: BitGrid<*const BitGridBaseVtable>,
 
130
 
131
  // =========================================================================
132
  // Sprite/bitmap table (0x3DD4 - 0x4DD7)
 
188
  }
189
 
190
  const _: () = assert!(core::mem::size_of::<DisplayGfx>() == 0x24E28);
191
+ const _: () = assert!(core::mem::offset_of!(DisplayGfx, embedded_bitgrid) == 0x3DA8);
192
+ const _: () = assert!(core::mem::offset_of!(DisplayGfx, sprite_table) == 0x3DD4);
193
  const _: () = assert!(core::mem::offset_of!(DisplayGfx, tile_bitmap_sets) == 0x4DD4);
194
  const _: () = assert!(core::mem::offset_of!(DisplayGfx, tile_total_width) == 0x4DDC);
195
  const _: () = assert!(core::mem::offset_of!(DisplayGfx, tile_total_height) == 0x4DE0);