home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 070.lha / ud.asm < prev    next >
Assembly Source File  |  1986-11-20  |  7KB  |  177 lines

  1. ******************************************************************************
  2. *                                                                            *
  3. *  UD.asm - UpsideDown - A fun (and educational too!) Schwabie               *
  4. *                                                                            *
  5. *  Programmed by Darrin Massena, Mantis Development.                         *
  6. *  No Rights Reserved - Hey everybody, it's FREE!                            *
  7. *                                                                            *
  8. *  To make UD using the Aztec 'C' assembler:                                 *
  9. *    1) as UD.asm                                                            *
  10. *    2) ln -o UD UD.o -lc32                                                  *
  11. *                                                                            *
  12. *  To make UD 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 for linking.                                            *
  17. *    5) Wonder why it doesn't run correctly.                                 *
  18. *    6) Give up and go buy Aztec 'C'.                                        *
  19. *    7) Use the Aztec instructions above.                                    *
  20. *                                                                            *
  21. *  WARNING!  Playing around with the copper-list like this is very much dis- *
  22. *  couraged for SERIOUS programs, but hey, why :-| when you can :-) ?        *
  23. *                                                                            *
  24. *  Revision history :                                                        *
  25. *  ------------------                                                        *
  26. *  06/20/87 (DWM) Just having some innocent fun.                             *
  27. *  06/21/87 (DWM) Aggg!  It's out of control!  RUN, RUN!                     *
  28. *                                                                            *
  29. ******************************************************************************
  30.  
  31.             include    "exec/types.i"
  32.             include    "graphics/gfx.i"
  33.             include    "graphics/gfxbase.i"
  34.             include    "graphics/view.i"
  35.             include    "graphics/copper.i"
  36.  
  37.             DSEG
  38. SysBase    equ        4
  39.  
  40. * ===========================================================================
  41.             CSEG
  42. * Define these as public and they'll be pulled in from C32.lib.
  43.             public    _LVOOpenLibrary,_LVOCloseLibrary
  44.             public    _LVOOutput,_LVOWrite
  45.  
  46. call        MACRO                                    ;macro to call system routines
  47.             jsr    _LVO\1(a6)
  48.             ENDM
  49.  
  50. * ===========================================================================
  51.             public    UD
  52. UD
  53. * Does anyone know a 'cleaner' way to set the initial A4 data pointer?
  54. *            movea.l    #dummyVar+32766,a4    ;special stuff to get my relative A4
  55.             dc.w        %0010100001111100        ; <-- doing it the hard way
  56.             dc.l        dummyVar+32766
  57.  
  58. * If any initializations fail, we'll just abort (cleanly, of course.)
  59.             lea.l        szDOS,a1
  60.             moveq        #0,d0
  61.             move.l    SysBase,a6
  62.             call        OpenLibrary                ;open dos.library
  63.             move.l    d0,_DOSBase
  64.             beq        Quit                        ;failed!
  65.  
  66.             move.l    d0,a6
  67.             call        Output                    ;get output filehandle
  68.             move.l    d0,d1                        ;d1 = out fh
  69.             lea.l        szCredit,a0
  70.             move.l    a0,d2                        ;d2 = szCredit
  71.             moveq        #-1,d3
  72. 99$        addq.l    #1,d3                        ;loop, counting sz len
  73.             tst.b        (a0)+
  74.             bne        99$
  75.             call        Write                        ;take the blame
  76.  
  77.             lea.l        szGfx,a1
  78.             moveq        #0,d0
  79.             move.l    SysBase,a6
  80.             call        OpenLibrary                ;open graphics.library
  81.             move.l    d0,_GfxBase
  82.             beq        Quit                        ;failed? How?
  83.  
  84. * Will the REAL copper-list please stand up?
  85.             move.l    d0,a0                        ;a0 = _GfxBase
  86.             move.l    gb_ActiView(a0),a0    ;a0 = _GfxBase->ActiView
  87.             move.l    v_ViewPort(a0),a1        ;save ptr to first ViewPort
  88.             move.l    v_LOFCprList(a0),a0    ;a0 = _GfxBase->ActiView->LOFCprList
  89.             move.l    crl_start(a0),a0        ;a0 = ptr to actual copper list in use
  90.  
  91. * We now have _GfxBase->ActiView->LOFCprList->start (whew!)
  92.  
  93. * Get a pointer to the first BitMap in the view
  94.             move.l    vp_RasInfo(a1),a1
  95.             move.l    ri_BitMap(a1),a1        ;a1 = first BitMap
  96.             move.w    bm_BytesPerRow(a1),d1    ;d1 = # of bytes across screen's bm
  97.             move.w    bm_Rows(a1),d2            ;d2 = # of rows in screen's BitMap
  98.  
  99. * Scan through the copper-list until we find the first BPLMOD initialization.
  100. 1$            move.l    (a0)+,d0
  101.             swap        d0
  102.             cmp.w        #$0108,d0                ;move to BPLMOD1?
  103.             bne        1$                            ; no, loop until we found it
  104.  
  105. * Change modulos to step BACK a couple of scanlines instead of forward.
  106.             move.w    d1,d0                        ;# of bytes for one line across screen
  107.             add.w        d0,d0                        ; * 2 (have to skip back 2 lines -
  108.             neg.w        d0                            ; think about it)
  109.             move.w    d0,-2(a0)                ;set BPLMOD1 back up 2 lines
  110.             move.w    d0,2(a0)                    ;set BPLMOD2 back up 2 lines
  111.  
  112.             subq.w    #1,d2                        ;bottom line = BytesPerRow * (Rows - 1)
  113.             mulu        d1,d2                        ;d2 = bottom line
  114.  
  115. * Since we're going backwards, we have to start at the bottom of each bit-
  116. * plane instead of at the top.
  117.             move.w    6(a0),d0                    ;first plane hi addr
  118.             swap        d0
  119.             move.w    10(a0),d0                ;first plane lo addr
  120.             add.l        d2,d0                        ;drop to bottom line
  121.             move.w    d0,10(a0)                ;put back hi
  122.             swap        d0
  123.             move.w    d0,6(a0)                    ;put back lo
  124.  
  125.             move.w    14(a0),d0                ;second plane hi addr
  126.             swap        d0
  127.             move.w    18(a0),d0                ;second plane lo addr
  128.             add.l        d2,d0                        ;drop to bottom line
  129.             move.w    d0,18(a0)                ;put back hi
  130.             swap        d0
  131.             move.w    d0,14(a0)                ;put back lo
  132.  
  133. * It's time to quit, close up shop and say good-night.
  134. Quit
  135.             move.l    SysBase,a6
  136.             move.l    _DOSBase,d0                ;close the dos.library if open
  137.             beq        1$
  138.             move.l    d0,a1
  139.             call        CloseLibrary
  140. 1$
  141.             move.l    _GfxBase,d0                ;close the graphics.library if open
  142.             beq        2$                            ; oops, not open
  143.             move.l    d0,a1
  144.             call        CloseLibrary
  145. 2$
  146.             rts                                    ;bye!
  147.  
  148. * ===========================================================================
  149.                 DSEG
  150. *  These vars are derived using the Mantis naming conventions.  A brief
  151. *  summary follows:
  152. *
  153. *  p - indicates a pointer
  154. *  n - 'new' structure
  155. *  win,scr,fh - abbreviations for window, screen and filehandle structures
  156. *  co - color 0x0RGB data type
  157. *  sz - null terminated string type
  158. *  rg - range of values (array)
  159. *  b,w,l - byte, word, long data types
  160. *
  161. *  Quiz:  What does prgpfhOpen stand for?
  162. *  .selif nepO fo sretnioP eldnaHeliF fo eGnaR a ot retnioP a :rewsnA
  163.  
  164. dummyVar                                            ;dummy, used to create my A4
  165. szGfx            dc.b    "graphics.library",0
  166. szDOS            dc.b    "dos.library",0
  167. szCredit        dc.b    "UD - UpsideDown",$a1
  168.                 dc.b    " - by Darrin Massena, Mantis Development",$0a
  169.                 dc.b    "Press Left-Amiga-N or drag any screen to return to normal.",$0a,0
  170.  
  171.                 even
  172. _GfxBase        dc.l    0
  173. _DOSBase        dc.l    0
  174.  
  175. * ===========================================================================
  176.                 END
  177.