home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HISOFT.LZH / HISOFT_B.MSA / LIBS / LIBDEMO.S < prev    next >
Text File  |  1987-09-15  |  4KB  |  171 lines

  1.     opt    l+,c+
  2.  
  3. *
  4. *    HiSoft BASIC demo library ╜ HiSoft 1987
  5. *    version 1.1
  6. *
  7. *    SCS
  8. *
  9. * This library is an example of the procedure to follow when writing a user
  10. * library. These are several routines which use all of the features and
  11. * functions available to the user libraries.
  12. *
  13. * This library was written using DevpacST, the HiSoft assembly language
  14. * development system.
  15.  
  16.  
  17.     include    library.h    the standard library include file
  18.  
  19.     library    STUFF        library name
  20.  
  21.     xref    get_string    external references
  22.     xref    get_array
  23.     xref    make_string
  24.     xref.l    gl_scratch    this is referenced off global!
  25.  
  26.     xdef    setbit        the names of the routines in the library
  27.     xdef    getbit
  28.     xdef    straint
  29.     xdef    baint
  30.     xdef    nullterm
  31.  
  32.     subdef    int,vlng    setbit takes an int and a long-variable
  33.     fn_int    int,lng        getbit function returns an int
  34.     subdef    str,aint,lng    straint takes a string, array of ints
  35. *                and a long
  36.     subdef    aint,aint,lng    baint takes 2 arrays of ints and a long
  37.     subdef    vstr        nullterm takes a string-variable
  38.  
  39.     option    'uv'        underlines & variable checks
  40.  
  41.     libstart        the code follows
  42.  
  43.  
  44. *
  45. * This statement takes an int and a long as parameters and sets the bit
  46. * specified by the int in the long.
  47. *
  48.  
  49. setbit    move.l    4(sp),a0    pointer to the long
  50.     move.l    (a0),d1        the long to be set
  51.     move.w    8(sp),d2    which bit?
  52.     ext.l    d2        paranoia
  53.     bset.l    d2,d1        set the bit
  54.     move.l    d1,(a0)        return the value to the variable
  55.     rts
  56.  
  57.  
  58. *
  59. * This function takes an int and a long and checks if the bit specified by
  60. * the int is set in the long. 0 is returned if not, -1 if the bit is set.
  61. *
  62.  
  63. getbit    move.l    4(sp),d1    the long to be tested
  64.     move.w    8(sp),d2    which bit?
  65.     ext.l    d2        paranoia
  66.     btst.l    d2,d1
  67.     beq.s    nope        bit is cleared
  68.     moveq    #-1,tos        set
  69.     rts
  70. nope    moveq    #0,tos        not set
  71.     rts
  72.  
  73.  
  74. *
  75. * This routine copies a string into an array of integers.
  76. *
  77. * The descriptors of the string and array are passed, as well as the number
  78. * of bytes to be copied. Checks are made as to the length of the string and
  79. * array, as well as to the number of dimensions in the array.
  80. *
  81. * get_string is used to access the string, get_array to access the array
  82. *
  83.  
  84. straint    move.l    4(sp),d5    how many bytes to move
  85.     move.l    12(sp),a0    string descriptor
  86.     bsr    get_string
  87.     move.l    a1,-(sp)    save string address
  88.     cmp.l    d4,d5        is amount to move > string?
  89.     ble.s    oklen        no
  90.     move.l    d4,d5        string isn't as long as he says
  91.  
  92. oklen    move.l    12(sp),a0    array descriptor
  93.     moveq.l    #1,d0        one dimension only
  94.     bsr    get_array
  95.     cmp.l    d4,d5        is source > target?
  96.     ble.s    oktrg1        no
  97.     move.l    d4,d5        target's not big enough
  98.  
  99. oktrg1    move.l    (sp)+,a1    pop string address
  100.     subq.l    #1,d5        dbf!
  101.  
  102. shovel    move.b    (a1)+,(a2)+
  103.     dbf    d5,shovel
  104.     rts
  105.  
  106.  
  107. *
  108. * This routine copies bytes from an array of integers into seperate
  109. * elements of a target array of ints.
  110. *
  111. * This is useful if an array of ints has been used as a buffer, and the
  112. * byte data needs sorting out. Checks are made as to the length of the
  113. * source and target arrays, as well as to the number of dimensions in
  114. * the arrays.
  115. *
  116. * get_array is used to access the arrays
  117. *
  118.  
  119.  
  120. baint    move.l    4(sp),d5    get the number of bytes to move
  121.  
  122.     move.l    12(sp),a0    the source array descriptor
  123.     moveq    #1,d0        only 1 dimension
  124.     bsr    get_array
  125.     cmp.l    d4,d5        check for size
  126.     ble.s    oksrc
  127.     move.l    d4,d5    
  128. oksrc    move.l    a2,-(sp)    1st element of source
  129.  
  130.     move.l    12(sp),a0    the target array
  131.     moveq    #1,d0        only 1 dimension
  132.     bsr    get_array
  133.     cmp.l    d4,d5
  134.     ble.s    oktrg
  135.     move.l    d4,d5        it's not big enough
  136.  
  137. oktrg    move.l    (sp)+,a1    pop source array
  138.     subq.l    #1,d5        dbf!
  139.  
  140. shovel2    addq.l    #1,a2
  141.     move.b    (a1)+,(a2)+
  142.     dbf    d5,shovel2
  143.     rts
  144.  
  145.  
  146. *
  147. * This routine takes a string, null terminates it, and returns the string
  148. *
  149. * Uses get_string, gl_scratch, make_string
  150. *
  151.  
  152. nullterm
  153.     move.l    4(sp),a0    get the descriptor
  154.     bsr    get_string
  155.     cmp.l    #128,d4        check for size
  156.     blt.s    oksiz
  157.     moveq    #127,d4        reduce size to fit
  158. oksiz    lea    gl_scratch(global),a0
  159.     move.l    a0,a2        save address of copy
  160.     move.w    d4,d5        save string length
  161.     subq.w    #1,d4        subtract 1 for dbf
  162. loop    move.b    (a1)+,(a0)+    copy string
  163.     dbf    d4,loop
  164.     move.l    a2,a1
  165.     move.w    d5,d4
  166.     clr.b    0(a1,d4.l)    null-terminate string
  167.     addq.w    #1,d4        a byte was added
  168.     move.l    4(sp),a0    the descriptor is needed
  169.     bra    make_string    return the string to the variable & then
  170. *                back to BASIC
  171.