gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/examples/megaduck/laptop_printer/src/main.c
1 #include <gbdk/platform.h>
2 #include <gbdk/console.h>
3 #include <gb/isr.h>
4
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <stdio.h>
8
9 #include <duck/laptop_io.h>
10
11 #include "megaduck_printer.h"
12 #include "megaduck_printscreen.h"
13
14 uint8_t printer_type;
15
16 const uint8_t bg_tile[] = {
17 0x00, 0x00,
18 0x00, 0x00,
19 0xFF, 0x00,
20 0xFF, 0x00,
21 0x00, 0xFF,
22 0x00, 0xFF,
23 0xFF, 0xFF,
24 0xFF, 0xFF, };
25
26
27 uint8_t printer_query(void) {
28
29 printf("Printer Query\n");
30
31 uint8_t printer_query_result = duck_io_printer_query();
32 printf("Printer Result %hx\n", printer_query_result);
33
34 // return (printer_query_result & DUCK_IO_PRINTER_INIT_OK);
35 return printer_query_result;
36 }
37
38
39 static bool duck_laptop_and_printer_init(void) {
40
41 bool megaduck_laptop_init_ok = duck_io_laptop_init();
42 if (!megaduck_laptop_init_ok) {
43 // If laptop hardware is not present then there isn't anything
44 // for this program to do, so just idle in a loop
45 printf("Laptop not detected\n"
46 "or Failed to Initialize\n");
47 return false;
48 }
49
50 // Otherwise laptop init succeeded
51 printf("Laptop Detected!\n");
52
53 // Check to see if the printer was connected at startup, and if so what model
54 printer_type = duck_io_printer_last_status();
55 // Fix up printer status == 3 to be printer type 1, sort of a hack
56 if (printer_type == DUCK_IO_PRINTER_MAYBE_BUSY) printer_type = DUCK_IO_PRINTER_TYPE_1_PASS;
57
58 // If that failed, try a re-query of the printer
59 if (printer_type == DUCK_IO_PRINTER_FAIL) {
60
61 printf("No printer at startup\n"
62 " re-querying...\n");
63 if (duck_io_printer_query() == DUCK_IO_PRINTER_FAIL) {
64 printf("Printer not found\n");
65 return false;
66 }
67 }
68
69 // Otherwise printer init succeeded
70 printf("Printer Detected!\n");
71 if (printer_type == DUCK_IO_PRINTER_TYPE_1_PASS)
72 printf("- Single Pass model\n");
73 else
74 printf("- Double Pass model\n");
75
76 return true;
77 }
78
79
80 void main(void) {
81
82 uint8_t gamepad = 0;
83 uint8_t gamepad_last = 0;
84
85 SPRITES_8x8;
86 SHOW_SPRITES;
87 SHOW_BKG;
88 printf("Initializing..\n");
89
90 // Set tile as last tile
91 set_bkg_data(255, 1, bg_tile);
92 fill_bkg_rect(0, DEVICE_SCREEN_HEIGHT - 4, DEVICE_SCREEN_WIDTH - 1, DEVICE_SCREEN_HEIGHT - 1, 255);
93
94 // Stop here if no printer detected
95 if (duck_laptop_and_printer_init() == false) {
96 // Optionally take action if no printer is detected
97 }
98
99 printf("\nPress:\n"
100 "* START to print\n"
101 "* SELECT requery\n"
102 "* A print blank row\n");
103
104 while(1) {
105 vsync();
106 gamepad_last = gamepad;
107 gamepad = joypad();
108
109 // Send command to print the screen if START is pressed
110 switch (gamepad) {
111 case J_START:
112 printf("Starting print...\n");
113 // uint8_t printer_type = printer_query();
114 bool print_job_status = duck_print_screen();
115 printf("Finished print, status: %hu\n", print_job_status);
116 // Wait until START is released before continuing
117 waitpadup();
118 break;
119 case J_A: duck_print_blank_row(); waitpadup(); break;
120 case J_SELECT: printer_query(); waitpadup(); break;
121 }
122 }
123 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.