From af2c0e14a455c9d1df05518e523372ce66456181 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Tue, 24 Aug 2021 22:54:10 +0200 Subject: [PATCH] [Maintenance] Adopt the peek() and poke() inline functions from Which still allows us to replace a bunch of manual MK_FP() macros with calls to these functions. Part of P0157, funded by Yanga. --- th01/formats/grz.cpp | 15 +++++---------- th01/hardware/ztext.c | 2 +- th04/main/scrolly3.cpp | 4 ++-- th04/snd/snd.h | 2 +- x86real.h | 23 +++++++++++++++++++---- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/th01/formats/grz.cpp b/th01/formats/grz.cpp index ce8ce827..3fef161f 100644 --- a/th01/formats/grz.cpp +++ b/th01/formats/grz.cpp @@ -56,11 +56,6 @@ void grx_put_col(unsigned int slot, uint4_t col) grx_col = 0; } -inline void vram_put(seg_t segment, uint16_t offset, dots8_t dots) -{ - *reinterpret_cast(MK_FP(segment, offset)) = dots; -} - void grx_put(unsigned int slot) { uint8_t command; @@ -70,12 +65,12 @@ void grx_put(unsigned int slot) #define put(vram_offset, vram_offset_last, planar) \ if(!grx_col) { \ - vram_put(SEG_PLANE_B, vram_offset, *(planar++)); \ - vram_put(SEG_PLANE_R, vram_offset, *(planar++)); \ - vram_put(SEG_PLANE_G, vram_offset, *(planar++)); \ - vram_put(SEG_PLANE_E, vram_offset_last, *(planar++)); \ + pokeb(SEG_PLANE_B, vram_offset, *(planar++)); \ + pokeb(SEG_PLANE_R, vram_offset, *(planar++)); \ + pokeb(SEG_PLANE_G, vram_offset, *(planar++)); \ + pokeb(SEG_PLANE_E, vram_offset_last, *(planar++)); \ } else { \ - vram_put(SEG_PLANE_B, vram_offset_last, 0xFF); \ + pokeb(SEG_PLANE_B, vram_offset_last, 0xFF); \ } if(grx_col) { diff --git a/th01/hardware/ztext.c b/th01/hardware/ztext.c index ddc762a2..e2e85d96 100644 --- a/th01/hardware/ztext.c +++ b/th01/hardware/ztext.c @@ -85,7 +85,7 @@ void z_text_hide(void) void z_text_setcursor(z_text_cursor_t type) { - _BX = *(char*)MK_FP(0, 0x53B); + _BX = peekb(0, 0x53B); // Text mode line height outportb(0x62, 0x4B); // CSRFORM outportb(0x60, _BL | 0x80); switch(type) { diff --git a/th04/main/scrolly3.cpp b/th04/main/scrolly3.cpp index 02f11a45..c6247040 100644 --- a/th04/main/scrolly3.cpp +++ b/th04/main/scrolly3.cpp @@ -22,7 +22,7 @@ vram_y_t pascal near scroll_subpixel_y_to_vram_seg3(subpixel_t y) #define ret static_cast(_AX) // Must be signed! _BX = _SP; - ret = *reinterpret_cast(MK_FP(_SS, _BX + 2)); /* = */ (y); + ret = peek(_SS, (_BX + 2)); /* = */ (y); ret = TO_PIXEL(ret); if(scroll_active) { @@ -39,7 +39,7 @@ vram_y_t pascal near scroll_subpixel_y_to_vram_always(subpixel_t y) #define ret static_cast(_AX) // Must be signed! _BX = _SP; - ret = *reinterpret_cast(MK_FP(_SS, _BX + 2)); /* = */ (y); + ret = peek(_SS, (_BX + 2)); /* = */ (y); ret = (TO_PIXEL(ret) + scroll_line); ret = roll(ret); diff --git a/th04/snd/snd.h b/th04/snd/snd.h index 4c10e95c..2c551645 100644 --- a/th04/snd/snd.h +++ b/th04/snd/snd.h @@ -35,7 +35,7 @@ static inline bool16 snd_se_active() { // MODDERS: Just use [new_se] directly. static inline int16_t snd_get_param(int16_t ¶m) { _BX = _SP; - return *reinterpret_cast(MK_FP(_SS, (_BX + 4))); + return peek(_SS, (_BX + 4)); } #endif #endif diff --git a/x86real.h b/x86real.h index ef28546a..8ff4799a 100644 --- a/x86real.h +++ b/x86real.h @@ -96,10 +96,25 @@ int int86(int __intno, union REGS *__inregs, union REGS *__outregs); #define FP_SEG(fp) ((uint16_t)(void __seg *)(void __far *)(fp)) #define FP_OFF(fp) ((uint16_t)(fp)) -#define peek(a,b) (*((int16_t __far * )MK_FP((a),(b)))) -#define peekb(a,b) (*(( int8_t __far * )MK_FP((a),(b)))) -#define poke(a,b,c) (*((int16_t __far * )MK_FP((a),(b))) = (int16_t)(c)) -#define pokeb(a,b,c) (*(( int8_t __far * )MK_FP((a),(b))) = ( int8_t)(c)) +#ifdef __cplusplus + int16_t inline peek(uint16_t __segment, uint16_t __offset) { + return (*((int16_t __far *)MK_FP(__segment, __offset))); + } + int8_t inline peekb(uint16_t __segment, uint16_t __offset) { + return (*((int8_t __far *)MK_FP(__segment, __offset))); + } + void inline poke(uint16_t __segment, uint16_t __offset, int16_t __value) { + (*((int16_t __far *)MK_FP(__segment, __offset)) = __value); + } + void inline pokeb(uint16_t __segment, uint16_t __offset, int8_t __value) { + (*((int8_t __far *)MK_FP(__segment, __offset)) = __value); + } +#else + #define peek(a,b) (*((int16_t __far * )MK_FP((a),(b)))) + #define peekb(a,b) (*(( int8_t __far * )MK_FP((a),(b)))) + #define poke(a,b,c) (*((int16_t __far * )MK_FP((a),(b))) = (int16_t)(c)) + #define pokeb(a,b,c) (*(( int8_t __far * )MK_FP((a),(b))) = ( int8_t)(c)) +#endif /// ---------------- #endif