home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / sysutil / toad8253.lzh / TOAD825X.ASM < prev    next >
Assembly Source File  |  1988-09-01  |  9KB  |  227 lines

  1.     title    Toad825X
  2. Comment ~
  3. Author: David Kirschbaum 31 Aug 88
  4. From "DMA Control on the PC"
  5. by Larry Fogg, Micro Cornucopia #37, Sep-Oct 87
  6.  
  7. The article suggests a way to tweak the 8253 timer to slow down the RAM
  8. refresh rate.  Author suggests you can slow the normal DREQ0 interrupt
  9. from its normal 15-microsecond interval to up to a full second before RAM
  10. will start failing.
  11.  
  12. Extract from the article's text:
  13.      "It was right at one refresh every second that my RAM faded away.
  14. A count of 900H loaded into the 8253's Timer 1 gives the one second
  15. period.
  16.      "The BIOS loads the count with 12H and the point of diminishing returns
  17. comes around 30H or 40H.  After 40H refresh happens so infrequently as to
  18. have no effect on system performance.  Benchmarks show no difference between
  19. 40H and 900H.
  20.      "A value of 40H gives a 2.6% speed increase on my Holliston 186 board
  21. and a 5.8% increase on a standard 4.77 MHz 8088.  I haven't had any problems
  22. using this speedup.  But don't blame me if your machine dissolves into a
  23. puddle of blue slime.  After all, we've gone beyond the limits of computer
  24. decency."
  25.  
  26. Toad Hall Notes:
  27. The author provided some assembler code to be used via DEBUG.
  28. I rewrote it into a proper MASM-compatible .ASM format so you can compile
  29. to REFRESH.COM (or whatever you wanna name it).  Run it on startup.
  30. Returns the LSB as the DOS ERRORLEVEL (for what that's worth).
  31. ERRORLEVEL of 1 means illegal entry, help, whatever.
  32.  
  33. Sure, I could write this to take the LSB from the DOS command line,
  34. but that would only be for experimental use.  Better for you to determine
  35. the "magic number" that's best for your system and just leave it hard-
  36. coded.  That way no user will accidentally enter some weird number!
  37.  
  38. |v1.1 Command line entry is now allowed.  Use the original TOAD8253.ASM
  39. |if you want to stick with the smaller program, hard-coded speed, etc.
  40.  
  41. I used the public domain MIPS.COM v1.10 CPU speed utility as a benchmark.
  42. I also ran Norton's SYSINFO.COM (SI) utility just for comparisons.
  43. The SI values vary irregularly on sequential runs (e.g., the 40H lsb
  44. value produced SI ratings of 7.0 to 7.1).
  45.  
  46. Following are MIPS and SI results after running TOAD8253 with various
  47. LSB values (and in the most extreme, a new MSB value).
  48.  
  49.                 Counter 1 values
  50.             12H    40H    80H    0A0H    0100H
  51. General Instructions    0.48    0.50    0.51    0.51    0.51
  52. Integer Instructions    0.87    0.90    0.90    0.91    0.91
  53. Memory to Memory    0.69    0.74    0.75    0.76    0.76
  54. Register to Register    1.13    1.14    1.15    1.15    1.15
  55. Register to Memory    0.89    0.94    0.96    0.96    0.96
  56. Performance Rating    0.81    0.85    0.85    0.86    0.86
  57. Norton's SI rating    7.0    7.1    7.1    7.1    7.1
  58.  
  59. So, no significant changes after bumping the lsb to 0A0H or beyond.
  60. (No, I did NOT push the timer to RAM memory failure!)
  61.  
  62. v1.1 SPEED.COM statistics:
  63. "TOAD8253 18" (PC-DOS default):
  64.     Checking memory block write   ticks: 126 compared to IBM/PC 400%
  65.     Checking register to memory   ticks: 160 compared to IBM/PC 306%
  66.     Checking memory to register   ticks: 196 compared to IBM/PC 250%
  67.     Checking register to register ticks: 190 compared to IBM/PC 290%
  68.     Checking divide by register   ticks:  78 compared to IBM/PC 656%
  69.     Checking divide by memory     ticks: 116 compared to IBM/PC 520%
  70.     Checking multiply by register ticks:  90 compared to IBM/PC 534%
  71.     Checking multiply by memory   ticks: 114 compared to IBM/PC 488%
  72.     Checking stack operations     ticks: 163 compared to IBM/PC 273%
  73.     Checking far jumps, far calls ticks: 207 compared to IBM/PC 250%
  74.   Total time is: 1440 clock ticks, (80 seconds) compared to IBM/PC 357%
  75.  
  76. "TOAD8253 160" (Optimum for my system):
  77.     Checking memory block write   ticks: 118 compared to IBM/PC 427%
  78.     Checking register to memory   ticks: 147 compared to IBM/PC 334%
  79.     Checking memory to register   ticks: 177 compared to IBM/PC 276%
  80.     Checking register to register ticks: 177 compared to IBM/PC 311%
  81.     Checking divide by register   ticks:  77 compared to IBM/PC 664%
  82.     Checking divide by memory     ticks: 112 compared to IBM/PC 539%
  83.     Checking multiply by register ticks:  87 compared to IBM/PC 552%
  84.     Checking multiply by memory   ticks: 104 compared to IBM/PC 535%
  85.     Checking stack operations     ticks: 148 compared to IBM/PC 300%
  86.     Checking far jumps, far calls ticks: 194 compared to IBM/PC 267%
  87.   Total time is: 1341 clock ticks, (74 seconds) compared to IBM/PC 384%
  88.  
  89.  
  90. Now, if you want to slow your system DOWN (not the original intention,
  91. but some users need to slow down fast clones for games, etc.), here are
  92. some slowdown stats:
  93.                     Counter 1 values
  94.             10H    0AH    07H    05H    03H    02H    01H
  95. General Instructions    0.47    0.44    0.39    0.38    0.26    0.23    LOCKUP!
  96. Integer Instructions    0.87    0.84    0.83    0.77    0.63    0.57
  97. Memory to Memory    0.68    0.63    0.59    0.54    0.33    0.35
  98. Register to Register    1.11    1.09    1.01    1.01    0.81    0.81
  99. Register to Memory    0.87    0.81    0.75    0.66    0.47    0.50
  100. Performance Rating    0.80    0.76    0.71    0.67    0.50    0.49
  101. Norton's SI rating:    6.6    6.6    6.3    6.2    4.4    4.6
  102.  
  103. My system is an older GulfStream 8MHz 80286 (XT-compatible, Phoenix ROM)
  104. running PC-DOS 3.1.  Your mileage may vary.
  105.  
  106. Released to public domain.  PLEASE do not distribute this program without
  107. its assembler source code and/or documentation!
  108.  
  109. David Kirschbaum
  110. Toad Hall
  111. kirsch@braggvax.ARPA
  112.  
  113. v1.1, 1 Sep 88
  114.  - Added command line speed entry (2..2048 decimal), help.
  115.  - more statistics from the PD utility SPEED.COM
  116.  - Renamed TOAD825X.ASM to differ from hardcoded TOAD8253.ASM
  117.  
  118. Comment ends
  119. ~
  120.  
  121. CodeSeg    SEGMENT PUBLIC PARA 'Code'
  122.     ASSUME    CS:CodeSeg, DS:CodeSeg, ES:CodeSeg
  123.  
  124. CR    EQU    0DH
  125. LF    EQU    0AH
  126. VALUE    EQU    00A0H        ;TH optimum value, LSB=0AH, MSB=0
  127. DEADRAM    EQU    800H        ;Assume max RAM refresh delay
  128.     org    100H
  129.  
  130.  
  131. Toad8253    proc    near
  132.     jmp    Start        ;skip the data
  133.  
  134. usemsg    db 'TOAD825X - David Kirschbaum, Toad Hall, 1 Sep 88',CR,LF
  135.     db "Adjust a PC's 8253 timer to change RAM refresh rate.",CR,LF
  136.     db 'Usage  TOAD825X %',CR,LF
  137.     db '  where % is a timer value value 2 (slowest) .. 2048.',CR,LF
  138.     db 'PC-DOS normal delay value is 18,',CR,LF
  139.     db 'optimum value for most systems is 64, 128, or 160.',CR,LF
  140.     db 'A delay value over 2048 may lock up your system!',CR,LF,'$'
  141. badmsg    db 'TOAD825X - Illegal timer value!',CR,LF
  142.     db 'Range of 2 (slowest) .. 2048 (maximum) only!',CR,LF
  143.     db '(TOAD825X ?  for help)',CR,LF,'$'
  144. setmsg    db 'TOAD825X - 8253 timer reset.',CR,LF,'$'
  145.  
  146. Start:    call    Get_Rate        ;get cmd line rate
  147.     jc    No_Action        ;CF means bad rate
  148.     mov    al,74H            ;configure 8253 (see Micro C #35, p.30)
  149.     out    43H,al
  150.     mov    al,bl            ;counter 1 lsb from Get_Rate
  151.     out    41H,al            ;change counter 1 lsb to alter
  152.                     ; refresh rate
  153.     mov    al,bh            ;counter 1 msb from Get_Rate
  154.     out    41H,al
  155.     mov    dx,offset setmsg    ;'8253 timer reset'
  156.     mov    ah,9            ;DOS display string
  157.     int    21H
  158.  
  159. No_Action:
  160.     mov    al,bl            ;return lsb as ERRORLEVEL
  161.     mov    ah,4CH            ;DOS terminate process
  162.     int    21H
  163.  
  164. Toad8253    endp
  165.  
  166. Get_Rate    proc    near
  167.     mov    si,81H            ;DOS PSP cmd line buffer
  168.     xor    ax,ax            ;clear msb
  169.     xor    bx,bx            ;accumulate cmd line value in BX
  170.     mov    cx,10            ;*10 constant multiplier
  171.     xor    dx,dx            ;clear to flag overflow
  172. Cmd_Loop:
  173.     lodsb                ;snarf cmd line char
  174.     cmp    al,'?'            ;user wants help?
  175.     je    Usage            ;yep, skip the rest
  176.     cmp    al,0DH            ;CR means done
  177.     je    Cmd_Done
  178.     cmp    al,' '            ;gobble spaces
  179.     je    Cmd_Loop
  180.     cmp    al,'0'            ;only 0..9 chars accepted
  181.     jb    Cmd_Loop
  182.     cmp    al,'9'
  183.     ja    Cmd_Loop
  184. ;We have a legal digit
  185.     sub    al,'0'            ;deasciify the digit
  186. ;    or    bx,bx            ;first time thru?
  187. ;    je    Ones            ;Yep, no testing or MUL
  188. ;
  189.     xchg    ax,bx            ;swap, AX=prev value
  190.     cmp    ax,DEADRAM        ;max allowable timer value
  191.     ja    Bad_Val            ;illegal
  192.     mul    cx            ;old timer value * 10
  193.     or    dx,dx            ;any product > an integer is illegal
  194.     jnz    Bad_Val            ;illegal
  195.     xchg    ax,bx            ;bx=new timer value, AL=this digit,AH=0
  196. ;Ones:
  197.     add    bx,ax            ;add in new 1's
  198.     jnc    Cmd_Loop        ;CF means > an integer, illegal
  199. Bad_Val:
  200.     mov    dx,offset badmsg    ;'Bad timer value'
  201.     jmp    short Bad_Ret        ;display msg, exit
  202.  
  203. Cmd_Done:
  204. ;total cmd line value has been accumulating in BX
  205.     or    bx,bx            ;no cmd line value at all?
  206.     jz    Usage            ;right, tell user how
  207.     cmp    bx,2            ;minimum timer value allowed
  208.     jb    Bad_Val            ;bad, return CF set
  209.     cmp    bx,DEADRAM        ;maximum timer value allowed
  210.     ja    Bad_Val            ;bad, return CF set
  211.     clc                ;CF clear means Ok
  212. Cmd_Ret:
  213.     ret
  214.  
  215. Usage:
  216.     mov    dx,offset usemsg    ;'TOAD825X changes...'
  217. Bad_Ret:
  218.     mov    ah,9            ;DOS display str
  219.     int    21H
  220.     mov    bl,1            ;ERRORLEVEL 1
  221.     stc                ;CF means no action
  222.     ret
  223. Get_Rate    endp
  224.  
  225. CodeSeg    ends
  226.     end    Toad8253
  227.