home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / proasm / routines / progressbars.r < prev    next >
Text File  |  1995-04-19  |  5KB  |  264 lines

  1.  
  2. ;---;  ProgressBars.r  ;-------------------------------------------------------
  3. *
  4. *    ****    GTFACE ADDENDUM FOR PROGRESSBARS    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        1.00
  8. *    Last Revision    19.04.95
  9. *    Identifier    pgb_defined
  10. *       Prefix        pbg_    (Progressbars)
  11. *                 ¯  ¯    ¯
  12. *    Functions    InitProgressBar, ClearProgressBar,
  13. *            UpdateProgressBar, SetProgressBar,
  14. *
  15. *            NEED_ pgb_fakedbitmap:    for a custom bitmap (only
  16. *                        1 plane will be inverted).
  17. *
  18. *
  19. *    Requirements    - graphics.library needed (in GfxBase(pc))
  20. *            - library function offsets for graphics.library included
  21. *              (e.g. lvo.s)
  22. *
  23. ;------------------------------------------------------------------------------
  24.  
  25.     IFND    pgb_defined
  26. pgb_defined    SET    1
  27.  
  28. ;------------------
  29. pgb_oldbase    EQU __BASE
  30.     base    pgb_base
  31. pgb_base:
  32.  
  33. ;------------------
  34.     opt    sto,o+,ow-,q+,qw-        ;all optimisations on
  35.  
  36. *    incdir    'include:'
  37.  
  38.     include    'basicmac.r'
  39. ;    include    'graphics/gfx.i'
  40.     include    'graphics/rastport.i'
  41.  
  42.  
  43. ;------------------------------------------------------------------------------
  44. *
  45. * needed macros and structure definitions
  46. *
  47. ;------------------------------------------------------------------------------
  48.         RSRESET
  49. pgb_x        RS.W    1    ; PRIVAT
  50. pgb_y        RS.W    1    ; PRIVAT
  51. pgb_width    RS.W    1    ; PRIVAT
  52. pgb_height    RS.W    1    ; PRIVAT
  53. pgb_last    RS.W    1    ; PRIVAT
  54. pgb_window    RS.L    1    ; pointer to window structure
  55. pgb_value    RS.L    1    ; current value
  56. pgb_max        RS.L    1    ; maximum value for pgp_value
  57. pgb_SIZEOF    RSVAL
  58.  
  59.  
  60. ;
  61. ; ProgressStruct_  basename[,maxvalue[,currentvalue]]
  62. ;
  63. ; NOTE: the window pointer must be set manually
  64. ;
  65. ProgressStruct_    MACRO
  66.         dc.w    \1_x
  67.         dc.w    \1_y
  68.         dc.w    \1_width
  69.         dc.w    \1_height
  70.         dc.w    0
  71.         dc.l    0        ; window
  72.  
  73.         IFNC    '\3',''
  74.         dc.l    \3
  75.         ELSE
  76.         dc.l    0
  77.         ENDC
  78.         IFNC    '\2',''
  79.         dc.l    \2
  80.         ELSE
  81.         dc.l    0
  82.         ENDC
  83.         ENDM
  84.  
  85.  
  86.  
  87. ;------------------------------------------------------------------------------
  88. *
  89. * InitProgressBar    - initialize the progress bar
  90. *
  91. * INPUT:    a0:    pointer to a ProgressStruct
  92. *        a1:    window pointer
  93. *
  94. * RESULT:    d0:    -: ok    0: structure invalid (max<value) (CCR)
  95. *
  96. ;------------------------------------------------------------------------------
  97.     IFD    xxx_InitProgressBar
  98. InitProgressBar:
  99.     movem.l    d1-a6,-(a7)
  100.     moveq    #0,d0
  101.     clr.w    pgb_last(a0)
  102.     move.l    a1,pgb_window(a0)    ; no window!?! -> error
  103.     beq.s    .out
  104.     move.l    pgb_value(a0),d1
  105.     bne.s    1$
  106.     CALL_    ClearProgressBar    ; empty progressbar
  107.     bra.s    .ok
  108. 1$:    cmp.l    pgb_max(a0),d1
  109.     bhi.s    .out
  110.     CALL_    SetProgressBar        ; set bar to an initial value
  111.  
  112. .ok:    moveq    #1,d0
  113. .out:    movem.l    (a7)+,d1-a6
  114.     tst.l    d0
  115.     rts
  116.     ENDC
  117.  
  118.  
  119.  
  120.  
  121.  
  122. ;--------------------------------------------------------------------
  123. *
  124. * SetProgressBar    - set progress bar (absolute)
  125. *
  126. * INPUT:    a0:    pointer to a ProgressStruct
  127. *
  128. * RESULT:    d0:    -: ok   0: failed (no window, bar too large,...) (CCR)
  129. *
  130. ;--------------------------------------------------------------------
  131.     IFD    xxx_SetProgressBar
  132. SetProgressBar:
  133.     movem.l    d1-a6,-(a7)
  134.     CALL_    ClearProgressBar
  135.     tst.l    d0
  136.     beq.s    .out
  137.     CALL_    UpdateProgressBar
  138. .out:    movem.l    (a7)+,d1-a6
  139.     tst.l    d0
  140.     rts
  141.     ENDC
  142.  
  143.  
  144.  
  145.  
  146. ;--------------------------------------------------------------------
  147. *
  148. * ClearProgressBar    - clear progress bar
  149. *
  150. * INPUT:    a0:    pointer to a ProgressStruct
  151. *
  152. * RESULT:    d0:    -: ok   0: failed (no window) (CCR)
  153. *
  154. ;--------------------------------------------------------------------
  155.     IFD    xxx_ClearProgressBar
  156. ClearProgressBar:
  157.     movem.l    d1-a6,-(a7)
  158.     clr.w    pgb_last(a0)
  159.     move.l    pgb_window(a0),d0
  160.     beq.s    .out
  161.     move.l    d0,a1
  162.     moveq    #0,d0
  163.     moveq    #0,d1
  164.     move.w    pgb_x(a0),d2
  165.     move.w    pgb_y(a0),d3
  166.     move.w    pgb_width(a0),d4
  167.     move.w    pgb_height(a0),d5
  168.     moveq    #0,d6            ; clear destination
  169.     move.l    50(a1),a1        ; wd_RPort
  170.     IFD    xxx_pgb_fakedbitmap
  171.     lea    pgb_fakedbitmap(pc),a0
  172.     ELSE
  173.     move.l    rp_BitMap(a1),a0
  174.     ENDC
  175.     move.l    GfxBase(pc),a6
  176.     jsr    _LVOBltBitMapRastPort(a6)
  177.     moveq    #1,d0
  178. .out:    movem.l    (a7)+,d1-a6
  179.     tst.l    d0
  180.     rts
  181.     ENDC
  182.  
  183.  
  184.  
  185. ;--------------------------------------------------------------------
  186. *
  187. * UpdateProgressBar    - update progress bar (relativ from pgb_last)
  188. *
  189. * INPUT:    a0:    pointer to a ProgressStruct
  190. *
  191. * RESULT:    d0:    -: ok   0: failed (no window, bar too large,...) (CCR)
  192. *
  193. ;--------------------------------------------------------------------
  194.     IFD    xxx_UpdateProgressBar
  195. UpdateProgressBar:
  196.     movem.l    d1-a6,-(a7)
  197.     move.l    pgb_window(a0),d0
  198.     beq.s    .out
  199.     move.l    d0,a1
  200.  
  201.     move.l    pgb_max(a0),d0
  202.     bne.s    1$
  203.     moveq    #1,d0            ; to prevent division by zero exceptions
  204. 1$:
  205.     move.l    pgb_value(a0),d1
  206.     move.w    pgb_width(a0),d4
  207.     ext.l    d4
  208.     mulu    d1,d4
  209.     divu    d0,d4
  210.     cmp.w    pgb_width(a0),d4
  211.     bhi.s    .err            ; bar gets larger than allowed -> error
  212.  
  213.     move.w    pgb_last(a0),d2        ; update last field...
  214.     move.w    d4,pgb_last(a0)        ;
  215.     sub.w    d2,d4
  216.     beq.s    .ok            ; no changes
  217.     bpl.s    2$
  218. .dec:    neg.w    d4            ; decrease bar
  219.     sub.w    d4,d2            ;
  220.     bmi.s    .err            ; negative x offset -> error
  221.  
  222. 2$:    add.w    pgb_x(a0),d2
  223.     move.w    pgb_y(a0),d3
  224.     move.w    pgb_height(a0),d5
  225.     moveq    #$50,d6            ; invert destination (source not affected)
  226.     moveq    #0,d0
  227.     moveq    #0,d1
  228.     move.l    50(a1),a1        ; wd_RPort
  229.     IFD    xxx_pgb_fakedbitmap
  230.     lea    pgb_fakedbitmap(pc),a0
  231.     ELSE
  232.     move.l    rp_BitMap(a1),a0
  233.     ENDC
  234.     move.l    GfxBase(pc),a6
  235.     jsr    _LVOBltBitMapRastPort(a6)
  236.  
  237. .ok:    moveq    #1,d0
  238. .out:    movem.l    (a7)+,d1-a6
  239.     tst.l    d0
  240.     rts
  241. .err:    moveq    #0,d0
  242.     bra.s    .out
  243.     ENDC
  244.  
  245.  
  246. ;--------------------------------------------------------------------
  247.     IFD    xxx_pgb_fakedbitmap
  248. pgb_fakedbitmap:
  249.     dc.w    2,1
  250.     dc.b    0,1
  251.     dc.w    0
  252.     ds.b    8*4,0
  253.     EVEN
  254.     ENDC
  255.  
  256.     base    pgb_oldbase
  257.     opt    rcl
  258.  
  259. ;------------------
  260.     ENDIF
  261.  
  262.  end
  263.  
  264.