English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 08 March 2013, 16:36   #1
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
Clean exit of code

Hi,

Clean exit of code, to return t the CLI or Workbench was never important for me when I did my ASM coding some 20-25 years ago.

Can someone help me with code for initializing and exiting to gracefully return to the CLI or WB? I need code that compiles on Asm-One v1.20.

I can make this myself, but I'd rather not spend time on this, but rather on coding other stuff. I'm going to setup a website for oldskool-coding on Amigas during the weekend, with sources and resources. But these example programs should be able to exit gracefully.

Hopefully I can get some help here, otherwise I'll have to make it myself.
Vikke is offline  
Old 08 March 2013, 16:49   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
http://eab.abime.net/showpost.php?p=671760&postcount=22
thomas is online now  
Old 18 March 2013, 17:02   #3
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
So, I made my own, but I read online what other suggested to be done.

Especially the text of xeron on Amiga.org http://www.amiga.org/forums/showpost...19&postcount=3 was of great help.

It is made to work on OCS Amigas and can be found in all code examples at http://vikke.net
Vikke is offline  
Old 21 March 2013, 16:16   #4
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Close any opened libs, then moveq #0,d0;rts if you haven't turned off interrupts etc

Else you just restore what hardware registers you changed and do the same. (To restore the copper list pointer(s) you must get the current pointers from graphics.library at the start).

It's considered good form to restore all registers (except d0) before exit.

If you want to be compatible with Amigas with graphics cards, you should wait for vertical blank twice and restore the Intuition view the program was started from.
Photon is offline  
Old 21 March 2013, 17:01   #5
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Why do we clear d0?
BippyM is offline  
Old 21 March 2013, 17:54   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
D0 contains the return code. If you return 10 or higher, you get a "command xy failed return code nn" message. If you return -1 you get "xy: unknown command".
thomas is online now  
Old 22 March 2013, 11:55   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Photon View Post
It's considered good form to restore all registers (except d0) before exit.
Why? I would expect that the caller saves and restores all registers anyway.
phx is offline  
Old 23 March 2013, 01:25   #8
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Quote:
Originally Posted by phx View Post
Why? I would expect that the caller saves and restores all registers anyway.
Well, that knowledge comes from aquirable experience/OS documentation. Having it there makes the code independent from relying on that the caller does that. I have the experience and don't do it, so I was probably a bit overzealous there. (But I certainly like code that is independent from experience and OS documentation.)

Some startups wait for end of frame, then set copperptr and trigger the new copper, even though it's not necessary. This is verbatim, logical, independent code that works - but you could argue the same there, "everyone knows it's not necessary". I think spelling it out is sometimes pedagogical and sensible.
Photon is offline  
Old 23 March 2013, 08:07   #9
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
Commands don't need to save/restore registers, except of course stack pointer

Quote:
Some startups wait for end of frame, then set copperptr and trigger the new copper, even though it's not necessary. This is verbatim, logical, independent code that works - but you could argue the same there, "everyone knows it's not necessary". I think spelling it out is sometimes pedagogical and sensible.
Sometimes this is 100% necessary, for example if you start interlaced copper list or copper list has side-effects (writes to intreq, uses blitter etc..). Triggering copper list twice very quickly (once by manual COPJMP1 write and then again when vblank starts or vice versa) can cause random "unexplained" glitches.
Toni Wilen is online now  
Old 23 March 2013, 22:38   #10
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
I know the exceptions, and I bet you see some weird and sometimes incorrectly programmed startups that you have to handle But as I see it the topic is about a normal startup and what should be in it.

If I were to nitpick I could f.ex. say that you don't have to save/restore the stack pointer, because if it were trashed you wouldn't RTS to the code that restores it.

Startup code is a relative thing. There is no way to write a perfectly safe wrapper, if you were to do proprietary things with the hardware as if it were your own, if it's executed while a task using a shared hardware resource is running, for example running a custom hardware-musicplayer while running a modplayer with the OS.
Photon is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AmigaXL install error (tar exit code) kayt support.Apps 3 28 July 2010 23:00
Cannot exit from Some games @UAE project.WHDLoad 13 19 November 2008 13:28
WinUAE crashes on exit glwxxx support.WinUAE 13 19 August 2006 11:41
OS 3.9 can't exit and some more problems Tea support.WinUAE 1 09 July 2003 12:51
WHERE is the goddammit exit (Leander)? T.R.Schmidt support.Games 2 08 April 2003 15:42

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:03.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.17292 seconds with 13 queries