The
Transactor
Book
of
Bits
and
For
ALL
Commodore
Computers!
The
Transactor
Book
of
Bits
and
Pieces
#1
©
June
1986 TransactorPublishingInc.500
SteelesAvenue
Milton,Ontario.L9T 3P7Allrightsreserved
Printedin
Canada
Canadian
Cataloguing
inPublication
Data
Main
entryundertitle:The
Transactorbook
ofbitsand
pieces,#1A
collection oftheBitsand
piecessectionsfromThe
Transactor,v.4-6.Includesindex.
ISBN
0-9692086-1-8
1.
Commodore
computers. I.TheTransactorQA76.8.C64T73 1986
004.165
C86-Q94352-6
Commodore
64,VIC,PET,CBM,
Plus4,C16,B128, 1541,4040, 8050,
8250,9090,
1525,C128,
and AMIGA,
areregisteredtrademarksofCommodore
BusinessMachines PALand
POWER
areregisteredtrademarksof Pro-LineSoftwareThe
Transactor
Book
of
Bits
and
Pieces
#
1
edited
by
Karl J.H.
Hildon
and
Chris
Zamara
produced
by
Karl J.H.
Hildon
Zero
Page
Once
againwe'veproducedabookthatwas
necessaryasa"workingtool".LiketheAnthology, the"Bits Book"(our abbreviated in-housetitle)
was
designed toeliminate alotofflippingthrough pagesandpagesofmagazinestryingtofind that
oneparticularitemthat
we
justknow
isintheresomewhere.You'llnotice thetitleof thisbookisfollowedby"#1".This isadeliberateployto
eliminateanyambiguitybetweenthis BitsBook andthepossibility ofasecondBits
Book.
We
chosetoincludealltheBitsandPiecesineverymagazinefromVolume
4to
Volume
6forafewreasons:first,tokeepthiseditiona reasonablesize;second,itseemedlikea logical startingpointandatidyendingpoint;andthird,sincethe
Bitscolumn seemsto getbiggerand
more
compacteveryissue,it'sverypossiblewe'llhaveenough materialforthesecondBits
Book
bytheendofVolume
8, atwhichpointwe'llbegoingcrazyflippingthroughmagazineaftermagazinelooking
for that. ..well,you know.
Some
seriously meaningless items were omitted, and references to magazinearticles have been removed
when
unnecessary. Othersomewhat
outdated bitshave beenleftinpurelyfor their historicalvalue, butotherwisethey'veallbeen
printedhereastheyoriginallyappeared, exceptfor
some
minoreditingduringtheproofreadingstage.
They're listed in the
same
order, starting fromVolume
4 Issue 01 through toVolume
6 Issue 06.We
consideredre-grouping theinformationbutabandonedtheideaforseveral reasons.
We
couldhavere-groupeditbymachine, bysubject, by BASICversusM.L.,oranumber
ofotherways.Intheendwe
decidedthatleavingtheorder undisturbedwould bebest,andthatadding acomprehensiveindexand
cross-referencewouldeliminateflippingthrough pageafterpageoftheBitsBook.
Also,bymaintainingthe original order, thereadercanprogressfrombeginningto
end on the
same
path as thosewho
read the material from one issue of themagazine to the next.
One
can also get a feel for the time these items wereoriginallyconceivedandatwhatpointthenewer machinesarrivedonthe scene,
thus maintaining alittle"machinegrouping".You'llfind
PET/CBM
material nearthefront,
C128
andAmiga
info atthe back,withPlus4andB
Seriessomewhere
in-between;VIC 20 and
Commodore
64bitsarespreadprettymuch
overthe entirebook.
Although
some
bitsare written specifically foronecomputer, often theycan beapplied to the other machines, in principal if not in practice. For example, it
wouldn'tbedifficulttoportPlus4dazzlerstotheCI28.
The
cross-referenceImentionedarethosenumbersinsquarebrackets beside the titlesof each bit.They
refer to pages which contain other bits that are eitherdirectlyorindirectly related.Often theyrefer to bits thathave beenupdated from
an earlier issue. In such cases you'll notice that the cross-references are "bi-directional".Inothers the cross-referencewillbe"uni-directional"-itdepends on
the subjectattheoutset.For example,page117describes a
method
forsalvagingsquashed diskettes. It referencespage 182 whichdescribes salvaging scratched
files. However, page 182 does not reference 117 because information on
un-squashing afloppyisnotnecessaryforun-scratching afileonaperfectlysound
diskette.
A
bi-directionalreferenceherewouldcause a wasteoftime. Isupposeifyou hadtoun-scratchafileonasquasheddiskettethe referencemight have been
useful,butthat'sreachingtoofar.
The same
itemon 117has areferencetopage35.Page35references117becauseboth itemsdealwithfloppy diskettesspecifically,even thoughthey'retwoentirely
unrelated ideas. There are other areas where we've attempted to thread root subjectmatter suchasvideochips,sound, printers, keyboards, anddisk access.
Butifyoufindthe cross-referenceisn'tsteeringyoutotheright spot, trythe index. Also,iffor
some
reasonyouthinkthattwoitemsshouldbeconsidered"related",pleasecallor write- perhaps
we
canmake
thechangeifthereis asecondpress run.Ifanyoftheitemsraiseanyquestions, please writeusat
The
Transactor.Asofthecompletionof thisbook,
we
are also availableon CompuServe.Sign on andtypeGO
CBMNET
atany"!"prompt.Officiallywe'reinthe
Commodore
Programming andCommodore
CommunicationsForums
with plansforathirdsectiondevotedto
Commodore
Magazines. However, helpful advicecan be found in anyoftheforumsof
CBMNET.
Ifyou haven'tyettriedyourhandatonline networking, seetheTeleColumnin
The
TransactorMagazinestartingwithVolume
7,Issue04.I'dlike tothank everyone
who
hascontributedtotheBitsandPiecesColumn
overthelastfew yearsandhopetosee
more
overtheyearstocome.Remember,
eachpublishedbit isgoodforafreeoneyearsubscription.
Likeeverythingelse,bookprojects usuallytake twice aslongastheinitialestimate
- arulethat,I'mafraid, willalwaysbe"asconstantaschange".
The
firstBitsBookwas
no exception, so without further adieu, it's back to work on the nextmagazine. .
.
KarlJ.H.Hildon, Editor-in-Chief
The
TransactorMagazinededicated
toColleen
J.Hildon,
my
mom
Contents
The "Volume" and"Issue"refers tothe issue ofTheTransactorthattheseBitsandPiecesfirst
appeared.Youwon'tneedthemagazines -these arejustforreference.
A
"•" indicatesa "screen dazzler" oritems publishedpurelyfor theirentertainmentvalue.1 TheVerifizers Volume4,Issue01 5 6 6 6 7 7 9 9 10 11 11 12 OpticalIllusion • SelectiveDirectory
A
MostWelcomeErrorMessage?QuickFileReader
TheDreadedIllegalQuantity
TheMysterious Extra Records
Out OfMemoryError?
Stack(Crackle)Pop!
POPForTheC64
Universal Reset
VerticalMessages Escape Without Escape
13 ShiftKeyDetect
14 SuperPETs With HardDisks 14 Petunia Users Beware!
15 Supermon64Correction Volume4,Issue02 17 TheTransactor? 1 7 ScreenSpaced•
18 MindTwister / BrainBender•
19 LoadingC64ProgramsOnPET/CBMs
21 Cheating
A
SyntaxError21 MoreKeyCombos
22 Looks AreDeceiving! 23 Incompatibilityisms:C64 24 MoreIncompatibilityisms: Disk 24 1540/41CommandChange
25 VIC-20PrinterOutputBug
25 NoInterlaceOnVICIIChips 26 ZenithTV Mod
26 Commodore64Bugs Update
27 NewKernal
ROM
For64 28 BestMonitorPictureFromVIC/64Volume4,Issue03
31 Kaleidoscope•
32 4.0DiskAppend
33 CrashYourCommodore64! •
33 C64TVColourAdjust
34 CRlessCMD
35 SunnySideUp!
35 Waste Space 36 MovingStrings
37 Butterware
38 StringThing
38 TapemakerforBASIC4.0
40 Universal DiskChange
41 Drive1,AreYouThere?
41 SuperPETBits
41 Index ExpressionsInAPL
41 FormFeeds andSuperPETPrinterOutput
42 Simulating aGETinPASCAL
Volume4,Issue04
43 OneLine Squiggle• 44 InvisibleColours
44 Miscompulations 45 Cathode Ray Tubing 46 Combomands
47 Number Numbing
47 TimingTheCommodore64
48 DATAdjuster 50 New64 VideoPort
50 NewVIC 20PowerSupply
51 ThreeBlindNoughts
52 RetinaWrencher•
53 SupermonNotes
54 MachineCodeDelay
56 Flag Stacking
57 Arithmetickling
57 SuperPETBits
57 APLCharacterSet 57 ACIAStatusHandling
Volume4,Issue05
59 ...hadnoBitsandPiecescolumn
Volume4,Issue06 61 Incrementation• 62 Moneyout 63 Palindrome 64 AutoLiner 65 DisClosedFiles 66 DirectErrorReads 67 HardDisk Formatting
67 Disk De-ActivityIndicator 68 Weirdities
68 DLOAD'N*
68 FiveandDime• 68 PiratePeeves 69
RAM
Expansion 69 Marquis de Sade 69 InstantBASICMonitor 70 TextInDrag71 TheWooden Wedge
72 SomeMore C64HardwareTips
72 OctopusSyndrome 72 DATAdjuster Update Volume5,Issue01 75 ComputenmachinenBlitzensparken< 75 TheBrain• 75 ScreenMarquis• 76 The Boxer* 76 ScreenMarquis40•
76 Commodore64andVIC 20Versions
'
78 ThePlunge* 79 Sequins
•
79 Curtains*
80 GraphicPrint 80 Modulo Counter
81 ReverseRVS
81 OneLinePETEmulator
82 OnErrorGoto 82 But SeriouslyFolks..
.
83 Zoundz
84 aMAZEingquickies•
84
CBM
4032V2. 2 DisableVolume5,Issue02
85 Kernal 3ForThe Commodore64
85 CylinderScreen• 85 DownScroll64
86 ScreenSpaced WithColourMods• 87 Machine LanguageScreenSpaced• 87 amaZAMARAing•
88 QuickNote:on VIC 20speed
88 StopRUN/STOP
88 CursedCommodoreCursor!
89 Sorry,ButThatDOESCompute
91 Low-ResScreenCopy
91 Eep Eep
92 Mirror* 94 RamScan 95 Crystal*
96 NumberBaseConverter
97 TheUn-Cursor•
Volume5,Issue03
99 LineDoo Daa•
99 Colourtest
100 Would You BuyAUsedCarFromThisMan?
100 Bytefinder
101 QuickNote:onCollect
101 UN-DIMension 103
ERROROUTER
104 LineHider 104 GhostLiner 105 ListDecorator 106 Sinhibitors 106 ListTerminator 106 SaveTerminator 107 STOPKey 107 KeyboardKiller 107 ETCHASKETCH108 C64DefaultScreen Colours 109 TapeSaving Notes 110 RESTOREX Volume5,Issue04 111 64QuickBeep 111 Colour Bar 1 1 1
DazzleroftheMonth•
112 WhichWayDidHeGo?•
1 1
2
Aquarius•
112 QuickNote:onsprites
113 SHIFTing yourWAIT
113 InterruptKey-Scanning 113 C64Example 114 40/8032Example 114 FileRipper 1 1 5
QuickNote:oncharactersets
1 1
6
FileLoader
116 ASCII/CBMConversion
117 QuickNote:onGET
11
7
Easy Disk Salvaging 118 AMagicNumber?
118 SafeVALFunction 119 QuickNote:onloops
119 HardwareRandomNumberGenerationonthe64
119 Round-up
119 QuickNote:on INT
120 PrimeNumberGeneration 122 QuickNote:onvariables 122 UselessFact:onRUNsuffix
123 UsefulFact:on
REM
replacementVolume5,Issue05
125 Built-inDebugging Aid
125 Easy Disk Directory PatternMatching
125 Poison LineNumber
126 Closing "Forgotten"Files
126 SAVE-ingaRangeofMemory FromBASIC
127 WAIT
A
SECOND!128 CheckingforSHIFT,CTRL,andCommodorekeys
128 ChangingScreen Character Colours 129 Deathby Garbage
130 DrowninginGarbage! 131 SingleDiskCopyProgram
132 BASIC4.0 StringBug
133 InterceptingC64 SystemErrorMessages
134 C64RESTOREKey Checking
135
A
QuestionablePrompt136 FastBASICHI-RESPointPlot
136 FastHI-RESScreen Clear
137 DecimaltoHexConversionTable
138 UrgeCharacterson VICor64
Volume5,Issue06
141 C64 IRQReset
141 80ColumnRight-Justify
141 QuickNote:onloading 141 C64 Zero PageView
142 C64 V2
ROM
ColourMemoryFix143 SYScreechingOff IntoOblivion 143 DisablingRESTOREOnC64
143 QuickNote:on
NOT
144 FastHi-ResScreen ClearFrom BASIC
144 InSearchOf...ThePerfectColourCombination
144 QuickNote:VICIIvideo chip 144 PutMentalNotesonDisk(orTape)!
145 AssemblerProgrammingTip (onbranching) 145 OneLineDecimaltoBinaryConversion
146 TheBleeper
146 40Column Wordpro
Dump
146 Regain
147 WarmStartBorderFlasher 147 DoubleWidthDirectory Printout 148 C64Easy DiskStatus
148 Bounce 8032
149 FilenameExtensionsWithSHIFTedSPACE
149 EasyScreenPrint
149 PhoneSpeller
150 AssemblerProgrammingTip#2 (on BIT) 151 1541/4040Write IncompatibilityBug
152 AutoKeywordsForTheVIC, C64, PET,and
CBM
Volume6,Issue01
155 VIC/64ClearScreen Line 155 MoveScreen Line
155 TheMemoryTransfer Subroutine
156 Cheap Video-GameDept.
157 Full-featuredRACERforPETs:
157 C64mods:
157 VIC-20mods:
157 CI 6/+4mods:
158
NEW
facts158 C64 ProgrammingTip 159 DefaultsinINPUTStatements 159 350800AndItsRelatives
161 Tickertape
162 DebuggingAidUpdate
162 EasyProgram
UN-NEW
AfterReset 163 1541DOSCrashWithRELFiles163 1541DOSWedgeTips
163 One-Line Decimal
^
BaseB164 RestoreKey Fun
164 QuickNote:ondisk writing 164 ScreenSave Update
165 +4andCI 6Bits
169 B-128,1541,and 8050Bits
Volume6,Issue02
173 C64KeyboardJoystickSimulation
173 1-LineSEQfileread
173 C-64Character FlashMode
174 Plus4/C16PrettyPatterns
175 C-64: TextonaHi-ResScreen 176 "Someone's coming"or"Boss"mode
176 FastKeyRepeat 176 ModemSpeed-Up
177 1200BaudFallacy
177 BtoPET/CBMProgramConverter 178 C64ScreenSizzle
179 C64SimpleBanner Program
179 BreakBoxBaffler
Volume6,Issue03
181 Disk Cleaner
182 The1541'samazing "*" 182 World's SimplestUn-Scratch
182 C-64 Directory
LOAD
&
RUN
183 JumboRelative Files
183 APPENDingMLtoBASIC
184 Another UseFor ",A" 184 CreatingDELFiles
185 ReadBlocks FreeDirectly
185 1541 TrackProtect
186 Scratch
&
Save188 C-64POP
188 C64/VIC20PRINTAT
188 MenuSelect
189 LIST Freeze
190 ACoupleofPlus/4Goodies
191 SimulatedIF..THEN..ELSE
191
ML
Binary /ASCIIConversions193 Lett'erFly!
Volume6,Issue04
195 Multiple Directory Pattern-Matching 195 CorruptingRAMTASRoutine
195 WhereamI?
196 QUAKE!!
197 TheSchizophrenicSprite
198 Try This
198 Error-Driven Catalog RoutineforVIC/64
199 REVCNT: TheErrorRecovery CountVariable
200
ML
RightJustify200 SlippedDisks:Speedingup yourdisk drive
202 1541ders
203 C-64BASICSTP
204 Gaussian Elimination Routine
204 TheLotteryCompanion
205 TheEvilSwords OfDoom!
Volume6,Issue05
207 C-64Input RoutineWithScreenEditing! 207 QuickScreenCodetoASCIIConversion
207 C-64/VIC20Mini-Datafier
208 Dale'sDazzler
208 TheAlienFrom The CheapSci-FiMovie 208 VERIFIZERForTapeUsers
209 Improved1541Head-Cleaning Program
210 PRINT ATUpdate
212 C-128Bits
213 More B128BitsFromLizDeal
21
3
Un-ScratcherForCommodoreDrives
214 Hardware DeviceNumber Changefor2031 21
5
C64DoodleScreen
215 1541 Write-ProtectCheck 215 C-64MemoryFill
ROM
Routine216 Relocate!
Volume6,Issue06
219 SAVERIFY
219 DoubleVerifizer
220 CorruptingRAMTASUpdate 220 Finding the MissingFile
220
LOAD & RUN
Trick221 CheckFor Device Present
221 Word-WrapFor VIC,64,PET,etc.
222 Visible"searching"Messages 222 C-64ScrollDownRoutine
223 Easy'RESTOREX'Using TransBASIC 224 SneakySaves
224 SanitationEngineer
225 WhatIsGarbageCollection?
225 Faster Collection 227 SomeCI 28Bits
227 OrnamentandHappyNewYear
227 MultipleCircle,Triangle,and Square
High-ResDrawRoutine
228 3-DEffectHigh ResDrawRoutine
228 MoreIdeas
228 SomeAmigaBitsandPieces
228 NotesAbout
CU
The
"Verifizers"
[208,219]
The
Transactor's Foolproof
Program
Entry
Method
Verifizershould be runbefore typingin
any
longprogram fromthepages ofThe
Transactor.It willletyou
check yourwork
lineby lineasyou
enter theprogram,
and
catchfrustratingtypingerrors.The
Verifizerconceptworks bydisplaying a two-letter code for each
program
linewhich you
can checkagainstthecorresponding codeinthe
program
listing.Forthis Bits
and
PiecesBook,The
Verifizerwilloftennotbenecessary-theprogramsaremostlyshort
enough
that errorswillbeeasyto spot. Also,The
Verifizer
was
not invented untilVolume
6, Issue 01. Although most of theprograms
shown
are not"verifized", theVerifizershave been included hereforthosethatare,
and
forreferenceshouldwe
ever discontinuelistingone
ofthe versionsinfuturemagazines.
Thereare four versionsof Verifizer
on
thispage;one
forPET/CBMs,
theVICorC64, the Plus4,
and
theCI28.Enter the applicableprogram and
RUN
it.Ifyou
geta data or
checksum
error,re-checktheprogram and
keeptryinguntilallgoeswell.
You
shouldSAVE
theprogram,sinceyou'llwant
touseitevery timeyou
enterone
ofour programs.Once
you'veRUN
theloader,remember
toenter
NEW
topurgeBASIC
textspace.Then
turnVerifizeron
with:SYS
634
toenable thePET/CBM
version (turnitoffwithSYS
637)SYS
828
toenable theC64/VIC
version (turnitoffwithSYS
83
1)
SYS
4096
toenable thePlus4
version (turnitoffwithSYS
4099)
SYS
3072,1 toenable theC1 28
version (turnitoffwithSYS
3072,0)Once
Verifizerison, everytimeyou
pressRETURN
on
aprogram
lineatwo-letterreportcodewillappear
on
the topleftofthe screeninreversefield.Notethat these letters are in uppercase
and
will appear as graphics charactersunless
you
are in upper/lowercasemode
(pressshift/Commodore on C64/
VIC).
Note:Ifareportcodeismissing(or
"—
")itmeans
we'veeditedthat lineatthelast minute
which
changesthe reportcode. However, this willonlyhappen
occasionally
and
usuallyonlyon
REM
statements.With Verifizer on, just enter the
program
from the magazine normally,checking each report code after
you
pressRETURN
on
a line. Ifthe codedoesn't
match
upwith thelettersprintedinthebox
beside thelisting,you canre-check
and
correcttheline,thentryagain.Ifyou
wish,you
can LISTarangeoflines,thentype
RETURN
over eachinsuccessionwhile checkingthereportcodesasthey appear.
Once
theprogram
hasbeenproperly entered,besuretoturnVerifizeroffwith the
SYS
indicatedabovebeforeyou
do anythingelse.Verifizer will catch transposition errors(eg.
POKE
52381,0 instead ofPOKE
53281,0), but ignores spaces, soyou
may
add oromitspacesfrom the listedprogram at will(providing youdon't split
up
keywords!). Standardkeyword
abbreviations(like
nE
insteadofnext)willnotaffecttheVerifizerreportcode.Technical
info:The
PET/CBM
andVIC/C64
Verifizersresideinthecassettebuffer, so ifyou're using a datasette be aware that tape operations can be
dangerous to its health.
As
far as compatibility with other utilities goes, Verifizer shouldn't cause any problems since itworks
through theBASIC
warm-start link and jumps to the original destination of the link after it's
finished.
When
disabled, itrestoresthelinkto itsoriginalcontents.PET/CBM
Verifizer(BASIC
2.0 or4.0) CI 10rem*
data loaderfor "verifizer4.0" *CF
15rem
pet versionLI
20cs
=
HC
30
fori= 634to
754:read a:poke i,aDH
40cs
=
cs+
a:nextiGK
50:
OG
60
ifcs<> 15580
then print"***** dataerrorJO
70
rem
sys634
AF
80
end
IN100:
ON
1000
data 76, 138, 2, 120, 173, 163, 2 IB1010
data173, 164,2,133,145,
88,96
CK
1020
data145, 201, 2,240, 16,141,164
EB
1030
data144, 141, 163,2,169,165, 133
HE
1040
data2,133,145,
88, 96, 85,228
011050
data 201, 13,208,62,165,167, 208
JB
1060
data 254,1,133,251,162,
0,134
PA
1070
data 0,2,168,201,
32,240,
15HE
1080
data165, 253, 41,3,133,254,
32
EL
1090
data198,254, 16,249, 232, 152,208
LA
1100
data 251, 41, 15,24,105,193,
141 Kl 1110 data165, 251, 74, 74, 74, 74,24
EB
1120data141,
1,128,108,163,
2,152
DM
1130
data 251,133,251,
96
, 133, , 120, , 2, , 144, , 165, , 58, ,253, ,230, ,236, ,229, , 0, , 105, , 24, :end
144
165
165
169
217
173
189
253
2165
128
193
101C64 and
VIC-20
VerifizerKE
JF
LI
1
rem*
data loaderfor15
rem
vic/64version20cs
=
verifizer" *
BE
30
fori=
828
to958: reada:poke
i,a
DH
40cs
=
cs+
a:nextiGK
50:
FH
60
ifcs<>1 4755
thenprint"***** dataerror*****":end
KP
70
rem
sys828
AF
80
end
IN100:
EC
1000
data 76, 74,3,165,251,141,
2,3,165
EP
1010
data 252, 141, 3, 3,96,173,
3,3,201
OC
1020
data 3,240,17,133,252,173,
2, 3^133
MN
1030
data 251, 169,99,141,
2, 3,169,3,141
MG
1040
data 3, 3,96,173,254,
1,133,89,162
DM
1050
data 0,160, 0,189, 0, 2,240,22,201
CA
1060data
32,240,
15,133,91,200,152,
41,' 3NG
1070
data133, 90,32,183,
3,198, 90,16,249
OK
1080
data 232, 208, 229, 56,32,240,255,169,
19AN
1090
data32,210,255,169,
18,32,210,255,165
GH
1100
data 89, 41, 15,24,105,
97,32,210,255
JC
1110 data165, 89, 74, 74, 74, 74,24,105,
97
EP
1120
data32,210,255,169,146,
32,210,255,
24
MH
1130
data32,240,255,108,251,
0,165, 91,24
BH
1140
data101,89,133,
89,96
Plus
4
VerifizerNl
1000 rem
* data loaderfor "verifizer+4"
PM
1010 rem
*commodore
plus/4 versionEE
1020
graphic1: scnclr: graphic0:rem
make
room
forcode
NH
1030cs =
J
I
1
040
forj= 4096
to4216: readx: pokej.x:ch
=
ch
+
x: nextAP
1050
ifch<>13146
then print"checksum
error": stopNP
1060
print "sys4096:
rem
toenable"
JC
1070
print "sys4099:
rem
todisable" ID
1080
end
PL
1090
data 76, 14,16,165,211,141,
2, 3CA
1100data165,
212, 141, 3, 3,96,173,
3OD
1110
data 3,201, 16,240,17,133,212,173
LP
1120
data 2,3,133,211,169,
39,141,
2EK
1130data
3,169, 16,141, 3, 3,96,165
Dl 1140
data20,133,208,162,
0,160,0,189
LK
1150
data 0, 2,201,48,144,
7,201,58
GJ
1160
data176,3,232,208,242,189,
0, 2DN
1170
data 240,22,201,
32,240,
15,133,210
GJ
1180
data 200, 152, 41,3,133,209,
32,113
CB
1190
data16,198,209,
16,249,232,208,229
CB
1200
data165
PE
1210
dataDO
1220
data24
BA
1230
dataBG
1240
data96
208, 41, 15,24,105,193,141
12,165,208,
74, 74, 74,74
105,193,141,
1,12,108,211
165,210,
24,101,208,133,208
C128
Verifizer(40column
mode)
PK
1000
rem
* dataloaderfor "verifizerd
28
"
AK
1010
rem
*commodore
d
28
versionJK
1020
rem
*use
in40
column
mode
only!NH
1030
cs=
OG
1040
forj= 3072
to3214: readx:pokej,x:ch
=
ch
+
x: nextJP
1050
ifch<>1 7860
then print "checksum
error": stopMP
1060
print "sys 3072,1:rem
toenable"AG
1070
print "sys 3072,0:rem
todisable " ID1080
end
GF
1090
data 208,11,165,253,141,
2, 3,165
MG
1100
data 254, 141, 3, 3,96,173,
3, 3HE
1110 data 201, 12,240,17,133,254,173,
2LM
1120
data3,133,253,169,
38,141,
2, 3JA
1130
data 169, 12,141, 3, 3,96,165,
22
El1140
data 133,250, 162, 0,160, 0,189,KJ
1150
data 2,201,48,144,
7,201, 58,176
DH
1160
data3,232,208,242,189,
0, 2,240
JM
1170
data22,201,
32,240,
15,133,252,
200
KG
1180
data 152, 41,3,133,251,
32,135,
12EF
1190
data 198,251, 16,249, 232, 208, 229,56
CG
1200
data32,240,255,169,
19,32,210,
255
EC
1210
data169, 18, 32, 210,255, 165,250, 41AC
1220
data 15,24,105,193,
32,210,255, 165
JA
1230
data 250, 74, 74, 74, 74,24,105, 193
CC
1240
data32,210,255,169,146,
32,210, 255
BO
1250
data 24,32,240,255,108,253,
0,165
PD
1260
data 252,24,101,250,133,250,
96
Volume
4,
Issue
01
OpticalIllusion
This neatlittle
machine
languageprogram was
writtenbyDave
BerezowskiatCommodore
Canada. Itdoesn'tdo
verymuch
exceptcreatea ratherinterest-inglookingscreen.
The program
willwork on
40or80column
machinesbutthe80
column seemed
tobethemostimpressive.033c
Idx#$00
033e
inc$8000,
x
;vicusers
must
subst0341
inx screenaddress
0342 bne
$fa0344
inc$033f
0347 jmp
$e455
;forBASIC
4.0 users0347 jmp
$e62e
;forBASIC
2.0users0347
jmp
$eabf
;forVIC-20
usersAs you
can see, the routine is interruptdrivenwhich
means
you'll needtoPOKE
theinterruptvectorto getitgoing.poke
144,60:
poke
145,3
Afterservicing thiscode, thenormal interrupt routines areexecuted which
means
you'llstillsee thecursor.You
can evenedit(andRUN)
BASIC
whilethisisrunning,justdon'ttrytouse thecassette buffer thatitlivesinor
whammo!
Try
moving
the cursoraroundthe"affected area".Notice that the
program
is self modifying, a practice that isOK
for smallprogramsbutshouldbe avoidedliketheplagueinlargerones. Self-modifying
softwareisthe worstfordebugging
and
finding out thehardway
isnotfun.Vic users could also get thisgoingwithout too
much
difficulty(maybe
evenwithcolour?). Just substitutethe
PET/CBM
screenstartaddress($8000inthesecond line)with thestartaddressofthe screeninyourparticular Vic,
one
oftwo possibilities,
$1E00
normally or$1000
withsome
memory
expansionunits.
To
engageit. . .poke
788,60
:poke
789,3For
BASIC
4.0users,justtypein thisloader.Otherswillneedtochangejustthelasttwo
DATA
elementsand
theinterruptvectorPOKEs.
1 forj
= 828
to841
: readx:poke
j, x :next
20
data162, 0,254, 0, 128, 232, 208,250
30
data 238, 63, 3, 76,85,228
One
lastnote. . .don'ttryto include theinterruptvectorPOKEs
intheaboveprogram.
Chances
areyourmachine
willcrashbecausebeforebothPOKEs
getexecuted, aninterruptoccurs
somewhere
in-between.Selective
Directory
[125, 147, 195]Everbeensearchingthrough yourdiskettesfora
program
and
foundyourselfsifting through
SEQ
and
REL
filenamesthatjustseem
togetintheway?
Or
how
'boutthe opposite...when
you're lookingforanSEQ
orREL
filenamethat's lostindiskettesfullofprograms.Well..here'sa quick
way
aroundit.LOAD
"$0:*=PRG",8
When
finished, LISTwill display allPRG
files from the directory. Itwould
standtoreasonthatmatchingtypefilenames
would
appearforbothdirectoriesifthe drive
number
were
omitted,butsuchisnot thecase.Ifyou
leave out thedrive
number
the diskonlyreturnsfilenamesfromthelastdrive used.Mysteriously,
DLOAD
won'twork
thesame
way.You
must use theLOAD
command
followed by ',8'.Any
file type can be selected though. Merelysubstitute
PRG
forSEQ,REL
orUSR.Another variation. ..subtitute the * for filename patterns. This has been
discussedbefore,but
now
you
canlookforfilenamesthatmatch
a patternand
arealso ofaparticular type. . .
LOAD
"$1:B*=SEQ",8
.
. .wouldload adirectory ofallsequentialfiles
on
drive1 thatstartwith'B'.A
Most
Welcome
Error
Message?
[69]Never thought you'dsee theday anerrormessage
would
bepleasant,didyou?Well todayisthe day!Justturn
on
your machine,hitHOME
and
RETURN.
Too
bad
you
canonlygetitwhen
themachine
isempty!Quick
FileReader
[114,173]This three-linerwill readjustabout
any
SEQ
file.It'snot verysophisticatedbut
when
you
justwant
to"takeaboo"atafile,itcanbetypedinquicklyand
isn'ttoohardtomemorize.
The
RVS
willhelptospotany
trailingspaces.10
open
8, 8, 8,"some
file"20
input#8,a$
:?"
Q
"
a$
: ifst=
64
then close 8 :end
30
goto20
For
REL
files,simplychangetheIFstatementin line20to:ifst
=
64
and
ds
=
50
then. . .The Dreaded
IllegalQuantity
[i18]Sometimes you want
toreadfilesone
byteatatime.A
routinemuch
liketheone
above might be used, only theINPUT*
would
be replaced by aGET
#.There'sjust
one
minor gotcha. Itseems
thatwhen
a byte value of zero isretrievedby
GET*,
thestringvariableslatedtoreceiveitissettoanullstring,notCHR$(0).
The
mostcommon
occurenceofbyte-by-bytereadingiswithPRG
filesfromdisk.
Program
filescontainlotsofthesezeroes, atleastone
perline ofBASIC
(end-of-line markers). Usually a
program
toread thePRG
file isset up likethis:
10
open
8, 8, 8,"some
prgfile,p,r"20
get#8,a$
: printa$, asc(a$): ifst= 64
then close 8:end
30
goto20
The
problemisthatwhen
a zeroisreadintoA$, theASC(
functioncannot copewill a null string
and
bombs
out with?ILLEGAL
QUANTITY
ERROR.
The
solution?
You
couldadd anextraIFstatementaftertheGET*
forexample:ifa$="
"thena$
=
chr$(0).
. .but that
would
mean
an extra line for theand
thefollowingIF. . .ratherclumsy.
Keep
thingstidywith:printa$,
asc
(a$+
chr$(0))The
ASC(
function returns theASCII valueofthefirst characterofA$. IfA$
startswith avalid character,then adding CHR$(0)will
make
no
difference. Ifnot,thenCHR$(0)willbe
added
tothenullstringand
a "0" will beprintedratherthanthedreadedillegalquantityerror.
The
Mysterious
Extra
Records
[163, 183, 202]Those
ofyou
familiarwith the RelativeRecord systemwillknow
thattheend
of a relative file is flagged by the
?RECORD
NOT
PRESENT
error,DS =
50.However,thelastrecordused fordataisnotnecessarilythelastrecordofthe
file.
As
relativefilesget bigger, theDOS
formatsadditional sectors byfillingthem
with
"empty
records".An
empty
recordstartswith aCHR$(255)
followedbyCHR$(0)'stothe
end
ofthe recordwhich
isdetermined bythe recordlength.This formatting process occurs
when
data is written to a record that willrequire
more
diskspacethan has beenallocatedtothefilesofar.Each 256bytesectorcancontain254bytesofdata(theother 2 areusedbythe
DOS).Let'stakean
example
record lengthof127,thus 2 recordsfitexactlyinto1sector.Imaginethat2completerecordshavealreadybeenwrittentothefile.
Upon
writingathirdrecord,theDOS
must
formatanothersector.Two
empty
records arewritten,but thefirstwillbereplacedbythe dataofourthirdrecord.
Closing thefilecausesourthirdrecord
and
theone
empty
recordtobestoredon
thediskette.Re-openingthefile is
no
problem,buthow
dowe
findthenextavailablespaceforwritinga
new
record?Athough
ourfourthrecordisempty,aRECORD
#lf,4will
NOT
producea7RECORD
NOT
PRESENT
errorand
theCHR$(255)
couldsuccessfullybe retrieved
and
mistaken forvalid information. Therefore,we
must testthe firstcharacteroftherecord forCHR$(255).
An
INPUT*
ofthisrecordwillresultinastring oflength1,soacombinationofthetwoconditions
might beappropriate.However,
INPUT
#ingliverecordsoflengthgreaterthan 80 will produce?STRING
TOO LONG
error, soGET*
must be used incombinationwithan
ST
test:1
000
rem
* * *findnextavailable record * * *101 record*(If),(rn) :rem rn
=
recordnumber
1
020
get#lf,a$
:rem
get1stchar1030
ifds
=
50
thenreturn1
040
ifa$
=
chr$(255)and
st=
64
then return1050rn =
rn+
1 :goto1010
This subroutinewillsearchforwardfrom wherever
you
setRN
initially.Itstopswhen
eithera7RECORD
NOT
PRESENT
occurs orwhen
anempty
recordisfound. For largerfiles,
you
mightconsider startingat theend
ofthe file anwork
backwards,butyou'llneed
tofindthefirstliverecordand
thenmove
therecord pointer
one
forward.In
summary,
relyingon
RECORD
NOT
PRESENT
is notgood
enough.Althoughitwillinsurean
empty
recordeverytime,itwilleventually leaveyouwith wasted disk space. Often the first record of the file is usedto store a
"greatestrecord
number
used"variablewhich
isupdatedon
closingand
readback
on
opening.Althoughthisisprobablythe cleanest approach,itwillonlyreturn
new
recordnumbers.Any
recordsthathavebeen
deletedbywritingasingle
CHR$(255)
must be found with a subroutine like above. Possibly acombination of both these techniques will produce a
more
efficient filingsystem.
Out Of
Memory
Error?
10gosub20
20
goto10
The
problemisobvious.As
line10callsline20, line20routestoline 10,and
around
we
goagain.The
"return" information placedon
the stackbyGosub
never gets removed.
As
more and more
piles up, eventually the stackoverflows
and
the?OutOfMemory
Errorisdisplayed.FOR-NEXT
loopswillalsodo
ittoyou.IfyoustartaFOR-NEXT
loopandjump
out ofthe loop with
GOTO,
information islefton
the stack waiting fortheNEXT
statement tocome
alongand
use it. Ifanother loop is opened, thisinformation get
pushed
fartherdown
the stackand
will probably not beremoved.Thisisthebeginningofamess.
There are, however, a coupleof built-in safeguards. Ifthe loop iswithin a
subroutine,a
RETURN
will strip offtheNEXT
informationas well.Likewise,ifyou
exita loop, butusethesame
loop variabletoopen
anew
one, the old"NEXT"
informationwillbe removed.Ofcourse
nobody
writesprogramslike thisbutifyou
getthe?OutOfMemory
Error
and
FRE(0)indicates plenty ofroom
available, check your loopsand
GOSUBs.
Stack
(Crackle)Pop!
[io,188]The
following SYS'swill "crackle" yourstackand
cause a POP. Appleuserswill
know
all about thePOP
command.
It's used toremove one
level ofsubroutine
RETURN
information.However,thisPOP
simulatorremoves
ALL
levels ofsubroutinereturns.
A
particularly usefulapplicationiswithinanInput Subroutine.You
may
havealinethatdetectsacertaincharacter(eg.
"@")
that exitsthe Input routineand
transfers control toa
Command
Inputroutine. Further,theCommand
routinemighttestforaspecialcharacter
and
exittoaMenu
routine.But,jumpingoutofsubroutines with
GOTO
canbe hazardous(asdiscussedinthepreviousitem).
By
usingone
oftheseSYS's,the stackisallcleanedup and
potentialstackoverflowisprevented.
BASIC
1.0BASIC
2.0BASIC
4.0VIC
20
C64
sys50568
sys50583
sys46610
sys50544
sys42352
No,
Wait!Fooled!
The C64 and
VIC 20SYS
commands
tosimulateaPOP,don'twork. Atfirst,the
C64 SYS
appearedtobeworking, buton
further testingitwas
FUBAR.
Ididn'thavea
VIC
20atthetimeand
justassumed
itwould
bethesame
plus8192, butofcoursethis didn't
work
either.The BASIC
1.0, 2.0,and
4.0SYS
callsarecorrect.
UsingtheSYS'sfromtheearlierBASICs, I
compared
disassembliesand
foundtheequivalent
C64
andVIC
20ROM
codeliesat:64:sys
42622
($a67e)20:sys50814($c67e)
Note: differenceis
8192
($2000)Butthesedon't
work
either.Argh!The
resultsappearthesame
asRUN/STOP
-
RESTORE. The
problem? Althoughthecodeattheseaddresses isvirtuallyidenticaltotheearliermachines,thecodethatperformsthe
SYS
command
ismuch
different. Garry Kiziak ofBurlington, Ontario, explained thisin detail(Volume
5, Issue 02, Page 49)and
offered the following short routines toreplacetheabove
SYS
callswhich
don'twork.1 clear
= 828
:fork=
cleartoclear+
4
: readj:poke
k,j: next k20
data104,104,76,126,166
:remforthec64
20
data104,104,76,126,198
:remforthevie20
The
routineiscompletelyrelocatable,soyou
canputitinany(safe)placethatyou
like.Now,
aSYS
CLEAR
will clearthe stackofallRETURNS
and open
FOR/NEXT
loops.POP
For
The
Commodore
64
[9,188]The
CLEAR
routinedoesitsjobjust fine. However, itmay
alsodomore
thanyou
reallywant.Theremay
betimeswhen
allyou
want
todo
is'POP' thelastRETURN
addressoffthestack.The
following routinewilldo
justthaton
theCommodore
64.1
pop
=
828
:fork= pop
topop
+
24
: readj:
poke
k,j: next k20
data104,104,169,255,133,74,32,138,163,154,201,141,240,5
30
data162,12,76,55,164,104,104,104,104,104,96
The
command
SYS
POP
willremove
justthelastRETURN
address.Any
higherlevels ofsubroutineswillbeunaffecteduntilanothercallto
SYS
POP.Also,likethe normal
RETURN
statement,any
activeFOR
.. .NEXT
loopswithin thesubroutine will be
removed
by the POP. Notice that this routine is alsorelocatablesoitcanbeplacedin
any
'safe'place.Universal Reset
[hi,158]Instead of switching off your computer next time you
want
to clear outmemory,
etc, try thisSYS. It does thesame
thing without that nastypower
interruption.
sys
peek(65532)
+ 256
*peek(65533)
This
works
not onlyon
allCommodore
machines,butanymachine
thatusesthe6502as itsmicroprocessor.
The
6502pre-defines addresses65532($fffc)and
65533($fffd)asthelocations thatwillcontain theaddressofthemachinesreset routine.
When
you "power
up", the 6502 does a"JMP
Indirect" to $FFFC. This isknown
astheHardware
ResetVector.The
HRV
willchange frommachine
tomachine. Usetheabovestatementforuniversality; usethese
when
youwant
toresetfromaparticularmachine:
BASIC
1.0 : sys64824
($fd38)BASIC
2.0 : sys64721
($fcd1)BASIC
4.0 : sys64790
($fd16)VIC
20
: sys64802
($fd22)C64
: sys64738
($fce2) VerticalMessages
[45,80,81,173]Want
toprintastring verticallyinstead ofthesame
old horizontalway?
Easywith the
windowing
feature of8032typeand
Fat40 machines.1 input"
^3some
string"; ss$20 a$
=
ss$:gosub
1000
:printss$30
goto105010
returnThe
two "CursorHome"
charactersinline10clearany
existingwindow.
SS$is transferred toA$
tomake
the subroutinemore
versatile.Line1
000
can be removed.ItmerelyTABs
arandom amount
across the screenforthe demonstration.
Line5000 sets a
window
one
column
wideand
as high asA$
is long.The
routineleavesthe cursoratthebottomofthe
window.
Upon
returning,SS$isprinted
and
neatlyscrollsinto place.Forone
column
windows,thescrollingissofastyou'll nevernoticeit.
The
specialcharactersinline5000areachievedusing thesequenceofESCape
and
RVS.Aftertyping the quote,ESC
turnsquotemode
off,RVS
entersreversefieldmode,
and
theletter"o" (SetTop
character) ispressed. However,you'restillinreverse
mode;
hitShiftRVS
toget out.Same
goesfor"0"
(SetBottom). Trythisprogram:100
a$=
'...==»...
..=„*„.=„***„...'
110 print"d"
::remt48='s
1
20
a
=
rnd(0)*48
:i=
rnd(0)*80
1
30
printtab(i)"Q
"left$("|
|"left$(a$,a); :
rem
124
down's
&
1 right1
40
printspc(24
+
a/2)"20
Pretty useless,eh?
Escape Without Escape
The ESC
(Escape) key is foundon
Commodore
machines with businesskeyboardsonly.
On
some
earliermachinesitdoesabsolutely nothing.On
latermachineswith
BASIC
4.0,itservestocancel "quotesmode"; invokedwhen
anodd
number
ofquotekeys(")have beenpressed.
However,quotes
mode
isalso invokedwhen
anodd
number
of quotes arePRINTed
tothescreen(eg.anInput Subroutine,especially
when
you
don'twant
todisable thequotekey.Afterthe userhitsthe "
key,anycursorkeyspressedwillbedisplayedintheir
reversefieldor
"programmed"
representation.To
disablethismode,
theusermusteitherhitthe
ESC
key(ifthereisone) or typeanother quoteand DELete
it.
What
apain.The
followingPOKEs
willcancel quotesmode.
The
POKE
could beplacedafteratestforthequotekey:
geta$
if
a$
=
chr$(34) then poke. . .. ..or,
more
simply, executedafterevery keypress:get
a$
: poke. . .Herearethe
POKEs
you'llneed dependingon
your machine:BASIC
1.0 :poke
234,BASIC
2.0 :poke
205,0
BASIC
4.0 :poke
205,VIC
20
:poke
212,0
C64
:poke
212,0
Iffor
some
reasonyou
want
toturnquotemode
on,justPOKE
the respectivelocationwith a1
.
Shift
Key
Detect
[i13,128, 134]On
PET/CBMs,
thisprogram
willdetectiftheShiftkeyisdepressed.1
00
ifpeek(1 52) then print"shiftkeydown
"
101 print "shiftkey
up"
:goto100
And
YOU
say, "so what?".Well, theShiftkey hasone
advantage overotherkeysin that
no
character isentered in thekeyboard buffer to interferewithyour
GET
and
INPUT
commands. As
part ofa pieceofsoftwareits uses arelimited (Superscriptuses theShiftkeytospeed
up
scrollingthroughtextand
outputtovideo). Butofevengreater significanceisduring
program
develop-ment. Such a statement couldbe usedto re-directexecution,testvariables,
changevariables, orevenalter
machine
conditionssuch astogglingUpper/Lower
case orSTOP
keydisabled/enabled.For example:2000
print "Press'S' to
Save
Record
"
201
x=
rn :gosub
10000
:geta$
:ifa$
=
" " then2012020
ifa$
<>
"s" thenreturn2030
record#8, rn2040
print#8, rn$2050
. . .1
0000
ifpeek
(152)thenprintx;1001 if
peek
(152)then 100110020
returnOf course
any
amount
of information could be transferred to subroutine10000.
By
using acommon
variableto receive data(ie. "x"),the subroutineremainsversatile
and
can becalledfrom elsewhereinyour program.Line1001 isa loopthatwaitsfortheShiftkeytobereleased.If
you
hit"Shift"and
nothing happens, you've probablypresseditduringthisline;releaseand
tryagain.
This merely demonstratesa technique. Itcould be
much
more
sophisticatedthan shown.
One
improvement
might bethe additionofcursorposition store&
restoresubroutinecallsatthebeginningand end
ofthis"pseudo-monitor".Variables couldthenbedisplayedon, say,the top orbottomlineofthe screen
where
theywon't disturb otherscreen contents.Then
thecursorwould
besentbacktoitspreviouspositiontoretainnormal
program
appearance.Once
again,themain
PEEK
willdepend
on:BASIC
1.0BASIC
2.0BASIC
4.0VIC
20
C64
peek
(51 6)peek
(152)peek
(152)peek
(653)peek
(653)In all cases, ifthe above
PEEK
yields a zero, the Shift key isup, otherwisedown.
Otherpossibilitiesfor
poke
59468,
26-peek(59468)
poke
144,173-peek(144)
poke
144,95-peek(144)
poke
537,269-peek(537)
flip
case
(pet/cbm) stop en/disable(4.0)stop en/disable(2.0)
stop en/disable(1.0)
SuperPETs With
Hard
Disks
[4i,53]When
using the SuperPET, the language disk isusually in drive 1 ofyourfloppy.
From
theSuperPET menu, by
simply entering thefirst letter ofthelanguage(ie."a"forAPL,"b"forBASIC,etc.),thesystem goesofftodrive1 to
beginloading.
But ifyou havejustadded a
Commodore
9060or9090 Hard
Disk,you
may
have noticedthereis
no
drive 1,only drive0.Now
you must
enterlanguageload
commands
manually.Syntaxis:disk/O.APL
Ofcourse,
"APL"
couldbeany language bychoice.Petunia
Users
Beware!
Back around 1978/79,
an
interface forPET/CBMs
was
releasedcalled"The
Petunia". It
combines
an active digital to analog converterand
a videointerface for connecting to external monitors.
The
unitworks
verywellon
PET/CBMs,
but don'tusethem on
yourVICor64!The
Petuniapluggedon
atthePET
UserPort.Videolinesareon
thetopedgeand
the UserPort linesareon
the bottom.On
theVICand
64 theUserPortlinesare stillon thebottom edge, butvideosignal linesare
now
routedto aconnectorall theirown.
Where
thevideoout(pin 2)used tobeon
thePET
UserPort,is
now +
5voltson
theVIC/C64
UserPort. IfthePetunia "videoin" isconnectedto+
5voltsitwill fry likeabanana!Now,
youask,"How
doesabanana
fry?". . .plugyourPetuniaintoyourVICand
you'll find out!Supermon
64
Correction
[53]In theJanuary '82 issue of
COMPUTE!,
Jim Butterfield'sSupermon
64was
published with
one
slighterror thatwillthrowawrench
intothe works.At the
end
oftheBASIC
listingare three pokes.The
middleone
should bePOKE
45,235(not,232).Also,
Dave
Berezowski ofCommodore
Canada
suggests thismod
to beincludedatthebeginningoftheprogram:
poke 53281,
12The poke
setsthebackgroundcolourtogreywhich
looksmuch
nicerthanthebluebackground from power-up
Volume
4,
Issue
02
The
Transactor?
Since therelease ofourlatest
"new
format" Transactor,we've hadalotofnew
interestfromalotof different people,.. .
and
fordifferentreasons.Butitseems
that
one
ofthe questionsmost oftenaskedis,"Why
isitcalledThe
Transac-tor?".
Back intheolden days,
Commodore's
very first micro to hitthe market, asmost of you will
remember,
was
called thePET; an acronym
for PersonalElectronic Transactor.Also,the
word
"transactor"was
definedina dictionarysomewhere
(thatescapesmy
recollection) as"a vehicle or devicefortransfer-ring information from
one
placeto another". Thiswas
also the basis ofournew
masthead, designed to represent outward motion from a centre, butretainthefamiliarborderthat'sthe
same
shape asthestickers puton
earlymachines.
So,influencedbythesetwofacts,the
name
"The
Transactor"was
created.Butenough
nostalgicreminiscingand
sentimental memorabilia, let'shavesome
fun.
Screen Spaced
[86,87]This short one-linershouldgetan
award
forvariety of display.1 c
=
32:forn
=
1 to41 : c= 192-c
:fora=
0ton
:for
b
= 32768
+
a
to34768
stepn :poke
b, c: nextb, a, nAfterentering
RUN,
theprogram
will appeartodo
nothing. . . but don't hityour
STOP
key. . . itjustneedstowarm
up.Once
itgetsgoing Ithinkyou'll agree. . ."notbadfora one-liner, eh?"The program
couldbe sped upslightlybysubstitutingtheliteralnumericsforvariables
which would
beinitializedon
line0.Infact,anyBASIC
programon
any
Commodore
machine
will runfasterbyusingfloatingpointvariablestorepresentyourconstants(integervariables are not asfast*).
When
BASIC
runsinto aliteral numeric such as "32768", it mustfirst interpret each character
and
thenconvertittofloatingpointinthe "Floating PointAccumulator"(seeany
memory
map).Duringthis,timeisalsospenton
errorchecking.(*Integer variables aren't asfastbecausetheyalsoneedtobeconvertedto floating point)But
BASIC
just loves floatingpointvariables.The
value islookedup
in thesimplevariables table, transferred intothe F.P.Accumulator,
and
executionproceeds. Notonly that, but if the
same
constant is used in several places,you'llsave
on memory, and
therun-timeimprovesconsiderablytoo.Gettingbacktoourone-liner.. .it'swrittenforthe8032so4032,VIC-20,
and
64userswillneedto
make
changes.4032
:change 34768
to33768.
VIC-20
:change 32768
to4096
or7680* and
change 33768
to4602
or8186*
*
use
second
valuewith8K
(ormore)
memory
expanders.C64
:change 32768
to1024 and
change 34768
to2024
Mind
Twister
/Brain
Bender
This
one
will dazzle you! It's thehandiwork
ofJohn
Stoveken in MiltonOntario. In fact, don't lookat ittoo long or yourgrey matterwill turn three
shadesofpurple-ishorange
and
oozoutyour nose onto yourkeyboard, andmake
arealmess.The program
simply fillsthe screen with charactersand
then starts playingwith the
Upper/Lower
case register at decimal 59468.By
tapping any key,Upper/Lower
casemode
istoggledatdifferentrates. . .256inall! Hita "1"toend
theroutine.The
program,likesome
otherswe'vepresented hereinBits&
Pieces,issofastthatthe video
beam
can'tkeepup
with thechangingdisplay,thusproducingthetrulyweirdeffects.
It'sdesigned to
work on
8032's;BASIC
2.0and
FatForty userswill have notrouble
making
itwork, but theresultswill differ.VIC-20 and C64
userswill,once again, need changes; two to the screen start
and end
addressesand
anotherfortheUpper/
Lower
case controlregister(59468on PET/CBMs). The
codeisrelocatablesoitwill
work
whereveryou
havememory.
The BASIC
loaderthat followsis allyou
need toget itgoing(or ratherall itneedstoget
you
going).RUN
itand
enter:SYS
20480
The
number
"1"shown
inbold
on
line30isthebasecharacterusedtofillthescreen.Fordifferenteffects,trychangingthisto193, 223, 255, oryourchoice.
You
"need-to-know-what-makes-it-tick"machine
codeaddictswillfindthesourcecodefollowing theloader.
1 forj
= 20480
to20539
: read x:poke
j, x: next:end
20
data169, 128, 133, 1,169,0,133,
30
data 168, 169, 1,145,0,200,192,
40
data 208, 247, 230, 1,165,1,201,136
50
data 208, 239, 169, 12,141,76,232,173
60
data76,232,
73, 2,141,76,232,165
70
data151,201
, 255, 240, 7,201
, 49,208
80
data 1,96,198,
2,166,2,202,208
90
data 253, 76, 31,80
loop sta loop2 next lop lopl Ida sta Ida sta tay Ida ($00) inycpy
bne
inc Idacmp
bne
Ida sta Ida eor sta Idacmp
beq
cmp
bne
rtsdec
Idxdex
bne
jmp
.end$5000
#$80
$01#$00
$00
#$01
,y#$00
loop $01 $01#$88
loop#$0c
$e84c
$e84c
#$02
$e84c
$97
#$ff lop#$31
next$02
$02
lopl loop2 ;screenstart ;base
char. ;screenfull? ;setgraphic ;toggleto ;textmode
;keypressed?
;no,do
delay ;yes, isita
1?;no,
change
delay;yes,
end
;alterdelay ;and
do one
Loading
C64 Programs
On PET/CBMs
pi6]BASIC
programs inPET/CBMs commonly
start at $0401. ButC64 BASIC
programsstartat
memory
location$0801 (remember,thereisalwaysa "zero"in the byte preceding
BASIC
text space). SoCommodore,
in their infinitewisdom, decidedthatthe64
would
havethecapability tore-locatePET/CBM
programs.
They
LOAD
rightwhere
the64 wantsthem
withallchain pointersadjustedperfectly.
Notsointhe reversesituation!
PET/CBMs
didn'tknow
therewas
goingtobeaC64. .. so programswritten
on
the 64 willLOAD
into thePET
at address$0801.
YUK!
Thereareactuallytwosolutionstothisone.First,
we
couldmove
theStart-of-BASIC
pointerinthePET
"up"to$0801.Then
a zeromust
beplacedat$0800tokeepthe operatingsystem happy.
A
LISTwould
displayyourprogram
ok,but
SAVE
orDSAVE
would
reephavoc!On
PET/CBMs,
SAVE
alwaysstarts at$0401. This
would
storeIK
of "fore-junk" before reaching the start oftheactualprogram. Takethisfileovertothe64
and
itwill tryand
loadthisfore-junk,leaving
memory
fulloforganizedhodgepodge.The
onlyway
arounditisto use the M.L.Monitor to store the
program
from the PET,which
is alsopainful because
we
need to find the end-of-program address for the .Scommand.
Soforgetallthis. .. here'sa
much
easierway
(thankstoJames
Whitewood,MiltonOntario):
l.Type:
NEW
2.
LOAD
theC64
programintoyourPET/CBM.
A
"LIST"atthispointshouldresultin
"READY."
3.
Add
the followingline ofBASIC:REM
4.
Now
enter:poke
1026,85.Deleteline bytypinga
and
<RETURN>
6.lastly,enter:
poke
43,peek(43)-4
: clr7.
Type
"LIST"and
yourprogram
willbethere!A
briefexplanation.InStep1,thePET
thinksno program
existsbecausethefirstthingin
memory
isanend-of-BASIC
marker
(2consecutivezeroes).Step 2 loads the64
program
intothePET
and
setstheEnd-Of-BASIC
pointer.PET
now
thinks aprogram
existsinmemory,
but theend
markerisstilldown
at$0401,soLISTwillnevergetpastthispoint.
InStep3,all
memory
between
$0401and
theEnd-Of-BASIC
pointer(whichispointingatthe
end
ofthe64 program)ismoved
up
tomake room
for"0 rem".The
forward chain pointerforLine isnow
pointingat$0407, theend
marker.The
firstbyteofthe64program
now
liesat $0807.By
alteringonly the highorder byteof the chain pointer(Step 4), Line is "linked" to the
program
residingat$0807.
The
loworder byteneednotbeadjusted sinceitwillbethesame.
Step 5 deletes Line 0.
The
PET
treats this likeany
other delete.The
space occupied byLine isreclaimedbymoving
theLinesabovedown.
Line is effectively"squeezed out". But since Linewas
thefirst Line, thenew
firstLinewillbethat ofthe64 program.Presto!
The
64program
isrightwhere
thePET/CBM
ismostcomfortable with it.Step 6adjuststheEnd-Of-BASICpointer.
When
alineisdeleted, itisassumed
itwillneverbelongerthan255bytes so only theloworder byteofthe pointer
isalteredunless
one
pageboundary
iscrossed. In thiscase4page boundariesarecrossed, so
we
have todo theadjustmentourselves.The
CLR
command
cleans
up
all the other pointers. Omitting this stepwould
cause 4 pages of"after-junk"tobestored
on
aSAVE.Wouldn'titbeniceifeverything
were
so simple?Cheating
A
Syntax Error
[46,220]Ifyou're extremely lazy like me,
you
probably take any chance tomake
programming more
effortless.Forexample.The
RUN
command
isthreeentirekeypresses followedbya Return.
And
you
don'talwayshitthem
right.How
many
ofyou
haveentered"RUIN","RUB"
or"RUM".
Argh! Right?Wellfellow short-cutters,
Wayne
GarvinofToronto hasthisone
for us.The
keys Shift
and
RUN/STOP
do the autoLOAD
and
RUN
sequence.Some
machines
want
toloadfromdisk,othersfromtape,but everymachine, backtotheoriginalPET,hasthisfeature.
Buttry this!
Type
a letter (eg. "k")and
thenhitShift-RUN/STOP.A
?SyntaxErrorwill result
and
theLOAD
is ignored. However, the charactersR-U-N
and
Returnarestillinthekeyboardbuffer.Thesewillbehonoured
asifYOU
enteredthem,
and
your programsbegins!Justdon'thita
number
keyfirstortheLOAD
command
willbeenteredon
aprogram
linewhich
mightmutilateexistingcode.Thislittletrickisconvenient.. .it
means
I'llseemy
programerrors thatmuch
faster.More Key
Combos
[46,220]If
you
have an8032,8096
oraSuperPET, you've probably usedthe":"keytopausescrolling
when
LISTing aprogram
or aCatalog.Trythis. LISTaprogram
and
hitthe":"key;thelistingstopsatthebottomofthescreen.
Now,
withyourforefinger
on
the":", useyour pinky topress theRUN/STOP
key; scrolling
resumes.
To
pause,releaseRUN/STOP;
toabort,releasethe":".AnotherIuseoftenis"Shift,RVS,
A &
L". HitShiftfirst,then RVS,and
pressthe
A
and
L keystogether.Thiscombination doesaline insert.. .handy
forinserting lines into programsvisually.
The
screen will scrolldown
from thecursorline
and you
fillinthe gap.Looks
Are
Deceiving!
How
may
syntaxerrorscanyou
find in thisline:ifgorb>tandforinthend
=
storun:header
"disk",d1,ifnSome
areratherobviousbut don'tbefooled. ..otherpartswillrunfine.The
problemisaresult of"tokenizing".When
you
hitReturntoenteralineof text, theBASIC
editorbegins analyzing or parsing the line(from leftto right)lookingforpatternsthat
match
pre-defined keywordsinROM.
Ifamatch
ismade,theeditorconverts thesequenceintoa
number
or"token".Tokens
areusednotonlytosave
memory
(ie.keywords
consume
onlyone
byte)butalsoforspeed.Duringexecution,
BASIC
needonlyinterpretasinglebyte insteadofstring of2to7 characterslong.
The
first is probably themost
difficult to spot.The
sequenceG
OR
B
willcorrectly calculate
G
OR'd
with B, until the spaces are removed!Now
iteffectively
becomes
GO
RB.Yes,"GO"
isactuallydefined asakeyword
thatdoesn't
do
anything, unlessyou
like puttingspaces in yourGOTOs
(ie.GO
TO).To
honour
thespacedout"GO
TO",Commodore
hadtoincludeGO
inthe
keyword
table. Otherwise"GO"
would
be considered a variable duringexecution, followedbythe
keyword
"TO",and
a?Syntax Errorwould
result.Such
was
the case in the originalBASIC
1.0. AllBASICs
from 2.0on
incorporatedthischange.
Two
rules here: 1. Don't useGO
for a variable, and; 2. if the variableG
precedes the boolean operator OR, follow
G
with a space or enclose it in brackets.This next
one
iseasy.T
AND
Fwillread asTAN
DF. Since thereisno open
bracketforthe variable DF,?SyntaxErroroccurs.
Once
again,followT
with aspaceorputitinbrackets.
The same
thingwillhappen on
FOR
and INT
untilwe
use spacestoseparate:. . .t
and
forin. . .is