home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d4xx
/
d463
/
fileio.lha
/
FileIO
/
FileIO.lzh
/
asm
/
CustomList.asm
next >
Wrap
Assembly Source File
|
1991-02-08
|
19KB
|
654 lines
;Set your editor's TAB width to 3
;====Uncomment these directives for MANX asm only!! Advice: Buy a good asm.
; far code ;so that we can use register a4, and no limit on program size.
; far data
ADDSYM
SMALLOBJ ;CAPE PC directive. Comment out if not using CAPE
OBJFILE "rad:CustomList.o"
; This program opens and utilizes the requester.library in order to use
; the new SPECIAL_REQ flag. This flag allows us to display a list of
; strings in a requester with all the features of the FileIO requester.
; Because version 0 of the library did not support this feature, but version
; 1.? now does, we must open the library with version #1. Old applications
; that do not know about SPECIAL_REQ will still work with this version of
; the library. It is backward compatible as far as the disk IO features are
; concerned. This program also demos how to use the StartHandler custom
; vector to add gadgets to the requester, the GadgetHandler custom vector to
; handle those gadgets, and how to alter the wakeup mask so that the
; StartHandler is called for these events (i.e. in case you want to be able
; to also handle a msg at another port in addition to window IDCMP msgs).
; You can also use these custom handlers in this manner when doing normal
; filename selection with the requester.
; If running this program from the CLI and you specify any argument on the
; command (i.e. 1> TestFileIO blort ), then the window will open on a hires
; screen. You can then see what the requester looks like in hires.
; For Manx, ln -o TestFileIO ManxStartUp.o main.o cl32.lib
;
; For Others, Blink StartUp.o main.o amiga.lib NODEBUG to TestFileIO
INCLUDE "rad:FileIO.i"
;======Amiga Library routines======
XREF _LVOCloseLibrary,_LVOCloseScreen,_LVOCloseWindow,_LVOSetMenuStrip
XREF _LVOOpenWindow,_LVOOpenScreen,_LVOOpenLibrary
XREF _LVOGetMsg,_LVOReplyMsg,_LVOWait,_LVOMove,_LVOText
XREF _LVOSetAPen,_LVOSetBPen,_LVOSetDrMd
;======From the startup code======
XREF _SysBase,_DOSBase
LIB_VERSION equ 33
SECTION FileIOTestCode,CODE
XDEF _main
_main:
movem.l d2-d7/a2-a6,-(sp)
movea.l _SysBase,a6
;======Open The Intuition Library=======
moveq #LIB_VERSION,d0
lea IntuitionName,a1
jsr _LVOOpenLibrary(a6)
lea _IntuitionBase,a4
move.l d0,(a4)+
beq C7
;======Open The Graphics Library========
moveq #LIB_VERSION,d0
lea GfxName,a1
jsr _LVOOpenLibrary(a6)
move.l d0,(a4)+
beq C6
;*******Open the "Brand New, Improved, Exciting" Requester library*********
moveq #1,d0 ;version #1 please
lea RequesterName,a1
jsr _LVOOpenLibrary(a6)
move.l d0,(a4)+
beq C5
;=====If started from WBench, then don't open a CUSTOM screen
movea.l _IntuitionBase,a6
move.l 52(sp),d0
beq.s .9
;=====If opened from CLI with any argument, then open CUSTOM screen
subq.l #2,48(sp)
bcs.s .9
lea newScreen,a0
jsr _LVOOpenScreen(a6)
lea newWindow,a0
;---Window's Screen = ScreenPtr
move.l d0,30(a0)
beq.s .9A ;If an error, forget the screen!
;---Window's Type = CUSTOMSCREEN
move.w #15,46(a0)
;=========Open the FileIO window==========
.9 lea newWindow,a0
.9A jsr _LVOOpenWindow(a6)
move.l d0,(a4)+
beq C2
movea.l d0,a3
;---Get Window's RastPort
move.l 50(a3),(a4)
lea ProjectMenu,a1
movea.l a3,a0
jsr _LVOSetMenuStrip(a6)
;---Get a FileIO structure
E1 movea.l _RequesterBase,a6
jsr _LVOGetFileIO(a6)
movea.l d0,a4
move.l d0,d1
beq IOe ;If NULL, then error, so exit this test program.
;---Set Colors and DrawMode
moveq #1,d0
move.b d0,FILEIO_DRAWMODE(a4)
movea.l RastPort,a2
movea.l a2,a1
movea.l _GfxBase,a6
jsr _LVOSetDrMd(a6)
moveq #2,d0
move.b d0,FILEIO_PENA(a4)
movea.l a2,a1
jsr _LVOSetAPen(a6)
moveq #0,d0
move.b d0,FILEIO_PENB(a4)
movea.l a2,a1
jsr _LVOSetBPen(a6)
;====VERY IMPORTANT: Indicate that we want a SPECIAL_REQ==========
bset.b #7,(a4) ;set the SPECIAL_REQ bit of Flags
;====Set up the XY co-ordinates of where the requester will open====
moveq #6,d0
move.w d0,FILEIO_X(a4) ;x position
moveq #11,d0
move.w d0,FILEIO_Y(a4) ;y position
;===========SET UP OUR LIST OF STRINGS==========
;NOTE: Since our list is initially empty, we don't have to call NewEntryList
;first, but we will anyway to develop good habits.
movea.l _RequesterBase,a6
movea.l a4,a1
jsr _LVONewEntryList(a6)
lea StringAddr,a2
moveq #10-1,d7 ;make a list of 10 strings
nxtEN move.l d7,d1
addq.w #1,d1 ;ID = loopcount+1 (i.e. 1 to 10)
movea.l a4,a1
movea.l (a2)+,a0
jsr _LVOAddEntry(a6)
dbra d7,nxtEN
;---Set up our routine, Information(), as the custom FileIO gadget routine
; We don't have to set up these 2 fields, we could leave them 0 in which
; case the custom gadget is ignored.
lea About,a0
move.l a0,FILEIO_TEXT(a4)
lea Information,a0
move.l a0,FILEIO_ROUTINE(a4)
;---Add our Custom vectors (i.e. for StartHandler and GadgetHandler)
lea HandlerBlock,a0
move.l a0,FILEIO_CUSTOM(a4)
bset.b #CUSTOM_HANDLERS-8,(a4)
;====Create a mask of the Window's UserPort's mp_Sigbit=====
E3 movea.l 86(a3),a0
move.b 15(a0),d0
moveq #0,d7
Bset.l d0,d7
;=====Get the message that arrived at our UserPort====
E4 movea.l 86(a3),a0
movea.l _SysBase,a6
jsr _LVOGetMsg(a6)
move.l d0,d1
bne.s E7
;===Check if we are ready to exit the program=====
E5 Btst.b #0,Quit
beq E15
;---Print out "Click Mouse to start demo....
movea.l RastPort,a2
moveq #5,d0
moveq #75,d1
movea.l a2,a1 ;our window's RastPort
move.l a6,-(sp) ;save _SysBase
movea.l _GfxBase,a6
jsr _LVOMove(a6)
moveq #36,d0 ;# of bytes to output.
lea Click,a0
movea.l a2,a1
jsr _LVOText(a6)
movea.l (sp)+,a6 ;restore _SysBase
;===Wait for a message sent to our Window (from Intuition)===
E6 move.l d7,d0
jsr _LVOWait(a6)
bra.s E4
;====Copy all the info we want from the IntuiMessage====
E7 movea.l d0,a1
lea 20(a1),a0 ;get the address of the first field to copy.
move.l (a0)+,d6 ;Class field to d6
move.w (a0)+,d5 ;Code field to d5
move.w (a0)+,d4 ;Qualifier field to d4
movea.l (a0)+,a2 ;IAddress field to a2
move.w (a0)+,d3 ;MouseX position to d3
move.w (a0)+,d2 ;MouseY position to d2
;====Now reply to the message so Intuition can dispose of it
E8 ;Address of the message is in a1.
jsr _LVOReplyMsg(a6)
;========switch (class)=========
Bclr.l #9,d6 ;CLOSEWINDOW
bne.s CW
Bclr.l #8,d6 ;MENUPICK
bne.s MU
Bclr.l #3,d6 ;MOUSEBUTTONS
beq E4
;---Make sure that it's an UP select if MOUSEBUTTONS
subi.b #$68,d5
beq E4 ;ignore down
;===The FOLLOWING ROUTINE IS OUR TEST CALL. WHEN THE USER IS DONE (in FileIO lib)
;===HE WILL SELECT EITHER THE CANCEL OR OK! GADGET. IF CANCEL, TestFileIO
;===DOES NOTHING. IF OK!, TestFileIO JUSTS PRINTS THE SELECTED STRING.
E2 bsr TestFileIO
bra E4
;=========case CLOSEWINDOW:============
CW Bclr.b #0,Quit
bra E4
;=========case MENUPICK:==============
;---Determine which item
MU lsr.w #5,d5 ;Shift the item # bits into lowest bits of reg.
andi.w #$3F,d5 ;Isolate the Item # from the Menu and subitem #.
bne E4
;---Set MULTIPLE_FILES
bchg.b #MULTIPLE_FILES,1(a4)
bra E4
;======if an error, indicate NO_MEMORY. This is a FileIO routine
;======and is callable even if GetFileIO() fails
IOe movea.l a3,a0
moveq #0,d0
movea.l _RequesterBase,a6
jsr _LVOAutoFileMessage(a6)
;========NOW BEGINS OUR EXIT ROUTINE=========
;ReleaseFileIO will free our list of strings
E15 movea.l a4,a1 ;If the pointer to FileIO was NULL, then
movea.l _RequesterBase,a6 ;ReleaseFileIO just returns, so it's safe to
jsr _LVOReleaseFileIO(a6) ;always release any return value of GetFileIO.
;=====Close the Window and Screen======
C1 movea.l _IntuitionBase,a6
movea.l a3,a0
jsr _LVOCloseWindow(a6)
C2 move.l ScreenPtr,d0
beq.s C3 ;check if we specified a screen
movea.l d0,a0
; _IntuitionBase in a6
jsr _LVOCloseScreen(a6)
;=====Close Whichever Libs are Open (_SysBase in a6 for ALL calls)=====
C3 movea.l _SysBase,a6
movea.l _RequesterBase,a1
jsr _LVOCloseLibrary(a6)
C5 movea.l _GfxBase,a1
jsr _LVOCloseLibrary(a6)
C6 movea.l _IntuitionBase,a1
jsr _LVOCloseLibrary(a6)
C7 movem.l (sp)+,d2-d7/a2-a6
rts
;*******************************************
; This just calls the DoFileIO library routine and displays a msg on return.
; (We must have a FileIO structure).
; The DoFileIO routine returns -1 if the user selected CANCEL, -2 if the
; library is in use by another task, or returns non-zero if OK! was selected.
; At this point, if the user selected OK, our FILEIO_FILENAME buffer will
; contain the selected string and FILEIO_FILESIZE will be the ID.
;
; TestFileIO(FileIO, window)
; a4 a3
typename:
;--This shows what would happen (automatically) if the lib was in use on a
; call to DoFileIO(), or the requester couldn't open.
.error:
lea errmsg,a0
prt move.l a0,d0
movea.l a3,a0
jsr _LVOAutoMessage(a6)
moveq #0,d0
rts
.can lea cancel,a0
bra.s prt
.inuse:
lea inuse,a0
bra.s prt
XDEF TestFileIO
TestFileIO:
movea.l _RequesterBase,a6
;---DoFileIO(FileIO, window)
movea.l a3,a1
movea.l a4,a0
jsr _LVODoFileIO(a6)
move.l d0,d1
beq.s .error
;Must have been an error if returned 0. If we were using DoFileIOWindow(),
;the window might not have opened. Or the requester might not have opened.
;We could check the FileIO's ERRNO field to see what the specific error was.
addq.l #1,d1
beq.s .can ;If -1, user must have selected CANCEL
addq.l #1,d1
beq.s .inuse ;If -2, the library was in use
;---AutoMessage(string, window) Display our chosen string.
;Filename buffer address in d0
movea.l a3,a0
jsr _LVOAutoMessage(a6)
;---If ID = -1 then user must have typed a string not in the list
move.l FILEIO_FILESIZE(a4),d0 ;this is the ID of the chosen field
bpl.s out1
movea.l a3,a0
lea NotIn,a1
move.l a1,d0
jsr _LVOAutoMessage(a6)
;---Did our custom routine end the requester?
out1 moveq #ERR_APPGADG,d0
sub.b FILEIO_ERRNO(a4),d0
bne.s out2
movea.l a3,a0
lea AppCan,a1
move.l a1,d0
jsr _LVOAutoMessage(a6)
;---If MULTIPLE_FILES, display all selected entries
out2 btst.b #MULTIPLE_FILES,1(a4)
beq.s out3
clr.l -(sp) ;zero our PTR to a FileEntry
morFL movea.l sp,a0
movea.l a4,a1
jsr _LVORetrieveEntry(a6)
move.l d0,d1
beq.s last
movea.l d0,a0
move.l 8(a0),d0 ;get the Entry structure
addq.l #5,d0 ;get the EntryString address
movea.l a3,a0
jsr _LVOAutoMessage(a6)
bra.s morFL
last addq.l #4,sp
out3 moveq #1,d0
rts
;=====================================================================
;Our routine for the custom FileIO gadget. Lib passes our FileIO in a2
;and Window in a3. This returns the BOOL value from AutoPrompt3 so that
;if the user selects YES (TRUE) the requester ends. Note that it is permiss-
;ible to change the FILEIO_TEXT and FILEIO_ROUTINE fields in which case these
;will become effective upon return from here.
XDEF Information
Information:
movem.l a2/a3,-(sp)
movea.l a3,a0
lea Msg1,a1
lea Msg2,a2
lea Msg3,a3
movea.l _RequesterBase,a6
jsr _LVOAutoPrompt3(a6)
movem.l (sp)+,a2/a3
rts
;========================================================================
; This is our StartHandler. The library calls this once after the requester
; is up and been displayed. We are passed the requester's window in a3, the
; FileIO in a2, the Requester in a5, and the WakeupMask in d0. At this point,
; we could modify RequesterBase's WakeupMask field so that we can be woken up
; when some other event besides window IDCMP happens. (i.e. If we wanted to
; handle messages received at some port while the requester is open, we would
; set the port's mp_SigBit in WakeupMask the first time into this function.
; How do we know that this is the first time into this function? WakeupMask=0.
; Now, whenever a msg is received at that port, this function will be called.
; The port's mp_SigBit of WakeupMask should be set. We can then get, handle,
; and reply the msg from here.)
;
; This routine should return a 0 to redraw the display, a 1 to not redraw the
; display, or a -1 to end the requester. Note that if we end the requester,
; we should probably set the FILEIO_ERRNO field to some value that will tip
; us off that this routine ended the requester.
start_msg:
;---Is this the first time in this function? If so, add a few of our own
; gadgets to the req. We could also modify WakeupMask if we had some
; other ports to wait on.
move.l d0,d1
bne.s _2nd
lea BoolGadg,a0
;req in a5, window in a3
movea.l _RequesterBase,a6
jsr _LVOAddFileGadgs(a6)
;---If we had some port called Blort, we might do this here
; movea.l BlortPortAddr,a0 ;get our port address
; move.b 15(a0),d0 ;get it's wakeup bit # (assuming PA_SIGNAL)
; movea.l _RequesterBase,a6
; move.l ReqWakeupMask(a6),d1
; bset.l d0,d1 ;set that bit of WakeupMask
; move.l d1,ReqWakeupMask(a6)
notme moveq #0,d0
rts
;=====================================================
;---Note: If we had modified WakeUpMask as above, we would do this
_2nd:
; movea.l BlortPortAddr,a0
; move.b 15(a0),d1
; btst.l d1,d0
; beq.s notme ;Who woke us up besides the Window or Blort port??
moreMsgs:
; movea.l BlortPortAddr,a0
; movea.l _SysBase,a6
; jsr _LVOGetMsg(a6)
; move.l d0,myMsg
; beq.s notme
;now do something with the msg
; movea.l myMsg,a1
; movea.l _SysBase,a6
; jsr _LVOReplyMsg(a6)
bra notme
;========================================================================
; This is our GadgetHandler. The library calls this whenever the user selects
; those gadgets we added in StartHandler. We are passed the following:
;
;gadgAddr in a4
;gadgID in d0
;MouseX in d6
;MouseY in d7
;secs in d2
;micros in d5
;FileIO in a2
;Window in a3
;Requester in a5
;Note that we should not use gadgIDs above 32673 as these are
;reserved by the requester.
XREF _LVORefreshGadgets
do_gadg:
tst.w d0
bne.s gadg2
;---Our BOOL Gadget (just "flip" the text between ON/OFF)
lea ON,a0
bchg.b #0,GadgFlags
bne.s itsOn
lea OFF,a0
itsOn move.l a0,GadgStr
;---We're responsible for refreshing our own gadgets
move.l a2,-(sp)
movea.l a5,a2
movea.l a3,a1
lea BoolGadg,a0
movea.l _IntuitionBase,a6
jsr _LVORefreshGadgets(a6)
movea.l (sp)+,a2
gok moveq #0,d0 ;don't end the requester
rts
;---Our String Gadget
gadg2:
;I can't think of anything to do with the text that the user just typed
;in, but maybe you can.
bra gok
;SECTION MainData,DATA ;Not needed for CAPE PC relative addressing!!
XDEF _IntuitionBase,_GfxBase,ScreenPtr,_RequesterBase
;must be in this order
_IntuitionBase dc.l 0
_GfxBase dc.l 0
_RequesterBase dc.l 0
window dc.l 0
RastPort dc.l 0
XDEF newScreen
newScreen:
dc.w 0,0 ;LeftEdge, TopEdge
dc.w 640,400 ;Width, Height
dc.w 2 ;Depth
dc.b 0,1 ;Detail, Block pens
dc.w -32764 ;ViewPort Modes HIRES|LACE (must set/clr HIRES as needed)
dc.w 15 ;CUSTOMSCREEN
dc.l TextAttr ;Font
dc.l ScrTitle
dc.l 0 ;Gadgets
dc.l 0 ;CustomBitmap
XDEF newWindow
newWindow:
dc.w 30,30,306,145
dc.b 0,1
;IDCMP = MOUSEBUTTONS|CLOSEWINDOW|MENUPICK
dc.l $308
;WindowFlags = WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|ACTIVATE|WINDOWSIZE
;(no FOLLOWMOUSE allowed as that messes up the requester when using
;DoFileIO(). If you need FOLLOWMOUSE, then use DoFileIOWindow() to open
;the req in its own window.)
dc.l $100F
dc.l 0
dc.l 0
dc.l WINTITLE
ScreenPtr:
dc.l 0
dc.l 0
dc.w 306,145,600,240
dc.w 1 ;WBENCHSCREEN
;==========THE PROJECT MENU===========
ProjectMenu:
dc.l 0
dc.w 0,0
dc.w 90,0
dc.w 1
dc.l ProjectTitle
dc.l MultiItem
dc.w 0,0,0,0
;These are MenuItem structures for the preceding Menu Structure.
MultiItem dc.l 0
dc.w 0,0
dc.w 200,10
dc.w $5F
dc.l 0
dc.l MultiText
dc.l 0
dc.b 'M'
dc.b 0
dc.l 0
dc.w 0
MultiText dc.b 0,1,1,0
dc.w 19,0
dc.l TextAttr,MultiString,0
TextAttr: ;Topaz 8 is a ROM font so doesn't need to be opened
dc.l FONTNAME
dc.w 8 ;TOPAZ_EIGHTY
dc.b 0,0
;For custom vectors StartHandler and GadgetHandler
HandlerBlock:
;these are the addresses of my custom handlers for the requester's
;REQSET, GADGETUP and GADGETDOWN, DISKINSERTED, RAWKEY, and
;MOUSEMOVE respectively. Note that I only installed a StartHandler and
;GadgetHandler. The rest are NULL because I don't care about them.
dc.l start_msg ;StartUpHandler
dc.l do_gadg ;GadgetHandler
dc.l $0000 ;NewDiskHandler
dc.l $0000 ;KeyHandler
dc.l $0000 ;MouseMoveHandler
;========== Two gadgets to add to the req (a BOOL and String) ===========
;Bool Gadget
BoolGadg:
dc.l StrGadg
dc.w 70,83,61,11,0
dc.w 1
dc.w $1001 ;REQGADGET|BOOLGADGET
dc.l BoolBorder,0,BoolGadgText,0
dc.l 0
dc.w 0
dc.l 0
BoolGadgText:
dc.b 0,1,1,0
dc.w 8,2
dc.l TextAttr
GadgStr:
dc.l OFF
dc.l 0
BoolPts:
dc.w 60,10,60,0,0,0,0,10,61,10,61,1,62,1,62,11,1,11
BoolBorder:
dc.w 0,0
dc.b 0,1
dc.b 0
dc.b 9
dc.l BoolPts
dc.l 0
;String Gadget
StrGadg:
dc.l 0
dc.w 70,99,202,10,0,1,$1004
dc.l StrBorder,0,StrGadgText,0
dc.l StrInfo
dc.w 1
dc.l 0
StrBorder:
dc.w 0,0
dc.b 0,1
dc.b 0,9
dc.l StringPts
dc.l 0
StringPts:
dc.w 0,-1,199,-1,200,0,200,7,199,8,0,8,-1,7,-1,0,0,-1
StrGadgText:
dc.b 0,1,1,0
dc.w -52,0
dc.l TextAttr
dc.l String
dc.l 0
StrInfo:
dc.l StringBuf
dc.l 0
dc.w 0,40,0,0,0,0,0,0
dc.l 0,0,0
StringBuf ds.b 40
;For our list of strings to display
StringAddr:
dc.l Ten
dc.l Nine
dc.l Eight
dc.l Seven
dc.l Six
dc.l Five
dc.l Four
dc.l Three
dc.l Two
dc.l One
Ten dc.b 'Ten',0
Nine dc.b 'Nine',0
Eight dc.b 'Eight',0
Seven dc.b 'Seven',0
Six dc.b 'Six',0
Five dc.b 'Five',0
Four dc.b 'Four',0
Three dc.b 'Three',0
Two dc.b 'Two',0
One dc.b 'And this is One',0
Quit dc.b 1 ;When this is a 0, the user wants to exit.
ScrTitle dc.b 'Example FileIO Program Screen',0
WINTITLE dc.b 'Example FileIO Program Window',0
Click dc.b 'Click mouse for demo or CLOSEWINDOW.',0
IntuitionName dc.b 'intuition.library',0
DOSName dc.b 'dos.library',0
GfxName dc.b 'graphics.library',0
RequesterName dc.b 'requester.library',0
FONTNAME dc.b 'topaz.font',0
errmsg dc.b 'Error in opening the requester',0
cancel dc.b 'The CANCEL gadget was selected',0
inuse dc.b 'Another task using the requester',0
About dc.b ' About',0
Msg1 dc.b 'An example of SPECIAL_REQ',0
Msg2 dc.b 'by Jeff Glatt',0
Msg3 dc.b 'dissidents',0
NotIn dc.b 'This string is not in the list.',0
AppCan dc.b 'Cancelled by the custom gadget.',0
MultiString dc.b 'Multi File',0
ProjectTitle dc.b 'Project',0
ON dc.b 'On ',0
OFF dc.b 'Off',0
String dc.b 'String',0
GadgFlags dc.b 0
END