| 1 | /* ibm1130_plot.c: IBM 1130 1627 plotter emulation\r |
| 2 | \r |
| 3 | Based on the SIMH simulator package written by Robert M Supnik\r |
| 4 | \r |
| 5 | Brian Knittel\r |
| 6 | Revision History\r |
| 7 | \r |
| 8 | 2004.10.22 - Written.\r |
| 9 | 2006.1.2 - Rewritten as plotter routine by Carl V Claunch\r |
| 10 | \r |
| 11 | * (C) Copyright 2004, Brian Knittel.\r |
| 12 | * You may freely use this program, but: it offered strictly on an AS-IS, AT YOUR OWN\r |
| 13 | * RISK basis, there is no warranty of fitness for any purpose, and the rest of the\r |
| 14 | * usual yada-yada. Please keep this notice and the copyright in any distributions\r |
| 15 | * or modifications.\r |
| 16 | *\r |
| 17 | * This is not a supported product, but I welcome bug reports and fixes.\r |
| 18 | * Mail to simh@ibm1130.org\r |
| 19 | */\r |
| 20 | \r |
| 21 | #include "ibm1130_defs.h"\r |
| 22 | \r |
| 23 | #ifndef ENABLE_PLOT_SUPPORT\r |
| 24 | \r |
| 25 | DEVICE plot_dev = {\r |
| 26 | "PLOT", NULL, NULL, NULL,\r |
| 27 | 0, 16, 16, 1, 16, 16,\r |
| 28 | NULL, NULL, NULL,\r |
| 29 | NULL, NULL, NULL};\r |
| 30 | \r |
| 31 | void xio_1627_plotter (int32 addr, int32 func, int32 modify)\r |
| 32 | {\r |
| 33 | /* silently eat any plotter commands */\r |
| 34 | }\r |
| 35 | \r |
| 36 | #else\r |
| 37 | \r |
| 38 | #include "gd.h"\r |
| 39 | \r |
| 40 | /***************************************************************************************\r |
| 41 | * 1627 model 1 plotter (based on Calcomp 535 which was sold as IBM 1627)\r |
| 42 | *\r |
| 43 | * - 11" wide carriage, addressible in .01" steps\r |
| 44 | * - continous sheet paper up to 120' in length\r |
| 45 | * - sheet moveable in .01" steps, either direction\r |
| 46 | * - switchable pen, in various colors and line widths\r |
| 47 | *\r |
| 48 | * Simulator implementation will create a JPEG image corresponding to a \r |
| 49 | * landscape mode sheet of paper, the width of the carriage at 11".\r |
| 50 | * A diagram of more than 8" of paper travel will span printed pages\r |
| 51 | * in landscape mode. \r |
| 52 | *\r |
| 53 | * When an 'att plot' command is issued a file is created based on the\r |
| 54 | * default or currently set values of paper length, starting\r |
| 55 | * position of the pen in both X and Y axes, pen color and pen width.\r |
| 56 | * Based on the number of logical pages of paper, the command will create\r |
| 57 | * the proper size canvas internally and create the output JPEG file.\r |
| 58 | * \r |
| 59 | * When a 'det plot' command is issued, the plotter image will be converted \r |
| 60 | * into the file that was specified during the attach process. The\r |
| 61 | * image is not viewable until this point, unless an examine plot is\r |
| 62 | * issued which will dump the current state of the paper into the file.\r |
| 63 | * \r |
| 64 | * The 'set plot' command can set pen width, paper length, pen color,\r |
| 65 | * current carriage X and Y coordinates. Paper length can be set\r |
| 66 | * to alter the default of 800 (8"); changes are ignored until\r |
| 67 | * the next 'attach' command. The current carriage x and y positions\r |
| 68 | * can be set at any time and will go into effect immediately, just\r |
| 69 | * as the pen color and pen width can be altered on the fly.\r |
| 70 | *\r |
| 71 | * NOTE: requires gd library and definition of ENABLE_PLOT_SUPPORT in makefile or Visual C configuration\r |
| 72 | * gd is not included in the main simh and ibm1130.org distributions at the present time.\r |
| 73 | ***************************************************************************************/\r |
| 74 | \r |
| 75 | #define PLOT1627_DSW_OP_COMPLETE 0x8000\r |
| 76 | #define PLOT1627_DSW_BUSY 0x0200\r |
| 77 | #define PLOT1627_DSW_NOT_READY 0x0100\r |
| 78 | \r |
| 79 | #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT)\r |
| 80 | #define IS_DEBUG ((plot_unit->flags & UNIT_DEBUG) == UNIT_DEBUG)\r |
| 81 | #define IS_PENDOWN ((plot_unit->flags & UNIT_PEN) == UNIT_PEN)\r |
| 82 | \r |
| 83 | static t_stat plot_svc (UNIT *uptr); /* activity routine */\r |
| 84 | static t_stat plot_reset (DEVICE *dptr); /* reset of 1130 */\r |
| 85 | static t_stat plot_attach (UNIT *uptr, char *cptr); /* attach, loads plotter */\r |
| 86 | static t_stat plot_detach (UNIT *uptr); /* detach and save image */\r |
| 87 | static t_stat plot_examine (UNIT *uptr); /* update file with current canvas */\r |
| 88 | static t_stat plot_set_length (UNIT *uptr, int32 val, char * ptr, void *desc); /* set paper length */\r |
| 89 | static t_stat plot_set_pos (UNIT *uptr, int32 val, char * ptr, void *desc); /* reset current X/Y position */\r |
| 90 | static t_stat plot_show_vals(FILE *fp, UNIT *uptr, int32 val, void *descrip); /* print x, y and length */\r |
| 91 | static t_stat plot_show_nl(FILE *fp, UNIT *uptr, int32 val, void *descrip); /* overcome wacky simh behavior */\r |
| 92 | static void update_pen(void); /* will ensure pen action is correct when changes made */\r |
| 93 | static t_stat plot_validate_change (UNIT *uptr, int32 val, char * ptr, void *desc); /* when set command issued */\r |
| 94 | static void process_cmd(void); /* does actual drawing for plotter */\r |
| 95 | \r |
| 96 | extern int32 sim_switches; /* switches set on simh command */\r |
| 97 | static int16 plot_dsw = 0; /* device status word */\r |
| 98 | static int16 plot_cmd = 0; /* the command to process */\r |
| 99 | static int32 plot_wait = 1000; /* plotter movement wait */\r |
| 100 | static int32 plot_xpos = 0; /* current X position */\r |
| 101 | static int32 plot_xmax = 799; /* end of paper */\r |
| 102 | static int32 plot_ypos = 0; /* current Y position */\r |
| 103 | static int32 plot_ymax = 1099; /* right edge of carriage */\r |
| 104 | \r |
| 105 | #define PEN_DOWN 0x80000000\r |
| 106 | #define PEN_UP 0x00000000\r |
| 107 | static int32 plot_pen = PEN_UP; /* current pen position */\r |
| 108 | \r |
| 109 | static int black_pen; /* holds color black */\r |
| 110 | static int blue_pen; /* holds color blue */\r |
| 111 | static int red_pen; /* holds color red */\r |
| 112 | static int green_pen; /* holds color green */\r |
| 113 | static int yellow_pen; /* holds yellow color */\r |
| 114 | static int purple_pen; /* holds color purple */\r |
| 115 | static int ltgrey_pen; /* holds light grey */\r |
| 116 | static int grey_pen; /* holds grey */\r |
| 117 | static int white_background; /* holds white of paper roll */\r |
| 118 | static int plot_pwidth; /* set and display variable */\r |
| 119 | static int plot_pcolor; /* set and display variable */\r |
| 120 | static int need_update = 0; /* flag to force and update_pen() */\r |
| 121 | static gdImagePtr image; /* pointer to our canvas */\r |
| 122 | \r |
| 123 | #define UNIT_V_COLOR (UNIT_V_UF + 0) /* color of selected pen - 3 bits */\r |
| 124 | #define UNIT_V_WIDTH (UNIT_V_UF + 3) /* width of pen - two bits */\r |
| 125 | #define UNIT_V_NOOP (UNIT_V_UF + 5) /* dummy for set/show commands */\r |
| 126 | #define UNIT_V_DEBUG (UNIT_V_UF + 6) /* for -d switch on attach command */\r |
| 127 | #define UNIT_V_PEN (UNIT_V_UF + 7) /* track pen state */\r |
| 128 | \r |
| 129 | #define UNIT_WIDTH (3u << UNIT_V_WIDTH) /* two bits */\r |
| 130 | #define UNIT_COLOR (7u << UNIT_V_COLOR) /* three bits */\r |
| 131 | #define UNIT_NOOP (1u << UNIT_V_NOOP) /* dummy for set/show */\r |
| 132 | #define UNIT_DEBUG (1u << UNIT_V_DEBUG) /* shows debug mode on */\r |
| 133 | #define UNIT_PEN (1u << UNIT_V_PEN) /* the pen state bit */\r |
| 134 | \r |
| 135 | #define PEN_BLACK (0u << UNIT_V_COLOR)\r |
| 136 | #define PEN_RED (1u << UNIT_V_COLOR)\r |
| 137 | #define PEN_BLUE (2u << UNIT_V_COLOR)\r |
| 138 | #define PEN_GREEN (3u << UNIT_V_COLOR)\r |
| 139 | #define PEN_YELLOW (4u << UNIT_V_COLOR)\r |
| 140 | #define PEN_PURPLE (5u << UNIT_V_COLOR)\r |
| 141 | #define PEN_LTGREY (6u << UNIT_V_COLOR)\r |
| 142 | #define PEN_GREY (7u << UNIT_V_COLOR)\r |
| 143 | \r |
| 144 | #define SET_COLOR(op) {plot_unit[0].flags &= ~UNIT_COLOR; plot_unit[0].flags |= (op);}\r |
| 145 | #define GET_COLOR (plot_unit[0].flags & UNIT_COLOR)\r |
| 146 | \r |
| 147 | #define BLACK 0,0,0\r |
| 148 | #define BLUE 0,0,255\r |
| 149 | #define RED 255,0,0\r |
| 150 | #define GREEN 0,255,0\r |
| 151 | #define YELLOW 200,200,0\r |
| 152 | #define PURPLE 150,0,150\r |
| 153 | #define LTGREY 200,200,200\r |
| 154 | #define GREY 120,120,120\r |
| 155 | #define WHITE 255,255,255\r |
| 156 | \r |
| 157 | #define PEN_SINGLE (0u << UNIT_V_WIDTH)\r |
| 158 | #define PEN_DOUBLE (1u << UNIT_V_WIDTH)\r |
| 159 | #define PEN_TRIPLE (2u << UNIT_V_WIDTH)\r |
| 160 | #define PEN_QUAD (3u << UNIT_V_WIDTH)\r |
| 161 | \r |
| 162 | #define GET_WIDTH() (plot_unit[0].flags & UNIT_WIDTH)\r |
| 163 | #define SET_WIDTH(cd) {plot_unit[0].flags &= ~UNIT_WIDTH; un.flags |= (cd);}\r |
| 164 | \r |
| 165 | UNIT plot_unit[] = {\r |
| 166 | { UDATA (&plot_svc, UNIT_ATTABLE, 0) },\r |
| 167 | };\r |
| 168 | \r |
| 169 | REG plot_reg[] = {\r |
| 170 | { HRDATA (DSW, plot_dsw, 16) }, /* device status word */\r |
| 171 | { DRDATA (WTIME, plot_wait, 24), PV_LEFT }, /* plotter movement wait */\r |
| 172 | { DRDATA (Xpos, plot_xpos, 32), PV_LEFT }, /* Current X Position*/\r |
| 173 | { DRDATA (Ypos, plot_ypos, 32), PV_LEFT }, /* Current Y Position*/\r |
| 174 | { FLDATA (PenDown, plot_pen, 0)}, /* Current pen position - 1 = down */\r |
| 175 | { DRDATA (PaperSize, plot_xmax, 32), PV_LEFT }, /* Length of paper in inches */\r |
| 176 | { NULL } };\r |
| 177 | \r |
| 178 | MTAB plot_mod[] = {\r |
| 179 | { UNIT_COLOR, PEN_BLACK, "black", "BLACK", &plot_validate_change},\r |
| 180 | { UNIT_COLOR, PEN_RED, "red", "RED", &plot_validate_change},\r |
| 181 | { UNIT_COLOR, PEN_BLUE, "blue", "BLUE", &plot_validate_change},\r |
| 182 | { UNIT_COLOR, PEN_GREEN, "green", "GREEN", &plot_validate_change},\r |
| 183 | { UNIT_COLOR, PEN_YELLOW, "yellow", "YELLOW", &plot_validate_change},\r |
| 184 | { UNIT_COLOR, PEN_PURPLE, "purple", "PURPLE", &plot_validate_change},\r |
| 185 | { UNIT_COLOR, PEN_LTGREY, "ltgrey", "LTGREY", &plot_validate_change},\r |
| 186 | { UNIT_COLOR, PEN_GREY, "grey", "GREY", &plot_validate_change},\r |
| 187 | { UNIT_WIDTH, PEN_SINGLE, "1.0", "1.0", &plot_validate_change},\r |
| 188 | { UNIT_WIDTH, PEN_DOUBLE, "2.0", "2.0", &plot_validate_change},\r |
| 189 | { UNIT_WIDTH, PEN_TRIPLE, "3.0", "3.0", &plot_validate_change},\r |
| 190 | { UNIT_WIDTH, PEN_QUAD, "4.0", "4.0", &plot_validate_change},\r |
| 191 | { UNIT_PEN, UNIT_PEN, "pendown", "PENDOWN", &plot_validate_change},\r |
| 192 | { UNIT_PEN, 0, "penup", "PENUP", &plot_validate_change},\r |
| 193 | /* below is dummy entry to trigger the show routine and print extended values */\r |
| 194 | { UNIT_NOOP, 0, "", NULL, NULL, &plot_show_vals},\r |
| 195 | /* extended entries must allow parm for both unit and dev, but\r |
| 196 | * then they will print the value twice for a 'show plot' command\r |
| 197 | * therefore they are set to not display unless explicity requested\r |
| 198 | * and the special dummy NOOP entry will cause the print of these values */\r |
| 199 | { MTAB_XTD | MTAB_VAL | MTAB_VUN | MTAB_VDV | MTAB_NMO, 2,\r |
| 200 | "length", "LENGTH", &plot_set_length, &plot_show_nl, &plot_reg[5]},\r |
| 201 | { MTAB_XTD | MTAB_VAL | MTAB_VDV | MTAB_VUN | MTAB_NMO, 0,\r |
| 202 | "Xpos", "XPOS", &plot_set_pos, &plot_show_nl, &plot_reg[2]},\r |
| 203 | { MTAB_XTD | MTAB_VAL | MTAB_VDV | MTAB_VUN | MTAB_NMO, 1,\r |
| 204 | "Ypos", "YPOS", &plot_set_pos, &plot_show_nl, &plot_reg[3]},\r |
| 205 | { 0 } };\r |
| 206 | \r |
| 207 | DEVICE plot_dev = {\r |
| 208 | "PLOT", plot_unit, plot_reg, plot_mod,\r |
| 209 | 1, 16, 16, 1, 16, 16,\r |
| 210 | NULL, NULL, plot_reset,\r |
| 211 | NULL, plot_attach, plot_detach};\r |
| 212 | \r |
| 213 | /* xio_1627_plotter - XIO command interpreter for the 1627 plotter model 1 */\r |
| 214 | \r |
| 215 | void xio_1627_plotter (iocc_addr, iocc_func, iocc_mod)\r |
| 216 | {\r |
| 217 | char msg[80];\r |
| 218 | \r |
| 219 | if (! IS_ONLINE(plot_unit) ) {\r |
| 220 | SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* set not ready */\r |
| 221 | if (IS_DEBUG) printf("Plotter has no paper, ignored\n");\r |
| 222 | return; /* and ignore */\r |
| 223 | }\r |
| 224 | \r |
| 225 | switch (iocc_func) {\r |
| 226 | case XIO_READ: /* read XIO */\r |
| 227 | xio_error("Read XIO not supported by 1627 plotter");\r |
| 228 | break;\r |
| 229 | \r |
| 230 | case XIO_WRITE: /* write: do one plotter operation */\r |
| 231 | if ((plot_dsw & PLOT1627_DSW_NOT_READY)) {\r |
| 232 | if (IS_DEBUG) printf("Wrote to non-ready Plotter\n");\r |
| 233 | break;\r |
| 234 | }\r |
| 235 | plot_cmd = (uint16) ( M[iocc_addr & mem_mask] >> 10 ); /* pick up command */\r |
| 236 | process_cmd(); /* interpret command */\r |
| 237 | sim_activate(plot_unit, plot_wait); /* schedule interrupt */\r |
| 238 | SETBIT(plot_dsw, PLOT1627_DSW_BUSY); /* mark it busy */\r |
| 239 | break;\r |
| 240 | \r |
| 241 | case XIO_SENSE_DEV: /* sense device status */\r |
| 242 | ACC = plot_dsw; /* get current status */\r |
| 243 | if (iocc_mod & 0x01) { /* reset interrupts */\r |
| 244 | CLRBIT(plot_dsw, PLOT1627_DSW_OP_COMPLETE); \r |
| 245 | CLRBIT(ILSW[3], ILSW_3_1627_PLOTTER);\r |
| 246 | }\r |
| 247 | break;\r |
| 248 | \r |
| 249 | case XIO_CONTROL: /* control XIO */\r |
| 250 | xio_error("Control XIO not supported by 1627 plotter");\r |
| 251 | break;\r |
| 252 | \r |
| 253 | default:\r |
| 254 | sprintf(msg, "Invalid 1627 Plotter XIO function %x", iocc_func);\r |
| 255 | xio_error(msg);\r |
| 256 | }\r |
| 257 | return;\r |
| 258 | }\r |
| 259 | \r |
| 260 | // plot_svc - 1627 plotter operation complete\r |
| 261 | \r |
| 262 | static t_stat plot_svc (UNIT *uptr)\r |
| 263 | {\r |
| 264 | CLRBIT(plot_dsw, PLOT1627_DSW_BUSY); /* clear reader busy flag */\r |
| 265 | \r |
| 266 | SETBIT(plot_dsw, PLOT1627_DSW_OP_COMPLETE); /* indicate read complete */\r |
| 267 | \r |
| 268 | SETBIT(ILSW[3], ILSW_3_1627_PLOTTER); /* initiate interrupt */\r |
| 269 | calc_ints();\r |
| 270 | \r |
| 271 | return SCPE_OK;\r |
| 272 | }\r |
| 273 | \r |
| 274 | /* plot_reset - reset emulated plotter */\r |
| 275 | \r |
| 276 | static t_stat plot_reset (DEVICE *dptr)\r |
| 277 | {\r |
| 278 | char * buf;\r |
| 279 | int32 size;\r |
| 280 | \r |
| 281 | sim_cancel(plot_unit);\r |
| 282 | \r |
| 283 | CLRBIT(plot_dsw, PLOT1627_DSW_BUSY | PLOT1627_DSW_OP_COMPLETE);\r |
| 284 | \r |
| 285 | if (IS_DEBUG) printf("reset routine for Plotter\n");\r |
| 286 | \r |
| 287 | CLRBIT(ILSW[3], ILSW_3_1627_PLOTTER);\r |
| 288 | calc_ints();\r |
| 289 | \r |
| 290 | return SCPE_OK;\r |
| 291 | }\r |
| 292 | \r |
| 293 | \r |
| 294 | /* plot_attach - attach file to simulated plotter */\r |
| 295 | \r |
| 296 | static t_stat plot_attach (UNIT *uptr, char *cptr)\r |
| 297 | {\r |
| 298 | t_stat result;\r |
| 299 | \r |
| 300 | CLRBIT(uptr->flags, UNIT_DEBUG);\r |
| 301 | if (sim_switches & SWMASK('D')) SETBIT(uptr->flags, UNIT_DEBUG);\r |
| 302 | \r |
| 303 | /* get the output file by using regular attach routine */\r |
| 304 | result = attach_unit(uptr, cptr);\r |
| 305 | \r |
| 306 | if (result != SCPE_OK) {\r |
| 307 | if (IS_DEBUG) printf("problem attaching file\n");\r |
| 308 | return result;\r |
| 309 | }\r |
| 310 | \r |
| 311 | SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* assume failure */\r |
| 312 | \r |
| 313 | /* set up our canvas at the desired size */\r |
| 314 | image = gdImageCreate(plot_ymax+1,plot_xmax+1); /* create our canvas */\r |
| 315 | if (image == NULL) {\r |
| 316 | if (IS_DEBUG) printf("problem creating image canvas\n");\r |
| 317 | return SCPE_MEM;\r |
| 318 | }\r |
| 319 | \r |
| 320 | /* set up the basic colors after image created */\r |
| 321 | white_background = gdImageColorAllocate(image,WHITE); /* white is background */\r |
| 322 | black_pen = gdImageColorAllocate(image,BLACK); /* load up black color */\r |
| 323 | blue_pen = gdImageColorAllocate(image,BLUE); /* load up blue color */\r |
| 324 | red_pen = gdImageColorAllocate(image,RED); /* load up red color */\r |
| 325 | green_pen = gdImageColorAllocate(image,GREEN); /* load up green color */\r |
| 326 | yellow_pen = gdImageColorAllocate(image,YELLOW); /* load up yellow color */\r |
| 327 | purple_pen = gdImageColorAllocate(image,PURPLE); /* load up purple color */\r |
| 328 | ltgrey_pen = gdImageColorAllocate(image,LTGREY); /* load up light grey color */\r |
| 329 | grey_pen = gdImageColorAllocate(image,GREY); /* load up grey color */\r |
| 330 | \r |
| 331 | if ( (white_background == -1) || (black_pen == -1) ||\r |
| 332 | (red_pen == -1) || (blue_pen == -1) || (green_pen == -1) ||\r |
| 333 | (purple_pen == -1) || (ltgrey_pen == -1) || (grey_pen == -1) ) {\r |
| 334 | if (IS_DEBUG) printf("problem allocating pen colors\n");\r |
| 335 | return SCPE_MEM;\r |
| 336 | }\r |
| 337 | \r |
| 338 | CLRBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* we're in business */\r |
| 339 | \r |
| 340 | update_pen(); /* routine to ensure pen is okay */\r |
| 341 | \r |
| 342 | return SCPE_OK;\r |
| 343 | }\r |
| 344 | \r |
| 345 | /* pen updating routine, called at attach and whenever we reset the values */\r |
| 346 | \r |
| 347 | void update_pen (void)\r |
| 348 | {\r |
| 349 | int color;\r |
| 350 | int width;\r |
| 351 | \r |
| 352 | if (!IS_ONLINE(plot_unit)) return; /* only do this if attached */\r |
| 353 | \r |
| 354 | /* pick up latest color as active pen */\r |
| 355 | color = GET_COLOR;\r |
| 356 | switch (color) {\r |
| 357 | case PEN_BLACK:\r |
| 358 | plot_pcolor = black_pen;\r |
| 359 | break;\r |
| 360 | \r |
| 361 | case PEN_RED:\r |
| 362 | plot_pcolor = red_pen;\r |
| 363 | break;\r |
| 364 | \r |
| 365 | case PEN_BLUE:\r |
| 366 | plot_pcolor = blue_pen;\r |
| 367 | break;\r |
| 368 | \r |
| 369 | case PEN_GREEN:\r |
| 370 | plot_pcolor = green_pen;\r |
| 371 | break;\r |
| 372 | \r |
| 373 | case PEN_YELLOW:\r |
| 374 | plot_pcolor = yellow_pen;\r |
| 375 | break;\r |
| 376 | \r |
| 377 | case PEN_PURPLE:\r |
| 378 | plot_pcolor = purple_pen;\r |
| 379 | break;\r |
| 380 | \r |
| 381 | case PEN_LTGREY:\r |
| 382 | plot_pcolor = ltgrey_pen;\r |
| 383 | break;\r |
| 384 | \r |
| 385 | case PEN_GREY:\r |
| 386 | plot_pcolor = grey_pen;\r |
| 387 | break;\r |
| 388 | \r |
| 389 | default:\r |
| 390 | if (IS_DEBUG) printf("invalid pen color state\n");\r |
| 391 | plot_pcolor = black_pen;\r |
| 392 | break;\r |
| 393 | }\r |
| 394 | \r |
| 395 | /* set up anti-aliasing for the line */\r |
| 396 | gdImageSetAntiAliased(image, plot_pcolor);\r |
| 397 | \r |
| 398 | /* pick up latest width for pen */\r |
| 399 | width = GET_WIDTH();\r |
| 400 | switch (width) {\r |
| 401 | case PEN_SINGLE:\r |
| 402 | plot_pwidth = 1;\r |
| 403 | gdImageSetThickness(image, 1);\r |
| 404 | break;\r |
| 405 | \r |
| 406 | case PEN_TRIPLE:\r |
| 407 | plot_pwidth = 3;\r |
| 408 | gdImageSetThickness(image, 3);\r |
| 409 | break;\r |
| 410 | \r |
| 411 | case PEN_DOUBLE:\r |
| 412 | plot_pwidth = 2;\r |
| 413 | gdImageSetThickness(image, 2);\r |
| 414 | break;\r |
| 415 | \r |
| 416 | case PEN_QUAD:\r |
| 417 | plot_pwidth = 4;\r |
| 418 | gdImageSetThickness(image, 4);\r |
| 419 | break;\r |
| 420 | \r |
| 421 | default:\r |
| 422 | if (IS_DEBUG) printf("invalid pen width\n");\r |
| 423 | plot_pwidth = 1;\r |
| 424 | gdImageSetThickness(image, 1);\r |
| 425 | break;\r |
| 426 | }\r |
| 427 | \r |
| 428 | /* now ensure the pen state is accurate */\r |
| 429 | plot_pen = IS_PENDOWN ? PEN_DOWN : PEN_UP;\r |
| 430 | return;\r |
| 431 | }\r |
| 432 | \r |
| 433 | /* plot_detach - detach file from simulated plotter */\r |
| 434 | static t_stat plot_detach (UNIT *uptr)\r |
| 435 | {\r |
| 436 | char * buf;\r |
| 437 | int32 size;\r |
| 438 | FILE * fp;\r |
| 439 | int32 result;\r |
| 440 | \r |
| 441 | SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY);\r |
| 442 | \r |
| 443 | /* copy images to files, close files, set device to detached, free gd memory */\r |
| 444 | \r |
| 445 | buf = gdImageGifPtr(image,&size);\r |
| 446 | if (! buf) {\r |
| 447 | if (IS_DEBUG) printf("failure creating GIF in-memory\n");\r |
| 448 | return SCPE_MEM;\r |
| 449 | }\r |
| 450 | \r |
| 451 | fp = uptr->fileref; /* get file attached to unit */\r |
| 452 | \r |
| 453 | if (! fseek(fp,0,SEEK_SET)) { /* first we reset to begin of file */\r |
| 454 | if (IS_DEBUG) printf("wrote out GIF to file\n");\r |
| 455 | result = fwrite(buf,1,size,fp); /* write out our image to the file */\r |
| 456 | }\r |
| 457 | \r |
| 458 | gdFree(buf); /* free up the memory of GIF format */\r |
| 459 | gdImageDestroy(image); /* free up the canvas memory */\r |
| 460 | \r |
| 461 | if (result != size) { /* some problem writing it */\r |
| 462 | if (IS_DEBUG) printf("error in write of image file\n");\r |
| 463 | return SCPE_IOERR;\r |
| 464 | }\r |
| 465 | \r |
| 466 | return detach_unit(uptr); /* have simh close the file */\r |
| 467 | }\r |
| 468 | \r |
| 469 | /* process_cmd - implement the drawing actions of the plotter */\r |
| 470 | \r |
| 471 | static void process_cmd (void)\r |
| 472 | {\r |
| 473 | int32 oldx, oldy;\r |
| 474 | \r |
| 475 | /* first see if we set any changes to pen or position, do an update */\r |
| 476 | if (need_update) {\r |
| 477 | update_pen();\r |
| 478 | need_update = 0;\r |
| 479 | }\r |
| 480 | \r |
| 481 | /* will move pen one step or flip pen up or down */\r |
| 482 | oldx = plot_xpos;\r |
| 483 | oldy = plot_ypos;\r |
| 484 | \r |
| 485 | switch (plot_cmd) {\r |
| 486 | case 1: /* raise pen command */\r |
| 487 | plot_pen = PEN_UP;\r |
| 488 | plot_unit->flags = plot_unit->flags & (~UNIT_PEN);\r |
| 489 | return;\r |
| 490 | break;\r |
| 491 | \r |
| 492 | case 2: /* +Y command */\r |
| 493 | plot_ypos = plot_ypos + 1;\r |
| 494 | break;\r |
| 495 | \r |
| 496 | case 4: /* -Y command */\r |
| 497 | plot_ypos = plot_ypos - 1;\r |
| 498 | break;\r |
| 499 | \r |
| 500 | case 8: /* -X command */\r |
| 501 | plot_xpos = plot_xpos - 1;\r |
| 502 | break;\r |
| 503 | \r |
| 504 | case 10: /* -X +Y command */\r |
| 505 | plot_xpos = plot_xpos - 1;\r |
| 506 | plot_ypos = plot_ypos + 1;\r |
| 507 | break;\r |
| 508 | \r |
| 509 | case 12: /* -X -Y command */\r |
| 510 | plot_xpos = plot_xpos - 1;\r |
| 511 | plot_ypos = plot_ypos - 1;\r |
| 512 | break;\r |
| 513 | \r |
| 514 | case 16: /* +X command */\r |
| 515 | plot_xpos = plot_xpos + 1;\r |
| 516 | break;\r |
| 517 | \r |
| 518 | case 18: /* +X +Y command */\r |
| 519 | plot_xpos = plot_xpos + 1;\r |
| 520 | plot_ypos = plot_ypos + 1;\r |
| 521 | break;\r |
| 522 | \r |
| 523 | case 20: /* +X -Y pen command */\r |
| 524 | plot_xpos = plot_xpos + 1;\r |
| 525 | plot_ypos = plot_ypos - 1;\r |
| 526 | break;\r |
| 527 | \r |
| 528 | case 32: /* lower pen command */\r |
| 529 | plot_pen = PEN_DOWN;\r |
| 530 | plot_unit->flags = plot_unit->flags | UNIT_PEN;\r |
| 531 | return;\r |
| 532 | break;\r |
| 533 | \r |
| 534 | default:\r |
| 535 | if (IS_DEBUG) printf("invalid plotter command\n");\r |
| 536 | return;\r |
| 537 | break;\r |
| 538 | }\r |
| 539 | \r |
| 540 | /* check to see if carriage has moved off any edge */\r |
| 541 | if ((plot_xpos > (plot_xmax+1)) || (plot_ypos > (plot_ymax+1)) ||\r |
| 542 | (plot_xpos < 0) || (plot_ypos < 0)) {\r |
| 543 | /* if so, ignore as 1627 has no way of signalling error */\r |
| 544 | if (IS_DEBUG) printf(\r |
| 545 | "attempted to move carriage off paper edge %d %d for command %d\n",\r |
| 546 | plot_xpos,plot_ypos,plot_cmd);\r |
| 547 | return;\r |
| 548 | }\r |
| 549 | \r |
| 550 | /* only draw a line if the pen was down during the movement command */\r |
| 551 | if (plot_pen) {\r |
| 552 | gdImageLine(image, plot_ymax-plot_ypos, plot_xmax-plot_xpos, plot_ymax-oldy, plot_xmax-oldx, gdAntiAliased);\r |
| 553 | /* semantics are 0,0 point is lower right */\r |
| 554 | }\r |
| 555 | \r |
| 556 | return;\r |
| 557 | }\r |
| 558 | \r |
| 559 | /* plot_set_length - validate and store the length of the paper */\r |
| 560 | \r |
| 561 | static t_stat plot_set_length (UNIT *uptr, int32 set, char *ptr, void *desc)\r |
| 562 | {\r |
| 563 | char *cptr;\r |
| 564 | int32 val;\r |
| 565 | \r |
| 566 | #define LONGEST_ROLL 1440000 /* longest is 120', 14400", 1,440,000 .01"s */\r |
| 567 | \r |
| 568 | val = strtotv (ptr, &cptr, (uint32) 10); /* sim routine to get value */\r |
| 569 | if ((val < 1) | (val >= LONGEST_ROLL)) { /* check valid range */\r |
| 570 | if (IS_DEBUG) printf("setting paper more than 120' or less than 1 inch\n");\r |
| 571 | return SCPE_ARG;\r |
| 572 | }\r |
| 573 | \r |
| 574 | /* origin zero drawing, reduce by 1 but show command will fudge by adding it back */\r |
| 575 | *((int32 *)((REG *) desc)->loc) = val - 1;\r |
| 576 | \r |
| 577 | return SCPE_OK;\r |
| 578 | }\r |
| 579 | \r |
| 580 | /* plot_set_pos - validate and store the new position of the carriage */\r |
| 581 | \r |
| 582 | static t_stat plot_set_pos (UNIT *uptr, int32 set, char *ptr, void *desc)\r |
| 583 | {\r |
| 584 | char *cptr;\r |
| 585 | int32 val;\r |
| 586 | int32 max;\r |
| 587 | \r |
| 588 | max = (set == 1) ? plot_ymax : plot_xmax;\r |
| 589 | val = strtotv (ptr, &cptr, (uint32) 10);\r |
| 590 | if ((val < 0) | (val > max)) {\r |
| 591 | if (IS_DEBUG) printf("error moving carriage off paper edge\n");\r |
| 592 | return SCPE_ARG;\r |
| 593 | }\r |
| 594 | \r |
| 595 | *((int32 *)((REG *) desc)->loc) = val;\r |
| 596 | \r |
| 597 | return SCPE_OK;\r |
| 598 | }\r |
| 599 | \r |
| 600 | /* routine to display the paper length and carriage position\r |
| 601 | * cannot use regular simh routine because it prints values twice,\r |
| 602 | * once for device and once for unit\r |
| 603 | */\r |
| 604 | \r |
| 605 | static t_stat plot_show_vals (FILE *fp, UNIT *uptr, int32 val, void *descrip)\r |
| 606 | {\r |
| 607 | fprintf(fp, "length=%d, Xpos=%d, Ypos=%d",plot_xmax+1, plot_xpos,plot_ypos);\r |
| 608 | return SCPE_OK;\r |
| 609 | }\r |
| 610 | \r |
| 611 | /* routine to add a terminating NL character when 'show plot length'\r |
| 612 | * or equivalent for xpos or ypos is issued, as simh will not append for us */\r |
| 613 | \r |
| 614 | static t_stat plot_show_nl(FILE *fp, UNIT *uptr, int32 val, void *descrip)\r |
| 615 | {\r |
| 616 | int32 disp;\r |
| 617 | char *label;\r |
| 618 | \r |
| 619 | disp = (val == 2) ? plot_xmax + 1 : ((val == 1) ? plot_ypos : plot_xpos);\r |
| 620 | label = (val == 2) ? "length=" : ((val == 1) ? "Ypos=" : "Xpos=");\r |
| 621 | \r |
| 622 | fprintf(fp, "%s%d\n", label, disp);\r |
| 623 | return SCPE_OK;\r |
| 624 | }\r |
| 625 | \r |
| 626 | /* plot_validate_change - force the update_pen routine to be called after user changes pen setting */\r |
| 627 | \r |
| 628 | static t_stat plot_validate_change (UNIT *uptr, int32 set, char *ptr, void *desc)\r |
| 629 | {\r |
| 630 | need_update = 1;\r |
| 631 | return SCPE_OK;\r |
| 632 | }\r |
| 633 | \r |
| 634 | #endif /* ENABLE_PLOT_SUPPORT */\r |