Skip to content

Commit

Permalink
fix and clean up setcolors command
Browse files Browse the repository at this point in the history
  • Loading branch information
maron2000 committed Oct 5, 2023
1 parent 7726416 commit 51aefc7
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 66 deletions.
82 changes: 46 additions & 36 deletions src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8146,35 +8146,38 @@ static void COLOR_ProgramStart(Program * * make) {
}

alt_rgb altBGR[16], *rgbcolors = (alt_rgb*)render.pal.rgb;

bool setVGAColor(const char *colorArray, int j) {
if (!IS_VGA_ARCH||!CurMode) return false;
const char * nextRGB = colorArray;
int rgbVal[4] = {-1,-1,-1,-1};
if (sscanf(nextRGB, " ( %d , %d , %d)", &rgbVal[0], &rgbVal[1], &rgbVal[2]) == 3) {
for (int i = 0; i< 3; i++) {
if (rgbVal[i] < 0 || rgbVal[i] > 255)
return false;
}
} else if (sscanf(nextRGB, " #%6x", (unsigned int*)(&rgbVal[3])) == 1) {
if (rgbVal[3] < 0)
uint8_t rgbVal[3] = {0};
int32_t red, green, blue;
int32_t nextRGB_val = -1;
if (sscanf(nextRGB, " ( %d , %d , %d)", (int32_t*)&red, (int32_t*)&green, (int32_t*)&blue) == 3) {
if(red >= 0) rgbVal[0] = (uint8_t)(red & 0xFF);
if(green >= 0) rgbVal[1] = (uint8_t)(green & 0xFF);
if(blue >= 0) rgbVal[2] = (uint8_t)(blue & 0xFF);
} else if (sscanf(nextRGB, " #%6x", (uint32_t*)&nextRGB_val) == 1) {
if (nextRGB_val < 0)
return false;
for (int i = 0; i < 3; i++) {
rgbVal[2-i] = rgbVal[3]&255;
rgbVal[3] >>= 8;
for (int i = 2; i >= 0; i--) {
rgbVal[i] = nextRGB_val&255;
nextRGB_val >>= 8;
}
} else
return false;
IO_ReadB(mem_readw(BIOS_VIDEO_PORT)+6);
IO_WriteB(VGAREG_ACTL_ADDRESS, j+32);
uint8_t imap=IO_ReadB(VGAREG_ACTL_READ_DATA);
IO_WriteB(VGAREG_DAC_WRITE_ADDRESS, imap);
IO_WriteB(VGAREG_DAC_DATA, rgbVal[0] >> 2);
IO_WriteB(VGAREG_DAC_DATA, rgbVal[1] >> 2);
IO_WriteB(VGAREG_DAC_DATA, rgbVal[2] >> 2);
rgbcolors[j].red = rgbVal[0];
rgbcolors[j].green = rgbVal[1];
rgbcolors[j].blue = rgbVal[2];

for(int i = j > -1 ? j : 0; i < (j > -1 ? j + 1 : 16); i++) {
IO_ReadB(mem_readw(BIOS_VIDEO_PORT) + 6);
IO_WriteB(VGAREG_ACTL_ADDRESS, i + 32);
uint8_t imap = IO_ReadB(VGAREG_ACTL_READ_DATA);
IO_WriteB(VGAREG_DAC_WRITE_ADDRESS, imap);
IO_WriteB(VGAREG_DAC_DATA, rgbVal[0] >> 2);
IO_WriteB(VGAREG_DAC_DATA, rgbVal[1] >> 2);
IO_WriteB(VGAREG_DAC_DATA, rgbVal[2] >> 2);
rgbcolors[j].red = rgbVal[0];
rgbcolors[j].green = rgbVal[1];
rgbcolors[j].blue = rgbVal[2];
}
return true;
}

Expand Down Expand Up @@ -8228,9 +8231,12 @@ void SETCOLOR::Run()
if (p==NULL) {
#if defined(USE_TTF)
bool colornul = staycolors || (IS_VGA_ARCH && (altBGR1[i].red > 4 || altBGR1[i].green > 4 || altBGR1[i].blue > 4) && rgbcolors[i].red < 5 && rgbcolors[i].green < 5 && rgbcolors[i].blue < 5);
altBGR[i].red = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].red:rgbcolors[i].red;
altBGR[i].green = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].green:rgbcolors[i].green;
altBGR[i].blue = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].blue:rgbcolors[i].blue;
rgbcolors[i].red = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].red:rgbcolors[i].red;
rgbcolors[i].green = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].green:rgbcolors[i].green;
rgbcolors[i].blue = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].blue:rgbcolors[i].blue;
altBGR[i].red = rgbcolors[i].red;
altBGR[i].green = rgbcolors[i].green;
altBGR[i].blue = rgbcolors[i].blue;
WriteOut("Color %d: (%d,%d,%d) or #%02x%02x%02x\n",i,altBGR[i].red,altBGR[i].green,altBGR[i].blue,altBGR[i].red,altBGR[i].green,altBGR[i].blue);
#else
WriteOut("Color %d: (%d,%d,%d) or #%02x%02x%02x\n",i,rgbcolors[i].red,rgbcolors[i].green,rgbcolors[i].blue,rgbcolors[i].red,rgbcolors[i].green,rgbcolors[i].blue);
Expand Down Expand Up @@ -8279,14 +8285,15 @@ void SETCOLOR::Run()
#if defined(USE_TTF)
} else if (setColors(value,i)) {
bool colornul = staycolors || (IS_VGA_ARCH && (altBGR1[i].red > 4 || altBGR1[i].green > 4 || altBGR1[i].blue > 4) && rgbcolors[i].red < 5 && rgbcolors[i].green < 5 && rgbcolors[i].blue < 5);
LOG_MSG("%d,%d,%d %d,%d,%d",altBGR[i].red, altBGR[i].green, altBGR[i].blue, rgbcolors[i].red,rgbcolors[i].green,rgbcolors[i].blue);
LOG_MSG("colornul=%d, colorChanged=%d, IS_VGA_ARCH=%d",colornul, colorChanged, IS_VGA_ARCH);
altBGR[i].red = (colornul||(colorChanged&&!IS_VGA_ARCH))?altBGR1[i].red:rgbcolors[i].red;
altBGR[i].green = (colornul||(colorChanged&&!IS_VGA_ARCH))?altBGR1[i].green:rgbcolors[i].green;
altBGR[i].blue = (colornul||(colorChanged&&!IS_VGA_ARCH))?altBGR1[i].blue:rgbcolors[i].blue;
LOG_MSG("%d,%d,%d %d,%d,%d",altBGR[i].red, altBGR[i].green, altBGR[i].blue, rgbcolors[i].red,rgbcolors[i].green,rgbcolors[i].blue);
WriteOut("Color %d => (%d,%d,%d) or #%02x%02x%02x\n",i,altBGR[i].red,altBGR[i].green,altBGR[i].blue,altBGR[i].red,altBGR[i].green,altBGR[i].blue);
rgbcolors[i].red = (colornul || (colorChanged && !IS_VGA_ARCH)) ? altBGR1[i].red : rgbcolors[i].red;
rgbcolors[i].green = (colornul || (colorChanged && !IS_VGA_ARCH)) ? altBGR1[i].green : rgbcolors[i].green;
rgbcolors[i].blue = (colornul || (colorChanged && !IS_VGA_ARCH)) ? altBGR1[i].blue : rgbcolors[i].blue;
altBGR[i].red = rgbcolors[i].red;
altBGR[i].green = rgbcolors[i].green;
altBGR[i].blue = rgbcolors[i].blue;
WriteOut("Color %d => (%d,%d,%d) or #%02x%02x%02x\n",i, rgbcolors[i].red, rgbcolors[i].green, rgbcolors[i].blue, rgbcolors[i].red, rgbcolors[i].green, rgbcolors[i].blue);
resetFontSize();
setVGAColor(value, i); // also change pallette value for non-TTF output
} else
WriteOut("Invalid color value - %s\n",value);
#endif
Expand All @@ -8296,10 +8303,13 @@ void SETCOLOR::Run()
for (int i = 0; i < 16; i++) {
#if defined(USE_TTF)
bool colornul = staycolors || (IS_VGA_ARCH && (altBGR1[i].red > 4 || altBGR1[i].green > 4 || altBGR1[i].blue > 4) && rgbcolors[i].red < 5 && rgbcolors[i].green < 5 && rgbcolors[i].blue < 5);
altBGR[i].red = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].red:rgbcolors[i].red;
altBGR[i].green = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].green:rgbcolors[i].green;
altBGR[i].blue = colornul||(colorChanged&&!IS_VGA_ARCH)?altBGR1[i].blue:rgbcolors[i].blue;
WriteOut("Color %d: (%d,%d,%d) or #%02x%02x%02x\n",i,altBGR[i].red,altBGR[i].green,altBGR[i].blue,altBGR[i].red,altBGR[i].green,altBGR[i].blue);
rgbcolors[i].red = colornul || (colorChanged && !IS_VGA_ARCH) ? altBGR1[i].red : rgbcolors[i].red;
rgbcolors[i].green = colornul || (colorChanged && !IS_VGA_ARCH) ? altBGR1[i].green : rgbcolors[i].green;
rgbcolors[i].blue = colornul || (colorChanged && !IS_VGA_ARCH) ? altBGR1[i].blue : rgbcolors[i].blue;
altBGR[i].red = rgbcolors[i].red;
altBGR[i].green = rgbcolors[i].green;
altBGR[i].blue = rgbcolors[i].blue;
WriteOut("Color %d: (%d,%d,%d) or #%02x%02x%02x\n",i, rgbcolors[i].red, rgbcolors[i].green, rgbcolors[i].blue, rgbcolors[i].red, rgbcolors[i].green, rgbcolors[i].blue);
#else
WriteOut("Color %d: (%d,%d,%d) or #%02x%02x%02x\n",i,rgbcolors[i].red,rgbcolors[i].green,rgbcolors[i].blue,rgbcolors[i].red,rgbcolors[i].green,rgbcolors[i].blue);
#endif
Expand Down
16 changes: 10 additions & 6 deletions src/ints/int10_pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
void GFX_EndTextLines(bool force);
bool setColors(const char *colorArray, int n);
#endif
bool setVGAColor(const char* colorArray, int j);
static INLINE void ResetACTL(void) {
IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6u);
}
Expand Down Expand Up @@ -241,6 +242,7 @@ void INT10_SetSingleDACRegister(uint8_t index,uint8_t red,uint8_t green,uint8_t
}
setColors(value,imap[index]);
if (ttf.inUse) GFX_EndTextLines(true);
setVGAColor(value, imap[index]);
#endif
}

Expand Down Expand Up @@ -270,7 +272,7 @@ void INT10_SetDACBlock(uint16_t index,uint16_t count,PhysPt data) {
IO_Write(VGAREG_DAC_DATA,blue);
#if defined(USE_TTF)
if (start==16) {
sprintf(value,"(%d,%d,%d)",red*255/63, green*255/63, blue*255/63);
sprintf(value,"(%d,%d,%d)",(red<<2|red>>4), (green<<2|green>>4), (blue<<2|blue>>4));
str+=std::string(value)+" ";
}
#endif
Expand All @@ -289,18 +291,20 @@ void INT10_SetDACBlock(uint16_t index,uint16_t count,PhysPt data) {
IO_Write(VGAREG_DAC_DATA,ic);
#if defined(USE_TTF)
if (start==16) {
sprintf(value,"(%d,%d,%d)",red*255/63, green*255/63, blue*255/63);
sprintf(value,"(%d,%d,%d)", (red << 2 | red >> 4), (green << 2 | green >> 4), (blue << 2 | blue >> 4));
str+=std::string(value);
}
#endif
}
}

if(str.size()) {
#if defined(USE_TTF)
if (str.size()) {
setColors(str.c_str(),-1);
if (ttf.inUse) GFX_EndTextLines(true);
}
setColors(str.c_str(), -1);
if(ttf.inUse) GFX_EndTextLines(true);
#endif
setVGAColor(str.c_str(), -1);
}
}

void INT10_GetDACBlock(uint16_t index,uint16_t count,PhysPt data) {
Expand Down
48 changes: 24 additions & 24 deletions src/output/output_ttf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int menuwidth_atleast(int width), FileDirExistCP(const char *name), FileDirExist
void AdjustIMEFontSize(void),refreshExtChar(void), initcodepagefont(void), change_output(int output), drawmenu(Bitu val), KEYBOARD_Clear(void), RENDER_Reset(void), DOSBox_SetSysMenu(void), GetMaxWidthHeight(unsigned int *pmaxWidth, unsigned int *pmaxHeight), SetWindowTransparency(int trans), resetFontSize(void), RENDER_CallBack( GFX_CallBackFunctions_t function );
bool isDBCSCP(void), InitCodePage(void), CodePageGuestToHostUTF16(uint16_t *d/*CROSS_LEN*/,const char *s/*CROSS_LEN*/), systemmessagebox(char const * aTitle, char const * aMessage, char const * aDialogType, char const * aIconType, int aDefaultButton);
std::string GetDOSBoxXPath(bool withexe=false);
bool setVGAColor(const char* colorArray, int i);

#if defined(C_SDL2)
void GFX_SetResizeable(bool enable);
Expand Down Expand Up @@ -242,9 +243,9 @@ void setVGADAC() {
IO_WriteB(VGAREG_ACTL_ADDRESS, i+32);
imap[i]=IO_ReadB(VGAREG_ACTL_READ_DATA);
IO_WriteB(VGAREG_DAC_WRITE_ADDRESS, imap[i]);
IO_WriteB(VGAREG_DAC_DATA, altBGR1[i].red>>2);
IO_WriteB(VGAREG_DAC_DATA, altBGR1[i].green>>2);
IO_WriteB(VGAREG_DAC_DATA, altBGR1[i].blue>>2);
IO_WriteB(VGAREG_DAC_DATA, rgbColors[i].red>>2);
IO_WriteB(VGAREG_DAC_DATA, rgbColors[i].green>>2);
IO_WriteB(VGAREG_DAC_DATA, rgbColors[i].blue>>2);
}
}
}
Expand All @@ -261,36 +262,35 @@ bool setColors(const char *colorArray, int n) {
staycolors = strlen(colorArray) && *colorArray == '+';
const char* nextRGB = colorArray + (staycolors?1:0);
uint8_t * altPtr = (uint8_t *)altBGR1;
int rgbVal[4] = {-1,-1,-1,-1};
for (int colNo = 0; colNo < (n>-1?1:16); colNo++) {
if (n>-1) altPtr+=4*n;
if (sscanf(nextRGB, " ( %d , %d , %d)", &rgbVal[0], &rgbVal[1], &rgbVal[2]) == 3) { // Decimal: (red,green,blue)
int8_t rgbVal[3] = {-1,-1,-1};
int32_t nextRGB_val = -1;
for (int colNo = n>-1?n:0; colNo < (n>-1?n+1:16); colNo++) {
if (sscanf(nextRGB, " ( %d , %d , %d)", (int32_t*)&rgbVal[0], (int32_t*)&rgbVal[1], (int32_t*)&rgbVal[2]) == 3) { // Decimal: (red,green,blue)
for (int i = 0; i< 3; i++) {
if (rgbVal[i] < 0 || rgbVal[i] > 255)
return false;
altPtr[i] = rgbVal[i];
}
while (*nextRGB != ')')
nextRGB++;
nextRGB++;
} else if (sscanf(nextRGB, " #%6x", ((uint32_t*)(&rgbVal[3]))) == 1) { // Hexadecimal
if (rgbVal[3] < 0)
} else if (sscanf(nextRGB, " #%6x", (uint32_t*)&nextRGB_val) == 1) { // Hexadecimal
if (nextRGB_val < 0)
return false;
for (int i = 0; i < 3; i++) {
rgbVal[2-i] = rgbVal[3]&255;
rgbVal[3] >>= 8;
for (int i = 2; i >= 0; i--) {
rgbVal[i] = nextRGB_val&255;
nextRGB_val >>= 8;
}
nextRGB = strchr(nextRGB, '#') + 7;
} else
return false;
altPtr += 4;
altBGR1[n].blue = rgbVal[2];
altBGR1[n].green = rgbVal[1];
altBGR1[n].red = rgbVal[0];
rgbColors[n].blue = rgbVal[2];
rgbColors[n].green = rgbVal[1];
rgbColors[n].red = rgbVal[0];

for(int i = n > -1 ? n : 0; i < (n > -1 ? n + 1 : 16); i++) {
altBGR0[i].red = rgbColors[i].red;
altBGR0[i].green = rgbColors[i].green;
altBGR0[i].blue = rgbColors[i].blue;
}
rgbColors[colNo].blue = (uint8_t)rgbVal[2];
rgbColors[colNo].green = (uint8_t)rgbVal[1];
rgbColors[colNo].red = (uint8_t)rgbVal[0];
}
setVGADAC();
colorChanged=justChanged=true;
Expand Down Expand Up @@ -696,8 +696,9 @@ void OUTPUT_TTF_Select(int fsize) {
str+=std::string(value)+" ";
}
if (str.size()) {
setColors(str.c_str(),-1);
colorChanged=justChanged=false;
colorChanged = justChanged = false;
setColors(str.c_str(), -1);
//setColors("#000000 #0000aa #00aa00 #00aaaa #aa0000 #aa00aa #aa5500 #aaaaaa #555555 #5555ff #55ff55 #55ffff #ff5555 #ff55ff #ffff55 #ffffff",-1);
}
}
SetBlinkRate(ttf_section);
Expand Down Expand Up @@ -1331,7 +1332,6 @@ void AutoBoxDraw_mapper_shortcut(bool pressed) {
if (ttf.inUse) resetFontSize();
}

bool setVGAColor(const char *colorArray, int i);
void ttf_reset_colors() {
if (ttf.inUse) {
SetVal("ttf", "colors", "");
Expand Down

0 comments on commit 51aefc7

Please sign in to comment.