the first book of kim

178
8/6/2019 The First Book of KIM http://slidepdf.com/reader/full/the-first-book-of-kim 1/178

Upload: cubemanpdx

Post on 08-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 1/178

Page 2: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 2/178

Hie

First Book of KIA\Edited by

JIM BUTTERFIELD • STAN OCKERS • ERIC REHNKE

HAYDEN BOOK COMPANY, INC.

Rochelle Park, New Jersey

Page 3: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 3/178

Dedicated to the person who just purchased a KIM-1an d doesn't know what to do with it...

Individual programs in this book were contributed by the various authors

wthout copyright restrictions.

These programs may be used or copied without restriction. It is, how-

ever, 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 revi-

sions 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, Penn-

sylvania 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

Copyr ight © 1977, 1978 by F. J. Butterfield. Al l rights reserved. Except asnoted 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

an y 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 PRINTING

78 79 SO 81 82 83 84 85 86 YEAR

Page 4: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 4/178

Page 5: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 5/178

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 useof his KIM-interfaced Selectric.

The KlM-1 microcomputer is manufactured by Commodore/MOS Technol-ogy, 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, th e complete KIM-1 system (less powersupply) sells for $245.

All programs in this book run on the basic KIM-1 system; two require anaudio amplifier.

Page 6: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 6/178

Page 7: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 7/178

A BEGINNER'S GUIDE TO KIM PROGRAMMING.'

Running programs can be fun. But writing programs can beeven 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 tothe mechanics of programming, so you can find your own wayat 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 seewhat happens. And you can borrow whole sections of codingfrom another program if it does something you want.

LOOKING AT MEMORY

Random Access Memory.

If you've just turned your KIM system on f press theRS (Reset) button to get things started. Hit the followingkeys: AD (for ADDRESS) 0000. You've just entered th eaddress of memory cell 0000, the lowest numbered one inmemory. The display will show 0000 (the number youentered) on the left. On the right, you'll see thecontents of cell 0000: it will be a two digit number. Thatnumber might be anything to start with; let's change it.

Press key DA (for DATA). Now you're ready to change thecontents of cell 0000. Key in 44, for example, and you'llsee that the cell contents have changed to 44.

Hit the + button, and KI M will go to the next address.As you might have guessed, the address following 0000 is0001. 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 thedisplay.

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 memoryyou lik e, directly , without having to start at the lowest

address and working your way through. Check this by goingstraight up to address 0123 and looking at its contents(key AD 0 1 2 3); then address 0000 (key AD 0 0 0 0), whichshould still contain the value 44 that we put there.

Page 8: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 8/178

Hexadecimal N umbers

Now that you're back at address 0000, let's step throughseveral locations using the + key. Don't worry aboutcontents too much. 0001 will still contain your lucky

numbe r, of course, but keep stepping with the + key untilyou reach 0009. What will the next address be? Most peoplewould think that the next number should be 0010, and thatwould be correct if KIM used the familiar decimal numberingscheme. But KIM still has six more digits to go past 9,because it uses a computer numbering scheme calledHexadecimal. Hit the + key and you'll see address OOOA comeup.

Don't let the alphabetic confuse you - to KIM, A is justthe digit that comes after 9. And there are more digits tocome. Keep pressing the + button and you'll see that A isfollowed by B, C, D, E and F. Final ly, 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 valueafter 0000; it's really the sixteenth (the word Hexadecimalmeans: based on sixteen).

If you don't understand why the letters appear, don't worryabout it too much. Just understand, for the moment, thatthe alphabetics represent genuine numbers. So if you'reasked to look at address 01EB, you'll know that it's alegitimate address number like any other. And if you'retold 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 explainHexadecimal numbering in detail. There's even an appendixin your 6502 Programming Manual on the subject. It makesimportant and worth-while reading. But for now, justrecognize that although the numbers may look a littlefunny, 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 intoRAM.

There's another kind of memory in KIM, but you can't storenumbers there. It's called ROM, for Read Only Memory. Thiskind of memory contains fixed values that cannot bechanged.

Page 9: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 9/178

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. Tryit: press DA 6 6 to try to change the contents to 66. Seehow it won't work?

ROM contains pre-stored programs which do important thingslike lighting the display, detecting keyboard input, andreading or writing your cassette tape. These programs arecalled th e Monitor. In fact, the name KIM stands forKeyboard I nput Monitor in recognition of the importance ofthese programs. We'll talk briefly about the Monitorprograms later.

Special Memory Locations

A few addresses in KIM are connected to things that aren'treally memory at all. You can read up on them in the KIMUser Manual when you're ready; we'll just point out a few

examples here.If you try to store a number into address 1700, forexample, you might find that instead of storing the value,KIM will convert it to voltages and deliver these voltagesto certain pins on your Application Connector at the edgeof the board! Another example: address 1704 connects to avery fast timer - look at that address and you'll see"time going by" as a blur!

Page 10: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 10/178

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'lllearn quite a few things about getting KIM programsgoing.

CAUTION: Before running this or any other program, besure that you have set the contents of the KIM "vector"locations as follows:

Set address 17FA to 00Set address 17FB to 1CSet address 17FE to 00Set address 17FF to 1C

The first two locations are needed so that your SSTswitch and ST key will work right. The last two make theBRK (break) instruction behave properly. YOU MUST ALWAYSSET 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 usuallylooks something like this:

0200 A5 10

0202 A6 110204 85 110206 86 100208 00

START LDA 10

LDX 11STA 11

STX 10

BRK

address 10 to A

address 11 to XA to address 11X to address 10stop the program

The business end of the program - the part that goes intothe computer - is the group of numbers on the left handside. The stuff on the right helps explain what theprogram does.

If you look at the numbers on the left, you'll see thatthe first one, 0200, looks like an address. That'sexactly what it is, and we can start by entering it withAD 0 2 0 0. The next number is A5, and that will be its

contents. So h it DA A 5, and the display will confirmthat we've put it in.

Page 11: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 11/178

Keep going on the same line. Each line of the programlisting may contain more than one value - for more thanone 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 modeuntil you press the AD key. Continue to the nextline: just hit + A 6 + 1 1 and keep going until you'veput the 00 in location 0208. Congratulations! You'veloaded your first program. Now go back and check itfor correctness. Hit AD 0 2 0 0 and use the + key tostep through and check th e values.

Now let's run the program and see if it works. First,look at the contents of addresses 0010 and 0011. Makea note of them; when the program runs, it will swapthose two values.

Keep in mind that loading the program doesn't makeanything 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 instructionin the program is located - you may have noticed thatit's marked START in the listing. Now the displayshows 0200 A5, and w e're ready to go. So - hit GO.And the program will run.

Doesn't take long, does it? The display will havechanged to 020A xx. If the display shows any otheraddress, something's wrong. Check that your SST switchis off (left), that th e program is entered correctly,and that your vectors are OK.

Your program ran in less than a fifty thousandth of asecond. No wonder you didn't see the displayflicker.

Now check that the program did indeed run correctly b y -

looking at the contents^ of locations OQIO and CX011.You'll see that they have been exchanged.

10

Page 12: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 12/178

How it works

Inside the Central Processor (the heart of thecomputer) are several temporary storages calledregisters. You can LOAD many of these registers withthe contents of memory; and you can STORE the contents

of the registers into memory. The two registers we areusing here are called A and X.

If we Load A from address 10, A now contains a copy ofthe contents of 0010. Location 0010 itself won't bechanged; it will also contain that number. We do thesame thing when we Load X from address 0011.

Now our A and X registers contain copies of the numbersin 0010 and 0011 respectivel y. If we Store A intoaddress 0011, that address will now contain a copy ofthe value in A - which was originally the contents ofaddress 0010, remember? Finally, we Store X into 0010to complete the swap.

Look at the listing again. On the right hand side, wehave the program exactly as we have described it, butabbreviated. You can see that LDA means Load A and soforth. 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. Evenso, follow this procedure. It will show you how totest any KIM program.

First go back to addresses 0010 and 0011 and put acouple 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.

1 1

Page 13: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 13/178

Seeing the Registers

Registers A and X, plus quite a few we haven't talkedabout, are inside the 6502 microprocessor chip. There'sno way you can view them - they are buried deep within

the electronics.

To help you out, the KIM Monitor system wil l write outa copy of these registers into memory where you caninspect them. Th e contents of the A register may beseen at address OOFS, and the contents of the Xregister are at OOFS.

Don't be confused: These locations are not the actualregisters, just copies made for your convenience. Butit's a great convenience, for it allows you to seeeverything 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 switchis on, hit the GO button once. The display will show0202. That means: instruction at 0200 completed, readyto do the one at 0202.

Okay, let's check everything in sight. The firstinstruction was to load the A register, right? Enteraddress OOFS and check that its contents (whichcorrespond to the contents of A) are indeed the valuefrom address 0010. If you like, look at 0010 andconfirm that it hasn't changed.

Now for a clever KIM touch. If you're ready to proceedwith the nex t instruc tion , hit PC (for Program Counter)and you'll find yourself back at address 0202, ready toperform the next instruction.

You've executed one instruction, performed one programstep. Remember this: No matter how complex the program,it always operates one simple step at a time. And nowyou 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

Page 14: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 14/178

From this point, find your own way through the last twoinstructions. Don't bother about the BRK (Break); itjust stops the program. As the two registers arestored, you'll want to check that the memory addresseshave been changed as expected.

Summary

Th e most important things that you've learned aboutcoding 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 befound in the KIM U ser Guide on page 39, Fig. 3-13 -when you need it.

From here on, you don't have to take anybody's word forany 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 swapthe contents of locations 0010 and 0011:

0200 A5 100202 85 110204 A6 110206 86 100208 00

START LDA 10

STA 11

LDX 11

STX 10

BRK

put 0010into A

store A to 0011put 0011 nto Xstore X to 0010stop

It didn't work. Can you see why?

3. Can you write a program to take the contents ofaddress 0010 and place the same value in locations0011, 0012, and 0013?

13

Page 15: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 15/178

MINI-PROGRAM B; Setting many locations to zero

Here's the program:

020002020204

020602070209

A9A295CA

1000

00

0930

FB

START

LOOP

LDA

LDX

STA

DEX

BPL

BRK

#0

19

30, X

LOOP

value 0 into Astart X at 9zero into 0030+Xdecrease X by 1back if X positvstop the program

This program, when you load and run it, will set thevalue 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 theprogram does. But here are a few highlights:

When we load registers A and X in the first twoinstructions, we don't want to load the contents of amemory location. Instead, we want the actual values 0and 9. To do this, we use a new kind of addressingcalled IMMEDIATE addressing.

Immediate addressing, when we use it, says "Don't go tomemory - use this value." Immediate addressing can bespotted two ways. First, note the I sign that we usein writing the program: that signals that we are using

immediate mode adressing. Secondly, you may havenoticed that the computer instruction (called the OpCode) has changed: the previous program used code A5to mean LDA; now we're using A9, which also means LDAbut signals immediate addressing.

You can - and should - use the SST feature to checkthat immediate addressing works as advertised.

Th e instruction at 0204 uses the X register forINDEXING. That means that instead of storing the Avalue in address 30, the computer first calculates aneffective address by adding the contents of the Xregister to the "base address" of 30. Since X contains9 the first time through, the effective address will be30+9 or 39 - and that's where we store our A value of00. Later, X will be decreased to a value of 8, sowe'll store into address 38.

14

Page 16: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 16/178

Indexing seems complicated, but remember that it's avery powerful feature of KIM. Try to g i e t the hang ofit; 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 soon). Eventually, as this part of the program isautomatically repeated, X will reach a value of 00.Finally, when we decrement X one more time, X will goto value FF, which KIM "sees" as a negative number,kind of like the value -1. KIM views all values in therange 80 to FF as negative - when you're ready, theProgramming Manual will tell you more.

The BPL instruction at line 0207 is a CONDITIONALTEST. BPL means Branch plus. If the result of ourprevious operation (Decrement X) gives us a positive,or plus, number, we will branch back to address 0204and

repeat the instructions from that point. The Xvalues of 9, 8, 7 ... down through 0 are all positiveor plus; so each time we'll go back and set one morelocation in memory to value zero. Finally, X becomesequal to value FF - a negative number. So in thiscase, BPL won't branch: the "plus" or "positive"condition isn't satisfied.

This last time, since BPL doesn't take us back, weproceed to the following instruction, BRK , which stopsthe program. That's OK because we've done our job ofsetting addresses 0030-0039 to value zero.

Single Step the program carefully, checking the valueof X from time to time (location OOF5, remember?).Satisfy yourself that you can see it working.

By the way, that funny address on the branchinstruction (FB) is a special kind of addressing modecalled RELATIVE addressing. All branches use it; it'sworth reading up on.

Exercises

1. Can you change the program to place value 55 in theabove locations?

2. Can you change the program to place value 00 inlocations 0030 to 0037?

3. Can you change the program to place value FF inlocations OOAO to OOBF?

15

Page 17: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 17/178

INTERLUDE - PROGRAM TESTING

You've met one very powerful tool for checking outprograms - the Single Step mode of operation. Let'sreview 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.Th e register values are copied into memory locationsfrom OOEF to OOF5, and while they are not realregisters, just copies, they are just as good fortesting purposes. Not only can you look at them, youcan change them to new values. This ability to change aregister can be handy in solving the "what if ... " typeof question, or shortening testing of a loop.

For example, if you are single-stepping throughmini-program B and you don't want to go around the loopa full ten times, you might use this trick. Go around acouple of times to get the loop started, and then changeX (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 setthe whole ten locations to zero, of course. But youwill see that the loop itself is working right.

The Inserted BRK (Break)

Sometimes SST seems slow. You might have a longprogram, and you're sure that the first part isworking. What you want is a way to run directly throughthe 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 BRKcommand, 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 hashappened.

Let's try doing that on mini-program B. Let's say wewant to run straight through to the BPL instruction at0207, and then single-step from that point on.

16

Page 18: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 18/178

Change 0207 (previously 10) to value 00, the BRKcommand. Now go to the beginning of the program(0200), be sure SST is off, and hit GO. You'll see0209 00 on the displ ay, which tells you that the haltat 0207 has worked. Now go back to 0207, put the value

of 10 (for BPL) back in, set the SST switch on, andyou're ready to step. Easy? You bet - and you can savelots of time this way in testing big programs.

No Operation (NOP, code EA)

It sounds funny, but a very handy instruction is onethat doesn't do anything. When the microprocessorencounters Op Code EA (NOP), it does nothing - justpasses on to the next instruction.

The biggest use of the NOP instruction is to take outanother instruction that you don't want any more; or to

leave room in the coding to add another instructionlater if you need to.

Some programmers write their programs in sections, andat first they put a BRK instruction between eachsection. That way, when they are testing, the programwill stop after each part, and they can check to seethat each part runs OK. When they are finishedtesting, they change the BRK's to NOP's and the programwill 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 away

1on 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 DEXinstruction. We'll do this by replacing it with a NOP;so write value EA into location 0206. What willhappen?

When we run the program, the X register will neverchange from its starting value of 9 because we don't

have a DEX instruction . So the program will keepbranching back to LOOP forever, and it will neverstop. We've created this situation artificially, ofcourse, but it could have happened by oversight when wewere writing the program.

17

Page 19: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 19/178

Set address 0200, SST off, and hit GO. Everything goesdead. Our program is running but it will never stop.Meanwhile, th e display is dark. This time we know whyit's happening. But if we didn't, how would we solve

it?

Press ST - stop - and the computer will freeze. Thedisplay will light showing the next instruction we wereabout to execute. If we wanted to pinpoin t thetrouble, we could flip over to SST now and track theproblem down, step by step.

A last comment on the ST button: If the display goesdark and pressing ST doesn't relight it, the computerhas a different problem. It has gone berserk due to acompletely 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

Page 20: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 20/178

MINI-PROGRAM C; Displaying values

KIM has a 6-digit display. You can show information onthe display quite easily, if you know how.

In the KIM Monitor programs there are several packagescalled subroutines that you can call upon to docertain jobs. You could write the same coding forthese jobs yourself; but use the Monitor subroutines tosave time and trouble.

When you give the command JSR SCANDS (coded 20 IF IF),the Monitor will briefly light the display with thedata it finds in addresses OOFB, OOFA, and OOF9.That's three locations, each displaying as two digi ts,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 repeatthe JSR SCANDS command over and over again. Use aloop, of course; no point in filling up your programwith JSR SCANDS instructions.

You should also know that when you call this Monitorsubroutine, the contents of your registers are wipedout. So if you have something important in the Aregister that you will want to use after giving JSRSCANDS, be sure to put it safely somewhere in memory oryou'll lose it. The same goes for other registers likeX and Y.

Here's a simple program to show 0000 00 on thedisplay. Note that we must put the value 00 intoaddresses FB, FA, and F9 before we call JSR SCANDS.

02000202

0204

02060208

020B

A9858585204C

00FBFA

F9

IF08

IF02

START LDA

STA

STA

STA

LOOP JSR

JMP

#0

POINTH

POINTL

INK

SCANDS

LOOP

zerofirstnextlastlightdo it

into A

22

2 digitsdigitsdigits

up!again

19

Page 21: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 21/178

This program never ends, so eventually you'll have tostop it with the RS or ST keys. See how the lastinstruction jumps back to address 0208 so the displayis lit continuously? Another interesting point: seehow the jump address at 020B is "backwards" - 08 02instead of 0208? This is called "low order first"addressing and you'll see a lot of it on the KIMsystem.

The single-step feature doesn't work too well onMonitor subroutines. That's normal, and it's notserious. These subroutines are well tested anddependable, so you shouldn't need to use SST withthem.

Exercises

1. Can you ch ange the program to make th e display show5555 55?

2. Can you write a program to make the display show1234 56?

3. How about a program to show the word EFFACE? orFACADE? or COOCOO?

20

Page 22: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 22/178

MINI-PROGRAM D; reading the k eypad

To read the KIM pushbuttons you have another Monitorsubroutine called GETKEY. You "call" it with

JSR GETKEY (20 6A IF). This subroutine will give youthe identity of the key that is being pressed at thatmoment as a value in the A register. You can continueby using this value any way you want. If no key isbeing pressed at the time, you'll get a value of 15 inA.

There are a couple of cautions on the use ofJSR 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 upthe channel" from the keyboard with either one of two

subroutines: JSR SCANDS or JSR KEYIN. You've metJSR SCANDS before: it's used to light the display. Ifyou 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 itsees:JVi0•

02000201

0203

02050207

0209020C020F

D8A9858585

20204C

00FB

FA

F9

IF6A

03

START CLD

LDA

STORE STA

STA

STA

IF JSRIF JSR

02 JMP

clr dc mode#0POINTH

POINTL

INK

SCANDSGETKEY

STORE

zero into A

light displaytest keys

Exercises

1. Do you think that the instruction at 0201 is reallyneeded? Try removing it (change 0201 and 0202 to EA)and see.

2. What values do you get for the alphabetic keys? Forkeys like PC and GO? Are there any keys that don'twork with JSR GETKEY?

3. Try running in decimal mode (change 0200 to SED,code F8). What happens? Is it serious? How about keyF?

4. Can you change the program so that only the lastdigit of the display changes with the keyboard?

21

Page 23: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 23/178

CONCLUSION

You've reached the end of our little Beginner's Guide.But you've only started on the road towardsunderstanding programming.

Use the tools we have given you here to forge your ownpath. KIM is a very rich machine. You have 56 OpCodes to choose from, and many powerful addressingcombinations. You don't need to learn them all rightaway, but when you need them, they'll be there.

The KIM Programming Manual makes good reading. Don'ttry to go through the whole thing at one sitting. Stopand try a few th ings; you have the Single Step featureto help you understand what each instruction reallydoes.

Try leafing through - or stepping through - otherpeople'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 todo, borrow the coding - you don't need to re-invent thewheel.

Don't be discouraged when your program doesn't work onthe first try. Even experts have to spend time gettingthe "bugs" out of their coding. It's part of thegame: Think of yourself as Sherlock Holmes,methodically tracking down the elusive villains.

A proverb says that a journey of a thousand milesstarts with the first step. In the same way, hebiggest programs still operate one step at a time.

So forge ahead at your own speed. Communicate withother KIM owners; you'll have a lot of information toswap.

But most of all: have fun.

22

Page 24: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 24/178

RECREATIONALPROGRAMS

Clear Decimal Mode: Set 00?1 to 00 before running these programs.

Page 25: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 25/178

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 STARTOVER. THEN ENTER A NU MBER AND HIT THE PLUS KEY TO ADD IT

TO THE PREVIOUS TOTAL. IF YOU MAKE A MISTAKE IN ENTERING

A N UMBER, 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 S T A R T0203 20 6A IF0206 C5 600208 FO F 6020A 85 60

020C C9 O A020E 90 29

0210 C9 130212 FO 18

0211* C9 120216 DO E80218 F8 18021A A 2 FD

021C B 5 FC AD D021E 75 650220 9 5 F C0 2 2 2 95 65022ii E8

0225 30 F50227 86 610 2 2 9 D8022A 10 D U

0 2 2 C A 9 0 0 D O G O

0 2 2 E 85 610230 A 2 0 20232 9 5 F 9 CLEAR

023k CA0235 10 F B0237 30 C 70239 A l* 61 N U M

023B D O O F023D E6 61023F 1*8021*0 A 2 0 2

JS R SCANDSJS R G E T K E YC M P PR3VBEQ S T A R TST A P R E VC M P #$OAB C C N U M

C M P #$13B E Q D O G O

C M P #$12BN E S T A R TS ED CL CL D X #$FD

L D A P O I N T H + 1 , XA DC A C C U M + 3 , X

S T A PO I NT H-» - l , XS T A A C C U M + 3 , XIN XBM I A DDS T X F I A GCL D

B P L S T A R TL D A #0S T A F L A G

L D X nS T A I N H , X

D E XBPL CLEARB M I S T A R TL DY F I A GBN E P A S SIN C F I A GP H A

L D X #2

light displayread keyboardsame as last time?yes, skipno, save new keynumeric key?yes, branchG O key?yes, branch+ key?no, invalid keyprepare to addminus 3; 3 digits

display digitadd totaltotal to display& to total a c c um

next digitlast digit?flag total-in-disnlay

return to startset flap fortotal-in-diS Dl ayfor 3digits...clear disnlay

next digitlast digit?finished, back to gototal-in-display?no, add new digitclear t-i-d flagsave key3 digits to move

24

Page 26: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 26/178

02^2 B 5 F 902UU 95 6202U6 9 U F 90 2 U8 C A

0 2 U 9 10 F 702UB 6802i|C O A O A02l|E Q A OA0250 A 2 O U

02^2 O A

0253 26 F90255 26 FA0 2 5 7 26 FB0259 CA025A DO F6025C FO A 2

M O V E IDA I N K ,IST A A C C U M , XS T Y I N H , XD E X

B P L M O V EP L A

P A S S A S L A A S L AA S L A A S L A

L D X # bS HI F T A S L A

R OL IN HR O L P O I N T LR O L P O I N T HD E X

B N E SHIFTBEQ S T A R T

get display digitcopy to total Accumclear displaynext digit

last digit?recall keymove digit....into positionh bitsmove bit f ro m A..to I N H . ...to rest of

displaynext bitlast bit?yes. back to start

«xxx:: HEX DUMP - ADDITION K X X J C X

0200 20 IF IF 20 6A IF C5 60 FO F6 85 60 C9 OA 90 29

0 2 1 0 C9 13 FO 18 C9 12 DO E8 F8 18 A2 FD B5 FC 75 650220 95 FC 95 65 E8 30 F5 86 61 D8 10 D4 A9 00 85 610230 A2 02 95 F9 CA 10 FB 30 C7 A4 61 DO OF E6 61 480240 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

N O T E : W H E N E V E R S P A C E P E R M IT S , A H E X D U M P O F T H EP R O G R A M S L IS T E D W I L L B E G I V E N . T H E S E D U M P SW E R E T A K E N F R O M A C T U A L R U N N I N G P R O G R A M S . S O ,I F T H E R E IS A D I S C R E P A N C Y B E TW E E N T H E L I S T I N GA N D T H E D U M P , T H E L I S T I N G I S M O S T P R O B A B L Y INERROR.

25

Page 27: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 27/178

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.

26

02000202020402060208020A020D020F

0210021202140216

0218021A

. 021D

02200221

02230226

0229022B022D022F

02310233

0235

0237Q239023B023D023F0241

02430244

0246

A9 00

85 F985 FA85 FBA2 06BD CE 02

95 E2CA

10 F8

A5 E849 FF

85 E8

A2 0520 48 0220 97 02CA

DO F720 40 IF

20 6A IF

C9 1510 E5C9 00

FO 06

C9 03FO OA

DO DB

06 E7A9 40

C5 E7DO D346 E7DO CF

3826 E7DO CA

LDA t t $ 0 0

STA 00 9STA OOFA

STA 00 B

LDX t t $ 0 6

INIT LDA 02CE/X

STA OOE2,XDEX

BPL INIT

TOGG LDA OOE8EOR #$FF

STA OOE8

LDX t t $ 0 5

LITE JSR DISPJSR CHEK

DEX

BNE LITE

JSR KEYIN

JSR GETKEY

CMP t i $ 1 5

BPL TOGG

CMP t t $ 0 0

BEQ LEFT

CMP t t $ 0 3

BEQ RT

BNE TOGG

LEFT ASL OOE7

LDA tt$40

CMP OOE7

BNE TOGG

RT LSR OOE7BNE TOGG

SECROL OOE7BNE TOGG

...INITIALIZE COUNTER...

...INITIALIZE OOE2-OOE8

...TOGGLE OOE8...

CFLASHER FLAG)

DELAY BETWEEN FLASHESDISPLAY AND..CHECK FOR MATCH

SET DIRECTIONAL REGS.GET KEYBOARD ENTRY

A VALID KEY?

NOKEY 0?

YES, GO LEFT

KEY 3?

YES, GO RIGHT

NOT A VALID KEY

SHIFT CRAFT LEFT

LEFT HAND EDGE?

NO, RETURN

SHIFT RIGHTNOT RIGHT SIDE, RETURN

OFF EDGE, RETURN TORIGHT SIDE

RETURN

—" DISPLAY SUBROUTINE -""

0248

024A024D024F0252025402560258025A

A9 7F8D 41 17

A9 098D 42 17A9 20

85 EO

AO 02A9 0085 El

DISP LDA t t $ 7 F

STA 1741

LDA t t $ 0 9

STA 1742LDA tt$20

STA OOEO

BIT LDY t t $ 0 2

LDA t t $ 0 0

STA OOE1

PORT TO OUTPUT

INIT. DIGIT

BIT POSITION TO

6TH BIT3 BYTESZERO CHARACTER

Page 28: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 28/178

025C025E

0260

0262

0264

02670269026A

026C026E

0270027202740276027802 7A027D

027F

0282

02850287

0289028C

028F02920294

0296

0297

0299

029B029D

029F

02AO

02A102A302A4

02A502A702A902AB

02 AC

02AE02AF02BO

02B1

02B3

02B502B7

02B902BB02BD02BF

02C1

Bl

25

FO

A5

198588

1 0

A5C4DO

A4C4DO

098D

A98D

AD

FO

A9

8DEE

EE

46DO

60

C6DO

A9

858A

48

A2F8

38

B5

6995E8DO

D868AA

E6

A5

C9F O

AO

A531DO

60

E2

EO

07El

E4El

F O

ElE808EO

E702

08403006

07FB

00

4042

42EO

CO

E9

1A

30

E9

FD

FC

00FC

F7

E2

E2

300900

E7E2

07

BYTE IDA

AND

(OOE2),Y

OOEO

BEQ NOBT

LDA

00 ORASTADEY

BPL

LDACPY

BNE

LDY

CPY

BNE

ORA

17 DIGT STALDA

17 STA

17 DELA LDA

BEQ

LDA

17 STA17 INC

17 INCLSRBNE

RTS

OOE1

OOE4,YOOE1

BYTE

OOE1OOE8

DIGT

OOEO

OOE7DIGT

t t $ 0 8

1740t t $ 3 0

1706

1707DELA

t t $ 0 0

17401742

1742

OOEO

BIT

»""" CHECK S U b K U U i i i N t "•

CHEK DEC OOE9

BNE

LDA

STA

TXA

PHA

LDXSED

SECNXTB LDA

ADCSTA

I N X

BNE

CLD

PLATAX

INC

LDA

MORE CMPBEQ

MATCH LDY

LDAAND

BNE

RTS

MORE

t t $ 2 0

OOE9

#$FD

OOFC,X

t t $ 0 0

OOFC,X

NXTB

OOE2

OOE2

#$30RECY

t t $ 0 0

OOE7OOE2,Y

FIN

GET BYTE

NTH BIT = 1?

NO, SKIP

YES, UPDATE

CHARACTER

NEXT BYTE

CHAR. INACCUM.SHIP ON?

NO, SKIP

IS THIS SHIPDIGIT?

NO, SKIP

ADD IN SHIP

LIGHT DIGITDELAY (DIGIT ON)

TIME UP?

NO

TURN OFF SEGMENTS

SHIFT TO NEXT DIGIT

SHIFT TO NEXT BIT

MORE BITS

DEC. TIMES THRU COUNT

SKIP IF NOT 48TH TIME

RESET TIMES THRU COUNT

SAVE X

NEGATIVE 3 IN XDECIMAL MODE(TO ADD ONE)

..INCREMENT COUNTER

WHICH IS MADE OF BYTESIN DISPLAY AREA (OOF9-

OOFB)..NEXT BYTE

RETURN X

..SET UP FOR NEXT GROUP

OF BYTES..

ALL GROUPS FINISHED?YES, RECYCLE ASTR. FIELD

SHIP - ASTEROID MATCH?

LOAD CRAFT POSITIONAND WITH ASTEROID BYTEIF MATCH, YOU'VE HAD IT

EXIT MATCH SUBROUTINE

2 7

Page 29: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 29/178

02C202C402C602C802CB

02CE

02CF02DO02D1

02D2

02D302D4

A9 0085 E2

FO Fl20 IF IFif C C8 02

RECY LDA #$00STA OOE2

BEQ MATCH

FIN JSR SCANDSJMP FI N

D5 LOW POINTER, ASTEROID

0208

400104FF

HIGH POINTER, ASTEROIDMASK, BOTTOM SEGMENTMASK, MIDDLE SEGMENTMASK, TOP SEGMENT

CRAFT POSITIONFLAG (SHIP ON)

GO THRU ASTEROID FIELD

AGAIN

UNCONDITIONAL BRANCH

DISPLAY COUNTCONTINUOUSLY

BELT

BELT

02D5-02E5-02F5-

0305-

00162E

10

000000

00

00290900

040000

00 0816 00IB 00

00 062B 0024 00

12

26

15

000000

11 00

19 00

39 00

05 0017 00OD 00

2C 0038 0021 00

:{:{"::"HEX DUMP - ASTEROID "5««"«

0200-0210-

0220-0230^0240-0250-0260-0270-0280-

0290-02AO-

02BO-02CO-02DO-

02EO-02FO-

0300-

pO,

A910CA

06

E742FO

DO

06

4248AA

0708

000000

.

00F8DO

C9DO

170708

17

17A2

E66040

0517OD

85 F9A5 E8

F7 2003 FOCF 38

A9 20A5 ElA4 EO

AD 07

46 EOFD F8

E2 A5A9 0001 04

00 2C00 3800 21

5

854940OA

26

8519C4

17

DO38E2

85FF

0000

00

FA 85FF 85IF 20

DO DB

E7 DO

EO AOE4 00E7 DO

FO FB

CO 60B5 FC

C9 30E2 FO00 00

16 00

2E 0010 00

-7 *

FB A2E8 A26A IF

06 E7CA A9

02 A985 El

02 09A9 00

C6 E969 00

FO 09Fl 2000 04

29 0009 0000 , ~

106

05C9A97F

0088088D

DO95AOIF

0016

IB

A p

BD CE

20 48

15 1040 C58D 41

85 El10 FO

8D 40

40 17

1A A9FC E8

00 A5IF 4C08 0000 2B00 24

c02

02

E5E717Bl

A517EE

30DO

E7C806

0000

O9520

C9D OA9

E2El

A942

85F7310212

26

15

T

E2 CA

97 0200 FOD3 4609 8D

25 EOC4 E830 8D

17 EE

E9 8AD8 68E2 DOD5 0200 11

00 1900 39

CHANGES -

YOU CAN MAKE YOUR OWN ASTEROID FIELD STARTING AT 02D5. THEGROUP COUNT, C02B6), WILL HAVE TO BE CHANGED IF THE FIELD SIZEDIFFERS. THE SPEED OF THE CRAFT MOVING THROUGH THE FIELD ISCONTROLLED 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 REACHEDYOUR DESTINATION? HOW ABOUT ALLOWING A HIT OR TWO BEFORE YOUARE FINALLY DISABLED?

28

x:c::;::: ASTEROID FIELD «•»»'"

Page 30: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 30/178

BAGELS BY JIM BUTTERFIELD

DIRECTIONS -

THE COMPUTER HAS CHOSEN FOUR LETTERS, ALL OF WHICH AR E

A,B,C,D,E, OR F. LETTERS MAY BE REPEATED - FOR EXAMPLE,

THE COMPUTER'S "SECRET" COMBINATION MIGHT BE CACF OR BBBB.

YO U GET TEN GUESSES. EACH TIME YOU GUESS, THE COMPUTER

WILL TELL YOU TWO THINGS: HO W MANY LETTERS AR E EXACTLY CORRECT

(THE RIGHT LETTER IN THE RIGHT PLACE); AND HOW MANY LETTERS

ARE CORRECT, BUT IN THE WRONG POSITION.

FO R EXAMPLE, IF THE COMPUTER'S SECRET COMBINATION IS

CBFB AND YOU GUESS BAFD, THE TWONUMBERS WILL BE 1 AND 1

(THE F MATCHES EXAC TL Y ; THE B MATCHES BUT IN THE WRONG PLACE).

THESE NUMBERS WILL SHOW ON THE RIGHT HAND SIDE OF THE DISPLAY;

TH E 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 TH E

CODE EXACTLY IN SEVEN OR EIGHT WORDS. A CORRECT GUESS WILL

PRODUCE A RESPONSE OF if - 0. IF YOUDON'T GUESS RIGHT IN

TEN MOVES, THE-COMPUTER WILL GIVE YOU THE ANSWER.AFTER A CORRECT GUESS, OR AFTER THE COMPUTER TELLS YOU

TH E 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 IF0205 DO F9

020? D80208 A9 OA NEW020A 85 18020C A9 03020E 85 10

0210 38 RAND0211 A5 130213 65 160215 65 1?0217 85 120219 A2 04021B B5 12 RLP021D 95 13021F CA0220 10 F90222 A6 100224 AO CO0226

84 110228 AO 06

022A C5 11 SET022C 90 02022E E5 110230 46 11 PASS0232 880233 DO F50235 180236 69 OA

INC RND+4JSR KEYINBNE GOCLDLDA #$OA

STA COUNTLDA #3STA POINTRSECLDA RND+1

ADC RND+4ADC RND+5STA RNDLDX #4LDA RND,X

randomizeon pushbutton delay

ten guesses/gamenew game startingcreate 4 mystery codes

one plus .... . . three previous

random numbers

=new random value

move random numbers overSTA RND+1, XDEX

BPL RLPLDX POINTRLDY #$CO

STY MODLDY #6

CMP MODBCC PASSSBC MODLSR MODDEYBNE SETCLCADC #$OA

divide by 6

keeping remainder

continue division

random value A to F

2 9

Page 31: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 31/178

0238 95 00023A C6 10023C 10 D2023E C6 180240 30 7 0 2 *4 - 2 A9 000244 A2 OC0246 95 04

0248 CA0249 10 FB

024B 20 CE 02024E FO FB0250 20 CE 020253 FO F60255 A5 08025? FO 08

0259 29 60025B 49 60

025D FO A9025F DO DD0261 20 6A IF0264 C9 100266 BO E3

0268 09 OA026A 90 DF026C A8026D A6 10026F E6 100271 B9 E7 IF0274 95 040276 980277 D5 000279 DO 03027B E6 OE027D 8A027E 95 OA0280 A5 070282 FO 310284 AO 030286 B9 oA 00

0289 29 18028B FO 12028D B9 00 000290 A2 030292 D5 OA

0294 FO 050296 CA

0297 10 F90299 30 04029B E6 OF029D 16 OA029F 8802AO 10 E4

STA SECRET, XDEC POINTR

BPL RAND

GUESS DEC COUNT new guess starts hereBMI FINISH ten guesses?LDA #0LDX #$OC clear from WINDOW. . .

WIPE STA WINDOW,X ...to POINTR

DEXBPL WIPE

' ; WAIT FOR KEY TO BE DEPRESSED•

WAIT JSR SHOW

BEQ WAITJSR SHOW

BEQ WAIT debounce keyLDA WINDOW+4 new guess?BEQ RESUME no, input digitAND #$60EOR #$60 previous game finished?

BEQ NEW ...yes, new game;BNE GUESS ...no, next guessRESUME JSR GETKEY

CMP #$10 guess must be inBCS WAIT range A to FCMP #$OABCC WAITTAYLDX POINTR zero to startINC POINTRLDA TABLE, Y segment patternSTA WINDOW, XTYACMP SECRET, X exact match?BNE NOTEXINC EXACTTXA destroy input

NOTEX STA INPUT, XLDA WINDOW+3 has fourth digit arrived?BEQ BUTT . . .noLDY #3 ...yes, calculate matches

STEP LDA INPUT,Y for each digit:AND #$18 . .has it already beenBEQ ON matched?LDA SECRET,YLDX #3 if not, test

LOOK CMP INPUT, X ...against input

BEQ GOTDEXBPL LOOKBMI ON

GOT INC MATCH increment counterASL INPUT, X and destroy input

ON DEYBPL STEP

30

Page 32: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 32/178

02A202A402A6

02A902AB02AC

02AE

02B1

02B302B502B802BA

02BC02BE02CO

02C3020502C6

020802CA02CC

A2

B4

B995CA1020E6

DO20

DOFO

A2B4

B995CA10

A985DO

01GEE708

F6CEOF

F9CEFB8F

0300

E704

F6

E308EO

TRANSIF

02 DELAY

02 BUTT

J

!•

FINISH

FIN2IF

LDX

LDYLDA

STADEXBPL

JSRINC

BNEJSRBNEBEQ

TEN

LDX

LDYLDASTADEXBPLLDASTABNE

#1EXACT, XTABLE,Y

display counts

WINDOW+4.X

TRANS

SHOWMATCH

DELAYSHOWBUTTWAIT

GUESSES

#3SECRET, X

TABLE , YWINDOW, X

FIN2

#$e3 'WINDOW+4

long pause for debounce

wait for key release

MADE - SHOW ANSWER

square ' flag

DELAY unconditional jimp

SUBROUTINE TO DISPLAY

AND TEST KEYBOARD

02CE AO 13 SHOW02DO A2 0502D2 A9 7F

02D4 8D 41 17

02D7 B5 04 LITE02D9 8D 40 1702DC 80 42 1702DF E6 11 POZ02E1 DO FC02E3 88

02E4 8802E5 CA02E6 10 EF02E8 20 40 IF02EB 60

LDY #$13LDX #5LDA #$7FSTA PADD

LDA WINDOW,XSTA SADSTY SBD

INC MOD pause loopBNE POZDEY

DEYDEXBPL LITEJSR KEYIN

RTS

END

Program notes t

1. Program enforces a pause of about 4 seconds afterdisplaying counts or answer. This guards againstdisplay being 'missed

1due to bounce, hasty keying.

2. After count displayed, or at end of game(s), usercan blank display, if desired, by pressing GO orany numeric key. Game operation is not affected,but user may feel it 'separates' games better.

3 1

Page 33: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 33/178

When a digit from the user's guess is matched, itis destroyed so that it will not be matched again.There are two significantly different types of'destruction

1, however (at 2?D and 29D); the test

at label STEP is sensitive to which one is used.

00000004OOOAOOOEOOOF0010001100120018

LINKAGES TO KIM MONITOR•

KEYIN =551F^OGETKEY =:;iF6ATABLE ={>1FE7PADD =!517*HSBD = 5 5 1 7 ^ - 2

SAD =J51740*

; WORK AREAS

SECRET *=*+ computer's secret codeWINDOW *=*+6 display windowINPUT *=*+4 player"s input areaEXACT #=*+! # of exact matchesMATCH *=*+! # of other matchesPOINTR *=*+! digit being inputMOD *=*+! divisor/delay flagRND *=*+6 random number seriesCOUNT *=*+! number of guesses left

ttxxswe HEX DUMP - BAGELS --""»

0200

02100220023002400250

026002700280029002AO02BO

02CO

02DO02EO

E6 16 20

38 A5 131 0 F9 A6

46 11 8830 7A A9

20 CE 02

DD 20 6A

1 0 B9 E7A5 07 FO

A2 03 D510 E4 A202 E6 OF

B9 E7 IF

A2 05 A91 1 DO FC

40 IF

65 1610 AO

DO F5

00 A2

FO F6

IF C9

IF 9531 AO

OA FO

01 B4

DO F9

95 047F 8D

88 88

DO F9

65 17C O 84

18 69

OC 95A5 08

10 BO

04 9803 B905 CAOE B920 CE

CA 10

41 17CA 10

D8 A9

85 121 1 A O

OA 9504 CA

F O 08

E3 C9

D5 00OA 00

10 F9

E702

IF

DO

F6 A9

B5 04EF 20

OA 85

A2 0406 C5

00 C610 FB

29 60OA 90

DO 0329 1830 04

95 08FB FO

E3 858D 4040 IF

18 A9

B5 1211 90

10 1020 CE

49 60

DF A8

E6 OE

FO 12

E6 OF

CA 108F A2

08 DO

17 8C6 0

03 85 10

95 13 CA02 E5 11

D2 C6 18

02 FO FB

FO A9 DO

A6 10 E68A 95 OA

B9 00 0016 OA 88F6 20 CE

03 B4 00

EO AO 13

42 17 E6

32

Page 34: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 34/178

Label Table f o r P r o g r a m B A G E L SA D D R E S S L A B E L W H E R E U S E D

02B5001802AEO O O E

02BE

02BC

1F6A

0200

029B

023E

OOOA

1F40

02D7

0292

OOOF00110208027E029F

174]0230001002DF

02100261021B0012

174017420000022A02CE

02861FE702A4

024B

0246

0004

BUTT

COUNT

DELAY

EXACT

FIN2

FINISH

GETKEY

GO

GOT

GUESS

INPUT

KEYIN

LITE

LOOK

MATCHMOD

NEW

NOTEX

ON

PADD

PASS

POINTR

POZ

RAND

RESUME

RLP

RND

SADSBD

SECRET

SET

SHOW

STEP

TABLE

TRANS

WAIT

WIPE

WINDOW

0282

020A

02B3027B02C6

024002610205

0294025F

027E

020202E60297

029B0226025D0279

029902D4

022C020E02E1023C0257

0220

0200

02D902DC

02380233024B

02AO027102 AC024B

0249

0246

02B8023E

02CC02A4

0286 0292 029D

02E8

02B1022A 022E 0230 02DF

0222 023A 026D 026F

0211 0213 0215 0217 021B 021D

0277 028D 02BE

0250 02AE 02B5

02A6 02CO

0253 0266 026A 02BA

0255 0274 0280 02A9 02C3 02CA 02D7

L a b e l tables, when available, are o f t e n u s e f u lfo r studying a program. For each label (alphabeticallyarranged) you can see,on the left, the addressbelonging to the label; and on the right, where thelabel is used in the program.

3 3

Page 35: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 35/178

BANDIT JIM BUTTERFIELD

Start the program at 0 2 0 0 and on the right, you'll see the $25that KIM has given you to play with. The f u n n y symbols on thel e f t are your "wheels" - hit any key and see them spin.

Every time you spin the wheels by hitting a key it costs you $1.When the wheels stop, you might have a winning combination,in which case you'll see money being added to your totalo n the right. Most of the time, you'll get nothing ...but that's the luck of the game.

T he biggest jackpot is $15: that's three bars across thedisolay. Other combinations pay off, too; you'll soon learnto recognize the "cherry" symbol, which pays $2 every timeit shows in the l e f t hand window.

T h e r e ' s no house percentage, so you can go a long t i m e onyour beginning $25. The most you can make is $99;and ifyou run out of money, too bad: KIM doesn't give credit.

- 7 7 V-i J J

BANDIT MICRO-WARE ASSEMBLER 65XX-1.0 PAGE 01

0010:0020:0030:0040:0050:0060:0070:0080:0090:0100:0110:0120:0130:0140:0150:0160:0170:0180:0190:0200:

02D102D102D102D102D102D1

02D102D102D102D102D1

* * « * « f t f t » * » » f t » » f t » f t » * * f t » f t * * » * X * *

*««*» ONE ARMED BANDIT ********** BY JIM BUTTERFIELD ****** « * *»*»*»* *»« * « « * * * « *»« * * « »« »»

WINDOWAMTARROWRWDSTALLATUMBLE

KEYINPADDSADSBDTABLE *

$0000

$0005$0006$0007$0008$0009

LINKAGES TO KIM

$1F40$1741$1740$1742$1FE7

DISPLAY WINDOWCASH CACHE

REWARD

WAIT WHILE

IS KEY DEPRESSED?

HEX:7 SEG

34

Page 36: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 36/178

0210:0220:0230:0240:0250:0260:

0270:0280:0290:0300:0310:0320:0330:0340:0350:0360:0370:0380:0390:0400:0410:0420:0430:0440:0450:0460:0470:0480:0490:0500:0510:0520:0530:0540:0550:

0560:0570:0580:0590:0600:0610:0620:0630:0640:0650:0660:0670:0680:

0690:0700:0710:0720:0730:0740:0750:0760:0770:0780:0790:

0200020002020204

02070209

020B020E021002120215

02170219021B02 1 C02 1D

021F022102230226

0228022B022D022F023102330235

02370239023B023D023F

A98520A985

20DOE620FO

A985F838A5E9852026

20C6DOA6A52909

954646C6DO

2505BA 0200

06

8D 02FB098D 02F9

0306

050105BA 02

09

8D 0208F906090640

01

090906E7

MAIN PROGRAM

BANDIT ORGGO LDAIM

STAJSRLDAIMSTA

MAIN DISPLAY

LPA JSRBNE

ROLL INCJSRBEQ

LDAIMSTASEDSECLDASBCIMSTAJSR

ROL

LPB JSRDECBNELDXLDAANDIMO R A IM

STAAXLSRLSRDECBNE

$0200$25AMTCVAMT$00

A R ROW

LOOP

DISPLYLPATUMBLEDISPLYROLL

$03ARROW

AMT

$01AMTCVAMTTUMBLE

DISPLYSTALLALPBA R ROW

TUMBLE$06$40

WINDOWTUMBLETUMBLEA R ROWLPB

ALL WHEELS STOPPED

0241024302450247

0249024B024D024F

025102530255

02570259025B025D

A5C5DOC5

DOA2C9FOA2C9FOA2C9FOCA

04033702

331040ODOB4207064401

LDACMPBNECMP

BNELDXIMCMPIMBEQLDXIMCMPIMBEQLDXIMCMPIMBEQDEX

3 5

WINDOWWINDOWNOMATWINDOW

NOMAT$10$40PAY$08$42PAY$06$44

PAY

GIVE HIMTO STARTAND SHOW

$25WITHIT TO HIM.

RESET AR R O W.

DISPLAY[GO] IS

RANDOMIZDISPLAYA KEY IS

UNTILRELEASED.E TUMBLE.UNTILHIT.

CHARGE ONE BUCK.

CONVERT

DISPLAY

MAKE

FOR LED.

A WHILE.

A

RESULT

+01

DO ALL3 WINDOWS.

- COMPUTE

+04

PAYOFF

+03 CHECK FORA

+02

PAY $15

PAY $10

MATCH.

FOR 3 BARS

FOR 3 UPS

PAY $5 FOR 3 DOWNS

Page 37: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 37/178

0800:0810:0820:0830:0840:

0850:0860:0870:0880:0890:0900:0910:0920:0930:0940:0950:0960:0970:

0980:0990:1000:1010:1020:1030:1040:1050:1060:1070:1080:1090:1100:1110:

1120:1130:1140:1150:1160:1170:1180:1190:1200:1210:1220:1230:1240:

1250:1260:1 270 1 280 1 290:1300:1310:1320:1330:

025E0260

0262026402670269026B026D026F027002710273027502770279

027C

86A9

8520C6DOC6FO18F8A569BO

8520

DO

0780

088D 0208F9079C

05019405BA 02

E2

A WIN!!!PAY

PAY STXPAX LDAIM

STALPC JSR

DECBNEDECBEQCLCSEDLDAADCIMBCSSTAJSR

BNE

AMOUNT

RWD$80

STALLADISPLY

STALLALPCRWDLPA

AMT$01LPAAMTCVAMT

PAX

IN X

HIDE REWARD

DISPLAYFOR A HALFA WHILE.

SLOWLY ADDTHE PAYOFFTO THE AM'T.

WHEELS NOT ALL THE SAME - CHECK FOR SMALL PAYOF

027E028002820284

02870289028B

A2C9FO20A5DOFO

0346DA8D 020580F7

NOMAT LDXIMCMPIMBEQ

LOK JSRLDABNEBEQ

$03$46PAYDISPLYAMTLPALOK

A CHERRY?

CAN'T PLAYWITH NO DOUGH!

DISPLAY SUBROUTINE

028D028F

02910293029402960298029B029D029F

02A102A402A702A802AA02AC02AE

02B102B2

A610F6CA10A98DAOA2B5

8C8DD8A9E9DO8DC8C8

060202

FB7F41 17OB0400

42 1740 17

7F01FC42 17

DISPLY LDXBPL

OVER INCAXINDIS DEX

BPLLDAIMSTALDYIMLDXIM

LITE LDAAX

STYSTACLDLDAIM

ZIP SBCIMBNESTAINYINY

ARROWINDISWINDOW

OVER$7F

PADD$08$04WINDOW

SBDSAD

$7F$01ZIPSBD

ROLL+02 THE DRUM

LIGHT

ALL THEWINDOWS

36

Page 38: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 38/178

11111

11111111111111

11

340:350:360:370:380:

390:400:410:420:430:440:450:460:470:480:490:500:510:520:530:540:

02B302B402B602B9

02BA02BC

02BE

02BF02C202C4

02C602C702C8

02C902CA02CB02CE02DO

CA102060

A529AABD85A54A4A4A4A

AABD

8560

E940

05OF

E70005

E701

1F

1F

1 F

DEXBPLJSRRTS

LITEKEYIN

AMOUNT CONVERSION

CVAMT LDA AMTANDIM $OF TRANSLATETAX AMOUNTLDAAX TAB LE TO LEDSTA WINDOW CODE.LDA AMTLSRALSRALSRALSRATAXLDAAX TABLESTA WINDOW +01RTS

SYMBOLAMIDISPLY

LITELPCPAXSAD

TUMBLE

TABLE0005028D029F026402601740

0009

3000 30A2AR R O W 0006GO 0200LOK 0284NOMAT 027EPAY 025ESBD 1742

WINDOW 0000

000602000284027E025E17420000

BANDITINDISLP AOVERROLLSTALLA

ZI P

0200

0293020B02910210

000802AA

CVAMTKEYINLP BPADDRWDTABLE

02BA1F40

0228174100071FE7

You'll notice that the listing for B A N D I T looks a littledifferent f rom others in this book. That's because itis the output of a resident assembler operating inan expanded K IM system. See the section on expansionfo r a f u r t h e r discussion of assemblers .

Y o u might like to change the payouts so that there isa "house percentage". That way, visitors will eventuallyrun out of money if they play long enough. This hastwo possible advantages: it will teach them the evilsof gambling, and they won't hog your KIM all day playingthis game.

37

Page 39: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 39/178

3172 BY JIM BUTTERFIELD

A teaching program which drills you on "binary andhexadecimal numbering schemes. It's kind of funjust as a speed testc

Start the program at 0200 and you'll see eight bitson the left side of the display. Some of the bitsare in the lower position, meaning 'off* or zero.Others will be in the top row, where they mean 'on

1

or logic one.

All you have to do is translate those bits into hexadecimalnotation, and enter the hex value. For example, if allbits happen to be 'on*, the number you'd enter is FF;or if all the bits were 'off, you'd enter 00.KIM rewards a correct answer with another problem.

If you're not yet at ease with the concept of bits

and how they relate to hexadecimal numbering, a fewruns of this program will help a lot.

0200 D8 START0201 A9 010203 85 ID0205 20 40 IF MAIN0208 20 6A IF0 2 0 B 0 5 1 4020D FO 50020F 85 140211 C9 150213 FO 1C

0215 A6 1C021? DO OC0219 C5 16021B DO 42021D AA021E BD E? IF0221 85 1C0223 DO 3A0225 C5 1? DIG10227 DO 360229 AA022A BD E7 IF022D 85 ID

022F DO 2E0231 A6 ID NOKEY

0233 FO 2A0235 A9 000237 85 1C0239 85 ID023B AD 04 17023E AA

023F 29 OF0241 85 17

CLDLDA #1 Set FLAG2 . .STA FLAG2 . . to new problemJSR KEYIN set directnl regJSR GETKEY get key inputCMP PREV same as last time?BEQ LIGHT yes, skipSTA PREV record new inputCMP #$15 no key?BEQ NOKEY yes, brnch

LDX FLAG1 first digit found?BNE DIG1 yes, check secondCMP SEED1 first digit match?BNE LIGHT no, ignore inputT A X .LDA TABLE, X change to segmentSTA FLAG1 ..store..BNE LIGHT .. and exitCMP SEED2 second digit match?BNE LIGHT no, ignore inputTAXLDA TABLE, X change to segmentSTA FLAG2

BNE LIGHTLDX FLAG2 problem solved?BEQ LIGHT not yet, skipLDA #0 Clear. .STA FLAG1 . . for new problem.STA FLAG2

LDA TIMER get random valueTAXAND #$OF extract last digitSTA SEED2 . .and store

38

Page 40: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 40/178

024-302440246024-8024A

024C024E02500252

025302550256

0257025A

025C025D025F0261

026402660268026A026D027002720274027602770279027B027D

8A4A 4A4A 4A85 1686 15

A2 FCA9 00

26 152A26 152AA8B9 7B 0295 1CE8DO EFA9 7F8D 41 17

AO 09A2 FAB5 IE8D 4-0 1780 42 17C6 11DO FC08 08E830 EF10 8A14 1224 22

PATT

LIGHT

SHOW

WAIT

TXALSRA LSRALSRA LSRASTA SEED1STX SEED

LDX #$FCLDA #0ROL SEEDROL AROL SEEDROL ATAYLDA TAB,YSTA FLAG1.X

Extract first digit

..and storeStore whole number

Minus 4 for windowClear Accum..then roll in....two bits...•and.•..convert....to....segments

next segment

Set directional....registers

Minus 6Window contents

TAB

l e n d

INXBNE PATTLDA #$7FSTA SADD

LDY #9LDX #$FALDA FLAG2+1.XSTA SAD

STY SBDDEC MODBNE WAITINY INYINXBMI SHOWBPL MAIN.BYTE $14,$12,$24,$22

x s s s s s t t : HEXDUMP - BITZ "»"""

0200-

0210-

0220-

3230-

0240-

0250-

0260-0270-

D814I F

2E

0F

26

7FC6

A9

C985

A6

65

15

8D1 1

0115

1C

ID

17

2A

41

D0

85

F0

D0

F0

8A

26

17FC

I E

1C

3A

2A

4A

15

A0

C8

20

A6

C5

A9

4A

2A

09C8

40

1C

17

00

4A

A3

A 2E8

IF

D0

D0

85

4A

59

FA

30

20

0C

36

1C

857E

E5EF

6A

C5

AA

85

16

02

I E10

I F

16ED

I D

86

95

8D8A

C5

D0

E7

AL

15

1C

40

14

14

42

I F

04

A2

E8

1712

F0

AA

85

17

FCD0

6C

24

50

ED

I D

AA

A9

EF

42

22

85

E7

D0

29

00

A9

17

39

Page 41: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 41/178

BLACKJACK BY JIM BUTTERFIELD

Descriptions

KIM uses a 'real* deck of cards in this game.

So when youfve seen four aces going by, you knowthat there will be no more - until the next shuffle.

BLACKJACK starts at address 0200. You'll see thecards being shuffled - the word SHUFFL appears on thedisplay - and then KIM will ask how much you want to bet.

You'll start with an initial amount of $20. Your balanceis always shown to the right of the BET? question, soon the first hand, you'll see BET? 20 on the display.

You may bet from $1 to $9, which is the house limit.The instant you hit key 1 to 9 to signal your bet,KIM will deal. Of course, you can't bet more money

than you have ... and KIM ignores freeloaders who tryto bet a zero amount.

After the deal, you'll see both your cards on the leftof the display, and one of KIM's cards on the right.(KIM's other card is a "hole" card, and you won't seeit until it's KIM's turn to play). Aces are shownas letter A, face cards and tens as letter F, andother cards as their value, two to nine. As always,Aces count value 1 or 11 and face cards count 10.

You can call for a third card by hitting the 3 button .•then the fourth card with the 4 button, and so on.If your total goes over 21 points, KIM will ungrammatically

say BUSTED, and you'll lose. If you get five cardswithout exceeding 21 points, you'll win automatically.If you don't want any more cards, hit key 0. KIM willreport your point total, and then will show and playits own hand. KIM, too, might go BUSTED or win ona five-card hand. Otherwise, the most points wins.

From time to time, KIM will advise SHUFFL when thecards start to run low.

Remember that you have a good chance to beat KIM atthis game. Keep track of the cards that have beendealt (especially aces and face cards), and you'relikely to be a winner.'

,

0200 A2 33 START0202 8A DK10203 95 00205 CA0206 10 FA0208 A2 02020A BD BB 03 INLOP

020D 95 75020F CA

LDX #51TXASTA DECK.XDEXBPL DK1LDX #2LDA INIT,XSTA PARAM.XDEX

52 cards in deckCreate deckby inserting cardsinto deckin sequence

Set up 3 locations..into..zero page

addresshi/ dpt/ amt

40

Page 42: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 42/178

0210 10 F80212 AD 0 4- 1?

0215 85 80021? D80218 A6 76

021A EO 09

021C BO 34

DEAL

use random timerto seed random chain

main loop repeats herenext-card pointerless than 9 cards?

9 or morei don't shuffl

021E AO0220 20

0223 AO0225 840227 20022A 38022B A5022D 65022F 650231 85

0233 A2

0235 B50237 950239 CA023A 10

023C 29023E C90240 BO

D8

57 03337630 03 SHLP

8182858004

8081

BPL INLOP-LDA TIMERSTA RNDOLDLDX DPTCPX #9

BCS NOSHUFshuffle deck

LDY #SHUF-$300 Set up SHUFFL msgJSR FILL put in WINDOWLDY #51 ripple 52 cardsSTY DPT set full deckJSR LIGHT illuminate displaySECLDA RND+1 GenerateADO RND+2 newADC RND+5 random

number

RMOV

F93F34E5

S T A R N DL DX #4

L DA R N D , XS T A R N D + 1 , XDEXBPL RMOVAND #$3FCMP #52BCS SHLP

move overthe randomseed numbers

0242 AA0243 B9 40 000246 480247 B5 400249 99 40 00024C 68024D 95 40024F 880250 10 05

Strip to 0-63 rangeOver 51?yes, try new number

swap each card into random slotTAXLDA DECK,Y get next card

save itget random cardinto position N

and the original cardinto the random slotnext in sequencebck for next card

PHALDA DECK,XSTA DECK,Y

PLASTA DECK.XDEYBPL SHLP

0252025402570259025C025F026102630264

026602670269026B

AO DE20 57 03

A5 7720 A6 0320 30 03C9 OABO F9AA86 79CA30 F3E4 77BO EF

; ready to accept betNOSHUF LDY #MBET-$300

JSR FILLLDA AMTJSR NUMDIS

BETIN JSR LIGHTCMP #10BCS BETINTAXSTX BET

DEXBMI BETINCPX AMT

BCS BETIN

Set up BET? msgput in WINDOW

display balance.. put in WINDOW

illuminate displaynot key 0 to 9?nope, ignore

store bet amount

026D A2 OB026F A9 000271 95 900273 CA0274 10 FB

zero bet?sufficient funds?no, refuse bet

; bet accepted - dealLDX #11 Clean WINDOW andLDA #0 card counters

CLOOP STA WINDOW,XDEXBPL CLOOP

41

Page 43: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 43/178

I0276 20 78 030279 20 8F 03027C 20 78 03027F 20 64 030282 86 7A0284 20 28 03

0287 20 30 03 TRY028A AA CA028C 30 11028E E4 960290 DO F5

here come the cardsJSR YOU one for you..

& one for me..another for you..put my second card....in the hole

wait a moment

wait for Hit or Stand

JSR MEJSR YOUJSR CARDSTX HOLEJSR WLITE

deal completeJSR LIGHTTAX DEXBMI HOLDGPX UGNTBNE TRY

0292 20 78 030295 C9 220297 BO 400299 EO 05029B FO 53029D DO E8

029F A5 9502A1 4802A2 A2 0002A4 20 OF 0302A7 A2 0402A9 A9 0002AB 95 9002AD CA02AE 10 FB

02BO 68

02B1 85 9502B3 A6 7A02B5 20 6D 0302B8 20 92 03

Hit - deal another card

key input?zero for Stand?N for card #n?nope, ignore key

JSR YOUCMP #$22BCS UBUSTCPX #5BEQ U WINBNE TRY

deal it22 or over?yup, you bust5 cards?yup, you winnope, keep going

; Stand - show player's totalHOLD LDA WINDOW+5 save KIM card

PHA on stackLDX #0 flag player ..JSR SHTOT .. for total displayLDX #4LDA #0

HLOOP STA WINDOW,X clean windowDEXBPL HLOOP

\ restore display card and hole cardPLA display card

STA WINDOW+5 back to display

02BB02BE02CO02C202C402C602C8

02CA

02CC02CE

02DO02D202D4

02D7

20 28 03 PLAY

A5 9AC9 22BO 2965 9BA6 91DO 18

LDX HOLEJSR CRECJSR MEX

KIM plays hereJSR WLITELDA MTOTCMP #$22BCS IBUSTADC MACELDX WINDOW+1

BNE IWIN

C9 22 CMP #$22

90 02 BCC POVA5 9A LDA MTOTC9 17 POV CMP #$17BO 2C BCS HOLD220 8F 03 JSR MEDO E2 BNE PLAY

; KIM wins hereJSR WLITEJSR BUSTJSR WLITE

02D9 20 28 03 UBUST

02DC 20 55 0302DF 20 28 03

get hole cardrebuildplay and display

pause to show cardspoint total..22 or over?yup, KIM bust

add 10 for aces?five cards?yes, KIM wins

22+ including aces?

nope, count ace highyup, ace low17 or over?yes, stand.,no, hit..

unconditional Branch

show player's hand.,make BUST message....and show it

42

Page 44: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 44/178

02E2 A5 7702E4 P8 3802E6 E5 7902E8 85 7702EA 4- C 17

IWIN

JLINK02 XLINK

LDA AMTSED SECSBC BETSTA AMTJMP DEAL

decrease balance

..by amount of betstore new balancenext play

02ED02FO02F302F502F7

02F902FB02FD02FE

2020

A5F8

65AO9098DO

5528

7718799901

E8

0303

IBUSTUWINADD

JSRJSRLDASEDADCLDYBCCTYABNE

BUSTWLITEAMTCLCBET#$99NOFLO

JLINK

0300 A2 030302 20 OF0305 A5 9A

0307 C5 970309 FO DF030B BO D5030D 90 E4

Player wins here

make BUST message..display pauseincrease balance

by amount of bet$99 maximum..have we passed it?yes, restore $99unconditional branch

KIM stands - compare pointsHOLD2

03LDX #3JSR SHOTOTLDA MTOT

CMP UTOTBEQ XLINKBCS IWINBCC ADD

flag KIM..

.. for total displayKIM's total.,

vs. Player's total.,same, no score;KIM higher, wins;KIM lower, loses.

030F B50311 F80313 750315 C90317 BO0319 95031B D8031C B5031E 4- 8031F AO0321 200324- 680325 20

0328 AO032A 20032D 88032E DO

0330 84

0332 AO033 A20336 A90338 8D033B B5

033D 8D0340 8C

0343 E6

9718982202

97

97

E2

57 03

A6 03

8030 03

FA

7F

13057F4-1 17904o 1742 177B

; subroutines start here; SHTOT shows point totals per X registerSHTOT LDA UTOT.X player's or KIM's total

SED CLCADC UACE,X try adding Ace points

exceeds 21 total?yes, skipno, make permanent

CMP #$22BCS SHOVERSTA UTOT,X

SHOVER CLDLDA UTOT,XPHA

get revised totalsave it

LDY #TOT-$300 set up TOT- msgJSR FILL put in WINDOWPLA recall totalJSR NUMDIS insert in window

display pause, approx 1 secondtiming constantilluminate screen

countdown

WLITE LDY #$80WDO JSR LIGHT

DEYBNE WDO

; illuminate displayLIGHT STY YSAV

LDY # 13

save register

6 digits to show

DIGIT

WAIT

LDX #(

LDASTA PADD set directional regLDA WINDOW,XSTA SAD character segmentsSTY SBD character IDINC PAUSE

43

Page 45: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 45/178

0345 DO P C0347 88 8803*1-9 C A034A 10 EF034C 20 40 IF034F 20 6A IF0352 A4 ?F

0354 60

0355 AO E60357 84 74

0359 AO 05035B B l 74035D 99 90 000360 880361 10 F80363 60

0364 A6 76

0366 C6 760368 B5 40036A 4A 4A036C AA036D 18036E DO 010370 380371 BD BE 030374 BC CB 030377 60

0378 20 64 03037B E6 96

037D A6 96037F 94 8F0381 AO 100383 90 020385 84 980387 18 F80389 65 97038B 85 97038D D8038E 60

038F 20 64 030392 C6 990394 A6 990396 94 960398 AO 10039A 90 020390 84 9B039E 18 F803AO 65 9A03A2 85 9A03A4 D803A5 60

switch Dir Regtest keyboardrestore Y value

BNE WAIT wait loopDEY DEYDEXBPL DIGITJSR KEYINJSR GETKEYLDY YSAVRTS

; fill WINDOW with BUST or other messageBUST LDY #$BST-$300FILL STY POINTR

LDY #5 six digits to moveFILLIT LDA (POINTR),Y load a digit

STA WINDOW,Y put in windowDEYBPL FILLITRTS

; dealCARD

a card, calc value & segments

CREC

LDX DPT

DEC DPTLDA DECK,XLSRA LSRATAXCLCBNE NOTACESECLDA VALUE,X

LDY SEGS.X

Pointer in deck

Move pointerGet the cardDrop the suit0 to 12 in Xno-ace flagbranch if not aceace flagvalue from tablesegments from table

; cardYOU

RTSto player, including display & countJSR CARD deal cardINC UCNT card count

LDX UCNT use as display pointerSTY WINDOW-1,X put card in Wndw

YOVER

ten count for acesno ace?ace, set 10 flag

add points to....point total

; cardME

MEX

LDY #$10BCC YOVERSTY UACECLC SED

ADC UTOTSTA UTOTCLD

RTS

to KIM, including display & countsJSR CARD deal cardDEC MCNT inverted countLDX MCNT use as (r) display pontrSTY WINDOW+6.X into window

MOVER

LDY #$10BCC MOVERSTY MACECLC SED

ADC MTOTSTA MTOTCLDRTS

ten count for acesno ace?ace, set 10 flag

add points to.... point total

44

Page 46: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 46/178

03A6 480 3 A ? 4A 4A0 3 A 9 4A 4A0 3 A B A 803AC B 9 E?03AF 85 9403B1 6803B2 29 OF

' A803B5 B 9 E 703B8 85 9503BA 60

03BB 03 000 3 CB F 7 D B03D8 ED F603E2 F 8 D C

; transfer number in A to displayNUMDIS PHA save number

ISRA LSRA extract left digitLSRA LSRATAY

IF LDA TABLE,Y convert to segmentsSTA WINDOW+4PLA restore digitAND #$OF extract right digitTAY

IF LDA TABLE,Y convert to segmentsSTA WINDOW+5RTS

; tables in hex format20 01 02 03 04 05 06 0? 08 09 10 10 10 10O F E6 ED FD 8? FF EF Fl Fl Fl Fl

BE Fl Fl B8 FC F9 F8 D3F 8 C O F C B E E D 8? F 9 D E

"""-""HEX DUMP - BLACKJACK """""

0 2 0 002100 2 2 00230

02400 2 5 00 2 6 00 2 7 00280

0 2 9 0

02AO02BO02CO02DO

0 2 E O

0 2 F O0300

0310032003300340

0350

0360

03700380

039003AO03BO03CO03DO03EO

A 2 33 8A10 F8 AD2 0 57 03

85 85 80B O E5 AA10 D5 AOO A BO F9

00 9 5 9 064 03 86D O F5 20

9 5 4 8 A 268 85 95C9 22 BOC9 17 BO2 8 0 3 A 52 0 28 03A 2 03 2097 F8 18

E2 2 0 5784 7 F A O8C 42 176A IF A 488 10 F8

38 BD BE8F A O 1 064 03 C665 9A 8594 68 29

03 04 05FD 87 FFF8 D3 F8

95 40

04 17AO 33A2 04

B9 40DE 20AA 86

CA 10

7A 2078 03

00 20A6 7A

29 652C 20

77 F8

A5 77OF 03

75 98

03 6813 A2E6 7B

7F 60

60 A6

03 BC90 02

99 A69A D8OF A8

06 07EF FlDC F8

CA 10

85 8084 76

B5 8000 4857 0379 CA

FB 2028 03C9 22

OF 0320 6D9B A68F 03

38 E5

F8 18A5 9A

C9 2220 A605 A9DO FC

AO E6

76 C6

CB 0384 9899 9460 48B9 E708 09Fl Fl

CO FC

FA A2

D8 A620 30

95 81

B5 40A5 7730 F3

78 0320 30BO 40

A2 0403 2091 DODO E2

79 85

65 79C5 97BO 02

03 AO7F 8D

88 8884 7476 B5

60 2018 F8

96 AO4A 4AIF 85

10 10Fl EDBE ED

02 BD BB

76 EO 09

03 38 A5CA 10 F9

99 40 0020 A6 03E4 77 BO

20 8F 0303 AA CA

EO 05 FO

A9 00 9592 03 2018 C9 2220 28 0377 4C 17

AO 99 90FO DF BO

95 97 D880 20 3041 17 B5CA 10 EF

AO 05 Bl

40 4A 4A

64 03 E665 97 8510 90 024A 4A A895 60 0310 10 F7F6 BE Fl87 F9 DE

03 95BO 34

81 65

29 3F

68 9520 30EF A2

20 78

30 11

53 DO

90 CA28 0390 0220 5502 20

01 98D5 90B5 9703 8890 8D20 40

74 99AA 18

96 A69 7 D 884 9BB 9 E700 20DB CF

Fl B8

75 CAA O D8

82 65C9 3440 8803 C9O B A 9

0 3 2 0E4 9 6E 8 A 5

10 FBA 5 9AA 5 9A03 2055 03D O E8E4 B548 AOD O F A

40 17IF 20

9 0 00D O 01

96 9460 2018 F8

I F 8501 02E6 EDFC F 9

Page 47: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 47/178

SLACK MATCHby Ron Kushnier(modified bythe editors)

Description -There are 21 matches. Each player must take 1,2, or

3 matches per turn. The player who winds up with the lastmatch loses. The player plays against the computer and goes

first. Starting address - 0200, press "GO". Player entersa number on the keyboard; the left two digits display theplayers number. The centre digits display the computer'schoice after some "think time". The rightmost digits displaya running total of matches left. The computer has an I.Q.and will become dumber if you lose, smarter if you win.

0200 A90202 850204 A90206 85

0208 A9020A 85

020C 20020F 20

0212 C90214 10

0216 C9

0218 FO021A 85021C A9

021E 850220 F80221 380222 A5

0224 E5

0226 300228 85022A A9022C 85022E A9

0230 8D0233 200236 2C

0239 10023B C6023D DO023F 18

0240 A50242 FO0244 690246 E90248 FO024A C9024C BO024E AE0251 E40253 BO0255 A9

21ED21F900FB

IF IF6A IF04F200

EEFB00FA

F9FB

EOF908EEFF0? 17IF IF

07 17F8EEEF

F9260404OB04F846 17ED0201

START

NEW

PLAY

TIME

DISP

SUB

DUMP

LDA #$21STA IQLDA #$21STA INKLDA #0STA POINTH

JSR SCANDSJSR GETKEYCMP #4BPL PLAYCMP #0

BPL PLAYSTA POINTHLDA #0STA POINTLSEDSECLDA INH

SBC POINTH

BMI PLAYSTA INHLDA #8STA SLOW

LDA #$FFSTA CLOCKJSR SCANDSBIT CLOCKBPL DISP

DEC SLOWBNE TIMECLC

LDA INHBEQ DEADADC #4SBC #4BEQ DUMPCMP #4BCS SUBLDX 1746CPX IQBCS COMPLDA #1

46

initial IQ

21 matchesto start game

clear player's move

light displayand test keys

key 4 or over?go back

key 0? go " b a c k

record movewipe last KIM move

decimal mode

get total matches

subtract movenot enough matches?OK, new total

set slow counterslowest count into....slowest KIM timer

get totalplayer loses?divide m-1 by 4

keep dividingrandom, timer#2KIM smart enough?YesNo

Page 48: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 48/178

0257 85 FA0259 38025A A5 F9

025C E5 FA025E 85 F9

0260 DO A60262 A2 5A0264 AO FE

0266 46 ED0268 10 0?026A A2 DE026C AO AD026E 38026F 26 ED

0271 86 FB0273 84 FA0275 20 IF IF0278 DO 8A

027A FO F9027C

COMP

DEAD

SHOW

LOK

end

STA POINTL

SECLDA INH

SBC POINTLSTA INH

BNE PLAYLDA #$5ALDY #$FELSR IQBPL SHOWLDX #$DELDY #$ADSEC

ROL IQSTX POINTHSTY POINTLJSR SCANDS

BNE NEW

BEQ LOK

Record the move

Subtract KIM movefrom total

Player wins:SAFE

get smart

K IM wins:DEAD

get dumb

new game if key

xxxxx HE X MATCH """""

0200-

0210-

0220-

0230-

0240-

0250-

2260-

0270-

A9

6A

F8

8D

17

D0

ED

21

I F

38

07

F9

£4

A6

86

85

C9

A

17

F0

ED

A 2FB

ED

04

F9

20

26

50

5A

84

A9

10

E5

IF

69

02

A0

FA

21F2

FE

IF

04

A9

FE

20

85C9

30

2C

E9

01

46

IF

F9

00

E0

07

04

85

ED

IF

A9

F0

85

17

F0

FA

10

D0

00

EE

F9

10

0B

38

07

8A

85

85

A9

F8

C9

A 5A2

F0

FB

Ft

08

C6

04

F9

DE

F9

20

A9

85

EE

B0

E5

A0

IF

00

EE

D0

F8

FAAD

IF

85

A9

EF

AE

85

38

20

FAFF

18

46

F9

26

47

Page 49: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 49/178

CARD DEALS ft BY DM LEWART

DESCRIPTION -

THIS PROGRAM WI LL DEAL A FULL DECK OF 52 CARDS.

THE VALUE AND SUIT OF THE CARDS APPEARS IN THE RI GHT

TWO DIGITS OF THE DISPLAY. PRESS ANY KEY TO GETANOTHER CARD. EACH WILL APPEAR ONLY ONCE. WHEN ALL

CARDS HAVE BEEN DEALT, THE PROGRAM MUST BE RESTARTED

AT 0000.

00000002

00040006

00070009OOOA

OOOC

OOOE

O O O F

0011

0012

00140016

0018

00 I B

00 IE

00200023002500270028

0029002B002D002F

003100330036

0038003900 3B

003D00 3E

004000420044004500460047

A2 06 INIT

AO 00

94 8B INIT 1

CA

DO FBD8

A2 3486 92C8

94 92 INIT 2CA

DO FB

A5 92 NEWCRD

DO 034C 4F 1C

AD 04 17 RANDOM

DO OB

AD 44 17DO 06

A5 924A18

69 01

C5 92 FASTER90 07

F O 05

E5 924C 2B 00

A2 33 FIND

38 FIND 1F5 93FO 03

CA

10 F8

95 93 UPDATE

C6 928A

4A4A

A8

LDX #$06LDY #$00STY 008B,XDEX

BNE INIT 1CLD

LDX #$34STX 0092I Y

STY 0092,XDEX

BNE INIT 2

LDA 0092BNE RANDOM

JMP START

LDA 1704

BNE FASTER

LDA 1744BNE FASTER

LDA 0092

LSR

CLC

ADC #$01CMP 0092

BCC FIND

BEQ FIND

SBC 0092JMP FASTER

LDX -$33

SECSBC 0093,X

BEQ UPDATE

DEX

BPL FIND 1STA 0093,X

DEC 0092

TXALSR

LSR

TAY

CLEAR DISPLAY

C8C-91)=0

FILL DECK

STORE CARDS LEFT (52)

C 9 3 - C 6 ) = 1

DECK FINISHED?

YES, STOPGET RANDOM # (1-FF)

BOTH CLOCKS OUT OF RANGE

# APPROX. MIDDECK

GET NUMBER 1-34

FIND THE CARD

KEEP SUBTRACTING CARDCARD^O MEANS PI CKEDCARD=1 MEANS IN DECK

X=CARD POSITION

CARD=0

1 LESS CARD LEFT

GET FIRST 6 BITS OF XY=(0-C)

48

Page 50: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 50/178

004800 4B004D00 4E

0050

005100540056

0059005B005E

006000620064

0067

0069006B006E

00700073007400760078

00 7B00 7C00 7D

00 7E007F

0080

0081008200830084

0085008600870088008900 8A

00 8B

B9

858A

29A8

B98520

DO20DO

FO

A98D

AOA2

B984

20C8CO

904C

775B4F

666D7D

077F6F

78

IE

67706D765E

39

0000001000200030

0040

0050006000700080

7B

90

03

889162FB

62B4

F97F41

00088C

FC

4E

06

F33D

****

A2

92AD

05

95A8F O

207D

00

00

00

00

17

00

IF

IF

************

06CA

44E5

93B9F94E07

LDA

STATXA

ANDTAY

007B,Y0090

#$03

LDA 0088,Y

K DOWN

K UP

DISP

DISP 1

****************************

VALTBL

SUITBL

HEX DUMP

AO 00 94DO FB A5

17 DO 00

92 4C 2B

C6 92 8A88 00 85A9 7F 8D

IF C8 CO7F 6F 78

STAJSR

BNEJSR

BNE

BEQLDASTA

LDY

LDX

LDA

STY

JSRI Y

CPY

BCC

JMP

TABLES"A"1 1 2 "

llTll

Hij.ll

l i c i t

II6II

tl^ll

llgll

t t g l l

l l j i l

l l j l l

MQII

"K"

lien

"H""D"

"C"

0091DISP

K DOWNDISPNEWCRD

K UP#$7F1741

#$00#$08008C,YOOFC

1F4E

#$06DISP 1

1F3D

XXJCC9CCX

GET VALUE FROM VALTBL

STORE AS 5TH DISPLAY DIG

GET LAST 2 BITS OF

Y=CO-3)

X

GET SUIT FROM SUITBLSTORE AS 6TH DISP.DISPLAY C8C-91)UNTIL KEY UP

DISPLAY C8C-91)UNTIL KEY DOWN

SEGMENTS TO OUTPUT

INITIALIZE

GET CHARACTER

DISPLAY CHARACTERNEXT CHARACTER

DONE, KEY DOWN?

DIGIT

- CARD DEALER "5««

{-

8B CA

92 DOA5 9200 A2

4A 4A91 2041 17

06 90IE 67

DO FB D8

03 4C 4F4A 18 69

33 38 F5

A8 B9 7B62 00 DOAO 00 A2

F3 4C 3D70 6D 76

A2 34 86 92 C8 941C AD 04 17 DO OB

01 C5 92 90 07 FO

93 FO 03 CA 10 F8

00 85 90 8A 29 03FB 20 62 00 DO B4

08 B9 8C 00 84 FCIF 77 5B 4F 66 6D

5E 39

49

Page 51: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 51/178

CHESS CLOCK BY CASS LEWART

DESCRIPTION -

THE PROGRAM STARTS AT LOCATION 0200. TWO INDEPENDENT

CLOCKS ARE OPERATED BY THE TWO PLAYERS BY DEPRESSING KEYS

1 OR 2 RESPECTIVELY. THE RIGHT TWO DIGITS SHOW THE MOVE

NUMBER, THE LEFT FOUR DIGITS SHOW MINUTES AND SECONDS.MAXIMUM TIME IS 99 MINUTES 59 SEC. THE CLOCK PROGRAM CAN

BE FINELY TUNED BY CHANGING THE VALUE OF WORD 027F, INCREASE

BY 1 SLOWS THE CLOCK BY APPROXIMATELY 6 SEC/24 HOURS ANDVICE VERSA.

ZERO ALL OF PAGE ZERO200

0202

020302060207

0209020C020F0211

02130215

0217021A021D

021F

02210224

022502270229022B022E

0231

0233023502370239023B023D023F0241

0243

0245

02470248024A024C

024E02500252025402560258

A9 00AA9D 00 00 ZEROE8DO FA

20 IF IF DISP20 6A IF

C9 02DO F6

A9 01 LOOP85 D420 60 02

20 31 02A9 02

85 D420 60 0218

A5 F969 0185 F920 31 024C 13 02

xx ee SAVE TIME

A9 02 SAVEC5 D4DO 11

A5 FB85 D2A5 FA85 D3A5 DO85 FBA5 Dl

85 FA

60A5 FB CLK1

85 DOA5 FA85 Dl

A5 D285 FB

A5 D385 FA60

LDA #$00TAXSTA 0000, XINX

BNE ZEROJSR SCANDSJSR GETKEYCMP #$02

BNE DISPLDA #$01

STA OOD4

JSR TIMEJSR SAVELDA #$02STA OOD4JSR TIMECLC

LDA OOF9

ADC #$01STA OOF9JSR SAVEJMP LOOPINDICATED SI

LDA #$02

CMP OOD4BNE CLK1LDA 00 FB

STA OOD2

LDA OOFA

STA OOD3LDA 00 DO

STA OOFB

LDA OOD1STA OOFA

RTSLDA OOFB

STA OODO

LDA OOFA

STA OOD1

LDA OOD2

STA OOFB

LDA OOD3STA OOFA

RTS

50

DISPLAY ZEROSKEY PRESSED?KEY # 2?

NO, WAIT TILL 2 DOWN

FLAG TO 1C C L O C K # 1 T O RUN)G E T C L O C K R U N N I N GS A V E T I M E O N D I S P L A YFLAG TO 2CCLOCK #2 TO RUN)

GET OTHER CLOCK RUNNING...INCREMENT MOVE

NUMBER...

SAVE CLOCK 2 TIME

BACK TO CLOCK # 1

JTINE »>s:x

CLOCK # 2 ?

NO, STORE FOR CLOCK # 1

...STORE VALUES FOR

CLOCK # 2 IN OOD2

AND OOD3 ...

...LOAD DISPLAY WITH

VALUES FORCLOCK # 1 ...

...STORE VALUES FOR

CLOCK # 1 IN OODO

AND OOD1...

...LOAD DISPLAY WITH

VALUES FORCLOCK # 2 .

Page 52: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 52/178

:s«::: CLOCK ADVANCE SUBROUTINE :c""!

02600261

0 2 6 302650 267026A026D

0270

0 2 7 20274

02750278

027A

027C

027E

0 2 8 0

0 2 8 3

02860288

0289

02 88

028D

028F

0291

0 2 9 30294

0296

0298029A029C

029E

F8

A9

85

A98D

2020

C 5

D O

6 02C

10

C6

D O

A98D

2C

1018

A569

85C9D O

38A9

85

A5

6 9854C

04

D5

FO

07

IF

6 A

D4

01

07

FO

D5

E7BF

06

07

FB

FA

01

FA

6005

00FA

FB

00

FB

17

IF

IF

17

17

17

TIME

LOAD

LITE

WAIT

TINY

NOMN

60 02

SED

LDA #$04

ST A OOD5

LD A # $ F O

ST A 1707JSR SCANDS

JS R GETKEY

CMP OOD4

BNE WAI T

RTS

BIT 1707

BPL LITE

DEC OOD5

BNE LOAD

LDA #$BF

STA 1706

BIT 1707

BPL TINYCLC

LD A 00FA

AD C #$01

ST A OOFA

CMP # $ 6 0

BNE NOMN

SEC

LDA # $ 0 0ST A OOFA

LD A OOFB

AD C #$00

ST A OOFB

JMP TIME

SET DECIMAL MODE

TIME MULTIPLIER TO

SE T TIMER

DISPLAY CLOCKGET KEYBOARD ENTRY

EQUAL TO FLAG?

4

NO,TIME OUT THEN UPDATE

YES, RETURN FROM SUBR.

TIME DONE?

NOT YETDECREMENT TIME MULT•

NO T ZERO, RESET TIMER

LAST LITTLE BIT OF

INTO TIMER

DONE?

NO..ONE SECOND ADDED

TO CLOCK..

(CENTER TWO DIGITS)

A MINUTE UP?

NOT YET

YES, SEC. TO ZERO

TIME

... MINUTES INCREMENTED

IF CARRY SET...

LOOP

xxxxx HEX DUMP - CHESS CLOCK ""»"-

0200-

0210-

0220-

0230-

0240-

0250-

0260-

0270-

0280-0290-

02A0-

A9

02

D4

02

D0

A5

F8

C5

8D60

02

00

D0

20

A9

85

D2

A9

DA

AA

F6

60

02

FB

85

04

D0

06 17D0 05

9D 00

A9 01

02 18

C 5 DA

A5 Dl

FB A5

85 D5

01 60

2C 0738 A9

00 E8 D0 FA

85 D4 20 60

A5 F9 69 01

D0 11 A5 FB

85 FA 60 A5

D3 85 FA 60

A9 F0 8D 07

2C 07 17 10

17 10 FB 1800 85 FA A5

20 IF IF 20 6A IF

02 20 31 02 A9 02

85 F9 20 31 02 A C

85 D2 A5 FA 85 D3

FE 85 D0 A5 FA 85

17 20 IF IF 20 6A

F0 C6 D5 D0 E7 A9

A5 FA 69 01 85 FAFE 69 00 85 FB A C

C9

85

13

A5

Dl

IF

BF

C960

51

Page 53: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 53/178

CLOCK - Charles Parsons

This clock routine uses KIM's built in interval timer with theinterrupt option. It works by loading $F^f into the timer (/1024) eachtime the Non-Maskable Interrupt (NMI) occurs. This theoretically pro-duce a time of 2^9»856 microseconds or just under %second. The adjust-

ment to % second is done with the timer (/I) in the interrupt routine.A fine adjustment of the clock can be made by modifying the value inlocation $0366. Only two subroutines will be documented here (ESCAPETO KI M & HOUR CHIME) but many more can be added by simply replacingthe NOP codes starting at $03DE with jumps to your own subroutines.

For instance, a home control system could be set up using th e clock

program.

The escape to KIM allows KIM to run without stopping the clock.This means that you can run other programs simultaneously with the

clock program unless your program also needs to use the NMI (such assingle step operation) or if there could be a timing problem (such aswith the audio tape operation). Pressing the KIM GO button will get

you out of the KIM loop.

To start the clock:

1. Connect PB? U-15) to NMI (E-6).2. Initialize NMI pointer (17FA, 1?FB) with 60 and 03.3. Set up the time and AM-PM counter locations in page

zero.k. Go to address S03CO and press GO.

To get back into the clock display mode if the clock is run-ning - start at location $039•

NOTE; These routines are not listed in any particular order

so be watchful of the addresses when you load them.

PAGE ZERO LOCATIONS

0070 NOTE . Sets frequency of note

0080 QSEC % second counter0081 SEC second counter0082 MIN minute counter0083 HR hour counter0084 DAY day counter for AM-PM

52

Page 54: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 54/178

INTERRUPT EOUTINE

This routine uses the NMI to update a clock in zero pagelocations. Since the crystal may be slightly off one MHz a

fine adjustment is located at 0366. NMI pointers must be setto the start of this program.

save A

save X

save Y

fine adjust timing

test timer

loop until time out

count H secondsdo four times before

updating seconds

reset K second counter

advance clock in decimal

advance seconds

until 60 seconds

then start again

and advance minutes

until 60 minutes

then start again

and advance hours

until 12 hours

advance % dayif 13 hoursstart again with one

go back to hex modestart timer with interruptin 249,856 microseconds

0360036103620363036403650367036A036D036F0371

0373037503770379037B

037C037D037F03810383038503870389

038B038D038E03900392

039403960398039A039C039D039F03A1

03A303A503A703A903AB03AD03AF03BO03B2

48

8A

489848A9838D04172C0717 TM10FB

E680A904

C580D038A900

8580

18F8A58169018581C960D028

A900

8581

A5821869018582C960D019

A900

8582

A5831869018583C912

D002E684

C913 THD004

A901

8583D8 RTNA9F48DOF17

PHA

TXAPHA

TYA

PHA

LDA #$83

STA TIME4

BIT TIME?

BPL TM

INC QSEC

LDA #$04

CMP QSECBNE RTNLDA #$00

STA QSEC

CLC

SED

LDA SEC

ADC #$01STA SECCMP #$60

BNE RTN

LDA #$00

STA SEC

LDA MINCLCADC #$01STA MIN

CMP #360

BNE RTN

LDA #$00STA MIN

LDA HRCLC

ADC #$01

STA HR

CMP #$12

BNE THINC DAY

CMP #313BNE RTN

LDA #301STA HRCLD

LDA #3F4

STA TIMEF

Page 55: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 55/178

03B5 6803B6 A803B7 6803B8 AA03B9 6803BA 40

PLA

TAY

PLA

TAX

PLA

RTI

restore Y

restore Xrestore A

return from interrupt

ESCAPE TO KIM IF 1 ON KIM IS PRESSED

This is a subroutine which will return to the KIM monitor routinewithout stopping the real time clock. It is done by pressing 1 on theKIM keyboard.

0300 206A1F KIM

0303 G9010305 DOOD

0307 201F1F

030A 206A1F

030D C901

030F D003

0311 4co5ic0314 60

JSR GETKEYCMP #»01

BNE ENDR

JSR SGANDS

JSR GETKEYCMP #301

BNE ENDR

JMP SAVE1

go back to KIM ifKIM keyboard is one

delay to make sure

ENDR RTS

TWO TONE SOUND TO INDICATE HOURS

This is a subroutine which when added to the clock displayroutine will use the real time clock data to produce one sound

per hour on the hour. The output is a speaker circuit as shownon Pg. 57 of the KIM-1 Manual. It is hooked to PBO rather thanPAO. The specific notes can be changed by altering 0330 and 033C«

0320

03220324

0326

0327

0329032B

032D

032F

03310333

0335

03370339

033B033D033F03410344

03470349034A034B034D034F

A582D029

A 5 8 138E5831024

A58oD006A91E

8570DOOA

A901

C580

D014

A9288570

A9018D0317EE0217

A570

AA

CA

10FD

30DC

60

BEEP

AGAIN

ONE

DEC

END

LDA MIN

BNE SND

LDA SEC

SECSBC HR

BPL END

LDA SEC

BNE ONE

LDA #S1E

STA NOTEBNE GO

LDA #301

CMP QSEC

BNE END

LDA #$28STA NOTELDA #$01

STA PBDD

INC PBD

LDA NOTETAX

DEXBPL DEC

BMI AGAIN

RTS

on the hour?if not returnexecute until SEC = HR

first #second?

set high note

sound note for % secondsecond % second?

set low note

set I/O ports

toggle speaker

set delay

keep sounding

54

Page 56: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 56/178

DISPLAY CLOCK ON KIM-1 READOUT

I

*

03CO

03C2Q J C k

03C603C903CB03CD03CF03D103D303D503D803DB

03DE

03E103E4

03E?03EA03ED

03FO

03F303F603F903FC

A900

8580A9F*f

8DOF1?A581 DSP

85F9A58285FAA58385FB

201F1F

200003202003EAEAEA

EAEAEA

EAEAEA

EAEAEAEAEAEA

EAEAEAEAEAEA

EAEAEA

EAEAEA

EAEAEA4CC903

LDA #$00 reset % s<STA QSECLDA #$FV start t i m i

STA TIMEFLDA SEC start her.

STA INH display c.

LDA MIN

STA POINTLLDA HRSTA POINTHJSR SCANDSJSR KIM escape toJSR BEEP sound on

JMP DSP

***** Hex D u m p - Clock *****

0300- 20 6A I F C9 01 D0 0D 20 IF IF 20 6A IF C9 01 D0

0310- 03 4C 05 1C 60

0320- AS 82 D0 29 A5 81 38 E5 83 10 24 A5 80 D0 06 A9

0330- I E 85 70 D0 0A A9 01 C5 80 D0 14 A9 28 85 70 A9

0340- 01 8D 03 17 EE 02 17 A5 70 AA CA 10 FD 30 DC 60

0360- 48 8A 48 98 48 A9 83 8D 04 17 20 C0 17 10 FB E6

0370- 80 A9 04 C5 80 D0 38 A9 00 85 80 18 F8 A5 81 69

0380- 01 85 81 C9 2 D0 28 A9 00 85 81 A5 82 18 69 01

0390- 85 82 C9 60 V&' 19 A9 00 85 82 A5 83 18 69 01 8503A0- 83 C9 12 D0 02 E6 84 C9 13 B0 04 A9 01 85 83 D8

03B0- A9 F4 8D 0F 17 68 A8 68 AA 68 40

03C0- A9 00 85 80 A9 F4 8D 0F 17 A5 81 85 F9 A5 82 85

03D0- FA A5 83 85 FB 20 IF IF 20 00 03 20 20 03 EA EA

03E0- EA EA EA EA EA EA EA EA EA EA EA EA EA EA EA EA

03F0- EA EA EA EA EA EA EA EA EA EA EA EA 4C C9 03

55

Page 57: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 57/178

CODE TfST BY STAN OCKERS

DESCRIPTION -THIS PROGRAM REQUIRES THAT A SPEAKER BE HOOKED

TO PAO AS IN FIGURE 5.1 OF THE KIM MANUAL. WHEN STARTED

AT 0200, THE PROGRAM WILL SEND 5 LETTER CODE GROUPS,(INTERNATIONAL MORSE), OVER THE SPEAKER. THE CODE GROUPSWILL CONSIST OF RANDOM CHARACTERS INCLUDING A-Z, 0-9, A

PERIOD, COMMA, QUESTION MARK AND EQUAL SIGN. AFTER THIS

TRANSMISSION, YOUR RECEPTION CAN BE CHECKED BECAUSE THEGROUPS SENT WILL BE SHOWN ON THE DISPLAY. PRESSING ANY

KEY WILL CAUSE THE NEXT GROUP TO BE DISPLAYED. LIMITATIONS

IMPOSED BY THE 7 SEGMENT DISPLAYS MAKE SOME CHARACTERSPRETTY STRANGE AND THERE IS SOME REDUNDANCY; BUT BY SLOWING

THE TRANSMISSION YOU SHOULD BE ABLE TO FIGURE OUT WHAT

EACH CHARACTER IS.

02000202

0205

02070208020A

020C020F0 2 1 1

0 2 1 3

0 2 1 5

0 2 1 7

0 2 1 9

0 2 1 C

0 2 1 F

0 2 2 1

0223

022502260229022B022E

0230

0232

02340236

023902 3B023D023F0241

02430246

A2 OC

BD DF 02 INIT

95 E2

CA

10J~ 8

A 2 b f GRUP20 AO 02

A9 06

85 EOC6 EO CHAR

FO F3

A2 03

20 AO 0220 CB 02 NUMB

29 3FC9 28

10 F7AA

BD 13 03A4 E2

99 3B 03E6 E2

A5 E2

C9 1A

FO 20BD EB 02

85 DF

06 DF BITS

FO D4BO OD

A2 0120 82 02

A2 01 SPAC

LDX #$OCLDA 02DF,XSTA OOE2,X

DEX

BPL INIT

LDX #$04JSR SPACE

LDA #$06STA OOEO

DEC OOEO

BEQ GRUP

LDX #$03

JSR SPACEJSR RANDAND #$3F

CMP #$28

BPL NUMB

TAX

LDA 0313,XLDY OOE2

STA 033B,Y

INC OOE2

LDA OOE2

CMP #$1A

BEQ DEBOLDA 02EB,XSTA OODF

ASL OODF

BEQ CHARBCS DASH

LDX #$01JSR MARK

LDX #$01

... INITIALIZATION ...

.. 12 VALUES ARE LOADEDFROM OOE2 ON UP ..

(SPACE LENGTH)SPACE FOR ANOTHER GROUPGROUP SIZE, 5 CHAR.

NEXT CHAR. IN GROUP

FINISHED, GET NEW GROUP

(SPACE LENGTH)

SPACE BETWEEN CHAR.GET A RANDOM f t

MAKE SURE POSITIVELESS THAN 41 (DECIMAL)?NO, GET ANOTHER

USE AS INDEX

GET DISPLAY CONVERSIONCHAR. INDEX IN Y

STORE CONVERSION

INDEX UP ONE

LAST CHARACTER?

Y E S ,GO READOUTGET CODE CHARACTER

TEMPORARY STORE

SHIFTEMPTY, GET NEXT CHAR.IF CARRY SET, SEND DASH

..ELSE SEND DOT

THEN SPACE

56

Page 58: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 58/178

024802 4B

024C

024E

02500253

02540256

0259025C

025E0 2 6 1

0263026402660268026A026C

026E0 2 7 1

0272

02740276027802 7A

02JC0*.,£

0280

02820284

0286028902 8B

02 8E0 2 9 1

029302940296

0299029B029D029F

02AO02A202A4

02A702M02AC

02AE02BO

20 AO18

90 ED

A2 0320 8218

90 FO20 8E

20 Bl

DO F8

20 Bl

F O FB

18

A5 E469 0585 E4AO 04Bl E4

99 E88810 F8

C6 E3

DO DE

A9 3685 E4

A9 0585 E3DO D4

«*«**>**w***

86 DD

A5 E6

8D 07A9 018D 01EE 00

A6 E7CA

DO FD

2C 07

10 F3

C6 DD

DO E5

60

86 DD

A5 E68D 072C 0710 FB

C6 DDDO F260

02 JSR SPACECLC

BCC BITS

DASH LDX #$03

02 JSR MARK

CLC

BCC SPACIE DEBO JSR INIT1

02 JSR DISP

BNE DEBO

02 WAIT JSR DISP

BEQ WAI T

CLC

LDA OOE4

ADC #$05STA OOE4

LDY #$04

WIND LDA (OOE4),Y

00 STA OOE8,YDEY

BPL WIND

DEC OOE3

BNE DEBO

LDA #$36STA OOE4

LDA #$05STA OOE3

BNE DEBO

"MARK SUBROUTINE::":::c

STX OODD

TIMM LDA OOE6

17 STA 1707LDA #$01

17 STA 1701

17 TOGG INC 1700LDX OOE7

FREQ DEX

BNE FREQ

17 BIT 1707

BPL TOGG

DEC OODD

BNE TIMM

RTS

""""" SPACE SUBROUTINE ' ' • " ' " ' '

DISP STX OCDD

TIMS LDA OOE6

17 STA 1707

17 HOLD BIT 1707BPL HOLD

DEC OODD

BNE TIMSRTS

UNCOND. JUMP

(DASH LENGTH)

SEND A DASH

UNCOND. JUMP..DEBOUNCE KEY..

WAIT FOR KEY RELEASE

WAIT FOR KEY DOWN

..UPDATE POINTER TOPOINT AT NEXT GROUP..

..LOAD WINDOWS OOE8-

OOEC WITH CONVERSIONS

FOR DISPLAY..

LAST GROUP?

NO, GET ANOTHER

REINITILIZE POINTER

TO RU N THRU GROUPS AGAIN

UNCOND. JUMP

TEMP. STORE

SPEED BYTE

START TIMERPAD TO OUTPUT

TOGGLE PAO

DETERMINE FREQ.

TIME UP?

NO

DETERMINE MARK LENGTH

TEMP. STORE

SPEED BYTE

START TIMER

DONE?NO

FULL TIME UP?

NO

57

Page 59: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 59/178

02B1 A9 7F02B3 8D 41 17

02B6 AO 0002B8 A2 09

02BA B9 E8 00

02BD 84 FC

02BF 20 4E IP02C2 C802C3 CO 0602C5 90 F3

02C7 20 3D IF

02CA 60

02CB 38 D8

02CD A5 Dl

02CF 65 D4

02D1 65 D502D3 85 DO02D5 A2 0402D7 B5 DO

02D9 95 Dl

02DB CA

02DC 10 F9

02DE 60

***** Display Subroutine *******change segments....to outputsinit. recall indexinit. digit numberget charactersave Ydisplay characterset up for next char6 chars displayed?no, do morekey down?

from K i r n User Notesvol 1, #1(J. Butterfield)

DISP LDA #$7FSTA PADD

LDY #0

LDX #9

SIX LDA OOE8,Y

STY YSAV

JSR DISPLINY

CPY #6

BCC SIX

JSR KEYTS

RTS

***** Random Number Subroutine ******RAND SEC CLD

LDA RND+1

ADC RND+3

ADC RND+4

STA RND

LDX #4

ROLL LDA RND,X

STA RND+1,XDEX

BPL ROLL

RTS***** initialization Values *******

02DF 00 05 36 03 33 6$CO CO CO CO CO 00***** Morse Code Characters *******

02EB 60 88 A8 90 40 28 DO 08 20 78 BO 48 EO AO FO 68

02FB D8 50 10 CO 30 18 70 98 B8 C8 FC 7C 3C 1C OC 04

030B 84 C4 E4 F4 56 CE 32 8C***** Display Characters **********

0313 F7 FC B9 DE F9 Fl BD F6 84 9E FO B8 B7 D4 DC F3

0323 E7 DO ED F8 BE EA 9C 94 EE C9 BF 86 DB CF E6 ED

0333 FD 87 FF EF 90 84 D3 C8

*** Characters sent stored in 033B - 03FF ***CHANGES: The program sends and displays 5 groups of5 characters each. This may be changed, althoughyou may need to do some debugging along the way.

Important parameters are:—0233 contains characters-to-be-sent, plus one;—02EO contains groups-to-be-displayed-after-transmission;—02E3 contains speed-of-transmission; hex 33 gives about16 groups/min, hex 66 gives 8 words/min—02E4 varies the tone—02E1/02E2 points at the block of'characters to be sent;—0222 controls the character set;1A for letters only.See Byte magazin e, October 1976,page 36, for details ofmorse character storage.

58

Page 60: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 60/178

CRAPS BY JIM BUTTERFIELD

DESCRIPTION -

SET ADDRESS 0200, THEN HOLD "GO" DOWN .. YOU'LL SEE:- 2 DICE "ROLLING" ON THE LEFT

- $10 BALANCE ON THE RIGHTLET "GO" GO ... THE DICE WILL STOP ROLLING, AND YOU'LL GET:

- A WIN ON A TOTAL OF 7 OR 11; YOU'LL SEE YOUR DOLLAR

BALANCE RISE; OR

- A LOSS ON TOTALS OF 2,3, OR 12; YOUR DOLLAR BALANCEWILL DROP; OR

- A "POINT" - THE CENTER SEGMENTS WILL LIGHT WITH THE

ROLL AND YOU MUST TRY TO ROLL THIS TOTAL AGAIN

BEFORE YO U ROLL 7 -PUSH THE "GO" BUTTON ONLY ON THE FIRST ROLL. FOR SUBSEQUENT

ROLLS, PUSH ANOTHER BUTTON.

0200 D8 START0201 20 40 IF0204 20 6A IF0207 C 5 4o0209 FO 79

020B 85 40020D 49 15020F 85 410211 C9 060213 DO 050215 A9 100217 20 A9 02021A AD 04 17 NOGO021D A2 CO021F 86 4E0221 A2 050223 C5 4E RNDLP0225 90 02

0227 E5 4E0229 46 4E RNDOV022B CA0220 10 F5022E AA

022F E80230 BD E7 IF

0233 A4 410235 FO 060237 86 420239 85 43023B DO 47023D 85 47 PLAY023F A5 430241 85 460243 A5 44

CJ-0)J.I KEYINJSR GETKEYCMP LASTBEQ LIGHT same key as before?STA LASTEOR #$15 no-key testSTA FLAG into flagCMP #6 GO key?BNE NOGO nope . .LDA #$10 yes, $10JSR DOBUX put in windowLDA TIMER random valueLDX #$CO divide by 6STX DIVRLDX #5CMP DIVR divide..BCC RNDOV . .a. .SBC DIVR . . digitLSR DIVRDEXBPL RNDLP

TAX die 0-5INX die 1-6LDA TABLE, X segment

LDY FLAG which die?BEQ PLAY second?STX DIE first, save it..STA WINDX ..& segmentBNE LIGHT unconditionalSTA WINDOW+1 show die. .LDA WINDX . . and otherSTA WINDOW oneLDA BUX out of dough?

59

Page 61: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 61/178

' 024-5 FO 3D024-7 8A 18024-9 65 4- 2

024-B C5 4- 5

024-D FO 28024-F A6 4- 5

0251 FO 120253 09 070255 DO 2D0257 A5 44 LOSE0259 FO 05025B 18 F8025D E9 00025F D80260 20 A9 020263 DO IF

0265 A6 4- 6 FIRST0267 86 4- 8

0269 A6 4- 7

026B 86 4-9026D 85 4- 5026F AA

» 0270 BD 06 020273 FO OF0275 30 EO0277 A5 4 - 4 - WIN0279 C9 99027B FO 0 4-

027D F8027E 69 010280 D80281 20 A9 02 WINX

0284- A5 4-1 LIGHT0286 FO 0 4-0288 E6 4- 6028A E6 4- 7

028C A9 7F NOINC028E 8D 4- 1 170291 AO 130293 A2 050295 B5 4- 6 LITE0297 8D 4-0 17029A 8C 4- 2 17029D E6 4-F PAWS029F DO FC02A1 88 8802A3 CA02A4- 10 EF02A6 4- C 00 02

BEQ LIGHT . .no breadTXA CLGADC DIE add other dieCMP POINT get the point?BEQ WIN . .yupLDX POINT point=zero. . .

BEQ FIRST ..first rollCMP #7 seven you loseBNE LIGHT . . nopeLDA BUXBEQ LOSX nough dough?CLC SED decimal add..SBC #0 neg oneCLDJSR DO BUX put in windowBNE LIGHT unconditionalLDX WINDOW copy pointSTX WINDOW+2LDX WINDOW+1

STX WINDOW+3STA POINT

TAX\ point valueLDA B-2,X 'win

1 tableBEQ LIGHT ..says pointBMI LOSE . . says crapsLDA BUX . . says winCMP #$99 maximum bucks?BEQ WINX yes, skip addSED decimally add..ADC #1 . . oneCLDJSR DO BUX make segmentsLDA FLAG still rolling?BEQ NOINC ..nope;INC WINDOW . .yup, so..INC WINDOW+1 ..roll em!LDA #$7FSTA PADD

LDY #$13LDX #5LDA WINDOW, XSTA SADSTY SBD

INC PAUSEBNE PAWSDEY DEYDEXBPL LITEJMP START

02A9 85 4402AB AO 0002AD 84- 4-502AF 84- 4- 8

DOBUX STA BUXLDY #0STY POINT clear pointSTY WINDOW+2 ..and..

60

Page 62: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 62/178

02B1 8 4-902B3 A8 4- A

02B5 4- A 1*A02B8 AA02B9 BD E? IF02BC 85 ^A02BE 98

02BF 29 OF02C1 AA

02C2 BD E? IF02C5 85 4- B

02C7 60

STY WINDOW+3 displayTAY LSRALSRA LSRA LSRATAXLDA TABLE,X

STA WINDOW+4TYAAND #$OFTAXLDA TABLE,X

STA WINDOW+5

RTS

02C8 FF FF 00 00 00 01 00 00 00 01 FF (TAB)

: ss jsc5? HEX D U M P - C R A P S >«««««

0200-0210-

0220-

0230-0240-0250-0260-0270-0280-0290-02AO-02BO-

02CO-02 DO-

08

41

4EBD

43

45*20BD

08

17FC48OF

00

20 40

C9 06

A2 05E7 IF

85 46

F O 12

A9 02C6 02

20 A9AO 1388 88

84 49AA BD01 FF

IF

D O

C5A4

A5

C9DO

F O

02

A2CA

A8

E7

20

054E4144

07IF

OF

A5

05104AIF

6A

A990FO

FO

DO

A630

41

B5EF

4A

85

TC5

ij 20

02 E5

06 863D 8A

2D A546 86E O A5

F O 0446 8D4C 004A 4A

4B 60

40 FO

A9 024E 4642 8518 65

44 FO48 A644 C9E6 4640 1702 85AA BD

FF FF

79AD

4E

4342

054799E68C44E700

85 40

04 17CA 10

DO 47

C5 4518 F8

86 49F O 04

47 A942 17AO 00I F 85

00 00

49A2

F585F O

E985F8

7F

E6844A

01

15 85C O 86

AA E8

47 A528 A600 D845 AA

69 0180 414F DO45 84

98 2900 00

Coding notes: C R A P S is a highly top-down program.T h e p r o g r a m always f l o w s f r o m S T A R T t o L I G H T a n dback again with few breaks in sequence. The dicea r e randomized f r o m T I M E R ( 1 7 0 4 ) a n d R N D L P containsa s m a l l division routine, dividing by 6; theremainder, randomly 0 to 5, gives the roll ofone die. On the first roll of a run,we usethe table at 02 C8 to analyze the total: in thistable, FF means you lose and 01 means you win.

F L A G is zero if you're not pushing any button.Segments for the display are stored in tableWINDOW, 0 0 4 6 to 0 0 4 B .

61

Page 63: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 63/178

DUEL BY STAN OCKERS

DESCRIPTION -

THIS IS A GAME FOR TWO PLAYERS. WHEN THE PROGRAM IS

STARTED AT 0200, EACH PLAYER IS GIVEN TEN POINTS AS INDICATED

ON OPPOSITE SIDES OF THE DISPLAY. THE CENTER DIGITS WILL

BE BLANK. AFTER A RANDOM DELAY, THE CENTER DIGITS WILL LIGHT.THE FIRST PLAYER TO PRESS HIS KEY WILL INCREASE HI S SCORE

BY ONE AND DECREASE HIS OPPONENT'S BY ONE. THE CENTER DIGITS

WILL THEN BLANK FOR ANOTHER RANDOM DELAY. IF A PLAYERPRESSES HIS KEY WHILE THE CENTER DIGITS ARE BLANK, HI S SCORE

WILL BE DECREASED BY ONE. WHEN ONE PLAYER REACHES ZERO THE

GAME IS OVER AND MUST BE RESTARTED AT 0200. THE PLAYER TO

THE LEFT USES KEY ZERO AND THE ONE ON THE RIGHT USES KEYSEVEN.

02000202

02040206

0209020B

020D020F

0211

02130216

021902 IB

02 ID

02200222022402260228

0229022C022F

023102330235

0237023902 3B02 3D023F

0241

0243024502470249

A9 1085 F985 FBAD 44 17

29 IF

09 0185 EEA9 0085 FA

20 71 02AD 07 17F O OD

A9 FF

8D 07 17C6 EE

10 04A9 36

85 FAD8

20 40 IF20 6A IF

C9 1510 EO

C9 07FO OE

C9 00FO 02

DO D6A2 02A5 EE10 14

30 06

A2 00A5 EE10 OC

RAND

DISP

MORE

LEFT

RITE

LDASTA

« STA

LDA

AN D

ORASTA

LDA

STA

JSR

LDA

BEQ

LDASTA

DEC

BPL

LDASTA

CLD

JSRJSR

CMP

BPLCMP

BEQ

CMPBEQBNELDX

LDA

BPLBMI

LDXLDA

BPL

#$10OOF900 B1744

#$1F

#$01

OOEE

#$00OOFA

LITE

1707MORE

#$FF

1707OOEE

MORE

#$36OOFA

KEY INGET KEY

#$15DISP

#$07RITE

#$00LEFT

DISP

#$02OOEE

LOS1ADD1

#$00OOEE

LOS1

INITIALIZE DIGITS

GET "RANDOM" #

NOT TOOJ3IG

NOT TOf JMALL

PUT IN DECREMENT LOC.

BLANK CENTER DIGITS

DISPLAY DIGITS

TIME UP?

NO

START TIMERFULL TIME UP?

NO, SKIP

YES, CHANGE ..

CENTER DIGITS

CLEAR FOR KEYBOARD

INIT. KEYBOARDKEY DEPRESSED?

VALID KEY?

NORIGHT KEY?

YES

LEFT KEY?YES

NOT A 0 OR A 7INDEX FOR LEFT

TIME UP?NO DECREASE LEFT ONEYES, INCREASE LEFT

INDEX FOR RIGHT

CHECK TIMENOPE, NOT YET

62

Page 64: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 64/178

024B

024C024D

024F

0251

0 2 5 3

02540256

02570258

0 2 5 9025B

025D

025F

0261

0264

0267

0269026B026E

026F

F8

18

B5 F9

69 01

95 F98A

49 02AA

F8

38

B5 F9E9 01

95 F9FO OA

20 71

20 40

DO F8

FO 9B

20 71

B 850 FA

ADD1 SED

CLCLD A O O F9 ,X

AD C #$01

STA OOF 9,X

TX A

EOR #$02TAX

LO S 1 SED

SEC

LDA OOF9,X

SB C #$01

STA OOF 9,X

BEQ FIN

02 WAIT JSR LITE

IF JSR KEYIN

BNE WAIT

BEQ RAND

02 FIN JSR LITE

CLV

BVC FIN

INCREASE SCORE ..

BY ON E

INDEX TO OTHER ..

SIDE

DECREASE SCORE ..

BY ONE

GO TO FIN IF ZERO

WAIT FOR SWITCH ..

TO BE RELEASED

THEN START NEW DELAYFINISHED LOOP

UNCOND. JUMP

xxxxx DISPLAY SUBROUTINE """-"

0271

0273

02760278

02 7A

02 7D

02 7F0 282

0285

0 2 8 702 8A

02 8B028C

02 8D

02 8E028F

0 2 9 0

0292

0 29 50296

0298

029B029C

029E

02AO

02A302A4

A9 7F8D 41

A2 09A5 FB20 8B

A5 FA20 4E

20 4E

A5 F9

20 8B60xxxxx

A84A4A4A

4AFO OA

20 48

9829 OF20 48

60A9 8084 FC

20 4E

B 850 EF

LITE LDA # $ 7 F

17 STA SADD

LDX # $09LDA OOFB

02 JSR 2HEX

LD A OOFA

IF JSR CONVX

IF JSR CONVX

LD A OOF9

02 JSR 2HEXRTS

HEX CHARACTER CONVERSION

2HEX TAY

LS R A

LS R A

LS R A

LS R ABEQ ZBLK

IF JSR CONVD

2NDC TYAAN D # $ O F

IF JSR CONVD

RTSZBLK LDA # $ 8 0

ST Y 00 FC

IF JSR CONVX

C LV

BV C 2NDC

•/

INIT. DIGIT ft

GET CENTER DIGITS

CONVERT NONHEX CHAR.

TWO OF THEM

SUBROUTINE ""'""

SUBROUTINE TO CONVERT

ON E WORD TO 2 HEX

CHARACTERS

SECOND CHARACTER

BLANK LEADING ZEROS

CONVERT NONHEX CHAR.

UNCOND. JUMP

6 3

Page 65: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 65/178

MOWNby Jim Butterf eld

Y ou are farmer B rown. You are g r o w i n g a beautiful crop of cornBut the following animals try to come and steal your corn:

" C C _

Ant Bird

0

Cow Dog Elephant

CD

Fox

As soon as you see one of these animals coming for your corn,you can scare it away by calling its name. Press the buttonwith the first letter of the animal's name. So you wouldpress A to shoo away an ant, to shoo away a bird, and so on.

If you press the right button, the animal will go back. If youpress the wrong button, it will think you mean somebody else

and keep coming for your corn. And when all your corn is gone,KIM will show 000 and the game is* over.

The animal won't "shoo" unless it has completely entered thedisplay. Speed of the animals can be adjusted by changing thecontents of location 026A. -"

0200 A 2 O D S T A R T0202 86 6E

020ij A9 00

0206 95 60 S L O O P0208 C A

0209 10 FB020B A 2 O B TEST020D B5 60 T L O O P020F DO 3B0211 CA0212 10 F9021i| E6 6D0216 A £ 6C0218 FO 09021A C6 6D021C C6 6E021E DO 03

0220 U C 25 19

0223 A D O U 1? M O R E0226 hA . I jA 1|A0 2 2 9 U A U A022B C 9 0 6022D 90 02022F 29 03

0231 18 M A K E

0232 A A0233 6 9 O A

L D X #$13ST X C O R N

IDA # 0S T A W I N D O W , !

DEX

BPL S L O O PL D X #11I D A W I N D O W , !B N E C O N T I N

D E XB PL T L O O PINC GOTL D A F I A GBEQ M O R E

DEC GOTD E C C O R N

BN E M O R E

JM P D O N E

L D A T I M E R

bushels of corn to startclear the w i n d o w

.

is window empty?

no, keep going

yes. make new animal

did last animal get in?

take away some cornany left?no, end of game

random value..L S R A L S R A L S R A ..to generate..L S R A L S R AC M P #6B C C M A K E

A N D #$03C L C

T A X

A D C #$OA

..new ra n d o m animal6 types of animal

animal type to Xkey type A to F

64

Page 66: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 66/178

ALOOF

NOKEY

0235 B5 6F0237 ED kh 02023A 85 70023C A9 02

023S 85 7102UO AO 0502U2 Bl 70

02hh 99 66 0002U7 8802U8 10 F802UA 8 1 * 6002UC A2 0502 E B5 660250 DO 130252 CA

0253 10 F90255 20 hO IF0258 20 6A IF025B C5 6F025D DO 06

025F A5 6C0261 10 02

0263 E6 6C0265 C6 720267 DO IE0269 A9 20026B 85 72026D A5 6C026F 30 OD

0271 A2 OA

0273 B5 5A0275 95 5B

0277 CA0278 DO F9027A 86 5A027C FO 09027E A2 FO0280 B5 6C0282 95 6B028U E80285 30 F90287 A9 7F0289 8D Ul 17028C AO 13028E A2 05

0290 B5 60 LITE0292 8D hO 170295 8C h 2 170298 E6 73029A DO FC

029C 88 88 CA029F 10 EF02A1 UC OB 02

animal 'picture1address

to indirect pointer

STA KEYLDA INDEX,XSTA POINLLDA #2

STA POINHLDY #5 six locations to moveLDA (POINL),Y from 'picture'

STA WINGS,YDEYBPL ALOOPSTY FLAG

CONTIN LDX #5CLOOP

..to 'wings'

animal c o m in g

R L O O P

L D A W I N G S ,XB N E N O K E Y

D E X

B PL C L O O P

JS R KE YI NJS R G E T K E Y

C M P K E Y

B N E N O K E Y

L D A F L A GB P L N O K E Y *

IN C F L A G

DEC DELAYB N E N O M O V E

L D A #$20

STA DELAY

L D A F L A G

BM I COMING

L D X #10L D A W I NDO W -6.XS T A W I N D OW - 5 . X

D E XBN E R L O O PSTX WINDCW-6B E Q N O M O V E

COMING L DX # $ F OCMLOOP LDA WINDOW+12,X

S T A WINDOW+11,XIN X.BMI CMLOOP

NOMOVE LDA #$7FSTA PADD

LDY #$13

LDX #5

LDA WINDCW,XSTA SADSTY SBD

INC WAIT

BNE LITEXDEY DEY DEXBPL LITE

flag FFtest:

is animal out of 'wingsno, ignore keyboard

right anim al named?no, ignore key

animal retreating?make animal retreatwait a while.•before moving animalspeed control value

move animal - which way?

..left

..right

clear extreme leftunconditional branch-16

light KIM display

six display digits

LITEX

JMP TESTj index and animal 'pictures' in hexadecimal form

02AU AA BO B6 BC C2 C8 08 00 00 00 00 00 01 61 61 hO 00 00

02B6 61 51 hi 01 00 00 63 58 UE 00 00 00 71 ID 11 1 IF 01 0002C8 63 58 UC UO 00 00 -

Page 67: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 67/178

FARMER BROWN....

Exercises:

1. You can see that each animal occupies 6 memory locations,starting at 02AA (the Ant)- and the last location must alwaysbe zero. Can you make up your own animals? The letters maynot fit exactly, but you can always invent names or useo d d ones (youcould make an Aardvark, a Burfle, a Cobra, andso on).

2. The game might be more fun if the animals went faster aftera while, so that sooner or later they would just zip by.The location that controls speed is at address 026A;the lower the number, the faster the animals will go.So if you could arrange to have the program decreasethis number automatically once in a while, you'd geta nice speed-up feature.

3. You can't "shoo" the animal until it's completely enteredthe display; but you can still catch it after it's partlyleft. The game would be harder - and maybe more fun -if you could only shoo it while it was completely in thedisplay. Hint - testing location 00$F (WINDOW-l) wouldtell you if an animal was on its way out.

U. You'd have a "Target Practice" game if you made the animaldisappear (instead of backing up) when you pressed theright button. With a little planning, you'll find that

this is quite easy to do.

X J O C K X HEX DUMP - FARMER BROWN:{!««~

{

0200-

0210-

0220-

0230-0240-

0250-

0260-

0270-0280-

0290-02A0-

02B0-

02C0-

A2

3B

4C

03

A0

D0

6C

0DB5

B5

EF

0100

0D 86

CA 10

25 1918 AA05 Bl

13 CA10 02

A2 0A6C 95

60 8D

4C 0B

61 6100 71

6E A9

F9 E6

AD 04

69 0A

70 99

10 F9E6 6C

B5 5A6B E8

40 1702 AA

40 00

ID 41

00

6D

17

85

66

20

C6

9530

8C

B0

00

IF

95

A5

4A

6F

00

40

72

5BF9

42

B6

61

01

60

6C

4A

BD

88

I F

D0

CAA9

17BC

51

00

CA

F0

4A

A4

10

20

I E

D07F

E6

C2

47

63

10

09

4A

02

F8

6A

A9

F98D

73

C8

01

58

FB

C64A

85

84

IF

20

8641D0

08

00

4C

A2

6D

C970

6C

C5

85

5A17FC

00

00

40

0B

C6

06

A9

A2

6F

72

F0A0

88

00

63

00

B5

6E

90

02

05

D0

A5

091388

00

58

00

60 D0

D0 03

02 29

85 71

B5 66

06 A5

6C 30

A2 F0A2 05CA 10

00 00

4E 00

66

Page 68: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 68/178

HI 10 BY JIM BUTTERFIELD

DESCRIPTION -

AN EASY GAME FOR ONE OR MORE PLAYERS. KIM CHOOSES A MSECRET NUMBER FROM 01 TO 98. AT THE START, THE FIRST FOUR

DIGITS SHOW THE HIGH AND LOW BOUNDS OF THE NUMBER - 99 HIGH

AND 00 LOW. AS GUESSES ARE ENTERED - ENTER THE GUESS AND

PRESS A FOR ATTEMPT - THE BOUNDS CHANGE AS YOU ARE NARROWINGDOWN THE POSSIBILITIES. FOR EXAMPLE, GUESS 32 AND THE DISPLAY

MI GHT CHANGE TO 32 00, MEANING THAT THE COMPUTER'S SECRET

NUMBER IS BETWEEN THESE VALUES. AFTER EACH LEGAL GUESS,

THE COMPUTER SHOWS THE NUMBER OF ATTEMPTS MADE SO FAR.

ONE PLAYER GAME: TRY TO GET THE MYSTERY NUMBER IN SIX ATTEMPTS.

MULTI PLAYER GAME: EACH PLAYER TRIES TO AVOID GUESSING THE

MYSTERY NUMBER - THE CORRECT GUESSER LOSES AND IS "OUT".

0200 F80201 A50203 380204 690206 A20208 C9020A DO020C 8A020D 85020F 200212 DO0214 D80215 A90217 850219 A9021B 8502 D A2

021F 86

0221 86

0223 200226 200229 C9022B FO022D C5

022F FO0231 85

EO

00

019901

EO40 IF

ED

99

FB

00

FAAOF9

El

IF IF6A IF

13D3E2

F2

E2

START SED

TOP LDA

SEC

ADC

LDX

CMP

BNE

TXA

OVRO STA

JSR

BNE

CLD

LDA

STA

LDA

STA

RSET LDX

NSET STX

STX

GUESS JSRJSR

CMP

BEQ

CMP

BEQ

STA

RND generate random f01 to 98

#0fl overflow at 99#$99OVRO

RNDKEYIN

TOPinitialize:

#$99 hiPOINTH

#0

POINTL and lo#$AO guess counterINKNGUESS

SCANDS light displayGETKEY test key#$13 go key?START

LAST

GUESS same key?LAST

67

Page 69: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 69/178

02330 2 3 502370 2 3 90 2 3 A0 2 3 B

0 2 3 C0 2 3 D023F0 2 4 00242

0243024502470249024B024D

024F0 2 5 1

0255

0257

0259

025B

025D

025F

0 2 6 1

0263

0264

02660268

OAFO 10BO EAOAOAOA

OAA2 03OA

26 F9CA10 FA

30 DC

A5 F9C5 EO90 06C5 FB

BO D285 FB

A6 EOE4 F9

90 08

A6 FA

E4 F9

BO C4

85 FAA6 ElE8

EO AAFO B5DO B5

LOOP

EVAL

OVR1

OVR2

CMP

BEQ

BCS

ASL

ASL

ASL

ASLLDX

ASL

ROL

DEX

BPL

BMI

LDA

CMP

BCC

CMP

BCS

STA

LDXCPX

BCC

LDX

CPX

BCS

STA

LDX

I NX

CPX

BEQ

BNE

#$OAEVAL

GUESS

AA

A

A#3A

INK

LOOP

GUESS

INKRND

OVR1

POINTH

GUESS

POINTH

RNDINK

OVR2

POINTL

INK

GUESS

POINTL

NGUESS

#$AA

RSET

NSET

'A' key?y e s , evaluate guessno key?roll character..into..position..

. then

. into

.display

guess lower....than number?yes, skipno, check hiout of range?

n u m b e r lower....than guess?yes, skipno,check lo

out of range?

'guess' number. .plus 1

past limit?yes, reset

xxxxx HEXDUMP - HI LO~J5::::

0200 F8 A5 EO 38 69 00 A2 01 C9 99 DO 01 8A 85 EO 200 2 1 0 40 IF DO ED D8 A9 99 85 F B A9 00 85 FA A2 AO 860220 F9 86 El 20 IF IF 20 6A IF C9 13 FO D3 C5 E2 FO

0230 F2 85 E2 C9 O A FO 10 BO EA OA OA OA OA A2 03 OA

0240 26 F9 CA 10 FA 30 DC A5 F9 C 5 EO 90 06 C5 FB BO

0 2 5 0 D2 85 FB A6 EO E4 F9 90 08 A6 FA E4 F9 BO C4 85

0260 FA A6 El E8 EO AA FO B5 D O B5

68

Page 70: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 70/178

BY CHUCK EATON

DESCRIPTION -THIS IS AN EIGHT LAP HORSE RACE AND YOU CAN BE THE

JOCKEY AND WHIP YOUR HORSE TO GO FASTER. WARNING ... WHIP

THE HORSE TOO MUCH AND HE PROBABLY POOPS OUT. THE PROGRAMSTARTS AT 0200.

HORSE TRACK WHIPPING BUTTONPRINCE CHARMING TOP PCCOLORADO COWBOY MIDDLE C

IRISH RAIR BOTTOM 4

02000201

020302060208

0209020B020D0210

0212

02140217

0219021C021D

021F

0221

0224

0226

0228022A

022B022D

022F

0231

023302350237023A

023C023E023F

0241024402460248024A024C024E025002520254

D8A2BD

95CA

1 0

A98D

AO

A2

B98420

C8

C O

90

20A530

A2CA

30D6

DO

86A4B6

B9

3595E8

96

B94915

95EO

30DO

A5F ODO

1 3

D97C

F8

7F

41

00

09

7CFC4E

06

F33D

8F

E3

03

DE86

F9

999983ED7C

7C

83

EDFF

7C

7C

052B

068F

IB

23

02

17

00

IF

IF

02

02

CLD

LDX #$13

INIT LDA 02D9,XSTA 007C,X

DEX

BPL INIT

DISP LDA #$7F

STA 1741

LDY #$00

LDX #$09LITE LDA 007C,Y

STY OOFC

JSR 1F4E

INY

CPY #$06BCC LITE

JSR 1F3D

LDA LAP CNT.BMI DISP

LDX #$03NEXT DEX

BMI DISPDEC 0086,X

BNE NEXT

STX 0099

LDY 0099LDX 0083,YLDA 02ED,YAND 007C,X

STA 007C,X

INX

STX 0083,Y

LDA 02ED,YEOR #$FF

ORA 007C,XSTA 007C,X

CPX #$05BMI POOP

BNE NLAP

LDA 008F

BEQ LASTBNE POOP

...INITIALIZATION...

HORSES TO STARTING GATE

...LIGHT DISPLAY...

OUTPUT DIGIT

SIX DIGITS DISPLAYED?NOT YET

TURN OFF DIGITS

FINISHED TOTAL LAPS?YES, FREEZE DISPLAY

NEXT HORSE

FINISHED 3 HORSESDEC. CNT., HORSE X

NOT ZERO, NEXT HORSE

SAVE HORE INDEX

AND PUT IN Y AS INDEX

DIGIT POS.OF HORSE I N X

MASK TO REMOVE HORSE

GET RID OF HORSE

RETURN REMAINING HORSES

GO TO NEXT DIGIT RIGHT

UPDATE HORSE DIGIT POS.

GET MASKCHANGE TO AN INSERT MASKPUT HORSE IN NEXTDIGIT RIGHT

REACHED RIGHT SIDE?

NOT YETOFF RIGHT SIDE, CHANGE LAPCHECK LAP COUNTER

IF ZERO, LAST LAP

69

Page 71: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 71/178

02560258

0259025B

025D025F

026002620264

0266

0268026A026C026D026F0271

0273

027502770279

027C027E0281

0283

02850288028B

028D028F02920294

02960298029A029C

029F02A202A402A6

02A902AB02 C

02 D02AF

02B102B4

02B502B702B902BA02BC02BE02CO02C2

A2 02 NLAP

38 DOWN

B5 83

E9 06

95 83CA

10 F6A2 06

B5 7C STOR95 76A9 8095 7CCA

DO F5C6 8F LASTDO 06

A5 81

0 9 0 6 .

85 81B9 89 00 POOPFO OA

20 C5 0229 3C

DO 1A

99 89 0020 C5 02 NOPO29 3885 9AB9 8C 0030 OB29 38

C5 9ABO 05A9 FF

99 89 00

20 3D IF FAST

AO FF

A6 993D FO 02

FO 018898 SKIP

55 8985 9A

20 C5 023829 0165 9A18

A6 9975 8C95 8C95 864C 2A 02

LDX #$02

SECLDA 0083,X

SBC #$06STA 0083,X

DEX

BPL DOWNLDX #$06LDA 007C,XSTA 0076,XLDA #$80STA 007C,XDEX

BNE STOR

DEC 00 8FBNE POOPLDA 0081

ORA #$06STA 0081LDA 0089,Y

BEQ NOPOJSR RAND

AND #$3C

BNE FASTSTA 0089,Y

JSR RAND

AND #$38

STA 009A

LDA 008C,Y

BMI FAST

AND #$38

CMP 009ABCS FASTLDA #$FF

STA 0089, Y

JSR KEYIN

LDY #$FF

LDX 0099AND 02FO,X

BEQ SKIP

DEYTYAEOR 0089,X

STA 009A

JSR RANDSEC

AND #$01ADC 009ACLC

LDX 0099

ADC 008C,XSTA 008C,X

STA 0086,X

JMP NEXT

...CHANGE TO A NEW LAPSHIFT ALL HORSE DIGIT

POSITIONS SIX PLACESDOWN...

...ALSO SHIFT DIGIT

CONTENT\INTO STORAGE

AREA AND CLEAR DISPLAYAREA...

DEC. LAP COUNTER

NOT LAST LAP, CONTINUE

LAST LAP, PUT FINISH

LINE IN LAST DIGIT

HORSE Y POOP FLAG

HORSE NOT POOPED

...POOPED, BUT MAY

BECOME UNPOOPED DEPENDINGON RANDOM NUMBER

...NOT POOPED, BUT MAYBECOME POOPED DEPENDING

ON RANDOM NUMBER...

IF POOPED, SET POOP

FLAG TO "FF"

GET KEY FROM KEYBOARD

INIT. Y TO MAXHORSE INDEX IN X

MASK (IS HORSE WHIPPED?)

NO, NOT BEING WHIPPEDWHIPPED, Y MADE SMALLER..CHANGE SIGN IF POOPED

EXC. OR WITH 00 OR FF

SAVE SPEED UPDATE

GET A RANDOM NUMBER

..LOWEST BIT OF #COMBINE WHIP UPDATE,RAND # CO OR 1) S CARRY

HORSE INDEX IN XHORSES SPEED ADDED IN

SAVE NEW SPEED

ALSO IN WINDOW COUNTER

LOOP

70

Page 72: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 72/178

02C5

02C602C802CA

02CC02CE

Q2DO02D202D402D502D7

********«h*k«h«»

38

A5 9265 9565 96

85 91A2 04

B5 9195 92CA

10 F9

60

RANDOM

RAND

MOVE

02D8-02EO-02FO-

NUMBER SUBROUTINE

SEC

LDA 0092 FROM J. BUTTERFIELD

ADC 0095 KIM USER NOTES -1ADC 0096 PAGE 4

STA 0091LDX #$04

LDA 0091,XSTA 0092,XDEXBPL MOVE w

RTS "Vm

xxxxx TABLES - HORSERACE """""

00/80/80/80/80/80/80/80

FF/FF/FF/80/80/80/00/00/00/80/80/80/08/FE/BF/F701/02/04

x x s w c x HEX DUMP - HORSERACE x x x x x

02000 2 1 0

0220023002400250026002700280029002AO

02BO02CO

02DO02EO02FO

D8 A2

AO 00

F3 20

F9 86

83 B9A5 8F

10 F68F DO

02 298C 003D IF

9A 2095 86

B5 91FF FF

01 02

13 BD

A2 093D IF

99 A4ED 02FO IB

A2 0606 A53C DO

30 OB

AO FF

C5 024C 2A

95 92FF 8004

D9 02B9 7C

A5 8F

99 B649 FFDO 23

B5 7C

81 091A 99

29 38

A6 99

38 2902 38CA 10

7C CA84 FC

9500

30 E3 A2

83 B9 ED

15 7C 95A2 02 38

95 76 A906 85 8189 00 20C5 9A BO

3D FO 02

01 65 9AA5 92 65F9 60 00

80 80 00 00 00

10 F8 A920 4E IF

03 CA 30

02 35 7C7C EO 05

B5 83 E980 95 7CB9 89 00C5 02 29

05 A9 FF

F O 01 88

18 A6 9995 65 9680 80 8080 80 80

7F 8D

C8 CO

DE D6

95 7C30 2B

06 95CA DO

F O OA

38 8599 8998 55

75 8C85 9180 80

41 1706 9086 DO

E8 96D O 0683 CAF5 C6

20 C59A B900 20

89 85

95 8CA2 04

80 8008 FE BF F7

71

Page 73: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 73/178

KtY TRAIN Butterfi«ld

Ever wish you could touch-type your KIM keypad like some people

can type? It's not hard; all you need is practice. And whatbetter teacher to drill you on key entry than the KIM system itself?

Load this fully relocatable program anywhere. Start it up, andthe display will show a random hexadecimal digit, f f c w n 0 to F.Hit the corresponding key, and the display will blank, and thenpresent you with another random digit. Hit the Wrong key. andnothing will happen.

The educational principle involved is called positive reinforcem^ht.That is, you're rewarded for doing the right thing, and ignored ifyou do it wrong. A few minutes of practice a d a y . and you'll become

a speed demon on the keyboard.

1

0000 20 hO IF START0003 DO FB0005 AD Oh 170 0 0 8 U A U AO O O A U A U AOOOC 85 FFOOOE OA OA

0010 OA OA0012 05 FF

OOlU 85 F90016 85 FA

0018 85 FB001A 20 IF IF LIGHT001D 20 6A IF0020 C5 FF0022 FO DC002U DO FU

JSR KEYINBNE STARTLDA TIMERLSRA LSRALSRA LSRA

STA TEMPASLA ASLA

ASLA ASLA

ORA TEMP

STA INH

STA POINTL

STA POINTHJSR SCANDSJSR GETKEY

CMP TEMPBEQ STARTBNE LIGHT

key still depressed - blankrandom valuewipe high order bits"

save the digitmove back left

repeat the digitput..

..into..

..displaylight displaytest keysright key?yes, blank & rpeat

The random number used in this program is taken from the KIM timer.This timer runs continuously and might be anywhere between 00 and FFat the instant we push the button. We use the four left hand (high order']bits of the timer to produce the next digit.

Be sure that KIM is not in decimal mode when you run this nrogram -

set address OOF1 to 00 before starting. If you forget, you mightfind that the alphabetic keys (A to F) don't work right.

Exercises: can you make the program clear decimal mode automatically?How about a counter to record the number of correct keystrokes youhave made? That way, you could time yourself to see how many keysyou can get right in 60 seconds. The count could be shown in thetwo right hand digits of the display. Do you think it should bein decimal or hexadecimal?

72

Page 74: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 74/178

KIM NIM BY JIM BUTTERFIELD

Here's a jumbo NIM that's good for all skill levels.Why? Because KIM matches wits with you - literally.Play a duffer's game and KIM will make lots of errors,too. Start winning a few - and KIM will move up tothe master player level.

Hit GO and several digits on the KIM display will light.Each lit digit represents a pile of objects you canpick from. Decide which pile you wantl*and enterits identity: A for the left-hand pile through toF for the right-hand pile. The pile f c r o u have selectedwill start to flash on and off. Now enter the numberof items you want to take from that pile.

KIM will take its turn the same way - you'll seethe pile selected begin to flash, and then some

items will be taken away. After the computer moves,it's your turn again.

The winner is the player who takes the last object.When this happens, KIM will identify the winner.A new game can be started at any time by^hitting GO.

0200

020302060208

020A

020D

020F021002120214

021502170219021A021D021E0220

0223

0225

0228022A022B022D022F

0230

0233023402360238023A

20 40

20 6AC9 13DO 3AAD 04

A2 02

A829 0?FO 031869 02

95 04984A 4ACA10 EF20 40DO FBAD 04

A2 02A829 0795 07984A 4ACA10 F485 0185 02A2 06

IF STARTIF

directional regs

17

SPLIT

GO key?nope, skipget random nbrsplit into 3

save Aextract 3 bitsunless zero....add two

ZINCH

4A

IF STALL

17

SPLAT

4A

JSR KEYINJSR GETKEYCMP #$13BNE NOGOLDA TIMERLDX #2

TAYAND #7

BEQ ZINCHCLCADC #2STA VALUE,X store pile valTYA bring back randLSRA LSRA LSRADEXBPL SPLIT

JSR KEYIN wait for. .BNE STALL ..key releaseLDA TIMER new random nbr

LDX #2 split 3 waysTAY againAND #7 3 bitsSTA VALUE+3.XTYALSRA LSRA LSRADEX

BPL SPLATSTA PILE pile zeroSTA MOVE it's y our moveLDX #6 for each pile..

73

Page 75: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 75/178

023C023E0241024202440246

0243024A024C024E02500252

0254

02550257

0259025B0250025E

02600262026402660268026A026C026E02?002720274

02770279

027C027E02310233

0235

02370239023B023D023F0292029402960293029B029E02AO02A202A402A502A7

02A9

B5 0320 2D

CADO F3A6 02DO 3D

C9 10BO 39C9 00FO 3 5C9 OA90 1233E9 09A6 01DO 2AAAB5 OAFO 25

36 0135 OABO IFA6 01FO IB

85 03B5 0305 0390 13E5 0320 2D

E6 0220 16

DO 0720 0535 OB

46 00

A6 01A5 OA

55 OA9 5 O AA9 7F3D 41AO 13A2 05

B5 OB3D 4030 42E6 11DO FC88 38CA10 EFE6 12DO E7

03DRESS

NOGO

LDA VALUE-1,X ..change toJSR SEG ..segmentsDEXBNE DRESS

whose move?computer's, skip

hex digit keyed?no, skipzero key?yes, skipalphabetic?no, numericchange A-F.....to 1-6pile already....selected?

LDX MOVEBNE NOKEY

CMP #$10BOS NOKEYCMP #0

BEQ NOKEYCMP #$OABCC NUMSEC

SBC #9LDX PILE

BNE NOKEYTAXLDA FLASHR,X ^

BEQ NOKEY nothing in pile?

STX PILE OK, mark pileSTA FLASHR store flash codeBCS NOKEY unconditional

NUM LDX PILE

BEQ NOKEY no pile selectedSTA TEMP save numberLDA VALUE-1,X pile valueCMP TEMP pile big enough?BCC NOKEY nopeSBC TEMP yes, take out

03 JSR SEG compute segmentsINC MOVE computer's move

03 JSR SURVEY end of game?BNE NOKEY no, keep going

03 JSR MESSAG yes, show messgSTA WINDOW ''I LOSE

1'

LSR IQ get smart!; all routines join here - displayNOKEY LDX PILE

LDA FLASHR flash pileEOR FLASHR,X

STA FLASHR,X

LDA #$7F17 STA PADD

LIGHT LDY #13LDX #5

LITE LDA WINDOW,X17 STA SAD17 STY SBD

LITEX INC CUEBNE LITEX

DEY DEYDEX

BPL LITEINC WAITBNE LIGHT

74

Page 76: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 76/178

02AB A9 F802AD 85 1202AF A6 0202B1 FO 4E02E3 CA02B4- DO 2B

02B6 A9 0002B3 A2 0502BA 55 0 ^ 4 -

02BC CA02BD 10 FB

02BF 85 OA

02C1 A2 06

02C3 B5 030205 4 - 5 O A02C7 D5 0302C9 90 0502CB CA02CC DO F5

02CE FO OB02DO A ** 0002D2 CC 0402D5 BO 0 4-

02D? 85 0302D9 86 0102DB A6 0102DD B5 OA02DF 85 OA02E1 E6 0202E3 A5 0202E5 C9 10

02E? 90 1302E9 A6 0102EB A5 0302ED 20 2D02FO 20 1602F3 DO 0602F5 20 0502F8 3802F9 26 0002FB A9 0002FD 85 0202FF 85 010301 D8

0 3 0 2 4c oo

0305 A9 000307 85 02

0309 85 01030B A2 06030D BD 3B

0 3 1 0 95 OA0312 CA0313 10 F80315 60

LDA #$F8STA WAITLDX MOVE whose move?BEQ EXIT not computer'sDEX first step?BNE TRY no, skip stratgy

LDA #0LDX #5 merge all piles..

MERGE EOR VALU E, X ..by EOR-ing themDEXBPL MERGE

STA FLASHR save EOR productLDX #6 re-examine piles

LOOP LDA VALUE-1, XEOR FLASHR }

CMP VALUE-1, X ^ «BCC FOUND

W

DEX

BNE LOOP

BEQ MOVEFOUND LDY IQ IQ high enuff?

17 CPY TIMER ..randomly..BCS MOVE no, move dumbSTA TEMP amountSTX PILE pile number

MOVE LDX PILELDA FLASHR, X flash maskSTA FLASHR Flash.. .

TRY INC MOVE but don*t makeLDA MOVE ..the move till..CMP #$10 ..time has passedBCC EXITLDX PILE time to move.'LDA TEMP

03 JSR SEG make move03 JSR SURVEY end of game?

BNE KEEP nope, keep go in03 JSR MESSAG « U LOSE

1

SEC dummy up. .ROL IQ ..the computer

KEEP LDA #0

STA MOVE it's your moveSTA PILE un-flashCLD

02 JMP START

MESSAG LDA #0STA MOVE end of playSTA PILE no flashingLDX #6 move 7 digits

03 MLOOP LDA DATA,X pick em up..STA FLASHR, X ..put em downDEXBPL MLOOPRTS

75

Page 77: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 77/178

0 3 1 60 3 1 30 3 1 A0 3 1 C0 3 1 E

0320032203240326032?

0329032B

032C

A9 00

85 OAA2 06

05 03BO 06

B 5 0385 0386 01CADO F3C 6 03A360

SURVEY LDA #0

REVUE

SMALL

STA FLASHR un-flash ,,

LDX #6 for all piles..CMP VALUE-1,XBCS SMALL

LDA VALUE-1,XSTA TEMP

STX PILEDEX

BNE REVUEDEC TEMP

TAY test ARTS

032D 95 03032F FO 04

0 3 3 1 A30332 B9 E? IF

0335 95 OA0337 A 9 o o0339 60

SEG

NIL

STA VALUE-1,X

BEQ NILTAYLDA TABLE,Y

STA FLASHR,XLDA #0

RTS

store valueblank digit

segments to wndw

033A FF 06 BE 00 B8 BF ED F9 (DATA)

Jc:::s;;- HEX DUMP - KIM NIM """""

0342

0200

0 2 1 0

0220

023002400250026002700280029002AO

02BO

02CO02DO

02EO

02FO

03000 3 1 0

0320

03300340

20 40 IF

29 07 FO

20 40 I F

4A 4A 4A03 CA DOC9 OA 9086 01 85

90 13 E5

03 85 OB41 17 AODO FC 88

02 FO 4EOA A2 06

A4 00 CC

OA E6 02

20 16 0301 D8 4C95 OA CA

B5 03 8504 A8 B9ED F9

20 6A I F

03 18 69D O FB AD

CA 10 F4F8 A6 0212 38 E9OA BO IF

03 20 2D

46 00 A613 A2 0588 CA 10

CA DO 2B

B5 03 45

04 17 BO

A5 02 C9D O 06 2000 02 A910 F8 6003 86 01E7 IF 95

C9 13

02 9504 17

85 01DO 3D

09 A6A6 01

03 E6

01 A5

B5 OBEF E6

A9 00OA D5

04 85

10 90

05 03

00 85A9 00CA DOOA A9

DO 3A AD

04 98 4AA2 02 A8

85 02 A2C9 10 BO01 DO 2A

FO IB 85

02 20 16O A 55 OA8D 40 1712 DO E7A 2 0 5 550 3 9 0 0 503 86 0118 A6 0138 26 0002 85 01

85 OA A 2F 3 C6 0300 6 0 F F

04 17 A24A 4A CA

2 9 0 7 9 5

0 6 B 5 0 339 C9 00A A B 5 O A

0 3 B 5 0 303 DO 079 5 O A A 98C 42 17A 9 F8 8504 CA 10C A DO F5

A 6 0 1 B 5A 5 03 20A 9 00 85A 2 06 BD06 D5 03A 8 60 9506 BE 00

0 2 A 810 EF0 7 9 8

20 2DF O 35F O 25C5 0 32 0 0 57F 8D

E6 1112 A6FB 85F O O B

O A 852 D 0 302 853B 03B O 0603 FOB8 BF

7 6

Page 78: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 78/178

KfM- TAC-TOiBY LEW EDWARDS

DIRECTIONS -

PLAY BEGINS WITH KI M MAKING THE FIRST PLAY WHEN

"GO" IS PRESSED. THE SECOND THROUGH FOURTH DIGITS OF *THE DISPLAY HOLD THE PATTERN WITH SQUARES NUMBERED AS:

YOUR ENTRY WILL BE IMMEDIATE BU T 7 8 9

KIM'S ACTION WILL BE DELAYED. YOUR 45 6

PLAYS LIGHT STEADILY WHILE KIM'S 1 2 3

FLICKER. A WINNING ROW BLINKS AND A DRAW BLINKS

EVERYTHING. ON COMPLETION OF A GAME, THE "GO"KEY WILL

START A NEW GAME. IF YOU PREFER TO PLAY FIRST, PRESS THE

"+" KEY INSTEAD. THE KIM HAS AN I.Q. LEVEL THAT CAN BECHANGED BY PRESSING "PC" T GAMES END. YOU WILL SEE,

"ODDS" AND KIM'S I.Q. DISPLAYED. THE I.Q. IS INITIALLY

SET TO 75%, COO. CHANGE IT TO WHAT YOU WISH AND THEN

PRESS "DA" TO RETURN TO THE DONE LOOP AND yART A tftw

GAME IN THE NORMAL MANNER. THE I.Q.L£ ADJUSTED UPWARD

EACH TIME THE PLAYER WINS AND DOWNWARD EACH TIME KIM WINS.

THE PROGRAM STARTS AT 0100.

0100

0103

010601080 1 0 A0 1 0 C

0 1 0 D

0 1 0 F

01180 1 2 00 1 2 8

4C 10 03EA EA EA

JM P STIQ

NOPS

JUMP TO START LOCATION

SUBROUTINE "LOAD BLINK" "!"

A9 20

15 BF

95 BF

60

EA EA

BLINK FLAG

ADD IT TO THE..

INDEXED BYTE

LDA "$20

O RA SQST,X

STA SQST,X

RTS

NOPS

""""" TABLE - SEGMENTS ZZ""::

08/08/08/40/40/40/01/01/01:c::x:c:: TABLE - ROWS --""»

01/04/07/01/02/03/01/0302/05/08/04/05/06/05/0503/06/09/07/08/09/09/07

""" SUBROUTINE "GET PLAY" «««

GPLA STA TEMP SAVE THE ACCUMULATOR

LDX "$09 FOR TESTING

GPLP LDA TEMP GET IT BACK

AND PS,X MASK THE STATUS BYTE

BI T TEMP CHECK FOR BIT ON

BNE OUT GOT IT - DONEDEX

BNE GPLP NOPE - KEEP TRYING

OUT RTS SQUARE VALUE IN X

0 = NO MATCH"-""» SUBROUTINE "TEST AND INCREMENT" s««««s

0140 B5 BF LDA SS,X

0142 DO 02 BNE OUT COUNT OPEN SQUARES

0144 F6 DB INC PS,X ONLY

0146 60 OUT RTS

01300132013401360138

013A013C013D013F

85 D9A2 09A5 D935 DB

24 D9

D O 03CA

DO F560

77

Page 79: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 79/178

01470149014B

014D0150

0153

01560159015C015F01620163

0165

02000202

020402060207

0209020B020D020F

0212

02140216

0218021902 I B

02 IE

021F

0221

022302250228022A

022C

022E022F

02310234

02350237023902 3B

023E02400241024302450248024B024E

»

95AO

A9

99BE

20

BE20BE

20

88DO

60

A9A2

95CA

DO

A985AO

20

A2

D5FO

CA

DO

9988DO

E6

AO20A2

D5FO

CA

DO

9988DO

A9AO

D9

FO88DO

FO

BE

BF08

00

C8 0017 018A 03

IF 018A 0327 018A 03

E6

00ID

B4

FB

05BB04

F2 0304BB

F7

F9BB 00

EE

B6

04F2 03

05B6

F7

F9B6 00

EE

03

08C8 00

05

F815

17 01

• . * » . #*M*«*'W*W*tf*

UPDA

UPLP

NEW

INLP

ELP1

ELP2

OLP1

OLP2

PVAL

TESTWNLP

WIN

20 06 01BE IF 0120 06 01

SUBROUTINE "UPDATE"5«J!««

{

STA SS,X

LD Y "$08

LDA -$00

ST A RS,Y

LDX SQ1,Y

JSR RSADD

LDX SQ2,YJSR RSADD

LD X SQ3,Y

JSR RSADD

DEY

BNE UPLP

RTS

LDA #$00

LDX #$1D

STA OOB4, X

DEX

BNE INLP

LD A #$05ST A OOBB

LDY #$04

JSR RPLA

LDX #$04

CMP REVN,X

BEQ ELP1

DEX

BNE ELP2

ST A REVN,Y

DEY

BNE ELP1

INC ODEV

LD Y #$04JS R RPLA

LDX #$05

CMP RODD,X

BEQ OLP1

DEX

BNE OLP2

STA RODD,Y

DEY

BN E OLP1

LDA #$03

LD Y #$08

CMP ROWS,Y

B E Q W I NDEY

BNE WNLP

BEQ DRAW

LD X SQ1,Y

JSR BLNK

LDX SQ2,Y

JSR BLNK

FLAG THE SQUARE

CLEAR THE REGISTER

THEN LOAD

CURRENT STATUS

VALUES

LOOP TILL DONE

CLEAR REGISTERS

INITALIZE ORDER OF..NCf CALCULATED PLAYS

CENTER - FIXED ORDER

SIDES IN RANDOM ORDER

CORNERS- N RANDOM ORDER

TEST FOR 3 IN A ROW

03=PLAYER WIN/OC=KIM WIN

GAME WON-BLINK THE ROW

NOT YET-CK NEXT ROWNO WINNER-CK FOR DRAW

BLINK #1

BLINK #2

78

Page 80: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 80/178

0 2 5 1

0254

0257025A025C025E0260

02620263

02650267026A

026B026D02700272027402760279027B

027D027F

0280028202840286

0289028B028D

029002920294

02960299029B

029E02AO

02A302A502A802AA02AD02AF

02B102B4

02B602B802BB02BD

02CO

02C202C4

02C6

BE 27 01

20 06 014C FE 02

A2 09 DRAW

A9 CO OPEN35 BFFO OE

CADO F7

A2 0920 06 01 NXBLCA

DO FA

4C 15 03E6 B5 TURN

A5 DBDO 17

20 A6 03 KEYFO FB

C9 OA

BO F7AAB4 BF

DO F2

A9 4020 47 01

E6 DBDO AA

20 4C 03 WAIT

E6 Dl

DO F9

A9 08

20 C8 03A9 0220 C8 03A9 0420 C8 03A9 0120 C8 03

A9 CO20 30 01D O 43A9 30

20 30 01DO 3C

A9 0820 30 01DO 3520 B3 03 IPLA

29 OF

C5 D2B O IF

A4 B5

LDX SQ3,YJSR BLNK

JMP MTST

LDX -$09LDA #$COAND DSPL,X

BEQ TURN

DEXBNE OPEN

LDX #$09JSR BLNK

DEX

BNE NXBL

JMP DONEINC PLA4LDA MODE

BNE WAIT

JSR KEYS

BEQ KEY

CMP #$OA

BCS KEYTAX

LDY DSPL,X

BNE KEY

LDA #$40JSR UPDATE

INC MODEBNE PVAL

JSR DISPLAY

INC LPCNT

BNE WAIT

LDA #$08JSR PSLD

LDA #$02JSR PSLD

LDA #$04

JSR PSLD

LDA #$01JSR PSLD

LDA #$CO

JSR GETPLABNE PLAY

LDA #$30

JSR GETPLA

BNE PLAY

LDA #$08JSR GETPLABNE PLAYJSR RAND

AND #$OF

CMP IQ

BCS DUMBLDY PLAC

BLINK #3CHECK THE WINNER

OPEN SQUARE? ^

YES - CONTINUE GAME

NO - CK NEXT SQUAREALL DONE?

NO OPEN SQUARES

IT'S A DRAW

BLINK 'EM ALL

GAME'S OVER

COUNT THE PLAYS

WHO'S TURN?

WM'S *

PLAYER'S

GET A KEY

OVER 9?

GET ANOTHER»WSE IT AS AN INDEX

SEE IF SQUARE'S OPEN

NO, TRY AGAIN

YES, MARK IT FOR..

PLAYER

KIM'S NEXT

BUT FIRST CK FOR WIN

HOLD KIM BACK

A LITTLE

UPDATE AND..

THEN CHECK THE..

BOARD

WINNING PLAY FOR KIM

YES - MAKE IT

2 IN A ROW FOR..

PLAYERYES - BLOCK IT

POSSIBLE SQUEEZEPLAY FOR K IMYES - DO ITHOW MUCH SMARTS?NEEDED?

KIM'S I.Q.TOO LOW - BAD MOVES

SMART

79

Page 81: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 81/178

02C802CA

02CC

0 2C E

02 DO

02D2

02D4

02D6

02D8

02DA

02DC

02DF

02E1

02E3

02E5

02E7

02E9

02EB

02ED

02EE

02FO

02F2

02F4

02F7

02F9

02FB

02FE

0300

0302

0304

0306

0 3 0 8

030 A030C

030E

03100312

0314

03150318Q31A

031C

031E

031F

0321

0 3 2 303250 3 2 70329032B

03 2D

032F

0331

0 3 3 30 336

0339

C O 01D O 04

29 01

D O 17C O 04

D O 06

24 C4

30 OD70 07A9 0220 30 01

D O 11

AO 05

D O 02

AO 09B6 B6B5 BF

FO 05

88

D O F7

FO F3A9 80

20 47 01

C6 DB

A9 OC

4C 39 02A5 DB

D O 04

C6 D2

10 OF

E6 D2

A9 10

C5 D290 F4

BO 05A9 OC

85 D2D8

20 A6 03AO 01

C9 13

FO 28

88

C9 12

FO 23

C9 14D O EE

A9 OD

85 FB

A9 D585 FA

A5 D285 F920 IF IF

20 40 IF

20 6A IF

FOUR

SPLA

PLAC

DUMB

TPLA

PLAY

MTST

IQDN

IQUP

BCS DONE

STIQ

IQST

DONE

CHIQ

C P Y #$01

BNE FOUR

AN D #$01

BNE TPLA

C PY #$04

BNE SPLA

BIT SQST+5

BMI DUMBBVS PLAC

LD A # $ 0 2

JS R GETPLA

BNE PLAY

LD Y "$05

BNE TPLA

LDY #$09

LDX RPLA,Y

LDA DISP,X

BEQ PLAY

DEY

BNE RPLA

BEQ DUMB

LDA #$80

JSR UPDATE

DEC MODE

LD A # $ O C

JMP TEST

LDA MODE

BNE IQUP

DEC IQ

BP L DONE

INC IQ

LD A #$10

CMP IQBCC IQDN

LD A # $ O C

ST A IQ

CLD

JS R KEYS

LD Y:c$01

CMP #$13

BEQ SEMO

DEY

CMP #$12

BEQ SEMO

CMP #$14BNE DONE

LD A # $ O D

ST A POINTH

LD A # $ D 5

ST A POINTL

LDA IQ

STA INH

JS R SCANDS

JS R KEYPR

JSR GETKEY

1ST PLAY?

NO

YES

1/2 TIME PLAY A CORNER4TH PLAY?

NO, SKIP

YES, CK WHO HAS CENTER

KIM - PLAY A SIDEPLAYER-PLAY A CORNER

CAN PLAYER MAKE A..

SQUEEZE PLAY?

YES - BLOCK IT

START WITH THE CENTER

START WITH THE SIDES

USE THE RANDOM PLAY

TABLE - OPEN* SQUARE?

FOUND ONE - PLAY IT

NO, TRY NEXT ONE

NOT YET

START OVER

MARK THE..

SQUARE FOR KIM

PLAYBfc'S TURN NEXT

FIRST™ DID KIM WIN?

WHO WON?

PLAYER, UPKIM'S I.Q

KIM'S TO O SMART

LOWER THE I.Q.

NO T BELOW ZERO

NO T OVER 10 HEX

START WITH 75 %

I.Q.

DISPLAY RESULTS-GET KEY

START WITH KIM

IF "GO" KEY PRESSED

START WITH P LA YE R ..

IF "+" KEYPRESSED

"PC" PRESSED - SKIPNO KEY - LOOP

SHOW "ODDS"

AND I.Q

ON DISPLAY

80

Page 82: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 82/178

0 33C

033E

03400342

0 3 4 4

03460 3 4 8

034B

034C034E

0 3 5 1

0 3 5 30 3 5 50 3 5 7035A

0 35C

035E0 3 6 00 3 6 2

03640 3 6 6

0 3 6 80 3 6 A

0 3 6 C

036E

03700 3 7 2

0 3 7 40376

0379037B

037E0 3 7 F

0 3 8 1

0 3 8 30385

0387

0 3 8 9

038A

03 8 C

038E0 3 9 00 3 9 2

0 3 9 403960 3 9 8039A039C039E039F

03A203A5

C9 *L1

FO D5

B O E5

85 D290 El

84 DB

4C 00 02

EA

A9 7F

8D 41 17

E6 DA

AO 00

A2 OB

B9 CO 00

85 FC

FO 14

29 20F O 04

24 DA

70 OCA5 FC

29 40

D O O A

A5 DA

29 08FO 04

A9 00

FO 03B 9 OF 01

84 FC

20 4E IF

C8C O 09

FO 06

EO 11FO CE

DO CE

6 0

B5 BF

85 D924 D930 0670 08

A9 00FO 06A9 04

D O 02

A9 01

18

79 C8 00

99 C8 0060

SEMO

CMP #$11

BEQ DONE

BC S CHIQ

STA IQ

BCC CHIQ

STY MODE

JMP NEW

"DA" KEY PRESSED

RETURN TO "DONE" LOOP

KEEP TR Y I NG IF OVER "AD"

UNER ll(HEX), CHANGE

IQ TO KEY #, NO KEY AGAIN

SE T STARTING PLAY

ANOTHER GAME1*

NOP

DISPLAY

DIGX

SEGY

FLIC

O FF

ON

DIGT

bUBKUUHINt "UlbHLAY" ••"•""•

L D A # $ 7 F

ST A PADD

INC RATE

LD Y # $ 0 0

LD X # $ O B

LDA SQST,Y

ST A SAVE

BEQ OFF

AN D # $ 2 0

BEQ FLIC

BIT RATE

BVS OFF

LDA SAVE

AN D # $ 4 0

BNE ON

LD A RATE

A N D # $ 0 8

BEQ ON

LD A # $ 0 0

BEQ DIGT

LDA SEGS,YST Y SAVE

JSR CONVD+6

INYC P Y # $ 0 9

BEQ LAST

C PX #$11

BNE DIGX

BN E SEGY

OPEN DISPLAY CHANELS*

INDEX DIGIT

GET CONTROL BYTE

SAVE IT

OPEN SQUARE

BLINK FLAG

NO T ON - SKIP*BLINK

ALTERNATE ON-OFF

STE/DY FLAG

ON - SKIP FLICKER

FLICI R RATEON

OFF

SAVE FROM LOSS IN SUBR.

DISPLAY A SEGMENT

LAST SQUARE

YES - DONE

NO, LAST DIGIT?

YES - REPEAT DIGITS

NO - NEXT DIGIT

LAST R TS;"SUBROUTINE "RS ADD"•"'•'"''

RSA LD A SQST,X

OPEN

KIM

PLYR

ADD

STA TEMP

BIT TEMP

BMI KIM

BVS PLYR

LD A # $ 0 0BEQ ADD

LDA # $ 0 4

BNE ADD

L D A #$01

CLC

AD C RS,Y

STA RS,Y

RTS

WHO'S SQUARE?

KIM'S

P L A Y E R ' S

OPEN SQUARE VALUE

KIM VALUE

PLAYER VALUE

ADD TO ROW STATUS

BYTE

81

Page 83: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 83/178

03A6

03A9

03AC

03AE03B103B2

03B303B4

03B503B7

03B903BB

03BD03BF

03C1

03 C303C4

03C6

0 3C 7

20 4C

20 40

FO F8

20 6AM

60

D838

A9 04

65 D765 D8

85 D3A2 04

B5 D395 04

CA10 F9

60

EA

"""""SUBROUTINE "KEYS" ""——

03 BACK JSR DISPLAY 01

IF JSR ANYK UN

BEQ BACK A

IF JSR KEYS THTAX RE

RTS

""""-SUBROUTINE "RANDOM" "--"-

CLD

SEC GE

LDA R+l RA

AD C R+4 (T

ADC R+5STA R

LDX "$04

ROLL LDA R,X

STA R+1,X

DEXBPL ROLL

RTS

NOP

DISPLAY LOOPUNLESSA KEY IS PRESSED

THEN GET A NUMBERRECOVER THE FLAGS

GENERATES A..

RANDOM NUMBER

(THANKS TO d. BUTTERFIELD)

SUBROUTINE "PS LOAD"

03C803CA03CC03CE03000301

0303

030503D703DA03DC03DF03E203E503E803EB03EE03EF03F1

03F203F503F703F903FB03FD03FF

85A21616CA

DO

AO

A5D9DO

BE

20BE

20BE

2088DO

60

202905FO

C9BO

60

0909OBDB

F908

D9C812

1740IF

402740

E4

B3OE

B6F7OA

F3

00

01

010101

01

01

03

PSL

XLP

YLP

NOCT

STA TEMP

LDX "$09ASL PS,X

ASL PS,X

DEX

BNE XLP

LD Y -$08

LDA TEMPCM P RS,Y

BNE NOCT

LDX SQ1,Y

JSR T+l

LD X SQ2,Y

JSR T+l

LDX SQ3,Y

JS R T+l

DEY

BNE YLP

RTS

SUBROUTINE "RANDOM PLAYS"

SHIFT PREVIOUS DATA

OUT OF THE WAY

COUNT THE TIMES AN OPEN.

SQUARE FITS THE..

TEST PARAMETER

RPLA JSR RANDAND "$OEORA ODEVBEQ RPLA

CMP -$OA

BCS RPLARTS

GET RANDOM NUMBER0 - E (EVEN)

MAKE IT ODD IF 01

NO ZEROS

LOOP TILL DONE

82

Page 84: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 84/178

HEX DUMP - KIM TAG TOE;«

i s -

0 1 0 0 4C 10 03 EA EA EA A9 20 15 BF 95 BF 60 EA EA 08

0 1 1 0 08 08 40 40 40 01 01 01 01 04 07 01 02 03 01 03

0 1 2 0 02 05 08 04 05 06 05 05 03 06 09 07 08 09 09 070 1 3 0 85 D9 A2 09 A5 D9 35 DB 24 D9 DO 03 CA DO

0140 B5 BF DO 02 F6 DB 60 95 BF AO 08 A9 00 990 1 5 0 BE 17 01 20 8A 03 BE IF 01 20 8A 03 BE 27 01 200 1 6 0 8A 03 88 DO E6 60

0200 A9 00 A2 ID 95 B4 CA DO FB A9 05 85 BB AO 04 20

0 2 1 0 F2 03 A2 04 D5 BB FO F7 CA DO F9 99 BB 00 88 DO0220 EE E6 B6 AO 04 20 F2 03 A2 05 D5 B6 FO F7 CA DO'

0230 F9 99 B6 00 88 DO EE A9 03 AO 08 D9 C8 00 FO 05

0240 88 DO F8 FO 15 BE 17 01 20 06 01 BE IF 01 20 060250 01 BE 27 01 20 06 01 4C FE 02 A2 09 A9 CO 35 BF

0260 FO OE CA DO F7 A2 09 20 06 01 CA DO FA 4C 15 03

0270 E6 B5 A5 DB DO 17 20 A6 03 FO FB C9 OA BO F7 AA

0280 B4 BF DO F2 A9 40 20 47 01 E6 DB DO AA 20 4C 030290 E6 Dl DO F9 A9 08 20 C8 03 A9 02 20 C8 03 A9 04

02AO 20 C8 03 A9 01 20 C8 03 A9 CO 20 30 01 DO 43 A902BO 30 20 30 01 DO 3C A9 08 20 30 01 DO 35 20 B3 0302CO 29 OF C5 D2 BO IF A4 B5 CO 01 DO 04 29 01 D& 7

02DO CO 04 DO 06 24 C4 30 OD 70 07 A9 02 20 30 01 DO

02EO 11 AO 05 DO 02 AO 09 B6 B6 B5 BF FO 05 88 DO F702FO FO F3 A9 80 20 47 01 C6 DB A9 OC 4C 39 02 A5 DB

0300 DO 04 C6 D2 10 OF E6 D2 A9 10 C5 D2 90 F4 BO 05

0 3 1 0 A9 OC 85 D2 D8 20 A6 03 AO 01 C9 13 FO 28 88 C90320 12 FO 23 C9 14 DO EE A9 OD 85 FB A9 D5 85 FA A50330 D2 85 F9 20 IF IF 20 40 IF 20 6A IF C9 11 FO D5

0340 BO E5 85 D2 90 El 84 DB 4C 00 02 EA A9 7F 8D 41

0350 17 E6 DA AO 00 A2 OB B9 CO 00 85 FC FO 14 29 20

0360 FO 04 24 DA 70 OC A5 FC 29 40 DO OA A5 DA 29 080370 FO 04 A9 00 FO 03 B9 OF 01 84 FC 20 4E IF C8 CO

0380 09 FO 06 EO 11 FO CE DO CE 60 B5 BF 85 D9 24 D90390 30 06 70 08 A9 00 FO 06 A9 04 DO 02 A9 01 18 7903AO C8 00 99 C8 00 60 20 4C 03 20 40 IF FO F8 20 6A03BO IF AA 60 D8 38 A9 D4 65 D7 65 D8 85 D3 A2 04 B5

03CO D3 95 D4 CA 10 F9 60 EA 85 D9 A2 09 16 DB 16 DB03DO CA DO F9 AO 08 A5 D9 D9 C8 00 DO 12 BE 17 01 2003EO 40 01 BE IF 01 20 40 01 BE 27 01 20 40 01 88 DO

03FO E4 60 20 B3 03 29 OE 05 B6 FO F7 C9 OA BO F3 60X S S S B H S ZERO PAGE USAGE """""

OOB6 ODD/EVEN MODIFIER

O O C O - C 8 PRESTORED RANDOM PLAYS

OOC9-DO ROWS STATUSO O D 1 DELAY TIMER

O O D 2 I.Q.OOD3-D8 RANDOM NUMBER REGISTERS

OOD9 TEMPORARY STORAGEOODA FLICKER / BLINK RATE

OODB PLAY MODE

OODC-E4 PLAY STATUSOOFC SAVE

83

Page 85: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 85/178

Page 86: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 86/178

0210 B5 D5

0212 75 D70214 95 D50216 CA0217 330213 10 F60 2 1 A B5 D30 2 1 C 10 02021E A9 990220 75 D5

0222 95 D50224 CA

0225 10 E50227 A5 D50229 10 OD022B A9 00022D 35 E2

022F A2 02

0 2 3 1 95 D50233 95 DB0235 C A0236 10 F9

0233 330239 A5 EO023B E5 DD023D 35 EO023F A2 010241 B5 DE0243 E9 000245 95 DE0247 CA

0243 10 F7024A BO OC024C A9 00024E A2 030250 95 DD0252 CA0253 10 FB

0255 20 BD 020253 A5 DE

025A A6 DF025C 09 FO

025E A4 El

0260 FO 200262 FO 9C0264 FO A40266 A2 FE0263 AO 5A026A 13026B A5 D9026D 69 05026F A 5 D30271 69 00

DIGIT LDA ALT.XADC ALT+2.X add each digitSTA ALT.X

DEX

DEYBFL DIGIT next digitLDA ALT+3.X hi-order .. zero..BFL INCR . . or . .LDA #$99 ,

INCR ADC ALT.X %

STA ALT.XDEXBPL REGAL do next additionLDA ALTBPL UP still flying?LDA #0 nope, turn offSTA DOWN *LDX #2

DD STA ALT,XSTA TH2,X

DEXBPL DD V

UP SEC update fuelLDA FUEL+2

SBC THRUST

STA FUEL+2LDX #1 two more digits to go

LP2 LDA FUEL.X

SBC #%STA FUEL.X

DEX

BPL LP2BCS TANK still got fuel?LDA #0 nope, kill motorLDX #3

LF3 STA THRUST,X

DEXBPL LP3

; show alt,fuel, or messagesJSR THRSET

TANK LDA FUEL fuel into regstrsLDX FUEL+1ORA #$FO plus F flagLDY MODE

BEQ STGOLINK BEQ GOCLINK BEQ CALC

LDX #$FELDY #$5ACLCLDA VEL+1ADC #5LDA VELADC #0

Page 87: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 87/178

027302?502770279027A

027C027E02300232

02360233

023C023D023F

0291

02930295

029702930 2 9 B029E0 2 A O02A202A402A7

02A90 2 A B

02AD02AF02B102B302B502B6

02B702B902BB02BD02BD02BF

02CO

02C102C302C5

02C702C902CB

BOA2 ADAO DE93A4 E2

FO 04A5 05A6 D635 ?B

36 FA

A5 D9A6 D3

10 05

33A9 00E5 D9 -35 F9

A9 0235 E3D3

20 IF IF20 6A IF

C9 13FO COBO 0320tAD 02

C6 E3DO EDFO B7

C9 OA90 0549 OF35 El60AAA5 DDFO FA36 DD

A5 DD

33F3

E9 0535 DCA9 00E9 0035 DB60

BCS GOODLDX #$ADLDY #$DE

GOOD TYALDY DOWN

BEQ STLDA ALT

LDX ALT+1ST STA FOINTH

STX POINTL

; show rate of ascent/descnt as absoluteLDA VEL+1LDX VEL up or down?BPL FLY ..up, we're OKSECLDA #0 ,SBC VEL+1

FLY STA INH

LDA #2STA DECK

FLITE CLD display &*ey testJSR SCANDS light 'em up

loop twice thru display

02CC 45 01 0002CF 99 31 00

JSR GETKEYCMP #$13BEQ GOLINK

BCS NOKEYJSR DOKEY

NOKEY DEC DECK

BNE FLITEBEQ CLINK

; subroutine to test keysDOKEY CMP #$OA test numeric

BCCJKUMBEREOR F$OFSTA MODE

RETRN RTSNUMBER TAX

LDA THRUSTBEQ RETRNSTX THRUST

{Calculate accel as thrust minus 5THRSET LDA THRUST

SEC

SED

SBC #5STA TH2+1LDA #0SBC #0STA TH2RTS

; initial valu esINIT .BYTE $45,1,0 altitude

.BYTE $99,$31,0 rate of ascent

check keysGO key?

. .yes..if no key

to CALC

Fuel F gives 0 flag

test; is motor off?yes, ignore keyno, set thrust

86

Page 88: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 88/178

02D2 99 9702D4 0202D5 03 00 0002D8 0102D9 01

.BYTE $99,$9?

.BYTE 2

.BYTE 8,0,0

.BYTE 1

.BYTE 1

end

accelerationthrustfueldisplay modein flight/landed

OOD5OOD8OODBOODDOODE

OOE1OOE2

OOE3

A L TV ELT H 2T H R U S TF U E LM O D ED O W NDECK

*=*+3

*=*+2*=*+!*=*+3

*=*+!*=*+!*=*+!

; linkages to KIM monitorSGANDS =S1F1F

GETPCEY =$1F6A

POINTH =$FB %

POINTL = $FA «

INK =$F9 V

***** Hex Dump - Lunar Lander *****

0 2 0 0 A 20210 B 50 2 2 0 7 50 2 3 0 0 20 2 4 0 0 10 2 5 0 9 50 2 6 0 F O0 2 7 0 D80 2 8 0 A 60 2 9 0 D902AO F O

02BO 0502CO F 802DO 81

O D B D C C

D5 75 D7D5 95 D59 5 D 5 9 5B5 D E E9D D CA 10

2 0 FO5C

69 00 BDD6 85 FB8 5 F 9 A 9C O BO 03

49 O F 8 5E9 05 8500 99 97

02 9 595 D5CA 10D B C A

00 9 5F B 20

F O A 40 4 A 286 FA02 852 0 A DEl 60

D C A 90 2 08

D5 CA 10C A 88 10E5 A5 D510 F9 38D E CA 10B D 02 A 5

A2 FE AOAD AO DE

A 5 D 9 A 6E3 D8 2002 C6 E3A A A5 DD

00 E9 0000 00 01

F 8 A 2 0 5F6 B5 D810 OD A9A5 EO E5F 7 B O O C

D E A6 DF

5A 18 A59 8 A 4 E 2D8 10 05IF IF 20D O E D F O

FO FA 86

85 DB 6001

A O 0110 0200 85D D 85A 9 0009 FO

D 9 69F O 0438 A96A IF

B7 C9D D A 5

45 01

F8 18

A 9 99E 2 A 2E O A 2

A 2 0 3A 4 E l

0 5 A 5A5 D500 E5C9 13O A 90D D 38

00 9 9

A C K N O W L E D G E M E N T S : Ted Beach suggested the addition ofthe F flag w h e n displaying fuel. C h u c k Eaton spottedthe cause of an erratic bug in the original keyboardinput subroutine. Thanks to both.

87

Page 89: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 89/178

MULTI-MAZE BY JIM BUTTERFIELD

Description: Find your way out of the maze. You are theflashing light in the centre of the display. As you moveup (key 9) down (1), left (4) or right (6), KIM will keep

you in the central display; you'll see the walls of the mazemoving by as you travel. Like walk ing through a real maze,you'll only see a small part of the maze as you pass through.If you can get out, you'll find yourself in a large openarea; that means you've won. Press GO at any time fora new maze. Program starts at address 0200.

Listing:

0200

0202

0205

0207

0209020B

020D

0 2 1 0

0 2 1 3

0 2 1 6

0 2 1 90 2 1 A

024B

0 2 1 E

0 2 2 1

0224

0225

0227

0229

022A

022C

022F

0 2 3 10232

E6

20

DOA2

2690

BC

BD

59

99C8

C8

BD5999

CA

10

A2

D830BD

95

CA

10

DO40

F9

07

DO1708

10

DE

DE

18

DE

DE

E2

02

D4

DB

D2

F8

IF

03

0302

02

03

0202

02V

START

LP1

NXUP

SLINK

SETUP

0234 AO OB

0236 Bl D2

0238 99 D8 00

023B 88

023C 10 F8

023E A2 OA0240 A4 D4

0242 A9 FF

0244 38

0245 36 D9

0247 36 D8

0249 2A

024A 88

024B DO F7

INC RND

JSR KEYIN

BNE START

LDX #7

ROL RNDBCC NXUP

LDY PLACE,X

LDA POINT1,X

EOR MAZE,Y

STA MAZE,Y

random seed

patch the maze

in 8 places

; pickMAPGETMOR

; shift

NXDIG

RE OL

INY

LDA POINT2,X

EOR MAZE,Y

STA MAZE,Y

DEX

BPL LP1

LDX #2

CLD

BMI START

LDA INIT,X

STA MZPT,X

DEX

BPL SETUP

out specificL DY #11L D A ( M Z P T ) ,Y

S T A W O R K , YDE YB P L G E T M O R

for vertical

L DX # 10L DY POSITL D A #$FFSEC

R O L W O R K + 1 , XR O L W O R K , XR O L ADE YB N E R E R O L

3 values from INIT

part of maze

6 rows x 2

positionfor each of 6 rows..shift Y positionsfilling with 'walls'. . . o n both sides

roll 'em

88

Page 90: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 90/178

024D 29 07024F A8

0250 B9 C6 02

0253 95 D80255 CA

0256 CA0257 10 E7

0259 C6 D5025B 10 OA025D A9 05

025F 85 D50261 A5 DE

0263 49 400265 85 DE

0267 A90269 8D

026C AO026E A2

0270 B5

0272 8D

0275 8C

0278 C6

027A DO027C C8027D1C8

027E CA

027F CA

0280 10

7F

41 17

09OA

D8

40 17

42 17

D6FC

EE

0282 20 40 IF0285 20 6A IF

0288 C5 D7

028A FO CD

028C 85 D7

02A8 CA

02A9 10 04

02AB C6 D4

02AD DO 85

; calculate segmentsAND #7

TAY

LDA TAB1,Y

STA WORK,X

DEX

DEXBPL NXDIG

; test flasherLIGHT DEC PLUG

BPL MUG

LDA #5

STA PLUG

LDA WORK+6

EOR #$40

STA WORK+6

; light display

3 bits to segment..stored

time out?..no..yes, reset

..and....flip....flasher

open the gateUG LDA #$7F

STA SADD

LDY #$09LDX #10

SHOW LDA WORK,X

STA SAD

.STY" S$D

STl DEC STALL

BNE STl

IN¥INT

DEX

DEX

BPL SHOW

; test new key depression

tiptoe thru....the segments

..pausing

set dir reg

same as last?

028E

0290

02930295

0296

0298

029A029B029D

02AO

02A3

02A6

A2

DD

FOCA

10

30

CA30

BCB9

3D

DO

04

CE

05

F8

BC

8D

D3D8

D7

Bl

»

02

02

00

02

, ueo

SCAN

FOUND

JSR KEYIN

JSR GETKEY

CMP SOK

BEQ LIGHT

STA SOK

test which keyLDX #4 5 items in tableCMP TAB2,X

BEQ FOUND

DEX

BPL SCAN

BMI LIGHT

DEXBMI SLINK

LDY TAB3,X

LDA WORK,Y

AND TAB4,X

BNE LIGHT

go key?

move

MLINK

DEX

BPL NOTUP

DEC POSIT

BNE MAP

89

upward movel.o.n.g branch

Page 91: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 91/178

02AF

02B1

02B3

02B5

02B6

02B8

02BA02BC

02BE

02CO

02C2

02C4

02C6

02CE02D302D7

02DB

02DE

D0*04

E6 D4

DO F8

CADO 06

C6 D2

C6 D2DO EF

E6 D2

E6 D2

DO E9

FO F2

TAB1

TAB 

TABS

TAB4

INIT

MAZE

0308 PLACE0310 POINT1

0318 POINT2

NOTUP BNE SIDEWY

INC POSIT downward moveBNE MLINK

SIDEWY DEX

BNE LEFT

RIGHT DEC MZPT right move

DEC MZPTBNE MLINK

LEFT INC MZPT left move

INC MZPT

BNE MLINK

BEQ RIGHT

; tables follow in Hex format00 08 40 48 01 09 41 49

13 09 01 06 0406 06 04 0801 08 40 40

DA 02 08

FF FF 04 00 F5 7F 15 00 41 FE 5F 04 51 7D 5D 04

51 B6 54 14 F7 D5 04 54 7F 5E 01 00 FD FF 00 00

00 00 00 00 00 00 00 00,00 00

05 OB la 10 14 18 17 1001 04 80 10 80 02 40 4002 02 40 01 10 04 80 10

; end of program

***** Hex D^hnp - Multimaze *****

0200

0210022002300240

0250

026002700280

"029002AO02BO

02CO02DO

02EO02FO

0 \E6 DO

BD 1002 99D2 CAA4 D4

B9 C6

D5 A5B5 D80 EE

CEB9 D804 E6E6 D201 06.

04 0054 14

.20. 40 IF

03 59 DEDE 02 CA

10 F8 AOA9 FF 3802 95 D8

DE 49 408D 40 1720 40 IF

02 FT

00 3J

D4 DO F8

DO E9 FO

04 06 06

F5 7F 15F7 D5 04

05D7

DO F9

02 9910 E2OB Bl

36 D9CA CA

85 DE8C 4220 6ACA 1.0

02 DOCA DO

F2 0004 08

00 4154 7F

~ > 9A2 07

DE 02A2 02

D2 9936 D810 E7

A9 7F

17 C6IF C5

F8 30Bl CA

06 C6

08 4001 08

FE 5F5E 01

ft tf>

26 DO

C8 C8D8 30D8 00

2A 88

C6 D58D 41

D6 DO

D7 FOBC CA

TIT 04

D2 C6

48 01

40 40

04 5100 FD

, c90 17

BD 18D4 BD

88 10DO F710 OA

17 AOFC C8CD 8530 8DC6 D4D2 DO

09 41DA 02

7D 5DFF 00

BC 08J3

03 59 DEDB 02 95F8 A2 OA29 07 A8A9 05 8509 A2 OAC8 CA CA

D7 A2 04BC D3 02DO 85 DOEF E6 D2

49 13. 0908 FF FF

04 51 B600 00 00

0300 00 00 00 00 00 00 00 Ob 05 OB 10 10 14 18 17 100310 01 04 80 10 80 02 40 40 02 02 40 01 10 04 80 10

90

Page 92: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 92/178

MUSIC BOX JI M BUTTERFIELD

DESCRIPTION

THIS PROGRAM PLAYS ONE OR SEVERAL TUNES VIA THE "AUDIO O U T "

INTERFACE OF KIM-1. USE THE SAME CONNECTION AS THAT FOR

RECORDING ON CASSETTE TAPE. IF YOUR TAPE RECORDER HAS

A "MONITOR" FEATURE, YOU CAN LISTEN TO THE TUNE AS WELLAS RECORD IT. ALTERNATIVELY, AN AMPLIFIER WILL PLAY THE

SIGNAL THROUGH A SPEAKER.

HOW TO RUN

LOAD THE PROGRAM. LOAD THE TUNECS) EITHER FROM CASSETTE

TAPE, PAPER TAPE, OR KEYBOARD ENTRY. BE SURE TO STORE

THE VALUE FA AT THE END OF EACH TUNE, AND BEHIND THE LAST

T U N E , S T O R E : FF oo .STARTING ADDRESS FOR THE PROGRAM IS 200.ENTER AD 0 2 0 0 GO

HOW TO WRJTE. YOUR OWN TUNE(S)

"-i

EACH NOTE GOES INTO A BYTE OF STORAGE, STARTING AT LOCATION

0000 OF MEMORY. EACH TUNE SHOULD END WITH THE VALUE FAWHICH STOPS THE PROGRAM UNTIL GO IS PRESSED.

SPECfKL CODES ARE I NCORPORATED IN*THE PROGRAM TO ALLOW

CERTAIN EFFECTS - ADJUSTMENT OF SPEED, TONE, ETC.

THE CODES ARE FOLLOWED BY A VALUE WHICH SETS THE

PARTICULAR EFFECT. CODES ARE LISTED BELOW.

CODE EFFECT **

FB SETS SPEED OF TUNE

FC SETS LENGTH OF"LONG" NOTES

> F D SETS OCTAVE (PITCH)

FE SETS INSTRUMENTFF SETS ADDRESS FOR

TUNE

INITIALLY EXAMPLES

$30 18 IS QUICK; 60 IS SLOW

02 2 MEANS, "LONG NOTE LASTSTWICE AS LONG AS SHORT"

01 2 IS BASS; 4 IS DEEP BASS.

$FF FF IS PIANO; 00 IS CLARINET.00 00 WILL TAKE YOU BACK TO

FIRST TUNE; LIKE A "JUMP".

FOR EXAMPLE, AT ANY TIME DURING A TUNE, YOU MAY INSERTTHE SEQUENCE FB 18 AND THE TUNE WILL THEN BEGIN TO PLAY

AT FAST SPEED. INSERTING FF 45 WILL CAUSE A SWITCH TO

THE TUNE AT ADDRESS 45. THE INITIAL VALUES SHOWN CANBE RESET AT W? TIME BY STARTING AT ADDRESS 200.

NO TUNE SHOULD EXTEND BEYOND ADDRESS DF, SINCE PROGRAM

VALUES ARE STORED AT EO AND UP.

THE PROGRAM CAN BE EASILY CONVERTED TO A SUBROUTINE

(BY REPLACING THE BRK INSTRUCTION WI TH A RTS). THIS ALLOWSTHE PROGRAMMER TO PLAY VARIOUS "PHRASES" OF MUSIC TO

PRODUCE QUITE COMPLEX TUNES.

91

Page 93: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 93/178

THE LOWEST NOTE YOU CAN PLAY IS A BELOW MIDDLE C. FOR EACH NOTE,

YOU CAN SELECT WHETHER IT IS PLAYED AS A LONG NOTE OR A SHORT NOTE(NORMALLY, A LONG NOTE WILL LAST TWICE AS LONG AS A SHORT NOTE).

SOME OF THE NOTES ARE AS FOLLOWS:

NOTE SHORT LONG

A..................75A# 6EB..................68

MIDDLE C 62

Cfl.................5C

D 56D#.................52

E 4DF..................48

F# 44G..................40

G# 3C

A..................39A# 35

B..................32HIGH C 2F

C#.................2CD 29

.................24

, 2 2G..................1E

PAUSE 00

F5EE

E8

E2DC

D6

D2

CD

C8

C4COBC

B9

,B5

B2AFAC

A9A4A2

9E80

INITIALIZE - RESET WORK PARAMETERS

02000202

0205

02070208

A2 05BD 86 02

95 EOCA10 F8

STARTLP1 LDA INIT,X

STA WORK,XDEX

BPL LP1

ROUTINE HERE - WORK NOT RESET

020A

020C020F

02110213

0 215

0 2 1 7

0 2 1 9

021A0 2 1 B

02 D

0 2 1 F

0221

A9 BF

8D 43AO 00

Bl E4E6 E4

C9 FADO 04

00EA

FO ED

90 OB

E9 FBAA

17

GO

NEXT

LDA #$BF

STA PBDDLDY #$00

LDA CWORK+4),Y GET NEXT NOTEINC WORK+4

CMP #$FABNE NEXT

BRK

NOPBEQ GOBCC NOTESBC #$FB

OPEN OUTPUT CHANNEL

TEST FOR HALT

COR RTS IF USED AS SUBR.)

TAX

RESUME WHEN GO PRESSEDIS IT A NOTE?IF NOT, ECODE INSTR.AND PUT INTO X

92

Page 94: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 94/178

0222 Bl E40224 E6 E4

0226 95 EO0228 BO EO

LDA (WORK+4),Y get parameterINC WORK+4STA WORK,X store in work tableBCS GO unconditional branch

set up for timing notetiming

long note factortest accumulatorlong note?nopei set short notestore length factorremove short/long flag

is it a pause?no, set pitch

get timing and..bypass if muted

else fade thenote

bit 7 ondelay half cycle

bit 7 offdelay the other halfend of note?

no, more cycles

octave flag

bit timingend of timing?no, continuerestore timingin case of....another octaveelse exit

022A A6 EO

022C 86 E7022E A6 El

0230 A8

0231 30 020233 A2 010235 86 E60237 29 7F0239 85 E9023B FO 02023D 85 EA

023F A5 E90241 25 E3024-3 FO 04

0245 E6 EA

0247 06 E9

0249 A6 E9024B 9A7024D 20 5D 020250 30 B80252 A6 EA0254 A9 27

0256 20 5D 020259 30 AF

025B 10 E2

025D A4 E2025F 84 EB

0261 86 EC

0263 EO 000265 DO 080267 A^ EC0269 C6 EB026B DO F6

026D FO 16026F 8D 42 17

0272 CA0273 C6 E80275 DO EC0277 C6 E70279 DO E8027B A4 EO027D 84 E7027F C6 E6

NOTE LDX WORKSTX LIMIT+1LDX WORK+1TAYBMI OVERLDX #1

OVER STX LIMITAND #$7FSTA VAL2BEQ HUSHSTA VAL1

HUSH LDA VAL2AND WORK+3BEQ ONINC VAL1

DEC VAL2

ON LDX VAL2

LDA #$A7JSR SOUNDBMI GOLDX VAL1LDA #$27JSR SOUNDBMI GO

*£PL HUSH

; subroutine to se:

SOUND LDY WORK+2STY TIMERSTX XSAV

SLOOP CPX #0BNE CONTLDX XSAVDEC TIMERBNE SLOOPBEQ SEX

CONT STA SBD

DEXDEC LIMIT+2BNE SLOOPDEC LIMIT+1BNE SLOOPLDY WORKSTY LIMIT+1

DEC LIMIT

93

Page 95: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 95/178

0281 D O f O0283 A 9 F F0285 60

0286 30 02 01

F F 00 00

B N E SLOOPL DA #$FF

S E X R T S; I N I T I A L C O N S T A N T SINIT . B Y T E $30,2 /1,$FF/0,0

SAMPLE MUSIC FO R MUSIC BO X PROGRAM

0 0 0 0 F B 1 8 F E F F 4 4 51 E6 E6 66 5A 51 4C C4 C4 C4 Dl0010 BD BD BD 00 44 BD 00 44 3D 36 33 2D A 8 80 80 33002 0 44 B3 80 80 44 51 C4 80 80 5A 51 E6 80 80 FA

0020 FE0030 00 FB 28 5A 5A 51 48 5A 48 Dl 5A 5A 51 48 DA EO

0040 5A 5A 51 48 44 48 51 5A 60 79 6C 60 DA DA FA

0040 FE

0050 FF 5A 5A 5A 5A 5A 5A 66 72 79 E6 E6 80 00 56 560060 56 56 56 56 5A 66 F2 80 80 4C 4B 4C 4C 4C 4C 560070 5A 56 4C 00 C4 44 4C 56 5A 5A 56 5A 66 56 5A 660080 F2 80 FE 00 00 72 5A CC 72 5A CC 72 5A CC 80 B80090 80 4C 56 5A 56 5A E6 F2 80 FA FF 00

NOTE THAT TUNES 1 AND 2 SET BOTHTHE SPEED AND THE INSTRUMENT.

TUNE 3 CONTINUES AT THE SAME SPEED AS THE PREVIOUS ONE;BUT THE

INSTRUMENT IS CHANGED DURING THE TUNE.

THE PROGRAM CAN BE CHANGED TO USE THE SPEAKER SHOWN IN

FIGURE 5.1 OF THE KIM MANUAL AS FOLLOWS:

BYTE INITIALLY CHANGE TO

020D 43 01

024C A7 FF0255 27 00

0270 42 00

***** Extra Datafile for Music Box *****

0000-

0010-

0020-

0030-

0040-

0050-

0060-0070-

FE

2F

56

44

4D

A4

2FFF

00

29

52

39

AF

32

2900

56

26

4D

2F

4D

A9

A4

52

24

AF

A4

FC

AF

2F

4D

£F

4D

29

06

80

29

AF

29

AF

2F

AF

80

2F

4D

A4

4D

39

FC

2F

24

AF

32

FC

A9

02

29

2F

4D

A9

06

80

FE

24

29

FC

FC

AF

80

FF

2F

A4

06

06

FC

FE

2F

29

32

AF

AF

02

00

29

A4

A9

FC

FC

FE

56

26

2F

AF

02

02FF

52

24

29

80

FE FF

FE 00

39 40

4D AF

2F 29

2F 24

80 FA

Note: be sure to set the break vector 1 7 F E , F F ( 0 0 , 1 C )

9 4

Page 96: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 96/178

PING PONG JIM BUTTERFIELD

Play against the computer, orchange the program for a two-playergame. On each shot, you choosebetween four plays: Spin, Lob,Block, or Slam. If you're playingthe left side of the court, use theleft-hand buttons (0, 4, 8 and C).See the diagram at right.

C slam F

8 block B

4 lob 7

0 spin 3

Each shot has its own strengths and weaknesses: forexample, a Slam is a powerful shot, but it's also likelyto be "fluffed". Strategy is not trivial - your chancesof success on any play depend not only on your choice of

shot, but on what shots have gone before. You'll have tolearn the combinations the hard way.

see the net in the middle of the court. Don't tryto play th e ball until it is on your side of the net, oryou'll lose th e point. Each type of shot has adistinctive appearance, which you'll learn to recognize.TF^py are similar to the key positions: a Spin lights thebottom segment, a Lob lights the middle segment, a Blocklights the upper segment, and the mighty Slam shot lightsal l three segments and travels faster.

Th e original version of the game was published for theHP-67 calculatornot given.

in "65 Notes", V4N2P5. Authorship was

At first, the shots will come too fast for you to copewith. There are two ways to solve this. The easy way isthe "freeze" the ball by holding down any unused key,like AD or 7: play will be suspended until you figureout what you want to do next. The harder way, but nottoo hard, is just to slow down the ball by changing theprogram: locations 0331 to 0334 contain the speeds foreach type of shot. Increase these values and the ballwill slow down, e.g., 40 40 40 28 will halve the speed.

For a two-player game, where KIM does not play the rightside, change location 032C to 01. To have KIM play theleft side, change location 032B to 00.KIM plays a strong game, but CAN BE BEATEN!

95

Page 97: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 97/178

0200 20 40

0203 20 6A0206 C9 130208 DO OA

020A A2 08020C BD 24

020F 95 800211 CA

0212 10 F8

0214021602180219021B021D021F

022102230224

02260228

0229022B

022D

022F02300232

C9 10BO 22AA29 03FO 04C9 03DO 19

45 85A8

29 04DO 128A45 8429 02FO OB9829 02DO 69

0234 8A

0235 4A 4A0237 20 Bl

023A

023D023F

02410243

0245

0247

0248024A024C

024E0250

20 40DO 27C6 8310 23A5 8085 8318A5 8565 8485 85

29 04FO 14

IF START JSR KEYIN directional registrsIF JSR GETKEY input key

CMP |$13 GO key?BNE NOGO nope, skip

; GO k ey - set up game here

LDX #8 get 9 ..03 SETUP LDA INIT,X

STA SPEED,X

DEX

BPL SETUP

; test legal keys (0,3,4,7,8,B,C,F)

..inital valusto zero page

NOGO CMP #$10BCS NOKEY

TAX

AND #3

» BEQ KEYCMP #3

BNE NOKEY

KEY EOR PLACETAY

AND #4

BNE NOKEY

TXA

EOR DIRECT

AND #2

BEQ NOKEY

TYA

AND #2

BNE POINT

; legal play found hereTXA restore key

LSRA LSRA type (0=Spin02 JSR SHOT make shot

; key rtns complete - play ball

key 0 to F?no, skipsave key in Xtest columncol 0 (0,4,8,C)?

col 3 (3,7,B,F)?neither - skip

check vs ball postn

ball off screen?

restore keyball going away?

yes, ignore keyball positionwrong side of net?yes, lose!

etc)

IF NOKEY i f key still prest..freeze ball

wait til timeout

move...ball

0252 A5 850254 30 040256 A5 880258 10 02025A A5 87025C DO 3F

JSR KEYIN

BNE FREEZE

DEC PAUSE

BPL FREEZE

LDA SPEED

STA PAUSE

CLC

LDA PLACE

ADC DIRECT

STA PLACE

AND #4BEQ FREEZE

ball outside - KIM to play?LDA PLACE

BMI TESTL

LDA PRITE

BPL SKPTLDA PLEFT

BNE POINTTESTL

SKPT

ball still..in court?

ball on leftKIM plays right?unconditionalKIM plays left?no, lose point

96

Page 98: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 98/178

025E A6 82

0260 BD 39

0263 20 Bl0266 A9 7F

0268 8D 41

KIM plays either side here

026B026D026F02710273027502770279027B

027D

027E

0281

Q2810286

0288028A028C028F

02910293029502980299029B

AO 13A2 01

86 89A5 864A 4A4A 4A85 8AA5 86

29 OFAABD E7

20 A4A6 8A

C6 8910 F4A2 03BD 2DE4 85

DO 0205 8120 A4CA10 Fl

30 03

log determines....KIM's playmake the shot

open registers

count score digts

shift & store... .left player score

..right player score

029D 20 E9

02AO D802A1 4C 00

02A4

02A7

02AA02 AC

02AE

02BO

02B102B2

02B402B6

02B802BA02BC

02BE

02BF

02C1

02C3

8D 408C 42C6 8BDO FC88 8860

A8

A6 82

06 8206 8205 8229 OF85 8238A5 80E5 83

85 83

LDX LOG03 LDA PLAY,X

02 JSR SHOT

FREEZE LDA #$7F

17 STA PADD

; l ig h t display hereLDY #$13LDX #1STX DIGIT

LDA SCORE

LSRA LSRA

LSRA LSRA

STA ARC

LDA SCORE

AND #$OFTAX

IF HOO^ LDA TABLE,X

02 JSR SHOW

LDA ARC

DEC DIGIT

BPL HOOP

LDX #303 VUE LDA PIX,X

CPX PLACE

BNE NOPIX'ORASPOT02 NOPIX JSR SHOW

DEXBPL VUE

BMI SLINK

; lose! score &.reverse board02 POINT JSR SKORE

SLINK CLD

02 JMP START return to main loop; display subroutine

17 SHOW STA SAD

17 STY SBD

STALL DEC MOD

BNE STALL

DEY DEY

RTS

SHOT TAY

LDX LOG

ASL LOGASL LOG

ORA LOG

AND #$F

STA LOG

SEC

LDA SPEED

SBC PAUSE

show the ball

save shot in Yold log in X

update log book..last two shots

STA PAUSE

invert timing

97

Page 99: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 99/178

02C5 B902C8 8502CA B9

02CD 85

02CF BD02D2 88

02D3 3002D5 4A02D7 10

02D9 29

02DB OA02DC 85

02DE AD

02E1 2902E3 C5

02E5 FO02E7 90y

02E9 A2

02EB A5

02ED OA02EF OA02F1 10

02F3 A2

02F5 A9

02F7 86

02F9 18

02FA 65

02FC 85

02FE AO0300 AA

0301 290303 C90305 DO0307 84

0309 8A030A 4A

030C 4A030E DO

0310 A2

0312 BD

0315 950317 CA

0318 10

031A A5031C 18

031D 49031F 69

31803581

49

044AF903

8C04

078C

33

31

0484OAOA04FF

01

85

8686

00

OFOB0284

4A4AFO

0324

80

F8

84

FF

01

03

03

; test

03GIT

GET

17

; loseSKORE

\

OVER

TLP

SKI

; set

03 SRV

; reveREVRS

odds from log bk

unconditionalodds 0 to 3..now 0 to 6

random numbernow 0 to 7

position ball L

0321 85 840323 60

set speed & display segment(s)LDA SPD,Y

STA SPEED

LDA SEG,Y

STA SPOT

test play success - randomLDA CHANCE,XDEY

BMI GET

LSRA LSRA

BPL GIT

AND #3

ASL A

STA TEMP

LDA TIMER

AND #7

CMP TEMP

BEQ REVRS success?

BCCREVRS success?a point & position

LDX #4 position ball RLDA DIRECT

ASLA ASLA

ASLA ASLA

BPL OVER

LDX #$FF

LDA #1

STX PLACE

CLC

ADC SCORE

STA SCORE

LDY #0TAX

AND #$F

CMP #$11

BNE SKI

STY DIRECT

TXA

LSRA LSRA

LSRA LSRA

BNE TLP

serve - speed, spot, log, pauseLDX #3LDA INIT,X

STA SPEED,XDEX

BPL SERVE

reverse ball directionLDA DIRECT

CLC

EOR #$FF

ADC #1

STA DIRECT

RTS

end game, kill ball

get one score11 points?

kill ball

98

Page 100: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 100/178

0324 INIT032D FIX0331 SPD

0335 SEG

0339 PLAY

0349 CHANCE

0359 end

Zero Page:

; tables - in Hexadecimal format30 08 00 80 01 FF 00 01 0000 06 30 0020 20 20 1408 40 01 4902 02 01 02 01 03 01 02 03 03 00 02 00 00 02 0278 B5 9E 76 6E Al AE 75 AA EB 8F 75 5B 56 7A 35

80:81;82;83;84;85;86:

SPEED

SPOT -

LOG -

PAUSE

DIRECT

PLACE

SCORE

87: .PLEFT

8 8: S P R I T E

- speed ball travelssegment(s) ball lights

record of recent plays- delay before ball moves- direction of ball

- position of ball

- 0 for KIM to play left- 0 for KIM to play right

***** Hex D u m p - Ping P o n g *****

02000210

0220

02300240

025002600270

0280029002AO

02BO

02CO

02DO

02EO

02FO

20 40 IF

80 CA 10

19 45 8529 02 DO

83 10 23

FO 14 A5BD 39 03

89 A5 86I F 20 A4

85 DO 02

D8 4C 0060 A8 A6

80 E5 8349 03 88

17 29 07OA 10 04

20 6AF8 C9

A8 2969 8A

A5 80

85 3020 Bl4A 4A

02 A6

05 8102 8D

82 06

85 8330 04C5 8C

A2 FF

IF C9 13

10 BO 22

04 DO 12

4A 4A 20

85 83 18

04 A5 8802 A9 7F4A 4A 85

8A C6 89

20 A4 0240 17 8C82 06 82

B9 31 034A 4A 10

F O 33 90

A9 01 86

DO OA A2

AA 29 03

8A 45 84

B l 02 20

A5 85 65

10 02 A58D 41 178A A5 86

10 F4 A2

CA 10 Fl

42 17 C6

05 82 29

85 80 B9F9 29 033 1 A2 04

85 18 65

08 BD 24

FO 04 C9

29 02 FO40 I F DO

84 85 85

87 DO 3FAO 13 A229 OF AA

03 BD 2D

30 03 20

8B DO FC

OF 85 82

35 03 85OA 85 8CA5 84 OA

86 85 86

03 9503 DOOB 98

27 C6

29 04

A6 8201 86BD E703 E4

E9 0288 88

38 A581 BD

AD 04OA OA

AO 00

0 3 0 0 A A 29 OF C9 O B D O 02 84 84 8A 4A 4 A 4 A 4 A D O ' F O

0310 A 2 03 BD 24 03 95 80 CA 10 F8 A 5 84 18 49 FF 690 3 2 0 01 85 84 60 30 CO 00 80 01 F F 00 01 00 00 06 300 3 3 0 0 0 2 0 2 0 2 0 1 4 0 8 4 0 0 1 4 9 0 2 0 2 0 1 0 2 0 1 0 3 0 10 3 4 0 0 2 0 3 0 3 0 0 0 2 0 0 0 0 0 2 0 2 78 B 5 9 E 76 6E A l A E0 3 5 0 75 AA EB 8 F 75 5B 56 7A 35

99

Page 101: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 101/178

QUICK B y Peter JenningsModified by Jim Rutterfield

f t

Description -Here's a program to test your speed of reaction. Press

" G O " and the display will blank for a r a n d o m period of time.When it lights, hit any numbered button. The n u m b e r on thedisplay will tell you how quick you were; the smaller then u m b e r , the faster your reaction time. You may play repeatedly,just press " G O " each time you want a new test.

0300

0302

0303030503070309030C030E03100312

031

03160318031 A

031B

*031C031E0320

0322

0323

03250326

0329032B032E

033103330335

0300-

0310-0320-

0330-

A5 F9

2A

65 F929 7F

85 FB20 40 IF

DO FBE6 FA

DO F7E6 FB

DO F3

85 F9A2 FDF8

38

B5 FC69 0095 FCE8

DO F7

D8

20 IF IFFO ED

20 IF IF20 6A IF

C9 13DO F6FO C9

t ) i :A5 F9 2

D0 F7 E

95 FC E

I F C9 1

START

Z I P

RUN

D I G I T

STAND

LDA INH

RO L A

ADC INHAN D #$7F

RANDOMIZE DELAY

..BY MULTIPLYING

BY 3 ANDMASKING

COUNT DOWN FOR

RANDOM DELAY

SET TO ZERO

NEGATIVE THREE

COUNT IN DECIMAL

AD D VALUE 1

STA POINTH WORK rW DISPLAY AREA

JSR KEYIN IF YOU CHEAT BY KEYING...

BNE ZIP PROGRAM WAITS YOU OUT

I N C P O I N T L

B N E ZI PIN C P O I N T H

B N E Z IP

S T A I N HLD X

SED

SEC

L DA P O I N T H + 1 , XA DC # $ 0 0 A D D I T I NS T A P O I N T H + 1 , XIN X M O V E O N T O N E X T D I G I T SBN E D I G I T

CLD

JSR SCANDS LIGHT UP COUNT

BEQ RUN AND KEEP COUNTING

JSR SCANDSJSR GETKEY

CMP #$13 GO KEY DEPRESSED?BNE STAND NOPE, HOLD IT

BEQ START YUP, START OVER

***** Hex Dump - Quick *****

A5 F9 2A 65 F9 29 7F 85 FE 20 40 I F D0 Ft E6 FA

D0 F7 E6 FE D0 F3 85 F9 A2 FD F8 38 B5 FC 69 00

95 FC E8 D0 F7 D8 20 IF 1F F0 EL 20 I F I F 20 6A

100

Page 102: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 102/178

By JIB Butterfield

Start at 0200 - the display will show a combination of 6 letterssuch as CDBAEF. Hit a n u m b e r f r om 2 to six to 'flip' letters.

For example, if you hit 2 with the previous example, the first

tw o letters will flip over to give DC BA E F . Now if you hit 4,you'll get the winning combination - A B C D E F - and the displaywill signal your win with a line of dashes.

T he computer won't limit your num b e r of flips - but try toget a win in 6 m o v es or less. By the w a y , the c o m p u t e r forbidsdoing the same flip twice in succession - so you can't back up a m o v e .

randomize

**Gane by Bob Albrecht -People's C o m p u t e r C o * *

set window to zeros

hash in new random number

0200 E6 16 S T A R T0202 20 40 IF0205 D O F 9020? D8

0208 A2 05

020A A 9 0 0020C 86 10020E 95 18 Z L O O P

0 2 1 0 CA0211 10 FB

0 2 1 3 38 R A N D

0214 A5 130 2 1 6 65 160218 65 17023A 85 120 2 1 C A2 040 2 1 E B5 12 R L P

0220 95 13

"* 0222 CA0223 10 F9

0225 A O C O0227 84 110229 A O 0 6022B C5 11 SET

022D 90 02022F E5 110 2 3 1 46 11 P A S S0233 880234 D O F 50236 A A

0237 A4 100239 B9 Fl IF023C C A T O P023D 10 02

023F A 2 050 2 4 1 B4 18 TRY0243 D O F 70245 95 180247 C6 100249 10 C 8

IN C R N D + 4 rJS R KE YI NBN E S T A R T

CL D

L DX £5

L D A *0S T X P O I N T RS T A W I N D O W , X

DEXBP L ZLOCPS ECL D A RND+1 hA D C R N D + 4

A D C R N D +5S T A R N D

L D X 44L D A R N D . X r a

S T A R N D + l . X

DEXB P L R L P

L DY *$COS T Y M O DL DY #6

C M P M O D

BCC PAS SS B C M O D

L S R M O D

DEYBN E S ETT A X

L EY P OIN TRLDA TA BLE+ 10.YDEXBP L TR YLDX 45L D Y W IN D O W , *B N E T O PS T A W I N D O W , XDEC P O I N T RBPL R A N D

move random string down o ne

divide random 4 by 6

digits A to F

find an e m p ty window

an d put the digit in

101

Page 103: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 103/178

0 2 U B F O B 3 S L I N K024D A 2 05 WTEST02*JF B5 18 T E S T 20251 D D A 6 0 20254 DO O C

0256 CA0257 10 F60259 A 2 05025 B A9 40025D 95 18 SET

025F CA0260 10 FB0262 A 9 7F P L A Y0264. 8D to 1?0267 A O 0 90269 A 2 F A026B B 5 IE S H O W

026D 8D 40 1?

0270 8C 42 170273 C6 11 ST10275 D O F C0277 C 80278 C 80279 E8027A 30 EF027C 20 40 1?027F 20 6A IF

0282 C9 130284 F O C 50286 C9 07

0288 B O C 3

028A A A028B F O D 5028P CA028E FO D2 ^0290 E4 100292 F O C E0294 86 100296 B5 18 TOPI

0298 480299 CA029A 10 FA029C A 6 10029E 68 TOP2

029F 95 1802A1 CA0 2 A 2 1 0 F A0 2 A 4 30 B C

0 2 A 6 F 7 F C B 9 WINNER0 2 A 9 DE F9 Fl

; end

BEQ S T A R T

LDX #5L D A WINDOW ,X

C M P W I N N E R , X

B N E PLAY

D E XBP L T E S T 2L DX #5IDA #$40S T A W I N D O W .X

BP L SET

L D A #$7FST A SADD

L DY 4$09L DX #3FAL DA WINDOW.XSTA SAD

ST Y SH)DEC M DBN E S T 1I N Y

IN YIN XBPL S H O W

JS R K E Y I N

JS R G E T K E Y

CF J5£$13

BH J S L I N KC M P -*7BCS WTEST

T A XB E Q P L A Y *

DEXBEQ P L A YC P X P O I N T R95Q PL A YST X P O I N T RL D A WINDOW.XP H A

DEXBP L T O P ILDX P O I N T RPL A

S T A WINDOW.XDEXBP L T O P 2B M I P L A Y. B YT E $F7,$FC

link to starttest

wincondition

,

set

toIt N

directionalregisters

negative 5light

display

W

00 key?yes, restart

K e y s 0 to 6?no, test win

Keys 1 to 6?no, exit

K ey s 2 to 6 (=1 to 5)?no, exit

Sane key as before?yes, ignoreno, we've got a live one

rollf e m out...

roll 'era back in

,$B9,$DE,$F9,$F1

102

Page 104: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 104/178

TEASER B y L ew E d w a r d s

Description -This p r o g r a m is an adaptation of the "Shooting Stars"

game utilizing the keyboard and display of the K I M - 1 .Originally published in the Sept. '7 4 issue of_PCC_, a

version also appeared in the May '7 6 issue of Byte magazine.The starfield is displayed on the horizontal segments

o f the second through f o u r t h digits of the display. Thesegments represent stars when lit and are numbered as follows:Shooting a star creates a hole where th e star 7 8 9w a s . The resulting "explosion" changes the 4 5 6condition of certain adjacent stars or holes, 1 2 3(stars to holes, or holes to stars) according to the following:

< 4 » • Sides (2,8) • » or (4,6)enter (5)

Comers (1 )

T he game starts with a star in position 5; the restare holes. The object of the game is to reverse the initialcondition, m a k i n g 5 a hole and all the rest stars. E l e v e nmoves are the m i n i m u m number.

S h o u l d you attempt to "shoot" a hole, the first digitdisplays a " H " until a star key is pressed. This digitalso displays a valid n u m b e r selection. A count of validmoves is given at the right of the display. A win givesa "F" in the first digit. All holes is a losing situation,( " L " in the first digit). You may start over at any timeby pressing the "Go" button. The program starts at 0 2 0 0 .

f }2000 20 2

0204

0 20 6

02070209020B020D

020F

0 2 1 1

0 2 1 2

0214

0 2 1 7

0 2 1 90 2 1 B

0 2 1 E

0220

0223

Q2250228022A022C022E

0230

A9 00A2 10

95 CFCA

DO FB

A9 40

85 D4A9 1085 DE4A85 DF20 DD 02

A6 D3

DO 5020 40 IFFO F420 40 IF

FO EF20 6A IFC9 13

FO D4

C9 OA10 E4A8

BEGN

CLOP

LD A Jt$00LD X #$10

STA O O C F , X

DEX

BNE CLOP

ZERO REGISTERS DO-DA

MLOP

STA OODR

LDA #$10STA OODE

LSR

STA 00 F

JSR DISP

LDX 00 D3

BNE DELAJSR 1F40BEQ MLOP

JSR 1F40BEQ MLOPJSR GETKEYCMP #$13

BEQ BEGNCMP #$OA

BPL MLOPTAY

103

...INITIALIZE DISPLAY...

INIT. STARFIELDREGISTERS

...DISPLAY...

MODE?

MODE=1, DELAY AND UPDATEMODE=0, GET KEYNO K E Y , RETURN

KEY STILL PRESSED?

NO, RETURNYES, GET KEY"GO" KEY?

Y E S , START AGAIN

OVER 9?Y E S , TRY AGAIN

USE AS INDEX

Page 105: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 105/178

0231

023302350238023A023D

023F0241

02430245

02470249024B024D024F02510252

0253025502570259025A025D025F

0261

026402660268026B

026D02700271

0273027502780279027B027D027F

0281

02820284

028502870289028A028B028D028F02900292

FO

85

20

85

B9C O

3024

DO

F O

24

DOA9

85D OF838

A96585D8

20

85

A520

85E6

4C

AO

2088

DO

A6BD

A8EO

30

458598

AOOA

4585984A

4585OA

A5A2

ElDl

F4 02DOCA 02

06

06DF

OC

04

DE

0676

DO

C3 /

00D5D5

F4 02DA

D5

FO 02

D8

D3

14 02

00

DD 02

FA

Dl

D3 02

0608DFDF

00

DEDE

DF

DF

DE

06

SKIP

HOLE

STAR

DELA

LOWF

BEQ MLOP

STA OQD1

JSR SEG

STA OODO

LDA 02CA,Y

CMP §$06

BMI SKIPBIT OODF

BNE STAR

BEQ HOLE

BIT OODE

BNE STAR

LDA #$76

STA OODO

BNE MLOPSED

SEC

LDA #$00ADC OOD5

STA 00D5CLD

JSR SEGSTA 00DA

LDA 00D5

JSR LEFT

STA 00D8

INC OOD3

JMP MLOP

LDY #$00

JSR DISPDEY

BNE DELA

LDX OOD1

LDA 02D3,X

TAY

CPX #$06BMI LOWF

EOR OODF

STA OODF

TYA

LDY #$00

ASL A

EOR OODESTA OODE

TYALSR AEOR OODF

STA OODF

ASL ALDA OODE

LDX #$06

0? - NOT VALID

1-9 STORE IT

CONVERT TO SEGMENTS

DISPLAY - LEFT DIGIT

GET STAR TEST BI T

TEST KEY #

1-5, SKIP6-9, TEST HI FIELDIT'S A STAR

IT'S A HOLE

1 TO 5, TEST LO FIELD

IT'S A STAR

IT'S A HOLE LOAD "H"

DISPLAY-LEFT DIGIT

UNCOND. JUMPUPDATE COUNT

BY ADDING ONESTORE IT

UNPACK, CONVERT i

TO SEGMENTS AND *

DISPLAY IN DIGITS

5 AND 6...

SET MODE TO 1

MAIN LOOP AGAIN

MODE = 1

DELAY ABOUT .8 SECWHILE DISPLAYING

KEY # AS INDEXGET SHOT PATTERN

SAVE IN Y REGISTER

KEY # OVER 5?

NO, GO TO LOW FIELD

UPDATE HI FIELD, 6-9

RECALL PATTERN, 6-9

NO SHOT 3RD TIME

ALIGN WITH LO FIELD

UPDATE LO FIELD

RECALL PATTERN, 1-5ALIGN WITH HI FIELDUPDATE HI FIELD, 1-5

(BLANK SHOT IF 6-9)

SHIFT 9 TO CARRYGET REST OF FIELD

...STAR DISPLAY...

104

Page 106: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 106/178

0294029502960298

02 9A029B029C029D029F02AO

02A202A4

02A602A802AA

02 C02AE

02BO

02B2

02B4

02B602B802BB

02BE0 2 C 1

02C4

02C6

02C8

02CB

02DB

2A

48

29

95

68CA

CA

DO2A

B O

F O

C9DO

A9DO

A9DO

C6A9

85

DO4C

20

2020

C9DO

4C

01

EO

49DO

F5

OE

08FF

0871083804D300

DO

0314DD

406A

13

F300

02

D8

DLOP ROLPHA

AND

STA

PLADEX

DEX

BNE

ROL}

BCS

« BEQ/ CMP

/ BNELDA

BNE

LOSE LDA

BNE

MODE DECLDA

FRST STA

BNE

02 JMP

02 DONE JSR

IF JSR

IF JSR

CMP

* BNE

02 JMP

04 08 10 10 20 40

#$49

OODO,X

DLOP

MODE

LOSE#$FF

MODE

#$71FRST

#$38FRST

OOD3

#$00

00 DO

NONEMLOP

DISP

1F40

GETKEY

#$13DONE

BEGN

80 IB 07

ALIGN WITH DISPLAY

SAVE IT FOR NEXT TIME

MASK TO HORIZ. SEGS

INTO DISPLAY WI NDOW

RECALL FIELDSHIFT TO NEXT

DISPLAY DIGIT

REPEAT TILL DONEBIT FOR 5 TO CARRY

5 IS STAR, CONTINUE

5 IS HOLE, ALL HOLESALL THE REST STARS?NO

Y E S , LOAD "F"

AND SKIP

LOAD "L", CLOSE)

AND SKIP

SET MODE TO 0BLANK FIRST DIGIT

FILL FIRST DIGIT

END OF GAME

MAIN LOOP AGAIN 4DISPLAY UNTIL

"GO" KEY IS

PUSHED

START A NEW GAME

36 49 BA 92 6C

:c;cx DISPLAY SUBROUTINE "-"-02DD

02DF

02E202E402E6

02E802EB02ED02EF

A98D

A2

B58420EO

DO

60

7F4109

C7FC

4E

15F5

DISP LDA

17 STA

LDXMORE LDA

STY

IF JSR

CPX

BNE

RTS

#$7F1 7 41

#$09OOC7,X

OOFC

1 F 4 E

#$15MORE

:s:::HEX CONVERSION SUBROUTINE02FO0 2 F 1

02F202F302F4

02F602F7

02FA

4A4A4A4A

29A8B960

OF

E7

LEFT LSR

LSR

LSR

LSR

SEG AND

TAYIF LDA

RTS

A

AAA

#$OF

1FE7,Y

TURN ON DISPLAY

PUT IN4SEGMENTSSAVE YDISPLAY THEM

DONE? 6 TIMESNO, LOOP

Y E S , RETURN

JOSH

MASK TO 4 BITSUSE AS INDEX

CONVERT TO SEGMENTS

RETURN

105

Page 107: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 107/178

B y Joel Swank

Description -T I M E R turns KIM into a digital stopwatch showing up to

9 9 m i n u t e s and 5 9 . 9 9 seconds. It is designed to be accurateto 50 microseconds per second. The interval timer is usedto count 9 9 8 4 cycles and the instructions between the timeout and the reset of the timer m a k e up the other 16 cyclesin .01 seconds. The keyboard is used to control the routineas follows: Stop ( 0 ) , Go (1), R e t u r n to KIM (4),Reset ( 2 ) .

020002020204

02060208

020B020E

02100212

02150217021902 IB

021D02 IF

0222

02250228

022A022D

022F

0232

02330234

0236023802 3A023C023E0240

0242

02440246

0248024A024B024D

024F02500253

02550257

A9 . f l f l . BEGN85 F985 FA

85 FB20 IF IF HOLD

20 6A IFC9 04

DO 034C 64 1C

C9 02 CONTFO E7C9 01DO EB

A9 9C8D 06 1720 IF IF DISP

AD 07 17 CLCK

F O FB

8D 00 1C *A9 9C

8D 06 1718

F8

A5 F969 0185 F9

A5 FA

69 0085 FAC9 60

DO OB

A9 0085 FA

A5 FB1869 0185 FBD8 CKEY20 6A IF

C9 00DO CB

FO AF

LDA #$00STA INH

STA POINTLSTA POINTHJSR SCANDS

JSR GETKEYCMP #$04

BNE CONTJMP 1C64

CMP #$02BEQ BEGNCMP #$01BNE HOLD

LDA #$9CSTA 1706,

JSR SCANDS

LDA 1707BEQ CLCK

STA ROMLDA #$9C

STA 1706

CLCSED

LDA INH

ADC #$01STA INH

LDA POJNTLADC #$00STA POINTL

CMP #$60

BNE CKEY

LDA #$00STA POINTLLDA POINTHCLCADC #$01STA POINTHCLDJSR GETKEY

CMP #$00BNE DISPBEQ HOLD

106

ZERO DISPLAY

LIGHT DISPLAY

KEY 4?

RETURN TO KIM

KEY 2?BACK TO ZEROKEY 1? \

SET TIMER

DISPLAY VALUE

CHECK TIMER

DELAY 4 MICROSECSET TIMER

SET FLAGS

INC. 100THS

INC. SECONDS

STOP AT 60

ZERO SECONDS

INC. MINUTES

READ KEYBOARD

KEY 0?

STOP

Page 108: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 108/178

WUMPUS B y Stan Ockers

Description -

W u m p u s lives in a cave of 16 rooms (labeled 0-F). Each room

has f o u r tunnels leading to other rooms (see the figure). When the

program is started at 0305, you and W u m p u s are placed at random in

the rooms. A l s o placed at random are two bottomless pits (they don't

bother W u m p u s , he has sucker-type feet) and two rooms with Super-

bats (also no trouble to W u m p u s , he's too heavy). If you enter a bat'sroom you are picked up and f l o w n at random to another room. You

will be warned when bats, pits or W u m p u s are nearby. If you enter the

room with W u m p u s , he wakes and either moves to an adjacent room or

just eats you up (you lose). In order to capture W u m p u s , you have

three cans of "mood change" gas. W h e n thrown into a room containing

W u m p u s , the gas causes him to turn f r o m a vicious snarling beast

into a meek and loveable creature. He will even come out and give you

a hug. Beware though, once you toss a can of gas in the room, it is

contaminated and you cannot enter or the gas will turn you into a

beast (you lose). L

If you lose and want everything to stay the same for another try,

start at 0316. The byte at 0229 controls the speed of the display. Once

yo u get used to the characters, you can speed things up by putting in a

lower number. The message normally given tells,you what room you

are in and what the choices are for the next room. In order to fire

the m o o d gas, press PC (pitch can?), when the rooms to be selected

are displayed. The n indicate the room into which you wa nt to pitch

the can. It takes a fresh can to get W u m p u s (he may m o v e into a room

already gassed) and he will hear you and change rooms whenever a

can is tossed (unless you get him). If W u m p u s moves into a room with

a pit or Superbats, he'll be hidden - you won't be told W U M P U S CLOSE.

Either guess, or pitch a can to make him move. G o o d hunting.

The program is adapted f r o m a game by Gregory Yob which

appears in The Best of Creative Computing.

/7\B —— 8

107

Page 109: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 109/178

030503070309030B

030C

030E

03100312

0314

031603180 3 1 A

0 3 1 D

0 3 1 F

0 3 2 1

0323032403260329

032A032C032F0331

03330336

0339033A033C

033E

034003420344

03460348034A034C

034E03500353

035503570359035B035E026003620364

03670369036 A

036C036E036F

A9A2

95CA

10

A9

85AO10

AOA2

20

29

D5FO

CA

109988

1020AO

84

B9208A

30EO

30

A910EO

30

A910

A9AO

20C6

A410A4

B9

85A2B4B9

95CA

10

AO9820

FF

OE

Cl

FB

03

EO0502

000572 02OF

CA

F5

F9CA 00

ECB2 02

03El

C6 00

8F 02

170304

19OA

01

04OE0200

01

00 02El

El

DACA

E7 IF

OC

03C6

E7 IF

20

F600

00 02

INIT

GETN

CKNO

ADJR

NXTR

SKP1

SKP2

MESS

NOMA

XRO

ROOM

LDA

LDX

STA

DEX

BPL

LDA

STALDYBPL

LDY

LDX

JSR

ANDCMP

BEQ

DEX

BPL

STADEY

BPLJSR

LDY

STY

LDA

JSR

TXA

BMI

CPX

BMI

LDA

BPLCPX

BMI

LDA

BPLLDA

LDY

JSR

DEC

LDY

BPLLDY

LDA

STALDXLDY

LDA

STA

DEX

BPL

LDYTYAJSR

#$FF

#$OE

OOC1,X

INIT

#$03

OOEO#$05GETN

#$00

#$05RAND

#$OF

OOCA,X

GETN

CKNOOOCA,Y

GETNNXTR

#$03O Q E 1

OOC6,Y

COMP

NOMA

#$03S K P 1

#$19MESS

#$01

SKP2#$OEMESS

#$00

#$01SCAN

O O E 1

O O E 1

NXTROOCA

1FE7,Y

OOOC

#$03OOC6,X1FE7,Y

0020, X

XRO

#$00

SCAN

...INITIALIZATION...

..CLEAN OUT ROOMS..

INIT. TO FF

FINISHED?

NO

GIVE THREE CANS OF GAS

...RANDOMIZE...

YOU,WUMPUS,PITS AND BATS(ONLY YOU ENTRY)

..MAKING SURE ALLARE DIFFERENT..

STORE IN OOCA-OOCF

SET UP ADJACENT ROOM LISTHAZARDS IN ADJ. ROOMS?

COMPARE EACH TO HAZARDS

(X CONTAINS MATCH INFO.)

NO MATCH, NO HAZARDSBATS?

NO «

(BATS NEARBY MESSAGE)

PIT?

NO *

(PIT CLOSE MESSAGE)

MUST BE WUMPUS

(PAGE ONE)

DISPLAY HAZARD MESSAGETRY NEXT ADJ. ROOM

FINISHED?

NO..LOAD AN D DISPLAY -

"YOU ARE IN ... TUNNELSLEAD TO ...." MESSAGE..

(FOUR NEXT ROOMS)

CONVERSION

PUT IN MESSAGE 'FINISHED?

NO

LOCATION AND..PAGE OF MESSAGEDISPLAY MESSAGE

108

Page 110: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 110/178

0372037503770379037C037E

037F03810383038503870389038A038C038F

03900392

03940396

0398039A039C039E03A1

03A403A603A803AA03 D

03AF

03B1

03B403B703B903BC03BE

03C1

03C303C503C803CB03CE03DO03D1

03D303D503D703D903DB03DD

03DF03E1

03E303E6

20

C9FO

20

858A

30A5A2

D5

FOCA

10

208A

30

EO

10

EO

10AO

A9

20

20

C5D O

A9

4C

AOA9

20

4CA94C

A94C

AO

A92020

20

858A

30

A5A6

95C5FO

C6

FO

A62020

581448C5CA

EBCA

04Cl

33

F98F

9A

03

1701

ID00

2600

99CA

8426CF

013D

00

164F

CF

65CF

00

B70058

C5Dl

EE

DlEO

CO

CB

15EO

1ACB

B4

A5

02

02

02

0202

02

02

03

02

02

0202

02

0202

NXTG

BATM

PITM

GASM

ROOM

JSR DEBO

CMP #$14

BEQ ROOMJSR VALID

STA OOCA

TXA

BMI ROOMSLDA OOCA

LDX #$04CMP OOC1,X

BEQ GASM

DEX

BPL NXTG

JSR COMP

TXABMI ADJR

CPX #$03

BPL BATM

CPX #$01BPL PITM

LDY #$00

LDA #$26JSR SCAN

JSR MOVE

CMP OOCA

BNE ADJR

LDA #$26

JMP LOSE

LDY #$01

LDA #$3D

JSR SCAN

JMP CHNGLDA #$4F

JSR LOSE

LDA #$65JMP LOSE

LDY #$00

LDA #$B7JSR SCAN

JSR DEBO

JSR VALIDSTA OOD1

TXA

BMI ROOM

LDA OOD1LDX OOEO

STA OOCO,X

CMP OOCB

BEQ WIN

DEC OOEO

BEQ OU TLDX OOCB

JSR NEXTJSR MOVE

DEBOUNCE KEY

PC PUSHED?

YES

AN ADJACENT ROOM?

UPDATE YOUR ROOM

IF X=FF, NOT VALID ROOMCHECK FOR GAS IN ROOM

5 POSSIBLE (EXPANSION)

GASSED!!ALL CHECKED?NO

CHECK YOUR NEW

ROOM FOR HAZARDS..NO MATCH, NO HAZARDS

BATS

PIT!!!

MUST HAVE BUMPED WUMPUSDISPLAY MESSAGE

..SEE IF HE MOVES..

STILL IN YOUR ROOM?

NO, YOU'RE O.K.HE GOT YOU!

BAT MESSAGE

CHANGE YOUR ROOMFELT- IN PIT!

GAS IN ROOM!

PITCH CAN AND SEE.

IF YOU GET HIMROOM?

VALID ROOM?

IF X=FF, NOT VALID

CANS OF GAS LEFT

..IS WUMPUS INROOM GASSED?YES, YOU GOT HIM

DECREASE CAN COUNT

GAS IS GONE..MOVE WUMPUS TO ANADJACENT ROOM (FOR HIM)

109

Page 111: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 111/178

03E903EB

03ED

03F2

03F403F603F903FB03FD

0200020202040206

0208020A020C

020E0 2 1 0

0 2 1 2

0 2 1 3

0 2 1 5

0 2 1 6

0 2 1 7

0 2 1 9

021A

0 2 1 B

0 2 1 C

0 2 1 E

022002230225

0228022A

022C

022E

0 2 3 1

0234

0237

0239023B

023D

C5FO

4C

AOA9

20

F O

A94C

8485A9

85AO

A2Bl

C9DO

6095

88CA

10D818

98

65

85

20A44C

A286

A98D

202C10

C6D O

60

CA

BB

DE 02

01

80

00 02

F773CF 02

DEDD

07DF

05

05DD

0001

E8

F3

DF

DC

28 02DCOA 02

OA

DB

52

07 173E 02

07 17F8DB

EF

CMP

BEQJMP

LDY

LDA

JSR

BEQ

OUT LDA

JMP

STYSTALDA

STA

LDY

CONT LDX

CHAR LDA

CMPBNE

RTSSTA

MORE DEY

DEX

BPLCLD

CLC

TYA

ADC

STA

JSRLDY

JMP

DELAY DISPLAY

LDXSTX

TIME LDA

STA

JSR

BIT

BPL

DEC

BNE

RTS

00 CA

03A802DE

#$01

#$80

SCANWIN

#$73LOSE

OODE

OODD

#$07OODF

#$05

#$05(OODD),Y

#$00MORE

OOE8,X

CHAR

OODF

OODC

0228OODCCONT

SUBROUTINE

#$OA

00 DB

#$52

1707

DISP

1707

LITEOODB

TIME

DID HE MOVE INTO YOUR ROOM?YES

DISPLAY CANS LEFT MESSAGEGREATS ETC. MESSAGE

REPEAT

OUT OF GAS!

TRANSFER POINTER HIGH

TRANSFER POINTER LOW

INIT. SCAN FORWARD

INIT Y

INIT X

GET CHARACTER

LAST CHARACTER?IF NOT, CONTINUE

STORE IT

SET UP NEXT CHARACTER

SET UP NEXT STORE LOG.

LOOP IF NOT 6TH CHAR.BINARY MODE

PREPARE TO ADD

GET CHAR. POINTER

UPDATE FOR 6 NEW CHAR.

SAVE NEW POINTER *

DELAY-DISPLAY ^RESTORE POINTERCONTINUE REST OF MESSAGE

SET RATEPUT IN DECR. LOC.LOAD TIMER

START TIMER

JUMP TO DISPLAY SUBR.

TIMER DONE?IF NOT, LOOP

DECREMENT TIMER

NOT FINISHED

GET 6 NEW CHAR.s w s s c s BASIC DISPLAY SUBROUTINE ""

::x

023E0240

024302450247024A

024C

A98D

AO

A2

B984

20

7F

41 17

00

09E8 00FC

4E IF

LDASTA

LDY

LDX

SIX LDA

STY

JSR

#$7FPADD

#$00

#$09OOE8,Y

OOFC

1F4E

CHANGE SEGMENTS..TO OUTPUT

INIT.' RECALL INDEX

INIT. DIGIT NUMBER

GET CHARACTER

SAVE Y

DISPLAY CHARACTER

110

Page 112: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 112/178

024F C8

0250 CO 06

0252 90 F30254 20 3D0257 60

INY

CPY #$06

BCC SIX

IF JSR 1F3D

RTS

SET UP FOR NEXT CHAR.

6 CHAR. DISPLAYED?

NO

KEY DOWN?EXIT

:s:::x DEBOUNCE SUBROUTINE """"

0258 20 8C025B 20 3E025E DO F8

0260 20 3E

0263 FO FB

0265 20 3E0268 FO F6

026A 20 6A

026D C9 15026F 10 E7

0271 60'

0272 8A0273 480274 D80275 380276 A5 41

0278 65 44027A 65 45027C 85 4002 7E A2 04

0280 B5 400282 95 410284 CA

0285 10 F9

0287 85 CO0289 6802 8A AA

028B A5 CO028D 60

028F A2 04

0291 D5 CB0293 FO 030295 CA

0296 10 F90298 60

IE DEBO JSR INIT1

02 JSR DISPBNE DEBO

02 SHOW JSR DISP

BEQ SHOW02 JSR DISP

BEQ SHOW

IF JSR GETKEY

CMP #$15

BPL DEBORTS

s:;:::: RANDOM NUMBER SUBROUTINE

RAND TXAPHA

CLD

SEC

LDA 0041

ADC 0044

ADC 0045STA 0040LDX #$04

NXTN LDA 0040, X

STA 0041,X

DEX

BPL NXTN

STA OOCOPLA

TAX

LDA OOCO

RTS

"«"" COMPARE SUBROUTINE::-:"

COMP LDX J$Q4

HAZD CMP OOCB,X

BEQ OUTDEX

BPL HAZDOUT RTS

.

WAIT FOR PREVIOUS KEY

TO BE RELEASED

WAIT FOR NEW KEY TO

BE DEPRESSED

CHECK AGAIN AFTER

SLIGHT DELAY

GET A KEY

A VALID KEY?

NO

********

SAVE X REGISTER

RANDOM # ROUTINE FROMJ. BUTTERFIELD, KIM ^

USER NOTES #1 PAGE 4

4

RETURN X REGISTER'

*

COMPARE ROOM IN ACC.

WITH EACH HAZARD.

X ON EXIT SHOWS MATCH

se:aa: MOVE WUMPUS SUBROUTINE "x::"

0299 20 72029C 29 OF029E C9 04

02AO 30 OD

02A2 20 B202A5 AD 06

02A8 29 0302AA AA02AB B5 C602AD 85 CB

02 MOVE JSR RANDAND #$OF

CMP #$04

BMI NOCH

02 JSR NEXT17 LDA 1706

AND J$03

TAX

LDA OOC6,X

STA OOCB

GET A RANDOM #STRIP TO HEX DIGIT

CHANGE ROOMS 75%OF THE TIME

GET ADJ. ROOMS CTO WUMPUS)

GET RANDOM #, 0-3

USE AS INDEXGET AN ADJ. ROOM

PUT WUMPUS IN IT

111

Page 113: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 113/178

02C502C7

02C902CB02CC

02CE

02CF

02D1

02D4

02D602D8

02DB

02DE

02EO

02E3

02E502E702E902EC

A5 CB60 '

A6 CA

B5 5085 C6

B5 6085 C7

B5 70

85 C8B5 80

85 C960

A2 03D5 C6

F O 03

CA10 F960

AO 01

20 0 0 »

AO 00A9 AC20 00

4C D4

A4 EO

B9 E785 9F

AO 00A9 9020 004C 2C

NOCH

LOAD NEXT

"--"• CH!VALID

YVAL•****-**** 1 O 1LXOl

LOSE

02

02

02

•"""• G A S 1

IF

0 2 f *

03

LDA OOCB

RTS

DMS SUBROUTINl

LDX OOCA

LDA 0050,X

STA OOC6

LDA 0060,XSTA OOC7

LDA 0070,X

STA OOC8LDA 0080,X

STA OOC9

RTS

CHECK VALID SUBROUTINELDX #$03CMP OOC6,X

BEQ YVAL

DEX

BPL NXTVRTS

LOSE SUBROUTINE ":-::

LDYx$01

JSR SCAN

LDY #$00LDA #$AC

JSR SCAN

JMP REPT

T MESSAGE """:

LDY OOEO

LDA 1FE7,Y

STA 09F

LDY #$00LDA #$90JSR SCAN

JMP ADJR

WUMPUS ROOM IN ACC.

YOUR ROOM AS INDEX

... NEXT ROOMS ARE LOADED

INTO OOC6-OOC9 FROM

TABLES ...

... CHECK IF ACC.

MATCHS OOC6-OOC9

YES, VALID ROOM

...DISPLAY REASON LOST,THEN "YOU LOSE" ...

GET CANS LEFT

GET CONVERSIONSTORE IN MESSAGE

(PAGE ZERO)DISPLAY CANS OF GASLEFT MESSAGE

***** Messages *****

0000 80 EE DC BE 80 F7 DO F9 80 84 D4 80 EF 80 CO 80

0010 F8 BE D4 D4 F9 B8 ED 80 B8 F9 F7 DE 80 F8 DC 800020 FD FF F7 B9 80 00 80 DC DC F3 ED 80 CO 80 FC BE

0030 B7 F3 F9 DE 80 F7 80 9C BE B7 F3 BE ED 80 80 00

***** Next R0om List *****

0050 02 02 00 01 01 00 03 OH 00 06 07 00 09 OA 01 040060 05 03 01 02 03 02 05 06 05 08 09 08 OB OC OB 070070 08 04 03 04 07 06 07 OA 09 OA OF OC OD OE OC OA

0080 OB OE 05 06 OF 08 09 OF OB OC OD OE OE OF OD OD

112

Page 114: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 114/178

***** Messages *****

0090 80 B7 84 ED ED F9 DE 80 C O 80 DC D4 B8 EE 80 DB'

O O A O 80 B9 F7 D4 ED 80 B8 F9 Fl F8 80 00 80 EE DC BE

O O B O 80 B8 DC ED F9 80 00 80 D O DC DC B7 D3 80 00 03

• . . s

0 1 0 0

0 1 1 0

0 1 2 00 1 3 0

0 1 4 00 1 5 0

0 1 6 0

0 1 7 0

0 1 8 0

0 1 9 0

0 1 A O

80 9C

84 F8

B8 DCF3 BE

F3 F9EE EE

F3 84

B 7 80

80 80BD F9BE B7

BE B7

80 B9

ED F9ED 80

DO FC

84 84

F8 80

00 80

80 80F8 80

F3 BE

F3 BE ED

B8 DC ED

80 00 80BD DC F8

F7 F8 80F9 F9 F900 80 BD

DC BE F8

80 BD DO

F7 80 F6

ED 80 00

80 B9 B8

F9 00 80

F6 F7 8080 EE DC

ED D4 F7

80 Fl F9

F7 ED 8080 DC Fl

F9 F7 F8

BE BD 80

DC ED

FC F7

F6 F7BE 80

F8 B9

B 8 B 884 D4

80 BD

C O 80

Fl DO

F9 00

F8 ED

80 9C00 80

F6 80

80 84

80 DOF7 ED

EE DC

DC B7

80 F3

80 B9

BE B7ED BE

00 80D4 80DC DC

80 00BE 8080 9C

***** Hex D u m p - Main P r o g r a m *****W u m p u s

02000 2 1 0

022002300240025002600270

0280029002AO

02BO

02CO

02DO

02EO

02FO

03000 3 1 0

03200330

034003500360

03700380039003AO

03BO

03CO03DO03EO03FO

84 DE

DO 01

20 2817 208D 41

CO 0620 3EE7 60

B5 4004 D530 OD

CB 60

B5 8001 20

B9 E7BE BD

EA EA

85 EOCA FO

03 84

A9 1920 00A2 03

00 02EB A530 9A02 20

3D 20

02 AO

8A 30

1A A6EA EA

85 DD

60 9502 A43E 02

17 AO

90 F302 FO8A 48

95 41

CB FO

20 B2

A6 CA

85 C900 02IF 85

80 Fl

EA EA

AO 05F5 CA

El B9

10 OA

02 C6B4 C6

20 58CA A2

EO 0399 0200 02

00 A9EE A5

CB 20AO 01

A9 07E8 £8

DC 4C

2C 0700 A2

20 3D

FB 20

D8 38

CA 10

03 CA02 AD

B5 5060 A2AO 00

VA0

DO DC

EA A9

10 02

10 F9

C6 00

EO 01

El A4

B9 E7

02 C904 D5

10 17C5 CA4C 16

B7 20Dl A6

B4 02

A9 80

85 DF AOCA 10 F3

OA 02 A217 10 F8

09 B9 E8

IF 60 203E 02 FO

A5 41 65

F9 85 CO

10 F9 60

06 17 29

85 C6 B5

03 D5 C6A9 AC 20

00 A9 90B7 80 9C

FF A2 OE

AO 00 A2

99 CA 0020 8F 02

30 04 A9El 10 DA

IF 95 20

14 FO 48Cl FO 33EO 01 10

DO 84 A903 A9 4F

00 02 20EO 95 CO

20 A5 02

20 00 02

05 A2 05D8 18 98

03 86 DBC6 DB DO

00 84 FC

8C IE 20

F6 20 6A44 65 4568 AA A5

20 72 0203 AA B5

60 85 C7F O 03 CA00 02 4C

20 00 02

BE B7 F3

95 Cl CA

05 20 7288 10 EC8A 30 17

OE 10 02

A4 CA B9

CA 10 F6

20 C5 02CA 10 F9

ID AO 00

26 4C CF

4C CF 02

58 02 20C5 CB FO

C5 CA FO

FO F7 A9

Bl DD

65 DF

A9 52EF 60

20 4E

3E 02I F C9

85 40

CO 60

29 OF

C6 85

B5 7010 F9

D4 024C 2C

BE ED

10 FB

02 2920 B2

EO 03

A9 00

E7 IF

AO 00

85 CA20 8F

A9 2602 AO

A9 65C5 021 5 C6

BB 4C

73 20

C9 0085 DC

8D 07A9 7FI F C8

DO F8

1 5 1 0A2 04

60 A2C9 04

CB A5

85 C860 AOA4 EO

03 F6

80 00

A9 03OF D502 AO30 04

AO 01

85 OC98 20

8A 3002 8A

20 0001 A94C CF

85 DlEO FO

DE 02

CF 02

113

Page 115: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 115/178

DIAGNOSTIC A\n

UTILITY I»KO«KAA\S

Page 116: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 116/178

BKANCH BY JIM BUTTERFIELD

L o a d this fully relocatable program anywhere.O n c e it starts, key in the last two digits of

a . branch instruction address; then the last twodigits of the address to which you are branching;and read off the relative branch address.

For example, to calculate the branch to A D D R near theend of this programs hit 26 ( f r o m 0026); 20 (to 0020)and read F8 on the two right hand digits of the display.

T h e program must be stopped with the RS key.

0000 D80001 180002 A5 FA0004 E5 FB0006 85 F90008 06 F9OOOA 20 IFGOOD 20 6A0010 C5 F30012 FO EG0014 85 F30016 09 100018 BO E6001A OA001B OA0010 OA

001D OA001E A2 040020 OA0021 26 FA0023 26 FB

0025 CA0026 DO F80028 FO D6

START OLD

CLCLDA POINTL

SBC POINTHSTA INKDEC INK

IF JSR SCANDSIF JSR GETKEY

CMP EASTBEQ STARTSTA LAST

CMP #$10BCS STARTASL AASL AASL A

ASL ALDX #4ADDR ASL A

ROL POINTL> ROL POINTH

DEX

BNE ADDRBEQ START

K e e p in m i n d that the m a x i m u m "reach" of a branch instructionis 127 locations f o r w a r d ( 7 F ) or 128 locations backward ( 8 0 ) .

If you want a f o r w a r d branch, oheck that the calculated branchis in the range 01 to 7F. Similarly, be sure that a backwardbranch produces a value f r o m 80 to FE. In either case, a valueoutside these limits means that your desired branch is out ofreach.

115

Page 117: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 117/178

BROWSE Jim Butterfield

Load BROWSE anywhere in memory - it's fully relocatable -start it ut>, and presto.' It doesn't seem to do anything.

BROWSE is a mini-Monitor that performs most of the functionsof the regular KIM monitor; but you'll find it handy for enteringand proof-reading programs. Most of the keys work the same asusual; but PC, +. and DA are slightly different.

When you hit + you go to the next address as usual .. but thenyou keep on going.' Graat for proofreading a program you'veJust entered. It lets you browse through memory.

Hit PC and the program steps backwards, so you can look ata value you've just passed. All other keys instantly freezethe browsing process; you can hit AD or DA to stop on a given

address, or just enter a new address if you wish.

Key DA operates a little differently from the regular KIMfunction. To enter data, first set up the address before

the one you want to change. As you enter the data, BROWSEwill automatically step forward to the next address - andthen the next one, and so on. You never need to hit the +key during entry; and the display will show the last valueyou have entered. %

clear decimal modeGO key image

value zero....to address pointer

main program looppause 1 secondup or down?neither

down, decrementnext page?

light displaycheck keyssame key as last time?

note new key inputno key?yes, skip

clear up/down flag

0110 D8 S T A R T

0111 A9 13

0113 85 FE0115 A9 000117 85 FA

0119 85 FB011B C6 F3 L O O P011D DO OE >

011F A 5 F D0121 F O O A0123 10 690125 A 5 F A012? D O 0 20129 C6 FB012B C6 FA , D O W N

012D 20 19 3F LP10130 20 6A IF0133 05 FE0135 FO Eli0137 85 FE0139 C9 15013B FO D E013D A2 00

013F 86 FD

O LD

L D A #$13

STA C H A RL m # oST A P O I N T LS T A P O I N T HD E C WAI TBN E LP1

L D A TMPXBEQ L P1B P L U PL D A P O I N T LB N E D O W N

DEC P O I N T HDEC P O I N T L

JS R SCANDJS R GETKEYC M P C H A R

BEQ L OOPST A C H A R

C M P #&15BEQ L OOPL D X #0ST X T M P X

116

Page 118: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 118/178

OlUl C9 10

011*3 90 1C01U5 86 FU01U7 C9 11

Olli9 F O 01O l U B E8O l U C 86 FFO l U E C 9 120150 D O 0 2015? E6 FD0 1 5 U C9 1U0156 D O 0 20158 C6 FD015A C9 13015C DO CF015E U C C 8

0161 O A O A0163 O A O A0165 85 F C0167 A 2 Oh0169 All FF016B DO 17016D C6 FU016F 10 070171 20 63017U E6 FU0176 E6 FU0178 Bl FA

017A 06 FC

017C 2A017D 91 FA

017F CA0180 DO F8

0182 FO- 9018U O A0185 26 FA

0187 26 FB0189 CA018A DO F 80 1 8 C FO 9F

018E 20 630191 A A0192 10 990 1 9 U

C M P #$10 numeric?B C C H U M yes,branchSTX D I G I TC M P nil DA?

B E Q O V E R yes. leave X-0IN X no. set X-l

O V E R STXM O D E 0 or 1 into M O D E

C M P #$12 +?B N E P A S S no , skipIN C T M P X yes. set browse

PASS CM P #$1U PC?BN E P A S S 2 no, skipD E C T M P X yes, down-browse

P A S S 2 CM P #$13 G O ?B N E L P 1 n o , loop

ID J M P G O E X E C start p r ogr a m; numeric (hex) entry comes here

N U M A S I A A S L A position digitA S L A A S I A to leftST A T E M P

L D X #U h bits to moveL D Y M O D E A D o r DA ?

B N E A D D R branch i f AD modeD E C DIGIT time to step?B PL S A M E no, skip

IF JSR INCPT yes, stepIN C DIGIT ^.and restore

IN C DIGIT ..digit countS A M E L D A ( P O I N T L ) , Y get dataD A D A A S L TEMP move a bit..

R O L A ' ..into dataS T A ( P O I N T L ) , YD E X

BN E D A D A last bit?

BEQ LP1 yes,exitA D D R A S L A m ov e bits

R O L P O I N T L into addressR O L P O I N T HDEXBN E A D D R

BEQ L P1j increment address for browsing

IF U P J S R INCPTT A XBP L LP1

en d

O H . 5 0 —

117

Page 119: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 119/178

DIRECTORY Jim Butierfield

enough for most program

Ever thought about the best way to organize your programs on tape?

I used to call the first program on each tape number 01, the next 02, etc.Mostly I was afraid of forgetting the ID number and having trouble readingit in. Program DIRECTORY (below) fixes up that part of the problem and

liberates you to choose a better numbering scheme.

You've got 25 program IDs to choose from

libraries with some to spare.

So every program and data file would carry a unique number ... and ifyou've forgotten what's on a given tape, just run DIRECTORY and get all the

IDs.

Another thing that's handy to know is the starting address (SA) of aprogram, expecially if you want to copy it to another tape,. (Ending add-

resses are easy ... just load the program, then look at the contents of

17ED and 17EE). Well, DIRECTORY shows starting addresses, too.

The program is fully relocatable, so put it anywhere convenient.Start at the first instruction (0000 in the listing). Incidentally, 0001

to 001D of this program are functionally identical to the KIM monitor l88Cto 18C1.

After you start the program, start your audio tape input. When DI-RECTORY finds a program, it will display the Start Address (first fourdigits) and the Program ID. Hit any key and it will scan for the nextprogram.

0000

0001

000300060009OOOB

GOOD

OOOF

0011

00130016

0018

001A001C

001E

0020

0023

00250026

0028

002B

002D

D8

A9" D20

k 6

0585C9DO20

C6

10

C 9DOA2

20

95E8

3020

DOFO

07k2

kl

F9F9

F9

16F32k

F9

F5

2AFl

FD

F3FC

F8

IF

D3F9

171A

1A

19

IF

GO CLD

LDA #$07

STA SBDSYN JSR RDBIT

LSR INK

ORA INK

STA INHTST CMP #Sl6

BNE SYN

JSR RDCHT

DEC INH

BPL TST

CMP #S2ABNE TSTLDX #3FD

RD JSR RDBYT

STA POINTH+1

INXBMI RD

SHOW JSR SCANDS

BNE GOBEQ SHOW

Directional reg

Scan thru bits...

..shifting new bit

..into left of

..byte INHSYNC character? -

no, back to bits

get a charactercount 22 SYNC's

then test astk..or SYNC

if asterisk,stack 3 bytes

,X into displayarea ^

..«and shineuntil keyedat's all folks

118

Page 120: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 120/178

by Jim Butterfield

H o w long does it take you to load a f u l l IK of K I M - 1m e m o r y ? O v e r tw o m i n u t e s ? A n d i f you're going f o rm e m o r y expansion, how long will it take you to load

your 8 K ? Twenty minutes?

Hold onto your hats . P r o g r a m H Y P E R T A P E ! will writef u l l y compatible tapes in a fraction of the time.Y o u c an l o a d a f u l l IK in 21 seconds.

Fully compatible means this: once you've writtena tape using H Y P E R T A P E ! you can read it back in usingthe normal KIM-1 program (starting at 1873 as usual).A nd the utilities and daagnostic p r o g r a m s w o r k on thissuper-compressed data (e.g., D I R E C T O R Y a n d V U T A P E ) .

*

Y o u ' l l need some m e m o r y space for the program, of course.I f you have m e m o r y expansion, there'll be no problemf i n d i n g space, of course. But if you're on the basicKIM-1, as I am, you'll have to "squeeze in" H Y P E R T A P E !along with the programs you're d u m p i n g to tape. I tryto leave page 1 alone usually (the stack can overwriteyour p r o g r a m due to bugs); so I stage H Y P E R T A P E ! inthat area. For the convenience of relocation, thelisting underlines those addresses that will needchanging. T h e r e are also f o u r values needed in page zerowhich you may change to any convenient location.

F o r those interested in the theory of the thing, I

should^piention: H Y P E R T A P E ! is not the limit. If youwished to abandon KIM-1monitor compatibility, youcould continue to speed up tape by a factor of 4 or 5times more. Can you imagine reading I K in f o u r seconds?For the moment, however, H Y P E R T A P E ! is plenty fast for me,

;this program also included in Super-dupe0100 A9 AD DUMP LDA #$AD

0102 8D EC 17 STA VEB

0105 20 32 19 JSR INTVEB set up sub0108 A9 27 LDA #$27

010A 85 F5 STA GANG flag for SBD010C A9 BF LDA #$BF

01O E 8D 43 17 STA PBDD ,

0111 A2 64 LDX #$64

0113 A9 16 LDA #$16

0115 20 J61 01 JSR HIC

0118 A9 2A LDA #$2A

011A 20 88 01 JSR OUTCHT011D AD F9 17 LDA ID

0120 20 JTJLjQl JSR OUTBT0123 AD F5 17 LDA SAL

119

Page 121: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 121/178

0126 20 6D 010129 AD F6 17

012C 20 fLILJll012F 20 EC 17

0132 20 6D 01

0135 20 EA 190138 AD ED 17

013B CD F7 17

013E AD EE 17

0141 ED F8 17

0144 90 E9

0146 A9 2F0148 20 88 01014B AD E7 17

014E 20 7JLJU0151 AD E8 17

0154 20 70 010157 A2 02

0159 A9 04015B 20 61 01015E 4C 5C 18

0161 86 Fl0163 480164 20 88 010167 680168 C6 Fl016A DO F7016C 60

016D 20 4C 190170 48 >0171 4A0172 4A0173 4A0174 4A

0175 20 1D__OJL

0178 680179 20 7D 01017C 60

017D 29 OF017F C9 OA0181 18

0182 30 020184 69 070186 69 300188 AO 07

018A 84 F2

018C AO 02018E 84 F3

0190 BE BE 01

0193 48 "

JSR OUTBTC

LDA SAH

JSR OUTBTC

DUMPT4 JSR VEB

JSR OUTBTC

JSR INCVEB

LDA VEB+1

CMP EAL

LDA VEB 2

SBC EAR

BCC DUMPT4

LDA #$2F

JSR OUTCHT

LDA CHKL

JSR OUTBT

LDA CHKH

EXIT JSR OUTBT

LDX #$02

LDA #$04JSR HIC

JMP DISPZ

SubroutinesHIC STX TIC

HIC1 PHA

JSR OUTCHTPLA

DEC TIC

BNE HIC1

RTS

OUTBTC JSR CHKT

OUTBT PHA

LSR A

LSR A

LSR A

LSR A

JSR HEXOUT

PLA

JSR HEXOUT

RTS*

HEXOUT AND #$OF

CMP #$OA

CLC

BMI HEX1ADC #$07

HEX! ADC #$30

OUTCHT LDY #$07

STY COUNT

TRY LDY #$02

STY TRIE

ZON LDX NPUL,Y

PHA

120

Page 122: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 122/178

Page 123: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 123/178

MEMORY TEST J i mButt«rfi«ld

Testing RAM isn't just a question of storing a value andthen checking it. It's important to test for interference

between locations. Such tests often involve writing to onelocation and then checking all other locations to see theyhaven't been disturbed; this can be time consuming.

This nropram checks memory thoroughly and runs exceptionallyfast. It is adapted from an algorithm by Knai?uk and Hartmannpublished in 'IEEE Transactions on Computers', Anril 1977.

The program first puts value FF in every location under test.Then it puts 00 in every third location, after which it testsall locations for correctness. The test is repeated twice morewith the positions of the 00's changed each time. Finally,the whole thing is repeated with the FF and 00 values interchanged.

To run; Set the addresses of the first and last memory pagesyou wish to test into locations 0000 and 0001 respectively.Start the program at address 0002j it will halt with a memoryaddress on the display. If no faults were found, the addresswill be one location past the last address tested. If a faultis found, its address will be displayed. ^

Example: To test 0100 o 02FF (pages 01 and 02) in KIM:Set 0000 to 01, 0001 o 02, start program at 0002. If memoryis good, see 0300 (-02FF + 1). Now if you try testing0100 to 16FF (0000-01,0001-16) the piflgram will halt at

the first bad location - this will be OhOO if you haven'tadded memory.

0000 xx0001 xx

0002 A9 00OOOU A80005 85 FA0 0 0 7 85 700009 A2 02O O O B 86 72GOOD A5 00OOOF 85 FB

0011 A6 01

0013 A5 700015 U9 FF0017 85 710019 91 FA001B C8001C DO FB001E E6 FB0020 EU FB0022 BO F5

BEGINEND

START

BIGLP

PASS

CLEAR

xx star tii

xx endingLDA #0 z ei

TAY fo:STA POINTL ad«

STA FLAG -(

LDX #2STX MOD sLDA BEGIN s e "

STA POINTH ..!LDX ENDLDA FLAGEOR #$FF r e -

STA FLIPSTA (POINTL). Y

INIBNE CLEARINC POINTHCPX POINTHBCS CLEAR

zero pointersfor low-orderaddresses;-00 first pass, -FF second pass

3 tests each passset pointer to..

r t of test area

reverse FLAGFF first pass. -00 second pass

write above FLIP value....into all locations

122

Page 124: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 124/178

0021* A6 720026 A5 000028 85 FB002A A 5 70

002C CA002D 10 Ok002F A2 02

0 0 3 1 91 FA

0033 C 8003lj D O F 60036 E6 FB

0038 A5 01003A C5 FB003C BO EC

003E A5 00

O O k O 85 FB

0014? A6 720014*4 A 5 7 100146 CA

0014? 10 014

00li9 A 2 0 20014B A 5 7 00014D Dl FA

O O U F DO 150 0 5 1 C80052 D O F O00514 E6 FB0056 A5 010058 C5 F B

005A B O E 8

FILL

T O P

SKIP

j mer

PO P

SLIP

,F L I P value in all locations - now change 1 in 3L D X M O D

L D A BEGIN set pointer....back to startT A P OI N T H

L D A F I A G

DEXB PL SKIP

L D X #2ST A ( P O I N T L ) , YIN YBN E T O PIM G PO I NT HL D A E N D

CM P P O I N T HBCS FILL

change value

skip 2 out of 3restore 3-counter

change 1 out of

new pageh a v e w e passed....end of test area?nope, keep going

memory set up - now test itset pointer....back to start

set u r > 3-countertest for F L IP value..

..2 out of 3 times..- or -

1 out of 3..test for F L A G value;

Here's the test...branch if failed

L D A BEGINS T A P O I N T H

L D X M O DL D A FLIPDEX

B PL SLIP

L D X nL D A F L A G

C M P ( P O I N T L ) , YB N E O T T T

INT.BN E PO PIN C P OI N T HL D A E N D

C M P P O I N T H

005C C6 72005E 10 AD

0060 A5 700062 h9 FF00614 30 A10066 8h F A0068 kc U F ic

BCS POPabove test O K - cHffnge & repeat

DEC MOD

B P L P A S SL D A F L A G

EO R

OUTBUT BIGLPSTY POINTLJMP START

change 1/3 position..& do next third

invert....flag for pass two

put low order adds to display...and exit to KIM

006B

***** Hex D u m p - Memory Test *****

0000 00 00 A9 00 A8 85 FA 85 70 A2 02 86 72 A5 00 850 0 1 0 FB A6 01 A5 70 49 FF 85 71 91 FA C8 DO FB E6 FB

0020 E4 FB BO F5 A6 72 A5 00 85 FB A5 70 CA 10 04 A20030 02 91 FA C8 DO F6 E6 FB A5 01 C5 FB BO EC A5 000040 85 FB A6 72 A5 71 CA 10 04 A2 02 A5 70 Dl FA DO0050 15 C8 DO FO E6 FB A5 01 C5 FB BO E8 C6 72 10 AD

0060 A5 70 49 FF 30 Al 84 FA 4C 4F 1C

123

Page 125: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 125/178

MIN I DIS B y D an L e w a r t

O ne day I was single-stepping through a program and notbeing too alert, I kept going after the p r o g r a m ended.T h e n I noticed I was going through instructions not in any

OP-code table. What was being executed? With a littleluck I f o u n d that m a n y nonexistent codes w o u l d duplicateothers with only one bit changed. I haven't looked intoit very deeply, but here are two examples: 17 is the sameas 16 ( A S L - Z , P A G E ) and FF is the same as FE (INC A B S , X ) .

B y single-stepping I could determine the n u m b e r of bytesin all instructionsft T h i S i w o r k e d for all instructions exceptfor ^2,12,22732,42,^2,62,7*2,92,62^2 andF2,whichblank the display. A f t e r filling in the Bytes per Instructiontable m a n y patterns became obvious. For example, theop-code ending with digits 8 and A could be s u m m a r i z e d ashaving a bit pattern of x x x x l O x O , where "x" means don't

care. This covers all possibilities and when a n u m b e r ofthis f o r m is A N D e d with 0 0 0 0 1 1 0 1 ( m a s k all the x bits) theresult will be 0 0 0 0 1 0 0 0 . By doing this for all 0 (i llegal),1 and 3 byte instructions and having the 2 byte instructions"whatever's l e f t over" I had the basis of my semi-disassembler.T he only odd byte length is that of 20 (JSR) which "should"be only 1 byte long.

T h o u g h this is not a f u l l disassembler, it has helped me towrite several programs, including itself. To relocate thep r o g r a m change locations 3 7 4 - 6 , 3 7 9 - B and 3 8 E - 3 9 0 to j u m pto the appropriate locations. If you have a p r o g r a m in page

1 o r don't w a n t to write o n t h e stack, change 3 9 7 a n d 39 Ato E A ( N O P ) .

T o run the program, store 00 in 17FAand 03 in 17FB. Goto the beginning of your p r o g r a m and press " S T " . You willthen see the first instruction displayed. If it is illegal, thelocation and opcode will flash on and off. In that case, press" R S " . To display the next instruction press 'JJ^FTo displaythe current address and opcode press "@&', at anytime. Tobackstep press '$& $When you have backstepped to thebeginning of your program, or changed locations 397 and 3 9 A ,pressing " B " acts like "PC".

0 3 0 00 3 0 10 3 0 30 3 0 40 3 0 603080 3 0 A0 3 0 B0 3 0 D

D8A 2 F F9 AA O 00

A 2 0994 E5C A

D O F B

E 8

START

INIT

INIT1

SEDLDX t t $ F F

TXS

LDY #$00

LDX #$09STY OOE5,X

DEX

BNE INIT1

I N X

INITIALIZE STACK

POINTER(E&-EE)=0

124

Page 126: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 126/178

0 3 0 E B l F A0310 C9 2 00312 FO 3B0314 2 9 9 F0316 F O 3 50318 C 9 9 2031A FO 1A

031C A 8

031D 29 ID031F C9 190 3 2 1 F O 2 C0 3 2 3 2 9 O D0 3 2 5 C 9 0 80 3 2 7 F O 2 40 3 2 9 2 9 O C032B C 9 OC0 3 2 D F O 2 00 3 2 F 9 80 3 3 0 2 9 8 F0 3 3 2 C9 0 20 3 3 4 DO 18

0336 E6 EC0338 A 9 F F033A 8D 07 17033D A 5 EC0 3 3 F 2 9 0 10341 F O 0 30 3 4 3 20 19 IF034 6 2C 07 170349 30 EB034B 10 FO

034D E8

0 3 4 E E 8

0 3 4F 8 A0 3 5 0 4 9 0 70 3 5 2 8 5 E D0 3 5 4 A 4 E E0 3 5 6 B l F A0358 480 3 5 9 4A 4A0 3 5 B 4A 4A0 3 5 D A 80 3 5 E B 9 E 7 IF0 3 6 1 9 5 E 50363 E 80364 68

0365 2 9 O F0 3 6 7 A 80368 B 9 E 7 IF0 3 6 B 9 5 E 50 3 6 D E 80 3 6 E E 6 E E0 3 7 0 E 4 E D0 3 7 2 9 0 E O0 3 7 4 2 0 A F 0 30377 D O F B0379 20 AF 03

L E N G T H L DA ( P O I N T L ) , YC M P # $ 2 0BEQ 3BYTE 

A N D # $ 9 FBEQ 1BYTEC M P # $ 9 2BEQ F L A S H

T A Y

A N D #$1DC M P #$19

BEQ 3 B Y T E

A N D 34 OD

C M P # $ 0 8BE Q 1 BY T E

A N D # $ O C

C M P # $ O C

BEQ 3 BY T ET Y A

A N D # $ 8 FC M P # $ 0 2B N E 2 B Y T E

F L A S H IN C O O E C

L D A # $ F FS T A 1707

F L A S H 1 L D A O O E C

A N D # $ 0 1BEQ F L A S H 2JS R S C A N D

F L A S H 2 B IT 1707

B M I F L A S H

B PL F L A S H 1

1 B Y T E IN X2 B Y T E IN X

G ET O PC O D E , F I N D L E N G T H

A N A L Y Z E B IT P A T T E R N S% 00 1 0 0 0 0 0 ; 3 B YT E S"X " M E A N S D O N ' T CARE

% O X X O O O O O ; 1 B Y T E (20)

% 1 XX1 0 0 1 0 ; I L L E G A L ( B 2 , D 2 )S T O R E T E M P O R A R I L Y

% X X X 1 1 0X 1 ;3 B Y T E S (59,B 9 )

% X X X X X O X O ; 1 B Y T E (D8,4A)

% X X X X 1 1 X X ; 3 B Y T E S (4C,EE)

R E S T O R E

% O X X X 0 0 1 0 ; I L L E G A L (22,52)

A L L L E F T O V E R S ; 2 B Y T E S

F L I P B I T 0L O O P F O R 1 / 4 SEC.

B L I N K O N O R O F F

B IT 0=0 ; B L I N K OFF

B IT 0=1 ; B L I N K ON

3B Y T E T X A C E N T E R C O D EEO R #$07S T A O . O E D

C O N V R T L D Y # $ E E LOOP F O R E A C H B Y T EL DA ( P O I N T L ) ,Y C O N V E R T A N D S T O R EP H A IN E6 - EBL S R ' sL S R ' sT A YL D A T A B L E , YS T A O O E 5 , XIN XP L A

A N D # $ O FT A YL D A T A B L E , YS T A O O E 5 , XIN XI N C O O E E

C P X O O E DB C C C O N V R T

K D O W N JS R DISPB N E K DOWN

K U P J S R DISP

D I S P L A Y U N T I L A L L K E Y SA R E U P

D I S P L A Y A N D G E T K E Y

125

Page 127: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 127/178

Page 128: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 128/178

MOVIT B y L ew E d w a r d s

A N O T H E R m o v e p r o g r a m ? T h i s o n e m o v e s anything anywhere!N o limit to n u m b e r of bytes, or locations in m e m o r y , oroverlapping of source and destination. Use it to l i f t sections

o f code f r o m other programs, close in or open up gaps foraltering programs, m o v i n g programs to another location (useB u t t e r - f i e l d ' s R E L O C A T E to take care of the branch and addresscorrection). Locate it wherever you have the^room .-

Use is straight forward. Old start address goes in D0,l ;old end address in D 2 , 3 ; new start address in D 4 , 5 beforerunning the program which starts at 1780, or wherever youwant to have it in your system. P r o g r a m uses zero pagelocations DOthru D9 to do the job.

1780

1781

1783

17841786

1788

USA178C

178E

1790

1791

17931795

1797

1799

179B

179D

179F

1 7 A 1

17A2

17A417A6

17A8

17AA

17AC17AE

1 7 B O

1 7 B 2

17B4

17B6

1 7 B8

17B9

1 7 B B

D8AO FF

38

A5 D2

E5 DO

85 D8

A5 D3E5 Dl

85 D9

18

A5 D8

65 D485 D6

A5 D965 D585 D7

E6 D8E6 D938

A5 D4E5 DO

A5 D5E5 DlA2 00

90 02A2 02

Al DO

81 D490 14

C6 D29845 D2DO 02

START

LOOP

MOVE

CLD

LDY

SE C

LD A DEAL

SB C OSAL

STA B C L

LD A OEAH

SBC OSAH

STA BCH

CLC

LDA BCL

AD C NSALSTA NEAL

LDA BCH

ADC NSAH

STA NEAH

INC BCL

INC BCH

SE C

LD A NSAL

SB C OSAL

LD A NSAH

SBC OSAH •LD X # $ 0 0

BC C MOVELD X # $ 0 2

LD A OSAL,X

STA NSAL,X

BCC DOWN

DEC OEAL

TY AEOR OEALBNE NO

STORE TEST VALUE

HOW MANY BYTES?

TO MOVE?

ADD THE COUNT TO

THE NEW START TO

GET A NEW END

ADJUST THE BYTE COUNT

TO PERMIT ZERO TESTING

IF NEW LOCATION

HIGHER THAN OLDCARRY FLAG IS SET

HIGH POINTER INDEX

LOW POINTER INDEX

MOVE OLDTO NEW

ADJUST UP POINTER, COLD)

BELOW ZERO?

NO, ENOUGH

127

Page 129: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 129/178

17BD

17BF17C1

17C2

17C417C617C8

17CA17CC

17CE

17DO17D217D417D617D817DA17DC

17DE

C6 D3C6 D698

45 D6

DO 02C6 D7B O OC

E6 DO

DO 02E6 Dl

E6 D4

DO 02

E6 D5C6 D8DO 02

C6 D9DO CC

00

NOT

NEIN

DOWN

NYET

COUNT

ONE

DONE

DEC OEAH

DEC NEALTYA

EOR NEAL

BNE NEINDEC NEAHBCS COUNT

INC OSALBNE NYET

INC OSAHINC NSAL

BNE COUNTINC NSAHDEC BCL

BNE ONE

DEC BCH

BNE LOOP

BRK

YES, ADJUST THE HIGH BYTE

ADJUST THE OTHER ONE (NEW)

NEED HIGH BYTE ADJUSTED?

NOYES, DO IT

ADJUST "OLD" DOWN POINTER

*>AND THE HIGH BYTE IF NEEDED

AND THE "NEW"ONE

TICK OFF THE BYTES,ENOUGH FINGERS?

USE THE OTHER HAND'TIL THEY'RE ALL DONE

& BACK TO MONITOR

P.S. Don't forget to set the IRQvector for the break( K I M - 1 C O O at 17FE,FF)

***** Hex D u m p - Movit *****

1780 D8 AO FF 38 A5 D2 E5 DO 85 D8 A5 D3 E5 Dl 85 D91790 18 A5 D8 65 D4 85 D6 A5 D9 65 D5 85 D7 E6 D8 E6

17AO D9 38 A5 D4 E5 DO A5 D5 E5 Dl A2 00 90 02 A2 0217BO Al DO 81 D4 90 14 C6 D2 98 45 D2 DO 02 C6 D3 C617CO D6 98 45 D6 DO 02 C6 D7 BO OC E6 DO DO 02 E6 Dl

17DO E6 D4 DO 02 E6 D5 C6 D8 DO 02 C6 D9 DO CC 00

Addition: The last address filled can be displayed after theprogram is complete by adding the following code:

(1 ) 85 FAbetween instructions now at 1795 and 1797

(2 ) 85 FBbetween instructions now at 179B and 179D(3) replace the break at the end with 4C 4F 1CUse Movit to m o v e itself to another location and then againto open up the necessary spaces!

128

Page 130: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 130/178

Lewis Edwards, Jr.

Having trouble loading from tape, especially on "HYPERTAPE"? Suspectthe PLL adjustment might be off, but were afraid to adjust it, or didn't

have a meter or scope handy? Use this program and KIM's built in hardware

to make the adjustment. Hold the tip of the plug you plug into the taperecorder's earphone jack to applications pin #14 and adjust the controlfor O's or combinations of 7's and L's on the display. "L" means the PLLTEST line is low and "7" means it's high. The program generates a signalthat alternates slightly below and slightly above theone generated by KIM

at 1A6B. The regular tape input channel is utilized and decoded to con-

trol the display.

1780178217851787

178A178C178E1791179317951798179A179C179F17A217A517A7

17A917AB

17AD

17AF

17B117B2

17B517B717B917BB

17BE

17BF

17CO

17C217C4

A 98DA 98D

8 5A98DA2AO2C

30AO

8c8E

2C

10

E6

30A9DO

A9EA8D

A9

45858DE8E8EO

DOFO

074201

01

El7F

41090742

02

384042

47FBE2

04910393

4401

ElEl

00

15

CFCB

17

17

17

17

171717

17

17

BEGN

MORE

SEGS

DELA

HITO

LOTO

CLK1

IDA #07

STA SBD

LDA #01

STA PAD

STA ElLDA #7F

STA PADD

LDX #09

LDY #07

BIT SBD

BMI SEGS

LDY #38

STY SADSTX SBDBIT CLKRDI

BPL DELAINC E2

BMI LOTOLDA #91

BNE CLK1

LDA #93

NOP

STA CLK1T

LDA #01

EOR El

STA ElSTA PAOINX

INX

CPX #15

BNE NEXTBEQ MORE

Set the input

and output ports

Initialize the toggle

Open display channelsStart with the firstdigit Light top & rightif PLL outputis highotherwise left & bottomTurn on the segmentsand the digit

Half cycle done?No, wait for time upCount the cycles

128 %cycles, send low tone128 % cycles, send hi tone

Equalize the branchesSet the clock

Flip the toggle register

Toggle the output port

Next display digitLast one?

No, do nextYes, do more

1780 A9 07 8D 42 17 A9 01 8D 01 17 85 El A9 7F 8D 411790 17 A2 09 AO 07 2C 42 17 30 02 AO 38 8C 40 17 8E17AO 42 17 2C 47 17 10 FB E6 E2 30 04 A9 91 DO 03 A917BO 93 EA 8D 44 17 A9 01 45 El 85 El 8D 00 17 E8 E8

17CO EO 15 DO CF FO CB

129

Page 131: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 131/178

R E L O C A T E Jim Butterfield

Ever long for an assembler? Remember when you wrote that 300 byteprogram - and discovered that you'd forgotten one vital instruction in the

middle? And to make room, you'd have to change all those branches, all

those addresses... Or the program with that neat piece of coding in it, t h r •you suddenly need to remove (say, to change it to a subroutine)...but ifyou do, you'll have to fill all that empty space with NOPs? It's enoughto make a grown programmer cry...

Dry those tears. Program RELOCATE will fix up all those addressesand branches for you, whether you're opening out a program to fit in anextra instruction, closing up space you don't need, or just moving the wholething someplace else.

RELOCATE doesn't move the data. It just fixes up the addresses beforeyou make the move. It won't touch zero page addresses; you'll want them

to stay the same. And be careful: it won't warn you if a branch instruc-

tion goes out of range.

You'll have to give RELOCATE a lot of information about your program:

(1) Where your program starts. This is the first instruction inyour whole program (including the part that doesn't move).RELOCATE has to look through your whole program, instructionby instruction, correcting addresses and branches where neces-sary. Be "sure your program is a continuous series of instruc-tions (don't mix data in; RELOCATE will take a data value of10 as a BPL instruction and try to correct the branch address),and place a dud instruction (FF) behind your last program in-struction. This tells RELOCATE where to stop.

Place the program start address in locations EA and EB, loworder first as usual. Don't forget the FF behind the last

instruction; it doesn't matter if you temporarily wipe out abyte of data - you can always put it back later.

(2) Where relocation starts, this is the first address in yourprogram that you want to move. If you're moving the wholeprogram, it will be the same as the program start address,above. This address is called the boundary.

Place the boundary address in locations EC and ED, low orderfirst.

(3) How far you will want to relocate information above the bound-ary. This value is called the increment. For example, if youwant to open up three more locations in your program, the in-crement will be 0003. If you want to close up four addresses,the increment will be FFFC (effectively, a negative number).

Place the increment value in locations E8 and E9, low orderfirst.

130

Page 132: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 132/178

A page limit, above which relocation should be disabled. Forexample, if you're working on a program in the 0200 to 03FFrange, your program might also address a timer or I/O regist-ers, and might call subroutines in the monitor. You don'twant these addresses relocated, even though they are above theboundary! So your page limit would be 17, since these addressesare all over 1700.

On the other hand, if you have memory expansion and your programis at address 2000 and up, your page limit will need to be much

higher. You'd normally set the page limit to FF, the highestpage in memory.

Place the page limit in location E7.

Now you're ready to go. Set RELOCATE's start address, hit go - andZAP!-your addresses are fixed up.

After the run, it'sa good idea to check the address now in OOEA andOOEB - it should point at the FF at the end of your program, confirmingthat the run went OK.

Now you can move the program. If you have lots of memory to spare,you can write a general MOVE program and link it in to RELOCATE, so as todo the whole job in one shot.

But if, like me, you're memory-deprived, you'll likely want to runRELOCATE first, and then load in a little dustom-written program to do

the actual moving. The program will vary depending on which way you wantto move, how far, and how much memory is to be moved. In a pinch, you canuse the FF option of the cassette input program to move your program.

Last note: the program terminates with a . BRK instruction. Be sureyour interrupt vector (at 17FE and 17FF) is set to KIM address 1COO sothat you get a valid "halt".

RELOCATE Jim Butterfield

OOE?OOE8OOEAOOEC

0110 D8

0111 AO 00

0113 Bl EA0115 A8

0116 A2 07

0118 98

0119 3D 8E 01

011C 5D 95 01

011F FO 03

*=*+!

*=*+2

; following addresses must be initialized; by user prior to runPAGLIMADJSTPOINT

BOUND

; main program starts hereSTART CLD

limit above which kill relocnadjustment distance (signed)start of programlower boundary for adjustment

LDY #0LDA (POINT),Y

TAYLDX #7

LOOP TYAAND TAB1-1.X

EOR TAB2-1.X

BEQ FOUND

131

get op code+cache in Y

restore op coderemove unwanted bits& test the rest

Page 133: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 133/178

0121 CA

0122 DO F4

012*f BC 9D 01

012? 30 OD

0129 FO 22

012B E6 EA012D DO 02

012F E6 EB

0131 880132 DO F?

013 FO DA

0136 c80137 30 D90139 C8013A Bl EA013C AA0130 C8

013E Bl EAOUtO 20 ?9 01

01 3 91 EA

01 5 8801 6 8AOlU? 91 EA

01 9 AO 03

Ol B 10 DE

Ol D C8

Ol E A6 EA

0150 A5 EB

0152 20 79 01

0155 86 E O0157 A2 FF

0159 Bl EA

015B 18

015C 69 02

015E 30 01

0160 E8

0161 86 E30 1 6 3 18016 65 EA

0166 AA

016? A5 E3

0169 65 EB016B 20 79 01

016E CA

016F CA

0170 8A

0171 38

0172 E5 EO

017 91 EA0176 c80177 10 B2

DEXBNE LOOP

FOUND LDY TAB3,X

BMI TRIP

BEQ BRAN

SKIP INC POINT

BNE INEX

INC POINT+1

INEX DEYBNE SKIP

BEQ START

; length 3 or illegalTRIP INY

BMI START+2

INY

IDA (POINT) ,YTAXINY

IDA (POINT) ,YJSR ADJUST

STA (POINT) ,Y

DEY

TXASTA (POINT) ,Y

LDY #3

BPL SKIP

; branch: check "to" andBRAN INY

LDX POINT

IDA POINT+1

JSR ADJUST

STX ALOCLDX #$FF

IDA (POINT) ,YCLCADC #2BMI OVER

INXOVER STX LIMIT

CLCADC POINT

TAX

IDA LIMIT

ADC POINT+1

JSR ADJUST

DEX-DEX

TXASEC

SBC ALOC

STA (POINT ,YINYBPL SKIP

on to the next test...if anylength or flagtriple length?branch?

mving right along....to next op code

illegal/end to BRK haltset Y to 1lo-order operand...into X regY=2

hi-order operandchange address, maybe...and put it backY=l

...also hi-orderY=3

"from" address

Y=l"from" addrs lo-order...Be hi-orderchange, maybe

save lo-order onlyflag for "back" branches

get relative branch

adjust the offsetbackwards branch?nope

calculate "to" lo-order...and put in X00 or FF"to" hi-orderchange, maybereadjust the offset

recalculate relative branchand re-insert

Y=2

132

Page 134: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 134/178

0179 C5 E701?B BO 1101?D C5 ED

01?F DO 02

0181 E* f EC

0183 90 090185 ^80186 8A

0187 180188 65 E8018A AA018B 68Ol8c 65 E9018E 60

018F OC IF OD0192 87 IF FF

0195 03

0196 OC 19 080199 00 10 20

019C 03019D 02 FF FF

01AO 01 01 00

01A3 FF FE

; examine address and adjust, maybeADJUST CMP PAGLIM

BCS OUTCMP BOUND+1

BNE TES2CPX BOUND

TES2 BCC OUTPHA

TXACLC

ADC ADJUST

TAX

PLAADC ADJST+1

OUT RTS; tables for op-code indentificationTAB1 .BYTE $OC,8lF,«OD,$87,SlF,$FF,$03

too high?

hi-order?lo-order?

too low?stack hi-order

adjust lo-order

unstack hi-orderand adjust

TAB2 .BYTE

TAB3 .BYTE

end

*OC,$19,$08,$00,$10,$20,$03

f02,$FF,$FF,$01,$01,$00,$FF,$FE

Credit for the concept of RELOCATE goes to Stan Ockers, who insistedthat it was badly needed, and maintained despite my misgivings that itshould be quite straightforward to program. He was right on both counts.

***** Hex Dump - Relocate *****

0 1 1 0 -0120-

0130-0140-

0150-0160-

0170-

0180-0190-01A0-

0D8

03

EB

20

A5

E8

8A

02I F

01

\A0

CA

88

79

EB

86

38

E40D

01

200

D0

D0

0120

E3

E5

EC87

00

iBl

F4

F7

91

79

18

E0

90I F

FF

EA

BC

F0

EA

0165

91

09FFFE

89D

DA

88

86EA

EA

4803

uA2

01

C8

8A

£0

AA

C8

8A0C

707

30

30

91A2

AS10

1819

•%98

0D

D9

EA

FF

E3

E2

6508

< f3DF0

C8

A0

Bl

65

C5

E800

A8E

22

B l

03

EA

EB

E7

AA10

£01

E6

EA

10

18

20

B0

6820

c5D

EAAA

DE

69

79

1 1

6503

£95

D0

C8

C802

01

C5

E902

01 F002 E6

Bl .EA

A6 EA

30 01

CA CAED D0

60 0CFF FF

133

Page 135: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 135/178

USING PROGRAM RELOCATE - an example. Jim Butterfield

Program RELOCATE is important, and powerful. But it takesa little getting used to. Let's run through an example.Follow along on your KIM, if you like.

Suppose we'd like to change program LUNAR LANDER.When you run out of fuel on the lander, you get nospecial indication, except that you start falling

very quickly. Let's say we want to make this minorchange i if you run out of fuel, the display flips^over to Fuel mode, so that the pilot will see immediately.

Digging through the program reveals two things: (i) yougo to fuel mode by storing 00 into MODE (address El);and, (ii) the out-of-fuel part of the program is locatedat 02^C to 0257. So if we can insert a program to storezero in mode as part of our out-of-fuel, we should have

.accomplished our goal. Closer inspection reveals thatwe can accomplish this "by inserting 85 El (STA MODE)right behind the LDA instruction at 02^-C.

Let's do it.

First, we must store value FF behind the last instructionof our program. So put FF into address 02CC. That wipesout the value ^5> but we'll put it back later.

Now, we put our program start address (0200) into addressesEA and EB. Low order first, so 00 goes into address OOEAand 02 goes into OOEB.

Next, the part that we want to move. Since we want toinsert a new instruction at address 02^-E, we must movethe program up at this point to make space. In goesthe address, low order first: ^E into address OOEC and02 into address OOED.

The page limit should be set to 17, since we don't wantthe addresses of the KIM subroutines to be changed(SCANDS, GETKEY, etc.). So put 17 into address OOE7-

Finally, how far do we want to move the program to makeroom? Two bytes, of course. Put 02 and 00 intoaddresses OOE8 and OOE9 respectively.

We're ready to go. Be sure your vectors have been setproperly (at addresses 17FA to 17FF). Then set address0110, the start address of RELOCATE, and press GO.

The display will stop showing 011 EA, confirming that

RELOCATE ran properly. Now check to see the whole programwas properly converted by looking at the addresses OOEA-B.We put address 0200 there, remember? Now we'll seeaddress 02CC stored there - the address of the value FFwe stored to signal end of program.

Go back to 02CC, where we stored FF, and restore theoriginal value of ^5-

134

Page 136: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 136/178

We've completed part I. The addresses have been correctedfor the move. Let's go on to part II and actually movethe program fo make room.

My favorite method is to use a tiny program to do themove itself. For moving 1 to 256 bytes to a higher address ,I use the program:

BD xx 9DttttCAD0F?00.

In the above, nn is the number of bytes to be moved, and$xxx and tttt are the from and to addresses of the data,minus one. Since we want to move about 160 bytes froma block starting at 02^-E to a block starting at 0250,we code like this: ^D Q2^ Q2CA ?00.

This little program can be fitted in anywhere. Let'sput it in memory starting at address 00 0. The finalbyte, value 00, should end up in OO^B. Now back to00^-0, hit GO ... and your data/program is moved over.(The tiny program should stop showing address OO^D) .

There's nothing left to do but actually put the extrainstruction (85 El) into the program at 02^-E and 02^-F.

Now run the program. Try deliberately running out offuel and see if the display flips over to fuel modeautomatically when you run out.

If you have followed the above successfully with yourKIM, it all seems very easy. It's hard to realize thatprogram RELOCATE has done so much work. But if youcheck, you'll find the following addresses have beenautomatically changed:

0203 02^-B 0256/8 0263/5 0265/7 02A5/7

Do you think that you'd have caught every one ofthose addresses if you'd tried to do the job manually?

135

Page 137: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 137/178

SORT by Jim Pollock

This pro gram will take any given block of data andarrange it in numerical sequence, whether the data ishex or BCD, or

both. Sincethe program uses relative

branch addressing, it can be located anywhere in memorywithout modification.

T he instruction that determines whether data is arrangedin ascending or descending order is 01IF, ( B O -descending order, 90 - ascending order).

This is a bubble sort. The top item is compared withsucceeding items and if a larger n u m b e r is found, theyare swapped. The larger item (now at the top) is thenused for comparisons as the process continues throughthe list. A f t e r one complete pass, the largest n u m b e r

will have "bubbled" to the top. The whole process isrepeated using the second item to start, then againstarting with the third item. Eventually the whole listwill be sorted in sequence.

17F5

17F6

17F7

17F8

0200

020302050207020A020C

020E

0211

0213

0216

0218021A02 IB

021D

021F

0221

0223

AD

8585AD

8585AD

85AD

85A2D8Al

ClBOAl

85

F5

E8EA

F6

E9EB

F7ECF8ED

00

E8EA

OCE8

E7

17

17

17

17

START LO

START HIGH

END LO

E N D H I (NOTE: E N D IN G A D D R E S S i s O N E P A S T L A S T I T E M )

SORT LDA 17F5

STA OOE8STA OOEA

LDA 17F6

STA OOE9STA OOEB

LDA 17F7

STA OOEC

LDA 17F8STA OOED

LDX t t $ 0 0

CLDGET LDA (OOE8,X)

CMP (OOEA,X)

BCS INCNSWAP LDA (OOE8,X)

STA OOE7

TRANSFER START POINTER

TO ZERO PAGE

TRANSFER END POINTER

INDEX TO ZERO (STAYS THERE)

GET DATA INDIRECT OOE8

GREATER THAN INDIR. OOEA?

NO, INCR. POINTER OOEASWAP DATA IN POINTER

LOCATIONS

136

Page 138: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 138/178

022502270229022B

022D022F

0231

0233023502370239023B023D023F

0241

02430245

02470249024B024D024F

02510253025502570259025B

Al EA

81 E8

A5 E781 EA

E6 EADO 02E6 EB

A5 EAC5 ECDO E2

A5 ED

C5 EBDO DC

E6 E8

DO 02

E6 E9A5 E8

85 EAA5 E985 EBA5 EA

C5 ECDO C8

A5 E985 EB

C5 ED

DO CO

4C 4F 1C

L DA COOEA, X )

STA COOES,/)

LD A OOE7

STA (OOEA,X)

INCN INC OOEABNE LASTNINC OOEB

LASTN LDA OOEA

CMP OOEC

BNE GETLDA 00ED

CMP OOEB

BNE GET

INC OOE8BNE OVER

INC OOE9OVER LDA OOE8

STA OOEALDA OOE9STA OOEB

LDA OOEA

CMP OOEC

BNE GETLDA OOE9

STA OOEB

CMP OOED

BNE GET

JMP 1C4F

SET UP NEXT COMPARISONNO PAGE CHANGE

PAGE CHANGE

CK FOR LAST ITEM IN PASS

NOT YETIS THIS LAST PASS/LOOP?

NO

NO PAGE CHANGE

PAGE CHANGEINIT. VALUE FOR NEXT PASS

LAST ITEM IN LIST?

NO, NOT YET

LAST PAGE?NO

BACK TO KIM, DONE

***** Hex Dump - Sort *****

0200 AD F5 17 85 E8 85 EA AD F6 17 85 E9 85 EB AD F70210 17 85 EC AD F8 17 85 ED A2 00 D8 Al E8 Cl EA BO0220 OC Al E8 85 E7 Al EA 81 E8 A5 E7 81 EA E6 EA DO0230 02 E6 EB A5 EA C5 EC DO E2 A5 ED C5 EB DO DC E6

0240 E8 DO 02 E6 E9 A5 E8 85 EA A5 E9 85 EB A5 EA C50250 EC DO C8 A5 E9 85 EB C5 ED DO CO 4C 4F 1C

137

Page 139: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 139/178

SUPSR-DUPSby Jim Butterfield

SUPER-DUPE is handy: it lets you duplicate a complete tape

containing many programs in jig time. SUPER-DUPE isversatile: it will wr ite various tape densities, fromregular to Hypertape . SUPER-DUPE is multi -purpose: if youdon't want to duplicate prog rams, you can use it forcataloguing tapes, or for writing Hypertape.

The maximum size program that SUPER-DUPE can copy isdependent on the amount of memory of the KIM system. Thebasic IK system can copy programs up to 512 bytes long.

For duplicating tape, it'suseful to have two taperecorders: one for reading the old tape, one for writing

the new. They are connected in the usual way, at TAPE INand TAPE OUT. Pause controls are handy.

SUPER-DUPE starts at address 0000. Hit GO and start theinput tape. When a program has been read from the inputtape, the display will l i g h t , showing the start address ofthe program and its ID. If you don't want to copy thisprogram, hit 0. Otherw ise, stop the input tape; start theoutput tape (on RECORD) ; then hit 1 for Hypertape , 6 forregular tape, or any intermediate number. The output tapewill be written; upon completion, the display will lightshowing 0000 A2. Stop the output tape. Now hit GO to copythe next program.

SUPER-DUPE contains a Hypertape writing program which canbe used independently; this starts at address 0100.

Basically, SUPER-DUPE saves you the work of setting up theSA, EA, and ID for each program, and the trouble ofarranging the Hypertape writer into a part of memorysuitable for each program.

0000 A2 030002 B5 E20004 95 EO

0006 CA0007 10 F9

0009 A9 00

OOOB 85 F6OOOD 85 F7

OOOF D80010 A9 070012 8D 42 17

0015 20 41 1A0018 4& F9001A 05 F9

START LDX #3

LOOP LDA POINT2,X

STA POINT, X

DEXBPL LOOP

LDA #0

STA CHKSUM

STA CHKKI

CLD

LDA #7

STA SBD

SW JSRRDBIT

LSR INK

ORA INH

138

Page 140: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 140/178

001C 85001E C90020 DO0022 20

0025 C60027 10

0029C9

002B DO002D 200030 850032 A20034 200037 950039 20003C E8003D 30003F A20041 20

0044 C9

0046 FO0048 20004B DO004D CA004E DO0050 810052 200055 E60057 DO0059 E6005B DO005D 200060 C5

0062 DO0064 200067 C5

0069 DO006B 20006E FO0070 200073 850075 OA0076 FO0078 8D

007B 65

007D 8D0080 A90082 85

0084 A90086 8D0089 A2

008B A9

F9

16 TST

F324 1AF9

F52AFl

F3 19F9FEF3 19 ADDRFC

91 IF

F502 BYTE

24 1A DUBL

2F

1500 1A1C

Fl

EO91 IFEO02ElE2 OVERF3 19 WINDF7

05F3 19F6

95 ELNKIF IF FLSH

FB6A IFP5

88BE 01

F5

CO 0127F5

BF

43 176416

STA INKCMP #$16 sync?BNE SYN

JSR RDCHT

DEC INK

BPL TST

CMP #$2ABNE TST

JSR RDBYT

STA INKLDX #$FE neg 2JSR RDBYT

STA POINTH+1, X

JSR CHK

INX

BMI ADDR

LDX #2

JSR RDCHT

CMP #$2F eot?

BEQ WINDJSR PACKT

BNE ELNK error?DEXBNE DUBL

STA (POINT, X)

JSR CHK

INC POINT

BNE OVER

INC POINT+1

BNE BYTE

JSR RDBYT

CMP CHKHI

BNE ELNK error?JSR RDBYTCMP CHKSUM

BNE START (or 65?)

JSR SCANDS

BEQ FLSH display SA,ID

JSR GETKEY

STA GANG

ASL A

BEQ START

STA NPUL

ADC GANG

STA TIMG+1LDA #$27 register maskSTA GANG

LDA #$BF

STA PBDD

LDX #$64

LDA #$16 sync

1 39

Page 141: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 141/178

008D A2

008F A9

0091 200094 A90096 200099 A5009B 20009E

A5OOAO 20OOA3 A5OOA5 20OOA8 AOOOAA BlOOAC 20

OOAF E6OOB1 DOOOB3 E6

OOB5 A5OOB7 C5

OOB9 A5

OOBB E5OOBD 90

OOBF A9OOC1 20OOC4 A5OOC6 20OOC9 A5OOCB 4C

641661 012A88 01F9

70 01

FA70 01FB

70 0100E2

70 01E202E3E2EOE3

ElE92F88 01

F7

70 01F6

54 01

DATA

SAMP

LDX

LDA

JSR

LDA

JSR

LDA

JSR

LDA

JSR

LDA

JSR

LDY

LDA

JSR

INC

BNE

INC

LDA

CMP

LDA

SBCBCC

LDA

JSR

LDA

JSR

LDA

JMP

#$64

#$16

HIC

#$2A

OUTCHT

INK

OUTBT

POINTL

OUTBT

POINTH

OUTBT

#0(POINT2)

OUTBT

POINT2

SAMP

POINT2+1

POINT2

POINT

POINT2+1

POINT+1DATA

#$2FOUTCHTCHKHI

OUTBTCHKSUM

EXIT

send 100sync

start char

write ID

start adds

write data

next addrs

more data?eot

checksum

O O D O 4C 2 9 19

O O E 2 0 0 0 2 0 0 0 2

JMP L O A D T 9 FFFF option

data area; set as desired

****** Hex D u m p Super - D u p e ******

0000-

0 0 1 0 -0020-

0030-

0040-

0050-

0060-

0070-

0080-

0090-

00A0-03B0-

00C0-00D0-

00E0-

A2

A9

D0

85

02

81C5

20

F5

16

20E2

2F

4C

03

07

F3

F9

20

E0

F7

6A

8D

20

70D0

20

29

B5

8D

20

A2

24

20

D0

IFC0

61

010288

19

00

E2

42

24

FE

1A

91

05

C9

01

01

A5E6

01

02

95

17

1A

20

C9

IF

20

07

A9

A9

FBE3

A5

00

E0

20

C6

F3

2F

E6

F3

B0

27

2A

20A5

F7

02

CA

41

F9

19F0

E0

19

F4

85

20

70E2

20

10

1A

10

95

15

D0

C5

85

F5

88

01C570

F9

46

F5

FC20

02

F6

F5

A9

01

A0E0

01

A9

F9

C9

20

00

E6

D0

0A

BF

A5

00A5

A5

00

05

2A

911A

El

95

F0

8D

F9

BlE3

F6

85

F9

00

IF

D0

D0

20

84

43

20

E2E5

4C

F6

85

Fl

E8

1C

E2

IF

8D

17

70

20El

54

85

F9

20

30

CA

20

IF

BE

A2

01

7090

01

F7

C9

F3

F5

D0

F3

F0

0164

A5

01E9FF

D8

16

19

A2

Fl

19

FB

65

A9

FA

E6A9EA

R E M E M B E R : Y o u m u s t also include H Y P E R T A P E ! (page 119).

140

Page 142: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 142/178

VERIFY TAPf James Van Ornum

Do you want to verify the cassette tape you just recorded before theinformation is lost? Then follow this simple procedure:

1. Manually verify that the starting address ($1?F5, 8l?F6), theending address ($17*7, $1?F8) and the block identification(S17F9) locations are correct in memory.

2. Enter zeros (800) into CHKL ($1?E7) and CHKH ($17E8).

3. Enter the following routine:

17EC CD 00 00

17EF DO 03

17F1 If C OF 19

kC 29 19

VEB cmp STARTbne failedjmp LOAD12

failed jmp LOADT9

Rewind the tape, enter address 8l88C, press GO and playbackthe tape. If the tape compares, the LEDs will come back on

with address $0000. If there is a discrepancy between memoryand the tape, the LEDs will come on with address 8FFFF.

VU-TAPf Jim Butterfield

Program VUTAPE lets you actually see the contents of a KIM formattape as it's going by. It shows the data going by very quickly, becauseof the tape speed..but you can at least "sense" the kind of material onthe tape.

In case of tape troubles, this should give you a hint as to the areaof your problem: nothing? noise? dropouts? And you can prepare a testtape (see below) to check out the tape quality and your recorder. Thetest tape will also help you establish the best settings for your volumeand tone controls.

Perhaps VUTAPE1s most useful function, though, is to give you a

"feeling" for how data is stored on tape. You can actually watch theprocessor trying to synchronize into the bit stream. Once it's synohed,you'll see the characters rolling off the tape...until an END or illegal

character drops you back into the sync mode again. It's educational towatch» And since the program is fairly short, you should be able to traceout just how the processor tracks the input tape.

VUTAPE starts at location 0000 and is fully relocatable (so you canload it anyplace it fits).

141

Page 143: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 143/178

KIM UTILITY: VUTAPE

0000

0001

000500060008

OOOAOOOD0010

0012

0014

0016

0019001B

001D

0020

0022

0024

0026

0029002C

002F

0031

00330034003500370039003B003D0040oo4i00440047

D8

A98D

A985

8D20

4605858DC9DO20

C9DO

A 98D

2020

DOA6

E8

E8EODOA286

8EAA

BD

8D

DO

7F41

13EO

4241F9F9

F9

4o16E924

2A

F5

00

E9

2400

D5EO

1502

09EO

42

E740DB

17

171A

17

1A

171A1A

17

IF

17

START

SYN

TST

STREAM

-OVER

CLD

LDA #87F

STA PADD

LDA #$13STA POINT

STA SBDJSR RDBITLSR INH

ORA INH

STA INHSTA SAD

CMP #816BNE SYNJSR RDCHT

CMP #82A

BNE TST

LDA #800

STA SAVX

JSR RDCHTJSR PACKTBNE SYN

LDX POINT

INX

INX

C P X #815BNE OVER

LDX #809STX POINTSTX SBD

TAX

LDA TABLE,X

STA SADBNE STREAM

set display dir reg..window 6 and tape inand keep pointer

get a bit and..slip it into

..the right-hand

..side:show bit flow on display..is it a SYNC?nope, keep 'em rollingyup, start grabbing..8 bits at a time and....if it's not an "*"..

..then start showing

..characters 1 at a time

..converting to hexadec..

..if legal

Move along to next....display position(If last digit,....reset to first)

change character read

..to segments and..

send to the displayunconditional jump

Checking Out Tapes/Recorders

Make a test tape containing an endless stream of SYNC characterswith the following program:

00500052

0055

0057005A

AO BF

8c 43 17A9 1620 7A 19

DO F9

GO

LP

LDY #8BFSTY PBOD

LDA #816

JST DUTCHBNE LP

directional.....registersSYNC

...out to tape

Now use the program VUTAPE. The display should show a steadysynchronization pattern consisting of segments b,c, and e on the right

hand LED. Try playing with your controls and see over what range thepattern stays locked in. The wider the range, the better your cassette/recorder.

142

Page 144: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 144/178

EXPANDING YOIIK KIA\

Page 145: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 145/178

E X P A N D I N G Y O U R K IM

G a m e s and diversions using the keyboard and display are f i n e .Programming in assembly language can even be a lot of fun,once you get over the f i r s t few hurdles . B u t , sooner or lateryo u are going to get the urge to have your KIMact like the"big machines". What do you have to add on? How m u c h willit cost? How m u c h trouble is it going to be? Let's look ata few of the options and you can decide for yourself.

M e m or y Expansion

If you only had m o r e m e m o r y , you could do anything, right?Well, not exactly, but let's see what's involved in addingm e m o r y .

C o m p u t e r b u f f s abreviate a thousand m e m o r y locations, m o r eor less, with the letter K. Y o u r K I M - 1 has a I K block of R A Mand 2 K of R O M . Provision is also built into the KIM-1for

easily adding an additional 4K of m e m o r y .4K Expansion

If you want to add only 4K of memory, it'snot especiallyd i f f i c u l t . An article in K i l o b a u d #4, ( A p r i l '77), givesinstructions for adding one of the lower priced 4K R A M kits.It is p r i m a r i l y a m a t t e r of connecting wires between theexoansion connector on your KIMand the new board. Dependingon the size of your present power supply, an additional supplymay be required for the new board.

Further Expansion

%A d d i n g m o r e than 4K of m e m o r y is a bit m o r e difficult. Parto f the p r o b l e m has to do with address decoding. The expansionconnector is essentially an extension of the main arteries ofthe computer, the address and data busses. These carry signalsbetween the CPU and memory. The data bus carries informationto or f r o m a mem o r y location specified by the address bus.

The "Central Processing Unit1" ( C P U ) , on the KIM has the

potential of addressing 64 K however, so you can see that wehave barely begun to scratch the surface.

Decoding

T he complete address bus isn't available to each m e m o r y chipbecause there are just too many lines and not enough pins onthe chips. Instead , there is some extra circuitry which looks

1 4 4

Page 146: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 146/178

at the entire address bus and determines which block,(usually I K blocks), of m e m o r y should be allowed to function.This is called decoding circuitry. Sub-addressing withinblocks is handled by the lower address lines which are

connected to all chips.

Decoding sufficient to select one of f o u r IK blocks alreadyexists on the K IM and is brought out to the expansion connector.If you a dd m ore than 4 K o f m e m o r y , additional decoding willbe required. Usually this is built into the m e m o r y board.

B u f f e r i n g

If you start adding too m a n y chips to the address and databusses, the extra circuits begin to "load d o w n " the bus andcause it to not f u n c t i o n prooerly. A d d it io n a l boards aresometimes isolated f r o m the m a i n busses with circuits

called " b u f f e r s " which prevent this f r o m happening. S o m em e m o r y boards have buffers built in.

Another problem you should be aware of has to do with how fastthe CPU runs and how fast m e m o r y chips respond. S o m e CPU'shave a wait state so that if the m e m o r y is a little slow inresponding to entry or retrevial of information, the CPU canwait for it. The 65 0 2 processor in KIM doesn't have thisfeature. This means that the m e m o r y used has to be fast enoughto work with the processor. G

What B o a r d ?

We see then that m e m o r y expansion can get a little complicatedFurther details are given in sections 3 .2 and 6.1 of the KirnUser's Manual. Perhaps the easiest way to get around thesep r o b l e m s is to buy an assembled board m a d e especially for theK I M . All decoding, b u f f e r i n g etc. should already have beentaken care of in this case.

If you build f rom a kit,there are m a n y solder connections thatare very close to each other; it's easy to m a k e mistakes. Kitor assembled board however, you should f o l l o w the instructionso f someone who has already done it.

What does it cost?

Here's the good part! Memory prices have been dropping andare continuing to drop. Recently boards have been coming outusing 4K m e m o r y chips which have m o r e bits per chip than theolder I K R A M . This reduces the cost further, especially onboards having a lot of memory.

145

Page 147: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 147/178

A ny price quoted w o u l d soon be out of date and the price perbyte depends heavily on the size of board you buy. A quickscan th r o u g h a recent hobbyist publication should give you arough idea of what to expect.

How M u c h Do You Need ?

It depends primarily on what you want to do. Quite a bitcan be done with just the IK on the basic K I M - 1 . E v e n if youadd a terminal, this I K should be adequate for small games etc.written in assembly language. If you want to use a lot oftext or go to a higher level language like Basic, you will haveto expand. Exactly how m u c h you need to expand depends on howelaborate your software is.

Motherboards

If you want to add m o r e than just one board to the expansion

connector of your K I M , you should start thinking in terms ofa motherboard. A motherboard is a g r o u p of sockets connectedin parallel. B uf f e r ing is also usually provided so the extraboards don't load the busses.

If you buy a motherboard specifically for the K I M - 1, it willalso have provision for letting KIMk n o w when one of its boardsis being addressed. This is so the decoding present on theK IM will be disengaged and not conflict with decoding on theexpansion boards.

" S t a n d a r d " Busses

T he largest n u m b e r of boards m a d e for hobbyist use have a 100 pinconfiguration that plugs into the so-called "S-100" bus. MOSTechnology also makes a motherboard for KIMwith yet anotherbus. It should be possible to hook the K IM to motherboardsm a d e for other 8 bit machines too. One group is getting togetheran expansion board for KIMbased on the standard 44 pin connector.

Once you decide on a particular motherboard, you are prettym u c h locked in to buying or building boards whose pins matchthose in the sockets of the motherboard.

"S-100" Bus

T he S-100 bus derives f rom the Altair^motherboard. Presumably,any board which works in an Altair then should work in any otherS-100 machine. Unfortunately, that has not always been the case.T h e S-100 bus is popular though and already a couple manufacturershave advertised S-100 motherboards meant to be attached to theK I M . Because of the competition, S-100 boards sometimes givea cost advantage. This is especially true in the case of m e m o r yboards where competition is fierce.

N O T E : Altair is a trademark of M I T S , Inc.

1 46

Page 148: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 148/178

A Caution

N o matter what bus you decide on, you are going to needprograms written for K IM to drive certain boards you mightplug in. Unless there is a program for that particular board,written for K I M , you are in for a lot of work.

T he Serial Port

It's not necessary that all expansion take place along thedata and address busses of your K I M . There is anotherentrance/exit for information - the serial ports. The serialI/O, (Input and Output), ports also have the advantage thatmost of the required software already exists in the ROM of K I M .For example, to o u t p u t a character, it is only necessary toput that character in the accumulator and j u m p to the subroutineO U T C H ( 1 E A O ) . The character then comes spewing out the serialoutput port, bit by bit.

ASCII

T he code that is used in this process is the " A m e r i c a n StandardCode for Information Interchange", or A S C I I for short. Thehardware connection is also standardized and is m a d e of two2 0 milliamp current loops. The device to be connected to KIMshould be set up for these standards. Connections are madeas shown starting on page 17 of the KimUser's Manual.

The Teletype^

T he serial ports were obviously set up with a particularmachine in m i n d , the Teletype. The problem is that a new

Teletype will cost over $ 1 0 0 0 and used ones aren't m u c h cheaper.

Bau d o t Machines

Older model Teletypes and some other makes of teleprinters gofor $25 on up. The difference? These are B a u d o t machines.Where the modern Teletype uses a 8 bit (8 level) code torepresent A S C I I characters, the older machines use a 5 bit(5 level) code called Baudot. A good place to find out whatis available etc. is a series of three articles appearing inthe April, May and June '77 issues of Byte magazine.

Teleprinters are noisey, smelly and slow. What's more, the

interface of a Baudot machine to your KIM is far f rom a trivialproblem. Whythen even bother with the teleprinter? One reasonit's great to have a hardcopy of your program, a piece of paperyou can sit d o w n and take a pencil to w hen something goes wrong.

Video Terminals

Also easily connected through the serial port are stand alonevideo terminals. These units contain a cathode ray T . V . tube,

147Teletype is a trademark of Teletype Corp.

Page 149: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 149/178

( C R T ) , keyboard and all necessary guts to display a largen u m b e r of lines of characters on the screen at once. C o m m o nare 12 or 24 lines of 80 characters each. With 80 characters,a f u l l 72 character Teletype line can be duplicated, m a k i n g

the unit indeed a "Glass Teletype".

Fewer Characters - L o w e r Price

T he price of most video terminals is still up around $ 1 0 0 0 evenin kit f o r m . One way to reduce the cost is to reduce the numbero f characters and display the results on an ordinary T.V. set.16 lines of 32 or 64 characters are c o m m o n .

T h i s type of unit can be purchased as a video board alone oralong w i t h a keyboard in a nice case. If purchased seperately,you will also need a serial interface board.

Serial/Parallel Conversion

R e m e m b e r that we had planned to use the serial I/O ports on K I M .T he video board or the keyboard is m o r e than likely hooked upto i n p u t or o u t p u t in bytes, (parallel i n p u t or output). A wholebyte appears on 8 seperate pins along with a timing pulse, calleda strobe, on yet another pin. The strobe is used to indicate whendata is valid. We have to convert this type of input or output tothe sequential bit by bit i n f o r m a t i o n required by the serial port.

Luckily, there are chips designed especially to do this. Theyare called U A R T ' s and are f o u n d on serial interface boards.

One such board was described in issue #1 of Kilobaud, (Jan. 77).

Wha>to look for

V i d e o boards vary considerably in the features they o f f e r .T he simplist boards begin writing characters in the upper lefto f the screen and continue on d o w n the page. When the end ofthe last line is reached, they return to the upper left cornerand start over. The only control you m i g h t have is a "home"signal which returns you to the starting point. Any carriagereturns, linefeed etc. have to be taken care of by a p r o g r a m whichis keeping track of exactly where you are.

A better scheme is to have a cursor which is usually a flashingor solid white square located where the next character willappear. In m o r e advanced units, you can m o v e this cursor aroundunder software (or hardware) control. That way, it's easy toback up and go over any mistakes.

Another handy feature is scrolling. When you reach the end ofthe last line on the screen, it'sa little confusing to have

148

Page 150: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 150/178

the next line start at the top. Instead, s o m e boards automaticallypush every line up to m a k e r o o m for the incoming line, (the topline goes off the screen).

B l a n k to end-of-line and b l a n k to end-of-screen features arenecessary to keep f rom having a lot of unwanted characters l e f ton the screen. Be sure to check to f i n d out exactly what featuresare included on the board you are buying. If you can, f i ndsomeone who has a similar board up and running.

B a c k To The Busses

It's not manditory that a video board work off the serial ports.There are boards made to plug into most "standard" motherboards.

These w o r k off the data and address busses directly. In m a n ycases, they include m e m o r y to hold the characters which looksjust like any other m e m o r y to the processor. This has the

advantage that any character can be changed instantaneously.A board like this is undoubtedly going to require software to keepthings organized and you'll have to provide programs writtenespecially f o r K I M .

Hardware vs S o f t w a r e

With the prices of m e m o r y continuing to drop, it's becomingcheaper to replace m a n y hardware functions with software. Inthe case of video, you can use software not only to keep tracko f what characters go where; you can also use it to generatemost of the display itself. This tends to reduce the costconsiderably.

Using this fact, Don Lancaster describes a T.V. Typewritteraddition to the KIM for $25-$35, ( K i l o b a u d #6, J u n e '77 orPopular Electronics, July '77 and A u g u s t '77). But a w o r d ofcaution. Y o u ' l l have to "chop up" your K I M a bit to i m p l e m e n tthis-^the project involves cutting a piece of K I M ' s printedcircurTfoil, plus wiring in a whole bunch of new wires. Andwhile the changes don't affect K I M 's operation, you have torecognize that m e m o r y expansion becomes a different ball gameDon uses the addresses f ro m 2 0 0 0 to E F F F , and that meansthat you can't just add on extra m e m o r y in those areas.

Dedicating the processor to running the display in thism a n n e ralso means that it is going to have to "steal" time f r o m this

job to run your programs. This can slow things up a bit.

Keyboards

T he keyboard also doesn't have to come into the serial port.S o m e video boards have a keyboard port built in. Anotherpossibility is the parallel I/O ports on the KIM itself. Again,you'll have to provide the necessary software, but it wouldsave you f r o m having to buy a serial interface board.

149

Page 151: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 151/178

If you are t h i n k i n g of r u n n i n g both the keyboard and video boardo f f the parallel ports o f K I M , yo u should add up the total n u m b e ro f lines you need. By the time you include all necessary strobelines, you will probably f ind you don't have e n o u g h ports available,

Hooking To Y o u r T . V .

W h e n you h o o k a video board to a T . V . set, m a k e sure that theT . V . has a transformer which isolates the set f r o m the A.C.line. 110 volts can ruin a lot of chips in a hurry!

There are two ways of putting the video signal in the T . V .If you want to go into the antenna terminals, you will need aboard which generates a regular T . V . f r e q u e n c y signal withthe video signal being imposed upon it. K i t s are availablefo r $10 - $15.

A m e t h o d less susceptible to interference problems is to go

directly into the video a m p l i f i e r of the set. A T . V . repairshop should be able to handle this if you can't. A b o u t thesimplest circuit was given in July '76 Byte, p. 38. Anotherappeared in K i l o b a u d #7, ( J u l y '7 7 p. 30). K i t s are availableto m a k e this type of conversion also.

Video Monitors

A video monitor is like a T . V . set without the ability to pickup channels. It just takes a standard video signal (likethe one c o m i n g f r o m a video b o a r d ) and puts it on the screen.B e c a u s e they have a larger b a n d w i d t h than the n o r m a l T . V . set,they can display m o r e i n f o r m a t i o n without the characters gettingf u z z y .

Costs

A t the present time, ( S u m m e r '77), you can expect to pay $ 1 5 0 -$ 2 5 0 for a video board, $50 - $ 1 5 0 for a keyboard and over $ 3 0 0fo r the combination in a box along with a serial interface.Most of the serial interface is in the U A R T chip which sellsf o r about $10. K i t s may be available for about $25 - $50.Motherboards run $ 1 0 0 - $ 1 5 0 and a video monitor will costaround $ 1 5 0 - $200.

Graphics

If you want to use your KIM for simulating video games on aT.V., you should be thinking in terms of a graphics board.T h e graphics boards that are used with T . V . sets generate m a n ytiny white rectangles, squares or dot patterns on the screen,these can be individually turned on or off at will. S o m e videoboards m e a n t to display characters also have limited graphicscapability.

150

Page 152: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 152/178

Printers

T h e r e are a n u m b e r of printers on the m a r k e t which use m a n ysmall solenoids to form dot patterns through a typewritterribbon onto paper. These dot patterns form characters faster

than can be d o n e with a typewritter or teleprinter. S o m e useadding m a c h i n e paper and others, a standard size sheet. Pricesr u n f r o m $ 2 5 0 o n up.

A l s o available are printers which use a specially sensitizedpaper and print using a t h e r m a l process.

Floppy Disks

Once yo u start reading in programs which require 4K o r m o r e o fm e m o r y , you are going to f ind the cassette interface on yourK IM a little slow. E v e n w i t h Hypertape, it will take about

1 1/2 minutes to read in 4K.

There are faster tape units on the market, but the ultimate asfa r as the hobbist is now concerned is the " f l o p p y " . The f l o p p ydisk is like a flexable p h o n o g r a p h record coated with iron oxideas is used on tapes. A read/write head is m o v e d radially o u t w a r df rom the center to r e a d or write on d i f f e r e n t "tracks". The m a i nadvantage over tape is the speed at which any block of i n f o r m a t i o ncan be located. The information is also put on very compactlyand reading it back takes only a few seconds at most.

T h e m e c h a n i s m to do all this is a precision piece of e q u i p m e n ta n d quite expensive. Prices are continuing to d r o p h o w e v e r

as the d e m a n d becomes greater. The electronics necessary isalso quite complex, but as with the U A R T , single chips are nowbeing m a d e which do most of the job.

Floppies are o f t e n used in pairs. One reason for this is tobe able to back up what is stored on a disk. One disk iss i m p l y copied to another. Since each disk may store over 1/4million bytes, you can see how time consuming this would beif you tried to read all information into memory and back outon another disk. Smaller versions of floppies using a 5"diskette (wi t h less storage capacity) are also available atsomewhat lower prices.

A g a i n , you need not only the f l o p p y drive and controller(electronics), but also the necessary software written for K I M .T h e operating system software that goes with floppies is quitecomplex. But then, it's also very powerful.

151

Page 153: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 153/178

S O F T W A R E T O E X P A N D Y O U R K IM

In addition to building extra devices onto your KIM system,like teletype, display, or more m e m o r y , you can increase thepower of your system with special programs called software.

The name, software, is often misunderstood. Software, strictlyspeaking, refers to programs that help you do the j o b .

They are helping programs, not doing programs. For example,if you write a program to play a game, that's not software -it's called an application program, for it actually does something,B u t the programs that help your game, such as the Monitorsubroutines that you may call, are software. They don't do thej o b , but they sure help.

Most of the extra software that we'll talk about here willrequire extra m e m o r y to be fitted to your KIM system.

Assemblers

I f you've tried writing a program, you may have noticed thatconverting your coding into K I M 's machine language is quitea tedious job. For example, you mayhave written the commandL DA T O T A L to load the accumulator with a zero page quantitythat you have called T O T A L . B e f o r e you can enter the program,you m u s t convert this to the 6 5 0 2 code: A5 ( f o r LDAf r o m zero page),63 ( t h e zero page location you have chosen for T O T A L ) .Not too hard, perhaps; but you m u s t look up the code and keeptrack of the addresses If your program contains dozens ofinstructions, this conversion - called hand assembly - can

become quite a chore.

A n assembler p r o g r a m will do the conversion for you, quickly,neatly, and without error. If you have a hard copy printingdevice, it will give you a complete printout (called a "listing")of your program.

A resident assembler works on program data held entirely withinK I M ' s m e m o r y . It'svery fast, but it does need lots of m e m o r yto hold all of your p r o g r a m information. Other assemblers workf r o m data stored on magnetic tape or on floppy disk. They areslower, since the data m u s t be copied into m e m o r y as it's needed,but allow your programs to be almost unlimited in size.

A cross-assembler will assemble your KIM program on a completelydifferent machine, such as a Digital E q u i p m e n t Corporation PDP-11or a commercial time-sharing processor. Because these othercomputers are not so limited in size compared to the K I M , theycan be very powerful.

152

Page 154: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 154/178

Pis-Assemblers

A d i s a s s e m b l e r w o r k s in reverse f ro m a n assembler. I f y o u havea p r o g r a m in K IM machine language, the disassembler will print

it out in the m o r e easily readable assembly language . V e r yhandy for investigating a w o r k i n g p r o g r a m , if you don't havethe listing.

For example, if you have coding starting at address 0 2 O F thatreads: CA 10 F8 AD 04 17 85 80 .. . , the disassembler w o u l dprint something like this:

0 2 O F C A0 2 1 0 1 0 F 80 2 1 2 A D 0 4 1 70 2 1 5 85 80

DEXB P L 0 2 O AIDA 1704S T A 0080

A s you can see, this is m u c h more readable.

Interpreters ( B A S I C . F O C A L , etc.)

There are several "high level" languages that are m u c h easierf o r writing p r o g r a m s than K I M ( 6 5 0 2 ) machine language.With the proper software package, KIM can translate thesehigh level instructions and p e r f o r m the desired actions.The translation job takes time, so KIMwill run m a n y times slowerthan its normal "machine" speed. P r o g r a m m i n g convenience isso great, however, that most users don't m in d the loss of speed.

Interoreters can take up quite a bit of m e m o r y - anywhere f r o m2 K to 16Klocations - so you'll have to be fitted with theappropriate a m o u n t of m e m o r y expansion. If you hear of an8K Basic interpreter, you'll k n o w that m e a n s 8 , 0 0 0 locationsfo r the program; and of course you'll need to provide extram e m o r y to fit your own programs in.

A brief example will show how simple a language like B A S I Ccan be for programming. To input a number f r o m your keyboard,and type its square, you need only write:

5 0 I N P U T A receive value " a " f r o m keyboard60 L E T B » A * A "*" means multiplication

70 P R I N T " T H E S Q U A R E O F ";A;" IS " ; B80 S T O P

See how easy it is? KIM must read each line, character by character,decide what it means: inputting, calculating, printing or whatever,and then p e r f o r m that action. KIM works hard, but you don't .

153

Page 155: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 155/178

Text Editors

It can be very handy to compose a n u m b e r of lines of materialsuch as a letter, a program, or general data; put it into your

K IM system; save it permanently on tape or disk; and then laterrecall it and change, insert or delete information.

If you're writing a letter, you can correct mistakes and insertnew thoughts as they occur to you, perhaps even generatingseveral slightly different versions to mail to various people.If you have a program, you can correct bugs as you f ind themand insert new coding as needed Data files can be kept upto date.

Text Editors are very important with other software such asassemblers and interpreters; often, they are built in.

Mathematical Packages

Each m e m o r y location in KIM can store a n u m b e r f rom 0 to FFhexadecimal, or 0 to 255 decimal. Ther are no fractions,an d you have to m a k e special arrangement for signed (positivean d negative) n u m b e r s . You can link m e m o r y locations togetherto hold larger numbers; but extremely large n u m b e r s and fractionscall for special mathematical techniques to be used. In addition,K IM gives you only addition and subtraction; you have to workout multiplication and division for yourself, to say nothing ofmo re complex f u n c t i o n s like square roots and powers.

Y ou can program all this yourself, if you have the time and

the m a t h e m a t i c a l background. But if you really need to p e r formadvanced m a t h on your K I M , you'll be better off to obtaina pre-written mathematical package.

Floating-point on computers m e a n s about the same as the term"Scientific Notation" on calculators. It lets you use fractionsand deal with very large and very small values . In addition,you'll often get extra functions - powers, roots, logarithms,and trigonometric functions such as sines and cosines.

M a n y m a t h e m a t i c a l f u n c t i o n s are o f t e n included in large interpreters

154

Page 156: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 156/178

CONNECTINGT O T H E W O K I J I

Page 157: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 157/178

KIM RUNS THE WORLD OR HOW TO CONNECT YOUR MICROPROCESSOR

TO EXTERNAL DEVICES

By Cass Lewart

Introduction - Calculator versus Computer

Most of you are familiar with the ubiquitous pocketcalculator. From the simple "four-banger" to the mostsophisticated card-programmable, the sequence of ope-rations is always the same. You enter numbers fromeither the keyboard or a program card, depress a fewkeys, the calculator "crunches" your input and outcome the processed numbers on the display or printer.

Though a calculator will do a great job of processingnumbers, just try to make it perform a simple trickof a different kind - e.g., ring a bell after comple-ting the 150th iteration. No way! A calculator isa closed system. In general it is not possible toattach to it external devices not envisioned duringthe original design. A microprocessor such as KIM isquite different in this respect. In fact frequentlyits main functions are not to "crunch" numbers but toreceive signals from various sensors such as photocells,

thermostats, switches or pressure transducers, to doa small amount of processing of these inputs and then

to control devices such as lights, motors, relaysor even to play music.

In this chapter we will try to show you how easy it isfor KIM to perform operations of the type described.KIM via its input/output ports can receive and transmitcontrol signals. Its built-in precision quartz crystalcontrolled time reference and a built-in interval timerfurther simplify various controlling tasks.

KIM Ports - KIM Talks and Listens

KIM has four special memory locations which are used

for input, output and various applications. Greatthings happen if you store numbers in these locations!

156

Page 158: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 158/178

Location

1700

1701

1702

1703

Contents of Application Port A

Data Direction of Port A

Contents of Application Port B

Data Direction of Port B

The data contents locations 1700 and 1702 store thedata transmitted to or from KIM while the data directionlocations 1701 and 1703 determine which port operatesin the input and which in the output mode. These fourspecial memory locations can be accessed by KIM programs

in the same way as any other location. In additionthe application port A in location 1700 and the appli-cation port B in location 1702 are also accessible on

connector pins. They represent the physical interface

of KIM. By monitoring the appropriate pins with a volt-

meter one can detect the data stored in memory locations1700 and 1702 when KIM is in the output mode. By setting

the appropriate pins to ground or to Vcc (+5 Volts) onecan feed data into KIM in the input mode.

As KIM is an 8-bit microprocessor, each of the twoports A and B actually consists of eight independentinputs or outputs. Each of the eight bit positions

from 0 through 7 appears on a different connector pinand is a port in itself. The following are connector

pin assignments for the A and B application ports.For example PAD represents the 0-th or the least sig-nificant bit of port A and PA7 the 7-th or the mostsignificant bit. Pin A-14 means Application connector(lower left), the 14-th pin counting from the top,on the upper side of the connector (the lower side

of the connector is designated by letters instead ofnumbers).

Connector Pin Assignments

Port Pin

PBO A-9

PB1 A-10

157

Page 159: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 159/178

Port Pin Port Pin

PA2 A-3 PB2 A-ll

PAS A-2 PB3 A-12

PA4 A-5 PB4 A-13

PAS A-6 PB5 A-16

PA6 A-7 PB6 Not accessible

PA7 A-8 PB7 A-15

To assign any of the above connector pins to eitherinput or output mode we have to store a "magic"number in location 1701 to control port A or inlocation 1703to control port B. A "1" stored ina specific bit position makes the correspondingport into an output, a "0" into an input. Forexample, to assign PA7 to output and PAD through

PA6 to input requires storing 10000000 or SO ex ^n

location 1701. In the following example althoughwe deal only with port A, all the remarks applyequally to the port B.

Example - Burglar Alarm

Let's suppose that we want to design a system underKIM control such that PAO through PA6 are connected

to seven normally closed burglar alarm switcheswhile PA7 should control a warning bell. We wantthe bell to start ringing as soon as one of thecontacts opens. The bell should keep ringing evenif the contact closes again. We will first describethe software, or the programming part of the problem,and then will show you the actual circuit. We assumethat by now you scanned through the KIM softwarechapters and are familiar with its basic instructionset.

158

Page 160: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 160/178

Burglar Alarm Program

Comments

/Set PAD through PA6 to

(.input and PA7 to output

Set output to 0

Will affect PA7 only

/Read 1700 to find if PAO

4 through PA6 contain all

V'l"s (closed switches)

All are closed, go to OA

/At least one switch open,

Csound alarm

Stay in the loop

Now let's look at the simple circuit to operate our

burglar alarm. We connect PAO through PAS pins directlyto the switches. If a switch is closed then the voltageat that port is 0 Volts (ground); as soon as the switchopens, an internal resistor located on the KIM board"pulls" the port to the positive voltage Vcc of 5 Volts.All ports except PB7 are equipped with built-in resis-tors, called "pull-up" resistors connected to Vcc, whichset voltage at a port to VGC when the port is in theinput mode and is not connected to ground. On the outputport PA7 is connected to the base of an amplifying tran-sistor which drives a relay to operate an alarm bell.Th e transistor is necessary because the maximum availa-ble current of each KIM port is only on the order of

1 mA. This current would not be sufficient to drivea relay directly.

Loc

00

02

05

07

OA

OD

OF

11

13

15

18

Code

A9 80

8D 01 17

A9 00

8D 00 17

AD 00 17

29 7F

C9 7F

FO F7

A9 80

8D 00 17

4C 13 00

Mnemonic

LDA #80

STA 1701

LDA #00

STA 1700

LDA 1700

AND #7F

CMP #7F

BEQ OA

LDA #80

STA 1700

JMP 0013

159

Page 161: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 161/178

B U R G L A R A L A R M C I R C U I T

Multiple Drives

Now suppose you want KIM to drive several devicesrather than a single one. For example you may wantto connect a 3 x 3 matrix of LED lights to the A andB ports to play tic-tac-toe. Th e simplest way to dothis is by using one of the inexpensive digit drivingICs, such as 75492 used in many calculator circuits.

Each of these ICs will drive up to 6 lights, relaysor what have you with the simple circuit shown below.

The six 1C outputs act as "sinks", which requiresthat you connect one side of your electric load tothe positive battery vol tage and the other side toone of the 1C outputs. When the appropriate port is"on" current will flow through your load; when theport is "off", current will stop. The maximum currentthrough each load is 200 mA.

?

M U L T I P L E K I M I N T E R F A C E

6 +5-dttM.TS / - ,-L f +

|N4*»1-Si

UMIOS

160

Page 162: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 162/178

AC Control

To go one step further we can show you how KIM canoperate AC devices without relays. However we wouldlike to caution you that the power line voltage of110 Volts AC and the low voltages in your KIM do notmix easily. You may even achieve a non-voluntarybeautiful pyrotechnic display. In other words, ifyou are not careful in your soldering techniquesand like to leave a few wires dangling "just in case"we would recommend that you skip the followingparagraph.

The circuit we show here electrically separates KIMfrom the power line by means of a lamp/photocell

interface. The amplified voltage from one of theKIM ports turns on an incandescent lamp or an LEDwhich lowers the resistance of a photocell whichthen turns on the electronic TRIAC switch. Thissimple and inexpensive circuit can easily controlan AC lamp or appliance of up to 600 Watts.

A C I N T E R F A C E

• f - S V •i«r$>«*'\p

F R O M75191

* * * *R.S.276-H4o)

_ > , TO L I G H T

*OR

RADIO SHACK 176-1080

T O I I O V

O U T L E T

161

Page 163: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 163/178

KIM versus Hardwired Logic

We have showed you how KIM qan control relays, lightsand AC operated devices but these applications hardlytap KIM's capabilities. With the same methods youcan also switch tracks on a model train layout, controltraffic lights, and keep your fans and air conditionersgoing. The beauty of performing such tasks with a com-puter rather than with hardwired relay logic is thatlogical responses and changes in rules can easily beimplemented by changing a few statements in your prog-ram. A redesign of a hardwired circuit on the otherhand is always difficult, time consuming, frequentlyimpossible without starting your design from scratch.

D/A and A/D ^Converters

So far we have discussed on/off type controls such asswitches or relays which are either open or closed.However, there are many areas where a proportionalcontrol with "shades of gray" instead of black or whitewould be more desirable. For example if you are inte-rested in electronic music you would like to shapethe electric signals driving your amplifiers and speakersinto sinusoids, triangles and seesaws to mimic variousinstruments. Though even with a simple on/off controlyou can create sounds, their acoustical range is very

limited. If you connect an audio amplifier to one ofthe KIM ports and listen to the sound generated bythe 5 Volt pulses of various length and at variousrepetition rates the sound will remind you only ofa variety of buzz saws and not of musical instruments.The next step therefore is to develop a digital-to-analog (D/A) interface for your KIM. Such an interfacewill, for example, translate an 8-bit binary numberon ports AO through A7 into a voltage proportionalto the numerical value stored in location 1700 (Port A).

A number FFftex stored in 1700 could then generate2.0,Volts, while 20hex stored in the same locationwould generate (32/255) x 2.0 = 0.25 Volts. Though

we will not describe a D/A converter in detail, itcan easily be built with either separate amplifiersor with specially designed ICs. An example of a rela-tively inexpensive converter is MC1408L by Motorola.

162

Page 164: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 164/178

Similarly an analog-to-digital (A/D) converter inter-face can be used to turn KIM into a measuring instrument

such as a digital voltmeter, thermometer or even aspeech recognizer. Applications of a microprocessorequipped with D/A and A/D converters are limited onlyby your imagination and by your wallet.

Interval Timer

Many applications which interface KIM to the outsideworld benefit from the addition of a timer. Forexample, you may want the train in a model trainlayout to stop for exactly 45 seconds at a stationunder seme conditions but for only 30 seconds under

other conditions. For this and other purposes as well,KIM has a built-in interval timer which can be set tovarious multiples of its crystal controlled cycletime of 1 microsecond (10~

6sec.). By storing a number

K between 1 and FF^QX in one of the special memorylocations listed below we direct the timer to counta specific number of cycles. The special memory lo-cations used by the interval timer and the longestcount-down period are as follows«

Location Timer Count

1704

1705

1706

1707

(microseconds)

K x 1

K x 8

K x 64

K x 1024

Max. Period (sec.)For K = FFhex

0.000255

0.002

0.016

0.26

Location 1707 is also used to sense that the timerhas finished counting. By putting the interval timerinside a loop the timing can be lengthened to seconds,minutes and hours. The timer starts counting as soonas a number between 1 and FFhex ^s stored in one of

the above four locations by means of the STA (SToreAccumulator in memory) instruction. When time runsout the BIT (test BITs in memory with accumulator)instruction returns a non-positive value from lo-cation 1707.

163

Page 165: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 165/178

Timer Example

The following short program illustrates the use ofthe interval timer. The program will leave the loopafter 5 x 64 = 320 microseconds count is detectedby the BIT instruction. While the timer counts,other tasks can be performed by KIM.

Mnemonic

LDA #05

STA 1706

Comments

(Start timer by storing

5 in 1706

Perform other tasks

10 2C 07 17

'13 10 FO

15 ........

BIT 1707

BPL 05

Check if timer finished?

If still counting, go to 05

Otherwise continue

How KIM Communicates with its ovn Keyboard and Display

At first glance the KIM keyboard and the LED displayseem to be a hardwired fixed part of the micropro-cessor and as difficult to access as if they wouldbelong to a calculator. Fortunately it is not so.Both the keyboard and the display can be used quitedifferently from the way they are used by the KIMbuilt-in operating system program. You can run thedisplay and the keyboard under the control of yourown programs to perform all kinds of tricks. Forexample, you can program the LEDs to display anypattern in any digit position which can be made withthe seven LED segments. Similarly the keyboard can

be used as input to various programs with individualkeys performing functions unrelated to their numericallabels. For example, the "B" key in your program can

164

Page 166: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 166/178

indicate a "Backward", command, while the "F" key can

mean "Forward". Various game programs shown in othersections of this book are examples of such applications,

We have tried in this chapter to give you a feeling forwhat KIM can do in the way of control applications.We hope that by now you have gained some appreciationfor KIMs potential.

******************

165

Page 167: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 167/178

Page 168: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 168/178

G U I D E L I N E S F O R W R I T I N G K I M P R O G R A M S

1. Use of Memory.

—Wherever possible, place your programs in pages 2 and 3 —addresses 0 2 0 0 to 0 3 F F . It's handy to keep page zero forvariables

- values thatchange

duri ng program run; andpage one is best left alone because the program Stackuses it. The Stack, by the way,only uses a few locations- usually. But a small p r o g r a m error can sometimes m a k ethe stack run wild, which would destroy your page one data.

— Y o u r variables (changeable data) should be kept in page zero,in locations 0 0 0 0 to O O E E . These addresses are easy to use,since you can use zero-page addressing modes which save youtime and m e m o r y .

2. P ro gram and constants.

—Set U D your programs in the following pattern: first,the main program (starting at address 0 2 0 0 or higher);then your subroutines; and finally your data.K e e p them all fairly close together, so that when youd u m p the whole thing to cassette tape it won't takeextra time to write the 'blank spaces in between'.

3. Initial values.

—Don't assume anything about the beginning values in yourregisters or in zero page. If you want to be out ofdecimal m o d e (andyou usually do), m a k e your first c o m m a n da CLD ( D 8 ) . If you want the accumulator to be zero,

load it with ID A #$00 (A900). Every zero page variablethat needs to start at a certain value should be setto that value by the program. For example, if youw a n t address 0 0 4 3 to start out w i t h a value of 7, writeIDA #$07, S T A 0 0 4 3 (A 9 0 7 8 5 43).

4. General.

— - M a k e your subroutines simple, with clearly visible entryand return points. One of the stickiest problems to f indis a subroutine that doesn't return via a RTS command,but instead j u m p s straight back to your main coding ...or a subroutine that you somehow get into without givingthe vital JSR c o m m a n d .

— A v o i d super clever programming, such as having the programchange itself. (It can w o r k . .. but if it misbehaves, youcan have a bad time).

5. Remember: Computers are dumber than humans, but smarterthan nTwrrammorethan programmers

167

Page 169: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 169/178

L I G H T I N G T H E KIM-1 D I S P L A Y J im Butterfield

A . SIX-DIGIT H E X A D E C I M A L .

T he easiest way to display six digits of data is to usethe KIM-1 Monitor subroutine S C A N D .

Calling JSR S C A N D (20 19 IF) will cause the first four digitsto show the address stored in P O I N T L and P O I N T H ( O O F A and O O F B ) ,while the last two digits of the display show the contentso f that address.

If you look at the first three lines of subroutine S C A N D(lines 1057 to 1059 on page 25 of the listing), you'llsee how the program 'digs out' the contents of theaddress given by P O I N T L / P Q I N T H and stores it in locationIN H ( O O F 9 ) . It's neat programming, and worth studying

if you're not completely familiar with the 6502's indirectaddressing operation.

Thus, if you skip these three lines, and call JSRS C A N D S(2 0 I F IF ) you will be displaying , in hexidecimal, thecontents of three locations: P O I N T H , P O I N T L , and INHThis, of course, takes six digits.

T o recap: S C A N D will display f o u r digits of address andtwo digits 3& contents. S C A N D S will display six digitso f data.

Important: in both cases, the display will be illuminated

fo r only a few milliseconds. You m u s t call the subroutinerepeatedly in order to obtain a steady display.

B . D R I V IN G T H E B I T S O F T H E D I S P L A Y D I R E C T L Y .

1. Store the value $7F into P A D D ( 1 7 4 1 ) . This sets thedirectional registers .

2. To select each digit of the display, you will want tostore the following values in location SBD ( 1 7 4 2 ) :

, z ^ H < • 6 7

Digit 1: $09 i

Digit 2: $OB 0 'Digit 3: $OD a V * u x

Digit 4: $OF , t > ^l°' 1 0 M 1

_ Digit 5: $11_ \ Digit 6: $13

rNote that this can easily be done in a loop, adding twoto the value as you move to the next digit.

O

o |> o \168

Page 170: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 170/178

N o w that you have selected a particular digit, lightthe segments you want by storing a 'segment control

1

byte into location SAD ( 1 7 4 0 ) . The segments will belit by setting the appropriate bit to 1 in SAD accordingto the following table:

7

P i t : 6center

is

5upperleft

f4

lowerl e f t

3bottom

\2

lowerright

1upperright

i l

0top

•W :4| \'

? >

"g"

o

"f

H

"e" "c"

\

"a"

For example, to generate a small letter 't1, we

would store $ 7 8 (center, upper left, lower left, b o t t o m )into S A D . t Q

4. Now that you have picked a digit and lit the appropriatesegments, wait a while. Sit in a delay loop forabout 1/2 millisecond before moving on to the next digit.

T H E KIM-1 A L P H A B E T .

S o m e letters, like M and W, just won't go onto a 7-segmentdisplay. S o m e , like E , are only possible in capitals; others,like T, can only be done in lower case. So here's an

alphabet of possibles:

6 f\0ll)| 00f

O OO Q

ABCD

EFGHI

J

L

0

P

^S

UY

- $F7

- $FF- $B9- $BF- $F9- $F1- $BD- $F6- $86- $9E- $B8

- $BF- $F3

- $ED

- $BE- $EE

bcd

f

ghiJ1

n0pr

t

u

y

- $FC- $D8

- $DE

- $F1- $EF- $F4- $84- $9E- $86

- $D4- $DC- $F3- $DO

- $F8- $9 C- $EE

m i n u s

1234

567890

- $86- $DB- $CF- $E6

- $ED- $FD- $87- $FF- $EF- $BF- $CO

169

Page 171: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 171/178

The following is reprinted from the KIM-1 User Manual with permissionfrom MOS Technology.

Interval Timer

1. Capabilities

The KIM-1 Interval Timer allows the user to specify a preset

count of up to 25610an<^ a clock divide rate of 1, 8, 64, or 1024

by writing to a memory location. As soon as the write occurs,counting at the specified rate begins. The timer counts down atthe clock frequency divided by the divide rate. The current timer

count may be read at any time. At the user's option, the timermay be programmed to generate an interrupt when the counter countsdown past zero. When a count of zero is passed, the divide rateis automatically set to 1 and the counter continues to count down

at the clock rate starting at a count of FF (-1 in two's comple-ment arithmetic). This allows the user to determine how many clock

cycles have passed since thetimer

reached a count of zero. Sincethe counter never stops, continued counting down will reach 00again, then FF, and the count will continue.

2 » Operation

a. Loading the timer

The divide rate and interrupt option enable/disable areprogrammed by decoding the least significant address bits. - T h e

starting count for the timer is determined by the value written tothat address.

Writing to Address Sets Divide Ratio To Interrupt Capability Is

1704170517061707170C170D170E170F

186 k

102418641024

DisabledDisabledDisabledDisabled

EnabledEnabledEnabledEnabled

b. Determining the timer statusAfter timing has begun, reading address location 1707 will

provide the timer status. If the counter has passed the count of

zero, bit 7 will be set to 1, otherwise, bit 7 (andall other bitsin location 170?) will be zero. This allows a program to "watch"location 1707 and determine when the timer has timed out.

c. Reading the count in the timerIf the timer has not counted past zero, reading location

1706 will provide the current timer count and disable the inter-rupt option; reading location 170E ill provide the current timercount and enable the interrupt option. Thus the interrupt optioncan be changed while the timer is counting down.

170

Page 172: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 172/178

yif the timer has counted past zero, reading either memorylocation 1706or 170E ill restore the divide ratio to its pre-

viously programmed value, disable the interrupt option and leave

the timer with its current count (not the count originally writ-ten to the timer). Because the timer never stops counting, the

timer will continue to decrement, pass zero, set the divide rateto 1, and continue to count down at the clock frequency  unlessnew information is written to the timer.

d. Using the interrupt option

In order to use the interrupt option described above, linePB7 (application connector, pin 15) should be connected to eitherthe IRQ (Expansion Connector, pin *f ) or NMI (Expansion Connector,pin 6) pin depending on the desired interrupt function. PB7should be programmed as in input line (its normal state after aRESET).

NOTE: If the programmer desires to use PB7 as a normalI/O line, the programmer is responsible for dis-

abling the timer interrupt option (by writing orreading address 1706) o that it does not inter-fere with normal operation of PB7. Also, PB7 wasdesigned to be wire-ORed with other possible inter-rupt sources; if this is not desired, a 5.IK resis-tor should be used as a pull-up from PB7 to +5v.(The pull-up should NOT be used if PB7 is connectedto NMI or IRQ.)

I M P O R T A N T ! !T he KIM Cassette T a p e Interface

The K I M - 1 U S E R G U I D E doesn't emphasize one vitalinstruction in telling you how to read and write tapes.

B E F O R E R E A D I N G O R W R I T I N G M A G N E T I C T A P E , B E S U R ET O S E T T H E C O N T E N T S O F A D D R E S S O O F 1 T O V A L U E 00.

This ensures that the computer is not in Decimal Mode.T h e k e y sequence i s A D _ 0 0 _ F _ IDA 0 _ 2. A D .

If you forget to do this, you're likely to have trouble withaudio tape. You m i g h t write bad tape - which can never beread back in correctly; and you might f ind yourself unableto input properly f r o m tape . M a ny of us have run into thisproblem, and have wasted countless hours trying d i f f e r e n ttapes and recorders or even investigating K I M ' s electronics.

You'll find KIMaudio tape to be 100% reliable, even oninexpensive recorders, providing you f o l l o w this rule andalways ensure that location O O F 1 is set to zero.

171

Page 173: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 173/178

NOTES ON A RANDOM NUMBER GENERATOR Jim Butterfield

It's not my original idea - I picked up it from a technicaljournal many years ago. Wish I could remember the source,so I could credit it.

This program produces reasonably random numbers, and it won't"lock up" so that the same number starts coming out over andover again. The numbers are scattered over the entire rangeof hexadecimal 00 to FF. A Statistician would observe thatthe numbers aren't completely "unbiased", since a givenseries of numbers will tend to favor odd or even numbers slightly.But it's simple, and works well in many applications.

Here's how it works. Suppose the last five random numbersthat we have produced were A, B, C, D and E. We'll make anew random number by calculating A + B + E + 1. (The oneat the end is there so we don't get locked up on all zeros).

When we add all these together, we may get a carry, butwe just ignore it. That's an. The new "last five" willnow be B, C, D, E and the new number. To keep everythingstraight, we move all these over one place, so that B goeswhere A used to be, and so on.

The program:

xxxx D8 RANDxxxx 38xxxx A5 13 h ^ >

xxxx 65 16xxxx 65 17

xxxx 85 12 i? 7-xxxx A2 O Uxxxx B5 12 *"*- RPLxxxx 9513xxxx C Axxxx 10 F9

OLD clear decimal if neededSEC carry adds value 1LDA RND+1 last value (E)ADC R N D - ^ i add B ( + carry)ADC R N D - » 5 add C

STA RND new numberLDX #U move 5 numbersLDA RND,XSTA RND+1, X ..move over 1DEXBPL RPL all moved?

The new random number will be in A, and in RND, and in RND+1.Note that you must use six values in page zero to hold therandom string ... I have used 0012 to 0017 in the above coding.

You often don't want a random number that goes all the way

up to 255 (Hexadecimal FF). There are two ways of reducingthis range. You can AND out the bits you don't want;for example, AND #$7 reduces the range to 0-7 only.Alternatively, you can write a small divide routine, andthe remainder becomes your random number; examples of this

can be seen in programs such as BAGELS.

172

Page 174: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 174/178

.,.; *If The one publication that devotes all of its space to the KIM-1/6502

hines is:KIM-1/6502 USER NOTES

109 Centre Ave.,W. Norriton ?

Six issues of this bimonthly newsletter costs U.S. $5*00 for North

American subscribers and U.S.$10.00 for international subscribers.

Here's some pointers to other KIM-1/6502 articles-

BYTE-November 1975 p.56) - Son Of Motorola

- A description of the 6502 instruction set and comparisonwith the 6800.

May 1976(p.8) - A Date With KIM- An in depth description of KIM

August 1976(p.Mf) - True Confessions; How I Relate To KIM- How to; use cheap memories with KIM by stretching the clock;

expand memory; implement interrupt prioritizing logic; sim-ulate a HALT instruction.

March 1977 (p.36) - 6502 op code table

March 1977 p.70) - Simplified Omega Receiver Details- Using the 6502 for signal processing in a low cost navigation

receiver (Mini -Omega).

April 1977 (p.8) - K i r n Goes To The Moon

- A real-time lunar lander program for KIM

April 1977 (p.100) - Navigation With Mini-0

- Software details for a phase-tracking loop filter using Joltor KIM.

June 1977 (p.l8) - Designing Multichannel Analog Interfaces- Hardware and 6502 software for an 8 channel analog I/O.

June 1977 (p. 6)-Teaching KIM To Type Hardware and software for hooking KIM up to a Selectric.

June 1977(p.76) - Come Fly With KIM- Hardware and software for interfacing a Fly Paper Tape Reader

to KIM.

July 1977 (p. 26) - Giving KIM Some Fancy Jewels- How to outboard KIM's seven segment displays.

DR. DOBBS-

March 1976(p.17) -£502 Breakpoint Routine

August 1976(p. 17) - 6502 Floating Point Routine*•

August 1976(p.20) - Monitor For The 6502

173

Page 175: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 175/178

August 1976 (p.21) - Lunar Lander For The 6502

September 1976 (p.22) -6502 Disassembler

September 1976 (p.26) - A 6502 Number Game

September 19?6 (p.33) - 6502 String Output Routine

November 1976 (p.50) 6502 String Output Routine

November 1976 (p.57) - 6502 Floating Point Errata

February 1977 (p.8) - More 6502 String Output Routine

INTERFACE AGE-

September 1976 (p.l4) - A 6502 Disassembler

October 1976 (p.65) - Interfacing The Apple Computer- How to: hook a SWTPPR-40 to the Apple 6502.

November 1976 (p.12) - Build A Simple A/D- Hardware and 6502 software for simple joystick (or

whatever) interface.

November 1976 (p.103) - Floating Point Routine For 6502

April 1977 (p.l8) - "Mike"-A Computer Controlled Robot- Hardware and 6502 software for a KIM controlled robot likevehicle.

KILOBAUD-

January 1977 (p.11*0 - A Teletype Alternative- How to: Convert a parallel input TVT to serial operation;

interface to KIM.

February 1977 (p»8) - Found; A Use For Your Computer

April 1977 (p.7*0 - KIM-1 Memory Expansion- How to: Add an $89.95 ^K Ram board to KIM.

May 1977 (p.98) - Adding "PLOP" To Your System- A 6502 noisemaker for computer games.

June 1977 (p.50) - A TVT For Your KIM

NOTE; Kilobaud now has a monthly KIM column.

MICHOTREK-

August 1976 (p.7) - KIM-1 Microcomputer Module- A very in depth look inside KIM0

POPULAR ELECTRONICS-

July 1977 (p. 7) - Build The TVT-6- How to: KIM-1 TVT (same as Kilobaud #6).

174

Page 176: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 176/178

7 3 M A G A Z I N EJanuary 1977(p. 100) - Bionic Brass P o u n d e r

- How to: T u r n K IM into a smart morse code keyboard.

*********************************************

6502 S O F T W A R E S O U R C E S( as o f s u m m e r 1977)

A R E S C O314 Second Ave.Haddon Hts., New Jersey

0 8 0 3 5

T he ComputeristP.O. Box 3S. C h e l m s f o r d M A

0 1 8 2 4

Itty Bitty ComputersP . O . Box 23189San Jose, Calif.

95153

M I C R O W A R E2 7 Firstbrooke R d .Toronto, OntarioC A N A D A M 4E 2 L 2

MICRO- S O F T W A R E S P E C I A L I S T SP . O . B o x 3 2 9 2E . T. StationC o m m e r c e , Texas 7 5 4 2 8

6 5 0 2 P r o g r a m Exchange2 9 2 0 M o an a L a n eReno, N e v a d a 8 9 5 0 9

P yr amid Data Systems6 Terrace A v e .N e w Egypt, New Jersey

0 8 5 3 3

Julien Dub63174 R u e DouaiSte-Foy, Quebec G1W 2X2Canada

Focal, 2 1/2Kassembler6K assembler/text editor(send S.A.S.E. for inf o)

Please Package, Help,editor and mailing listpackages(send S.A.S.E. for i n f o )

T o m Pittman'sT i n y Basic(send S.A.S.E. f o r i nfo)

M I C R O C H E S S , (Chess inIk), assembler(s end S.A.S.E. fo r info)

2 K assembler /editor(send S.A.S.E. f o r inf o)

Focal, Focal programs,K im a nd TIM p r o g r a m s(send 5 0 £ fo r pr ogr am list)

IK monitor system,(send S.A.S.E. f o r i n fo )

B a u d o t Monitor(send S.A.S.E.)

175

Page 177: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 177/178

Jim Butterfield14 Brooklyn AvenueToronto, Ontario, Canada

M4M 2X5

Lew Edwards1451 Hamilton Ave.Trenton 9, N.J. 08629

Ron Kushnier3108 Addison Ct.Cornwells Hts., Penna.

19020

Stan OckersR.R.#4, Box 209Lockport, 111.

60441

Charles Parsons80 Longview Rd.Monroe, Conn.

06468

Eric Rehnke109 Centre Ave.W. Norriton PA

19401

Charles Eaton19606 Gary AvenueSunnyvale, California

94086

Peter Jennings27 Firstbrooke Rd.Toronto, Ontario Canada

M4E 2L2

Cass Lewart orDan Lewart12 Georjean DriveHolmdel, N.J. 07733

James Van Ornum55 Cornell DriveHazlet, N.J.

07730

Jim Pollock6 Terrace Ave.New Egypt, New Jersey

08533

Joel Swank#1864655 S.W. 142ndBeaverton, Ore. 97005

****************************************************

Here are the folks responsible. They eagerly await yourpraise, comments, criticism, indignation - whatever...Please do the courtesy of enclosing a self-addressedstamped (if possible) envelope (SASE) if you wish a reply.

176

Page 178: The First Book of KIM

8/6/2019 The First Book of KIM

http://slidepdf.com/reader/full/the-first-book-of-kim 178/178

5119-0

$8.95

THE FIRST BOOK OF KIMJIM BUTTERFIELO. STAN OCKERS, and ERIC REHNKE

Here is a step-by-step guide that wil l take yo u through the fundamentals ofwriting KIM programs. This beginner's guide includes dozens of examplesof programs that are run on a basic KIM-1 system. These programs include

games and puzzles such as Blackjack, Chess Clock, Horserace, LunarLander, Music Box, and Png Pong, which are fully described so that you

can learn from the programming techniques i l lustrated as well as have funplaying the games.

The authors go into detail on how you can expand your KIM from thebas>c small-but-powerful KIM-1 system to a huge-and-super-powerful ma-chir-e. They include diagnostic and utility programs to help you build extradevices onto your KIM system, such as teletype, display, or more memory.The book also covers the jargon of KIM programming and what 's available

in both hardware and sof tware i ' - > r the KIM microprocessor.

Other Books of interest...

HOW TO BUILD A COMPUTER-CONTROLLED ROBOTTOD LOCFBOURROW

Use the KIM-1 microprocessor t ; build your own computer-controlled robot,r