home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 192.lha / GfxMem_vA.6 / gfxmem.asm < prev    next >
Assembly Source File  |  1988-04-28  |  23KB  |  1,010 lines

  1.     NOLIST
  2. *
  3. *  gfxmem.c  - graphically display available memory.  Quick program
  4. *     that's a freebie.  Give it to anyone you please, just don't sell it.
  5. *
  6. *       Version 0.0 - initial version, released on INFO-AMIGA.
  7. *       Version 0.1 - added numeric indication of available and used memory
  8. *                     in bar graphs.
  9. *       Version 0.2 - added condition compilation for timer.device code.  If
  10. *                     I can figure out how to make it create timer signals,
  11. *                     then I can define USE_TIMER for much more prompt
  12. *                     response to window sizing attempts.  Oh well.
  13. *       Version 0.3 - removed conditional compilation for timer.device
  14. *                     code.  We now use the timer, and all seems well.
  15. *       Version 0.4 - calculate character data placement according to
  16. *                     display preferences.  Check for updated preferences
  17. *                     while running.
  18. *     Version 0.5 - don't display fast memory if none exists.  Handle
  19. *               Lattice C 3.03 in V1.1 update kit that insists on
  20. *               creating a window for stdin, stdout and stderr with-
  21. *               out asking.  Foo!
  22. *            source size = 19,728 bytes
  23. *            running size= 32,088 bytes
  24.  
  25. *    Version A.6 - converted to assembly by Darrel Schnieder.
  26. *            source size =  1,576
  27. *            running size=  9,984
  28. *        Changes:
  29. *             1. Window now SMART_REFRESH. This simplifies what
  30. *              messages need to be responded to. The only time
  31. *              the window needs to be refreshed is if the window
  32. *              is resized.
  33. *             2. Used RMBTRAP so that the window wouldn't get
  34. *              menu messages.
  35. *             3. Got rid of the SetWindowTitles message that was
  36. *              written when the window became active.
  37. *             4. HorizSpace = AvailWidth>>5 in place of
  38. *               HorizSpace = AvailWidth/20
  39. *              This has the effect of the margin being smaller.
  40. *             5. The loop that sets ChipMax & FreeMax is only
  41. *              called once. This means that if the user adds
  42. *              memory to the system while running gfxmem that
  43. *              memory will not show up.
  44. *               Also in the same loop comparisons are made to
  45. *              MEMF_FAST+1 and MEMF_CHIP+1 rather than
  46. *              MEMF_FAST   and MEMF_CHIP as the original program
  47. *                      did.
  48. *              This works on my system and I don't understand the
  49. *              need for the difference.
  50. *             6. The redraw subroutine uses FORBID/PERMIT so that
  51. *              once it starts tasks of a higher priority will not
  52. *              preempt it.
  53. *             8. The numerical sizes of the memory are displayed
  54. *              to the far left and right rather than the middle.
  55. *              I did this so that it would be easier to use the
  56. *              middle to display some more info.
  57. *              I also made the text colors opposite.
  58. *             9. When the numerical amount is printed it only
  59. *              prints the actual number with no preceeding
  60. *              blank spaces.
  61. *              This means it is more likely that the number can
  62. *              be printed since it takes up less space.
  63. *            10. Used SetDrMd to set the mode to JAM1 and thus
  64. *              need never worry about setting the background
  65. *              pen. This got rid of 6 calls to SetBPen.
  66. *            11. Consolidated the natural parrallelism between
  67. *              ChipMem and FastMem code in redraw. This roughly
  68. *              cut the size of redraw in half.
  69. *            12. Will now run with a stack as small as 1600 bytes.
  70. *            13. Displays graphically most recent change.
  71. *              This is done by a bar in the middle.
  72.  
  73.              
  74. *  TODO:
  75. *       Add menu selection package to display Kbytes or percent of memory
  76. *       used and free. If you do this get rid of the RMBTRAP.
  77. *
  78. *       Add requestor to display statistics like min and max for free and
  79. *       avail, time running, etc..
  80. *
  81. *
  82. *                 Copyright (C) 1985,
  83. *                 Louis A. Mamakos
  84. *                 Software & Stuff
  85.  
  86.     INCLUDE "exec/types.i"
  87.     INCLUDE "exec/nodes.i"
  88.     INCLUDE "exec/lists.i"
  89.     INCLUDE "exec/interrupts.i"
  90.     INCLUDE "exec/libraries.i"
  91.     INCLUDE "exec/execbase.i"
  92.     INCLUDE "exec/ables.i"
  93.     INCLUDE "exec/ports.i"
  94.     INCLUDE "exec/devices.i"
  95.     INCLUDE "exec/memory.i"
  96.     INCLUDE "exec/io.i"
  97.     INCLUDE "devices/timer.i"
  98.     INCLUDE "hardware/blit.i"
  99.     INCLUDE "graphics/copper.i"
  100.     INCLUDE "graphics/gfx.i"
  101.     INCLUDE "graphics/regions.i"
  102.     INCLUDE "graphics/rastport.i"
  103.     INCLUDE "graphics/gfxbase.i"
  104.     INCLUDE "graphics/gels.i"
  105.     INCLUDE "graphics/text.i"
  106.     INCLUDE "graphics/view.i"
  107.     INCLUDE "devices/inputevent.i"
  108.     INCLUDE "graphics/clip.i"
  109.     INCLUDE "graphics/layers.i"
  110.     INCLUDE "intuition/intuition.i"
  111.  
  112.     XREF    _LVOAvailMem
  113.     XREF    _LVOFreeMem
  114.     XREF    _LVOOpenLibrary
  115.     XREF    _LVOOpenWindow
  116.     XREF    _LVOAllocSignal
  117.     XREF    _LVOAllocMem
  118.     XREF    _LVOFreeSignal
  119.     XREF    _LVOFindTask
  120.     XREF    _LVOAddPort
  121.     XREF    _LVOOpenDevice
  122.     XREF    _LVOCloseDevice
  123.     XREF    _LVOCloseLibrary
  124.     XREF    _LVORemPort
  125.     XREF    _LVOFreeSignal
  126.     XREF    _LVOCloseWindow
  127.     XREF    _LVOReplyMsg
  128.     XREF    _LVOGetMsg
  129.     XREF    _LVOSendIO
  130.     XREF    _LVOGetPrefs
  131.     XREF    _LVOSetAPen
  132.     XREF    _LVOSetDrMd
  133.     XREF    _LVOText
  134.     XREF    _LVOMove
  135.     XREF    _LVODraw
  136.     XREF    _LVORectFill
  137.     XREF    _LVOWait
  138.     XREF    _LVOBeginRefresh
  139.     XREF    _LVOEndRefresh
  140.  
  141.     TASK_ABLES
  142.     
  143. ;    LLEN 132
  144. ;    NOPAGE
  145. ;    LIST
  146.  
  147. * D2 = Refresh: if 0 then redraw changes only; if 1 then total redraw 
  148. * D3 = IntuitionLib
  149. * D4 = waitFlags
  150. * D5 = TimerPort
  151. * D6 = if 0 then Do Draw; if 1 then Don't Draw
  152. * D7 = GraphicsLib
  153.  
  154. * A2 = window's rastPort
  155. * A3 = window
  156. * A4 = window's userPort
  157. * A5 = timeRequest
  158.  
  159. *********************** CODE ****************************************
  160.  
  161. ************** Find out how much memory is installed ****************
  162.  
  163.     MOVEA.L 4,A6            ; load exec library address
  164.  
  165.     MOVEQ    #0,D4    
  166.     MOVEQ    #0,D5    
  167.     MOVE.L    MemList+LH_HEAD(A6),D0    ; D0 = Memory Region Header
  168.     FORBID
  169. BeginScanMemoryLoop:
  170.     MOVE.L    D0,A0            ; A0 = Memory Region Header
  171.     MOVE.L  (A0),D0            ; look ahead
  172.     BEQ.S    EndScanMemoryLoop    ; EXIT LOOP
  173.     MOVE.W    MH_ATTRIBUTES(A0),D2
  174.     MOVE.L    MH_UPPER(A0),D1
  175.     SUB.L    MH_LOWER(A0),D1
  176.     CMP.W    #MEMF_FAST+1,D2
  177.     BNE.S    isItChip
  178.     ; it is Fast Memory
  179.     ADD.L    D1,D5
  180.     BRA.S    BeginScanMemoryLoop
  181. isItChip:
  182.     CMP.W    #MEMF_CHIP+1,D2
  183.     BNE.S    BeginScanMemoryLoop
  184.     ; it is Chip Memory
  185.     ADD.L    D1,D4
  186.     BRA.S    BeginScanMemoryLoop
  187. EndScanMemoryLoop:    
  188.     PERMIT
  189.     lea    ChipMax(PC),A0
  190.     move.l    D4,(A0)+    ; save ChipMax
  191.     move.l    D5,(A0)        ; save FastMax
  192.  
  193. ***** open libraries *****
  194.     lea    IntuitionName(PC),A1
  195.     moveq    #0,D0
  196.     jsr    _LVOOpenLibrary(A6)
  197.     move.l    D0,D3
  198.     BEQ.L    FailOpeningIntuitionLib
  199.  
  200.     lea    GraphicsName(PC),A1
  201.     moveq    #0,D0
  202.     jsr    _LVOOpenLibrary(A6)
  203.     move.l    D0,D7
  204.     BEQ.L    FailOpeningGraphicLib
  205.  
  206. ***** open window *****
  207.     lea    MyNewWindow(PC),A0
  208.     exg    D3,A6
  209.     jsr    _LVOOpenWindow(A6)
  210.     exg    D3,A6
  211.     tst.l    D0
  212.     BEQ.L    FailOpeningWindow
  213.     movea.l    D0,A3
  214.     ; get Window->UserPort->mp_SigBit into D0
  215.     MOVEA.L wd_UserPort(A3),A0    ; A0 = @lockWindow->UserPort
  216.     MOVEQ   #0,D0
  217.     MOVE.B  MP_SIGBIT(A0),D0    ; D0 = the @lockWindow's mp_SigBit
  218.     MOVEQ   #1,D1
  219.     LSL.L   D0,D1
  220.     MOVE.L  D1,D4        ; D4 = waitFlags
  221.  
  222. ***** create timer port *****
  223.     ; get a signal bit
  224.     MOVEQ   #-1,D0
  225.     JSR     _LVOAllocSignal(A6)
  226.     MOVE.L  D0,D2        ; D2 = sigBit
  227.     BMI.L   FailCreateTimer1
  228.  
  229.     ; alloc port structure
  230.     MOVEQ   #MP_SIZE,D0    ; size of structure
  231.     MOVE.L  #$10001,D1    ; memory type = CLEAR and PUBLIC
  232.     JSR     _LVOAllocMem(A6)
  233.     MOVE.L  D0,D5        ; D5 = timer Port
  234.     BNE.S   SkipFailCode
  235.  
  236.     ; AllocMem failed
  237.     MOVE.L  D2,D0
  238.     JSR     _LVOFreeSignal(A6)
  239.     BRA.S   FailCreateTimer2
  240. SkipFailCode:
  241.     ; fill port fields
  242.     MOVEA.L D5,A2
  243.     ADDQ.L  #8,A2        ; A2 now points to the LN_TYPE field
  244.     MOVE.W  #$400,(A2)+    ; LN_TYPE = NT_MSGPORT, LN_PRI = 0
  245.     LEA    TimerPortName(PC),A0
  246.     MOVE.L  A0,(A2)+    ; LN_NAME = address of timer port name
  247.     MOVE.W  D2,(A2)+    ; MP_FLAGS = (#PA_SIGNAL=0), MP_SIGBIT = sigBit
  248.     MOVEQ   #0,D0
  249.     MOVEA.L D0,A1
  250.     JSR     _LVOFindTask(A6)    ; 0 arg means find this task
  251.     MOVE.L  D0,(A2)        ; MP_SIGTASK = pointer to found task
  252.  
  253.     ; add the port
  254.     MOVEA.L D5,A1
  255.     JSR     _LVOAddPort(A6)
  256.  
  257. ***** use the timer port sigBit(D2) to set the waitFlags(D4) *****
  258.     MOVEQ   #1,D0
  259.     LSL.L   D2,D0
  260.     OR.L    D0,D4        ; update the waitFlags(D4)
  261.  
  262.     BRA.S    EndTerminationSection
  263.  
  264. **************** TERMINATION SECTION ********************
  265.  
  266. CloseWindow:
  267.     ; abort any standing timer request
  268.     MOVEA.L A5,A1
  269.     ; ABORTIO System Macro
  270.         MOVE.L  A6,-(A7)
  271.         MOVEA.L $14(A1),A6
  272.         JSR     -$24(A6)    
  273.         MOVEA.L (A7)+,A6
  274.     ; close timer device
  275.     MOVEA.L A5,A1
  276.     JSR     _LVOCloseDevice(A6)
  277.     ; deallocate timeRequest structure
  278.     MOVEQ   #-1,D6
  279.     MOVE.B  D6,8(A5)
  280.     MOVE.L  D6,$14(A5)
  281.     MOVE.L  D6,$18(A5)
  282.     MOVEA.L A5,A1
  283.     MOVEQ   #$28,D0
  284.     JSR     _LVOFreeMem(A6)
  285.  
  286. FailOpeningDevice:
  287. FailTimeRequestAlloc:
  288.     ; close timer port
  289.     MOVEA.L D5,A1
  290.     JSR     _LVORemPort(A6)
  291.     MOVEA.L D5,A2
  292.     ; D6 = -1
  293.     MOVE.B  D6,$A(A2)
  294.     MOVE.L  D6,(A2)
  295.     MOVEQ    #0,D0
  296.     MOVE.B  MP_SIGBIT(A2),D0    ; get the sigBit
  297.     JSR     _LVOFreeSignal(A6)
  298.     MOVEA.L D5,A1
  299.     MOVEQ   #$22,D0
  300.     JSR     _LVOFreeMem(A6)
  301.  
  302. FailCreateTimer2:
  303. FailCreateTimer1:
  304.     MOVEA.L A3,A0
  305.     EXG     D3,A6
  306.     JSR     _LVOCloseWindow(A6)
  307.     EXG    D3,A6
  308.  
  309. FailOpeningWindow:
  310.     MOVEA.L    D7,A1            ; Graphics Library
  311.     JSR    _LVOCloseLibrary(A6)
  312.  
  313. FailOpeningGraphicLib:
  314.     MOVEA.L    D3,A1            ; Intuition Library
  315.     JSR    _LVOCloseLibrary(A6)
  316.  
  317. FailOpeningIntuitionLib:
  318.     MOVEQ   #0,D0        ; this is the return value
  319.     RTS
  320.  
  321. **************** END TERMINATION SECTION ****************
  322.  
  323. EndTerminationSection:
  324.  
  325. ***** allocate timeReq structure *****
  326.     MOVEQ   #IOTV_SIZE,D0
  327.     MOVE.L  #(MEMF_CLEAR!MEMF_PUBLIC),D1
  328.     JSR     _LVOAllocMem(A6)
  329.     TST.L   D0
  330.     BEQ.S   FailTimeRequestAlloc
  331.     MOVEA.L D0,A5        ; A5 = timeRequest
  332.     MOVE.W  #((NT_MESSAGE<<8)+0),LN_TYPE(A5)
  333.     MOVE.L  D5,MN_REPLYPORT(A5)
  334.     ; AllocMem set to zero the IO_FLAGS, IO_ERROR fields
  335.  
  336. ***** open vblank timer device *****
  337.     LEA     TimerName(PC),A0    ; A0 = timer name
  338.     MOVEA.L A5,A1            ; A1 = timeRequest
  339.     MOVEQ   #UNIT_VBLANK,D0    
  340.     MOVEQ   #0,D1
  341.     JSR     _LVOOpenDevice(A6)
  342.     TST.L   D0
  343.     BNE.S   FailOpeningDevice
  344.     MOVE.W  #TR_ADDREQUEST,IO_COMMAND(A5)
  345.  
  346. ***** initialize enviroment *****
  347.  
  348.     movea.l wd_UserPort(A3),A4
  349.     movea.l wd_RPort(A3),A2
  350.  
  351.     moveq    #1,D2            ; 1 ->  refresh = true
  352.     moveq    #0,D6            ; 0 ->  do draw
  353.     BSR.S    newPrefs
  354.     BSR.L    redraw
  355.     BSR.S    startTimer
  356.  
  357. mainLoop:
  358.     move.l    D4,D0
  359.     JSR    _LVOWait(A6)
  360. BeginWhileMsg:
  361.     movea.l    A4,A0
  362.     JSR    _LVOGetMsg(A6)
  363.     tst.l    D0
  364.     BEQ.S    ExitWhileMsg
  365.     movea.l    D0,A1
  366.     move.l    im_Class(A1),D2        ; save the class of the message
  367.     JSR    _LVOReplyMsg(A6)
  368.     move.l    D2,D0            ; D0 = message's class
  369.  
  370.     move.w    #(NEWSIZE!SIZEVERIFY!NEWPREFS!CLOSEWINDOW),D1
  371.     and.w    D0,D1            ; will be zero if D0 not in the D1 set
  372.     BEQ.S    BeginWhileMsg        ; ignore the message
  373.     cmpi.w    #NEWSIZE,D0
  374.     BNE.S    isItSIZEVERIFY
  375.     ; message is NEWSIZE
  376.     moveq    #0,D6            ; 0 ->  do draw    
  377.     moveq    #1,D2            ; 1 ->  refresh = TRUE
  378.     pea    BeginWhileMsg(PC)    ; push the return address
  379.     BRA.S    redraw            ; jump to the subroutine
  380. isItSIZEVERIFY:
  381.     cmpi.w    #SIZEVERIFY,D0
  382.     BNE.S    isItNEWPREFS
  383.     ; message is SIZEVERIFY
  384.     moveq    #1,D6            ; 1 ->  don"t draw
  385.     BRA.S    BeginWhileMsg
  386. isItNEWPREFS:
  387.     cmpi.w    #NEWPREFS,D0
  388.     BNE.L    CloseWindow        ; only option left is CloseWindow
  389.     ; message is NEWPREFS
  390.     BSR.S    newPrefs
  391.     moveq    #1,D2
  392.     pea    BeginWhileMsg(PC)    ; push the return address
  393.     BRA.S    redraw
  394.  
  395. ExitWhileMsg:
  396.     movea.l    D5,A0
  397.     JSR    _LVOGetMsg(A6)
  398.     tst.l    D0
  399.     BEQ.S    mainLoop
  400.     moveq    #0,D2        ; 0 ->  refresh = false
  401.     BSR.S    redraw
  402.     pea    mainLoop(PC)    ; push the return address
  403.  
  404.     ; let it fall through to startTimer
  405.  
  406. ************************ SUBROUTINES *********************************
  407.     
  408. startTimer:
  409.     QUANTUM: EQU 2
  410.     lea    IO_SIZE+TV_SECS(A5),A0
  411.     clr.l    (A0)
  412.     addq.l    #QUANTUM,(A0)+        ; QUANTUM = number of seconds to wait
  413.     clr.l    (A0)            ; TV_MICRO = 0 => zero ticks
  414.     movea.l    A5,A1
  415.     JSR    _LVOSendIO(A6)
  416.     RTS
  417.  
  418. ***********************************
  419.     
  420. *
  421. *  This function is called during startup and when new preferences are
  422. *  selected.  Get the font size from the Preferences structure.
  423. */
  424. newPrefs:
  425.     lea    fontType(PC),A0
  426.     moveq    #1,D0
  427.     exg    D3,A6
  428.     jsr    _LVOGetPrefs(A6)
  429.     exg    D3,A6
  430.     move.b    fontType(PC),D0
  431.     moveq    #TOPAZ_EIGHTY,D1
  432.     cmp.b    D1,D0
  433.     BNE.S    isItSIXTY
  434.     rts            ; D0 = 8 = char_size
  435.  
  436. isItSIXTY:
  437.     moveq    #TOPAZ_SIXTY,D1
  438.     cmp.b    D1,D0
  439.     BNE.S    setnmfaultSize
  440.     moveq    #11,D0        ; D0 = 11 = char_size
  441.     rts
  442.  
  443. setnmfaultSize:
  444.     moveq    #12,D0        ; D0 = 12 = char_size
  445.     rts
  446.  
  447. ***************************************
  448.     GUTTER: EQU 3
  449.     BLUE:    EQU 0
  450.     WHITE:    EQU 1
  451.     BLACK:    EQU 2
  452.     ORANGE: EQU 3
  453.  
  454. redraw:
  455.     tst.b    D6
  456.     BEQ.S    continueRedraw
  457.     RTS
  458.  
  459. continueRedraw:
  460.     movem.l    D3-D6/A4-A5,-(SP)
  461. **        x_max     = D2
  462. **        y_max     = D3
  463. **        ChipMax  = D4
  464. **        FastMax  = D5
  465. **        ChipFree = D6
  466. **        FastFree = D7
  467. **        A4,A5 used as memory variable pointers
  468.  
  469.     FORBID
  470.  
  471. *   ChipFree = AvailMem (MEMF_CHIP);
  472.     MOVEQ    #MEMF_CHIP,D1        ; also D1<<16 = MEMF_LARGEST
  473.     JSR    _LVOAvailMem(A6)
  474.     MOVE.L    D0,D6            ; store ChipFree
  475.  
  476. *   FastFree = AvailMem (MEMF_FAST);
  477.     MOVEQ    #MEMF_FAST,D1
  478.     JSR    _LVOAvailMem(A6)
  479.     exg    D7,A6
  480.     move.l    D7,-(SP)
  481.     MOVE.L    D0,D7            ; store FastFree
  482.  
  483.     lea    oldChipFree(PC),A4
  484.     lea    ChipDiff(PC),A5
  485.     move.l    D6,D0
  486.     sub.l    (A4),D0            ; D0 = newChipFree - oldChipFree
  487.     move.l    D6,(A4)+        ; store newChipFree as oldChipFree
  488.     cmp.l    D0,D6
  489.     BNE.S    wasNotFirstTime
  490.     ; if this code is executed then this is the first time
  491.     ; need to clear the Diff variables so that no change will be drawn.
  492.     ; The fact that oldChipFree was 0 implies that oldFastFree was 0
  493.     ; This assummes that the only time 0 bytes of Chip mem will be
  494.     ; availiable is the first time through
  495.  
  496.     moveq    #0,D1
  497.     moveq    #0,D0
  498.     addq.l    #8,A5    ; ChipDiff & FastDiff already zero
  499.     move.l    D7,(A4)+        ; store newFastFree as oldFastFree
  500.     BRA.S    skipSinceFirstTime
  501.  
  502. wasNotFirstTime:
  503.     move.l    D0,(A5)+        ; store D0 into ChipDiff
  504.     move.l    D7,D1
  505.     sub.l    (A4),D1            ; D1 = newFastFree - oldFastFree
  506.     move.l    D7,(A4)+        ; store newFastFree as oldFastFree
  507.     move.l    D1,(A5)+        ; store D1 into FastDiff
  508.  
  509. skipSinceFirstTime:
  510.     ; A4 now points to txt
  511.     move.l    (A5)+,D4        ; D4 = ChipMax
  512.     move.l    (A5)+,D5        ; D5 = FastMax
  513.     ; A5 = &HorizSpace
  514.  
  515.     tst.w    D2
  516.     BNE.S    totalRedraw
  517.  
  518.     ; partial Redraw
  519.     add.l    D0,D1
  520.     BEQ.L    exitRedraw
  521.     BRA    needsRedrawing
  522.  
  523. totalRedraw:
  524.     movea.l    A2,A1
  525.     moveq    #BLACK,D0
  526.     JSR    _LVOSetAPen(A6)
  527.     ; SetOPen
  528.     move.b    #BLACK,rp_AOLPen(A2)
  529.     ori.w    #8,rp_Flags(A2)
  530.     movea.l    A2,A1
  531.     moveq    #0,D0
  532.     moveq    #0,D1
  533.     moveq    #0,D2
  534.     moveq    #0,D3
  535.     move.w    wd_Width(A3),D2
  536.     move.b    wd_BorderRight(A3),D0
  537.     sub.w    D0,D2
  538.     move.w    wd_Height(A3),D3
  539.     move.b    wd_BorderBottom(A3),D0
  540.     sub.w    D0,D3
  541.     move.b    wd_BorderLeft(A3),D0
  542.     move.b    wd_BorderTop(A3),D1
  543.     JSR    _LVORectFill(A6)
  544.     ; now recalculate the spacing parameters for this sized window
  545.     moveq    #0,D0
  546.     move.b    wd_BorderLeft(A3),D0
  547.     sub.w    D0,D2            ; D2 = availWidth
  548.     move.b    wd_BorderTop(A3),D0
  549.     sub.w    D0,D3            ; D3 = availHeight
  550.  
  551.     ; clear the Chip & Fast Diff since the window is being resized
  552.     ; this keeps the drawChange routine from executing.
  553.  
  554.     lea    ChipDiff(PC),A4
  555.     clr.l    (A4)+
  556.     clr.l    (A4)+
  557.     addq.l    #8,A4
  558.  
  559.     ; A4 now points to HorizSpace
  560.  
  561.     ; set HorizSpace
  562.     move.w    D2,D0
  563.     lsr.l    #5,D0
  564.     move.w    D0,(A4)+
  565.     add.w    D0,D0
  566.     sub.w    D0,D2
  567.  
  568.     ; set Thickness
  569.     tst.l    D5
  570.     BEQ.S    noFastMemory
  571.     sub.w    #(GUTTER*3),D3
  572.     lsr.w    #1,D3
  573.     BRA.S    doneSettingThickness
  574.  
  575. noFastMemory:
  576.     subq.w    #(GUTTER*2),D3
  577. doneSettingThickness:
  578.     move.w    D3,(A4)+        ; store in Thickness
  579.  
  580.     ; set Scale
  581.     cmp.l    D4,D5            ; is FreeMax > ChipMax
  582.     BHI.S    FreeMaxLarger
  583.     ; ChipMaxLarger
  584.     move.l    D4,D0
  585.     BRA.S    setScale
  586.  
  587. FreeMaxLarger:
  588.     move.l    D5,D0
  589. setScale:
  590.     DIVU    D2,D0
  591.     move.w    D0,(A4)+        ; store in Scale
  592.     addq.l    #8,A4
  593.  
  594.     ; A4 now points to txt
  595.  
  596. needsRedrawing:
  597.     
  598. **** draw amount of allocated chip memory *****
  599.     movea.l    A2,A1
  600.     moveq    #RP_JAM1,D0
  601.     JSR    _LVOSetDrMd(A6)
  602.     movea.l    A2,A1
  603.     moveq    #ORANGE,D0
  604.     JSR    _LVOSetAPen(A6)
  605.     ; SetOPen
  606.     move.b    #WHITE,rp_AOLPen(A2)
  607.     moveq    #0,D0
  608.     moveq    #0,D1
  609.     move.w    (A5)+,D0            ; x_min = HorizSpace
  610.     move.b    wd_BorderTop(A3),D1
  611.     addq.w    #GUTTER,D1            ; y_min
  612.     lea    tempYmin(PC),A0
  613.     move.w    D1,(A0)
  614.     move.l    D0,D2
  615.     sub.l    D6,D4                ; D4 = ChipMax - ChipFree
  616.     move.l    D4,D3
  617.     divu    Scale(PC),D3
  618.     add.w    D3,D2                ; x_max
  619.     move.l    D1,D3
  620.     add.w    (A5),D3                ; y_max = D3 + Thickness
  621.     movea.l    A2,A1
  622.     JSR    _LVORectFill(A6)
  623.     movea.l    D4,A0
  624.     moveq    #0,D4
  625.     move.b    fontType(PC),D4        ; D4 is now used for the fontType
  626.     BSR.L    printAllocatedMem    
  627.  
  628. printAmountOfFreeChipM:
  629.     move.l    ChipDiff(PC),-(SP)
  630.     pea    ChipDividingLine(PC)
  631.     BSR.L    printAmountOfFreeMem
  632.  
  633. printaC:
  634.     lea    Cstring(PC),A0
  635.     BSR.S    printMemTypeChar(PC)
  636.  
  637. printAllocatedFastM:
  638.     tst.l    D5
  639.     BEQ.S    exitRedraw
  640.     
  641. ***** draw amount of allocated fast memory *****
  642.     movea.l    A2,A1
  643.     moveq    #ORANGE,D0
  644.     JSR    _LVOSetAPen(A6)
  645.     moveq    #0,D0
  646.     move.w    (A5)+,D0            ; x_min = HorizSpace
  647.     move.l    D3,D1
  648.     addq.w    #GUTTER,D1            ; y_min = y_max + GUTTER
  649.     lea    tempYmin(PC),A0
  650.     move.w    D1,(A0)
  651.     move.l    D0,D2
  652.     sub.l    D7,D5                ; D5 = FastMax - FastFree
  653.     move.l    D5,D3
  654.     divu    Scale(PC),D3
  655.     add.w    D3,D2                ; x_max = x_min + (D5/Scale)
  656.     move.l    D1,D3
  657.     add.w    (A5),D3                ; y_max = y_min + Thickness
  658.     movea.l    A2,A1
  659.     JSR    _LVORectFill(A6)
  660.     move.l    D5,A0
  661.     BSR.L    printAllocatedMem    
  662.  
  663. *****************************
  664.  
  665. printAmountOfFreeFastM:
  666.     move.l    D7,D6
  667.     move.l    FastDiff(PC),-(SP)
  668.     pea    FastDividingLine(PC)
  669.     BSR.S    printAmountOfFreeMem
  670.  
  671. printaF:
  672.     lea    Fstring(PC),A0
  673.     BSR.S    printMemTypeChar(PC)
  674.  
  675. exitRedraw:
  676.     move.l    (SP)+,D7
  677.     movem.l    (SP)+,D3-D6/A4-A5
  678.     exg    D7,A6
  679.     PERMIT
  680.     RTS
  681.  
  682. *********************************************************************
  683.  
  684. * expects pointer to character to print in A0
  685.  
  686. printMemTypeChar:
  687.     move.l    D4,D0            ; get fontType
  688.     addq.w    #5,D0
  689.     cmp.w    -(A5),D0
  690.     BLS.S    contPrintMemType1    ; since HorizSpace > fontType+5
  691.     RTS
  692.  
  693. contPrintMemType1:
  694.     subq.w    #4,D0
  695.     cmp.w    Thickness(PC),D0
  696.     BLS.S    contPrintMemType2    ; since Thickness > fontType
  697.     RTS
  698.  
  699. contPrintMemType2:
  700.     move.l    A0,D6        ; save A0 in D6
  701.     movea.l    A2,A1
  702.     moveq    #0,D0
  703.     move.w    (A5),D0        ; get the HorizSpace
  704.     sub.w    D4,D0
  705.     subq.w    #1,D0        ; D0 = (HorizSpace - fontType - 1)
  706.     move.w    Thickness(PC),D1
  707.     lsr.w    #1,D1
  708.     add.w    tempYmin(PC),D1
  709.     addq.w    #4,D1        ; D1 = (y_min + Thickness/2 + 4)
  710.     JSR    _LVOMove(A6)
  711.     movea.l    A2,A1
  712.     move.l    D6,A0
  713.     moveq    #1,D0
  714.     JSR    _LVOText(A6)
  715.     RTS
  716.  
  717. ******************************************************************
  718. * expects the amount of free memory in D6
  719.  
  720. printAmountOfFreeMem:
  721.     movea.l    A2,A1
  722.     moveq    #BLUE,D0
  723.     JSR    _LVOSetAPen(A6)
  724.     move.l    D2,D0        ; x_min = x_max
  725.     move.l    D6,D1
  726.     divu    Scale(PC),D1
  727.     add.w    D1,D2        ; x_max += (Chip/Fast)Free/Scale
  728.     moveq    #0,D1
  729.                 ; y_max unchanged
  730.     lea    tempXmin(PC),A0
  731.     move.w    D0,(A0)+
  732.     move.w    (A0),D1        ; y_min =  TOP + GUTTER (i.e. tempYmin)
  733.     JSR    _LVORectFill(A6)
  734.     move.l    (SP)+,D0    ; pop return address temporarily
  735.     move.l    (SP)+,A0    ; get address of (Chip/Fast)DividingLine
  736.     move.l    (SP),D1        ; get (Chip/Fast)Diff value
  737.     move.l    D0,(SP)        ; put the return address back on the stack
  738.     move.w    D2,-(SP)
  739.     BSR.L    drawChange
  740.     move.w    (SP)+,D2
  741.     movea.l    A2,A1
  742.     moveq    #WHITE,D0
  743.     JSR    _LVOSetAPen(A6)
  744.  
  745.     ; can it be printed?
  746.     move.l    D4,D1        ; get the fontType
  747.     addq.w    #1,D1
  748.     cmp.w    (A5),D1
  749.     BLS.S    contPrintAmountFree1    ; since Thickness <= fontType+1
  750.     RTS
  751.  
  752. contPrintAmountFree1:
  753.     moveq    #10,D0
  754.     lsr.l    D0,D6
  755.     move.l    D6,D0
  756.     BSR.S    IntToString
  757.     move.l    D4,D1
  758.     mulu    D0,D1            ; D1 = fontType * #ofCharacters
  759.     move.l    D0,D6            ; save the #ofCharacters
  760.     swap    D6
  761.     addq.w    #2,D1    
  762.     move.w    D1,D6            ; save (fontType * #ofCharacters) + 2
  763.     move.w    D2,D0
  764.     sub.w    tempXmin(PC),D0
  765.     cmp.w    D1,D0
  766.     BHI.S    contPrintAmountFree2    ; since x_max-x_min <= (#ofChar * fontType) + 2
  767.     RTS
  768.  
  769. contPrintAmountFree2:
  770.     
  771.     move.l    A0,-(SP)        ; save string pointer
  772.     movea.l    A2,A1
  773.     move.l    D2,D0
  774.     sub.w    D6,D0        ; D0 = x_max - ((#ofChars * fontType) + 2)
  775.     move.w    (A5),D1
  776.     lsr.w    #1,D1
  777.     add.w    tempYmin(PC),D1
  778.     addq.w    #3,D1        ; D1 = (y_min + Thickness/2 + 3)
  779.     JSR    _LVOMove(A6)
  780.     movea.l    A2,A1
  781.     movea.l (SP)+,A0    ; get the string pointer
  782.     swap    D6
  783.     move.w    D6,D0
  784.     JSR    _LVOText(A6)
  785.     RTS
  786.  
  787. ********************************
  788. * expects D0 = integer to put in string pointed to by A4
  789. * the 5th character of A4 is the last and only the first 4 
  790. * can be numeric. IntToString assummes that the Int in D0 will have
  791. * no more then 4 numeric characters representing it. 
  792. * It will convert 0 to '0'
  793. * RETURNS:
  794. *        A0 = points to first character
  795. *        D0 = count of characters including terminating 'K'
  796.  
  797. IntToString:
  798.     move.l    A4,A0
  799.     move.l    #$30303030,(A0)+
  800.     moveq    #3,D1
  801. IntRepeatTop:
  802.     divu    #10,D0
  803.     swap    D0
  804.     add.b    D0,-(A0)
  805.     clr.w    D0
  806.     swap    D0
  807.     DBEQ    D1,IntRepeatTop
  808.     ; D1 >= 0
  809.     moveq    #5,D0
  810.     sub.w    D1,D0
  811.     RTS
  812.  
  813. ******************************************
  814. * expects amount of allocated memory in A0
  815.  
  816. printAllocatedMem:
  817.     ; can it be printed?
  818.     moveq    #0,D1
  819.     move.b    D4,D1
  820.     addq.w    #1,D1
  821.     cmp.w    (A5),D1            ; compare D1 and Thickness
  822.     BLS.S    contPrintAllocated1    ; since Thickness > fontType+1
  823.     RTS
  824.  
  825. contPrintAllocated1:
  826.  
  827.     moveq    #10,D1
  828.     move.l    A0,D0
  829.     lsr.l    D1,D0
  830.     BSR.S    IntToString
  831.     move.l    D4,D1
  832.     mulu    D0,D1            ; D1 = fontType * #ofCharacters
  833.     move.l    D0,A1            ; save the #ofCharacters
  834.     addq.w    #4,D1    
  835.     move.w    D2,D0
  836.     sub.w    HorizSpace(PC),D0
  837.     cmp.w    D1,D0
  838.     BHI.S    contPrintAllocated2    ; since x_max-x_min > #ofChars * fontType
  839.     RTS
  840.  
  841. contPrintAllocated2:
  842.     move.l    A0,-(SP)    ; save string pointer address
  843.     move.w    A1,-(SP)    ; save #ofCharacters
  844.  
  845.     movea.l    A2,A1
  846.     moveq    #BLACK,D0
  847.     JSR    _LVOSetAPen(A6)        
  848.     movea.l    A2,A1
  849.     moveq    #0,D0
  850.     move.w    HorizSpace(PC),D0
  851.     addq.w    #2,D0            ; D0 = x_min + 2
  852.     moveq    #0,D1
  853.     move.w    (A5),D1        ; get the Thickness
  854.     lsr.w    #1,D1
  855.     add.w    tempYmin(PC),D1
  856.     addq.w    #3,D1        ; D1 = (y_min + Thickness/2 + 3)
  857.     JSR    _LVOMove(A6)
  858.     movea.l    A2,A1
  859.     move.w    (SP)+,D0
  860.     move.l    (SP)+,A0
  861.     JSR    _LVOText(A6)
  862.     RTS
  863.  
  864. *********************************************************************
  865. * expects A0 to contain address of (Chip/Fast)DividingLine
  866. * expects D1 to contain (Chip/Fast)Diff value 
  867. * on entry and exit D3 = y_max
  868.  
  869. drawChange:
  870.     move.w    (A0),D2        ; get old dividing line
  871.     swap    D2
  872.     move.w    tempXmin(PC),D2    ; get new dividing line
  873.     move.w    D2,(A0)        ; store new dividing line as the old div. line
  874.     addq.w    #1,D2
  875.  
  876.     ; SetAPen
  877.     moveq    #ORANGE,D0
  878.  
  879.     tst.l    D1
  880.     BNE.S    contDrawChange1
  881.     RTS
  882.  
  883. contDrawChange1:
  884.     BPL.S    contDrawChange2
  885.     subq.w    #2,D2
  886.     ; SetAPen
  887.     moveq    #BLUE,D0
  888.  
  889. contDrawChange2:
  890.     move.l    A2,A1
  891.     JSR    _LVOSetAPen(A6)
  892.     swap    D3
  893.     move.w    tempYmin(PC),D3
  894.     ; D2 = x_max | x_min = DividingLine | tempXmin
  895.     ; D3 = y_max | y_min = y_max | tempYmin
  896.  
  897.     move.l    A2,A1
  898.     moveq    #0,D0
  899.     move.w    D2,D0    ; D0 = tempXmin
  900.     moveq    #0,D1
  901.     move.w    D3,D1    ; D1 = tempYmin
  902.     JSR    _LVOMove(A6)
  903.  
  904.     swap    D2
  905.     ; D2 = x_max | x_min = tempXmin | DividingLine
  906.     BSR.S    drawLineSegment
  907.  
  908.     swap    D3
  909.  
  910.     ; D3 = y_max | y_min = tempYmin | y_max
  911.     BSR.S    drawLineSegment
  912.  
  913.     swap    D2
  914.     ; D2 = x_max | x_min = DividingLine | tempXmin
  915.     BSR.S    drawLineSegment
  916.  
  917.     swap    D3
  918.  
  919.     ; D3 = y_max | y_min = y_max | tempYmin
  920.     BSR.S    drawLineSegment
  921.     
  922.     clr.w    D3
  923.     swap    D3    ; D3 = y_max
  924.  
  925.     RTS
  926.  
  927. drawLineSegment:
  928.     move.l    A2,A1
  929.     moveq    #0,D0
  930.     move.w    D2,D0
  931.     moveq    #0,D1
  932.     move.w    D3,D1
  933.     JSR    _LVODraw(A6)
  934.     RTS
  935.  
  936. ***************************************************
  937.  
  938. IntuitionName:    CNOP 0,2
  939.     DC.B    'intuition.library',0
  940. GraphicsName:    CNOP 0,2
  941.     DC.B    'graphics.library',0
  942.  
  943. TimerPortName:    CNOP 0,2
  944.     DC.B    'Timer',0
  945. TimerName:    CNOP 0,2
  946.     TIMERNAME
  947.  
  948. windowFlags:     EQU CLOSEWINDOW!SIZEVERIFY!NEWSIZE!NEWPREFS!REFRESHWINDOW
  949. windowGadgets:    EQU NOCAREREFRESH!RMBTRAP!WINDOWDRAG!WINDOWDEPTH!WINDOWCLOSE!WINDOWSIZING!SMART_REFRESH
  950.  
  951. windowTitle:    CNOP 0,2
  952.     DC.B    'GfxMem A.6',0
  953. MyNewWindow:    CNOP 0,2
  954.     DC.W    10
  955.     DC.W    10
  956.     DC.W    170
  957.     DC.W    40
  958.     DC.B    -1
  959.     DC.B    -1
  960.     DC.L    windowFlags
  961.     DC.L    windowGadgets
  962.     DC.L    0
  963.     DC.L    0
  964.     DC.L    windowTitle
  965.     DC.L    0
  966.     DC.L    0
  967.     DC.W    150
  968.     DC.W    30
  969.     DC.W    640
  970.     DC.W    100
  971.     DC.W    WBENCHSCREEN
  972.  
  973. ChipDiff:    CNOP 0,2
  974.     DC.L    0
  975. FastDiff:    CNOP 0,2
  976.     DC.L    0
  977. ChipMax:    CNOP 0,2
  978.     DS.L    1
  979. FastMax:    CNOP 0,2
  980.     DS.L    1
  981. HorizSpace:    CNOP 0,2
  982.     DS.W    1
  983. Thickness:    CNOP 0,2
  984.     DS.W    1
  985. Scale:        CNOP 0,2
  986.     DS.W    1
  987. oldChipFree:    CNOP 0,2
  988.     DC.L    0
  989. oldFastFree:    CNOP 0,2
  990.     DC.L    0
  991. txt:        CNOP 0,2
  992.     DC.L    0
  993.     DC.B    'K'
  994. fontType:    CNOP 0,2
  995.     DS.B    1
  996. Cstring:    
  997.     DC.B    'C'
  998. Fstring:    
  999.     DC.B    'F'
  1000. tempXmin:    CNOP 0,2
  1001.     DS.W    1
  1002. tempYmin:    CNOP 0,2
  1003.     DS.W    1
  1004. ChipDividingLine:    CNOP 0,2
  1005.     DC.W    0
  1006. FastDividingLine:    CNOP 0,2
  1007.     DC.W    0
  1008.  
  1009.     END
  1010.