Porters_Programs_for_the_Commodore_64.pdf

download Porters_Programs_for_the_Commodore_64.pdf

of 166

Transcript of Porters_Programs_for_the_Commodore_64.pdf

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    1/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    2/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    3/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    4/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    5/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    6/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    7/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    8/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    9/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    10/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    11/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    12/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    13/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    14/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    15/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    16/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    17/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    18/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    19/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    20/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    21/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    22/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    23/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    24/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    25/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    26/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    27/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    28/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    29/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    30/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    31/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    32/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    33/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    34/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    35/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    36/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    37/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    38/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    39/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    40/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    41/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    42/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    43/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    44/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    45/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    46/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    47/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    48/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    49/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    50/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    51/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    52/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    53/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    54/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    55/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    56/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    57/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    58/166

    4 6 PORTER S PROGRAMS FOR THE COMMODORE 6 @l

    Liquid MeasurementsThis is a really easy program to set up. Just load the distanceprogram into memory and change lines 100, 270, and the DATAstatements. You ll then have a program that converts among:

    Cups Pints Quarts (U.S.)

    Imperial quarts Gallons (U.S.) Imperial gallons Liters

    NEW100 REM LIQUID MEASUREMENTS110 D = 7129 DIM C O , O ) , N ( O )130 FOR X = 1 TO D140 READ X$, C(X,0)150 NEXT X: RESTORE160 FOR Y = 1 TO D170 READ N ( ' Y ) , C( 0, Y180 NEXT Y

    190 REM CONVERSION FACTORS GRID200 FOR X = 1 TO D210 FOR Y = 1 TO D220 C(X,Y) = C(0,Y) / C(X,0)230 NEXT Y240 NEXT X259 REM SCREEN SETUP260 PRINT CHR$(147)270 PR INT Ll QUI D MEASUREMENTS:II280 FOR X = 1 TO D290 PRINT TAB(5); X; N$(X)390 NEXT X: PRINT310 INPUT CCNJERTTO ; Y320 PRINT CHR$(145) CONVERT TO H N$(Y)330 PRINT: INPUT HCONVERT FROMH; X

    340 PRINT CHR$( 145) CONVERTFROM

    N$(X)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    59/166

    Weights and Measures 47

    359 PRINT: PRINT uHCl

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    60/166

    48 PORTER'S PROGRAMS FOR THE COMMODORE 64@l

    HEI>.jlee R E ~ ** RECI PE CHANGER1113 PRINT CHR$( 147120 PRINT RECIPE CHANGER: : PRINT130 IHPUT NUI'1BER RECIPE SERIJES ; R Q1413 INPUT NUMBER YOU'RE SERVING ; sa15 CF = SQ / RQ1,513 REM MAIN LOOP170 PRINT: INPUT II QUANTITY ; Q$1813

    IF Q$ = 0 THEN END1 10 L = LEN( Q$): X = 1: SL = 1: Q = 02913 FOR P = 1 TO L210 IF MID$(Q$, P, 1) = / THEN 24022 NEXT P23 Q = IJAL (Q$) : GOTO 3602413 FOR P = 1 TO L250 IF MID$(Q$,P, 1 = H THEN SL = P: GOTO 28026 NEXT P270 GOTO 2992:30 Q = tJAULEFT$(Q$, P : X = P + 12 113 FOR P = X TO L3013 IF MID$(Q$, P, 1 = / THEN 3303113 NEXT P .320 PRINT BAD INPUT : GOTO 16133313 N = tJAU M D$ ( Q$, SL, P - S U )340 D = IJAU R GHT$( Q$, L - P3513 F = N D: Q = Q + F360 REM ** FIGURE QUANTITY3713 Q = Q * CF: W = INT(Q)380 F = Q - W: F$ =3913 IF F ) = .95 THEN W = W +413 PRINT CHAI'IGE TO W;410 RH1 H FRACTIOt'-l4213 IF F ( .136 THEN 510430 IF F ( .95 THEN F$ = 7/S440 IF F ( .S2 THEN F$ = 3 /4450 IF F ( .7 THEN F$ = U 2/3469 IF F ( .6 THEN F$ = II 1/2

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    61/166

    Weights nd easures 4 9

    470 IF F ( .4 THEN F = U 1/3480 IF F ( 3 THEN F = 1/4490 IF F (

    18 THENF = 1/8500 PRINT F

    510 PRINT: PRINT: GOTO 160RUN

    Sample r l Jn

    RECIPE CHANGER:

    NUMBER RECIPE SERVES? 5NUMBER YOU'RE SERVING? aQUANTITY? 1 1/3CHANGE TO 2 1/8

    QUANTITY? 3 4CHANGE TO 1 1/4

    QUANTITY? 2 112CHANGE TO 4

    QUAt ..JTITY? e

    READY

    emperature Co-nversionBack in the olden days they called it Centigrade, but nowadays it'sCelsius. No doubt someone knows why. At any rate, it's the metric

    way of measuring temperatures, in which water freezes at 00

    andboils at 100, rather than at the capricious Fahrenheit marks of 32 0and 212. This program converts from one system to the other, witha menu that lets you pick which converstion you want to make.Using it, you'll know whether to be hot or cold when the tempera-ture is 40C.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    62/166

    5 PORTER S PROGRAMS FOR THE COMMODORE 64@

    NEW109 REM ~ ~ TEMPERATURECONVERSION119 DEF FNC(X) = 5/9) (X - 32)129 DEF FNF(X) = 9 / 5 X) + 32130 DEF FNR(X) = INTX * 19) + .5) 19149 REM CONVERSIONlOOP159 PRINT CHR$(147)169 PRINT TEMPERATURECONVERSION:179 PRINT

    189 PRINT 1 CELSIUS TO FAHRENHEIT199 PRINT 2 FAHRENHEIT TO CELSIUS209 PRINT: INPUT WHICH ; X219 PRINT: INPUT TEMPERATURE ; T229 PRINT: PRINT230 IF X = 2 THEN 280240 REM ~ CEl TO FAHR250 PRINT

    TDEGREES

    C = ;260 PRINT FNR(FNF(T DEGREES F279 GOTO 310280 REM FAHR - eEL299 PRINT T DEGREES F = ;300 PRINT FNR(FNC(T DEGREES C310 PRINT: INPUT ANOTHER (YIN) ; X$320 IF X$ = y THEN 140330 END~

    Sample r u n

    TEMPERATURECONVERSION:

    1 CELSIUS TO FAHRENHEIT2 FAHRENHEIT TO CELSIUS

    WHICH? 1

    TEMPERATURE?40continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    63/166

    Weights and easures 5

    4 DEGREES C 1 4 DEGREES F

    ANOTHER YIN)?

    READY

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    64/166

    SECTION 3SORTING NDTEXT PROCESSING

    Sorting a Group of Numbersorting is the process of rearranging unorganized information into

    an orderly sequence. This program takes numbers and puts theminto ascending order lowest to highest in value), with the results

    displayed on the screen in a left-to-right fashion. The display holdsup to 88 numbers before lines begin to scroll off the top, so isthe limit of the sort size. When you enter 0 the program stopsaccepting numbers and begins sorting.

    NEW

    109 REM NUMERIC SORT119 PRINT CHR$(147)120 PRINT -NUMERIC SORT : PRINT139 PRINT MENTER NUMBERS ONE AT A TIME149 PRINT -ENTER e TO START SORTa159 DIM A 87)160 N 0170 REM INPUT LOOP

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    65/166

    Sorting and Text rocessing 5

    189 INPUT A N)199 IF A N) = 9 THEN 229209 N = N + 1210 IF N = 87 THEN 189220 REM SORT230 L = 999999: M = 8240 FOR P = 0 TO N - 1259 IF A P) < L THEN L = A P): M = P268 NEXT P270 IF L = 999999 THEN END288 PRINT L290 A M) = 999999300 GOTO 220RU

    Sample run:

    NUMERIC SORT

    ENTER NUMBERS ONE AT A TIMEENTER 0 TO START SORT? 9? 73? 55

    ? 37? 19? 29? 46? 64? 92? e

    195591

    READY

    2964

    3773

    4692

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    66/166

    5 4 PORTER S PROGRAMS FOR THE COMMODORE 64@

    Descending SortSometimes it s useful to sort numbers into descending order (highestto lowest in value), which produces a result that is exactly oppositethat of the preceding program. This program works the same in allother respects.

    NEW

    188 REM ~ DESCENDING SORT118 PRINT CHR$( 147)120 PRINT IDESCENDING SORT I : PRINT138 PRINT ENTER NUMBERS ONE AT A TIMEU148 PRINT IENTER 8 TO START SORT I159 DIM A(87)160 N = 8178 REM ~ INPUT LOOP

    180 INPUT A(N)198 IF A(N) = 0 THEN 220208 N = N + 1210 IF N = 87 THEN 180220 REM SORT230 L = 1: M= 0240 FOR P = 8 TO (N - 1)250 IF A(P) ) L THEN L = A(P): M = P260 NEXT P279 IF L = -1 THEN END280 PRINT L,299 A(M) = 1389 GOTO 220

    ~

    Sample run:

    NtJ1ERIC SORT

    ENTER NUMBERS ONE AT A TIMEENTER 0 TO START SORT? 91

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    67/166

    Sorting and Text rocessing

    ? 73? 55? 37? 19? 8? 46? 64? 8? 0

    91 8 73 6455 46 37 819

    READY.

    Text AnalysisAlthough the word computer suggests (and the majority of us-ages confirms) a machine devoted exclusively to doing calculations,computers can also process and analyze text in various ways. This'program demonstrates simple text analysis by taking any line youtype and telling you the number of words it contains, the length ofthe line, and the number of occurrence's of each character. Theonly character you cannot use is a comma, since the INPUTinstruction thinks a comma separates two different data itemsentered on the same line. The counts of individual characters do notinclude SPACEs, although the number of SPACEs is included in thetotal. Also, if you have two or more SPACEs together, they willinflate the word count; the program assumes one SPACE betweeneach word and no SPACE at the start of the text.

    NEW100 REM TEXT ANALYSIS110 PRINT CHR$(147)120 DIM CH 255)130 REM U GET AND ANALYZE TEXT140 PRINT -ENTER A LINE OF TEXT150 INPUT TX$: PRINT

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    68/166

    6 PORTER S PROGRAMS OR THE COMMODORE 64@

    160 LT = LEN(TX )178 FOR P = 1 TO LT180 V = ASC(MID (TX , P, 1199 CH(V) = CH V,) 1208 NEXT P218 REM DISPLAY RESULTS229 W = CH(32) 1239 PRINT CONTAINS LT CHARACTERS ;249 PRINT IN W WORDS258 FOR P = 0 TO 255269 IF P = 32 THEN 298279 IF CH(P) = 9 THEN 299280 PRINT TAB(8) CHR (P) CH(P)290 NEXT P300 END

    ~

    Sample r un

    ENTER A LINE OF TEXT \? THIS LINE IS GOING TO BE ANALYZED

    CONTAINS 33 CHARACTERSIN 7 WORDSA 2B 1

    D 1E 3G 2H 1I 4L 2N 3o 2S 2T 2Y 1Z 1

    READY.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    69/166

    Sorting and Text rocessing 7

    eversing TextTo see another example of text processing type a line and theCommodore 64 immediately displays i t backwards. It repeats asmany times as you want. Stop it by entering the number 0.

    NEW

    lee REM TEXT REVERSER110 PRINT CHR$(147129 PRINT: PRINT ENTER A LINE OF TEXT130 INPUT X$140 IF X$ = 0 THEN END150 PRINT U ;160 FOR P = LEN(X$) TO 1 STEP -1170 PRINT MID$(X$, P 1);180 NEXT P190 PRINT2 GOTO 120RUN

    Sample run:

    ENTER A LINE OF TEXT? THIS LINE WILL APPEAR BACKWARDS

    SDRAWKCAB RAEPPA LLIW ENIL SIHT

    ENTER A LINE OF TEXT? 0

    READY

    lphabetizingThe process of alphabetizing a list differs little from sorting agroup of numbers. The computer compares entries in the list andselects the one whose ASCII value is the lowest. In this particularprogram a selected entry is printed and then the program changes

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    70/166

    5 8 PORTER S PROGRAMS FOR THE COMMOOORE 64@J

    that entry to the highest possible ASCII value so it won't beselected again. You can alphabetize up to 25 entries with this

    program. During the input phase, a /) signals the end of the hst,and the program then sorts and displays the hst in alphabeticorder.

    NEW

    100 REM ALPHABETIZE110 PRINT CHR$(147): X$ = CHR$(255)

    120 PRINT -ALPHABETIZE A LIST-130 PRINT ENTER ITEMS ONE T A TIME140 PRINT ENTER 0 TO END LIST150 DIM L (25)160 N = 0170 REM INPUT LOOP180 INPUT L$(N)190 IF L$(N) = 0 Y THEN PRINT: GOTO 220

    89 N = N + 1210 IF N = 25 THEN 170220 REM H ALPHABETIZE238 C$ = X : M= 9240 FOR P = 0 TO (N - 1)250 IF L$(P) ) = C$ THEN 270269 C$ = L (P): M = P270

    NEXTP280 IF C$ = X$ THEN END

    290 PRINT C309 L$(M) = X$310 GOTO 220RUN

    Sample run:

    ALPHABETIZE A LISTENTER ITEMS ONE T A TIMEENTER 0 TO END LIST

    ? JOIf .I? MARIANNE? BETH

    ? M RY

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    71/166

    Sorting and Text Processing 9

    ? LUISA? ZEI

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    72/166

    6 PORTER S PROGRAMS FOR THE COMMODORE 6 @J

    289 N = N + 1218 IF N = 25 THEN 178

    229REM ~

    ALPHABETIZE239 C = X : M = 0240 FOR P = 0 TO (N - 1)250 IF L (P)(= C THEN 270269 C = L (P>: M = P279 NEXT P289 IF C = X THEN END290 PRINT C390 L (M) I X310 GOTO 229

    ~

    Sample run:

    REVERSE ALPHABETIZE A LISTENTER

    ITEMSONE AT

    A TIMEENTER 0 TO END LIST? JOHN? MARIANNE? BETH? MARY? LUISA? ZEl

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    73/166

    SECTION

    PROGR MS H VING TOO WITH MONEY

    oan Terms

    So you're thinking about borrowing some money, are you? he bigquestion is, how much will it cost you, given a certain interest rateapplied t the amount over time? Since lenders usually calculateinterest on the declining balance, estimating the monthly payment

    with any degree of accuracy is no simple task.This program figures it for you within a penny, giving you themonthly and final payments and the total amount you'll repay thelender. hat entails quite a lot of work, s there is a brief delaywhile the program thinks. This is a very useful program that letsyou play what i f with differing interest rates, repayment terms,and borrowed amounts. I t repeats until you tell it you want toborrow $0.

    NEW

    189 REM LO N TERMS110 DEF F N M X ) = I N T X * M P ) ~ 1 0 0 ) + . 5 ) / 1 9 8129 PRINT CHRS(147)130 PRINT LOAN TERMS : PRINT

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    74/166

    6 PORTER S PROGRAMS FOR THE COMMODORE 6 @l

    148 INPUT AHOIJ'.IT OF LOAN H; A158 IF A = 8 THEN END160 INPUT -ANNUAL INTEREST RATE H; AI178 INPUT HNUMBER OF PAYMENTS H; NP188 REM U COMPUTE TERMS198 IF AI ) 1 THEN AI = AI / 180290 MP = AI / 12218 F = MP + 1: T = F220 FOR C = 2 TO NP238 T = T F240 NEXT C250 PF = 1 / T268 SMP = A (MP / 1 - PF279 SMP = INT SMP 188 / 188 + .01280 CB = A290 FOR C = 1 TO NP - 1)390 CB = N T C B - S M P + F N M C B ~ 1 0 0 ) / 1 0 0310 NEXT C320 FP = CB + FNM CB)338 TP = SMP NP - 1 + FP340 REM PRINT RESULTS350 PRINT360 PRINT NP-l PAYMENTS OF- TAB 30) S

    SMP370 PRINT AND A FINAL PAYMENT OFH TAB

    38) HS FP380 PRINT390 PRINT FOR A TOTAL OF S TP400 PRINT: PRINT: GOTO 148RUN

    Sample run:

    LOAN TERMS

    AMOUNT OF LOAN ? 3580ANNUAL INTEREST RATE ? 18NUMBER OF PAYMENTS ? 36

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    75/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    76/166

    6 4 PORTER'S PROGRAMS FOR THE COMMODORE@ 6 4 l t ~

    NEl-j

    lee REM ** LOAN ANALYSIS110 PRINT CHR$( 147)120 QI$= PRINCIPAL AMOUNT : 1)2$= MONTHLY PAYMENT

    130 tD$= NUHBER OF PAYMENTS : Q4$= ANNUAL ' / INTEREST 140 GOTO 220150 REM ** GET FACTORS1 ~ 0 PRINT 1)1$;: INPUT V: RETUf

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    77/166

    Programs aving to 00 with Money 6

    599 130TO 511361313 REM QUIT OR REPEAT619 PRINT: INPUT NAI'lOTHER RUN (YIN) ; R

    620 IF R$= Y THEN PRINT:PRINT:GOTO 2213639 ENDRUN

    Sample run: In the i r s t case, the monthly payment i s unknot-Jn. Inthe second run, the terms are the same but the annual percentin teres t ra te i s indicated as unknown. The thinking messageappears because th is computation causes a delay.

    LOAN ANALYSIS:

    ENTER 9 FOR THE UNKNOWN

    PRINCIPAL AMOUNT ? 190013MONTHLY PAYMENT ? 3NUMBER OF P Y M E N T S ~120ANNUAL i INTEREST? 10.135

    MONTHLY PAYMENT $ 132.42

    ANOTHER RUN (YIN)? Y

    LOAN ANALYSIS:

    ENTER e FOR THE UNKNOWN

    PRINCIPAL AMOUNT ? 190130MONTHLY PAYMENT ? 132.42NUMBER OF PAYMENTS? 120ANNUAL :: INTEREST ? 0THINKING

    ANNUAL INTEREST HI.0485992

    ANOTHER RUN (YIN)? N

    READY.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    78/166

    PORTER S PROGRAMS OR THE COMMOOORE 64@

    Interest Paid Over a PeriodHere's a lifesaver during income tax time, when you have toitemize interest deductions for the year on your home mortgage,car loan, and so on. This program figures up how much interestyou paid over a period bracketed by two payments: say in Januaryyou made payment #19 and in December, payment 30. If you knowthe annual interest rate, the monthly payment, and the total number of payments over the life of the loan, the program tells you the

    interest cost for that period. As a fringe benefit, it also gives youthe starting and ending balances for the period.

    NEW

    HHI REM INTEREST PAl D110 PRINT CHR$(147)120 PRINT INTEREST OVER A PERIOD: :PRINT130 PRIt-.JT MONTHLY PAYMEt-.JT TAB( 28) ;140 INPUT P150 IF P = 0 THEN END160 PRINT ANNUAL INTEREST RATE TAB(28);170 INPUT J180 IF J ) I THEN J = J 100190 1 = .J I 12200 PRINT TOTAL PAYMENTS IN LOAN ;210 PRINT

    TAB(28);:INPUT

    T220 PRINT # OF FIRST PMT IN PERIOD ;230 PRINT TAB(28);: INPUT PI: Pl=P1-1240 PRINT ft OF LAST PHT IN PERIOD ;250 PRINT TAB(28);: INPUT P2: PRINT260 DEF FNI(X) = (1 + I)AX270 DEF FNR(X) = INT(X * 100) I 1280 IP = P * (P2 - PI - (FNI(P2-T)/I) +FNI (P I-T) I I290 Bl = (P I) * (1 - FNI(Pl - T300 B2 = (P I) * (1 - FNI(P2 - T310 PRINT INTEREST OIJER PERIOD: $ ;320 PRINT FNR(IP): PRINT330 PRINT STARTING BALANCE:340 PRINT FNR(BI)3513

    PRINT ENDING BALANCE:

    $

    $

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    79/166

    Programs aving to 00 with oney 7

    360 PRINT FNR(B2)370 PRINT: PRINT: GOTO 130RUN

    Sample rlJn:

    INTEREST OJER A PERIOD:

    MONTHLY PAYMENTANNUAL INTEREST RATETOTAL PAYI 1ENTS IN LOAN# OF FIRST PMT IN PERIOD# OF LAST PMT IN PERIOD

    ? 285.36? 8 5? 360? 168? 179

    INTEREST OVER PERIOD: $ 2512.43

    STARTING BALANCE:ENDING BALANCE:

    MONTHLY PAYMENT:

    READY.

    $ 2 71 7169.63$ 2'?057. 75

    ? 3

    Present Worth of a Future mount

    This and the following three programs deal with various aspects ofthe time value of money. f you have a certain amount of moneytoday and interest applies to it, it will increase in value with time;conversely, i you want to have a certain amount of money severalyears from now, you can use the time value to calculate how muchthat amount is worth today. All of these programs assume continuous compounding, which most banks and financial institutionsuse. Inflation and taxes are not considered.

    The present worth of a future amount, though self-explanatory,is a stuffy economists' term. What it means is: If you want to havea certain amount of money after so many years, how much do you

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    80/166

    8 PORTER S PROGRAMS FOR THE COMMODORE 64@

    have to put in the bank, given a fixed interest rate? This program,then, tells you the lump sum to invest today in order to meet an

    objective several years from now.

    N E ~

    100 REM PRESENT ~ O R T HOF FUTURE HT110 PRINT CHR$(147)129 PRINT PRESENT WORTH: : PRINT139 INPUT FUTURE MOUNT . F

    140 IF F = 0THEN END

    150 INPUT INTEREST R TE ; I160 INPUT NUMBER OF YE RS ; N170 IF I ) 1 THEN I = I 100180 J = LOG(1 + I) LOG(2.71828)190 PF = 1 1 + I)AN)299 PW = F * PF210 REM DISPLAY RESULTS229 PW = INT(PW * 109) / 190230 PRINT: PRINT240 PRINT PRESENT WORTH IS $ ; PW250 PRINT: PRINT . - - - - - - - - - - - - - - - -269 PRINT: GOTO 139R\J 4

    Sample run:

    PRESENT ~ O R T H

    FUTURE MOUNT ? 20900INTEREST R TE ? 10.SNUMBER OF YE RS ? 10

    PRESENT WORTH IS $ 7368.97

    FUTURE MOUNT ? 20090INTEREST R TE ? 11.5NUMBER OF YE RS ? 10

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    81/166

    Programs Having to o with Money 9

    PRESENT WORTH IS $ 6734.12

    FUTURE AMOLNT ? 9

    READY

    This sample run means that if you want $20,000 ten years from

    now, you have to invest $7368.97 at 10.5 percent interest or$6734.12 at 11.5 percent. Obviously, the amount of up-frontmoney varies greatly with the interest rate.

    Future orth of a Present Amount

    This is the opposite of the preceding program, but the same as

    sumptions apply concerning continuous compounding. Future worthanswers such questions as, If I make a one-time deposit of acertain amount in a savings account, how much will it be worthafter some number of years, given a fixed interest rate?

    NEW109 REM ~ ~ FUTURE WORTH OF PRESENT AMT

    119 PRINT CHR (147)128 PRINT MFUTURE WORTH:-: PRINT139 INPUT PRESENT AMOUNT ; P149 IF P = 8 THEN END159 INPUT INTEREST RATE M; I169 INPUT M NUMBER OF YEARS M; N179 IF I ) 1 THEN I = I / 199189 J = LOG(l I) / LOG(2.71828)198 FF = (1 I)AN299 FW = P FF218 REM ~ DISPLAY RESULTS229 FW = INT(FW 189) / 199239 PRINT: PRINT249 PRINT -FUTURE WORTH IS H; FW

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    82/166

    7 PORTER S PROGRAMS FOR THE COMMODORE@ 64@)

    250 PRINT: PRINT M

    269 PRINT: GOTO 130RUN

    Sample run:

    FUTURE WORTH

    PRESENT AMOUNTINTEREST RATENUMBER OF YEARS

    ? 5000? 9 65? 15

    FUTURE WORTH IS 19911.29

    PRESENT AMOUNTINTEREST RATENUMBER OF YEARS

    ? 5000

    ? 10.5? 5

    FUTURE WORTH IS 22356.51

    PRESENT AMOUNT ? 0

    READY

    This display means that i f you have 5000 and you invest it at9,65 percent interest, after 15 years i t will be worth 19,911.29,and i f you're fortunate enough to earn 10.5 percent on it, it will beworth 22,356.51 after 15 years. A small variation in the interest

    rate, then, can greatly influence the time value of money.

    Saving Toward a Future AmountLet's suppose you're a parent and you want to set up a savingsplan to put the kid through college. Your objective is to have

    30,000 fifteen years from now. How much do you have to saveper month, given a fixed interest rate and continuous compounding,

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    83/166

    Programs Having to 00 with Money 7

    to reach this goal? (Or let's say you're not a parent, but you want totake a fabulous trip around the world.) This program helps youestablish a savings plan toward a specific amount.

    NEW

    190 REM U MONTHLY SAIJINGS PLAN110 PRINT CHR$(147)120 PRINT SAVING PLAN: : PRINT130 INPUT YOUR GOAL ; F140 IF F = 0 THEN END150 INPUT INTEREST RATE ; I160 INPUT NUMBER OF YEARS ; N170 IF I ) 1 THEN I = I / 100180 J = LOG(l + I / LOG(2.71828)190 AF = J / ( 1 + I)AN) - 1)200 M = F AF) / 12210 REM D SPLAY RESULTS220 M

    =INT(M f 100) / 100

    230 PRINT: PRINT240 PRINT A ~ 1 U N TTO SAtJE 11 NTHLY IS $ M250 PRINT: PRINT - - - - - - - - - - - - - - - -269 PRINT: GOTO 130RUN

    Sample run:

    SAVINGS PLAN:

    YOUR GOAL

    INTEREST RATENUMBER OF YEARS

    ? 30900? 8.65? 15

    AMOUNT TO SAIJE MONTHLY IS $ 83.93

    YOUR GOAL ? 30000INTEREST RATE ? 9.6NUMBER OF YEARS ? 15

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    84/166

    7 2 PORTER'S PROGRAMS FOR THE COMMODORE' 6 t ~

    At 10Ut H TO SAl)E t 10t'HHU' IS $ 77.54

    \'OUR GO L

    READY

    Annuity From a Present AmountThis is somewhat different from the preceding programs having todo with the time value of money. They dealt with building towardthe attainment of a measure of financial independence, whereasthis problem assumes you've reached that enviable plateau andnow you want to spend it.

    Let's say you've come into a $100,000 inheritance and you have

    decided to live it up. You want it to last five years, at the end ofwhich you won't have a penny left. How much can you spend permonth, given compounding interest on the balance?

    This program, of course, also pertains to establishing a pension,the idea being to set aside a certain amount that has to last for aspecified period of time. In other words, this program answers thequestion If I put $P in the bank at 1 percent, how much can Itake out each month to have it last N years?

    NEW

    100 REM ** ANNUITY FROM A PRESENT MT110 PRINT CHR$( 147)120 PRINT IANNUITY: : PRINT130 INPUT INITIAL MOUNT140 IF P = e THEN END150

    INPUTINTEREST R TE

    160 INPUT I NUMBER OF YE RS170 IF I ) 1 THEN I = I I 1

    ; P

    ;I; N

    180 J = LOG(l + I) LOG(2.71828)190 F = (J*(l+I)AN) l+I)AN-l)200 M = (P *AF) I 2210 REM ** DISPLAY RESULTS220 M = INT(MA * 100) 100

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    85/166

    Programs aving to 00 with Money 7

    23 PRINT: PRINT24 PRINT aMONTHLY PAYOUT IS $ ; MA25 PRINT: PRINT - - - - - - - - - - - - - - - -269 PRINT: GOTO 13RUN

    Sample run:

    A ,, ,UITY :

    INITIAL AMOUNTINTEREST RATENUMBER OF YEARS

    , ? 100000? 7.5? 5

    MONTHLY PAYOUT IS 1986.12

    INITIAL AMOUNTINTEREST RATENUMBER OF YEARS

    ? 100000? 6.5? 5

    MONTHLY PAYOUT IS 1942.81

    INITIAL AMOUNT ? 0

    READY.

    ease v Purchase AnalysisIt has become increasingly popular for individuals to lease big-ticket items, such as cars, pianos, and entire suites of homefurnishings. The assumption is that things wear out and have tobe replaced, and besides, they're usually bought on credit, soleasing is about the same as buying.

    But is t really? Which is the more advantageous to you, theconsumer? The answer, of course, depends on many factors. This

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    86/166

    74 PORTER S PROGR MS FOR THE COMMODORE 64@>

    program helps you analyze the real costs of leasing versuspurchasing. It does not consider the tax advantages pro or oneither alternative, as those vary widely with circumstances, nordoes it take into account hidden costs, such as the loss ofinterest if you withdraw money from savings to buy the item.

    The salvage category covers the estimated trade-in value at theend of the item's expected life, or, in other words, how much youthink you will be able to sell it for. Depreciation can be viewed asa reserve fund set aside to replace the item. It assumes an amountequivalent to the purchase price, without regard for inflation. Both

    of these are deferred noncash effects that you experience at theend of the purchase's life, and that is why they are separated onthe analysis report.

    NEW100 REM LEASE/PURCHASE ANALYSIS110 PRINT CHR$(147)

    129 PRINT RLEASE/PURCHASE COMPARISON:-130 PRINT: INPUT -DESCRIPTION-; 1$149 PRINT150 PRINT: PRINT -OPERATING EXPENSES:160 INPUT -FUEL AND OILlYEAR ; Gl170 INPUT -POWERIYEAR R; G218e INPUT aSUPPLIESIYEAR ; G3190 INPUT -OTHER MISC/YEAR ; G4290 PRINT: PRINT -LEASE OPTION:u210 INPUT MONTHLY PAYMENT u; L1220 INPUT aINSURANCE/YEAR ; L2239 INPUT aTAXESlYEAR - ; L3240 INPUT -LICENSESIYEAR ; L4259 INPUT - REPAI RS MTNCEIYEAR ; L5269 PRINT: PRINT -PURCHASE OPTION:

    279 INPUT -PURCHASE PRICE R; Pl280 INPUT REST. LIFE IN YEARS u; Y290 INPUT FINANCING EXPENSE R; P6390 INPUT -INSURANCE/YEAR ; P2310 INPUT aTAXESlYEAR ; P3320 INPUT aLICENSESIYEAR ; P4339 INPUT aREPAIRS MTNCEIYEAR ; P5340 INPUT aSALVAGE VALUE ; P7

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    87/166

    Programs Having to o with oney 7

    350 REM ~ LEASE AND GENERAL COSTS360 Al = Ll A2 = L2 / 12

    370 A3 = L3 / 12 A4 = L4 / 12380 AS = LS / 12 A6 = 0399 A7 = Gl / 12 A8 = G2 / 12400 A9 = G3 / 12 B1 = G4 / 12410 L9 = Al+A2+A3+A4+A5+A7+A8+A9+Bl420 REM ~ PURCHASE COSTS439 82 = P2 / 12449 B3 = P3 / 12 : 84 = P4 / 12459 85 = P5 / 12 : 86 = P6 / Y / 12460 P9 = B2+B3+84+B5+B6+A7+A8+A9+Bl470 C2 = P7/12lY : C3 = PI / Y / 12480 T = P9 - C2 + C3490 REM ~ DISPLAY ANALYSIS590 PRINT CHR (147): PRINT510 PRINT -LEASE/PURCHASE FOR I :PRINT

    520 PRINT TAB(18) LEASE TAB(29) PURCHASE530 X$=HO. PAYMENT R: X1=Al: X2=0 : GOSUB 800540 X$=INSURANCE :Xl=A2:X2=B2:GOSUB800559 X$= TAXES :Xl=A3:X2=B3:GOSUB 800560 X$= LICENSES :X1=A4:X2=B4:GOSUB 800570 X$=aHAINTENANCE :Xl=A5:X2=B5:GOSUB800580 X$= INTEREST :X1=A6:X2=B6:GOSUB800590 X$=RFUEL AND OIL :X1=A7:X2=A7: GOSUB

    8 8600 X = a p ~ E R u610 X$=RSUPPLIES620 X$=HMISC.H

    :Xl=A8:X2=A8:GOSUB 899:Xl=A9:X2=A9:GOSUB 899:X1=Bl:X2=B1:GOSUB 800

    630 PRINT TAB(18)- - - - - - - -

    TAB(29)- -

    - - - - - -

    640 X$= CASH EXP/MOB: Xl=L9: X2=P9650 GOSUB 800: PRINT660 X$= - SALVAGEa :Xl=0:X2=C2:GOSUB 800670 X =U + DEPREC. :Xl=0:X2=C3:GOSUB 800

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    88/166

    7 PORTER S PROGRAMS OR THE COMMODORE 64@

    680 PRINT TAB(18) 8 H TAB(29) - -

    690 X$=8NET EXPIMO :Xl=L9:X2=T:GOSUB890700 END800 REM ** FORMAT OUTPUT LINE810 DEF FNR(X) = INTX*199)+.499)/100820 PRINT X j830 PRINT TAB(17) $ FNR Xl);840 PRINT TAB(28) . FNR(X2)850 RETURN

    Sample run:

    LEASE/PURCHASECOMPARISON

    DESCRIPTION? NEW CAR

    OPERATING EXPENSES:FUEL AND OIL/YEARP ~ E R y E A R

    SUPPLIES/YEAROTHER MISe/YEAR

    LEASE OPTION:MONTHLY PAYMENTINSURANCE/YEARTAXES/YEARLICENSES/YEARREPAIRS MTNCE/yR

    PURCHASE OPTION:PURCHASE PRICEEST. LIFE IN YEARSFINANCING EXPENSEINSURANCE/YEARTAXES/yEARLICENSES/YEARREPAIRS ~ MTNCE/YRSALVAGE VALUE

    ? 1209? 9? 250? 308

    ? 249.81? 625? 0? 55? 100

    ? 11800? 4? 824.13? 625? 50? 55? 375? 1500

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    89/166

    Programs aving t 00 with Money 77

    SCr een clear s, then

    LEASE/PURCHASE FOR NEW CAR

    LEASE PURCHASEMO. PAYMENT 249.81 0INSURANCE 52.08 52.98TAXES 0 4.17LICENSES 4.58 4.58MAINTENANCE 8.33 31.25INTEREST 0 17.17FUEL AND OIL 100 100POWER 0 9SUPPLIES 29.83 20.83MISC. 25 25

    CASH EXP/MO 460.64 255.09

    - SALVAGE 9 31.25DEPREC. < 0 229.17

    --------NET EXP/MO < 460.64 < 453

    READY.

    Car Operating ExpenseMost of us think of a car as something we have to replace now andagain-always at a dramatically higher price than last t ime-sothat we can get from one place to another. To some, it's also an

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    90/166

    7 8 PORTER'S PROGRAMS FOR THE COMMODORE 6 @J

    expression of individuality, and the vehicle not only for transportation but for personal freedom. We think about the cost of operating

    the car when we buy gas or get it worked on, but those seem likeincidental expenses more in the category of petty drains on thepocketbook than as significant expenditures.

    This program attempts to put a price on personal transportationby answering the question What does it re lly cost to operate acar? You might be quite surprised at the answer: for me, at least,it's nearly as much as the purchase price. The answer, of course,varies with individual circumstances, but it's probably more thanyou think.

    This is more than just an academic, nice-to-know figure, too. Ifyou have to drive 30 miles to take advantage of that big sale, howmuch do you have to save on the merchandise to recover the costof travel? This program will give you a guide, and make you thinkbefore you hop in and dash off somewhere on a whim.

    The program simply totals up the costs of operation that you

    provide and averages them over the prOjected lifetime and milesdriven. I t does build in an automatic kicker for unexpectedrepairs ($300 a year after you've driven 30,000 miles), but otherwise the costs are extrapolations of the amounts you furnish.

    NEI .jle0 REM CAR EXPENSE105 DEF FNR(X)=INTX

    *100) + .5) le0

    110 PRINT CHR$(147)120 PRINT CAR EXPENSE: : PRINT130 INPUT EXPECTEDLIFE IN YEARS ; LY140 INPUT MI LES DRIVEN PER YEAR ; MY150 M = LY *MY160 INPUT FINANCED (YIN) ; X$170 IF X$ = yn THEN 200180 INPUT PURCHASE PRICE ; PC190 GOTO 240200 INPUT DOWN PAYMENT210 INPUT NUMBER OF PAYMENTS220 INPUT MONTHLY PAYMENT230 PC = FNR(Pl + (P2 * P3)240 INPUT MILES PER GALLON

    250INPUT

    PRICEPER GALLON

    .,..

    II ,

    PIP2P3

    MGGG

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    91/166

    Programs aving to 00 with Money 79

    261 3 TG = FNR( (M / MG) *Gm270 INPUT "ANNUAL t1TNCE COST ; At 1

    280 AM=

    AM*

    LY290 ER = LY * M - 30(00) / M) *300300 IF ER ) 0 THEN AM = FNR(AM + ER)311 3 INPUT COST OF A TIRE ; TC320 TC = FNRM / 300(0) * (TC *43 3 ~ 3 INPUT I NSURANCE COST/YEAR"; I P340 IP = FNR(IP *LY)350 INPUT " "IISC EXPENSES ; AA360 C = FNR(PC+TG+AM+TC+IP+AA)371 3 CI I = I N T ( C / MH1(00) + .5 ) /1000380 R E ~ ** OUTPUT RESULTS3913 PRIt'H CHR$( 147)400 PRINT "OPERATING EXPENSES:"410 PRINT II FUEL $ ; TG420 PRINT UPKEEP $ ; AM

    430 PRINT TIRES $ ; TC4 4 ~ JPRINT INSURANCE $ ; IP4513 PRINT MISCELLANEOUS $ ; AA460 PRINT4713 PRINT "OPERATING TOTAL480 PRINT4913 PRINT PURCHASE COST5130 PRINT

    $ ' C-PC

    $ ; PC

    510 PRINT "TOTAL COST OF CAR $ ; C520 PRINT5313 PRINT "MI LES DRItJEN540 PRINT550 PRINT COST PER MILE560 ENDRUN

    ; M

    $ ; eM

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    92/166

    80 PORTER S PROGRAMS FOR THE COMMODORE@64@)

    Sample run :CAR EXPENSE:

    EXPECTED LI FE IN ,( EARS? 4MILES DRIVEN PER YEAR? 1751313FINANCED YIN)? YDOI '-I PAYI-1EHT ? 8013NUt1BER OF PAYMENTS ' ) 361'10NTHLY P A y ~ 1 E N T ' ) 2.55.26MILES PER GALLON ? 17 5

    PRICE PER GALLON ? 1 26ANNUAL MTNCE COST ' ) 225COST OF A TIRE ? 90INSURANCE COST/YEAR? 4251 1I SC EXPENSES ? 21313

    (NeI/J scr een)OPERATIHG EXPENSES:

    FUEL 513413UPKEEP 1585.71TIRES 8413INSURANCE 171313MISCELLANEOUS 21313

    OPERATING TOTAL

    PURCHASE COST

    TOTAL COST

    MILES

    COST PER 11I LE

    ersonal et Worth

    9365 71

    113349.36

    19715.137

    713131313

    282

    How much are you worth? Corporations and other businessesregularly assess and publish their net worth, but as individuals weseldom do so, and as a consequence we have only the vaguest ideahow we're doing on making our fortunes in the world, This pro-gram lets you know how things are going,

    We all earn money, spend it, and accumulate property during

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    93/166

    Programs aving t 00 with Money 8

    our lives. Your n t worth is the total of all you have less the total ofall you owe. The things you own are called assets; the amounts

    you owe are liabilities. Thus your total assets are your gross worth;that is, the total value of all you have. Net worth supposes that yousell it all and payoff your obligations, and that's how much youhave left. It is, in effect, the equity you have in yourself (andcorporations, in fact, regard this difference as the stockholders'equity and view it as a liability).

    The program, though long, is very simple. t asks you for amountsin various categories. Use whole dollars without cents, since anynet-worth assessment is only an approximation anyway. t thensummarizes this information and gives you the totals in eachcategory and your net worth.

    The program goes through three screens of questions and answers,and produces two screens of output. The first report screen listsyour assets and freezes ; advance to the liabilities and net-worthscreen by pressing any key.

    Net worth is a static figure. It does not attempt to place a valueon the income-producing potential of holdings, such as investments.Instead, i t deals with current market values, consistent with thenotion of liquidating everything today. The net-worth figure isuseful for evaluating your financial progress on a regular bas i s -quarterly, for example and comparing i t with previous periods.

    Try it. You'll probably find that you're richer than you think (andif you get an unpleasant surprise instead, maybe it will spur you toplan your way out of trouble).

    NEW

    100 REM ~ PERSONAL NET WORTH110 DATA CASH ON HAND120 DATA IN BANK ACCOUNTS 130 DATA IN IRA/KEOGH PLANS

    140 DATA IN RETIREMENT PLANS150 DATA CASH VALUE OF SAVINGS BONDS160 DATA OF LI FE INSURANCE170 DATA OF STOCKS180 DATA OTHER CASH VALUE ASSETS190 DATA VALUE OF REAL ESTATE200 DATA OF CARS

    (continued

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    94/166

    8 PORTER S PROGRAMS FOR THE COMMODORE 54@

    219 DATA \I OF BOATS, PLANES, ETC.229 DATA H OF BUSINESS EQUITY

    239DATA

    REPLACEMENTCOST OF

    CLOTHING249 DATA OF FURNITURE259 DATA OF HOBBY EQUIPMENP269 DATA OF JEWELRY AND FURS279 DATA OF ART WORKS AND ANTIQUES289 DATA n OF TOOLS AND MACHINERya299 DATA OF COLLECTIONS399 DATA OTHER ASSETS OF VALUE319 DATA SHORT-TERM DEBTS DUE329 DATA n BALANCE ON MORTGAGE339 DATA ON CAR LOANS349 DATA R ON PERSONAL LOANS359 DATA ON RETAIL CREDIT369 DATA ON OTHER LONG-TERM DEBTSu379 DATA OTHER LIABILITIES

    380 REM - - - - - - - - - -399 CLR: DIM C 8), C$(8)499 DIM A(12), A$(12), L 7), L$(7)419 FOR X=1 TO 8: READ C$(X): NEXT X429 FOR X=l TO 12: READ A$(X): NEXT X439 FOR X=l TO 7: READ L$(X): NEXT X449 REM - - - - - - - - - -459 POKE 53281, 12: POKE 53289, 13469 PRINT CHR$(5): T = 28: GOSUB 1999479 PRINT CURRENT ASSETS: : PRINT489 FOR X = 1 TO 8499 PRINT C$(X) TAB(T);599 INPUT C(X)519 C(9) = C(9) + C(X)529 NEXT X

    539 GOSUB 1999 :REM NEW SCREEN540 PRINT OTHER ASSETS: : PRINT559 FOR X = 1 TO 12560 PRINT A$(X) TAB(T);579 INPUT A(X)589 A(9) = A(e) + A(X)599 NEXT X699 GOSUB 19913 :REM NEW SCREEN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    95/166

    Programs aving t 00 with Money 8

    610 PRINT -LIABILITIES:-: PRINT629 FOR X = 1 TO 7630 PRINT L$(X) TAB(T);649 INPUT UX)659 L(9) = L(9) + L(X)669 NEXT X670 REM - - - - - - - - - -680 GOSUB 1099 :REM NEW SCREEN699 PRINT BASSETS:-7BB FOR X = 1 TO 8

    719 IF C(X) = 9 THEN 739729 PRINT C$(X) TAB(T) C(X)739 NEXT X740 PRINT TAB(T) -------1750 PRINT -TOTAL CURRENT ASSETS ;769 PRINT TAB(T) C(9): PRINT770 FOR X = 1 TO 12789 IF A(X)

    =9 THEN 899

    799 PRINT A$(X) TAB(T) A(X)899 NEXT X819 PRINT TAB(T) B ______ H820 PRINT TOTAL OTHER ASSETS;830 PRINT TAB(T) A(0)840 PRINT TAB(T) =======8859 PRINT TOTAL ASSETS860 PRINT TAB(T) (C(0) A(9870 GET X$: IF X$ = . THEN 879889 REM - - - - - - - - - -890 GOSUB 1900 :REM NEW SCREEN990 PRINT DLIABILITIES:919 FOR X = 1 TO 7920 IF L(X) = 0 THEN 949939 PRINT L$(X) TAB(T) L(X)940 NEXT X950 PRINT TAB

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    96/166

    8 PORTER'S PROGRAMS OR THE COMMODORE: 6 ~

    1000 REM ~ ~ SCREEN ADVANCE1010 PRINT CHR$(147);

    1020 PRINT 'PERSONALNET

    WORTH:1030 PRINT1040 RETURNRUN

    Sample run

    [Input screen 1]PERSONAL NET WORTH

    CURRENT ASSETS:

    CASH ON HAND ? 366IN BANK ACCOUNTS ? 2866

    IN IRA/KEOGH PLANS ? 2000IN RETIREMENT PLANS ? 6395CASH VALUE OF SAVINGS BONDS ? 800

    OF LIFE INSURANCE ? 1160OF STOCKS ? 1200

    OTHER CASH VALUE ASSETS ? 0

    [Input screen 2]PERSONAL NET WORTH

    OTHER ASSETS:

    VALUE OF REAL ESTATE ? 85000OF CARS ? 6500OF BOATS, PLANES, ETC. ? 0OF BUSINESS EQUITY ? 0REPLACEMENT COST OF CLOTHING? 3500OF FURNITURE ? 9000OF HOBBY EQUIPMENT ? 500OF JEWELRY ~ ~ FURS ? 0OF ART WORKS AND ANTIQUES ? 1000OF TOOLS AND MACHINERY ? 2500

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    97/166

    Programs aving to with Money 85

    OF COLLECTIONS ? eOTHER ASSETS OF VALUE ? e

    [Input screen 3]PERSONAL NETWORTH:

    LIABILITIES:

    SHORT TERM DEBTS DUEBALANCE ON MORTGAGE

    ON CAR LOANSON PERSONAL LOANSON RETAIL CREDITON OTHER LONG TERMDEBTS

    OTHER LIABILITIES

    [Output screen *1]

    PERSONALNET WORTH:

    ASSETS:

    ? 587? 53000? 3450? 955? 740? 0? 8e0

    CASH O HAND 366IN BANK ACCOUNTS 2866IN IRA/KEOGH PLANS 2080IN RETIREMENT PLANS 6395

    CASH VALUE OF SAVINGS BONDS 880OF LIFE INSURANCE 1160OF STOCKS 1280

    TOTAL CURRENT ASSETS 14787

    VALUE OF REAL ESTATE 85000OF CARS 6500

    REPLACEMENTCOST OF CLOTHING 3500OF FURNITURE 9000OF HOBBY EQUIPHENT 500OF ART WORKS ANDANTIQUES 1000OF TOOLS AND MACHINERY 2500

    TOTAL OTHER ASSETS 108000continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    98/166

    8 PORTER'S PROGRAMS FOR THE COMMODORE 64@

    TOTAL ASSETS 122787

    [Output screen 2JPERSONAL NET WORTH

    LIABI LITIES:

    SHORT-TERM DEBTS DUE 587BALANCE ON MORTGAGE 53000

    ON CAR LOANS 3450

    ON PERSONAL LOANS 955ON RETAIL CREDIT 740

    OTHER LIABILITIES 800

    TOTAL LIABILITIES 5953

    NET WORTH 63 55

    READY.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    99/166

    SECTION

    C LEND RSND CLOCKS

    ay of the Weekn which day of the week were you born? What day was it when

    the Founding Fathers signed the Declaration of Independence?This program figures out the day of the week for any date, butthere is one catch: in 1582, the calendar was changed in most ofthe world to the one we currently use, so any day of the weekgiven for a date prior to that year is subject to doubt. It's stillaccurate in terms of our calendar, but October 12 1492 was not

    necessarily a Wednesday under the old way of keeping track of thepassage of time.

    This program is fun and a little startling because of its instantaneous production of a day, no matter how many years before orhence. Incidentally, the New Year's Eve that will usher in thetwenty-first century occurs on Friday. What a weekend that'sgoing to be

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    100/166

    8 8 PORTER S PROGRAMS FOR THE COMMOOORE 64@

    NEW199 REM DAY OF THE WEEK119 PRINT CHR$(147)129 DEF FNA(X) = INT(X / 4)139 DEF FN8(X) = INT(X / 7)149 DIM T(12), 0 (7)159 FOR X = 1 TO 12: READ T(X): NEXT X169 FOR X = 1 TO 7: READ O (X): NEXT X179 PRINT DAY OF THE WEEK FOR ANY DATE:

    : PRINT189 INPUT DATE AS MM,DD,YYYY. ;M,D,Y199 IF M = 9 THEN END299 GOSU8 399219 PRINT: PRINT229 PRINT DATE IS A 0 (8)239 PRINT - - - - - - - - - - - - - - - - - - : PRINT249 GOTO 189399 REM FIGURE DAY OF WEEK319 J = INTY - 1509) / 190)329 A = J * 5) + J + 3) / 4339 K = INT(A - FNB(A) * 7)349 W = INT(Y / 199): V = INT(Y-W*199)359 A = (V / 4) + V + 0 + T(M) + K369 B = INT(A - FNB(A) * 7) + 1379 IF M ) 2 THEN 469389 IF V = 9 THEN 449399 Tl = INT(Y - FNA(Y) * 4)499 IF Tl (> 9 THEN 469419 IF 8 ( ) 3 THEN 439429 8 = 6439 B = 8 - 1: GOTO 469449 A = J - 1: Tl = INT(A-FNA(A)*4)459 IF T1 = 9 THEN 419469 IF 8 ( ) 9 THEN 489479 8 = 7489 RETURN499 DATA 9,3,3,6,1,4,6,2,5,9,3,5599 DATA SUNDAY, MONDAY, nTUESDAY519 DATA WEDNESDAY , THURSDAY

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    101/166

    Calendars and Clocks 9

    520 DATA FRIDAY , uSATURDAYRUN

    Sample run:

    DAY OF THE WEEK FOR ANY DATE:

    DATE AS MM,DD,YYYY . ? 10 30 1983

    DAY I S A SUNDAY

    DATE AS MM,DD,YYYY. . ? 7,4,1776

    DATE IS A THURSDAY

    DATE AS MM,DD,YYYY ? 0 0 0

    READY.

    Perpetual alendarU sing this program, you can see the calendar for any month of anyyear. It s handy for history buffs, vacation planners, and anybodyelse who has to look ahead or behind farther than a year or so. Theprogram uses the same day-finding subroutine (line 300 onward)as DAY OF THE WEEK to determine which day is the first of the

    month. And, like the preceding program, it s reliable for all yearsstarting in 1582.

    NEW1130 REM PERPETUAL CALENDAR110 PRINT CHR$(147): D = 1

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    102/166

    90 PORTER S PROGRAMS FOR THE COMMOOORE 64@

    129 DEF FNA(X) = INT(X / 4)139 DEF FNB(X) = INT(X / 7)149 DIM T( 12), N( 12)159 FOR X = 1 TO 12: READ T

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    103/166

    510 D T 30 31 30 31RUN

    Sample run:

    C L H ~ D RFOR t10NTH

    SU MO TU WE TH1 2 3 4

    7 8 9 10 1114 15 16 17 1821 22 23 24 2528 29 30 31

    C LEND R FOR MONTH

    READY.

    lapsed Time in ays

    alendars and locks 91

    YE R ? 12,1941

    FR S5 612 1319 2026 27

    YE R ? 0,O

    How many sunrises have there been during your lifetime? Howmany days since Pearl Harbor? How many days did you live inyour last home? did the revolutionary war last? remain in thetwentieth century? Answers to questions such as these usuallyaren t the most compelling concerns of our lives, but it s interest-ing to find out.

    This program computes the elapsed days between any two datesof all time, and t doesn t care in which order you enter them. It

    adjusts for the vagaries of leap years and century leap years, butbecause of rounding t might be one day off over a very long spanof time (does t really matter whether t was 792,616 or 792,617days?). It does ot take into account the calendar change thatoccurred in 1582. Sorry, but again, it s hard to get excited over aminor discrepancy in that long a period.

    Have fun. This is a neat program that will gladden the heart ofany trivia lover.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    104/166

    9 PORTER S PROGRAMS OR THE COMMOOORE 64:

    NEW11 30 REM H ELAPSED DAYS110 DIM M( 12)120 FOR X = 1 TO 121313 READ M(X)148 NEXT X158 REM GET DATES160 PRINT CHR$(147)170 PRINT: PRINT ELAPSED DAYS: : PRINT

    188 INPUT MONTH, DATE, YEAR ; t1M,DD, YY17'0 GOSUB 3602013 IF EC = 0 THEN 2202113 PRINT ** ERROR H : GOTO 180220 Dl = J : PRINT230 INPUT MONTH, DATE, YEAR ; MM,DD,YY249 GOSUB 3,50258 IF EC

    =8 THEN 278

    260 PRINT ** ERROR H : GOTO 230278 02 = J : PRINT280 REM 1* COMPUTE ELAPSED DAYS290 ED = ABS(D1 - D2)300 ED = ED - INT(ED (10e * 365.25310 ED = ED + INT(ED (488 * 365.25320 PRINT ED DAYS BETWEEN DATES

    339 PR INT: I ~ U TR ANOTHER (YIN) ; X$340 IF X$ ) Y THEN END350 PRINT: PRINT: PRINT: GOTO 1893,50 REM JULIAN DATE370 EC = 0380 IF DD ) 31 THEN EC = 99: GOTO 469390 IF MM ) 12 THEN EC = 99: GOTO 461.3400 X = YY

    *365.25

    4Hl J = INT(X)420 L = X - J430 J = ,J + M(MM) + DD440 IF L ) 0 THEN 4604513 IF MM { 2 THEN J = J - 1460 RETURN470 REM H MONTH ELAPSED DAYS

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    105/166

    alendars and locks 9

    480 DATA 0 3 1 5 9 9 0 1 2 0 1 5 1 1 8 1490 DATA 212, 243, 273, 304, 334

    RUN

    Sample r u n

    ELAPSED DAYS:

    MONTH, DATE YEAR? 11,18,1983

    MONTH, DATE YEAR? 7 , 17 1 7 4 1

    15464 DAYS BETWEEN DATES

    ANOTHER YIN)? Y

    I-tONTH, DATE YEAR? 6 ,2 , 1969

    MONTH, DATE YEAR? 8,14,1972

    1169 DAYS BETWEEN DATES

    ANOTHER YIN)? N

    READY.

    Digital lockThis program turns your computer into a digital clock that keepsextremely accurate time. In the center of the screen, it displays adigital readout showing the hour, minute, and second, surrounded

    by a boxThe program asks you to set the time by entering the hour andminutes, separated by a comma. I t does not ask for seconds, so ifthe precise time is important, press the RETURN key at theinstant the minute advances on the clock you re synchronizingwith. This program will run forever, or until you press any key tostop it. It keeps the time on a 12-hour basis; if you want it todisplay military time instead, change 12 to 24 in line 360.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    106/166

    9 PORTER S PROGRAMS FOR THE COMMODORE 5 @>

    NEW100 REM DIGITAL CLOCK110 PRINT CHR$(147)120 PRINT BDIGITAL CLOCK:-: PRINT130 PRINT BENTER CURRENTHOUR, MINUTE140 PRINT SEPARATED BY CCtt1A : PRINT150 INPUT H, M169 PRINT CHR$(147)170 CT = TIME

    180 FOR X = 1 TO 10: PRINT: NEXT X190 PRINT TAS(14) CHR$(lll);299 FOR X = 1 TO 19: PRINT CHR$(183);: NEXT X219 PRINT CHR$(112): PRINT220 PRINT TAS(14) CHR$(198);230 FOR X = 1 TO 19: PRINT CHR$(175);: NEXT X240 PRINT CHR$(186) CHR$(145) CHR$(145)250 GOSUS 399260 REM TIMER LOOP270 GET X : IF X$ 0 8 THEN 510289 NT = TIME299 IF (NT - CT) < 60 THEN 260390 REM ADVANCETIME

    319 CT = NT329 S = S + 1338 IF S < 69 THEN 379340 M = M + 1: S = 0350 IF M ) 59 THEN M = 0: H = H + 1360 IF H ) 12 THEN H = 1370 GOSUB 390380 GOTO 279399 REM DISPLAY TIME499 H$ = STR$( H)419 IF LEN(H$) = 2 THEN H = + H$420 M = STR$(M)430 IF LEN(M$) = 2 THEN M = -0 + RIGHT$(M$, 1>448 M = :- + RIGHT$(M$,2)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    107/166

    alendars and locks 95

    459 S = STR S)469 IF LEN(S ) = 2 THEN S = -9 n + RIGHT

    (S , 1)470 S = H:_ + RIGHT (S ,2) + a480 T = CHR (165)+H +M +S +CHR (167)499 PRINT TAB(14) T CHR (145)500 RETURN510 REM QUIT520 PRINT CHR (147)530 ENDRUN

    himing Digital lockhe best of two worlds combine in this program: the accuracy and

    readability of a modem digital clock, with the charming and homeysound of old-fashioned chimes ringing the hour.

    This program builds upon the digital clock in the last program,and, in fact, the lines listed here are additions to t and not acomplete program. If you didn t type that one, go back and do sothen add these lines for the chimes.

    la9 REM CHIMING DIGITAL CLOCK350 IF M ) 59 THEN M = 0: H = H+1: C = H360 IF H ) 12 THEN H = 1: C = H375 IF C ) 0 THEN GOSU 549495 IF C = a THEN POKE 54296, 9540 REM CHIME THE HOUR559 V = 54272569 POKE V + 1, 90: POKE V + 15, 37

    579 POKE V + 5, 9: POKE V + 24, 15580 POKE V 4, 21590 FOR = 1 TO 370: NEXT600 POKE V + 4, 20610 C = C - 1620 RETURNRUN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    108/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    109/166

    alendars and locks 97

    NEW

    100 REM COUNTDOWNALARM110 PRINT CHR$(147): PRINT120 PRINT COUNTDOWNALARM: : PRINT130 INPUT HOURS, MINUTES, SECONDS ; HH,t1'1, SS

    140 PRINT CHR$(147): PRINT: PRINT150 PRINT -REMAINING TIME:": PRINT160 M = TIME: S = 54272170 REM COUNTDOWNLOOP180 GOSUB 390190 SS = SS - 1200 IF SS ) -1 THEN 250210 SS = 59: = - 1220 IF t1'1 ) -1 THEN 250230 = 59: HH = HH - 1

    250 X$ = STR$(HH) + HOURS, + STR$(MM)260 X$ = X$ MIN, +STR$(SS)+H SEC270 PRINT X$ + II + CHR$( 145)280 IF HH=0 AND MM=0 AND SS=0 THEN 300290 GOTO 170300 REM ~ THE MOMENTHAS ARRIVED310 PRINT: PRINT: PRINT TIME'S UP 320 GOSUB 430: GOSUB 390330 GET X$: IF X ) 1111 THEN 369340 GOSUB 480: GOSUB 390350 GET X : IF X = I R THEN 320360 REM SHUT DOWN370 GOSUB 480380 END390 REM ONE-SECOND TIMER

    400 IF (TIME -M)

    ( 60THEN

    400410 M = TIME420 RETURN430 REM SOUNDTHE ALARM440 POKE S+6, 240: POKE S+24, 15450 POKE S+0, 35: POKE S+I, 40460 POKE S+4, 33

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    110/166

    9 PORTER S PROGRAMS FOR THE COMMODORE 64't

    47 R TURN48 R M SILENCE

    49 FOR X TO 24: POK S X, : N XT X5 R TURN~

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    111/166

    SE TION

    UTILITY PROGR MS

    General

    Utilities are programs intended chiefly to aid the cause of pro-gramming itself, rather than to perform useful tasks for the enduser (the consumer of programs). They make a programmer'slife easier by removing some of the drudgery of the work. sa result, the programs in this section are a valuable addition toyour software library, even if you only write programs for your ownamusement.

    here are five utilities here for making sprites, doing codeconversions, and programming graphics. The graphics utilities areespecially important because they provide a comprehensive envi-

    ronment in which to develop superb screen displays without hav-ing to remember all the rigamarole the Commodore 64 requires forits graphics. They consist of subroutines that support the impor-tant graphics functions, and that you can set up and call withsimple instructions from your programs. he remaining five pro-grams in this section demonstrate how to use the graphics utilities,and provide some striking displays as well.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    112/166

    1 0 0 PORTER S PROGRAMS FOR THE COMMODORE 6 @l

    Sprite Making Tool 1This is an extraordinarily useful tool for making sprites on thescreen and seeing the results, and it lets you touch up and fiddlearound with the sprite until you've got it right. And when you do, itgives you the values to put in your program's DATA statements.This program, along with all the theory that underlies it, is fromMastering Sight nd Sound on the ommodore 64, by Yours Truly.No collection of programs for the Commodore 64 is complete

    without it.How to use this program:

    1. Type RUN. A grid of dots appears on the screen, represent-ing the dots in the sprite image.

    2. Use the cursor keys to move the cursor about the grid. Typeasterisks *) to form the sprite.

    3. Move the cursor down to the line immediately below the lastrow of the grid and type RUN 200. Be careful not to shiftthe grid upward by moving the cursor too far down.

    4. The sprite image forms in the lower right comer of thescreen. In the upper right comer is a menu that says K IFOK, N IF NOT , followed by a question mark.

    5. f the sprite doesn't suit you yet, type N and rework thesprite according to steps 2 and 3. You can undo an asterisk

    (to make the dot transparent again) by typing a period toreplace it. Repeat step 4 to see the revised image. You canrepeat this step (5) as many times as necessary to get thesprite the way you want it.

    6. When the sprite is satisfactory, type K. The grid vanishesand is replaced by the 63 values that represent the spriteimage. Copy them and put them into your program.

    One further note: I f you want to expand the sprite in eitherdirection (or both), use POKE commands from the keyboard be-fore you run this program. Afterward, be sure to POKE the expan-sion byte(s) with 0.

    NEW

    199 REM SPRITE M KER 1110 POKE 53269 0: PRINT CHRS(147)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    113/166

    tility rograms 101

    120 FOR Y = 1 TO 21130 FOR X = 0 TO 23: PRINT H. ;: NEXT X140 PRINT: NEXT Y150 PRINT CHR$(19)160 PRINT TAB(28) STEP 1:170 PRINT TAB(28) RUN 200 NEXT180 FOR Y = 3 TO 20: PRINT: NEXT Y: END190 REM200 REM ** STEP 2 BUILDS SPRITE210 SL=14336: SP=SL/64: PRINT CHR$(19)

    220 PRINT TAB(28) STEP 2: 230 PRINT TAB(28) K IF OK240 PRINT TAB(28) UN IF NOT : PRINT TAB(28) ;250 FOR P=0 TO 63: POKE SL+P,0: NEXT P260 POKE 2040, SP: POKE 53287, 1279 POKE 53248, 255: POKE 53249, 200280 POKE 53269, 1: E = 8: B = 0290 FOR Y = 1 TO 21300 FOR X = 9 TO 23: P=1024+X+(Y*40)310 E = E - 1: V = PEEK(P)329 IF V = 46 THEN 349330 POKE SL + B, PEEK(SL + B) OR 2AE349 IF E = 0 THEN E = 8: B = B + 1350 NEXT X: NEXT Y

    360 INPUT X$370 IF X$ = UK THEN 419380 PRINT CHR$(19)390 FOR X = TO 5: PRINT TAB(28) ;409 PRINT [12 spaces u:NEXT X:GOTO 160410 REM ** PRINT VALUES FOR SPRITE420 POKE 53269, O: PRINT CHR$(147)439 FOR Y = 0 TO 20449 FOR X = 0 TO 2: P = X + (Y * 49)459 PRINT PEEK(SL + P),460 NEXT X470 PRINT: NEXT YRUN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    114/166

    1 0 2 PORTER S PROGRAMS FOR THE COMMODORE 64@

    Sprite-Making Tool 2This is similar to the preceding program, except that it helps youmake multicolor sprites. Like SPRITE-MAKING TOOL 1, it comesfrom Mastering Sight and Sound on the ommodore 64, and isincluded here to round out the collection of programs.

    How to use this program:

    1. Type RUN. A grid of dots appears on the screen, representing the dots in the sprite image.

    2. Use the cursor keys to move the cursor about the grid. Typeasterisks (*) to form the sprite.3. Move the cursor down to the line immediately below the last

    row of the grid and type RUN 200. Be careful not to shiftthe grid upward by moving the cursor too far down.

    4. The sprite image forms in the lower right corner of thescreen. In the upper right corner is a menu that says K IFOK, N IF NOT , followed by a question mark.

    5. f the sprite doesn't suit you yet, type N and rework thesprite according to steps 2 and 3. You can undo an asterisk(to make the dot transparent again) by typing a period toreplace it. Repeat step 4 to see the revised image. You canrepeat this step (5) as many times as necessary to get thesprite the way you want it.

    6. When the sprite is satisfactory, type K The grid vanishes

    and is replaced by the 63 values that represent the spriteimage. Copy them and put them into your program.

    One further note: I f you want to expand the sprite in eitherdirection (or both), use POKE commands from the keyboard before you run this program. Afterward, be sure to POKE the expansion byte(s) with 0.

    NEW19 A$ = -MULTICOLOR SPRITE MAKER-29 PRINT CHR$(147): PRINT A$39 PRINT: PRINT49 INPUT NUMBER FOR COLOR 1 ; C159 INPUT NUMBER FOR COLOR 2M; C269 INPUT NUMBER FOR COLOR 3 ; C3

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    115/166

    Utility Programs 1 03

    70 POKE 53285, Cl: POKE 53286, C380 POKE 53287, C2100 REM ~ O R GRID119 POKE 53269, 0: PRINT CHR$(147)120 FOR Y = 1 TO 21130 FOR X = 0 TO 23 STEP 2: PRINT II ; :NEXT X

    140 PRINT: NEXT Y150 PRINT CHR$(19)160 PRINT TAB(28) STEP 1:

    170 PRINT TAB(28) RUN 200 NEXT189 FOR Y = 3 TO 20: PRINT: NEXT Y: END190 REM200 REM STEP 2 BUILDS SPRITE210 SL=14336: SP=SL/64: PRINT CHR$(19)220 PRINT TAB(28) STEP 2:230 PRINT TAB(28) K IF OK240 PRINT TAB(28) N IF NOP: PRINT TAB(28) ;250 FOR P = 0 TO 63: POKE SL+P,0: NEXT P255 POKE 53276, 1260 POKE 2040, SP: POKE 53287, 1270 POKE 53248, 255: POKE 53249, 200280 POKE 53269, 1: E = 256: B = 0290 FOR Y = 1 TO 21300 FOR X = 0 TO 23 STEP 2: P = 1024 + X+ Y * 40)310 E = E 4: V = PEEK(P)320 IF V = 46 THEN 340325 V = V AND 3330 POKE SL + B, PEEK(SL + B) OR (E * V340 IF E = 1 THEN E = 256: B = B + 1350 NEXT X: NEXT Y360 INPUT X$370 IF X$ = K THEN 410380 PRINT CHR$(19)390 FOR X = 1 TO 5: PRINT TAB(28) ;400 PRINT [12 spaces] :NEXT X:GOTO 160410 REM PRINT VALUES FOR SPRITE

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    116/166

    1 0 4 PORTER S PROGRAMS FOR THE CDMMODORE) 64@:

    429 POKE 53269, e: PRINT CHR$( 147)430 FOR Y = 0 TO 20440 FOR X

    =0 TO 2: P

    =X + Y 3)

    450 PRINT PEEK(SL + P ,460 NEXT X470 PRINT: NEXT YRUN

    ode onvertor

    The Commodore 64 uses two different sets of values to make thesame characters, depending on how the program places the charac-ters on the screen. For every possible character that the computercan make, there is an ASCII (American Standard Code for Informa-

    tion Interchange) code. The ASCII codes consist of numbers be-tween 0 and 255 that stand for graphic symbols or control codes;ASCII code 65, for example, means the letter A.

    When you want to display the letter A you can do it with theBASIC instruction

    PRINT A

    and the Commodore 64 knows and does exactly what you want.You can also use the CHR$ function to display an A CHR$ meansmake the character whose ASCII value follows. Thus, the

    instruction

    PRINT CHR$(65)

    also places an A on the screen. CHR$ is usually employed togenerate nonprintable control characters, but you can use it this

    way as well.Confusion arises, however, when you want to POKE a characterinto screen memory while building a graphics display. The reasonis that, although most of the ASCII codes have a correspondingPOKE code, the numeric values differ.

    The Commodore 64 User s Guide shows these two character setsin Appendixes E and F, but i t never really explains that there is anumeric correlation between them, so sometimes programmers

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    117/166

    Utility rograms 105

    end up flipping back and forth between the appendixes, increasingthe chances of introducing an error.

    This program is an aid that shows, for any character you type, itsASCII code, its CHR$ code (always the same), and the corresponding POKE code. Stop the program by entering STOP in responseto the prompt. .

    For a more comprehensive discussion of this subject, seeMastering Sight nd Sound on the Commodore 64, Chapter 4.

    NEW

    190 REM CODE CONVERSION110 PRINT CHR$(147)129 PRINT CODE CONVERSION:130 PRINT: INPUT CHARACTER ; CS140 IF CS = STOp THEN END150 AC = ASC(CS)160 IF AC = 255 THEN AC=126

    170 IF AC ) 223 THEN AC=AC-64189 IF AC } 191 THEN AC=AC-96190 IF AC } 159 THEN PC=AC-64:GOTO259299 IF AC } 127 THEN 240210 IF AC} 95 THEN PC=AC-32:GOTO250229 IF AC} 63 THEN PC=AC-64:GOTO250239 IF AC 31 THEN PC=AC :GOTO 250249 PC = -1250 PCS = STRS(PC)269 IF PC 9 THEN PCS =279 PRINT ASCII289 PRINT CHR CODE290 PRINT U POKE CODE390 GOTO 139

    ~

    Sample run:

    CODE CONVERSION:

    CHARACTER? K

    NONEACAC

    PCS

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    118/166

    1 6 PORTER S PROGRAMS FOR THE COMMODORE 6

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    119/166

    Utility Programs 107

    mapped mode, load the environment from storage into thecomputer.

    4. After the load is complete, type your graphics program starting at line 1000. I t must end before line 9960. U sage ofthe environment's services is discussed below.

    5. Test the program to make sure it works properly.6. Save it under a name other than HRG. This will save both

    the graphics services and your instructions as a completeprogram that you can then reload and run directly (withoutreloading HRG).

    Using the HRG Environment s ServicesThe three programs following the environment listing illustrate theapplication of these services. This is a description of each of them.

    1. Background/foreground colors: You automatically get whiteon a brown background with the HRG environment, as shownhere. You can change this default combination by altering line140, which currently reads

    POKE 49172, 1 * 16) + 9

    The 9 is brown, the 1 in the parentheses is white. Change thesedigits to the desired combination using the color numbers shownon page 61 of your Commodore 64 User s Guide. As an alternative,you can include an instruction in your program that will overridethis combination. Code it the same as shown here, but with your

    desired colors substituted. The next instruction isSYS 49171

    which calls a machine-language subprogram to reset the colors.2 urning on a dot on the screen: Graphics works one dot at a

    time on the Commodore 64. There are 320 dots horizontally, num-bered 0-319, and 200 dots vertically (0-199). The horizontalposition is called by the variable name X and the vertical by Y.Therefore you must assign the desired position coordinates to Xand Y and then issue the instruction

    GOSUB 170

    The effect of this is to tum on the dot (give it the foregroundcolor) at the specified position on the screen.

    3 Changing foreground color: Within a character cell of 8 x 8

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    120/166

    1 8 PORTER S PROGRAMS FOR TH COMMODORE 6 @i

    dots, you may have any of the 16 colors as the foreground (thecolor assumed by a dot that is turned on ). The environment setsall cells to the same foreground color; this routine is used tochange it to something else within a given cell.

    The Commodore 64 has 40 columns by 25 lines, for a total of1000 character cells on the screen. The position within the line isgiven by the variable X and the line number by Y. The columns number 0-39, the rows 0-24. Therefore, assign the column and row coordinates to X and Y, respectively. Next assignthe number (page 61 of the User s Guide) of the color you want to

    the variable CN. Finally, issue the instructionGOSUB 250

    to put the change into effect. (HRG DEMO 1 illustrates this bychanging four cells from white to blue.)

    4 Changing background color: This is the same as item 3 above,except that it changes the background color in the cell specified byX and Y. The background color is the color that a dot has whent is ot turned on. Load the location into X and Y and the

    desired background color into eN, then write

    GOSUB 300

    to alter the background color in the speCified cell.5 Painting a line: This routine turns on all the dots in a row

    between two dot X coordinates; in other words, it paints a solid

    horizontal line between two points. Specify the starting point's dotX coordinate (0-319) in the variable SX and the ending location in EX. You must also give the row number (0-199) invariable Y. Then issue the instruction

    GOSUB 350

    to paint the line. You can use this routine to fill in a large area bystepping one row at a time and painting in each row, in themanner of painting a wall with separate brush strokes. (HRGDEMO 1 uses this routine to make an hourglass figure.)

    6 Stopping the program: The environment has instructions toend the program and restore normal graphics mode starting at line9950. Have your program GOTO 9950 to stop, or else falloff thelast instruction into 9950. Line 9960 is a loop that freezes thedisplay until you tap the SPACE bar or another key. The environ-

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    121/166

    Utility Programs 1 09

    ment then clears the screen and places the computer into thesame condition t had before the program began.

    The HRG environment is a great time-saver for graphicsprogrammers, and it has everything you need to create stunningdisplays with your computer.

    N E ~

    19 REM U HRG EI NI RON 1ENT29 FOR A = 49152 TO 4929439 READ B: POKE A, B: NEXT A49 DATA 169 O 169 9 162 32 153 O 3250 DATA 299 298 250 238 8 19269 DATA 292 208 244 96 .79 DATA 169 16 169 232 162 4 141 9 489 DATA 238 26 192 298 3 238 27 19290 DATA 136 208 242 292 208 239 169 9199 DATA 141 26 192 169 4 141 27 192 96

    110POKE

    53265, PEEK(53265)OR

    32129 POKE 53272, PEEK(53272) OR 8139 SYS 49152149 POKE 49172, 1 ~ 16) + 9159 POKE 53280, 0: SYS 49171169 GOTO 1999 :REM START PROGRAM165 REM179 REM ~ TURN ON DOT AT XY

    189 IF X < 9 OR X ) 319 THEN 249199 IF Y < 9 OR Y ) 199 THEN 240299 BA = INT Y/8)*329) + INT Xl8)*8)219 BA = BA + (Y AND 7) + 8192229 BP = 7 - (X AND 7)230 POKE BA, (PEEK(BA) OR 2A BP)240 RETURN

    245REM

    250 REM ~ CHANGE FOREGROUND COLOR260 CB = 1024 + (Y * 48) + X270 POKE CB,(PEEK(CB) AND IS)+ CN 16)280 RETURN290 REM300 REM ** CHANGE BACKGROUND COLOR

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    122/166

    1 1 PORTER'S PROGRAMS FOR THE COMMODORE 54@

    319 CB = 1024 + (Y * 40) + X320 POKE CB,(PEEK(CB) AND 240) + CN339 RETURN349 REM - - - - - - - - - -359 REM PAINT ONE LINE3613 CX = SX379 IF SX (= EX THEN 399389 SX = EX: EX = CX: CX = sx3ge REM START OF LINE4ee X = CX: GOSUB 1713419 IF BP ) (EX - SX + 1) THEN 559429 PV = 2A (BP + 1) - 1439 POKE SA, PEEK(BA) OR PV449 CX = CX + BP + 1: BA = BA + 84513 REM WHOLE BYTE4613 BR =EX - CX + 1479 IF BR ( 8 THEN 590489 POKE BA, 255498 SA = BA + 8: ex = ex + 8: GOTO 450588 REM END OF LINE510 IF BR ( 0 THEN BR = e520 PV = 256 - 2A(8 - BR530 POKE BA, PEEK(BA) OR PV5413 RETURN55e REM BIT PLOT

    569 FOR X = SX TO EX: GOSUB 1713: NEXT X570 RETURN580 REM - - - - - - - - - -Ieee REM PROGRAM START

    (Your program goes here s t a r t ing a t1 ne lee0)

    9950 REM END OF PROGRAM9968 GET X : IF X = u THEN 99609970 POKE 53265, PEEK(53265) AND 223998e POKE 53272, PEEK(53272) AND 2479990 PRINT CHR (147): END

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    123/166

    tility rograms 111

    HRG emonstration 1

    Now that you've typed in and saved the HRG environment, you'reno doubt eager to try it and see how it works. This program is aninsert to the master, meaning that the HRG environment mustalready be in the computer's memory when you type it

    It demonstrates painting a horizontal line (line 1020), drawing avertical line (lines 1040-1050), making an hourglass figure (lines1070-1130), and changing foreground colors (lines 1150-1180).

    The brevity and simplicity of this program ought to convince youof the HRG environment's worth; i f you had to write a program fromscratch to do even these relatively simple graphics, it would runto several screens and probably take you a couple of hours just lookingup how to do this stuff. With the HRG environment, it's quite easyto create very striking computer art displays such as this one.

    (NOTE: the HRG environment mu-:.t be in

    the computer s memory f o r t h i sprogram to IIJork.)

    11310 REM n HOR ZONTAL LINE1020 Y=100: SX=0: EX=319: GOSU8 3501930 REM lJERT CAL LINE1040 X = 1601050 FOR Y = 0 TO 199: GOSUB 170: NEXT Y1060 REM TOP OF HOURGLASS1070 SX = 110: EX = 21 : Y = 501080 GOSUB 350: Y=Y+ 1: SX=SX+ 1: EX=EX-l1090 IF SX < EX THEN 10801 H10 REM BOTTot'1 OF HOURGLASS1110 Y = Y + 1: GOSUB 3591120 SX = SX - 1: EX = EX + 1

    1130 IF SX = 110 THEN 111911413 REM H CHANGE FOREGROUND1150 FOR Y = 8 TO 16 STEP 81160 FOR X = 19 TO 201170 CN = 6: GOSUB 25131180 HE>(T X: NEXT YRUN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    124/166

    11 2 PORTER S PROGRAMS FOR TH COMMODORE 6 ~

    HRG Demonstration 2

    This program, like the preceding one, is an insert that workswithin the HRG environment. I t draws a symmetrical pattern thatlooks like a corporate logo, a diamond with a sine wave in itscenter. The purpose of the program is to demonstrate the makingof diagonal lines and curves using the HRG environment.

    The subroutine between lines 1110 and 1170 plots a line between two points. The origin of the line is given by Xl and Y1, thedestination by X2 and Y2. Lines 1120-1190 set up four sets ofcoordinates for the four lines that form the diamond.

    Lines 1200-1270 plot a sine curve. Line 1210 provides positioning information, where H is the horizontal placement, V is thevertical placement, and P is the relative horizontal position at themoment. Lines 1220-1270 form a loop that steps through 360 0counting by 2s. Line 1230 converts degrees to radians, an anglemeasurement required by the BASIC trigonometric function SIN,which appears in the next line. t calculates the vertical placementof the sine of the current angle. Line 1250 provides horizontalposition and calls the environment to turn on the dot at thatlocation. Line 1260 then steps the horizontal position a half-pointto the right. The loop repeats through the entire cycle of the sinewave.

    NOTE: the HRG environment must be inthe computer s memory for th isprogram to work.)

    1910 REM PLOT DIAGONAL LINES1929 Xl = 0: Yl = 1901930 X2 = 168: Y2 = 0: GOSUB 11191949 Xl = 160: Yl = 01050 X2 = 319: Y2 = 199: GOSUB 11101960 Xl = 319: Yl = 1901970 X2 = 160: Y2 = 199: GOSUB 11191980 Xl = 160: Yl = 1991990 X2 = 9: Y2 = 190: GOSUB 11191109 GOTO 11891110 REM DR W A LINE

    1120 D = SGRXI - X2)A2 + Yl - Y2)A2)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    125/166

    Utility rograms 11 3

    1138 XV = (X2-XI) / D: YV = (Y2-Yl) / D1148 X = X1 Y = Y1 D = INT D 5)1150 FOR I = 1 TO D: GOSUB 1781168 X = X XV: Y = Y YV: NEXT1170 RETURN1180 REM PAINT BISECTOR1190 Y=100: SX=0: EX=319: GOSUB 3501200 REM PLOT SINE CURVE1210 H = 115: V = 100: P = 91220 FOR D = 0 TO 369 STEP 21230 A = D ~ / 180)1240 Y = V - INTSIN(A) 30) .5)1250 X = P HI GOSUB 1781260 P = P 51270 NEXT 0

    FU.l I

    HRG Demonstration 3

    he last of the inserts for the HRG environment, this programdemonstrates the effects of altering the background and fore-ground colors in cells. It produces a background of repeatingstripes of shades from white to black, passing through the threegrays, and superimposes a brilliantly striped Easter egg that seems

    to float in front of the background. he stripes in the backgroundare vertical, those in the foreground horizontal.

    ou can watch the first part of the program altering the back-ground as the grays march across the screen. he egg emergesnext in pure white. Finally, stripes color i t as the foreground isaltered by the program. It s actually changing the cells outside theegg as well, but since no foreground dots are turned on exceptwithin the egg, you can t see them.

    NOTE: the HRG environment must be inthe computer s memory for th i sprogram to worK.)

    1000 REM HRG DEMO 13continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    126/166

    4 PORTER S PROGRAMS OR THE COMMODORE 64@

    1910 POKE 53289, 9: N = 11020 FOR X = 9 TO 391939 FOR

    Y =0 TO 24

    1040 ON N GOTO 1050,1060,1070,1989,19991050 ON = 1: GOTO 11001069 N = 15: GOTO 11991979 ON = 12: GOTO 11901989 N = 11: GOTO 11901990 ON = e1100 GOSUB 399 :REM IG STRIPES1110 NEXT Y1120 N = N + 1: IF N = 6 THEN N = 11130 NEXT X: N = 11140 REM EASTER EGG1150 R = 69: H = 168: V = 1001160 FOR A = 99 TO 279 STEP .51170 RD = A * 1 1891180 Y = INT RC SIN RD) +

    V+ .5)1190 IF Y = LY THEN 1240

    1290 SX = INT RC COS RD) + H + .5)1210 EX = H - SX + H1229 IF EX CH + 3) THEN GOSUB 3591230 LY = Y1240 NEXT A1258 REM

    1260 REM FIG STRIPES1278 FOR Y = 4 TO 291288 FOR X = 19 TO 391290 ON N GOTD 1398,1319,1320,1330,13491300 N = 2: GOTO 13501310 ON = 14: GOTD 13501320 ON = 8: GOTO 13581330 ON

    =5: GOTO 1350

    1340 N = 71350 GOSUB 2501360 NEXT X1370 N = N + 1: IF N = 6 THEN N = 11380 NEXT YRUN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    127/166

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    128/166

    6 PORTER S PROGRAMS FOR THE COMMODORE 64@

    Using the MHR Environment s ServicesThe two programs following the environment listing illustrate appli

    cations of the services described here.1 Background/foreground colors: You automatically get white ascolor pointer 3 ( foreground ) against a brown background (colorpointer (/)) with the MHRG environment as shown here. You canchange this combination by altering line 15(/), which now reads

    POKE 49172, 1: POKE 53281, 9

    The 1 is white and 9 is brown. Change these digits to thedesired combination using the color numbers shown on page 61 ofyour Commodore 64 User s Guide.

    As an alternative, you can include instructions in your programto override this combination. To change the background:

    POKE 53281, [color number]

    and to change the color associated with color pointer 3:

    POKE 49179, 216: POKE 49172, [color number]SYS 49171: POKE 49179, 4

    which calls the machine-language subprogram given by the DATAstatements in lines 4f/J-6(/).

    Change the background color (given by color pointer value#(/)) by POKEing the appropriate color number into 53281.

    2 Setting colors for color pointers # 1 and 2: The environmentdoes not establish the colors associated with color pointers 1 and

    2. Before using them, therefore, you have to set them up. The follOwing instructions establish these colors for the screen as a whole:

    POKE 49172, (16 * [color 1] + [color 2]SYS 49171

    where [color 1] is a number ~ 1 5that assigns a color to pointer 1

    and [color 2] assigns a color to pointer 2.3 urning on a pixel on the screen: MHRG consists of pixels onthe Commodore 64, a pixel being two dots side by side. There are160 dots horizontally numbered / ) ~ 1 5 9 ,and 200 pixels vertically

    / ) ~ 1 9 9 ) .A pixel is twice as wide as it is high. Each horizontalposition is given by the variable name X and the vertical by Y .Therefore, you must assign the desired position coordinates to Xand Y and the pointer value / ) ~ 3to CP , then write

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    129/166

    Utility rograms 7

    GOSUB 190

    The effect of this is to turn on the pixel at the specified positionon the screen, giving it the color pointed to by CP . (MHRGDEMONSTRATION 1 uses this routine to place stars. )

    4 Changing COIOT # 1: Within a character cell of 4 x 8 pixels, colorpointer value 1 may indicate anyone of 16 colors. Item 2 abovetells how to set all cells to the same color # 1; this section tells howto change t within a given cell.

    The Commodore 64 has 40 columns by 25 lines, for a total of

    1000 character cells on the screen. The position within the line isgiven by the variable X and the line number by Y . The col-umns number 0-39, the rows 0-24. Therefore, assign the col-umn and row coordinates to X and Y , respectively. Next assignthe number (page 61 of the User s Guide) of the color you wantcolor pointer value 1 to indicate to the variable CN . Finally, issuethe instruction

    GOSUB 290to put the change into effect within the cell.

    5 Changing COIOT 2: This is the same as item 4 above, exceptthat it changes the color indicated by pointer value 2 in the cellat X and Y. Load the location into X and Y and the colornumber to be given by pointer value 2 into CN , then write

    GOSUB 3406 Changing color 3: This is the same as items 4 and 5

    above, but it changes the color indicated by pointer value 3 in thecell at X and Y . Do as above, but call the appropriate routinewith

    GOSUB 3907 Painting a line: This routine turns on all the pixels in a row

    between two X coordinates; in other words, it paints a solidhorizontal line between two points. Specify the starting pixel's Xcoordinate (0-159) in the variable SX and the ending location inEX . You must also give the row number (0-199) in Y and the

    color pointer value for the line in CP, then write

    GOSUB 350

    to paint the line. You can use this routine to fill in a large area by

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    130/166

    8 PORTER S PROGRAMS FOR THE COMMODORE 64@

    stepping one row at a time and painting in each row, in themanner of painting a wall with separate brush strokes. MHRG

    DEMONSTRATION 1 uses this routine to make stripes on a flagbunting.)8 Stopping the program The environment has instructions to

    end the program and restore normal graphics mode starting at line9950. Have your program GOTO 9950 to stop, or else fall off thelast instruction into 9950. Line 9960 is a loop that freezes thedisplay until you tap the SPACE bar or another key. The environment then clears the screen and places the computer into thesame condition i t had before the program began.

    The MHRG environment is a great time-saver for graphicsprogrammers, and i t has everything you need to create stunningdisplays with your computer.

    1e REM l MHRG ENV I RCN1ENT20 FOR A = 49152 TO 4928430 READ B: POKE A, B: NEXT A40 DATA 169 8 160 O 162 32 153 O 3258 DATA 208 208 250 238 8 19260 DATA 282 288 244 9678 DATA 169 16 160 232 162 4 141 O 488 DATA 238 26 192 288 3 238 27 19299 DATA 136 208 242 202 288 239 16 9 9

    190 DATA 141 26 192 169 4 141 27 192 96119 POKE 53270, PEEK 53270) OR 16120 POKE 53265, PEEK 53265) OR 32130 POKE 53272, PEEK 53272) OR 8140 POKE 49179, 216150 POKE 49172, 1: POKE 53281, 9160 SYS 49171: SYS 49152: POKE 49179,4179 GOTO 188e :REM START PROGRAM180 REM190 REM l l COLOR PIXEL AT XY280 IF X < 0 OR X ) 159 THEN 270210 IF Y < 8 OR Y ) 199 THEN 270220 SA = I N T Y / 8 ) * 3 2 8 ) + I N T X * 2 ) / 8 ) ~ 8230 SA = BA + Y AND 7) + 8192240 BP = 3 - X AND 3)250 PM = 4A BP: PP = 255 - PH l 3)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    131/166

    tility Programs

    269 POKE BA,PEEK SA) ND PP) OR CPlPH)279 RETURN280 REM - - - - - - - - - -290 REH CH NGE COLOR _1 IN CELL XY309 CB = 1924 + Y l 40) + X310 POKE CB, PEEK CB) AND 15)+ CN l 16)329 RETURN330 REM - - - - - - - - - -349 REM I I CH NGE COLOR 12 IN CELL XY358 CB = 1824 + Y l 40) + X368 POKE CB, PEEK CB)

    AND240) + eN370 RETURN

    380 REM - - - - - - - - - -398 REM CH NGE COLOR 13 IN CELL XY490 CB = 55296 + Y l 40) + X4 10 POKE CB, O f429 RETURN438 REM - - - - - - - - - -440 REM PAINT LINE IN COLOR CP450 CX = SX460 IF SX = EX THEN 488478 SX = EX: EX = CX: CX = SX480 REM l l START OF LINE499 X = CX: GOSUB 198500 IF BP EX - SX + 1) THEN 688

    510 IF BP = 3THEN

    578520 IF BP=0 THEN CX=CX+l:BA=SA+8:GOT0570530 BR = BP548 FOR PB = BR TO 8 STEP -1: X = CX558 GOSUB lS8: CX = ex + 1560 NEXT PB: B = SA + 8579 REM l* WHOLE BYTE580 PB = 8590 FOR PV = 3 TO e STEP -1608 PB = PB + CP l 4 A PV)619 NEXT PV620 BR = EX - CX + 1639 IF BR < 4 THEN 669649 POKE BA, PB: SA = S + 8

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    132/166

    1 2 0 PORTER S PROGRAMS FOR THE COMMODORE 6 @l

    659 ex = ex + 4: GOTO 629660 REM END OF LINE678 IF BR = 0 THEN 790680 REM PIXEL PLOT690 FOR X = ex TO EX: GOSUB 188: NEXT X790 RETURN100e REM PROGR M START

    (Your program goes here)

    9950 REM * END OF PROGR M9960 GET X : IF X = THEN 99609970 POKE 53265, PEEK(53265) ND 2239980 POKE 53270, PEEK(53270) ND 2399990 POKE 53272, PEEK(53272) ND 2479999 PRINT CHR (147): END

    MHRG Demonstration 1

    This program is an insert to the MHRG environment that illustrates use of some of its features for creating pixel-mapped graphics.I t draws a patriotic figure consisting of a red, white, and blue flagbunting studded with stars and surrounded by an oval of stars

    against a black background. Specifically:

    Line 1010 sets the background and border to black. Line 1020 establishes red (2) as the color associated with

    color pointer value 1 and blue (6) as pointer value 2. Lines 1030-1120 draw stripes of red, white, and blue, using

    the painting routine. Lines 1040-1200 place stars at regular intervals in the red

    and blue stripes of the bunting. Lines 1210-1290 create an oval of white stars around the

    bunting.

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    133/166

    Utility rograms 1 21

    NOTE: the MHRG environment must be inthe computer s memory for t h i sprogram to worK.)

    1090 REM ~ ~ MHRG DEMO ~ 11010 POKE 53281, : POKE 53280, 01020 POKE 4 9 1 7 2 , 1 6 ~ 2 ) + 6 :SYS 491711030 SX = 49: EX = 119: CP = 11040 REM ~ * RED STRIPE1050 FOR Y = 81 TO 9 : GOSUB 4401960 NEXT Y: CP = 31970 REM ** WHITE STRIPE1980 FOR Y = 91 TO 100: GOSUB 4401990 NEXT Y: CP = 21100 REM ** BLUE STRIPE1110 FOR Y = 191 TO 110: GOSUB 4401120 NEXT Y

    1130REM ~ *

    STARS INBUNTING

    1140 FOR X = 50 TO 110 STEP 101150 FOR Y = 85 TO 861160 CP = 3: GOSUB 1901170 NEXT Y1180 FOR Y = 105 TO 106: GOSUB 1901190 NEXT Y1200 NEXT X1210 REM OVAL OF STARS1229 XC = 8 : YC = 100: RC = 601230 FOR A = 9 TO 350 STEP 101240 R = A * t 180)1259 X = INT SIN R) * RC + XC1260 Y = INT COS R) RC + YC1270 GOSUB 1901280 Y

    =Y + 1: GOSUB 199

    1290 NEXT ARUN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    134/166

    1 2 2 PORTER S PROGRAMS FOR THE COMMODORE 6 @>

    MHRG Demonstration 2

    This subprogram uses the MHRG environment to create a fourcolor needlepoint pattern. I t works an octagonal figure repeated insix rows by eleven columns, all identical, and then it goes backand changes two of the three colors in the figures that are in thesecond position inside the pattern. The program demonstrates:

    1. Creation of a pattern image (lines 1050-1140) in an arrayusing data statements (lines 5000-5110) that give the

    color pointer value for each pixel.2. Use of a pair of loops (lines 1150-1200) and subroutine(lines 1400-1520) to place the pattern stored in the arrayat a specific location on the screen. Note that lines 1460-1470work two bytes at a time, stacking one atop the other, inorder to make the octagonal figure square (since a pixel istwice as wide as its height). Each figure is thus 24 x 24 dots,filling an area of 3 x 3 cells. The coordinates PX and PYspecify the upper left cell of the figure and the subroutinebuilds down and right from that point.

    3. Use of the environment's services to change colors in selected cells. Lines 1210 through 1390 repeatedly call twosubroutines to change the colors of the cells in the innerborder areas from blue, red, white, and black to red, green,white, and black.

    NOTE: the HHRG environment must be inthe computer s memory for th i sprogram to w o r ~ .

    1910 REM ~ ~ MHRG DEMO 121020 POKE 49172,(16*6)+2: SYS 491711030 POKE 53280, 0: POKE 53281, 01040 DIM A 12,3)1050 FOR R = 1 TO 121960 FOR C = 1 TO 31070 P = 01080 FOR B = 3 TO 0 STEP -11090 RE D N1100 P = P + N * (4 A B

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    135/166

    Utility rograms 3

    1110 NEXT B1120 A R,C) = P1138 NEXT C1140 NEXT R1150 REM ~ NEEDLEPOINT PATTERN1160 FOR PX = 3 TO 33 STEP 31170 FOR PY = 3 TO 18 STEP 31180 GOSUB 14091190 NEXT PY1288 NEXT PX

    1210 REM ~ INNER BORDER - HORIZ1220 FOR X = 6 TO 321230 FOR Y = 6 TO 81240 CN=2: GOSUB 290: CN=5: GOSUB 3401250 NEXT Y1260 FOR Y = 15 TO 171279 CN=2: GOSUB 299: CN=5: GOSUB 340

    1289NEXT

    Y1290 NEXT X1309 REM INNER BORDER - VERT1310 FOR Y = 9 TO 141320 FOR X = 6 TO 81330 CN=2: GOSUB 290: CN=5: GOSUB 3401340 NEXT X1350 FOR X = 39 TO 321360 CN=2: GOSUB 290: CN=5: GOSUB 3491370 NEXT X1380 NEXT Y1399 GOTO 99591499 REM ~ DISPLAY PATTERN AT PX, PY1419 CP=9: X=PX*4: Y = P Y ~ 8 :GOSUB 1991420 BL = SA: SR = 11430 FOR W

    =1 TO 3

    1440 FOR C = 1 TO 31450 FOR R = SR TO SR+3) .1469 POKE BL, A R,C): POKE BL+l, A R,C)1479 BL = BL + 21480 NEXT R1490 NEXT C

    continued)

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    136/166

    2 4 PORTER S PROGRAMS FOR TH COMMODORE 64@

    598 BL = BL 296: SR = SR 45 8 NEXT W528 RETURN

    5099 D T 0 0 0 1 1 1 1 1 1 0 0 05018 D T O,O,1,O,O,O,O,O,O,1,O,95020 D T O 1 2 2 2 2 2 2 2 2 1 O5030 D T 1 2 2 2 3 3 3 3 2 2 2 15048 D T 1 2 2 3 9 9 0 0 3 2 2 15058 D T 1 2 2 3 0 9 9 0 3 2 2 15860 D T 1 2 2 3 9 O 8 9 3 2 2 15078 D T 1 2 2 3 9 O O 9 3 2 2 15080 D T 1 2 2 2 3 3 3 3 2 2 2 15890 D T 9 1 2 2 2 2 2 2 2 2 1 O5190 D T 9 0 1 2 2 2 2 2 2 1 0 05118 D T O 9 9 1 1 1 1 1 1 O 9 9RUN

  • 8/10/2019 Porters_Programs_for_the_Commodore_64.pdf

    137/166

    SE TION

    COMPUTER G MES

    GeneralWhen Univac produced the first commercial computers back inthe early 1950s, computer pioneers immediately began