home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol009 / which.asm < prev    next >
Assembly Source File  |  1984-04-29  |  3KB  |  179 lines

  1. ;    which.asm
  2. ;
  3. ;    this program returns size and version
  4. ;    of cp/m you are running.
  5. ;    this can be useful when running under
  6. ;    fast, despool, ddt, sid, etc.
  7. ;
  8. ;    version of 25 nov 1980
  9. ;
  10. ;    by David Fiedler
  11. ;       InfoPro Systems
  12. ;       Denville, NJ
  13.  
  14. ;    Copyright 1980 InfoPro Systems.  This program may
  15. ;    not be used for commercial purposes without written
  16. ;    permission from InfoPro Systems.  However it may
  17. ;    be used by hackers to their heart's content as long
  18. ;    as they don't try to sell it or pass it off as their
  19. ;    own.
  20. ;
  21. ;    Please note that this has not been tried out under
  22. ;    other than CP/M 2.2, although it should work fine.
  23. ;
  24. ;    code adapted from tpa3.asm by:
  25. ;       Ron Fowler    
  26. ;       Westland, Mich.
  27. ;
  28. ;       fixes and code optimizations to tpa3 by
  29. ;       Keith Petersen
  30. ;
  31.     org    100h
  32. ;
  33. base:    lxi    h,0
  34.     dad    sp    ;get local stack
  35.     shld    oldstk    ;save old stack
  36.  
  37.     call    tb
  38. msg:    db    'Welcome to $'
  39.  
  40. tb:    mvi    c,9    ;print msg function
  41.     pop    d    ;get msg adrs
  42.     call    5    ;print it
  43.  
  44.     mvi    c,12    ;get version number function
  45.     call    5
  46.     shld    retword    ;hold for later
  47.     mov    a,h    ;multi-tasking?
  48.     cpi    1
  49.     jz    mpm    ;yes.
  50.     mvi    a,'C'    ;no.
  51.     sta    versms    ;so announce properly
  52.     jmp    getsiz
  53. mpm:
  54.     mvi    a,'M'
  55.     sta    versms
  56.         
  57. getsiz:    lhld    6    ;get the bdos address
  58.     xchg        ;into de
  59.     lhld    retword
  60.     mov    a,l
  61.     cpi    0
  62.     jnz    newone
  63.     lxi    h,-3100h    ;get 16k bdos address for cp/m 1.4
  64.     dad    d        ;subtract it, answer left in hl
  65.     lxi    d,(16 * 1024)    ;this would print 16k if addresses were equal
  66.     dad    d        ;not efficient but clear at least
  67.     jmp    print
  68. newone:    
  69.     lxi    h,-3c00h    ;20k bdos offset for 2.0
  70.     dad    d
  71.     lxi    d,(20 * 1024)
  72.     dad    d
  73. print:    
  74.     mov    a,h
  75.     rrc            ;divide by 2
  76.     rrc            ;divide by 4
  77.     ani    7fh        ;mask to positive
  78.     mov    l,a        ;effectively divide by 2 ^ 8
  79.     mvi    h,0        ;for a total of 2 ^ 10 = 1K
  80.     call    decout        ;print it
  81.     call    tb1        ;print the line
  82. sizems:    db    'K '
  83. versms:    db    ' P/M Version $'
  84. ;
  85. ;
  86. tb1:    mvi    c,9    ;print msg function
  87.     pop    d    ;get msg adrs
  88.     call    5    ;print it
  89. ;
  90. getnum:
  91.     lhld    retword
  92.     mov    a,l
  93.     cpi    0    ;previous to 2.2?
  94.     jz    oldone    ;yes.
  95.     push    psw    ;save value
  96.     ani    0f0h    ;get high nibble
  97.     rrc
  98.     rrc
  99.     rrc
  100.     rrc        ;into low nibble
  101.     adi    '0'    ;make ascii
  102.     call    co    ;print
  103.     mvi    a,'.'
  104.     call    co
  105.     pop    psw    ;retrieve lower four bits
  106.     ani    0fh    ;mask them
  107.     adi    '0'
  108.     call    co
  109.     call    tb2
  110.     db    13,10,'$'
  111. ;
  112. oldone:
  113.     call    tb2
  114.     db    '1.4',13,10,'$'
  115. ;
  116. ;
  117. tb2:    mvi    c,9    ;print msg function
  118.     pop    d    ;get msg adrs
  119.     call    5    ;print it
  120.     lhld    oldstk    ;restore ccp stack
  121.     sphl
  122.     ret        ;back to the ccp
  123. ;
  124. ;    subroutines
  125. ;
  126. ; Console output routine
  127. ;    prints character in 'a' register
  128. ;
  129. co:    push    h
  130.     push    d
  131.     push    b
  132.     mov    e,a    ;character to e for CP/M
  133.     mvi    c,2    ;print console function
  134.     call    5    ;print character
  135.     pop    b
  136.     pop    d
  137.     pop    h
  138.     ret
  139. ;
  140. ; Decimal output routine
  141. ;    this routine has following
  142. ;    entry and external parameters:
  143. ;
  144. ;       entry:    hl=binary number to print in decimal
  145. ;       external calls: co routine
  146. ;       ** note...this routine is recursive, and uses
  147. ;       6 bytes of stack for each recursive call, in ad-
  148. ;       dition to any stack space used by the co routine.
  149. ;
  150. decout: push    b
  151.     push    d
  152.     push    h
  153.     lxi    b,-10
  154.     lxi    d,-1
  155. ;
  156. decou2: dad    b
  157.     inx    d
  158.     jc    decou2
  159.     lxi    b,10
  160.     dad    b
  161.     xchg
  162.     mov    a,h
  163.     ora    l
  164.     cnz    decout
  165.     mov    a,e
  166.     adi    '0'
  167.     call    co
  168.     pop    h
  169.     pop    d
  170.     pop    b
  171.     ret
  172. ;
  173. stack    equ    $+80    ;40 level stack
  174. ;
  175. oldstk:    ds    2
  176. retword:ds    2
  177.  
  178.     end    base
  179.