MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / UpdateDHiResCellRGB

Function UpdateDHiResCellRGB

source/RGBMonitor.cpp:749–959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

747static int g_dhgrLastBit = 0;
748
749void UpdateDHiResCellRGB(int x, int y, uint16_t addr, bgra_t* pVideoAddress, bool isMixMode, bool isBit7Inversed)
750{
751 const int xpixel = x * 14;
752 int xoffset = x & 1; // offset to start of the 2 bytes
753 addr -= xoffset;
754
755 uint8_t* pAux = MemGetAuxPtr(addr);
756 uint8_t* pMain = MemGetMainPtr(addr);
757
758 // We need all 28 bits because one 4-bits pixel overlaps two 14-bits cells
759 uint8_t byteval1 = *pAux;
760 uint8_t byteval2 = *pMain;
761 uint8_t byteval3 = *(pAux + 1);
762 uint8_t byteval4 = *(pMain + 1);
763
764 // all 28 bits chained
765 uint32_t dwordval = (byteval1 & 0x7F) | ((byteval2 & 0x7F) << 7) | ((byteval3 & 0x7F) << 14) | ((byteval4 & 0x7F) << 21);
766
767 // Extraction of 7 color pixels and 7x4 bits
768 int bits[7];
769 UINT32 colors[7];
770 int color = 0;
771 uint32_t dwordval_tmp = dwordval;
772 for (int i = 0; i < 7; i++)
773 {
774 bits[i] = dwordval_tmp & 0xF;
775 color = ((bits[i] & 7) << 1) | ((bits[i] & 8) >> 3); // DHGR colors are rotated 1 bit to the right
776 colors[i] = *reinterpret_cast<const UINT32*>(&g_pPaletteRGB[12 + color]);
777 dwordval_tmp >>= 4;
778 }
779 UINT32 bw[2];
780 bw[0] = *reinterpret_cast<const UINT32*>(&g_pPaletteRGB[12 + 0]);
781 bw[1] = *reinterpret_cast<const UINT32*>(&g_pPaletteRGB[12 + 15]);
782
783 if (isBit7Inversed)
784 {
785 // Invert mixed mode detection
786 byteval1 = ~byteval1;
787 byteval2 = ~byteval2;
788 byteval3 = ~byteval3;
789 byteval4 = ~byteval4;
790 }
791
792 // RGB DHGR is quite a mess:
793 // Color mode is a real 140x192 RGB mode with no color fringe (ref. patent US4631692, "THE 140x192 VIDEO MODE")
794 // BW mode is a real 560x192 monochrome mode
795 // Mixed mode seems easy but has a few traps since it's based on 4-bits cells coded into 7-bits bytes:
796 // - Bit 7 of each byte defines the mode of the following 7 bits (BW or Color);
797 // - BW pixels are 1 bit wide, color pixels are usually 4 bits wide;
798 // - A color pixel can be less than 4 bits wide if it crosses a byte boundary and falls into a BW byte;
799 // - If a 4-bit cell of BW bits crosses a byte boundary and falls into a Color byte, then the last BW bit is repeated until the next color pixel starts.
800 //
801 // (Tested on Le Chat Mauve IIc adapter, which was made under patent of Video-7)
802
803 UINT32* pDst = (UINT32*)pVideoAddress;
804
805 if (xoffset == 0) // First cell
806 {

Callers 1

Calls 4

MemGetAuxPtrFunction · 0.85
MemGetMainPtrFunction · 0.85
IsVideoStyleMethod · 0.80
GetFrameBufferWidthMethod · 0.80

Tested by

no test coverage detected