/*->c.vxprint */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <time.h>

#include "h.os"
#include "h.wimp"
#include "h.bbc"
#include "h.flex"
#include "h.Drawlevel0"


#include "h.def"
#include "h.wos"
#include "h.main"
#include "h.ram"
#include "h.mym"


#include "h.vtprint"
#include "h.pr"

#include "h.vxdef"
#include "h.vxwimp"
#include "h.vxterm"


#include "h.vxprint"



/***************************************************************************/
/*
 Code to handle Viewdata printer interface
*/
/*****************************************************************************/



pset vxpset={0x1,1,100,100,100,100,0,0,1,
                                          0,0,0,0,0,0};



int vxpinvert;


#define NLINE    0x0
#define RDATA    0x1
#define RDRAW    0x2



void vxprredraw(int invert,wimp_redrawstr * redrawstr)
{

 redrawstr->scx=redrawstr->scy=0;

 redrawstr->box.x0=0;
 redrawstr->box.y0=VXBDY*vscr->start;
 redrawstr->box.x1=VXBDX*40;
 redrawstr->box.y1=VXBDY*vscr->height;

 vxpinvert=invert;

 redrawvxsub(redrawstr,RDRAW,vscr);

 vxpinvert=0;
}




void vxprzoom(int command)
{
 static zoomer przoom;

 switch(command)
 {
  case PRSAVEZOOM:
                  przoom=vscr->zoom;
                  break;

  case PRLOADZOOM:
                  vscr->zoom=przoom;
                  break;

 case PRUNITYZOOM:
                  vscr->zoom.mul=vscr->zoom.div=1;
                  vscr->zoom.var=0;
                  break;

 }

 vxsetscales(vscr); 
}


void vxprintfile(int invert)
{
 vxpset.box0=0;
 vxpset.box1=VXBDY*vscr->start;
 vxpset.box2=VXBDX*40;
 vxpset.box3=VXBDY*vscr->height;
 vxpset.height=400*VXBDY*24;

 printfile(invert,&vxpset,vxprzoom,vxprredraw);
}





static void printchar(int code)
{
 int byte;

 byte=(code & VXCMASK)+32;

 if(byte>=127) printprint('*');
 else          printprint(byte);
}





void vxtextdump(vxscreen ** vsc)
{
 int x,y;

 printinit();
                /* main loop */
 for(y=(*vsc)->start;y<(*vsc)->height;y++)
 {
  for(x=0;x<40;x++)  printchar((*vsc)->tvbuf[y][x]);
  prnlf();
 }

 if(vxprintff) printprint(FF);
 else
 {
  prnlf();
  prnlf();
 }
}





/* dump prestel screen */

void printframe(vxscreen ** vscp)
{
 if(vxdump==VXTEXT) vxtextdump(vscp);
 else
 if(vxdump==VXGRPOS || vxdump==VXGRNEG) vxprintfile(vxdump==VXGRNEG);
}


void vxdumpscreen(int fp)
{
 fp=0;
 printframe(&vscr);
}


