English Amiga Board


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

 
 
Thread Tools
Old 30 April 2018, 09:10   #1
fstarred
Registered User
 
fstarred's Avatar
 
Join Date: Mar 2018
Location: Rome
Posts: 173
Proper way to open library?

Altough I guess it's a very basic question, I can't find a proper way on how properly open a library.

1st issue:

I've found this snippet on this link:

Code:
_AbsExecBase EQU  4          ;System pointer to Exec's library base

        XREF    _LVOOpenLibrary       ;Offset from Exec base for OpenLibrary()
        XREF    _LVOCloseLibrary      ;Offset from Exec base for CloseLibrary()
        XREF    _LVODisplayBeep       ;Offset from Intuition base for DisplayBeep()

        move.l  _AbsExecBase,a6       ;Move exec.library base to a6
        lea.l   IntuiName(pc),a1      ;Pointer to "intuition.library" string
        moveq   #33,d0                ;Version of library needed
        jsr     _LVOOpenLibrary(a6)   ;Call Exec's OpenLibrary() and
        tst.l   d0                    ;check to see if it succeeded
        bne.s   open_ok
        moveq   #20,d0                ;Set failure code
        rts                           ;Failed exit

open_ok move.l  d0,a6                 ;Put IntuitionBase in a6.
        suba.l  a0,a0                 ;Load zero into a0
        jsr     _LVODisplayBeep(a6)   ;Call Intuition's DisplayBeep()

        move.l  a6,a1                 ;Put IntuitionBase into a1
        move.l  _AbsExecBase,a6
        jsr     _LVOCloseLibrary(a6)  ;Call Exec's CloseLibrary()
        moveq   #0,d0                 ;Set return code
        rts

IntuiName:      dc.b 'intuition.library',0
        END

Running from Amiga 600 it fails on _LVOOpenLibrary(a6) with Illegal Instruction Raised error (AsmOne).

2nd issue:

I often see the offset of the function declare on top of the source, like this :

_LVODelay EQU -198

Now I wonder, how can I obtain the offset of the function I wish to use ?

Can you give me some hints ?
Thank you
fstarred is offline  
Old 30 April 2018, 09:49   #2
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
This code needs to be linked as _LVOOpenLibrary, _LVOCloseLibrary and _LVODisplayBeep are external references (XREF) hence the illegal instruction. You can find the LVO's in the include files for each library, e.g. Exec's LVO's can be found in exec/exec_lib.i.
StingRay is offline  
Old 30 April 2018, 10:19   #3
fstarred
Registered User
 
fstarred's Avatar
 
Join Date: Mar 2018
Location: Rome
Posts: 173
Sorry I can't get it, I've tried adding

include "dh1:/asmone/Include/intuition/intuition_lib.i" at top of the source of the first post, however I receive this compilation error:

Double symbol
XREF _LVODisplayBeep

EDIT
Yes it would work by adding:

_LVODisplayBeep = -96
_LVOOpenLibrary = -552
_LVOCloseLibrary= -414

or

INCDIR "dh1:/asmone/Include/"

include exec/exec_lib.i
include intuition/intuition_lib.i


and removing XREF, however I'd like to know how to use the other way with XREF ?

Last edited by fstarred; 30 April 2018 at 10:37.
fstarred is offline  
Old 30 April 2018, 10:49   #4
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
If you're just learning asm you'll have less troubles in doing things "by hand".
In short : do not mess with includes and use numbers directly. They work everywhere and you know exactly what you're doing. Just keep the function names at their side to keep the readability.

Your code can be rewritten as :
Code:
 move.l 4.w,a6           ; exec base
 lea IntuiName(pc),a1
 moveq #33,d0
 jsr -$228(a6)           ; OpenLibrary
 tst.l d0
 bne.s open_ok
 moveq #20,d0            ; set failure code
 rts
open_ok
 move.l d0,a6            ; IntuitionBase
 suba.l a0,a0
 jsr -96(a6)             ; DisplayBeep
 move.l a6,a1
 move.l 4.w,a6
 jsr -$19e(a6)           ; CloseLibrary
 moveq #0,d0
 rts

IntuiName dc.b "intuition.library",0
meynaf is online now  
Old 30 April 2018, 11:10   #5
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by fstarred View Post
and removing XREF, however I'd like to know how to use the other way with XREF ?
You will have to use a linker in that case! Since you are apparently just starting don't worry about that yet, try to grasp the basics first, then read up on how to use linkers.
StingRay is offline  
Old 01 May 2018, 01:28   #6
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 839
Just use the includes, why would you go out of your way to have to link code or type in all those offsets by hand?

I have my own set of macros so I can do
SYS Disable
which assumes a6 has the library base already, or
DOS Open
which assumes I can trash a6 and have a label named DOSBase where my pointer to dos.library is stored. All of which depends on the includes being used.
NorthWay 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
Open-source dos.library Don_Adan Coders. System 273 02 September 2020 00:42
cannot open rtg.library AGS support.WinUAE 6 02 April 2015 18:41
AWeb can't open asl.library carloratm support.Apps 11 03 June 2014 08:04
dos.library Open() hangs MrD Coders. Asm / Hardware 15 24 July 2012 19:55
unable to open reqtools.library RabidRabbit support.WinUAE 6 31 March 2009 13:43

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 18:10.

Top

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