home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MAGAZINE / MISC / QBNWS203.ZIP / SPRITE.ZIP / G13UTIL.BAS
Encoding:
BASIC Source File  |  1991-09-16  |  5.9 KB  |  168 lines

  1. DEFINT A-Z
  2. '$DYNAMIC
  3. DECLARE SUB changeclr (ary(), oclr, nclr)
  4. DECLARE SUB mirror (ary(), bry())
  5. DECLARE SUB superimp (ary(), xpos, ypos, mode)
  6. DECLARE SUB scrollup (ary(), xpos, ypos)
  7.  
  8. '***************************************************************************
  9. '                       SCREEN 13 GRAPHIC UTILITIES                                                                 
  10. '                            by FRED SEXTON JR.                                     
  11. '  CHANGECLR
  12. '     Searches an image array for a color and changes it to a
  13. '     different color.
  14. '     syntax =>  CALL changeclr(array(),oldcolor,newcolor)
  15. '
  16. '  MIRROR
  17. '     Returns a mirror image of first array in second array.
  18. '     ****DIMENSION BOTH ARRAYS TO THE SAME SIZE****
  19. '     syntax =>  CALL mirror(array1(), array2())
  20. '
  21. '  SUPERIMP
  22. '     Puts a graphic image at specified location.
  23. '     Depending on setting of mode varible the image
  24. '     is either put in front of or behind the images
  25. '     that exist on the screen.
  26. '     syntax =>  CALL superimp(array(), xpos, ypos, mode)
  27. '                mode = 0  => put in front
  28. '                mode = 1  => put behind
  29. '
  30. '  SCROLLUP
  31. '     Scrolls a graphic image up onto the screen ending up
  32. '     at specifeid location.
  33. '     syntax =>  CALL scrollup(array(), xpos, ypos)
  34. '
  35. '
  36. '***************************************************************************
  37.  
  38. SUB changeclr (ary(), oclr, nclr)
  39.  
  40. xwidth = ary(0) \ 8                     'get x-axis width
  41. yheight = ary(1)                        'get y-axis height
  42.  
  43. bytes& = CLNG(xwidth) * CLNG(yheight)   'find # of bytes in image
  44.                                         'while avoiding overflow error
  45.  
  46. DEF SEG = VARSEG(ary(2))                'set the segment
  47. aofs = VARPTR(ary(2))                   'get starting offset
  48.  
  49. FOR t& = 0& TO bytes& - 1               'search the required # of bytes
  50.  IF PEEK(t& + aofs) = oclr THEN POKE t& + aofs, nclr   'change as needed
  51. NEXT
  52.  
  53. END SUB
  54.  
  55. SUB mirror (ary(), bry())
  56.  
  57. bry(0) = ary(0)                         'make bit width the same
  58. bry(1) = ary(1)                         'make height the same
  59.  
  60. xwidth = ary(0) \ 8                     'get x-axis width
  61. yheight = ary(1)                        'get y-axis height
  62.  
  63. aseg = VARSEG(ary(2))                   'get the segment of array1
  64. aofs = VARPTR(ary(2))                   'get the offset of element 2
  65. bseg = VARSEG(bry(2))                   'get the segment of array2
  66. bofs = VARPTR(bry(2)) + xwidth - 1      'get the offset to start at
  67.  
  68.  
  69.                                         'the two sets of "FOR:NEXT
  70.                                         'will effectively step thru array1
  71.                                         'byte by byte
  72. FOR t = 1 TO yheight
  73.  FOR tt = 0 TO xwidth - 1
  74.     DEF SEG = aseg
  75.     value = PEEK(aofs + tt)             'get a value from array1
  76.     DEF SEG = bseg
  77.     POKE bofs, value                    'put it into array2
  78.     bofs = bofs - 1
  79.   NEXT
  80. aofs = aofs + xwidth                    'setup offsets for next row
  81. bofs = bofs + (xwidth * 2)
  82. NEXT
  83.                                         'return to default segment
  84. DEF SEG
  85.  
  86. END SUB
  87.  
  88. SUB scrollup (ary(), xpos, ypos)
  89.  
  90. yheight = ary(1)                      'get yaxis height
  91. ypos = ypos + yheight                 'setup starting ypos value
  92.  
  93. FOR t = 1 TO yheight
  94.   ary(1) = t                          'modify the value that PUT will use
  95.   ypos = ypos - 1                     'move ypos up one row
  96.   PUT (xpos, ypos), ary, PSET         'put image to screen
  97.  
  98.   SOUND 32767, 2                      'use your favorite method to create
  99.                                       'a delay here
  100.                                       '(I use an routine I wrote in
  101.                                       '            MASM but this will work)
  102. NEXT
  103.  
  104. END SUB
  105.  
  106. SUB superimp (ary(), xpos, ypos, mode)
  107.  
  108. DIM wry(UBOUND(ary))                  'dim a work array the same size
  109.  
  110. xwidth = ary(0) / 8                   'get x-axis width
  111. yheight = ary(1)                      'get y-axis height
  112.  
  113. GET (xpos, ypos)-(xpos + xwidth - 1, ypos + yheight - 1), wry
  114.                                      
  115.                                   'get the target area of screen in work array
  116.  
  117.  
  118. IF mode = 0 THEN                      'mode 0 means put in front
  119.  
  120.  FOR t = 2 TO UBOUND(ary)             'search the source array
  121.  
  122.   DEF SEG = VARSEG(ary(t))            'starting with element 2
  123.   lb = PEEK(VARPTR(ary(t)))           'get the lower byte
  124.   ub = PEEK(VARPTR(ary(t)) + 1)       'get the upper byte
  125.  
  126.   IF lb <> 0 THEN                     'if soucre array isn't zero
  127.    DEF SEG = VARSEG(wry(t))
  128.    POKE VARPTR(wry(t)), lb            'put it into work array
  129.   END IF
  130.  
  131.   IF ub <> 0 THEN                     'same thing for upper byte
  132.    DEF SEG = VARSEG(wry(t))
  133.    POKE VARPTR(wry(t)) + 1, ub
  134.   END IF
  135.  
  136.  NEXT
  137.  DEF SEG                              'return to default segment
  138.  
  139. ELSE                                  'nonzero mode means put behind
  140.  
  141.  FOR t = 2 TO UBOUND(wry)             'search work array
  142.   DEF SEG = VARSEG(wry(t))            'starting with element 2
  143.   lb = PEEK(VARPTR(wry(t)))           'get lower byte
  144.   ub = PEEK(VARPTR(wry(t)) + 1)       'get upper byte
  145.  
  146.   IF lb = 0 THEN                      'if work value is zero
  147.    DEF SEG = VARSEG(ary(t))           'get corresponding byte
  148.    lb = PEEK(VARPTR(ary(t)))          'from source array
  149.    DEF SEG = VARSEG(wry(t))           'put it into work array
  150.    POKE VARPTR(wry(t)), lb
  151.   END IF
  152.  
  153.   IF ub = 0 THEN                      'same thing for upper byte
  154.    DEF SEG = VARSEG(ary(t))
  155.    ub = PEEK(VARPTR(ary(t)) + 1)
  156.    DEF SEG = VARSEG(wry(t))
  157.    POKE VARPTR(wry(t)) + 1, ub
  158.   END IF
  159.  
  160.  NEXT
  161.  DEF SEG                              'return to default segment
  162. END IF
  163.                                      
  164. PUT (xpos, ypos), wry, PSET           'put the resulting array on screen
  165.  
  166. END SUB
  167.  
  168.