home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk463.lzh / ILBM / ilbm.lzh / ASM / ShowPic.asm < prev   
Assembly Source File  |  1991-02-15  |  7KB  |  276 lines

  1. ;Set your editor's TAB width to 3 chars.
  2.  
  3. ;*************************************************************************
  4. ;ShowPic.asm
  5. ;    Reads an ILBM file and displays it as a screen/window until the right
  6. ;    mouse button is clicked. This program is similiar to Scheppner's Display
  7. ;    program in that it handles normal and HAM ILBM's.
  8. ;
  9. ;    This program is different than Display in the following ways:
  10. ;    1). It is written in assembly code.
  11. ;    2). It utilizes the dissidents IFF ILBM library which can be opened and
  12. ;            used by many different tasks.
  13. ;    3). It utilizes the dissidents requester library for filename selection.
  14. ;
  15. ;This source code was assembled using INNOVATRONICS CAPE assembler. It was
  16. ;linked using Blink as follows:
  17. ;
  18. ;    Blink StartUp.o ShowPic.o small.lib NODEBUG to ShowPic
  19. ;
  20. ;    small.lib is from CATS, or Fish Disk #92.
  21. ;    StartUp.o is my own version of a standard, startup code.
  22. ;
  23. ; If using an asm other than CAPE, delete the next 4 lines and also uncomment
  24. ; the section directive toward the end.
  25.  
  26.     SMALLOBJ    ;CAPE directive for PC-relative addressing replaces absolute
  27.     ADDSYM
  28.     OPTIMON
  29.     OBJFILE    "rad:ShowPic.o"
  30.  
  31.    SECTION ShowPicCode,CODE
  32.  
  33.     INCLUDE    "IFF.i"        ;the asm include file for ilbm.library
  34.     INCLUDE    "FileIO.i"    ;the asm include file for requester.library
  35.  
  36.     ;from StartUp.o
  37.     XREF    _SysBase,_DOSBase,_stdout,_BUFFER
  38.  
  39.     ;from small.lib
  40.     XREF    _LVOCloseScreen,_LVOCloseWindow
  41.     XREF    _LVODelay
  42.     XREF    _LVOWait,_LVOWaitPort,_LVOGetMsg,_LVOPutMsg,_LVOReplyMsg,_LVOSignal
  43.     XREF    _LVOOpenLibrary,_LVOCloseLibrary
  44.     XREF    _LVODisplayAlert,_LVOWrite,_LVOInput,_LVOOutput,_LVOCurrentDir
  45.     XREF    _LVOAllocMem,_LVOFreeMem
  46.     XREF    _LVOFindTask
  47.  
  48. LIB_VERSION    equ    33
  49.  
  50. out    rts
  51.  
  52.    XDEF  _main
  53. _main:
  54.         movea.l    _SysBase,a6
  55.         moveq        #LIB_VERSION,d0
  56.         lea        IntuiName,a1
  57.         jsr        _LVOOpenLibrary(a6)
  58.         move.l    d0,_IntuitionBase
  59.         beq        out
  60. ;======Open dissidents Requester lib========
  61.         moveq        #0,d0                    ;any version (for now)
  62.         lea        RequesterName,a1
  63.         jsr        _LVOOpenLibrary(a6)
  64.         move.l    d0,d1
  65.         beq.s        REQe
  66.         move.l    d0,_RequesterBase
  67. ;======Open dissidents ILBM library===========
  68.         moveq        #0,d0                    ;any version (for now)
  69.         lea        ILBMName,a1
  70.         jsr        _LVOOpenLibrary(a6)
  71.         move.l    d0,d1
  72.         beq.s        IFFe
  73.         move.l    d0,_ILBMBase      
  74. ;================Do our Display Pic routine=================
  75.         bsr        MAIN2
  76.    ;---Free the FileIO if allocated (FileIO lib checks for 0)
  77.         movea.l    a5,a1
  78.         movea.l    _RequesterBase,a6
  79.         jsr        _LVOReleaseFileIO(a6)
  80.     ;---Close requester, ilbm libs
  81.         movea.l    _SysBase,a6
  82.         movea.l    _RequesterBase,a1
  83.         jsr        _LVOCloseLibrary(a6)
  84.         movea.l    _ILBMBase,a1
  85.         jsr        _LVOCloseLibrary(a6)
  86. cIntu movea.l    _IntuitionBase,a1
  87.         jmp        _LVOCloseLibrary(a6)        ;exit program, return to AmigaDOS
  88. ;==========Display An Alert Error Msg=========
  89.     ;---No ILBM lib
  90. IFFe    movea.l    _RequesterBase,a1
  91.         jsr        _LVOCloseLibrary(a6)
  92.         lea        IFFErrMsg,a1
  93.         bra.s        post
  94.     ;---No Requester lib
  95. REQe    lea        ReqErrMsg,a1
  96. post    bsr        dsp_alert
  97.         bra.s        cIntu
  98.  
  99.     XDEF    dsp_alert
  100. ;This makes an alert message out of the passed string in a1
  101. ;and displays it as an alert or CLI msg. 79 chars MAX in passed string.
  102. dsp_alert:
  103.         lea        _BUFFER+2,a0    ;for WB, skip first WORD of _BUFFER for X pos
  104.         moveq        #20,d0
  105.         move.b    d0,(a0)+            ;y co-ordinate = 20
  106.         move.l    a0,d2
  107.     ;---copy passed string to BUFFER and get numOfChars
  108.         movea.l    a1,a6
  109. lenS    move.b    (a6)+,(a0)+
  110.         bne.s        lenS
  111.         subq.l    #1,a6
  112.         suba.l    a1,a6            ;numOfChars
  113.     ;---If the CLI, write the msg there
  114.         move.l    _stdout,d1
  115.         beq.s        WBalert
  116.         move.l    a6,d3
  117.     ;---add new line char
  118.         addq.l    #1,d3
  119.         clr.b        (a0)
  120.         moveq        #10,d0
  121.         move.b    d0,-(a0)
  122.         movea.l    _DOSBase,a6
  123.         jmp        _LVOWrite(a6)
  124.     ;---If WB, post an alert
  125. WBalert:
  126.         clr.b        (a0)            ;continuation byte = 0
  127.         moveq        #80-1,d1        ;80 chars - 1 Dbra
  128.         sub.l        a6,d1
  129.         bcc.s        aler
  130.         moveq        #1,d1
  131. aler    lsr.l        #1,d1
  132.         lsl.w        #3,d1            ;assume Topaz 8 system font
  133.         movea.l    d2,a0
  134.         subq.l    #3,a0
  135.         move.w    d1,(a0)        ;x co-ordinate = (numOfChars/2) * 8 (WORD)
  136.     ;---display the alert
  137.         moveq        #50,d1        ;Height
  138.         moveq        #0,d0            ;RECOVERY_ALERT
  139.         movea.l    _IntuitionBase,a6
  140.         jmp        _LVODisplayAlert(a6)
  141.  
  142. MAIN2:
  143. ;===========Get a FileIO structure for the FileIO lib==========
  144.         movea.l    _RequesterBase,a6
  145.         jsr        _LVOGetFileIO(a6)
  146.         movea.l    d0,a5
  147.         move.l    d0,d1
  148.         bne.s        gFIO
  149.         rts
  150.     ;---Setup the FileIO fields
  151.         ;---X pos = 6
  152. gFIO    moveq        #6,d1
  153.         move.w    d1,FILEIO_X(a5)
  154.         ;---Y pos = 11
  155.         moveq        #11,d1
  156.         move.w    d1,FILEIO_Y(a5)
  157.         ;---DrawMode = JAM2
  158.         moveq        #1,d1
  159.         move.b    d1,FILEIO_DRAWMODE(a5)
  160.         ;---PenA = 0
  161.         clr.b        FILEIO_PENA(a5)
  162.         ;---PenB = 1
  163.         move.b    d1,FILEIO_PENB(a5)
  164.         ;---The pathname buffer
  165.         lea        _BUFFER,a0
  166.         move.l    a0,FILEIO_BUFFER(a5)
  167. ;========Get the address of our ILBMFrame==============
  168.         lea        ILBMFrame,a2
  169. ;========Set pointers initially to 0====================
  170. next    suba.l    a3,a3        ;screen = 0
  171.         suba.l    a4,a4        ;window = 0
  172. ;=======Get the filename to display===========
  173.         movea.l    a5,a0                    ;the FileIO
  174.         suba.l    a1,a1                    ;open requester on WB screen
  175.         movea.l    _RequesterBase,a6
  176.         jsr        _LVODoFileIOWindow(a6)
  177.         move.l   d0,d1            ;pathname buffer address
  178.         beq        close_up        ;an error in opening the window. Exit
  179.         addq.l    #1,d0
  180.         beq        close_up        ;If -1, user must have selected CANCEL. Exit
  181. ;======Load the IFF pic (whose Filename is argv[1]) into the window========
  182.         movea.l    a2,a1
  183.         ;pathname in d1
  184.         clr.l        iWindow(a1)                ;indicate no open window
  185.         clr.l        iScreen(a1)                ;no open screen
  186.         moveq        #$13,d0                    ;blank pointer, no title bar, adjust view
  187.         move.b    d0,iUserFlags(a1)
  188.         movea.l    _ILBMBase,a6
  189.         jsr        _LVOLoadIFFToWindow(a6)
  190.     ;---get opened screen and window addresses
  191.         movea.l    iWindow(a2),a4
  192.         movea.l    iScreen(a2),a3
  193.     ;---check for error (not IFF_OKAY)
  194.         move.b    d0,d1
  195.         beq.s        dspp
  196.     ;---ERROR: "Load error"
  197.         lea        BadLoad,a1
  198.         move.l    a4,d0
  199.         beq.s        post_msg
  200.         movea.l    d0,a0
  201.         move.l    a1,d0
  202.         movea.l    _RequesterBase,a6
  203.         jsr        _LVOAutoMessage(a6)
  204.         bra.s        nextp
  205. post_msg:
  206.         bsr        dsp_alert
  207.         bra.s        nextp
  208. ;========Display picture until the user clicks the mouse=======
  209. dspp    movea.l    _SysBase,a6
  210. mmsg    movea.l    86(a4),a0
  211.         jsr        _LVOGetMsg(a6)
  212.         move.l    d0,d1
  213.         bne.s        wmsg
  214.         movea.l    86(a4),a0
  215.         jsr        _LVOWaitPort(a6)
  216.         bra.s        mmsg
  217. wmsg    movea.l    d0,a1
  218.         move.l    20(a1),-(sp)     ;save CLASS
  219.         jsr        _LVOReplyMsg(a6)
  220.         move.l    (sp)+,d0
  221.         Btst.l    #3,d0
  222.         beq.s        mmsg
  223.     ;---Close window, screen, and then get next picture
  224. nextp    bsr.s        close_up
  225.         bra        next
  226.  
  227.     XDEF close_up
  228. close_up:
  229. ;================drain the IDCMP of the window and close it===============
  230.         move.l    a4,d0
  231.         beq.s        nowind
  232.         movea.l    _SysBase,a6
  233. MMSG    move.l    86(a4),a0
  234.         jsr        _LVOGetMsg(a6)
  235.         move.l    d0,d1
  236.         beq.s        nMSG
  237.         movea.l    d1,a1
  238.         jsr        _LVOReplyMsg(a6)
  239.         bra.s        MMSG
  240. nMSG    movea.l    _IntuitionBase,a6
  241.         movea.l    a4,a0
  242.         jsr        _LVOCloseWindow(a6)
  243. ;=============Close the Screen=====================
  244. nowind:
  245.         move.l    a3,d0
  246.         beq.s        noscr
  247.         movea.l    d0,a0
  248.         movea.l    _IntuitionBase,a6
  249.         jsr        _LVOCloseScreen(a6)
  250. noscr    rts
  251.  
  252. ;    SECTION view,DATA        ;If not using CAPE, uncomment this line
  253.  
  254.  ;******************* DATA ***********************
  255.   XDEF  _IntuitionBase
  256. _IntuitionBase    dc.l 0    ; intuition lib pointer
  257.  
  258.     XDEF    _RequesterBase,_ILBMBase
  259. _RequesterBase    dc.l 0
  260. _ILBMBase        dc.l 0
  261.  
  262.     XDEF    ILBMFrame
  263.     CNOP 0,2    ;word-align
  264. ILBMFrame        ds.b    sizeofILBMFrame
  265.  
  266. BadLoad            dc.b    'Load Error',0
  267.  
  268. IFFErrMsg        dc.b 'Need the dissidents '
  269. ILBMName            dc.b 'ilbm.library',0
  270. ReqErrMsg        dc.b 'Need the dissidents '
  271. RequesterName    dc.b 'requester.library',0
  272. INUSE                dc.b 'requester.library already in use',0
  273. IntuiName        dc.b 'intuition.library',0
  274.  
  275.     END
  276.