1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
|
#/* This is part of tmview, a dvi previewer. (c) 1995 Thomas Moor */
/* */
/* This program may be used without any warranty. It may be modified and */
/* distributed without any restrictions. */
#include "../src/defs.h"
#include <vga.h>
#include <vgagl.h>
#include <vgamouse.h>
/* option MECK indicates 16-color mode */
int MECK;
/* globals used by my painting stuff */
static GraphicsContext offscreen, physicalscreen;
static uchar *offscreenmem, *ptorigin;
static int enablebackground;
static int ofscx1, ofscy1, ofscx2, ofscy2;
static int thegraphmode, oldgraphmode;
static int fontw, fonth, fonts;
/* Function prototypes for ugly font-scaling */
void preparefont(void);
void closefont(void);
char* expandedfont=NULL;
int (*flip)(void)=vga_flip;
/* #define DEBUGVGA */
/* debugging makros to report pixel warnings (does not go with PORTRAIT) */
/* #define DEBUGPIXEL */
#ifdef DEBUGPIXEL
#define CPT(apt,mess) \
if(apt<VBUF || apt>=VBUF+vgaxdim*vgaydim ) \
{pfprot("(ctp %s)\n",mess); exit(1);}
#define CXY(mess) \
if(x2<=x1 || y2<=y1) \
{pfprot("(cxy %s)\n",mess);}
#define CXW(mess) \
if(w<0 || h<0) \
{pfprot("(cxw %s)\n",mess);}\
#else /* no debugging */
#define CPT(apt,mess)
#define CXW(mess)
#define CXY(mess)
#endif
void vgaclose(void) {
vga_setmode(oldgraphmode);
closefont();
gl_freecontext(&offscreen); /* does not hurt if not allocated ? */
if(!MECK) gl_freecontext(&physicalscreen); /* does not hurt if not allocated ? */
#ifndef VGAHASWAITIO
#ifdef LETSTRYGS
pfprot("\n\
warning: display: use polling when rendering eps-figures due to
a compiletime-option. If your svgalib is above version 1.2.10,
recompiling with \"VGAHASWAITIO\" defined may speed up rendering.\n\n");
#endif
#endif
}
void vgaerror(char* mssg)
{
pfprot("\nfatal error: display: %s\n",mssg);
vgaclose();
exit(1);
}
void vgaopen(void) {
vga_init();
enablebackground=0;
/* The svgalib doc marks the background stuff as "may work" */
/* Actually, I dont use the "GOTOBACK" feature. But I've only */
/* tested with svgalib versions which do support it. */
/* Anyway, in case of problems disable the backgound by */
/* undefining LETSTRYBG */
#ifdef LETSTRYBG
#ifdef VGA_GOTOBACK
if(vga_runinbackground_version()==1)
enablebackground=1;
#endif
#endif
}
void setpalette(void) {
int i,gl;
for(i=0;i<COLORS_PER_GREY;i++) {
gl=(i==0) ? 0: 63 * exp(GAMMA*log(i/(float) (COLORS_PER_GREY-1)));
if(MECK) vga_setpalette(COLORS_PER_GREY-1-i,gl,gl,gl);
else gl_setpalettecolor(COLORS_PER_GREY-1-i,gl,gl,gl);
}
if(MECK) {
vga_setpalette(8,PALDRED);
vga_setpalette(9,PALDGREEN);
vga_setpalette(10,PALDBLUE);
vga_setpalette(11,0,0,0); /* not used */
vga_setpalette(12,PALLRED);
vga_setpalette(13,PALLGREEN);
vga_setpalette(14,PALLBLUE);
vga_setpalette(15,PALLGREY);
}else{
gl_setpalettecolor(SETPALTEXTCOL);
gl_setpalettecolor(SETPALTEXTBACKCOL);
gl_setpalettecolor(SETPALBORDERCOL);
gl_setpalettecolor(SETPALFRAMECOL);
gl_setpalettecolor(SETPALRECTCOL);
gl_setpalettecolor(SETPALTFMCOL);
gl_setpalettecolor(SETPALHREFCOL);
gl_setpalettecolor(SETPALMIXEDCOL);
gl_setpalettecolor(SETPALMARKSCOL);
gl_setpalettecolor(SETPALMARKHCOL);
gl_setpalettecolor(SETPALMARKDCOL);
gl_setpalettecolor(SETPALFOUNDCOL);
}
}
void mysetclip(int x1, int y1, int x2, int y2) {
if(x1<0) x1=0; if(y1<0) y1=0;
if(x2>vgaxdim-1) x2=vgaxdim-1;
if(y2>vgaydim-1) y2=vgaydim-1;
if(x2<x1 || y2<y1) {
CXY("clip")
x1=0;x2=0;x2=0;y1=0; /* dirty point? should not happen anyway */
}
ofscx1=x1;
ofscy1=y1;
ofscx2=x2;
ofscy2=y2;
}
void mysetclipof(void) {
ofscx1=0;
ofscy1=0;
ofscx2=truevgaxdim-1;
ofscy2=truevgaydim-1;
}
#ifndef PORTRAIT
void myupdate(int x1, int y1, int x2, int y2) {
if(x1<0) x1=0; if(y1<0) y1=0;
if(x2>truevgaxdim-1) x2=truevgaxdim-1;
if(y2>truevgaydim-1) y2=truevgaydim-1;
if(x2<x1 || y2<y1) return;
if(!MECK){
gl_setcontext(&physicalscreen);
gl_copyboxfromcontext(&offscreen,x1,y1,x2-x1+1,y2-y1+1,x1,y1);
gl_setcontext(&offscreen);
}else{
x1=x1 & 0xfff8; x2=x2 | 0x0007; /* make divisible by 8 */
/* pfprot("(myupdate: vga_copytoplanar16 x1 %d y1 %d x2 %d y2 %d)",
x1,y1,x2,y2); */
vga_copytoplanar16(VBUF+y1*BYTEWIDTH+x1, BYTEWIDTH,
(y1*truevgaxdim+x1)>>3, truevgaxdim>>3,
x2-x1+1, y2-y1+1);
}
}
#else /* portrait displays the other way around ... no MECK !! */
void myupdate(int x1, int y1, int x2, int y2) {
if(x1<0) x1=0; if(y1<0) y1=0;
if(x2>truevgaxdim-1) x2=truevgaxdim-1;
if(y2>truevgaydim-1) y2=truevgaydim-1;
if(x2<x1 || y2<y1) return;
/* pfprot("(myupdate, portrait coordinates x1 %d y1 %d x2 %d y2 %d\n",
x1,y1,x2,y2);
pfprot(" physical coordinates x1 %d y1 %d w %d h %d\n",
y1,truevgaydim-1-x2,y2-y1+1,x2-x1-1); */
gl_setcontext(&physicalscreen);
gl_copyboxfromcontext(&offscreen,y1,truevgaxdim-1-x2, /* (h,v) of topleft */
y2-y1+1,x2-x1+1, /* (width,height) */
y1,truevgaxdim-1-x2);/* (h,v) of topleft */
gl_setcontext(&offscreen);
}
#endif
void vgagraph(void) {
int n;
n=0;
if(vgaxdim==320 && vgaydim==200) n=5;
if(vgaxdim==640 && vgaydim==480) n=10;
if(vgaxdim==800 && vgaydim==600) n=11;
if(vgaxdim==1024 && vgaydim==768) n=12;
if (n==0 || !vga_hasmode(n)) {
n=vga_getdefaultmode();
if((n!=5 && n!=10 && n!=11 && n!=12) || !vga_hasmode(n)) {
pfprot("\n\
warning: display: mode not supported on this machine. Now try -d640x480.
Check your svgalib configuration.\n");
n=10;
}
}
if(vga_hasmode(n)) {
MECK=0;
} else {
MECK=1;
pfprot("\n\
warning: display: mode -d640x480 not supported at 256 colors. Now try at
16 colors. This will reduce display quality and speed. Check your
svgalib configuration.\n\n");
n=4;
if(!vga_hasmode(n)) {
pfprot("\n\
warning: display: mode -d640x480 not even supported at 16 colors.\n");
vgaerror("Sorry.");
}
}
thegraphmode=n;
if(n==5) {truevgaxdim=320; truevgaydim=200; vgaxdim=320; vgaydim=200;}
if(n==10 || n==4) {truevgaxdim=640; truevgaydim=480; vgaxdim=640; vgaydim=480;}
if(n==11) {truevgaxdim=800; truevgaydim=600; vgaxdim=800; vgaydim=600;}
if(n==12) {truevgaxdim=1024; truevgaydim=768; vgaxdim=1024; vgaydim=768;}
/* set up the "MECK-dependent-constants" which used to be makros */
/* these are colors as bytes in the internal buffer */
if(!MECK){
COLORS_PER_GREY =16; /* should be 2^BITS_PER_GREY */
/* use lots of different values, so you may design a rainbow tmview */
WHITECOL =0;
BLACKCOL =(COLORS_PER_GREY-1);
BORDERCOL =COLORS_PER_GREY;
TEXTCOL =COLORS_PER_GREY+1;
TEXTBACKCOL =COLORS_PER_GREY+2;
FRAMECOL =COLORS_PER_GREY+3;
TFMCOL =COLORS_PER_GREY+4;
RECTCOL =COLORS_PER_GREY+5;
BACKCOLS =COLORS_PER_GREY+16; /* start at least transparent */
MARKSCOL =COLORS_PER_GREY+17;
MARKHCOL =COLORS_PER_GREY+18;
FOUNDCOL =COLORS_PER_GREY+19;
HREFCOL =COLORS_PER_GREY+20;
MARKDCOL =COLORS_PER_GREY+21;
MIXEDCOL =COLORS_PER_GREY+22; /* mixed all */
NUMBER_OF_COLORS =COLORS_PER_GREY+23; /*number of colors */
}else{
/* Now here we are in 16-color mode, and less fexible.
/* set up 8 greylevels, 3 solid colors, 3 transparent and one mixed */
/* this is hardwired, cause there are no more colors left */
/* if you still want to change the colors, change the rgb tripels in*/
/* the defssvga.h. That is, make PALDRED look yellow or so */
COLORS_PER_GREY =8; /* use only 8 of 16 greyscales */
WHITECOL =0;
BLACKCOL =7;
TEXTCOL =7;
TEXTBACKCOL =15;
FRAMECOL =8; /* dark red */
BORDERCOL =9; /* dark green */
TFMCOL =10; /* dark blue */
RECTCOL =10;
BACKCOLS =11; /* mixing modus only */
MARKDCOL =12; /* light red */
MARKHCOL =13; /* light green */
FOUNDCOL =13;
MARKSCOL =14; /* light blue */
HREFCOL =14;
MIXEDCOL =15; /* mixed all=light grey */
NUMBER_OF_COLORS =15; /*number of colors */
}
oldgraphmode=vga_getcurrentmode();
#ifdef HASMOUSE
vga_setmousesupport(1);
#endif
/* init physical screen */
vga_setmode(thegraphmode);
if(!MECK){
gl_setcontextvga(thegraphmode);
gl_getcontext(&physicalscreen);
gl_disableclipping();
setpalette();
#ifdef VGA_GOTOBACK
if(enablebackground){
pfprot("vgaopen: background running will be enabled.\n");
vga_runinbackground(1);
}
#endif
}else{ /* MECK */
setpalette();
}
/* init offscreen, always 256-colors */
if(!MECK){
if(gl_setcontextvgavirtual(thegraphmode) ==-1) /* this allocates mem */
vgaerror("libgl: can't allocate virtual context");
gl_getcontext(&offscreen);
}else{
allocmem(&offscreenmem,640L*480L);
gl_setcontext(&offscreen); /* here, mem is allocated above */
gl_setcontextvirtual(640,480,1,8,offscreenmem);
}
/* init logical screen, might be portrait modus */
#ifndef PORTRAIT
ptorigin=VBUF;
#define PTDELTAH (1)
#define PTDELTAV (BYTEWIDTH)
#else /* Portait-mode : no MECK !!!*/
if(MECK)
vgaerror("PORTRAIT not supported in 16 colors mode. Check ./tmview/svga/defssvga.h");
ptorigin=VBUF+BYTEWIDTH*(truevgaydim-1);
#define PTDELTAH (-BYTEWIDTH)
#define PTDELTAV (1)
/* pfprot("portraitmodue: vbuf %ld origin %ld deltah %d deltav %d\n",
VBUF,ptorigin,PTDELTAH,PTDELTAV); */
vgaxdim=truevgaydim;
vgaydim=truevgaxdim;
truevgaxdim=vgaxdim;
truevgaydim=vgaydim;
#endif
mysetclip(0,0,vgaxdim-1,vgaydim-1);
preparefont();
vgastatushight=fonth+fonts;
vgamaxstatuslines=truevgaydim/vgastatushight;
vgastatuslen=(truevgaxdim-1)/fontw;
#ifdef HASMOUSE
mouse_setxrange(-vgaxdim,2*vgaxdim);
mouse_setyrange(-vgaydim,2*vgaydim);
mouse_setwrap(MOUSE_NOWRAP);
#endif
}
/**************************************************************************/
/* scrolling .. */
/* */
#ifndef PORTRAIT
void vgaxscroll(short dx) {
if(abs(dx) >= vgaxdim) return;
if(dx<0)
gl_copybox(-dx,0,vgaxdim+dx,vgaydim,0,0);
else
gl_copybox(0,0,vgaxdim-dx,vgaydim, dx,0);
}
void vgayscroll(short dy) {
if(abs(dy) >= vgaydim) return;
if(dy<0)
gl_copybox(0,-dy,vgaxdim,vgaydim+dy,0,0);
else
gl_copybox(0,0,vgaxdim, vgaydim-dy, 0,dy);
}
#else /* portrait modus scrolls the other way round */
void vgayscroll(short dy) {
if(abs(dy) >= vgaydim) return;
if(dy<0)
gl_copybox(-dy,0,vgaydim+dy,vgaxdim,0,0);
else
gl_copybox(0,0,vgaydim-dy,vgaxdim, dy,0);
}
void vgaxscroll(short dx) {
if(abs(dx) >= vgaxdim) return;
if(dx>0)
gl_copybox(0,dx,vgaydim,vgaxdim-dx,0,0);
else
gl_copybox(0,0,vgaydim, vgaxdim+dx, 0,-dx);
}
#endif
/**************************************************************************/
/* keys and mice .. */
/* */
/* mini key queue, holds at most one key */
int mode2char=-1;
int vgawaitio(fd_set * fdsetin, fd_set * fdsetout, struct timeval *timeout) {
#ifdef VGAHASWAITIO
int sel;
if(mode2char>=0) return(VGA_KEYEVENT);
sel=vga_waitevent(VGA_KEYEVENT | VGA_MOUSEEVENT,
fdsetin, fdsetout, NULL, timeout);
return(sel);
#else
return(select(FD_SETSIZE,fdsetin, fdsetout,NULL, timeout));
#endif
}
uchar vgagetchar(int mode) {
/*
mode==0: get next key, dont block
mode==1: get next key, wait
mode==2: peek next key, dont block
*/
uchar input,next1,next2,next3;
uchar com=KEYNOP;
fd_set dummy;
if(mode2char>=0){
com=mode2char;
if(mode!=2) mode2char=-1;
return(com);
}
#ifdef VGAHASWAITIO
if(mode==1){ /* hang until event occurs */
vga_waitevent(VGA_KEYEVENT | VGA_MOUSEEVENT,
NULL, NULL, NULL, NULL);
}
#endif
input = vga_getkey();
if(input >= ' ' && input < 128) com= input;
else switch(input) {
case 9: com=KEYTAB; break;
case 10: com=KEYRET; break;
case 27: /* escape */
next1=0; next2=0; next3=0;
next1=vga_getkey();
switch(next1) {
case 91:
next2=vga_getkey();
switch(next2) {
case '6': com= KEYNEXT; break;
case '5': com= KEYPREV; break;
case 'A': com= KEYUP; break;
case 'B': com= KEYDOWN; break;
case 'D': com= KEYLEFT; break;
case 'C': com= KEYRIGHT; break;
case 'G': com= KEYCENTER; break;
case '1': com= KEYHOME; break;
case '4': com= KEYEND; break;
}
break;
case 0: case 27: com= KEYESC; break; /* allow wild escape abuse */
default:
}
break;
}
/*if(input !=0 && input != 255)
fprintf(prot,"(vgacommeand: %d %d %d %d)",input,next1,next2,next3);*/
while(input !=0 && input != 255) input=vga_getkey();
if(mode==2 && com!=KEYNOP)
mode2char=com;
return(com);
}
int omx, omy;
void vgasetmouse(int x, int y) {
omx=x;
omy=y;
#ifdef HASMOUSE
mouse_setposition(x,y);
#endif
}
void vgagetmouse(int *x, int *y, int *left, int* right) {
int button,nmx,nmy;
#ifdef HASMOUSE
mouse_update();
nmx = mouse_getx();
nmy = mouse_gety();
if(abs(nmx-omx) > MOUSESPEED) *x=omx+MOUSESPEED*(nmx-omx);
else *x=nmx;
if(abs(nmy-omy) > MOUSESPEED) *y=omy+MOUSESPEED*(nmy-omy);
else *y=nmy;
vgasetmouse(*x,*y);
button = mouse_getbutton();
*left= (button & MOUSE_LEFTBUTTON);
*right=(button & MOUSE_RIGHTBUTTON);
#endif
#ifndef HASMOUSE
*x=omx;
*y=omy;
*left=0;
*right=0;
#endif
}
void vgascreen(int son) {
}
/**************************************************************************/
/*
now the pixel copy stuff.
destination is allways the offscreen context
*/
void mycopybitsbw(int tx, int ty, int sw, int sh, void* src) {
/* this is with self made clipping. no good ? */
/* but it will do for all kind of BMUNIT */
int j,i,supi,supj,mini,minj,sx, skip;
BMUNIT *srow, *sbmu;
BMUNIT premask, firstpremask;
register BMUNIT data, mask;
short sbmu_wide;
char *ydest, *xdest;
/*fprintf(prot,"(vgacopybitmap1 : tx %d ty %d sw %d sh %d, ...\n",
tx,ty,sw, sh); */
mini=minj=0;
if(ty<ofscy1) {mini= ofscy1-ty; ty=ofscy1;}
if(tx<ofscx1) {minj= ofscx1-tx; tx=ofscx1;}
supi= MIN(sh,ofscy2+1-ty+mini);
supj= MIN(sw,ofscx2+1-tx+minj);
if(supi <= mini || supj <= minj) {
/*fprintf(prot,"clipped all away. no drawings)\n"); */
return;
}
ydest=ptorigin+ty*PTDELTAV+tx*PTDELTAH;
/* fprintf(prot,"clipped: tx %d ty %d mi %d si %d mj %d sj %d \n",
tx,ty,mini,supi,minj,supj); */
sbmu_wide= ROUNDUP(sw,BITS_PER_BMUNIT);
skip= minj & (BITS_PER_BMUNIT-1);
sx= minj >> BITS_LOG2;
premask = 1 << (BITS_PER_BMUNIT-1);
firstpremask = premask >> skip;
srow=((BMUNIT*)src)+mini*sbmu_wide+sx;
for (i = mini;i<supi;i++) {
xdest=ydest;
mask = firstpremask;
sbmu=srow;
data=*sbmu;
for (j = minj;j<supj;j++) {
CPT(xdest,"copybitbw")
if(!mask) {
mask=premask;
data= *(++sbmu);
}
if(data & mask) *xdest=BLACKCOL;
mask >>= 1;
xdest+=PTDELTAH;
}
srow+=sbmu_wide;
sbmu=srow;
ydest+=PTDELTAV;
}
}
void mycopybitsgs(int tx, int ty, int sw, int sh, void* src) {
/* this is with self made clipping. no good ? */
/* but it will do for all kind of BMUNIT */
/* compatible to gl_putbox */
int j,i,supi,supj,mini,minj,sx, skip;
BMUNIT *srow, *sbmu;
BMUNIT premask, firstpremask;
register BMUNIT data, mask;
short sbmu_wide;
int rs, firstrs;
char *ydest, *xdest;
#ifdef DEBUGVGA
pfprot("(mycopybitsgs : ptr 0x%x tx %d ty %d sw %d sh %d, ...",
src,tx,ty,sw, sh);
pfprot(" clipping : %d %d %d %d, ...\n",
ofscx1,ofscy1,ofscx2,ofscy2);
#endif
mini=minj=0;
if(ty<ofscy1) {mini= ofscy1-ty; ty=ofscy1;}
if(tx<ofscx1) {minj= ofscx1-tx; tx=ofscx1;}
supi= MIN(sh,ofscy2+1-ty+mini);
supj= MIN(sw,ofscx2+1-tx+minj);
if(supi <= mini || supj <= minj) {
#ifdef DEBUGVGA
pfprot("clipped all away. no drawings)");
#endif
return;
}
ydest=ptorigin+ty*PTDELTAV+tx*PTDELTAH;
/* fprintf(prot,"clipped: tx %d ty %d mi %d si %d mj %d sj %d \n",
tx,ty,mini,supi,minj,supj); */
sbmu_wide= ROUNDUP(sw << GREYSCALE_LOG2,BITS_PER_BMUNIT);
skip= minj & ((BITS_PER_BMUNIT>>GREYSCALE_LOG2)-1);
sx= minj >> (BITS_LOG2-GREYSCALE_LOG2);
premask = ((1<<GREYSCALE)-1) << (BITS_PER_BMUNIT-GREYSCALE);
firstpremask = premask >> (skip<< GREYSCALE_LOG2);
firstrs = BITS_PER_BMUNIT-GREYSCALE - skip*GREYSCALE;
srow=((BMUNIT*)src)+mini*sbmu_wide+sx;
for (i = mini;i<supi;i++) {
xdest=ydest;
mask = firstpremask;
rs = firstrs;
sbmu=srow;
data=*sbmu;
for (j = minj;j<supj;j++) {
CPT(xdest,"copybitgs")
if(!mask) {
mask=premask;
rs=BITS_PER_BMUNIT-GREYSCALE;
data= *(++sbmu);
}
/* pfprot("- ptr 0x%x data %d -",xdest,((data &mask)>>rs)); */
(*xdest) |= ((data & mask) >> rs);
mask >>= GREYSCALE;
rs-=GREYSCALE;
xdest+=PTDELTAH;
}
srow+=sbmu_wide;
sbmu=srow;
ydest+=PTDELTAV;
}
#ifdef DEBUGVGA
pfprot("done)");
#endif
}
void mycopybits88(int tx, int ty, int sw, int sh, char* src) {
/* this is with self made clipping. no good ? */
/* copy bytes to bytes */
/* compatible to gl_putbox */
int j,i,supi,supj,mini,minj,skip;
char *srow, *sbmu;
char *ydest, *xdest;
mini=minj=0;
if(ty<ofscy1) {mini= ofscy1-ty; ty=ofscy1;}
if(tx<ofscx1) {minj= ofscx1-tx; tx=ofscx1;}
supi= MIN(sh,ofscy2+1-ty+mini);
supj= MIN(sw,ofscx2+1-tx+minj);
if(supi <= mini || supj <= minj) {
/* fprintf(prot,"clipped all away. no drawings)\n"); */
return;
}
ydest=ptorigin+ty*PTDELTAV+tx*PTDELTAH;
/* pfprot("(copy 88 clipped: tx %d ty %d mi %d si %d mj %d sj %d \n",
tx,ty,mini,supi,minj,supj); */
srow= src+mini*sw+minj;
for (i = mini;i<supi;i++) {
xdest=ydest;
sbmu=srow;
for (j = minj;j<supj;j++) {
*xdest = *sbmu;
xdest+=PTDELTAH;
sbmu++;
}
srow+=sw;
ydest+=PTDELTAV;
}
/* pfprot("(done 88)\n");*/
}
void myfillboxor(int tx, int ty, int w, int h, int c) {
char *ydest, *xdest;
int i;
/* fprintf(prot,"(vgafillboxor : tx %d ty %d sw %d sh %d, ...\n",
tx,ty,sw, sh); */
if(ty<ofscy1) {h-=ofscy1-ty; ty=ofscy1;}
if(tx<ofscx1) {w-=ofscx1-tx; tx=ofscx1;}
if(ty+h>ofscy2+1) h=ofscy2+1-ty;
if(tx+w>ofscx2+1) w=ofscx2+1-tx;
if(w <= 0 || h<= 0) {
/*fprintf(prot,"clipped all away. no drawings)\n"); */
return;
}
CXW("rector");
ydest=ptorigin+ty*PTDELTAV+tx*PTDELTAH;
/* fprintf(prot,"clipped or box: tx %d ty %d w %d h %d \n",
tx,ty,w,h); */
for (;h>0;h--) {
xdest=ydest;
for (i=w;i>0;i--) {
CPT(xdest,"rector")
(*(xdest))|=c;
xdest+=PTDELTAH;
}
ydest+=PTDELTAV;
}
}
void myfillboxbg(int tx, int ty, int w, int h, int c) {
char *ydest;
int i;
register char *xdest;
register char xdc;
/* fprintf(prot,"(vgafillboxor : tx %d ty %d w %d h %d, ...\n",
tx,ty,w,h); */
if(ty<ofscy1) {h-=ofscy1-ty; ty=ofscy1;}
if(tx<ofscx1) {w-=ofscx1-tx; tx=ofscx1;}
if(ty+h>ofscy2+1) h=ofscy2+1-ty;
if(tx+w>ofscx2+1) w=ofscx2+1-tx;
if(tx+w>vgaxdim) w=vgaxdim-tx;
if(w <= 0 || h<= 0) {
/*fprintf(prot,"clipped all away. no drawings)\n"); */
return;
}
CXW("rectbg");
ydest=ptorigin+ty*PTDELTAV+tx*PTDELTAH;
/* fprintf(prot,"clipped bgbox : tx %d ty %d w %d h %d \n",
tx,ty,w,h); */
for (;h>0;h--) {
xdest=ydest;
for (i=w;i>0;i--) {
CPT(xdest,"rectbg")
xdc=*xdest;
if(xdc) {
/*if(xdc>c) *xdest=c; /* transparent modus */
if(xdc>BACKCOLS && xdc!= c) *xdest=MIXEDCOL; /* mixing modus */
} else *xdest=c;
xdest+=PTDELTAH;
}
ydest+=PTDELTAV;
}
}
void myfillbox(int tx, int ty, int w, int h, int c) {
char *ydest;
int i;
register char *xdest;
register char xdc;
/* fprintf(prot,"(vgafillbox : tx %d ty %d w %d h %d, ...\n",
tx,ty,w,h); */
if(ty<ofscy1) {h-=ofscy1-ty; ty=ofscy1;}
if(tx<ofscx1) {w-=ofscx1-tx; tx=ofscx1;}
if(ty+h>ofscy2+1) h=ofscy2+1-ty;
if(tx+w>ofscx2+1) w=ofscx2+1-tx;
if(tx+w>vgaxdim) w=vgaxdim-tx;
if(w <= 0 || h<= 0) {
/*fprintf(prot,"clipped all away. no drawings)\n"); */
return;
}
CXW("rectbg");
ydest=ptorigin+ty*PTDELTAV+tx*PTDELTAH;
/* pfprot("clipped box : tx %d ty %d w %d h %d \n",
tx,ty,w,h); */
for (;h>0;h--) {
xdest=ydest;
for (i=w;i>0;i--) {
CPT(xdest,"rectbg")
(*(xdest))=c;
xdest+=PTDELTAH;
}
ydest+=PTDELTAV;
}
}
int vgasetstatuslines(int n) {
/* pfprot("(setstatus %d ... \n",n); */
vgastatuslines=MAX(0,MIN(vgamaxstatuslines,n));
vgaydim= truevgaydim- vgastatuslines* vgastatushight;
vgaxdim= truevgaxdim;
mysetclipof(); /* not clipped !! */
if(vgastatuslines!=vgamaxstatuslines)
myfillbox(0,vgaydim,truevgaxdim,vgastatuslines*vgastatushight,TEXTBACKCOL);
else
myfillbox(0,0,truevgaxdim,truevgaydim,TEXTBACKCOL);
myupdate(0,0,vgaxdim-1,truevgaydim-1);
mysetclip(0,0,vgaxdim-1,vgaydim-1);
return(vgastatuslines);
/* pfprot("... done setstatus)\n"); */
}
void vgaupdatestatus(void) {
mysetclipof();
myupdate(0, vgaydim,truevgaxdim-1,truevgaydim-1);
mysetclip(0,0,vgaxdim-1,vgaydim-1);
}
void vgadrawstatus(char chr, int line, int pos) {
int i;
if(line>=vgastatuslines || line <0) return;
if(pos>=vgastatuslen || pos <0) return;
mysetclipof();
/* chr=(line&0x0f)*16 + (pos&0x0f); /* test charset */
mycopybits88(pos*fontw+1, vgaydim+(line+1)* vgastatushight-fonth,
fontw, fonth, expandedfont + (unsigned char) chr *fonth*fontw);
mysetclip(0,0,vgaxdim-1,vgaydim-1);
/* pfprot("(vgadrawstatus [%c] l %d p %d )",chr,line,pos); */
}
void (*vgaupdate)(int, int, int, int) = myupdate;
void (*vgasetclip)(int, int, int, int) = mysetclip;
void (*vgadrawrect)(int x, int y, int w, int h, int c) = myfillbox;
void (*vgadrawrector)(int x, int y, int w, int h, int c) = myfillboxor;
void (*vgadrawrectbg)(int x, int y, int w, int h, int c) = myfillboxbg;
void (*vgacopybitmapgs)(int x, int y, int w, int h, void* src) = mycopybitsgs;
void (*vgacopybitmapbw)(int x, int y, int w, int h, void* src) = mycopybitsbw;
/***************************************************************************/
/* now the font stuff ... */
/* #include "9x14thin.h" */
/* #include "gekl9x16.h" */
#include "font9x16.h"
/* now the pronounced ugly fontscaling code: */
void preparefont(void) {
long i;
char* buptr;
fonth=FONTH;
fontw=FONTW;
fonts=FONTS;
allocmem(&expandedfont,256L*fontw*fonth);
gl_expandfont(fontw,fonth,TEXTCOL,tmviewfont,expandedfont);
for(i=0;i<256L*fontw*fonth;i++)
if(expandedfont[i]==0) expandedfont[i]=TEXTBACKCOL;
}
void closefont(void) {
freemem(&expandedfont);
}
|