home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 326.lha / requester.library_v1.3 / CustomList.asm < prev    next >
Assembly Source File  |  1989-12-30  |  13KB  |  402 lines

  1.  ;====Uncomment these directives for MANX asm only!! Advice: Buy a good asm.
  2.  ; far   code ;so that we can use register a4, and no limit on program size.
  3.  ; far   data
  4.  
  5.     SMALLOBJ ;CAPE PC directive. Comment out if not using CAPE
  6.     OBJFILE    "rad:CustomList.o"
  7.  
  8. ; This program opens and utilizes the requester.library in order to use
  9. ; the new SPECIAL_REQ flag. This flag allows us to display a list of
  10. ; strings in a requester with all the features of the FileIO requester.
  11. ; Because version 0 of the library did not support this feature, but version
  12. ; 1.4 now does, we must open the library with version #1. Old applications
  13. ; that do not know about SPECIAL_REQ will still work with this version of
  14. ; the library. It is backward compatible as far as the disk IO features are
  15. ; concerned.
  16.  
  17. ; If running this program from the CLI and you specify any argument on the
  18. ; command (i.e.  1> TestFileIO blort ), then the window will open on a hires
  19. ; screen. You can then see what the requester looks like in hires.
  20.  
  21. ;  For Manx,   ln -o TestFileIO  ManxStartUp.o  main.o  cl32.lib
  22. ;
  23. ;  For Others, Blink StartUp.o main.o amiga.lib NODEBUG to TestFileIO
  24.  
  25.  INCLUDE  "rad:FileIO.i"
  26.  
  27.  ;======Amiga Library routines======
  28.    XREF    _LVOCloseLibrary,_LVOCloseScreen,_LVOCloseWindow,_LVOSetMenuStrip
  29.    XREF    _LVOOpenWindow,_LVOOpenScreen,_LVOOpenLibrary
  30.    XREF    _LVOGetMsg,_LVOReplyMsg,_LVOWait,_LVOMove,_LVOText
  31.    XREF    _LVOSetAPen,_LVOSetBPen,_LVOSetDrMd
  32.  
  33.  ;======From the startup code======
  34.    XREF    _SysBase,_DOSBase
  35.  
  36. LIB_VERSION equ 33
  37.  
  38.    SECTION FileIOTestCode,CODE
  39.  
  40.    XDEF   _main
  41. _main:
  42.     movem.l   d2-d7/a2-a6,-(sp)
  43.     movea.l   _SysBase,a6
  44. ;======Open The Intuition Library=======
  45.     moveq     #LIB_VERSION,d0
  46.     lea       IntuitionName,a1
  47.     jsr       _LVOOpenLibrary(a6)
  48.     lea       _IntuitionBase,a4
  49.     move.l    d0,(a4)+
  50.     beq       C7
  51. ;======Open The Graphics Library========
  52.     moveq     #LIB_VERSION,d0
  53.     lea       GfxName,a1
  54.     jsr       _LVOOpenLibrary(a6)
  55.     move.l    d0,(a4)+
  56.     beq       C6
  57. ;*******Open the "Brand New, Improved, Exciting" Requester library*********
  58.     moveq     #1,d0            ;version #1 please
  59.     lea       RequesterName,a1
  60.     jsr       _LVOOpenLibrary(a6)
  61.     move.l    d0,(a4)+
  62.     beq       C5
  63. ;=====If started from WBench, then don't open a CUSTOM screen
  64.     movea.l   _IntuitionBase,a6
  65.     move.l    52(sp),d0
  66.     beq.s     .9
  67. ;=====If opened from CLI with any argument, then open CUSTOM screen
  68.     subq.l    #2,48(sp)
  69.     bcs.s     .9
  70.     lea       newScreen,a0
  71.     jsr       _LVOOpenScreen(a6)
  72.     lea       newWindow,a0
  73.    ;-----Window's Screen = ScreenPtr
  74.     move.l    d0,30(a0)
  75.     beq.s     .9A             ;If an error, forget the screen!
  76.    ;-----Window's Type = CUSTOMSCREEN
  77.     move.w    #15,46(a0)
  78. ;=========Open the FileIO window==========
  79. .9  lea       newWindow,a0
  80. .9A jsr       _LVOOpenWindow(a6)
  81.     move.l    d0,(a4)+
  82.     beq       C2
  83.     movea.l   d0,a3
  84.    ;---Get Window's RastPort
  85.     move.l    50(a3),(a4)
  86. ;---Get a FileIO structure
  87. E1  movea.l   _RequesterBase,a6
  88.     jsr       _LVOGetFileIO(a6)
  89.     movea.l   d0,a4
  90.     move.l    d0,d1
  91.     beq       IOe          ;If NULL, then error, so exit this test program.
  92. ;---Set Colors and DrawMode
  93.     moveq     #1,d0
  94.     move.b    d0,FILEIO_DRAWMODE(a4)
  95.     movea.l   RastPort,a2
  96.     movea.l   a2,a1
  97.     movea.l   _GfxBase,a6
  98.     jsr       _LVOSetDrMd(a6)
  99.     moveq     #2,d0
  100.     move.b    d0,FILEIO_PENA(a4)
  101.     movea.l   a2,a1
  102.     jsr       _LVOSetAPen(a6)
  103.     moveq     #0,d0
  104.     move.b    d0,FILEIO_PENB(a4)
  105.     movea.l   a2,a1
  106.     jsr       _LVOSetBPen(a6)
  107. ;====VERY IMPORTANT: Indicate that we want a SPECIAL_REQ==========
  108.     bset.b    #7,(a4)  ;set the SPECIAL_REQ bit of Flags
  109. ;====Set up the XY co-ordinates of where the requester will open====
  110.     moveq     #6,d0
  111.     move.w    d0,FILEIO_X(a4)  ;x position
  112.     moveq     #11,d0
  113.     move.w    d0,FILEIO_Y(a4)  ;y position
  114. ;===========SET UP OUR LIST OF STRINGS==========
  115. ;NOTE: Since our list is initially empty, we don't have to call NewEntryList
  116. ;first, but we will anyway to develop good habits.
  117.     movea.l   _RequesterBase,a6
  118.     movea.l   a4,a1
  119.     jsr       _LVONewEntryList(a6)
  120.     lea       StringAddr,a2
  121.     moveq     #10-1,d7         ;make a list of 10 strings
  122. nxtEN:
  123.     move.l    d7,d1
  124.     addq.w    #1,d1            ;ID = loopcount+1 (i.e. 1 to 10)
  125.     movea.l   a4,a1
  126.     movea.l   (a2)+,a0
  127.     jsr       _LVOAddEntry(a6)
  128.     dbra      d7,nxtEN(pc)
  129. ;---Set up our routine, Information(), as the custom FileIO gadget routine
  130. ;   We don't have to set up these 2 fields, we could leave them 0 in which
  131. ;   case the custom gadget is ignored.
  132.     lea       About,a0
  133.     move.l    a0,FILEIO_TEXT(a4)
  134.     lea       Information,a0
  135.     move.l    a0,FILEIO_ROUTINE(a4)
  136. ;====Create a mask of the Window's UserPort's mp_Sigbit=====
  137. E3  movea.l   86(a3),a0
  138.     move.b    15(a0),d0
  139.     moveq     #0,d7
  140.     Bset.l    d0,d7
  141. ;=====Get the message that arrived at our UserPort====
  142. E4  movea.l   86(a3),a0
  143.     movea.l   _SysBase,a6
  144.     jsr       _LVOGetMsg(a6)
  145.     move.l    d0,d1
  146.     bne.s     E7
  147. ;===Check if we are ready to exit the program=====
  148. E5  Btst.b    #0,Quit
  149.     beq       E15
  150. ;----Print out "Click Mouse to start demo....
  151.     movea.l   RastPort,a2
  152.     moveq     #5,d0
  153.     moveq     #75,d1
  154.     movea.l   a2,a1           ;our window's RastPort
  155.     move.l    a6,-(sp)        ;save _SysBase
  156.     movea.l   _GfxBase,a6
  157.     jsr       _LVOMove(a6)
  158.     moveq     #36,d0          ;# of bytes to output.
  159.     lea       Click,a0
  160.     movea.l   a2,a1
  161.     jsr       _LVOText(a6)
  162.     movea.l   (sp)+,a6        ;restore _SysBase
  163. ;===Wait for a message sent to our Window (from Intuition)===
  164. E6  move.l    d7,d0
  165.     jsr       _LVOWait(a6)
  166.     bra.s     E4
  167. ;====Copy all the info we want from the IntuiMessage====
  168. E7  movea.l   d0,a1
  169.     lea       20(a1),a0  ;get the address of the first field to copy.
  170.     move.l    (a0)+,d6   ;Copy the Class field to d6
  171.     move.w    (a0)+,d5   ;Copy the Code field to d5
  172.     move.w    (a0)+,d4   ;Copy the qualifier field to d4
  173.     movea.l   (a0)+,a2   ;Copy the IAddress field to a2
  174.     move.w    (a0)+,d3   ;Copy MouseX position to d3
  175.     move.w    (a0)+,d2   ;Copy MouseY position to d2
  176. ;====Now reply to the message so Intuition can dispose of it
  177. E8  ;Address of the message is in a1.
  178.     jsr       _LVOReplyMsg(a6)
  179. ;========switch (class)=========
  180.     Bclr.l    #9,d6  ;CLOSEWINDOW
  181.     bne.s     CW
  182.     Bclr.l    #3,d6  ;MOUSEBUTTONS
  183.     beq       E4
  184. ;---Make sure that it's an UP select if MOUSEBUTTONS
  185.     subi.b    #$68,d5
  186.     beq       E4     ;ignore down
  187. ;===The FOLLOWING ROUTINE IS OUR TEST CALL. WHEN THE USER IS DONE (in FileIO lib)
  188. ;===HE WILL SELECT EITHER THE CANCEL OR OK! GADGET. IF CANCEL, TestFileIO
  189. ;===DOES NOTHING. IF OK!, TestFileIO JUSTS PRINTS THE SELECTED STRING.
  190. E2  bsr     TestFileIO
  191.     bra     E4
  192. ;=========case CLOSEWINDOW:============
  193. CW  Bclr.b    #0,Quit
  194.     bra       E4
  195. ;======if an error, indicate NO_MEMORY. This is a FileIO routine
  196. ;======and is callable even if GetFileIO() fails
  197. IOe movea.l   a3,a0
  198.     moveq     #0,d0
  199.     movea.l   _RequesterBase,a6
  200.     jsr       _LVOAutoFileMessage(a6)
  201. ;========NOW BEGINS OUR EXIT ROUTINE=========
  202.  ;ReleaseFileIO will free our list of strings
  203. E15 movea.l   a4,a1                ;If the pointer to FileIO was NULL, then
  204.     movea.l   _RequesterBase,a6    ;ReleaseFileIO just returns, so it's safe to
  205.     jsr       _LVOReleaseFileIO(a6) ;always release any return value of GetFileIO.
  206. ;=====Close the Window and Screen======
  207. C1  movea.l   _IntuitionBase,a6
  208.     movea.l   a3,a0
  209.     jsr       _LVOCloseWindow(a6)
  210. C2  move.l    ScreenPtr,d0
  211.     beq.s     C3            ;check if we specified a screen
  212.     movea.l   d0,a0
  213.     ; _IntuitionBase in a6
  214.     jsr       _LVOCloseScreen(a6)
  215. ;=====Close Whichever Libs are Open (_SysBase in a6 for ALL calls)=====
  216. C3  movea.l  _SysBase,a6
  217.     movea.l  _RequesterBase,a1
  218.     jsr      _LVOCloseLibrary(a6)
  219. C5  movea.l  _GfxBase,a1
  220.     jsr      _LVOCloseLibrary(a6)
  221. C6  movea.l  _IntuitionBase,a1
  222.     jsr      _LVOCloseLibrary(a6)
  223. C7  movem.l  (sp)+,d2-d7/a2-a6
  224.     rts
  225.  
  226. ;*******************************************
  227. ; This just calls the DoFileIO library routine and displays a msg on return.
  228. ; (GetFileIO must have been called with success first).
  229. ; The DoFileIO routine returns -1 if the user selected CANCEL, -2 if the
  230. ; library is in use by another task, or returns non-zero if OK! was selected.
  231. ; At this point, if the user selected OK, our FILEIO_FILENAME buffer will
  232. ; contain the selected string and FILEIO_FILESIZE will be the ID.
  233. ;
  234. ;   TestFileIO(FileIO, window)
  235. ;                a4      a3
  236.  
  237. typename:
  238. ;--This shows what would happen (automatically) if the lib was in use on a
  239. ;  call to DoFileIO(), or the requester couldn't open.
  240.  
  241.    XDEF TestFileIO
  242. TestFileIO:
  243.     movea.l  _RequesterBase,a6
  244.  ;---DoFileIO(FileIO, window)
  245.     movea.l  a3,a1
  246.     movea.l  a4,a0
  247.     jsr      _LVODoFileIO(a6)
  248.     move.l   d0,d1
  249.     beq.s    .error 
  250.  ;must have been an error. If we were using DoFileIOWindow(), the window
  251.  ;might not have opened. For DoFileIO(), we shouldn't see a 0 return.
  252.  ;We could check the FileIO's ERRNO field to see what the specific error
  253.  ;was.
  254.     addq.l   #1,d1
  255.     beq.s    .can        ;If -1, user must have selected CANCEL
  256.     addq.l   #1,d1
  257.     beq.s    .error      ;If -2, the library was in use
  258.  ;---AutoMessage(string, window)  Display our chosen string.
  259.     ;Filename buffer address in d0
  260.     movea.l    a3,a0
  261.     jsr        _LVOAutoMessage(a6)
  262.  ;---If ID = -1 then user must have typed a string not in the list
  263.     move.l    FILEIO_FILESIZE(a4),d0  ;this is the ID of the chosen field
  264.     bpl.s        out1
  265.     movea.l    a3,a0
  266.     lea        NotIn,a1
  267.     move.l    a1,d0
  268.     jsr        _LVOAutoMessage(a6)
  269.     ;---Did our custom routine end the requester?
  270. out1:
  271.     moveq        #ERR_APPGADG,d0
  272.     sub.b        FILEIO_ERRNO(a4),d0
  273.     bne.s        out2
  274.     movea.l    a3,a0
  275.     lea        AppCan,a1
  276.     move.l    a1,d0
  277.     jsr        _LVOAutoMessage(a6)
  278. out2:
  279.     rts
  280. .error:
  281.     move.l    #errmsg,d0
  282. prt:
  283.     movea.l    a3,a0
  284.     jsr        _LVOAutoMessage(a6)
  285.     moveq        #0,d0
  286.     rts
  287. .can:
  288.     move.l    #cancel,d0
  289.     bra.s        prt
  290.  
  291. ;=====================================================================
  292. ; Our routine for the custom FileIO gadget. Lib passes our FileIO in a2
  293. ; and Window in a3. This returns the BOOL value from AutoPrompt3 so that
  294. ; if the user selects YES (TRUE) the requester ends.
  295.  
  296.    XDEF Information
  297. Information:
  298.     movem.l  a2/a3,-(sp)
  299.     movea.l  a3,a0
  300.     lea      Msg1,a1
  301.     lea      Msg2,a2
  302.     lea      Msg3,a3
  303.     movea.l  _RequesterBase,a6
  304.     jsr      _LVOAutoPrompt3(a6)
  305.     movem.l  (sp)+,a2/a3
  306.     rts
  307.  
  308.   ; SECTION MainData,DATA  ;Not needed for CAPE PC relative addressing!!
  309.  
  310.    XDEF _IntuitionBase,_GfxBase,ScreenPtr
  311.    XDEF _RequesterBase
  312.  ;must be in this order
  313. _IntuitionBase dc.l 0
  314. _GfxBase       dc.l 0
  315. _RequesterBase dc.l 0
  316. window         dc.l 0
  317. RastPort       dc.l 0
  318.  
  319.    XDEF   newScreen
  320. newScreen:
  321.    dc.w   0,0         ;LeftEdge, TopEdge
  322.    dc.w   640,400     ;Width, Height
  323.    dc.w   2           ;Depth
  324.    dc.b   0,1         ;Detail, Block pens
  325.    dc.w   -32764      ;ViewPort Modes HIRES|LACE (must set/clr HIRES as needed)
  326.    dc.w   15          ;CUSTOMSCREEN
  327.    dc.l   TextAttr    ;Font
  328.    dc.l   ScrTitle
  329.    dc.l   0           ;Gadgets
  330.    dc.l   0           ;CustomBitmap
  331.  
  332.    XDEF   newWindow
  333. newWindow:
  334.           dc.w   30,30
  335.           dc.w   306,145
  336.           dc.b   0,1
  337.  ;IDCMP = MOUSEBUTTONS|CLOSEWINDOW
  338.           dc.l   $208
  339.  ;WindowFlags = WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|ACTIVATE|WINDOWSIZE
  340.  ;(no FOLLOWMOUSE allowed as that messes up the requester when using
  341.  ;DoFileIO(). If you need FOLLOWMOUSE, then use DoFileIOWindow() to open
  342.  ;the req in its own window.)
  343.           dc.l   $100F
  344.           dc.l   0
  345.           dc.l   0
  346.           dc.l   WINTITLE
  347. ScreenPtr dc.l   0
  348.           dc.l   0
  349.           dc.w   306,145
  350.           dc.w   600,240
  351.           dc.w   1         ;WBENCHSCREEN
  352.  
  353. TextAttr:        ;Topaz 8 is a ROM font so doesn't need to be opened
  354.    dc.l   FONTNAME
  355.    dc.w   8      ;TOPAZ_EIGHTY
  356.    dc.b   0,0
  357.  
  358. StringAddr:
  359.    dc.l  Ten
  360.    dc.l  Nine
  361.    dc.l  Eight
  362.    dc.l  Seven
  363.    dc.l  Six
  364.    dc.l  Five
  365.    dc.l  Four
  366.    dc.l  Three
  367.    dc.l  Two
  368.    dc.l  One
  369.  
  370. Ten   dc.b 'Ten',0
  371. Nine  dc.b 'Nine',0
  372. Eight dc.b 'Eight',0
  373. Seven dc.b 'Seven',0
  374. Six   dc.b 'Six',0
  375. Five  dc.b 'Five',0
  376. Four  dc.b 'Four',0
  377. Three dc.b 'Three',0
  378. Two   dc.b 'Two',0
  379. One   dc.b 'And this is One',0
  380.  
  381. Quit dc.b 1  ;When this is a 0, the user wants to exit.
  382.  
  383. ScrTitle            dc.b 'Example FileIO Program Screen',0
  384. WINTITLE            dc.b 'Example FileIO Program Window',0
  385. Click                dc.b 'Click mouse for demo or CLOSEWINDOW.',0
  386. IntuitionName    dc.b 'intuition.library',0
  387. IconName            dc.b 'icon.library',0
  388. DOSName            dc.b 'dos.library',0
  389. GfxName            dc.b 'graphics.library',0
  390. RequesterName    dc.b 'requester.library',0
  391. FONTNAME            dc.b 'topaz.font',0
  392. errmsg            dc.b 'Error in accessing the requester',0
  393. cancel            dc.b 'The CANCEL gadget was selected.',0
  394. About                dc.b '   About',0
  395. Msg1                dc.b 'An example of SPECIAL_REQ',0
  396. Msg2                dc.b 'by Jeff Glatt',0
  397. Msg3                dc.b 'dissidents',0
  398. NotIn                dc.b 'This string is not in the list.',0
  399. AppCan            dc.b 'Cancelled by the custom gadget.',0
  400.  
  401.    END
  402.