--------------------- "My mind is going..." --------------------- Don't you wish you had a place to dump information to in your program. You want a place where you can store data temporarily. A place that other programs can read it. Well you have 3 options: Dump it too a disk, uses COMMONs and CHAINs, or dump it to memory Now, dumping it to a disk isn't so bad. Sometimes, there is no way around this. Windows 3.x, 95, and 98 do it. You can store as much data on a disk as there is space. There is just one big problem: Disk access is the slowest thing you can do on a computer. Your computer moves around at the "speed" of electricity inside you computer (what the speed of electricity is, I have no idea, but it is really damn fast, in fact speed isn't a good word for it, but this will make it easier to understand) Know, when the computer has to get data from a disk, it must PHYSICIALY spin the platters in of the disk and then move the read/write head to a part of the disk then start reading the information very slowly. This is the equivalent of going 85mph on the highway, and then suddenly have slam on your brakes and precede at the rate of my Grandmother's walker! COMMONs and CHAINs are not that great. Sure they allow variables to be pasted to other programs, but you can't use CHAIN or COMMON if you compile the program. You will need to use RAM OH MY GOD, RAM! I was so scared of RAM. Nobody could tell me exactly what it was, and why you needed it, or how it worked. It a little magic gnome that lived in your computer and made everything better. Here is an analogy my brother told me many years ago. Think of the computer as a B- student. He can read and read all day, but only remembers so much. Know he read a book. Later when asked about the book, he can tell you only so much about it, but if you want a lot of information, he will have to go back and re-read parts of the book. Now think of the "book" as your Hard disk. When you run a program, say, Quake II, the computer reads the program from the disk and "remembers" it in. RAM. When the program needs something, like a graphic or a sound. The computer first checks its RAM to see if it "remembers" it. If the computer doesn't have the WAV file of a fiend ripping you open, it will then go back to your hard disk and re-read that part into RAM. This is why adding more RAM gives you the largest performance increases. The less time the computer speeds re-reading stuff, the more time it can devote to running the program. But wait, RAM is a busy place. Windows uses it to Multitask. DOS is loaded into it. Also, memory managers like QEMM shove stuff in different locations on different computers. You only need to worry about memory managers on MS-DOS or WIN 3.x systems. But how do you find a little space and RAM to crawl inside and claim that land for Spain? There are a few ways to do this, but it depends on what system you are using. If you are using a Windows 95, just use DEF SEG = 0. First run a Dos prompt, and then run Qbasic, as long as you don't close the DOS prompt, Win95 auto-restricts a certain area in memory for you, and you don't have to worry about other programs running using it up. If the program is a compiled program, you might want to consider re-starting your computer in MS-DOS mode, or launching it from a DOS prompt. However, if you are using Win 3.x, or you are not sure what systems you program will be run on, it is safer to use the following method. Editor's note. I started writing this article before I wrote Issue 3. I did touch on Video memory briefly in issue 3, but will repeat it here. I don't want to go into RAM workings, XMS,EMS, and other hard stuff like, because it is very confusing. But I'll tell you this. Back in the day of XT's, IBM need a place in RAM, 8k to be exact, to use as the screen buffer for BIOS. Well, there are monochromatic monitors, and there are color monitors, they thought. We'll just set aside 4k for each to use. The did 4k because at that time, screen could only have a max of 25 rows by 80 columns. (25*80=4000) And since everything must be in hexadecimal, which is short for binary, it must be in a power of 2 (4096 instead of 4000) So, IBM made 2 little places in memory that are 4k (4096) in size. But wait, if you are using a color monitor, what happens to the 4k of RAM for Monochrome Monitors? Jack squat. It just sits there, wanting to be loved. Now, the memory addresses of the 2 4k blocks are as follows. Mono &HB000 (&H just tells basic it is in HEX number system) Color &HB800 There is one and only one exception to this rule, Hercules Video. For thoughts of you who don't know, Hercules has a graphics card you could by that let monochrome monitors display graphics. It was neato, but wasn't supported in BIOS, so you had to load a TSR (MSHerc.com, QBHERC.com, or HercDrv.com) that did the graphic. Because it did have this BIOS support, Hercules uses BOTH 4k screen buffers. To load stuff into RAM, use will you the following Statements and functions: FOR, LEN, ASC, CHR$, POKE, PEEK, and DEF SEG Now, this took me while to figure out, but here it is. You use DEF SEG to go to an address in RAM. An Address is a little space (1 byte) where stuff is stored. Once you get to an address, you use PEEK and POKE to read and write data. Now remember the computer works in BINARY, and a more complex form of that is HEXIDECMAL. All the addresses in RAM are in hex. In BASIC, hex numbers are represented by an "&H". Here is an example: DEF SEG=&H300 ' Heah computer, Move me to address &H300 a = PEEK(0) ' Read the byte at address &H300 + 0, and save it as "a" b = PEEK(1) ' Read the byte a address &H301 (&H300+1); save as "b" PutMeInMemory = 27 POKE(0), PutMeInMemory There is in memory. To retrieve it, use PEEK. Now, why would you want to use PEEK and POKE so much you ask. Since they directly access and assign memory addresses, PEEK and POKE make Qbasic very powerful. You can use these areas of memory that I have shown you to POKE in data, and then PEEK it later, or by another program. If you need to store a lot of information to pass to another program (such as our task swapping OS we made in Issue 3) I would POKE a string of ASCII characters that are the filename and directory of a file that contains all the information you need. Such as: Placeme$="C:\AcidOS\OsSet.ini" For x=1 to len(placeme$) Poke(x),asc(mid$(Placeme$,x,1) Next Enjoy! -------------------------------------------------------------------------------- This tutorial originally appeared in the QBasic Developers Forum, Issue #4. This was written by Lord Acidus.