home *** CD-ROM | disk | FTP | other *** search
- MODULE TmpToDP;
-
- (*======================================================================*)
- (* TmpToDP v1.0 *)
- (*======================================================================*)
- (* Copyright (c) 1989 Chris Bailey, All Rights Reserved *)
- (*======================================================================*)
- (* Version: 1.00 Author : Chris Bailey *)
- (* Date : 23-Oct-89 *)
- (*======================================================================*)
- (* Source note : there are a few conventions in here which I am not *)
- (* really sure of, but the program is very very stable the way it is. *)
- (* The main thing that gave me problems was getting the message format *)
- (* right. One of the keys to this seemed to be setting the reply port *)
- (* name to "REMO". This may or may not be necessary, but it works, *)
- (* and the program as it stands meets my needs. *)
- (*======================================================================*)
- (* Link with RT.lnk *)
- (*======================================================================*)
-
- FROM SYSTEM IMPORT ADR, TSIZE, BYTE, SHIFT, ADDRESS, STRPTR,
- WORD;
- FROM Tasks IMPORT Wait, SetSignal, SignalSet;
- FROM DOS IMPORT SIGBreakC;
- FROM Nodes IMPORT NodeType;
- FROM Ports IMPORT WaitPort, GetMsg, ReplyMsg, PutMsg,
- MsgPortPtr, FindPort, Message, MessagePtr;
- FROM Memory IMPORT AllocMem, FreeMem, MemReqSet, MemReqs;
- FROM Conversions IMPORT ConvNumToStr;
- FROM TermOut IMPORT WriteString, WriteCard, WriteLongInt, WriteHex;
- FROM Strings IMPORT LengthStr, AppendSubStr, AssignStr;
- FROM PortUtils IMPORT CreatePort, DeletePort;
- FROM BufferedDOS IMPORT BufHandle, BufOpen, BufClose, ModeOldFile,
- BufRead;
- FROM CmdLineUtils IMPORT argc, argv;
-
- CONST
- BANNER = "\x9b33;1mTmpToDP\x9b0m V1.0, 23-Oct-89\nCopyright © 1989 Chris Bailey, All Rights Reserved\n\n";
-
- TYPE rgbs = (red, green, blue);
-
- (* header format for temp file *)
- HeaderType = RECORD
- Width, Height : CARDINAL;
- NumRegisters : CARDINAL;
- END;
-
- (* we need to do this so that we don't run into *)
- (* alignment problems. This way we have an even # of bytes *)
- Colors = RECORD
- r, g, b : BYTE;
- r2,g2,b2: BYTE;
- END;
-
- (* max of 256 colors *)
- ColorType = RECORD
- colors : ARRAY[0..127] OF Colors;
- END;
-
- (* our extension part of the message *)
- Mess = RECORD
- Header : ARRAY[0..7] OF CHAR; (* REMODlva *)
- Count : WORD; (* how many RGB triplets *)
- Line : WORD; (* which line # to render on *)
- RGBs : ARRAY[0..1023] OF ARRAY[red..blue] OF WORD;
- (* that's the image data, max of 1024 pixels wide *)
- END;
-
- (* message we will send to DigiPaint *)
- SendMsgPtr = POINTER TO SendMsg;
- SendMsg = RECORD
- header : Message; (* normal exec message *)
- stuff : Mess; (* our extension *)
- END;
-
- VAR file : BufHandle; (* filehandle for input file *)
- len : LONGINT; (* used for dos reads *)
- header : HeaderType; (* file header *)
- ColorTable : ColorType; (* colortable from the file *)
- line : ARRAY[0..1023] OF BYTE; (* one line of data *)
- j, LineNum : CARDINAL; (* current line number, tmp value *)
- OurPort : MsgPortPtr; (* msg port to communicate w/DP *)
- Stuff : Mess; (* a temp message to fill in *)
- DPPort : STRPTR; (* portname for DigiPaint *)
-
- (*******************
- * Send one line of data to DigiPaint 3's port which has already
- * been filled in by previous procedures
- *)
-
- PROCEDURE SendData();
- VAR
- HostPort : MsgPortPtr; (* digipaint host pointer *)
- rep, msg : SendMsgPtr; (* our message, reply message *)
- BEGIN
- (* could speed up program by only finding the port once the *)
- (* entire program, but this way somebody doesn't pull the rug *)
- (* out from under us. *)
-
- HostPort := FindPort(DPPort);
- IF HostPort # NIL THEN
- msg := AllocMem(TSIZE(SendMsg),MemReqSet{MemPublic,MemClear});
- IF msg # NIL THEN
- msg^.stuff := Stuff;
- msg^.header.mnNode.lnName := ADR("REMO");
- msg^.header.mnNode.lnType := NTMessage;
- msg^.header.mnReplyPort := OurPort;
- msg^.header.mnLength := TSIZE(SendMsg);
- PutMsg(HostPort,msg);
-
- (* wait for a reply to our message *)
- LOOP
- rep := WaitPort(OurPort);
- rep := GetMsg(OurPort);
- IF rep # NIL THEN
- IF (rep = msg) & (rep^.header.mnNode.lnType = NTReplyMsg) THEN
- EXIT;
- ELSE
- ReplyMsg(rep);
- END;
- END; (* reply # NIL *)
- END; (* loop *)
-
- FreeMem(msg,TSIZE(SendMsg)); (* dealloc message *)
- ELSE
- WriteString("\n** Couldn't allocate message.\n");
- END;
- ELSE
- WriteString("\n** Can't find DigiPaint 3's Port\n");
- END;
-
- END SendData;
-
- (*******************
- * Figure out an Amiga RGB value from the data we read in
- *)
-
- PROCEDURE GetColor(col : BYTE; rgb : rgbs) : CARDINAL;
- VAR which : CARDINAL;
- temp : BYTE;
- ret : CARDINAL;
- BEGIN
- which := CARDINAL(col);
- IF (which MOD 2) = 0 THEN
- CASE rgb OF
- |red : temp := ColorTable.colors[which DIV 2].r;
- |green: temp := ColorTable.colors[which DIV 2].g;
- |blue : temp := ColorTable.colors[which DIV 2].b;
- END;
- ELSE
- CASE rgb OF
- |red : temp := ColorTable.colors[which DIV 2].r2;
- |green: temp := ColorTable.colors[which DIV 2].g2;
- |blue : temp := ColorTable.colors[which DIV 2].b2;
- END;
- END;
-
- ret := CARDINAL(temp);
- ret := ret * 4; (* Convert from 0..1023 to 0..4095 the easy way *)
- RETURN(ret);
- END GetColor;
-
- (*******************
- * Convert and send one line of data from the tmp file to DigiPaint 3
- *)
-
- PROCEDURE WriteLine();
- VAR i : CARDINAL;
- bool : BOOLEAN;
- BEGIN
- (* fill in our temp message *)
- Stuff.Header := "REMODlvb";
- Stuff.Count := header.Width;
- Stuff.Line := LineNum;
- FOR i := 0 TO (header.Width-1) DO
- Stuff.RGBs[i][red] := INTEGER(GetColor(line[i],red));
- Stuff.RGBs[i][green] := INTEGER(GetColor(line[i],green));
- Stuff.RGBs[i][blue] := INTEGER(GetColor(line[i],blue));
- END;
- i := header.Width;
- (* fill things out to an even multiple of 32, like DigiPaint needs *)
- WHILE((i MOD 32) # 0) DO
- Stuff.RGBs[i][red] := 0;
- Stuff.RGBs[i][green] := 0;
- Stuff.RGBs[i][blue] := 0;
- INC(i); INC(INTEGER(Stuff.Count));
- END;
- WriteString("\x9b13\x44\x9b\x4aSending....");
- SendData();
- WriteString("\x9b8\x44\x9b\x4at.\r");
- END WriteLine;
-
- (*******************
- * See if the user pressed ctrl-C
- *)
-
- PROCEDURE Break(): BOOLEAN;
- BEGIN
- RETURN SIGBreakC IN SetSignal(SignalSet{},SignalSet{SIGBreakC});
- END Break;
-
- BEGIN
- WriteString(BANNER);
-
- IF argc = 3 THEN (* only 1 way to call this *)
- DPPort := argv[2];
- IF BufOpen(file,argv[1],1024,ModeOldFile) THEN (* open the file *)
- OurPort := CreatePort(ADR("REMO"),0);
- IF FindPort(DPPort) # NIL THEN (* quick check to see if port exists *)
- IF OurPort # NIL THEN (* now we're ready to start *)
- len := BufRead(file,ADR(header),TSIZE(HeaderType));
- WriteString("Picture is ");
- WriteCard(header.Width,1);
- WriteString("x");
- WriteCard(header.Height,1);
- WriteString("x");
- WriteCard(header.NumRegisters,1);
- WriteString(" colors.\n"); (* 1 record per 2 colors, 6 bytes per record *)
- len := BufRead(file,ADR(ColorTable),(header.NumRegisters DIV 2) * 6);
- WriteString("Color table loaded\n\n");
- LineNum := 0;
- REPEAT
- len := BufRead(file,ADR(line),header.Width);
- WriteString("Line "); WriteCard(LineNum,1); WriteString(" converting...");
- WriteLine();
- INC(LineNum);
- UNTIL(LineNum = header.Height) OR Break();
- IF (LineNum = header.Height) THEN
- WriteString("\nLooks like everything functioned normally.\n");
- ELSE
- WriteString("^C\nProgram halted.\n");
- END;
- DeletePort(OurPort);
- ELSE
- WriteString("Can't open required message port.\n");
- END;
- IF BufClose(file) THEN END;
- ELSE
- WriteString("Can't find DigiPaint's port.\n");
- END;
- ELSE
- WriteString("Error opening file.\n");
- END;
- ELSE
- WriteString("Invalid arguments.\nUsage: ");
- WriteString(argv[0]^);
- WriteString(" <temp file> <digipaint portname>\n");
- END;
-
- END TmpToDP.
-