Text content (OCR)
Oper-Apple —
Releasing the power to everyone.
March 1985
Vol. 1, No. 2
: FLASH:
yer eS BR,
Steve Wozniak, designer of the Apple II, is no longer involved in any Apple
projects, although he remains an employee on a consulting basis, according to
Linda Merrill, Apple II specialist in Apple's corporate relations department. Steve
is starting a home video products company, which will develop products that will
allow consumers to use video cassette recorders in new ways. Wendell Sander,
head hardware designer for the Apple III, has reportedly joined Steve, but that is
unconfirmed.
According to the Wall Street Journal (Feb 7, p. 42), Wozniak told reporters that
his departure was prompted in part by bitter disagreement with Apple’s manage-
ment over the company's direction and by frustration with the rigidity of a big
corporate bureaucracy. Wozniak said the Apple II “has been ignored in the hope
that it will die and go away.”
Steve's new products have “nothing to do with home computers,” according to
_. Mertill. Steve has always been a vocal spokesperson for Apple II users inside
Apple itself. Although he is still “officially a part of Apple”, his absence on a full-
time basis is a blow to those of us already concemed about the relatively
minuscule development investment Apple makes in its Apple I! family.
Apple's annual stockholders meeting, held on January 23 this year, was a
Macintosh circus. Not one of the new products announced works with the Apple Il
Apple did announce, however, that by fall it would have a peripheral card for the
IBM PC that will allow connection to AppleTalk —its new low-cost system for
hooking (non-Apple II) personal computers, printers, large memory devices, and
other peripherals together.
Apple spokesperson Merrill tells us Apple is aware that many Apple II users,
particularly in educational institutions, are interested in this capability and she
assures us that Apple is working on it.
Meanwhile, AppleWorks was December's sales leader in retail stores,
according to Infocorp,a market research firm in Cupertino. The program walked
away with 17 per cent ofall software sales. The much ballyhooed Lotus 1-2-3 was
in second place with just 10 per cent of the market.
Quote of the month:
‘
I would argue that the ultimate deciding factor in computer obsolescence is
software availability. The sure sign of a computer growing into obsolescence is
: that no new software is being developed for it. And if software is available to do
* what you want done with your computer, it will not be obsolete for quite some
time. (By this measure, the Apple II may never be obsolete.)
The quote is from Mark Wilsdorf, editor of AgriComp (105 Outdoors Bldg,
* Columbia, MO 65201, $24/yr), a well-done magazine that covers the area where
agriculture and personal computers overlap. Much of the magazine's material is
based on spreadsheet templates that work with any kind of computer. If you are
one of the world’s unfortunate souls involved in agriculture, you should get this
one, depression or not.
New enhanced ROMs for the Apple Ile have been mentioned in various press
reports the last few weeks. The new ROMs reportedly make the Ile and IIc more
compatible. When Apple officially introduces these new ROMs we'll have a com-
plete report (and if it's not by March 15, the April Open-Apple may be mostly
blank).
Basham fires up the Incinerator
I got a letter and disk from Bill Basham, developer of Diversi-DOS (arch-
competitor of my own ProntoDOS) this month:
Your discussion of garbage collectors in the January issue inspired me to
finally write one. I've enclosed the latest Diversi-DOS update, which includes a
48K and a 64K garbageman on it.
I hereby donate the 48K garbageman to the public domain. Since the 64K
version works only with Diversi-DOS, | will retain the rights to it. There's also a
source listing for the 48K garbageman for you to publish if you wish. Of course,
used the Pascal assembler (ed note: expletive deleted), so you may have to do
some retyping and possibly add some improved comments. Feel free to make
upacatchy name for it.
My garbageman may be a little slower, but I'm confident that it is the world’s
smallest. That should make it ideal for publication, and | hope will make that
issue a hot one.
Bill apparently wants me firmly entrenched in the newsletter business and out
of the DOS-enhancement business. After looking over his program | am inclined
to give up trying to compete with him — this is a masterpiece.
Readers of our January issue will remember a two-page spread on how to avoid
garbage collection — the malady that strikes string-intensive Applesoft programs
at the most inopportune times, ProDOS solves the problem by including its own
high-speed garbage collector. Now DOS 3.3 users also have a high-speed garbage
collector that fits entirely within DOS. As with ProDOS, however, you have to give
up the ability to initialize disks.
Basham’s program, hereby christened the Incinerator, works by making a
temporary copy of the standard Applesoft garbage collection routine and mod-
iffing it. The copy is placed in the DOS “nibble buffers”, a rather large memory
area that gets overwritten whenever a disk is accessed. Since the disk is inaccess-
ible while the routine is running, however, its a nice safe place to go to burn the
garbage.
The modifications cause the old garbage collector to use two new routines at
critical places. These routines, as well as the code that moves and patches the
old garbage collector, resides in the DOS area normally used by the init com-
mand. The program begins with a third section that installs the main body inside
DoS.
Here's the speed comparison from our January article with Incinerator timings
added:
Garbage
500 Ls t)
2
14 4
1008 5
For those of you interested in such stuff, the complete source code for
Basham’s Incinerator follows. You can study it with the help of the comments I've
written. If all you want to do is use it, you can type it in by hand. However, if you
have a modem, software that allows you to capture files, and access to Compu-
Serve, you can also download it from the Micronetworked Apple User Group
library (GO PCS-51). It's filed in the “Apple Il Hacking” section. Select brouse from
the menu that appears and enter INCINERATOR when you are asked for a "/key”
(All of the other programs in the first three issues of Open-Apple are also now
available in the MAUG library.)
Basham’s original version— the one that now comes with Diversi-DOS—is
connected to the Applesoft ampersand hook. | have modified the version pub-
18 Open-Apple
lished here so that itis called automatically by DOS every time a carriage retum
is printed. On each call, the amount of unused memory left is checked. If there
is more than about 1K, control quickly returns to DOS, If there is less, collection
occurs automatically.
To force collection, use the following command:
POKE 48816,0 : PRINT : POKE 48€16,4
The complete source code follows:
If you want to type in the Incinerator by hand rather than downloading it
from CompuServe, the easiest way is to enter the material in the gray boxes
using the Monitor commands we've covered in last month's issue and in this,
one. Check your entries using the Monitor's L(ist) command. Then enter
BSAVE INCINERATOR, AS4000, LS1BA. To execute the program, enter BRUN
INCINERATOR.
+: INCINERATOR
+ Fast garbage collector for 48K 905 3.3
+: By Bill Bashan, Diversified Softuare Research
. Jarvary 1988
+ Camara ti by Ton Keishaar
* 2B public domair program
OR $4000
TF INCINERATOR
COUNTER EQ 546
INDEX EQ $86
STREND EQ SED the louer edge of string space
FRETOP EQ S6F_ new strings are stored From rere doun
NENSIZ «£0 $73 the upper edge of string space, HINEM
FNCNAM EQ. 588A
OSCLEN «EQ S8F
LOWTR £9 $98
P3.D0SWARM .£0 $300 page 3 vector
INITADR EQ $9D1E_INIT’s entry in 00S eva Jump taole
FMINIT EQ SREBE File Manager's INIT instruction area
RUTS.INIT EQ SBEAF RNTS's INIT instruction area
cout EQ SFDED Monitor's print-character subroutine
e800: 00 .GeRB £0 $8600 ($£484) Audresses of FP.GARE
e808: MOD.CONTINUE £9 $8808 (SE48C) entry points after
BCE: MOD.CHECK.BUMP .£0 $BBCE (SESS2) relocation in 00S
e8e4: MOD.MOVEUP «EQ. SBBE4 ($E56B) nibble buffer.
e621: mO0.RELO EQ $8621 (SE4AS) Points where MO0.GARS
e852: NOD.PTCH.2 EQ $8852 ($£406) ust be changed due to
ea8e : NOD.PTCH.1 EQ S8BBE (SES42) relocation.
e484: FP.GARE +0 S484 Address of original garbagenan
+ INCINERATOR’s string address buffers
NSTR £0 34 of strings collected on each pass (34 7ax)
1SC.AOR-LO .£9 FM. INIT FILINIT ares (AESE-AF27)
DSC.ADR-HI £0 OSC.ADR.LO-NSTR is usea to save string
DSC.LEN £0 OSC.ADR.HI+NSTR variable table pointers.
STR.ADR-LO .£0 $8C1L Left-over part of nibble ouf
STR.ADR.HI EQ STR.ADR.LO*NSTR is used for string pointers;
. ends at $856, thus 34 max
CHECK 005,
cic First, check to sake sure DOS
E LDA 2s00 hasn't already been nodified.
4003:A2 00 LOx ase0 Installing the INCINERATOR
4005:A0 01 Loy 2801 over an existing 00S patch
4007:79 01 @3 | .1 ADC P3.DOSUARM+1,Y could damage disks.
4008:90 01 ecc.2
4000:€8 Inx Check ts made by simply adding
4000:73 1€ 90)
4010:90 OL
4012:08
4013:79 8E A
4016:90 @1
401a:£8
4019:79 AF Bt
401C:90 @L
4016268
401F :68
4020:10 £5
4022:09 FL
4024:00 04
4026:£0 03
4028: 43
402A:AE 53. AR
4020:¢8
402£:89 30 40
4031:F0 06
4033:20 €0 FO
4036:4C 20 40
4039:8€ 59.98
403C:60
4030:80 C3 CL
4040:87 C1 C3
4950:C6 C9 CS
4@60:CE 16 90
4070:89 56
4072:80 0€ BE
4075:80 00
4077289 CS 40
4078:99 AF BE
4070:¢8
4076:00 F7
4080:A0 02
4082:89 C2 40
4085:99 20 SF
4088:88
4089:10 F7
4088:AE $9 -AA
408€:C8
408F 189 9 40
4092:F0 06
4094:20 £0 FO
4097240 BE 40
4098:86 53.AA
4090:60
409€:80 04 CB
40RE:A@ C9 03
408E C4 AE 8D
40¢:
CAF BE
2 AOC
INx
oc
Ink
AOC
INnx
+5 OEY
PL
ace.
Bcc.
ec.
Vol. 1, No.2
INITAOR.Y together the First two bytes
3 in each area to be modified
and comparing the result uith
FIINIT.Y the standard 00S 3.3 result.
4
If 005 has been roved to tre
UTS. INIT. Y language card area, or if
s program is run under ProD0S,
inclusion of page-3 uarsstart
vector (see $4907) will cause
dh check to fail.
381
6
3803
INSTAL F installation below.
$0AS3 DOS ~ooified.
Save DOS stack pointes unile
“3 printing error vessage.
8
cout Print nessage.
2
$AA53 Restore stack pointer
"1 EXECUTE.”
AS ="ACTIVE 00S MODIFIED OR MOVED. ~
HS. 60.00 +
CE A? D4 AB CS 08 CS C3 OS 04 CS AL BO
D4 C9 06 CS AO C4 CF 03 AO CO CF Ca Co
C4 AO CF 02 AO CD CF 0S CS C4 AC BO 00
INSTALL
EC INITAOR Point INIT entry in 00S cosmand table to a7
LOR 2856 RTS--005 INIT command nou does nathing.
STR S8E0E Disable RUTS ‘format’ command.
Loy 2800
<1 LOR TEST.GARB,Y Move INCINERATOR routines to area normally
STA RUTS.INIT,Y used by the RMTS init command.
Iny
BNE 1
Loy #se2
-2 LOR .6,Y Irstall hook in 00S. Putting hook at SSF2C
STA s9F2C,¥ neans INCINERATOR will be called wherever
oey a <retur> is printed.
ePL 2
LOX sARSS Save DOS stack pointer while printing “sg.
<2 Ny
\OR .5.¥ Print successful-installation-message.
EO .4
JSR COUT
sre 3
<4 STX SARSS Restore stack pointer and
RTS return to caller; installation done.
+3 -HS 80
-AS -"THE INCINERATOR 15 NOM INSTALLED.
HS 80.00
C5 AO C9 CE C3 C9 CE CS 2 Cl D4 CF D2
AQ CE CF 07 A C9 CE 03 04 C1 CC CC CS
20
6 JNP RUTS.INIT Hook to our routines; waved to $9F2C
+ INCINERATOR main eody
These routires are moved into the RUTS INIT space ang
are called by DUS every tine something is printed.
TEST.GARB
LOA Hso4 Main entry point. First check to see if
BEQ INCINERATE garbage needs to be collected. If
cue lots of space is left, don’t proceed.
AOC STREND+1 The $04 at $49C6 means collection
CNP FRETOP.1 occurs only if there is less than
BCS INCINERATE 1K free. Change it if necessary.
DONE
INP s9FRa Return to 00S to continue output.
March 1985
“
* INCINERATE
+ These routines move a copy of Applescft’s original
+ garbage collector into the 00S nibble buffers, patch it
+ so that it calls new routines at tuo critical places,
* and then junps to the neu version.
INCINERATE
4003:80 13, Loy 2813 FP.GARB is Applesoft’s original garbage
4005:69 83 £5] .1 LOA FP.GARE-SFF.y collector. First ue move it into the
4008:99 FF 88 STA MOD.GARB-SFF.Y 005 “ribble buffe-s” at $8800-8C55.
4008268 ogy These are overuritten on all 00S
4000:00 F7 BNE «1 calls, but ue can use then for a
one :83 84 £4] .2 L08 FP.GARB.Y morent here.
40€1:99 00 68 STA MOD.GARB.Y -«MOD.GARB is uhat we call the new
406408 INy location, since the rex copy will be
40€5:00 F7 BNE .2 patched by the routines belos.
4967:98 Ta
40€8:90 2 Loy BNSTR-L
40ER:84 45 STY COUNTER Initialize COUNTER with the nunber of
49EC:93 33 EC] .3.STASTR.AOR.HILY strings (minus 1) and Fill the string
408F 283 adores ouffer uith zeros.
40Fo:12 FA
40F 2:90 03 Loy 2503
40F 4:86 03 GF | .4 LOX RELOCATION. TABLE,Y —Aajist Four adrs within MOD.GARB
40F7:69 07 F | LOR RELOCATION. TRELE+4.¥ that rust charge beca.se it’s
40FA:90 21 88} STA MOD.RELO.x beer saved.
40F0:A9 8B Lon ase (S88 is the correct high byte
40FF:30 22 88] STA MOD.RELO+1,x for all relocates adrs.)
4102:68 oey
4103:10 EF ePL 4
4105200 02 Loy 2502
4107:89 08 BF | .5 LOR PATCH.HOOK,Y Modify GARB in tuo places so that it
4108:99 BE 68 STP MOD.PTCH.1.Y jumps to our new patch routines
4100:89 0£ BF | —_LOF PATCH.HOOK+3,¥ rather than doing thicgs
4110:99 52 68 STR MOD.PTCH.2,Y FP way.
4113286 vey
414210 FL BPL Ss
4116:4c 00 68 | InP mOD.GaRB Junp to the neuly sodified garbage
‘ collect
8F03: RELOCATION. TABLE £9 *-TEST.GARB+RMTS. INIT
HS 00.19.70.8F .9F.95.9F Data reeded for relocation.
ef oF 95 SF
4120:60 Patch for original mave-string routine.
eF08: PATCH.MODK EQ *-TEST.GARB-RUTS. INIT
alzisa0 60 OF IMP SAVE.AORS
4c 11 BF IMP POVE STRINGS
+ MOVE.STRINGS is called b, our roviFied ga-bagerar
+ afzer a corplete scar of the strirg variable
+ tables has beer corpletes.
Bri: MOVE .STRINGS -GARB+RUTS. INIT
4127209 22 alize courter with tre runber of
4129:85 46 STA COUNTER strings our buffers will hold.
FINO.AIGH
4128282 21 LOX ENSTR-1 X is first adr: becones tne highest found.
4120280 20 LOY SNSTR-2 ¥ points to the adr under stuoy.
AL.CHECK
412F :89 33 8C L09 STR.ADR.I,Y —Corpare current to highest fourd so far.
4132:00 33 eC Che STR.ADR.HI.X
4138:90 @C BCC NXT.HI Current is less.
4137:00 08 BNE NEWT Current is greater.
4139:89 11 BC | LOR STR.AOR.LO.Y Can't tell, test low ©.
413¢:D0 11 BC | CHP S7R.AOR.LO,x
413F:30 02 CC AxT.AL Current 1s less, next please.
4141298 NEu.aT 18 Currect is greater, “ove currert
4142:R8 Tex pointer to xX.
4143268 NXT ol OEY Conzinse uci entice Cuffs" has beer
4144210 £9 PL I.CHECK scarred: X ther poirts to highest
d string in buffer.
Open-Apple 19
* Pass this adgress to a section of the
+ original garoage collector for moving.
LDA STR.AOR.HI,X Get highest adr
4149:F0 BED DONE If zero, we've moved then all.
‘ Collection complete, return to 00S
4148:85 9C STA LOMTRSL Pass it to MOD.GARA
4140:80 11 8C] LOA STR.ADR.LO,x
4150:85 98 STA LOMTR
4182:89 00 Loa 2800 Resove this access fron buffer
4154:90 33 BC] STA STR.AOR.HI,x
4187:80 80 PE] LDA DSC.ADR.HI,X Pass the descriptor address and length
415R:85 8B STA FNCNAMSL to MOD.GAFE
41SC:80 8£ AE | LOA OSC.AOR.LO,x
415F 95 6A STA FNCNAH
4161:80 02 AC | LOR OSC.LEN,x
4164:20 £4 88 JSR MOD.MOVEUP Tell MOD.GARB to move it.
+ Repeat until everything in buffer has been noved.
4167286 GF 51% FRETOP Adjst FRETOP
4169:85 70 STA FRETOP+1
4168:C6 46 DEC COUNTER Continve wrtil all ages
4160:00 BC ENE FIND. IGH buffer have been =oves.
416F 90 LOY aNSTR=1 Reset counter for SAVE.ADRS
TY COUNTER
4173:4C 08 88 | INP MOD.CONTINUE Ana continue search.
+ SAVE.ROR is called uhen MOD.GARB has found a string highe-
+ than the lowest string found so far. SAVE.ADR saves
+ the address of tne string and its variable-table
+ descriptor address and length in our special buffer
+ The reu string’s addresses overurite those of the louest
+ string found 4p till nou.
+ Afteruards, a scan is made of the buffers to redetermine
+ the address of the lovest string found so far.
4 The address of that string is passed to MOD.GARB
+ and the pointer to it is saved so that any higher
+ string found will overurite it.
BF60: SAVE.AORS £9 1-TEST.GARB+RUTS. INIT
‘4i76:A4 46 COUNTER Get current index to adr-sa.e buffers.
4178:99 33 SC STR.AOR.HI,Y High byte of string adr ir A; store it.
4178:88 Lou byte of string adr in x: store it.
4170:99 11 8C STRAOR.LOWY
417F AS SF INDEXe1 High byte of descriptor address was in
4181:99 60 AE OSC.AOR.HILY INDEX-+1; store it.
4184: AS SE INDEX Lou byte of descriptor add-ess was in
4186:99 BE AE OSC.AOR.LOY INDEX: store it.
4189:AS BF OSCLEN Descriptor lergth:
4188:99 02 AE OSC.LEN.Y store it.
418682 21 LOX ANSTR=L X starts as pt- to first adr ir oft
. becoves ptr to lowest adr in buf.
4190:A0 20 LOY aNSTR-2 Y as pointer to adr mou under study.
cOu.crK
4192:80 33 8C | LOA STR.ADR.HI,X Compare current low to adr under study.
4195:FO 1E 8E2 LONE Hf current low is zero, evit.
4197209 33 BC | CHP STR.ADR HI.
419A:90 @C BCC NXT.LOM Current low is louer, next please
419C:00 08 BNE NEW.LOM Neu adr is lover, point to
419€:60 11 @C] LOA STR.AOR.LO,X Can't tell--test low byte.
41Al:09 11 BC} CHP STR.AOR.LO,Y
414290 02 BCC NXT.LOM rest please
NEW.LOW
4196:98 1A Move pointer ained at current adr to
4187228 TAK pointer for lovest aa
NXT LOW
4198:68 Oey Check next adr in buffer till
4199210 €7 PL LOW.CHK there aren't any move.
41A8:80 11 BC] LOA STR.AOR.LO.X Ther tale the lowest address we have ir
41RE285 9 378 LOMTR the buffer so far and put it in LOUTR,
41B0:80 33 8C | LOA STR.ADR.MI.X so MOD.GARB ill call us if it Firds
4183:85 9C STA LOMTR-L ary higher strings.
LOONE
4185:65 46 31x COUNTER Save ptr to louest string as neu index
Open-Apple
20
A Song Continued
We descended into the murky depths of the Apple Monitor last month,
examined memory 2sa dump of hexadecimal values, as machine language code,
and as ASCII characters. | explained how to change the contents of any memory
byte from one hex value to another. While these are the most common uses of
the Monitor, it can also do other useful and interesting things.
The Monitor was actually designed as an assembly-language-program debug-
ging aid. Nowadays— nearly a decade after Wozniak designed it—much better
debuggers are available. Nonetheless, the fact that this one has been built into
every Apple ever manufacturered makes its features worth further investigation.
It is difficult to stamp out all the bugs in assembly language programs without
some way to stop the program at trouble spots and see what's happening. The
standard method for doing this is to use the break instruction. The machine
language code for a break is $00. To see what happens when this instruction gets
executed, let's put one at address $300 and jump to it. Here's how:
#30020
- 88 2 08 20 ee 02 20 08
*3006
(veep)
0302-
Ae00 x=00 200 P=3
£0
When you enter 500G, your Apple executes the break instruction we just put at
thataddress. This causes a “crash” back into the Monitor. You will hear a beep and
seea one line display that begins with an address. The address is always two bytes
beyond the location of the crash-inducing break instruction. The rest of the line
shows you the status of your microprocessor when the break occurred. The 6502
microprocessor found in Apples has five special memory locations, called regis-
ters, that do all the work. These are called the A, X. Y, P, and S registers. The display
shows what values were in these registers when the break occurred.
After a break, you can List your program or examine memory. Ifyouneed torefer
back to what the contents of the registers were when the break occurred, you can
do so with the control-E(xamine) command, like this:
J (press control-€. return)
A:00 x200 ¥=00 Pe:
SsFo
You can also load the registers with any desired values before executinga routine
by using control-E, entering a colon and the desired memory values, and Going to.
the desired routine. In the following example, we putnewnumbersin the A, X.andY
registers and jump to our break instruction to see if they're really there:
‘ (press contral-£, return)
A=00 x=00 ¥=00 P=30 S=FO
fru 22 3
*3006
302-AeLL x22
Note: unless you know what you're doing, don'ttry to change the contents of the P
or S registers. The effect can be dramatic.
Meet Mini. The Monitor program built into the original Integer Basic Apple II
also had commands for stepping through and tracing machine language pro-
grams, as well as a Mini-Assembler. The Mini-Assembler allows you to enter a
program in assembly language. Itstil exists in the integer Basicimage on DOS 5.3
System Master disks, but the S(tep) and T(race) commands are unavailable to all
buta few old-timers.
The Mini-Assembler is useful for entering short and quick assembly language
programs. It doesn’thave many of the features ofa full-blown assembler, however
(such as labels, equates, and assembler directives), so its usefulness is limited.
To get it running, boot a DOS 3.3 System Master disk and enter the intcommand
to get into Integer Basic. Then call -2458 (or drop into the Monitor and enter
F666G).
The Mini-Assembler prompt is the exclamation point. All Monitor commands
work within the Mini-Assembler if you start a line with a dollar sign. To begin an
assembly, enter the address at which you want the machine langage to go, acolon,
and a mnemonic:
snnesstidnaiotaalsin am inlet nicl
Vol. 1, No. 2
Monitor Command Summary
Commands for Examining Meaory
display contents of one sesory byte {adr} (return)
(successive returns display up to 8 additional bytes)
display contents of a mesory range {stare} . {ena}
display contents as a machine language program: L(ist) {stare}
display contents of registers last tine BRK occurred. (Control -£)
display differences betueen tuo ranges of
nenory; V(erify) {rngl.stare} < feng2.start} . {eng2.end} v
S(earch) for consecutive bytes holding $xx SY¥
(enhanced Ie OKs only) wxx ¢ feng.start}. {rng-end}
Commands for Changing Nenory
place neu values tor] : {val} (space) {val} (space) {val}
place neu values (Control-£) : {A} (space) {x} (space) {¥}
copy an existing range of nenary into
another range: Mave)
in registers
{20} < {Fron.start} . {From.ena} 1
Program Control Commands
G(o) to program at adr {aor} s
go to $3F8 (user program vector) (control-¥)
S(tep) through pragran at adr (old II ROMs only) fade} 5
T(race) progran at adr (old 11 ROMs only) fade} 7
recrececreerennererpeeeseeocneneconsecnenerseeesennenesnennsneneenensenenae
Other Conaands
begin printing I(nverse) characters 1
begin printing N(ormal) characters N
add tuo hex numbers and print result {nt} + {ne}
subtract n2 From nl and print result {ni} - {na}
Mini-Assenbler enhanced Ile ROMs '
from Integer Basic CALL -2458
{rng.start}. {rng.ena} 4
{eng.start}. {rng.end} R
W(rite) memory contents on cassette tape
R(ead) cassette tape (Read/tirite not avail on IIc)
Blasic)
C(ontinue Basic)
K(eyboard)
Plrinter)
DCALL
'8300.30F
-2458 (beep)
(5 means this is a Mont
0300- 20 02 00 00 00 00 02 00
0308- 22 00 00 09 22 00 00 00
"00:08 uC
99 OF
eruction)
2300-
Lor
aSOF
(note space before JSR
sFOED
To get out of the Mini-Assembler, press reset.
Enhanced ROM enhancements. The Mini-Assembler can also be found in the
new enhanced ROMS for the Apple Ile. You can start up this version of the Mini-
‘Assembler directly from the Monitor by entering an exclamation point.
The enhanced Ile ROMs also have a new search command that finds all
occurrences of a one- or two- byte value in a specified memory range. The
command for finding two sequential bytes with the values $ED and $FD in the
range from $F800 to SFFFF is FDED<F800.FFFFS. Note that the value to be
searched for is entered backward (which makes forward if you're looking for an
address pointer that's stored backward) and that the line ends with an “S”. You
can also search for a single byte (ED<F800.FFFFS), but you can't search for a two
byte pair if the first byte is a zero.
The Ilc’s Monitor, although otherwise similar to the Monitor in the enhanced
Ile ROMS, doesn't have these features. On the other hand, the IIc Monitor's list
command (examined last month) correctly disassembles the additional com-
mands in the 65C02 microprocessor's instruction set; this is something neither
Ie Monitor can do.
“
March 1985
More Commands. There are several fairly useless commands available from
within the Monitor. W(rite) and R(ead) are used to save and recall ranges of memory
toand from cassette tape. The licis missing these commands since it doesn’thave
a cassette interface.
Still around in all versions of the Monitor, but of little value since the introduction
of DOS, are the control-Biasic), control-C(ontinue Basic), control-P(rinter), and
control-K(eyboard) commands. Control-B will coldstart Basic, jumping out of the
Monitor and erasing any Basic program in memory. Control also jumps from the
Monitor to Basic, but does a warmstart and leaves any Basic program intact. To
keep DOS active, 3D3G (DOS/Basic coldstart) and 3D0G (DOS/Basic warmstart)
should be used instead.
Contro-P and Control-K are the equivalent to the DOS pr# and in# commands.
Avoid trouble and use the DOS versions.
Two more infrequently used Monitor commands are I(nverse) and Normal).
These commands affect the way characters are printed. They work just like their
Applesoft brethren. N(ormal) is also often used to separate several commands ona
single command line, much like the colon is used in Applesoft. We used it that
way ourselves last month in line 500 of the Lam Technique demonstration
program (page 13). And we use it that way again momentarily.
Monitor magic, with bells. Hexadecimal arithmethicis easy with the Monitor —
ifyou are willing to limit your questions to two digits and can put up with two-digit
answers. Watch this:
12F +80
AF
+50
31
+80-30
Fo
"80-90
=10
;
Only addition and subtraction work. Multiplication and division are not supported.
The Monitor includes commands that allow you to move a range of memory toa
new location or to compare two ranges of memory with each other and print the
differences. The format for these commands is {destination} < {start}.{end} fol-
lowed by either a M(ove) or Verify) command character. Note how the less-than sign
forms a little arrow that graphically displays which way the bytes will be moved.
Here's how you use them:
+800¢300.3FFM (roves the $300-52FF range to $600-£82F.)
+900¢300.3°FV (verify that the rove tock place--ro response
rears that it oid.)
#9651<300.3FFV
are the $300-83FF rarge to $9€51-$9€80.)
93F2-8F (4C) (discrepancies:
03F 3-90 (65) runber after gash 1s value at address shour
03F 4-38 (FF) unter is parantheses is value at cor-espording
adoress in comparison -arge.)
The first line above demonstrates the M(ove) command. This command copies
an image of the $3D0-$3FF memory range at $800-($82F). The image at $3D0is left
unchanged, although this is not always the case, as we'll see shortly.
The second line demonstrates the V(erify) command. Here we ask the Monitor to
compare the $3D0-$3FF memory range with what's at $800. It does so and reports
all discrepancies. Since our move command just made these ranges match, there
are no discrepancies to report.
The third line compares the $3D0-$3FF range with a range of memory inside
DOS 3.3 at $9£51-$9E80. The two areas should be similiar, since Uncle DOS moves
what's at $9E51 to $3D0 whenever a disk is booted. As you can see, three bytes are
~ different. The number after the hypen shows the value at the address displayed
on the screen; the number in the parentheses shows the corresponding value in
the range being verified.
Now, consider what happens when the range of memory we are moving
overlaps the range of memory we are moving to. Ifwe are moving a memory image
lower, the move will take place normally. In the process, however, the overlapped
Part of the original image will be destroyed.
When we move a memory image higher, on the other hand, an interesting thing
happens. The portion of the image that does not overlap is repeated throughout
the new range. You can quickly filla range of memory with a specific value or pattern
of values, for example, like this:
*2000:FF N 2001°2020.200E” (Put FF at 2000, use N(crval] 28 a comm:
F 2000-2026 -0 2001.
Move} cer
Open-Apple 21
*2000.200F (Displayneu contents of 2000-200F.}
2000- FF FF FF FF FF FF FF FF
2008- FF FF FF FF FF FF FF FF
The 2000;FF initializes the first byte of the range. The Ntells the Monitor we are
done with the memory change command and now want to enter another com-
mand. The 2001<2000.200EM moves the value nowat byte 2000 into bytes 2001
through 200F.
‘The generalized format for the M(ove) command used in this way—when length
indicates the length of the patter to be repeated —is:
{stareelergen] < [start] . fend-Lengtn}
The machine language command 20 DD FB will beep your Apple's speaker. Want
to hear a thousand beeps? Thy this:
2000:20 00 FE N 200% 2000.2684" N 2888:60 N 20006
That command line only takes about 114 seconds to execute. The 2BB8:60 puts
amachine language command at the end that returns us smoothly to the Monitor.
Try 2000L. Then try LLLLLLLL. Amazing stuff.
‘Or perhaps you'd prefer:
'N FBODG 34:0 (put a space after the ze-o, before you pres:
eur)
This trick creates a repeating command. Start the line with a single letter
command, end it with 34:0(space). This pokes a zero into byte $34, which causes
the Monitor to start executing the line over again at the beginning, Ifyou want to
start beyond the beginning, replace the zero with the number of the character you
want to start with, minus one.
Enough tricks. The points that a familiarity with the Monitor, which is available
in every Apple II ever built (and few other kinds of computers), gives you the
power to control your machine ata very elementary level. The box on the previous
page summarizes the Monitor's commands.
Help for the absent-minded
Absent-mindedness is a common fault, especially around here. Conse
quently, we have a great deal of sympathy for those who manage to destroy
important files by mistake.
Word processing and spreadsheet files are particularly vulnerable. The prob-
lem is that most programs’ save and load commands are easily mixed up. A
frequent cause of file loss is that a user absent-mindedly saves a blank screen
over the top of a valuable file. Listen carefully on any clear evening and you will
hear crys of file-loss anguish emanating from chimneys in most major cities.
However, ifthe word processor or spreadsheet program uses DOS 3.3 text files,
the lost data is easily recoverable. This is because DOS 3.3 doesn’t remove the
old file from the disk. Instead the new contents are written over the top of the old
contents and an end-of-file mark (control-e, hex $00) is placed at the end of the
new stuff. If the new contents consist of nothing (a blank screen), only one
character of the original file is destroyed (the one under the new end-of-file mark).
To recover the file, all you have to do is replace that file-ending zero with
something else.
Typically this is done using a disk-edit utility. | once used this technique to
recover a large section of a friend's Masters Thesis and prevented a potential
suicide. The technique requires some expertise, however.
A etter way, once you get DOS 3.3's append command working (see the back
page of this letter) is to let append find the end-of-file mark, then overwrite it with
a carriage return. When the file is reloaded into the word processor or spread
sheet, it will burst forth virtually unscathed (damage to word processor files will
be at the beginning: damage to spreadsheet files will be at the end). Here’s a
program that uses this trick, Go out and save a few lives with it.
Lo Ren +88 Phoersx 148
100 HOME : VTAB 12 : DS=CHRS(4)
110 PRINT “PLEASE INSERT OIS« WITH LOST FILE.
120 PRINT * WHAT IS THE NANE OF THE FILE?”
139 PRINT
140 INPUT “"2F
150 PRINT 2 REY Create error :
160 PRINT DE:PPPEND":FS : REM rove File po 0 erc-of -file
170 PRINT DEs"URITE"SFS : REM overurite varver with a Greturr-.
195 PRINT
180 PRINT C8;“CLOSE":FS + REM Rest of File nag:cally veappears.
190 PRINT “FILE FIXE2!” : END
Open-Apple
22
Ask
(or tell)
Uncle
Loose Ends
Last month I left some questions unanswered, and
a couple of them still have me puzzled. But readers
have helped with answers to some.
Regarding AppleWorks and non-Apple printers
and interface cards: Apple has released an updated
version of AppleWorks to dealers that solves this
problem. Dealers are supposed to update your orig-
inal disks for free. Call ahead to make sure your
dealer has the update. My source on this one highly
recommends you insist on talking to the dealer's
technicians, rather than salespeople, for this and all
similar problems with Apple programs and equip-
ment. Its the technicians that Apple notifies about
such bugs and how to fix them. My source adds that
the ProDOS version of AppleWriter has the same
problem —dealers have also been issued a fix for
this.
One of last month's letters asked how to do an 80-
column screen dump. In the response to that letter,
I mentioned that my printer garbled when I printed
while the 80-column screen's even columns, which
are stored in auxiliary memory, were turned on. But
I didn’t know why. The reason occurred to me as
soon as the letters were printed. Printer interface
cards, like most Apple I! peripherals, use a small
amount of memory inside the text screen. This area
is usually called the scratchpad area, or the screen
holes. When the even columns are on, the scratchpad
area the interface card is using disappears; thus the
problems.
If you need a faster 80-column screen dump,
delete line 505 from last month's program (page 15),
remove the “L$+" in line 340, change line 360 to
“PRINT L$+CHRS(PEEK(ADR));”, and remove the “L$”
from line 380.
Remittance bug revealed
‘Tom, try this program:
1@ vi=2a = REM 1
20 v2=4a : REM 2
30 PRINT (¥1#2)
UN
4
fear subscription price
f° subscri
ton price
Why do your bills say a two-year subscription is an
ings?
$8 savings Philip Straus
Philadelphia, Pa.
My error. Abby, Open-Apple’s spokeswoman,
nearly resigned when she saw your letter. She
agreed to continue with Open-Apple only if I tacked
a couple of extra months onto the subscriptions of
those of you who actually paid $44, and I've done so.
Input comma no garbage
[have an addition to the Selective String Preserva-
tion technique for avoiding garbage collection that
you wrote about in the January issue (pages 4-5).
Here's a routine that replaces Applesoft’s input com-
mand so that commas are allowed. Normally rou-
tines that use get like this cause garbage collection
to occur frequently, but this one doesn't create any
more garbage than input itself does. As written, the
routine also filters out control characters.
50 SL SH=PEEK( 112)
PEEK(ILL) +
10 285,
PRINT 88:
13 THEN C=255
31 THEN [S=18+as
: GET AS
IF ascya:
IF aSc(As)
NEXT
S7 PRINT
POKE 1LL,SL =
MIDS(I8,.1
soto $6
POKE LL
I$ is made permanent by line 59, which makes a
new copy of it after the pointers at 111 and 112 have
been changed to erase the temporary copies of AS
and I$. They will be overwritten and won't cause
garbage collection.
Jim Parr
Bloomington, Il.
Fast garbage bugs
| tried the fast garbage collector published in the
January 1981 Call -A.PPL.E. and mentioned in your
January issue. I had some trouble getting it to work.
After studying the code, I discovered some bugs. The
subroutine NZTAB, which zeros out the address table,
ends with a JMP to FNDVAR2, not an RTS. Conse-
quently, the initial call to NZTAB should be a JMP, not
a JSR and should occur just before FNDVAR2,
between lines 63 and 64, not at line 59.
In addition, the Y register should be cleared when
anew address is placed in INDEX. Add a LDY #0 just
before lines 69 and 79.
Steve Hunt
Cambridge, Mass.
There was one more bug. Val Golding, editor of
Call -APPLE. when the original program was pub-
lished, tells me he misspelled the author's name and
reprinted his mistake. The author's name is Randy
Wigginton. It's an important name to spell right, as
Randy has been involved with Apple since, as a 16-
year-old in 1976, he hitched rides to Homebrew
Computer Club meetings with Steve Wozniak. He's
been one of Apple's most prolific wizards ever since.
Rana, A.P.P.L.E, Abacus
Your February editorial about DOS 5.5 was on the
mark, and raises an interesting question, How do
people who make double-sided drives (e.g, Rana Elite
Il) make them compatible with DOS 3.3? Do they
define a logical track to be two physical tracks—
presumably one on each side of the disk? This would
create, in effect, tracks with 32 sectors, which you say
DOS 5.3 can handle. limagine this scheme would not
require any repositioning of the head to read all data
from any logical track.
Speaking of Rana, while | still see their products
being advertised by a number of mail order houses,
they appear to have completely discontinued their
own advertising. | was greatly interested in their
8086/2 unit since it provides MS-DOS compatibility
for the Apple as well as high capacity drives usable
under all four operating systems that run on the
Vol. 1, No.2
Apple (DOS 3.3, Apple Pascal, CP/M-80, and ProDOS).
l obtained a pre-publication copy of the 8086/2 man-
ual, and actually saw a unit once at a dealer, though
like most dealers he couldn't answer a single ques-
tion. A friend of a friend has one, and while the level
of compatibility with the IBM PC is not as high as one
would like, he reportedly is satisfied with it. | wrote a
lengthy letter to Rana asking a number of questions
about six months ago and never got an answer. I'm
still interested. | still have all those unanswered ques-
tions and one more besides: How come you don’t
hear anything about a product that once seemed
destined to sell several hundred thousand copies at
over $1,500 each?
I would like to call attention to a situation that | feel
is deplorable, especially since it involves a group in
which | had placed considerable trustand which | had
enthusiastically recommended to many friends. The
billing policy of APPLE. (the user group in the Seattle
area that publishes Call-A.PP.L.E. magazine) doesn't
conform to the standard practices of ethical mail
order merchandising. On December 1 | ordered sev-
eral software packages from them by mail. They
billed my credit card on December 11, and as of late
January they had not yet shipped me anything and
refused to make a commitment on when they would
ship. Standard practice is to bill only at the time
shipment occurs. Ilike to think of A.PP-LE. as a group
of the Apple community's most upstanding citizens,
so this incident comes as a grave disappointment.
On a more pleasant note, I would like to recom:
mend the 128K RAM card manufactured by Abacus
Enterprises, P.O. Box 1836, Detroit, MI 48231 (313-
524-2444 voice, 315-524-0238 300 baud). | think it
is a super product and the service provided by Aba-
cus is outstanding, The hardware is unique in thatan
external switch allows the card to emulate either the
Saturn or Legend bank switching protocols. The card
can be write protected, also by means of an external
switch. Abacus has released a software package
called Back-to-Back that allows swapping images of
the lower 48K of RAM into and out of the 128K card
at the press of a button. This makes it possible to
suspend operaton of one program, toggle to a
second and, at the press of a button, resume opera-
tion of the first right where you left off. Abacus also
provides avery easy-to-use RAM disk emulator for use
with DOS 3.3.
Dan Strassberg
Arlington, MA.
Rana provides a highly modified version of DOS
5.3 with its high capacity drives. It actually has two
Volume Table Of Contents sectors on each disk anc
is consequently incompatible with lots of stuff
including ProntoDOS. ! picture Rana as a company
that tries just a little bit too hard. Their products do
wonderful things nobody else can do, but at the
price of compatiblity problems that keep them out of
the fast lane.
Like you, I've bought tons of stuff from A.PPL.E.
over the years and have recommended them in this
letter and other places. Like you, I recently had an
order delayed. The folks in Seattle say they ran into
unexpected problems with a cross-town move they
made in late December, and that is why customers
are experiencing delays.
Asa certified mail order junkie, commend you for
having the good sense to pay by credit card, and |
recommend that everyone buy mail order goods
that way when possible. If APPLE. still hasn’t
shipped, complain to your credit card company anc
let them handle it. That will get A.PPL.E‘s attention.
March 1985
Acharming difference
You say the S.H. Lam technique for entering Mon-
itor commands from inside Basic programs (Feb
pages 12-15) works from within a subroutine. But the
same routine appears on the Beagle Bros Peeks,
Pokes and Pointers chart and the chart says it
won'twork within a subroutine. Who's right?
Uncle Louie
San Diego, Calif.
Both of us. In the version shown on the Beagle
Bros chart, D823G is tacked onto the end of the
Monitor command string. In the Open-Apple ver-
sion, D9C6G is tacked on. Both formulae cause the
Monitor to jump to charmed spots within Applesoft,
however, one spot is more charmed than the other
and works from within subroutines.
Who needs OPEN
In January's Digging Into DOS (page 2), the
straightforward way you give to read a text file con-
tains an extra step. For reading text files, open is a
redundant command. If you want to open abc and
read from it, just print d$;"read abc”.
Looking at the code for read, it's easy to see why
openis not required. The first thing DOS does in read
is to check whether the file is open. If not, it opens it.
Ino longer use the open command for reading text
files. An added advantage is that a file is not created
if it doesn’t already exist—you'll get a file not found
error instead.
The write command works in a simliar manner.
Charles H. Putney
Shankill, Co. Dublin, Ireland
You are absolutely right. The only problem with
this trick is that Apple never documented it; conse-
quently the ProDOS developers apparently didn't
know about it; consequently it doesn’t work with
ProDOS.
Disk free space
In the March 1984 issue of Softalk, you wrote about
the DOS 3.3 Volume Table of Contents and you
printed a Basic program to calculate the number of
free sectors on a disk. | have used that program as a
subroutine in a larger program, which is now running
under your ProntoDOS. | am getting very limited by
having DOS at 48K, and the program is causing
Applesoft’s garbage collection to occur very fre-
quently, | would like to use your DOS-UP program on
the ProntoDOS disk to move DOS up to the top 16K.
Can you tell me where DOS’s VTOC buffer is located
after DOS has been moved? Robert Nyberg
Tucson, Ariz.
It's 16,384 ($4000) bytes higher than before, but
that information won't help you much. If you look at
that address range from within a Basic program,
what you'll see is the machine language code of
Applesoft itself, not DOS. If you turn the upper 16K
of memory on so you can see DOS, your Basic
program will crash because Applesoft will disappear.
You have to peer at the high reaches of memory
with an assembly language routine. A better
approach to solving your problems may be to use
the garbage collection tips published in this issue
and in January's.
Although I've written a program for moving DOS to
the upper 16K of memory and although many, many
people use it, my experience has been that moving
DOS often causes as many problems as it solves. If
you are writing pure Basic with no assembly lan-
guage routines and no fancy tricks, a relocated DOS
works great. But as soon as you try to fine tune
things, problems begin to occur.
‘Another approach to consider is to switch to Pro-
DOS, This won't increase the amount of memory
available, but it gives you fast garbage collection and
achain command that’s quick and easy to use. On
128K machines you'll have the ProDOS /RAM disk:
you can use it to keep the chained parts of your
program available for quick access. Finding the
number of free blocks on ProDOS disks is pretty
easy. Fish it out of the catalog, which you can open
and read like any other file.
80-columns & machine language
How do you activate or deactivate Apple's 80-
column card from within a machine language pro-
gram? After the cardis activated, what routineis used
to write a character to the screen?
Tom Carlin
Cleveland, Ohio
First, the easy stuff. Once you have the card turned
on, you send characters to it from machine language
by loading the character into the A register and
doing a JSR to COUT ($FDED)—exactly the same
procedure as used in 40 columns. To deactivate the
card, simply use this procedure to print a Control-U.
Other fancy things you can do by sending control
characters to COUT with 80-column mode activated
are:
control ASCII nane
che val
curser noving coges/nane clear any part of the scveen
# $08
\ SIC fad. space right
J $08 lire fees dow
" $00 return left eage ard daun one
Y 519° hore upper left corer
packspace lef: ore chara
fe char
ore lire
text coving coues/neither moves the cursor
u $17 scroll up
v $16 scroll doun text moves doun
text aoves up
screen clearing codes
L soc clear uhole screen
K $08 clear E05 cur: erd of screen
1 $1) cles- EOL cursor to end of lire
z SA clear lire clear Line cursor ison
other ccges
0 sor egic
N S08 begin rovmal
0 sul begin 40-colur~ sisplay
R $12 BO-colusn begin B0-colusr display
u SIS quit turn B0-colunn card off
Turning the card on varies depending on whether
you want DOS io remain connected or not. If you are
using DOS 3.3 and you leave it connected, Uncle
DOS will respond to commands that are preceeded
by a return and a control-D, just as he does from
Basic. Simply send the command to COUT one letter
ata lime. Inthis situation, you turn on the 80-column
card by sending DOS the command PR#3.
ProDOS does not respond to commands sent to
COUT from assembly language programs. You must
use the ProDOS machine language interface, or, if
your machine language program is CALLed from a
Open-Apple 23
Basic program, you can poke the command string
into the keyboard input buffer at $200 (don't forget
to put a return at the end), and do a JSR DOSCMD
($BE03) to execute it. Once again, use PR#3 to turn
on the 80-column card. (CAUTION: several com-
mands, including read, write, and append, don't
work correctly when initiated with DOSCMD.)
If you don’t need DOS, turn on the card like this:
69.03 LOR 2803 80-colune slot nanber
20 95 FE JSR QUTPORT 0 a pr with SFES5
#960 LOR 880 etre
20. ED FO JSR COUT p to with SFOED
Big Boy Data Managers
Is there a good database manager for the Apple IIc
that will accomodate 15-20 thousand names and
cross reference them with about 25 categories?
Lowell Levinger
Inverness, CA
I haven't tried all of the database programs avail-
able for the Apple, but of the ones | have used, the
database manager in AppleWorks is my run-away
favorite. | think it’s the strongest of the three pro-
grams that comes with AppleWorks. It won't do
what you want, but keep reading.
After trying for a couple of weeks to set up Open:
Apple’s subscriber records with a “high-powered”
Apple II database manager (and getting nowhere), I
turned to AppleWorks and had the whole thing set
up, complete with several kinds of status reports, in
a single afternoon.
Since then I've written some Basic programs that
read AppleWorks-generated text files and do spe-
cial manipulations (such as, while printing monthly
mailing labels, also printing an invoice label for the
remittance envelope if an account is unpaid). Apple-
Works’ ability to generate standard text files holding
data it has sorted, selected, and formatted is a very
strong feature of the program.
If you have a lic, you should have AppleWorks
anyhow, so if I were you I'd start with it. It’s quite
easy to use and is a good place to organize and
practice using a database. It won't be your final
solution, however—the great limitation is that you
won't be able to get anywhere near 15,000 records
ina single file. Using alic you'd probably need about
30 separate files to hold that much data. There is a
possibility this wouldn't be a problem for you, but
that's unlikely.
By starting with AppleWorks, however, you'll
have a clearer idea of what you want to do and how
to doit. Its great advantages are speed, ease of use,
and clarity. Sorting a 500 record file takes less than
10 seconds. You can move from record to record
instantaneously. You can display a whole screenful
of records at the same time and scroll through them.
Once you see what AppleWorks can do with a
sample of your data, you'll be in a better position to.
judge other database managers by their instruction
manuals. Given ProDOS, there is no theoretical rea-
son why a llc shouldn't be able to handle a database
as large as yours. | would recommend a hard disk or
other high-capacity storage device to avoid finger
blisters caused by constantly opening and closing
disk drive doors, however.
It's also necessary to consider how often the
records in your file are to be updated. If the records
consist of something like daily meal requests for
15,000 people, the Apple Ic will be woefully inade-
quate simply because one person working at one
computer can’t update that many records in one
Open-Apple
24
day. If the records are updated yearly, on the other
hand, a single person using good software and a llc
will be able to manage the data and do lots of other
stuff, oo. Always keep in mind the limits of what one
person using one computer can do when organizing
this much data. Sometimes you just can’t handle it
without going to some kind of multi-user system.
Another big boy
‘A company here in Texas called Applied Engineer-
ing has a card for the Apple lle that can expand
memory to as much as 1 megabyte (1,024K bytes).
The company also offers a patch for AppleWorks
that will allow the user to have an 800K desktop, That
should quell some of the blithering about how
limited AppleWorks is due to memory restraints.
For the price of an IBM PC and Lotus XYZ a smart
user could have a Ile with 1 meg of RAM, Apple-
Works, and the Sider hard disk drive. There might
even be enough left over to buy a joystick. This would
turn the Ile into a real mother-hummer. It might also
make a few of the PC parrots choke on their crackers.
Gary Maddox
Weatherford, Texas
You think just like | do. | have one of Applied
Engineering's cards on order—look for a complete
report here in a month or two.
The DOS 3.3 append challange
Could you discuss the bug in the append com-
mand of DOS 3.3? When the file being appended to
ends at the end of a sector, it doesn’t work. | have
discussed this with Apple, but they had no help to
offer. Is there a way to fix this?
Ferd G. Fender
Glenview, Ill.
DOS 3.3’ append command graphically demon-
strates the difficulty of getting all the little bugs out
of complex software. Apple has officially modified
append three times and still doesn’t have it right. 1
have officially modified it once and didn't get it right
either. So it's with some fear and trembling that |
enter this discussion.
Append is very similar to the DOS open command.
You use it to get a specific text file ready for reading
from or writing to. When you use open, DOS aims its
position-in-file pointer at the first byte of the file.
When you use append, on the other hand, DOS aims
its pointer at the byte just beyond the last byte in the
file. If your next action is to write to the file, what you
© Copyright 1985
b
Y
Tom Weishaar
Published monthly.
World-wide price:
US$24/year
Send all
correspondence to:
Open-Apple
10026 Roe Ave.
‘Overland Park, Kans.
86207 Ysa
Source Mall
CompuServe:
79120202
Open-Apple is a trademark of Tom Weishaar. Apple Computer and
Open-Apple are two different, unrelated, independent companies
that wish everyone in the world had an Apple
write will start at the end of the file, rather than the
beginning, and thus will be appended, or added to,
the original file. (If your next action is to read from
the file, you'll get anend of data error.)
Unlike ProDOS, DOS 3.3 doesn't keep a record of
how long text files actually are. When you issue an
append, DOS 3.3 simply starts reading the file and
continues until it comes across a byte holding a zero.
By definition, the first zero byte encountered marks
the end of the file. However, by the time DOS
retrieves the zero, the position-in-file pointer is
aimed at the next byte—the byte beyond the zero.
So DOS next executes an internal position command
to back up the position-in-file pointer by one byte.
So far this all seems pretty simple, right? What I've
just described is exactly how the DOS 3.2.1 append
command worked. But there's a bug here. While a
zero byte inafile is themain method for marking the
end of the file, it's also possible for a file to simply
have no more sectors. This happens whenever a
file's length is a multiple of exactly 256 bytes. The
final sector in the file will be completely filled with
data, there will be no more sectors assigned to the
file, and there won't be a zero anywhere in sight. In
this situation, the position-in-file pointer doesn't get
bumped up an extra notch, yet append insists on
bumping it back a notch as usual. The effect is that
the final byte of the original file is overwritten by the
appended material whenever a file ends exactly on
asector boundry.
When the original version of DOS 3.3 was released
(around here | call it DOS 3.3.0), a patch was added
to take care of the problem. Unfortunately, what
should have beena simple test in the append routine
to determine whether the position-in-file pointer
should be reset or not became a 74 byte patch of
amazing complexity. However, it fixed the bug.Yet,
like many patches, it added a new bug of its own.
This bug is quite obscure—let’s just say that when
the stars are right, the DOS 3.3.0 append command
will still fail to work,
It was about this time that yours truly wrote
ProntoDOS for Beagle Bros. Much of the room for
the ProntoDOS routines came from removing
Apple's 74-byte patch. | solved the major append
bug and got rid of the exotic one with just a few bytes
of code. | bragged that I had solved the DOS 3.5
append problem. Such fat-headedness is always
inappropriate for assembly language programmers.
For there was yet another bug. The position rou-
tine that DOS calls to notch back the position-in-file
pointer doesn't work correctly if the file being
appended to is longer than 32,767 bytes. Art
Schumer described the bug in an article that
appeared in the August 1982 Call -APPLE., page 57.
(It’s also inCall -A.PP.L.E. In Depth #3: All About DOS,
page 191) Unfortunately, ! didn’t come across the
article until several months after | had finished
ProntoDOS.
The folks at Apple saw the article, however, and
when they released a new version of DOS 5.3 for the
He in January 1983 (I call this version DOS 3.3e),
they fixed this bug. Rather than using position to
notch back the pointer, the Ile version modifies the
pointer by hand. Apple also added 15 additonal
bytes of code to fix the more exotic bug in their
original 74-byte patch.
Was everybody happy? Does this story have a
pleasant ending? Not yet, gentlepeople; Apple's new
patch made things even worse.
The position-infile pointer within DOS is three
bytes long. One byte is aimed at the byte offset
Vol. 1, No. 2
within a sector. The next byte is aimed at the sector
number—until it hits 256 anyhow. Then the third
byte comes into play and the second byte starts over
again at zero.
‘Apple's DOS 3.3e patch only adjusts the lowest of
these three bytes. Whena file-ending zero appears in
the final byte of a sector, the middle byte of the
pointer will have been advanced to point at the next
sector. But since the patch doesn’t decrement the
middle byte, the position-in-file pointer ends up
aimed 256 bytes beyond where it should be. DOS
3.3e's append fails completely once every 256
times.
In September 1983 Apple released a third version
of DOS 3.3. Apple's people said this would be the
final update to DOS 3.3, since ProDOS would be
introduced within a few months. (I call this final
fairly-fixed version DOS 3.5f). This version expands
the 3.3e patch to decrement the middle byte of the
position-in-file pointer correctly. However, it still ne-
glects to decrement the high byte of the pointer
when necessary; consequently even this version has
an append that will fail if you try to add something
toafile that's exactly 65,535 bytes long.
The program that follows fixes all the append bugs
I know about in all three versions of DOS 3.3. Enter
and run the program and test the results on a few
files. If everything works, you can initialize a new
disk and the changes will become a permanent part
of the DOS on your new disk. With standard DOS 3.3,
the patch overlays a portion of Apple’s useless 74-
byte append patch and thus requires no additional
Space.
ProntoDOS, however, already uses that area for
something else. If you are a Pronto user, start with
an unmodified copy fresh from the original Beagle
Bros disk. Then enter, run, and test this program.
After the append patch has been added, you can use
Pronto Update to add most, but not all, of the other
ProntoDOS enhancements and to update your
disks. Don’t run this program after making other
enhancements to ProntoDOS or trouble could
result.
(if you are a DiversiDOS user, incidentally, your
append command already works correctly.)
10 IF PEEK(978)O157
THEN PRINT “48K 00:
8 500
PRINT OTS:
PRINT