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