Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

#1 2021-08-25 15:58:52

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

GBDK 2020 problems.

GBDK 2020 will give a warning about the following code:

Code:

unsigned char *ptr_div_reg = 0xFF04; 
unsigned char random_number = *(ptr_div_reg);

Converting integral to pointer without a cast 'cons-unsigned-int literal' 'unsigned-cjar generic* auto'

And not only that, it's super slow to compile. I liked the older version better. I could put this on a single line:

Code:

    set_sprite_data(2, 2, tarantula);
    set_sprite_tile(2, 3);

like so:

Code:

     
set_sprite_data(2, 2, tarantula),    set_sprite_tile(2, 3);

My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#2 2021-08-25 18:04:45

toxa
Member
Registered: 2020-02-13
Posts: 300

Re: GBDK 2020 problems.

That is absolutely correct warning. You should cast integer to pointer.
Inline functions were fixed in recent sdcc builds. Did you compile gbdk-2020 yourself or downloaded binaries from github releases section?

Offline

 

#3 2021-08-26 09:06:55

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: GBDK 2020 problems.

I downloaded the binaries from github.
But why did the first thing work okay in the previous GBDK and give no warnings at all?


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#4 2021-08-26 12:01:30

toxa
Member
Registered: 2020-02-13
Posts: 300

Re: GBDK 2020 problems.

Because old gbdk is full of bugs and problems. Support for inline functions is new in sdcc, so there were some known problems. On the other hand that gives significant performance gain. set_sprite_tile() is 10 times faster in gbdk-2020 than in old gbdk 2.96.

Last edited by toxa (2021-08-26 12:05:46)

Offline

 

#5 2021-08-26 12:22:52

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: GBDK 2020 problems.

I discovered how to get random numbers again.

Code:

tarantulax=DIV_REG % 128

gives tarantulax a random numebr between 0 and 128.


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#6 2021-08-27 04:18:57

toxa
Member
Registered: 2020-02-13
Posts: 300

Re: GBDK 2020 problems.

those numbers will not be random. better use rand.h. you may initialize rand seed (once, when user press START button) with that value, that will give fine result.

Last edited by toxa (2021-08-27 04:20:57)

Offline

 

#7 2021-08-27 11:31:54

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: GBDK 2020 problems.

How do I put the result into the game? I looked at DeepScan code and it was all stuff I don't understand.


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#8 2021-09-05 03:14:17

bbbbbr
Member
Registered: 2019-03-04
Posts: 123

Re: GBDK 2020 problems.

Look into the "rand" sample

Offline

 

#9 2021-10-01 23:13:31

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: GBDK 2020 problems.

I got the game working again. I got rid of the %s and replaced them with division. But this begs the question: What do %s do to a number?


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#10 2021-10-03 10:52:34

0x7f
Member
Registered: 2019-11-24
Posts: 65

Re: GBDK 2020 problems.

The modulo operator gives back the rest of a division.

4 % 8 gives back the rest of 4 / 8 = 4
8 % 8 gives bakc the rest of 8 / 8 = 0

x % 8 will create numbers between 0 and 7. But please avoid using modulo or division because they are very slow. Its better to use the AND operator to limit the random number.

rand() & 3 (0011b) will generate a random number between 0 and 3
rand() & 7 (0111b) will generate a random number between 0 and 7

Offline

 

#11 2021-10-04 17:10:05

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: GBDK 2020 problems.

Thanks for the reply. I found that if I run rand and then divide it by 128, I can get a number between 0 and 1. Dividing it by 64 gets me a number between 0-3, and so on.


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson