Fun Programs

General discussions related to the Altair 8800 Clone

Fun Programs

Hello all,

I am having a blast playing with my Altair Clone in CP/M.

I have a couple of fun programs that I like to play with whenever I am playing on a new system or playing around with a new programming language. Here's the first one - it figures out how many ways to make US \$1.00 from change. This code is for MBASIC on CP/M:

100 REM HOW MANY WAYS TO MAKE \$1.00 FROM CHANGE
110 REM
199 C=0
200 FOR P=0 TO 100 STEP 5
210 FOR N=0 TO 20
220 FOR D=0 TO 10
230 FOR Q=0 TO 4
240 IF (P+(N*5)+(D*10)+(Q*25))=100 THEN PRINT P;"PENNIES ";N;"NICKELS ";D;"DIMES ";Q;"QUARTERS" : C=C+1
250 NEXT Q
260 NEXT D
270 NEXT N
280 NEXT P
300 PRINT : PRINT C;"WAYS TO MAKE A DOLLAR FROM CHANGE"
310 END

So give it a try. It's fun to see how long different machines and different languages take to get this done. You can see that I cheated a little bit by putting in a "step 5" in the loop for pennies to shorten up the time a little bit.

What fun programs are you folks playing around with? Maybe you'd like to share one, too?

smp
smp

Posts: 12
Joined: March 12th, 2014, 6:45 pm

Re: Fun Programs

Hi again,

I was wandering around the Internet recently, and I came across a blog where the fellow was also playing around with MBASIC.

http://jefftranter.blogspot.com/2014/03 ... n-cpm.html

Here's a memory dump program that he devised, and I modified a little so it would not simply go on forever:

100 REM Dump memory in hex and ASCII
110 REM
110 A = &H100 : REM Start of transient program area in CP/M
115 L = 0 : REM Line counter
120 A\$ = "000" + HEX\$(A)
130 A\$ = RIGHT\$(A\$,4)
140 PRINT A\$;": ";
150 FOR I = 0 TO 15
160 S\$ = "0" +HEX\$(PEEK(A+I))
170 S\$ = RIGHT\$(S\$,2)
180 PRINT S\$;" ";
190 NEXT I
200 FOR I = 0 TO 15
210 IF PEEK(A+I) >= 32 AND PEEK(A+I) <= 126 THEN PRINT CHR\$(PEEK(A+I)); ELSE PRINT".";
220 NEXT I
230 PRINT
233 L = L+1 : REM Increment the line counter
235 IF L>63 GOTO 300 : REM Arbitrary stop after 64 lines of 16 bytes output
240 A = A+16
250 GOTO 120
300 END

This could be a good program to keep in a "toolbox" of programs for looking into what's going on inside the system.

I am looking forward to see what other folks come up with.

smp
smp

Posts: 12
Joined: March 12th, 2014, 6:45 pm

Re: Fun Programs

Went through old copies of Computer Notes this weekend and found a demonstration program
with reference to HAL from the movie 50 years ago. Made a few changes so I did not feel
upper cased all over the place.

Code: Select all
`newclear10 CLEAR20 REM From Computer Notes November 1976 Page 5. Revised to include input15 REM subroutines, Longer variable names, Flexable U/L case,17 REM Better Random seeding, 2K larger in size.30 PRINT TAB(10) "Hi! I'm a 70's computer. my name is HAL. what's yours?"40 INPUT "(type your name and hit the return key)";YOURNAME\$50 PRINT TAB(10) "Well ";YOURNAME\$;" a computer can do a lot of things. For instance, I"60 PRINT TAB(10) "am a super calculator. Let's try an easy one first."70 REM ----------------- LETTER COUNTING ----------------------80 PRINT TAB(10) "Would you like to ADD, SUBTRACT, MULTIPLY, DIVIDE or find"90 PRINT TAB(10) "a SQUARE or SQUARE ROOT?"100 INPUT "(type your choice and hit return)"; MATHCHOICE\$110 PASSSTRING\$ = MATHCHOICE\$120 GOSUB 960130 MATHCHOICE\$ = PASSSTRING\$140 IF LEFT\$(MATHCHOICE\$,1) = "D" THEN 220150 IF LEFT\$(MATHCHOICE\$,1) = "M" THEN 260160 IF LEFT\$(MATHCHOICE\$,1) = "A" THEN 300170 IF MATHCHOICE\$="SUBTRACT" THEN 330180 IF MATHCHOICE\$="SQUARE ROOT" THEN 360190 IF MATHCHOICE\$="SQUARE" THEN 380200 PRINT TAB(10) "I'm sorry. I don't understand ";MATHCHOICE\$;". Please try again" : GOTO 80210 REM         DIVIDE220 PRINT "First the Numerator you are dividing."230 PRINT "Not over 16 digits, please"; : INPUT A#240 INPUT "Now the Denominator (divisor)"; B# : C#=A#/B# : GOSUB 820250 REM         MULTIPLY260 INPUT "The first number to multiply (not over 16 digits)"; A#270 REM         SQUARE280 INPUT "The second"; B# : C#=A#*B# : GOSUB 820290 REM         ADD300 INPUT "The first number to Add (not over 16 digits)"; A#310 INPUT "The second"; B# : C#=A#+B# : GOSUB 820320 REM         SUBTRACT330 INPUT "The number you are subtracting from (not over 16 digits)"; A#340 INPUT "The number you are subtracting"; B# : C#=A#-B# : GOSUB 820350 REM         SQUARE ROOT360 INPUT "The number you wish to find the square root of";A#370 C#=SQR(A#) : GOSUB 820380 INPUT "The number you wish to square";A#390 C#=A#*A# : GOSUB 820400 REM --------------- LETTER COUNTING ----------------------410 PRINT TAB(10) "Had enough arithmetic ";YOURNAME\$;" Huh? of course i can do more"420 PRINT TAB(10) "complicated math too. But enough of that. Tell you what."430 PRINT "Type me a sentence now:" : LETTERCOUNT=0440 LINE INPUT SENTENCE\$450 PASSSTRING\$ = SENTENCE\$460 GOSUB 900470 PRINT TAB(10) "Now I'll tell you how many there"480 PRINT TAB(10) "are of any letter in your sentence."490 INPUT "What letter should I count";SEARCHLETTER\$500 IF LEN(SEARCHLETTER\$)>1 THEN PRINT "Only one character please." : GOTO 490510 IF SEARCHLETTER\$=>"A" AND SEARCHLETTER\$<="Z" THEN SEARCHLETTER\$ = CHR\$(ASC(SEARCHLETTER\$) + 32)520 IF SEARCHLETTER\$=>"a" AND SEARCHLETTER\$<="z" THEN 540530 PRINT TAB(10) "Please, a letter." : GOTO 490540 FOR INDEXCOUNT%=1 TO LEN(SENTENCE\$) : IF MID\$(PASSSTRING\$,INDEXCOUNT%,1)=SEARCHLETTER\$ THEN LETTERCOUNT=LETTERCOUNT+1550 NEXT INDEXCOUNT%560 PRINT TAB(10) "There are";LETTERCOUNT;SEARCHLETTER\$;"'s in your sentence:"570 PRINT TAB(10) SENTENCE\$580 REM ------------------NUMBER GUESING ---------------------590 PRINT TAB(10) "How bout them apples? Now let's play a simple number"600 PRINT TAB(10) "guessing game. I'll choose a number between 1 and 100."610 PRINT TAB(10) "You tell me what you think it is. I'll tell you if"620 PRINT TAB(10) "you are too high, too low or correct."630 RANDOMIZE LEN(SENTENCE\$)640 A=INT(99*RND(1)+1) : GUESSES=0650 PRINT TAB(10) "OK, I've got a number."660 INPUT "Your guess"; B670 IF B>A THEN PRINT TAB(10) "Too high" : GUESSES=GUESSES+1 : GOTO 660680 IF B<A THEN PRINT TAB(10) "Too low" : GUESSES=GUESSES+1 : GOTO 660690 PRINT TAB(10) "You guessed it - in ";GUESSES;" tries!"700 INPUT "Try again";YESNOANSWER\$710 GOSUB 790720 IF LEFT\$(YESNOANSWER\$,1) = "y" THEN 640730 IF LEFT\$(YESNOANSWER\$,1) = "n" THEN 750740 PRINT TAB(10) "Sorry, i don't understand ";YESNOANSWER\$;". please use YES or NO." : GOTO 700750 PRINT TAB(10) "Now wasn't that marvelous ";YOURNAME\$;"? and so ends"760 PRINT TAB(10) "the demonstration. Good bye my friend." : END770 REM ------ Subroutines ------780 REM Yes No answer. Convert first character to lower case790 YESNOANSWER\$ = LEFT\$(YESNOANSWER\$,1)800 IF YESNOANSWER\$=>"A" AND YESNOANSWER\$<="Z" THEN YESNOANSWER\$ = CHR\$(ASC(YESNOANSWER\$) + 32)810 RETURN820 REM Full Math answer and continue830 PRINT TAB(10) "The answer is: ";C#840 INPUT "Try another calculation (YES or NO)"; YESNOANSWER\$850 GOSUB 790860 IF LEFT\$(YESNOANSWER\$,1) = "y" THEN 80870 IF LEFT\$(YESNOANSWER\$,1) = "n" THEN 410880 PRINT TAB(10) "I'm sorry I don't understand "YESNOANSWER\$;". Please use YES or NO." : GOTO 840890 RETURN900 REM Case Conveter to all lower910 FOR X%=1 TO LEN(PASSSTRING\$)920     TEMP\$=MID\$(PASSSTRING\$,X%,1)930     IF TEMP\$=>"A" AND TEMP\$<="Z" THEN MID\$(PASSSTRING\$,X%) = CHR\$(ASC(TEMP\$) + 32)940 NEXT X%950 RETURN960 REM Case Conveter to all UPPER970 FOR X%=1 TO LEN(PASSSTRING\$)980     TEMP\$=MID\$(PASSSTRING\$,X%,1)990     IF TEMP\$=>"a" AND TEMP\$<="z" THEN MID\$(PASSSTRING\$,X%) = CHR\$(ASC(TEMP\$) - 32)1000 NEXT X%1010 RETURN`

By having New and Clear a few lines above the top of your source code mbasic will use them as commands before

Kinda nostalgic.
TimC

Posts: 3
Joined: May 6th, 2017, 12:28 pm 