it's...
The Basix Fanzine
issue 12 september/october 1998

 

email: basix@dewarr.globalnet.co.uk
www: http://come.to/basixfanzine

[ Basix Fanzine Main Index ]


Welcome to issue 12 of the Basix Fanzine, now bigger and more colourful than ever! You'll notice that this is the "September/October 1998" issue - I'm trying to release this thing more regularly, and at first I'll be aiming for a bi-monthly issue. It would be nice if I could release it monthly, but I'm not sure if I'll ever have the time or get enough submissions for that to be possible. Anyway, on with the show.

In this issue: improve your programming skills... include data in an EXE file... encrypt files... and relieve boredom!

Hope you like the new, more colourful, more graphical look! I created the graphics myself - maybe you can tell.


Levels are represented in bold by B, I or A for Beginner, Intermediate and Advanced respectively, or a combination. They aren't clear-cut definitions though, so you might find something useful labelled (B) even though you've been programming for 10 years, for example. Unless otherwise stated, the articles apply to all major breeds of BASIC.

Most of these links point to parts of this HTML document, although some may point to other HTML files in the Basix Fanzine directory. Each article has a link back to this contents section to save you the bother of scrolling back.

 

basix fanzine issue 12
SECTION CONTENTS
news COMP.LANG.BASIC.POWERBASIC PASSES
The proposed comp.lang.basic.powerbasic newsgroup is a reality!

NEW ABC MIRROR
The ABC packets now have a mirror in the UK. Which is nice.

articles FONTS: AN ALTERNATIVE GRAPHIC
Regular contributor RudeJohn ponders upon the subject of fonts.

GRAPHICS IN QBASIC TUTORIAL (PART 3) (I/A)
"Hacker" aka Damian Nikodem rounds off his graphics series with a look at randomic algorithms.

INTERMEDIATE PROGRAMMING TIPS (PART 1) (I)
Alex Warren takes a look at variable types and screen-page swapping.

INCLUDING FILES IN EXEs (I/A)
Ollie Cook demonstrates a method of including data files within your EXE file.

TEN ODD MOMENTS
RudeJohn's amazing list of "things to do", for bored programmers.

BACKUS-NAUR FORM (A)
RudeJohn presents an introduction to the Backus-Naur Form.

your programs DETECTING THE PARALLEL PORT
by Juan F. Miguez

BINARY FILE ENCRYPTION
by Daniel Bolger

CONTROL+BREAK DISABLER
by Daniel Bolger

"A SCREENSAVER TYPE THING"
by Mike Anderson

letters PROGRAMS, MIDI & INP
from Daniel Bolger
final words LAST WORDS, THANKS ETC.

NEXT ISSUE

main index internet resources

 

(The "From the Newsgroups" section is on holiday...)

 



the latest news in the BASIC world

 

COMP.LANG.BASIC.POWERBASIC PASSES

The proposed comp.lang.basic.powerbasic newsgroup passed its vote, with 149 "yes" votes to 14 "no" votes. 100 more "yes" than "no" votes were required, and two thirds had to be in favour in order for the group to be created - and that has happened, so comp.lang.basic.powerbasic should be hitting your news server soon!

 

NEW ABC MIRROR

There is a new mirror for the ABC packets in the UK, available at http://www.cvnet.co.uk/o.cook/abc. The site also includes several useful links so is worth a look anyway, even if you don't need the packets.

[ Back to Contents ]

 

Got a BASIC news article?
pleeease?

Opening a website? Want to announce a new product that will benefit BASIC programmers? Want to reach hundreds of readers for free? Then send your press release to basix@dewarr.globalnet.co.uk NOW!

[The editor reserves the right to edit or omit articles recieved for publication - if you want an advert rather than a news article, read on.]

 



enhance your programming - this is the place to learn BASIC tips, techniques and tricks!

 

GRAPHICS IN QBASIC TUTORIAL (PART 3), by "Hacker" aka Damian Nikodem Hacker@alphalink.com.au

Intro :
Today I will cover RANDOMIC ALGORITHMS. You will probably be asking yourself what are they and how will they improve the graphics in my programs. Well randomic algorythms add a twist of reality to your graphics. Take a look around you is everything around you in total order is there NO light shining off ANYTHING near you. If you notaice nearly everything has a random element. So this is where I will base my tutorial on today.

Grass Routine:
Now lets just say that your writing a RPG and you have to write a graphics routine. It most likeley looks kinda like this (asuming you are doing a 15x15 tileset)

'Start CODE
SCREEN 13
LINE (1,1)-(15,15),2 , BF
'END CODE

Well try this little program instead [ 12-rnd1.bas ]

'Start CODE
SCREEN 13
RANDOMIZE TIMER
FOR x = 1 TO 15
FOR y = 1 TO 15
z = INT(RND * 2) + 1
IF z = 2 THEN z = 10
IF z = 1 THEN z = 2
PSET (x, y), z
NEXT y
NEXT x
'END code

Does that look a bit better? It should. But its still missing something isnt it, it dosent have enough colors. Because we are using VGA mode 13h(Screen 13) we have 255 colors to play with theres bound to be at least 1 GREEN! WAIT. there is also dirt on the ground so we have to add BROWN and if you look almost always there is about 2 browns before a green so here is a small EDIT of the program above [ 12-rnd2.bas ]

'Start CODE
SCREEN 13
RANDOMIZE TIMER
FOR x = 1 TO 15
FOR y = 1 TO 15
z2 = INT(RND * 8) + 1
z = z2 + 186
PSET (x, y), z
NEXT y
NEXT x
'End CODE

Now do you see the benifits of randomized graphics. If you downloaded quake2 unzip it and play it. While you are doing that take a look at some of the graphics they look fuzzy (Unless you have a 3d card). If the graphics werent fuzzy they would look hopeless. Because of the time that it would take to "smooth" the graphic. So if you have some kind of graphic that dosent look quite right try stuffing around with the colors for a bit if done properly it will look ok if not good.

This is the end of what is going to be the last tutorial in this series because I dont have enough time to write them. But eventually I might be able to write another tutorial series on sound or even 3d calculations (pick up
where the other guys one left off)

- Hacker (Hacker@alphalink.com.au)

[ Back to Contents ]

 

INTERMEDIATE PROGRAMMING TIPS (PART 1), by Alex Warren alexwarren@writeme.com

I hope this will become a fairly regular feature of the fanzine, designed to help those programmers who have only been programming in BASIC for a little while to improve their programs.

The trouble with the term "intermediate" is that it is rather vague - in this series I'll classify an "intermediate" programmer as one who can make a program and knows the really basic things such as file I/O, simple graphics, etc., and would like to make their programs better (faster, more user-friendly, easier-to-read, or whatever else a "better" program is)

I'm not sure how many parts this series will have, nor what it exactly it will cover - if anyone has any ideas or would like to donate a tip or two, please feel free to send some in.

Anyway, are you sitting comfortably? Then I'll begin.

TIP 1: VARIABLES AND USER-DEFINED VARIABLE TYPES

This is two tips in one really...

We all know what a variable is (I hope) and we all know that they come in several delicious flavours - strings, integers, long integers, and floating-point variables, for example, which each have their own uses. As a programmer, you should know the best circumstances in which to use each variable type as there are differences between them in terms of speed and in what they can store.

Obviously, a string is pretty much self-explanatory, and you would never (I hope) use it to store a number (other than a phone number etc. which would need formatting). It is up to you to decide when to use the other types of variable. By default, BASIC will choose a floating-point variable if you don't specify which type the variable is going to be, and this will really slow your program down if it is doing a lot of calculations that don't require that kind of precision. If your variable is never going to store anything with a decimal point, declare it to be an integer and it will work more quickly.

If you're lazy, the easiest way to make BASIC use integers by default instead of floating-point variables is to stick

DEFINT A-Z

at the beginning of your program. Better though, would be to explicitly state the variable type, and you can do this in two ways:

integ% = 3

would set an integer variable called "integ%" to 3, as you should know. Or, you could use:

DIM integ AS INTEGER
integ = 3

This would set an integer variable "integ", without a percent sign, to 3.

Which method you choose is up to you - if you have a large program it may be better to use the second method as then you will be able to change the variable's type by changing one word, without having to go all through the program changing the % signs to # signs, or whatever.

Integers are the fastest variable types but they have disavantages. Apart from the obvious fact that they can't contain anything with decimal places, they also cannot store numbers greater than 32767 or less than -32768. (if you try to set integ% to 40000 you get an "Overflow" error). If you need bigger integer numbers, use a long integer. This can hold values from -2,147,483,648 to +2,147,483,647 and takes up twice as many bytes of memory as a short integer, and therefore will be a bit slower.

The various variable types, their limits and their memory requirements should be discussed in more detail in the help file or manual for your particular flavour of BASIC.

Visual Basic for Windows adds a few more flavours such as a Boolean one, which can be either True or False, and a Variant, which can be just about anything. If you have a BASIC compiler that is more modern than QuickBasic, you should have a few more too, such as a currency type for example - have a look through the types which are available, and see which types will suit your data best.

"User-defined" variable types are very useful. These are basically blocks of other variables all stuck together. The following code shows an example of their use:

TYPE persontype
thename AS STRING * 50
phonenumber AS STRING * 20
numberofhouses AS INTEGER
salary AS LONG
height AS SINGLE
END TYPE

DIM people(5) AS persontype

people(1).thename = "Bill Gates"
people(1).phonenumber = "1234-567-890"
people(1).numberofhouses = 353
people(1).salary = 500000000
people(1).height = 1.96

(All figures made up, in case you hadn't guessed... though maybe they aren't all that far from the truth <g>)

As can be seen, a variable called "people" of type "persontype" is created, with five elements. This only needs to be done once - so you don't need to DIM arrays for thename, phonenumber, numberofhouses, etc., and it can be clearly seen from the code that the phonenumber and salary are related to the same thing (in this case, our old mate Bill). This is more readable than setting phonenumber(1)="1234-567-890" and height(1)=1.96, etc., for example.

It also has the advantage that we can quickly, easily and efficiently copy all the data to another person or record. If you add the line

people(2) = people(1)

and then read the value of people(2).salary, you will see that all five pieces of data have been copied with this single statment. This is ever so much easier than having five statements such as numhouses(2)=numhouses(1) which would have been necessary had we not used user-defined types. So, as you can see, user-defined types can make life a lot, lot easier, especially if you are dealing with large amounts of data. They're also useful because you can pass them to functions - much easier than passing each element to a function. In VB5 you can also declare functions to return user-defined data types, though I don't think this is possible in QB. Anyway, as you can see, user-defined TYPEs are a powerful tool which will make your code cleaner, easier to code and easier to understand. Use them!

TIP 2: SCREEN PAGE SWAPPING

Ever tried making some graphics animation in your BASIC code only to find that it flickered so much it gave you a migraine? No? Then you were one of the lucky ones...

Seriously though, flickering doesn't look nice and it happens when you clear the screen, draw a graphic, clear it again, draw it again, etc. - all that clearing becomes really obvious and looks terrible. However, there is a way round it, which is screen page swapping, as 12-pswap.bas will show you.

What this code does is draw seven pages of spectacular graphics action (well, lines and dots) into seven pages of video memory, completely hidden from view. It then instantly switches between them - no flicker, no waiting for the screen to draw - the page just pops into view.

If you examine the code you'll see the secret behind this trickery is some extra numbers given to the SCREEN statement. The first number is the mode number which you usually use with the screen statement. The third and fourth numbers control the "apage" and the "vpage" respectively. The "apage" is the one that LINE statements, PRINT statements and in fact any statements that draw to the screen will be sent to. The "vpage" is the one the user will see while all this is going on. (The second number in the SCREEN statement can be safely ignored - just stick a space there instead). So, if you draw all the stuff to the apages and then flick through the vpages, the pages that were drawn pop up instantly.

This technique is very useful for animation. The easiest way to use it for animation is to use something like:

cpage% = 0
DO
SCREEN 7, , cpage%, 1 - cpage%

' insert code here to draw screen

cpage% = 1 - cpage%
LOOP

This will alternate between the pages; whenever page 0 is displayed, page 1 is being drawn to, and then vice versa. The 1-cpage% bits are a useful shortcut - because 1-0=1 and 1-1=0 - so they return whatever cpage% "isn't", without the need for writing IF statements such as IF cpage% = 1 THEN cpage% = 0, etc.

Look in the help file for more information on screen pages. Screen 7, as used in the demonstration program, can use up to 7 on a VGA or better monitor. Screen 13, unfortunately, only has room for one, so page swapping is not possible directly from QB code, even though a modern SVGA monitor has several times the 256K memory that one screen 13 page will use. There are probably interrupts that will let you do it... perhaps this could be the subject of a future article.

 

That's all for part 1 of my "Intermediate Programming Tips" series - if anybody can think of anything they'd like me to cover in future parts, please let me know - address at the top of the page.

 

INCLUDING FILES IN EXEs, by Ollie Cook oliver.cook@bigfoot.com

This is the first programming article that I've ever written so I hope that I make myself clear enough to be understood. This article is going to take the form of a tutorial which will allow you to get this technique working, and will give you scope to adapt and update the source included. We're going to make a program which will play a WAV file, using only one executable.

Let's get started. Get 12-exe.bas loaded up. It includes a lot of code written by Mike Huff, and is simply to play the WAV were going to include, at a decent quality.

Now. If we're going to append the WAV onto the end of the EXE, once compiled, we are going to have to know where the EXE ends and the WAV begins. Luckily for us, all WAV files begin with the same string: "RIFF". So, what we need to do is to make the EXE scan itself until it finds that string. So to do that, replace offset& = 1 with this:

stringmatch$ = CHR$(82) + CHR$(73) + CHR$(70) + CHR$(70)
OPEN Filename$ FOR BINARY AS #1
FOR loop1& = 1 TO LOF(1) - 4
GET #1, loop1&, RIFFsearch(1)
IF RIFFsearch(1) = stringmatch$ THEN offset& = loop1&: EXIT FOR
NEXT
CLOSE #1
IF offset& = 0 THEN CLS : PRINT "No WAV file detected": STOP

 

That will scan the file into a buffer, four bytes at a time, and check if what's in the buffer matches the header we want. We use stringmatch$ = CHR$(82) + CHR$(73) + CHR$(70) + CHR$(70) instead of stringmatch$ = "RIFF" because if we did that the routine would pick up the wrong 'RIFF' in the file.

Now that the program knows where to find the WAV it's our job just to compile the program and add the WAV onto the end. (To make the sound play correctly replace 11000 in Freq& = 11000 with the actual frequency of the sound you want to attach, in Hertz).

OK, now compile the code to 'exetute.exe', as that's what we referenced to in the source. Now from a DOS prompt type the following:

copy /b exetute.exe + wavfile.wav

That will add on the WAV file to the EXE. The EXE knows where the WAV starts and when run will play it, thanks to Mike Huff, and a little devious thinking.

Please pass on any comments you may have on this article to me at oliver.cook@bigfoot.com - It's my first article, I hope you liked it.

 

 

MORE ARTICLES:

Yep, more articles - courtesy of RudeJohn. These articles appear in separate HTML files in the Basix Fanzine directory - click the links to read 'em:

[ Back to Contents ]

 

 

WANT TO SEE...

YOUR AD HERE AND ON THE BASIX FANZINE WEBSITE?

If so, please email basix@dewarr.globalnet.co.uk for details.

Advertising can be placed here in exchange for anything that would help the fanzine - for example, webspace, a domain name, or the money to provide this - in fact, if somebody could "sponsor" the fanzine and give us www.basixfanzine.com with 10mb or more of webspace, that would be absolutely fantastic! In return, your advertisements would be sprinkled liberally here and there in the fanzine and on the website too.



useful programs demonstrating useful techniques

 

DETECTING THE PARALLEL PORT, from Juan F. Miguez jfm7620@megahertz.njit.edu / miguez@andromeda.rutgers.edu / miguez@bifoot.com (take your pick... I'm sure that last one should be miguez@bigfoot.com really, but that's what it said in the code I recieved -ed)

The program 12-pport.bas demonstrates how to detect the parallel port automatically.

 

BINARY FILE ENCRYPTION, from Daniel Bolger daniel.bolger@ukonline.co.uk

Daniel Bolger writes:

"It works by adding the ascii numbers from each letter of the password together and then dividing by the number of letters -- basically finding the average. Then things get XORed etc. It originated as a copier - and a fast one at that, but now it isn't very fast - perhaps you could change that. Anyway, I hope it is of use."

12-encrp.bas

 

CONTROL+BREAK DISABLER, from Daniel Bolger daniel.bolger@ukonline.co.uk

Daniel Bolger writes:

"This is a version of NoBreak (I call DazNoBreak). It disables the use of the Cntrl + Break and the Cntrl + C keyboard shortcuts for exiting programs in QBasic. I believe [the Basix Fanzine] had a program like this in the past... I hope this is clearer. It isn't based on the previous version and any similarity is purely coincedental.

Some disadvantages:

1. You cant use Num Lock or Caps, they stop it working, so they are turned off at program startup. They are prevented from going back on. At program end, they resume their status before the program was run.

2. Every time you use the two aforementioned shortcuts, the scroll lock toggles!

3. More seriously: you can't use INPUT, or LINE INPUT, although you can use INKEY$, and INPUT$() as in the example.   I hope you like it."

12-nbrk.bas

 

"A SCREENSAVER TYPE THING", from Mike Anderson MikeAinIA@aol.com

His words, not mine :) "I've sent you this instead of a good article. :-)" he says...

12-ssave.bas

 



your questions answered, your comments printed...

 

PROGRAMS, MIDI & INP, from Daniel Bolger daniel.bolger@ukonline.co.uk

Hi

Below, I have included the source of my binary file encrypter... [included above]

One more piece of code: This is a version of NoBreak (I call DazNoBreak). [also included above]

Cheers, Daniel Bolger :-) (Age 12 - no kidding!)   PS. Great fanzine, BTW is it possible to play midi files in QB? Perhaps you could go over things like INP which means nothing to me...

 

Thanks for the programs. It is indeed possible to play MIDI files from QB, but not directly. It can be done using the QMIDI routines - the URL is in the Internet Resources section of the fanzine, and you can download it directly by clicking this link: http://members.tripod.com/~jdorland/qmidi/qmidi35.zip

INP is the opposite of OUT, and you use it for reading info from the ports. I don't use it very much, probably the only time I need it is when reading/writing the palette info (though this can be done in QB already using the PALETTE command, but I find using OUT easier). Anyway, the following SUB uses OUT and sets colour number n to the colours specified in r, g, and b. (The Red, Green, and Blue values)

SUB pal (n AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER)
OUT &H3C8, n
OUT &H3C9, r
OUT &H3C9, g
OUT &H3C9, b
END SUB

If you turn OUT to INP in the last three lines, they return the r, g and b values rather than set them. So you can read the r, g and b values of colour 200 by using:

OUT &H3C8, 200
R = INP &H3C9
G = INP &H3C9
B = INP &H3C9

There are many other uses of INP and OUT - they're used in programming the SoundBlaster for example. They can also control other things as well - just about any piece of hardware connected to your computer can be controlled via INP and OUT, if you know the various numbers. I have uploaded a file that I found somewhere on the web to the Basix Fanzine website, it lists many of these ports and the values they take. You can download it directly by clicking this link - http://www.users.globalnet.co.uk/~dewarr/ports.txt

 

 

WANT TO SEE...

YOUR BASIC PRODUCT REVIEWED IN THE FANZINE?

If so, please email basix@dewarr.globalnet.co.uk for details.

If you market a compiler or other BASIC-related product and want the DOS BASIC world to know about it, why not send in a review copy? It could be emailed to the address above (please ask first though, before you plant a massive binary in my mailbox) or, if you're kind enough, you could post a copy - email me for the address.


 

Thanks to the following for contributing articles and source code for this issue, in no particular order:

 

Finally, thanks to "Rembrandt Packaging" aka Jeroen and Marc van den Dikkenberg for pointing out a few old links in the "Internet Resources" section.

 

NEXT ISSUE:

Well, hopefully I'll have the next issue - the last fanzine of 1998 - out by the end of October. But, to do that, I need your contributions - so send something in!

Alex Warren,
14th August 1998

[ Back to Contents ]

[ Basix Fanzine Main Index ]