home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
disks
/
disk463.lzh
/
PrintSpool
/
PrtSpool.lzh
/
BasicPrint
(
.txt
)
next >
Wrap
AmigaBASIC Source Code
|
1990-06-27
|
13KB
|
318 lines
'This code was written by Jeff Glatt of dissidents software, and has been
'placed in the public domain along with the ilbm and requester libraries.
'This program uses these 3 custom libraries to select an IFF ILBM file and
'display, and print it. Documentation for the requester and ILBM library
'appears ON Fish #203!
CLS
LOCATE 1,8
PRINT "Demo Basic program using the requester, ilbm, and prtspool libs."
LOCATE 2,11
PRINT "Literally hacked together by Jeff Glatt (dissidents)"
DEFLNG a-Z 'IMPORTANT! All variables are longs (for the library calls)
'requester.bmap, ilbm.bmap, exec.bmap, prtspool.bmap and intuition.bmap must be in the
'current directory, or prepend the appropriate path to the lib name.
LIBRARY "requester.library"
LIBRARY "ilbm.library"
LIBRARY "exec.library"
LIBRARY "intuition.library"
LIBRARY "prtspool.library"
DECLARE FUNCTION AllocMem() LIBRARY
DECLARE FUNCTION GetMsg() LIBRARY
DECLARE FUNCTION WaitPort() LIBRARY
DECLARE FUNCTION DoFileIOWindow() LIBRARY 'These are in the requester lib.
DECLARE FUNCTION GetFullPathname() LIBRARY 'Other functions in the lib do
DECLARE FUNCTION GetFileIO() LIBRARY 'not return values, and so do not
DECLARE FUNCTION AutoFileMessage() LIBRARY 'need declaring
DECLARE FUNCTION AutoPrompt3() LIBRARY
DECLARE FUNCTION TypeFilename() LIBRARY
DECLARE FUNCTION UserEntry() LIBRARY
DECLARE FUNCTION PromptUserEntry() LIBRARY
DECLARE FUNCTION GetRawkey() LIBRARY
DECLARE FUNCTION DecodeRawkey() LIBRARY
DECLARE FUNCTION LoadIFFToWindow() LIBRARY
DECLARE FUNCTION SaveWindowToIFF() LIBRARY
'Test the PrintText function of prtspool library. Note that the user
'should set up his preferences via WorkBench. We could use CALL PrintNullText(WINDOW(7),SADD(WindowTitle$))
'on Basic strings since Amiga basic null terminates its strings, but we
'also get that double quote at the end of the string. ICK!
WindowTitle$ = "Demo Basic program using dissidents libs."
length=41 'the length of the string we wish to print.
NumCopies=1 'total 2 copies
flags=0 OR NumCopies 'regular text processing (i.e. no RAWWRITE)
CALL PrintText(flags,length,WINDOW(7),SADD(WindowTitle$))
'First we must get a buffer for the pathname. The FileIO's DoFileIOWindow()
'will copy the complete pathname there. The complete path looks just like
'a CLI line:
' Diskname:TopDrawer/SubDrawer...etc...BottomDrawer/Filename
'Of course, the user may only select a disk or drawer, but no filename, and
'so the final "/Filename" will not be there. Also, the Filename might not
'be in any drawers, and so it will appear directly after the diskname. If
'this format looks weird to you, you need to learn about the CLI.
'We'll get our buffer from Exec via AllocMem().
MEMF.PUBLIC = 1 : MEMF.CLEAR = 65536 : BUFSIZE = 202
BufferPtr=AllocMem(BUFSIZE,MEMF.PUBLIC+MEMF.CLEAR) 'A buffer to copy the pathname to
IF BufferPtr = 0 THEN GOTO NoMem1
'Now we need to get a buffer if we want to allow the user to utilize the
'extention match feature.
BUFSIZE2 = 24
ExtPtr=AllocMem(BUFSIZE2,MEMF.PUBLIC+MEMF.CLEAR)
IF ExtPtr = 0 THEN GOTO NoMem2
FileIO=GetFileIO(0) 'Get the address of the FileIO structure
'Actually you don't need to pass the 0, but AmigaBasic seems to want something...
IF FileIO = 0 THEN GOTO CloseUp1 '0 means that you don't have a FileIO.
'Set the FileIO's Buffer field to our allocated PathBuffer's address
POKEL FileIO+248,BufferPtr
POKEL FileIO+222,ExtPtr 'Set the address of the extention string
'Set the title that will displayed in the FileIO window. This can be changed
'for each call so that you might have the title read "Save File" during a
'save routine, for example.
WindowTitle$ = "Display ILBM"
POKEL FileIO+244,SADD(WindowTitle$)
'Set the fore pen, back pen, and draw mode for title bar routines to some
'defaults. We always need to do this in case the requester is in use by
'another program and we get automatic title bar file entry. To demo this,
'run this program twice simultaneously with one of them having the file
'requester displayed. Note that the title bar entry appears in the 2nd
'window. This is because only 1 task can be displaying the FileIO requester
'at a time. Other simultaneous calls get redirected to the title bar entry.
POKE FileIO+261,1 'JAM2 DrawMode
POKE FileIO+262,1 'PenA = Color1
POKE FileIO+263,0 'PenB = Color0
DIM Pathname$(202)
'Suppress the .info files
POKE FileIO+1,128
'Now let's get the ILBMFrame structure (via AllocMem)
ILBMSIZE = 172
ILBMFrame=AllocMem(ILBMSIZE,MEMF.PUBLIC+MEMF.CLEAR)
IF ILBMFrame = 0 THEN GOTO NoMem3
Again:
CALL ResetTitle(FileIO,WINDOW(7)) 'Maybe we changed it for the error msgs.
Result=DoFileIOWindow(FileIO,0) 'do the FileIO selection on WB screen
IF Result = -1 THEN GOTO CloseUp2 '-1 means the user selected CANCEL.
'0 means the FileIO window couldn't open (probably due to lack of mem).
'Too bad! We'll have to get the filename some other way.
IF Result <> 0 THEN GOTO GotPathname
INPUT "Enter Filename >";Pathname$
ParseString(FileIO,SADD(Pathname$))
GOTO PrintName
GotPathname: 'We got a selection from the user!
'Now, our BufferPtr has the complete pathname. Let's copy it to Pathname$.
Pathname$ = ""
FOR i = 0 TO 202
value = PEEK(BufferPtr+i)
IF value = 0 THEN GOTO PrintName
char$ = CHR$(value)
Pathname$ = Pathname$+char$
NEXT i
PrintName:
'Now if this is a loadable file, the FileIO has it's size. If it's only a
'disc name or dir, or the file doesn't exist, then the size = 0.
IF PEEK(FileIO+2) = 0 THEN GOTO DiscOrDir 'Disk or Dir only
IF PEEKL(FileIO+240) = 0 THEN GOTO NoExist 'Aha! User typed in a Filename that doesn't yet exist
'Let's print out the filename being loaded and set a Wait pointer.
PRINT "Loading ";Pathname$
CALL SetWaitPointer(WINDOW(7))
'Now, if you want to load into a window that you already opened, then you
'must store the window and screen addresses in the ILBMFrame's iWindow and
'iScreen fields. The image will be clipped to fit the size of your window.
'(i.e. If you try to load a HIRES pic into a LORES window/screen, it will
'be clipped to fit.) If you want the lib to open a window of the right size
'when it loads the pic, set these fields to 0. The lib will return the
'addresses of the window and screen it opened in these fields. Now, the only
'problem I have is how to do an IDCMP loop in AmigaBasic. I really don't
'know what I'm doing in Basic, so I'll do it the way that I would in assem-
'bly.
'Initialize the iUserFlags field for invisible pointer, no title bar.
POKE ILBMFrame+1,3
picWindow&=0
picScreen&=0
UseMine=0 'a 1 if we load into an already opened window
INPUT "Do you want the lib to open a window (y or n)";ans$
IF ans$ = "y" THEN GOTO setaddress
SCREEN 2,320,200,5,1 'Open a LORES screen with 5 bitplanes
WINDOW 2,"Picture",,0,2 'Open a window to load the picture into
WINDOW OUTPUT 2
picWindow&=WINDOW(7) 'Get address of this current output window
picScreen&=PEEKL(picWindow&+46) 'Get the window's screen
UseMine=1
'Initialize the iUserFlags field
POKE ILBMFrame+1,0
setaddress:
POKEL ILBMFrame+156,picWindow& 'Set the iWindow and iScreen to 0 before we load.
POKEL ILBMFrame+160,picScreen& 'This tells the lib to open a window/screen for us.
Result=LoadIFFToWindow(BufferPtr,ILBMFrame) 'This does it all!
IF Result <> 0 THEN GOTO iffError 'Oops something went wrong
'Successful load. We should be looking at a picture right now
IF UseMine = 1 THEN GOSUB BasicLoop 'Do an AmigaBasic IDCMP loop
IF UseMine = 0 THEN GOSUB CustomLoop 'Do my assembly equiv IDCMP loop
NoWait:
IF UseMine = 1 THEN GOTO CloseMine 'Close the window WE opened.
'We must close any window and screen that the lib opened for us.
picWindow&=PEEKL(ILBMFrame+156)
picScreen&=PEEKL(ILBMFrame+160)
IF picWindow& <> 0 THEN CALL CloseWindow(picWindow&)
IF picScreen& <> 0 THEN CALL CloseScreen(picScreen&)
GOTO Query
CloseMine: 'I opened them for the image so I'll close my Basic window/screen
WINDOW CLOSE 2
SCREEN CLOSE 2
Query:
'Restore the mouse pointer
CALL ClearPointer(WINDOW(7))
'Note how the lib automatically spaces these messages symmetrically
Message2$ = "Example program and asm libs by Jeff Glatt" + CHR$(0)
Message3$ = "Would you like to view another?" + CHR$(0)
Message$ = "Basic ILBM Viewer" + CHR$(0)
boolean=AutoPrompt3(SADD(Message$),SADD(Message2$),SADD(Message3$),WINDOW(7))
IF boolean=1 THEN GOTO Again
CloseUp2:
CALL ClearPointer(WINDOW(7)) 'Restore the mouse pointer
CALL ResetTitle(FileIO,WINDOW(7)) 'Maybe we changed it for the error msgs.
CALL ReleaseFileIO(FileIO) 'Free the FileIO structure
NoMem3:
CALL FreeMem(ILBMFrame,ILBMSIZE) 'Free the ILBMFrame
CloseUp1:
CALL FreeMem(ExtPtr,BUFSIZE2) 'Free the extention match buffer
NoMem2:
CALL FreeMem(BufferPtr,BUFSIZE) 'Free the pathname buffer
NoMem1:
LIBRARY CLOSE
END
'**************************** ERROR MSG ROUTINES ************************
' For these 3 errors, let's see how the SetTitle function works. This will
' display in the window's title bar string1 followed by string2, but unlike
' a requester, returns control back to the program. When we finally call
' ResetTitle, the original title is restored. We can call SetTitle without
' needing a ResetTitle inbetween and vica versa. Notice how this message
' appears in the window and requester title bars. Subsequent calls to these
' error routines will change the title bar further. Yet, when we finally
' call ResetTitle upon exit, the initial title is restored. As you can see,
' these routines are good ror posting error msgs that don't halt the program
' (like requesters) but remain visible for as long as they are needed.
DiscOrDir:
Message$ = "Dir only - "+CHR$(0)
'String2 will be our Pathname
CALL SetTitle(SADD(Message$),SADD(Pathname$),FileIO,WINDOW(7))
GOTO Again
NoExist:
Message$ = "This file doesn't exist."+CHR$(0)
'Note how we indicate that we don't want String2. You must have string1
'though, even it were just a space.
CALL SetTitle(SADD(Message$),0,FileIO,WINDOW(7))
GOTO Again
iffError:
stringAddress=GetIFFPMsg(Result) 'Get the IFFP error msg
CALL SetTitle(stringAddress,0,FileIO,WINDOW(7))
GOTO NoWait
'********************* IDCMP Loop for ILBMLib-opened window ***************
CustomLoop:
'Let's get the iWindow field in the ILBMFrame. This contains the address of the
'window that the ilbm lib opened for us. We'll modify the IDCMP to allow
'MOUSEBUTTONS messages from intuition. Then we'll just wait for the user
'to click a MOUSEBUTTON before we close down the window/screen with the
'picture in it.
picWindow&=PEEKL(ILBMFrame+156) 'Here's our window address
picScreen&=PEEKL(ILBMFrame+160) 'Here's our screen address
idcmp.flags=8 'MOUSEBUTTONS
CALL ModifyIDCMP(picWindow&,idcmp.flags)
'First, let's start the print
NumCopies=0 '1 copy only
'OR with 65536 because we don't know if colors 0 and 1
'of the loaded picture will be different
'This forces a call to req libs' Window_BW before
'showing the "Remap background" req, then
'restores via BW_Restore() after user answers.
flags= 65536 OR NumCopies
CALL PrintFullWindow(flags,picWindow&)
port=PEEKL(picWindow&+86) 'Get the UserPort of the window
iloop:
Msg=WaitPort(port) 'Wait for a msg sent by Intuition
Msg=GetMsg(port) 'Get/Remove the Message
Result=PEEKL(Msg+20) 'Get its CLASS
CALL ReplyMsg(Msg) 'Reply to the Message
IF Result <> 8 THEN GOTO iloop 'If not MOUSEBUTTONS CLASS, just loop
'Display the picture until another mouse click
Msg=WaitPort(port) 'Wait for a msg sent by Intuition
Msg=GetMsg(port) 'Get/Remove the Message
Result=PEEKL(Msg+20) 'Get its CLASS
CALL ReplyMsg(Msg) 'Reply to the Message
RETURN
'********************* IDCMP Loop for BASIC-opened window ******************
BasicLoop:
NumCopies=0 '1 copy only
flags= 65536 OR NumCopies
CALL PrintFullWindow(flags,picWindow&)
MOUSE ON
IF MOUSE(0) = 0 THEN GOTO BasicLoop
WaitMouse:
SLEEP
IF MOUSE(0) = 0 THEN GOTO WaitMouse
'Wait for another mouse click
WaitMouse2:
IF MOUSE(0) = 0 THEN GOTO WaitMouse2
WaitMouse3:
SLEEP
IF MOUSE(0) = 0 THEN GOTO WaitMouse3
MOUSE OFF
RETURN