Welcome, Guest. Please login or register.

Author Topic: API Question  (Read 1071 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline trekiejTopic starter

API Question
« 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.
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline AndrewBell

  • Sr. Member
  • ****
  • Join Date: Jun 2007
  • Posts: 343
    • Show only replies by AndrewBell
Re: API Question
« Reply #1 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
« Last Edit: February 16, 2011, 04:47:27 AM by AndrewBell »
Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.
 

Offline Zac67

  • Hero Member
  • *****
  • Join Date: Nov 2004
  • Posts: 2890
    • Show only replies by Zac67
Re: API Question
« Reply #2 on: February 15, 2008, 07:25:11 AM »
Have u tried Wikipedia?
 

Offline AndrewBell

  • Sr. Member
  • ****
  • Join Date: Jun 2007
  • Posts: 343
    • Show only replies by AndrewBell
Re: API Question
« Reply #3 on: February 15, 2008, 07:29:15 AM »
@Zac67

Weird coincidence: My home town is twinned with yours.
________
G-POWER
« Last Edit: February 16, 2011, 04:47:36 AM by AndrewBell »
Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.
 

Offline motorollin

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: API Question
« Reply #4 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
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline trekiejTopic starter

Re: API Question
« Reply #5 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.
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: API Question
« Reply #6 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, and that varies between systems so I'm not going into specifics).
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: API Question
« Reply #7 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!

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: API Question
« Reply #8 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.
 

Offline trekiejTopic starter

Re: API Question
« Reply #9 on: February 15, 2008, 08:59:49 PM »
@ Piru
http://en.wikipedia.org/wiki/System_call
I did see Wikipedia earlier and it helps.
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: API Question
« Reply #10 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.

Offline trekiejTopic starter

Re: API Question
« Reply #11 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.
Amiga 2000 Forever :)
Welcome to the Planar System.