Manual / Guide · 1977
The First Book of KIM (1977)
Programs, games and tutorials for the KIM-1, from Hayden's 1977 collection.
Manual / Guide · 1977
Programs, games and tutorials for the KIM-1, from Hayden's 1977 collection.
Hie First Book of KIA\ Edited by JIM BUTTERFIELD • STAN OCKERS • ERIC REHNKE HAYDEN BOOK COMPANY, INC. Rochelle Park, New Jersey I Dedicated to the person who just purchased a KIM-1 and doesn't know what to do with it... Individual programs in this book were contributed by the various authors without copyright restrictions. These programs may be used or copied without restriction. It is, however, common courtesy to quote author and source when copying; and a copy of any published material should be sent directly to the author. In general, program authors welcome comments, suggestions or revisions to their programs. Depending on circumstances, they may not find it possible to reply to all correspondence. If you develop a program that you'd like to share with other KIM users, send it in to KIM/6502 User Notes, 109 Centre Avenue, W. Norriton, Pennsylvania 19401. It might appear in User Notes ... and even in a future Book of KIM. ISBN 0-8104-5119-0 Library of Congress Catalog Card Number 78-53963 Copyright © 1977, 1978 by F. J. Butterfield. All rights reserved. Except as noted above, no part of this book may be reprinted, or reproduced, or utilized in any form or by any electronic, mechanical, or other means, now knovyn or hereafter invented, including photocopying and recording, or in any information storage and retrieval system, without permission in writing from the copyright holder, application for which should be addressed to the Publisher. Printed in the United States of America 1 2 3 4 5 6 7 8 9 78 79 SO 81 82 83 84 85 86 PRINTING YEAR IN THIS BOOK YOU'LL FIND: A BEGINNER'S GUIDE TO KIM PROGRAMMING: 5 guidelines which take the absolute beginner, step by step, through the fundamentals of understanding and writing programs. RECREATIONAL PROGRAMS: 23 dozens of programs including games, diversions and educational programs; fully detailed so that you can learn from the programming techniques as well as have fun. All programs run on the basic KIM-1 system. DIAGNOSTIC AND UTILITY PROGRAMS: 114 to help you test your KIM computer — to help you test other devices, such as cassette recorders — and to make your KIM a more powerful machine. EXPANDING YOUR KIM: 143 guidelines on how to expand your KIM from the basic small-butpowerful KIM-1 system to a huge-and-super-powerful machine; understanding the jargon; seeing what's available in both hardware and software. CONNECTING TO THE WORLD: 155 an introduction to the methods by which KIM can read or sense other devices, and can in turn control other mechanisms. POTPOURRI: other useful pieces of information about your KIM system; reference material, hints, etc. 166 r Acknowledgments Thanks to all who have supported the KIM-1/6502 User Notes, from which much of this material was taken. A special thanks to Earl Nied for the use of his KIM-interfaced Selectric. The KlM-1 microcomputer is manufactured by Commodore/MOS Technology, 950 Rittenhouse Road, Norristown, Pennsylvania 19401. It may be obtained directly from the manufacturer or from many hobbyist computer retail stores. At the time of writing, the complete KIM-1 system (less power supply) sells for $245. All programs in this book run on the basic KIM-1 system; two require an audio amplifier. A BEGINNER'S GUIDE TO KIM PROGRAMMING.' Running programs can be fun. But writing programs can be even more fun .. and exasperating, and exhilirating, too! When you get the hang of it - and it will take time you'll be able to create your own games, diversions, or useful routines. This section tries to introduce you to the mechanics of programming, so you can find your own way at your own speed. Don't be afraid to use ideas from other parts of this book. If you like, try changing parts of a program or two and see what happens. And you can borrow whole sections of coding from another program if it does something you want. LOOKING AT MEMORY Random Access Memory. If you've just turned your KIM system onf press the RS (Reset) button to get things started. Hit the following keys: AD (for ADDRESS) 0 0 0 0 . You've just entered the address of memory cell 0000, the lowest numbered one in memory. The display will show 0000 (the number you entered) on the left. On the right, you'll see the contents of cell 0000: it will be a two digit number. That number might be anything to start with; let's change it. Press key DA (for DATA). Now you're ready to change the contents of cell 0000. Key in 44, for example, and you'll see that the cell contents have changed to 44. Hit the + button, and KIM will go to the next address. As you might have guessed, the address following 0000 is 0001. You're still in DATA mode (you hit the DA key, remember?), so you can change the contents of this cell. This time, put in your lucky number, if you have one. Check to see that it shows on the right hand part of the display. This kind of memory - the kind you can put information into - is called RAM, which stands for Random Access Memory. Random access means this: you can go to any part of memory you like, directly, without having to start at the lowest address and working your way through. Check this by going straight up to address 0123 and looking at its contents (key AD 0 1 2 3); then address 0000 (key AD 0 0 0 0), which should still contain the value 44 that we put there. Hexadecimal Numbers Now that you're back at address 0000, let's step through several locations using the + key. Don't worry about contents too much. 0001 will still contain your lucky number, of course, but keep stepping with the + key until you reach 0009. What will the next address be? Most people would think that the next number should be 0010, and that would be correct if KIM used the familiar decimal numbering scheme. But KIM still has six more digits to go past 9, because it uses a computer numbering scheme called Hexadecimal. Hit the + key and you'll see address OOOA come up. Don't let the alphabetic confuse you - to KIM, A is just the digit that comes after 9. And there are more digits to come. Keep pressing the + button and you'll see that A is followed by B, C, D, E and F. Finally, after address OOOF, you'll see address 0010 appear. A word about pronunciation: don't call address 0010 "ten"; say "one zero" instead. After all, it isn't the tenth value after 0000; it's really the sixteenth (the word Hexadecimal means: based on sixteen). If you don't understand why the letters appear, don't worry about it too much. Just understand, for the moment, that the alphabetics represent genuine numbers. So if you're asked to look at address 01EB, you'll know that it's a legitimate address number like any other. And if you're told to store a value of FA in there, go right ahead you're just putting a number into memory. When you get time, you'll find lots of books that explain Hexadecimal numbering in detail. There's even an appendix in your 6502 Programming Manual on the subject. It makes important and worth-while reading. But for now, just recognize that although the numbers may look a little funny, they are still exactly that: numbers. Read Only Memory So far, we've talked about one kind of memory, called RAM. You recall that we said that you can store numbers into RAM. There's another kind of memory in KIM, but you can't store numbers there. It's called ROM, for Read Only Memory. This kind of memory contains fixed values that cannot be changed. For example, let's look at address 1C3A (key AD 1 C 3 A). You'll see the value 18, and that value never changes. Try it: press DA 6 6 to try to change the contents to 66. See how it won't work? ROM contains pre-stored programs which do important things like lighting the display, detecting keyboard input, and reading or writing your cassette tape. These programs are called the Monitor. In fact, the name KIM stands for Keyboard Input Monitor in recognition of the importance of these programs. We'll talk briefly about the Monitor programs later. Special Memory Locations A few addresses in KIM are connected to things that aren't really memory at all. You can read up on them in the KIM User Manual when you're ready; we'll just point out a few examples here. If you try to store a number into address 1700, for example, you might find that instead of storing the value, KIM will convert it to voltages and deliver these voltages to certain pins on your Application Connector at the edge of the board! Another example: address 1704 connects to a very fast timer - look at that address and you'll see "time going by" as a blur! MINI-PROGRAM A; Swap the contents of two locations This is our first beginner's program. It doesn't do much: just exchanges the contents of locations 0010 and 0011. But it's a start, and you'll learn quite a few things about getting KIM programs going. CAUTION: Before running this or any other program, be sure that you have set the contents of the KIM "vector" locations as follows: Set address 17FA to 00 Set address 17FB to 1C Set address 17FE to 00 Set address 17FF to 1C The first two locations are needed so that your SST switch and ST key will work right. The last two make the BRK (break) instruction behave properly. YOU MUST ALWAYS SET UP THESE LOCATIONS AS SOON AS YOU TURN ON YOUR KIM SYSTEM. Loading the Program We'll take time to describe how the program works later. First, let's see how to load it. A listing usually looks something like this: 0200 A5 10 0202 A6 11 0204 85 11 0206 86 10 0208 00 START LDA 10 LDX 11 STA 11 STX 10 BRK address 10 to A address 11 to X A to address 11 X to address 10 stop the program The business end of the program - the part that goes into the computer - is the group of numbers on the left hand side. The stuff on the right helps explain what the program does. If you look at the numbers on the left, you'll see that the first one, 0200, looks like an address. That's exactly what it is, and we can start by entering it with AD 0 2 0 0. The next number is A5, and that will be its contents. So hit DA A 5, and the display will confirm that we've put it in. Keep going on the same line. Each line of the program listing may contain more than one value - for more than one address. The next value is 10, and it needs to go into 0201. You don't need to enter the address. Just hit the + key and there you are - enter 1 0 and you've got it. Notice you didn't need to hit DA; you stay in Data mode until you press the AD key. Continue to the next line: just hit + A 6 + 1 1 and keep going until you've put the 00 in location 0208. Congratulations! You've loaded your first program. Now go back and check it for correctness. Hit AD 0 2 0 0 and use the + key to step through and check the values. Now let's run the program and see if it works. First, look at the contents of addresses 0010 and 0011. Make a note of them; when the program runs, it will swap those two values. Keep in mind that loading the program doesn't make anything happen. You have to run it to do the job and that's what we'll do next. , Running the Program Set address 0200. That's where the first instruction in the program is located - you may have noticed that it's marked START in the listing. Now the display shows 0200 A5, and we're ready to go. So - hit GO. And the program will run. Doesn't take long, does it? The display will have changed to 020A xx. If the display shows any other address, something's wrong. Check that your SST switch is off (left), that the program is entered correctly, and that your vectors are OK. Your program ran in less than a fifty thousandth of a second. No wonder you didn't see the display flicker. Now check that the program did indeed run correctly bylooking at the contents^ of locations OQIO and CX011. You'll see that they have been exchanged. 10 How it works Inside the Central Processor (the heart of the computer) are several temporary storages called registers. You can LOAD many of these registers with the contents of memory; and you can STORE the contents of the registers into memory. The two registers we are using here are called A and X. If we Load A from address 10, A now contains a copy of the contents of 0010. Location 0010 itself won't be changed; it will also contain that number. We do the same thing when we Load X from address 0011. Now our A and X registers contain copies of the numbers in 0010 and 0011 respectively. If we Store A into address 0011, that address will now contain a copy of the value in A - which was originally the contents of address 0010, remember? Finally, we Store X into 0010 to complete the swap. Look at the listing again. On the right hand side, we have the program exactly as we have described it, but abbreviated. You can see that LDA means Load A and so forth. The BRK (Break) at the end stops the program. Step by Step Let's go through the program a step at a time literally. Maybe you're satisfied that it works. Even so, follow this procedure. It will show you how to test any KIM program. First go back to addresses 0010 and 0011 and put a couple of brand new numbers there. This will help you the computer operating. Bow set address 0200 again, but don't press GO yet. V> 're going to "Single Step" our program, and see every ?truction work. So slide the SST (Single STep) ^•itch over to the right ... and then read the next , :tion carefully. 11 Seeing the Registers Registers A and X, plus quite a few we haven't talked about, are inside the 6502 microprocessor chip. There's no way you can view them - they are buried deep within the electronics. To help you out, the KIM Monitor system will write out a copy of these registers into memory where you can inspect them. The contents of the A register may be seen at address OOFS, and the contents of the X register are at OOFS. Don't be confused: These locations are not the actual registers, just copies made for your convenience. But it's a great convenience, for it allows you to see everything that's going on inside the microprocessor. A Small Step for a Computer, but ... If you're set up at location 0200 and your SST switch is on, hit the GO button once. The display will show 0202. That means: instruction at 0200 completed, ready to do the one at 0202. Okay, let's check everything in sight. The first instruction was to load the A register, right? Enter address OOFS and check that its contents (which correspond to the contents of A) are indeed the value from address 0010. If you like, look at 0010 and confirm that it hasn't changed. Now for a clever KIM touch. If you're ready to proceed with the next instruction, hit PC (for Program Counter) and you'll find yourself back at address 0202, ready to perform the next instruction. You've executed one instruction, performed one program step. Remember this: No matter how complex the program, it always operates one simple step at a time. And now you know how to check out each step, individually. Hit GO and execute one more instruction. Check it out remember that you'll find X at address OOFS. 12 From this point, find your own way through the last two instructions. Don't bother about the BRK (Break); it just stops the program. As the two registers are stored, you'll want to check that the memory addresses have been changed as expected. Summary The most important things that you've learned about coding are: —the BRK (code 00) command stops the program; —the SST switch causes a single instruction to be executed; —the internal registers can be viewed. BUT YOU MUST SET YOUR VECTORS PROPERLY (see the beginning of this section) OR NONE OF THE ABOVE WILL WORK! A complete list of the register image addresses can be found in the KIM User Guide on page 39, Fig. 3-13 when you need it. From here on, you don't have to take anybody's word for any KIM operation. You can go to your KIM, set SST, and try it for yourself. Exercises 1. Can you change the program so that it swaps the contents of locations 0020 and 0021? 2. Billy Beginner wrote the following program to swap the contents of locations 0010 and 0011: 0200 A5 10 0202 85 11 0204 A6 11 0206 86 10 0208 00 It didn't work. START LDA 10 STA 11 LDX 11 STX 10 BRK put 0010 into A store A to 0011 put 0011 into X store X to 0010 stop Can you see why? 3. Can you write a program to take the contents of address 0010 and place the same value in locations 0011, 0012, and 0013? 13 MINI-PROGRAM B; Setting many locations to zero Here's the program: 0200 A9 00 0202 A2 09 0204 95 30 0206 CA 0207 10 FB 0209 00 START LDA #0 LDX 19 LOOP STA 30, X DEX BPL LOOP BRK value 0 into A start X at 9 zero into 0030+X decrease X by 1 back if X positv stop the program This program, when you load and run it, will set the value of the ten locations from 0030 to 0039 to zero. We can't give you a whole programming course here. Hopefully, you'll use the Programming Manual and the single-step feature to trace-out exactly what the program does. But here are a few highlights: When we load registers A and X in the first two instructions, we don't want to load the contents of a memory location. Instead, we want the actual values 0 and 9. To do this, we use a new kind of addressing called IMMEDIATE addressing. Immediate addressing, when we use it, says "Don't go to memory - use this value." Immediate addressing can be spotted two ways. First, note the I sign that we use in writing the program: that signals that we are using immediate mode adressing. Secondly, you may have noticed that the computer instruction (called the Op Code) has changed: the previous program used code A5 to mean LDA; now we're using A9, which also means LDA but signals immediate addressing. You can - and should - use the SST feature to check that immediate addressing works as advertised. The instruction at 0204 uses the X register for INDEXING. That means that instead of storing the A value in address 30, the computer first calculates an effective address by adding the contents of the X register to the "base address" of 30. Since X contains 9 the first time through, the effective address will be 30+9 or 39 - and that's where we store our A value of 00. Later, X will be decreased to a value of 8, so we'll store into address 38. 14 Indexing seems complicated, but remember that it's a very powerful feature of KIM. Try to giet the hang of it; it's well worth the effort. The DEX instruction (Op Code CA) is the one that decreases X from 9 to 8 (and later to 7, 6, 5 and so on). Eventually, as this part of the program is automatically repeated, X will reach a value of 00. Finally, when we decrement X one more time, X will go to value FF, which KIM "sees" as a negative number, kind of like the value -1. KIM views all values in the range 80 to FF as negative - when you're ready, the Programming Manual will tell you more. The BPL instruction at line 0207 is a CONDITIONAL TEST. BPL means Branch plus. If the result of our previous operation (Decrement X) gives us a positive, or plus, number, we will branch back to address 0204 and repeat the instructions from that point. The X values of 9, 8, 7 ... down through 0 are all positive or plus; so each time we'll go back and set one more location in memory to value zero. Finally, X becomes equal to value FF - a negative number. So in this case, BPL won't branch: the "plus" or "positive" condition isn't satisfied. This last time, since BPL doesn't take us back, we proceed to the following instruction, BRK, which stops the program. That's OK because we've done our job of setting addresses 0030-0039 to value zero. Single Step the program carefully, checking the value of X from time to time (location OOF5, remember?). Satisfy yourself that you can see it working. By the way, that funny address on the branch instruction (FB) is a special kind of addressing mode called RELATIVE addressing. All branches use it; it's worth reading up on. Exercises 1. Can you change the program to place value 55 in the above locations? 2. Can you change the program to place value 00 in locations 0030 to 0037? 3. Can you change the program to place value FF in locations OOAO to OOBF? 15 . INTERLUDE - PROGRAM TESTING You've met one very powerful tool for checking out programs - the Single Step mode of operation. Let's review it and talk about a few others. The SST mode is especially useful because you can pause between instructions and look at memory or registers. The register values are copied into memory locations from OOEF to OOF5, and while they are not real registers, just copies, they are just as good for testing purposes. Not only can you look at them, you can change them to new values. This ability to change a register can be handy in solving the "what if ... " type of question, or shortening testing of a loop. For example, if you are single-stepping through mini-program B and you don't want to go around the loop a full ten times, you might use this trick. Go around a couple of times to get the loop started, and then change X (OOFS) to a much lower value, say 1 or 2. Go back to single-stepping. A couple more turns around the loop, and you're out. Using this method, you won't have set the whole ten locations to zero, of course. But you will see that the loop itself is working right. The Inserted BRK (Break) Sometimes SST seems slow. You might have a long program, and you're sure that the first part is working. What you want is a way to run directly through the first bit, and then stop and single-step the rest. It's not hard. Decide where you want the program to stop, so you can start single-stepping. Then put a BRK command, code 00, at that point. You'll have to wipe out a live instruction, of course, but that's OK. You can put it back after the halt has happened. Let's try doing that on mini-program B. Let's say we want to run straight through to the BPL instruction at 0207, and then single-step from that point on. 16 Change 0207 (previously 10) to value 00, the BRK command. Now go to the beginning of the program (0200), be sure SST is off, and hit GO. You'll see 0209 00 on the display, which tells you that the halt at 0207 has worked. Now go back to 0207, put the value of 10 (for BPL) back in, set the SST switch on, and you're ready to step. Easy? You bet - and you can save lots of time this way in testing big programs. No Operation (NOP, code EA) It sounds funny, but a very handy instruction is one that doesn't do anything. When the microprocessor encounters Op Code EA (NOP), it does nothing - just passes on to the next instruction. The biggest use of the NOP instruction is to take out another instruction that you don't want any more; or to leave room in the coding to add another instruction later if you need to. Some programmers write their programs in sections, and at first they put a BRK instruction between each section. That way, when they are testing, the program will stop after each part, and they can check to see that each part runs OK. When they are finished testing, they change the BRK's to NOP's and the program will run straight through. The ST (Stop) Key When everything is under control in program testing, you won't need the ST key. But sometimes the program 'gets away1 on you - and the only way to find out what it's doing is to use this key. Let's wreck mini-program B by wiping out the DEX instruction. We'll do this by replacing it with a NOP; so write value EA into location 0206. What will happen? When we run the program, the X register will never change from its starting value of 9 because we don't have a DEX instruction. So the program will keep branching back to LOOP forever, and it will never stop. We've created this situation artificially, of course, but it could have happened by oversight when we were writing the program. 17 Set address 0200, SST off, and hit GO. Everything goes dead. Our program is running but it will never stop. Meanwhile, the display is dark. This time we know why it's happening. But if we didn't, how would we solve it? Press ST - stop - and the computer will freeze. The display will light showing the next instruction we were about to execute. If we wanted to pinpoint the trouble, we could flip over to SST now and track the problem down, step by step. A last comment on the ST button: If the display goes dark and pressing ST doesn't relight it, the computer has a different problem. It has gone berserk due to a completely illegal Op Code. Press the RS (Reset) button; now you'll need to start over and use the BRK and SST features to track down the trouble. 18 MINI-PROGRAM C; Displaying values KIM has a 6-digit display. You can show information on the display quite easily, if you know how. In the KIM Monitor programs there are several packages called subroutines that you can call upon to do certain jobs. You could write the same coding for these jobs yourself; but use the Monitor subroutines to save time and trouble. When you give the command JSR SCANDS (coded 20 IF IF), the Monitor will briefly light the display with the data it finds in addresses OOFB, OOFA, and OOF9. That's three locations, each displaying as two digits, so the full six-digit display is filled. "Briefly" means exactly that. The display lights for a split second. To get a steady display, you must repeat the JSR SCANDS command over and over again. Use a loop, of course; no point in filling up your program with JSR SCANDS instructions. You should also know that when you call this Monitor subroutine, the contents of your registers are wiped out. So if you have something important in the A register that you will want to use after giving JSR SCANDS, be sure to put it safely somewhere in memory or you'll lose it. The same goes for other registers like X and Y. Here's a simple program to show 0000 00 on the display. Note that we must put the value 00 into addresses FB, FA, and F9 before we call JSR SCANDS. 0200 A9 00 START 0202 85 FB 0204 85 FA 0206 85 F9 0208 20 IF IF LOOP 020B 4C 08 02 LDA #0 STA POINTH STA POINTL STA INK JSR SCANDS JMP LOOP 19 zero into A first 2 digits next 2 digits last 2 digits light up! do it again This program never ends, so eventually you'll have to stop it with the RS or ST keys. See how the last instruction jumps back to address 0208 so the display is lit continuously? Another interesting point: see how the jump address at 020B is "backwards" - 08 02 instead of 0208? This is called "low order first" addressing and you'll see a lot of it on the KIM system. The single-step feature doesn't work too well on Monitor subroutines. That's normal, and it's not serious. These subroutines are well tested and dependable, so you shouldn't need to use SST with them. Exercises 1. Can you change the program to make the display show 5555 55? 2. Can you write a program to make the display show 1234 56? 3. How about a program to show the word EFFACE? or FACADE? or COOCOO? 20 MINI-PROGRAM D; reading the keypad To read the KIM pushbuttons you have another Monitor subroutine called GETKEY. You "call" it with JSR GETKEY (20 6A IF). This subroutine will give you the identity of the key that is being pressed at that moment as a value in the A register. You can continue by using this value any way you want. If no key is being pressed at the time, you'll get a value of 15 in A. There are a couple of cautions on the use of JSR GETKEY. First, you must not be in Decimal Mode. If you're not sure about this, give a CLD (D8) instruction at the beginning of your program. Secondly, before giving JSR GETKEY, you must "open up the channel" from the keyboard with either one of two subroutines: JSR SCANDS or JSR KEYIN. You've met JSR SCANDS before: it's used to light the display. If you don't want to light the display, use JSR KEYIN (20 40 IF) before using JSR GETKEY. This program reads the keyboard and displays what it sees: WJ^Vi 0 • 0200 D8 START CLD clr dc mode LDA #0 0201 A9 00 zero into A STORE STA POINTH 0203 85 FB STA POINTL 0205 85 FA 0207 85 F9 STA INK 0209 20 IF IF JSR SCANDS light display 020C 20 6A IF JSR GETKEY test keys JMP STORE 020F 4C 03 02 Exercises 1. Do you think that the instruction at 0201 is really needed? Try removing it (change 0201 and 0202 to EA) and see. 2. What values do you get for the alphabetic keys? For keys like PC and GO? Are there any keys that don't work with JSR GETKEY? 3. Try running in decimal mode (change 0200 to SED, code F8). What happens? Is it serious? How about key F? 4. Can you change the program so that only the last digit of the display changes with the keyboard? 21 CONCLUSION You've reached the end of our little Beginner's Guide. But you've only started on the road towards understanding programming. Use the tools we have given you here to forge your own path. KIM is a very rich machine. You have 56 Op Codes to choose from, and many powerful addressing combinations. You don't need to learn them all right away, but when you need them, they'll be there. The KIM Programming Manual makes good reading. Don't try to go through the whole thing at one sitting. Stop and try a few things; you have the Single Step feature to help you understand what each instruction really does. Try leafing through - or stepping through - other people's programs, to understand what makes them tick. Change the coding, if you like, to see what happens. When you see a program that does something you want to do, borrow the coding - you don't need to re-invent the wheel. Don't be discouraged when your program doesn't work on the first try. Even experts have to spend time getting the "bugs" out of their coding. It's part of the game: Think of yourself as Sherlock Holmes, methodically tracking down the elusive villains. A proverb says that a journey of a thousand miles starts with the first step. In the same way, the biggest programs still operate one step at a time. So forge ahead at your own speed. Communicate with other KIM owners; you'll have a lot of information to swap. But most of all: have fun. 22 RECREATIONAL PROGRAMS Clear Decimal Mode: Set 00?1 to 00 before running these programs. ADDITION BY JIM BUTTERFIELD DIRECTIONS HERE'S A HANDY LITTLE ADDING MACHINE PROGRAM. KIM BECOMES A SIX DIGIT ADDER. "GO" CLEARS THE TOTAL SO YOU CAN START OVER. THEN ENTER A NUMBER AND HIT THE PLUS KEY TO ADD IT TO THE PREVIOUS TOTAL. IF YOU MAKE A MISTAKE IN ENTERING A NUMBER, JUST HIT THE "0" KEY SEVERAL TIMES AND ROLL THE BAD NUMBER OUT BEFORE ENTERING THE CORRECTION. NO OVERFLOW INDICATOR, AND NO SUBTRACTION OR MULTIPLICATION - MAYBE YOU WOULD LIKE TO TRY YOUR HAND AT ADDING THESE. THE PROGRAM IS FULLY RELOCATABLE. 0200 20 IF IF START 0203 20 6A IF 0206 C5 60 0208 FO F6 020A 85 60 020C C9 OA 020E 90 29 0210 C9 13 0212 FO 18 0211* C9 12 0216 DO E8 0218 F8 18 021A A2 FD 021C B5 FC 021E 75 65 0220 95 FC 0222 95 65 022ii E8 0225 30 F5 ADD 0227 86 61 0229 D8 022A 10 DU 022C A9 00 022E 85 61 0230 A2 02 0232 95 F9 023k CA 0235 10 FB 0237 30 C 7 0239 Al* 61 023B DO OF 023D E6 61 023F 1*8 021*0 A2 02 DOGO CLEAR NUM JSR SCANDS light display JSR GETKEY read keyboard CMP PR3V same as last time? BEQ START yes, skip STA PREV no, save new key CMP #$OA numeric key? BCC NUM yes, branch GO key? CMP #$13 BEQ DOGO yes, branch CMP #$12 + key? BNE START no, invalid key SED CLC prepare to add LDX #$FD minus 3; 3 digits LDA POINTH+1,X display digit ADC ACCUM+3,X add total STA POINTH-»-l,X total to display STA ACCUM+3,X & to total accum INX next digit BMI ADD last digit? STX FIAG flag total-in-disnlay CLD BPL START return to start LDA #0 set flap for STA FLAG total- in- di SDlay LDX n STA INH,X DEX BPL CLEAR BMI START LDY FIAG BNE PASS INC FIAG PHA LDX #2 24 for 3 digits . . . clear disnlay next digit last digit? finished, back to go total-in-display? no, add new digit clear t-i-d flag save key 3 digits to move 02^2 B5 F9 02UU 95 62 02U6 9U F9 02U8 CA 02U9 10 F7 02UB 68 02i|C OA OA 02l|E QA OA 0250 A2 OU 02^2 OA 0253 26 F9 0255 26 FA 0257 26 FB 0259 CA 025A DO F6 025C FO A2 MOVE IDA INK, I STA ACCUM,X STY INH,X DEX BPL MOVE PLA PASS ASL A ASL A ASL A ASL A LDX #b SHIFT ASL A ROL INH ROL POINTL ROL POINTH DEX BNE SHIFT BEQ START get display digit copy to total Accum clear display next digit last digit? recall key move digit.. ..into position h bits move bit from A ..to INH.. ..to rest of display next bit last bit? yes. back to start «xxx:: HEX DUMP - ADDITION KXXJCX 0200 20 IF IF 20 6A IF C5 60 FO F6 85 60 C9 OA 90 29 0210 C9 13 FO 18 C9 12 DO E8 F8 18 A2 FD B5 FC 75 65 0220 95 FC 95 65 E8 30 F5 86 61 D8 10 D4 A9 00 85 61 0230 A2 02 95 F9 CA 10 FB 30 C7 A4 61 DO OF E6 61 48 0240 A2 02 B5 F9 95 62 94 F9 CA 10 F7 68 OA OA OA OA 0250 A2 04 OA 26 F9 26 FA 26 FB CA DO F6 FO A2 NOTE: WHENEVER SPACE PERMITS, A HEX DUMP OF THE PROGRAMS LISTED WILL BE GIVEN. THESE DUMPS WERE TAKEN FROM ACTUAL RUNNING PROGRAMS. SO, IF THERE IS A DISCREPANCY BETWEEN THE LISTING AND THE DUMP, THE LISTING IS MOST PROBABLY IN ERROR. 25 ASTEROID BY STAN OCKERS YOU ARE PILOTING YOUR SPACECRAFT BETWEEN MARS AND JUPITER WHEN YOU ENCOUNTER A DENSE PORTION OF THE ASTEROID BELT. PRESS KEY ZERO TO MOVE LEFT, THREE TO MOVE RIGHT. WHEN YOUR CRAFT IS HIT THE DISPLAY WILL GIVE A NUMBER TO INDICATE HOW SUCESSFUL YOU WERE. THE PROGRAM STARTS AT 0200. A9 00 85 F9 85 FA 85 FB A2 06 BD CE 02 95 E2 020F CA 0210 10 F8 0212 A5 E8 0214 49 FF 0216 85 E8 0218 A2 05 02 1A 20 48 02 . 021D 20 97 02 0220 CA 0221 DO F7 0223 20 40 IF 0226 20 6A IF 0229 C9 15 022B 10 E5 022D C9 00 022F FO 06 0231 C9 03 0233 FO OA 0235 DO DB 0237 06 E7 Q239 A9 40 023B C5 E7 023D DO D3 023F 46 E7 0241 DO CF 0243 38 0244 26 E7 0246 DO CA 0200 0202 0204 0206 0208 020A 020D LDA tt$00 STA 00 F9 STA OOFA STA 00 FB LDX tt$06 INIT TOGG LITE ...INITIALIZE COUNTER... ...INITIALIZE OOE2-OOE8 LDA 02CE/X STA OOE2,X DEX BPL INIT LDA OOE8 EOR #$FF STA OOE8 LDX tt$05 JSR DISP JSR CHEK DEX BNE LITE JSR KEYIN JSR GETKEY CMP ti$15 BPL TOGG CMP tt$00 BEQ LEFT ...TOGGLE OOE8... CFLASHER FLAG) DELAY BETWEEN FLASHES DISPLAY AND.. CHECK FOR MATCH SET DIRECTIONAL REGS. GET KEYBOARD ENTRY A VALID KEY? NO KEY 0? YES, GO LEFT KEY 3? YES, GO RIGHT NOT A VALID KEY SHIFT CRAFT LEFT LEFT HAND EDGE? CMP tt$03 BEQ RT BNE TOGG LEFT ASL OOE7 LDA tt$40 CMP OOE7 NO, RETURN BNE TOGG SHIFT RIGHT RT LSR OOE7 NOT RIGHT SIDE, RETURN BNE TOGG OFF EDGE, RETURN TO SEC RIGHT SIDE ROL OOE7 RETURN BNE TOGG —" DISPLAY SUBROUTINE -"" PORT TO OUTPUT DISP LDA tt$7F 0248 A9 7F STA 1741 024A 8D 41 17 INIT. DIGIT 024D A9 09 LDA tt$09 STA 1742 024F 8D 42 17 BIT POSITION TO LDA tt$20 0252 A9 20 6TH BIT STA OOEO 0254 85 EO 3 BYTES BIT LDY tt$02 0256 AO 02 ZERO CHARACTER LDA tt$00 0258 A9 00 STA OOE1 025A 85 El 26 025C 025E 0260 0262 0264 0267 0269 026A 026C 026E 0270 0272 0274 0276 0278 02 7A 027D 027F 0282 0285 0287 0289 028C 028F 0292 0294 0296 0297 0299 029B 029D 029F 02AO 02A1 02 A3 02A4 02A5 02A7 02A9 02AB 02 AC 02AE 02AF 02BO 02B1 02B3 02B5 02B7 02B9 02BB 02BD 02BF 02C1 GET BYTE Bl E2 BYTE IDA (OOE2),Y NTH BIT = 1? AND OOEO 25 EO BEQ NOBT NO, SKIP FO 07 YES, UPDATE LDA OOE1 A5 El ORA OOE4,Y CHARACTER 19 E4 00 STA OOE1 85 El DEY 88 NEXT BYTE BPL BYTE 10 FO CHAR. IN ACCUM. LDA OOE1 A5 El CPY OOE8 SHIP ON? C4 E8 NO, SKIP BNE DIGT DO 08 A4 EO LDY OOEO IS THIS SHIP DIGIT? CPY OOE7 C4 E7 NO, SKIP BNE DIGT DO 02 ADD IN SHIP ORA tt$08 09 08 LIGHT DIGIT 8D 40 17 DIGT STA 1740 DELAY (DIGIT ON) LDA tt$30 A9 30 8D 06 17 STA 1706 AD 07 17 DELA LDA 1707 TIME UP? FO FB NO BEQ DELA LDA tt$00 TURN OFF SEGMENTS A9 00 8D 40 17 STA 1740 EE 42 17 SHIFT TO NEXT DIGIT INC 1742 EE 42 17 INC 1742 SHIFT TO NEXT BIT 46 EO LSR OOEO BNE BIT MORE BITS DO CO RTS 60 »""" CHECK SUbKUUiiiNt "• C6 E9 CHEK DEC OOE9 DEC. TIMES THRU COUNT DO 1A SKIP IF NOT 48TH TIME BNE MORE A9 30 LDA tt$20 RESET TIMES THRU COUNT STA 85 E9 OOE9 8A SAVE X TXA PHA 48 LDX #$FD NEGATIVE 3 IN X A2 FD SED DECIMAL MODE F8 (TO ADD ONE) 38 SEC ..INCREMENT COUNTER NXTB LDA OOFC,X B5 FC WHICH IS MADE OF BYTES ADC tt$00 69 00 STA OOFC,X IN DISPLAY AREA (OOF995 FC E8 I NX OOFB).. NEXT BYTE BNE NXTB DO F7 D8 CLD 68 PLA RETURN X AA TAX ..SET UP FOR NEXT GROUP INC OOE2 E6 E2 LDA OOE2 OF BYTES.. A5 E2 MORE CMP #$30 ALL GROUPS FINISHED? C9 30 YES, RECYCLE ASTR. FIELD FO 09 BEQ RECY SHIP - ASTEROID MATCH? MATCH LDY tt$00 AO 00 LOAD CRAFT POSITION LDA OOE7 A5 E7 AND WITH ASTEROID BYTE AND OOE2,Y 31 E2 IF MATCH, YOU'VE HAD IT BNE FIN DO 07 EXIT MATCH SUBROUTINE RTS 60 27 02C2 02C4 02C6 02C8 02CB RECY A9 00 85 E2 FO Fl 20 IF IF FIN ifC C8 02 02CE 02CF 02DO 02D1 02D2 02D3 02D4 D5 02 08 40 01 04 FF LDA #$00 STA OOE2 BEQ MATCH JSR SCANDS JMP FIN GO THRU ASTEROID FIELD AGAIN UNCONDITIONAL BRANCH DISPLAY COUNT CONTINUOUSLY LOW POINTER, ASTEROID BELT HIGH POINTER, ASTEROID BELT MASK, BOTTOM SEGMENT MASK, MIDDLE SEGMENT MASK, TOP SEGMENT CRAFT POSITION FLAG (SHIP ON) x:c::;::: ASTEROID FIELD «•»»'" 02D502E502F50305- 00 00 00 04 00 08 00 06 12 00 11 00 05 00 2C 00 16 00 29 00 16 00 2B 00 26 00 19 00 17 00 38 00 2E 00 09 00 IB 00 24 00 15 00 39 00 OD 00 21 00 10 00 00 : { : {: : " " HEX DUMP - ASTEROID "5««"« . -7 * 1 A p c O ^T A9 00 85 F9 85 FA 85 FB A2 06 BD CE 02 95 E2 CA 10 F8 A5 E8 49 FF 85 E8 A2 05 20 48 02 20 97 02 CA DO F7 20 40 IF 20 6A IF C9 15 10 E5 C9 00 FO 06 C9 03 FO OA DO DB 06 E7 A9 40 C5 E7 DO D3 46 E7 DO CF 38 26 E7 DO CA A9 7F 8D 41 17 A9 09 8D 42 17 A9 20 85 EO AO 02 A9 00 85 El Bl E2 25 EO FO 07 A5 El 19 E4 00 85 El 88 10 FO A5 El C4 E8 DO 08 A4 EO C4 E7 DO 02 09 08 8D 40 17 A9 30 8D 06 17 AD 07 17 FO FB A9 00 8D 40 17 EE 42 17 EE 42 17 46 EO DO CO 60 C6 E9 DO 1A A9 30 85 E9 8A 48 A2 FD F8 38 B5 FC 69 00 95 FC E8 DO F7 D8 68 AA E6 E2 A5 E2 C9 30 FO 09 AO 00 A5 E7 31 E2 DO 07 60 A9 00 85 E2 FO Fl 20 IF IF 4C C8 02 D5 02 08 40 01 04 FF 00 00 00 04 00 08 00 06 12 00 11 00 05 00 2C 00 16 00 29 00 16 00 2B 00 26 00 19 00 17 00 38 00 2E 00 09 00 IB 00 24 00 15 00 39 00 OD 00 21 00 10 00 00 , ~ pO, 0200021002200230^ 02400250026002700280029002AO02BO02CO02DO02EO02FO0300- 5 CHANGES YOU CAN MAKE YOUR OWN ASTEROID FIELD STARTING AT 02D5. THE GROUP COUNT, C02B6), WILL HAVE TO BE CHANGED IF THE FIELD SIZE DIFFERS. THE SPEED OF THE CRAFT MOVING THROUGH THE FIELD IS CONTROLLED BY 027E.'' WHAT ABOUT A VARYING SPEED, SLOW AT FIRST AND SPEEDING UP AS YOU GET INTO THE FIELD? WHAT ABOUT A FINAL "DESTINATION COUNT" AND A SIGNAL TO INDICATE YOU HAVE REACHED YOUR DESTINATION? HOW ABOUT ALLOWING A HIT OR TWO BEFORE YOU ARE FINALLY DISABLED? 28 BAGELS BY JIM BUTTERFIELD DIRECTIONS THE COMPUTER HAS CHOSEN FOUR LETTERS, ALL OF WHICH ARE A,B,C,D,E, OR F. LETTERS MAY BE REPEATED - FOR EXAMPLE, THE COMPUTER'S "SECRET" COMBINATION MIGHT BE CACF OR BBBB. YOU GET TEN GUESSES. EACH TIME YOU GUESS, THE COMPUTER WILL TELL YOU TWO THINGS: HOW MANY LETTERS ARE EXACTLY CORRECT (THE RIGHT LETTER IN THE RIGHT PLACE); AND HOW MANY LETTERS ARE CORRECT, BUT IN THE WRONG POSITION. FOR EXAMPLE, IF THE COMPUTER'S SECRET COMBINATION IS CBFB AND YOU GUESS BAFD, THE TWO NUMBERS WILL BE 1 AND 1 (THE F MATCHES EXACTLY; THE B MATCHES BUT IN THE WRONG PLACE). THESE NUMBERS WILL SHOW ON THE RIGHT HAND SIDE OF THE DISPLAY; THE CODE YOU ENTERED WILL APPEAR ON THE LEFT. MAKE A NOTE OF YOUR GUESSES AND THE COMPUTER'S RESPONSE. WITH A LITTLE MENTAL WORK, YOU SHOULD BE ABLE TO BREAK THE CODE EXACTLY IN SEVEN OR EIGHT WORDS. A CORRECT GUESS WILL PRODUCE A RESPONSE OF if - 0. IF YOU DON'T GUESS RIGHT IN TEN MOVES, THE-COMPUTER WILL GIVE YOU THE ANSWER. AFTER A CORRECT GUESS, OR AFTER THE COMPUTER TELLS YOU THE ANSWER, IT WILL START A NEW GAME (WITH A NEW SECRET CODE) THE INSTANT YOU TOUCH A NEW KEY. 0200 E6 16 GO 0202 20 40 IF 0205 DO F9 020? D8 0208 A9 OA NEW 020A 85 18 020C A9 03 020E 85 10 0210 38 RAND 0211 A5 13 0213 65 16 0215 65 1? 0217 85 12 0219 A2 04 021B B5 12 RLP 021D 95 13 021F CA 0220 10 F9 0222 A6 10 0224 AO CO 0226 84 11 0228 AO 06 022A C5 11 SET 022C 90 02 022E E5 11 0230 46 11 PASS 0232 88 0233 DO F5 0235 18 0236 69 OA INC RND+4 randomize JSR KEYIN on pushbutton delay BNE GO CLD LDA #$OA ten guesses/game STA COUNT new