home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / C80 / C80FNS.C < prev    next >
Text File  |  2000-06-30  |  4KB  |  173 lines

  1.  
  2.  
  3. /* A few non-redundant functions from Harvey G. Lord's C80LIB.C, for
  4.    the Software Toolworks C/80 Version 3.1 C compiler, including:
  5.  
  6.    char    bios(call_number,register_c_value)
  7.    char peek(addr)
  8.     poke(addr,char_value)
  9.    char inp(port_number)
  10.     outp(port_number,char_value)
  11.     pause()                         -- wait for keyboard activity
  12.     sleep(tenths_of_second_value)   -- interruptible by kbhit, 4 mHz(?)
  13.     kbhit()                         -- true iff keypress
  14.  
  15.  
  16.    H.G.L's original header refers to C/80 Version 2.  Note that C/80 v3.1,
  17.    the Software Toolworks current version (8-25-84), contains a very nice
  18.    standard library with functions which make nearly all of the HGL library
  19.    obsolete, at this point.  The full C80.LBR for the Toolworks' version 2
  20.    is still available on the Royal Oak Technical RCPM (where it is a
  21.    "squeezed" LBR!), and maybe on the Acropolis board in Georgia.  HGL's
  22.    library is the major part of that LBR, which also contains the originals
  23.    of RANDI1.C and RANDI2.C, plus a nearly incomprehensible (undocumented,
  24.    non-recursive, inaccurately described as the program in K&P's Software
  25.    Tools) version of quicksort.  The time required to download the squeezed
  26.    LBR at Royal Oak makes the final package disappointing; it is not worth
  27.    the expense, now that Toolworks is shipping version 3.1.
  28.  
  29.    These functions are passed on in exactly the same form as I found them.  No
  30.    warranty expressed or implied, except that they have survived the scrutiny
  31.    of numerous sysops since at least April of 1983.
  32.                     --David C. Oshel
  33.                       1219 Harding Ave.
  34.                       Ames, Iowa 50010
  35.                       August 25, 1984
  36.  
  37.    Original header:
  38.  
  39.        Standard library of C functions       
  40.         for C/80 (Software Toolworks)        (... Bilofsky's is STDLIB.C)
  41.  
  42.  
  43.  
  44.     NOTE:  C/80 requires that you pass the
  45.     number of arguments to a function that
  46.     the function expects. If you only need
  47.     to pass one argument, but the function
  48.     was  written for two,  pass a null for
  49.     the other. Without the second argument
  50.     C/80 bombs.                               (... still true! -dco)
  51.                 Harvey G. Lord  
  52. */
  53.  
  54. /* abbreviated library follows -dco, 8/25/84 */
  55.  
  56. char bios(n,c) /* calls bios function number n */
  57. int n,c;
  58. {
  59.     /* get bios address + function # times 3 */
  60. #asm
  61.     JMP .begin
  62. .addr:    DW 0
  63.  
  64. .begin:    POP H    ; save return address
  65.     SHLD .addr
  66.  
  67.     POP B    ; 1st arg into c
  68.     POP D    ; get function #
  69.     LXI H,.retadd
  70.     PUSH H    ; put return addr on stack
  71.  
  72.     LHLD 1    ; get bios vector
  73.     DCX H
  74.     DCX H
  75.     DCX H
  76.     DAD D    ; times 3, add to vector
  77.     DAD D
  78.     DAD D
  79.     PCHL    ; jump to bios vector
  80.  
  81. .retadd: LHLD .addr ; restore stack
  82.     PUSH B
  83.     PUSH B
  84.     PUSH H
  85.     MOV L,A    ; return argument in hl
  86.     MVI H,0
  87. #endasm
  88. }
  89.  
  90. char peek(n) /* return the contents of address n */
  91.     char *n; {
  92.     return(*n);
  93. }
  94.  
  95. poke(n,b) /* "poke" byte value b into address n */
  96.     char *n,b; {
  97.     *n = b;
  98. }
  99.  
  100. char inp(n) /* return byte value from port n */
  101. int n; {
  102. #asm
  103.     INX SP ; past return address
  104.     INX SP
  105.     POP H  ; port number
  106.     MOV H,L
  107.     MVI L,0DBH ; input op code
  108.     SHLD .port
  109.  
  110. .port:    DW 0   ; opcode & port go here, then .port is executed (dco)
  111.  
  112.     MVI H,0
  113.     MOV A,L
  114.     PUSH H
  115.     DCX SP ; return address
  116.     DCX SP
  117. #endasm
  118. }
  119.  
  120. outp(n,b) /* send byte value b to port n */
  121.     int n,b; {
  122. #asm
  123.     INX SP ; past return addr
  124.     INX SP
  125.  
  126.     POP H ; value
  127.     MOV A,H
  128.     POP H ; port
  129.     MOV H,L
  130.     MVI L,0D3H ; out op code
  131.     SHLD .oport
  132.  
  133. .oport: DW 0 ; opcode & port go here, then .oport is executed (dco)
  134.  
  135.     PUSH H ; restore stack
  136.     PUSH H
  137.     DCX SP
  138.     DCX SP
  139. #endasm
  140. }
  141.  
  142. pause() /* sit and wait until the keyboard is hit */
  143. {
  144.     while(!kbhit());
  145. }
  146.  
  147. sleep(n) /* sleep for n/10 seconds */
  148. int n; {
  149.     int i,j,k;
  150.     for(i=0; i!=n; ++i){
  151.         for(j=0; j!=10; ++j){
  152.             for(k=0; k!=0xAF; ++k);
  153.             if(kbhit()){ getchar(); exit();}
  154.         }
  155.     }
  156. }
  157.  
  158. kbhit() /* return true if a character is waiting at 
  159.     the console */
  160. {
  161.     return(bdos(11,0)); /* console status */
  162.  
  163. /* 
  164.  
  165. kbhit() also works as a bios call. In that case it's
  166.  
  167.     return(bios(2,0));
  168.  
  169.                 H.G.L.
  170. */
  171.  
  172. }
  173.