[comp.sys.apple] What is source code?

AWCTTYPA@UIAMVS.BITNET ("David A. Lyons") (02/08/89)

>Date:         Sat, 4 Feb 89 08:30:12 GMT
>From:         Dale Brisinda
>              <att!alberta!calgary!cpsc!brisinda@UCBVAX.BERKELEY.EDU>
>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

bfox%vision@HUB.UCSB.EDU (Brian Fox) (02/09/89)

Dale:	`Source code' is text meant to be easily read by human beings.  Its
	purpose is to ease the process of turning a person's idea for performing
	an operation (such as merging a list of names into successive form
	letters) into the complex set of instructions that a computer
	understands.

	The computer understands "object code", the human programmer writes
	"source code", and the "compiler" makes the translation.

	You may now press the "D" key.

   From: "David A. Lyons" <AWCTTYPA%UIAMVS.BITNET@cunyvm.cuny.edu>
   Mmdf-Warning:  Parse error in original version of preceding line at BRL.MIL

   >
   >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. :)

I agree. Your copius answer could only be comprehended by someone who already
understood the difference between a compiler and an interpreter, and it is
doubtful that they would actually be able to get any real information from it.
I especialy liked the examples, which served no purpose but to demonstrate
that you could write the same trivial function in more than one language.

An excellent example of your clarity is:

    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).

which I showed to a wizard programmer friend of mine who could not make head
or tails of it.  This friend is an expert Unix programmer, X-windows hacker,
and has worked on Apple's, IBM's, and (in the remotest past) trash-80's.

Of special note:

        ldx #$150E   ;FrontWindow function number
        jsl $e10000  ;toolbox dispatcher
        ldx #$2B0E   ;GetWKind function number
        jsl $e10000
        pla

demonstrating without a trace of a doubt why someone would rather use "Source
Codes" than something else, whatever that might be.  I'm surprised you didn't
just show him hex codes...

    F4 00 00 F4 00 00 F4 00 00 A2 0E 15 22 00 00 E1 A2 0E 2B 22 00 00 E1

oh, perhaps you did.

Well, I'm sure that the "thoroughly bewildered and confused" Dale will be
happy to read your answer to his complex question, and will be prepared to
explain to his friends the difference between "Source Codes" and "regular
stuff".

Brian Fox

MEK4_LTD@DB2.CC.ROCHESTER.EDU (02/09/89)

MrI would beg to differ with Mr. Brian Fox. I think David A. Lyons 
explanation of source code vrs object code was well done, considering
the complexety of the issue and the space he had to explain it. Perhaps
you could offer a better explanation?
	As for no serious desktop programs being written in Applesoft
basic, this is true for one simple reason. You cannot accesss the tool-
box from applesoft basic without special software. Often, it is simpler
to go to another language, than to write your own toolbox interface
for Applesoft. People have done it, however, check out So-
What-Software. 
					Mark Kern