home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 15 / bbd15.zip / BITS&PCS.TXT < prev    next >
Text File  |  1987-10-19  |  8KB  |  134 lines

  1. |D╔══════════════════╗════════════════════════════════════════════════════════════
  2. |D║ |5The Happy Hacker |D║════════════════════════════════════════════════════════════
  3. |D╚══════════════════╝════════════════════════════════════════════════════════════
  4.  
  5. ^C^1Bits 'N PC's
  6. ^Cby
  7. ^CGeorge Leritte
  8.  
  9.    This time we have another installment on interfacing assembly language and a
  10. couple of short routines for your BASIC programs, one that's new and one that's
  11. a revision of an earlier routine.  In Turbo Pascal, there is a function for
  12. moving parts of memory from one spot to another.  Sometimes, there is a need for
  13. doing that in BASIC.  Our SMOVE routine does just that, and it does it pretty
  14. quickly, too.  In issue 9, we published a video scrolling routine that used BIOS
  15. interrupt 10 to scroll parts of the screen.  One of our readers complained that
  16. he got lost in the shuffle towards the last part of the discussion.  Admittedly,
  17. passing the variables the way we did it is not the best way to do things, but it
  18. did get the job done.  We will correct it this month with the code in BASIC, the
  19. assembly language source code, and the object file for inclusion in your
  20. compiled BASIC versions.
  21.  
  22.    For those of you who weren't here in Issue 9, I'll offer a short refresher on
  23. BIOS interrupt 10.  BIOS interrupt 10 controls the video services offered on the
  24. IBM PC.  With it, you can set or determine the video mode, set or determine the
  25. cursor location and size, write to the screen, or scroll windows on your
  26. computer and other nice things.  The problem is interfacing them with your
  27. programs.  For the screen scroll routine, the registers are loaded with the
  28. desired values and the interrupt call is performed.  For the interrupt 10
  29. scroll window service, the registers and the information needed is:
  30.  
  31. AH:  6 (for scrolling up) or 7 (for scrolling down)
  32. AL:  number of lines to scroll (0 to clear window)
  33. BH:  attribute to be used for blanked area
  34. CH:  row coordinate of upper left corner of window
  35. CL:  column coordinate of upper left corner of window
  36. DH:  row coordinate of lower right corner of window
  37. DL:  column coordinate of lower right corner of window
  38.  
  39. Note that the row coordinates range from 0 to 24 and the column coordinates
  40. range from 0 to the screen width minus one, not 1 to 25 and 1 to the screen
  41. width as in BASIC.
  42.  
  43.    The implications become obvious.  You can scroll all or part of the screen by
  44. using this interrupt.  From BASIC, once the assembly language is complete, you
  45. load the routine into memory and determine its starting location.  The BASIC
  46. manuals suggest putting it in a location outside BASIC's data space.  This is
  47. fine, as long as you have enough memory.  Today's computers almost always have
  48. at least 256K of RAM, so memory shouldn't be a problem.  However, putting
  49. routines in absolute memory locations can cause problems if you have a lot of
  50. memory resident software, since you cannot guarantee the memory location you
  51. selected will not be in BASIC's data segment anyway.  Since I started doing this
  52. on a 128K machine, and like to have it in BASIC's data space where I can keep an
  53. eye on it, and since it occupies only 22 bytes of memory, I place the routine in
  54. an array variable and use BASIC's VARPTR function to get the starting address of
  55. the routine.  I also don't have to fool with segments using the DEF SEG
  56. statement, since the routine is in the data segment.
  57.  
  58.    You pass the parameters to the routine with the call statement.  If you have
  59. loaded the routine in the array scr%(), the syntax is:
  60.  
  61. scroll%=varptr(scr%(0))
  62. call scroll% (ch%,cl%,dh%,dl%,attribute%,lines%,direction%)
  63.  
  64.    The varptr statement is precautionary because if you define a new variable
  65. (not redefine an old one), the location of the array will move and you will
  66. crash your program.  I put the two statements together in a subroutine and call
  67. it when needed.  Also note the parameters passed are integers.  The subroutine
  68. is expecting integers and you must define them with the type identifer % or with
  69. a defint statement at the beginning of your program.  The first four variables
  70. in the example line correspond to the register values needed for the interrupt
  71. and the last three are the attribute to be used in the blank window, the number
  72. of lines to scroll, and the direction to scroll the window.  If the routine
  73. doesn't work, the first place to check is the order and value of the parameters
  74. you're passing.  Check the sample program on the disk to see how I've done it.
  75.  
  76.    In a compiled program, you simply use the call scroll statement and compile
  77. your program to object code, then link it with the command LINK PROGNAME+SCROLL.
  78. This is why the object code to the routine is on the disk and also why the line
  79. 'public scroll' is in the assembly listing.  This tells the link program that
  80. the name SCROLL is an external routine.  I used this routine in the conversion
  81. of Rock and Roll Quiz for this issue.
  82.  
  83.    The SCROLL.BAS file on this disk is the interpreted BASIC source code for a
  84. demo.  The SCROLL.ASM file is the source code for the assembly language routine,
  85. and the SCROLL.OBJ is the object code needed for use with a compiler.
  86.  
  87.    Sometimes you may have a need for moving data from one place to another
  88. quickly and for..next loops are just too slow.  The solution is our SMOVE
  89. routine.  SMOVE means short move--memory moves within the data segment.  I've
  90. written a long move version--moves anywhere in memory, but it's too easy to
  91. crash the computer with it, so, I'm sorry to say, you won't see it here.  If you
  92. like you can modify SMOVE, but any crashes are your fault.
  93.  
  94.    SMOVE uses the MOVS assembly language instruction.  MOVS means 'Move String'.
  95. There are two versions, MOVSB and MOVSW, move string-bytes and move string-
  96. words.  If you load register CX with the number of bytes or words to move, you
  97. can move sections of memory very quickly with REP MOVS.  Don't worry about the
  98. 'string' label.  They had to call it something.
  99.  
  100.    For arguments sake, let's say you had a large array of numbers to fill with a
  101. repeating sequence of numbers.  You could do it with code like this:
  102.  
  103. 10 dim t%(1999)
  104. 20 for i=0 to 49
  105. 30 for j=0 to 39: t%(I*50+j)= j+1: next j
  106. 40 next i
  107.  
  108. If you created a small array of 40 elements, and then copy repeatedly the small
  109. array into the larger, you could load the large array quicker.  With SMOVE, you
  110. can do this 12 to 13 times quicker than the above code.
  111.  
  112.    With the routine loaded in the sm%() array and the data you want to move in
  113. the f%() array, the syntax of SMOVE is:
  114.  
  115. smove%=varptr(sm%(0)): from_offset%=varptr(f%(0)): to_offset%=varptr(t%(0))
  116. call smove% (from_offset%,to_offset%,no_bytes%)
  117.  
  118.    The variables from_offset% and to_offset% are the memory locations of the
  119. data you are moving.  To change the destination in the array, change the index
  120. of the t%() variable.  The variable, no_bytes%, is the number of bytes to move.
  121. See the sample program on this disk.
  122.  
  123.    As with SCROLL, the variables being passed must be integers.  Also, limit the
  124. definitions of new variables between calls.  The assembly language source code
  125. and the object code is on disk.  Use the object code with your compiled programs
  126. just like the example for SCROLL.
  127.  
  128.    The SMOVE.BAS file on this disk is the interpreted BASIC source code for a
  129. demo.  The SMOVE.ASM file is the source code for the assembly language routine,
  130. and the SMOVE.OBJ is the object code needed for use with a compiler.
  131.  
  132.    Well, that's all for now.  If you come up with any interesting uses for these
  133. routines, let us know.  Happy computing.
  134.