English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 06 October 2017, 21:27   #1
oRBIT
Zone Friend
 
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
Coding a .library in asm?

I'm interested in writing a .library in assembler. What I would be interested in would be some kind of basic example on how to do this properly.. I've got some (very) old assembler-example but I'm having troubles with it so..
Anyone got a library example (suitable for Asm-Pro/Asm-One) lying around?

I also notice, experimenting with this, is that once my test-library has loaded I can't seem to compile it again and add new code (without restarting). Obviously once the library has loaded once it stays in memory. I am pretty sure there's a way of "unloading" the library from memory but have no idea how..?

I wish we had some kind of stackoverflow for Amiga assembly-coders sometimes.
oRBIT is offline  
Old 06 October 2017, 21:31   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
The command to unload unused libraries is "avail flush" from the shell.

Sent from my Prism II using Tapatalk
Samurai_Crow is online now  
Old 06 October 2017, 21:33   #3
Cylon
Registered User
 
Join Date: Oct 2014
Location: Europe
Posts: 470
there is also a 'flushlibs' command somewhere.

Edit
http://aminet.net/package/util/cli/FlushLibs391

for WB3+
Cylon is offline  
Old 06 October 2017, 21:36   #4
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,335
There's assembly source for a sample library in the Amiga ROM Kernel Reference Manual: Libraries.
mark_k is online now  
Old 06 October 2017, 21:51   #5
oRBIT
Zone Friend
 
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
Thanks guys, looks like my code I already had is pretty similar to that example. However my test-library never seems to get "flushed" (even with flushlibs/avail flush) so the constant rebooting keeps annoying me.
Back to bughunting...
oRBIT is offline  
Old 06 October 2017, 21:54   #6
Cylon
Registered User
 
Join Date: Oct 2014
Location: Europe
Posts: 470
It only gets flushed if the opencounter is =0.
Cylon is offline  
Old 07 October 2017, 14:48   #7
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Here is my example code (for PhxAss):
Code:
                              
                incdir          "include:"
                include         "exec/execbase.i"
                include         "exec/initializers.i"
                include         "exec/resident.i"
                include         "lvo/LVOs.i"
                              
;--------------------------------------------------------------------------
                              
                RTS           
                              
ROMTag          DC.W            RTC_MATCHWORD
                DC.L            ROMTag
                DC.L            LibEnd
                DC.B            RTF_AUTOINIT
Ver             DC.B            1                       ; library version
                DC.B            NT_LIBRARY
Pri             DC.B            0
                DC.L            LibName
                DC.L            LibId
                DC.L            LibInit
                              
LibInit         DC.L            LIB_SIZE + 8            ; 8 = private data
                DC.L            FuncTable
                DC.L            DataTable
                DC.L            Init
                              
FuncTable       DC.W            -1
                DC.W            Open    - FuncTable
                DC.W            Close   - FuncTable
                DC.W            Expunge - FuncTable
                DC.W            Null    - FuncTable
                DC.W            Func1   - FuncTable
                DC.W            Func2   - FuncTable
                DC.W            -1
                              
DataTable       INITBYTE        LIB_FLAGS,LIBF_SUMUSED|LIBF_CHANGED
                INITWORD        LIB_REVISION,2          ; library revision
                DC.W            0
                              
Init            MOVEA.L         D0,A1                   ; testbase
                MOVEM.L         A0/A6,LIB_SIZE(A1)      ; seglist, execbase
                RTS           
                              
Open            ADDQ.W          #1,LIB_OPENCNT(A6)
                BCLR.B          #LIBB_DELEXP,LIB_FLAGS(A6)
                MOVE.L          A6,D0
                RTS           
                              
Close           SUBQ.W          #1,LIB_OPENCNT(A6)
                BNE.S           Null
                BTST.B          #LIBB_DELEXP,LIB_FLAGS(A6)
                BEQ.S           Null
                              
Expunge         TST.W           LIB_OPENCNT(A6)
                BEQ.S           kickout
                BSET.B          #LIBB_DELEXP,LIB_FLAGS(A6)
Null            MOVEQ           #0,D0
                RTS           
                              
kickout         MOVEM.L         A5-A6,-(SP)
                MOVEA.L         A6,A5                   ; testbase
                MOVEA.L         (A6)+,A0                ; removing lib node
                MOVEA.L         (A6),A6
                MOVE.L          A0,(A6)
                MOVE.L          A6,4(A0)
                MOVEA.L         A5,A1                   ; testbase
                MOVEQ           #0,D0
                MOVE.W          LIB_NEGSIZE(A5),D0
                SUBA.W          D0,A1                   ; start of memblock
                ADD.W           LIB_POSSIZE(A5),D0
                MOVEM.L         LIB_SIZE(A5),A5-A6      ; seglist, execbase
                JSR             _LVOFreeMem(A6)
                MOVE.L          A5,D0                   ; seglist
                MOVEM.L         (SP)+,A5-A6
                RTS           
                              
LibName         DC.B            "test.library",0
LibId           DC.B            "test.library 1.2",0    ; just an ID-string
                              
;--------------------------------------------------------------------------
                              
                CNOP            0,4
                              
Func1           RTS           
                              
Func2           RTS           
                              
                CNOP            0,4
                             
LibEnd
Attached Files
File Type: lha TestLibrary.lha (3.1 KB, 128 views)

Last edited by PeterK; 10 October 2017 at 01:51.
PeterK is offline  
Old 07 October 2017, 16:32   #8
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Hi PeterK, are you sure about this line?
Code:
FuncTable      DC.W            -1
A clarification (which is not reported in the RKM example):
InitTable->dataTable is not mandatory, you can construct it 'by hand' in InitRoutine.

Last edited by ross; 14 November 2017 at 22:43.
ross is offline  
Old 07 October 2017, 16:43   #9
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Yes, if you enclose the FuncTable with -1 at the top and at the bottom, then you can use word distances relative to FuncTable instead of absolute long addresses.

Of course, there are different possibilities to init a library, it's just my favourite example how to do it.
PeterK is offline  
Old 07 October 2017, 17:01   #10
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by PeterK View Post
Yes, if you enclose the FuncTable with -1 at the top and at the bottom, then you can use word distances relative to FuncTable instead of absolute long addresses.
Thanks for the tips

Last edited by ross; 14 November 2017 at 22:43.
ross is offline  
Old 09 October 2017, 04:30   #11
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Hey oRBIT "Alter Schwede", how is it going with your library? Any progress so far?
PeterK is offline  
Old 09 October 2017, 11:57   #12
oRBIT
Zone Friend
 
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
Still experimenting with it, thanks for asking. Real life (kids and stuff you know) taking too much time.

By the way, you're using custom includes with your example?
oRBIT is offline  
Old 09 October 2017, 20:02   #13
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Ok, I understand, you have your duties. I've no wife, no kids, no job and my life is boring.

No, there are no custom includes for my libraries. I'm using the OS 3.9 includes and a few related to PhxAss. LVOs.i is just an all-in-one collection of many single LVO files.

If you like, I could upload my IconLibDevKit.7z to the Zone, which comes with PhxAss, PhxLnk, PhxAssGUI, some other tools, all includes, autodocs and my configuration.
PeterK is offline  
Old 09 October 2017, 20:14   #14
oRBIT
Zone Friend
 
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
The includes/autodocs (and your LVO-file) might be interesting. I probably have (some of) them but scattered everywhere...
oRBIT is offline  
Old 09 October 2017, 20:27   #15
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
The DevKit is zoned now.
PeterK is offline  
Old 09 October 2017, 21:24   #16
oRBIT
Zone Friend
 
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
Thanks. Got it running in Asm-Pro and it seems to working nicely with "avail flush" aswell.
Thanks.

Only one question..How do I know the offsets for my functions? I mean "func1" and "func2" for example in your code? How do I reach them properly?
"jsr -???(a6)"

Last edited by oRBIT; 09 October 2017 at 21:31.
oRBIT is offline  
Old 09 October 2017, 21:50   #17
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,335
Offset is (-6) × function_number
So Func1 being the fifth function, offset is -30.
mark_k is online now  
Old 23 October 2017, 23:29   #18
Wepl
Moderator
 
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 866
There should be a 'moveq #-1,d0' before the rts at the start.
With that AmigaDOS will tell 'not excutable' when started from the CLI.
Wepl is offline  
Old 23 October 2017, 23:38   #19
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
That MOVEQ #-1,D0 and RTS is only for the idiots who are trying to execute a library directly. Nothing bad will happen if you reduce it to the RTS except that the idiots may get a random return code for RC.

But without this MOVEQ #-1,D0 the following resident structure gets a better longword alignment. That's why I remove this useless instruction.

Last edited by PeterK; 24 October 2017 at 01:54. Reason: some typos
PeterK is offline  
Old 24 October 2017, 00:04   #20
Hedeon
Semi-Retired
 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
You could add a nop after the rts if you want alignment. For a library coded in asm you could check source of the sonnet's powerpc.library. Google sonnet Amiga git.
Hedeon 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
Anyone up for an ASM coding competition? DanScott Coders. Asm / Hardware 526 22 September 2018 21:38
asm coding compo meynaf Coders. Asm / Hardware 66 01 July 2017 22:59
3rd tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 6 26 March 2013 15:57
First tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 46 18 March 2013 12:33
2nd tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 10 17 March 2013 11:49

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 17:48.

Top

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