Added a test for MUIA_Listview_SelectChange.
[AROS.git] / workbench / demos / turboprint.c
blobd5ba73d017d544c9e92e856b971599c4871004a0
1 /***********************************
2 * C-Source
3 * Demonstration of printing 24bit
4 * graphics bitmap with TurboPrint
5 * Professional 3.x/4.x
6 * December 1995
7 ***********************************
8 * IrseeSoft
9 * Meinrad-Spiess-Platz 2
10 * D-87660 Irsee
11 * Germany
12 * Tel. (49) 8341 74327
13 * Fax (49) 8341 12042
14 * Email: IrseeSoft@t-online.de
15 ***********************************/
17 #include <stdio.h>
19 #include <exec/types.h>
20 #include <exec/ports.h>
21 #include <exec/devices.h>
22 #include <devices/printer.h>
23 #include <devices/prtbase.h>
24 #include <dos/dos.h>
26 #include <proto/exec.h>
27 #include <proto/graphics.h>
28 #include <proto/intuition.h>
29 #include <proto/alib.h>
31 #include <libraries/cybergraphics.h>
32 #include <intuition/intuition.h>
33 #include <intuition/screens.h>
35 // some new Includes
36 #include <turboprint.h>
39 #define Width 256
40 #define Height 256
42 struct IntuitionBase *IntuitionBase;
43 struct GfxBase *GfxBase;
46 union printerIO
48 struct IOStdReq ios;
49 struct IODRPReq iodrp;
50 struct IOPrtCmdReq iopc;
55 // this short demo programm opens an invisible 24bit RastPort and
56 // dumps it through TurboPrint to the printer
57 // You see: it works almost like the normal graphics dump
59 int main(int argc, char **argv)
61 struct MsgPort *PrinterMP;
62 union printerIO *PIO;
63 struct PrinterData *PD;
64 struct TPExtIODRP ExtIoDrp;
66 struct RastPort MyRastPort;
67 struct BitMap MyBitMap;
68 UWORD x,y;
69 UBYTE *MemPoint;
70 BOOL TP_Installed;
72 UWORD TPVersion;
73 char* TPIdString;
75 if ((IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library",37)))
76 if ((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library",37)))
79 // create a RastPort Width * Height 24-Bit
81 InitRastPort(&MyRastPort);
82 MyRastPort.BitMap = &MyBitMap;
83 // we need only one BitPlane, because it's chunky format
84 InitBitMap(&MyBitMap,1,Width,Height);
86 // now set the right BytesPerRow
87 // we could have set it as 3*Width in InitBitMap but
88 // InitBitMap sometimes calculates wrong BytesPerRow
89 // so we do it on our own
91 MyBitMap.BytesPerRow = 3*Width;
94 // allocate a demo bitmap
96 if ((MyBitMap.Planes[0]= (APTR)AllocMem(3*Width*Height,0)))
98 MemPoint = (UBYTE*)MyBitMap.Planes[0];
100 // and fill it with some colored stuff
102 for (y=0;y<256;y++)
103 for (x=0;x<256;x++)
105 // fill it with some nice colors
106 *MemPoint++ = 255-((x+y)>>1); // red
107 *MemPoint++ = (x>127)? 2*(x-128):255-2*x; // green
108 *MemPoint++ = (y>127)? ((x<127)? 255-((x+y)>>1):2*(y-127)):0; // blue
112 // now create a MessagePort and Open the printer.device as usual
114 if ((PrinterMP = (struct MsgPort*)CreateMsgPort()))
116 if ((PIO = (union printerIO *)CreateExtIO(PrinterMP,sizeof(union printerIO))))
118 // open printer.device, if TurboPrint is installed, we automatically access the
119 // turboprint printer.device
120 if (!(OpenDevice("printer.device",0,(struct IORequest *)PIO,0)))
123 // before printing we need to know if TurboPrint is installed
124 // therefore check the MatchWord in the "PrinterData" structure
125 // element "pd_OldStack"
127 PD = (struct PrinterData *)PIO->iodrp.io_Device;
129 typedef union {UBYTE b[4]; ULONG l;} BL;
130 BL *p = (BL*)(PD->pd_OldStk + (2 * sizeof(ULONG)));
131 TP_Installed = (p->l == TPMATCHWORD) ? TRUE : FALSE;
134 TPVersion = PIO->iodrp.io_Device->dd_Library.lib_Version;
136 TPIdString = (char*)(PIO->iodrp.io_Device->dd_Library.lib_IdString);
138 // you could now check chars 25-27 for version and revision
139 printf("Device-Version:%d\nTPIdString:%s\n",TPVersion,&TPIdString[1]);
142 if (TP_Installed && TPVersion >= 39)
144 // fill in IORequest as normal
145 PIO->iodrp.io_Command = PRD_TPEXTDUMPRPORT;
146 PIO->iodrp.io_RastPort = &MyRastPort;
147 PIO->iodrp.io_ColorMap = 0;
148 PIO->iodrp.io_SrcX = 0;
149 PIO->iodrp.io_SrcY = 0;
150 PIO->iodrp.io_SrcWidth = Width;
151 PIO->iodrp.io_SrcHeight = Height;
152 // all Special Flags are possible, here we do not need any
153 PIO->iodrp.io_Special = 0;
156 // new: io.Modes must point to a new Structure (ExtIoDrp)
157 PIO->iodrp.io_Modes = (IPTR)&ExtIoDrp;
159 // fill in the new structure
160 ExtIoDrp.PixAspX = 1; // for the correct aspect ratio
161 ExtIoDrp.PixAspY = 1; // normally the values of the monitor-structure
162 // TicksX and TicksY
163 // our bitmap is 3 bytes format RGB (24 bits)
164 ExtIoDrp.Mode = TPFMT_RGB24;
166 // send IORequest as usual to the printer.device
167 // Turboprint behaves exactly like the old printer.device
168 // so SendIO etc. are also possible
169 DoIO((struct IORequest *)PIO);
171 // if TurboPrint is not installed: Error-Message
172 // also possible: load TurboPrint:TurboPrefs with the -q flag, so
173 // you can install it yourself
174 else printf("Error: TurboPrint Pro 3 (or higher) not installed\n");
176 CloseDevice((struct IORequest *)PIO);
178 DeleteExtIO((struct IORequest *)PIO);
180 DeleteMsgPort(PrinterMP);
182 FreeMem(MyBitMap.Planes[0],MyBitMap.BytesPerRow*MyBitMap.Rows);
185 if (GfxBase) CloseLibrary((struct Library*)GfxBase);
186 if (IntuitionBase) CloseLibrary((struct Library*)IntuitionBase);
188 return 0;