Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

math library #36

Open
rustyoz opened this issue Apr 23, 2012 · 7 comments
Open

math library #36

rustyoz opened this issue Apr 23, 2012 · 7 comments

Comments

@rustyoz
Copy link
Contributor

rustyoz commented Apr 23, 2012

a good goal would be for a library supporting

  • 32 bit signed arithmetic (add, sub, mul div)
  • 32 bit signed fixed point fraction arithmetic ie 16.16

i good starting point might be entropers library https://github.com/Entroper/DCPU-16-fixedmath and a fork from vertarmis https://github.com/vietarmis/DCPU-16-fixedmath/blob/1e2e4ed49bd0e12923ee39e0b1a312fe5ef2314a/fixedmath.dasm

@chessmaster42
Copy link
Member

Sounds good and I think that we should start looking at compiling libraries into binaries using a variation of the ABI format. Make it like loading a dll.

@chessmaster42
Copy link
Member

Ignore what I said earlier. We will just compile this into the library.dasm16 file for now.

@chessmaster42
Copy link
Member

Plusmid and I are working on the format for the equivalent of .dll or .so using the ABI format for libraries. I think we should make a math lib as our first external library. The library will be setup like a normal program but will have a jumptable that is setup like this:

:libmath_api
dat add_32
dat sub_32
dat mul_32
dat div_32
:libmath_api_end

Thoughts?

@rustyoz
Copy link
Contributor Author

rustyoz commented Apr 30, 2012

sounds good. they way atlas has gone, even though its partly my working, it is getting beyond my skills.
im guessing that programs will have a code at their start to load in libraries.
functions in the application go to their jump table, then to the libs jump table find the function address and then run the subroutine?

@chessmaster42
Copy link
Member

What will happen is that the program will call a function named, say, lib_run_func, and set A to a buffer with the library name and B to a buffer with the function name like this:

SET A, myLibName
SET B, myLibFuncName
JSR lib_run_func (this would be translated to the API location [0x1234] format)

Then the OS function lib_run_func searches through the loaded libraries list, finds the library with the matching name, then searches through the jump table of the library to find the function. If it finds it, it then runs it using params pushed onto the stack or maybe registers.

@rustyoz
Copy link
Contributor Author

rustyoz commented Apr 30, 2012

ok that makes sense. what about having the lib_run_func use some other registers like x and y so registers a and b which are commonly used don't need to be pushed to the stack as often. if someone makes a library using registers a and b as parameters they wouldn't need to do as much work porting it to atlas by making the functions pop a and b back from the stack.

@noxer
Copy link
Member

noxer commented Jun 20, 2012

Then X and Y need to be pushed. The problem is you never know if registers are unused or not.
Chessmaster is wrong this his statement the lib_run_func will search the library table. This would take too much time. My approach is to request the library handler first and then the function addresses:

; Get Library handler
SET A, my_lib_name
JSR lib_get_instance
SET B, A

; Get function address
SET A, my_lib_func1
JSR lib_get_func

; Save address for future use
SET [my_lib_addr1], A

; Call the function
JSR [ly_lib_addr1]

; Free the handle (so the library can automatically be unloaded if the instance counter reaches 0)
SET A, B
JSR lib_free_instance

This may be a bit more compicated but this will (hopefully) be done by the compilers /assemblers later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants