/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/************************************************************************/
/* � Acorn Computers Ltd, 1992.                                         */
/*                                                                      */
/* This file forms part of an unsupported source release of RISC_OSLib. */
/*                                                                      */
/* It may be freely used to create executable images for saleable       */
/* products but cannot be sold in source form or as an object library   */
/* without the prior written consent of Acorn Computers Ltd.            */
/*                                                                      */
/* If this file is re-distributed (even if modified) it should retain   */
/* this copyright notice.                                               */
/*                                                                      */
/************************************************************************/

/*
 * Title: print.c
 * Purpose: provide printer driver access
 * History: IDJ: 06-Feb-92: prepared for source release
 *
 */


#include "os.h"
#include "print.h"

#define DrawPrint  1
#define PaintPrint 0
#define LibPrint 1

/*                          Printer Driver SWI's                             */

#define Info          0x00080140
#define SetInfo       0x00080141
#define CheckFeatures 0x00080142
#define PageSize      0x00080143
#define SetPageSize   0x00080144
#define SelectJob     0x00080145
#define CurrentJob    0x00080146
/* FontSWI goes in here - only the font manager may use this */
#define EndJob        0x00080148
#define AbortJob      0x00080149
#define Reset         0x0008014A
#define GiveRectangle 0x0008014B
#define DrawPage      0x0008014C
#define GetRectangle  0x0008014D
#define CancelJob     0x0008014E
#define ScreenDump    0x0008014F
#define SelectIllus   0x00080153

#pragma -s1

#if LibPrint || DrawPrint || PaintPrint
os_error * print_info(print_infostr *i)
{
  os_regset r;
  os_error *e;

  e = os_swix(Info, &r);

  i->version     = r.r[0] & 0xFFFF;
  i->identity    = r.r[0] >> 16;
  i->xres        = r.r[1];
  i->yres        = r.r[2];
  i->features    = r.r[3];
  i->description = (char*)r.r[4];
  i->xhalf       = r.r[5];
  i->yhalf       = r.r[6];
  i->number      = r.r[7];

  return(e);
}
#endif

#ifndef UROM
#if LibPrint
os_error * print_setinfo(print_infostr *i)
{
  os_regset r;

  r.r[1] = i->xres;
  r.r[2] = i->yres;
  r.r[3] = i->features;
  r.r[5] = i->xhalf;
  r.r[6] = i->yhalf;
  r.r[7] = i->number;

  return(os_swix(SetInfo, &r));
}
#endif
#endif

#ifndef UROM
#if LibPrint
os_error * print_checkfeatures(int mask,int value)
{
  os_regset r;

  r.r[0] = mask;
  r.r[1] = value;

  return(os_swix(CheckFeatures, &r));
}
#endif
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error * print_pagesize(print_pagesizestr *p)
{
  os_regset r;
  os_error *e;

  e = os_swix(PageSize, &r);

  p->xsize = r.r[1];
  p->ysize = r.r[2];
  p->bbox.x0 = r.r[3];
  p->bbox.y0 = r.r[4];
  p->bbox.x1 = r.r[5];
  p->bbox.y1 = r.r[6];

  return(e);
}
#endif

#ifndef UROM
#if LibPrint
os_error * print_setpagesize(print_pagesizestr *p)
{
  os_regset r;

  r.r[1] = p->xsize;
  r.r[2] = p->ysize;
  r.r[3] = p->bbox.x0;
  r.r[4] = p->bbox.y0;
  r.r[5] = p->bbox.x1;
  r.r[6] = p->bbox.y1;

  return(os_swix(SetPageSize, &r));
}
#endif
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error * print_selectjob(int job,char *title, int *oldjobp)
{
  os_regset r;
  os_error *e;

  r.r[0] = job;
  r.r[1] = (int)title;

  e = os_swix(SelectJob,&r);

  *oldjobp = r.r[0];

  return(e);
}
#endif

#ifndef UROM
#if LibPrint
os_error * print_currentjob(int *curjobp)
{
  os_regset r;
  os_error *e;

  e = os_swix(CurrentJob,&r);

  *curjobp = r.r[0];

  return(e);
}
#endif
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error * print_endjob(int job)
{
  os_regset r;

  r.r[0] = job;
  return os_swix(EndJob,&r);
}
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error * print_abortjob(int job)
{
  os_regset r;

  r.r[0] = job;
  return os_swix(AbortJob,&r);
}
#endif

#ifndef UROM
#if LibPrint
os_error * print_canceljob(int job)
{
  os_regset r;

  r.r[0] = job;
  return os_swix(CancelJob,&r);
}
#endif
#endif

#ifndef UROM
#if LibPrint
os_error * print_reset(void)
{
  os_regset r;
  return os_swix(Reset,&r);
}
#endif
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error *print_giverectangle(int ident, print_box *area,
                              print_transmatstr *trans,
                              print_positionstr *posn, int bgcol)
{
  os_regset r;

  r.r[0] = ident;
  r.r[1] = (int)area;
  r.r[2] = (int)trans;
  r.r[3] = (int)posn;
  r.r[4] = bgcol;

  return os_swix(GiveRectangle,&r);
}
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error * print_drawpage(int copies,int sequ,char *page,
                          print_box *clip,int *more, int *ident)
{
  os_regset r;
  os_error *e;

  r.r[0] = copies;     /* number of copies                      */
  r.r[1] = (int)clip;  /* where to return clip rectangle        */
  r.r[2] = sequ;       /* pages sequence number within document */
  r.r[3] = (int)page;  /* 'real' page number as a string        */

  e = os_swix(DrawPage, &r);

  *more = r.r[0];      /* number of copies left to do   */
  *ident = r.r[2];     /* rectangle identification word */

  return(e);
}
#endif

#if LibPrint || DrawPrint || PaintPrint
os_error * print_getrectangle(print_box *clip, int *more, int *ident)
{
  os_regset r;
  os_error *e;

  r.r[1] = (int)clip;  /* where to return clip rectangle        */

  e = os_swix(GetRectangle, &r);

  *more = r.r[0];      /* number of copies left to do   */
  *ident = r.r[2];     /* rectangle identification word */

  return(e);
}
#endif

#ifndef UROM
#if LibPrint
os_error * print_screendump(int job)
{
  os_regset r;

  r.r[0] = job;
  return os_swix(ScreenDump,&r);
}
#endif
#endif

#if LibPrint || DrawPrint
os_error * print_selectillustration(int job, char *title, int *oldjobp)
{
  os_regset r;
  os_error  *e;

  r.r[0] = job;
  r.r[1] = (int)title;
  e = os_swix(SelectIllus, &r);

  *oldjobp = r.r[0];
  return (e);
}
#endif

#pragma -s0