diff --git a/2.13/mono/spi/pet/.gitignore b/2.13/mono/spi/pet/.gitignore new file mode 100644 index 0000000..62a563e --- /dev/null +++ b/2.13/mono/spi/pet/.gitignore @@ -0,0 +1,2 @@ +/pixpaper-213-m-test-frdm-imx93-pet +/pixpaper-213-m-test-rpi5-pet diff --git a/2.13/mono/spi/pet/Makefile b/2.13/mono/spi/pet/Makefile new file mode 100644 index 0000000..0a23702 --- /dev/null +++ b/2.13/mono/spi/pet/Makefile @@ -0,0 +1,34 @@ +# Local build for the Open-EP Pet examples. +# +# Flags mirror ci/build-one.sh; CI (ci/discover-targets.py + GitHub Actions) +# remains the source of truth for the cross-arch board builds. +# +# This x86 dev host can natively build only the libgpiod v1 target (imx93). +# The rpi5 target needs libgpiod v2 headers/lib (build it on an rpi5 or in CI). +# +# make build every target +# make imx93 build the frdm-imx93 (libgpiod v1) target +# make rpi5 build the rpi5 (libgpiod v2) target +# make clean remove built binaries + +CC ?= cc +CFLAGS ?= -std=gnu11 -Wall -Wextra \ + -Wno-error=incompatible-pointer-types \ + -Werror=implicit-function-declaration +LDLIBS ?= -lgpiod + +COMMON := pet_app.h petsprite.h jpfont.h + +IMX93 := pixpaper-213-m-test-frdm-imx93-pet +RPI5 := pixpaper-213-m-test-rpi5-pet + +.PHONY: all imx93 rpi5 clean +all: $(IMX93) $(RPI5) +imx93: $(IMX93) +rpi5: $(RPI5) + +%: %.c $(COMMON) + $(CC) $(CFLAGS) -I. $< -o $@ $(LDLIBS) + +clean: + $(RM) $(IMX93) $(RPI5) diff --git a/2.13/mono/spi/pet/README.md b/2.13/mono/spi/pet/README.md new file mode 100644 index 0000000..a24cdd1 --- /dev/null +++ b/2.13/mono/spi/pet/README.md @@ -0,0 +1,106 @@ +# Open-EP Pet + +A Tamagotchi-style virtual pet running on the 2.13" mono PixPaper e-paper +panel over SPI, animated with partial +refresh so the puppy blinks, walks, eats and jumps without full-screen +flashing. + +The UI shows the pet sprite, three stat bars (空腹 hunger / 元気 energy / +気分 mood) and three action buttons (エサ feed / あそぶ play / そうじ clean), +in either landscape or portrait orientation. + +## Layout + +| File | Description | +|---|---| +| `pet_app.h` | Board-independent core: SPI transport, EPD init/partial-refresh sequence, custom partial LUT, framebuffer drawing, Latin + Japanese fonts, pet state machine and main loop | +| `pixpaper-213-m-test-frdm-imx93-pet.c` | GPIO backend for FRDM-i.MX93 (libgpiod **v1**) | +| `pixpaper-213-m-test-rpi5-pet.c` | GPIO backend for Raspberry Pi 5 (libgpiod **v2**) | +| `petsprite.h` | Generated 1-bit sprite frames (do not edit) | +| `jpfont.h` | Generated 1-bit Japanese glyph bitmaps (do not edit) | +| `sprite_gen.py` | Regenerates `petsprite.h` from the `dog*.png` artwork | +| `jpfont_gen.py` | Regenerates `jpfont.h` from a system Noto CJK font | +| `dog*.png` | Source artwork for the 14 sprite frames | +| `pixpaper-pet.service` | systemd unit to run the pet as an auto demo at boot | +| `Makefile` | Local build for both targets | + +Each per-board `.c` file only provides the GPIO backend +(`epd_dc_set` / `epd_rst_set` / `epd_busy_get` / `epd_gpio_init` / +`epd_gpio_release`) and then includes `pet_app.h`, which contains +everything else including `main()`. + +## Hardware / wiring + +SPI device: `/dev/spidev0.0` at 5 MHz, mode 0. + +| Signal | FRDM-i.MX93 (`gpiochip0`) | Raspberry Pi 5 (`gpiochip15`) | +|---|---|---| +| DC | line 0 | line 5 | +| RST | line 5 | line 6 | +| BUSY | line 26 | line 26 | + +To port to another board, copy one of the `.c` files and adapt the chip +name / line offsets (use the libgpiod v1 file for libgpiod < 2.0, the +rpi5 file for v2). + +## Build + +Requires libgpiod development headers (v1 for the imx93 target, v2 for +the rpi5 target). + +```sh +make # build every target +make imx93 # FRDM-i.MX93 (libgpiod v1) +make rpi5 # Raspberry Pi 5 (libgpiod v2) +make clean +``` + +## Run + +```sh +sudo ./pixpaper-213-m-test-rpi5-pet [auto|interactive] [landscape|portrait] +``` + +- **Orientation**: `landscape` (default) or `portrait`. If portrait comes + out upside-down on your unit, see the note at the top of `pet_app.h`. +- **Interactive mode** (default when stdin is a TTY) — keys: + - `f` feed (エサ): +hunger + - `p` play (あそぶ): +mood, -energy + - `c` clean (そうじ): +mood + - `q` quit +- **Auto mode** (`auto`, or automatic when stdin is not a TTY, e.g. under + systemd): cycles feed → play → clean on its own as a demo. + +Left alone, the pet idles with random liveliness gestures (blinks, +looking around, a short walk cycle, a floating heart), falls asleep after +~60 frames without interaction, and its stats slowly decay; at zero +hunger it sulks until fed. + +## Regenerating the assets + +Both generated headers are committed, so this is only needed after +changing the artwork or UI strings. Requires Python 3 with Pillow and +NumPy. + +```sh +python3 sprite_gen.py --emit # dog*.png -> petsprite.h (preview: /tmp/sprite_frames.png) +python3 jpfont_gen.py # Noto Sans CJK Bold -> jpfont.h +``` + +`sprite_gen.py` traces every frame at one fixed scale (anchored to the +sitting frame) and bottom-aligns them on a common floor, so crouch/jump +poses keep their real height differences. `jpfont_gen.py` embeds only +the glyphs actually used by the UI (edit its `JOBS` list when adding +strings). + +## Display technique notes + +- **Partial refresh** uses a custom LUT (`WF_PARTIAL` in `pet_app.h`); + animation frames are written to RAM 0x24 only, keeping the panel in a + `0x0C` "keep on" display mode between frames (~35 ms/frame pacing). +- **Ghosting control**: every 200 frames the panel is hardware-reset, + re-initialised and given a full refresh of the current frame as a new + base map. +- **Blink masking**: when switching between sprite frames with very + different silhouettes (sad/eat/walk), a one-frame blink pose is + inserted in between to hide partial-refresh residue. diff --git a/2.13/mono/spi/pet/dog.png b/2.13/mono/spi/pet/dog.png new file mode 100644 index 0000000..032e2ae Binary files /dev/null and b/2.13/mono/spi/pet/dog.png differ diff --git a/2.13/mono/spi/pet/dog_blink.png b/2.13/mono/spi/pet/dog_blink.png new file mode 100644 index 0000000..2e177f4 Binary files /dev/null and b/2.13/mono/spi/pet/dog_blink.png differ diff --git a/2.13/mono/spi/pet/dog_crouch.png b/2.13/mono/spi/pet/dog_crouch.png new file mode 100644 index 0000000..fdfe5a0 Binary files /dev/null and b/2.13/mono/spi/pet/dog_crouch.png differ diff --git a/2.13/mono/spi/pet/dog_eat.png b/2.13/mono/spi/pet/dog_eat.png new file mode 100644 index 0000000..c8b6ea4 Binary files /dev/null and b/2.13/mono/spi/pet/dog_eat.png differ diff --git a/2.13/mono/spi/pet/dog_eat_closed.png b/2.13/mono/spi/pet/dog_eat_closed.png new file mode 100644 index 0000000..f0556ad Binary files /dev/null and b/2.13/mono/spi/pet/dog_eat_closed.png differ diff --git a/2.13/mono/spi/pet/dog_happy.png b/2.13/mono/spi/pet/dog_happy.png new file mode 100644 index 0000000..7850d34 Binary files /dev/null and b/2.13/mono/spi/pet/dog_happy.png differ diff --git a/2.13/mono/spi/pet/dog_jump.png b/2.13/mono/spi/pet/dog_jump.png new file mode 100644 index 0000000..c66ed3e Binary files /dev/null and b/2.13/mono/spi/pet/dog_jump.png differ diff --git a/2.13/mono/spi/pet/dog_look.png b/2.13/mono/spi/pet/dog_look.png new file mode 100644 index 0000000..4e9e16c Binary files /dev/null and b/2.13/mono/spi/pet/dog_look.png differ diff --git a/2.13/mono/spi/pet/dog_look_half.png b/2.13/mono/spi/pet/dog_look_half.png new file mode 100644 index 0000000..56fa50d Binary files /dev/null and b/2.13/mono/spi/pet/dog_look_half.png differ diff --git a/2.13/mono/spi/pet/dog_sad.png b/2.13/mono/spi/pet/dog_sad.png new file mode 100644 index 0000000..1f9c24a Binary files /dev/null and b/2.13/mono/spi/pet/dog_sad.png differ diff --git a/2.13/mono/spi/pet/dog_walk1.png b/2.13/mono/spi/pet/dog_walk1.png new file mode 100644 index 0000000..eabd4a2 Binary files /dev/null and b/2.13/mono/spi/pet/dog_walk1.png differ diff --git a/2.13/mono/spi/pet/dog_walk2.png b/2.13/mono/spi/pet/dog_walk2.png new file mode 100644 index 0000000..ba42c4d Binary files /dev/null and b/2.13/mono/spi/pet/dog_walk2.png differ diff --git a/2.13/mono/spi/pet/dog_walk3.png b/2.13/mono/spi/pet/dog_walk3.png new file mode 100644 index 0000000..6d8b294 Binary files /dev/null and b/2.13/mono/spi/pet/dog_walk3.png differ diff --git a/2.13/mono/spi/pet/dog_walk4.png b/2.13/mono/spi/pet/dog_walk4.png new file mode 100644 index 0000000..ed055f0 Binary files /dev/null and b/2.13/mono/spi/pet/dog_walk4.png differ diff --git a/2.13/mono/spi/pet/jpfont.h b/2.13/mono/spi/pet/jpfont.h new file mode 100644 index 0000000..1751ca6 --- /dev/null +++ b/2.13/mono/spi/pet/jpfont.h @@ -0,0 +1,76 @@ +/* generated by jpfont_gen.py - do not edit by hand */ +#ifndef JPFONT_H +#define JPFONT_H +#include + +struct jpglyph { uint32_t cp; uint8_t size, w, h; uint16_t off; }; + +static const struct jpglyph jpglyphs[] = { + {0x3042, 14, 14, 14, 0}, + {0x3046, 14, 14, 14, 28}, + {0x3058, 14, 14, 14, 56}, + {0x305D, 14, 14, 14, 84}, + {0x3076, 14, 14, 14, 112}, + {0x30A8, 14, 14, 14, 140}, + {0x30B5, 14, 14, 14, 168}, + {0x304A, 16, 16, 16, 196}, + {0x304B, 16, 16, 16, 228}, + {0x306A, 16, 16, 16, 260}, + {0x30C3, 16, 16, 16, 292}, + {0x30C8, 16, 16, 16, 324}, + {0x30DA, 16, 16, 16, 356}, + {0x5143, 20, 20, 20, 388}, + {0x5206, 20, 20, 20, 448}, + {0x6C17, 20, 20, 20, 508}, + {0x7A7A, 20, 20, 20, 568}, + {0x8179, 20, 20, 20, 628}, +}; +#define JPGLYPH_COUNT (sizeof(jpglyphs)/sizeof(jpglyphs[0])) + +static const uint8_t jpbits[] = { + 0x00,0x00,0x06,0x00,0x3F,0xE0,0x3F,0xE0,0x04,0x40,0x07,0xE0,0x0F,0xF0,0x1C,0x98, + 0x35,0x98,0x67,0x18,0x66,0x18,0x7E,0x70,0x30,0xE0,0x00,0x00,0x00,0x00,0x0F,0xC0, + 0x07,0xC0,0x00,0x00,0x03,0x80,0x3F,0xE0,0x38,0x60,0x00,0x20,0x00,0x60,0x00,0x60, + 0x00,0xE0,0x07,0xC0,0x0F,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x18,0xA0,0x18,0xB0, + 0x18,0xC0,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x10,0x18,0x30,0x18,0x70, + 0x1F,0xE0,0x07,0x80,0x0F,0xC0,0x1F,0xE0,0x01,0x80,0x03,0x00,0x0E,0x30,0x7F,0xF0, + 0x7F,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x03,0xE0,0x01,0xC0,0x00,0x00, + 0x00,0x00,0x06,0x00,0x07,0x88,0x01,0xA8,0x01,0x90,0x00,0x00,0x06,0x00,0x07,0x20, + 0x03,0x30,0x19,0x90,0x71,0x98,0xE1,0x98,0x4F,0x80,0x07,0x00,0x00,0x00,0x3F,0xF0, + 0x3F,0xF0,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x7F,0xF8, + 0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x60,0x08,0x40,0x08,0x40, + 0x7F,0xF8,0x7F,0xF8,0x08,0x40,0x08,0x40,0x18,0xC0,0x00,0xC0,0x01,0xC0,0x03,0x80, + 0x07,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x06,0xD8,0x3F,0xDC,0x3F,0x0E, + 0x06,0x02,0x06,0xE0,0x0F,0xF8,0x1E,0x1C,0x3E,0x0C,0x76,0x0C,0x76,0x1C,0x3E,0xF8, + 0x1C,0xE0,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x06,0x18,0x3F,0xCC,0x7F,0xEC, + 0x0C,0x66,0x0C,0x66,0x0C,0x67,0x18,0x60,0x18,0x60,0x38,0x60,0x30,0xC0,0x77,0xC0, + 0x23,0x80,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x7F,0x98,0x7F,0x1E,0x0C,0x0E, + 0x0C,0x60,0x18,0x60,0x18,0x60,0x38,0x60,0x33,0xF0,0x77,0xF8,0x06,0x7C,0x06,0x6C, + 0x07,0xE0,0x01,0xC0,0x00,0x00,0x00,0x00,0x01,0x00,0x19,0x9C,0x19,0x9C,0x19,0x98, + 0x0C,0x38,0x00,0x30,0x00,0x70,0x00,0xE0,0x03,0xC0,0x07,0x80,0x02,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00, + 0x07,0x80,0x07,0xF0,0x07,0xFC,0x06,0x18,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00, + 0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x16,0x07,0x16,0x0F,0x9C, + 0x0F,0xC0,0x1C,0xE0,0x38,0x70,0x70,0x38,0x60,0x38,0x00,0x1C,0x00,0x0E,0x00,0x04, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0x80,0x1F,0xFF,0x80,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xE0,0x7F,0xFF,0xE0,0x03, + 0x1C,0x00,0x07,0x1C,0x00,0x07,0x1C,0x00,0x07,0x1C,0x00,0x0E,0x1C,0x60,0x0E,0x1C, + 0x60,0x1C,0x1C,0x60,0x78,0x1F,0xE0,0x70,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x03,0x0C,0x00,0x07,0x0E,0x00,0x07,0x07,0x00,0x0E,0x07,0x00,0x1C,0x03,0x80,0x3C, + 0x01,0xC0,0x78,0x01,0xE0,0x7F,0xFF,0xE0,0x6F,0xFF,0xC0,0x01,0xC3,0x00,0x01,0xC3, + 0x00,0x01,0x83,0x00,0x03,0x83,0x00,0x03,0x83,0x00,0x07,0x03,0x00,0x0F,0x07,0x00, + 0x1E,0x07,0x00,0x3C,0x3E,0x00,0x30,0x3E,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x0F, + 0xFF,0xE0,0x1F,0xFF,0xE0,0x1C,0x00,0x00,0x3F,0xFF,0x80,0x77,0xFF,0x80,0x70,0x00, + 0x00,0x3F,0xFF,0x00,0x1F,0xFF,0x00,0x00,0x63,0x00,0x0C,0x73,0x00,0x1E,0xE3,0x00, + 0x0F,0xC3,0x00,0x03,0xC3,0x00,0x07,0xE3,0x20,0x0F,0xF3,0xA0,0x3E,0x7B,0xE0,0x3C, + 0x11,0xE0,0x30,0x00,0xC0,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x7F,0xFF, + 0xE0,0x7F,0xFF,0xE0,0x73,0x98,0xE0,0x73,0x98,0xE0,0x23,0x98,0x00,0x07,0x18,0xC0, + 0x3E,0x1F,0xC0,0x3C,0x0F,0xC0,0x30,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0x80,0x1F, + 0xFF,0x80,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x7F,0xFF,0xE0,0x7F,0xFF, + 0xE0,0x00,0x00,0x00,0x3F,0x30,0x00,0x3F,0x7F,0xE0,0x37,0x7F,0xE0,0x37,0xE0,0x00, + 0x37,0xFF,0xC0,0x3F,0xF0,0xC0,0x3F,0x70,0xC0,0x37,0x7F,0xC0,0x37,0x60,0xC0,0x37, + 0x7F,0xC0,0x3F,0x3C,0x00,0x3F,0x3F,0xC0,0x37,0x7F,0xC0,0x77,0xF1,0xC0,0x67,0xFF, + 0x80,0x67,0x1F,0x00,0x67,0x7F,0x80,0x6F,0xFF,0xE0,0x6E,0xE0,0xE0,0x00,0x00,0x00, +}; + +#endif /* JPFONT_H */ diff --git a/2.13/mono/spi/pet/jpfont_gen.py b/2.13/mono/spi/pet/jpfont_gen.py new file mode 100644 index 0000000..320c3ec --- /dev/null +++ b/2.13/mono/spi/pet/jpfont_gen.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +""" +Generate jpfont.h: a tiny 1-bit bitmap font holding ONLY the Japanese (and any +other) glyphs used by the Open-EP Pet UI, rasterised from a system CJK font. + +Each glyph is rendered into a square size*size cell (fullwidth), thresholded to +pure black/white (no anti-alias, for crisp e-paper output). Re-run after +changing any UI string; the build embeds only what is listed in JOBS. + + python3 jpfont_gen.py # writes jpfont.h next to this script +""" +import os +from PIL import Image, ImageFont, ImageDraw + +FONT = "/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc" +OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "jpfont.h") + +# (pixel size, text whose unique chars must be available at that size) +JOBS = [ + (20, "空腹元気気分"), # stat labels + (16, "おなかペット"), # title + (14, "エサあそぶそうじ"), # buttons: Feed / Play / Clean +] + +def render_glyph(ch, size): + """Return (w, h, rows[]) 1-bit bitmap centred in a size*size cell.""" + font = ImageFont.truetype(FONT, size) + img = Image.new("L", (size, size), 0) + d = ImageDraw.Draw(img) + x0, y0, x1, y1 = font.getbbox(ch) + gw, gh = x1 - x0, y1 - y0 + pos = ((size - gw) // 2 - x0, (size - gh) // 2 - y0) + d.text(pos, ch, font=font, fill=255) + px = img.load() + stride = (size + 7) // 8 + rows = [] + for y in range(size): + row = bytearray(stride) + for x in range(size): + if px[x, y] >= 128: + row[x >> 3] |= 0x80 >> (x & 7) + rows.append(row) + return size, size, rows + +def main(): + glyphs = [] # (cp, size, w, h, rows) + seen = set() + for size, text in JOBS: + for ch in text: + key = (ord(ch), size) + if key in seen: + continue + seen.add(key) + w, h, rows = render_glyph(ch, size) + glyphs.append((ord(ch), size, w, h, rows)) + glyphs.sort(key=lambda g: (g[1], g[0])) # by (size, codepoint) + + blob, offs = bytearray(), [] + for cp, size, w, h, rows in glyphs: + offs.append(len(blob)) + for row in rows: + blob += row + + with open(OUT, "w") as f: + f.write("/* generated by jpfont_gen.py - do not edit by hand */\n") + f.write("#ifndef JPFONT_H\n#define JPFONT_H\n#include \n\n") + f.write("struct jpglyph { uint32_t cp; uint8_t size, w, h; uint16_t off; };\n\n") + f.write("static const struct jpglyph jpglyphs[] = {\n") + for (cp, size, w, h, _), off in zip(glyphs, offs): + f.write(f"\t{{0x{cp:04X}, {size}, {w}, {h}, {off}}},\n") + f.write("};\n#define JPGLYPH_COUNT (sizeof(jpglyphs)/sizeof(jpglyphs[0]))\n\n") + f.write("static const uint8_t jpbits[] = {\n") + for i in range(0, len(blob), 16): + f.write("\t" + ",".join(f"0x{b:02X}" for b in blob[i:i+16]) + ",\n") + f.write("};\n\n#endif /* JPFONT_H */\n") + + print(f"{len(glyphs)} glyphs, {len(blob)} bytes -> {OUT}") + +if __name__ == "__main__": + main() diff --git a/2.13/mono/spi/pet/pet_app.h b/2.13/mono/spi/pet/pet_app.h new file mode 100644 index 0000000..ac62784 --- /dev/null +++ b/2.13/mono/spi/pet/pet_app.h @@ -0,0 +1,986 @@ +/* + * Author: LC Wang + * Date: 2026-06-17 + * + * Open-EP Pet: a Tamagotchi-style virtual pet on the 2.13" mono PixPaper + * (250x122 landscape). Board-independent core: SPI, EPD command sequence, + * partial-refresh LUT, drawing, fonts, pet logic and main loop. + * + * The GPIO backend is board-specific and lives in the per-board .c file, + * which must, before including this header, provide: + * + * epd_dc_set(v) set the DC line + * epd_rst_set(v) set the RST line + * epd_busy_get() read the BUSY line (1 = busy) + * int epd_gpio_init(void) acquire DC/RST/BUSY; return <0 on error + * void epd_gpio_release(void) release the lines and close the chip + * + * Orientation only changes the logical->RAM coordinate map in fb_set(); the + * portrait map is a true 90deg rotation (transpose + x-flip, not a mirror). + * If portrait comes out upside-down on your unit, swap the two lines in the + * portrait branch of fb_set() to: gate = DISP_GATE_MAX - y; bit = x; + */ +#ifndef PET_APP_H +#define PET_APP_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "jpfont.h" +#include "petsprite.h" + +#define EPD_SPI_DEVICE "/dev/spidev0.0" +#define SPI_SPEED 5000000 + +#define DISP_W 250 +#define DISP_H 128 +#define DISP_VIS 122 +#define DISP_STRIDE (DISP_H / 8) +#define DISP_BUF_SIZE (DISP_W * DISP_STRIDE) +#define DISP_GATE_MAX (DISP_W - 1) + +static int g_portrait; +static int scr_w = DISP_W; +static int scr_h = DISP_VIS; + +int spi_fd; + +void sleep_ms(unsigned int milliseconds) { + struct timespec ts; + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = (milliseconds % 1000) * 1000000; + nanosleep(&ts, NULL); +} + +void sleep_us(unsigned int microseconds) { + struct timespec ts; + ts.tv_sec = microseconds / 1000000; + ts.tv_nsec = (microseconds % 1000000) * 1000; + nanosleep(&ts, NULL); +} + +void spi_write(uint8_t *data, int len) { + struct spi_ioc_transfer tr = { + .tx_buf = (unsigned long)data, + .len = len, + .speed_hz = SPI_SPEED, + .bits_per_word = 8, + }; + ioctl(spi_fd, SPI_IOC_MESSAGE(1), &tr); +} + +void epd_writeCommand(uint8_t command) { + epd_dc_set(0); + sleep_us(1); + spi_write(&command, 1); +} + +void epd_writeData(uint8_t data) { + epd_dc_set(1); + sleep_us(1); + spi_write(&data, 1); +} + +void epd_writeData_bulk(const uint8_t *data, int len) { + epd_dc_set(1); + sleep_us(1); + while (len > 0) { + int chunk = len > 4096 ? 4096 : len; + spi_write((uint8_t *)data, chunk); + data += chunk; + len -= chunk; + } +} + +void epd_waitUntilIdle() { + sleep_ms(2); + while (epd_busy_get() != 0) + ; +} + +void epd_HWreset() { + sleep_ms(50); + epd_rst_set(0); + sleep_ms(50); + epd_rst_set(1); + sleep_ms(50); +} + +void epd_reg_init(void) { + epd_waitUntilIdle(); + epd_writeCommand(0x12); + epd_waitUntilIdle(); + + epd_writeCommand(0x01); + epd_writeData(0xF9); + epd_writeData(0x00); + epd_writeData(0x00); + + epd_writeCommand(0x11); + epd_writeData(0x01); + + epd_writeCommand(0x44); + epd_writeData(0x00); + epd_writeData(0x0F); + + epd_writeCommand(0x45); + epd_writeData(0xF9); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x00); + + epd_writeCommand(0x3C); + epd_writeData(0x05); + + epd_writeCommand(0x21); + epd_writeData(0x00); + epd_writeData(0x80); + + epd_writeCommand(0x18); + epd_writeData(0x80); + + epd_writeCommand(0x4E); + epd_writeData(0x00); + epd_writeCommand(0x4F); + epd_writeData(0xF9); + epd_writeData(0x00); + + epd_waitUntilIdle(); +} + +void epd_init(void) { + spi_fd = open(EPD_SPI_DEVICE, O_RDWR); + if (spi_fd < 0) { + perror("Error opening SPI device"); + exit(1); + } + + uint8_t spi_mode = SPI_MODE_0; + ioctl(spi_fd, SPI_IOC_WR_MODE, &spi_mode); + uint32_t speed = SPI_SPEED; + ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); + + if (epd_gpio_init() < 0) + exit(1); + + epd_HWreset(); + sleep_ms(1000); + epd_waitUntilIdle(); + epd_reg_init(); +} + +static void epd_set_window(int xb_start, int xb_end, int g_start, int g_end) { + epd_writeCommand(0x44); + epd_writeData(xb_start & 0xFF); + epd_writeData(xb_end & 0xFF); + + epd_writeCommand(0x45); + epd_writeData(g_start & 0xFF); + epd_writeData((g_start >> 8) & 0xFF); + epd_writeData(g_end & 0xFF); + epd_writeData((g_end >> 8) & 0xFF); +} + +static void epd_set_cursor(int xb, int g) { + epd_writeCommand(0x4E); + epd_writeData(xb & 0xFF); + + epd_writeCommand(0x4F); + epd_writeData(g & 0xFF); + epd_writeData((g >> 8) & 0xFF); +} + +static void epd_set_full_window(void) { + epd_set_window(0x00, DISP_STRIDE - 1, DISP_GATE_MAX, 0x00); +} + +static void epd_set_full_cursor(void) { + epd_set_cursor(0x00, DISP_GATE_MAX); +} + +void epd_set_base_map(const uint8_t *buf) { + epd_set_full_window(); + + epd_set_full_cursor(); + epd_writeCommand(0x24); + epd_writeData_bulk(buf, DISP_BUF_SIZE); + + epd_set_full_cursor(); + epd_writeCommand(0x26); + epd_writeData_bulk(buf, DISP_BUF_SIZE); + + epd_writeCommand(0x22); + epd_writeData(0xF7); + epd_writeCommand(0x20); + epd_waitUntilIdle(); +} + +static const uint8_t WF_PARTIAL[159] = { + 0x0, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0, + 0x22, 0x17, 0x41, 0x0, 0x32, 0x36, +}; + +static const int g_phase0_tp = 0x10; +static const int g_fr = 3; + +void epd_load_partial_lut(void) { + uint8_t fr_byte = ((g_fr & 7) << 4) | (g_fr & 7); + epd_writeCommand(0x32); + for (int i = 0; i < 153; i++) { + uint8_t b = WF_PARTIAL[i]; + if (i == 60) + b = (uint8_t)g_phase0_tp; + else if (i >= 144 && i <= 149) + b = fr_byte; + epd_writeData(b); + } + epd_waitUntilIdle(); + + epd_writeCommand(0x3F); + epd_writeData(WF_PARTIAL[153]); + epd_writeCommand(0x03); + epd_writeData(WF_PARTIAL[154]); + epd_writeCommand(0x04); + epd_writeData(WF_PARTIAL[155]); + epd_writeData(WF_PARTIAL[156]); + epd_writeData(WF_PARTIAL[157]); + epd_writeCommand(0x2C); + epd_writeData(WF_PARTIAL[158]); + + epd_writeCommand(0x37); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x40); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x00); + epd_writeData(0x00); + + epd_writeCommand(0x3C); + epd_writeData(0x80); +} + +static void epd_partial_regs(void) { + epd_writeCommand(0x01); + epd_writeData(0xF9); + epd_writeData(0x00); + epd_writeData(0x00); + + epd_writeCommand(0x11); + epd_writeData(0x01); + + epd_writeCommand(0x21); + epd_writeData(0x00); + epd_writeData(0x80); + + epd_writeCommand(0x18); + epd_writeData(0x80); +} + +#define DISPLAY_PART_KEEP_ON 0x0C + +void epd_partial_begin(void) { + epd_rst_set(0); + sleep_ms(2); + epd_rst_set(1); + sleep_ms(2); + + epd_partial_regs(); + epd_load_partial_lut(); + + epd_writeCommand(0x22); + epd_writeData(0xC0); + epd_writeCommand(0x20); + epd_waitUntilIdle(); + + epd_set_full_window(); +} + +void epd_partial_frame(const uint8_t *image) { + epd_set_full_cursor(); + epd_writeCommand(0x24); + epd_writeData_bulk(image, DISP_BUF_SIZE); + + epd_writeCommand(0x22); + epd_writeData(DISPLAY_PART_KEEP_ON); + epd_writeCommand(0x20); + epd_waitUntilIdle(); +} + +void epd_partial_end(void) { + epd_writeCommand(0x22); + epd_writeData(0x03); + epd_writeCommand(0x20); + epd_waitUntilIdle(); +} + +static inline void fb_set(uint8_t *buf, int x, int y) { + int gate, bit; + + if (x < 0 || x >= scr_w || y < 0 || y >= scr_h) + return; + + if (g_portrait) { + gate = y; + bit = DISP_VIS - 1 - x; + } else { + gate = x; + bit = y; + } + buf[gate * DISP_STRIDE + (bit >> 3)] &= ~(0x80 >> (bit & 7)); +} + +static void fb_clear(uint8_t *buf) { + memset(buf, 0xFF, DISP_BUF_SIZE); +} + +static void fb_rect(uint8_t *buf, int x0, int y0, int x1, int y1) { + for (int x = x0; x < x1; x++) + for (int y = y0; y < y1; y++) + fb_set(buf, x, y); +} + +static void fb_hline(uint8_t *buf, int x, int y, int len, int th) { + for (int i = 0; i < len; i++) + for (int t = 0; t < th; t++) + fb_set(buf, x + i, y + t); +} + +static void fb_vline(uint8_t *buf, int x, int y, int len, int th) { + for (int i = 0; i < len; i++) + for (int t = 0; t < th; t++) + fb_set(buf, x + t, y + i); +} + +static void fb_frame(uint8_t *buf, int x0, int y0, int x1, int y1) { + fb_hline(buf, x0, y0, x1 - x0 + 1, 1); + fb_hline(buf, x0, y1, x1 - x0 + 1, 1); + fb_vline(buf, x0, y0, y1 - y0 + 1, 1); + fb_vline(buf, x1, y0, y1 - y0 + 1, 1); +} + +static void fb_disc(uint8_t *buf, int cx, int cy, int r) { + for (int dy = -r; dy <= r; dy++) + for (int dx = -r; dx <= r; dx++) + if (dx * dx + dy * dy <= r * r) + fb_set(buf, cx + dx, cy + dy); +} + +static const uint8_t font5x7[96][8] = { + [' ' - 32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + ['(' - 32] = {0x10, 0x20, 0x40, 0x40, 0x40, 0x20, 0x10, 0x00}, + [')' - 32] = {0x40, 0x20, 0x10, 0x10, 0x10, 0x20, 0x40, 0x00}, + ['-' - 32] = {0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00}, + ['[' - 32] = {0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00}, + [']' - 32] = {0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x00}, + ['C' - 32] = {0x70, 0x88, 0x80, 0x80, 0x80, 0x88, 0x70, 0x00}, + ['E' - 32] = {0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x00}, + ['F' - 32] = {0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x00}, + ['H' - 32] = {0x88, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x00}, + ['M' - 32] = {0x88, 0xD8, 0xA8, 0x88, 0x88, 0x88, 0x88, 0x00}, + ['O' - 32] = {0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00}, + ['P' - 32] = {0xF0, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x00}, + ['Z' - 32] = {0xF8, 0x08, 0x10, 0x20, 0x40, 0x80, 0xF8, 0x00}, + ['a' - 32] = {0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x78, 0x00}, + ['d' - 32] = {0x08, 0x08, 0x78, 0x88, 0x88, 0x88, 0x78, 0x00}, + ['e' - 32] = {0x00, 0x70, 0x88, 0xF8, 0x80, 0x70, 0x00, 0x00}, + ['g' - 32] = {0x00, 0x78, 0x88, 0x88, 0x78, 0x08, 0x70, 0x00}, + ['l' - 32] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x30, 0x00}, + ['n' - 32] = {0x00, 0x00, 0xF0, 0x88, 0x88, 0x88, 0x88, 0x00}, + ['o' - 32] = {0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x70, 0x00}, + ['p' - 32] = {0x00, 0x00, 0xF0, 0x88, 0x88, 0xF0, 0x80, 0x80}, + ['r' - 32] = {0x00, 0x00, 0xB0, 0xC0, 0x80, 0x80, 0x80, 0x00}, + ['t' - 32] = {0x40, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x30, 0x00}, + ['u' - 32] = {0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x78, 0x00}, + ['y' - 32] = {0x00, 0x00, 0x88, 0x88, 0x78, 0x08, 0x70, 0x00}, + ['z' - 32] = {0x00, 0x00, 0xF8, 0x10, 0x20, 0x40, 0xF8, 0x00}, +}; + +static int draw_char_ex(uint8_t *buf, int x, int y, char c, int sc, int bold) { + unsigned char uc = (unsigned char)c; + if (uc < 32 || uc > 127) + uc = ' '; + const uint8_t *g = font5x7[uc - 32]; + for (int row = 0; row < 8; row++) { + uint8_t bits = g[row]; + for (int col = 0; col < 8; col++) + if (bits & (0x80 >> col)) { + int px = x + col * sc, py = y + row * sc; + fb_rect(buf, px, py, px + sc + (bold ? 1 : 0), py + sc); + } + } + return 6 * sc + (bold ? 1 : 0); +} + +static int draw_text_ex(uint8_t *buf, int x, int y, const char *s, int sc, int bold) { + for (; *s; s++) + x += draw_char_ex(buf, x, y, *s, sc, bold); + return x; +} + +static int text_w_latin(const char *s, int sc, int bold) { + return (int)strlen(s) * (6 * sc + (bold ? 1 : 0)); +} + +#define JP_GAP 1 + +static uint32_t utf8_next(const char **s) { + const unsigned char *p = (const unsigned char *)*s; + uint32_t cp; + if (p[0] < 0x80) { cp = p[0]; *s += p[0] ? 1 : 0; return cp; } + if ((p[0] & 0xE0) == 0xC0) { cp = ((p[0] & 0x1F) << 6) | (p[1] & 0x3F); *s += 2; } + else if ((p[0] & 0xF0) == 0xE0) { + cp = ((p[0] & 0x0F) << 12) | ((p[1] & 0x3F) << 6) | (p[2] & 0x3F); + *s += 3; + } else { cp = '?'; *s += 4; } + return cp; +} + +static const struct jpglyph *jp_find(uint32_t cp, int size) { + for (unsigned i = 0; i < JPGLYPH_COUNT; i++) + if (jpglyphs[i].cp == cp && jpglyphs[i].size == size) + return &jpglyphs[i]; + return NULL; +} + +static void jp_blit(uint8_t *buf, int x, int y, const struct jpglyph *g) { + int stride = (g->w + 7) / 8; + for (int row = 0; row < g->h; row++) + for (int col = 0; col < g->w; col++) + if (jpbits[g->off + row * stride + (col >> 3)] & (0x80 >> (col & 7))) + fb_set(buf, x + col, y + row); +} + +static int draw_text_jp(uint8_t *buf, int x, int y, const char *s, int size) { + while (*s) { + uint32_t cp = utf8_next(&s); + const struct jpglyph *g = jp_find(cp, size); + if (g) { + jp_blit(buf, x, y, g); + x += g->w + JP_GAP; + } else { + x += size + JP_GAP; + } + } + return x; +} + +static int text_w_jp(const char *s, int size) { + int w = 0; + while (*s) { + uint32_t cp = utf8_next(&s); + const struct jpglyph *g = jp_find(cp, size); + w += (g ? g->w : size) + JP_GAP; + } + return w > 0 ? w - JP_GAP : 0; +} + +#define STAT_MAX 6 + +struct face_geo { + int lx, rx; + int eye_y; + int mouth_y; +}; + +static void draw_zzz_at(uint8_t *buf, int x, int y) { + draw_char_ex(buf, x, y, 'z', 1, 0); + draw_char_ex(buf, x + 8, y - 10, 'z', 2, 0); + draw_char_ex(buf, x + 22, y - 26, 'Z', 2, 1); +} + +static void draw_sparkle_at(uint8_t *buf, int cx, int cy, int r, int ph) { + int px[4] = {cx - r, cx + r, cx - r + 4, cx + r - 4}; + int py[4] = {cy - r, cy - r + 4, cy + r, cy + r - 6}; + for (int i = 0; i < 4; i++) { + if (((i + ph / 2) & 1) == 0) + continue; + int s = 2 + ((ph / 2 + i) & 1); + fb_hline(buf, px[i] - s, py[i], 2 * s + 1, 1); + fb_vline(buf, px[i], py[i] - s, 2 * s + 1, 1); + } +} + +static void draw_heart(uint8_t *buf, int cx, int cy, int r) { + fb_disc(buf, cx - r / 2, cy, (r + 1) / 2); + fb_disc(buf, cx + r / 2, cy, (r + 1) / 2); + for (int dy = 0; dy <= r; dy++) { + int half = r - dy; + fb_rect(buf, cx - half, cy + dy, cx + half + 1, cy + dy + 1); + } +} + +enum petframe { PF_IDLE, PF_BLINK, PF_HAPPY, PF_SAD, PF_EAT, PF_LOOK, + PF_CROUCH, PF_JUMP, PF_WALK1, PF_WALK2, PF_EAT_CLOSED, PF_LOOK_HALF, + PF_WALK3, PF_WALK4 }; + +struct anim { + int frame; + int flip; + int dx, dy; + int zzz, spark, heart; +}; + +static void draw_sprite(uint8_t *buf, const uint8_t *spr, int x, int y, int flip) { + for (int row = 0; row < PET_H; row++) + for (int col = 0; col < PET_W; col++) + if (spr[row * PET_STRIDE + (col >> 3)] & (0x80 >> (col & 7))) + fb_set(buf, x + (flip ? PET_W - 1 - col : col), y + row); +} + +static void draw_face(uint8_t *buf, const struct face_geo *g0, + const struct anim *a) { + static const uint8_t *const FR[] = { + pet_idle, pet_blink, pet_happy, pet_sad, pet_eat, pet_look, + pet_crouch, pet_jump, pet_walk1, pet_walk2, pet_eat_closed, pet_look_half, + pet_walk3, pet_walk4, + }; + int cx = (g0->lx + g0->rx) / 2 + a->dx; + int cy = (g0->eye_y + g0->mouth_y) / 2 + a->dy; + int x = cx - PET_W / 2, y = cy - PET_H / 2; + + draw_sprite(buf, FR[a->frame], x, y, a->flip); + + if (a->heart) { + int hp = a->heart - 1; + if ((hp / 2) % 2 == 0) + draw_heart(buf, cx, y - 8, 6 + (hp / 4) % 3); + } + if (a->zzz) + draw_zzz_at(buf, x + PET_W - 4, y + 6); + if (a->spark) + draw_sparkle_at(buf, cx, cy, PET_W / 2 + 4, a->spark - 1); +} + +static void draw_track(uint8_t *buf, int x, int y, int val, + int sw, int gap, int sh) { + for (int i = 0; i < STAT_MAX; i++) { + int sx = x + i * (sw + gap); + fb_frame(buf, sx, y, sx + sw, y + sh); + if (i < val) + fb_rect(buf, sx + 1, y + 1, sx + sw, y + sh); + } +} + +static void draw_button_jp(uint8_t *buf, int x, int y, const char *label, + int size, int active) { + int w = text_w_jp(label, size) + 8; + int h = size + 6; + fb_frame(buf, x, y, x + w, y + h); + if (active) + fb_frame(buf, x - 2, y - 2, x + w + 2, y + h + 2); + draw_text_jp(buf, x + 4, y + 3, label, size); +} + +enum action { ACT_NONE, ACT_FEED, ACT_PLAY, ACT_CLEAN }; + +enum gesture { + G_NONE, G_BLINK, G_DBLINK, G_LOOKL, G_HEART, G_WALK, +}; + +#define ACTION_LEN 10 +#define SLEEP_AFTER 60 +#define DECAY_EVERY 150 +#define GHOST_EVERY 200 +#define FRAME_DELAY_MS 35 + +static uint8_t frame_buf[DISP_BUF_SIZE]; + +struct pet { + int hunger, energy, mood; + enum action action; + int action_frames; + int last_interaction; + int shown; + + enum gesture gesture; + int gesture_frames; + int gesture_total; + int idle_gap; +}; + +static int clampi(int v, int lo, int hi) { + return v < lo ? lo : (v > hi ? hi : v); +} + +static void pet_trigger(struct pet *p, enum action a, int frame) { + p->action = a; + p->action_frames = ACTION_LEN; + p->last_interaction = frame; + p->gesture = G_NONE; + p->gesture_frames = 0; + switch (a) { + case ACT_FEED: p->hunger = clampi(p->hunger + 2, 0, STAT_MAX); break; + case ACT_PLAY: p->mood = clampi(p->mood + 2, 0, STAT_MAX); + p->energy = clampi(p->energy - 1, 0, STAT_MAX); break; + case ACT_CLEAN: p->mood = clampi(p->mood + 1, 0, STAT_MAX); break; + default: break; + } +} + +static void gesture_start(struct pet *p, enum gesture g, int len) { + p->gesture = g; + p->gesture_frames = len; + p->gesture_total = len; +} + +static void pet_idle_tick(struct pet *p) { + if (p->action != ACT_NONE || p->hunger == 0) + return; + + if (p->gesture != G_NONE) { + if (--p->gesture_frames <= 0) { + p->gesture = G_NONE; + p->idle_gap = 4 + rand() % 6; + } + return; + } + if (p->idle_gap > 0) { + p->idle_gap--; + return; + } + + int r = rand() % 100; + if (r < 12) gesture_start(p, G_BLINK, 1); + else if (r < 26) gesture_start(p, G_DBLINK, 3); + else if (r < 62) gesture_start(p, G_LOOKL, 5); + else if (r < 84) gesture_start(p, G_WALK, 16); + else gesture_start(p, G_HEART, 8); +} + +#define JUMP_PEAK 10 + +static int jump_dy(int phase, int total) { + int span = total - 1; + if (span < 1) + return 0; + if (phase < 0) + phase = 0; + if (phase > span) + phase = span; + return -(JUMP_PEAK * 4 * phase * (span - phase)) / (span * span); +} + +static const int WALKX[16] = {0, 2, 4, 6, 5, 3, 1, 0, -1, -3, -5, -6, -5, -3, -1, 0}; + +static const int WALK_CYCLE[4] = {PF_WALK1, PF_WALK2, PF_WALK3, PF_WALK4}; + +static void compute_face_state(const struct pet *p, int frame, struct anim *a) { + memset(a, 0, sizeof(*a)); + a->frame = PF_IDLE; + + if (p->action != ACT_NONE) { + int phase = ACTION_LEN - p->action_frames; + switch (p->action) { + case ACT_FEED: a->frame = (phase & 1) ? PF_EAT_CLOSED : PF_EAT; break; + case ACT_PLAY: + if (phase == 0 || phase == 4) { + a->frame = PF_CROUCH; + } else if (phase >= 1 && phase <= 3) { + a->frame = PF_JUMP; + a->dy = jump_dy(phase - 1, 3); + } else { + a->frame = PF_IDLE; + } + break; + case ACT_CLEAN: a->frame = PF_HAPPY; a->spark = phase + 1; break; + default: break; + } + return; + } + if (p->hunger == 0) { + a->frame = PF_SAD; + return; + } + if (frame - p->last_interaction > SLEEP_AFTER) { + a->frame = PF_BLINK; + a->zzz = 1; + return; + } + + int ph = p->gesture_total - p->gesture_frames; + switch (p->gesture) { + case G_BLINK: a->frame = PF_BLINK; break; + case G_DBLINK: a->frame = (ph == 1) ? PF_IDLE : PF_BLINK; break; + case G_LOOKL: { + int last = p->gesture_total - 1; + if (ph >= last) + a->frame = PF_IDLE; + else if (ph == 0 || ph == last - 1) + a->frame = PF_LOOK_HALF; + else + a->frame = PF_LOOK; + break; + } + case G_WALK: { + int i = ph % 16; + a->frame = WALK_CYCLE[i % 4]; + a->dx = WALKX[i]; + a->flip = (WALKX[(i + 1) % 16] < WALKX[i]); + break; + } + case G_HEART: a->frame = PF_HAPPY; a->heart = ph + 1; break; + default: a->frame = PF_IDLE; break; + } +} + +static void compose_landscape(const struct pet *p, const struct anim *a) { + static const struct face_geo g = {62, 92, 46, 66}; + static const struct { const char *name; int val_off; } row[3] = { + {"空腹", offsetof(struct pet, hunger)}, + {"元気", offsetof(struct pet, energy)}, + {"気分", offsetof(struct pet, mood)}, + }; + + fb_frame(frame_buf, 2, 0, 247, 121); + int tx = draw_text_ex(frame_buf, 8, 2, "Open-EP", 2, 1); + draw_text_jp(frame_buf, tx + 6, 2, "ペット", 16); + fb_hline(frame_buf, 4, 20, 242, 1); + + draw_face(frame_buf, &g, a); + + for (int i = 0; i < 3; i++) { + int val = *(const int *)((const char *)p + row[i].val_off); + int ly = 24 + i * 26; + draw_text_jp(frame_buf, 132, ly, row[i].name, 20); + draw_track(frame_buf, 176, ly + 3, val, 9, 1, 14); + } + + int wf = text_w_jp("エサ", 14) + 8; + int wp = text_w_jp("あそぶ", 14) + 8; + int wc = text_w_jp("そうじ", 14) + 8; + int left = 4, cell = 242 / 3; + draw_button_jp(frame_buf, left + 0 * cell + (cell - wf) / 2, 98, "エサ", 14, p->action == ACT_FEED); + draw_button_jp(frame_buf, left + 1 * cell + (cell - wp) / 2, 98, "あそぶ", 14, p->action == ACT_PLAY); + draw_button_jp(frame_buf, left + 2 * cell + (cell - wc) / 2, 98, "そうじ", 14, p->action == ACT_CLEAN); +} + +static void compose_portrait(const struct pet *p, const struct anim *a) { + static const struct face_geo g = {46, 76, 68, 92}; + static const struct { const char *name; int val_off; } row[3] = { + {"空腹", offsetof(struct pet, hunger)}, + {"元気", offsetof(struct pet, energy)}, + {"気分", offsetof(struct pet, mood)}, + }; + + fb_frame(frame_buf, 3, 1, 118, 248); + + draw_text_ex(frame_buf, (122 - text_w_latin("Open-EP", 2, 1)) / 2, 3, + "Open-EP", 2, 1); + draw_text_jp(frame_buf, (122 - text_w_jp("ペット", 16)) / 2, 22, "ペット", 16); + fb_hline(frame_buf, 4, 40, 114, 1); + + draw_face(frame_buf, &g, a); + + int wf = text_w_jp("エサ", 14) + 8; + int wp = text_w_jp("あそぶ", 14) + 8; + int wc = text_w_jp("そうじ", 14) + 8; + int gap = 8; + int fx = (122 - (wf + gap + wp)) / 2; + draw_button_jp(frame_buf, fx, 126, "エサ", 14, p->action == ACT_FEED); + draw_button_jp(frame_buf, fx + wf + gap, 126, "あそぶ", 14, p->action == ACT_PLAY); + draw_button_jp(frame_buf, (122 - wc) / 2, 150, "そうじ", 14, p->action == ACT_CLEAN); + + for (int i = 0; i < 3; i++) { + int val = *(const int *)((const char *)p + row[i].val_off); + int ly = 176 + i * 24; + draw_text_jp(frame_buf, 8, ly, row[i].name, 20); + draw_track(frame_buf, 52, ly + 3, val, 9, 1, 14); + } +} + +static void render_anim(const struct pet *p, const struct anim *a) { + fb_clear(frame_buf); + if (g_portrait) + compose_portrait(p, a); + else + compose_landscape(p, a); +} + +static void compose_frame(const struct pet *p, int frame) { + struct anim a; + + compute_face_state(p, frame, &a); + render_anim(p, &a); +} + +static int is_walk(int f) { + return f == PF_WALK1 || f == PF_WALK2 || f == PF_WALK3 || f == PF_WALK4; +} +static int is_eat(int f) { return f == PF_EAT || f == PF_EAT_CLOSED; } + +static int mask_frame(int f) { + return f == PF_SAD || is_eat(f) || is_walk(f); +} + +static int blink_between(int now, int prev) { + if (now == prev || (is_walk(now) && is_walk(prev)) || + (is_eat(now) && is_eat(prev))) + return 0; + return mask_frame(now) || mask_frame(prev); +} + +static struct termios kbd_orig; +static int kbd_raw; + +static void kbd_enable(void) { + if (!isatty(STDIN_FILENO)) + return; + tcgetattr(STDIN_FILENO, &kbd_orig); + struct termios t = kbd_orig; + t.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + int fl = fcntl(STDIN_FILENO, F_GETFL); + fcntl(STDIN_FILENO, F_SETFL, fl | O_NONBLOCK); + kbd_raw = 1; +} + +static void kbd_restore(void) { + if (kbd_raw) + tcsetattr(STDIN_FILENO, TCSANOW, &kbd_orig); +} + +static int kbd_get(void) { + unsigned char c; + return read(STDIN_FILENO, &c, 1) == 1 ? c : -1; +} + +int main(int argc, char **argv) { + int auto_mode = !isatty(STDIN_FILENO); + + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "auto")) + auto_mode = 1; + else if (!strcmp(argv[i], "portrait")) + g_portrait = 1; + else if (!strcmp(argv[i], "landscape")) + g_portrait = 0; + } + + if (g_portrait) { + scr_w = DISP_VIS; + scr_h = DISP_W; + } else { + scr_w = DISP_W; + scr_h = DISP_VIS; + } + + struct pet pet = { + .hunger = 4, .energy = 5, .mood = 5, + .action = ACT_NONE, .action_frames = 0, .last_interaction = 0, + .shown = PF_IDLE, + .gesture = G_NONE, .gesture_frames = 0, .idle_gap = 0, + }; + + srand((unsigned)time(NULL)); + + epd_init(); + + compose_frame(&pet, 0); + epd_set_base_map(frame_buf); + sleep_ms(500); + epd_partial_begin(); + + kbd_enable(); + + const enum action demo_seq[] = { ACT_FEED, ACT_PLAY, ACT_CLEAN }; + int demo_i = 0; + int demo_cooldown = 0; + int running = 1; + + for (int frame = 1; running; frame++) { + + if (auto_mode) { + if (demo_cooldown > 0) + demo_cooldown--; + if (pet.action == ACT_NONE && pet.gesture == G_NONE && + demo_cooldown == 0) { + pet_trigger(&pet, demo_seq[demo_i++ % (int)(sizeof(demo_seq) / sizeof(demo_seq[0]))], frame); + demo_cooldown = ACTION_LEN + 40; + } + } else { + int c; + while ((c = kbd_get()) != -1) { + switch (c) { + case 'f': pet_trigger(&pet, ACT_FEED, frame); break; + case 'p': pet_trigger(&pet, ACT_PLAY, frame); break; + case 'c': pet_trigger(&pet, ACT_CLEAN, frame); break; + case 'q': running = 0; break; + } + } + } + + if (frame % DECAY_EVERY == 0) { + pet.hunger = clampi(pet.hunger - 1, 0, STAT_MAX); + if (frame % (DECAY_EVERY * 2) == 0) + pet.energy = clampi(pet.energy - 1, 0, STAT_MAX); + if (pet.hunger <= 1) + pet.mood = clampi(pet.mood - 1, 0, STAT_MAX); + } + + pet_idle_tick(&pet); + + struct anim a; + compute_face_state(&pet, frame, &a); + if (blink_between(a.frame, pet.shown)) { + struct anim t; + memset(&t, 0, sizeof(t)); + t.frame = PF_BLINK; + render_anim(&pet, &t); + epd_partial_frame(frame_buf); + } + render_anim(&pet, &a); + epd_partial_frame(frame_buf); + pet.shown = a.frame; + + if (pet.action != ACT_NONE && --pet.action_frames <= 0) + pet.action = ACT_NONE; + + if (frame % GHOST_EVERY == 0) { + epd_HWreset(); + epd_reg_init(); + epd_set_base_map(frame_buf); + epd_partial_begin(); + } + + sleep_ms(FRAME_DELAY_MS); + } + + kbd_restore(); + epd_partial_end(); + close(spi_fd); + epd_gpio_release(); + return 0; +} + +#endif /* PET_APP_H */ diff --git a/2.13/mono/spi/pet/petsprite.h b/2.13/mono/spi/pet/petsprite.h new file mode 100644 index 0000000..d950ac7 --- /dev/null +++ b/2.13/mono/spi/pet/petsprite.h @@ -0,0 +1,624 @@ +/* generated by sprite_gen.py from dog*.png - do not edit */ +#ifndef PETSPRITE_H +#define PETSPRITE_H +#include +#define PET_W 65 +#define PET_H 56 +#define PET_STRIDE ((65+7)/8) +static const uint8_t pet_idle[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xEF,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0x79,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, + 0xF9,0xFF,0xE0,0x00,0x00,0x00,0x00,0x07,0xFF,0xC0,0x3F,0xFC, + 0x00,0x00,0x00,0x00,0x07,0x9E,0x00,0x03,0x3C,0x00,0x00,0x00, + 0x00,0x1F,0x9E,0x00,0x03,0x3F,0x00,0x00,0x00,0x00,0x1C,0x00, + 0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x3C,0xF0,0x00,0x00,0x07, + 0x80,0x00,0x00,0x00,0x73,0xF0,0x00,0x01,0xC1,0xE0,0x00,0x00, + 0x00,0x63,0x80,0x00,0x01,0xC0,0xE0,0x00,0x00,0x01,0xE3,0xC0, + 0x00,0x01,0xE0,0xF0,0x00,0x00,0x01,0x80,0xC0,0x00,0x00,0x60, + 0x30,0x00,0x00,0x03,0x8F,0xC0,0x00,0x00,0x61,0xBC,0x00,0x00, + 0x03,0xBF,0x80,0x00,0x00,0x61,0xFC,0x00,0x00,0x03,0xBF,0x80, + 0x00,0x00,0x60,0xFC,0x00,0x00,0x03,0xFF,0x80,0x00,0x00,0x79, + 0xFC,0x00,0x00,0x03,0xFF,0x9E,0x00,0x1E,0x3F,0xFC,0x00,0x00, + 0x01,0xFF,0x9F,0x00,0x3E,0x3F,0xF0,0x00,0x00,0x01,0xFF,0xBF, + 0x00,0x3F,0x3F,0xF0,0x00,0x00,0x00,0x77,0xB7,0x00,0x3F,0x3F, + 0xF0,0x00,0x00,0x00,0x7F,0xBF,0x00,0x3F,0x3F,0xF0,0x00,0x00, + 0x00,0x3E,0x3F,0x3F,0x3F,0x0F,0xE0,0x00,0x00,0x00,0x1C,0x1E, + 0x3F,0x1E,0x0F,0x80,0x00,0x00,0x00,0x1E,0x1E,0x3F,0x1E,0x0F, + 0x80,0x00,0x00,0x00,0x1F,0x00,0x3F,0x00,0x0F,0x00,0x00,0x00, + 0x00,0x07,0x00,0x0C,0x00,0x0F,0x00,0x00,0x00,0x00,0x07,0xC0, + 0x7F,0x80,0x7F,0x00,0x00,0x00,0x00,0x03,0xC0,0x7F,0x80,0x78, + 0x00,0x00,0x00,0x00,0x03,0xF8,0x7F,0x81,0xF8,0x1F,0x80,0x00, + 0x00,0x00,0xFF,0x00,0x3F,0xF8,0x1F,0xC0,0x00,0x00,0x00,0x1F, + 0x00,0x3F,0x78,0x1F,0xC0,0x00,0x00,0x00,0x7F,0xFF,0xFF,0x7C, + 0x3F,0xC0,0x00,0x00,0x00,0x79,0xFF,0xE0,0x0C,0x3C,0xC0,0x00, + 0x00,0x00,0x79,0xFF,0xE0,0x0F,0x3C,0xE0,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x07,0xB0,0xE0,0x00,0x00,0x00,0xF0,0x00,0x00,0x01, + 0xB0,0x60,0x00,0x00,0x00,0xF0,0x00,0x00,0x21,0xFC,0x60,0x00, + 0x00,0x00,0x70,0x00,0x00,0x21,0xFC,0x60,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x7C,0xFC,0xE0,0x00,0x00,0x00,0xF8,0x60,0xC0,0x7C, + 0xF8,0xE0,0x00,0x00,0x00,0xD8,0x60,0xC0,0x60,0xF0,0x60,0x00, + 0x00,0x00,0xD8,0x7B,0xC1,0xE0,0xF3,0xE0,0x00,0x00,0x00,0xD8, + 0x3B,0x81,0xC0,0x33,0xC0,0x00,0x00,0x00,0xF8,0x3F,0x81,0xE0, + 0x37,0xC0,0x00,0x00,0x03,0xF8,0x3F,0x83,0xF8,0xFF,0x80,0x00, + 0x00,0x03,0x98,0x3F,0x83,0x38,0xFC,0x00,0x00,0x00,0x03,0xD8, + 0x3F,0x83,0x78,0xFC,0x00,0x00,0x00,0x03,0xD8,0x3F,0x03,0x60, + 0xE0,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFB,0xFF,0xE0,0x00,0x00, + 0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x0F, + 0xE0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_blink[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xEF,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0x79,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, + 0xF9,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0xF9,0xC0,0x1F,0xF0, + 0x00,0x00,0x00,0x00,0x07,0xFE,0x40,0x03,0xFC,0x00,0x00,0x00, + 0x00,0x0F,0x9E,0x00,0x03,0x1F,0x00,0x00,0x00,0x00,0x0C,0x00, + 0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x3C,0xF0,0x00,0x00,0x03, + 0x80,0x00,0x00,0x00,0x7B,0xF0,0x00,0x00,0xC1,0xE0,0x00,0x00, + 0x00,0x63,0x80,0x00,0x00,0xC0,0x60,0x00,0x00,0x01,0xE3,0xC0, + 0x00,0x00,0xE0,0x70,0x00,0x00,0x01,0xC0,0xC0,0x00,0x00,0x20, + 0x30,0x00,0x00,0x03,0xCF,0xC0,0x00,0x00,0x61,0xBC,0x00,0x00, + 0x03,0xFF,0x80,0x00,0x00,0x61,0xFC,0x00,0x00,0x03,0xFF,0x80, + 0x00,0x00,0x60,0x7C,0x00,0x00,0x03,0xFF,0x80,0x00,0x00,0x79, + 0xFC,0x00,0x00,0x03,0xFF,0x80,0x00,0x00,0x19,0xFC,0x00,0x00, + 0x01,0xFF,0x80,0x00,0x00,0x1F,0xF0,0x00,0x00,0x01,0xFF,0x80, + 0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x1F, + 0xF0,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x1F,0xF0,0x00,0x00, + 0x00,0x3E,0x7F,0x00,0x3F,0x0F,0xE0,0x00,0x00,0x00,0x0C,0x7F, + 0x3F,0x3F,0x0F,0x80,0x00,0x00,0x00,0x0E,0x00,0x3F,0x00,0x0F, + 0x80,0x00,0x00,0x00,0x0C,0x00,0x3F,0x00,0x07,0x00,0x00,0x00, + 0x00,0x0F,0x00,0x3F,0x00,0x0F,0x00,0x00,0x00,0x00,0x07,0xC0, + 0x7F,0x80,0x7F,0x00,0x00,0x00,0x00,0x03,0xC0,0x7F,0x80,0x78, + 0x00,0x00,0x00,0x00,0x03,0xF8,0x7F,0x81,0xF8,0x1F,0x80,0x00, + 0x00,0x00,0xFF,0x00,0x3F,0xF8,0x1F,0xC0,0x00,0x00,0x00,0x1F, + 0x00,0x3F,0x78,0x1F,0xC0,0x00,0x00,0x00,0x7F,0xFF,0xFF,0x7C, + 0x3F,0xC0,0x00,0x00,0x00,0x79,0xFF,0xE0,0x0C,0x3C,0xC0,0x00, + 0x00,0x00,0x79,0xFF,0xE0,0x0F,0x3C,0xE0,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x07,0xB0,0xE0,0x00,0x00,0x00,0xD0,0x00,0x00,0x01, + 0xB0,0x60,0x00,0x00,0x00,0xF0,0x00,0x00,0x21,0xFC,0x60,0x00, + 0x00,0x00,0x70,0x00,0x00,0x21,0xFC,0x60,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x7D,0xFC,0xE0,0x00,0x00,0x00,0xF8,0x60,0xC0,0x7C, + 0x7C,0xE0,0x00,0x00,0x00,0xD8,0x60,0xC0,0x60,0x70,0x60,0x00, + 0x00,0x00,0xD8,0x79,0xC1,0xE0,0x73,0xE0,0x00,0x00,0x00,0xD8, + 0x39,0x81,0xC0,0x33,0xC0,0x00,0x00,0x00,0xF8,0x3F,0x81,0xE0, + 0x37,0xC0,0x00,0x00,0x03,0xF8,0x3F,0x83,0xF8,0x7F,0x80,0x00, + 0x00,0x03,0x98,0x3F,0x83,0x18,0x7C,0x00,0x00,0x00,0x03,0xD8, + 0x3F,0x83,0x78,0x7C,0x00,0x00,0x00,0x03,0xD8,0x3F,0x03,0x60, + 0x60,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00, + 0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x0F, + 0xE0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_happy[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xEF,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0x79,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0xFB, + 0xF8,0x3F,0xF0,0x00,0x00,0x00,0x00,0x07,0xFF,0xC0,0x3F,0xFE, + 0x00,0x00,0x00,0x00,0x07,0x9E,0x00,0x03,0x1F,0x00,0x00,0x00, + 0x00,0x1F,0x9E,0x00,0x03,0x13,0x00,0x00,0x00,0x00,0x3C,0xF0, + 0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x30,0xF0,0x00,0x00,0x01, + 0xE0,0x00,0x00,0x00,0xF3,0xE0,0x00,0x00,0xC0,0x60,0x00,0x00, + 0x01,0xE3,0xC0,0x00,0x00,0xF0,0x70,0x00,0x00,0x01,0x80,0xC0, + 0x00,0x00,0x70,0x30,0x00,0x00,0x03,0x9F,0xC0,0x00,0x00,0x71, + 0xFC,0x00,0x00,0x03,0xBF,0x80,0x00,0x00,0x71,0xFC,0x00,0x00, + 0x03,0xBF,0x80,0x00,0x00,0x70,0x7C,0x00,0x00,0x03,0xFF,0x80, + 0x00,0x00,0x79,0xFC,0x00,0x00,0x03,0xFF,0x9E,0x00,0x1E,0x1B, + 0xFC,0x00,0x00,0x01,0xFF,0x9F,0x00,0x3F,0x1B,0xF0,0x00,0x00, + 0x01,0xFF,0xBF,0x00,0x3F,0x1B,0xF0,0x00,0x00,0x00,0xF7,0xBF, + 0x00,0x3F,0x1F,0xF0,0x00,0x00,0x00,0x3E,0x3F,0x00,0x3F,0x0D, + 0xE0,0x00,0x00,0x00,0x3E,0x3F,0x3F,0x3F,0x0F,0xE0,0x00,0x00, + 0x00,0x1C,0x1E,0x3F,0x1E,0x0F,0x80,0x00,0x00,0x00,0x1E,0x1E, + 0x3F,0x1E,0x0F,0x80,0x00,0x00,0x00,0x1C,0x01,0x9E,0x60,0x07, + 0x00,0x00,0x00,0x00,0x1F,0x01,0xCC,0x60,0x0F,0x00,0x00,0x00, + 0x00,0x07,0x01,0xFF,0xE0,0x0C,0x00,0x00,0x00,0x00,0x07,0xC0, + 0xFF,0xC0,0x7C,0x00,0x00,0x00,0x00,0x03,0xF0,0x71,0x80,0xF8, + 0x00,0x00,0x00,0x00,0x00,0xF8,0x7F,0x81,0xE0,0x1F,0x80,0x00, + 0x00,0x00,0xFF,0x1F,0x3F,0xF8,0x1F,0xC0,0x00,0x00,0x00,0x1F, + 0x00,0x3F,0x78,0x1F,0xC0,0x00,0x00,0x00,0x7F,0xFF,0xFF,0x7C, + 0x3D,0xC0,0x00,0x00,0x00,0x79,0xFF,0xE0,0x0F,0x3C,0xC0,0x00, + 0x00,0x00,0x70,0x00,0x00,0x03,0x30,0xE0,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x03,0xB0,0xE0,0x00,0x00,0x00,0xF0,0x00,0x00,0x01, + 0xB0,0x60,0x00,0x00,0x00,0xF0,0x00,0x00,0x21,0xFC,0x60,0x00, + 0x00,0x00,0xF0,0x00,0x00,0x7D,0xFC,0xE0,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x7C,0x7C,0xE0,0x00,0x00,0x00,0xF8,0x60,0xC0,0x7C, + 0xFC,0xE0,0x00,0x00,0x00,0xD8,0x60,0xC0,0x60,0x70,0x60,0x00, + 0x00,0x00,0xD8,0x79,0xC1,0xE0,0x73,0xE0,0x00,0x00,0x00,0xF8, + 0x3F,0x81,0xE0,0x37,0xC0,0x00,0x00,0x00,0xF8,0x3F,0x81,0xE0, + 0x37,0x80,0x00,0x00,0x03,0xF8,0x3F,0x83,0xF8,0x7F,0x80,0x00, + 0x00,0x03,0x98,0x3F,0x83,0x38,0x7C,0x00,0x00,0x00,0x03,0xD8, + 0x3F,0x83,0x78,0xFC,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF, + 0xE0,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00, + 0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x0F, + 0xE0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_sad[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xE0,0x00, + 0x00,0x00,0x00,0x00,0x00,0x1E,0x71,0xE0,0x00,0x00,0x00,0x00, + 0x00,0x01,0xFB,0x80,0x3F,0x60,0x00,0x00,0x00,0x00,0x1F,0xFF, + 0x80,0x3F,0xFC,0x00,0x00,0x00,0x00,0x1E,0x1C,0x00,0x03,0xFC, + 0x00,0x00,0x00,0x00,0x3E,0x1C,0x00,0x03,0xFF,0x00,0x00,0x00, + 0x00,0x30,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0xF1,0xC0, + 0x00,0x00,0x07,0xC0,0x00,0x00,0x01,0xE3,0xC0,0x00,0x00,0xC1, + 0xE0,0x00,0x00,0x01,0x82,0x00,0x00,0x00,0xC0,0x60,0x00,0x00, + 0x07,0x83,0x80,0x00,0x00,0xE0,0x78,0x00,0x00,0x07,0x03,0x80, + 0x00,0x00,0x60,0x38,0x00,0x00,0x0F,0x17,0x80,0x00,0x00,0x60, + 0x3E,0x00,0x00,0x0C,0x16,0x00,0x00,0x00,0x60,0x0E,0x00,0x00, + 0x0F,0xF6,0x06,0x00,0x70,0x78,0x3E,0x00,0x00,0x0F,0xF6,0x06, + 0x00,0x70,0x38,0x7E,0x00,0x00,0x0F,0xF6,0x0E,0x00,0x70,0x38, + 0x7E,0x00,0x00,0x0F,0xF6,0x3E,0x00,0x7E,0x3B,0xFE,0x00,0x00, + 0x07,0xFE,0x3C,0x00,0x1E,0x3B,0xFC,0x00,0x00,0x01,0xFC,0x00, + 0x00,0x00,0x3B,0xF8,0x00,0x00,0x01,0xFC,0xFE,0x00,0x7F,0x3F, + 0xF8,0x00,0x00,0x00,0xFC,0xFE,0x00,0x7F,0x0D,0xE0,0x00,0x00, + 0x00,0xFC,0xFE,0x7E,0x7F,0x0F,0xE0,0x00,0x00,0x00,0x38,0x7C, + 0x7E,0x7F,0x0F,0xC0,0x00,0x00,0x00,0x30,0x38,0x7E,0x1E,0x07, + 0x00,0x00,0x00,0x00,0x3C,0x00,0x3C,0x1E,0x0F,0x00,0x00,0x00, + 0x00,0x1C,0x00,0x18,0x00,0x0F,0x00,0x00,0x00,0x00,0x1E,0x00, + 0x3C,0x00,0x3F,0x00,0x00,0x00,0x00,0x06,0x00,0x7E,0x00,0x38, + 0x00,0x00,0x00,0x00,0x07,0xE0,0x77,0x01,0xF8,0x00,0x00,0x00, + 0x00,0x01,0xFC,0x63,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0xFC, + 0x00,0x3F,0x78,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x7C, + 0x00,0x00,0x00,0x00,0x01,0xE7,0xFF,0xE0,0x0C,0x00,0x00,0x00, + 0x00,0x01,0xE7,0xFF,0xE0,0x0E,0x0F,0xF0,0x00,0x00,0x01,0x80, + 0x00,0x00,0x06,0x0F,0xF0,0x00,0x00,0x01,0x80,0x00,0x00,0x07, + 0x0F,0xF0,0x00,0x00,0x03,0x80,0x00,0x00,0x07,0xBF,0xF0,0x00, + 0x00,0x03,0x80,0x00,0x00,0x03,0xB8,0x70,0x00,0x00,0x03,0xC0, + 0x00,0x00,0xFB,0xB8,0x78,0x00,0x00,0x03,0xC0,0x00,0x00,0xF9, + 0xF8,0x78,0x00,0x00,0x07,0xE0,0xE1,0x80,0xF9,0xFC,0x78,0x00, + 0x00,0x06,0xE0,0xE1,0x80,0xE0,0x6C,0x18,0x00,0x00,0x06,0xE0, + 0xF7,0x81,0xE0,0x78,0xF8,0x00,0x00,0x07,0xE0,0x3F,0x01,0xE0, + 0x78,0xF0,0x00,0x00,0x07,0xE0,0x3F,0x01,0xE0,0x78,0x70,0x00, + 0x00,0x0F,0xF0,0x3F,0x07,0xF8,0x7B,0xF0,0x00,0x00,0x0C,0x70, + 0x3F,0x07,0x38,0x7B,0xC0,0x00,0x00,0x0D,0xF0,0x3F,0x07,0xF9, + 0xFF,0xC0,0x00,0x00,0x0D,0xF0,0x1C,0x07,0xC1,0xFE,0x00,0x00, + 0x00,0x0F,0xFE,0xFF,0xB7,0xFF,0xCC,0x00,0x00,0x00,0x07,0xFF, + 0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_eat[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x80,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xF0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0xB8,0xF0,0x00,0x00,0x00,0x00,0x00,0x01,0xFF, + 0xF8,0xFE,0xF0,0x00,0x00,0x00,0x00,0x0F,0xFF,0xC0,0x1F,0xFC, + 0x00,0x00,0x00,0x00,0x0F,0x1E,0x00,0x03,0x9E,0x00,0x00,0x00, + 0x00,0x1F,0x1E,0x00,0x03,0x9F,0x00,0x00,0x00,0x00,0x18,0x00, + 0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x78,0xF0,0x00,0x00,0x03, + 0xC0,0x00,0x00,0x00,0xF3,0xF0,0x00,0x00,0xC1,0xE0,0x00,0x00, + 0x00,0xC3,0x80,0x00,0x00,0xC0,0x60,0x00,0x00,0x03,0xC3,0xC0, + 0x00,0x00,0xF0,0x78,0x00,0x00,0x03,0x80,0xC0,0x00,0x00,0x30, + 0x38,0x00,0x00,0x07,0x9B,0xC0,0x00,0x00,0x71,0xFE,0x00,0x00, + 0x07,0xFB,0x00,0x00,0x00,0x71,0xFE,0x00,0x00,0x07,0xFB,0x80, + 0x00,0x00,0x70,0x7E,0x00,0x00,0x07,0xFB,0x00,0x00,0x00,0x79, + 0xFE,0x00,0x00,0x07,0xFB,0x80,0x00,0x00,0x19,0xFE,0x00,0x00, + 0x07,0xFB,0x9F,0x00,0x1F,0x1B,0xFE,0x00,0x00,0x03,0xFF,0xBF, + 0x80,0x3F,0x9B,0xF8,0x00,0x00,0x00,0xFF,0xB7,0x80,0x37,0x9B, + 0xF8,0x00,0x00,0x00,0xFF,0x3F,0x80,0x3F,0x9F,0xF8,0x00,0x00, + 0x00,0x7E,0x3F,0x9F,0x3F,0x8F,0xE0,0x00,0x00,0x00,0x78,0x1E, + 0x1F,0x1F,0x0F,0xC0,0x00,0x00,0x00,0x3E,0x1E,0x1F,0x1F,0x0F, + 0xC0,0x00,0x00,0x00,0x18,0x00,0x1F,0x00,0x03,0x00,0x00,0x00, + 0x00,0x1E,0x00,0x1F,0x00,0x0F,0x00,0x00,0x00,0x00,0x0F,0x80, + 0xEC,0xE0,0x3F,0x00,0x00,0x00,0x00,0x03,0x80,0xEC,0xE0,0x38, + 0x00,0x00,0x00,0x00,0x03,0xC3,0xFF,0xE0,0xF8,0x0F,0xC0,0x00, + 0x00,0x00,0xFF,0xBB,0xBF,0xF8,0x0F,0xE0,0x00,0x00,0x00,0x7E, + 0x03,0xBF,0xF8,0x0F,0xE0,0x00,0x00,0x00,0xFF,0x83,0xFF,0xFE, + 0x1F,0xE0,0x00,0x00,0x00,0xF3,0x83,0xF1,0x8E,0x1E,0x60,0x00, + 0x00,0x00,0xC7,0xC7,0xF0,0x0F,0x18,0x70,0x00,0x00,0x00,0xCF, + 0xFF,0x80,0x03,0xD8,0x70,0x00,0x00,0x00,0x83,0xFC,0x00,0x01, + 0xD8,0x30,0x00,0x00,0x00,0xC3,0xFC,0x00,0x21,0xFE,0x30,0x00, + 0x00,0x00,0xC1,0x80,0x00,0x21,0xEE,0x30,0x00,0x00,0x03,0xFF, + 0x80,0x00,0x7E,0x6E,0x70,0x00,0x00,0x03,0xFF,0xE0,0xC0,0x7E, + 0x7E,0x70,0x00,0x00,0x03,0xF0,0xE0,0xC0,0x70,0x78,0x30,0x00, + 0x00,0x03,0xF0,0xF3,0xC0,0xF0,0x79,0xF0,0x00,0x00,0x03,0xF0, + 0x33,0x80,0xC0,0x39,0xE0,0x00,0x00,0x03,0xF0,0x3F,0x80,0xF0, + 0x3B,0xE0,0x00,0x00,0x07,0xF0,0x3F,0x83,0xF8,0x7F,0xC0,0x00, + 0x00,0x06,0x30,0x3F,0x83,0x98,0x7E,0x00,0x00,0x00,0x07,0xB0, + 0x3F,0x83,0xF8,0x7E,0x00,0x00,0x00,0x07,0xB0,0x3E,0x03,0xE0, + 0x60,0x00,0x00,0x00,0x07,0xFD,0xBF,0xFF,0xFF,0xE0,0x00,0x00, + 0x00,0x03,0xFF,0xF3,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x1F, + 0xE0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_eat_closed[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xEF,0x80,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0x78,0xE0,0x00,0x00,0x00,0x00,0x00,0x01,0xFF, + 0xF8,0xFF,0xE0,0x00,0x00,0x00,0x00,0x0F,0xFF,0x80,0x1F,0xFC, + 0x00,0x00,0x00,0x00,0x0F,0x1E,0x00,0x03,0x1C,0x00,0x00,0x00, + 0x00,0x1F,0x1E,0x00,0x03,0x1F,0x00,0x00,0x00,0x00,0x78,0xF0, + 0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x70,0xF0,0x00,0x00,0x01, + 0x80,0x00,0x00,0x00,0xF3,0xF0,0x00,0x01,0xC1,0xE0,0x00,0x00, + 0x00,0xC3,0x00,0x00,0x01,0xC0,0x60,0x00,0x00,0x03,0xC3,0xC0, + 0x00,0x01,0xE0,0x70,0x00,0x00,0x07,0x9B,0xC0,0x00,0x00,0x61, + 0xBC,0x00,0x00,0x06,0x1B,0x00,0x00,0x00,0x61,0xBC,0x00,0x00, + 0x07,0xFB,0x00,0x00,0x00,0x61,0xFC,0x00,0x00,0x07,0xFB,0x00, + 0x00,0x00,0x60,0xFC,0x00,0x00,0x07,0xFB,0x00,0x00,0x00,0x79, + 0xFC,0x00,0x00,0x07,0xFB,0x1E,0x00,0x1E,0x3F,0xFC,0x00,0x00, + 0x03,0xFB,0x1F,0x00,0x3F,0x3F,0xF0,0x00,0x00,0x03,0xFF,0x7F, + 0x00,0x3F,0xBF,0xF0,0x00,0x00,0x00,0xFF,0x7F,0x00,0x37,0xBF, + 0xF0,0x00,0x00,0x00,0x7E,0x7F,0x00,0x3F,0x8D,0xE0,0x00,0x00, + 0x00,0x7E,0x7F,0x1E,0x3F,0x8F,0xE0,0x00,0x00,0x00,0x38,0x1E, + 0x3E,0x3F,0x0F,0x80,0x00,0x00,0x00,0x18,0x1C,0x3F,0x0E,0x0F, + 0x80,0x00,0x00,0x00,0x1E,0x00,0x1F,0x00,0x0F,0x00,0x00,0x00, + 0x00,0x0E,0x00,0x4C,0x80,0x0F,0x00,0x00,0x00,0x00,0x0F,0x00, + 0x7F,0x80,0x3E,0x00,0x00,0x00,0x00,0x03,0x00,0x7F,0x80,0x38, + 0x00,0x00,0x00,0x00,0x03,0xC0,0x30,0x01,0xF8,0x0F,0x80,0x00, + 0x00,0x00,0xFF,0x00,0x3F,0xF8,0x0F,0xE0,0x00,0x00,0x00,0x7F, + 0x00,0x3F,0x78,0x0D,0xE0,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x7C, + 0x3D,0xE0,0x00,0x00,0x00,0xEF,0xFF,0xE0,0x0F,0x3C,0x70,0x00, + 0x00,0x00,0xCE,0xC0,0x00,0x07,0x38,0x70,0x00,0x00,0x00,0xCB, + 0xC0,0x00,0x07,0xB8,0x70,0x00,0x00,0x00,0x83,0xC0,0x00,0x01, + 0xB8,0x30,0x00,0x00,0x00,0xC3,0xC0,0x00,0x01,0xFC,0x30,0x00, + 0x00,0x03,0xE3,0x80,0x00,0x7C,0xEC,0x70,0x00,0x00,0x03,0xFF, + 0x00,0x00,0x7C,0x6C,0xF0,0x00,0x00,0x03,0xFF,0xC0,0xC0,0x7C, + 0x7C,0x70,0x00,0x00,0x03,0xF0,0xC0,0xC0,0x60,0x78,0x30,0x00, + 0x00,0x03,0xF0,0xF3,0xC1,0xE0,0x79,0xF0,0x00,0x00,0x03,0xF0, + 0x73,0x81,0xE0,0x37,0xE0,0x00,0x00,0x03,0xF0,0x73,0x81,0xE0, + 0x37,0x80,0x00,0x00,0x0F,0xF0,0x7F,0x83,0xF8,0x7F,0x80,0x00, + 0x00,0x0E,0x70,0x7F,0x83,0x38,0x7C,0x00,0x00,0x00,0x0F,0xF0, + 0x7F,0x83,0x78,0x7C,0x00,0x00,0x00,0x0F,0xFD,0xFF,0xFB,0xFF, + 0xE0,0x00,0x00,0x00,0x0F,0xFD,0xF3,0xFB,0xFF,0xE0,0x00,0x00, + 0x00,0x03,0xFF,0xF3,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x1F, + 0xC0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_look[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF7,0x80,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, + 0xF8,0xFF,0xF0,0x00,0x00,0x00,0x00,0x07,0xFF,0xC0,0x0F,0xFE, + 0x00,0x00,0x00,0x00,0x07,0x8F,0x00,0x01,0x9E,0x00,0x00,0x00, + 0x00,0x0F,0x8F,0x00,0x01,0xDF,0x80,0x00,0x00,0x00,0x0C,0x00, + 0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x1C,0x3C,0x00,0x00,0x03, + 0xC0,0x00,0x00,0x00,0x38,0xFC,0x00,0x00,0x30,0xF0,0x00,0x00, + 0x00,0x30,0xE0,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0xF0,0xF8, + 0x00,0x00,0x3C,0x3C,0x00,0x00,0x00,0xE0,0x38,0x00,0x00,0x1C, + 0x1C,0x00,0x00,0x01,0xE0,0xF8,0x00,0x00,0x1C,0x7E,0x00,0x00, + 0x01,0xFC,0xE0,0x00,0x00,0x1C,0x7E,0x00,0x00,0x01,0xFE,0xE0, + 0x00,0x00,0x0C,0x3E,0x00,0x00,0x01,0xFF,0xE0,0x00,0x00,0x0E, + 0x7E,0x00,0x00,0x01,0xFF,0xE0,0x3E,0x00,0x3F,0xFE,0x00,0x00, + 0x00,0xFF,0xE0,0x3E,0x00,0x7F,0xFC,0x00,0x00,0x00,0xFF,0xE0, + 0xFF,0x00,0x7F,0xFC,0x00,0x00,0x00,0x3D,0xE0,0xEF,0x00,0x7F, + 0xFC,0x00,0x00,0x00,0x3F,0xE0,0xDF,0x00,0x7F,0xF0,0x00,0x00, + 0x00,0x1F,0x80,0x9F,0x1F,0x3F,0xF0,0x00,0x00,0x00,0x06,0x00, + 0x1E,0x1F,0x1F,0xC0,0x00,0x00,0x00,0x07,0x00,0x1E,0x1F,0x1F, + 0xC0,0x00,0x00,0x00,0x07,0x80,0x00,0x1F,0x07,0x80,0x00,0x00, + 0x00,0x07,0x80,0x00,0x0E,0x07,0x80,0x00,0x00,0x00,0x07,0xC0, + 0x00,0x7F,0x8F,0x80,0x00,0x00,0x00,0x01,0xC0,0x00,0x7B,0x8E, + 0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x7B,0xBE,0x3F,0x00,0x00, + 0x00,0x00,0xFF,0xC0,0x03,0xFC,0x3F,0x80,0x00,0x00,0x00,0x3F, + 0xC0,0x03,0xF0,0x3F,0x80,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xF8, + 0x7F,0x80,0x00,0x00,0x00,0xF0,0x7F,0xFE,0x18,0x79,0x80,0x00, + 0x00,0x00,0xF0,0x7F,0xFE,0x1E,0x79,0xC0,0x00,0x00,0x01,0xE0, + 0x00,0x00,0x0F,0x61,0xC0,0x00,0x00,0x01,0xE0,0x00,0x00,0x03, + 0x60,0xC0,0x00,0x00,0x01,0xE0,0x00,0x00,0x43,0xF8,0xC0,0x00, + 0x00,0x00,0xE0,0x00,0x00,0x43,0xF8,0xC0,0x00,0x00,0x01,0xE0, + 0x00,0x00,0xFB,0xF9,0xC0,0x00,0x00,0x01,0xF0,0xC1,0x80,0xF9, + 0xF1,0xC0,0x00,0x00,0x01,0xB0,0xC1,0x80,0xC1,0xE0,0xC0,0x00, + 0x00,0x01,0xB0,0xF7,0x83,0xC1,0xE7,0xC0,0x00,0x00,0x01,0xB0, + 0x77,0x03,0x80,0x67,0x80,0x00,0x00,0x01,0xF0,0x7F,0x03,0xC0, + 0x6F,0x80,0x00,0x00,0x07,0xF0,0x7F,0x07,0xF1,0xFF,0x00,0x00, + 0x00,0x07,0x30,0x7F,0x06,0x71,0xF8,0x00,0x00,0x00,0x07,0xB0, + 0x7F,0x06,0xF1,0xF8,0x00,0x00,0x00,0x07,0xB0,0x7E,0x06,0xC1, + 0xC0,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00, + 0x00,0x01,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F, + 0xC1,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_look_half[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0F,0x3D,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, + 0xFD,0xFF,0xE0,0x00,0x00,0x00,0x00,0x07,0xFF,0xCC,0x3F,0xFC, + 0x00,0x00,0x00,0x00,0x07,0x9E,0x00,0x03,0x3C,0x00,0x00,0x00, + 0x00,0x1F,0x9E,0x00,0x03,0x3F,0x00,0x00,0x00,0x00,0x1C,0x00, + 0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x3C,0xF0,0x00,0x00,0x07, + 0x80,0x00,0x00,0x00,0x70,0xF0,0x00,0x00,0xC1,0xE0,0x00,0x00, + 0x00,0x60,0xC0,0x00,0x00,0xC0,0xE0,0x00,0x00,0x01,0xE0,0xE0, + 0x00,0x00,0xF0,0xF0,0x00,0x00,0x01,0x80,0xE0,0x00,0x00,0x30, + 0x30,0x00,0x00,0x03,0x9C,0xE0,0x00,0x00,0x71,0xBC,0x00,0x00, + 0x03,0xBC,0xC0,0x00,0x00,0x61,0xFC,0x00,0x00,0x03,0xBE,0xC0, + 0x00,0x00,0x60,0xFC,0x00,0x00,0x03,0xFE,0xC0,0x00,0x00,0x79, + 0xFC,0x00,0x00,0x03,0xFF,0xC1,0xE0,0x01,0xFF,0xFC,0x00,0x00, + 0x01,0xFF,0x81,0xF0,0x03,0xFF,0xF0,0x00,0x00,0x01,0xFF,0x83, + 0xF8,0x07,0xFF,0xF0,0x00,0x00,0x00,0x77,0x83,0x78,0x06,0xFF, + 0xF0,0x00,0x00,0x00,0x7F,0x83,0xF8,0x07,0xFF,0xF0,0x00,0x00, + 0x00,0x3E,0x03,0xFB,0xF7,0xEF,0xE0,0x00,0x00,0x00,0x1C,0x01, + 0xE3,0xF1,0xCF,0x80,0x00,0x00,0x00,0x1E,0x01,0xE3,0xF1,0xCF, + 0x80,0x00,0x00,0x00,0x1F,0x00,0x03,0xF0,0x0F,0x00,0x00,0x00, + 0x00,0x07,0x80,0x00,0xC0,0x0F,0x00,0x00,0x00,0x00,0x07,0xC0, + 0x07,0xF0,0x3F,0x00,0x00,0x00,0x00,0x03,0xC0,0x07,0xF0,0x38, + 0x00,0x00,0x00,0x00,0x03,0xF8,0x07,0xF1,0xF8,0x1F,0x80,0x00, + 0x00,0x00,0xFF,0x00,0x3F,0xF8,0x1F,0xC0,0x00,0x00,0x00,0x1F, + 0x00,0x3F,0x78,0x1F,0xC0,0x00,0x00,0x00,0x7F,0xFF,0xFF,0x7C, + 0x3F,0xC0,0x00,0x00,0x00,0x79,0xFF,0xE0,0x0C,0x3C,0xC0,0x00, + 0x00,0x00,0x79,0xFF,0xE0,0x0F,0x3C,0xE0,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x07,0xB0,0xE0,0x00,0x00,0x00,0xF0,0x00,0x00,0x01, + 0xB0,0x60,0x00,0x00,0x00,0xF0,0x00,0x00,0x21,0xFC,0x60,0x00, + 0x00,0x00,0x70,0x00,0x00,0x21,0xFC,0x60,0x00,0x00,0x00,0xF0, + 0x00,0x00,0x7D,0xFC,0xE0,0x00,0x00,0x00,0xF8,0x60,0xC0,0x7C, + 0xFC,0xE0,0x00,0x00,0x00,0xD8,0x60,0xC0,0x60,0xF0,0x60,0x00, + 0x00,0x00,0xD8,0x7B,0xC1,0xE0,0xF3,0xE0,0x00,0x00,0x00,0xD8, + 0x3B,0x81,0xC0,0x33,0xC0,0x00,0x00,0x00,0xF8,0x3F,0x81,0xE0, + 0x37,0xC0,0x00,0x00,0x03,0xF8,0x3F,0x83,0xF8,0xFF,0x80,0x00, + 0x00,0x03,0x98,0x3F,0x83,0x38,0xFC,0x00,0x00,0x00,0x03,0xD8, + 0x3F,0x83,0x78,0xFC,0x00,0x00,0x00,0x03,0xD8,0x3F,0x03,0x60, + 0xE0,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFB,0xFF,0xE0,0x00,0x00, + 0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x0F, + 0xE0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_crouch[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFE, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00, + 0x00,0x00,0x00,0x00,0x3E,0xE3,0xC0,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7E,0xE3,0xFC,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00, + 0x7C,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x0C,0x00,0x00, + 0x00,0x3F,0x80,0x03,0xC0,0x00,0x0F,0x00,0x00,0x00,0xFF,0x80, + 0x0F,0x00,0x00,0x07,0x80,0x00,0x01,0xF3,0x80,0x1E,0x0F,0x00, + 0x01,0x80,0x00,0x01,0xE3,0x80,0x18,0x0F,0x00,0x01,0x80,0x00, + 0x07,0xE7,0x80,0x18,0x3F,0x00,0x01,0xE0,0x00,0x07,0x87,0x80, + 0x78,0x3F,0x00,0x00,0xE0,0x00,0x07,0x03,0x80,0x70,0x07,0x00, + 0x00,0xE0,0x00,0x0F,0x07,0x9F,0xF0,0x6F,0x00,0x00,0xF0,0x00, + 0x0F,0x1E,0xFF,0xF1,0xFC,0x00,0x00,0x30,0x00,0x0C,0x1E,0xF0, + 0xF1,0xEC,0x00,0x00,0x30,0x00,0x0E,0x1F,0xF0,0xFB,0xFC,0x03, + 0xC0,0xF0,0x00,0x0F,0x07,0x80,0x7F,0xFC,0x0F,0xE1,0xF0,0x00, + 0x0F,0x06,0x00,0x1F,0xFC,0x0F,0xE1,0xE0,0x00,0x0F,0x1E,0x00, + 0x1F,0xFC,0x0F,0xE1,0xE0,0x00,0x0F,0x18,0x00,0x1F,0xF8,0x0F, + 0xE1,0x80,0x00,0x07,0x18,0x00,0x0F,0xF8,0x0F,0xE1,0x80,0x00, + 0x07,0xB8,0x78,0x0F,0xF8,0x0F,0xE1,0xF0,0x00,0x01,0xF0,0xFE, + 0x03,0xE0,0x03,0xC1,0xF0,0x00,0x00,0xF0,0xCE,0x00,0xC0,0x00, + 0x01,0xF0,0x00,0x00,0xF0,0xCF,0x00,0xF8,0x00,0x01,0xF0,0x00, + 0x00,0x30,0x03,0x80,0x7C,0x00,0x01,0xF0,0x00,0x00,0x30,0x03, + 0x80,0x0C,0x00,0x01,0xB0,0x00,0x00,0x30,0x03,0x80,0x0F,0xE0, + 0x3F,0xF0,0x00,0x00,0x38,0x1F,0xD8,0x0F,0xFF,0xFF,0xE0,0x00, + 0x00,0x18,0x1F,0xD8,0x00,0xFF,0xEF,0x80,0x00,0x00,0x18,0x1F, + 0xFE,0x00,0xFF,0xFF,0x80,0x00,0x00,0x1F,0x81,0xFF,0x00,0xF9, + 0xF8,0x00,0x00,0x00,0x07,0x81,0xFF,0x00,0xD9,0xB8,0x00,0x00, + 0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x03,0xFF, + 0xF1,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_jump[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xFF,0xDF,0xE0,0x00,0x00,0x00,0x00,0x00, + 0x00,0xE0,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00, + 0xFC,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x00,0x3E,0x00,0x00, + 0x00,0x00,0x00,0x1C,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00, + 0x3C,0x78,0x00,0x0F,0x80,0x00,0x00,0x00,0x00,0x78,0xFC,0x00, + 0x07,0x80,0x00,0x00,0x00,0x00,0xE0,0xEC,0x00,0x01,0x80,0x00, + 0x00,0x00,0x00,0xE0,0x60,0x00,0x01,0x80,0x00,0x00,0x00,0x03, + 0xE0,0x78,0x00,0x01,0xC0,0x00,0x00,0x00,0x03,0xE0,0x38,0x00, + 0x00,0xE0,0x00,0x00,0x00,0x03,0xED,0xB8,0x00,0x00,0xF0,0x00, + 0x00,0x00,0x03,0xED,0xB8,0x00,0x01,0xB0,0x00,0x00,0x7E,0x03, + 0xFF,0xF8,0x0E,0x01,0xF0,0x00,0x01,0xFE,0x00,0xFF,0xF8,0x3F, + 0x81,0xF0,0x00,0x01,0xEF,0x00,0xFF,0xE0,0x33,0x80,0xE0,0x00, + 0x03,0xEF,0x00,0xFF,0xE0,0x3F,0x80,0xE0,0x00,0x03,0x67,0x00, + 0x7F,0xE0,0x3F,0x8F,0xE0,0x00,0x03,0x87,0x00,0x3F,0xC0,0x0E, + 0x0F,0xE0,0x00,0x07,0x8F,0x00,0x3F,0xC0,0x0E,0x0F,0xE0,0x00, + 0x07,0x0C,0x00,0x0F,0x00,0x00,0x0F,0xE0,0x00,0x07,0x0C,0x00, + 0x07,0x00,0x00,0x02,0x60,0x00,0x07,0x8C,0x00,0x0F,0x80,0x00, + 0x1F,0xE0,0x00,0x03,0x8F,0x07,0xFF,0xC0,0x00,0x1F,0xC0,0x00, + 0x03,0x83,0x07,0xFC,0xF8,0x00,0x0F,0x00,0x00,0x03,0xE3,0xFF, + 0xFC,0x7F,0x80,0xFF,0x00,0x00,0x01,0xE1,0xFC,0x00,0x0F,0x80, + 0xFC,0x00,0x00,0x01,0xE1,0xE0,0x00,0x0F,0xFF,0xF8,0x00,0x00, + 0x00,0xFB,0xC0,0x00,0x00,0xFF,0x80,0x00,0x00,0x00,0x3F,0x00, + 0x00,0x01,0x87,0xC0,0x00,0x00,0x00,0x0E,0x00,0x00,0x03,0x86, + 0xC0,0x00,0x00,0x00,0x0E,0x00,0x00,0x03,0xF6,0xE0,0x00,0x00, + 0x00,0x1E,0x00,0x00,0x00,0xFE,0x78,0x00,0x00,0x00,0x18,0x00, + 0x00,0x00,0x3E,0x38,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x0E, + 0x38,0x00,0x00,0x00,0x18,0x00,0x01,0x80,0x0E,0x38,0x00,0x00, + 0x00,0x38,0x00,0x01,0xC0,0x07,0xF8,0x00,0x00,0x00,0x3C,0x00, + 0x00,0xE0,0x07,0xE0,0x00,0x00,0x00,0xFC,0x03,0x80,0xFE,0x07, + 0xE0,0x00,0x00,0x01,0xE0,0x03,0x83,0xFF,0xDF,0xC0,0x00,0x00, + 0x01,0x80,0x07,0x03,0xE3,0xDC,0x00,0x00,0x00,0x01,0x80,0x07, + 0xFF,0xC0,0xF4,0x00,0x00,0x00,0x03,0x83,0x1F,0xFE,0x00,0xF0, + 0x00,0x00,0x00,0x03,0x03,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00, + 0x03,0x0F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x03,0x9F,0x3E, + 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x9C,0x30,0x00,0x00,0x00, + 0x00,0x00,0x00,0x03,0xFF,0x70,0x00,0x00,0x00,0x00,0x00,0x00, + 0x01,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_walk1[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xEF, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xE0,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7F,0xBB,0xF8,0x00,0x00,0x00,0x00,0x00, + 0x00,0xFF,0x80,0x7E,0x00,0x00,0x00,0x00,0x00,0x01,0xFC,0x00, + 0x3F,0x80,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x0F,0x80,0x00, + 0x00,0x00,0x00,0x07,0x80,0x00,0x03,0xC0,0x00,0x00,0x00,0x00, + 0x1E,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x1C,0x00,0xC0, + 0x00,0x70,0x00,0x00,0x00,0x00,0x3C,0x03,0xC0,0x00,0x78,0x00, + 0x00,0x00,0x00,0x30,0x03,0x80,0x00,0x78,0x00,0x00,0x00,0x00, + 0x70,0x03,0xC0,0x00,0x18,0x00,0x00,0x00,0x00,0x60,0x30,0xC0, + 0x00,0x18,0x00,0x00,0x00,0x00,0x6C,0xF3,0xC0,0x00,0x18,0x00, + 0x00,0x00,0x00,0x7E,0xF3,0x80,0x00,0x18,0x00,0x00,0x00,0x00, + 0x7E,0xF3,0x80,0x00,0x78,0x00,0x00,0x1F,0x00,0x7F,0xF3,0x80, + 0x78,0x70,0x00,0x00,0x1F,0x00,0x3F,0xF3,0x80,0xF8,0x70,0x00, + 0x01,0xFF,0xC0,0x3F,0xF7,0x81,0xFC,0x70,0x00,0x01,0xF3,0xF0, + 0x1F,0xFE,0x01,0xFC,0xF0,0x00,0x01,0xB0,0x70,0x1F,0xFE,0x01, + 0xFC,0xF0,0x00,0x03,0xA3,0xF0,0x1F,0xFE,0x01,0xFC,0x7C,0x00, + 0x03,0x07,0xF0,0x07,0xFC,0x00,0xF8,0x7C,0x00,0x03,0x06,0xF0, + 0x03,0xF0,0x00,0x00,0x7C,0x00,0x0F,0x0E,0xC0,0x03,0xF0,0x00, + 0x00,0x7C,0x00,0x0F,0x0E,0x00,0x00,0xE0,0x00,0x00,0x1C,0x00, + 0x0F,0x0E,0x7F,0x83,0xFC,0x00,0x00,0x1C,0x00,0x0F,0x0F,0xFF, + 0xFF,0xBE,0x00,0x06,0x3C,0x00,0x03,0x07,0xE0,0xFE,0x1F,0x80, + 0x07,0x78,0x00,0x03,0x87,0x80,0x00,0x07,0xF8,0x03,0xF8,0x00, + 0x03,0x06,0x00,0x00,0x00,0xF8,0x00,0x70,0x00,0x01,0xFC,0x00, + 0x00,0x00,0x0F,0xFF,0xC0,0x00,0x01,0xFC,0x00,0x00,0x00,0x0F, + 0xFF,0xC0,0x00,0x00,0x7C,0x00,0x00,0x00,0x01,0x80,0x00,0x00, + 0x00,0x30,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x30,0x00, + 0x00,0x00,0x0D,0xC0,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0D, + 0xC0,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00, + 0x00,0x70,0x01,0x80,0x1C,0x07,0x80,0x00,0x00,0x00,0x60,0x01, + 0x80,0x1C,0x03,0x80,0x00,0x00,0x01,0xE0,0x03,0x80,0x1E,0x01, + 0xE0,0x00,0x00,0x07,0xE0,0x07,0xF0,0x07,0x80,0xF0,0x00,0x00, + 0x07,0x80,0x0F,0xF0,0x07,0x80,0x70,0x00,0x00,0x0F,0x80,0x1F, + 0xFF,0xFF,0xC0,0x7C,0x00,0x00,0x1C,0x00,0xFF,0xFF,0xFF,0xE0, + 0x1F,0x80,0x00,0x1C,0x1F,0xFF,0xF0,0x1F,0xFC,0x07,0xC0,0x00, + 0x18,0x1F,0x98,0xF0,0x1C,0x7C,0x03,0xC0,0x00,0x18,0x7F,0x98, + 0x70,0x3C,0xFF,0x03,0xC0,0x00,0x18,0xF8,0x1E,0x3C,0x30,0xE7, + 0xE3,0xC0,0x00,0x1C,0xE0,0x0E,0x1E,0x30,0xC1,0xE3,0x80,0x00, + 0x1F,0xE0,0x0F,0x1E,0x31,0xE1,0xFF,0x80,0x00,0x1F,0x80,0x03, + 0xFE,0x3F,0xE0,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_walk2[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1D,0xFF, + 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x7B,0xC0,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7F,0xBB,0xF8,0x00,0x00,0x00,0x00,0x00, + 0x01,0xFD,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x03,0xDC,0x00, + 0x0F,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x05,0x80,0x00, + 0x00,0x00,0x00,0x07,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00, + 0x1E,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x1C,0x00,0xC0, + 0x00,0x70,0x00,0x00,0x00,0x00,0x3C,0x03,0xC0,0x00,0x70,0x00, + 0x00,0x00,0x00,0x30,0x03,0x80,0x00,0x38,0x00,0x00,0x00,0x00, + 0x30,0x03,0xC0,0x00,0x18,0x00,0x00,0x00,0x00,0xF0,0x33,0xC0, + 0x00,0x18,0x00,0x00,0x00,0x00,0xE0,0x33,0x80,0x00,0x18,0x00, + 0x00,0x00,0x00,0xF8,0x73,0x80,0x00,0x18,0x00,0x00,0x00,0x00, + 0xFA,0xE3,0x00,0x00,0x38,0x00,0x00,0x3E,0x00,0xFF,0xFB,0x00, + 0x78,0x30,0x00,0x00,0x7E,0x00,0x3F,0xFB,0x00,0x78,0x30,0x00, + 0x03,0xFF,0x00,0x3F,0xFF,0x01,0xFC,0x70,0x00,0x03,0xE7,0x00, + 0x1F,0xFE,0x01,0xFC,0x60,0x00,0x03,0x43,0x00,0x1F,0xEE,0x01, + 0xFC,0x70,0x00,0x07,0x07,0x00,0x1B,0xEE,0x01,0xFC,0x7C,0x00, + 0x06,0x1E,0x00,0x1F,0xFC,0x00,0x78,0x3E,0x00,0x06,0x1C,0x00, + 0x07,0xF8,0x00,0x00,0x3E,0x00,0x0E,0x3C,0x00,0x03,0xE0,0x00, + 0x00,0x3E,0x00,0x0E,0x38,0x00,0x03,0xE0,0x00,0x00,0x3E,0x00, + 0x0E,0x38,0x1C,0x03,0xF8,0x00,0x00,0x1E,0x00,0x0E,0x3C,0xFF, + 0x83,0xBC,0x00,0x07,0x1C,0x00,0x0E,0x0F,0xFF,0xFF,0xBF,0x00, + 0x07,0x3C,0x00,0x07,0x0F,0x80,0xFE,0x0F,0xC0,0x07,0xF8,0x00, + 0x06,0x0E,0x00,0x00,0x03,0xF8,0x00,0x70,0x00,0x07,0xDC,0x00, + 0x00,0x00,0xFF,0xFF,0xF0,0x00,0x03,0xF8,0x00,0x00,0x00,0x0F, + 0xFF,0xC0,0x00,0x00,0xF0,0x00,0x00,0x00,0x01,0xC0,0x00,0x00, + 0x00,0xF0,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x60,0x00, + 0x00,0x00,0x19,0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x19, + 0xC0,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x1D,0xC0,0x00,0x00, + 0x00,0x60,0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00,0xE0,0x03, + 0x00,0x18,0x0F,0x80,0x00,0x00,0x01,0xC0,0x07,0x00,0x1C,0x07, + 0x00,0x00,0x00,0x03,0xC0,0x06,0x00,0x0C,0x03,0x00,0x00,0x00, + 0x0F,0x80,0x0F,0x80,0x0E,0x03,0x80,0x00,0x00,0x1F,0x00,0x3F, + 0xFF,0xFF,0x01,0xC0,0x00,0x00,0x18,0x01,0xFC,0xFF,0xFF,0xC0, + 0xE0,0x00,0x00,0x38,0x01,0xF0,0x70,0x39,0xC0,0x60,0x00,0x00, + 0x38,0x3F,0xF0,0x70,0x38,0xE0,0x7E,0x00,0x00,0x30,0xFF,0x38, + 0x70,0x70,0xF8,0x3F,0x00,0x00,0x30,0xE0,0x38,0x38,0x60,0xF8, + 0x07,0x00,0x00,0x30,0xE0,0x3C,0x3E,0x61,0xDC,0x07,0x00,0x00, + 0x3D,0xE0,0x0E,0x1E,0x63,0xCF,0x1F,0x00,0x00,0x3F,0xE0,0x07, + 0xFE,0x7F,0xC7,0xCF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_walk3[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF, + 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x73,0xC0,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7F,0xB3,0xF8,0x00,0x00,0x00,0x00,0x00, + 0x01,0xFF,0x80,0x7E,0x00,0x00,0x00,0x00,0x00,0x01,0xEE,0x00, + 0x0E,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x00,0x0F,0x00,0x00, + 0x00,0x00,0x00,0x0F,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00, + 0x0E,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x1C,0x00,0xC0, + 0x00,0xE0,0x00,0x00,0x00,0x00,0x18,0x00,0xC0,0x00,0x60,0x00, + 0x00,0x00,0x00,0x78,0x03,0xC0,0x00,0x78,0x00,0x00,0x00,0x00, + 0x60,0x03,0xC0,0x00,0x38,0x00,0x00,0x00,0x00,0xE0,0x00,0xC0, + 0x00,0x38,0x00,0x00,0x00,0x00,0xE0,0x33,0xC0,0x00,0x38,0x00, + 0x00,0x00,0x00,0xD8,0x73,0x80,0x00,0x78,0x00,0x00,0x00,0x00, + 0xFC,0xF3,0x80,0x00,0x78,0x00,0x00,0x00,0x00,0xFC,0xF3,0x80, + 0x00,0x60,0x00,0x00,0x3F,0x00,0xFF,0xFB,0x80,0xF0,0xE0,0x00, + 0x00,0xFF,0x80,0x7F,0xFF,0x81,0xF8,0xE0,0x00,0x01,0xF3,0x80, + 0x1F,0xFE,0x01,0xD8,0xE0,0x00,0x01,0xE1,0x80,0x1F,0xFE,0x01, + 0xF8,0xE0,0x00,0x03,0x83,0x80,0x1F,0xFC,0x01,0xF8,0xF8,0x00, + 0x03,0x07,0x80,0x0F,0xFC,0x00,0xF0,0x7C,0x00,0x03,0x06,0x00, + 0x07,0xB8,0x00,0x00,0x7C,0x00,0x0F,0x0E,0x00,0x07,0xF0,0x00, + 0x00,0x7C,0x00,0x0F,0x1C,0x00,0x01,0xE0,0x00,0x00,0x3C,0x00, + 0x0F,0x1C,0x0E,0x07,0xF8,0x00,0x00,0x3C,0x00,0x0F,0x1F,0xFF, + 0xFF,0xBE,0x00,0x06,0x3C,0x00,0x03,0x07,0xE0,0xFC,0x0F,0x00, + 0x06,0x38,0x00,0x07,0x87,0x00,0x00,0x03,0x80,0x03,0xF8,0x00, + 0x07,0x87,0x00,0x00,0x03,0xF0,0x03,0xF8,0x00,0x03,0xDE,0x00, + 0x00,0x00,0xFF,0xFF,0xE0,0x00,0x01,0xFC,0x00,0x00,0x00,0x1F, + 0xFF,0xC0,0x00,0x00,0xF8,0x00,0x00,0x00,0x01,0x80,0x00,0x00, + 0x00,0xF8,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x30,0x00, + 0x00,0x00,0x0E,0xC0,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0E, + 0xC0,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x03,0xC0,0x00,0x00, + 0x00,0x30,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x70,0x01, + 0x80,0x0C,0x01,0xC0,0x00,0x00,0x01,0xE0,0x03,0x80,0x0E,0x00, + 0xF0,0x00,0x00,0x01,0xE0,0x03,0x00,0x06,0x00,0x70,0x00,0x00, + 0x07,0xE0,0x07,0x00,0x07,0x80,0x7C,0x00,0x00,0x0F,0x00,0x0F, + 0xFF,0xFF,0xC0,0x1F,0xC0,0x00,0x0C,0x00,0xFF,0xFF,0xFF,0xF0, + 0x07,0xE0,0x00,0x1C,0x00,0xFC,0x38,0x0C,0x78,0x00,0xE0,0x00, + 0x1C,0x1F,0xFC,0x38,0x0C,0x3E,0x00,0xE0,0x00,0x18,0x7F,0x9C, + 0x38,0x1C,0x7F,0x83,0xE0,0x00,0x18,0xF0,0x1E,0x38,0x18,0x73, + 0xE3,0xE0,0x00,0x18,0xE0,0x06,0x1E,0x18,0xE0,0xFF,0xC0,0x00, + 0x1F,0xE0,0x07,0x8F,0x18,0xF0,0xFF,0x80,0x00,0x1F,0x80,0x03, + 0xFF,0x1F,0xF0,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +static const uint8_t pet_walk4[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF, + 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF3,0xF8,0x00,0x00, + 0x00,0x00,0x00,0x00,0xF9,0xC0,0xF8,0x00,0x00,0x00,0x00,0x00, + 0x07,0xFE,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x0F,0x8E,0x00, + 0x1F,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x03,0x80,0x00, + 0x00,0x00,0x00,0x38,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00, + 0x78,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00, + 0x00,0xE0,0x00,0x00,0x00,0x00,0xC0,0x0E,0x00,0x00,0xE0,0x00, + 0x00,0x00,0x00,0xC0,0x0F,0x00,0x00,0xF0,0x00,0x00,0x00,0x01, + 0xC0,0x43,0x00,0x00,0x30,0x00,0x00,0x00,0x01,0x80,0xEE,0x00, + 0x00,0x30,0x00,0x00,0x00,0x01,0xE0,0xEE,0x00,0x00,0x30,0x00, + 0x00,0x00,0x01,0xF9,0xCE,0x00,0x00,0xF0,0x00,0x00,0x00,0x01, + 0xFF,0xEE,0x03,0x80,0xF0,0x00,0x00,0x00,0x01,0xFF,0xEE,0x03, + 0xC1,0xE0,0x00,0x00,0x3E,0x01,0xFF,0xFE,0x07,0xE1,0xE0,0x00, + 0x00,0x7F,0x80,0xFF,0xFE,0x07,0xE1,0x80,0x00,0x01,0xE3,0x80, + 0xFF,0xF8,0x07,0xE1,0x80,0x00,0x01,0xC3,0x80,0x7F,0xF8,0x07, + 0xE1,0xF8,0x00,0x01,0xC7,0x80,0x7F,0xF8,0x07,0xE0,0xF8,0x00, + 0x03,0xCE,0x00,0x3F,0xF0,0x03,0xC0,0xF8,0x00,0x03,0x0C,0x00, + 0x1F,0xF0,0x00,0x00,0xF8,0x00,0x03,0x0C,0x00,0x0F,0xE0,0x00, + 0x00,0x38,0x00,0x03,0x0C,0x00,0x07,0x80,0x00,0x00,0x38,0x00, + 0x03,0xCE,0x00,0x03,0xC0,0x00,0x0E,0x70,0x00,0x03,0xC6,0x3F, + 0x83,0xF0,0x00,0x0F,0xF0,0x00,0x03,0xE7,0xFF,0xFF,0xF0,0x00, + 0x03,0xE0,0x00,0x01,0xE3,0xE0,0xFE,0x3F,0x00,0x03,0xE0,0x00, + 0x01,0xF7,0x00,0x00,0x1F,0xFF,0xFF,0x80,0x00,0x00,0x76,0x00, + 0x00,0x01,0xFF,0xFE,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x03, + 0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x03,0x00,0x00,0x00, + 0x00,0x18,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x18,0x00, + 0x00,0x00,0x0F,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x0F, + 0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x07,0x80,0x00,0x00, + 0x00,0x18,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x78,0x01, + 0x80,0x18,0x01,0xE0,0x00,0x00,0x00,0xE0,0x03,0x80,0x1E,0x00, + 0xF0,0x00,0x00,0x03,0xE0,0x03,0x00,0x0E,0x00,0x38,0x00,0x00, + 0x03,0xC0,0x07,0xC0,0x0F,0x00,0x3C,0x80,0x00,0x07,0x80,0x0F, + 0xFF,0xFF,0xC0,0x0F,0xE0,0x00,0x06,0x00,0x3E,0x7F,0xFF,0xE0, + 0x07,0xF0,0x00,0x0E,0x00,0xFC,0x1F,0x1F,0xF8,0x00,0xF0,0x00, + 0x0C,0x1F,0xFC,0x18,0x38,0x7E,0x00,0x70,0x00,0x0C,0x3F,0xCC, + 0x1F,0x30,0x7F,0x81,0xF0,0x00,0x0C,0x38,0x0E,0x0F,0xB0,0x63, + 0xE0,0xE0,0x00,0x0C,0x38,0x0F,0x03,0xB1,0xE0,0xFF,0xC0,0x00, + 0x0F,0x78,0x07,0x87,0xBF,0xC0,0x3F,0x80,0x00,0x0F,0xF0,0x01, + 0x81,0x9F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif diff --git a/2.13/mono/spi/pet/pixpaper-213-m-test-frdm-imx93-pet.c b/2.13/mono/spi/pet/pixpaper-213-m-test-frdm-imx93-pet.c new file mode 100644 index 0000000..6743c1d --- /dev/null +++ b/2.13/mono/spi/pet/pixpaper-213-m-test-frdm-imx93-pet.c @@ -0,0 +1,60 @@ +/* + * Author: LC Wang + * Date: 2026-06-17 + * + * Open-EP Pet for frdm-imx93: libgpiod v1 GPIO backend. + * Shared SPI/EPD/pet logic lives in pet_app.h. + */ +#include +#include +#include + +#define EPD_GPIO_CHIP "gpiochip0" + +#define EPD_DC_PIN 0 +#define EPD_RST_PIN 5 +#define EPD_BUSY_PIN 26 + +struct gpiod_chip *chip; +struct gpiod_line *epd_dc_line, *epd_rst_line, *epd_busy_line; + +#define epd_dc_set(v) gpiod_line_set_value(epd_dc_line, (v)) +#define epd_rst_set(v) gpiod_line_set_value(epd_rst_line, (v)) +#define epd_busy_get() gpiod_line_get_value(epd_busy_line) + +static int epd_gpio_init(void) { + chip = gpiod_chip_open_by_name(EPD_GPIO_CHIP); + if (!chip) { + perror("Error opening GPIO chip"); + return -1; + } + + epd_dc_line = gpiod_chip_get_line(chip, EPD_DC_PIN); + epd_rst_line = gpiod_chip_get_line(chip, EPD_RST_PIN); + epd_busy_line = gpiod_chip_get_line(chip, EPD_BUSY_PIN); + + if (!epd_dc_line || !epd_rst_line || !epd_busy_line) { + perror("Error getting GPIO lines"); + gpiod_chip_close(chip); + return -1; + } + + if (gpiod_line_request_output(epd_dc_line, "epd_dc", 0) < 0 || + gpiod_line_request_output(epd_rst_line, "epd_rst", 0) < 0 || + gpiod_line_request_input(epd_busy_line, "epd_busy") < 0) { + perror("Error requesting GPIO lines"); + gpiod_chip_close(chip); + return -1; + } + + return 0; +} + +static void epd_gpio_release(void) { + gpiod_line_release(epd_dc_line); + gpiod_line_release(epd_rst_line); + gpiod_line_release(epd_busy_line); + gpiod_chip_close(chip); +} + +#include "pet_app.h" diff --git a/2.13/mono/spi/pet/pixpaper-213-m-test-rpi5-pet.c b/2.13/mono/spi/pet/pixpaper-213-m-test-rpi5-pet.c new file mode 100644 index 0000000..6897ecc --- /dev/null +++ b/2.13/mono/spi/pet/pixpaper-213-m-test-rpi5-pet.c @@ -0,0 +1,144 @@ +/* + * Author: LC Wang + * Date: 2026-06-17 + * + * Open-EP Pet for Raspberry Pi 5: libgpiod v2 GPIO backend. + * Shared SPI/EPD/pet logic lives in pet_app.h. + */ +#include +#include +#include + +#define EPD_GPIO_CHIP "gpiochip15" + +#define EPD_DC_PIN 5 +#define EPD_RST_PIN 6 +#define EPD_BUSY_PIN 26 + +struct gpiod_chip *chip; +struct gpiod_line_request *epd_dc_line, *epd_rst_line, *epd_busy_line; + +static const unsigned int EPD_DC_OFFSET = EPD_DC_PIN; +static const unsigned int EPD_RST_OFFSET = EPD_RST_PIN; +static const unsigned int EPD_BUSY_OFFSET = EPD_BUSY_PIN; + +static struct gpiod_line_request * +gpiod_request_output(struct gpiod_chip *c, unsigned int offset, + const char *consumer, int value) +{ + struct gpiod_line_settings *settings; + struct gpiod_line_config *line_cfg; + struct gpiod_request_config *req_cfg; + struct gpiod_line_request *request = NULL; + + settings = gpiod_line_settings_new(); + if (!settings) + return NULL; + gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_OUTPUT); + gpiod_line_settings_set_output_value(settings, + value ? GPIOD_LINE_VALUE_ACTIVE : GPIOD_LINE_VALUE_INACTIVE); + + line_cfg = gpiod_line_config_new(); + if (!line_cfg) { + gpiod_line_settings_free(settings); + return NULL; + } + if (gpiod_line_config_add_line_settings(line_cfg, &offset, 1, settings) < 0) + goto out; + + req_cfg = gpiod_request_config_new(); + if (req_cfg) + gpiod_request_config_set_consumer(req_cfg, consumer); + + request = gpiod_chip_request_lines(c, req_cfg, line_cfg); + + if (req_cfg) + gpiod_request_config_free(req_cfg); +out: + gpiod_line_config_free(line_cfg); + gpiod_line_settings_free(settings); + return request; +} + +static struct gpiod_line_request * +gpiod_request_input(struct gpiod_chip *c, unsigned int offset, + const char *consumer) +{ + struct gpiod_line_settings *settings; + struct gpiod_line_config *line_cfg; + struct gpiod_request_config *req_cfg; + struct gpiod_line_request *request = NULL; + + settings = gpiod_line_settings_new(); + if (!settings) + return NULL; + gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_INPUT); + + line_cfg = gpiod_line_config_new(); + if (!line_cfg) { + gpiod_line_settings_free(settings); + return NULL; + } + if (gpiod_line_config_add_line_settings(line_cfg, &offset, 1, settings) < 0) + goto out; + + req_cfg = gpiod_request_config_new(); + if (req_cfg) + gpiod_request_config_set_consumer(req_cfg, consumer); + + request = gpiod_chip_request_lines(c, req_cfg, line_cfg); + + if (req_cfg) + gpiod_request_config_free(req_cfg); +out: + gpiod_line_config_free(line_cfg); + gpiod_line_settings_free(settings); + return request; +} + +static inline void +gpiod_set_value(struct gpiod_line_request *req, unsigned int offset, int value) +{ + gpiod_line_request_set_value(req, offset, + value ? GPIOD_LINE_VALUE_ACTIVE : GPIOD_LINE_VALUE_INACTIVE); +} + +static inline int +gpiod_get_value(struct gpiod_line_request *req, unsigned int offset) +{ + return gpiod_line_request_get_value(req, offset) == GPIOD_LINE_VALUE_ACTIVE + ? 1 : 0; +} + +#define epd_dc_set(v) gpiod_set_value(epd_dc_line, EPD_DC_OFFSET, (v)) +#define epd_rst_set(v) gpiod_set_value(epd_rst_line, EPD_RST_OFFSET, (v)) +#define epd_busy_get() gpiod_get_value(epd_busy_line, EPD_BUSY_OFFSET) + +static int epd_gpio_init(void) { + chip = gpiod_chip_open("/dev/" EPD_GPIO_CHIP); + if (!chip) { + perror("Error opening GPIO chip"); + return -1; + } + + epd_dc_line = gpiod_request_output(chip, EPD_DC_OFFSET, "epd_dc", 0); + epd_rst_line = gpiod_request_output(chip, EPD_RST_OFFSET, "epd_rst", 0); + epd_busy_line = gpiod_request_input(chip, EPD_BUSY_OFFSET, "epd_busy"); + + if (!epd_dc_line || !epd_rst_line || !epd_busy_line) { + perror("Error requesting GPIO lines"); + gpiod_chip_close(chip); + return -1; + } + + return 0; +} + +static void epd_gpio_release(void) { + gpiod_line_request_release(epd_dc_line); + gpiod_line_request_release(epd_rst_line); + gpiod_line_request_release(epd_busy_line); + gpiod_chip_close(chip); +} + +#include "pet_app.h" diff --git a/2.13/mono/spi/pet/sprite_gen.py b/2.13/mono/spi/pet/sprite_gen.py new file mode 100644 index 0000000..a706f89 --- /dev/null +++ b/2.13/mono/spi/pet/sprite_gen.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +"""Trace the dog*.png frames into 1-bit pixel-art sprites for the pet UI. + +All frames share ONE fixed scale (anchored to the sitting frame) and are +bottom-aligned (feet on a common floor) + horizontally centred, so squash / +stretch poses keep their real height differences (crouch shorter, jump taller) +and every frame lands on the same ground line. Run from this directory; +with --emit it (re)writes petsprite.h. +""" +import os, sys +import numpy as np +from PIL import Image, ImageDraw, ImageFont + +DIR = os.path.dirname(os.path.abspath(__file__)) +OUT = DIR + "/petsprite.h" +BAND = (226, 599) # puppy band, excludes the "PET" label below +PH = 52 # sitting-dog height in sprite px (sets the fixed scale) +PAD_X, PAD_Y = 2, 2 # canvas margins +TH_INK = 180 + +FRAMES = [ # (C name, source png) + ("pet_idle", "dog.png"), + ("pet_blink", "dog_blink.png"), + ("pet_happy", "dog_happy.png"), + ("pet_sad", "dog_sad.png"), + ("pet_eat", "dog_eat.png"), + ("pet_eat_closed","dog_eat_closed.png"), + ("pet_look", "dog_look.png"), + ("pet_look_half", "dog_look_half.png"), + ("pet_crouch", "dog_crouch.png"), + ("pet_jump", "dog_jump.png"), + ("pet_walk1", "dog_walk1.png"), + ("pet_walk2", "dog_walk2.png"), + ("pet_walk3", "dog_walk3.png"), + ("pet_walk4", "dog_walk4.png"), +] + +def gray(name): + return np.asarray(Image.open(f"{DIR}/{name}").convert("L")).astype(int) + +def bbox(name): + a = gray(name)[BAND[0]:BAND[1], :] < 150 + xs = np.where(a.any(0))[0]; ys = np.where(a.any(1))[0] + return xs[0], BAND[0]+ys[0], xs[-1], BAND[0]+ys[-1] + +BOXES = {src: bbox(src) for _, src in FRAMES} +# fixed scale from the sitting frame's height +sx0, sy0, sx1, sy1 = BOXES["dog.png"] +SCALE = PH / (sy1 - sy0 + 1) + +def scaled(src): + x0, y0, x1, y1 = BOXES[src] + return src, x0, y0, x1, y1, int(round((x1-x0+1)*SCALE)), int(round((y1-y0+1)*SCALE)) + +DIMS = [scaled(src) for _, src in FRAMES] +PET_W = max(d[5] for d in DIMS) + 2*PAD_X +PET_H = max(d[6] for d in DIMS) + 2*PAD_Y +print(f"scale={SCALE:.4f} canvas={PET_W}x{PET_H}") + +def trace(src): + _, x0, y0, x1, y1, tw, th = scaled(src) + a = gray(src)[y0:y1+1, x0:x1+1] + ox = (PET_W - tw)//2 # centre horizontally + oy = PET_H - PAD_Y - th # bottom-align (feet on the floor) + g = [[0]*PET_W for _ in range(PET_H)] + for ty in range(th): + for tx in range(tw): + yy0=int(ty/SCALE); yy1=max(yy0+1,int((ty+1)/SCALE)) + xx0=int(tx/SCALE); xx1=max(xx0+1,int((tx+1)/SCALE)) + if a[yy0:yy1, xx0:xx1].min() < TH_INK: + gy, gx = oy+ty, ox+tx + if 0 <= gy < PET_H and 0 <= gx < PET_W: + g[gy][gx] = 1 + return g + +GRIDS = [(name, trace(src)) for name, src in FRAMES] + +def render(g, scale=6): + im=Image.new("L",(PET_W*scale,PET_H*scale),255); d=ImageDraw.Draw(im) + for y in range(PET_H): + for x in range(PET_W): + if g[y][x]: d.rectangle([x*scale,y*scale,x*scale+scale-1,y*scale+scale-1],fill=0) + # ground line to check feet alignment + fy=(PET_H-PAD_Y)*scale-1 + d.line([0,fy,PET_W*scale-1,fy],fill=160) + return im + +F=ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",14) +cols=4; rows=(len(GRIDS)+cols-1)//cols +cw=PET_W*6+8; chh=PET_H*6+20 +m=Image.new("L",(cols*cw+8,rows*chh+8),255); dd=ImageDraw.Draw(m) +for i,(name,g) in enumerate(GRIDS): + r,c=divmod(i,cols); x=8+c*cw; y=8+r*chh + dd.text((x,y),name.replace("pet_",""),font=F,fill=0); m.paste(render(g),(x,y+16)) +m.save("/tmp/sprite_frames.png"); print("preview /tmp/sprite_frames.png", m.size) + +def to_bytes(g): + stride=(PET_W+7)//8; out=[] + for y in range(PET_H): + for bx in range(stride): + v=0 + for b in range(8): + xx=bx*8+b + if xx>b + out.append(v) + return out +if "--emit" in sys.argv: + def emit(f,name,g): + b=to_bytes(g); f.write(f"static const uint8_t {name}[] = {{\n") + for i in range(0,len(b),12): f.write("\t"+",".join(f"0x{v:02X}" for v in b[i:i+12])+",\n") + f.write("};\n") + with open(OUT,"w") as f: + f.write("/* generated by sprite_gen.py from dog*.png - do not edit */\n#ifndef PETSPRITE_H\n#define PETSPRITE_H\n#include \n") + f.write(f"#define PET_W {PET_W}\n#define PET_H {PET_H}\n#define PET_STRIDE (({PET_W}+7)/8)\n") + for name,g in GRIDS: emit(f,name,g) + f.write("#endif\n") + print("wrote",OUT)