GameBoy (Color) port of the GTA San Andreas arcade game Duality
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gbprinter_error.c 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * gbprinter_error.c
  3. * Duality
  4. *
  5. * Based on the gbprinter example from gbdk-2020:
  6. * https://github.com/gbdk-2020/gbdk-2020/tree/develop/gbdk-lib/examples/gb/gbprinter
  7. *
  8. * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * See <http://www.gnu.org/licenses/>.
  21. */
  22. #include <gbdk/platform.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "banks.h"
  26. #include "gbprinter.h"
  27. BANKREF(gbprinter_error)
  28. #define ERROR_BITS 11
  29. static const char str_lowbat[] = "battery too low";
  30. static const char str_er2[] = "unknown error";
  31. static const char str_er1[] = "paper jam";
  32. static const char str_er0[] = "packet error";
  33. static const char str_untran[] = "unprocessed";
  34. static const char str_full[] = "data full";
  35. static const char str_busy[] = "printer busy";
  36. static const char str_sum[] = "checksum error";
  37. static const char str_cancel[] = "cancelled";
  38. static const char str_timeout[] = "timeout";
  39. static const char str_magic[] = "wrong magic byte";
  40. static const char * const error_strings[ERROR_BITS] = {
  41. str_sum, str_busy, str_full, str_untran,
  42. str_er0, str_er1, str_er2, str_lowbat,
  43. str_cancel, str_timeout, str_magic,
  44. };
  45. uint8_t gbprinter_error(enum PRN_STATUS status, char *buff) NONBANKED {
  46. if (status == PRN_STATUS_OK) {
  47. sprintf(buff, "ok");
  48. return 2;
  49. }
  50. uint8_t n = 0;
  51. START_ROM_BANK(BANK(gbprinter_error)) {
  52. for (uint8_t i = 0; i < ERROR_BITS; i++) {
  53. if (status & (1 << i)) {
  54. if (n != 0) {
  55. buff[n++] = '\n';
  56. }
  57. strcpy(buff + n, error_strings[i]);
  58. n += strlen(error_strings[i]);
  59. }
  60. }
  61. } END_ROM_BANK
  62. return n;
  63. }