Adding Rand crate (or possibly other no std lib ones) #3
-
Hey I tried installing the OK so I'm sure I would have done better asking you first for advice on this, but instead I created a StackOverflow issue because the question wasn't asked there yet. I have an inkling that the question is gravitating towards the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
True enough, there's no The |
Beta Was this translation helpful? Give feedback.
-
Oh before I forget, I managed to get this working! Thanks to Stephane-D/SGDK, I ported their code over: const GFX_HVCOUNTER_PORT: u32 = 0xC00008;
struct PseudoRng {
current_rand: u16,
}
impl PseudoRng {
// Thank you Stephane Dallongeville!
pub fn from_seed(seed: u16) -> PseudoRng {
PseudoRng {
current_rand: seed ^ 0xD94B // XOR with some val to avoid 0
}
}
pub fn random(&mut self) -> u16 {
unsafe {
// https://github.com/Stephane-D/SGDK/blob/908926201af8b48227be4dbc8fbb0d5a18ac971b/src/tools.c#L36
let hv_counter = read_volatile(&GFX_HVCOUNTER_PORT) as u16;
self.current_rand ^= (self.current_rand >> 1) ^ hv_counter;
self.current_rand ^= self.current_rand << 1;
self.current_rand
}
}
} As a rather dubious achievement, it's the first time I've used the |
Beta Was this translation helpful? Give feedback.
True enough, there's no
libc
on the Mega Drive. Judging by your Stack Overflow post, you're running it without default features though, which shouldn't depend on it. I'm happy to take a look if you've got it spitting out some logs!The
cargo megadrive
command is purely for building the final Mega Drive image, it largely just does acargo build --release
and then composes the output into the MD image format. Libraries built as part of that (or just building libraries on their own) can just use regular cargo. (I'm guessing that you've added this as a dependency to your game though!)