Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
T9000 HL reg issue
#1
While debugging my game, I found 1 strange issue.


I had a method to print an integer which starts like this :

Code:
void VDP_printInteger(u8 planeId, u8 xpos, u8 ypos, u8 palId, u16 number, u8 length, u8 leading){
    u16 *vramAddr = SCROLL_PLANE_1; 

looking at the code produced, it sets HL to 0x9000, nothing wrong here

later on my game, I do a collide test

Code:
unsigned char testCollide( ){
if (collide)
    return1

return 0;
}

this will produce a LD L,1
nothing wrong here too


my problem is with this code

Code:
if (testCollide( ) == 1)
{
     doSomething();
}

it will produce a CP HL, 1
not a CP L, 1

if I call VDP_printInteger BEFORE testCollide, HL = 9001, and so the test is "wrong"


I solved the issue using adecl, to force cleaner use of register XWA, XBC, XDE and XHL.  but  what should be done to avoid that ?!
Unless using adecl on every function using HL (sic!), I see no way to avoid this.....

what is even worst is that another similar test, with same return type
if ( testCollideNPC() == 1)
works like a charm! 

I found a "fix" but I didn't find the reason so if anyone had an idea, let me know Smile

Note: I'm actually trying to export the asm of every C file, to see where the problem happens on other methods but -la doesn't since to work.....
Reply
#2
The second method (which works) generates a CP L, 1
I do not understand why THIS one generate a CP HL, 1

....
Reply
#3
I FOUND IT !

I forgot to include the header file where testCollide is declared as unsigned char testCollide

Since the compiler didn't find it at pre processor time, it handles it by default to int.

I'm now looking for the option to generate a warning/error in this case because it will certainly happens again...and it costs hours to find the real reason !!!

edit : -w3 is the one to generate a Undefined return type in 'xxxx' warning
-w1 and -w2 are too soft....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)