|
01/27/99
|
|
|
|
|
Putting pixels on screen 13
Getting a 64Kb String
Assigning Colors
Memory Access Speed Up
Timing/Delays
Music and Sound effects
|
|
| Tips'n Tricks by: MRS
Subject: Putting pixels on screen 13 There are many ways of putting a pixel on the screen. But I have found that, when it comes to speed, the PSET command is about the fastest there is. The POKE command also makes it possible to draw directly to the screen using this bit of code: DEF SEG = &HA000
This code is similar to PSET, also the speed is about the same, but the code can be optimized: DEF SEG = &HA000 + (20 * Y%)
The advantage of this code is that it can be used on any segment in memory. To use this code to manipulate a 64000b screen buffer, just change the &HA000 segment to your buffer segment. But be careful one wrong step can be fatal. |
|
|
| Tips'n Tricks by: MRS
Subject: Getting a 64Kb String By using a 64Kb string you can easily load a 320x200 picture from a file into memory. This code will allocate the string: TYPE DoubleBuffer
REDIM BigBuffer(0) AS DoubleBuffer As you can see the buffer "BigBuffer(0)" is actually two buffers, just ignore that. To load a picture into the buffer just open a file in BINARY mode and set the filepointer to where the picture begins. You can load a picture from anywhere in the file using GET and PUT, and you can have more then one picture in the same file. To load the picture from the buffer to the screen you have to use assembly code and that is another trick. |
|
|
| Tips'n Tricks by: MRS
Subject: Assigning Colors By using the PALETTE statement you can assign your own colors. The number of attributes depends on the screen mode you have selected, in Screen 12 you have 16 attributes to work with, and in Screen 13 you have 256. When selecting a screen mode, all attributes are set to the most common used colors, attribute 0 is black, attribute 1 is blue and so on. If you what to change attribute 0, in mode 13, from black
SCREEN 13
Why 63? you may ask. Well - every color on your screen is represented by a unique number, that means that only that color have that number. There are more than one rule of generating a color, but the VGA adapter uses RGB (Red,Green,Blue) to generate it. In the QB environment the range of the three components are 0-63, where 63 is the brightest. The information on the three components have to be made into a unique number before Qbasic can use it. Here is how to do just that: uniquenum& = (0 to 63)(R) + (&h100 * (0 to 63))(G) + (&h10000*(0 to 63))(B) or uniquenum& = &h00003F 'Red
The number of unique colors to generate are 64 * 64 * 64 = 262144. The PALETTE USING statement allows you to set all the color attributes. In screen 13 the code is something like this: SCREEN 13
CLUT&(0)= &h000000
PALETTE USING CLUT&(0) This will take 1-2 sec. to load the new palette and that is not fast enough, if you want to do something like Fading or Cycling. Therefor I will mention another way of doing the same thing. SCREEN 13
Now you don't have to think of generating a unique number. Just think in the range of 0-63 for the three components RGB. CLUT%(0 , 0)= 63'R
CLUT%(0 , 1)= 13'R
CLUT%(0 , 255)= 0'R
OUT &H3C8, 0 'start loading at attribute 0
|
|
|
| Tips'n Tricks by: MRS
Subject: Memory Access Speed Up If you don't use XMS/EMS memory in your program, try removing your MemoryManager from memory. I got a 200% speed up on some of my programs. |
|
|
| Tips'n Tricks by: MRS
Subject: Timing/Delays Setting up a delay timer is actually very simple. Normally the computers timer is updated at a frequency of 18.2 Hz. That means that the TIMER function also have a resolution of 18.2 Hz. Here is an example of how to use the TIMER function as a delay: SUB delay(Var!)
Because of the clock resolution the minimum possible delay is 0.055s. You can change the clock frequency to get a better resolution, but then the TIMER function will not be working properly. One way of getting a delay below the 0.055s is by changing the clock tick frequency. This code will change the clock tick speed to any frequency: SUB ChangeClockTickSpeed(Frequency!)
When you change the clock tick speed the computers time will be wrong, and will only be reset if the computer is restarted. Changing the clock tick frequency under windows does not have any effect, it will always be 18.2 Hz. Also before you exit your program remember to reset the frequency to 18.2 Hz. You can get the clock ticks by reading memory location 40:6C. Here is an example: SUB WaitClockTicks(Ticks&)
Now how does this work. Well lets assume the clock tick speed was changed to 100 Hz, writing WaitClocksTicks 100 will then wait 1 sec. and writing WaitClocksTicks 1 will wait 1/100 sec. For higher clock frequencies the code may take longer to execute then the actual delay. So you may want to rewrite the code for more sensitive timing. |
|
|
| Tips'n Tricks by: MRS
Subject: Music and Sound effect The only way QBasic is able of producing sound is through the pc speaker.
The PLAY statement helps you make the sound using the common note system.
When the PLAY statement is used, the string send is placed into a buffer
from where it is played. The buffer can hold up to 32 notes at the same
time. That is useful if you want to play sound/music in the background
and do something else in the foreground.
PLAY "MB" makes QBasic go into background mode, in background mode both PLAY and SOUND is played in the background. SOUND can also be used to stop all sound/music that is currently being played in the background, simply by sending a sound duration of zero to the speaker (SOUND 0,0) To play music in the background you have to set up an event trapping system. When ever a certain amount of notes have been played the event trapping system will jump to a sub routine, and reload the play buffer. See the eksample on how to use an event trapping system to play music in the background: backmsc.zip |
|
|
MRS