Skip to content
Snippets Groups Projects
Commit 98df7803 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Make some changes

Mostly tightening things up and fixed some text things.
parent b9b062ca
No related branches found
No related tags found
No related merge requests found
...@@ -268,6 +268,9 @@ static struct { ...@@ -268,6 +268,9 @@ static struct {
int clipx; int clipx;
int clipy; int clipy;
struct mouse_field *saved_mfields; struct mouse_field *saved_mfields;
struct {
int sx, sy, ex, ey, xpos, ypos;
} text_region;
} rip = { } rip = {
RIP_STATE_BOL, RIP_STATE_BOL,
RIP_STATE_FLUSHING, RIP_STATE_FLUSHING,
...@@ -301,6 +304,8 @@ static struct { ...@@ -301,6 +304,8 @@ static struct {
false, false,
ANSI_STATE_NONE, ANSI_STATE_NONE,
0, 0, 0, 0,
NULL,
{0, 0, 0, 0, 0, 0},
}; };
   
static const uint16_t rip_line_patterns[4] = { static const uint16_t rip_line_patterns[4] = {
...@@ -7752,6 +7757,13 @@ map_rip_x(int x) ...@@ -7752,6 +7757,13 @@ map_rip_x(int x)
{ {
int i; int i;
   
if (x < 0 || x >= rip.x_dim) {
double dx = x;
dx *= rip.x_max;
dx /= rip.x_dim;
return roundl(dx);
}
if (rip.xmap == NULL) { if (rip.xmap == NULL) {
rip.xmap = malloc(rip.x_dim * sizeof(int)); rip.xmap = malloc(rip.x_dim * sizeof(int));
if (rip.xmap == NULL) { if (rip.xmap == NULL) {
...@@ -7773,6 +7785,13 @@ map_rip_y(int y) ...@@ -7773,6 +7785,13 @@ map_rip_y(int y)
{ {
int i; int i;
   
if (y < 0 || y >= rip.y_dim) {
double dy = y;
dy *= rip.y_max;
dy /= rip.y_dim;
return roundl(dy);
}
if (rip.ymap == NULL) { if (rip.ymap == NULL) {
rip.ymap = malloc(rip.y_dim * sizeof(int)); rip.ymap = malloc(rip.y_dim * sizeof(int));
if (rip.ymap == NULL) { if (rip.ymap == NULL) {
...@@ -8056,7 +8075,7 @@ buffer_data(const BYTE *buf, unsigned len) ...@@ -8056,7 +8075,7 @@ buffer_data(const BYTE *buf, unsigned len)
static int static int
next_char(const char *buf, size_t *pos) next_char(const char *buf, size_t *pos)
{ {
if (buf[*pos] == '\\') { while (buf[*pos] == '\\') {
(*pos)++; (*pos)++;
if (buf[*pos] == '\r') { if (buf[*pos] == '\r') {
(*pos)++; (*pos)++;
...@@ -8065,7 +8084,11 @@ next_char(const char *buf, size_t *pos) ...@@ -8065,7 +8084,11 @@ next_char(const char *buf, size_t *pos)
} }
else if (buf[*pos] == '\n') else if (buf[*pos] == '\n')
(*pos)++; (*pos)++;
else
return (uint8_t)buf[*pos];
} }
if (buf[*pos] == '!')
return -1;
else if (buf[*pos] == '|') else if (buf[*pos] == '|')
return -1; return -1;
else if (buf[*pos] == '\r') else if (buf[*pos] == '\r')
...@@ -8249,6 +8272,17 @@ char_top_bottom(char ch, int *top, int *bottom) ...@@ -8249,6 +8272,17 @@ char_top_bottom(char ch, int *top, int *bottom)
} }
} }
   
static int
font_height()
{
int mult = stroke_mults[rip.font.size];
int div = stroke_divs[rip.font.size];
if (rip.font.num == 0)
return 8 * rip.font.size;
return (((char)rip_fonts[rip.font.num - 1][0x88]) - ((char)rip_fonts[rip.font.num - 1][0x8a])) * mult / div;
}
static void static void
write_char(char ch) write_char(char ch)
{ {
...@@ -8289,7 +8323,7 @@ write_char(char ch) ...@@ -8289,7 +8323,7 @@ write_char(char ch)
if (this_font[fontoffset] & (0x80 >> x)) { if (this_font[fontoffset] & (0x80 >> x)) {
// NOTE: Bitmap fonts don't use write mode... // NOTE: Bitmap fonts don't use write mode...
//draw_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys); //draw_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys);
set_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys, ega_colours[rip.color]); set_pixel(rip.x + (x * rip.font.size) + xs, rip.y + (y * rip.font.size)+ ys, map_rip_color(rip.color));
} }
} }
} }
...@@ -8766,14 +8800,14 @@ draw_button(struct rip_button_style *but, bool inverted) ...@@ -8766,14 +8800,14 @@ draw_button(struct rip_button_style *but, bool inverted)
cc = ega_colours[0x0f ^ but->ccorner]; cc = ega_colours[0x0f ^ but->ccorner];
} }
else { else {
fg = ega_colours[but->cfore]; fg = map_rip_color(but->cfore);
bg = ega_colours[0]; bg = ega_colours[0];
ds = ega_colours[but->cdshadow]; ds = map_rip_color(but->cdshadow);
ch = ega_colours[but->chighlight]; ch = map_rip_color(but->chighlight);
cs = ega_colours[but->cshadow]; cs = map_rip_color(but->cshadow);
su = ega_colours[but->csurface]; su = map_rip_color(but->csurface);
ul = ega_colours[but->culine]; ul = map_rip_color(but->culine);
cc = ega_colours[but->ccorner]; cc = map_rip_color(but->ccorner);
} }
   
ox = but->box.x1; ox = but->box.x1;
...@@ -9592,7 +9626,7 @@ draw_ellipse(int x1, int y1, int arg1, int arg2, int x2, int y2) ...@@ -9592,7 +9626,7 @@ draw_ellipse(int x1, int y1, int arg1, int arg2, int x2, int y2)
y1 - nearbyint(sin((M_PI / 180.0) * arg3) * y2), y1 - nearbyint(sin((M_PI / 180.0) * arg3) * y2),
x1 + nearbyint(cos((1.0 + arg3) * (M_PI / 180.0)) * x2), x1 + nearbyint(cos((1.0 + arg3) * (M_PI / 180.0)) * x2),
y1 - nearbyint(sin((1.0 + arg3) * (M_PI / 180.0)) * y2), y1 - nearbyint(sin((1.0 + arg3) * (M_PI / 180.0)) * y2),
ega_colours[rip.color], 0xffff, rip.line_width); map_rip_color(rip.color), 0xffff, rip.line_width);
} }
} }
   
...@@ -10023,10 +10057,16 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10023,10 +10057,16 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
GET_XY2(); GET_XY2();
arg1 = parse_mega(&args[8], 2); arg1 = parse_mega(&args[8], 2);
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
arg3 = ceil((arg1 * vstat.scrnheight) / (((double)(vstat.scrnwidth)) * 3 / 4)); if (vstat.scale_numerator == 729 && vstat.scale_denominator == 1000) {
// Detect EGA mode and use the same value as RIPterm did.
arg3 = (arg1 * 7750 / 10000);
}
else {
arg3 = arg1 * vstat.scale_numerator / vstat.scale_denominator;
}
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
if (abs(arg3 - arg1) == 360) if (abs(arg3 - arg1) == 360)
full_ellipse(x1, y2, x2, y2, false); full_ellipse(x1, y1, x2, y2, false);
else else
draw_ellipse(x1, y1, x2, y2, arg1, arg3); draw_ellipse(x1, y1, x2, y2, arg1, arg3);
break; break;
...@@ -10134,9 +10174,9 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10134,9 +10174,9 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
struct ciolib_pixels *pix = getpixels(rip.viewport.sx, rip.viewport.sy, rip.viewport.ex, arg2, false); struct ciolib_pixels *pix = getpixels(rip.viewport.sx, rip.viewport.sy, rip.viewport.ex, arg2, false);
FREE_AND_NULL(pix->pixelsb); FREE_AND_NULL(pix->pixelsb);
// Blammo goes the stack! // Blammo goes the stack!
fg = ega_colours[arg1]; fg = map_rip_color(arg1);
uint32_t ffg, fbg; uint32_t ffg, fbg;
ffg = ega_colours[rip.fill_color]; ffg = map_rip_color(rip.fill_color);
fbg = ega_colours[0]; fbg = ega_colours[0];
if (x1 < pix->width && y1 < pix->height) if (x1 < pix->width && y1 < pix->height)
broken_flood_fill(pix, x1, y1, fg, ffg, fbg, rip.fill_color == 0, y1); broken_flood_fill(pix, x1, y1, fg, ffg, fbg, rip.fill_color == 0, y1);
...@@ -10165,6 +10205,27 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10165,6 +10205,27 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
* current drawing color and line thickness. The Line Pattern feature * current drawing color and line thickness. The Line Pattern feature
* does not apply to this command. * does not apply to this command.
*/ */
handled = true;
if (no_viewport())
break;
GET_XY2();
arg1 = parse_mega(&args[8], 2);
pthread_mutex_lock(&vstatlock);
if (vstat.scale_numerator == 729 && vstat.scale_denominator == 1000) {
// Detect EGA mode and use the same value as RIPterm did.
arg3 = (arg1 * 7750 / 10000);
}
else {
arg3 = arg1 * vstat.scale_numerator / vstat.scale_denominator;
}
pthread_mutex_unlock(&vstatlock);
if (abs(arg3 - arg1) == 360)
full_ellipse(x1, y1, x2, y2, false);
else
draw_ellipse(x1, y1, x2, y2, arg1, arg3);
draw_line(x1, y1, x1 + nearbyint(cos(M_PI / 180.0) * arg1) * x2, y1 + nearbyint(sin(M_PI / 180.0) * arg1) * y2);
draw_line(x1, y1, x1 + nearbyint(cos(M_PI / 180.0) * arg3) * x2, y1 + nearbyint(sin(M_PI / 180.0) * arg3) * y2);
puts("TODO: Needs to fill...");
break; break;
case 'L': // RIP_LINE !|L <x0> <y0> <x1> <y1> case 'L': // RIP_LINE !|L <x0> <y0> <x1> <y1>
/* This command will draw a line in the current drawing color, using the /* This command will draw a line in the current drawing color, using the
...@@ -10249,7 +10310,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10249,7 +10310,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
handled = true; handled = true;
if (no_viewport()) if (no_viewport())
break; break;
fg = ega_colours[rip.color]; fg = map_rip_color(rip.color);
arg1 = parse_mega(&args[0], 2); arg1 = parse_mega(&args[0], 2);
for (i = 0; i < arg1; i++) { for (i = 0; i < arg1; i++) {
if (i == 0) { if (i == 0) {
...@@ -10407,7 +10468,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10407,7 +10468,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
if (no_viewport()) if (no_viewport())
break; break;
GET_XY(); GET_XY();
set_pixel(x1, y1, ega_colours[rip.color]); set_pixel(x1, y1, map_rip_color(rip.color));
break; break;
case 'Y': // RIP_FONT_STYLE !|Y <font> <direction> <size> <res> case 'Y': // RIP_FONT_STYLE !|Y <font> <direction> <size> <res>
/* /*
...@@ -10561,7 +10622,9 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10561,7 +10622,9 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
curr_ega_palette[arg1] = arg2; curr_ega_palette[arg1] = arg2;
attr2palette(arg1, &fg, NULL); attr2palette(arg1, &fg, NULL);
setpalette(fg, ega_palette[arg2][0], ega_palette[arg2][1], ega_palette[arg2][2]); setpalette(fg, ega_palette[arg2][0], ega_palette[arg2][1], ega_palette[arg2][2]);
ega_colours[arg1] = fg; // TODO: Extended palette.
if (arg1 < 16)
ega_colours[arg1] = fg;
break; break;
case 'c': // RIP_COLOR !|c <color> case 'c': // RIP_COLOR !|c <color>
/* This command sets the color for drawing lines, circles, arcs, /* This command sets the color for drawing lines, circles, arcs,
...@@ -10647,7 +10710,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10647,7 +10710,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
arg2 += 360; arg2 += 360;
// TODO: Use 'o' command ellipse when possible... // TODO: Use 'o' command ellipse when possible...
puts("TODO: Needs to fill..."); puts("TODO: Needs to fill...");
fg = ega_colours[rip.color]; fg = map_rip_color(rip.color);
set_line(x1, y1, x1 + (x2 * cos(arg1 * (M_PI / 180.0))), set_line(x1, y1, x1 + (x2 * cos(arg1 * (M_PI / 180.0))),
y1 - (y2 * sin(arg1 * (M_PI / 180.0))), fg, 0xffff, rip.line_width); y1 - (y2 * sin(arg1 * (M_PI / 180.0))), fg, 0xffff, rip.line_width);
for (arg3 = arg1; arg3 < arg2; arg3++) { for (arg3 = arg1; arg3 < arg2; arg3++) {
...@@ -12082,7 +12145,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -12082,7 +12145,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
co |= (((planes[(row * 2) + (j / 8)] >> (7 - (j & 7))) & 1) << 1); co |= (((planes[(row * 2) + (j / 8)] >> (7 - (j & 7))) & 1) << 1);
co |= (((planes[(row * 1) + (j / 8)] >> (7 - (j & 7))) & 1) << 2); co |= (((planes[(row * 1) + (j / 8)] >> (7 - (j & 7))) & 1) << 2);
co |= (((planes[(row * 0) + (j / 8)] >> (7 - (j & 7))) & 1) << 3); co |= (((planes[(row * 0) + (j / 8)] >> (7 - (j & 7))) & 1) << 3);
*(op++) = ega_colours[co]; *(op++) = map_rip_color(co);
} }
} }
if (pix) { if (pix) {
...@@ -12339,7 +12402,14 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -12339,7 +12402,14 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
* NOTE: The "res" parameter is two bytes wide and is RESERVED for * NOTE: The "res" parameter is two bytes wide and is RESERVED for
* future use. * future use.
*/ */
// TODO: Justify things. handled = true;
GET_XY2();
rip.text_region.sx = x1;
rip.text_region.sy = y1;
rip.text_region.ex = x2;
rip.text_region.ey = y2;
rip.text_region.xpos = 0;
rip.text_region.ypos = 0;
break; break;
case 't': // RIP_REGION_TEXT !|1t <justify> <text-string> case 't': // RIP_REGION_TEXT !|1t <justify> <text-string>
/* A number of these commands may come sandwiched between the /* A number of these commands may come sandwiched between the
...@@ -12375,6 +12445,36 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -12375,6 +12445,36 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
* formatted text block. * formatted text block.
*/ */
// TODO: The things that are justified... // TODO: The things that are justified...
handled = true;
arg1 = parse_mega(&args[0], 1);
if (arg1) {
printf("TODO: Justify %d\n", arg1);
}
{
int oldsx = rip.viewport.sx;
int oldsy = rip.viewport.sy;
int oldex = rip.viewport.ex;
int oldey = rip.viewport.ey;
int oldx = rip.x;
int oldy = rip.y;
rip.viewport.sx = rip.text_region.sx;
rip.viewport.sy = rip.text_region.sy;
rip.viewport.ex = rip.text_region.ex;
rip.viewport.ey = rip.text_region.ey;
rip.x = rip.text_region.xpos;
rip.y = rip.text_region.ypos;
write_text(&args[1]);
rip.text_region.ypos += font_height();
rip.viewport.sx = oldsx;
rip.viewport.sy = oldsy;
rip.viewport.ex = oldex;
rip.viewport.ey = oldey;
rip.x = oldx;
rip.y = oldy;
}
break; break;
case 'U': // RIP_BUTTON !|1U <x0> <y0> <x1> <y1> <hotkey> <flags> <res> <text> case 'U': // RIP_BUTTON !|1U <x0> <y0> <x1> <y1> <hotkey> <flags> <res> <text>
/* This command physically creates a new Button using the previously /* This command physically creates a new Button using the previously
...@@ -12658,16 +12758,17 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -12658,16 +12758,17 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
} }
break; break;
} }
free(args);
if (!handled) { if (!handled) {
printf("Unhandled command: Level: %d, SubLevel: %d, cmd: %d, args: %s\n", level, sublevel, cmd, args); printf("Unhandled command: Level: %d, SubLevel: %d, cmd: %d, args: %s\n", level, sublevel, cmd, args);
fflush(stdout); fflush(stdout);
} }
free(args);
} }
   
static void static void
do_rip_string(const char *buf, size_t len) do_rip_string(const char *buf, size_t len)
{ {
enum do_states rs = NEED_BANG; // Reset state...
enum do_states ds = NEED_BANG; enum do_states ds = NEED_BANG;
int ch; int ch;
size_t pos; size_t pos;
...@@ -12680,54 +12781,56 @@ do_rip_string(const char *buf, size_t len) ...@@ -12680,54 +12781,56 @@ do_rip_string(const char *buf, size_t len)
switch (ds) { switch (ds) {
case NEED_BANG: case NEED_BANG:
ch = next_char(buf, &pos); ch = next_char(buf, &pos);
if (ch == '!' || ch == '\x01' || ch == '\x02') if ((ch == -1 && buf[pos] == '!') || ch == '\x01' || ch == '\x02')
ds = NEED_PIPE; ds = NEED_PIPE;
break; break;
case NEED_PIPE: case NEED_PIPE:
if (next_char(buf, &pos) == -1) { if (next_char(buf, &pos) == -1 && buf[pos] == '|') {
level = 0; level = 0;
sublevel = 0; sublevel = 0;
cmd = -1; cmd = -1;
ds = NEED_LEVEL; ds = NEED_LEVEL;
break;
} }
ds = rs;
break; break;
case NEED_LEVEL: case NEED_LEVEL:
ch = next_char(buf, &pos); ch = next_char(buf, &pos);
if (ch == -1)
break;
if (ch >= '1' && ch <= '9') { if (ch >= '1' && ch <= '9') {
level = ch - '0'; level = ch - '0';
ds = NEED_SUBLEVEL; ds = NEED_SUBLEVEL;
break;
} }
else { else if (ch == -1) {
level = 0; ds = rs;
sublevel = 0; break;
cmd = ch;
arg_start = 0;
ds = ARGUMENTS;
} }
level = 0;
sublevel = 0;
cmd = ch;
arg_start = 0;
ds = ARGUMENTS;
break; break;
case NEED_SUBLEVEL: case NEED_SUBLEVEL:
ch = next_char(buf, &pos); ch = next_char(buf, &pos);
if (ch == -1) {
ds = NEED_LEVEL;
break;
}
if (ch >= '1' && ch <= '9') { if (ch >= '1' && ch <= '9') {
sublevel = ch - '0'; sublevel = ch - '0';
ds = NEED_COMMAND; ds = NEED_COMMAND;
break;
} }
else { else if (ch == -1) {
sublevel = 0; ds = rs;
cmd = ch; break;
arg_start = 0;
ds = ARGUMENTS;
} }
sublevel = 0;
cmd = ch;
arg_start = 0;
ds = ARGUMENTS;
break; break;
case NEED_COMMAND: case NEED_COMMAND:
ch = next_char(buf, &pos); ch = next_char(buf, &pos);
if (ch == -1) { if (ch == -1) {
ds = NEED_LEVEL; ds = rs;
break; break;
} }
cmd = ch; cmd = ch;
...@@ -12738,9 +12841,13 @@ do_rip_string(const char *buf, size_t len) ...@@ -12738,9 +12841,13 @@ do_rip_string(const char *buf, size_t len)
ch = next_char(buf, &pos); ch = next_char(buf, &pos);
if (arg_start == 0) if (arg_start == 0)
arg_start = pos; arg_start = pos;
if (ch == -1 || ch == '\r') { if (ch == -1 || ch == '!' || ch == '|') {
do_rip_command(level, sublevel, cmd, &buf[arg_start]); do_rip_command(level, sublevel, cmd, &buf[arg_start]);
ds = NEED_LEVEL; if (buf[pos] == '|')
ds = NEED_LEVEL;
else
ds = NEED_PIPE;
rs = NEED_PIPE;
} }
break; break;
} }
...@@ -13693,8 +13800,6 @@ init_rip(int version) ...@@ -13693,8 +13800,6 @@ init_rip(int version)
rip.y = 0; rip.y = 0;
rip.viewport.sx = 0; rip.viewport.sx = 0;
rip.viewport.sy = 0; rip.viewport.sy = 0;
rip.viewport.ex = rip.x_dim - 1;
rip.viewport.ey = rip.y_dim - 1;
rip.color = 7; rip.color = 7;
rip.font.num = 0; rip.font.num = 0;
rip.font.vertical = 0; rip.font.vertical = 0;
...@@ -13714,6 +13819,8 @@ init_rip(int version) ...@@ -13714,6 +13819,8 @@ init_rip(int version)
if (rip.y_max > rip.y_dim) if (rip.y_max > rip.y_dim)
rip.y_max = rip.y_dim; rip.y_max = rip.y_dim;
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
rip.viewport.ex = rip.x_dim - 1;
rip.viewport.ey = rip.y_dim - 1;
   
pending_len = 0; pending_len = 0;
if (pending) if (pending)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment