home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 500.lha / Blankette / Blankette.asm < prev    next >
Assembly Source File  |  1991-04-08  |  12KB  |  397 lines

  1. *****************************************************************************
  2. *
  3. * AUTHOR    : Max Bithead
  4. * DATE    : 2-06-91
  5. *
  6. * NAME    : Blankette (very tiny screen blanker, hence "blankette")
  7. *
  8. * DESC.    : Blankette simply dims the screen when the user is away.  This
  9. *      avoids phospher burns in your monitor that may occur if the screen
  10. *      displays a bright image for an extended period of time.
  11. *
  12. *      To accomplish the screen "dimming", the color values are simply
  13. *      halved on the currently active viewport.
  14. *
  15. *      Blankette uses very little memory (under 2k) and very little CPU
  16. *      time, thus making it a practical screen blanker.
  17. *
  18. *      Blankette must be started under CLI by typing:
  19. *
  20. *        run >nil: Blankette [seconds of inactivity before blank]
  21. *
  22. *      You may use any value you wish for the delay period.  If Blankette
  23. *      is started by just typing "Blankette n", it will be attached to
  24. *      the CLI.  Hit Ctrl-C to cancel it.
  25. *
  26. *      Blankette first cancels any other copies of itself that may be
  27. *      running, so if you want a new delay period, simply restart
  28. *      Blankette.  To remove Blankette completely, simply type
  29. *      "Blankette" without any parameters, or "Blankette 0".
  30. *
  31. *      If you are running a program that is a real CPU hog, never waits
  32. *      on any event, and never does any I/O, then the chances are 
  33. *      Blankette won't get a chance to run.  This is due to the low 
  34. *      priority at which Blankette operates.  If Blankette wasn't at
  35. *      such a low priority, system performance would suffer.  I don't
  36. *      want that on my system.  If I need to walk away while a CPU 
  37. *      intensive program is running, shutting off the monitor works
  38. *      nicely to preserve it's life.  Blankette will otherwise kick in
  39. *      during normal system activity.
  40. *
  41. *      A word about HAM:  Normally, halving the color values of a HAM
  42. *      picture does little or no good, such is the nature of Hold And
  43. *      Modify mode.  To get around this, Blankette turns HAM mode off
  44. *      to dim the screen, and back on again when it detects user input.
  45. *
  46. *      Blankette is sensitive to mouse movement, joystick movement, the
  47. *      left mouse button, the joystick button, and keyboard input.
  48. *
  49. *
  50. * HAPPY    : So far, Blankette has proven to be compatible with just about
  51. *      everything!  In fact, I haven't been able to crash the system
  52. *      by using it. :)  Enjoy!
  53. *
  54. *      Ooops.  It's possible, by way of the DisplayBeep function, to
  55. *      get your screen stuck in the halved colors.  To fix this situation,
  56. *      simply pull up the system preferences.  When the preferences 
  57. *      window pops up it resets your colors for you.  Happy again.
  58. *
  59. *****************************************************************************
  60.     bra    start
  61.  
  62. author    dc.b    $0a,"(C)opyright Max Bithead",$0a,"Boulder, Colorado, USA",$0a,"1991",$0a,0
  63.  
  64.     incdir    "sys:include/"
  65.  
  66.     include    exec/exec_lib.i
  67.     include    libraries/dosextens.i
  68.     include    graphics/graphics_lib.i
  69.     include    graphics/view.i
  70.     include    exec/nodes.i
  71.  
  72. *****************************************************************************
  73.  
  74. start
  75.     move.l    a0,a2        Save input parm ptr
  76.     jsr    startup(pc)
  77.     tst.l    d0        If error
  78.     beq.s    .abort1        ..abort
  79.     jsr    no_clone(pc)    Only one copy of us at a time
  80.     jsr    parse(pc)
  81.     tst.l    d0
  82.     bne.s    .abort2
  83.     jsr    low_pri(pc)    Put us at very low priority
  84.     jsr    process(pc)    Check input & blank
  85. .abort2
  86.     jsr    cleanup(pc)    Clean up (free resouces, etc.)
  87. .abort1
  88.     rts            Return
  89.  
  90. *****************************************************************************
  91.  
  92. graph_nam    dc.b    "graphics.library",0
  93. _GfxBase    dc.l    0
  94.  
  95.     EVEN
  96. startup
  97.     lea    graph_nam(pc),a1    Addr of graphics lib name
  98.     moveq    #33,d0          Open latest version (1.2 or >)
  99.     move.l    _SysBase,a6    SysBase offset (at addr 4)
  100.     jsr    _LVOOpenLibrary(a6)    Open graphics library
  101.     move.l    d0,_GfxBase
  102.     rts
  103.  
  104. *****************************************************************************
  105.  
  106. task    dc.l    0        Ptr to our task control block (TCB)
  107. old_name    dc.l    0        Ptr to old task name
  108. task_name    dc.b    "$Max@Blanker",0
  109.  
  110.     EVEN
  111. no_clone
  112.     lea    task_name(pc),a1    Ptr to name of task to find
  113.     CALLEXEC    FindTask        If (already running blanker)
  114.     tst.l    d0
  115.     beq.s    .ok
  116.     move.l    d0,a1        ..Addr of other blanker TCB
  117.     move.l    #$1000,d0        ..Send CTRL-C abort signal
  118.     CALLEXEC    Signal        ..to other blanker task
  119. .ok
  120.     move.l    #0,a1        Ptr to name of task to find
  121.     CALLEXEC    FindTask        Find addr of our task
  122.     move.l    d0,task        Addr of our task
  123.     move.l    d0,a0
  124.     move.l    LN_NAME(a0),old_name Save ptr to old name
  125.     lea    task_name(pc),a1
  126.     move.l    a1,LN_NAME(a0)    Change our task name
  127.     rts
  128.  
  129. *****************************************************************************
  130.  
  131. time_val    dc.l    0        (# seconds before blank) * 60
  132.  
  133.     EVEN
  134. parse
  135.     moveq    #0,d0
  136.     move.b    (a2)+,d0        Get byte of input line
  137.     cmpi.b    #$0d,d0        If CR (eol)
  138.     beq    .done        ..end of input line
  139.     cmpi.b    #$0a,d0        If (line feed)
  140.     beq    .done        ..end of input line
  141.     cmpi.b    #$30,d0        If (NOT number value)
  142.     blt.s    parse        ..ignore it
  143.     cmpi.b    #$3a,d0
  144.     bgt.s    parse
  145.     subi.b    #$30,d0        Else convert to ascii
  146.     move.l    time_val(pc),d1
  147.     mulu    #10,d1
  148.     add.l    d0,d1        Add to time value
  149.     move.l    d1,time_val
  150.     bra.s    parse
  151. .done
  152.     tst.l    time_val        If (no time value)
  153.     beq.s    .error        ..error
  154.     move.l    time_val(pc),d1    Get time value
  155.     mulu    #60,d1        Convert to seconds (for 60hz clock)
  156.     move.l    d1,time_val
  157.     moveq    #0,d0        Good return
  158.     rts
  159. .error
  160.     moveq    #1,d0        Error return
  161.     rts
  162.  
  163. *****************************************************************************
  164.  
  165. low_pri
  166.     move.l    task(pc),a1    Addr of our task
  167.     moveq    #-128,d0        Lowest priority possible
  168.     CALLEXEC    SetTaskPri    Set our priority
  169.     rts
  170.  
  171. *****************************************************************************
  172.  
  173. ActiView    equ    34    Pointer to currently active View struct
  174. view    ds.l    1    Addr of active View struct
  175. vport    ds.l    1    Addr of active ViewPort struct
  176. cmap    ds.l    1    Addr of active ColorMap struct
  177. ctable    ds.w    32    Save area for color table
  178. vmodes    ds.w    1    Display modes
  179.  
  180.     EVEN
  181. get_cmap
  182.     move.l    _GfxBase(pc),a0    Addr of graphics library base
  183.     move.l    ActiView(a0),a0    Addr of active View
  184.     move.l    a0,view        Save it
  185.     move.l    v_ViewPort(a0),a0    Addr of ViewPort struct
  186. .loop1
  187.     move.l    a0,vport        Save it
  188.     move.w    vp_Modes(a0),d0
  189.     andi.w    #$2000,d0        WHILE (hidden view)
  190.     beq.s    .gotem
  191.     tst.l    vp_Next(a0)    ..IF (no more viewport structs)
  192.     beq.s    .gotem        ....BREAK
  193.     move.l    vp_Next(a0),a0    ..ELSE (get next viewport)
  194.     bra.s    .loop1        ENDWHILE
  195. .gotem
  196.     move.w    vp_Modes(a0),vmodes    Save ViewPort modes
  197.     move.l    vp_ColorMap(a0),a0    Addr of ColorMap struct
  198.     move.l    a0,cmap        Save it
  199.     move.l    cm_ColorTable(a0),a0  Addr of color values for this view
  200.     lea    ctable(pc),a1    Addr of our color save area
  201.     moveq    #15,d0
  202. .loop2
  203.     move.l    (a0)+,(a1)+    Copy color map
  204.     dbra    d0,.loop2
  205.     rts
  206.  
  207. *****************************************************************************
  208.  
  209. newctable    ds.w    32
  210.  
  211.     EVEN
  212. half_colors
  213.     CALLEXEC    Forbid        Don't be changing VP's on us here
  214.     jsr    get_cmap(pc)    Find current view
  215.     lea    ctable(pc),a0    Addr of saved colormap
  216.     move.l    cmap(pc),a1    Addr of ColorMap struct
  217.     move.l    cm_ColorTable(a1),a1  Addr of color values for this view
  218.     lea    newctable(pc),a2    Addr of new color table
  219.     moveq    #31,d0        Dew all colors
  220. .loop
  221.     move.b    (a0)+,d1        1st byte of color value
  222.     andi.b    #$0f,d1        Get just red value (hi nibble xtra)
  223.     lsr.b    #1,d1        halve red value
  224.     move.b    d1,d2
  225.     lsl.w    #8,d2        save in upper byte of d2 word
  226.     move.b    (a0),d1        Get green value
  227.     lsr.b    #1,d1        halve green value
  228.     andi.b    #$f0,d1        just green value
  229.     move.b    d1,d2        save in lower byte of d2 word
  230.     move.b    (a0)+,d1        get blue value
  231.     andi.b    #$0f,d1        just blue value
  232.     lsr.b    #1,d1        halve blue value
  233.     or.b    d1,d2        put with other halved values
  234.     move.w    d2,(a1)+        Put halved color in view color map
  235.     move.w    d2,(a2)+        Remember what we put there
  236.     dbra    d0,.loop
  237.     move.l    view(pc),a0    Addr of active view
  238.     move.l    vport(pc),a1    Addr of view port struct
  239.     andi.w    #$f7ff,vp_Modes(a1)    Make sure HAM is off
  240.     CALLGRAF    MakeVPort        Reset color instructs
  241.     move.l    view(pc),a1    Addr of active view
  242.     CALLGRAF    MrgCop        Merge copper instructions
  243.     move.l    view(pc),a1    Addr of active view
  244.     CALLGRAF    LoadView        Display color changes
  245.     CALLEXEC    Permit        Ok system, go for it
  246.     rts
  247.  
  248. *****************************************************************************
  249.  
  250. restore_colors
  251.     CALLEXEC    Forbid        Don't be changing VP's on us here
  252.     move.l    _GfxBase(pc),a0    Addr of graphics library base
  253.     move.l    ActiView(a0),a0    Addr of active View
  254.     cmp.l    view(pc),a0    IF (NOT same view that got changed)
  255.     bne.s    .done        ..forget it
  256.     move.l    v_ViewPort(a0),a0    Addr of 1st ViewPort struct
  257. .loop
  258.     cmp.l    vport(pc),a0    IF (ViewPort is gone)
  259.     beq.s    .gotem
  260.     tst.l    vp_Next(a0)
  261.     beq.s    .done        ..forget it
  262.     move.l    vp_Next(a0),a0
  263.     bra.s    .loop
  264. .gotem
  265.     lea    newctable(pc),a0    Addr of saved new colors
  266.     move.l    cmap(pc),a1    Addr of ColorMap struct
  267.     move.l    cm_ColorTable(a1),a1  Addr of color values for this view
  268.     moveq    #15,d0        Check all colors
  269. .loop1
  270.     cmp.l    (a0)+,(a1)+    If (program has changed its colors)
  271.     bne.s    .done        ..abort, don't need to restore 'em
  272.     dbra    d0,.loop1
  273.     lea    ctable(pc),a0    Addr of saved colormap
  274.     move.l    cmap(pc),a1    Addr of ColorMap struct
  275.     move.l    cm_ColorTable(a1),a1  Addr of color values for this view
  276.     moveq    #15,d0        Dew all colors
  277. .loop2
  278.     move.l    (a0)+,(a1)+    Restore colors
  279.     dbra    d0,.loop2
  280.     move.l    view(pc),a0    Addr of active view
  281.     move.l    vport(pc),a1    Addr of view port struct
  282.     move.w    vmodes(pc),d0    Get previous modes
  283.     andi.w    #$0800,d0
  284.     or.w    d0,vp_Modes(a1)    Turn HAM back on if needs to be
  285.     CALLGRAF    MakeVPort        Reset color instructs & display modes
  286.     move.l    view(pc),a1    Addr of active view
  287.     CALLGRAF    MrgCop        Merge copper instructions
  288.     move.l    view(pc),a1    Addr of active view
  289.     CALLGRAF    LoadView        Display color changes
  290. .done
  291.     CALLEXEC    Permit        Ok system, go for it
  292.     rts
  293.  
  294. *****************************************************************************
  295.  
  296. strt_clock  dc.l    0
  297. screen    dc.b    0    Status of screen colors (0=normal, 1=dim)
  298.  
  299.     EVEN
  300. process
  301.     jsr    get_clock_60hz(pc)    Get value of 60hz clock
  302.     move.l    d0,strt_clock    Save initial value
  303. .loop
  304.     moveq    #0,d0
  305.     moveq    #0,d1
  306.     CALLEXEC    SetSignal        Get copy of our signals
  307.     andi.l    #$1000,d0        CTRL-C pressed?
  308.     bne.s    .done
  309.     jsr    check_input(pc)    If (user input)
  310.     tst.l    d0
  311.     beq.s    .clock
  312.     tst.b    screen
  313.     beq.s    process        ..If (screen dim)
  314.     jsr    restore_colors(pc)    ....restore it
  315.     clr.b    screen
  316.     bra.s    process
  317. .clock
  318.     jsr    get_clock_60hz(pc)    Keep checking the clock
  319.     sub.l    strt_clock(pc),d0
  320.     cmp.l    time_val,d0
  321.     blt.s    .loop        If (times up)
  322.     tst.b    screen        ..If (screen NOT dim)
  323.     bne.s    process
  324.     jsr    half_colors(pc)    ....dim screen
  325.     move.b    #1,screen
  326.     bra.s    process
  327. .done
  328.     tst.b    screen
  329.     beq.s    .done2        ..If (screen dim)
  330.     jsr    restore_colors(pc)    ....restore it
  331. .done2
  332.     rts
  333.  
  334. *****************************************************************************
  335.  
  336. mouse    dc.l    0    Current mouse movement value
  337. keyboard    dc.b    0    Current keyboard value
  338. fire    dc.b    0    Current fire/mouse button value
  339.  
  340. check_input
  341.     move.l    $dff00a,d0    Check mouse & joystick movement
  342.     cmp.l    mouse(pc),d0    If (!same as last check)
  343.     beq.s    .more
  344.     move.l    d0,mouse        ..save current position
  345.     bra.s    .input        ..return input
  346. .more
  347.     move.b    $bfec01,d0    else if (keyboard input)
  348.     cmp.b    keyboard,d0
  349.     beq.s    .more2
  350.     move.b    d0,keyboard    ..save current value
  351.     bra.s    .input        ..return input
  352. .more2
  353.     move.b    $bfe001,d0    else if (fire or mouse button)
  354.     andi.b    #$c0,d0
  355.     cmp.b    fire,d0
  356.     beq.s    .more3
  357.     move.b    d0,fire        ..save current value
  358.     bra.s    .input        ..return input
  359. .more3
  360.     moveq    #0,d0        else return no input
  361.     rts
  362. .input
  363.     moveq    #1,d0
  364.     rts
  365.  
  366. *****************************************************************************
  367.  
  368. get_clock_60hz
  369.     moveq    #0,d0        Return 60hz clock value (24 bit)
  370.     move.b    $bfea01,d0    Read of this reg latches clock
  371.     lsl.l    #8,d0
  372.     move.b    $bfe901,d0
  373.     lsl.l    #8,d0
  374.     move.b    $bfe801,d0    Read of low byte unlatches clock
  375.     rts
  376.  
  377. *****************************************************************************
  378.  
  379. cleanup
  380.     move.l    task(pc),a1    Addr of our task
  381.     moveq    #0,d0        Priority
  382.     CALLEXEC    SetTaskPri    Set our priority back to normal
  383.                 ;This is so we don't accidently
  384.                 ;leave a shell or cli at low pri
  385.     move.l    task(pc),a1    Addr of our task
  386.     move.l    old_name(pc),d0    Addr of old task name
  387.     move.l    d0,LN_NAME(a1)    Restore old task name
  388.                 ;Won't completely abort without this
  389.                 ;if running directly from shell or CLI
  390.     move.l    _GfxBase(pc),a1    Addr of lib base to close
  391.     move.l    _SysBase,a6
  392.     jsr    _LVOCloseLibrary(a6) Close the lib
  393.     rts
  394.  
  395. *****************************************************************************
  396.  
  397.