Small floating point numbers

SGDK only sub forum

Moderator: Stef

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Small floating point numbers

Post by Grind » Thu Sep 22, 2016 12:26 am

Rebuilt the lib?

Code: Select all

%GDK_WIN%\bin\make -f %GDK_WIN%\makelib.gen

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Small floating point numbers

Post by Stef » Thu Sep 22, 2016 8:04 am

So definitely it seems the library was not recompiled otherwise the libmd.a file would be generated.
To compile the library you need to use this command :
%GDK_WIN%\bin\make -f %GDK_WIN%\makelib.gen

This is described in the SGDK wiki :
https://github.com/Stephane-D/SGDK/wiki ... SGDK-basic

Edit: Grind was faster than me !

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Thu Sep 22, 2016 9:24 am

Sorry! I was just indicating I'm referencing the right path in my code :) I've tried deleting and recompiling the library multiple times :)

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Small floating point numbers

Post by Grind » Thu Sep 22, 2016 2:06 pm

Actually, it appears sqrttab16 is declared but not defined (at least in master) :P

https://github.com/Stephane-D/SGDK/sear ... =sqrttab16

https://github.com/Stephane-D/SGDK/sear ... BIG_TABLES

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Small floating point numbers

Post by Stef » Thu Sep 22, 2016 6:02 pm

Hmm.. for me it's here :

https://github.com/Stephane-D/SGDK/blob ... tab_sqrt.c

And of course the declaration in the maths.h file :

#if (MATH_BIG_TABLES != 0)
extern const fix16 log2tab16[0x10000];
extern const fix16 log10tab16[0x10000];
extern const fix16 sqrttab16[0x10000];
#endif


And i tried to use the fix16Sqrt(...) method, it does work as soon you correctly defined the BIG TABLE stuff.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Thu Sep 22, 2016 6:40 pm

could you do an example project and I'll try compiling on mine?

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Thu Sep 22, 2016 7:13 pm

Code: Select all

#include <genesis.h>

void updateStage();

u16 stage;
char line[36];
u16 A;
u16 B;
u16 C;
int main() {

    // disable interrupt when accessing VDP
    SYS_disableInts();
    // initialization
    VDP_setScreenWidth320();
    VDP_setTextPalette(PAL0);
    // VDP process done, we can re enable interrupts
    SYS_enableInts();

    while(TRUE)
    {

        updateStage();

        VDP_waitVSync();

    }

}

void updateStage() {
    switch(stage) {
        case 0 :
            A = 100;
			B = 5;
			C = fix16ToRoundedInt((fix16Sqrt(intToFix16(A + B)) * 100) / 12);
			SYS_disableInts();
			memset(line,0,sizeof(line));
            uintToStr(C, line, 0);
			VDP_drawText(line, 1, 0);
			SYS_enableInts();
			stage++;
		break;
        case 1 :
		break;
    }
}
Wrote my own and still get the same issue

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Small floating point numbers

Post by Stef » Thu Sep 22, 2016 7:56 pm

I just wrote a single line containing the fix16Sqrt(..) operation and it compiled successfully.
Of course i recompiled the library before with big table set to 1.
You can get my libmd file from here : https://dl.dropboxusercontent.com/u/933 ... ve/libmd.a
Try to use it instead of your to see if it makes any difference

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Small floating point numbers

Post by Grind » Thu Sep 22, 2016 8:38 pm

Gonna have to keep in mind the search on github is buggy :oops:

Not sure what else could be going wrong other than maybe the object files in libmd weren't being regenerated.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Thu Sep 22, 2016 9:03 pm

Same problem with your file Stef :/ Could it be because I'm running off an external HD? Something in codeblocks can't be setup right :/ Not got a clue what though it compiles everything else :(

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Thu Sep 22, 2016 9:09 pm

Code: Select all

-------------- Clean: release in MegaRockBandManager (compiler: Sega Genesis Compiler)---------------

Executing clean command: make.exe -f D:\sgdk\makefile.gen clean
D:/sgdk/bin/rm -f out/res/gfx.o out/res/music.o out/res/sound.o out/src/main.o out/sega.o out/rom_head.bin out/rom_head.o out/rom.out
D:/sgdk/bin/rm -f out.lst out/cmd_ out/rom.nm out/rom.wch out/rom.bin
Cleaned "MegaRockBandManager - release"

-------------- Build: release in MegaRockBandManager (compiler: Sega Genesis Compiler)---------------

Checking if target is up-to-date: make.exe -q -f D:\sgdk\makefile.gen release
Running command: make.exe -f D:\sgdk\makefile.gen
D:/sgdk/bin/mkdir -p src/boot
D:/sgdk/bin/mkdir -p out
D:/sgdk/bin/mkdir -p out/src
D:/sgdk/bin/mkdir -p out/res
D:/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/sgdk/inc -ID:/sgdk/res -BD:/sgdk/bin -O1 -fomit-frame-pointer -c src/boot/rom_head.c -o out/rom_head.o
D:/sgdk/bin/ld -T D:/sgdk/md.ld -nostdlib --oformat binary -o out/rom_head.bin out/rom_head.o
D:/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/sgdk/inc -ID:/sgdk/res -BD:/sgdk/bin -O1 -fomit-frame-pointer -c src/boot/sega.s -o out/sega.o
D:/sgdk/bin/rescomp res/gfx.res res/gfx.s
rescomp v1.5
Resource: IMAGE report_layout "Images/clipboard.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE main_menu_layout "Images/mainmenu.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE write_song_layout "Images/WriteSong.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE tour_flags_layout "Images/TourFlags.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE tour_britain_layout "Images/TourBritain.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE tour_europe_layout "Images/TourEurope.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE tour_japan_layout "Images/TourJapan.png" NONE
--> executing plugin IMAGE...
Resource: IMAGE tour_usa_layout "Images/TourUSA.png" NONE
--> executing plugin IMAGE...
Resource: SPRITE hand_sprite "Sprites/Hand.png" 3 4 NONE 1 NONE
--> executing plugin SPRITE...
D:/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/sgdk/inc -ID:/sgdk/res -BD:/sgdk/bin -O1 -fomit-frame-pointer -c res/gfx.s -o out/res/gfx.o
D:/sgdk/bin/rescomp res/music.res res/music.s
rescomp v1.5
D:/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/sgdk/inc -ID:/sgdk/res -BD:/sgdk/bin -O1 -fomit-frame-pointer -c res/music.s -o out/res/music.o
D:/sgdk/bin/rescomp res/sound.res res/sound.s
rescomp v1.5
D:/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/sgdk/inc -ID:/sgdk/res -BD:/sgdk/bin -O1 -fomit-frame-pointer -c res/sound.s -o out/res/sound.o
D:/sgdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -ID:/sgdk/inc -ID:/sgdk/res -BD:/sgdk/bin -O1 -fomit-frame-pointer -c src/main.c -o out/src/main.o
echo "out/res/gfx.o out/res/music.o out/res/sound.o out/src/main.o" > out/cmd_
D:/sgdk/bin/gcc -BD:/sgdk/bin -n -T D:/sgdk/md.ld -nostdlib out/sega.o @out/cmd_ D:/sgdk/lib/libmd.a D:/sgdk/lib/libgcc.a -o out/rom.out
out/src/main.o: In function `processTour':
main.c:(.text+0x1bb8): undefined reference to `sqrttab16'
main.c:(.text+0x1c28): undefined reference to `sqrttab16'
make: *** [out/rom.out] Error 1
rm res/sound.s res/music.s res/gfx.s
Process terminated with status 2 (0 minute(s), 5 second(s))
2 error(s), 0 warning(s) (0 minute(s), 5 second(s))
 

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Thu Sep 22, 2016 9:09 pm

Thats codeblocks output! Can you spot anything off?

Interestingly when I turn the flag to FALSE I get the additional error: "src/main.c:972: warning: implicit declaration of function `fix16Sqrt'"

So the flag must be working :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Small floating point numbers

Post by Stef » Fri Sep 23, 2016 8:30 am

Haha that is insane, i uploaded the wrong libmd.a ^^
I fixed it, now it should compile with the new one i uploaded !
The new file is much more bigger because of the insane size of these tables (128 KB per table and there is 2 of them) , it's why i disable them by default...

Also one reason that it didn't generated the library correctly for you is that you need to rebuild it from whole when you modified the config.h file :

Code: Select all

make -f makelib.gen clean
then

Code: Select all

make -f makelib.gen
Because dependencies are not correctly made in the "lazy" makefile i made, so be sure to use command "rebuild" in codeblocks so it cleans everything before building the library.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Small floating point numbers

Post by matteus » Fri Sep 23, 2016 9:33 am

I'm going to have to think of a better way of doing that calculation as it's a ridiculous amount of cart space to take :(

P.S It works!!! Thank you both for all your help :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Small floating point numbers

Post by Stef » Fri Sep 23, 2016 4:40 pm

Yeah i agree it takes far too much rom space just for that, it's why i'm disabling them by default.
I should add some methods to provide both fast (estimation) or slow (accurate) calculation for log2 and sqrt. In fact i started doing that for log2 with the last SGDK, but not yet for sqrt...

Post Reply