[comp.sys.amiga.tech] Old/New Lattice C Confusion

rlcarr@athena.mit.edu (Rich Carreiro) (07/14/88)

I have Lattice C 4.0 with both patches applied.  I was
reading through Rob Peck's book "Programmer's Guide to the Amiga" and
am wondering how to deal with things that are linked with Astartup.obj
and Lstartup.obj.  I realize they are old versions of startup code, but
how does Lattice's c.o and cback.o relate to them?

Also, (and I realize it betrays a horrible lack of knowledge) how
do I write a program that can be launched from clicking on an icon?
What do I have to add to it, and what do I have to link against?
To make the question specific, I want to double-click on an icon, and I 
want the program to open a window and print "Hello, world" in it.

Finally, is there still a printf function built into the Amiga ROM Kernel
as Peck says in his book?  How do I turn off Lattice's optimizing to make
sure I can get that function?  Also, if I open a window with OpenWindow,
how can I set things up to use printf (kernel or c library version) or other
c standard I/O functions to read/write to the window.

Any help will be greatly appreciated!  I thank you in advance for your
time!

ARPA: rlcarr@athena.mit.edu
UUCP: ...!mit-eddie!athena.mit.edu!rlcarr
BIT: rlcarr%athena.mit.edu@mitvma.mit.edu


*******************************************************************************
* Rich Carreiro                 "...and she's buying a stairway to heaven."   *
* rlcarr@athena.mit.edu            - "Stairway to Heaven" by Led Zeppelin     *
*******************************************************************************

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (07/16/88)

In article <6193@bloom-beacon.MIT.EDU> rlcarr@athena.mit.edu (Rich Carreiro) writes:
>I have Lattice C 4.0 with both patches applied.  I was
>reading through Rob Peck's book "Programmer's Guide to the Amiga" and
>am wondering how to deal with things that are linked with Astartup.obj
>and Lstartup.obj.  I realize they are old versions of startup code, but
>how does Lattice's c.o and cback.o relate to them?

Lstartup.obj is what Lattice calls c.o (though they do more in their
new c.o than in the old one).  If you are linking with c.o (or Lstartup)
then you link with the Lattive .lib(s) before library Amiga.lib.
(So that all stdio and file stuff is resolved by THEIR lib).

If using Astartup.obj, you use the -v flag on the second pass of the
compiler (to disable their insertion of stack-checking code which requires
variables in their startup), and link with Amiga.lib prior to the
Lattice lib(s).  And you don't #include their stdio and file IO headers.
When you you this, your stdio and file IO uses AmigaDOS file handles,
and you are limited to just the io functions in Amiga.lib itself
(note that these don't handle floats and handle %c weirdly - they
are documented in the AW RKM Exec manual), and direct AmigaDOS file
functions (like Open, Write, etc).  But your code will be smaller.
I write stuff that way so that they can also compile my code under
Greenhill's on the Suns.

>Also, (and I realize it betrays a horrible lack of knowledge) how
>do I write a program that can be launched from clicking on an icon?
>What do I have to add to it, and what do I have to link against?
>To make the question specific, I want to double-click on an icon, and I 
>want the program to open a window and print "Hello, world" in it.

You link with a startup that handles WB startup (like c.o or Astartup.obj
or Lstartup.obj).  You make sure you are doing NO stdio output (since
unless you are using a Lattice startup that opens a little safety
output window for you on Workbench startup, you could crash the machine
if you try to printf, etc from Workbench).   So let's say you have a
program, linked with one of those startups, and your program opens
an Intuition window and Text()'s "Hello World".  And the program is
called "MyWindow".   All you have to do is copy some other Tool (program)
icon (like Preferences.info or Clock.info) and call your copy
"MyWindow.info".  Place it in the same directory as your "MyWindow"
program.  And double-click on it.

>Finally, is there still a printf function built into the Amiga ROM Kernel
>as Peck says in his book?  How do I turn off Lattice's optimizing to make
>sure I can get that function?  Also, if I open a window with OpenWindow,
>how can I set things up to use printf (kernel or c library version) or other
>c standard I/O functions to read/write to the window.

Yes.  We say so in our book too, the Addison-Wesley Rom Kernal Manual Exec.
There is a section that describes the C support and Exec support functions
in Amiga.lib.

But your second question is tougher.  You can not get printf to work in
an Intuition window opened at the Intuition level.  And you can not
build a file handle onto that window after opening it (good enhancement
request for 1.4 though).

What you could do is attach a console.device to your intuition window
(see AW RKM Libs and Devices), then use sprintf() to format your output
and the the CDPutStr code as shown in the RKM to print the formatted
string to your Intuition window.  You'll get automatic line wrap and
scrolling, ISO escape sequences can be used to position cursor, etc.
-- 
==========================================================================
  Carolyn Scheppner -- CATS  Commodore Amiga Technical Support
  PHONE 215-431-9180   UUCP  ...{uunet,allegra,rutgers}!cbmvax!carolyn 

 Pad with zeros for a light, airy program.
==========================================================================

jonasf@kuling.UUCP (Jonas Flygare) (07/22/88)

From article <6193@bloom-beacon.MIT.EDU>, by rlcarr@athena.mit.edu (Rich Carreiro):
> and Lstartup.obj.  I realize they are old versions of startup code, but
> how does Lattice's c.o and cback.o relate to them?

> Also, (and I realize it betrays a horrible lack of knowledge) how
> do I write a program that can be launched from clicking on an icon?

> Finally, is there still a printf function built into the Amiga ROM Kernel
> as Peck says in his book?  How do I turn off Lattice's optimizing to make
> sure I can get that function?  Also, if I open a window with OpenWindow,
 


The two are quite clearly stated in the lattice 4.* manual....
If you have it, look on pages 5-12 for cback.o, 8-8..8-12 for
what files correspond to the old astartup, lstartup, etc.
See doc on main() for help on how to write code one can run from
cli/wbench.
The Printf function is different from the printf, need I say more??
-- 
Jonas Flygare (aka Flax)         +------------------------------------------+
email: jonasf@kuling.UUCP        | "Never try to hack while a playful ferret |
real:  Vaktargatan 32 F:621      |  is watching your toes.                  |
       S-754 22 Uppsala Sweden   +-------- I TRIED....... OUCH! ------------+