|
| 1 | +// Screenshot build of the RPN app (native simulator only): prefills a stack of |
| 2 | +// representative symbolic values, draws once, then reads the framebuffer back |
| 3 | +// with eadk_display_pull_rect and writes it as a PPM to /out/shot.ppm. Used by |
| 4 | +// the headless capture harness; never shipped. |
| 5 | +extern "C" { |
| 6 | +#include <stdint.h> |
| 7 | +#include <stdio.h> |
| 8 | +} |
| 9 | + |
| 10 | +#include "../src/eadkpp.h" // brings in eadk.h (pull_rect, eadk_rect_t, eadk_color_t) |
| 11 | +#include "../src/rpn.h" |
| 12 | +#include "../src/view.h" |
| 13 | + |
| 14 | +const char eadk_app_name[] |
| 15 | +#if PLATFORM_DEVICE |
| 16 | + __attribute__((section(".rodata.eadk_app_name"))) |
| 17 | +#endif |
| 18 | + = "RPN"; |
| 19 | +const uint32_t eadk_api_level |
| 20 | +#if PLATFORM_DEVICE |
| 21 | + __attribute__((section(".rodata.eadk_api_level"))) |
| 22 | +#endif |
| 23 | + = 0; |
| 24 | + |
| 25 | +static void feed(Engine& e, const char* digits) { |
| 26 | + for (const char* p = digits; *p; p++) { |
| 27 | + char s[2] = {*p, 0}; |
| 28 | + e.appendText(s); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +int main(int argc, char* argv[]) { |
| 33 | + (void)argc; |
| 34 | + (void)argv; |
| 35 | + Engine e; |
| 36 | + feed(e, "1"); e.execute(Command::EnterOrDup); |
| 37 | + feed(e, "2"); e.execute(Command::Div); // 1/2 |
| 38 | + feed(e, "2"); e.execute(Command::Sqrt); |
| 39 | + feed(e, "3"); e.execute(Command::Sqrt); |
| 40 | + e.execute(Command::Add); // √2 + √3 |
| 41 | + feed(e, "1"); e.execute(Command::EnterOrDup); |
| 42 | + feed(e, "2"); e.execute(Command::Sqrt); e.execute(Command::Add); |
| 43 | + feed(e, "2"); e.execute(Command::Pow); // (1+√2)^2 = 3 + 2√2 |
| 44 | + e.execute(Command::PushPi); |
| 45 | + feed(e, "2"); e.execute(Command::Div); // π/2 |
| 46 | + |
| 47 | + View view; |
| 48 | + view.draw(e, false, 0); |
| 49 | + |
| 50 | + const int w = 320, h = 240; |
| 51 | + static eadk_color_t buf[320 * 240]; |
| 52 | + eadk_rect_t full = {0, 0, w, h}; |
| 53 | + eadk_display_pull_rect(full, buf); |
| 54 | + |
| 55 | + FILE* f = fopen("/out/shot.ppm", "wb"); |
| 56 | + if (f) { |
| 57 | + fprintf(f, "P6\n%d %d\n255\n", w, h); |
| 58 | + for (int i = 0; i < w * h; i++) { |
| 59 | + uint16_t c = buf[i]; // RGB565 |
| 60 | + unsigned char rgb[3] = { |
| 61 | + static_cast<unsigned char>(((c >> 11) & 0x1F) << 3), |
| 62 | + static_cast<unsigned char>(((c >> 5) & 0x3F) << 2), |
| 63 | + static_cast<unsigned char>((c & 0x1F) << 3)}; |
| 64 | + fwrite(rgb, 1, 3, f); |
| 65 | + } |
| 66 | + fclose(f); |
| 67 | + } |
| 68 | + return 0; |
| 69 | +} |
0 commit comments