English Amiga Board


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

 
 
Thread Tools
Old 08 March 2013, 17:36   #1
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 48
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, 17:49   #2
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,727
http://eab.abime.net/showpost.php?p=671760&postcount=22
thomas is offline  
Old 18 March 2013, 18:02   #3
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 48
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, 17:16   #4
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,591
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, 18:01   #5
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,712
Why do we clear d0?
BippyM is offline  
Old 21 March 2013, 18:54   #6
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,727
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 offline  
Old 22 March 2013, 12:55   #7
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,220
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, 02:25   #8
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,591
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, 09:07   #9
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,105
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 offline  
Old 23 March 2013, 23:38   #10
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,591
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 29 July 2010 00:00
Cannot exit from Some games @UAE project.WHDLoad 13 19 November 2008 14:28
WinUAE crashes on exit glwxxx support.WinUAE 13 19 August 2006 12:41
OS 3.9 can't exit and some more problems Tea support.WinUAE 1 09 July 2003 13:51
WHERE is the goddammit exit (Leander)? T.R.Schmidt support.Games 2 08 April 2003 16: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 13:17.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.10562 seconds with 15 queries