From 9a863caa23794b081f4e6831ab9f4fbafd366a13 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 17 Mar 2025 00:37:45 +0000 Subject: [PATCH] Fix rop core. Implement some basic image in memory methods. --- .../86box/nv/classes/vid_nv3_classes.h | 5 +++-- src/include/86box/nv/vid_nv3.h | 7 +++--- src/utils/video/video_rop.c | 10 ++++++--- .../classes/nv3_class_01c_image_in_memory.c | 14 +++++++++++- src/video/nv/nv3/render/nv3_render_core.c | 21 ++---------------- src/video/nv/nv3/subsystems/nv3_pgraph.c | 22 ++++++++++++++++++- 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/include/86box/nv/classes/vid_nv3_classes.h b/src/include/86box/nv/classes/vid_nv3_classes.h index c015d0659..39c03b295 100644 --- a/src/include/86box/nv/classes/vid_nv3_classes.h +++ b/src/include/86box/nv/classes/vid_nv3_classes.h @@ -81,6 +81,7 @@ typedef enum nv3_pgraph_class_e #define NV3_IMAGE_IN_MEMORY_IN_MEMORY_DMA_CTX_TYPE 0x0304 #define NV3_IMAGE_IN_MEMORY_PITCH 0x0308 #define NV3_IMAGE_IN_MEMORY_TOP_LEFT_OFFSET 0x030C +#define NV3_IMAGE_IN_MEMORY_TOP_LEFT_OFFSET_END 22 #define NV3_W95TXT_COLORA 0x03FC // It's the colour of the text. This is used to submit a dummy object so the notifier can be used to sync in Win2000 DDraw6 drivers. @@ -118,14 +119,14 @@ typedef struct nv3_color_argb_32_s } nv3_color_argb_32_t; /* 30-bit colour format for internal PGRAPH use */ -typedef struct nv3_color_x3a10g10b10_s +typedef struct nv3_color_x2a10g10b10_s { uint8_t reserved : 1; bool alpha_if_chroma_key_otherwise_reserved2 : 1; // 1-bit ALPHA if chroma key, OTHERWISE USELESS and IGNORE uint16_t r : 10; uint16_t g : 10; uint16_t b : 10; -} nv3_color_x3a10g10b10_t; +} nv3_color_x2a10g10b10_t; /* 16-bit A4R4G4B4 colour format */ typedef struct nv3_color_16_a4r4g4b4_s diff --git a/src/include/86box/nv/vid_nv3.h b/src/include/86box/nv/vid_nv3.h index 3c99782e6..fb080f1cd 100644 --- a/src/include/86box/nv/vid_nv3.h +++ b/src/include/86box/nv/vid_nv3.h @@ -1114,17 +1114,18 @@ typedef struct nv3_pgraph_s nv3_position_16_bigy_t dst_canvas_min; nv3_position_16_bigy_t dst_canvas_max; // Pattern stuff - nv3_color_x3a10g10b10_t pattern_color_0_0; + nv3_color_x2a10g10b10_t pattern_color_0_0; uint32_t pattern_color_0_1; // only 7:0 relevant - nv3_color_x3a10g10b10_t pattern_color_1_0; + nv3_color_x2a10g10b10_t pattern_color_1_0; uint32_t pattern_color_1_1; // only 7:0 relevant uint32_t pattern_bitmap_high; // high part of pattern bitmap for blit uint32_t pattern_bitmap_low; uint32_t pattern_shape; // may need to be an enum - 0=8x8, 1=64x1, 2=1x64 uint32_t plane_mask; // only 7:0 relevant - nv3_color_x3a10g10b10_t chroma_key; // color key + nv3_color_x2a10g10b10_t chroma_key; // color key uint32_t beta_factor; nv3_pgraph_dma_settings_t dma_settings; + uint8_t rop; // Current GDI Ternary Render Operation nv3_pgraph_clip_misc_settings_t clip_misc_settings; nv3_notifier_t notifier; nv3_position_16_bigy_t clip0_min; diff --git a/src/utils/video/video_rop.c b/src/utils/video/video_rop.c index b6350b2e9..8bfdc9627 100644 --- a/src/utils/video/video_rop.c +++ b/src/utils/video/video_rop.c @@ -10,8 +10,10 @@ This is currently used in the following graphics cards: Tseng Labs ET4000/32p, Cirrus Logic CL-GD54xx, 3dfx Voodoo Banshee/Voodoo 3, Trident TGUI9440, S3 ViRGE, C&T 69000, ATI Mach64, and NVidia RIVA 128 */ -int32_t video_rop_gdi_ternary(int32_t rop, int32_t dst, int32_t pattern, int32_t src, int32_t out) -{ +int32_t video_rop_gdi_ternary(int32_t rop, int32_t dst, int32_t pattern, int32_t src) +{ + uint32_t out = 0x00; + switch (rop) { case 0x00: @@ -782,5 +784,7 @@ int32_t video_rop_gdi_ternary(int32_t rop, int32_t dst, int32_t pattern, int32_t case 0xff: out = ~0; break; - } + } + + return out; } \ No newline at end of file diff --git a/src/video/nv/nv3/classes/nv3_class_01c_image_in_memory.c b/src/video/nv/nv3/classes/nv3_class_01c_image_in_memory.c index a74313276..b42583f7a 100644 --- a/src/video/nv/nv3/classes/nv3_class_01c_image_in_memory.c +++ b/src/video/nv/nv3/classes/nv3_class_01c_image_in_memory.c @@ -28,10 +28,22 @@ #include <86box/nv/vid_nv.h> #include <86box/nv/vid_nv3.h> -void nv3_class_01c_method(uint32_t name, uint32_t method_id, nv3_ramin_context_t context, nv3_grobj_t grobj) +void nv3_class_01c_method(uint32_t param, uint32_t method_id, nv3_ramin_context_t context, nv3_grobj_t grobj) { switch (method_id) { + case NV3_IMAGE_IN_MEMORY_COLOR_FORMAT: + break; + /* Pitch - length between scanlines */ + case NV3_IMAGE_IN_MEMORY_PITCH: + nv3->pgraph.image_in_memory.pitch = param & 0x1FF0; + nv_log("Image in Memory PITCH=0x%04x", nv3->pgraph.image_in_memory.pitch); + break; + /* Byte offset in GPU VRAM of top left pixel (22:0) */ + case NV3_IMAGE_IN_MEMORY_TOP_LEFT_OFFSET: + nv3->pgraph.image_in_memory.linear_address = param & ((1 << NV3_IMAGE_IN_MEMORY_TOP_LEFT_OFFSET_END) - 0x10); + nv_log("Image in Memory TOP_LEFT_OFFSET=0x%08x", nv3->pgraph.image_in_memory.linear_address); + break; default: nv_log("%s: Invalid or Unimplemented method 0x%04x", nv3_class_names[context.class_id & 0x1F], method_id); nv3_pgraph_interrupt_invalid(NV3_PGRAPH_INTR_1_INVALID_METHOD); diff --git a/src/video/nv/nv3/render/nv3_render_core.c b/src/video/nv/nv3/render/nv3_render_core.c index d0d30c66d..426cf2c9d 100644 --- a/src/video/nv/nv3/render/nv3_render_core.c +++ b/src/video/nv/nv3/render/nv3_render_core.c @@ -28,27 +28,10 @@ #include <86box/nv/vid_nv.h> #include <86box/nv/vid_nv3.h> #include <86box/nv/classes/vid_nv3_classes.h> - +#include <86box/utils/video_stdlib.h> /* Render Core: Performs a ROP */ void nv3_perform_rop(uint32_t src, uint32_t dst, uint32_t pattern, uint32_t pen, nv3_render_operation_type rop) { - switch (rop) - { - case nv3_rop_blackness: - return 0; - case nv3_rop_srcand: - - case nv3_rop_srccopy: - return src; - case nv3_rop_dstcopy: - return dst; // do nothing - case nv3_rop_dstinvert: - return !dst; - case nv3_rop_xor: - return src ^ dst; - case nv3_rop_whiteness: - return 1; - - } + return video_rop_gdi_ternary(rop, dst, pattern, src); } \ No newline at end of file diff --git a/src/video/nv/nv3/subsystems/nv3_pgraph.c b/src/video/nv/nv3/subsystems/nv3_pgraph.c index 802d98d10..510d8c1d3 100644 --- a/src/video/nv/nv3/subsystems/nv3_pgraph.c +++ b/src/video/nv/nv3/subsystems/nv3_pgraph.c @@ -70,7 +70,7 @@ nv_register_t pgraph_registers[] = { { NV3_PGRAPH_PATTERN_BITMAP_HIGH, "PGRAPH Pattern Bitmap (High 32bits)", NULL, NULL}, { NV3_PGRAPH_PATTERN_BITMAP_LOW, "PGRAPH Pattern Bitmap (Low 32bits)", NULL, NULL}, { NV3_PGRAPH_PATTERN_SHAPE, "PGRAPH Pattern Shape (1:0 - 0=8x8, 1=64x1, 2=1x64)", NULL, NULL}, - { NV3_PGRAPH_ROP3, "PGRAPH Render Operation ROP3 (2^3 bits = 256 possible operations)", NULL, NULL}, + { NV3_PGRAPH_ROP3, "PGRAPH GDI Ternary Render Operation ROP3 (2^3 bits = 256 possible operations)", NULL, NULL}, { NV3_PGRAPH_PLANE_MASK, "PGRAPH Current Plane Mask (7:0)", NULL, NULL}, { NV3_PGRAPH_CHROMA_KEY, "PGRAPH Chroma Key (17:0) (Bit 30 = Alpha, 29:20 = Red, 19:10 = Green, 9:0 = Blue)", NULL, NULL}, { NV3_PGRAPH_BETA, "PGRAPH Beta factor", NULL, NULL }, @@ -207,6 +207,16 @@ uint32_t nv3_pgraph_read(uint32_t address) case NV3_PGRAPH_BETA: ret = nv3->pgraph.beta_factor; break; + // Todo: Massive table of ROP IDs or at least known ones? + case NV3_PGRAPH_ROP3: + ret = nv3->pgraph.rop; + break; + case NV3_PGRAPH_CHROMA_KEY: + ret = *(uint32_t*)&nv3->pgraph.chroma_key; + break; + case NV3_PGRAPH_PLANE_MASK: + ret = nv3->pgraph.plane_mask; + break; // DMA case NV3_PGRAPH_DMA: ret = *(uint32_t*)&nv3->pgraph.dma_settings; @@ -400,6 +410,16 @@ void nv3_pgraph_write(uint32_t address, uint32_t value) case NV3_PGRAPH_BETA: nv3->pgraph.beta_factor = value; break; + // Todo: Massive table of ROP IDs or at least known ones? + case NV3_PGRAPH_ROP3: + nv3->pgraph.rop = value & 0xFF; + break; + case NV3_PGRAPH_CHROMA_KEY: + nv3->pgraph.chroma_key = *(nv3_color_x2a10g10b10_t*)value; + break; + case NV3_PGRAPH_PLANE_MASK: + nv3->pgraph.plane_mask = value; + break; // DMA case NV3_PGRAPH_DMA: *(uint32_t*)&nv3->pgraph.dma_settings = value;