From 54d805bd5cf113a415a4b17e685f086a3ea947ea Mon Sep 17 00:00:00 2001 From: krcroft Date: Tue, 14 Apr 2020 17:42:20 -0700 Subject: [PATCH] Simplify assignments with type-sized host reads --- include/mem.h | 6 +- src/ints/int10_vesa.cpp | 139 +++++++++++++++++++--------------------- 2 files changed, 68 insertions(+), 77 deletions(-) diff --git a/include/mem.h b/include/mem.h index 06e4e940..06768fe0 100644 --- a/include/mem.h +++ b/include/mem.h @@ -72,7 +72,7 @@ static INLINE uint16_t host_readw(const uint8_t *arr) uint16_t val; memcpy(&val, arr, sizeof(val)); // array sequence was DOS little-endian, so convert value to host-type - return le_to_host16(val); + return le16_to_host(val); } // Like the above, but allows index-style access assuming a 16-bit array @@ -105,7 +105,7 @@ static INLINE uint32_t host_readd(const uint8_t *arr) uint32_t val; memcpy(&val, arr, sizeof(val)); // array sequence was DOS little-endian, so convert value to host-type - return le_to_host32(val); + return le32_to_host(val); } // Like the above, but allows index-style access assuming a 32-bit array @@ -138,7 +138,7 @@ static INLINE uint64_t host_readq(const uint8_t *arr) uint64_t val; memcpy(&val, arr, sizeof(val)); // array sequence was DOS little-endian, so convert value to host-type - return le_to_host64(val); + return le64_to_host(val); } static INLINE void host_writeq(uint8_t *arr, uint64_t val) diff --git a/src/ints/int10_vesa.cpp b/src/ints/int10_vesa.cpp index 8b468b81..152a5dad 100644 --- a/src/ints/int10_vesa.cpp +++ b/src/ints/int10_vesa.cpp @@ -148,89 +148,80 @@ foundit: switch (mblock->type) { case M_LIN4: pageSize = mblock->sheight * mblock->swidth/2; - minfo.BytesPerScanLine = host_to_le( - static_cast(mblock->swidth / 8)); - minfo.NumberOfPlanes = host_to_le(static_cast(0x4)); - minfo.BitsPerPixel = host_to_le(static_cast(4)); - minfo.MemoryModel = host_to_le(static_cast(3)); // ega - // planar - // mode + minfo.BytesPerScanLine = host_to_le16(mblock->swidth / 8); + minfo.NumberOfPlanes = 0x4; + minfo.BitsPerPixel = 4u; + minfo.MemoryModel = 3u; // ega planar mode modeAttributes = 0x1b; // Color, graphics, no linear buffer break; case M_LIN8: pageSize = mblock->sheight * mblock->swidth; - minfo.BytesPerScanLine = host_to_le( - static_cast(mblock->swidth)); - minfo.NumberOfPlanes = host_to_le(static_cast(0x1)); - minfo.BitsPerPixel = host_to_le(static_cast(8)); - minfo.MemoryModel = host_to_le(static_cast(4)); // packed - // pixel + minfo.BytesPerScanLine = host_to_le16(mblock->swidth); + minfo.NumberOfPlanes = 0x1; + minfo.BitsPerPixel = 8u; + minfo.MemoryModel = 4u; // packed pixel modeAttributes = 0x1b; // Color, graphics if (!int10.vesa_nolfb) modeAttributes |= 0x80; // linear framebuffer break; case M_LIN15: pageSize = mblock->sheight * mblock->swidth*2; - minfo.BytesPerScanLine = host_to_le( - static_cast(mblock->swidth * 2)); - minfo.NumberOfPlanes = host_to_le(static_cast(0x1)); - minfo.BitsPerPixel = host_to_le(static_cast(15)); - minfo.MemoryModel = host_to_le(static_cast(6)); // HiColour - minfo.RedMaskSize = host_to_le(static_cast(5)); - minfo.RedMaskPos = host_to_le(static_cast(10)); - minfo.GreenMaskSize = host_to_le(static_cast(5)); - minfo.GreenMaskPos = host_to_le(static_cast(5)); - minfo.BlueMaskSize = host_to_le(static_cast(5)); - minfo.BlueMaskPos = host_to_le(static_cast(0)); - minfo.ReservedMaskSize = host_to_le(static_cast(0x01)); - minfo.ReservedMaskPos = host_to_le(static_cast(0x0f)); + minfo.BytesPerScanLine = host_to_le16(mblock->swidth * 2); + minfo.NumberOfPlanes = 0x1; + minfo.BitsPerPixel = 15u; + minfo.MemoryModel = 6u; // HiColour + minfo.RedMaskSize = 5u; + minfo.RedMaskPos = 10u; + minfo.GreenMaskSize = 5u; + minfo.GreenMaskPos = 5u; + minfo.BlueMaskSize = 5u; + minfo.BlueMaskPos = 0u; + minfo.ReservedMaskSize = 0x01; + minfo.ReservedMaskPos = 0x0f; modeAttributes = 0x1b; // Color, graphics if (!int10.vesa_nolfb) modeAttributes |= 0x80; // linear framebuffer break; case M_LIN16: pageSize = mblock->sheight * mblock->swidth*2; - minfo.BytesPerScanLine = host_to_le( - static_cast(mblock->swidth * 2)); - minfo.NumberOfPlanes = host_to_le(static_cast(0x1)); - minfo.BitsPerPixel = host_to_le(static_cast(16)); - minfo.MemoryModel = host_to_le(static_cast(6)); // HiColour - minfo.RedMaskSize = host_to_le(static_cast(5)); - minfo.RedMaskPos = host_to_le(static_cast(11)); - minfo.GreenMaskSize = host_to_le(static_cast(6)); - minfo.GreenMaskPos = host_to_le(static_cast(5)); - minfo.BlueMaskSize = host_to_le(static_cast(5)); - minfo.BlueMaskPos = host_to_le(static_cast(0)); + minfo.BytesPerScanLine = host_to_le16(mblock->swidth * 2); + minfo.NumberOfPlanes = 0x1; + minfo.BitsPerPixel = 16u; + minfo.MemoryModel = 6u; // HiColour + minfo.RedMaskSize = 5u; + minfo.RedMaskPos = 11u; + minfo.GreenMaskSize = 6u; + minfo.GreenMaskPos = 5u; + minfo.BlueMaskSize = 5u; + minfo.BlueMaskPos = 0u; modeAttributes = 0x1b; // Color, graphics if (!int10.vesa_nolfb) modeAttributes |= 0x80; // linear framebuffer break; case M_LIN32: pageSize = mblock->sheight * mblock->swidth*4; - minfo.BytesPerScanLine = host_to_le( - static_cast(mblock->swidth * 4)); - minfo.NumberOfPlanes = host_to_le(static_cast(0x1)); - minfo.BitsPerPixel = host_to_le(static_cast(32)); - minfo.MemoryModel = host_to_le(static_cast(6)); // HiColour - minfo.RedMaskSize = host_to_le(static_cast(8)); - minfo.RedMaskPos = host_to_le(static_cast(0x10)); - minfo.GreenMaskSize = host_to_le(static_cast(0x8)); - minfo.GreenMaskPos = host_to_le(static_cast(0x8)); - minfo.BlueMaskSize = host_to_le(static_cast(0x8)); - minfo.BlueMaskPos = host_to_le(static_cast(0x0)); - minfo.ReservedMaskSize = host_to_le(static_cast(0x8)); - minfo.ReservedMaskPos = host_to_le(static_cast(0x18)); + minfo.BytesPerScanLine = host_to_le16(mblock->swidth * 4); + minfo.NumberOfPlanes = 0x1u; + minfo.BitsPerPixel = 32u; + minfo.MemoryModel = 6u; // HiColour + minfo.RedMaskSize = 8u; + minfo.RedMaskPos = 0x10; + minfo.GreenMaskSize = 0x8; + minfo.GreenMaskPos = 0x8; + minfo.BlueMaskSize = 0x8; + minfo.BlueMaskPos = 0x0; + minfo.ReservedMaskSize = 0x8; + minfo.ReservedMaskPos = 0x18; modeAttributes = 0x1b; // Color, graphics if (!int10.vesa_nolfb) modeAttributes |= 0x80; // linear framebuffer break; case M_TEXT: pageSize = 0; - minfo.BytesPerScanLine = host_to_le( - static_cast(mblock->twidth * 2)); - minfo.NumberOfPlanes = host_to_le(static_cast(0x4)); - minfo.BitsPerPixel = host_to_le(static_cast(4)); - minfo.MemoryModel = host_to_le(static_cast(0)); // text + minfo.BytesPerScanLine = host_to_le16(mblock->twidth * 2); + minfo.NumberOfPlanes = 0x4; + minfo.BitsPerPixel = 4u; + minfo.MemoryModel = 0u; // text modeAttributes = 0x0f; // Color, text, bios output break; default: @@ -249,30 +240,30 @@ foundit: } else if (pageSize) { pages = (vga.vmemsize / pageSize)-1; } - minfo.NumberOfImagePages = host_to_le(static_cast(pages)); - minfo.ModeAttributes = host_to_le(static_cast(modeAttributes)); - minfo.WinAAttributes = host_to_le(static_cast(0x7)); // Exists/readable/writable + minfo.NumberOfImagePages = pages; + minfo.ModeAttributes = host_to_le16(modeAttributes); + minfo.WinAAttributes = 0x7; // Exists/readable/writable if (mblock->type==M_TEXT) { - minfo.WinGranularity = host_to_le(static_cast(32)); - minfo.WinSize = host_to_le(static_cast(32)); - minfo.WinASegment = host_to_le(static_cast(0xb800)); - minfo.XResolution = host_to_le(static_cast(mblock->twidth)); - minfo.YResolution = host_to_le(static_cast(mblock->theight)); + minfo.WinGranularity = host_to_le16(32u); + minfo.WinSize = host_to_le16(32u); + minfo.WinASegment = host_to_le16(0xb800); + minfo.XResolution = host_to_le16(mblock->twidth); + minfo.YResolution = host_to_le16(mblock->theight); } else { - minfo.WinGranularity = host_to_le(static_cast(64)); - minfo.WinSize = host_to_le(static_cast(64)); - minfo.WinASegment = host_to_le(static_cast(0xa000)); - minfo.XResolution = host_to_le(static_cast(mblock->swidth)); - minfo.YResolution = host_to_le(static_cast(mblock->sheight)); + minfo.WinGranularity = host_to_le16(64u); + minfo.WinSize = host_to_le16(64u); + minfo.WinASegment = host_to_le16(0xa000); + minfo.XResolution = host_to_le16(mblock->swidth); + minfo.YResolution = host_to_le16(mblock->sheight); } - minfo.WinFuncPtr = host_to_le(static_cast(int10.rom.set_window)); - minfo.NumberOfBanks = host_to_le(static_cast(0x1)); - minfo.Reserved_page = host_to_le(static_cast(0x1)); - minfo.XCharSize = host_to_le(static_cast(mblock->cwidth)); - minfo.YCharSize = host_to_le(static_cast(mblock->cheight)); + minfo.WinFuncPtr = host_to_le32(int10.rom.set_window); + minfo.NumberOfBanks = 0x1; + minfo.Reserved_page = 0x1; + minfo.XCharSize = mblock->cwidth; + minfo.YCharSize = mblock->cheight; if (!int10.vesa_nolfb) - minfo.PhysBasePtr = host_to_le(static_cast(S3_LFB_BASE)); + minfo.PhysBasePtr = host_to_le32(S3_LFB_BASE); MEM_BlockWrite(buf,&minfo,sizeof(MODE_INFO)); return VESA_SUCCESS;