feat: type BitGrid display-layer vtable (0x664144, 8 pixel ops)
Browse filesAdd BitGridDisplayVtable with 8 typed slots: fill_rect, fill_hline,
fill_vline, destructor, get/put_pixel (clipped and unchecked variants).
Consolidate with existing task::bit_grid::BitGrid β the display module
re-exports the same struct and adds the vtable definition. Replace old
DISPLAYGFX_VTABLE / DISPLAY_GFX_VTABLE constants with the macro-generated
BIT_GRID_DISPLAY_VTABLE.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-core/src/address.rs
CHANGED
|
@@ -71,6 +71,7 @@ pub mod va {
|
|
| 71 |
STREAMING_AUDIO_RESET, STREAMING_AUDIO_STOP, STREAMING_AUDIO_TIMER_CALLBACK,
|
| 72 |
};
|
| 73 |
pub use crate::display::base::DISPLAY_BASE_VTABLE;
|
|
|
|
| 74 |
pub use crate::display::compat_renderer::{
|
| 75 |
CompatRendererVtable, COMPAT_RENDERER_VTABLE, DDRAW8_RENDERER_VTABLE,
|
| 76 |
};
|
|
@@ -209,8 +210,8 @@ pub mod va {
|
|
| 209 |
fn/Usercall LOAD_SPRITE_FROM_VFS = 0x004F_AAF0;
|
| 210 |
/// ProcessSprite β parses .spr binary format
|
| 211 |
fn/Usercall PROCESS_SPRITE = 0x004F_AB80;
|
| 212 |
-
//
|
| 213 |
-
vtable
|
| 214 |
}
|
| 215 |
|
| 216 |
class "GfxHandler" {
|
|
@@ -236,8 +237,6 @@ pub mod va {
|
|
| 236 |
}
|
| 237 |
|
| 238 |
class "DisplayGfx" {
|
| 239 |
-
/// DisplayGfx vtable
|
| 240 |
-
vtable DISPLAY_GFX_VTABLE = 0x0066_4144;
|
| 241 |
/// DisplayGfx constructor
|
| 242 |
ctor/Stdcall DISPLAYGFX_CTOR = 0x0056_9C10;
|
| 243 |
/// DisplayGfx constructor (from raw image)
|
|
|
|
| 71 |
STREAMING_AUDIO_RESET, STREAMING_AUDIO_STOP, STREAMING_AUDIO_TIMER_CALLBACK,
|
| 72 |
};
|
| 73 |
pub use crate::display::base::DISPLAY_BASE_VTABLE;
|
| 74 |
+
pub use crate::display::bitgrid::{BitGridDisplayVtable, BIT_GRID_DISPLAY_VTABLE};
|
| 75 |
pub use crate::display::compat_renderer::{
|
| 76 |
CompatRendererVtable, COMPAT_RENDERER_VTABLE, DDRAW8_RENDERER_VTABLE,
|
| 77 |
};
|
|
|
|
| 210 |
fn/Usercall LOAD_SPRITE_FROM_VFS = 0x004F_AAF0;
|
| 211 |
/// ProcessSprite β parses .spr binary format
|
| 212 |
fn/Usercall PROCESS_SPRITE = 0x004F_AB80;
|
| 213 |
+
// Note: vtable 0x664144 is BitGrid display-layer vtable,
|
| 214 |
+
// now defined via #[vtable] macro as BITGRID_DISPLAY_VTABLE.
|
| 215 |
}
|
| 216 |
|
| 217 |
class "GfxHandler" {
|
|
|
|
| 237 |
}
|
| 238 |
|
| 239 |
class "DisplayGfx" {
|
|
|
|
|
|
|
| 240 |
/// DisplayGfx constructor
|
| 241 |
ctor/Stdcall DISPLAYGFX_CTOR = 0x0056_9C10;
|
| 242 |
/// DisplayGfx constructor (from raw image)
|
crates/openwa-core/src/display/bitgrid.rs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! BitGrid display layer vtable β pixel drawing primitives for rendering layers.
|
| 2 |
+
//!
|
| 3 |
+
//! The BitGrid struct lives in `crate::task::bit_grid`. This module adds the
|
| 4 |
+
//! display-layer vtable (0x664144, 8 slots) used by the three rendering layers
|
| 5 |
+
//! in DisplayGfx (+0x3D9C, +0x3DA0, +0x3DA4).
|
| 6 |
+
//!
|
| 7 |
+
//! When used as display layers, the BitGrid is allocated at 0x4C bytes (vs the
|
| 8 |
+
//! base 0x2C). The first 0x2C bytes share the same layout; the extra 0x20 bytes
|
| 9 |
+
//! hold display-layer-specific state.
|
| 10 |
+
//!
|
| 11 |
+
//! ## Field reinterpretation
|
| 12 |
+
//!
|
| 13 |
+
//! Some fields have different semantics in display-layer context:
|
| 14 |
+
//! - `cells_per_unit` (+0x0C) β bit depth (8 for 8bpp)
|
| 15 |
+
//! - `width/height` (+0x14/+0x18) β unused in display context
|
| 16 |
+
//! - `_unused_1c/20` (+0x1C/+0x20) β clip_left / clip_top
|
| 17 |
+
//! - `width_dup/height_dup` (+0x24/+0x28) β clip_right / clip_bottom
|
| 18 |
+
|
| 19 |
+
pub use crate::task::bit_grid::BitGrid;
|
| 20 |
+
|
| 21 |
+
/// BitGrid display-layer vtable (0x664144, 8 slots).
|
| 22 |
+
///
|
| 23 |
+
/// Pixel buffer operations for 8-bit paletted rendering layers.
|
| 24 |
+
/// All pixel addressing uses: `data[y * row_stride + x]`
|
| 25 |
+
///
|
| 26 |
+
/// The DDDisplay creates 3 layer objects in DDDisplay__Init:
|
| 27 |
+
/// - Layer 0 at DisplayGfx+0x3D9C
|
| 28 |
+
/// - Layer 1 at DisplayGfx+0x3DA0
|
| 29 |
+
/// - Layer 2 at DisplayGfx+0x3DA4 (uses BitGrid__Init for extended setup)
|
| 30 |
+
#[openwa_core::vtable(size = 8, va = 0x0066_4144, class = "BitGridDisplay")]
|
| 31 |
+
pub struct BitGridDisplayVtable {
|
| 32 |
+
/// fill rectangle β memset rows [y1..y2) from x1 to x2 with color (0x4F9090, RET 0x14)
|
| 33 |
+
#[slot(0)]
|
| 34 |
+
pub fill_rect: fn(this: *mut BitGrid, x1: i32, y1: i32, x2: i32, y2: i32, color: u8),
|
| 35 |
+
/// fill horizontal line β memset row y from x1 to x2 with color (0x4F90E0, RET 0x10)
|
| 36 |
+
#[slot(1)]
|
| 37 |
+
pub fill_hline: fn(this: *mut BitGrid, x1: i32, x2: i32, y: i32, color: u8),
|
| 38 |
+
/// fill vertical line β set pixels in column x from y1 to y2 (0x4F9110, RET 0x10)
|
| 39 |
+
#[slot(2)]
|
| 40 |
+
pub fill_vline: fn(this: *mut BitGrid, x: i32, y1: i32, y2: i32, color: u8),
|
| 41 |
+
/// destructor β reverts vtable to 0x6640EC, frees data if owned (0x4F5DE0, RET 0x4)
|
| 42 |
+
#[slot(3)]
|
| 43 |
+
pub destructor: fn(this: *mut BitGrid, flags: u8) -> *mut BitGrid,
|
| 44 |
+
/// get pixel (clipped) β returns 0 if (x, y) is outside clip rect (0x4F9140, RET 0x8)
|
| 45 |
+
///
|
| 46 |
+
/// Clip rect: `_unused_1c`..`width_dup` (x), `_unused_20`..`height_dup` (y)
|
| 47 |
+
#[slot(4)]
|
| 48 |
+
pub get_pixel_clipped: fn(this: *mut BitGrid, x: i32, y: i32) -> u8,
|
| 49 |
+
/// put pixel (clipped) β no-op if (x, y) is outside clip rect (0x4F9180, RET 0xC)
|
| 50 |
+
///
|
| 51 |
+
/// This is the main rendering primitive β DDDisplay dispatches drawing
|
| 52 |
+
/// operations through these layer objects.
|
| 53 |
+
#[slot(5)]
|
| 54 |
+
pub put_pixel_clipped: fn(this: *mut BitGrid, x: i32, y: i32, color: u8),
|
| 55 |
+
/// get pixel (unchecked) β direct read, no bounds checking (0x4F5E20, RET 0x8)
|
| 56 |
+
#[slot(6)]
|
| 57 |
+
pub get_pixel: fn(this: *mut BitGrid, x: i32, y: i32) -> u8,
|
| 58 |
+
/// put pixel (unchecked) β direct write, no bounds checking (0x4F5E40, RET 0xC)
|
| 59 |
+
#[slot(7)]
|
| 60 |
+
pub put_pixel: fn(this: *mut BitGrid, x: i32, y: i32, color: u8),
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Note: no bind macro here because BitGrid.vtable is u32, not a typed pointer.
|
| 64 |
+
// Use vcall! or manual vtable dispatch for calling these methods.
|
crates/openwa-core/src/display/gfx.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
use super::base::DisplayBase;
|
|
|
|
| 2 |
use core::ffi::c_void;
|
| 3 |
|
| 4 |
/// DisplayGfx β full display/graphics subsystem (derived from DisplayBase).
|
|
@@ -96,15 +97,15 @@ pub struct DisplayGfx {
|
|
| 96 |
// =========================================================================
|
| 97 |
/// 0x3D98: Render lock flag. Set during rendering, cleared by FlushRender.
|
| 98 |
pub render_lock: u32,
|
| 99 |
-
/// 0x3D9C: Layer 0
|
| 100 |
/// Allocated and initialized in DDDisplay__Init.
|
| 101 |
-
pub layer_0: *mut
|
| 102 |
-
/// 0x3DA0: Layer 1
|
| 103 |
-
pub layer_1: *mut
|
| 104 |
-
/// 0x3DA4: Layer 2
|
| 105 |
-
pub layer_2: *mut
|
| 106 |
-
/// 0x3DA8:
|
| 107 |
-
pub
|
| 108 |
/// 0x3DAC: Layer active flag (init 1)
|
| 109 |
pub layer_active: u32,
|
| 110 |
/// 0x3DB0: Unknown (init 0)
|
|
|
|
| 1 |
use super::base::DisplayBase;
|
| 2 |
+
use crate::task::bit_grid::BitGrid;
|
| 3 |
use core::ffi::c_void;
|
| 4 |
|
| 5 |
/// DisplayGfx β full display/graphics subsystem (derived from DisplayBase).
|
|
|
|
| 97 |
// =========================================================================
|
| 98 |
/// 0x3D98: Render lock flag. Set during rendering, cleared by FlushRender.
|
| 99 |
pub render_lock: u32,
|
| 100 |
+
/// 0x3D9C: Layer 0 β BitGrid pixel buffer (0x4C bytes, vtable 0x664144).
|
| 101 |
/// Allocated and initialized in DDDisplay__Init.
|
| 102 |
+
pub layer_0: *mut BitGrid,
|
| 103 |
+
/// 0x3DA0: Layer 1 β BitGrid pixel buffer (same type as layer_0)
|
| 104 |
+
pub layer_1: *mut BitGrid,
|
| 105 |
+
/// 0x3DA4: Layer 2 β BitGrid pixel buffer (uses BitGrid__Init for extended setup)
|
| 106 |
+
pub layer_2: *mut BitGrid,
|
| 107 |
+
/// 0x3DA8: BitGrid vtable pointer (0x664144). Set in constructor.
|
| 108 |
+
pub bitgrid_vtable: *const c_void,
|
| 109 |
/// 0x3DAC: Layer active flag (init 1)
|
| 110 |
pub layer_active: u32,
|
| 111 |
/// 0x3DB0: Unknown (init 0)
|
crates/openwa-core/src/display/mod.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
pub mod base;
|
|
|
|
| 2 |
pub mod compat_renderer;
|
| 3 |
pub mod dd_display;
|
| 4 |
pub mod display_wrapper;
|
|
@@ -8,6 +9,7 @@ pub mod opengl;
|
|
| 8 |
pub mod palette;
|
| 9 |
|
| 10 |
pub use base::{DisplayBase, DisplayBaseVtable, SpriteBufferCtrl, SpriteCacheWrapper};
|
|
|
|
| 11 |
pub use compat_renderer::CompatRenderer;
|
| 12 |
pub use dd_display::DDDisplay;
|
| 13 |
pub use display_wrapper::DDDisplayWrapper;
|
|
|
|
| 1 |
pub mod base;
|
| 2 |
+
pub mod bitgrid;
|
| 3 |
pub mod compat_renderer;
|
| 4 |
pub mod dd_display;
|
| 5 |
pub mod display_wrapper;
|
|
|
|
| 9 |
pub mod palette;
|
| 10 |
|
| 11 |
pub use base::{DisplayBase, DisplayBaseVtable, SpriteBufferCtrl, SpriteCacheWrapper};
|
| 12 |
+
pub use bitgrid::{BitGrid, BitGridDisplayVtable};
|
| 13 |
pub use compat_renderer::CompatRenderer;
|
| 14 |
pub use dd_display::DDDisplay;
|
| 15 |
pub use display_wrapper::DDDisplayWrapper;
|
crates/openwa-core/src/engine/ddgame_constructor.rs
CHANGED
|
@@ -852,7 +852,7 @@ unsafe fn init_graphics_and_resources(
|
|
| 852 |
core::ptr::write_bytes(tsm, 0, 0x2C);
|
| 853 |
if !tsm.is_null() {
|
| 854 |
bit_grid_init(tsm, 8, 0x100, 0x1E0);
|
| 855 |
-
*(tsm as *mut u32) = rb(va::
|
| 856 |
}
|
| 857 |
(*ddgame).display_gfx = tsm;
|
| 858 |
}
|
|
|
|
| 852 |
core::ptr::write_bytes(tsm, 0, 0x2C);
|
| 853 |
if !tsm.is_null() {
|
| 854 |
bit_grid_init(tsm, 8, 0x100, 0x1E0);
|
| 855 |
+
*(tsm as *mut u32) = rb(va::BIT_GRID_DISPLAY_VTABLE);
|
| 856 |
}
|
| 857 |
(*ddgame).display_gfx = tsm;
|
| 858 |
}
|
crates/openwa-dll/src/replacements/sprite.rs
CHANGED
|
@@ -24,7 +24,7 @@ unsafe extern "cdecl" fn construct_sprite_impl(sprite: *mut Sprite, context: *mu
|
|
| 24 |
|
| 25 |
(*sprite).vtable = rb(va::SPRITE_VTABLE) as *mut u8;
|
| 26 |
(*sprite).context_ptr = context;
|
| 27 |
-
(*sprite).display_gfx = rb(va::
|
| 28 |
|
| 29 |
// DisplayGfx sub-object fields (within _unknown_38)
|
| 30 |
let p = sprite as *mut u8;
|
|
|
|
| 24 |
|
| 25 |
(*sprite).vtable = rb(va::SPRITE_VTABLE) as *mut u8;
|
| 26 |
(*sprite).context_ptr = context;
|
| 27 |
+
(*sprite).display_gfx = rb(va::BIT_GRID_DISPLAY_VTABLE) as *mut u8;
|
| 28 |
|
| 29 |
// DisplayGfx sub-object fields (within _unknown_38)
|
| 30 |
let p = sprite as *mut u8;
|