[alt.sources.amiga] Short Hello World

dvljrt@cs.umu.se (Joakim Rosqvist) (05/02/91)

>Well, you are now:
>
>Use `lc -. -v -cus hello.c >nil:' [-O does't help ;-]
>    `blink from hello.o nd quiet'
>with SAS/C v5.0a (with 2.0 includes) to get an executable that is
>124 bytes long...  ...which is smaller than Mike's hand coded 180. :-)
>This may suprise a guy like Mike. :-)
>And, boy is the source more readable... :-)
>[Mike this was meant in good fun - ljr ;-]
>
>// [non-portable because we call AmigaOS functions directly instead of
>//  using the ANSI library and we use those snazzy C++ style comments. ;-]
>//
>// Programmed by Loren J. Rittle in more than 1 minute (but that is all it
>// would take next time :-).
>//
>// compiles and links into a 124 byte executable (62 byte codesize)
>// in .733 seconds (yes, Mike, I changed the time; that's all it took).
>//
>
[some boring C-code deleted]   :-)

Ok, assembler strikes back with this: (56 codesize, 92 executable)

OpenLib=-408
Output=-60
Write=-48

  move.l 4.w,a6
  lea    dos(pc),a1
  jsr    OpenLib(a6)
  move.l d0,a6
  jsr    Output(a6)
  move.l d0,d1
  lea    hello(pc),a0
  move.l a0,d2
  moveq  #12,d3
  jmp    write(a6)

dos:   dc 'dos.library',0
hello: dc 'Hello World',10

/$DR.HEX$

peterk@cbmger.UUCP (Peter Kittel GERMANY) (05/03/91)

In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>with SAS/C v5.0a (with 2.0 includes) to get an executable that is
>>//
>>// compiles and links into a 124 byte executable (62 byte codesize)
>
>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>
>OpenLib=-408
>Output=-60
>Write=-48

Shame on you, you cheated! You do an OpenLib without a CloseLib!
Perhaps this explains the difference.

-- 
Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

bj@cbmvax.commodore.com (Brian Jackson) (05/04/91)

In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>with SAS/C v5.0a (with 2.0 includes) to get an executable that is
>>>//
>>>// compiles and links into a 124 byte executable (62 byte codesize)
>>
>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>
>>OpenLib=-408
>>Output=-60
>>Write=-48
>
>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>Perhaps this explains the difference.

Not to mention absolutely no error checking. Hard to consider it
a "fully compliant" answer to the problem. The question should be
"how small can you make a -correct- 'hello world' ?"

>Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
>Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

bj

 -----------------------------------------------------------------------
 | Brian Jackson  Software Engineer, Commodore-Amiga Inc.  GEnie: B.J. |
 | bj@cbmvax.cbm.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj     |
 | "We defy augury"                                                    |
 -----------------------------------------------------------------------

espie@flamingo.Stanford.EDU (Marc Espie) (05/04/91)

In article <21231@cbmvax.commodore.com> bj@cbmvax.commodore.com (Brian Jackson) writes:
>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>>with SAS/C v5.0a (with 2.0 includes) to get an executable that is
>>>>//
>>>>// compiles and links into a 124 byte executable (62 byte codesize)
>>>
>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>>
>>>OpenLib=-408
>>>Output=-60
>>>Write=-48
>>
>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>Perhaps this explains the difference.
>
>Not to mention absolutely no error checking. Hard to consider it
>a "fully compliant" answer to the problem. The question should be
>"how small can you make a -correct- 'hello world' ?"
>
>>Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
>>Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk
>
>bj
>
> -----------------------------------------------------------------------
> | Brian Jackson  Software Engineer, Commodore-Amiga Inc.  GEnie: B.J. |
> | bj@cbmvax.cbm.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj     |
> | "We defy augury"                                                    |
> -----------------------------------------------------------------------
So far, neither the C nor the C hello world programs are correct, they do not
check for their environment and crash when started from workbench... I would
say that the C program is a little less flawed.
(you MUST check for the environment, even if you don't want to deal with the
workbench, you should AT LEAST exit politely when started from workbench.)
The code to do that looks like this:
-----------------------
t = FindTask(0L);
if (!t->pr_CLI) 
	{
		/* started from Workbench.
		 * you MUST execute the following code BEFORE opening DOS...
		 */
		while (!StartupMsg = GetMsg(t->pr_MsgPort))
			WaitPort(t->pr_MsgPort);
	}
/* do whatever you want... don't forget to close the DOS library */
/* clean exit code */
if (!t->pr_CLI)
	{
		/* don't forget the Forbid(), or Workbench might unload us before
		 * we're through...
		 */
		Forbid();
		ReplyMsg(StartupMsg);
	}
/* fall through the end of code, don't Disable(), this
 * is the only case where you don't pair Forbid()/Disable().
 */
------------------------
Write code that doesn't crash under Workbench and I'll write code that works
under 1.3, ok ?
(For further reference, check for instance the RKM (libr & devices) 1.3,
Workbench chapter.
---
    Marc Espie (espie@flamingo.stanford.edu)

dvljrt@cs.umu.se (Joakim Rosqvist) (05/04/91)

In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>with SAS/C v5.0a (with 2.0 includes) to get an executable that is
>>>//
>>>// compiles and links into a 124 byte executable (62 byte codesize)
>>
>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>
>>OpenLib=-408
>>Output=-60
>>Write=-48
>
>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>Perhaps this explains the difference.
>
I did not! It's ok to close a disk-library, but DosLib is in ROM, and
Closing it is the same as adding NOP's to the code. Anyway, with a
closelib it will be 60/96 bytes. Still shorter!
If you don't agree with me, reply in Amiga.programmer...

/$DR.HEX$

dvljrt@cs.umu.se (Joakim Rosqvist) (05/04/91)

In article <21231@cbmvax.commodore.com> bj@cbmvax.commodore.com (Brian Jackson) writes:
>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>>with SAS/C v5.0a (with 2.0 includes) to get an executable that is
>>>>//
>>>>// compiles and links into a 124 byte executable (62 byte codesize)
>>>
>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>>
>>>OpenLib=-408
>>>Output=-60
>>>Write=-48
>>
>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>Perhaps this explains the difference.
>
>Not to mention absolutely no error checking. Hard to consider it
>a "fully compliant" answer to the problem. The question should be
>"how small can you make a -correct- 'hello world' ?"
>

What should I error-check? Perhaps somebody has removed dolib from ROM...
And since the C-code was 62 bytes codesize, it couldn't have included any
error checking either. Replies to amiga.programmer, please
/$DR.HEX$

xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) (05/05/91)

dvljrt@cs.umu.se (Joakim Rosqvist) writes:

> [some boring C-code deleted]   :-)

> Ok, assembler strikes back with this: (56 codesize, 92 executable)

> OpenLib=-408
> Output=-60
> Write=-48

>   move.l 4.w,a6
>   lea    dos(pc),a1
>   jsr    OpenLib(a6)
>   move.l d0,a6
>   jsr    Output(a6)
>   move.l d0,d1
>   lea    hello(pc),a0
>   move.l a0,d2
>   moveq  #12,d3
>   jmp    write(a6)

> dos:   dc 'dos.library',0
> hello: dc 'Hello World',10

> /$DR.HEX$

And a better example of how _not_ to program would be hard to find.

You've managed, in a 15 line program, to include 3 "magic numbers"
that are dependent on the release of dos.library, so that your code
need not merely be reassembled for an operating system upgrade, but
rewritten.  Sprinkle an equivalent 20% fraction of bogosities into
100,000 lines of code, and you might as well throw it away and start
fresh as try to port it to the next release.

Doing the linker's job for it is _not_ a smart move, as the first
three lines clearly demonstrate.

If you are going to evade higher level languages to worship at the altar
of code size and speed, you have to work _much_ harder than this to
equal the high level language's relatively automatic maintainability
advantage.

Kent, the man from xanth.
<xanthian@Zorch.SF-Bay.ORG> <xanthian@well.sf.ca.us>

s608@cs.utexas.edu (Classroom Account) (05/05/91)

In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>
>OpenLib=-408
>Output=-60
>Write=-48
>
>  move.l 4.w,a6
>  lea    dos(pc),a1
>  jsr    OpenLib(a6)
>  move.l d0,a6
>  jsr    Output(a6)
>  move.l d0,d1
>  lea    hello(pc),a0
>  move.l a0,d2
>  moveq  #12,d3
>  jmp    write(a6)
>
>dos:   dc 'dos.library',0
>hello: dc 'Hello World',10

REXX weighs in at 23 bytes.

Here's the code:
----start----
/**/
say"Hello, world"
-----end-----

I wrote and debugged this in about 1 minute.

And, I can run this program on any machine that has REXX (IBM
mainframes, PC Clones, certain incarnations of UNIX, etc) without
modification.  The source code is short, there's no executable to
worry about, and it's incredibly clear what it does.

It just goes to show that you should use the language that is
best suited for the job.

Later,
  Logan
-- 
=----------------Logan-Shaw---(lshaw@ccwf.cc.utexas.edu)----------------=
  "Trust in the Lord with all thine heart, and lean not on thine own
   understanding.  In all thy ways acknowledge Him and he shall direct
   thy paths"        - Proverbs 3:5-6

mykes@amiga0.SF-Bay.ORG (Mike Schwartz) (05/05/91)

In article <1991May5.011748.11595@zorch.SF-Bay.ORG> xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) writes:
>dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>
>> [some boring C-code deleted]   :-)
>
>> Ok, assembler strikes back with this: (56 codesize, 92 executable)
>
>> OpenLib=-408
>> Output=-60
>> Write=-48
>
>>   move.l 4.w,a6
>>   lea    dos(pc),a1
>>   jsr    OpenLib(a6)
>>   move.l d0,a6
>>   jsr    Output(a6)
>>   move.l d0,d1
>>   lea    hello(pc),a0
>>   move.l a0,d2
>>   moveq  #12,d3
>>   jmp    write(a6)
>
>> dos:   dc 'dos.library',0
>> hello: dc 'Hello World',10
>
>> /$DR.HEX$
>
>And a better example of how _not_ to program would be hard to find.
>
>You've managed, in a 15 line program, to include 3 "magic numbers"
>that are dependent on the release of dos.library, so that your code
>need not merely be reassembled for an operating system upgrade, but
>rewritten.  Sprinkle an equivalent 20% fraction of bogosities into
>100,000 lines of code, and you might as well throw it away and start
>fresh as try to port it to the next release.
>
>Doing the linker's job for it is _not_ a smart move, as the first
>three lines clearly demonstrate.
>
>If you are going to evade higher level languages to worship at the altar
>of code size and speed, you have to work _much_ harder than this to
>equal the high level language's relatively automatic maintainability
>advantage.
>
>Kent, the man from xanth.
><xanthian@Zorch.SF-Bay.ORG> <xanthian@well.sf.ca.us>
>

Here's the right way, and NO HLL has any automatic anything over this.
It is 12 bytes shorter than the best 'C' equivilent (so far) and is
also 10% faster (clock cycles).  SAS 'C' can make a 124 byte executable
(88 bytes of code).

*
* Hello world in assembler language
*
* Programmed by Mike Schwartz in 1 minute.  Optimized in 1 minute more.
*
* assembles into 112 byte executable (75 byte codesize) in .733 seconds.
*

* The INCDIR directive tells the assembler where the include files are
		INCDIR	include:
* The OUTPUT directive tells the assembler the name of the output file
		OUTPUT	hello

		INCLUDE	lvo/exec.lvo
		INCLUDE	lvo/dos.lvo

EXECBASE	equ	4

Main		lea	dosName(pc),a1
		moveq	#0,d0
		move.w	(EXECBASE).w,a6
		jsr	_LVOOpenLibrary(a6)
		tst.l	d0
		beq.s	Exit

		move.l	d0,a6
		jsr	_LVOOutput(a6)

		move.l	d0,d1
		move.l	#hello,d2
		moveq.l	#helloLen,d3
		jsr	_LVOWrite(a6)

		move.l	a6,a1
		move.l	(EXECBASE).w,a6
		jmp	_LVOCloseLibrary(a6)

Exit		rts

hello		dc.b	"Hello, world",10
helloLen	equ	*-hello

dosName		dc.b	'dos.library',0


--
****************************************************
* I want games that look like Shadow of the Beast  *
* but play like Leisure Suit Larry.                *
****************************************************

dvljrt@cs.umu.se (Joakim Rosqvist) (05/05/91)

>Here's the right way, and NO HLL has any automatic anything over this.
>It is 12 bytes shorter than the best 'C' equivilent (so far) and is
>also 10% faster (clock cycles).  SAS 'C' can make a 124 byte executable
>(88 bytes of code).
>

10% faster in clock cycles?? Have you counted the about 4.8 Zilion
cycles requierd to put a character on the screen  :-)


>*
>* Hello world in assembler language
>*
>* Programmed by Mike Schwartz in 1 minute.  Optimized in 1 minute more.
>*
>* assembles into 112 byte executable (75 byte codesize) in .733 seconds.
>*
>
>* The INCDIR directive tells the assembler where the include files are
>		INCDIR	include:
>* The OUTPUT directive tells the assembler the name of the output file
>		OUTPUT	hello
>
>		INCLUDE	lvo/exec.lvo
>		INCLUDE	lvo/dos.lvo
>
>EXECBASE	equ	4
>
>Main		lea	dosName(pc),a1
>		moveq	#0,d0
>		move.w	(EXECBASE).w,a6
>		jsr	_LVOOpenLibrary(a6)

Whats wrong with OldOpenLibrary? It will do the same thing, but not
require a parameter.

>		tst.l	d0
>		beq.s	Exit
>
>		move.l	d0,a6
>		jsr	_LVOOutput(a6)
>
>		move.l	d0,d1
>		move.l	#hello,d2

This makes the code non-relocatable. Now the assembler must add an extra
hunk to fix that.  lea hello(pc),a0 followed by move.l a0,d2 also takes
4 bytes, but wont need this table.


>		moveq.l	#helloLen,d3
>		jsr	_LVOWrite(a6)
>
>		move.l	a6,a1
>		move.l	(EXECBASE).w,a6
>		jmp	_LVOCloseLibrary(a6)
>
>Exit		rts
>
>hello		dc.b	"Hello, world",10
>helloLen	equ	*-hello
>
>dosName		dc.b	'dos.library',0
>
>

/$DR.HEX$

sschaem@starnet.uucp (Stephan Schaem) (05/06/91)

 There is a way to get a label in a data register in 8 byte of code not
 12. (No reloc etheir)
 This is trick and is not recomanded!!
 Of course this aply for the hello world programe...
 using a bsr.s flowwed by the string (pushing return adress== string
 address) than move.l	(sp)+,dX.
 Speaking of tricks, I found that internal dos seem to be the same in
 2.0... my 180 byte task remover still work:-) (like the change task pri
 utilites: 230 byte internal dos, 256byte non internal...).
 Also a iff show programe in 1228 byte pure code, reantrant, no reloc
 etc... with 32bit decompacting.(handle all amiga modes, including
 overscan: curently using it with dctv pic).
 If anyone interested in the obove drop me a line.

							Stephan.

jms@tardis.Tymnet.COM (Joe Smith) (05/06/91)

In article <1991May5.011748.11595@zorch.SF-Bay.ORG> xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) writes:
>dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>> OpenLib=-408
>> Output=-60
>> Write=-48
>>   jsr    OpenLib(a6)
>>   jsr    Output(a6)
>>   jmp    write(a6)
>
>You've managed, in a 15 line program, to include 3 "magic numbers"
>that are dependent on the release of dos.library, so that your code need
>not merely be reassembled for an operating system upgrade, but rewritten.

I was about to post an article saying "don't be absurd, Kent.  If
Commodore were to change the library offsets, existing binaries would
stop working, therefore the offsets are engraved in stone; they will
never change."

But then I remembered that some of them HAVE changed.  OpenLibrary used to
be -408, now it is -552.  Offset -408 is still supported, however, as
OldOpenLibrary.  Using the old definitions is works, the program won't get
the newest features.

>Doing the linker's job for it is _not_ a smart move, as the first
>three lines clearly demonstrate.

Using the most recent *.h or *.i files is just as good as letting the linker
get the definitions out of amiga.lib.
-- 
Joe Smith (408)922-6220 | SMTP: jms@tardis.tymnet.com or jms@gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C51    | BIX: smithjoe | CA license plate: "POPJ P," (PDP-10)
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga 3000 speaks for me."

jms@tardis.Tymnet.COM (Joe Smith) (05/06/91)

In article <mykes.2178@amiga0.SF-Bay.ORG> mykes@amiga0.SF-Bay.ORG (Mike Schwartz) writes:
>Here's the right way, and NO HLL has any automatic anything over this.
>It is 12 bytes shorter than the best 'C' equivilent (so far) and is
>EXECBASE	equ	4
>		move.w	(EXECBASE).w,a6
>		jsr	_LVOOpenLibrary(a6)

That will never work.  You must use "move.l (EXECBASE).w,a6".  Otherwise
A6 will end up with 0x????07E0 instead of 0x07E007D8.  (Execbase is in
high memory on an A3000.)
-- 
Joe Smith (408)922-6220 | SMTP: jms@tardis.tymnet.com or jms@gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C51    | BIX: smithjoe | CA license plate: "POPJ P," (PDP-10)
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga 3000 speaks for me."

beust@taloa.unice.fr (Cedric Beust) (05/06/91)

In article <1418@saltillo.cs.utexas.edu>, s608@cs.utexas.edu (Classroom Account) writes:

: Here's the code:
: ----start----
: /**/
: say"Hello, world"
: -----end-----
: 
: I wrote and debugged this in about 1 minute.

  Fine, but a 'echo "Hello world"' would work on even more different
platforms, and would be shorter. Nothing prevents you from aliasing
the 'execute world' to the letter a and get the wonderful "Hello World"
by a mere a<RET>.

  :-)

  Actually, I agree with you. Use the languages for the purpose they're
meant to.

+------------------------------------------------------------------------+
| Cedric BEUST                                     University of Nice    |
| INET: beust@mimosa.unice.fr                      $whoami               |
| UUCP: llaor.unice.fr!arkonis!beust               god (personal alias)  |
|                   -- "To be, or not to be...",                         |
|                      That is illogical, captain!                       |
|                                     -- Spock                           |
+------------------------------------------------------------------------+

peterk@cbmger.UUCP (Peter Kittel GERMANY) (05/06/91)

In article <1991May4.134045.7550@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>
>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>
>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>Perhaps this explains the difference.
>>
>I did not! It's ok to close a disk-library, but DosLib is in ROM, and
>Closing it is the same as adding NOP's to the code. Anyway, with a
>closelib it will be 60/96 bytes. Still shorter!
>If you don't agree with me, reply in Amiga.programmer...

Well, we had a lengthy discussion on this in the German sub.sys.amiga
group. We came to the conclusion that it would really be dangerous!
Because, if your Amiga runs long enough and runs such programs in a
tight loop, the use counter of the library will be increased every time.
And, after *some* (:-) time, it will wrap around to zero. And, if it
happens that you have a tight memory situation just in this moment and
exec flushes all unused libs: POOF! I admit, not an everyday scenario, 
but sure possible :-).

You see, there was a related discussion whether you should check for
success of opening dos.library (or which lib was it?) at all, because
theoretically you always will succeed. But also there it was concluded
that you better use the safe way.

-- 
Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

kilian@cinnet.com (Kilian Jacob) (05/07/91)

From article <1804@tardis.Tymnet.COM>, by jms@tardis.Tymnet.COM (Joe Smith):
> In article <1991May5.011748.11595@zorch.SF-Bay.ORG> xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) writes:
>>dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>> OpenLib=-408

[deleted]

> But then I remembered that some of them HAVE changed.  OpenLibrary used to
> be -408, now it is -552.  Offset -408 is still supported, however, as
> OldOpenLibrary.  Using the old definitions is works, the program won't get
> the newest features.
>
I think OldOpenLibrary() is used here on purpose. This way you can omit
the moveq.l #0,d0 (or sub.l d0,d0 -- faster, I believe). Since no specific
version (or higher) is need in this example using OldOpenLibrary is perfectly
ok -- saves 2 bytes!! :-)

-- /<ilian
-- 
Kilian Jacob - Cincinnati, Ohio - VOICE: (513)-489-1891
UUCP: kilian@cinnet.com or {uceng.uc.edu, ukma!spca6, uunet!sdrc}!cinnet!kilian

dvljrt@cs.umu.se (Joakim Rosqvist) (05/07/91)

In article <1205@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>In article <1991May4.134045.7550@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>>
>>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>>
>>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>>Perhaps this explains the difference.
>>>
>>I did not! It's ok to close a disk-library, but DosLib is in ROM, and
>>Closing it is the same as adding NOP's to the code. Anyway, with a
>>closelib it will be 60/96 bytes. Still shorter!
>>If you don't agree with me, reply in Amiga.programmer...
>
>Well, we had a lengthy discussion on this in the German sub.sys.amiga
>group. We came to the conclusion that it would really be dangerous!
>Because, if your Amiga runs long enough and runs such programs in a
>tight loop, the use counter of the library will be increased every time.
>And, after *some* (:-) time, it will wrap around to zero. And, if it
>happens that you have a tight memory situation just in this moment and
>exec flushes all unused libs: POOF! I admit, not an everyday scenario, 
>but sure possible :-).
>
>
Normally, I would take that as a flame, but my FlameCnt for the 
"Hello World" posting just wrapped around  :-)

/$DR.HEX$

zog@intacc.uucp (Scott Lepore) (05/08/91)

Here! Here Logan!

chucks@pnet51.orb.mn.org (Erik Funkenbusch) (05/08/91)

peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>In article <1991May4.134045.7550@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>>
>>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>>
>>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>>Perhaps this explains the difference.
>>>
>>I did not! It's ok to close a disk-library, but DosLib is in ROM, and
>>Closing it is the same as adding NOP's to the code. Anyway, with a
>>closelib it will be 60/96 bytes. Still shorter!
>>If you don't agree with me, reply in Amiga.programmer...
>
>Well, we had a lengthy discussion on this in the German sub.sys.amiga
>group. We came to the conclusion that it would really be dangerous!
>Because, if your Amiga runs long enough and runs such programs in a
>tight loop, the use counter of the library will be increased every time.
>And, after *some* (:-) time, it will wrap around to zero. And, if it
>happens that you have a tight memory situation just in this moment and
>exec flushes all unused libs: POOF! I admit, not an everyday scenario, 
>but sure possible :-).
>
>You see, there was a related discussion whether you should check for
>success of opening dos.library (or which lib was it?) at all, because
>theoretically you always will succeed. But also there it was concluded
>that you better use the safe way.
>
>-- 
>Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
>Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk


not to mention that there is SOME RAM overhead for opening a library anyways,
if you happen to have all memory allocated and then try to open a library.. it
won't succeed, that is a MUCH more common occurance.  I think commodore should
DEFINATELY squelch this rumor that rom calls will always succeed.

.--------------------------------------------------------------------------.
| UUCP: {amdahl!tcnet, crash}!orbit!pnet51!chucks | "I know he's come back |
| ARPA: crash!orbit!pnet51!chucks@nosc.mil        | from the dead, but do  |
| INET: chucks@pnet51.orb.mn.org                  | you really think he's  |
|-------------------------------------------------| moved back in?"        |
| Amiga programmer at large, employment options   | Lou Diamond Philips in |
| welcome, inquire within.                        | "The First Power".     |
`--------------------------------------------------------------------------'

micja@ida.liu.se (Michael Jansson) (05/08/91)

In article <1205@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:

[Stuff deleted about small 'Hello'-programs]

>Well, we had a lengthy discussion on this in the German sub.sys.amiga
>group. We came to the conclusion that it would really be dangerous!
>Because, if your Amiga runs long enough and runs such programs in a
>tight loop, the use counter of the library will be increased every time.
>And, after *some* (:-) time, it will wrap around to zero. And, if it
>happens that you have a tight memory situation just in this moment and
>exec flushes all unused libs: POOF! I admit, not an everyday scenario, 
>but sure possible :-).

That is not really true (unless I got it all backwards). A library will
stay resident until there is a shortage of memory AND the Expunge
function (every library has one), which is called when Exec attempts to
remove the un-used library, returns the segment of the library itself.
In other words - The library is only flushed if the library admits it,
which might not be the case for the ROM-based libraries (my guess is that
they are un-removable since they are never loaded with LoadSeg).

I have used this feature in a library of mine. The library will eat a lot
of memory, which can be returned to the system if needed.  I managed to do
this by writing a neat little garbage collector and put it where the
Expunge function should be. I also bookkeep the number of users of the
library separately, i.e. not in the library structure that Exec knows of,
so that Exec will be convinced that the library is unused when it is not.
So what will this give me? Exec will attempt to remove the library
whenever there is a shortage of memory which will result in a call to my
new Expunge function, that will return some memory without removing
itself, i.e. an automatic GC. It works too! (At least so far ;-).


[Other stuff deleted]

>-- 
>Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
>Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk


--
##########################################################
#   Michael Jansson             |   \_/
#   Internet: mij@IDA.LIU.SE    |    V                   _|_
#   UUCP: uunet!liuida!mij      |    |    Absolut Software|
#   BITNET: mij@SELIUIDA        |   ~~~  

kilian@cinnet.com (Kilian Jacob) (05/09/91)

From article <1205@cbmger.UUCP>, by peterk@cbmger.UUCP (Peter Kittel GERMANY):
> In article <1991May4.134045.7550@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>>
>>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>>
>>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>>Perhaps this explains the difference.
>>>
>>I did not! It's ok to close a disk-library, but DosLib is in ROM, and
>>Closing it is the same as adding NOP's to the code. Anyway, with a
>>closelib it will be 60/96 bytes. Still shorter!
>>If you don't agree with me, reply in Amiga.programmer...
> 
> Well, we had a lengthy discussion on this in the German sub.sys.amiga
> group. We came to the conclusion that it would really be dangerous!
> Because, if your Amiga runs long enough and runs such programs in a
> tight loop, the use counter of the library will be increased every time.
> And, after *some* (:-) time, it will wrap around to zero. And, if it
> happens that you have a tight memory situation just in this moment and
> exec flushes all unused libs: POOF! I admit, not an everyday scenario, 
> but sure possible :-).
> 
To be exact: You'll have to call that program about 65000 times
(Library.OpenCnt is a UWORD.) and then wait for a low memory situation.
If you call that program 20 times a day, it'll take at least 10 years.
I think my A500 would die before that happenes.. :-)

> theoretically you always will succeed. But also there it was concluded
> that you better use the safe way.


Agreed.

-- /<ilian

-- 
Kilian Jacob - Cincinnati, Ohio - VOICE: (513)-489-1891
UUCP: kilian@cinnet.com or {uceng.uc.edu, ukma!spca6, uunet!sdrc}!cinnet!kilian

mykes@amiga0.SF-Bay.ORG (Mike Schwartz) (05/09/91)

In article <1205@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>In article <1991May4.134045.7550@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>In article <1200@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes:
>>>In article <1991May2.102554.8679@cs.umu.se> dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>>
>>>>Ok, assembler strikes back with this: (56 codesize, 92 executable)
>>>
>>>Shame on you, you cheated! You do an OpenLib without a CloseLib!
>>>Perhaps this explains the difference.
>>>
>>I did not! It's ok to close a disk-library, but DosLib is in ROM, and
>>Closing it is the same as adding NOP's to the code. Anyway, with a
>>closelib it will be 60/96 bytes. Still shorter!
>>If you don't agree with me, reply in Amiga.programmer...
>
>Well, we had a lengthy discussion on this in the German sub.sys.amiga
>group. We came to the conclusion that it would really be dangerous!
>Because, if your Amiga runs long enough and runs such programs in a
>tight loop, the use counter of the library will be increased every time.
>And, after *some* (:-) time, it will wrap around to zero. And, if it
>happens that you have a tight memory situation just in this moment and
>exec flushes all unused libs: POOF! I admit, not an everyday scenario, 
>but sure possible :-).
>
>You see, there was a related discussion whether you should check for
>success of opening dos.library (or which lib was it?) at all, because
>theoretically you always will succeed. But also there it was concluded
>that you better use the safe way.
>
>-- 
>Best regards, Dr. Peter Kittel  // E-Mail to  \\  Only my personal opinions... 
>Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk

Another note:

You probably want to also use a specific version number, especially if you
want to do 2.0 specific things.  For example, the 2.0 Dos library lets you
do SetFunction(), while the 1.3 doesn't.

--
****************************************************
* I want games that look like Shadow of the Beast  *
* but play like Leisure Suit Larry.                *
****************************************************

chucks@pnet51.orb.mn.org (Erik Funkenbusch) (05/09/91)

kilian@cinnet.com (Kilian Jacob) writes:
>From article <1804@tardis.Tymnet.COM>, by jms@tardis.Tymnet.COM (Joe Smith):
>> In article <1991May5.011748.11595@zorch.SF-Bay.ORG> xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan) writes:
>>>dvljrt@cs.umu.se (Joakim Rosqvist) writes:
>>>> OpenLib=-408
>
>[deleted]
>
>> But then I remembered that some of them HAVE changed.  OpenLibrary used to
>> be -408, now it is -552.  Offset -408 is still supported, however, as
>> OldOpenLibrary.  Using the old definitions is works, the program won't get
>> the newest features.
>>
>I think OldOpenLibrary() is used here on purpose. This way you can omit
>the moveq.l #0,d0 (or sub.l d0,d0 -- faster, I believe). Since no specific
>version (or higher) is need in this example using OldOpenLibrary is perfectly
>ok -- saves 2 bytes!! :-)
>
>-- /<ilian
>-- 
>Kilian Jacob - Cincinnati, Ohio - VOICE: (513)-489-1891
>UUCP: kilian@cinnet.com or {uceng.uc.edu, ukma!spca6, uunet!sdrc}!cinnet!kilian


But NOT guaranteed to continue to be supported.  they COULD remove
OldOpenLibrary in the next OS release.  They tell you not to use it.

.--------------------------------------------------------------------------.
| UUCP: {amdahl!tcnet, crash}!orbit!pnet51!chucks | "I know he's come back |
| ARPA: crash!orbit!pnet51!chucks@nosc.mil        | from the dead, but do  |
| INET: chucks@pnet51.orb.mn.org                  | you really think he's  |
|-------------------------------------------------| moved back in?"        |
| Amiga programmer at large, employment options   | Lou Diamond Philips in |
| welcome, inquire within.                        | "The First Power".     |
`--------------------------------------------------------------------------'

baxter_a@wehi.dn.mu.oz (05/11/91)

In article <1991May8.180919.8732@cinnet.com>, kilian@cinnet.com (Kilian Jacob) writes:
>> 
> To be exact: You'll have to call that program about 65000 times
> (Library.OpenCnt is a UWORD.) and then wait for a low memory situation.
> If you call that program 20 times a day, it'll take at least 10 years.
                          ^^^^^^^^^^^^^^

Lattice C used to always leave the library open and I got the count to 48 
in about 1/2 an hour. 

Many people leave their machines on for extended periods, often running
automatic macros than might run a function up to 10 times a second. 

I think the library should probably be closed.

Regards Alan

kilian@cinnet.com (Kilian Jacob) (05/14/91)

From article <4872@orbit.cts.com>, by chucks@pnet51.orb.mn.org (Erik Funkenbusch):
> kilian@cinnet.com (Kilian Jacob) writes:
[deleted]
>>I think OldOpenLibrary() is used here on purpose. This way you can omit
>>the moveq.l #0,d0 (or sub.l d0,d0 -- faster, I believe). Since no specific
>>version (or higher) is need in this example using OldOpenLibrary is perfectly
>>ok -- saves 2 bytes!! :-)
> 
> But NOT guaranteed to continue to be supported.  they COULD remove
> OldOpenLibrary in the next OS release.  They tell you not to use it.
>
Why why should they remove it? It only takes up a couple of bytes.

BTW: Who is 'they' ? Does *Commodore* say OldOpenLibrary should not be used?

-- /<ilian
 
-- 
Kilian Jacob - Cincinnati, Ohio - VOICE: (513)-489-1891
UUCP: kilian@cinnet.com or {uceng.uc.edu, ukma!spca6, uunet!sdrc}!cinnet!kilian

chucks@pnet51.orb.mn.org (Erik Funkenbusch) (05/15/91)

kilian@cinnet.com (Kilian Jacob) writes:
>From article <4872@orbit.cts.com>, by chucks@pnet51.orb.mn.org (Erik Funkenbusch):
>> kilian@cinnet.com (Kilian Jacob) writes:
>[deleted]
>>>I think OldOpenLibrary() is used here on purpose. This way you can omit
>>>the moveq.l #0,d0 (or sub.l d0,d0 -- faster, I believe). Since no specific
>>>version (or higher) is need in this example using OldOpenLibrary is perfectly
>>>ok -- saves 2 bytes!! :-)
>> 
>> But NOT guaranteed to continue to be supported.  they COULD remove
>> OldOpenLibrary in the next OS release.  They tell you not to use it.
>>
>Why why should they remove it? It only takes up a couple of bytes.
>
>BTW: Who is 'they' ? Does *Commodore* say OldOpenLibrary should not be used?

Yes, "they" are commodore, and they have said not to use it for quite some
time.  ever since 1.2 i think, or was it 1.1?  i don't remember, but it is no
longer supported and NOT guaranteed to continue to be there.  supose they get
short on rom space for 3.0.. guess what will probably go, all the unsupported
functions.

.--------------------------------------------------------------------------.
| UUCP: {amdahl!tcnet, crash}!orbit!pnet51!chucks | "I know he's come back |
| ARPA: crash!orbit!pnet51!chucks@nosc.mil        | from the dead, but do  |
| INET: chucks@pnet51.orb.mn.org                  | you really think he's  |
|-------------------------------------------------| moved back in?"        |
| Amiga programmer at large, employment options   | Lou Diamond Philips in |
| welcome, inquire within.                        | "The First Power".     |
`--------------------------------------------------------------------------'

sschaem@starnet.uucp (Stephan Schaem) (05/18/91)

 Lets hope not! Lets hope they will optimize the rom instead of removing
 oldfunction.Or go to 1 meg if really needed!
 And the original OpenLibrary was a mistake from CBM and should have
 never been without vesion... And removing it or replacing it would be
 another mistake.
 Come on how short could they be to remove a function that take them 6
 bytes! (+6 for lib jump).
 Doesn't make ANY sens.
 What they could do (Without removing/repacing!) is to make function
 fail with corect FAIL return code. (That would not make OldOpenLibrary
 shorter!)
 And from what I heard they have extra code in 2.0 to support earlyer
 verion function, more easyer to beleive...

								Stephan.

jesup@cbmvax.commodore.com (Randell Jesup) (05/20/91)

In article <4852@orbit.cts.com> chucks@pnet51.orb.mn.org (Erik Funkenbusch) writes:
>not to mention that there is SOME RAM overhead for opening a library anyways,
>if you happen to have all memory allocated and then try to open a library.. it
>won't succeed, that is a MUCH more common occurance.  I think commodore should
>DEFINATELY squelch this rumor that rom calls will always succeed.

	Some libraries, including ROM libraries I believe, do allocations on
open.  Some even allocate entire new lib/device bases on open.  If you fail
to close them, you may lose valuable resources (and they can fail).  Even
if they don't currently allocate ram, they may tomorrow.

	Follow the rules and you won't get burned.  Work around the rules or
try to find loopholes in the rules and you will.

-- 
Randell Jesup, Keeper of AmigaDos, Commodore Engineering.
{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.commodore.com  BIX: rjesup  
Disclaimer: Nothing I say is anything other than my personal opinion.
Thus spake the Master Ninjei: "To program a million-line operating system
is easy, to change a man's temperament is more difficult."
(From "The Zen of Programming")  ;-)

kilian@cinnet.com (Kilian Jacob) (05/21/91)

From article <1991May17.170132.23862@starnet.uucp>, by sschaem@starnet.uucp (Stephan Schaem):
> 
>  Lets hope not! Lets hope they will optimize the rom instead of removing
>  oldfunction.Or go to 1 meg if really needed!
>  And the original OpenLibrary was a mistake from CBM and should have
>  never been without vesion... And removing it or replacing it would be
>  another mistake.
>  Come on how short could they be to remove a function that take them 6
>  bytes! (+6 for lib jump).
>  Doesn't make ANY sens.
>  What they could do (Without removing/repacing!) is to make function
>  fail with corect FAIL return code. (That would not make OldOpenLibrary
>  shorter!)
>  And from what I heard they have extra code in 2.0 to support earlyer
>  verion function, more easyer to beleive...
> 
> 								Stephan.
-- 
Kilian Jacob - Cincinnati, Ohio - VOICE: (513)-489-1891
UUCP: kilian@cinnet.com or {uceng.uc.edu, ukma!spca6, uunet!sdrc}!cinnet!kilian