implemented some Z80 and randseeding
This commit is contained in:
+30
-6
@@ -8,10 +8,35 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef __CC65__
|
||||
#if defined(__CC65__) || defined(__Z80__)
|
||||
#define RETRO_IMPL
|
||||
#endif
|
||||
#ifndef RETRO_IMPL
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
char scanchar() {
|
||||
char c;
|
||||
scanf(" %c", &c);
|
||||
return c;
|
||||
}
|
||||
|
||||
#ifdef RETRO_IMPL
|
||||
void randomize() {
|
||||
int seed = 0, i, x, n = 6;
|
||||
printf("\nType %d characters: ", n);
|
||||
for(i=0;i<n;i++) {
|
||||
x = (int) scanchar();
|
||||
x ^= x << 7;
|
||||
x ^= x >> 9;
|
||||
x ^= x << 8;
|
||||
seed ^= x;
|
||||
}
|
||||
srand(seed);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* UI choices */
|
||||
#define CH1 0
|
||||
#define CH2 1
|
||||
@@ -51,7 +76,7 @@ void print_msg(char *s) {
|
||||
char get_choice() {
|
||||
char c, res;
|
||||
printf("Your choice: ");
|
||||
scanf(" %c", &c);
|
||||
c = scanchar();
|
||||
switch(c) {
|
||||
case 'a':
|
||||
case 'A':
|
||||
@@ -88,8 +113,7 @@ char get_choice() {
|
||||
int confirm(char *prompt) {
|
||||
char c, d;
|
||||
printf("%s", prompt);
|
||||
c = getchar();
|
||||
scanf(" %c", &c);
|
||||
c = scanchar();
|
||||
if(c == 'y' || c == 'Y') d = 1;
|
||||
else d = 0;
|
||||
printf("\n");
|
||||
@@ -322,8 +346,8 @@ int game() {
|
||||
/* Entry point */
|
||||
int main() {
|
||||
int score;
|
||||
#ifdef __CC65__
|
||||
_randomize();
|
||||
#ifdef RETRO_IMPL
|
||||
randomize();
|
||||
#else
|
||||
srand(time(NULL));
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user