SDCC DivuInt

edited February 2015 in Development
when I divide an integer
sdcc wants to import a function called divuint

I think it used to be in z80.lib but now it doesnt seem to be in there.
Im looking in
usr/local/share/sdcc/lib/src/z80
and it has divusigned.a
but no divuint
Post edited by slenkar on

Comments

  • edited February 2015
    I'm using windows so my directory structure might be a bit different. I'm also using the current version in svn, not the last release. There was a change in all the primitive names but I think that happened before the last release.

    My copy of sdcc/device/lib/divunsigned.s is exporting two symbols:

    .globl __divuint
    .globl __divuchar

    You can see if that symbol is defined inside z80.lib by running the archive program on it (you may have to look that up in the manual as I don't know what it is on sdcc offhand). I think the library format is plain text so maybe a search in a text editor will see if the definition is there too (as opposed to a call).
  • edited February 2015
    yeah I opened up the file in a text editor and it said divuint,
    I am including z80.lib in the build but I still get the error for some reason

    could you take a look at my makefile to see if Im doing anything wrong please?
    all: $(targetname).tap

    OBJECTS = Globals.lib graphics.lib menu.lib path.lib Dungeon.lib controls.lib UnitFunctions.lib



    $(targetname).tap: $(targetname).bin
    Bin/bin2tap -b -a 25000 -c 24999 -r 25000 -o $(targetname).tap $(targetname).bin
    fuse-sdl $(targetname).tap

    $(targetname).bin: $(targetname).ihx
    Bin/hex2bin $(targetname).ihx

    $(targetname).ihx: $(targetname).c $(OBJECTS)
    sdcc $(targetname).c -mz80 --code-loc 25000 --stack-loc 62000 --data-loc 40000 --no-std-crt0 -I Lib -I Obj $(OBJECTS)


    %.lib: %.rel
    sdcclib $@ $<

    %.rel:%.c %.h
    sdcc -mz80 -c $< -I Lib
    clean:
    rm *.lib *.rel *.ihx *.bin
  • edited February 2015
    slenkar wrote: »
    I am including z80.lib in the build but I still get the error for some reason

    You don't have to include anything -- I think the "-mz80" will cause the z80.lib to be linked against.
    sdcc $(targetname).c -mz80 --code-loc 25000 --stack-loc 62000 --data-loc 40000 --no-std-crt0 -I Lib -I Obj $(OBJECTS)
    

    The "-I" are for specifying include paths -- I assume you know what you are doing there. Other than that, I don't see a crt file. It needs to be the first file on this compile line because it sets up the memory map. I'm not sure if that would cause a symbol not found error.
  • edited February 2015
    thanks for helping
    I put the whole file path of the crt0.rel file in the command line but still get the same errors. I am using the latest version, so I could try downgrading
  • edited February 2015
    ok downgrading didnt help.

    I compiled divuint.c myself and included it, and the game compiled.

    It resets the spectrum though.

    I put this in my main function at the beginning:
    __asm
    LD SP,#50000


    __endasm;

    but it doesnt make any difference

    EDIT-
    ok after putting this in the compilation:
    --no-std-crt0

    it actually works but the stack is still at 29969, 31 bytes behind the code

    it still crashes after a few pathfinds, i dont know why doing a pathfind a certain number of times would cause the stack to grow,
    if the pathfind function was too much for the stack it would crash on its first use surely
  • edited February 2015
    slenkar wrote: »
    I put this in my main function at the beginning:
    __asm
    LD SP,#50000


    __endasm;

    but it doesnt make any difference

    You can't put it in main as the first thing main will do is create a stack frame before your inline asm runs. It should be done in your crt file.

    Without seeing your source it's hard to say exactly what is going on. You could open up a debugger screen in your emulator after loading the binary and have a look at the asm that was generated, at least the beginning to see what is going on with sp.
    it actually works but the stack is still at 29969, 31 bytes behind the code

    The stack grows down so that may not be a problem.
    it still crashes after a few pathfinds, i dont know why doing a pathfind a certain number of times would cause the stack to grow,
    if the pathfind function was too much for the stack it would crash on its first use surely

    Maybe. Have you tried compiling with "--reserve-regs-iy" for all your files? I'm wondering if you still have the basic isr running, which uses iy. sdcc may use iy if you don't have that flag set.

    The "-I" option is also for the include path (ie looking for header files) -- I don't know if you meant "-L" which is for library search path.
  • edited February 2015
    i tried --reserve-regs-iy but it crashes with some flashing blocks

    my machine code functions use iy so I dont know if that is the reason?

    -L lib didnt work,
    I remember that when I used to use SDCC in the past i set interupt mode to 1.
    I put IM 1 in the main function and the stack actually appeared close to 50000

    It still crashes after a few pathfinds though
  • edited February 2015
    slenkar wrote: »
    i tried --reserve-regs-iy but it crashes with some flashing blocks

    my machine code functions use iy so I dont know if that is the reason?

    I haven't seen sdcc use iy very often unless the optimization level is turned up. With "--max-allocs-per-node 200000" it always uses iy. But it expects both ix and iy to be unchanged. The rom isr is troublesome because it will poke values into the system vars area (iy+?) and sdcc will often have iy pointing into the stack so the rom isr will corrupt the stack. Incidentally, this will also happen if your m/c is using iy and maybe this is the problem. You'll have to provide your own isr or disable interrupts. Try a "di" in your main and see if you get further.

    If you have the rom isr running you will have to use "--reserve-regs-iy" for all the sdcc compiles. If your m/c is using iy it isn't compatible with the rom isr.
    -L lib didnt work,

    You might have to specify full path. Maybe "./lib"?
  • edited February 2015
    Thanks for the help, nothing has worked so I'm gonna just give up with sdcc
Sign In or Register to comment.