home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 038.lha / ushow.asm < prev    next >
Assembly Source File  |  1987-05-16  |  14KB  |  431 lines

  1. ******************************************************************************
  2. *                                                                            *
  3. *  uShow.asm - The Mantis Really-Really-Small-Micro Show command (ver 1.1)   *
  4. *                                                                            *
  5. *  Programmed by Darrin Massena, Mantis Development.                         *
  6. *  No Rights Reserved - Hey everybody, it's FREE!                            *
  7. *                                                                            *
  8. *  To make uShow using the Aztec 'C' assembler:                              *
  9. *    1) as uShow.asm                                                         *
  10. *    2) ln -o uShow uShow.o -lc32                                            *
  11. *                                                                            *
  12. *  To make uShow using the MetaCompost assembler:                            *
  13. *    1) Rewrite first few lines to get a suitable index into the data hunk.  *
  14. *    2) Fix other odd incompatibilities.                                     *
  15. *    3) Wait forever for assembling.                                         *
  16. *    4) Wait forever to linking.                                             *
  17. *    5) Give up and go buy Aztec 'C'.                                        *
  18. *    6) Use instructions above.                                              *
  19. *                                                                            *
  20. *  WARNING!  This code has been HIGHLY optimized for size.  Beware of code   *
  21. *  that seems unnecessary or incorrect, as it is probably part of a nasty    *
  22. *  hack to save a few bytes somewhere.  Be especially delicate when altering *
  23. *  register usage.  Do not change the contents of ANY register without first *
  24. *  examining the repercussions of the change on the rest of the program.     *
  25. *  Tread lightly around the global vars and structures, almost all of them   *
  26. *  have more than one use.                                                   *
  27. *                                                                            *
  28. *  Revision history :                                                        *
  29. *  ------------------                                                        *
  30. *  04/25/87 (DWM)  Started writing uShow.                                    *
  31. *  04/26/87 (DWM)  Completed writing uShow.                                  *
  32. *  04/27/87 (DWM)  Fixed a couple of bugs.                                   *
  33. *  05/01/87 (DWM)  Fixed masked images bug.                                  *
  34. *                                                                            *
  35. ******************************************************************************
  36.  
  37.             include    "exec/types.i"
  38.             include    "intuition/intuition.i"
  39.             include    "libraries/dosextens.i"
  40.             include    "libraries/dos.i"
  41.  
  42. call        MACRO                        ;macro to call system routines
  43.             jsr    _LVO\1(a6)
  44.             ENDM
  45.  
  46. * ===========================================================================
  47. * IFF BitMap header structure (BMHD)
  48.     STRUCTURE BitMapHeader,0
  49.         UWORD bmhd_w
  50.         UWORD bmhd_h
  51.         WORD    bmhd_x
  52.         WORD    bmhd_y
  53.         UBYTE    bmhd_nPlanes
  54.         UBYTE    bmhd_masking
  55.         UBYTE    bmhd_compression
  56.         UBYTE    bmhd_pad1
  57.         UWORD    bmhd_transparentColor
  58.         UBYTE    bmhd_xAspect
  59.         UBYTE    bmhd_yAspect
  60.         WORD    bmhd_pageWidth
  61.         WORD    bmhd_pageHeight
  62.     LABEL    bmhd_SIZEOF
  63.  
  64. * ===========================================================================
  65.             DSEG
  66. SysBase    equ        4
  67.  
  68. bmhd        equ        -bmhd_SIZEOF
  69. cmap        equ        bmhd-(32*2)
  70.  
  71. * ===========================================================================
  72.             CSEG
  73. * Define these as public and they'll be pulled from C32.lib.
  74.             public    _LVOOpenLibrary,_LVOCloseLibrary,_LVOAllocMem,_LVOFreeMem
  75.             public    _LVOOpenWindow,_LVOCloseWindow,_LVOOpenScreen,_LVOCloseScreen
  76.             public    _LVOOpen,_LVORead,_LVOWrite,_LVOSeek,_LVOClose,_LVOLoadRGB4
  77.             public    _LVOWait
  78.  
  79. * ===========================================================================
  80.             public    uShow
  81. uShow
  82. *            movea.l    #dummyVar+32766,a4    ;special stuff to get my relative A4
  83.             dc.w        %0010100001111100
  84.             dc.l        dummyVar+32766
  85.  
  86.             link        a5,#cmap                    ;grab space on stack for cmap/bmhd
  87.             move.l    a0,a2                        ;save copy
  88.             subq.w    #1,d0                        ;dec to drop \n
  89.             move.w    d0,d2                        ;save copy
  90.             beq        Quit9                        ;no args, quit
  91.  
  92. * Initialize all necessary structures, open necessary libraries, etc.
  93. * If any initializations fail, we'll just abort
  94.             move.l    SysBase,a6
  95.             lea.l        szGfx,a1
  96.             moveq        #0,d0
  97.             call        OpenLibrary
  98.             move.l    d0,GfxBase
  99.  
  100.             lea.l        szDos,a1
  101.             moveq        #0,d0
  102.             call        OpenLibrary                ;open dos.library
  103.             move.l    d0,DosBase
  104.  
  105.             lea.l        szIntuition,a1
  106.             moveq        #0,d0
  107.             call        OpenLibrary                ;open intuition.library
  108.             move.l    d0,IBase
  109.  
  110. * The Manx Shell seems to add a space to the end of the cli args somehow...
  111.             move.b    -1(a2,d2.w),d0            ;get char before \n
  112.             cmp.b        #' ',d0                    ;is it a space?
  113.             bne        1$                            ; no, clear \n
  114.             subq.w    #1,d2                        ; yes, clear it
  115. 1$
  116.             clr.b        (a2,d2.w)                ;null terminate filename
  117.             move.l    a2,d1                        ;d1 = szFileName
  118.             move.l    #MODE_OLDFILE,d2        ;d2 = access mode
  119.             move.l    DosBase,a6
  120.             call        Open                        ;open picture file
  121.             tst.l        d0                            ;did it open?
  122.             beq        Quit                        ; no, forget about error msgs for now
  123.             move.l    d0,pfhPic                ;save ptr to file handle
  124.  
  125.             lea.l        chunkBuff,a0            ;a0 = ptr to read buffer
  126.             moveq        #12,d3                    ;d3 = # of bytes to read from file
  127.             jsr        Read                        ;read 'em in
  128.  
  129.             cmp.l        #'FORM',chunkType        ;is it an IFF FORM?
  130.             bne        Quit                        ; no, quit
  131.             cmp.l        #'ILBM',chunkSubType    ;is it an ILBM?
  132.             bne        Quit                        ; no, quit
  133.  
  134. ReadILBM                                            ;read in the ILBM
  135.             lea.l        chunkBuff,a0
  136.             moveq        #8,d3
  137.             jsr        Read                        ;read in a chunk (type/len pair)
  138.  
  139. CkBMHD
  140.             move.l    chunkType,d0            ; yes, get type
  141.             cmp.l        #'BMHD',d0                ;is it a BitMap header?
  142.             bne        CkCMAP                    ; no
  143.             lea.l        bmhd(a5),a0                ;a0 = ptr to read buffer
  144.             moveq        #bmhd_SIZEOF,d3        ;# of bytes to read
  145.             jsr        Read
  146.             bra        ReadILBM                    ;get next piece of data
  147. CkCMAP
  148.             cmp.l        #'CMAP',d0                ;is it a color map?
  149.             bne        CkCAMG                    ; no
  150.             move.l    chunkLen,d4                ;# of colors to read * 3
  151.             divu        #3,d4                        ;divide by 3 to get color count
  152.             move.w    d4,ccoMap                ;save count of colors in map
  153.             subq        #1,d4
  154.             lea.l        cmap(a5),a3                ;a3 = ptr to cmap buffer
  155.             moveq        #3,d3                        ;# of bytes to read
  156. 1$
  157.             lea.l        chunkLen+1,a0
  158.             jsr        Read
  159.             move.w    chunkLen,d1
  160.             lsl.w        #4,d1
  161.             or.b        chunkLen+2,d1
  162.             lsl.w        #4,d1
  163.             or.b        chunkLen+3,d1
  164.             lsr.w        #4,d1
  165.             move.w    d1,(a3)+
  166.             dbra        d4,1$
  167.  
  168.             addq.b    #1,fGotCMAP                ;set found CMAP flag
  169.             bra        ReadILBM                    ;get next piece of data
  170.  
  171. CkCAMG
  172.             cmp.l        #'CAMG',d0                ;how about special Amiga ViewModes?
  173.             bne        CkBODY                    ; no, check for body
  174.             lea.l        chunkSubType,a0        ;a0 = ptr to camg buffer
  175.             moveq        #4,d3                        ;# of bytes to read
  176.             jsr        Read
  177.             move.w    chunkSubType+2,ns_ViewModes+nscrPic
  178.             bra        ReadILBM                    ;get next piece of data
  179.  
  180. CkBODY
  181.             cmp.l        #'BODY',d0                ;is it the ILBM body?
  182.             beq        Continue                    ; yes, try to do something with it
  183. TossIt
  184.             move.l    pfhPic,d1                ;throw unusable data away by
  185.             move.l    chunkLen,d2                ; simply seeking past it.
  186.             moveq        #OFFSET_CURRENT,d3
  187.             move.l    DosBase,a6
  188.             call        Seek
  189.             bra        ReadILBM
  190.  
  191. * If we've gotten here, we have a BMHD and we're prepared to read the BODY
  192. Continue
  193.             move.l    chunkLen,d7                ;save length of body
  194.             lea.l        bmhd(a5),a3                ;use values from BMHD to initialize
  195.             lea.l        nscrPic,a0                ; our new screen structure
  196.             move.w    bmhd_w(a3),ns_Width(a0)
  197.             move.w    bmhd_h(a3),ns_Height(a0)
  198.             move.b    bmhd_nPlanes(a3),ns_Depth+1(a0)
  199.  
  200.             cmp.w        #500,bmhd_w(a3)
  201.             ble        11$
  202.             or.w        #V_HIRES,ns_ViewModes(a0)
  203. 11$
  204.             cmp.w        #300,bmhd_h(a3)
  205.             ble        12$
  206.             or.w        #V_LACE,ns_ViewModes(a0)
  207. 12$
  208.             move.b    bmhd_compression(a3),d3
  209.             cmp.b        #2,d3                        ;do I know this kind of compression?
  210.             bge        Quit                        ; no, give up
  211.  
  212. * Open screen to display the picture on.
  213.             move.l    IBase,a6
  214.             call        OpenScreen
  215.             tst.l        d0
  216.             beq        Quit                        ;error while opening, abort
  217.             move.l    d0,pscrPic                ;save pointer to my picture screen
  218.  
  219. * Open a backdrop window so we can use its message port for communication.
  220.             lea.l        nwinPic,a0
  221.             move.l    d0,nw_Screen(a0)        ;point new window to this screen
  222.             call        OpenWindow
  223.             tst.l        d0                            ;everything opened ok?
  224.             beq        Quit                        ; no, quit
  225.             move.l    d0,pwinPic                ; yes, save window pointer
  226.  
  227.             tst.b        fGotCMAP                    ;did we get a colormap?
  228.             beq        1$                            ; no
  229.             move.l    pscrPic,a0                ; yes, let's jam those colors in ther
  230.             lea.l        sc_ViewPort(a0),a0
  231.             lea.l        cmap(a5),a1
  232.             move.w    ccoMap,d0
  233.             move.l    GfxBase,a6
  234.             call        LoadRGB4
  235. 1$
  236.             move.l    d7,d0
  237.             moveq        #0,d1
  238.             move.l    SysBase,a6
  239.             call        AllocMem
  240.             tst.l        d0
  241.             beq        Quit                        ;couldn't get buffer memory
  242.             move.l    d0,prgbPicBuff            ;save pointer to picture buffer
  243.             move.l    d0,a0
  244.             move.l    d7,d3
  245.             jsr        Read                        ;read the rest of the body into buffer
  246.  
  247. Decomp
  248.             move.l    pscrPic,a2
  249.             lea.l        sc_BitMap+bm_Planes(a2),a6    ;a6 = ptr to screen's 1st plane
  250.  
  251.             cmp.b        #1,bmhd_masking(a3)    ;does this image have a mask?
  252.             bne        10$                        ; no
  253.             moveq        #0,d0                        ; yes
  254.             move.b    bmhd_nPlanes(a3),d0    ;get planes count
  255.             lsl.w        #2,d0                        ;convert to planeptr array index
  256.             move.l    #$FE0000,(a6,d0.w)    ;set mask planeptr = ROMs (hehheh)
  257.             addq.b    #1,bmhd_nPlanes(a3)    ;increment planes count
  258. 10$
  259.  
  260.             lea.l        sc_BitMap+bm_BytesPerRow(a2),a2
  261.             move.w    (a2),d6                    ;d6 = bytes per row
  262.             move.l    prgbPicBuff,a0            ;a0 = ptr to body data buffer
  263.             move.w    bmhd_h(a3),d4            ;d4 = # of rows in image
  264.             subq.w    #1,d4
  265.             moveq        #0,d3                        ;d3 = offset within plane
  266. 1$
  267.             moveq        #0,d5
  268.             move.b    bmhd_nPlanes(a3),d5    ;d5 = # of planes in image
  269.             move.l    a6,a2                        ;reset plane array pointer
  270. 2$
  271.             dbra        d5,3$                        ;loop through each plane
  272.             add.w        d6,d3                        ;move offset down one line
  273.             dbra        d4,1$                        ;loop through all lines
  274.             bra        ShowDone
  275. 3$
  276.             move.l    (a2)+,a1
  277.             add.w        d3,a1
  278. 35$
  279.             move.w    d6,d2                        ;d2 = bytes per row
  280.             tst.b        bmhd_compression(a3)    ;data compressed?
  281.             bne        50$                        ; yes
  282.             subq        #1,d2                        ; no, setup copy loop
  283. 4$
  284.             move.b    (a0)+,(a1)+                ;move each byte
  285.             dbra        d2,4$                        ;loop for entire row
  286.             bra        2$                            ;this row done, next?
  287. 50$
  288.             tst.w        d2                            ;is this line done?
  289.             beq        2$                            ; yes, setup for next
  290.             moveq        #0,d1
  291. 51$
  292.             move.b    (a0)+,d1                    ;get token from source
  293.             bmi        53$                        ; handle repeat-run
  294.  
  295.             sub.w        d1,d2                        ;sub from bytes per row
  296.             subq.w    #1,d2                        ; and one more
  297. 52$
  298.             move.b    (a0)+,(a1)+
  299.             dbra        d1,52$
  300.             bra        50$
  301. 53$
  302.             cmp.b        #128,d1                    ;NULL? Is anyone that stupid?
  303.             beq        50$                        ; yes, someone is...
  304.             neg.b        d1
  305.             sub.w        d1,d2                        ;sub from bytes per row
  306.             subq.w    #1,d2                        ; and one more
  307.             move.b    (a0)+,d0
  308. 54$
  309.             move.b    d0,(a1)+
  310.             dbra        d1,54$
  311.             bra        50$
  312.  
  313. ShowDone
  314.             move.l    d7,d0
  315.             move.l    prgbPicBuff,a1
  316.             move.l    SysBase,a6
  317.             call        FreeMem                    ;free our load buffer
  318.  
  319.             move.l    pwinPic,a0
  320.             move.l    wd_UserPort(a0),a0
  321.             moveq        #0,d1
  322.             move.b    MP_SIGBIT(a0),d1
  323.             moveq        #1,d0
  324.             lsl.l        d1,d0
  325.             call        Wait
  326.             
  327. * It's time to quit, close everything and say good-night.
  328. Quit
  329.             move.l    IBase,a6                    ;get intuition base
  330.             move.l    pwinPic,d0                ;is our window open?
  331.             beq        1$                            ; no
  332.             move.l    d0,a0                        ; yes, close it
  333.             call        CloseWindow
  334. 1$
  335.             move.l    pscrPic,d0                ;is our screen open?
  336.             beq        2$                            ; no
  337.             move.l    d0,a0                        ; yes, close it
  338.             call        CloseScreen
  339. 2$
  340.             move.l    pfhPic,d1                ;is the pic file still open?
  341.             beq        3$                            ; no, it's closed
  342.             move.l    DosBase,a6
  343.             call        Close                        ;close that puppy
  344. 3$
  345.             move.l    GfxBase,a1                ;close the graphics.library
  346.             move.l    SysBase,a6
  347.             call        CloseLibrary
  348.  
  349.             move.l    IBase,a1                    ;close the intuition.library
  350.             call        CloseLibrary
  351.  
  352.             move.l    DosBase,a1                ;close the dos.library
  353.             call        CloseLibrary
  354. Quit9
  355.             unlk        a5
  356.             rts
  357.  
  358. * ===========================================================================
  359. * d0.l: len = Read(a0: prgbBuff, d3.l: len) 
  360. Read
  361.             move.l    pfhPic,d1                ;a nasty assumption, but saves space
  362.             move.l    a0,d2                        ;move buff ptr to d2
  363.             move.l    DosBase,a6
  364.             call        Read                        ;read the data in
  365.             cmp.l        d0,d3                        ;did we get it all
  366.             bne        Quit                        ; no, quit
  367.             rts                                    ; yes, just return
  368.  
  369. * ===========================================================================
  370.                 DSEG
  371. * These vars are derived using the Mantis naming conventions.  A brief summary
  372. * follows:
  373. *
  374. * p - indicates a pointer
  375. * n - 'new' structure
  376. * win,scr,fh - abbreviations for window, screen and filehandle structures
  377. * co - color 0x0RGB data type
  378. * sz - null terminated string
  379. * rg - range of values (array)
  380. * b,w,l - byte, word, long data types
  381. *
  382. * Quiz: What does prgpfhOpen stand for?
  383. * .selif nepO fo sretnioP eldnaHeliF fo eGnaR a ot retnioP a :resnA
  384.  
  385. dummyVar                                    ;dummy, used to create my A4
  386. * The following group of vars was created by a trained professional.
  387. *                     DO NOT try this at home.
  388.  
  389. szMe            dc.b    "   ",181
  390.                 dc.b    "Show ",169
  391.                 dc.b    " 1987 Darrin Massena"
  392.  
  393.                 even
  394. nscrPic
  395.                 dc.w    0,0,640,400,2
  396.                 dc.b    0,1
  397.                 dc.w    0                    ;ViewModes
  398.                 dc.w    CUSTOMSCREEN
  399. pscrPic
  400.                 dc.l    0,szMe            ;WARNING! nwinPic structure MUST follow
  401. nwinPic
  402.                 dc.w    0,0,24,10
  403.                 dc.b    0,1
  404.                 dc.l    CLOSEWINDOW|RAWKEY|MENUPICK
  405.                 dc.l    SIMPLE_REFRESH|BORDERLESS|ACTIVATE|WINDOWCLOSE
  406. pwinPic
  407.                 dc.l    0,0,0,0,0
  408. pfhPic        dc.l    0                    ;ptr to picture file handle
  409.                 dc.l    0
  410.                 dc.w    CUSTOMSCREEN
  411.  
  412. ccoMap
  413. szDos            dc.b    "dos.library",0
  414.                 even
  415. chunkBuff
  416. szIntuition
  417. chunkType    dc.l    'intu'                        ;IFF chunk info read here
  418. chunkLen        dc.l    'itio'
  419. chunkSubType dc.l    'n.li'
  420. prgbPicBuff    dc.l    'brar'
  421. fGotCMAP        dc.b    'y',0
  422. szGfx
  423. GfxBase        dc.l    'grap'
  424. IBase            dc.l    'hics'
  425. DosBase        dc.l    '.lib'
  426.                 dc.b    "rary",0
  427.  
  428. * ===========================================================================
  429.                 END
  430.  
  431.