0
|
1 #include<stdio.h>
|
|
2
|
|
3 #define PAD_BUFSIZ 32
|
|
4 #define RESET_BUTTON 768
|
|
5
|
|
6 #ifdef ENABLE_TRACEMODE
|
|
7
|
|
8 static FILE *pad_fp;
|
|
9 static char pad_buf[PAD_BUFSIZ];
|
|
10
|
|
11 void pad_trace(unsigned int pad)
|
|
12 {
|
|
13 fprintf(pad_fp, "%d\n", pad);
|
|
14 }
|
|
15
|
|
16 int pad_file_open(char *f)
|
|
17 {
|
|
18 pad_fp = fopen(f, "r+");
|
|
19 if (!pad_fp) {
|
|
20 // 本当はerrnoをチェックするのがいいんだろうなぁ
|
|
21 pad_fp = fopen(f, "w+");
|
|
22 if (pad_fp) {
|
|
23 return 0;
|
|
24 }
|
|
25 // goto dbg_abort(4);
|
|
26 return 1;
|
|
27 }
|
|
28 return 0;
|
|
29 }
|
|
30
|
|
31 int pad_file_read()
|
|
32 {
|
|
33 int padd;
|
|
34 if (fgets(pad_buf, PAD_BUFSIZ, pad_fp)) {
|
|
35 sscanf(pad_buf, "%d", &padd);
|
|
36 return padd;
|
|
37 }
|
|
38 return RESET_BUTTON;
|
|
39 }
|
|
40 #endif //ENABLE_TRACEMODE
|
|
41
|
|
42 #ifdef USE_MYRAND
|
|
43 static FILE *myrand_fp;
|
|
44 extern int runmode;
|
|
45
|
|
46 int myrand_open_file(char *filename)
|
|
47 {
|
|
48 myrand_fp = fopen(filename, "r+");
|
|
49 if (!myrand_fp) {
|
|
50 myrand_fp = fopen(filename, "w+");
|
|
51 if (myrand_fp) {
|
|
52 return 0;
|
|
53 } else {
|
|
54 return 1;
|
|
55 }
|
|
56 }
|
|
57 return 0;
|
|
58 }
|
|
59
|
|
60 static char buf[16];
|
|
61
|
|
62 int myrand()
|
|
63 {
|
|
64 int r = 0;
|
|
65 if (runmode) {
|
|
66 if (runmode == 1) {
|
|
67 r = rand();
|
|
68 fprintf(myrand_fp, "%d\n", r);
|
|
69 } else if (runmode == 2) {
|
|
70 // dbg_printf("check0\n");
|
|
71 if (fgets(buf, 16, myrand_fp)) {
|
|
72 sscanf(buf, "%d", &r);
|
|
73 } else {
|
|
74 fseek(myrand_fp, 0, SEEK_SET);
|
|
75 }
|
|
76 }
|
|
77 } else {
|
|
78 r = rand();
|
|
79 }
|
|
80 return r;
|
|
81 }
|
|
82 #endif // USE_MYRAND
|