Debugging

SGDK only sub forum

Moderator: Stef

Post Reply
danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Debugging

Post by danibus » Mon Aug 26, 2019 2:43 pm

Hi folks!

I'm writing some SGDK tutorials (in spanish, but google translate is making a good job, here).
Now it's (simple) debug tools turn. At the same time I am learning, lot of years without C programming.

Just learning now about KDebug_AlertNumber()+GensKmod. I have some doubts.

INTEGER (Positive numbers)

Code: Select all

int v = 100;
KDebug_AlertNumber(v);
...
Message window-> 64
That seems ok, as 64h=100d (hex, dec).


INTEGER (Negative numbers)

Code: Select all

int v = -100;
KDebug_AlertNumber(v);
...
Message window-> FFFFFF9C
That seems ok, as -FFFFFF9C h=-100d (hex, dec).
To check this easily:
Open windows CALC program:
Select Windows/Programmer option + Select DWORD + Select HEX, write FFFFFF9C.
Then Select DEC and obtain -100. All ok.
But I have to do manually everytime I check int numbers using KDebug_AlertNumber()


FIX16

Code: Select all

fix16 v = FIX16(5.4);
KDebug_AlertNumber(v);
...
Message window-> 159
Hmmmmm. Not sure about what to do with 159.
I think I need to split int and frac part.

Code: Select all

fix16 v = FIX16(5.4);
KDebug_AlertNumber(fix16Int(v));
KDebug_AlertNumber(fix16Frac(v));
...
Message window-> 140
Message window-> 19

So 140 for integer part and 19 for fractional part. Lets start with 140. So we are checking now 5.0 instead 5.4

Fix16: 1 bit for sign + 9 bits for integer part + 6 bits for fractional part (16 bits in total)

Open windows CALC program:
Select Windows/Programmer option + Select WORD (16 bits) + Select HEX, write 140.
Then Select BIN and obtain 0000 0001 0100 0000

That is 0 (sign bit) + 000 0001 01 (integer part) + 00 0000 (frac part)

0 (sign bit) -> is ok
000000101 = 101 = 5 dec -> is ok
000000 = 0 = 0 dec -> is ok

So all seems ok but not easy to "translate".
Are all these steps the right ones?
Are all these steps necessary? Maybe there is an easy way.



Now 19 for fractional part. So we are checking 0.4
Hmmmm. Not sure what to do now. As I said, lot of years without programming.

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

Re: Debugging

Post by Stef » Mon Aug 26, 2019 2:48 pm

You know you have many KLog_xx(..) functions to take care of different numbering formats ?

Code: Select all


void KLog(char* text);
void KLog_U1(char* t1, u32 v1);
void KLog_U2(char* t1, u32 v1, char* t2, u32 v2);
void KLog_U3(char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3);
void KLog_U4(char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3, char* t4, u32 v4);
void KLog_U1_(char* t1, u32 v1, char* t2);
void KLog_U2_(char* t1, u32 v1, char* t2, u32 v2, char* t3);
void KLog_U3_(char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3, char* t4);
void KLog_U4_(char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3, char* t4, u32 v4, char* t5);
void KLog_U1x(u16 minSize, char* t1, u32 v1);
void KLog_U2x(u16 minSize, char* t1, u32 v1, char* t2, u32 v2);
void KLog_U3x(u16 minSize, char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3);
void KLog_U4x(u16 minSize, char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3, char* t4, u32 v4);
void KLog_U1x_(u16 minSize, char* t1, u32 v1, char* t2);
void KLog_U2x_(u16 minSize, char* t1, u32 v1, char* t2, u32 v2, char* t3);
void KLog_U3x_(u16 minSize, char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3, char* t4);
void KLog_U4x_(u16 minSize, char* t1, u32 v1, char* t2, u32 v2, char* t3, u32 v3, char* t4, u32 v4, char* t5);
void KLog_S1(char* t1, s32 v1);
void KLog_S2(char* t1, s32 v1, char* t2, s32 v2);
void KLog_S3(char* t1, s32 v1, char* t2, s32 v2, char* t3, s32 v3);
void KLog_S4(char* t1, s32 v1, char* t2, s32 v2, char* t3, s32 v3, char* t4, s32 v4);
void KLog_S1_(char* t1, s32 v1, char* t2);
void KLog_S2_(char* t1, s32 v1, char* t2, s32 v2, char* t3);
void KLog_S3_(char* t1, s32 v1, char* t2, s32 v2, char* t3, s32 v3, char* t4);
void KLog_S4_(char* t1, s32 v1, char* t2, s32 v2, char* t3, s32 v3, char* t4, s32 v4, char* t5);
void KLog_S1x(u16 minSize, char* t1, s32 v1);
void KLog_S2x(u16 minSize, char* t1, s32 v1, char* t2, s32 v2);
void KLog_S3x(u16 minSize, char* t1, s32 v1, char* t2, s32 v2, char* t3, s32 v3);
void KLog_S4x(u16 minSize, char* t1, s32 v1, char* t2, s32 v2, char* t3, s32 v3, char* t4, s32 v4);
void KLog_f1(char* t1, fix16 v1);
void KLog_f2(char* t1, fix16 v1, char* t2, fix16 v2);
void KLog_f3(char* t1, fix16 v1, char* t2, fix16 v2, char* t3, fix16 v3);
void KLog_f4(char* t1, fix16 v1, char* t2, fix16 v2, char* t3, fix16 v3, char* t4, fix16 v4);
void KLog_f1x(s16 numDec, char* t1, fix16 v1);
void KLog_f2x(s16 numDec, char* t1, fix16 v1, char* t2, fix16 v2);
void KLog_f3x(s16 numDec, char* t1, fix16 v1, char* t2, fix16 v2, char* t3, fix16 v3);
void KLog_f4x(s16 numDec, char* t1, fix16 v1, char* t2, fix16 v2, char* t3, fix16 v3, char* t4, fix16 v4);
void KLog_F1(char* t1, fix32 v1);
void KLog_F2(char* t1, fix32 v1, char* t2, fix32 v2);
void KLog_F3(char* t1, fix32 v1, char* t2, fix32 v2, char* t3, fix32 v3);
void KLog_F4(char* t1, fix32 v1, char* t2, fix32 v2, char* t3, fix32 v3, char* t4, fix32 v4);
void KLog_F1x(s16 numDec, char* t1, fix32 v1);
void KLog_F2x(s16 numDec, char* t1, fix32 v1, char* t2, fix32 v2);
void KLog_F3x(s16 numDec, char* t1, fix32 v1, char* t2, fix32 v2, char* t3, fix32 v3);
void KLog_F4x(s16 numDec, char* t1, fix32 v1, char* t2, fix32 v2, char* t3, fix32 v3, char* t4, fix32 v4);
:)

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Debugging

Post by danibus » Mon Aug 26, 2019 4:07 pm

Nop, I had no idea.

I see they are in tools.h

Thanks Stef :D

EDIT:

* Using klog() to show int values, works nice

Code: Select all

KDebug_Alert("--- KLog(+INT) ---");
    int m = +1000;
    char s[32];
    intToStr(m, s, 1);
    KLog(s);

    KDebug_Alert("--- KLog(-INT) ---");
    m = -1000;
    intToStr(m, s, 1);
    KLog(s);
    
    ...
    
    Shows: 
    Message : --- KLog(+INT) ---
    Message : 1000
    Message : --- KLog(-INT) ---
    Message : -1000    

* Using KLog_f1() to show fix16 values, works almost nice, but not perfect

Code: Select all

    KDebug_Alert("--- KLog(+FIX16) ---");
    fix16 m16 = FIX16(5.40);
    char *sss = "fix16: ";
    KLog_f1(sss,m16);

    KDebug_Alert("--- KLog(+FIX16 int) ---");
    fix16 m16a = FIX16(5.40);
    m16a = fix16Int(m16a);
    KLog_f1(sss,m16a);

    KDebug_Alert("--- KLog(+FIX16 frac) ---");
    fix16 m16b = FIX16(5.40);
    m16b = fix16Frac(m16b);
    KLog_f1(sss,m16b);
    
    ...
    
    Shows:
    Message : --- KLog(+FIX16) ---
    Message : fix16: 5.39
    Message : --- KLog(+FIX16 int) ---
    Message : fix16: 5.00
    Message : --- KLog(+FIX16 frac) ---
    Message : fix16: 0.39
    
5.39 instead 5.40
But If I use 5.50... shows 5.50 why?

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

Re: Debugging

Post by Stef » Tue Aug 27, 2019 8:07 am

This is just rounding issue because fix16 has very limited precision. fix32 has better but still not perfect too.
Also just to make it more convenient, you can directly use :

Code: Select all

KLog_U1("int:", var);
or

Code: Select all

KLog_f1("", var);
if you don't need any text display before the value :)

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Debugging

Post by danibus » Wed Aug 28, 2019 6:19 pm

Thanks Stef, much clear now, Klog() methods are my prefer ones now. They rock!

Also another question about debugging, is timers/counters.

1. About subticks

Using getSubTick(); can count and using SUBTICKPERSECOND also show how many seconds (according to docs 76800 subticks per second)

You said...
You are using them correctly but sub tick is scanline based (where tick is frame based) so if your code compute is less than one scanline (< 488 68000 cycles) you will get 0.
Also if your code fit in a single VBlank period you will also get inaccurate result.


that means subticks and ticks are working only when drawing??


3. Regarding KDebug_StartTimer(); and KDebug_StopTimer(); they show how many cycles but... what is a cycle? 68K cycles?
I think they are 7.61M cycles/seg... then quantity in Debug window has to be divided with 7.610.000 to get result in seconds.

Post Reply