14 July 2017, 16:31 | #21 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Thanks a lot for the example, alkis, I've learned a lot from it. Unfortunately, it doesn't want to link:
Code:
execString: vlink -s -bamigahunk -o foo foo.o "E:\Amiga\Dev\NDK_3.9\Include\linker_libs\amiga.lib" Error 32: Target amigahunk: Unsupported relocation type R_PC (offset=0, size=16, mask=ffffffffffffffff) at text+0x10. Alright, now let's try to take the next (logical, at least for me) step: turning this into a proper linkable library (.lib will do, for now). Is that just a question of defining some labels and throwing in some rts's when your function is done? Anyone have any stub code you could quickly post? Also, your code seems to reference a function _printf in amiga.lib, which I assume is this function (but then prefixed with an underscore): http://amigadev.elowar.com/read/ADCD.../node0162.html Do those (auto-) docs contain an exhaustive list of everything in amiga.lib? Are these the reference/definitive docs? Btw, those kind of functions are exactly what I'm trying to make myself. The mentioned _printf function takes its arguments from the stack, probably because there can be up to 9. But if you were to, say, write a function that adds 2 numbers together, you'd probably assume those numbers to be in some agreed upon registers, right? |
14 July 2017, 20:10 | #22 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
First, linking problem.
Modify makefile to read Code:
foo: foo.asm mymacros.i $(AS) -esc -Fhunk -o foo.o foo.asm $(LD) -s -sc -bamigahunk -o foo foo.o amiga.lib Line 17 is correct, printfused should be 1 instead of -1. Also the two first lines should be setting variables to -1. The logic is this (idea totally stollen from Thorham's macros) The first time you use printf, the system needs _stdout to have a proper value, so you initialise _stdout by the return value of DOS/Output() But what happens on your second or third printf? You keep initialising it again and again. So you put a guard against it. You define a variable printfused and initially set it to 0. And then you have conditional assembly inside the macro asking "is printfused >= 0" (ifge printfused), if so it includes the code but also at the end of that code that you only need to run once, you set the guard variable 'printfused' to -1. So now, the second time you call mprintf the code between 'ifge printfused' and 'endc' won't run. Anyways, I re-attached the corrected code. Yes, the autodocs contain exchausted documentation and should be your _first_ reference when coding for amigaos. (and yes you got the function printf right All variadic functions (functions with variable number of arguments) take their args from stack. I don't quite understand the gist of your last question. Yes, you can have functions accepting arguments on registers. But that's not what you are asking, is it? PS: I messed up the 0,-1 logic far too many times..sorry...regrab source if you have dl'ed already Last edited by alkis; 14 July 2017 at 20:18. Reason: typo |
14 July 2017, 21:20 | #23 | |||
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Solved! Fantastic, thanks a lot!
Quote:
Quote:
Quote:
I could also default to always using the stack (as a lot of .lib functions seem to do), and/or saving all registers upon entering and restoring them back -- but that might generate a lot of unneccesary overhead for simple subroutines. Also, I was asking about putting this functionality in a more reusable kind of form (.lib), but I think I'm almost there right now.. Hang on.. |
|||
14 July 2017, 21:47 | #24 | ||||
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
There is no such a thing. Yes, you can write libraries (*.library). Yes, you can write libs. (*.lib) Yes, you can use autodoc style docementation on anything Quote:
Quote:
(UNLESS otherwise specified in the autodoc of the function, there are a couple of functions that preserve all registers by design) Everything (byte,word,long, char *, void *, whatever *) is returned at d0, as you have noticed. If something bigger than d0 is returned, like long long, I think it's on d0/d1. When you are not sure, just do a quick sketch in C and see how the compiler does it. (gcc -S is your friend or your compiler's equivalent) Quote:
Good |
||||
14 July 2017, 22:01 | #25 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Ok, I finally succeeded in using a .lib file for a reusable subroutine. The printing code is still done through macros, but at least the UByteRep routine is linkable as desired.
I've attached 2 zip files: the stringUtil source (and make-script.py), which you'll have to assemble first to generate stringUtil.lib, which you'll need in a path you'll be including in the second step: PrintDecimal2.zip, containing the exec source, the printing macros include file and also a make script. Works great over here, making me very happy, indeed! |
14 July 2017, 22:17 | #26 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
ok try to present UByteRep's C prototype.
(hint: who's defining the value of a5?) |
14 July 2017, 22:27 | #27 | ||||
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
They sure make maths library functions easier to use.
Yeah, they're parameters. There's also \0 for sizes, so you can do things like this: Code:
foo macro move.\0 \1,\2 endm foo.l #123,d0 Quote:
Code:
dosUtilRelease macro ; close dos.library movea.l _DOSBase,a1 movea.l _SysBase,a6 jsr _LVOCloseLibrary(a6) clr.l _DOSBase endm Quote:
Quote:
You also don't really need amiga.lib. Certainly not for OS calls. Just include this file: LVOs.zip With that you don't need those annoying XREFs for OS calls. You will have to allocate your own storage for things like library bases (I find that cleaner anyway). Quote:
VPrintf calls RawDoFmt (this performs the actual string formatting) and this doesn't handle floating point :http://amigadev.elowar.com/read/ADCD.../node0227.html |
||||
14 July 2017, 22:27 | #28 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
What? Why? You want me to program in C, now, do you?
Uhm, the caller is responsible for declaring enough storage, is this what you mean? Or are you asking why a5 and not a6? |
14 July 2017, 22:38 | #29 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Using a Python script instead of a Makefile is... interesting.
Your library test will become a real test as soon as you have more than one object module in it. Currently it links everything from the library to your executable, as only a single object is present. Try to make a library with two objects and do only reference symbols from one of them. Then verify that only a part of the library code is included in your executable. To answer some of your questions: Code:
XDEF _main ; ?? is this relevant/special ?? Code:
; ?? can't move this to dosUtil.i ?? .fail: Code:
; should probably put this in a data section or something.. Hello: dc.b 'Hello World!!' Read-write data, especially when it is larger, should go into its own data section to keep your code clean and small, and allow PC-relative 16-bit branches as long as possible. |
14 July 2017, 22:51 | #30 | ||
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
Also, I was using AsmPro earlier, and I felt the need for a separately usable linker, for reasons mentioned above, which is how I ended up with vasm/vlink. That and the fact I can now code on Windows, of course.. Quote:
|
||
14 July 2017, 23:19 | #31 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
You gonna need the system includes for other things. Use them. Use the LVOs. Ok, let me see you print VBlankFrequency which is part of SysBase structure without using system includes and linking with amiga.lib. |
|
14 July 2017, 23:20 | #32 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
|
14 July 2017, 23:22 | #33 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Just being pragmatic, here, using what I know. Using makefiles is on my todo list, so please let me know if you happen to know a good make.exe on win..
Quote:
Thanks for that, but I'll need some time to get head around all of this. I might get back to you on this |
|
14 July 2017, 23:38 | #34 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
That's gone way above my head, yet again, I'm afraid. I'll probably get there eventually, hopefully.. |
|
14 July 2017, 23:39 | #35 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
|
15 July 2017, 00:52 | #36 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Riiiiiight.
And here is some modified source. amiga.lib eliminated I rolled my own printf |
15 July 2017, 01:02 | #37 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
Code:
dos.library/Write dos.library/Write NAME Write -- Write bytes of data to a file SYNOPSIS returnedLength = Write( file, buffer, length ) D0 D1 D2 D3 LONG Write (BPTR, void *, LONG) So you could go like Code:
NAME UByteRep -- Writes ascii decimal value of ubyte at buffer SYNOPSIS UByteRep( byte, buffer) D0.b a5 void UByteRep (UBYTE, void *) |
|
15 July 2017, 18:17 | #38 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
|
16 July 2017, 11:55 | #39 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
http://www.equation.com/servlet/equation.cmd?fa=make Quote:
|
||
16 July 2017, 12:34 | #40 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
@phx would it be possible to embed lvo definitions in vasm? That would eliminate even the need for include
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AmiDevCpp and Floats | AmigaEd | Coders. General | 0 | 18 January 2006 03:16 |
|
|