home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 245.lha / UShow_v2.0 / ushow2.asm < prev    next >
Assembly Source File  |  1989-04-09  |  12KB  |  423 lines

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