home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 446.lha / PrintSpool_library / Asm_Example / PrintPic.asm < prev    next >
Assembly Source File  |  1990-12-06  |  9KB  |  335 lines

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