Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!UIAMVS.BITNET!AWCTTYPA From: AWCTTYPA@UIAMVS.BITNET ("David A. Lyons") Newsgroups: comp.sys.apple Subject: What is source code? (answered) Message-ID: <8902071649.aa27338@SMOKE.BRL.MIL> Date: 8 Feb 89 12:05:36 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 124 X-Unparsable-Date: Tuesday 07 Feb 89 3:18 PM CT >Date: Sat, 4 Feb 89 08:30:12 GMT >From: Dale Brisinda > >Subject: Source.Codes? > >I was wondering if there is anybody out there...that could explain to me >what the hell are source codes??? I've seen a handfull of these "Source >Codes" in the comp.binaries.apple2 (I think thats what its called). >[...] > --Dale I'll _try_ to keep this sort of brief, but I have problems in that area. :) "Source code" doesn't _do_ anything by itself: you can't run it. You can _read_ it, and you can run it through an assembler or a compiler to translate it into an actual runnable program. If you have programmed only in languages like Applesoft BASIC, there is no distinction between "source code" (your program as you type it in) and "object code" (the form of the program that can actually run). Since Applesoft is an interpreted language, there's no separate step where you create a file containing object code. Serious Apple IIgs desktop-based programs can't be written in Applesoft, because no RAM-based toolsets are available without GS/OS (or its obsolete predecessor, ProDOS 16). Typically GS programs are written in C, or Pascal, or assembly language. Pascal and C programs need to be translated from source code to object code by compilers, and assembly-language programs need to be translated from source code to object code by an assembler. Here's an example of how to close the front-most window in a GS program, testing whether the window belongs to the system (a New Desk Accessory Window) and letting either CloseNDAByWinPtr or CloseWindow handle it, depending. (We'll assume there is at least one window open, for simplicity.) ---------- in Pascal: if GetWKind(FrontWindow)<>0 then CloseNDAByWinPtr(FrontWindow) else CloseWindow(FrontWindow); ---------- in C: if(GetWKind(FrontWindow())) CloseNDAByWinPtr(FrontWindow()); else CloseWindow(FrontWindow()); [Yes, Pascal and C have different requirements about semicolons. :( ] ---------- in assembly language with the aid of macros ---------- (for APW or ORCA assembler): pushword #0 ;room for GetWKind result pushlong #0 ;room for FrontWindow result _FrontWindow _GetWKind pla beq NotNDA pushlong #0 _FrontWindow _CloseNDAByWinPtr bra Done NotNDA pushlong #0 _FrontWindow _CloseWindow Done anop --------- "plain" assembly language with no macros: pea 0 ;room for GetWKind result pea 0 pea 0 ;room for FrontWindow result ldx #$150E ;FrontWindow function number jsl $e10000 ;toolbox dispatcher ldx #$2B0E ;GetWKind function number jsl $e10000 pla beq NotNDA pea 0 pea 0 ldx #$150E ;FrontWindow jsl $e10000 ldx #$1C05 ;CloseNDAByWinPtr jsl $e10000 bra Done NotNDA pea 0 pea 0 ldx #$150E ;FrontWindow jsl $e10000 ldx #$0B0E ;CloseWindow jsl $e10000 Done anop ---------- The actual object code in memory (definitely for my ---------- assembly language source code; particular Pascal and ---------- C compilers may generate slightly different object ---------- code): F4 00 00 F4 00 00 F4 00 00 A2 0E 15 22 00 00 E1 A2 0E 2B 22 00 00 E1 68 F0 16 F4 00 00 F4 00 00 A2 0E 15 22 00 00 E1 A2 05 1C 22 00 00 E1 80 14 F4 00 00 F4 00 00 A2 0E 15 22 00 00 E1 A2 0E 0B 22 00 00 E1 (I hope this illustrates the need for compilers and assemblers! I prefer to write in Pascal or C much of the time, although you do have complete control over the object code produced when you write in assembly language: not so for higher-level languages like Pascal and C.) The "sample source code" files you have seen recently come from Apple II Developer Technical Support, and they demonstrate how to use various parts of the Apple IIgs toolbox. I don't know whether object code was supplied along with the source--some of the programs are interesting in themselves--but the main idea is for GS programmers to study & learn from the source code, and to adapt parts of it for use in their own programs. I believe all of the sample source that was released is assembly language source, but I may be misremembering that. If there is another language there, it's C. --David A. Lyons bitnet: awcttypa@uiamvs DAL Systems CompuServe: 72177,3233 P.O. Box 287 GEnie mail: D.LYONS2 North Liberty, IA 52317 AppleLinkPE: Dave Lyons