English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 06 February 2011, 19:57   #1
MethodGit
Junior Member
MethodGit's Avatar
 
Join Date: Dec 2002
Location: The Streets
Age: 34
Posts: 2,723
Full guide to TRAP commands?

Are commands like TRAP #0, TRAP #4 etc shortcuts to addresses $80, $90 et al? Are there any catches to using them, and will some games not support them?

Discovered recently that TRAP #F supposedly goes to $C0, so I'm interested.
MethodGit is offline  
Old 06 February 2011, 22:06   #2
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,163
They're not shortcuts as such, but meant to be used to implement OS calls. Basically the CPU goes into supervisor mode, and fetches the corresponding exception vector and subs there, just like any other exception or interrupt. The stack frame could look different on different 68K models.

Trap 0 maps to vector 32, trap 1 maps to vector 33 etc. There are only 16 traps and trap 15 doesn't map to offset $C0 but $BC. These are offsets into the vector base and could be anywhere in RAM on 68010 and above. The vector base is only fixed to address 0 on the 68000.

The full guide you want is the M68K programmer's reference from www.freescale.com which will tell you every detail on this and the rest of the 68K series.
Leffmann is offline  
Old 06 February 2011, 23:17   #3
WayneK
Registered User
 
Join Date: May 2004
Location: Somewhere secret
Age: 44
Posts: 261
Since I know you're into the evil cracking side of things MethodGit, there is no harm (usually) in using them to redirect to your code if space is tight (after all, it's only a word-long instruction to TRAP)... but remember it's an exception, so if you 'jump' into your code using a TRAP you need to return with RTE, not RTS. Check a few games and you'll probably find some with the author's own debugging/error routines hooked into one of the TRAPs (especially common on Sega Megadrive/Genesis games, for some odd reason)!
WayneK is offline  
Old 07 February 2011, 00:58   #4
MethodGit
Junior Member
MethodGit's Avatar
 
Join Date: Dec 2002
Location: The Streets
Age: 34
Posts: 2,723
Quote:
Originally Posted by Leffmann View Post
They're not shortcuts as such, but meant to be used to implement OS calls. Basically the CPU goes into supervisor mode, and fetches the corresponding exception vector and subs there, just like any other exception or interrupt. The stack frame could look different on different 68K models.

Trap 0 maps to vector 32, trap 1 maps to vector 33 etc. There are only 16 traps and trap 15 doesn't map to offset $C0 but $BC. These are offsets into the vector base and could be anywhere in RAM on 68010 and above. The vector base is only fixed to address 0 on the 68000.

The full guide you want is the M68K programmer's reference from www.freescale.com which will tell you every detail on this and the rest of the 68K series.
Having trouble finding it on that website. Is it possible to provide a direct link (if it's something that can be downloaded, of course)?
MethodGit is offline  
Old 07 February 2011, 01:18   #5
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 45
Posts: 6,978
Quote:
Originally Posted by MethodGit View Post
Having trouble finding it on that website. Is it possible to provide a direct link (if it's something that can be downloaded, of course)?
Method, you're making this more complicated than you need to.

Assuming you're coding on 68000 and not anything else, observe!

lea code(pc),a0
move.l a0,$80.w
trap #0
rts

code:
rte

Trap 0 = $80
Trap 1 = $84
Trap 2 = $88 etc, etc

As the trap is considered an exception call, you have to use RTE to return back from a Trap.

So the code above, stores the pointer to code at address $80 (which is TRAP #0), then executes TRAP #0 which will then direct the code to whaever is stored in address $80.

You don't have to return back to the TRAP routine, you could go on and go wherever you like, but if you wanted to return back, the end of the routine that is pointed to in $80 would have to end RTE.

Used extensively on the Atari ST as its used for OS calls.

On the Amiga most people simply used it to setup Supervisor Mode.

The correct way to store address points for use of TRAP instructions is not to assume that the Vector Base is set to 0 as it would be on 68000.

For instance, to PROPERLY install routines for use utilising TRAP instructions we would do the following.

Assumed you've already setup of a system friendly supervisor mode to use MOVEC instructions

movec vbr,d0
move.l d0,a0
lea code(pc),a1
move.l a1,$80(a0)

Note how I move the code pointer to an OFFSET of whatever is returned from the VBR?

TRAP 0 for instance will ALWAYS be at an offset of $80 from the Vector Base

TRAP 1 will ALWAYS be at an offset of $84 from the Vector Base

Only on 68000 can we know the Vector Base will be 0, hence why people simply directly put their address points at address $80 etc.

For proper compatibility, get the VBR, then move pointers at an offset.
Galahad/FLT is offline  
Old 07 February 2011, 01:49   #6
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,163
Quote:
Originally Posted by MethodGit View Post
Having trouble finding it on that website. Is it possible to provide a direct link (if it's something that can be downloaded, of course)?
http://cache.freescale.com/files/arc.../M68000PRM.pdf
Leffmann 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
Zip help commands mickolite support.Apps 5 16 June 2011 21:00
My first guide - Drakkhen leveling guide Fragger Nostalgia & memories 2 08 April 2010 21:35
Amiga ED commands list? boomtopper New to Emulation or Amiga scene 2 18 April 2008 17:40
FIXED: Venus The Fly Trap (TRAP #0) & NOVBRMOVE INFO Retro-Nerd project.Killergorilla's WHD packs 10 01 November 2007 23:42
ANy news on Treasure Trap / Death Trap tomcat666 request.Old Rare Games 2 26 March 2002 07:08

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


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