Amiga.org

The "Not Quite Amiga but still computer related category" => Alternative Operating Systems => Topic started by: trekiej on February 15, 2008, 05:09:06 AM

Title: API Question
Post by: trekiej on February 15, 2008, 05:09:06 AM
I understand that an API is the way a program talks to an OS.  Talks may not be the right term.  
So how does an API connect my app. to my OS?
Is there ports or internal functions the API link?
Is there a web site that can help?
Thanks.
Title: Re: API Question
Post by: AndrewBell on February 15, 2008, 07:23:36 AM
An API is a set of functions, intended to save programmers from having to constantly rewrite common routines.

Example: Windows' DirectX is an API that provides functions used in games, such as 3D graphics, sound playback and joystick input.

How it connects an application to the OS depends upon which OS and API you are talking about.
________
DODGE DEMON HISTORY (http://www.dodge-wiki.com/wiki/Dodge_Demon)
Title: Re: API Question
Post by: Zac67 on February 15, 2008, 07:25:11 AM
Have u tried Wikipedia (http://en.wikipedia.org/wiki/Application_programming_interface)?
Title: Re: API Question
Post by: AndrewBell on February 15, 2008, 07:29:15 AM
@Zac67

Weird coincidence: My home town is twinned with yours.
________
G-POWER (http://www.bmw-tech.org/wiki/G-Power)
Title: Re: API Question
Post by: motorollin on February 15, 2008, 08:03:58 AM
As for how your app "connects" to the API to talk to the OS, no you don't have to establish a "connection" through a port or anything like that. Generally the API functions are manifest in a shared library. You would need to look up in your programming language documentation how to do a shared library call. It might even be called an API call. This command will trigger the shared function within the library from your code.

An example: Let's say you want to write a GUI app for the Amiga. You could write it all from scratch, telling the hardware directly to draw some pixels in a particular place. But that would take ages, so you make the API do it for you. So you make a call to (probably) Intuition, basically saying "draw a window on this screen, in this position, this wide and this high", and Intuition then takes care of the rest for you.

--
moto
Title: Re: API Question
Post by: trekiej on February 15, 2008, 07:53:51 PM
@ Zac67 Wikipedia is where I got my first info. and thanks.

@ Moto

In my opinion a Library works similar to a function.  I would like to know on a low level how an application that I write is able to Interface with the OS.  I believe I understand what an API does but how does it?  If an app. needs to access the disk and requests it through the Kernel how does it request it.
As far as which OS, Linux is one of the targets.
I believe there has to be a way for it to communicate.
Thanks.
Title: Re: API Question
Post by: Piru on February 15, 2008, 08:01:09 PM
It's just like any regular program internal function call, except that it calls external (OS) function (the specifics fall into ABI (http://en.wikipedia.org/wiki/Application_binary_interface), and that varies between systems so I'm not going into specifics).
Title: Re: API Question
Post by: bloodline on February 15, 2008, 08:05:57 PM
No, that's wrong! A library is a collection of related functions...

You open the library, this gives you address of the jump table. The jump table is a list of address pointing the library's functions.

When you want to use one the functions, you goto the jump table and the select the pointer you know points to the function you want (these are at documented offsets). You fill the CPU registers with data, jump to the function and wait for the CPU execution to return to your program, the CPU regs now contain the function result.

Simple really!
Title: Re: API Question
Post by: Piru on February 15, 2008, 08:08:39 PM
@trekiej

Hmm reading the original post, I think you're interested to learn how AmigaOS/m68k library ABI works?

For OS/library calls the A6 typically holds the library base pointer (however, some rare calls don't need it, this is typically documented if so).

Integer arguments go to data registers, pointers to address registers, starting from D0 and A0 (except dos.library which due to legacy reasons has first argument on D1 and uses data registers for pointers too).

Varargs (variable number of arguments) are not directly supported for OS/library calls and these typically are implemeted by passing pointer to the array of the arguments in an address register (taglists for example).

Result (if any) is in D0 (again with some exceptions, dos.library, utility.library and some ARexx libraries also have some other registers returned). Some rare calls are documented to return condition code flags, too.
Title: Re: API Question
Post by: trekiej on February 15, 2008, 08:59:49 PM
@ Piru
http://en.wikipedia.org/wiki/System_call
I did see Wikipedia earlier and it helps.
Title: Re: API Question
Post by: bloodline on February 15, 2008, 09:19:24 PM
Quote

trekiej wrote:
@ Piru
http://en.wikipedia.org/wiki/System_call
I did see Wikipedia earlier and it helps.


AmigaOS (and its clones)  doesn't use interrupt based system calls because every thing runs in a single address space and so there is no need to change memory context. So that wiki article isn't relevant to Amiga programming.
Title: Re: API Question
Post by: trekiej on February 15, 2008, 09:28:49 PM
@ bloodline
I am looking for a generalization and am seeing system calls being the conection I am looking for.
It is at least part of it.
edit 15:47
Looking at Linux System Calls I see it goes even deeper than I thought.