Skip to content

Commit

Permalink
XGA: Rectangle command needs to obey -/+ X and Y direction bits. If s…
Browse files Browse the repository at this point in the history
…omeone wants to draw a bitmap bottom up, then do it
  • Loading branch information
joncampbell123 committed Jul 8, 2024
1 parent 50e8eb5 commit e8d5147
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/hardware/vga_xga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct XGAStatus {
bool newline;
bool wait;
uint16_t cmd;
uint16_t curx, cury;
uint16_t curx, cury, curdx, curdy;
uint16_t x1, y1, x2, y2, sizex, sizey;
uint32_t data; /* transient data passed by multiple calls */
Bitu datasize;
Expand Down Expand Up @@ -802,7 +802,7 @@ bool XGA_CheckX(void) {

if((xga.waitcmd.curx<2048) && xga.waitcmd.curx > (xga.waitcmd.x2)) {
xga.waitcmd.curx = xga.waitcmd.x1;
xga.waitcmd.cury++;
xga.waitcmd.cury += xga.waitcmd.curdy;
xga.waitcmd.cury&=0x0fff;
newline = true;
xga.waitcmd.newline = true;
Expand All @@ -814,7 +814,7 @@ bool XGA_CheckX(void) {
uint16_t realxend=4096-xga.waitcmd.x2;
if(realx==realxend) {
xga.waitcmd.curx = xga.waitcmd.x1;
xga.waitcmd.cury++;
xga.waitcmd.cury += xga.waitcmd.curdy;
xga.waitcmd.cury&=0x0fff;
newline = true;
xga.waitcmd.newline = true;
Expand All @@ -824,7 +824,7 @@ bool XGA_CheckX(void) {
} else { // else overlapping
if(realx==xga.waitcmd.x2) {
xga.waitcmd.curx = xga.waitcmd.x1;
xga.waitcmd.cury++;
xga.waitcmd.cury += xga.waitcmd.curdy;
xga.waitcmd.cury&=0x0fff;
newline = true;
xga.waitcmd.newline = true;
Expand All @@ -834,7 +834,7 @@ bool XGA_CheckX(void) {
}
}
} else {
xga.waitcmd.newline = false;
xga.waitcmd.newline = false;
}
return newline;
}
Expand All @@ -847,7 +847,7 @@ void XGA_DrawWaitSub(Bitu mixmode, Bitu srcval) {
//LOG_MSG("XGA: DrawPattern: Mixmode: %x srcval: %x", mixmode, srcval);

XGA_DrawPoint(xga.waitcmd.curx, xga.waitcmd.cury, destval);
xga.waitcmd.curx++;
xga.waitcmd.curx += xga.waitcmd.curdx;
xga.waitcmd.curx&=0x0fff;
XGA_CheckX();
}
Expand Down Expand Up @@ -1236,7 +1236,7 @@ void XGA_DrawCmd(Bitu val, Bitu len) {
#if XGA_SHOW_COMMAND_TRACE == 1
LOG_MSG("XGA: Drawing Bresenham line");
#endif
XGA_DrawLineBresenham(val);
XGA_DrawLineBresenham(val);
} else {
#if XGA_SHOW_COMMAND_TRACE == 1
LOG_MSG("XGA: Drawing vector line");
Expand All @@ -1262,6 +1262,13 @@ void XGA_DrawCmd(Bitu val, Bitu len) {
xga.waitcmd.wait = true;
xga.waitcmd.curx = xga.curx;
xga.waitcmd.cury = xga.cury;

/* Windows will always use 101b (+X +Y) to draw left to right, top to bottom.
* Apparently there is an MS-DOS CAD program out there that wants to draw
* (+X -Y) left to right, bottom to top. */
xga.waitcmd.curdx = ((val>>5)&1) ? 1 : uint16_t(~0u)/*equiv -1*/;
xga.waitcmd.curdy = ((val>>7)&1) ? 1 : uint16_t(~0u)/*equiv -1*/;

xga.waitcmd.x1 = xga.curx;
xga.waitcmd.y1 = xga.cury;
xga.waitcmd.x2 = (uint16_t)((xga.curx + xga.MAPcount)&0x0fff);
Expand Down

0 comments on commit e8d5147

Please sign in to comment.