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ƨ&P V$0BWufJK7 uf.!(%`z yseGUZm}|.tQTUFdm#JX:sA87&:OP(BWFU뾁s ݡոGi0C bYT͕=QK&Q0LXUGګ!v >׾\={cn}mF"P!%FݲaeTna|s6m<ЉU *UE~k4N3np*=i#z ] CPA:L:ڒeg=) _Do}Y# j$0܁!dhN#180#zEv7&< dd Am^CD yb]Nq^F2\d5>PK)騻 4c(>B& B:#p}]`mKľ$ȯ[LY)(I˪F,uw}8Xtr$0{jd6xo>F. _+4uek8T 1=t`8 frČYԝNnnDGbI ΰ$AՊ6?at,v_7Bza,x}lHg_~xw1:4"$y-~ A,"h&u-4uL:T?:`$ ?ԝ꽳zhGvhIG=y} !ԯ7\gٰ StmCd B轮2tY@,ӬH^ZV-> Q@@ &c&ظ!6#F0ha%8oe@=rŲ4G z}vS0i! RDSXe|(eI&\1f6"-1'%KDV#-s g@T#5R3> Y@0P'ӃEDAy '6o>{}g+0s=2% )1]''*bB/2]29I.zBvh'2h4eSu 5S;fW|x*-@b- README.TXT2*3(@|} -TA : h!4i怈2  b Cd"ґFL:i:xcĐ!6jq9oƤ!Y:f̸`M03 )O\y27r&9)%<#}}3G)IfiCSҸ"F6PyBΛ:YT 6oD4a` Yƍ4x` !iT3N[G2DQ&c4Ʃ0m6* C,[tLϮ~})AsGx3 ۙb4Lyts,F"4k` NTQs VE5frqփAe9uFlUxqF<^eD^恠 aNUdZsF}zX0(&)wO L\a"*D!1WWK;:uYf}]FXbd4TexCtIfC~&_M6T CDefine or reference a global symbol.used as:.globlfoo.wordGener}ate one or more 16-bit values.Values can be constants, expressions,symbol references etc. Values areseparated} by commas..byteGenerate one or more 8-bit values.Similar to above..blkbnGenerate n bytes of empty s}pace.=Set the value of a symbol. Used as:foo = 3[There's more; finish later]Command lines:Like all the me}mbers of the CC65 family, RA65 can either grok commandlines as used by Spartados and DOS XL, or prompt for its command line.}If no command line is given, or you're running something that doesn'tdo command lines, RA65 will prompt, asRA65>You're }then expected to type in the rest of the command line. Ex:under Spartados, if you typedRA65 -v foo.m65you get the same }effect under DOS 2.5 by starting up RA65, then at theRA65> prompt, typing-v foo.m65dRA65 -v foo.m65you get the same X-*- text -*-Internals doc for the CC65 environment.This is a somewhat cryptic, but hopefully informative description of }how things work in the CC65 runtime environment. You shouldunderstand this stuff if you want to write something to interfa }ce toCC65-generated code; you shouldn't need to understand it otherwise.The runtime model:Stacks:The program stack use }d by programs compiled with CC65 is located inhigh memory, typically #xBC00 or so. The virtual stack pointer (whichshould }not be confused with the 6502's stack pointer) is initializedby the canned startup code to point just below HIMEM (#x2E5). }Thestack starts there and grows down. Arguments to functions, local dataetc are allocated on this stack, and deallocated w }hen functions exit. The virtual stack pointer is kept in page 0 location #x80. Allpushing and popping of things on/off th }e stack is done with subroutinecalls to library routines (PUSHAX and POPAX), which adjust the stackpointer as appropriate. }[There are a bunch of other things defined in page 0 that are used bythe runtime library; see global.m65]Registers:Sin!+}-*- Mode: Text -*- This is the copyright notice for RA65, LINK65, LIBR65, and other Atari 8-bit programs. Said progra}ms are Copyright 1989, by John R. Dunning. All rights reserved, with the following exceptions: Anyone may copy or re}distribute these programs, provided that: 1: You don't charge anything for the copy. It is permissable to charge a} nominal fee for media, etc. 2: All source code and documentation for the programs is made available as part of the }distribution. 3: This copyright notice is preserved verbatim, and included in the distribution. You are allo}wed to modify these programs, and redistribute the modified versions, provided that the modifications are clearly noted. } There is NO WARRANTY with this software, it comes as is, and is distributed in the hope that it may be useful. T}his copyright notice applies to any program which contains this text, or the refers to this file. This copyright noti}ce is based on the one published by the Free Software Foundation, sometimes known as the GNU project. The idea is the same} as theirs, ie the software is free, and is intended to stay that way. Everybody has the right to copy, modify, and re- di}stribute this software. Nobody has the right to prevent anyone else from copying, modifying or redistributing it. re- diu-*- Text -*-Relocatable object file format:Header: #xFDFD identifies this as a relocatable obj file.Nbytes symbol: } word. Nbytes of symbol table. Includes 'nsymbols'.Nbytes segment: word. N bytes this segment uses.Nbytes data: w }ord. N bytes in segment data this object file.Nsymbols: word. N symbol structs following.Symtab: some number of sym }bol structs. Each one looks like: namelen:bytelength of namestring value:wordsymbol value flags:wordflag b }its this sym, one of:abs:value absoluterel:value relative to start of moduleData: a bunch of op bytes, followed } by data per op. ops:lit|0.0.0.n.n.n.n.n|n literal bytes follow.rel|0.0.1.0.0.0.0.0|generate the following w }ord offset by the start addressof this segmentrel-hi|0.0.1.0.0.0.0.1|generate a byte, the high half of the followin }gword, offset by segment baserel-lo|0.0.1.0.0.0.1.0|generate a byte, the low half of the followingword, offset b }y segment basesym|0.1.s.n.n.n.n.n|if s is clear, sym number is nnnnn, if set, nnnnn is top5 bits, next byte is bott }om 8.followed by a word. Generate the following wordoffset by the value of symbol n.sym-hi|1.0.s.n.n.n.n.n|Same } as above, but generate hi byte of resultant valuesym-lo|1.1.s.n.n.n.n.n|Same, but generate lo byte.n.n.n.n|Same m-*- Text -*-Libr-65 preliminary doc Libr65 is the object library maintenance utility part of the CC65package. Its} mission in life is to build, maintain, list etclibraries of object modules. Object libraries are useful when building th}ings like C programs, asthere are all kinds of functions that want to be optionally linked in,and keeping track of them all} by hand is too big a pain to beworthwhile. See the LINK65 doc for a [brief] explanation of how thelinker uses object file}s and libraries. Libr65 expects a command line containing a command, the name of alibrary file, and sometimes names of obj}ect files. Libr65 commands:AAdd file(s) to library, replacing any old members with the same name.DDelete member}(s) from libraryLList library contentsVPrint Libr65 version.As with all the other programs in the CC65 family, case} doesn'tmatter; 'a' is treated the same as 'A'. Example command lines:Libr65 a c.olb foo.obj... adds or replaces FOO.}OBJ in C.OLBLibr65 l c.olb... lists what's in c.olbOn DOS's that don't hack command lines, just start it up and it wil}lprompt, as LIBR65>then just type in the rest of the command.t don't hack command lines, just start it up and it wilF i = baz(i, c); generates this assembler code. I've added the comments. lda _i ; get 'i', low byte ldx _i+1 ; }get 'i', hi byte jsr pushax ; push it lda _c ; get 'c' ldx #0 ; fill hi byte with 0 jsr pushax ; push it ldy #2 } ; arg count jsr _baz ; call the function sta _i ; store the result stx _i+1 Note that the two words of arguments } to baz were popped before it exitted. The way baz could tell how much to pop was by the argument count in Y at call time. } Thus, even if baz had been called with 3 args instead of the 2 it was expecting, that would not cause stack corruption. } There's another tricky part about all this, though. Note that the args to baz are pushed in FORWARD order, ie the order } they appear in the C statement. That means that if you call a function with a different number of args than it was expect }ing, they wont end up in the right places, ie if you call baz, as above, with 3 args, it'll operate on the LAST two, not th }e first two. Symbols: CC65 does the usual trick of prepending an underbar ('_') to symbol names when compiling them in }to assembler. Therefore if you have a C function named 'bar', CC65 will define and refer to it as '_bar'. Note! One way i }n which the CC65 environment deviates from normal C environments is that all symbol names are upper-cased by the assembler. } This behaviour is often the right thing for assembly-language programming, but not at all the right thing for C programs. }It was originally intended that this behaviour be switchable, but I never got around to implementing it. Stack layout: } Suppose you've got a function that looks like this: foobar(i, j) int i, j; { int k; char ch; char vec[10]; } } The stack layout when running the body of this function will be as follows: Each line is a byte. ^ + }-------+ | | ... | higher | i^ | high byte of 'i' | i\ | low byte of 'i' | j^ | high byte of 'j' | j\ | lo }w byte of 'j' | argc^ | arg count for | argc\ | this function (typically 2, in this example) | k^ | high byte of }'k' | k\ | low byte of 'k' | ch | ch | vec[9]| last byte of 'vec' lower .... | | vec[0]| first (zeroth) byte }of 'vec' v +-------+ The virtual stack pointer SP (#x80) will be pointing at the 'top' (lowest address) of the stack, }ie at vec[0] in this example. Locals are allocated on the stack in order of appearance; most recently mentioned ones are }nearest the top of stack. Note that args are always passed as 16 bits; if i and j in that example were chars, the stack w }ould look the same. The arg count is used by the runtime code that maintains stack frames, to know how much stuff to pop }when exiting a function. DON'T BASH IT, or all kinds of hell will break loose. You can, however, use it to compute where }args are on the stack, in the case of functions with variable numbers of args. For instance: this is the source to the li }brary routine fprintf. fprintf(argc) int argc; { int dummy[1]; int * nxtarg; nxtarg = &argc + dummy[1] - 1; } return(_pfguts(*nxtarg, --nxtarg)); } The trick there is the reference to dummy[1]. Since dummy's only one long, tha }t picks the word after dummy, ie the real arg count. nxtarg then becomes the address of the real first arg. Arg counts a }re expected to show up in the Y register at function entry. Routines that are hand-coded in assembly language can just use } that directly, rather than go thru the C function entry protocol. Storage layout: Nothing suprising here. Ints and }pointers are 16 bits, chars are 8. The standard 6502 low/high order is used for everything. Data declarations are mixed w }ith the code, as there's no reason to put it in any particular place on a 6502. [What else?] The most effective wa }y to get familiar with how this all works is probably to just dive in and start compiling things, and see what gets generat }ed. amiliar with how this all works is probably to just dive in and start compiling things, and see what gets generat 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 SPIDERS G) *Gȩ GȽG GȌ*jj >G} then just type in the rest of the command. hack cw-*- Text -*- Link-65 preliminary doc. Link-65 is a linker for relocatable object modules. It inputs object fil}es and outputs an executable image. Link-65 accepts as input a series of names and switches. Valid switches: -O S}pecify output file, as "-O FOO.COM". -B Specify exec base address, as -B2800. Number is a hex constant. Default valu}e is #x2000. -M Write a map file. A bunch of information gets dumped to the map, like how big each oject module } ended up in the executable, and what addresses of global symbols etc. The name of the map file is the name of the ou}tput file, with the extension .MAP, ie "-M -O FOO.COM" will output the executable in FOO.COM, and the map in FOO.MAP. } -V Verbose. Turns on printing of various debug info while the link proceeds. Anything that's not a switch is expect}ed to be a file name. All files are linked together to produce the executable. Ex: You could say something like: LINK}65 -m -o foo.com start.obj foo.obj to link START.OBJ and FOO.OBJ together to form FOO.COM, and write the linker map to FO}O.MAP. Link-65 knows how to search object libraries (.OLB files) to resolve references to undefined symbols. This is esp}ecially useful when linking C programs, as they'll typically reference all kinds of canned library routines. Libraries are} specified as files like anything else. Ex: LINK65 -o hello.com runtime.obj hello.obj c.olb Runtime.obj is the C star}tup/runtime module, hello.obj is the main program, and c.olb is the C library. If a filespec contains a leading at-sign (}'@') it is interpreted as an indirect command file. That means it's expected to contain a list of names of the files that }are really supposed to be linked. Using this scheme, the above example would look like this: LINK65 -o hello.com @hello.}lnk where hello.lnk contains the following 3 lines: runtime.obj hello.obj c.olb Case does not matter in command }line args; ie -v is equivalent to -V. As usual, Link-65 will prompt for a command line if there isn't one, either because y}ou didn't type it, or 'cause you're running on some system that doesn't do command lines, like DOS 2.5. ither because yn-*- Text -*- Relocatable object file format: Header: #xFDFD identifies this as a relocatable obj file. Nbytes  }symbol: word. Nbytes of symbol table. Includes 'nsymbols'. Nbytes segment: word. N bytes this segment uses. Nb!}ytes data: word. N bytes in segment data this object file. Nsymbols: word. N symbol structs following. Symtab: "} some number of symbol structs. Each one looks like: namelen: byte length of namestring value: word symbol value#} flags: word flag bits this sym, one of: abs: value absolute rel: value relative to start of module Data: $}a bunch of op bytes, followed by data per op. ops: lit |0.0.0.n.n.n.n.n| n literal bytes follow. rel |0.0.1.0%}.0.0.0.0| generate the following word offset by the start address of this segment rel-hi |0.0.1.0.0.0.0.1| gener&}ate a byte, the high half of the following word, offset by segment base rel-lo |0.0.1.0.0.0.1.0| generate a byte, t'}he low half of the following word, offset by segment base sym |0.1.s.n.n.n.n.n| if s is clear, sym number is nnnnn,(} if set, nnnnn is top 5 bits, next byte is bottom 8. followed by a word. Generate the following word offset by the )}value of symbol n. sym-hi |1.0.s.n.n.n.n.n| Same as above, but generate hi byte of resultant value sym-lo |1.1.s.n*}.n.n.n.n| Same, but generate lo byte n| Same as above, but generate hi byte of resultant value sym-lo |1.1.s.n-ce CC65 is a member of the Small-C family of compilers, it uses thenotion of a 'primary register'. In the Atari implementat!,}ion, I usedthe AX register pair as the primary register. Just about everythinginteresting that the library code does is do!-}ne by somehow getting avalue into AX, and then calling some routine or other. In placeswhere Small-C would use a secondary!.} register, top-of-stack is used, sofor instance two argument function like integer-multiply work byloading AX, pushing it o!/}n the stack, loading the second value, andcalling the internal function. The stack is popped, and the resultcomes back in !0}AX.Calling sequences:C functions are called by pushing their args on the stack, and JSR'ingto the entry point. (See ex !1}1, below) If the function returns avalue, it comes back in AX. NOTE!!! A potentially significantdifference between the CC!2}65 environment and other C environments isthat the CALLEE pops arguments, not the CALLER. (This is done so asto generate m!3}ore compact code) In normal use, this doesn't cause anyproblems, as the normal function entry/exit conventions take care of!4}popping the right number of things off the stack, but you may have toworry about it when doing things like writing hand-cod!5}ed assemblylanguage routines that take variable numbers of arguments. More aboutthat later.Ex 1: Function call: Assumi!6}ng 'i' declared int and 'c' declaredchar, the following C codei = baz(i, c);generates this assembler code. I've ad!7}ded the comments.lda_i; get 'i', low byteldx_i+1; get 'i', hi bytejsrpushax; push itlda_c; get 'c'ldx!8}#0; fill hi byte with 0jsrpushax; push itldy#2; arg countjsr_baz; call the functionsta_i; store the re!9}sultstx_i+1Note that the two words of arguments to baz were popped before itexitted. The way baz could tell how much t!:}o pop was by the argumentcount in Y at call time. Thus, even if baz had been called with 3args instead of the 2 it was exp!;}ecting, that would not cause stackcorruption. There's another tricky part about all this, though. Note that theargs to !<}baz are pushed in FORWARD order, ie the order they appear inthe C statement. That means that if you call a function with a!=}different number of args than it was expecting, they wont end up inthe right places, ie if you call baz, as above, with 3 ar!>}gs, it'lloperate on the LAST two, not the first two.Symbols:CC65 does the usual trick of prepending an underbar ('_') to!?} symbolnames when compiling them into assembler. Therefore if you have a Cfunction named 'bar', CC65 will define and refer!@} to it as '_bar'.Note! One way in which the CC65 environment deviates from normal Cenvironments is that all symbol names a!A}re upper-cased by the assembler.This behaviour is often the right thing for assembly-languageprogramming, but not at all th!B}e right thing for C programs. It wasoriginally intended that this behaviour be switchable, but I nevergot around to implem!C}enting it.Stack layout:Suppose you've got a function that looks like this:foobar(i, j)int i, j;{ int k; char ch;!D} char vec[10]; }The stack layout when running the body of this function will be asfollows: Each line is a by!E}te. ^+-------+ || ...|higher| i^|high byte of 'i'| i\|low byte of 'i'| j^|high byte of 'j'| j\!F}|low byte of 'j'| argc^|arg count for | argc\| this function (typically 2, in this example)| k^|high byte o!G}f 'k'| k\|low byte of 'k'| ch|ch| vec[9]|last byte of 'vec'lower .... || vec[0]|first (zeroth) byte of !H}'vec' v+-------+The virtual stack pointer SP (#x80) will be pointing at the 'top'(lowest address) of the stack, ie at v!I}ec[0] in this example.Locals are allocated on the stack in order of appearance; mostrecently mentioned ones are nearest th!J}e top of stack.Note that args are always passed as 16 bits; if i and j in thatexample were chars, the stack would look the!K} same.The arg count is used by the runtime code that maintains stack frames,to know how much stuff to pop when exiting a f!L}unction. DON'T BASH IT,or all kinds of hell will break loose. You can, however, use it tocompute where args are on the st!M}ack, in the case of functions withvariable numbers of args. For instance: this is the source to thelibrary routine fprint!N}f.fprintf(argc)int argc; { int dummy[1]; int * nxtarg; nxtarg = &argc + dummy[1] - 1; return(_pfguts(*nxtarg, --!O}nxtarg));}The trick there is the reference to dummy[1]. Since dummy's only onelong, that picks the word after dummy, ie "}-*- Text -*- This is the second betatest distribution of CC65 and associated stuff. Please see INTRO.DOC for instructions%Q} on getting started. Since the last go-round, the following bugs have been fixed: o The low-level file-open code now u%R}pcases the filename before attempting to open it. This should fix the lossage observed on systems like DOS 2.5 that %S}treat lowercase characters as illegal. o The command-line parser should now be able to recognize DOS XL command l%T}ines, as well as SpartaDos. As before, all executables have their base address set to #x2000, with the exeception of CC65%U}.COM, which starts at #x2600. Please let me know if you run into memory problems; I suspect I can get another half K out o%V}f CC65 before running into stack problems. All text files are in ATASCII except the ones in DOC.ARC, which are in mushy-%W}dos format, ie CRLF as line delimiters. Since I've been remiss in writing the doc for the library routines etc, I've inc%X}luded the library source. You shouldn't have to rebuild it, but it may be useful for reference. If anyone feels inclined t%Y}o write part of the doc for me, don't let me stop you! BTW when I built LIBSRC.ARC I wasn't very selective, I just grabbed%Z} eveything out of my current development directory that looked relevant. There are probably some duplicates and extra file%[}s in there, esp since many of the routines were originally in C, then later hand-coded in assembler. Caveat emptor. Plea%\}se let me know how this stuff works for you. I'd like to declare it done and post it for real. . Caveat emptor. Plea$d-*- Text -*-Getting started using CC65.CC65, RA65, LINK65, and LIBR65, along with the assorted runtimelibraries and t)^}hings, comprise everything you should need to compileand run C programs on your Atari 8-bit computer.Basically, the sequen)_}ce of things you do to compile a and run a Cprogram is as follows:1: Use CC65 to compile your C source into assembler lan)`}guage2: Use RA65 assemble the results into an object file3: Use LINK65 to link your object file with the C runtime stuff,)a} to produce an executable.In the CC65 distribution, you should find the canonical test program,hello.c. You should al)b}so find the C runtime stuff, runtime.obj andc.olb. Here's what you do to compile up hello.c and run it.Put hello.c, runti)c}me.obj, and c.olb on drive 1 of your system, or, ifyou're using something like Spartados that supports default devices,put )d}those files on whatever device you're using as a default.Run CC65.COM. When it starts, it will prompt with CC65>. Type th)e}e line-V HELLO.Cat the prompt and hit return.CC65 will compile hello.c, producing hello.m65.Run RA65.COM. When it st)f}arts, it will prompt with RA65>. Type the lineHELLO.M65at the prompt and hit return.RA65 will assemble hello.m65, prod)g}ucing hello.obj. At this point youcan delete hello.m65 if you want.Run LINK65.COM. When it starts, it will prompt with L)q}?BDOC ARCB$RA65 DOCB COPYLEFTJRDB OBJ DOCB%DOS SYS LIBR65 DOCB LINK65 DOCB LIBR65 DOCB4INTERNALDOCB PREADME TXTB]INTRO DOCB*DUP SYSB,A2AT COMB-CC65 DOCINK65>. Type the line-O HELLO.COM RUNTIME.OBJ HELLO.OBJ C.OLBat the prompt and hit return.Link65 will link hello.obj w)r}ith the C runtime stuff, and produce anexecutable program called hello.com.You're done! You can now run hello.com, to see)s} the canonical message.The procedures for building bigger programs are much the same. Ifyou've got multiple source files,)t} you'll compile and assemble each ofthem separately, then feed all of them to LINK65, where you typedHELLO.OBJ in the examp)u}le above. See the link65.doc for more details.tely, then feed all of them to LINK65, where you typedHELLO.OBJ in the examp(0G  L }`8L`Lp8`  04}G)݁,G)ȱGȱGw}Hh0})Hh` B! 8`8ii(ZE6!JS Sd!  E  ` Tx}E 8  8LFEh   r9L )  EiFi(LdEE` dE`H)y}h/H^ji hEEdEiEȱEiE` WE QEEHI8 *hd ) z}8EEȱEEE` I !ʽ)E1F5I!  !ȘJHjm9Ghm:H`  {}!`GHLl Z dLȩ8 lI0 ` _} ; $ %  pLl`|}ݚ I(`DOS SYShChDC IC`0I B0x D)D`}Need DOS2.5,type Y }}Λ@@ "\DOS SYSCOPY3TO2COM/~}B}~B}}BDOC ARCB-CC65 DOCB COPYLEFTJRDB6INTERNALDOCCDOS SYSB LIBR65 DOCB LINK65 DOCB OBJ } DOC C C*(> 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 E} 3E:}DOS 2.5 - SPIDERS COMPANY:GAY LIPSON AARON MILLER,GUPPY SHCHR A. DISK DIRECTORY I. FORMAT 1050B. RUN CARTRIDG-}E J. DUPLICATE DISKC. COPY FILE K. BINARY SAVED. DELETE FILE(S) L. BINARY LOADE. RENAME FILE M. RUN AT ADDRES-}SF. LOCK FILE N. CREATE MEM.SAVG. UNLOCK FILE O. DUPLICATE FILEH. WRITE DOS FILES P. FORMAT 810 L !N'-}#"&))9(&*)/h)''-&؆莟R'S  vL/ˢ L }Insert DOS 2.0s, type Y Λx -}DEfHI 1莏#q! @ y0ɛ8A0,' ȅ 1 1ild! 1L!NO SUCH ITEMSELECT-} ITEM OR FOR MENU! 0 .z:*{}.|{ 1 0 0JB 18L%|DL-}%DIRECTORY--SEARCH SPEC,LIST FILE?[# 0 0 &|D3" 1L!NOT A DISK FILEN !B 1L!E# 1 !BD-}ED:}:1BJ|DE 1DEBHI 1 h0ߢ 0.-}  0?詛 1 y0YЛ 1 ;#L" ;#L! BL1TYPE "Y" TO DELETE...DELETE FILE SPEC-}COPY--FROM, TO?OPTION NOT ALLOWED133 FREE SECTORS COPYING---D2:ITDESHO.130l# 0|D .L/%#-}##JB|DE 1BHID#E 1#0: B 1L!#͑### B 1#c$0SY-}S1}:## # # .#Ƚ# # 𩛙## 1,#PD#ELJ- <.BJD#E -}1 1HH 0hh|DL%1}:̳# L% #D#EL% 1 0 . .0O% 1L!WILD CARDS NOT A-}LLOWED IN DESTINATION 0 <.|K7ł86/ 䃐-&ł'% 0ł 1}䃐 ł`` 0ł 䃐ł۰ 0łʰ 䃐ł𹰼 L H hL1} lHh` {!L !L hh捠ilŕŔ liL1}#`L!  ! Ɣ !$ D$& $ D$& 򦓥 !`Heeh`` 1} ! ! ! !Ńł &&L$FfFf3ōŌ8包卅1}FfFfͥ !ĕ !` \$L! ` `1}S L L L i?H ihL%  (l 1} S# 7   "+  t! A" {! 9!%  %L`&'  t)%  ( " 1} %% 9! %  i0% 9! '  . 9! "'' ..  t) .  %¢% 1}%  %¢% .  . 9! u ! !¢% ¢%  5% A" 9! (  %¢% (  . 9!  1}. 9! "P u L'  . 9!L' 9!L'L' #g' q' }'   ].LD'  -  -% 1} /¢% %  /  LY#A2AT>rCan't open '%s' error %x.tmpw S# a  9! . 9! "L(LA(L"( 1}~ "9 "(~ ..  ]. u #  9! #L( ..  ].  u A"  u `! u #  9! 1}#L>(  u A" `!  5% # LY# S# ((  3 ((  %LY# S# a    t! A" {! t! A" 1}  t! P" 9! u # u  9!  ) # LY# S# M ..    t! A" {! t! A"  t! P"  )  LY# S#1}# 7  9!% u # % 9! # {! 9! u !L- u #% "3 u #  9! # #)  ]. u  9!L)LE* 1}u  9! u #% "0 u #  9! # #)  ]. u  9!L) u #- " 9! u  9!L* 91}! u #0 " 0 9!L*  9! u # 3B u #  9! #  1 9! u # 3 u  9!L+L9+1} 9! u #. "< u  9!  1 9! u # 3 u  9!Ld+L+ 9!% u # % 9! # {!! 9!  1}9! u #  9! # # 4L, # u `!  A" `!L,! u  9!L,!   O3L,!    1L1},!    1L,!   1L,!    1L, u #  LY#L, #+c+s,d,b0,oI,ub,x1}L{,  5% 9! u   u " !  u  9!  u "  u P" 9!L- 9! u ! !7 u #1}  9! # ! )  ]. u  9!L!- u #  9! # !0 u #  9! # #)  ]. u  9!LX- u 1}7 u #  9! # ! )  ]. u  9!L-L) u #  LY# A# :3 #L. u LY# E# M   u1} # / 9! " u ..  LY# u  LY# HHIDE Bh VL/` `Œ1} eL!L. .`%H$H` HIDEB VL/``@ iɀ` .01}krwa dKJKHI)a0{8 驛DEB VL/``..` S#1}P 7 R   i0 Ԣ/  2  3P  LY# S#R 7 V   i0 e0  2T :  . 9!1} u 9!L30T u 9!   2 g0  2  2R  LY#, S#P 7 V :  . !2 0 1} % X  2R   %L0R X  %T u !%R .  . !R V  2P  LY#D: A# a  u # 1}4 u  9!L1 9! u !LR1 9! u  9!L_1 #91-B1+ 9! u # 3=  u #  u 1}#  9! # ! A" 0 P" 9!Lh1  u # # LY# I# a  u  9!  " 9!  " 9!  "  1}" 9! u %  !  u A" `! u # " u #0 A" `!Lz2 u #7 A" `! u  9!1}  u \$ 9! !L1 `! '4 # LY# E#  5% A"  %LY# .2 2DE BJK VL1}/` . 3 3DE!BJK VL/` B V0`` Ԇ !Ԇթ- ؠ01}L|3)ȑ` 0:`` NHɛD 4ȥi揠 4H1}hɛ`!8`` A[i ` A# a   5% A"  P" 9!  u "O u ! 9! u #  9! # 1}  u ! `! u #  9! #  u `!LL4 # LY# A# ": "" " #1}LY# `! u #  9! #  u `!LL4 # LY# A# ": "" " #0 -*- Text -*-CC65 preliminary doc CC65 is a PD C compiler for Atari 8-bit computers.Using it:Essentially, all yo5}u do to use CC65 is start it up and hand it a filename to compile. This can be done either on a command line, or bytyping 5}it in at the prompt after CC65 starts up.Input files are assumed to be C source. Extension .C is assumed ifnot specified.5}Include files are currently assumed to be on the same drive as the Csource file. [If anyone can think of a better way to 5}do this, pleasetell me]Switches:-vVerbose. -v once means print function names asthey're encountered. Twice prints5} source linesas they're read.-dDebug. Turns on various debugging code.CC65 processes a source file and produces a 5}file with the same name,and extension .M65, ie if you compile foo.c, you'll get foo.m65. Theassembler language produced is5} suitable for feeding to RA65, althoughyou could probably get it to work by defining a couple of macros usingsomething like5} MAC/65.What it understands:CC65 understands the following primitive datatypes:char8 bitsint16 bitsshort16 bit5}slong16 bits(sorry)floats are not supported, though they probably could be without toomuch effort. Structs and unio5}ns, arrays, and pointers are all supported in theusual fashion (at least I think it's the usual fashion; I'm not a Cweenie 5}by trade, and I didn't have the stomach to research it indetail)You may have structs containing pointers, pointers to poin5}ters,pointers to structs, etc, etc, ie all the things that other Small-Cvariants don't do.One peculiar caution about stru5}cts: field names in structs are partof a GLOBAL namespace, rather than a namespace per structure kind, asmopst modern comp5}ilers use. This means that if you try to saystruct frob { char blech };struct frobozz { int blech };you'll get griped a5}t, because it thinks field 'blech' is multiplydefined. (I'm told this was once considered a feature, but hey,everybody in 5}the 14th century had lice...)Enums are not currently supported in the native CC65, to save space,though the cross-compiler5} variant does hack them. They could easilybe put back at the cost of some symbol space.CC65 supports all the usual flow o5}f control constructions, for; while;switch; do .. while; goto, etc.Other syntactoids:CC65 has the usual problem of C com5}pilers on Ataris, namely thatAtascii doesn't contain braces and tilde characters. We use the samekludge, $(, $) and $- in 5}place of {, }, and ~.Temporary vars:CC65 supports temps asfoo(){ gubbish(); { int baz;/* temps in inner code5} fragment! */ char quux; more_gubbish(); } yet_more_gubbish();}In line assembly code:You can embed asse5}mbly language in your C source by using the magickeywords #asm and #endasm. Everything between those lines is copiedverbat5}im into the assembler output file. Ex:frobozz(){#asminc_foo#endasm}generates something like:_frobozz:jsrente5}rfninc_foojmpexitfunYou can also use #asm outside functions, as#asm_foo:.word0#endasmThis is particularly use5}ful for doing things like declaring things tobe on page 0; for instance:#asm_foo=$B0#endasmextern int foo;Subsequen5}t references to foo will generate the correct (page 0)variants of the instructions.Accessing local variables in inline as5}sembly code:This is tricky. Sigh. See internal.doc for details of the stacklayout. Magic symbols:CC65 understands tw5}o magic preprocessor symbols, NOARGC and FIXARGC.These are primarily used when trying to reduce code size, and improveperfo5}rmance. Defining these symbols have the following effects:NOARGCDo not pass arg count. If defined, called functionsw5}ill not have an arg count passed to them.FIXARGCFixed arg count. If defined, functions will notexpect to have an arg c6}ount passed to them.The way these work can be tricky: a function compiled with NOARGC mayONLY call functions compiled with6} FIXARGC. The reverse is not true;functions compiled with FIXARGC may call anything, since they DO passargcounts. Functio6}ns compiled with FIXARGC may be called fromanything as long as exactly the right number of args is passed; anyargcounts wil6}l be ignored. Known bugs:You can only use 256 bytes of local stack space per function. This isdue to the way I did the 6}local-var addressing. Ordinarily, this isn'ta problem, but you should watch out for things like:foo(){ char bar[500];6} ...}The structure-frobbing code doesn't know enough to correctly pass theaddress of a structure, when calling some funct6}ion on it, andgenerates bogus code. That means when you want to sayfrobnicate(structure);you have to sayfrobnicate(&s6}tructure);There are still bugs in the conditional-evaluation code generator. Ifyour "if (...)" statements are behaving in6} funny fashion, check thegenerated code carefully.You can't put comments on lines with #-sign directives at the front.Wh6 }ere it came from:The geneology of CC65 is complex. It started life as a hack based ona CPM version of Small-C, and lived 6 }in that form as a cross-compilerfor a couple of years. It was later updated to use the internalexpression-grokking guts of6 } another Small-C variant, this time for thePC. Finally, it inherited most of the parser etc from CC8, whichappears from th6 }e source to be yet another Small-C variant.The rest of the system and support programs RA65, LINK65, LIBR65 etc,were writt6 }en by JRD. Much of the runtime support was also written byJRD; some was inherited from the PC version of Small-C.ere writt4tthe real arg count. nxtargthen becomes the address of the real first arg.Arg counts are expected to show up in the Y regi"}ster at functionentry. Routines that are hand-coded in assembly language can just usethat directly, rather than go thru th"}e C function entry protocol.Storage layout:Nothing suprising here. Ints and pointers are 16 bits, chars are 8.The stan"}dard 6502 low/high order is used for everything.Data declarations are mixed with the code, as there's no reason to putit i"}n any particular place on a 6502.[What else?]The most effective way to get familiar with how this all works isprobably"} to just dive in and start compiling things, and see what getsgenerated. get familiar with how this all works isprobably M?/