#@L}5 _$% l0$)$$Hȱ$ UhL" `e$$%`$%`  R@W!( L(1   Y I`  d  Ld M * @  $ % CC$$)%1 Udߥ$9%: !0 S$% DD˙`  }J)Lr d M * @  $ % CC$$)%1 Udߥ$9%: !0 S$%} DD˙`  }J)Lr J  ((  p L ()   J}L= ( L 0q A    IB JC;? D W } LL  ` W )LA!  ߰")-݆ p" } $G@LL 08`Q")<2Q0 -G$Ș݆ UL# ; p8(()(0ʥ)NQ` }$GȘ݆LU )L ݆ L GȘ ݆LL )W>Z   HH)H }p h  hyhy D L> L JJ    ! LA*` BF }7'8  M HN H` 8 Z  \LdJJ!"! GFE@F (!L }EE !E^ ^ E E7EȩEdE/EȩE  D } .L }  ;F d  ;?F7F? ( .   Z D LL d } . D  L    p  E` , d)  D L) 0BM݊L݉} ML  N݆ L NLML [ TEqEHȱEqEh 0Gȹ G} HLL GɛL  LFREE SECTORS G) *Gȩ GȽG GȌ*jj >G} C8jJ3j2CD( C202C ԠBX` N 1? l LlD:RAMDISK}.COMLu L1 L ;LHL  T`  `1  ɐ     `TU  } L ? .  t`GBJ ~DEHI B V0dV!}QDEHI VF9 ,0 ,0 s0hhL  L` H hDHEh"}DEL8HI4 0 HI,0 0  9 .G VLO#},0 L4*IJ`llD1:AUTORUN.SYSNEED MEM.SAV TO LOAD THIS FILE.D1:MEM.SAV J y08 B|DEHI$} V0 0`B;DEL`?<0LV`@ʆ v s? F0Ξ05: [ BDEHI%} VY8 B V  @  /DE `E:D1:DUP.SYSERROR-SAVING USER MEMORY ON DISKTYPE Y TO &}STILL RUN DOS B;DE J  (` 9 V⪍ ઍ  -'}LLu ÝDEHILV 9 .l 9 .l  `` s$B BH(}I|DE V BLV nB,DE JLV B V BLVDEIʩ BꭝLu }M D D D D %BB! % 9* v% w%u % D %LJ& fffffff>`<*}|0`̌8l8pv00````00 0f< x||||-}|||~|l8l8lfff< 0`@`0 000006c!"|™.}|™|~x|™|as22sa>2222r|晒xLLLLNB|晁晉|™||™/}v|~Þ~fdddd||晙d8晙™晙dd|2x`x`~<~~<"#30 ~ <~~<0}|~~||~~||>````~~8<8<||1}~~~|0000~l8|ll8l~ 8`8pp##82}$ %0$1$3$4$ ?̏?1$4$ॄ``ex$w$e{$z$褄 x${3}$`(mDeXYi????)^̜D)DȄ?Čei?̜D@L$4}i( %&L$??`??????8??Ƌ拑` T8` 8` n%D5} %LJ&} T8t?????@:@CD(DDi?18?8?8?@K????` -??6} $ &= Y%&'?L' &= Y%?`'XRUT`H)h)` i@LG&8 `DCIDID $ 87}Х)LS&ЭC?H &hɛL&,C0ɜf) `{\\X^T_PHC^? e,h .&) C8} $8??''i?i? 'LJ&?'?'LJ&ʊ &HIHd'Hc'H`# \^_|}~2k)9}9:+O)29+,0];'3A/1/s)l32'))(m(( ):--,+<,+4,++d,CIC`"I"` (8??8??? ??:} $8?内?凅((?m???i? $L'`8???? ????8?? ??`8??;}`??`ЭD(DDΝD $ '} T8L &L'ЭDΜDΜDD $ '} T8L &ƇƆL'<}Ƌ^^()`8eiL'^` 懥͒?^eiL'??L'=}??8̓??? $LC)s)s)`)))))`Ƌ ^`^Ƌ͂?L)ƌ >}L(L)??L')*^懥͒?LC)懥͒?LC)^L4)??????}`8??hh``8Ie?Ie?????8?m?͉? &۠= Y%?`???m?@}??m?? $????8?傅*+?僅 $8??????` K* ( h*8????` n( K* ( h*L+A}L. 9*2 &= Y% o%H &h)_ @W K* (Lh*S K* )Lh*P K* ;-Lh*`8????ХL'??B}L+͒???L++,L+ee8?傅?僅8傍?働? $8??????`C} @LO, @ O,L4) @ {, @` @ @ {,L'?m @?m @ͅ?hhL,m @m @8?倅?偅D} M$?m @??m @?`?It?`= Y% 8)})Y`,-Э`2 & > Y% ,L & % %LJ&^懥͒?E}LC)L4)Ƌ^Ƌ̓?L)8ee8内包LM-L'@ԩ-0F}1-XYȑȑ`ppp-.A-Hs) ԍЍ)Х  h@ЭG} 9* &> Y%I $I2 o%)_ @W . )L.S . )L.P . -L. 'L &??`8??H}?? *?? $L5.'U?? T8~ T8? o%?,C09 .n/CL.ɛE~L.~ T8L.) }̓?𻥌)I}Ю ? T8CL.?`2 &Ϡ= Y% ,L &D D D D Lto/j0CL|/C??L/CJ}8?勪,C0ɛ^L/ .&L/^L/ 2` &9> Y% [00@ w/p?D?E8??H??I B V0 oK}/ ';0 LX1H o/h!H} T8Q> Y%h v8 P0 -?` &Y> Y%L70C BLVpCCH@k0f1 .h? &hhL- P0CL}D?E?HICJBLV8??ą &s> Y% [0L0 % 0L0LX1CDE8?冝HM}?凝IB V`CHm??Im???e??e? /??` P0L0} T8ig1b2> Y%L70@ԭs)N})`????8* &?.??.??.??.? ??L1? ?8??????L1?`8????O}?? ? &> Y%?`m?m?8?倅?偅eͅ? &> Y%?` M$?m???c2^3m??P}?? $L'ȱȊ`)?! ;I@Ln(H)h)` @@L2i `Э& &? Y% .@L &?@̔?Q}L &@@S@ .&ъ 拥͒?6@ei?Ō?卐8@@@ '` _3Z4& ? Y%R}?` &8???? v8?`KE:P@HH8@@@@1pHI B@ V( 0LJ&hh@`S} &נ>LY%L5ЭL= &> Y% o1 [0L5 o1 3?? @ @C3? @@3t@??[4V5@T}@?@L5^)@@@?挐?@?ȱ?8ei@ 5@ 58.@??䅎@ 7 5@U}? 258??<:? ?? 25?E T8> Y% o% '; -} T8 &LJ&LX48?@0 5??兎B W5V}R65 7 5 5 5@@?8@@@@ &> Y% o% 3??䅎A 5 7?@0 5` ?@ 3`?m@W}@ 5` 3C 3` @) 25656 @L.7ʊ @6HHG6HF6H`8@eiLX4^@`wlrtbsnhf%p?xmqi6666X}66S6N766766x6n6e6'7P7ȩ@L*6 1@L*6 1@?@L*6 1@?@L*6 1?L*6?L*6 1?L*6 1?L*6 1?LY}*6 1?L*6 1?L*6@ȘH 25h@` 7?A?L*6ȱ^` 7?B?L*6 7L*6ȱ @Ls4 1H @)Z}hd@ *6LO7-86^ 2???`CC 0L3 % 0L3hhpCLN4̏?0 2 3 @  3_ 3L[}7`@) @ 2c8@?J8? 3@L7e8??8? L7u @I @#@@@ q8@L7 @d@ 3L7.8)9 B V\}nD8EHIBLV䌡8HI B V䬡8`E:Lx8Dԅ ؠH),D0 T8L8 3h0``]}D 8D)?<D)@`I@`D9,P a{)ɀ`H2ҢҠh`lj;k+*opui-=vc*99bx^}z436521, .nm/reytwq907~8<>fhdgsaLJ:K\^OPUI_|VCBXZ$#&%"![ ]NM?REYTWQ()'@}FHDGSA {  _} ` }9: 2@ : 2@ &: $L9L &Э# &? Y% .:@?<@̔?`}L &8@@e@@ee8?傅?僅 $8?@???:@) @ @ {,<@ .&:@m:@ia}L':; ';pD>EHIJB V0\DDdDeDDD L;0?+K T8 L;03D L;0) T8DD. T8L: b} L;ƌL:p B VpC`H T8h T8 L;0 T8LA;pHIBLV o1 .8 o1R} T8 : =DDDΘDΘD = o%c};a;<)_ݼ;L<ʊ ;H;H`+*-=RLUF12345678 ;<<0<<<<<=========G=%= =DL< =DDd} DDDL; =D8L< =Di͘DުL<>C) 2 C C.ʎDC`pBDHIDe}CELV CL^;pCJ C< w<0% % 00} T8 - &LJ&T T8LT8@ '; Y=Q> Y%@ v8 T8g}> Y% o% =L< I==` Y=? Y%>LT8=>`124 chr=1 sector.PAGE 6 WRITERExit to DOSBuffer FullDelete (S,W,P):h} Are You Sure? (Y/N)ERASE ALL TEXTErase (S,W,P): to exitSave (Device:Filename)>Error #BREAK Key AbortNo ErrorsLi}oad (Device:Filename)> Press D1:*.*Memory Ful>?lNo text in bufferPrint (Device:Filename)>Printing...Insert nexj}t sheet, press Find:Not FoundChange To: -Exit ̭oad ̭elete ormat nlock ock ename Drive #k}Rename to:Format Diskrive #w8<<  B JKIHiDiELV`L8 8 BLV`Lxm}8t8l Lu8hihiHHȱȱL8c !#3`Lu8JJJJ`H 8h`Hn}ȩh Q8L8 Z8L8 8L8 8L8 8L8S:@9E:E9H '9 H9I9 8 '9h)0ICo}9D9L8 L :::: :Lr:::IEL[::i:iIIL[:`:i::iq}::L:`L{:w:w: C`L:L: D8:MEM.SAV: 8| 9 '9`L:L: D:DUP.SYS:̩ 8r} x:ɀL: '9`88 |9Y:X: '9L); D8:DUP.SYS; 8::88 9 '98? :`;WL`; 9s}Ln; ` :Y;Y;L;L;)} Setting Up ATARI 130XE Ram Disk; 9L; ; -9  t} L;D8:; :9 :Y;L USER IMMEDIATE VERTICAL BLANK * ! * INTERRUPT ROUT$}INE * ! * ! ! ! ! SYSVBV <--$}---------- ($E45F) ! ! OS VBI SERVICE ROUTI$}NE ! ! * ! * USER * VVBLKD *DEFERRED * ($022$}4) *VERTICAL* ! *BLANK<---* ! *INTERRUPT * ! *ROUTINE ! $} ! ! ! ! ------------->XITVBV ($E462) ! $} ! RTIVERTICAL BLANK INTERRUPT EXECUTION These two vectors were put into RAM to allow programmers$} to trap the vertical blank service routine and use the 60-Hertz interrupt for their own purposes. The procedure to use them $}is straightforward. First decide whether the vertical blank interrupt (VBI) routine is to be an immediate VBI or a deferred V$}BI. In many cases it makes little difference which is chosen. There are some instances where it does matter. The first case a$}rises when your VBI routine reads or writes to registers which are shadowed by the OS VBI routine. It might be necessary to w$}rite to the hardware registers after the OS VBI has written to them. He who writes last, writes best!PAGE 8-17 ABOVEy to w$w0080 The second case arises when your VBI routine consumes too much processor time. The OS VBI routine may then be de(}layed beyond the end of the vertical blank period. This in turn may cause some graphics registers to be changed while the bea(}m is tracing on the screen. The result may be unsightly. If this is the case, your VBI routine should be placed as a deferred(} VBI routine. The time limit for immediate VBI is about 2000 machine cycles; for deferred VBI it is about 20,000 cycles. Howe(}ver, many of these 20,000 machine cycles are executed while the electron beam is being drawn, so graphics operations should n(}ot be executed in extremely long deferred VBI routines. Furthermore, display list interrupt execution time comes out of the t(}ime available for this processing. Remember, VBI processing will cut down on the time available for mainline code execution.(} The third case arises when your own VBI must be mixed with time-critical I/O such as to the disk or cassette. The OS immed(}iate VBI routine has two stages, a critical and a non-critical stage. During time critical I/O, the OS immediate VBI routine (}aborts after stage one processing is complete. If you want your VBI to be executed during every vertical blank period, it mus(}t be defined as an immediate VBI. Be wary in this situation, for this may result in interference problems with time-critical )}I/O. Once you have decided whether your VBI routine should be immediate or deferred, you must place the routine in memory )}(page six is a good place), link it to the proper VBI routine, and modify the appropriate OS RAM vector to point to it. Termi)}nate an immediate VBI routine with a JMP to $E45F. Terminate a deferred VBI routine with a JMP to $E462. If you want to bypas)}s the OS VBI routine entirely (and thereby gain processing time), terminate your immediate VBI routine with a JMP to $E462. )} A common problem with interrupts on 8-bit micros arises when you try to change the vector to the interrupt. Vectors are 2-b)}yte quantities; it takes two store instructions to change them. There is a small chance that an interrupt will occur after th)}e first byte has been changed but before the second byte has been updated. This could crash the system. The solution to this )}problem has been provided by an OS routine called SETVBV at $E45C. Load the 6502 Y-register with the low byte of the address,)} the X-register with the high byte of the address, and the accumulator with a 6 for immediate VBI or a 7 for deferred VBI. Th) }en JSR SETVBV and the interrupt will be safely enabled. The new VBI routine will begin executing within one 60th of a second.) } A wide variety of operations can be performed with 60-Hertz interrupts. First, screen manipulations can be done during th) }e vertical blank to ensure that transitions do not occur on the screen. Second, high speed regular screen manipulations can b) }e performed. This can be very important in rhythmic animations where changes need to occur at a pace independent from other p) }rocessing. Another function of vertical blank interrupts is for real-time sound effects. The sound registers in the ATARI )}400/800 allow control of frequency, volume, and distortion, but not duration.PAGE 8-18 ABOVE sound registers in the ATARI (_0080 Duration can be controlled with a VBI by having a calling routine set some duration parameter which the VBI then-} decrements down to zero. This technique can be used to control the volume of the sound and so give attack and decay envelope-}s to sounds. Finer control of frequency and distortion is possible with extensions of this technique. The result can be very -}intricate sound effects. Since the VBI time resolution is only 1/60th of a second, VBIs are not useful for the volume only mo-}de of the audio channels. VBIs are also useful for handling user inputs. Usually, these inputs require little processing, -}but constant attention. A VBI allows the program to check for user input every 60th of a second without burdening the program-}. It is an ideal solution to the problem of maintaining computational continuity without ignoring the user. Finally, VBIs -}allow a crude form of multitasking to take place. A foreground program can run under the VBI while a background program runs -}in the mainline code. As with any interrupt, careful separation of the databases for the two programs must be maintained. The-} power derived from the vertical blank interrupt is, however, well worth the effort.PAGE 8-19 ABOVEmust be maintained. The,f0080THE SYSTEM VECTORS One measure of the power of any operating system is its adaptability. Just how easy is it for1} a user to take advantage of the OS routines or modify and customize system routines? In this regard, the OS for the ATARI1} Home Computer System would score well. In practically every instance where access to system routines could be beneficial, th1}e OS has "hooks" where you can attach or replace system routines with your own. This flexibility is provided by a combinat1}ion of several different mechanisms. The first of these is a ROM table of JMP instructions to crucial OS routines. In future 1}versions of the OS, the location of this Jump table will not change, although the values there probably will. Thus, if your s1}oftware accesses the main OS routines via this table, it will also work on future versions of the OS. If your software does n1 }ot use these ROM vectors, but instead jumps directly into the OS RAM, then it will almost certainly crash on future versions 1!}of the OS. The second mechanism is a series of address vectors in RAM which link many of the interrupt processing routines1"} together. To alter the handling of a particular interrupt, one need change only a single vector to point to the replacement 1#}code. The OS initializes these vectors as part of the power-up sequence. Again, though the initialized contents of these vect1$}ors may change, their location is guaranteed not to. The third mechanism is the device handler table where vectors to spec1%}ific device handlers (e.g. disk drive, printer,...) are stored. For a discussion of this facility, refer to the Centralized I1&}nput/Output subsection of this section. Name Location Use DISKIV $E450 Disk ha1'}ndler intialization DSKINV $E453 Disk handler vector CIOV $E456 Central I/O routine vec1(}tor SIOV $E459 Serial I/O routine vector SETVBV $E45C Set system timers routine vector1)} SYSVBV $E45F System vertical blank processing XITVBV $E462 Exit vertical blank processing1*} SIOINV $E465 Serial I/O initialization SENDEV $E468 Serial bus send enable routine 1+} INTINV $E46B Interrupt handler routine CIOINV $E46E Central I/O initialization BLKBD1,}V $E471 Blackboard mode (Memopad) vector WARMSV $E474 Warm start entry point (SYSTEM RESET) 1-} COLDSV $E477 Cold start entry point (power-up) RBLOKV $E47A Cassette read block routine vector 1.} CSOPIV $E47D Cassette open for input vectorFigure 8-6 ROM Jump VectorsSince this ROM table is actually a 1/}table of three byte JUMP instructions, an example of using a ROM vector is: JSR CIOVPAGE 8-20 ABOVEble is actually a 0k0080RAM VECTORSName Location Value Use -- Page Two Locations --VDLST $0200 $E7B3 51} Display List Interrupt NMI VectorVPRCED $0202 $E7B3 Proceed Line IRQ Vector -- Unused at presentVINTER $0252}04 $E7B3 Interrupt Line IRQ Vector -- Unused at presentVBREAK $0206 $E7B3 Software Break Instruction 53}IRQ VectorVKEYBD $0208 $FFBE Keyboard IRQ VectorVSERIN $020A $EB11 Serial Input Ready IRQ Vector54}VSEROR $020C $EA90 Serial Output Ready IRQ VectorVSEROC $020E $EAD1 Serial Output Complete IRQ Vec55}torVTIMR1 $0210 $E7B3 POKEY Timer 1 IRQ VectorVTIMR2 $0212 $E7B3 POKEY Timer 2 IRQ VectorVTIMR4 56} $0214 $E7B3 POKEY Timer 4 IRQ VectorVIMIRQ $0216 $E6F6 Vector to IRQ HandlerVVBLKI $0222 57} $E7D1 Immediate Vertical Blank NMI VectorVVBLKD $0224 $E93E Deferred Vertical Blank VectorCDTMA1 $022658} $xxxx System Timer 1 JSR AddressCDTMA2 $0228 $xxxx System Timer 2 JSR AddressBRKKY $0236 59}$E754 BREAK key Vector (** only Rev. B **) -- Page Zero Locations --CASINI $0002 $xxxx Vector for bootab5:}le cassette program initializationDOSINI $000C $xxxx Disk initialization VectorDOSVEC $000A $xxxx 5;} Disk software Run VectorRUNVEC $02E0 $xxxx DUP File Load and GO Run VectorINIVEC $02E2 $xxxx DUP5<} File Load and GO Initialization VectorAn x indicates that the contents of this location may varyFigure 8-7 RAM VectorsUn5=}like the ROM Jump tables, these vectors are true two byte address vectors. A typical calling sequence to use one of the RAM v5>}ectors might look like this: JSR CALLCALL JMP (DOSINI)PAGE 8-21 ABOVEpical calling sequence to use one of the RAM v4O0080THE CENTRALIZED INPUT/OUTPUT SUBSYSTEM One of the most taxing problems facing an operating system designer is ho9@}w to handle input/output to the wide variety of peripherals that might be hooked up to the system. A few general philosophica9A}l guidelines to efficient I/O handling are: - The transfer of data should be device-independent. - The I/O structur9B}e shouls support single-byte, multiple-byte, and record- organized data transfers. - Multiple devices/files should 9C}be concurrently accessible. - Error handling should be device-transparent. - The addition of new device handlers sh9D}ould be possible without having to change the OS ROM. The ATARI 400/800 OPERATING SYSTEM (OS) was designed to pro9E}vide exactly these capabilities. The ATARI 400/800 OS uses a table-driven centralized input/output subsystem. From the OS sta9F}ndpoint, I/O is organized around the IOCB, or Input/Output Control Block. An IOCB is a standard table that specifies one comp9G}lete input or output operation. Any of eight standard I/O operations can be executed through an IOCB. By changing an entry in9H} the IOCB, the user can change the nature of the input/output operation, even the physical device which is the target of the 9I}I/O. Thus, a user can easily perform I/O to completely different devices such as the disk drive and the printer without havin9J}g to worry about hardware details. Most I/O requires only that the user set up an IOCB with control data, and then pass contr9K}ol to the I/O subsystem. Two types of elements make up the I/O subsystem: I/O system routines and I/O system control block9L}s. The I/O system routines include the central I/O routine (CIO), the device handlers (E:, K:, S:, P:, C:, D:, R:) and the se9M}rial I/O routine (SIO). The Handler Address Table (HATABS) plays a major role in linking CIO with the individual device handl9N}ers. The system I/O control blocks contain control data that is routed to the I/O subsystem. The user interface is the same f9O}or all devices (e.g., the commands to output a line to the printer (P:) or to the display editor (E:) are very similar). U9P}nderstanding the structure of the I/O subsystem will enhance your use of it. Figure 8-8 shows the relationship of the I/O sys9Q}tem routines and the I/O system control blocks.PAGE 8-22 ABOVE use of it. Figure 8-8 shows the relationship of the I/O sys8A0080What would normally follow on this page should be a full page drawing of how an operating sub-system works, i.e.- b=S}oxes and lines and how they all connect together to carry out a specific task. Due to the limitations of graphics and drawing=T} and some printers, it was not practical to attempt to draw them, it is at this point it must be said that there may be some =U}of you who would desire these items and so I must reccommend that you should attempt to get hold of a photocopy of them, eith=V}er from the book or from an existing photocopy. There are several drawings throughout the book. It is reccommended that you a=W}lso print this page as a reminder to yourself just in case you ever wish to get the said pages. The importance of the drawing=X}s is relative to one's technical ability and the ambition to learn, therefore, if you don't have the ability or the thirst fo=Y}r knowledge you will not find any major use for the drawings. I am truly sorry I couldn't do them because this makes all the =Z}hard work done already, somewhat incomplete but nevertheless extremely useful. TORPEDO, EDITOR.FIGURE 8-8 I/O SUBSYSTEM SHOU=[}LD BE HERE.PAGE 8-23 ABOVEhat incomplete but nevertheless extremely useful. TORPEDO, EDITOR.FIGURE 8-8 I/O SUBSYSTEM SHOU<0080I/O CONTROL BLOCKS There are four types of control blocks: - Input/Output Control Block (IOCB) A]} - Zero-Page I/O Control Block (ZIOCB) - Device Control Block (DCB) - Command Frame Buffer A^} (CFB) The I/O system control blocks are used to communicate information about the I/O function to be executed. The contA_}rol blocks provide the I/O system routines with control information to perform the I/O function. Refer to the OPERATING SYSTEA`}M Manual for information as to the detailed structure of the four types of control blocks. Eight IOCBs in the OS are used Aa}to effect communication between user programs and CIO. Figure 8-9 shows the content of an IOCB for some common I/O functions.Ab} The IOCBs are: Name Location, Length IOCBO [$340,16] Ac} IOCB1 [$350,16] IOCB2 [$360,16] IOCB3 [$370,16] IOCB4 Ad} [$380,16] IOCB4 [$390,16] IOCB5 [$3A0,16] IOCB6 [$3B0,16] Ae} IOCB7 [$3C0,16] A second type of control block, the ZIOCB [$0020,16], is used to communicate I/O controAf}l data between CIO and the device handlers. When called, CIO uses the value contained in the X-register as an index to which Ag}of the IOCBs (one of eight) is to be used. CIO then moves the control data from the selected IOCB to the ZIOCB for use by theAq}b%DOS SYSbC)AUTORUN SYSb lRAMDISK COMbuDERE89 bDERE90 bDERE91 bDERE92 bDERE93 bDERE94 bDERE95 bDERE96 b DERE97 bDERE98 b0DERE99 b?DERE100 b RDERE101 b\DERE102 b uDERE103 b ~READMENOTE bDERE104 bDERE105 bDERE106 b DERE107 bDERE108 bDERE109 bDERE110 b DERE111 bDERE112 b%DERE113 bADERE114 bQDERE115 baDERE116 biDERE117 bxDERE118 b~DERE119 bDERE120 bDERE121 b DERE122 bDERE123 #DERE124 #DERE125 #DERE126 #DERE127 #DERE128 # 'DERE129 #1DERE130 #@DERE131 #SDERE132 #dDERE133 #uDERE134 #zDERE135 #DERE136 # DERE137 # DERE138 #DERE139 # DERE140 # DERE141 # DERE142 #DERE143 #DERE144 DERE145 appropriate device handler. The ZIOCB is of little interest unless you are writing a new device handler or are replacing a cAr}urrent one. Device handlers that require I/O over the serial bus will then load control information into the DCB [$0300,12As}]. SIO will use the DCB information and return the status information in the DCB for subsequent use by the device handler. FiAt}gure 8-10 illustrates some common I/O functions and the contents of their associated DCBs.PAGE 8-24 ABOVEevice handler. Fi@l0080 The resident disk handler does not conform to the regular user-CIO-handler-SIO calling sequence. Instead, you usEv}e the DCB to communicate directly with the resident disk handler. Section 9, the Disk Operating System, contains more informaEw}tion on the resident disk handler. The last type of control block encountered in the I/O subsystem is the Command Frame BuEx}ffer (CFB). This 4-byte table located at $023A is used by the SIO routine while performing the serial bus operations. The fouEy}r bytes contain the device code, command code, and command auxilliary bytes 1 and 2. The data buffer that is transmitted is dEz}efined by two pointers BUFRLO [$0032,2] and BFENLO [$0034,2]. In general it is not recommended that the OS be used at this leE{}vel. Other parameters have to be set, and extreme care must be taken in calling the proper sequence of subroutines. CIO and SE|}IO were designed to be easily called by user programs. Use them---but stay away from the command frame buffer!PAGE 8-25 ABOE}}VEwere designed to be easily called by user programs. Use them---but stay away from the command frame buffer!PAGE 8-25 ABOD0080A CHART OF THE INPUT/OUTPUT CONTROL BLOCK SHOULD BE IN THIS SPACE AND BELOW THAT SHOULD BE A CHART OF THE DEVICE COI}NTROL BLOCK. IT IS NOT PRACTICAL TO DRAW THESE AND A PHOTOCOPY OF THEM IS RECCOMMENDED.I CAN HAVE PHOTO COPIES DONE AT MY LOI}CAL LIBRARY AT 10p EACH, PLUS POST AND PACKAGE COSTS. IF YOU WANT THE PHOTO COPIES THERE IS A TOTAL OF 20 DRAWINGS THAT REALLI}Y SHOULD BE COPIED AND THEREFORE THE COST WILL BE 2 POUNDS PLUS POST AND PACKAGE OF SECOND CLASS IS 34p, PLEASE SEND A STANDAI}RD A4 SIZE ENVELOPE. TOTAL COST 2.34p PLUS ENVELOPE. THERE IS NO PROFIT IN IT FOR ME, I WILL DO THE RUNNING ABOUT AS A FAVOURI} SHOULD YOU REQUIRE IT. IT MAY BE CHEAPER TO BUY THE BLOODY BOOK. I THINK SO TOO BUT WHAT CAN I DO. I CANNOT SUPPLY FREE COPII}ES BECAUSE I DO NOT HAVE ACCESS TO A COPIER, IF YOU HAVE ACCESS TO A COPIER AND CAN ASSIST YOUR FELLOW ATARIANS THEN PLEASE CI}ONTACT ME A.S.A.P. AND LETS GET THE JOB DONE. A DOZEN COPIES OF EACH DRAWING WOULD BE NICE. TORPEDOI}. 16/6/1992.P.S. THE MAIN OF THIS NOTE CAN BE DELETED FROM DISK BUT LEAVE YOURSELF A SMALL REMINDER OF WHICH DRAWING SHOULDI} BE HERE.2.P.S. THE MAIN OF THIS NOTE CAN BE DELETED FROM DISK BUT LEAVE YOURSELF A SMALL REMINDER OF WHICH DRAWING SHOULDH 0080Central I/O System Routine The main function of CIO is to take control data from an IOCB and ensure that it is rM}outed to the specific device handler needed, and then to pass control to that handler. CIO also acts as a pipeline for most IM}/O in the system. Most of the OS I/O functions use CIO as a common entry point, and all handlers exit via CIO. For example, BM}ASIC will call CIO when performing an OPEN or a GRAPHICS statement. CIO supports the following functions: OPEN M}Device/file open CLOSE Device/file close GET CHARS Read N characters READ RECORD Read next recorM}d PUT CHARS Write N characters WRITE RECORD Write next record STATUS Get device status SPECIAM}L Device handler specific (e.g., NOTE for FMS) You may wish to make your own CIO calls. The calling sequence for CIOM} is: ;rem user has already set up IOCB LDX #IOCBNUM ;set the IOCB index M}(IOCB * 16) JSR CIOV ;system routine vector to CIO BMI ERROR ;if branch taken M}then CIO returned ;error code in Y-register As shown in the above call, one of the IOCBs M}is used to communicate control data to CIO. You may use any one of the eight IOCBs. CIO expects the IOCB index to be in the XM}-register. Note that this value must be the IOCB number multiplied by 16. The reason is that CIO uses this value as a true inM}dex into the various IOCBs, and each IOCB is 16 bytes. Upon return, the sign bit of the 6502 is set to indicate success or erM}ror in the I/O operation. If the N-bit is clear (i.e., a zero) the I/O was done successfully, and the Y-register will containM} a 1. If the N-bit is set, the I/O request resulted in an error; in that case the Y-register will contain the error code numbM}er. A BMI instruction to an error routine is the usual way to test for operational success. The error/success value is also rM}eturned in the IOCB byte ICSTA (see IOCB definition). Chapter 5 of the OPERATING SYSTEM Manual has a sample program segment tM}hat calls CIO to OPEN a disk file, READ some records, then CLOSE the file. CIO copies the control data from the selected IM}OCB to the page zero ZIOCB. CIO then determines the device handler entry point and vectors to the appropriate device handler M}routine. Figure 8-11 is a flowchart of the CIO system routine.PAGE 8-27 ABOVEŠӠśCIO Routine DRAWING M}GOES HERE. SEE PREVIOUS PAGE, READMENOTE.PAGE 8-28 ABOVEŠӠśCIO Routine (cont) DRAWING GOES HERE. SEEM} PREVIOUS PAGE, READMENOTE.PAGE 8-29 ABOVEGE 8-28 ABOVEŠӠśCIO Routine (cont) DRAWING GOES HERE. SEEL-0080OPERATING SYSTEMThe Handler Address TableCIO calculates the device handler entry point in an indirect manner. FQ}irst of all, an OPEN call must preceed any other I/O function to a device. While processing an OPEN command, CIO retreives thQ}e device specification for the file being opened. The devive specification is an ATASCII string pointed to by the buffer addrQ}ess portion of the IOCB. The first element in this string must be a one character device identifier (e.g., 'D' for disk driveQ}, 'P' for printer,...). CIO then searches for this character in a table of handler entry points called HATABS, which runs froQ}m $031A to $033B (Figure 8,12 shows the layout of HATABS). CIO begins the search at the bottom of HATABS and works upward untQ}il a match is found for the device identifier. The search is performed in this direction to facilitate the addition or modifiQ}cation of device handlers. During the initialization code, the HATABS table is copied from ROM down into RAM. Devices that arQ}e then booted (e.g. the disk drive, or RS-232 module) then add their handler information to the bottom of the table. There isQ} room in the table for a total of 14 entries, 5 of which are set up during system initialization. If a new printer handler weQ}re added to the bottom of the table, CIO would find it before the one transferred from ROM. This allows new handlers to replaQ}ce old ones.After the device identifier has been located, CIO knows that the next two bytes point to the devices' entry poinQ}t table. This is a table of addresses for the routines that handle each of the CIO functions. Figure 8,13 gives the layout ofQ} a typical entry point table.To find which one of the handler entry points to vector through, CIO then uses ICCOM, the IOCB Q}command byte, as an index into the entry table. The entry point tables for all of the resident device handlers can be found iQ}n the OS listing. The relative position of each of the vectors in an entry table have the same meaning from table to table. FQ}or exaample, the first position in all of the device handler entry point tables is the vector to the device handler OPEN routQ}ine.You can take advantage of the flexibility of HATABS to add some new features to the OS. Figure 8-14 is an example of howQ} to add a null handler. A null handler does exactly what its name implies: nothing. This can be useful in debugging programs.Q} Instead of waiting around for 50,000 disk accesses to find a bug, output can be directed to the null handler. With a null haQ}ndler, trouble spots in programs can be identified more quickly.PAGE 8-30 ABOVEirected to the null handler. With a null haPR0080 01 ; HANDLER ADDRESS TABLEE430 02 PRINTV = $E430E440 03 CASETV = $E440E40U}0 04 EDITRV = $E400E410 05 SCRENV = $E410E420 06 KEYBDV = $E420 07 ;000U}0 08 *= $031A 09 ; 10 HATABS031A 50 20 .BYTE 'P' PRINTER031B 3U}0E4 30 .WORD PRINTV ENTRY POINT TABLE031D 43 40 .BYTE 'C' CASSETTE031E 40E4 50 U} .WORD CASETV ENTRY POINT TABLE0320 45 60 .BYTE 'E' DISPLAY EDITOR0321 00E4 70 .WORD U} EDITRV ENTRY POINT TABLE0323 53 80 .BYTE 'S' SCREEN HANDLER0324 10E4 90 .WORD SCRENV U} ENTRY POINT TABLE0326 4B 0100 .BYTE 'K' KEYBOARD0327 20E4 0110 .WORD KEYBDV ENTRY POINTU} TABLE0329 00 0120 .BYTE 0 FREE ENTRY 1 (DOS)032A 00 00 0130 .BYTE 0,0032C 00 0140 U} .BYTE 0 FREE ENTRY 2 (850 MODULE)032D 00 00 0150 .BYTE 0,0032F 00 0160 .BYTE 0 FREE EU}NTRY 30330 00 00 0170 .BYTE 0,00332 00 0180 .BYTE 0 FREE ENTRY 40333 00 00 0190 .BYTEU} 0,00335 00 0200 .BYTE 0 FREE ENTRY 50336 00 00 0210 .BYTE 0,00338 00 0220 .BYTEU} 0 FREE ENTRY 60339 00 00 0230 .BYTE 0,0033B 00 0240 .BYTE 0 FREE ENTRY 7 U} Figure 8-12 Handler Address table (HATABS) *=$PRINTVE430 9E EE .WORD PHOPEN-1 DEVICE OPENE432 DU}B EE .WORD PHCLOS-1 DEVICE CLOSEE434 9D EE .WORD BADST-1 DEVICE READ-NOT IMPLEMENTEDE436 A6 EEU} .WORD PHWRIT-1 DEVICE WRITEE438 80 EE .WORD PHSTAT-1 DEVICE STATUSE43A 9D EE .WORD BADSTU}-1 SPECIAL-NOT IMPLEMENTEDE43C 4C 78 EE JMP PHINIT DEVICE INITIALIZATION Figure 8-13U} Printer Handler Entry Point TablePAGE 8-31 ABOVEJMP PHINIT DEVICE INITIALIZATION Figure 8-13T400800000 10 * = $600031A 20 HATABS = $031A0600 A000 40 START LDY #00602 B91Y}A03 60 LOOP LDA HATABS,Y0605 C900 70 CMP #0 ; FREE ENTRY?0607 F009 80 BEQ FOUNDY}0609 C8 90 INY060A C8 0100 INY060B C8 0110 INY ; POINT TO NEXT HATABS Y}ENTRY060C C022 0120 CPY #34 ; AT THE END OF HATABS?060E D0F2 0130 BNE LOOP ; NO... CY}ONTINUE0610 38 0140 SEC ; YES... INDICATE ERROR0611 60 0150 RTS 0160 ;06Y}12 A94E 0180 FOUND LDA #'N ; SET DEVICE NAME0614 991A03 0190 STA HATABS,Y0617 C8 0200 IY}NY0618 A924 0210 LDA #NULLTAB&255061A 991A03 0220 STA HATABS,Y ; HANDLER ADDRESS061D C8 0230 Y} INY061E A906 0240 LDA #NULLTAB/2560620 991A03 0250 STA HATABS,Y0623 60 0260 RTSY} 0270 ;0624 3206 0290 NULLTAB .WORD RTHAND-1 ; OPEN0626 3206 0300 .WORD RTHAND-1 ; CLOSE0628 Y}3406 0310 .WORD NOFUNC-1 ; READ062A 3206 0320 .WORD RTHAND-1 ; WRITE062C 3206 0330 .WORY}D RTHAND-1 ; STATUS062E 3406 0340 .WORD NOFUNC-1 ; SPECIAL0630 4C3306 0350 JMP RTHAND ; INITY}ILIZATION 0360 ;0633 A001 0380 RTHAND LDY #1 ; SUCCESSFUL I/O FUNCTION0535 60 0400 NOFUNC RTY}S ; FUNCTION NOT IMPLEMENTEDFigure 8-14 null handlerPAGE 8-32 ABOVE/O FUNCTION0535 60 0400 NOFUNC RTXV0080The Device HandlersThe device handlers can be devided into resident and nonresident handlers. The resident handler]}s are present in the OS ROM, and may be called through CIO whenever the handler has an entry in HATABS. The nonresident handl]}ers must first be loaded into RAM and have their entry placed into HATABS before they can be called from CIO. The resident de]}vive handlers are:(E:) Display Editor(S:) Screen(K:) Keyboard(P:) Printer(C:) CassetteAlthough the nonresident handlers]} are not present in the OS ROM, nonresident handlers may be added by the OS during power-up or SYSTEM RESET. You can even add]} your own device handler during program execution. Figure 8,14 presents an example of adding a handler to the OS.The device ]}handlers use I/O control data passed by CIO in the ZIOCB. Data in the ZIOCB is used to perform I/O functions such as OPEN, CL]}OSE, PUT, and GET. Not all of the device handlers support all the I/O commands (e.g., trying to PUT a character to the keyboa]}rd results in an Error 146, Function Not Implemented). Section 5 of the OPERATING SYSTEM Manual contains a list of the functi]}ons supported by each device handler, as well as complete operational details of the handlers.Serial I/O RoutineSIO handles]} serial bus communication between the serial device handlers in the computer and the serial bus devices. It communicates with]} its caller through the device control block (DCB). SIO uses the I/O control data in the DCB to send and recieve commands and]} data over the serial bus. The calling sequence is: ;caller has set up the DCB to do functionJSR SIOV ;syst]}em vector to SIOBMI ERROR ;N-bit set indicates error in I/O executionThe DCB contains I/O control information for SIO an]}d must be setup before the call to SIO. Figure 8-10 shows the contents of the DCB for some common I/O operations.To send com]}mands to SIO, you need to understand the structure of the DCB, which is described in Section 9 of the OPERATING SYSTEM Manual]}. Figure 8-15 demonstrates a simple assembly language routine to output a line to the printer by setting up the DCB and calli]}ng SIO.PAGE 8-33 ABOVEs a simple assembly language routine to output a line to the printer by setting up the DCB and calli\00800000 05 *= ARBITARY START 10 ;THIS ROUTINE PRINTS A LINE TO THE PRINTER BY CALLING Sa}IOE459 20 SIOV = $E459 SIO VECTOR009B 30 CR = $9B EOL0040 40 PRNTID = a} $40 PRINTER SERIAL BUS ID004E 45 MODE = $4E NORMAL MODE001C 50 PTIMOT = $001C a} TIMEOUT LOCATION0300 60 DDEVIC = $300 DEVICE SERIAL BUS ID0301 70 DUNIT = $301 SERIAa}L UNIT NUMBER0302 80 DCOMND = $302 SIO COMMAND0303 90 DSTATS = $303 SIO DATA DIRECTIONa}0304 0100 DBUFLO = $304 BUFFER LOW ADDRESS0305 0110 DBUFHI = $305 BUFFER HIGH ADDRESS0306 a} 0120 DTIMLO = $306 SIO TIMEOUT0307 0130 DTIMHI = $3070308 0140 DBYTLO = $308 BUFa}FER LENGTH0309 0150 DBYTHI = $309030A 0160 DAUX1 = $30A AUXILARY BYTE---PRINTER MODE030B a} 0170 DAUX2 = $30B AUXILARY BYTE---NOT USED 0180 ;0000 455841 0190 MESS .BYTE "EXAMPLE 12",CR300a}1 4D504C3005 4520313009 329B 0200 ;300B A940 0220 LDA #PRNTID SET BUS ID300D 8D0003 0230 a} STA $DDEVIC3010 A901 0240 LDA #1 SET UNIT NUMBER3012 8D0013 0250 STA DUNIT3015 A94E 0260 a} LDA #MODE3017 8D0A03 0270 STA DAUX1 PRINTER MODE NORMAL301A A901 0275 LDA #1301C 8D0B03a} 0280 STA DAUX2 UNUSED301F 8D0703 0290 STA DTIMHI TIMEOUT<256 SECS3022 A51C 0300 LDA Pa}TIMOT SET SIO TIMEOUT FOR PRINTER3024 8D0603 0310 STA DTIMLO3027 A900 0320 LDA #MESS&2553029 8D040a}3 0330 STA DBUFLO SET MESS AS BUFFER302C A930 0340 LDA #MESS/256302E 8D0503 0350 STA DBUFa}HI3031 A980 0360 LDA #$80 SET SIO DATA DIRECTION FOR3033 8D0303 0370 STA DSTATS PERIPHERAL TO Ra}ECEIVE3036 A957 0380 LDA #'W SIO COMMAND WRITE3038 8D0203 0390 STA DCOMND303B 2059E4 0410 a} JSR SIOV CALL SIO303E 3001 0420 BMI ERROR3040 00 0430 GOOD BRK3041 00 0440 ERROR BRKfia}gure 8-15 SIO Call to Dump Line to PrinterPAGE 8-34 ABOVEROR3040 00 0430 GOOD BRK3041 00 0440 ERROR BRKfi`<0080SIO InterruptsSIO uses three IRQ interrupts to control serial bus communications with serial bus devices: Le}OCATION,IRQ Length FunctionVSERIR [$020A,2] SERIAL INPUT READYVSEROR [$020C,2] SERIAL OUTPUT NEEDEDVSEROC [e}$020E,2] TRANSMISSION FINISHEDAll program execution is halted while SIO uses the serial bus for communication. Even though e}nothing else is happening during a serial bus transfer, the actual I/O itself is interrupt driven. The method of communicatioe}n between SIO and the interrupt handlers is known as the semaphore method. The mainline code waits in a loop until the interre}upt handlers signal it that they are finished. For instance, during output, SIO places a byte to be transferred into the serie}al output shift register located in POKEY. It then enters a loop and watches a flag which will be set when the requested I/O e}is completed. During this time POKEY is sending the bits out over the serial line. When the byte has been sent, a Serial Outpe}ut Needed IRQ is generated. This IRQ then vectors to a routine which loads the next byte in the buffer into the serial outpute} register. This process continues until the entire buffer has been sent. After taking care of checksum values, the interrupt f}handler then sets the transmit done flag. Meanwhile, SIO has been patiently looping, watching for this flag to be sent. When f}it sees that the flag has been set, SIO exits back to the calling routine.The SIO exection for input is similar. POKEY generf}ates an IRQ (VSERIR) to imform SIO a byte has been received in the serial input shift register (SERIN). The Interrupt handlerf} for VSERIR then stores the byte in a buffer and checks whether the end of the buffer has been reached. If so, it sets the trf}ansmit done flag.You may have noticed from the above explanation that SIO wastes some time idling while waiting for POKEY tof} send or receive information on the bus. Because the vectors for the three SIO IRQ service routines are RAM vectors, they canf} be used by your own handlers to improve system I/O performance. Indeed, this is how the ATARI 850 Interface Module ia able tf}o do concurrent I/O. That handler takes over the SIO IRQ vectors and points them to the module's own IRQ routines while in cof}ncurrent I/O. This allows the calling program to continue to execute while the Interface Module sends commands and data over f }the serial line.PAGE 8-35 ABOVEing program to continue to execute while the Interface Module sends commands and data over d"0080Using CIO from BASICMost of the CIO functions (OPEN, CLOSE, etc.) are available through calls from BASIC using thej } OPEN, GET and PUT statements. However, BASIC lacks one set of the functions of CIO, the ability to do non-record I/O more thj }an a byte at a time (GETCHRS and PUTCHRS).The ability to input or output a buffer of characters is a powerful asset. An assej }mbly language routine can be loaded directly into memory from a disk file for instance. Or a high resolution graphics image cj}an be loaded directly into the screen memory area. A common method of improving a BASIC language program's performance is to j}provide a machine language program to handle certain functions that BASIC executes slowly. Unfortunately, finding a place in j}RAM for such a routine can be a knotty problem. One solution is to place the routine into an area reserved for a string, and j}calling the routine with a USR call to ADR(string). Since the address of a BASIC string may shift during program editing, thej} assembly language routine must be relocatable. Therefore, unmodified memory reference instructions to addresses within the sj}tring will not work.The subroutine in Figure 8-16 avoids the use of strings by loading a routine into Page 6 RAM. Thus the aj}ssembly language routine need not be relocatable. Control data is POKEd into an IOCB to read an assembly language routine dirj}ectly into RAM at the address it was assebled. The BASIC subroutine in Figure 8-16 can also be used to output data directly fj}rom memory with the user specifying both the location and the length of the data buffer.PAGE 8-36 ABOVEput data directly fhj008030 REM THIS PROGRAM LOADS PAGE 6 FROM THE FILE D:TEST100 DIM FILE$(20),CIO$(7):CIO$="hhh*LVd"106 REM CIO$ IS PLAn},PLA,PLA,TAX,JMP $E456 (CIOV)110 FILE$="D:TEST":REM *FILE NAME120 CMD=7:STADR-1536:GOSUB 30000130 IF ERROR-1 THEN ? "TRANSn}FER COMPLETE":STOP135 ? "ERROR # ";ERROR;" OCCURRED AT LINE # ";PEEK(186)+256*PEEK(187)200 END300 REM CIO SETUP SUBROUTINEn}310 REM30000 REM30001 REM30002 REM THIS ROUTINE LOADS OR SAVES MEMORY FILE FROM BASIC30003 REM BY SETTING UP AN IOCB ANDn} CALLING CIO DIRECTLY30004 REM30006 REM ON ENTRY CMD=7 MEANS LOAD MEMORY30008 REM- CMD=11 MEANS SAVE MEMORY30009 n}REM- STADR= THE ADDRESS TO LOAD OR SAVE MEMORY30010 REM- BYTES= THE NUMBER OF BYTES TO SAVE OR LOAD30011 REn}M- IOCB= THE IOCB TO USE30012 REM- FILE$= DESTINATION FILE NAME30013 REM30014 REM ON EXIT ERROR=1 MEANS SUn}CCESSFUL COMMAND30018 REM- ERROR<>1 THEN ITS AN ERROR STATUS30019 REM30020 REM *** IOCB EQUATES ***30022 REM30024n} IOCBX=IOCB*16:ICCOM=834+IOCBX:ICSTA=835+IOCBX30026 ICBAL=836+IOCBX:ICBAH=837+IOCBX30028 ICBLL=840+IOCBX:ICBLH=841+IOCBX30n }029 REM30030 AUX1=4:IF CMD=11 THEN AUX1=830035 TRAP 30900:OPEN #IOCB,AUX1,0,F,FILE$30040 TEMP=STADR:GOSUB 3050030090 POKEn!} ICBAL,LOW:POKE ICBAH,HIGH30100 TEMP=BYTES:GOSUB 3050030130 POKE ICBLL,LOW:POKE ICBLH,HIGH30140 POKE ICCOM,CMD:ERROR=USR(An"}DR(CIO$),IOCBX)30150 ERROR=PEEK(ICSTA):RETURN30200 REM30300 REM *** ROUTINE RETURNS HIGH,LOW BYTE OF 16 BIT NUMBER ***304n#}00 REM30500 HIGH=INT(TEMP/256):LOW=INT(TEMP-HIGH*256):RETURN30550 REM30600 REM *** TRAP HERE IF ERROR OCCURS DURING ROUTINn$}E ***30900 ERROR=PEEK(195)30920 CLOSE #IOCB:RETURNFigure 8-16 BASIC Direct CIO CallPAGE 8-37 ABOVEOCCURS DURING ROUTINli0080REAL TIME PROGRAMMINGMost of the time in programming we have the luxury of ignoring time considerations. Usually wr&}e don't care how long a program takes to run, or don't bother to measure precise timing values on subroutine execution. Sometr'}imes, however, timing considerations play an important role in the performance of the program, and then we enter the world ofr(} Real Time Programming. Such cases arise often with the ATARI Home Computer System. Much more so than with other small computr)}ers, this system thrives on real time control. The very time base upon which the Internal circuitry operates was precisely chr*}osen so that the computer hardware would be in complete synchrony with a specific signal - namely, the television signal.In r+}order to get clean, crisp graphics and special effects, the hardware in the ATARI Home Computer System is slaved to the localr,} television signal. Unfortunately, there are several "standard" television signals in use in various countries. In the Unitedr-} States, the standard is the ntsc system: 60 frames per second, 262 horizontal lines per frame, and 228 color clocks per liner.}. The 262 lines comes about only because the ATARI Home Computer System generates a non-interlaced signal; the real standard r/}calls for 525 lines with half being shown each frame. Some European countries use a standard called PAL: 50 frames per secondr0}, 312 lines per frame. The result is that timing considerations are different on NTSC vs. PAL systems. Refer to section 2, ANr1}TIC and the Display List, for a more detalled discussion of the television signal. The remarks in this subsection are based or2}n NTSC systems.Synching to the Television SignalThe 6502 processor is synchronized to the television signal in two ways, a r3}coarse and a fine synchronization. Coarse synchronization is derived by having the same signal that synchronizes television rr4}eceivers to the transmitted television signal cause a system interrupt. This signal is called vertical blank, and in televisir5}on sets it is the cue to turn off the electron beam and begin retracing to the top of the screen in preparation for another fr6}rame. This same signal is presented to the computer as a non-maskable interrupt. To the programmer, this provides a regularlyr7} occurring interrupt that can be used for everything from sound and timing information to a crude multiprogramming method. For8}r a detailed discussion of Vertical Blank processing, see the subsection on Interrupt Processing Structure.An even finer corr9}relation between the 6502 processing and the television signal was achieved by setting the system clock rate to 1.79 MHz. Thir:}s results in a direct relationship between the time it takes to execute a machine instruction and the distance the electron br;}eam travels on the screen. For instance, during the time it takes to execute the shortest 6502 instruction (2 cycles), the ber<}am moves four color clocks, or one OS mode 0 character width across the screen. This precise correlation of timing allows a sr=}killful programmer to produce graphic effects in the middle of a single scan line. A note of caution is in order, however. ANr>}TIC'S direct memory access makes that this intraline timing very uncertain, and will vary depending upon the mode and other fr?}actors. In actual usage, this means that each intraline change must be dealt with and tested as a special case.PAGE 8-38 ABr@}OVErs. In actual usage, this means that each intraline change must be dealt with and tested as a special case.PAGE 8-38 ABp0080Hardware TimersThere are four countdown timers built into the POKEY chip. They function as reusable "hardware subrvB}outines". The most common use of these timers is in conjunction with the audio channels for producing sound effects (see SectvC}ion 7, Sound). They may also be used as straight countdown timers, since they generate an IRQ interrupt (see subsection on InvD}terrupt Processing Structure). Each timer is associated with a frequency register which holds the initial value for the timervE}. When the hardware register STIMER is written to, this initial value is loaded and the countdown timer started. When the timvF}er counts down to zero, an IRQ interrupt request is generated. It is important to note that only timers 1, 2 and 4 have intervG}rupt vectors for processing. The following steps must be taken to activate any of the timers.Step 1. Set AUDCTL [$D208] withvH} proper value to select clocking frequency for the desired timer.Step 2. Set the volume output to 0 for the audio channel asvI}sociated with the selected timer (AUDC1, AUDC2, AUDC4 [$D201, $D203, $D207]).Step 3. Set AUDF1, AUDF2 or AUDF4 [$D200, $D202vJ}, $D206] with the desired number of clock intervals to count.Step 4. Set up routine to process timer interrupt.Step 5. ChanvK}ge timer interrupt vector to point to processing code (VTIMR1, VTIMR2, VTIMR4 [$0210, $0212, $0214]). *** Note. Due to a bug vL}in the source code, the original version of the operating system will never vector through VTIMR4. This has been fixed in RevvM}. B.Step 6. Set bits 0, 1 or 2 in IRQEN and the OS shadow POKMSK [$D20E and $0010] to enable interrupts from timers 1, 2 or vN}4.Step 7. Write any value to register STIMER [$D209] to load and start the count down timers.One complication of working wivO}th these timers is that the 6502's response to them will be preepted and possibly delayed by ANTIC's direct memory access, divP}splay list interrupts or vertical blank processing.PAGE 8-39 ABOVEand possibly delayed by ANTIC's direct memory access, ditE0080Software TimersThere are 6 system software timers:Name Location Vector or flagRTCLOK [$0012,3] nonezR}CDTMV1 [$0218,2] CDTMA1 [$0226,2]CDTMV2 [$021A,2] CDTMA2 [$0228,2]CDTMV3 [$021C,2] CDTMF3 [$022A,1]CDTMV4 zS} [$021E,2] CDTMF4 [$022C,1]CDTMV5 [$0220,2] CDTMF5 [$022E,1]All of the system timers are decremented as part of thzT}e vertical blank (vblank) process. If the VBLANK process is disabled or intercepted, the timers will not be updated.The realzU} time clock (RTCLOK) and system timer 1 (CDTMV1) are updated during immediate VBLANK, Stage 1. RTCLOK counts up from 0 and iszV} a three-byte value. When RTCLOK reaches its maximum value (16,777,216) it will be reset to zero. RTCLOK can be used as a reazW}l time clock as Figure 8-17 shows.Because the system timers are updated as part of the VBLANK process, special care is needezX}d to set them correctly. A system routine called SETVBV [$E45C] is used to set them. The call to SETVBV is:REG: X contains tzY}he timer value high byte Y contains the timer value low byte A contains the timer number 1-5Example:LDA #1 ;SzZ}et system timer 1LDY #0LDX #2 ;value is $200 VBLANK periodsJSR SETVBV ;Call system routine to set timerSystem timers z[}1-5 are 2-byte counters. They may be set to a value using the SETVBV routine. The OS then decrements them during VBLANK. Timez\}r 1 is decremented during immediate VBLANK Stage 1. Timers 2-5 are decremented during immediate VBLANK, Stage 2. Different acz]}tions are taken by the OS when the different timers are decremented to 0.System timers 1 and 2 have vectors associated with z^}them. When timer 1 or 2 reaches 0, the OS simulates a JSR through the vector for the given timer. Figure 8-7 gives the vectorz_}s for the two timers.System timers 3-5 have flags that are normally SET (i.e.non-zero). When either of the timers count to 0z`}, the OS will clear (zero) that timer's flag. You may then test the flag and take appropriate action.PAGE 8-40 ABOVEt to 0xw0080Timers 1-5 are general purpose software timers that may be used for a variety of applications. For example, timer 1~b} is used by SIO to time serial bus operations. If the timer counts to zero before an bus operation is complete, a "timeout" e~c}rror is returned. Timer 1 is set to various values depending on the device being accessed. This ensures that, while a device ~d}has ample time to answer an I/O request, the computer will not wait indefinitely for a non-existent device to respond. The ca~e}ssette handler uses timer 3 to set the length of time to read and write tape headers. Figure 8-18 shows an example using tim~f}er 2 to time a sound acting as a metronome.The software timers are generally used when the time scale involved is greater th~g}an one VBLANK period. For time durations shorter than this, either the hardware timers or some other method must be employed.~h}PAGE 4-41 ABOVEod. For time durations shorter than this, either the hardware timers or some other method must be employed.|0080NOTE FROM ED:- WHERE IT HAS THE ?"+" IN THE PROGRAM IT SHOULD NORMALLY HAVE THE BENT ARROW BUT THIS IS NOT PRINTABLj}E USING THIS WORDPROCESSOR SO TO DO THE PROGRAM FULL JUSTICE YOU SHOULD REPLACE THE PRINT "+" WITH THE PRINT "BENT ARROW" STAk}TEMENT, ALTHOUGH PRINT CHR$(125) SHOULD WORK JUST AS WELL. THE PLUS SIGN IS USED HERE IN REPLACEMENT OF THE BENT ARROW. ED.1l} POKE 752,13 ? "+":REM CLEAR SCREEN (+=ESC-CTRL-CLR)4 ? "HOUR";:INPUT HOUR:? "MINUTE ";:INPUT MIN:? "SECOND";:INPUT SEC5 Cm}MD=1:GOSUB 456 ? "+";HOUR;" : ";MIN;" : ";SEC:? " ":? " "7 CMD=2:GOSUB 459 ? "";HOUR;":";MIN;":";" ":GOTO 710 REM THIS n}IS A DEMO OF THE REAL TIME CLOCK20 REM THIS ROUTINE ACCEPTS AN INITIAL TIME IN HOURS, MINUTES, AND SECONDS30 REM IT SETS THo}E REAL TIME CLOCK TO ZERO40 REM THE CURRENT VALUE OF RTCLOCK IS USED TO ADD TO THE INITIAL TIME TO GET42 REM THE CURRENT TIp}ME HOUR, MIN, SEC45 HIGH=1536:MED=1537:LOW=153850 REM60 REM ****** ENTRY POINT ******65 REM70 ON CMD GOTO 100,20095 REMq}96 REM ****** INITIALIZE CLOCK ******97 REM100 POKE 20,0:POKE 19,0:POKE 18,0105 DIM CLOCK$(50)106 CLOCK$=" "107 GOSUB 3r}00110 IHOUR=HOUR:IMIN=MIN:ISEC=SEC:RETURN197 REM198 REM ****** READ CLOCK ******199 REM200 REM201 A=USR(ADR(CLOCK$))21s}0 TIME=((((PEEK(HIGH)*256)+PEEK(MED))*256+PEEK(LOW))/59.923334220 HOUR=INT(TIME/3600):TIME=TIME-(HOUR*3600)230 MIN=INT(TIMEt}/60):SEC=INT(TIME-(MIN*60))235 SEC=SEC+ISEC:IF SEC>60 THEN SEC=SEC-60:MIN=MIN+1236 MIN=MIN+IMIN:IF MIN>60 THEN MIN=MIN-60:Hu}OUR=HOUR+1237 HOUR=HOUR+IHOUR240 HOUR=HOUR-(INT(HOUR/24))*24250 RETURN300 FOR J=1 TO 38:READ Z:CLOCK$(J,J)=CHR$(Z):NEXT Jv}:RETURN310 DATA 104,165,18,141,0,6,165,19,141,1,6,165320 DATA 20,141,2,6,165,18,205,0,6,208,234330 DATA 165,19,205,1,6,208w},227,165,20,205,2,6,208,220,96Figure 8-17 Real Time ClockPAGE 8-42 ABOVE5,18,205,0,6,208,234330 DATA 165,19,205,1,6,208M0080NOTE FROM ED. SEE PREVIOUS PAGE FOR NOTE ON CLEARING THE SCREEN AND THE BENT ARROW USED TO CARRY OUT THIS TASK.1 y}REM THIS IS A BASIC PROGRAM TO CONTROL THE RATE OF A METRONOME2 REM3 REM5 PRINT "+":REM CLEAR SCREEN10 X=10:REM INITIAL Vz}ALUE FOR RATE20 FOR J=1 TO 10:NEXT J:REM SOFTWARE DELAY LOOP50 IF STICK(0)=14 THEN X=X+1:REM STICK FORWARD MEANS SPEED UP R{}ATE51 IF STICK(0)=13 THEN X=X-1:REM STICK BACK MEANS SLOW METRONOME RATE52 IF X<1 THEN X=1:REM NEVER GO BELOW ONE53 IF X>2|}55 THEN X=255:REM OR ABOVE 25554 REM PRINT BEATS/MINUTE56 ? "";INT(3600/X);" BEATS/MINUTE60 POKE 0,X:REM LOCATION $0000 HO}}LDS THE RATE FOR70 70 NEXT I:REM THE FOLLOWING ASSEMBLY ROUTINEFigure 8-18 BASIC language Metronome RoutinePAGE 8-43 HOz008040 *=$60050 ;METRONOME ROUTINE...USES $0000 TO PASS THE METRONOME RATE60 ;70 AUDF1 = $D20}0 AUDIO FREQUENCY REGISTER80 AUDC1 = $D201 AUDIO CONTROL REGISTER90 FREQ = $08 AUDF1 VALUE}0100 VOLUME = $AF AUDC1 VALUE0110 OFF = $A0 TURN OFF VOLUME0120 SETVBV = $E45C SET} TIMER VALUE ROUTINE0130 XITVBV = $E4620140 CDTMV2 = $021A TIMER 20150 CDTMA2 = $0228 TIMER} 2 VECTOR0160 ZTIMER = $0000 ZPAGE VBLANK TIMER VALUE0170 ;0180 START LDA #100190 STA ZTIM}ER0200 ; SET THE TIMER VECTOR0220 ;0230 INIT LDA #CNTINT&2550240 STA CDTMA20250 LDA } #CNTINT/2560260 STA CDTMA2+10270 ;0280 ; SET THE TIMER VALUE AFTER THE VECTOR0290 ;0300 LDY } ZTIMER SET TIMER TWO TO COUNT0310 JSR SETIME0320 RTS0340 ; METRONOME COUNT DOWN VECTORS TO} HERE0380 ; SET UP AUDIO CHANNEL FOR MET CLICK0390 ;0400 CNTINT LDA #VOLUME0410 STA AUDC10420 } LDA #FREQ0430 STA AUDF10435 LDY #$FF DELAY0440 DELAY DEY0442 BNE }DELAY0450 STY AUDC10460 JMP INIT0480 ;0490 ; SUBROUTINE TO SET TIMER0500 ;0520 SETIME }LDX #0 NO TIME >256 VBLANKS0530 LDA #2 SET TIMER 20540 JSR SETVBV SYST}EM ROUTINE TO SET TIMER0550 RTS0560 *=$2E20570 .WORD START0580 .ENDFigure 8-19 As}sembly language Metronome RoutinePAGE 8-44 ABOVE *=$2E20570 .WORD START0580 .ENDFigure 8-19 As30080FLOATING POINT PACKAGEThe Floating Point Package (FPP) is a set of integrated routines that provide an extended ar}ithmetic capability for the OS. These routines are combined in a separate ROM chip that is provided as part of the ATARI 10K }OPERATING SYSTEM. The FPP is located at hexadecimal addresses $D800 - $DFFF. It has not been changed in the Revision B versio}n of the OS. The following paragraphs detail the internal representation of numbers, the actual routines available for use, a}nd their proper calling sequence. An assembly language program example is included to illustrate how to access the FPP from u}ser programs.Internal RepresentationThe FPP configures numbers internally as 6-byte quantities. Each number consists of a 1}-byte exponent and a 5-byte mantissa in Binary Coded Decimal (BCD) format. This representation was chosen to minimize roundin}g errors that might occur in some math routines.The sign bit of the exponent byte provides the sign of the mantissa, 0 for p}ositive, 1 for negative. The least significant 7 bits of the exponent byte provide the exponent as a power of 100 in "excess }64 notation". In excess 64 notation, the value 64 is added to the exponent value before it is placed in the exponent byte. Th}is allows the full range of exponents, positive and negative, to be expressed without having to use the sign bit.The mantiss}a is always normalized such that the most significant byte is non-zero. However, since the mantissa is in BCD format, and the} exponent represents powers of 100 and not 10, either 9 or 10 digits of precision may result. There is an implied decimal poi}nt to the right of the first mantissa byte so that an exponent that is less than 64 (40 hex) indicates a number less than 1.}EXAMPLES (Format values are in hex)Number: 0.02 = 2 * 100**-1Format: 3F 02 00 00 00 00 (exponent= 40-1)Number: -0.}02 = -2 * 100**-1Format: BF 02 00 00 00 00 (exponent= 80+40-1)Number: 37.0 = 37 * 100**0Format: 40 37 00 00 00 }00 (exponent= 40+0)Number: -460312 = -46.0312 * 100**2Format: C2 46 03 12 00 00 (exponent= 80+40+2)The number zero i}s handled as a special case, and is represented as a zero exponent and zero mantissa. Either the exponent or the first mantis}sa byte may be tested for zero.The dynamic range of numbers that can be represented by this scheme is 10**-98 to 10**+98PA}GE 8-45 ABOVEtested for zero.The dynamic range of numbers that can be represented by this scheme is 10**-98 to 10**+98PA0080Memory UtilizationTwo areas of RAM memory are used in implementing the FPP. They are:$00D4 - $00FF in Page zero$}057E - $05FF in Page fiveThese areas are used both for control parameter storage and to simulate several floating point regi}sters. The two pseudo-registers of primary interest are called FRO ang FRI (locations $00D4-$00D9 and $00E0-$00E5 respectivel}y). Each of these pseudo-registers is six bytes in length and will hold a number in floating point representation. A two-byte} pointer is used in pointing to a floating point number. This is called FLPTR and resides at $00FC.Buffer areas must be prov}ided for text strings in converting between floating point numbers and ATASCII text strings. The output buffer is called LBUF}F, a 128 byte block from $0580 to $05FF. The input buffer is set by the two byte pointer INBUFF at $00F3. Also, a one byte in}dex CIX at $00F2 is used as an offset into the buffer pointed to by INBUFF.A typical sequence to use the floating point pack}age from an assembly language routine would be as follows. First an ATASCII string that represents on of the numbers to be us}ed by a math routine would be stored in a buffer anywhere in memory. Next, pointer INBUFF would be set to point to the beginn}ing of this string. Also, the index value, CIX, should be set to 0. The number is then ready to be converted to a floating po}int representation, so routine AFP would be called. This would result in a floating point number being placed in FRO where it} could be used in any of the FPP operations. After the conclusion of the mathematical operations, the floating result would b}e in FRO. Calling the routine FASC would convert this number to an ATASCII string located in LBUFF. Refer to Figure 8-21 for }an example of this process.To use 16-bit values with the FPP, place the two bytes of the number into the lowest two bytes of} FRO ($D4 and $D5) and JSR IFP, which converts the integer to its floating point representation, leaving the result in FRO. S}ubroutine FPI performs the reverse operation.The chart on the next page lists the functions available, their ROM addresses, }pseudo registers affected and approximate maximum computation time.PAGE 8-46 ABOVEnctions available, their ROM addresses, U0080FLOATING POINT ROUTINESNAME ADDRESS FUNCTION RESULT MAX. TIME (microsec.)AFP D800 ATASC}II to floating point FRO 3500FASC D8E6 Floating point to ATASCII LBUFF 950IFP D9AA Integer to floating }point FRO 1330FPI D9D2 Floating point to integer FRO 2400FSUB DA60 FRO-FRI Subtraction FRO } 740FADD DA66 FRO+FRI Addition FRO 710FMUL DADB FRO*FRI Multiplication FRO 12000FDIV D}B28 FRO/FRI Divsion FRO 10000FLDOR DD89 Floating Load using X,Y FRO 70FLDOP DD8D Floating L}oad using FLPTR FRO 60FLD1R DD98 Floating Load using X,Y FRI 70FLD1P DD9C Floating Load using FLPTR} FRI 60FSTOR DDA7 Flaoting store using X,Y FRO 70FSTOP DDA8 Floating store with FLPTR FRO 70}FMOVE DDB6 Move FRO FRI 60PLYEVL DD40 Polynomial evaluation FRO 88300EXP DDC0 }Exponentiation - e**FRO FRO 115900EXP10 DDCC Exponentiation - 10**FRO FRO 108800LOG DECD Natural logarit}hm FRO 136000LOG10 DED1 Base 10 logarithm FRO 125400ZFRO DA44 Set to zero FRO} 80AF1 DA46 Set register in X to zero varies 80Figure 8-20 Floating Point RoutinePAGE 8-47 ABOVE FROw00800000 20 *= $4000 ; ARBITRARY STARTING POINTDDB6 30 FMOVE = $DDB6DA60 40 FSUB }= $DA600482 50 FTEMP = $0482DDA7 60 FSTOR = $DDA7D8E6 70 FASC = $D8E600F3 80 INBU}FF = $00F3D800 85 AFP = $D80000F2 90 CIX = $00F20580 100 LBUFF = $05800098 120 C}R = $9B0009 130 PUTREC = $090005 140 GETREC = $05E456 150 CIOV = $E4560342 160 ICCO}M = $03420344 170 ICBAL = $03440348 180 ICBLL = $0348 190 ; 200 ; FLOATING POI}NT DEMONSTRATION 210 ; READS TWO NUMBERS FROM SCREEN EDITOR, 215 ; CONVERTS THEM TO FLOATING POINT,} 220 ; SUBTRACTS THE FIRST FROM THE SECOND, 225 ; STORES THE RESULT IN FTEMP, 230 ; WH}ICH IS A USER DEFINED FP REGISTER, 240 ; AND DISPLAYS THE RESULT.4000 205340 260 START JSR GETNUM ; GET }1ST NUMBER FROM E:4003 20B6DD 270 JSR FMOVE ; MOVE NUMBER FROM FRO TO FR14006 205340 280 JSR GETNUM } ; GET 2ND NUMBER FROM E:4009 2060DA 290 JSR FSUB ; FRO <-- FRO-FR1400C 900A 300 BCC NOERR } ; SKIP IF NO ERROR400E A981 340 LDA #ERRMSG&255 ; IF ERR., DISPLAY MESSAGE4010 8D4403 350 STA ICBAL4}013 A940 360 LDA #ERRMSG/2564015 4C3940 370 JMP CONTIN4018 A282 390 NOERR LDX #FTEMP&255 ; STORE R}ESULT IN FTEMP401A A004 400 LDY #FTEMP/256401C 20A7DD 410 JSR FSTOR 420 ; 430 } ; CONVERT NUMBER TO ATASCII STRING. 440 ; FIND END OF STRING, 445 ; CHANGE NEGATIVE NUM. TO POSITI}VE, 450 ; AND ADD CARRIAGE RETURN.401F 20E6D8 470 JSR FASC ; FP TO ATASCII, RESULT IN LBUFF4022} A0FF 480 LDY #$FF4024 C8 490 MLOOP INY4025 B1F3 500 LDA (INBUFF),Y ; LOAD NEXT BYTE4027 10FB} 510 BPL MLOOP ; IF POSITIVE, CONTINUE4029 297F 520 AND #$7F ; IF NOT, MASK OFF MSBIT402B }91F3 530 STA (INBUFF),Y402D C8 540 INY402E A99B 550 LDA #CR ; STORE CARRAGE RETUR}N4030 91F3 560 STA (INBUFF),Y 570 ;PAGE 8-48 ABOVE0 LDA #CR ; STORE CARRAGE RETURN0080 580 ; DISPLAY RESULT4032 A5F3 600 LDA INBUFF ; GET BUFFER ADDRESS4034 8D4403 610 } STA ICBAL4037 A5F4 620 LDA INBUFF+14039 8D4503 630 CONTIN STA ICBAL+1403C A909 640 LDA #PUTRE}C ; COMMAND FOR PUT RECORD403E 8D4203 650 STA ICCOM4041 A928 660 LDA #40 ; SET BUFFER LENGTH }= 404043 8D4803 670 STA ICBLL4046 A900 690 LDA #04048 8D4903 700 STA ICBLL+1404B A200 710 } LDX #0 ; IOCB # = 0 FOR SCREEN EDITOR404D 2056E4 720 JSR CIOV ; CALL CIO4050 4C0040 730 } JMP START ; DO IT AGAIN 740 ; 750 ; GET ATASCII STRING FROM E: 755 ; CONVER}T TO FP, RESULT IN FRO4053 A905 780 GETNUM LDA #GETREC ; GET RECORD (ENDS WITH CR)4055 8D4203 790 STA ICCOM}4058 A980 800 LDA #LBUFF&255 ; SET BUFFER ADDRESS = LBUFF405A 8D4403 810 STA ICBAL405D A905 820 } LDA #LBUFF/256405F 8D4503 830 STA ICBAL+14062 A928 840 LDA #40 SET BUFFER LENGTH = 404064 }8D4803 850 STA ICBLL4067 A900 860 LDA #04069 8D4903 870 STA ICBLL+1406C A200 880 L}DX #0 ; IOCB # = 0 FOR SCREEN EDITOR406E 2055E4 890 JSR CIOV ; CALL CIO4071 A980 900 LDA }#LBUFF&255 ; STORE BUFFER ADD. IN INBUFF4073 85F3 910 STA INBUFF4075 A905 920 LDA #LBUFF/2564077 85F}4 930 STA INBUFF+14079 A900 940 LDA #0 ; SET BUFFER INDEX = 0407B 85F2 950 STA CIX}407D 2000D8 960 JSR AFP ; CALL ATASCII TO FP4080 60 970 RTS4081 45 980 ERRMSG .BYTE "ER}ROR",CR4082 524083 524084 4F4085 524086 9B 1000 ; ROUTINE START INFO4087 1020 * = $2E002E0 }0040 1030 .WORD START02E2 1040 .ENDFigure 8-21 Floating Point ExamplePAGE 8-49 ABOVE$2E002E0 s00809THE DISK OPERATING SYSTEMThe Disk Operating System (DOS) is an extension of the OS that allows you to access t}he ATARI 810 Disk Drive mass storage device as you would access any of the input/out devices. DOS has Three primary component}s, the resident disk handler, the File Management System (FMS), and the Disk Utility Package (DUP). The resident disk handler} is the only part of DOS provided in the OS ROM. FMS and DDUP both reside on diskette, with FMS being loaded ("booted") into }memory at power-up. DUP is not automatically loaded at power up, but requires an explicit request from an appilication progra}m. If the BASIC language cartridge is present, for instance, DUP is not loaded until a DOS statement is issued. The following} subsections describe each of these components in more detail and present other related topics necessary for effective utiliz}ation of DOS. You should note that the comments in this section refer to version 2.OS of the Disk Operating System, which is }substantially different from earlier versions of DOS. For complete technical details regarding DOS, you should also refer to }the OPERATING SYSTEM Manual, and the DISK OPERATING SYSTEM II Manual.The Resident Disk HandlerThe resident disk handler is }the simplest part of DOS. The disk handler does not conform to the normal CIO calling sequence as observed by other Device Ha}ndlers (see section 8, the Operating System, for details on using the Centralized Input/Output Subsystem). In DOS 2.OS, the r}esident disk handler is used only during the initial boot process. From then on, additional code in the FMS is used in access}ing the disk drives. The relationship of the disk handler to the I/O subsystem is shown in Figure 8-8 of this manual.The Dev}ice Control Block (DCB) is used to communicate with the disk handler.Figure 8-10 illustrates the stucture of the DCB. The cal}ling sequence for the disk handler is: ;caller has already set up DCBJSR DSKINV ;system routine Vector to the }resident Disk HandlerBPL OKAY ;Branch if success, Y Reg. =1 ;Else y reg. = error status (DCBSTA also has erro}r)The disk handler is a subroutine that is used to support the physical transfers of data between the 6502 inside the ATARI }Home Computer System, and another processor located inside the ATARI 810 Disk Drive. This data transfer occurs over the seria}l input/output bus. The OS resident disk handler supports four functions:FORMAT Issue a Format command to the} disk controllerREAD SECTOR Read a specified sectorWRITE/VERIFY SECTOR Write sector; check sector to see if wri}ttenSTATUS Ask the disk controller for its statusPAGE 9-1 ABOVE Write sector; check sector to see if wriR0080The format command clears all the tracks on the diskette and writes sector addresses onto the tracks. No file struc}ture is put on the diskette by this command. The data portion of each sector is set to all zeros, and the initial Volume Tabl}e of Contents and the File Directory are established. For more information on the physical layout of data on a diskette, refe}r to the OPERATING SYSTEM Manual and the subsection on FMS Disk Utilization.You should note that all I/O from the disk handl}er is sector-oriented. The sector I/O commands can be used to read and write any sector on the diskette. You can use them to }implement your own file structure. Section 10 of the OPERATING SYSTEM Manual has an example of using the disk handler to writ}e a boot file.The STATUS function is used to determine the status of the disk drive. This command causes the disk drive to t}ransmit four bytes that define its current status. These bytes are loaded into DVSTAT [$02EA,4]. The first byte is a command }status byte and contains the following bits:Bit-0 = 1 indicates an invalid command frame was received.Bit-1 = 1 indicates a}n invalid data frame was received.Bit-2 = 1 indicates that a PUT operation was unsuccessful.Bit-3 = 1 indicates that the di}sk is write protected.Bit-4 = 1 indicates active/standby.The second byte is a hardware status byte and contains a copy of t}he status register of the INS1771-1 Floppy Disk Controller chip used in the disk controller. The third byte is a timeout byte} that contains a controller-provided maximum timeout value (in seconds) to be used by the handler. The fourth byte is unused.} You can use the STATUS command for several purposes. Since the device timeout value for a STATUS command is less than that f}or the other commands, you can use it to see if a specific disk drive is connected. If the disk handler returns a device time}out error, you know the disk drive is not conected.PAGE 9-2 ABOVEe is connected. If the disk handler returns a device timeD0080File Management SystemThe File Management System (FMS) is a nonresident device handler that uses the normal device} handler-CIO interface. FMS is not present in the OS ROM. It is booted in at power-up if a diskette containing DOS is present }.FMS, like the other device handlers, gets I/O control data from CIO. FMS then uses its own disk handler to input and output } to the diskette. The additional disk handler code was provided primarily to overcome an operating system bug. This bug is th }e result of an incorrect 16-bit compare of buffer pointers that may occur during SIO transfers. Specifically, it occurs when }a buffer ends on a page boundary. However, since the result of this patch is to place a disk handler in RAM, it is possible t }o customize DOS somewhat. The hardware in the disk drive itself is capable of another function not supported by the resident }disk handler. This function is a WRITE SECTOR WITHOUT VERIFY command. Even though some reliability is sacrificed, disk writes} occur faster. To perform this customization from BASIC, you need to type:POKE 1913,80 for fast read (Write without Read Ver}ify)If you want to restore the Write with Read verify, type:POKE 1913,87FMS is called by setting up an IOCB and calling CI}O. FMS supports some special functions not available to other handlers:FORMAT FMS calls the disk handler to format the disk}ette. After a successful format, FMS writes some file structure data on the diskette.NOTE FMS returns the} current value of the file pointer.POINT FMS sets the file pointer to a specified value.The subsection on Random Access c}ontains instructions on using NOTE and point.Disk I/OYou can access all the standard file I/O calls through CIO. In BASIC }this means using the I/O commands, such as OPEN, CLOSE, GET, PUT and CIO.To do any disk I/O, you must first OPEN a file. The} BASIC syntax for the OPEN command is:OPEN #IOCB,ICAX1,0,"D:MYPROG.BAS"PAGE 9-3 ABOVEI/O, you must first OPEN a file. TheY0080The #IOCB selects one of the eight IOCBs available (see the CIO subsection in section 8, the Operating System, for }IOCB setup). You should avoid IOCBs #0, 6, and 7 since they are used by the OS and BASIC at various times. ICAX1 is the OPEN }type code. The bits for the type code are:BIT 7 6 5 4 3 2 1 0 x x x x W R D AWhere: A is Append } D is Directory R is Read W is Write x is unusedFigure 9-1 Auxillary Byte Layout for the OPEN Command}The various values for ICAX1 are discussed in section 5 of the OPERATING SYSTEM Manual. Some of the keys things to note abou}t the various OPEN modes are:ICAX1=6 This is used to OPEN the diskette directory. Records READ are the diskette directory en}tries.ICAX1=4 READ mode.ICAX1=8 WRITE mode. Any existing file opened in this mode is first deleted. The first bytes written} will be at the start of the file.ICAX1=9 WRITE APPEND mode. The file is left intact. Bytes written to this file are put }at the end of the file.ICAX1=12 UPDATE mode. this mode allows both READ and WRITE to the file. Bytes read and writen start a }t the first byte in the file.ICAX1=13 Not supported.There are two types of I/O you can use to transfer data between your pr!}ogram and the disk, record character. Character I/O means that the data in a file is a sequential string of bytes. DOS interp"}rets this list of bytes as data, with none of the values being interpreted as control characters. An example of character dat#}a (all values are in HEX):00 23 4F 55 FF 34 21.Record I/O means that data in a file is made up of a set of records. Arecord$} is a group of bytes followed by an END of Line (EOL) character with the value $9B. An example of two records is:00 23 4F 55%} FF 34 9B 21 34 44 9B I record 1 I record 2 IRecord and character I/O to files can be done in any arbitrar&}y order.PAGE 9-4 ABOVE I record 1 I record 2 IRecord and character I/O to files can be done in any arbitrar0080Indeed, data created as records can be read as characters, and file data created as characters can be read as recor(}ds. The only difference between character and record I/O is that records must end with a $9B value. $9B is treated as ordinar)}y data when using I/O.BASIC supports record I/O quite well. The commands PRINT and INPUT can be used to write and read recor*}ds from files. BASIC does not completely support character I/O. The commands GET and PUT allow you to read and write a single+} byte at a time. However, the OS has the ability to read and write blocks of characters. This ability is not used by BASIC. I,}n using this feature in the OS, you must specify the length and address of the data block to be transferred. To use the chara-}cter block mode of the OS from BASIC, you can write an assebly language module to be called from BASIC by the USR function. F.}igure 8-16 has an example of a subroutine to do character block I/O.The XIO command in BASIC is a general Input/Output state/}ment that allows for direct cmmunication with CIO from BASIC. it is described in more detail in the following subsection.PA0}GE 9-5 ABOVEows for direct cmmunication with CIO from BASIC. it is described in more detail in the following subsection.PA 0080Disk Utility PackageThe Disk Utility Package (DUP) is a set of utilities for diskette management, familiary seen a2}s the DOS menu. DUP executes commands by calling FMS through CIO. The commands are:A. DIRECTORYB. RUN CARTRIDGEC. COPY FIL3}ESD. DELETE FILESE. RENAME FILESF. LOCK FILESG. UNLOCK FILESH. WRITE DOS FILESI. FORMAT DISKJ. DUPLICATE DISKK. SAVE 4}BINARY FILEL. LOAD BINARY FILEM. RUN AT ADDRESSN. WRITE MEM.SAV FILEO. DUPLICATE FILEThe following subsections describe 5}each of these functions. However, for complete information on these functions, refer to the DISK OPERATING SYSTEM 11 Manual.6}Wild CardsMany of the DUP commands require a spcification. DOS recognizes two "wild cards" that you can substitute for chara7}cters in a filename. Wild cards are represented by the special characters, question mark (?) and asterisk (*).These characte8}rs are used in filename descriptors where, for whatever reason, there exists some uncertainty as to the exact fillename. an e9}xample of this would be when a filename extension is not known, for instance. Another example would be when you want to copy :}only files with a specific extension such as .OBJ.The question mark (?) may be substituted for a single character. The aster;}isk (*) can stand for any valid combination of characters or number of characters. The following examples illustrate the use <}of these characters in a directory command. *.BAS will list all files on a diskette in Drive 1 that end in .BAS.PRO*.BAS =}will list all the program files on diskette in Drive 1 that begin with PRO and have .BAS as the extender.TEST?? will list >}all the program files on diskette in Drive 1 that begin with TEST and have any combination of letters or numbers for the last?} two characters.PAGE 9-6 ABOVE in Drive 1 that begin with TEST and have any combination of letters or numbers for the last!0080Disk Directory (A)The Disk Directory contains a list of all the files on a diskette. This command will list the fiA}lenames, the extender, and the number of sectors that the file occupies on the diskette. A partial list can be generated by eB}ntering specific filename parameters. Wild cards can be used in the parameters.RUN CARTRIDGE (B)The 'B' command, Run CartriC}dge, is typed, DOS gives control of the system to whichever cartridge is inserted. The response from that point on is dependeD}nt upon specific cartridges. BASIC, for instance, will respond by printing READY on the screen.If the diskette in drive 1 haE}s not been changed since the DUP was loaded, and if a MEM.SAV file is present on the diskette, then the contents of this fileF} is copied back into RAM before control is released to the cartridge. This file normally is used to store the contents of theG} portion of RAM that DUP occupies when it is loaded. However, this file must already exist on the diskette when a call is issH}ued to load DUP. Before DUP is loaded, the RAM contents are written out to the diskette for later retrieval. You can think ofI} MEM.SAV and DUP as swapping places between the diskette and RAM.Copy File (C)The Copy File command ('C'), is used to copy J}a file from a diskette in one drive to another diskette in a second disk drive. You will be prompted to give file specificatiK}ons for the file to COPY-FROM, TO. The first file specification may contain wild cards, and can be used to indicate a series L}of files to be copied. The second parameter is also generally a file specification, but may also be a destination device suchM} as E: (screen) or P: (printer). The second parameter may be followed with a '/A' option, which indicates that the first nameN}d file should be appended to the second file. This option should not be used with tokenized Basic files.Delete File (D)ThisO} option allows you to delete one or more files from a diskette. Wildcards can be used in file specification names. You can avP}oid having to respond to the delete verification prompt by appending a '/N' option to the file specification.Rename File (E)Q}This option allows you to change the name of an existing file on a diskette. You must provide two parameters, OLD NAME and NR}EW.PAGE 9-7 ABOVEyou to change the name of an existing file on a diskette. You must provide two parameters, OLD NAME and N0080The first parameter must a be complete file specification, but the second is just the new file name. Wild cards areT} permitted for both names. If no device specification is included, D1: is assumed. An error will be generated if the first fiU}le name doesn't exist on the diskette, if the file is locked, or if the diskette is write protected.Lock File (F)This commaV}nd is used to prevent a file from being inadvertently erased or modified. A locked file is indicated by an asterisk (*) preceW}ding its name in the directory. Note however, that the Format command pays no attention to the Lock status of any file on a dX}iskette.Unlock File (G)This option is used to Unlock a file that has been previously Locked. Both this and the Lock commandY}s may use wild cards.Write DOS File (H)This option must be used to create a copy of DOS on a formatted diskette, since theyZ} can't be copied with a Copy command.Format Diskette (I)This option is used to create the sector and track information on a[} blank diskette so that it may by used by DOS. If a bad sector is encountered during the formatting process, DOS will not con\}tinue. A diskette with a bad sector cannot be formatted and is useless. WARNING! Be very careful with this command, for it wi]}ll wipe out any existing file on the diskette.Duplicate Disk (J)This menu option is used to create an exact duplicate of an^}y diskette that has been created and maintained by DOS. This option can be used with either single or multiple drive systems._} Duplicating on a single drive system does require repeated manual swapping of the source and the destination diskettes.The `}duplication process occurs on a sector-by-sector basis. However, only those sectors that are marked as in use by the Volume Ta}able of Contents are copied.Care should be taken in using this command, for it destroyes any files that may have resided on b}the destination diskette. A good policy would be to place a write protect tab on the source diskette to preclude a catastrophc}ic mistake by typing the source and destination values in reverse order.PAGE 9-8 ABOVEce diskette to preclude a catastrophY0080Binary Save (K)This command is used to save the contents of memory locations in an object (binary) format. This foe}rmat is also used by the ATARI Editor Assembler Cartridge. Ths format consists of two header bytes of $FF, two bytes for the f}starting load address, and two bytes for the ending load address. The remainder of the file is actual load data. You will be g}prompted to enter a filename and the starting and ending address for the load. There are also two additional address values th}hat may optionally be entered. These values that upon load will be placed in locations known as INIT [$O2EO,2] and RUN [$O2EOi},2].If these locations are updated during the load, then the code pointed to by the value in these locations will be executedj}.Binary Load (L)This command is used to load a binary load file from the diskette into RAM memory. If values for INIT and Rk}UN values have been appended to this file, then it will function as a load-and-go routine.Run At Address (M)This command isl} used to transfer control to a machine language routine located in memory. This is normally used to start a program that has m}been loaded, but did not have INIT or RUN values appended to the file.Create MEM.SAVThis menu option is used to create a fin}le called MEM.SAV. This file is used to save the contents of memory that will be overlaid when the DUP is loaded in. Effectivo}ely then, MEM.SAV and DUP swap places from RAM to disk. Note that MEM.SAV must be on the diskette in drive 1 to work. It alsop} takes about 2O seconds to swap memory out and load DUP in if MEM.SAV is used.Duplicate File (O)This option is provided to q}copy a file from one diskette to another in a single drive system. Functionally, it is very similar to the single drive Copy r}command. The primary difference is that Duplicate file can be used to copy a file created under DOS I, where as the Copy comms}and cannot.Substituting the XIO Command for DUP Menu OptionsThe XIO command in BASIC is a general I/O statement that issuet}s a direct call to the Centralized Input/Output Subsystem. The format of the XIO command is:PAGE 9-9 ABOVEement that issuem0080XIO command number, # iocb, auxialiary 1, auxialiary 2, file specification.The XIO command can be used to perform v}functions that would normally require DUP to be present. The command number for various DUP functions are shown below.COMMANw}D NUMBER FUNCTION 3 OPEN 5 GET Record 7 GET Character 9 x} PUT Record 11 PUT Character 12 CLOSE 13 STATUS request 32 y} RENAME 33 DELETE 35 LOCK File 36 UNLOCK FilePAGE 9-1O ABOVE x0080Random AccessOne common use of the diskette is to store records that may be accessed in a arbitrary order. This is{} referred to as Random Access. Using the I/O commands in conjunction with the special commands NOTE and POINT allows you to c|}reate and use random access files.DOS keeps a file pointer for each file currently OPEN which tells the DOS the location of }}the next byte to be accessed in the file. NOTE and POINT are used to find out the current value of this pointer, or to set it~} to a specific value. The file pointer has two parameters, a sector number and a byte number. The sector number is a value fr}om 1-719 that tells DOS what sector on the diskette the file pointer is pointing to. The byte number indicates the specific bˀ}yte in the sector that will be the next accessed. Figure 9-2 shows the value of the file pointer at different bytes within thˁ}e file. All values are hex. The file pointer values for the bytes in this file are given below the bytes in the file. ˂} E E E O O O ˃} A B C L D E F L G H I J K L A BFile 41 42 43 9B 44 45 46 9B 47 48 49 4A 4B ˄}9B...41 42File PointerSectorNumber 5O 5O 5O 5O 5O 5O 5O 5O 5O 5O 5O 5O 5O 5O...5O 51ByteCount O 1 ˅} 2 3 4 5 6 7 8 9 A B C D...7C OFigure 9-2 NOTE and POINT ValuesThe above file was created in BASICˆ} by the following program:1O OPEN #1,8,O,"D:FILE"2O ?#1;"ABC"3O ?#1;"DEF"4O ?#1;"GHIJK" : : :REM Fill thˇ}e rest of the sector :1OO ?#1;"AB" :REM This writes a record that crosses end of sector15O CLOSE #1The sector numberˈ} of 5O was arbitrarily chosen for this example. The sector number changed to 51 because the file is longer than a single sectˉ}or. FMS linked the file to the next available sector, 51. The record "AB" crosses the end of the first sector.PAGE 9-11 ABOˊ}VE FMS linked the file to the next available sector, 51. The record "AB" crosses the end of the first sector.PAGE 9-11 ABO0080The byte count of the file pointer starts at O and is increased until the end of the sector, $7D (125 Decimal). DOSό} reserves the last 3 bytes of every sector for overhead data for the file. The maximum byte number is 124 (O-124 = 125 total ύ}bytes). When the file reaches the end of a sector, the byte number recycles to O.When the POINT command is used to set the fώ}ile pointer, DOS checks that the sector pointed to belongs to the file that is OPENed. If a file number mismatch is found, thϏ}e POINT operation is not allowed.Figure 9-3 is a subroutine that may be used to save records, keep track of where they are, ϐ}and retrieve them in random access fashion.1OOO REM THIS ROUTINE CREATES AND ACCESSES RANDOM ACCESS FILES FOR FIXED1OO1 REMϑ} LENGTH RECORDS1OO2 REM1OO3 REM ... COMMANDS ARE1OO4 REM CMD=1 WRITE NTH RECORD1OO5 REM CMD=2 READ NTH RECORD1OO6 Rϒ}EM CMD=3 UPDATE NTH RECORD1OO7 REM1OO8 REM RECORD$ IS THE INPUT/OUTPUT RECORD1OO9 REM N IS THE RECORD NUMBER1O1O REM INDϓ}EX IS TWO DIMENIONAL ARRAY DIM'ED INDEX(1,RECNUM)1O15 INDEX HOLDS THE NOTE VALUES FOR ALL RECORDS1O2O REM THIS ROUTINE ASSUϔ}MES LOGICAL FILE #1 HAS BEEN OPENED FOR I/O11OO REM112O REM ROUTINE BEGINS AT 12OO113O REM12OO ON CMD GOTO 2OOO,3OOO,ϕ}4OOO2OOO REM ..........................21OO REM WRITE NTH RECORD22OO NOTE #1,X,Y23OO INDEX(SEC,N)=Y:INDEX(BYTE,N)=Y24OO ϖ}? #1;RECORD$:RETURN3OOO REM ..........................3O1O REM READ NTH RECORD3O2O REM3O3O X=INDEX(SEC,N):Y=INDEX(BYTE,N)ϗ}3O4O POINT #1,X,Y3O5O INPUT #1;RECORD$3O6O RETURN4OOO REM ..........................4O1O REM UPDATE NTH RECORD4O2O REMϘ}4O4O X=INDEX(SEC,N):Y=INDEX(BYTE,N)4O5O POINT #1,X,Y4O6O ? #1;RECORD$4O7O RETURNFigure 9-3 NOTE and POINT ExamplePAGE 9ϙ}-12 ABOVEEX(SEC,N):Y=INDEX(BYTE,N)4O5O POINT #1,X,Y4O6O ? #1;RECORD$4O7O RETURNFigure 9-3 NOTE and POINT ExamplePAGE 9 0080FMS Disk UtilizationThe map below shows the overall layout that DOS uses in managing disk sector utilization for aӛ} standard 72O sector diskette.+--------------+! BOOT record ! Sector 1+--------------+! FMS BOOT ! Sector 2= Ӝ}file =! 'DOS.SYS' ! Sector 4O ($28)+--------------+! DISK ! Sector 41 ($29)= Utilities =! Pacӝ}kage ! Sector 83 ($53)+--------------+! User ! Sector 84 ($54)= file =! Area !+---------Ӟ}-----+! VOLUME TABLE !! of CONTENTS ! Sector 36O ($168)+--------------+! File ! Sector 361 ($169)= Directӟ}ory =! ! Sector 368 ($17O)+--------------+! User ! Sector 369 ($171)= file =! AreaӠ} ! Sector 719 ($2CF)+--------------+! Unused ! Sector 72O ($2DO)+--------------+FMS Boot RecordThe first sӡ}ector on a diskette is reserved for FMS boot usage. This record contains information concerning the FMS system confifuration,Ӣ} as well as an indication of whether the DOS.SYS is present on the diskette or not. if the DOS files are present they usuallyӣ} begin at sector 2 and extend for 81 sectors.PAGE 9-13 ABOVEthe diskette or not. if the DOS files are present they usually?0080Volume Table of ContentsSector 36O is reserved for the FMS Volume Table of Contents (VTOC). This table contains a ץ}bit map that shows which sectors on the diskette are allocated and which are free. Since VTOC is referred to before every disצ}k write, sector 36O was chosen to hold VTOC. This sector is in the middle of the diskette and has the minimum average access ק}time of any diskette sector. The bit map begins in byte 1O of VTOC and extends to byte 99. Each byte in this area contains alר}location information for eight sectors. A O in a bit position indicates the corresponding sector is in use, and a 1 indicatesש} it is available. The volume bit map is organized as shown below: 7 O+-+-+-+-+-+-+-+-+! 1 2 3 4 5 6 7! Byte ת}1O of VTOC+-+-+-+-+-+-+-+-+ 11!8 9 . . . . . .!= =! ! 99+-+-+-+-+-+-+-+-+File D׫}irectory FormatEight sectors (361-368) are reserved for a diskette file directory, with each sector able to store informatio׬}n for up to eight files. Thus, the maximum number of files that can be placed on a single diskette is 64.Each file directory׭} entry consists of 16 bytes. The format of each entry is shown on the next page.PAGE 9-14 ABOVE is 64.Each file directoryb0080+---------------+! flag byte ! Byte O+---------------+! sector (lo) ! 1+ +! count ۯ} (hi) ! 2+---------------+! starting (lo) ! 3+ sector +! number (hi) ! 4+---------------+! ۰} (1) ! 5+ +! (2) ! 6+ +! (3) ! 7+ ۱} +! file (4) ! 8+ +! name (5) ! 9+ +! primary (6) ! 1O+ ۲} +! (7) ! 11+ +! (8) ! 12+---------------+! file (1) ! ۳} 13+ +! name (2) ! 14+ +! extension (3) ! 15+---------------+The flag byt۴}e has the following bit assignments:Bit-7 = if the file has been deleted.Bit-6 = if the file is in use.Bit-5 = if the file۵} is locked.Bit-O = if OPEN for output.PAGE 9-15 ABOVEhas been deleted.Bit-6 = if the file is in use.Bit-5 = if the file90080FMS File Sector FormatThe format of a sector in a diskette file is shown below: 7 O+-+-+-+-+-+-+-+-+߷}! ! Byte O= D A T A =! ! 124+-+-+-+-+-+-+-+-+! file # 1 hi! 125+-+-+-߸}+-+-+-+-+-+!forward pointer! 126+-+-+-+-+-+-+-+-+!SI byte count ! 127+-+-+-+-+-+-+-+-+The file # is informa߹}tion that FMS uses to ensure file integrity is maintained. This field contains the value of the directory position for that fߺ}ile. If there is ever a mismatch between the file's position in the directory and the file number field in a sector, the FMS ߻}will generate an error, and abort whichever operation was being performed.The forward pointer is a 1O-bit pointer that indic߼}ates the next sector in a file. This is described as a forward linked list, with the forward pointer of the last sector equal߽} to O.If the S bit is set (i.e., equal to 1), then the sector is a "short sector" and contains less than 125 data bytes.The߾} byte count field contains the number of bytes in the sector.PAGE 9-16 ABOVEor" and contains less than 125 data bytes.TheO0080THE AUTORUN.SYS FILEDOS contains a feature that allows a special file to be loaded into memory each time the syste}m is powered-up. This can be data to customize features of the system such as setting up different margin values, or changing} the default colors. If desired this can be a machine language program to be executed before the normal DOS boot process occu}rs.This file must be a binary load file with the name AUTORUN.SYS. To make this an executable file, an address value must be} loaded into the INIT [$O2EO,2] or the RUN [$O2E2,2] locations. The difference between these two parameters is that the code }pointed to by INIT will be executed as soon as that location is loaded, whereas code pointed to by RUN will only be executed }after the load process is complete. To return control to DOS after ececuting an AUTORUN.SYS file, terminate your code with an} RTS.The AUTORUN.SYS file can be extremely useful in setting up "load-and-go" assembly language routines. It also provides a} method of reconfiguring the OS by "stealing" certain of the system vectors before DOS has a chance to be initialized. Among }other things, this feature can be used to provide a certain measure of diskette protection. Refer to Figure 8-3 for an exampl}e of setting up an AUTORUN.SYS file to reset the MEMLO pointer.PAGE 9-17 ABOVErotection. Refer to Figure 8-3 for an examplQ00801OATARI BASICWHAT IS ATARI BASIC ?ATARI BASIC is an interpreted language. This means programs can be run when }they are entered without intermediate stages of compilation and linking. The ATARI BASIC interpreter resides in an 8K rom car}tridge in the left slot of the computer. It encompasses addresses AOOO through BFFF. At least 8K of ram is required to run BA}SIC.To use ATARI BASIC effectively, you must know its strengths and weaknesses. With this information, programs can be writt}en that make good use of the assets and features of ATARI BASIC.Strengths of ATARI BASIC1. It supports the operating system} graphics - Simple graphics calls can be made to display information on the screen.2. It supports the hardware - Such calls }as SOUND, STICK and PADDLE are simple interfaces to the hardware of the computer.3. Simple asembly interface - The USR funct}ion allows easy user access to assembly language routines.4. ROM based interpreter - The BASIC interpreter is in ROM, which }prevents accidental modification by the user program.5. DOS support - Specialized calls such as NOTE and POINT (DOS 2.OS) al}low the user to randomly access a disk through the disk operating system.6. Peripheral support - Any peripheral recognized b}y the operating system can be accessed from a BASIC program.Weaknesses of ATARI BASIC1. No support of integers - All number}s are stored as 6-byte BCB floating point numbers.2. Slow math package - Since all numbers are six bytes long, math operatio}ns become rather slow.3. No string arrays - Only one-dimensional strings can be created.PAGE 1O-1 ABOVEong, math operatiok0080HOW ATARI BASIC WORKSThe workings of the BASIC interpreter are summarized as follows:1. BASIC gets a line of inpu}t from the user and converts it into a tokenized form.2. It then puts this line into a token program.3. This program is the}n executed.The details of these operations are discussed in the following four sections1. The Tokenizing Process2. The Tok}en File Structure3. The program Execution Process4. System InteractionPAGE 1O-2 ABOVE. The Tokenizing Process2. The TokZ0080THE TOKENIZING PROCESSIn simple terms, the tokenization of a line of code in BASIC looks like this:1. BASIC gets }a line of input2. It then checks for legal syntax3. During syntax checking it is tokenized4. The tokenized line is moved i}nto the token program5. If the line is in immediate mode it is executedTo better understand the tokenizing process, some te}rms must first be defined:Token: An 8-bit byte containing a particular interpretable code.Statement: A complete "sent}ence" of tokens that causes BASIC to perform some meaningful task. In LIST form, statements are seperated by colons.Line: } One or more statements preceded either by a line number in the range of O to 32767 or an immediate mode line with no numb}er.Command: The first executable token of a statement that tells BASIC to interpret the tokens that follow in a particula}r way.Variable: A token that is an indirect pointer to its actual value; thus the value can be changed without changing th}e token.Constant: A 6-byte BCD value preceeded by a special token. This value remains unchanged throughout program executi}on.Operator: Any one of 46 tokens that in some way move or modify the values that follow them.Function: A token that wh}en executed returns a value to the program.EOL: End of Line. A character with the value 9B hex.BCD: Binary co}de decimal. A number that uses the 65O2 decimal mode.BASIC begins the tokenizing process by getting a line of input. This in}put will be obtained from one of the handlers of the operating system. Normally it is from the screen editor; however with th}e ENTER command, any device can be specified. The call BASIC issues is a GET RECORD command, and the data returned is ATASCII} information terminated by an EOL. This data is stored by CIO into the BASIC Input Line Buffer from 58O to 5FF hex.PAGE 1O-}3 ABOVEtion terminated by an EOL. This data is stored by CIO into the BASIC Input Line Buffer from 58O to 5FF hex.PAGE 1O-0080After the record is returned, the syntax checking and tokenizing processes begin. First BASIC looks for a line numb}er. If one is found, it is converted into a 2-byte integer. If no line number is present, it is assumed to be in immediate mo}de and the line number 8OOO hex is assigned to it. These will be the first two tokens of the tokenized line. This line is bui}lt in the token output buffer that is 256 bytes long and resides at the end of the reserved operating system RAM.The next to}ken is a dummy byte reserved for the byte count (or offset) from the start of this line to the start of the next line. Follow}ing that is another dummy byte for the count of the start of this line to the start of the next statement. These values will }be set when tokenization is complete for the line and the statement respectively. The use of these values is discussed in the} program execution process section.BASIC now looks for the command of the first statement of the input line. A check is made} to determine if this is a valid command by scanning a list of legal commands in ROM. If a match is found, then the next byte} in the token line becomes the number of the entry in the ROM list that matched. If no match is found, a syntax error token i}s assigned to that byte and BASIC stops tokenizing, copies the rest of the input buffer in ATASCII format to the token output} buffer, and prints the error line.Assuming a good line, one of seven items can follow the command: a variable, a constant, }an operator, a function, a double quote, another statement, or an EOL. BASIC tests if the next input character is numeric. If} not then it compares that character and those following against the entries of the variable name table. If this is the first} line of code entered in the program then no match is found. The characters are then compared against the function and operat}or tables. If no match is found there then BASIC assumes that this is a new variable name. Since this is the first variable i}t is assigned the first entry in the variable name table. The characters are copied out of the input buffer and stored into t}he name table with the most significant bit (MSB) set on the last byte of the name. Eight bytes are then reserved in the vari}able value table for this entry. (See the variable value table discussion in the section, "Token File Structure".)The token }that ends up in the tokenized line is the variable number minus one, with the MSB set. Thus the token of the first variable e}ntered would be 8O Hex, the second would be 81, and so on up to FF for a total of 128 unique variable numbers.If a function }