entropy management for NES port
This commit is contained in:
+17
-8
@@ -40,6 +40,13 @@
|
|||||||
#define NES_GREEN 0x28
|
#define NES_GREEN 0x28
|
||||||
#define NES_YELLOW 0x2A
|
#define NES_YELLOW 0x2A
|
||||||
|
|
||||||
|
/* RNG stuff */
|
||||||
|
static u16 _ez_entropy = 0;
|
||||||
|
|
||||||
|
u16 ezrand() {
|
||||||
|
return ((u16) rand()) ^ _ez_entropy;
|
||||||
|
}
|
||||||
|
|
||||||
/* Graphics section */
|
/* Graphics section */
|
||||||
|
|
||||||
void ppu_off() {
|
void ppu_off() {
|
||||||
@@ -58,6 +65,7 @@ u8 joy_input_wait() {
|
|||||||
while(joy_read(JOY_1));
|
while(joy_read(JOY_1));
|
||||||
/* wait for a new press */
|
/* wait for a new press */
|
||||||
while(1) {
|
while(1) {
|
||||||
|
++_ez_entropy;
|
||||||
joy = joy_read(JOY_1);
|
joy = joy_read(JOY_1);
|
||||||
pressed = joy & ~last_joy;
|
pressed = joy & ~last_joy;
|
||||||
if(pressed & JOY_UP_MASK) return EZJOY_UP;
|
if(pressed & JOY_UP_MASK) return EZJOY_UP;
|
||||||
@@ -141,9 +149,6 @@ void init_sound() {
|
|||||||
/* Game initialization section */
|
/* Game initialization section */
|
||||||
|
|
||||||
void init_game(u8 bg, u8 c1, u8 c2, u8 c3, u8 c4) {
|
void init_game(u8 bg, u8 c1, u8 c2, u8 c3, u8 c4) {
|
||||||
#ifdef _randomize
|
|
||||||
_randomize();
|
|
||||||
#endif
|
|
||||||
init_sound();
|
init_sound();
|
||||||
bgcolor(COLOR_BLACK);
|
bgcolor(COLOR_BLACK);
|
||||||
textcolor(0);
|
textcolor(0);
|
||||||
@@ -156,6 +161,7 @@ void init_game(u8 bg, u8 c1, u8 c2, u8 c3, u8 c4) {
|
|||||||
void wait_for_start() {
|
void wait_for_start() {
|
||||||
u8 joy;
|
u8 joy;
|
||||||
while(1) {
|
while(1) {
|
||||||
|
++_ez_entropy;
|
||||||
joy = joy_read(JOY_1);
|
joy = joy_read(JOY_1);
|
||||||
if(JOY_START(joy)) break;
|
if(JOY_START(joy)) break;
|
||||||
waitvsync();
|
waitvsync();
|
||||||
@@ -165,14 +171,17 @@ void wait_for_start() {
|
|||||||
/* randomize until Start is pressed */
|
/* randomize until Start is pressed */
|
||||||
void wait_for_start_rand() {
|
void wait_for_start_rand() {
|
||||||
u8 joy;
|
u8 joy;
|
||||||
u16 entropy = rand();
|
#ifdef _randomize
|
||||||
|
_randomize();
|
||||||
|
#endif
|
||||||
|
_ez_entropy = rand();
|
||||||
while(1) {
|
while(1) {
|
||||||
++entropy;
|
++_ez_entropy;
|
||||||
joy = joy_read(JOY_1);
|
joy = joy_read(JOY_1);
|
||||||
if(JOY_START(joy)) break;
|
if(JOY_START(joy)) break;
|
||||||
waitvsync();
|
waitvsync();
|
||||||
}
|
}
|
||||||
srand(entropy);
|
srand(_ez_entropy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic helper methods */
|
/* Generic helper methods */
|
||||||
@@ -181,8 +190,8 @@ void wait_for_start_rand() {
|
|||||||
void shuffle(s8 *array, u16 n) {
|
void shuffle(s8 *array, u16 n) {
|
||||||
u16 i, j, t;
|
u16 i, j, t;
|
||||||
if(n > 1) {
|
if(n > 1) {
|
||||||
for(i=n-1;i>0;i--) {
|
for(i=n-1;i>0;--i) {
|
||||||
j = (u16) (rand()%(i+1));
|
j = (u16) (ezrand()%(i+1));
|
||||||
t = array[j];
|
t = array[j];
|
||||||
array[j] = array[i];
|
array[j] = array[i];
|
||||||
array[i] = t;
|
array[i] = t;
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ void win_screen(s16 score) {
|
|||||||
ppu_off();
|
ppu_off();
|
||||||
for(j=0;j<12;j+=4)
|
for(j=0;j<12;j+=4)
|
||||||
for(i=3;i<32;i+=4)
|
for(i=3;i<32;i+=4)
|
||||||
colorxy(i, j, 1 + (rand() % 3));
|
colorxy(i, j, 1 + (ezrand() % 3));
|
||||||
cputsxy(0, 3, " ___ ___ ___ ______ \r\n" \
|
cputsxy(0, 3, " ___ ___ ___ ______ \r\n" \
|
||||||
" | Y | | _ \\ \r\n" \
|
" | Y | | _ \\ \r\n" \
|
||||||
" |. | |. |. | |\r\n" \
|
" |. | |. |. | |\r\n" \
|
||||||
|
|||||||
Reference in New Issue
Block a user