Browse Source

differentiate errors while printing or detecting printer

Thomas B 3 weeks ago
parent
commit
a6e0daf325
4 changed files with 11 additions and 5 deletions
  1. 1
    1
      src/gbprinter.c
  2. 3
    0
      src/gbprinter.h
  3. 6
    3
      src/gbprinter_error.c
  4. 1
    1
      src/main.c

+ 1
- 1
src/gbprinter.c View File

@@ -172,7 +172,7 @@ enum PRN_STATUS gbprinter_detect(void) BANKED {
172 172
 #ifdef DEBUG
173 173
     EMU_printf("%s: 0x%04x\n",  __func__, (uint16_t)r);
174 174
 #endif // DEBUG
175
-    return r;
175
+    return r | PRN_STATUS_DETECT;
176 176
 }
177 177
 
178 178
 static void win_str_helper(const char *s, uint8_t y_pos) {

+ 3
- 0
src/gbprinter.h View File

@@ -43,6 +43,9 @@ enum PRN_STATUS {
43 43
     PRN_STATUS_TIMEOUT     = 0x200, // timeout waiting for printer response
44 44
     PRN_STATUS_NO_MAGIC    = 0x400, // printer did not respond with proper 'alive'
45 45
 
46
+    // status flags for user code
47
+    PRN_STATUS_DETECT      = 0x800, // set in gbprinter_detect
48
+
46 49
     // masks to check for errors
47 50
     PRN_STATUS_MASK_ERRORS = 0x7F0,
48 51
     PRN_STATUS_MASK_ANY    = 0x7FF,

+ 6
- 3
src/gbprinter_error.c View File

@@ -29,7 +29,9 @@
29 29
 
30 30
 BANKREF(gbprinter_error)
31 31
 
32
-#define ERROR_BITS 11
32
+#define ERROR_BITS 12
33
+
34
+static const char str_ok[] = "ok";
33 35
 
34 36
 static const char str_lowbat[] = "battery too low";
35 37
 static const char str_er2[] = "unknown error";
@@ -42,16 +44,17 @@ static const char str_sum[] = "checksum error";
42 44
 static const char str_cancel[] = "cancelled";
43 45
 static const char str_timeout[] = "timeout";
44 46
 static const char str_magic[] = "wrong magic byte";
47
+static const char str_detect[] = "@ detection";
45 48
 
46 49
 static const char * const error_strings[ERROR_BITS] = {
47 50
     str_sum, str_busy, str_full, str_untran,
48 51
     str_er0, str_er1, str_er2, str_lowbat,
49
-    str_cancel, str_timeout, str_magic,
52
+    str_cancel, str_timeout, str_magic, str_detect,
50 53
 };
51 54
 
52 55
 uint8_t gbprinter_error(enum PRN_STATUS status, char *buff) BANKED {
53 56
     if (status == PRN_STATUS_OK) {
54
-        sprintf(buff, "ok");
57
+        sprintf(buff, str_ok);
55 58
         return 2;
56 59
     }
57 60
 

+ 1
- 1
src/main.c View File

@@ -94,7 +94,7 @@ static void highscore(uint8_t is_black) NONBANKED {
94 94
             break;
95 95
         } else if (key_pressed(J_SELECT)) {
96 96
             enum PRN_STATUS status = gbprinter_detect();
97
-            if (status == PRN_STATUS_OK) {
97
+            if ((status & PRN_STATUS_MASK_ANY) == PRN_STATUS_OK) {
98 98
                 win_score_clear(is_black, 1);
99 99
                 list_scores(is_black);
100 100
                 status = gbprinter_screenshot(1, is_black ? PRN_PALETTE_SC_B : PRN_PALETTE_SC_W);

Loading…
Cancel
Save