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.
GBDK 2020 will give a warning about the following 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:
set_sprite_data(2, 2, tarantula); set_sprite_tile(2, 3);
like so:
set_sprite_data(2, 2, tarantula), set_sprite_tile(2, 3);
Offline
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
I downloaded the binaries from github.
But why did the first thing work okay in the previous GBDK and give no warnings at all?
Offline
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
I discovered how to get random numbers again.
tarantulax=DIV_REG % 128
gives tarantulax a random numebr between 0 and 128.
Offline
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
Look into the "rand" sample
Offline
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?
Offline
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
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.
Offline