============================================== BASIX Newsletter - Issue 1 (June 5 1999) ============================================== BASIX Newsletter Author: Peter Johnson aka. Screech Web : http://members.tripod.com/Basixnewsletter Email : Basixzone@listbot.com ============================================== CONTENTS 1. Welcome! 2. Graphics (Intermediate) 3. Keyboard note 4. Hexadecimal and Binary numbers (Beginners to Intermediate) 5. A very BASIC tutorial - John Casson (Beginners) 6. Goodbye! ============= 1. Welcome! ============= Well here it is the second issue! This is the second time that I have started to write this Issue (I had to format my Hard Disk and I lost everything!). Basixzone is now dedicated to the Newsletter it has the back issues, the subscription form and everything to do with the Newsletter. After the last issue I received an email from Bucko (davidbuckley@bigfoot.com) with some things about the newsletter and I hope that I have fixed some of the things that he critised, the first was that in last months issue about the keyboard, I neglected to mention about Hexadecimal numbers (more about that later) and I didn't completely cover all the details in the article so I will do both of these things later in the issue. He also sent in the source code for an assembler version of my graphics sub that is in the second part of the Graphics tutorial. If you want to read any of the emails that I receive from people about the Newsletter head on over to http://members.tripod.com/Basixnewsletter The website has moved, head on over to http://members.tripod.com/Basixnewsletter ============= 2. Graphics ============= Last month we wrote a SUB that would plot pixel directly to the graphics memory, and I asked if anyone could send in the same SUB, but in inline assembler so here it is courtesy of Bucko. >Quick ASM Proggy > >MOV ES, A000h ;Extra Segment = Video buffer >MOV BX, X ;BX = X >MOV AX, Y ;AX = Y >MOV CL, 8 >SHL AX, CL ;AX = Y * 256 >ADD BX, AX ;BX = X + Y * 256 >MOV AX, Y ;AX = Y >MOV CL, 6 >SHL AX, CL ;AX = Y * 64 >ADD BX ;AX = BX + Y * 64 = X + Y * 320 >MOV DI, AX ;Offset = Offset of pixel >MOV AL, Colour ;AL = Colour >MOV [ES:DI],CL ;Set The pixel > >Probably could be shorter and/or faster, but it works (I hope - it's untested ~^.^~ and it >doesn't store the old stuff) > >Here's the Blast! library version of the same... > >PUSH DS ;Save the Destination Segment >PUSH BP ;Save the Base Pointer > >MOV BP,SP ;Get the Stack Pointer >MOV AX,[BP+10] ;Get the to buffer segment >MOV DS,AX ;and set DS to it. >MOV SI,[BP+0A] ;Get the Y position. > >MOV CL,06 ;Multiply it by 64 by using a Shift >SHL SI,CL ;Left (SHL) for speed. >MOV BX,SI ;Save the result temporarily. >MOV CL,02 ;Shift left again to multiply the >SHL SI,CL ;Y position by 256, then add that >ADD SI,BX ;value to our saved result. >MOV BX,[BP+0C] ;Now get the X position and add it >ADD SI,BX ;to the result to get our final >MOV BX,[BP+0E] ;offset. Then get the To buffer >ADD SI,BX ;offset and add the pixel offset. >MOV AL,[BP+08] ;Get the pixel color, >MOV [SI],AL ;and plot it. > >POP BP ;Reset the Base Pointer >POP DS ;Reset the Destination Segment >RETF 000A ;Return to BASIC Program, clean up > >It's in sub for but hey! What isn't... (it was built for a CALL ABSOLUTE) It's been edited becuase of some errors, but it should be all right now. RGB Palette As you may or may not know, there are only three primary colours for light: RED, GREEN and BLUE (not to be confused with paints: RED BLUE and YELLOW) to make pixtures on your screen the monitor displays each pixel as different amounts of RED GREEN and BLUE, this allows it to display a large range of colours. But there is a problem: the graphics memory, there is only a certain amount of graphics memory so even though in SCREEN 13 there are 64^3 possible colours only 256 can be displayed at one time, but we can change how much RED GREEN and BLUE a certain colour has by OUTPUTTING to the graphics card, this allows for very good special effects such as screen fading on some games. To change the PALETTE we have to do four commands, we have to output the number of the colour to port &H3C8 and then output the RED, GREEN and BLUE to port &H3C9, to output the RGB value we do them one at a time in the order RED, GREEN and BLUE. Note you can only use values 0-63 when you are changing the RGB values. SCREEN 13 DELAY = 100 'Increase or decrease this depending on your machine speed 'This will make the screen flash from red to black DO FOR C% = 0 TO 63 SETPAL 0, C%, 0, 0 FOR D = 0 TO DELAY: NEXT D NEXT C% FOR C% = 63 TO 0 STEP -1 SETPAL 0, C%, 0, 0 FOR D = 0 TO DELAY: NEXT D NEXT C% LOOP WHILE INKEY$ = "" SUB SETPAL (COL%, R%, G%, B%) OUT &H3C8, COL% 'Output the colour OUT &H3C9, R% 'Red value OUT &H3C9, G% 'Green value OUT &H3C9, B% 'Blue value END SUB Does anyone know how to do that in Inline assembler? Here is how that works, SETPAL(our PALETTE changing function) is called and changes the background colour 0, to pure red (0 to 63 are the different shades of red and this is what causes the fade effect) and then back to black. If you have a paint program and you want to use a colour from it, the chances are that the program will give you numbers from 0-255 not 0-63, to convert them so that you can use them divide all the RGB values by 4. some sample RGB values BLACK - 0,0,0 WHITE - 63,63,63 YELLOW - 63,63,0 RED - 63,0,0 BLUE - 0,0,63 GREEN - 0,63,0 PURPLE - 63,0,63 Next months issue, reading the PALETTE and reading graphics memory. =================== 3. Keyboard note =================== Last month I neglected to mention that after you have let go of the key the scan code will be the same scan code plus 128 on top, for example if I press ESCAPE the keyboard will generate scan code 1 and when you let go it will change to 129. This is useful if you need to know this kind of thing for your programs. =================================== 4. Hexadecimal and Binary numbers =================================== I have decided that I will try to tackle these two in the same article. They are basically two different number systems that are used by the computer and are needed to be understood by the programmer. The numbering system that we use from day to day is called decimal, this is becuase is uses base 10 (there are only ten characters involved 0-9), BINARY is base 2 and hexadecimal is base 16, this is because binary only uses two characters: 0 and 1, hexadecimal uses 16 characters: 0-9,A,B,C,D,E and F. BINARY Binary only uses two characters to represent its numbers because computers are digital and their circuits only have two states ON and OFF binary has 1 and 0. Binary numbers are a series of 0's and 1's which are then translated by the computer into the appropriate number. Binary numbers seem complicated at first, but then they get much simpler, here is an example of a binary number: 10011, this number is actually 19. To change a binary number into decimal you need to know what the number means, the numbers go from right to left, and each 0 or 1 means OFF or ON respectively. The number farthest to the right actually means one and the number on its left means two and its left means four and its left means 8 and they keep on doubling for ever. |-----|-----|-----|-----|-----|-----|-----|-----| | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |-----|-----|-----|-----|-----|-----|-----|-----| | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | |-----|-----|-----|-----|-----|-----|-----|-----| As you can see from the chart the numbers 1,2 and 16 are ON so we add them together to get 19! Notes: + A binary number should always start with 1 because even though the decimal numbers 05 and 5 are the same we always write 5 for simplicities sake. + Only the numbers 0 and 1 are used in binary anything else is wrong. + If the binary number ends with 1 then the decimal equivalent is an ODD number. + 0 and 1 are the only numbers that are represented the same in Decimal, Hexadecimal and Binary |--------|---------|-------------| | Binary | Decimal | Hexadecimal | |--------|---------|-------------| | 0 | 0 | 0 | | 1 | 1 | 1 | |--------|---------|-------------| HEXADECIMAL As I mentioned before hexadecimal numbers use A-F in their numbering system, they do this to keep the number short and so that larger numbers can be represented in a smaller amount of memory. BINARY Numbers and HEXADECIMAL numbers have a good relationship in that they can be easily translated from one to the other, whilst it is slightly more complicated with Decimal and Hexadecimal. Hexadecimal numbers use 0-F so there are 16 characters, to make 15(0 makes the total 16) we use 4 bits(Binary Digits) so F is 1111 and 0 is 0000(but we just say 0) |--------|-------------| | Binary | Hexadecimal | |--------|-------------| | 0000 | 0 | | 0001 | 1 | | 0010 | 2 | | 0011 | 3 | | 0100 | 4 | | 0101 | 5 | | 0110 | 6 | | 0111 | 7 | | 1000 | 8 | | 1001 | 9 | | 1010 | A | | 1011 | B | | 1100 | C | | 1101 | D | | 1110 | E | | 1111 | F | |--------|-------------| So if we have the number 10011 we split it up into four digit binary codes, 1 and 11(0011) we then know that Binary 1 is Hexadecimal 1 and Binary 11 is Hexadecimal 3 so we put them together to get 13, the Hexadecimal equivalent of 19. If you really want to convert Hexadecimal into Decimal then you must: 1. Divide the number by 16 2. If the number is bigger than 15 then repeat step 1 3. PUT the numbers together eg. 65 / 16 = 4 remainder 1 4 = 4 and 1 = 1 4 and 1 is 41 65 = 41 154 /16 = 9 remainder 10 9 = 9 10 = A 9 and A is 9A 154 = 9A 175 / 16 = 10 remainder 15 10 = A 15 = F A and F is AF 175 = AF 300 / 16 = 18(ignire this number) remainder 12(this is still the last digit) 18 / 16 = 1 remainder 2 1 = 1 2 = 2 12 = C 1 and 2 and C is 12C 300 = 12C They should be enough for you. ======================================== 5. A very BASIC tutorial - John Casson ======================================== >Note from Screech: >This article contained a few errors when I read it, I may have missed a few - this means that >not everything contained in this article is correct, but it is highly unlikely that anything is >uncorrect. Overall this is a very good article though, so get reading beginners. >Send him your comments at: J_cass1@hotmail.com This is a paper written by John Casson for the BASIX Newsletter, I decided to write this article because of the lack of beginners tutorials on the web. When I say run the program, I mean click on run then click on start. This will run the code that is in the main window. The first command that I am going to tell you about is REM, this command basically means REMARK and it is ignored by the compiler so it is used for programming notes, it can also be written as ' (The single speechmark) here is an example: PRINT "Hello" 'This command displays Hello on the screen I: CLS CLS is a command used to Clear the Screen. This command will clear any text that was printed on the screen and any graphic objects on the screen. This will become useful later in the paper, but for now don't worry about it. II: PRINT Print is a command used to put some text on a screen. If you typed in the following line of code into Qbasic/Quickbasic: PRINT "Hello" If you run this program you will see the word Hello written in the top left hand corner of the screen. You can use the print command to put text anywhere on the screen, which brings us onto the next topic. III: LOCATE Locate is used to tell qbasic/quickbasic where on the screen to put some text using the print command. Here is an example: CLS LOCATE 5, 6 PRINT "Hello" Now I will take you through the program line by line: -------------------------------------------------------------------------------- CLS 'This command clears the screen. Locate 5, 6 'This command tells Qbasic/quickbasic that you want to put text 'in at the fifth row, in the sixth column. -------------------------------------------------------------------------------- Print "Hello" This command, as you know places text onto a screen, but in this program, it will put it on at the fifth row, in the sixth column. IV: Input Input is used to receive input from the keyboard and to store it in a variable. There are many ways in which to store this information that can be received from the keyboard. You could store it as a whole number, a decimal number or you could store it as text. This means that you can store a string of text in a place with a name that you can specify. For example, if you kept someone's name in a variable and the variable's name was NAME1$ (the dollar sign after the title of the variable tells qbasic/quickbasic that NAME1$ is a STRING) then you could use the print command to print on screen the text that is contained in name1$. Here is an example: CLS 'Clear the screen INPUT "What is your name? ", A$ 'Prompts the user for input and stores it in the STRING A$ PRINT "Hi "; A$ 'Prints "Hi " onto the screen followed by the contents of A$ 'the speechmarks will NOT be printed Here is a line by line walk through of this program: IV: Color (Notice the American spelling) Color is the command used to change the color of the text. You do not type in the name of the color, you type in the number corresponding to the color. 0 = black 4 = red 8 = gray 12 = light red 1 = blue 5 = magenta 9 = light blue 13 = light magenta 2 = green 6 = brown 10 = light green 14 = yellow 3 = cyan 7 = white 11 = light cyan 15 = bright white This is a table that shows which number corresponds to which color. Here is an example program: CLS 'Clear the screen COLOR 4 'Change to colour RED PRINT "RED" 'Print "RED" on the screen(in RED) COLOR 2 'Change to GREEN PRINT "GREEN" 'Print "GREEN" on the screen(in GREEN) COLOR 14 'Change to YELLOW PRINT "YELLOW" 'Print "YELLOW" on the screen(in YELLOW) What this program does is clears the screen, sets a color, and prints some text in that color. V: IF and THEN IF and THEN are commands used in BASIC like this: IF I am hungry THEN I eat. This would not work in BASIC, but this would: IF 10+2 = 12 then print "hi" What this line says is that if ten + two is twelve then write at the next point on screen hi. We will use IF and THEN later on in the tutorial. VI: Variables A variable is where you store your information, it is usually named after what the information being stored in it is, for example I would store a persons name in a variable called NAME$, the dollar sign will be explained later. We said before that you can store information in variable. So if you wrote the following line of code in to qbasic/quickbasic it would save the number 15 to the variable A%. The % after the name of the variable makes it into an INTEGER(a whole number without a decimal place) A% = 15 If we use the print command with a variable, we can find out what information is in it. Here is a sample program that tells you what number is stored in the variable A% CLS A% = 1+1 PRINT A% This program clears the screen then adds one and one and stores the answer in a variable called A%. The last command print the information in the variable called A%. CONCLUSION This is the end of this paper on BASIC, but there will be more! I am going to finish off with a long program that uses all of the commands that were listed in this document. CLS LOCATE 5,5 COLOR 14 PRINT "THIS IS THE FINAL PROGRAM OF THIS TUTORIAL. A% = 5 + 5 PRINT "WHAT IS 5 + 5?" INPUT B% IF A% = B% THEN PRINT "YOU GOT IT RIGHT" This is the end of the tutorial! I will be writing more tutorials to follow this on soon, so keep on checking the newsletter! John Casson ============= 6. Goodbye! ============= Well it's the end of another issue, thanks to all who contributed: Bucko - davidbuckley@bigfoot.com (David Buckley) Casson - J_cass1@hotmail.com (John Casson) my email address: Basixzone@listbot.com Next issue is going to be posted on the 7th of August.