~rabbits/dexe

4520cefb41223625a38886871cb5a94ee11550b5 — neauoire a month ago 8625bcd
Progress on UI
5 files changed, 354 insertions(+), 1743 deletions(-)

M README.md
D dexe.c
D dexe.tal
A src/font.tal
M src/main.tal
M README.md => README.md +1 -0
@@ 1,3 1,4 @@
ABCDEF123456
# Dexe

[Dexe](https://wiki.xxiivv.com/site/dexe.html) is a hex editor, written in [Uxntal](https://wiki.xxiivv.com/site/uxntal.html).

D dexe.c => dexe.c +0 -806
@@ 1,806 0,0 @@
#include <SDL2/SDL.h>
#include <stdio.h>

/* 
Copyright (c) 2020 Devine Lu Linvega

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/

#define HOR 32
#define VER 16
#define PAD 2
#define SZ 512 * 16

typedef unsigned char Uint8;

typedef struct {
	int unsaved;
	char name[256];
	Uint8 data[SZ];
} Document;

typedef struct Brush {
	int x, y, i, swap, view;
	Uint8 clip;
} Cursor;

int WIDTH = 8 * HOR + 8 * PAD * 2;
int HEIGHT = 8 * (VER + 2) + 8 * PAD * 2;
int FPS = 30, GUIDES = 1, ZOOM = 2;

Document doc;
Cursor cursor;

Uint32 theme[] = {
	0x000000,
	0xFFFFFF,
	0x72DEC2,
	0x666666,
	0x222222};

Uint8 icons[][8] = {
	{0x38, 0x44, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00}, /* color:blank */
	{0x38, 0x7c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x00}, /* color:full */
	{0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00}, /* blank */
	{0x7c, 0x82, 0x92, 0xba, 0x92, 0x82, 0x7c, 0x00}, /* incr */
	{0x7c, 0x82, 0x82, 0xba, 0x82, 0x82, 0x7c, 0x00}, /* decr */
	{0x1c, 0x22, 0x42, 0x84, 0x42, 0x22, 0x1c, 0x00}, /* ror */
	{0x70, 0x88, 0x84, 0x42, 0x84, 0x88, 0x70, 0x00}, /* rol */
	{0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00}, /* view:grid */
	{0xee, 0x92, 0x82, 0x54, 0x82, 0x92, 0xee, 0x00}, /* view:bigpixels */
	{0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xe0, 0x10, 0x00}, /* clip:blank */
	{0x82, 0xc5, 0xe2, 0xf0, 0xf8, 0xe0, 0x10, 0x00}, /* clip:active */
	{0x00, 0x00, 0x00, 0x82, 0x44, 0x38, 0x00, 0x00}, /* eye open */
	{0x00, 0x38, 0x44, 0x92, 0x28, 0x10, 0x00, 0x00}, /* eye closed */
	{0x10, 0x54, 0x28, 0xc6, 0x28, 0x54, 0x10, 0x00}  /* unsaved */
};

Uint8 font[][8] = {
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x24, 0x00, 0x7e, 0x3c, 0x00, 0x00},
	{0x00, 0x00, 0x24, 0x00, 0x3c, 0x42, 0x00, 0x00},
	{0x00, 0x00, 0x6c, 0x7c, 0x7c, 0x38, 0x10, 0x00},
	{0x00, 0x10, 0x38, 0x7c, 0x7c, 0x38, 0x10, 0x00},
	{0x00, 0x38, 0x38, 0x7c, 0x6c, 0x10, 0x38, 0x00},
	{0x00, 0x10, 0x38, 0x7c, 0x7c, 0x10, 0x38, 0x00},
	{0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00},
	{0x00, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x00},
	{0x00, 0x00, 0x18, 0x24, 0x24, 0x18, 0x00, 0x00},
	{0x00, 0x3c, 0x66, 0x5a, 0x5a, 0x66, 0x3c, 0x00},
	{0x00, 0x1e, 0x06, 0x3a, 0x4a, 0x48, 0x30, 0x00},
	{0x00, 0x38, 0x44, 0x6c, 0x10, 0x7c, 0x10, 0x00},
	{0x00, 0x0e, 0x08, 0x08, 0x08, 0x38, 0x38, 0x00},
	{0x00, 0x3e, 0x3e, 0x22, 0x22, 0x66, 0x66, 0x00},
	{0x00, 0x00, 0x10, 0x44, 0x00, 0x44, 0x10, 0x00},
	{0x00, 0x00, 0x10, 0x18, 0x1c, 0x18, 0x10, 0x00},
	{0x00, 0x00, 0x08, 0x18, 0x38, 0x18, 0x08, 0x00},
	{0x00, 0x08, 0x1c, 0x00, 0x00, 0x1c, 0x08, 0x00},
	{0x00, 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x00},
	{0x00, 0x3e, 0x4a, 0x4a, 0x3a, 0x0a, 0x0a, 0x00},
	{0x00, 0x0c, 0x30, 0x46, 0x62, 0x0c, 0x30, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff},
	{0x00, 0x10, 0x38, 0x00, 0x38, 0x10, 0x00, 0x38},
	{0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x00},
	{0x00, 0x10, 0x10, 0x10, 0x54, 0x38, 0x10, 0x00},
	{0x00, 0x00, 0x08, 0x04, 0x7e, 0x04, 0x08, 0x00},
	{0x00, 0x00, 0x10, 0x20, 0x7e, 0x20, 0x10, 0x00},
	{0x00, 0x00, 0x40, 0x40, 0x7e, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x24, 0x66, 0x24, 0x00, 0x00},
	{0x00, 0x00, 0x10, 0x38, 0x7c, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x7c, 0x38, 0x10, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00},
	{0x00, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x24, 0x7e, 0x24, 0x24, 0x7e, 0x24, 0x00},
	{0x00, 0x08, 0x1e, 0x28, 0x1c, 0x0a, 0x3c, 0x08},
	{0x00, 0x62, 0x64, 0x08, 0x10, 0x26, 0x46, 0x00},
	{0x00, 0x30, 0x48, 0x32, 0x4c, 0x44, 0x3a, 0x00},
	{0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x04, 0x00},
	{0x00, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00},
	{0x00, 0x00, 0x14, 0x08, 0x3e, 0x08, 0x14, 0x00},
	{0x00, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10},
	{0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00},
	{0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00},
	{0x00, 0x3c, 0x46, 0x4a, 0x52, 0x62, 0x3c, 0x00},
	{0x00, 0x18, 0x28, 0x08, 0x08, 0x08, 0x3e, 0x00},
	{0x00, 0x3c, 0x42, 0x02, 0x3c, 0x40, 0x7e, 0x00},
	{0x00, 0x3c, 0x42, 0x1c, 0x02, 0x42, 0x3c, 0x00},
	{0x00, 0x08, 0x18, 0x28, 0x48, 0x7e, 0x08, 0x00},
	{0x00, 0x7e, 0x40, 0x7c, 0x02, 0x42, 0x3c, 0x00},
	{0x00, 0x3c, 0x40, 0x7c, 0x42, 0x42, 0x3c, 0x00},
	{0x00, 0x7e, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00},
	{0x00, 0x3c, 0x42, 0x3c, 0x42, 0x42, 0x3c, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x3e, 0x02, 0x3c, 0x00},
	{0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00},
	{0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20},
	{0x00, 0x00, 0x08, 0x10, 0x20, 0x10, 0x08, 0x00},
	{0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00},
	{0x00, 0x00, 0x10, 0x08, 0x04, 0x08, 0x10, 0x00},
	{0x00, 0x3c, 0x42, 0x0c, 0x10, 0x00, 0x10, 0x00},
	{0x00, 0x3c, 0x42, 0x52, 0x5e, 0x40, 0x3c, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x00},
	{0x00, 0x7c, 0x42, 0x7c, 0x42, 0x42, 0x7c, 0x00},
	{0x00, 0x3c, 0x42, 0x40, 0x40, 0x42, 0x3c, 0x00},
	{0x00, 0x78, 0x44, 0x42, 0x42, 0x44, 0x78, 0x00},
	{0x00, 0x7e, 0x40, 0x7c, 0x40, 0x40, 0x7e, 0x00},
	{0x00, 0x7e, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x00},
	{0x00, 0x3c, 0x42, 0x40, 0x4e, 0x42, 0x3c, 0x00},
	{0x00, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00},
	{0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00},
	{0x00, 0x02, 0x02, 0x02, 0x42, 0x42, 0x3c, 0x00},
	{0x00, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x00},
	{0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00},
	{0x00, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x00},
	{0x00, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00},
	{0x00, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x52, 0x4a, 0x3c, 0x00},
	{0x00, 0x7c, 0x42, 0x42, 0x7c, 0x44, 0x42, 0x00},
	{0x00, 0x3c, 0x40, 0x3c, 0x02, 0x42, 0x3c, 0x00},
	{0x00, 0xfe, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00},
	{0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00},
	{0x00, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00},
	{0x00, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42, 0x00},
	{0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00},
	{0x00, 0x82, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00},
	{0x00, 0x7e, 0x04, 0x08, 0x10, 0x20, 0x7e, 0x00},
	{0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00},
	{0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00},
	{0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00},
	{0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
	{0x00, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x38, 0x04, 0x3c, 0x44, 0x3c, 0x00},
	{0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x3c, 0x00},
	{0x00, 0x00, 0x1c, 0x20, 0x20, 0x20, 0x1c, 0x00},
	{0x00, 0x04, 0x04, 0x3c, 0x44, 0x44, 0x3c, 0x00},
	{0x00, 0x00, 0x38, 0x44, 0x78, 0x40, 0x3c, 0x00},
	{0x00, 0x0c, 0x10, 0x1c, 0x10, 0x10, 0x10, 0x00},
	{0x00, 0x00, 0x38, 0x44, 0x44, 0x3c, 0x04, 0x38},
	{0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x00},
	{0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x0c, 0x00},
	{0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x48, 0x30},
	{0x00, 0x20, 0x20, 0x28, 0x30, 0x28, 0x24, 0x00},
	{0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0c, 0x00},
	{0x00, 0x00, 0x68, 0x54, 0x54, 0x54, 0x54, 0x00},
	{0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00},
	{0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40},
	{0x00, 0x00, 0x3c, 0x44, 0x44, 0x3c, 0x04, 0x06},
	{0x00, 0x00, 0x2c, 0x30, 0x20, 0x20, 0x20, 0x00},
	{0x00, 0x00, 0x38, 0x40, 0x38, 0x04, 0x78, 0x00},
	{0x00, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x0c, 0x00},
	{0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x00, 0x00, 0x44, 0x44, 0x28, 0x28, 0x10, 0x00},
	{0x00, 0x00, 0x44, 0x54, 0x54, 0x54, 0x28, 0x00},
	{0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00},
	{0x00, 0x00, 0x44, 0x44, 0x44, 0x3c, 0x04, 0x38},
	{0x00, 0x00, 0x7c, 0x08, 0x10, 0x20, 0x7c, 0x00},
	{0x00, 0x0e, 0x08, 0x30, 0x08, 0x08, 0x0e, 0x00},
	{0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00},
	{0x00, 0x70, 0x10, 0x0c, 0x10, 0x10, 0x70, 0x00},
	{0x00, 0x32, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x3c, 0x42, 0x99, 0xa1, 0xa1, 0x99, 0x42, 0x3c},
	{0x00, 0x3c, 0x42, 0x40, 0x42, 0x3c, 0x10, 0x70},
	{0x00, 0x44, 0x00, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x08, 0x10, 0x38, 0x44, 0x78, 0x40, 0x3c, 0x00},
	{0x10, 0x28, 0x00, 0x3c, 0x44, 0x4c, 0x34, 0x00},
	{0x00, 0x24, 0x00, 0x3c, 0x44, 0x4c, 0x34, 0x00},
	{0x00, 0x20, 0x10, 0x3c, 0x44, 0x4c, 0x34, 0x00},
	{0x10, 0x28, 0x10, 0x3c, 0x44, 0x4c, 0x34, 0x00},
	{0x00, 0x00, 0x1c, 0x20, 0x20, 0x1c, 0x08, 0x18},
	{0x10, 0x28, 0x38, 0x44, 0x78, 0x40, 0x3c, 0x00},
	{0x28, 0x00, 0x38, 0x44, 0x78, 0x40, 0x3c, 0x00},
	{0x20, 0x10, 0x3c, 0x44, 0x78, 0x40, 0x3c, 0x00},
	{0x00, 0x28, 0x00, 0x30, 0x10, 0x10, 0x0c, 0x00},
	{0x10, 0x28, 0x00, 0x30, 0x10, 0x10, 0x0c, 0x00},
	{0x20, 0x10, 0x00, 0x30, 0x10, 0x10, 0x0c, 0x00},
	{0x42, 0x3c, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x00},
	{0x08, 0x14, 0x3c, 0x42, 0x7e, 0x42, 0x42, 0x00},
	{0x08, 0x10, 0x7e, 0x40, 0x7c, 0x40, 0x7e, 0x00},
	{0x00, 0x00, 0x6c, 0x12, 0x3c, 0x50, 0x6e, 0x00},
	{0x00, 0x3e, 0x50, 0x7c, 0x50, 0x50, 0x5e, 0x00},
	{0x10, 0x28, 0x00, 0x38, 0x44, 0x44, 0x38, 0x00},
	{0x28, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x20, 0x10, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x10, 0x28, 0x00, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x20, 0x10, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x44, 0x00, 0x44, 0x44, 0x44, 0x3c, 0x04, 0x38},
	{0x42, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00},
	{0x42, 0x00, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00},
	{0x00, 0x10, 0x38, 0x40, 0x40, 0x38, 0x10, 0x00},
	{0x00, 0x1c, 0x22, 0x78, 0x20, 0x20, 0x7e, 0x00},
	{0x00, 0x44, 0x28, 0x7c, 0x10, 0x7c, 0x10, 0x00},
	{0x00, 0x7c, 0x42, 0x52, 0x7c, 0x50, 0x4c, 0x00},
	{0x00, 0x0c, 0x10, 0x7c, 0x10, 0x10, 0x60, 0x00},
	{0x08, 0x10, 0x00, 0x3c, 0x44, 0x4c, 0x34, 0x00},
	{0x08, 0x10, 0x00, 0x30, 0x10, 0x10, 0x0c, 0x00},
	{0x08, 0x10, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x08, 0x10, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x32, 0x4c, 0x00, 0x5c, 0x62, 0x42, 0x42, 0x00},
	{0x32, 0x4c, 0x00, 0x62, 0x52, 0x4a, 0x46, 0x00},
	{0x38, 0x48, 0x58, 0x28, 0x00, 0x78, 0x00, 0x00},
	{0x30, 0x48, 0x48, 0x30, 0x00, 0x78, 0x00, 0x00},
	{0x00, 0x08, 0x00, 0x08, 0x30, 0x42, 0x3c, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x7c, 0x40, 0x40, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x7c, 0x04, 0x04, 0x00},
	{0x44, 0x48, 0x50, 0x2c, 0x42, 0x04, 0x0e, 0x00},
	{0x44, 0x48, 0x50, 0x24, 0x54, 0x1e, 0x04, 0x00},
	{0x00, 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00},
	{0x00, 0x00, 0x12, 0x24, 0x48, 0x24, 0x12, 0x00},
	{0x00, 0x00, 0x48, 0x24, 0x12, 0x24, 0x48, 0x00},
	{0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11},
	{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55},
	{0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11},
	{0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0x10, 0xf0, 0x10, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0xf0, 0x10, 0xf0, 0x10, 0x10},
	{0x28, 0x28, 0x28, 0x28, 0xe8, 0x28, 0x28, 0x28},
	{0x00, 0x00, 0x00, 0x00, 0xf8, 0x28, 0x28, 0x28},
	{0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x10, 0x10},
	{0x28, 0x28, 0x28, 0xe8, 0x08, 0xe8, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28},
	{0x00, 0x00, 0x00, 0xf8, 0x08, 0xe8, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0xe8, 0x08, 0xf8, 0x00, 0x00},
	{0x28, 0x28, 0x28, 0x28, 0xf8, 0x00, 0x00, 0x00},
	{0x10, 0x10, 0x10, 0xf0, 0x10, 0xf0, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0x10, 0x1f, 0x00, 0x00, 0x00},
	{0x10, 0x10, 0x10, 0x10, 0xff, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0xff, 0x10, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0x10, 0x1f, 0x10, 0x10, 0x10},
	{0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00},
	{0x10, 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0x1f, 0x10, 0x1f, 0x10, 0x10},
	{0x28, 0x28, 0x28, 0x28, 0x2f, 0x28, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0x2f, 0x20, 0x3f, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x3f, 0x20, 0x2f, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0xef, 0x00, 0xff, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0xff, 0x00, 0xef, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0x2f, 0x20, 0x2f, 0x28, 0x28},
	{0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00},
	{0x28, 0x28, 0x28, 0xef, 0x00, 0xef, 0x28, 0x28},
	{0x10, 0x10, 0x10, 0xff, 0x00, 0xff, 0x00, 0x00},
	{0x28, 0x28, 0x28, 0x28, 0xff, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x10, 0x10},
	{0x00, 0x00, 0x00, 0x00, 0xff, 0x28, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0x28, 0x3f, 0x00, 0x00, 0x00},
	{0x10, 0x10, 0x10, 0x1f, 0x10, 0x1f, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x1f, 0x10, 0x1f, 0x10, 0x10},
	{0x00, 0x00, 0x00, 0x00, 0x3f, 0x28, 0x28, 0x28},
	{0x28, 0x28, 0x28, 0x28, 0xef, 0x28, 0x28, 0x28},
	{0x10, 0x10, 0x10, 0xff, 0x00, 0xff, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x1f, 0x10, 0x10, 0x10},
	{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
	{0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff},
	{0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0},
	{0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f},
	{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x32, 0x4a, 0x44, 0x44, 0x3a, 0x00},
	{0x00, 0x38, 0x44, 0x5c, 0x42, 0x62, 0x5c, 0x40},
	{0x00, 0x7e, 0x42, 0x40, 0x40, 0x40, 0x40, 0x00},
	{0x00, 0x00, 0x7c, 0x28, 0x28, 0x28, 0x24, 0x00},
	{0x00, 0x7e, 0x22, 0x10, 0x10, 0x22, 0x7e, 0x00},
	{0x00, 0x00, 0x3e, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x7a, 0x40},
	{0x00, 0x00, 0x7c, 0x10, 0x10, 0x10, 0x08, 0x00},
	{0x00, 0x10, 0x38, 0x54, 0x54, 0x38, 0x10, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x7e, 0x42, 0x3c, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x42, 0x24, 0x66, 0x00},
	{0x78, 0x20, 0x18, 0x44, 0x44, 0x44, 0x38, 0x00},
	{0x00, 0x00, 0x6c, 0x92, 0x92, 0x6c, 0x00, 0x00},
	{0x00, 0x00, 0x18, 0x54, 0x54, 0x38, 0x10, 0x00},
	{0x00, 0x3e, 0x40, 0x7e, 0x40, 0x40, 0x3e, 0x00},
	{0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00},
	{0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x7e, 0x00},
	{0x00, 0x08, 0x08, 0x3e, 0x08, 0x00, 0x3e, 0x00},
	{0x00, 0x10, 0x08, 0x04, 0x08, 0x10, 0x3c, 0x00},
	{0x00, 0x08, 0x10, 0x20, 0x10, 0x08, 0x3c, 0x00},
	{0x00, 0x00, 0x08, 0x14, 0x10, 0x10, 0x10, 0x10},
	{0x10, 0x10, 0x10, 0x10, 0x50, 0x20, 0x00, 0x00},
	{0x00, 0x00, 0x08, 0x00, 0x3e, 0x00, 0x08, 0x00},
	{0x00, 0x00, 0x32, 0x4c, 0x00, 0x32, 0x4c, 0x00},
	{0x00, 0x18, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00},
	{0x00, 0x0e, 0x08, 0x08, 0x48, 0x28, 0x18, 0x00},
	{0x00, 0x50, 0x68, 0x48, 0x48, 0x00, 0x00, 0x00},
	{0x00, 0x60, 0x10, 0x20, 0x70, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00},
	{0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00}};

SDL_Window *gWindow;
SDL_Renderer *gRenderer;
SDL_Texture *gTexture;
Uint32 *pixels;

#pragma mark - HELPERS

int
clamp(int val, int min, int max)
{
	return (val >= min) ? (val <= max) ? val : max : min;
}

char *
scpy(char *src, char *dst, int len)
{
	int i = 0;
	while((dst[i] = src[i]) && i < len - 2)
		i++;
	dst[i + 1] = '\0';
	return dst;
}

#pragma mark - DRAW

void
clear(Uint32 *dst)
{
	int v, h;
	for(v = 0; v < HEIGHT; v++)
		for(h = 0; h < WIDTH; h++)
			dst[v * WIDTH + h] = theme[0];
}

void
putpixel(Uint32 *dst, int x, int y, int color)
{
	if(x >= 0 && x < WIDTH - 8 && y >= 0 && y < HEIGHT - 8)
		dst[(y + PAD * 8) * WIDTH + (x + PAD * 8)] = theme[color];
}

void
drawchr(Uint32 *dst, int x, int y, Uint8 *sprite)
{
	int v, h;
	for(v = 0; v < 8; v++)
		for(h = 0; h < 8; h++) {
			int ch1 = ((sprite[v] >> h) & 0x1);
			int ch2 = (((sprite[v + 8] >> h) & 0x1) << 1);
			putpixel(dst, x + 7 - h, y + v, ch1 + ch2);
		}
}

void
drawicn(Uint32 *dst, int x, int y, Uint8 *sprite, int fg, int bg)
{
	int v, h;
	for(v = 0; v < 8; v++)
		for(h = 0; h < 8; h++) {
			int ch1 = (sprite[v] >> (7 - h)) & 0x1;
			putpixel(dst, x + h, y + v, ch1 ? fg : bg);
		}
}

int
gethexfont(int v)
{
	if(v >= 0 && v <= 9)
		return 48 + v;
	if(v >= 10 && v <= 15)
		return 55 + v;
	return 46;
}

void
drawui(Uint32 *dst)
{
	int bottom = VER * 8 + 8;
	drawicn(dst, 0 * 8, bottom, icons[3], 2, 0);
	drawicn(dst, 1 * 8, bottom, icons[4], 2, 0);
	drawicn(dst, 2 * 8, bottom, icons[5], 2, 0);
	drawicn(dst, 3 * 8, bottom, icons[6], 2, 0);
	drawicn(dst, 5 * 8, bottom, icons[GUIDES ? 12 : 11], GUIDES ? 1 : 2, 0);
	drawicn(dst, (HOR - 1) * 8, bottom, icons[13], doc.unsaved ? 2 : 3, 0);
	drawicn(dst, 15 * 8, bottom, font[gethexfont((cursor.i >> 12) & 0xf)], 3, 0);
	drawicn(dst, 16 * 8, bottom, font[gethexfont((cursor.i >> 8) & 0xf)], 3, 0);
	drawicn(dst, 17 * 8, bottom, font[gethexfont((cursor.i >> 4) & 0xf)], 3, 0);
	drawicn(dst, 18 * 8, bottom, font[gethexfont(cursor.i & 0xf)], 3, 0);
}

void
drawline(Uint32 *dst, int y, int id)
{
	int b = 0;
	if(id >= SZ)
		return;
	for(b = 0; b < 8; ++b) {
		int x = b * 2 + ((b % 8) / 2);
		int k = id + b;
		int b0 = gethexfont(doc.data[k] >> 4 & 0xf);
		int b1 = gethexfont(doc.data[k] & 0xf);
		int bc = doc.data[k];
		int sel = cursor.i == k;
		int linesel = GUIDES && cursor.y == id / 8;
		int pagesel = id % 256 == 0;
		drawicn(dst, x * 8, y, font[b0], sel ? 0 : linesel + pagesel + 1, sel ? 2 : 0);
		drawicn(dst, x * 8 + 8, y, font[b1], sel ? 0 : linesel + pagesel + 1, sel ? 2 : 0);
		drawicn(dst, (19 + (k % 8)) * 8 + 8, y, bc ? font[bc] : icons[2], bc ? 1 : 3, sel ? 4 : 0);
	}
	drawicn(dst, 29 * 8, y, &doc.data[id], 1, 0);
	if(id % 16 == 0)
		drawchr(dst, 31 * 8, y, &doc.data[id]);
}

void
redraw(Uint32 *dst)
{
	int y;
	clear(dst);
	for(y = 0; y < VER; ++y)
		drawline(dst, y * 8, (cursor.view + y) * 8);
	drawui(dst);
	SDL_UpdateTexture(gTexture, NULL, dst, WIDTH * sizeof(Uint32));
	SDL_RenderClear(gRenderer);
	SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
	SDL_RenderPresent(gRenderer);
}

#pragma mark - OPTIONS

int
error(char *msg, const char *err)
{
	printf("Error %s: %s\n", msg, err);
	return 0;
}

void
savemode(int *i, int v)
{
	*i = v;
	redraw(pixels);
}

void
makedoc(Document *d, char *name)
{
	int i;
	for(i = 0; i < SZ; ++i)
		d->data[i] = 0x00;
	d->unsaved = 0;
	scpy(name, d->name, 256);
	printf("Made: %s\n", d->name);
	redraw(pixels);
}

int
savedoc(Document *d, char *name)
{
	FILE *f = fopen(name, "w");
	if(!fwrite(d->data, sizeof(d->data), 1, f))
		return error("Save", "Failure");
	d->unsaved = 0;
	scpy(name, d->name, 256);
	fclose(f);
	printf("Saved: %s\n", d->name);
	redraw(pixels);
	return 1;
}

int
opendoc(Document *d, char *name)
{
	FILE *f = fopen(name, "r");
	if(!f)
		return error("Load", "Invalid input file");
	fread(doc.data, sizeof(doc.data), 1, f);
	d->unsaved = 0;
	scpy(name, doc.name, 256);
	fclose(f);
	printf("Loaded: %s\n", doc.name);
	redraw(pixels);
	return 1;
}

int
printdoc(Document *d)
{
	int i;
	FILE *f = fopen("exed-output.c", "w");
	fprintf(f, "{");
	for(i = 0; i < SZ; ++i) {
		if(i > 0 && i % 16 == 0)
			fprintf(f, "},\n{");
		fprintf(f, "0x%02x", doc.data[i]);
		if(i % 16 < 15)
			fprintf(f, ", ");
	}
	fprintf(f, "}");
	fclose(f);
	puts("Saved exed-output.c");
	return 1;
}

int
printline(Document *d, int id)
{
	int i;
	FILE *f = fopen("exed-output-selection.c", "w");
	fprintf(f, "{");
	for(i = 0; i < 8; ++i) {
		fprintf(f, "0x%02x", doc.data[id + i]);
		if(i % 8 < 7)
			fprintf(f, ", ");
	}
	fprintf(f, "}");
	fclose(f);
	puts("Saved exed-output-selection.c");
	return 1;
}

void
copyclip(int i)
{
	cursor.clip = doc.data[i];
}

void
pasteclip(int i)
{
	doc.data[i] = cursor.clip;
	redraw(pixels);
}

void
cutclip(int i)
{
	copyclip(i);
	doc.data[i] = 0x00;
	redraw(pixels);
}

void
select(int x, int y)
{
	cursor.x = clamp(x, 0, 7);
	cursor.y = clamp(y, 0, SZ / 8 - 1);
	cursor.i = cursor.x % 8 + (cursor.y * 8);
	if(cursor.y >= cursor.view + VER)
		cursor.view = clamp(cursor.y - VER + 1, 0, SZ - 4);
	if(cursor.y <= cursor.view)
		cursor.view = clamp(cursor.y, 0, SZ - 4);
	cursor.swap = 0;
	redraw(pixels);
}

void
insert(int v)
{
	if(!cursor.swap)
		doc.data[cursor.i] = v * 16 + (doc.data[cursor.i] & 0xf);
	else
		doc.data[cursor.i] = (doc.data[cursor.i] / 16 * 16) + v;
	cursor.swap = !cursor.swap;
	redraw(pixels);
}

char
doincr(char c)
{
	return c + 1;
}

char
dodecr(char c)
{
	return c - 1;
}

void
transform(int key, char (*fn)(char))
{
	doc.data[key] = fn(doc.data[key]);
	doc.unsaved = 1;
	redraw(pixels);
}

void
selectoption(int option)
{
	switch(option) {
	case 0: transform(cursor.i, doincr); break;
	case 1: transform(cursor.i, dodecr); break;
	case 2:
		doc.data[cursor.i] = doc.data[cursor.i] << 2;
		redraw(pixels);
		break;
	case 3:
		doc.data[cursor.i] = doc.data[cursor.i] >> 2;
		redraw(pixels);
		break;
	case 5: savemode(&GUIDES, !GUIDES); break;
	case HOR - 1: savedoc(&doc, doc.name); break;
	}
}

void
selectcell(int x, int y)
{
	if(GUIDES) {
		if(x == 4 || x == 9 || x == 14)
			return;
		if(x > 4)
			x--;
		if(x > 9)
			x--;
		if(x > 13)
			x--;
		x /= 2;
	} else
		x /= 3;
	select(x, y + cursor.view);
}

void
quit(void)
{
	free(pixels);
	SDL_DestroyTexture(gTexture);
	gTexture = NULL;
	SDL_DestroyRenderer(gRenderer);
	gRenderer = NULL;
	SDL_DestroyWindow(gWindow);
	gWindow = NULL;
	SDL_Quit();
	exit(0);
}

#pragma mark - TRIGGERS

void
domouse(SDL_Event *event)
{
	switch(event->type) {
	case SDL_MOUSEBUTTONUP:
		break;
	case SDL_MOUSEBUTTONDOWN:
		if(event->motion.y / ZOOM / 8 - PAD == VER + 1) {
			selectoption(event->motion.x / ZOOM / 8 - PAD);
			return;
		}
		selectcell(
			event->motion.x / ZOOM / 8 - PAD,
			event->motion.y / ZOOM / 8 - PAD);
		break;
	case SDL_MOUSEMOTION:

		break;
	}
}

void
dokey(SDL_Event *event)
{
	int shift = SDL_GetModState() & KMOD_LSHIFT || SDL_GetModState() & KMOD_RSHIFT;
	int ctrl = SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL;
	if(ctrl) {
		switch(event->key.keysym.sym) {
		/* Generic */
		case SDLK_n: makedoc(&doc, "untitled.chr"); break;
		case SDLK_r: opendoc(&doc, doc.name); break;
		case SDLK_s: savedoc(&doc, doc.name); break;
		case SDLK_x: cutclip(cursor.i); break;
		case SDLK_c: copyclip(cursor.i); break;
		case SDLK_v: pasteclip(cursor.i); break;
		case SDLK_p: shift ? printline(&doc, cursor.y * 8) : printdoc(&doc); break;
		case SDLK_h: savemode(&GUIDES, !GUIDES); break;
		case SDLK_UP: transform(cursor.i, doincr); break;
		case SDLK_DOWN: transform(cursor.i, dodecr); break;
		}
	} else {
		switch(event->key.keysym.sym) {
		case SDLK_UP: select(cursor.x, cursor.y - 1); break;
		case SDLK_DOWN: select(cursor.x, cursor.y + 1); break;
		case SDLK_LEFT: select(cursor.x - 1, cursor.y); break;
		case SDLK_RIGHT: select(cursor.x + 1, cursor.y); break;
		case SDLK_PAGEUP: select(cursor.x, cursor.y - 16); break;
		case SDLK_PAGEDOWN: select(cursor.x, cursor.y + 16); break;
		case SDLK_BACKSPACE: insert(0); break;
		}
	}
}

void
dotext(SDL_Event *event)
{
	int i;
	if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL)
		return;
	for(i = 0; i < SDL_TEXTINPUTEVENT_TEXT_SIZE; ++i) {
		char c = event->text.text[i];
		if(c < ' ' || c > '~')
			break;
		if(c < '0' || c > 'f')
			break;
		if(c >= '0' && c <= '9')
			insert(c - '0');
		if(c >= 'a' && c <= 'f')
			insert(c - 'a' + 10);
	}
}

void
dowheel(SDL_Event *event)
{
	select(cursor.x, cursor.y - event->wheel.y);
}

int
init(void)
{
	if(SDL_Init(SDL_INIT_VIDEO) < 0)
		return error("Init", SDL_GetError());
	gWindow = SDL_CreateWindow("Exed",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		WIDTH * ZOOM,
		HEIGHT * ZOOM,
		SDL_WINDOW_SHOWN);
	if(gWindow == NULL)
		return error("Window", SDL_GetError());
	gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
	if(gRenderer == NULL)
		return error("Renderer", SDL_GetError());
	gTexture = SDL_CreateTexture(gRenderer,
		SDL_PIXELFORMAT_ARGB8888,
		SDL_TEXTUREACCESS_STATIC,
		WIDTH,
		HEIGHT);
	if(gTexture == NULL)
		return error("Texture", SDL_GetError());
	pixels = (Uint32 *)malloc(WIDTH * HEIGHT * sizeof(Uint32));
	if(pixels == NULL)
		return error("Pixels", "Failed to allocate memory");
	clear(pixels);
	return 1;
}

int
main(int argc, char **argv)
{
	int ticknext = 0;
	if(!init())
		return error("Init", "Failure");
	if(argc > 1) {
		if(!opendoc(&doc, argv[1]))
			makedoc(&doc, argv[1]);
	} else
		makedoc(&doc, "untitled.chr");
	select(0, 0);
	while(1) {
		int tick = SDL_GetTicks();
		SDL_Event event;
		if(tick < ticknext)
			SDL_Delay(ticknext - tick);
		ticknext = tick + (1000 / FPS);
		while(SDL_PollEvent(&event) != 0) {
			switch(event.type) {
			case SDL_QUIT: quit(); break;
			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEMOTION: domouse(&event); break;
			case SDL_MOUSEWHEEL: dowheel(&event); break;
			case SDL_TEXTINPUT: dotext(&event); break;
			case SDL_KEYDOWN: dokey(&event); break;
			case SDL_WINDOWEVENT:
				if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
					redraw(pixels);
				break;
			}
		}
	}
	quit();
	return 0;
}

D dexe.tal => dexe.tal +0 -797
@@ 1,797 0,0 @@
(
	app/dexe : hex editor
	
	arrows     - move selection
	enter      - insert byte
	backspace  - delete byte
	left-click - select bytes

	TODO:
		copy/paste
		scrollbar
)

%+  { ADD } %-   { SUB }  %*  { MUL } %/   { DIV }
%<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }

%RTN  { JMP2r }
%8**  { #30 SFT2 } %8//  { #03 SFT2 }
%TOS  { #00 SWP } %TOB { SWP POP }
%INCR { SWP #01 + SWP }
%TOGGLE { DUP LDZ #00 = SWP STZ }
%INCR2 { SWP2 #0001 ++ SWP2 }
%DECR2 { SWP2 #0001 -- SWP2 }
%DEBUG  { .Console/byte DEO #0a .Console/char DEO }
%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO }
%ASCII-FONT { TOS #0008 ** ;font-hex ++ }
%RELEASE-MOUSE { #00 .Mouse/state DEO }
%RESET-SELECTION { #0000 DUP2 .selection/from STZ2 .selection/to STZ2 }

( devices )

|00 @System     [ &vector $2 &pad     $6 &r      $2 &g     $2 &b     $2 ]
|10 @Console    [ &vector $2 &pad     $6 &char   $1 &byte  $1 &short $2 &string $2 ]
|20 @Screen     [ &vector $2 &width   $2 &height $2 &pad   $2 &x     $2 &y $2 &addr $2 &color $1 ]
|80 @Controller [ &vector $2 &button  $1 &key    $1 ]
|90 @Mouse      [ &vector $2 &x       $2 &y      $2 &state $1 &wheel $1 ]
|a0 @File       [ &vector $2 &success $2 &offset $2 &pad   $2 &name  $2 &length $2 &load $2 &save $2 ]

( variables )

|0000

@state
	&timer $1
	&trap $1
	&blink $1
@pointer
	&x $2 
	&y $2
	&last $1
@selection
	&from $2
	&to $2
	&scroll $2
	&nibble $1
@path 
	&length $1
	&name $20

( program )

|0100
	
	( theme )
	#0f77 .System/r DEO2 
	#0fc7 .System/g DEO2 
	#0f97 .System/b DEO2

	( vectors ) 
	;on-button .Controller/vector DEO2
	;on-mouse .Mouse/vector DEO2
	;on-frame    .Screen/vector DEO2

	;untitled-txt ;new-file JSR2

	;redraw JSR2

BRK

@on-frame ( -> )
	
	.state/trap LDZ #00 ! #01 JCN [ BRK ]

	( incr ) .state/timer LDZ #01 + DUP .state/timer STZ 

	#08 ! ,&no-toggle JCN
		.state/blink TOGGLE
		#23 .state/blink LDZ #09 * + ;draw-filepath JSR2
		#00 .state/timer STZ 
	&no-toggle
	
BRK

@on-mouse ( -> )
	
	;draw-cursor JSR2

	.Mouse/state DEI #00 ! .Mouse/y DEI2 .Screen/height DEI2 #0008 -- >> #0101 == 
		;on-touch-toolbar JCN2
	.Mouse/state DEI #00 ! .Mouse/x DEI2 .Screen/width DEI2 #0008 -- >> #0101 == 
		;on-touch-scrollbar JCN2

	( on mouse-down )
	.Mouse/state DEI #00 > .pointer/last LDZ 
	DUP2 #0100 !! ,&no-mouse-down JCN
		.Mouse/x DEI2 .Mouse/y DEI2 .selection/scroll LDZ2 #0008 ** ++ ;get-cell JSR2 .selection/from STZ2 &no-mouse-down
	POP2

	( on scroll up )
	.Mouse/wheel DEI #01 ! ,&no-scroll-up JCN
		( clamp ) .selection/from LDZ2 #0008 << ,&no-scroll-up JCN
		( move ) .selection/from LDZ2 #0008 -- DUP2 .selection/from STZ2 .selection/to STZ2
		;follow JSR2 ;redraw JSR2 BRK
	&no-scroll-up

	( on scroll down )
	.Mouse/wheel DEI #ff ! ,&no-scroll-down JCN
		( clamp ) .selection/from LDZ2 ;MEMORY-LEN LDA2 #0008 -- >> ,&no-scroll-down JCN
		( move ) .selection/from LDZ2 #0008 ++ DUP2 .selection/from STZ2 .selection/to STZ2
		;follow JSR2 ;redraw JSR2 BRK
	&no-scroll-down

	.Mouse/state DEI DUP .pointer/last STZ #01 JCN [ BRK ]

	.Mouse/x DEI2 .Mouse/y DEI2 .selection/scroll LDZ2 #0008 ** ++ ;get-cell JSR2 
	.selection/to STZ2

	;clamp-selection JSR2

	#00 .selection/nibble STZ

	;redraw JSR2

BRK

@on-touch-scrollbar ( -> )
	
	;MEMORY-LEN LDA2 8// .Screen/height DEI2 8// #0003 -- >> #01 JCN BRK

	.Mouse/y DEI2
	DUP2 8// TOB #00 ! ,&no-up JCN
		( clamp ) .selection/scroll LDZ2 #0000 == ,&no-scroll JCN
		.selection/scroll LDZ2 #0001 -- .selection/scroll STZ2
		;redraw JSR2 POP2 RELEASE-MOUSE BRK &no-up
	DUP2 8// TOB .Screen/height DEI2 8// TOB #03 - ! ,&no-down JCN
		( clamp ) ( TODO )
		.selection/scroll LDZ2 #0001 ++ .selection/scroll STZ2
		;redraw JSR2 POP2 RELEASE-MOUSE BRK &no-down
	DUP2 
		#aa DEBUG
		POP2
		(
		#0008 -- #0010 ** #0010 ** 
		;MEMORY-LEN LDA2 8// #0010 **
		// DEBUG2
		.Screen/height DEI2 8// #0003 -- DEBUG2
		)
	&no-scroll
	POP2

BRK

@on-touch-toolbar ( -> )
	
	.Mouse/x DEI2 8// .Screen/width DEI2 8// TOB SWP -
	DUP #01 ! ,&no-save JCN
		;save-file JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-save
	DUP #03 ! ,&no-load JCN
		;load-file JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-load
	DUP #04 ! ,&no-blank JCN
		;untitled-txt ;new-file JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-blank
	DUP #25 < OVR #05 > #0101 !! ,&no-rename JCN
		.state/trap TOGGLE
		#00 .state/blink STZ 
		#23 ;draw-filepath JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-rename
	POP

BRK

@on-button ( -> )
	
	.Controller/key DEI #00 ! .state/trap LDZ #0101 == ;on-button-trap JCN2

	.Controller/button DEI
	DUP #10 ! ,&no-up JCN
		( clamp ) .selection/from LDZ2 #0008 << ,&no-up JCN
		( move ) .selection/from LDZ2 #0008 -- DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-up
	DUP #11 ! ,&no-up-jump JCN
		( clamp ) .selection/from LDZ2 #0020 << ,&no-up-jump JCN
		( move ) .selection/from LDZ2 #0020 -- DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-up-jump
	DUP #20 ! ,&no-down JCN
		( move ) .selection/from LDZ2 #0008 ++ DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-down
	DUP #21 ! ,&no-down-jump JCN
		( move ) .selection/from LDZ2 #0020 ++ DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-down-jump
	DUP #40 ! ,&no-left JCN
		( clamp ) .selection/from LDZ2 #0007 AND2 #0000 == ,&no-left JCN
		( move ) .selection/from LDZ2 #0001 -- DUP2 .selection/from STZ2 .selection/to STZ2 
		#00 .selection/nibble STZ &no-left
	DUP #80 ! ,&no-right JCN
		( clamp ) .selection/from LDZ2 #0007 AND2 #0007 == ,&no-right JCN
		( move ) .selection/from LDZ2 #0001 ++ DUP2 .selection/from STZ2 .selection/to STZ2 
		#00 .selection/nibble STZ &no-right
	POP
	
	;clamp-selection JSR2

	.Controller/key DEI
	( insert )
	DUP #0d ! ,&no-enter JCN
		.selection/to LDZ2 .selection/from LDZ2 -- #0001 ++ STH2
		.selection/from LDZ2 ;MEMORY ++ STH2kr ;shift-memory-right JSR2
		;MEMORY-LEN LDA2 STH2r ++ ;MEMORY-LEN STA2 &no-enter
	( erase )
	DUP #08 ! ,&no-backspace JCN
		( no erase when size is tiny )
		;MEMORY-LEN LDA2 #0003 << ,&no-backspace JCN
		.selection/to LDZ2 .selection/from LDZ2 -- #0001 ++ STH2
		( no erase when size is small )
		STH2kr ;MEMORY-LEN LDA2 #0002 -- >> ,&no-backspace JCN
		.selection/from LDZ2 ;MEMORY ++ STH2kr ;shift-memory-left JSR2
		;MEMORY-LEN LDA2 STH2r -- ;MEMORY-LEN STA2 
		.selection/from LDZ2 .selection/to STZ2 &no-backspace
	( number keys )
	DUP #2f > OVR #3a < #0101 !! ,&no-number JCN
		DUP #30 - ;write JSR2 &no-number
	( lc letter )
	DUP #60 > OVR #67 < #0101 !! ,&no-lc-letter JCN
		DUP #60 - #09 + ;write JSR2 &no-lc-letter
	POP

	;redraw JSR2

BRK

@on-button-trap ( -> )

	( enter )
	.Controller/key DEI #0d ! ,&no-edit-enter JCN
		#00 .state/trap STZ
		#23 ;draw-filepath JSR2
		BRK &no-edit-enter
	( backspace )
	.Controller/key DEI #08 ! ,&no-edit-backspace JCN
		.path/length LDZ #00 = ,&edit-end JCN
		.path/length LDZ #01 - .path/length STZ
		#00 .path/name .path/length LDZ + STZ
		#23 ;draw-filepath JSR2
		BRK &no-edit-backspace
	( default )
	.path/length LDZ #1f = ,&edit-end JCN
		.Controller/key DEI .path/name .path/length LDZ + STZ
		.path/length LDZ #01 + .path/length STZ &edit-end
	#00 .path/name .path/length LDZ + STZ

BRK

@follow ( -- )
	
	( up )
	.selection/from LDZ2 #03 SFT2 STH2k
	.selection/scroll LDZ2
	>> ,&no-follow-up JCN
		STH2r .selection/scroll STZ2
		RTN &no-follow-up
	POP2r

	( down )
	.selection/to LDZ2 #03 SFT2 STH2k
	.selection/scroll LDZ2 .Screen/height DEI2 8// #0002 -- ++ 
	<< ,&no-follow-down JCN
		STH2r
		.Screen/height DEI2 8// #0003 --
		-- .selection/scroll STZ2
		RTN &no-follow-down
	POP2r

RTN

@write ( char -- )
	
	.selection/from LDZ2 ;MEMORY ++ STH2k LDA
	.selection/nibble LDZ ,&lo JCN
		#0f AND SWP #40 SFT +
		,&continue JMP
	&lo
		#f0 AND +
	&continue
	STH2r STA
	( toggle nibble )
	.selection/nibble TOGGLE

RTN

@redraw ( -- )
	
	( offset )
	;MEMORY .selection/scroll LDZ2 #0008 ** ++ STH2

	( draw lines )
	#0000 .Screen/y DEO2
	;font-hex .Screen/addr DEO2
	#0000 .Screen/height DEI2 #0010 --
	&loop
		#0000 .Screen/x DEO2
		OVR2 STH2kr ++ ,draw-line JSR
		SWP2 #0008 ++ SWP2
		OVR2 .Screen/y DEO2
		LTH2k ,&loop JCN
	POP2 POP2
	POP2r

	;draw-scrollbar JSR2
	;draw-toolbar JSR2

RTN

@draw-line ( addr* -- )
	
	STH2

	STH2kr ;draw-bytes JSR2
	STH2kr ;draw-ascii JSR2

	( icn )
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	STH2kr .Screen/addr DEO2
	#21 .Screen/color DEO

	( chr )
	.Screen/x DEI2 #0010 ++ .Screen/x DEO2
	STH2kr .Screen/addr DEO2
	#41 STH2kr #0008 // #0001 AND2 #0001 == - .Screen/color DEO

	POP2r

RTN

@draw-bytes ( addr* -- )
	
	STH2
	#00 #08
	&byte-loop
		OVR TOS STH2kr ++ STH2

		( is end of file )
		STH2kr ;MEMORY -- ;MEMORY-LEN LDA2 << ,&within-file JCN
			;font-hex .Screen/addr DEO2
			#23 .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
			#23 .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
			,&resume JMP
		&within-file
			STH2kr LDA #04 SFT ASCII-FONT .Screen/addr DEO2
			#21 [ STH2kr ;is-selected JSR2 #07 * ] + .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
			STH2kr LDA #0f AND ASCII-FONT .Screen/addr DEO2
			#21 [ STH2kr ;is-selected JSR2 #07 * ] + .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
		&resume
		POP2r

		( jump after a short )
		OVR #01 AND #00 = ,&no-leap JCN
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2 &no-leap
		INCR
		LTHk ;&byte-loop JCN2
	POP2

	POP2r

RTN

@draw-ascii ( addr* -- )
	
	STH2
	#00 #08
	&ascii-loop
		OVR TOS STH2kr ++ STH2
		( is end of file )
		STH2kr LDA #00 = ,&blank JCN
		STH2kr ;MEMORY -- ;MEMORY-LEN LDA2 << ,&within-file JCN
		&blank
			;font #2e TOS 8** ++ .Screen/addr DEO2 
			#23 [ STH2kr ;is-selected JSR2 ] - .Screen/color DEO
			,&resume JMP
		&within-file
			STH2kr LDA TOS 8** ;font ++ .Screen/addr DEO2 
			#21 [ STH2kr ;is-selected JSR2 #0b * ] + .Screen/color DEO
		&resume
		POP2r
		.Screen/x DEI2 #0008 ++ .Screen/x DEO2
		INCR
		LTHk ,&ascii-loop JCN
	POP2
	POP2r

RTN

@draw-toolbar ( -- )

	( selection )
	.Screen/height DEI2 #0008 -- .Screen/y DEO2
	#0000 .Screen/x DEO2
	.selection/to LDZ2 #22 .selection/from LDZ2 .selection/to LDZ2 == - ;draw-short JSR2
	#0028 .Screen/x DEO2
	;MEMORY-LEN LDA2 #23 ;draw-short JSR2

	( path )
	#0050 .Screen/x DEO2
	#21 ;draw-filepath JSR2

	( draw filesize )
	.Screen/width DEI2 #0008 -- .Screen/x DEO2
	;save-icn .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0010 -- .Screen/x DEO2
	;load-icn .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0008 -- .Screen/x DEO2
	;make-icn .Screen/addr DEO2
	#21 .Screen/color DEO

RTN

@draw-short ( short* color -- )

	STH SWP 
	DUP #04 SFT ASCII-FONT .Screen/addr DEO2
	( draw ) STHkr .Screen/color DEO
	#0f AND ASCII-FONT .Screen/addr DEO2
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	( draw ) STHkr .Screen/color DEO
	DUP #04 SFT ASCII-FONT .Screen/addr DEO2
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	( draw ) STHkr .Screen/color DEO
	#0f AND ASCII-FONT .Screen/addr DEO2
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	( draw ) STHr .Screen/color DEO

RTN

@draw-cursor ( -- )

	( clear last cursor )
	.pointer/x LDZ2 .Screen/x DEO2
	.pointer/y LDZ2 .Screen/y DEO2
	#30 .Screen/color DEO

	( record mouse positions )
	.Mouse/x DEI2 .pointer/x STZ2
	.Mouse/y DEI2 .pointer/y STZ2

	( draw new cursor )
	.pointer/x LDZ2 .Screen/x DEO2
	.pointer/y LDZ2 .Screen/y DEO2
	;cursor-icn .Screen/addr DEO2
	#33 .Mouse/state DEI #00 ! - .Screen/color DEO

RTN

@draw-scrollbar ( -- )

	;scrollbar_icn ( keeping a copy on stack )

	.Screen/width DEI2 #0008 -- .Screen/x DEO2
	#0008 .Screen/y DEO2
	DUP2 .Screen/addr DEO2

	#0008 .Screen/height DEI2 #0018 --
	&loop
		( draw ) #23 .Screen/color DEO
		( incr ) SWP2 #0008 ++ DUP2 .Screen/y DEO2 SWP2
		OVR2 OVR2 LTH2 ,&loop JCN
	POP2 POP2

	;MEMORY-LEN LDA2 #03 SFT2 
	.Screen/height DEI2 8// #0002 -- 
	<< ,&skip-indicator JCN
		.selection/scroll LDZ2 #0008 ++ .Screen/y DEO2
		DUP2 #0008 ++ .Screen/addr DEO2
		( draw ) #21 .Screen/color DEO &skip-indicator

	#0000 .Screen/y DEO2
	DUP2 #0010 ++ .Screen/addr DEO2
	( draw ) #23 .Screen/color DEO

	.Screen/height DEI2 #0018 -- .Screen/y DEO2
	#0018 ++ .Screen/addr DEO2
	( draw ) #23 .Screen/color DEO

RTN

@draw-filepath ( color -- )
	
	STH
	#0050 .Screen/x DEO2
	.Screen/height DEI2 #0008 -- .Screen/y DEO2
	;path/name
	&loop
		LDAk TOS #0008 ** ;font ++ .Screen/addr DEO2 
		STHkr .Screen/color DEO
		.Screen/x DEI2 #0008 ++ .Screen/x DEO2
		#0001 ++
		LDAk ,&loop JCN
	POP2
	POPr
	( clear last ) 
	#20 .Screen/color DEO

RTN

@shift-memory-left ( addr* length* -- )
	
	STH2
	DUP2 ;MEMORY-LEN LDA2 ++
	&loop
		OVR2 DUP2 STH2kr ++ LDA ROT ROT STA
		INCR2
		NEQ2k ,&loop JCN
	POP2 POP2
	POP2r
	
RTN

@shift-memory-right ( addr* length* -- )
	
	STH2
	DUP2 ;MEMORY-LEN LDA2 ++ SWP2 #0001 --
	&loop
		OVR2 DUP2 LDA ROT ROT STH2kr ++ STA
		DECR2
		NEQ2k ,&loop JCN
	POP2 POP2
	POP2r
	
RTN

@clamp-selection ( -- )
	
	( no outside )
	;MEMORY-LEN LDA2 STH2
	.selection/from LDZ2 STH2kr << ,&skip-from JCN
		STH2kr #0001 -- .selection/from STZ2 &skip-from
	.selection/to LDZ2 STH2kr << ,&skip-to JCN
		STH2kr #0001 -- .selection/to STZ2 &skip-to
	POP2r
	( no backward )
	.selection/to LDZ2 .selection/from LDZ2 >> ,&no-negative JCN
		.selection/from LDZ2 .selection/to STZ2 &no-negative
	
RTN

@is-selected ( addr* -- flag )
	
	;MEMORY --
	DUP2 .selection/from LDZ2 !! ,&no-from JCN
		POP2 #01 RTN &no-from 
	DUP2 .selection/to LDZ2 !! ,&no-to JCN
		POP2 #01 RTN &no-to 
	STH2k
	.selection/from LDZ2 >> 
	STH2r .selection/to LDZ2 << 
	#0101 ==

RTN

@get-cell ( x* y* -- addr* )

	( row ) 8// #0008 ** SWP2
	( col ) DUP2 #00a0 << ,&byte JCN
		POP2 RTN &byte
	DUP2 #0028 // #0008 ** --
	#0008 // #0002 //
	++ 

RTN

@clear ( from* to* -- )
	
	;MEMORY DUP2 ;MEMORY-LEN LDA2 ++
	&loop
		OVR2 #00 ROT ROT STA
		INCR2
		LTH2k ,&loop JCN
	POP2 POP2

RTN

@new-file ( default* -- )
	
	#20 ;draw-filepath JSR2 

	;clear JSR2
	RESET-SELECTION

	STH2
	#00 #0c
	&loop
		OVR DUP TOS STH2kr ++ LDA SWP .path/name + STZ
		INCR
		LTHk ,&loop JCN
	.path/length STZ POP 
	POP2r

	#00 .path/name #0c + STZ
	#0002 ;MEMORY-LEN STA2

RTN

@load-file ( -- )

	( BANK LENGTH ;op-clear JSR2 )
	;path/name .File/name DEO2 
	#fff0 ;MEMORY -- .File/length DEO2 
	;MEMORY .File/load DEO2
	.File/success DEI2 ;MEMORY-LEN STA2

RTN

@save-file ( -- )

	;path/name .File/name DEO2 
	;MEMORY-LEN LDA2 .File/length DEO2 
	;MEMORY .File/save DEO2

RTN

@untitled-txt  "untitled.chr $1
@save-icn      1054 28c6 2854 1000 
@make-icn      fe82 8282 848a f400 
@load-icn      feaa d6aa d4aa f400 
@cursor-icn    80c0 e0f0 f8e0 1000

@scrollbar_icn
	aa55 aa55 aa55 aa55 ( bg )
	ffff ffff ffff ffff ( fg )
	0010 387c fe10 1010 ( up )
	0010 1010 fe7c 3810 ( down )

@font-hex
	007c 8282 8282 827c 0030 1010 1010 1010
	007c 8202 7c80 80fe 007c 8202 1c02 827c
	000c 1424 4484 fe04 00fe 8080 7c02 827c
	007c 8280 fc82 827c 007c 8202 1e02 0202
	007c 8282 7c82 827c 007c 8282 7e02 827c
	007c 8202 7e82 827e 00fc 8282 fc82 82fc
	007c 8280 8080 827c 00fc 8282 8282 82fc
	007c 8280 f080 827c 007c 8280 f080 8080 

@font ( specter8 font )
	0000 0000 0000 0000 0000 2400 7e3c 0000
	0000 2400 3c42 0000 0000 6c7c 7c38 1000
	0010 387c 7c38 1000 0038 387c 6c10 3800
	0010 387c 7c10 3800 0000 0018 1800 0000
	007e 4242 4242 7e00 0000 1824 2418 0000
	003c 665a 5a66 3c00 001e 063a 4a48 3000
	0038 446c 107c 1000 000e 0808 0838 3800
	003e 3e22 2266 6600 0000 1044 0044 1000
	0000 1018 1c18 1000 0000 0818 3818 0800
	0008 1c00 001c 0800 0028 2828 2800 2800
	003e 4a4a 3a0a 0a00 000c 3046 620c 3000
	0000 0000 0000 ffff 0010 3800 3810 0038
	0010 3854 1010 1000 0010 1010 5438 1000
	0000 0804 7e04 0800 0000 1020 7e20 1000
	0000 4040 7e00 0000 0000 0024 6624 0000
	0000 1038 7c00 0000 0000 007c 3810 0000
	0000 0000 0000 0000 0008 0808 0800 0800
	0014 1400 0000 0000 0024 7e24 247e 2400
	0008 1e28 1c0a 3c08 0000 2204 0810 2200
	0030 4832 4c44 3a00 0008 1000 0000 0000
	0004 0808 0808 0400 0020 1010 1010 2000
	0000 2214 0814 2200 0000 0808 3e08 0800
	0000 0000 0000 0810 0000 0000 3e00 0000
	0000 0000 0000 0800 0000 0204 0810 2000
	003c 464a 5262 3c00 0018 0808 0808 1c00
	003c 4202 3c40 7e00 003c 421c 0242 3c00
	000c 1424 447e 0400 007e 407c 0242 3c00
	003c 407c 4242 3c00 007e 0204 0810 1000
	003c 423c 4242 3c00 003c 4242 3e02 3c00
	0000 0010 0000 1000 0000 1000 0010 1020
	0000 0810 2010 0800 0000 003e 003e 0000
	0000 1008 0408 1000 003c 420c 1000 1000
	003c 4232 4a42 3c00 003c 4242 7e42 4200
	007c 427c 4242 7c00 003c 4240 4042 3c00
	007c 4242 4242 7c00 007e 4078 4040 7e00
	007e 4078 4040 4000 003c 4240 4642 3c00
	0042 427e 4242 4200 001c 0808 0808 1c00
	007e 0202 0242 3c00 0042 4478 4442 4200
	0040 4040 4040 7e00 0042 665a 4242 4200
	0042 6252 4a46 4200 003c 4242 4242 3c00
	007c 4242 7c40 4000 003c 4242 4244 3a00
	007c 4242 7c44 4200 003e 403c 0242 3c00
	007e 0808 0808 1000 0042 4242 4244 3a00
	0042 4242 4224 1800 0042 4242 5a66 4200
	0042 423c 4242 4200 0042 423e 0242 3c00
	007e 020c 3040 7e00 000c 0808 0808 0c00
	0040 2010 0804 0200 0030 1010 1010 3000
	0008 1400 0000 0000 0000 0000 0000 7e00
	0008 0400 0000 0000 0000 3c02 3e42 3a00
	0040 407c 4242 7c00 0000 3c42 4042 3c00
	0002 023e 4242 3e00 0000 3c42 7e40 3e00
	0000 3e40 7840 4000 0000 3c42 3e02 3c00
	0040 405c 6242 4200 0008 0018 0808 0400
	0008 0018 0808 4830 0040 4244 7844 4200
	0010 1010 1010 0c00 0000 6c52 5252 5200
	0000 5c62 4242 4200 0000 3c42 4242 3c00
	0000 7c42 427c 4040 0000 3e42 423e 0202
	0000 5c62 4040 4000 0000 3e40 3c02 7c00
	0008 7e08 0808 1000 0000 4242 4244 3a00
	0000 4242 4224 1800 0000 5252 5252 2e00
	0000 4224 1824 4200 0000 4242 3e02 7c00
	0000 7e02 3c40 7e00 000c 0810 1008 0c00
	0008 0808 0808 0800 0030 1008 0810 3000
	0000 0032 4c00 0000 3c42 99a1 a199 423c
	003c 4240 423c 1070 0044 0044 4444 3800
	0810 3844 7840 3c00 0814 3c02 3e42 3a00
	1400 3c02 3e42 3a00 0804 3c02 3e42 3a00
	0814 2c02 3e42 3a00 0000 1c20 201c 0818
	1028 3844 7840 3c00 2800 3844 7840 3c00
	2010 3c44 7840 3c00 0028 0030 1010 0c00
	1028 0030 1010 0c00 2010 0030 1010 0c00
	423c 4242 7e42 4200 0814 3c42 7e42 4200
	0810 7e40 7c40 7e00 0000 6c12 3c50 6e00
	003e 507c 5050 5e00 1028 0038 4444 3800
	2800 3844 4444 3800 2010 3844 4444 3800
	1028 0044 4444 3800 2010 4444 4444 3800
	4400 4444 443c 0438 423c 4242 4242 3c00
	4200 4242 4242 3c00 0010 3840 4038 1000
	001c 2278 2020 7e00 0044 287c 107c 1000
	007c 4252 7c50 4c00 000c 107c 1010 6000
	0810 3c02 3e42 3a00 0810 0030 1010 0c00
	0810 3844 4444 3800 0810 4444 4444 3800
	324c 005c 6242 4200 324c 0062 524a 4600
	3848 5828 0078 0000 3048 4830 0078 0000
	0008 0008 3042 3c00 0000 0000 7c40 4000
	0000 0000 7c04 0400 4448 502c 4204 0e00
	4448 5024 541e 0400 0010 0010 1010 1000
	0000 1224 4824 1200 0000 4824 1224 4800
	8844 2211 8844 2211 aa55 aa55 aa55 aa55
	4411 4411 4411 4411 1010 1010 1010 1010
	1010 1010 f010 1010 1010 10f0 10f0 1010
	2828 2828 e828 2828 0000 0000 f828 2828
	0000 00f0 10f0 1010 2828 28e8 08e8 2828
	2828 2828 2828 2828 0000 00f8 08e8 2828
	2828 28e8 08f8 0000 2828 2828 f800 0000
	1010 10f0 10f0 0000 0000 0000 f010 1010
	1010 1010 1f00 0000 1010 1010 ff00 0000
	0000 0000 ff10 1010 1010 1010 1f10 1010
	0000 0000 ff00 0000 1010 1010 ff10 1010
	1010 101f 101f 1010 2828 2828 2f28 2828
	2828 282f 203f 0000 0000 003f 202f 2828
	2828 28ef 00ff 0000 0000 00ff 00ef 2828
	2828 282f 202f 2828 0000 00ff 00ff 0000
	2828 28ef 00ef 2828 1010 10ff 00ff 0000
	2828 2828 ff00 0000 0000 00ff 00ff 1010
	0000 0000 ff28 2828 2828 2828 3f00 0000
	1010 101f 101f 0000 0000 001f 101f 1010
	0000 0000 3f28 2828 2828 2828 ef28 2828
	1010 10ff 00ff 1010 1010 1010 f000 0000
	0000 0000 1f10 1010 ffff ffff ffff ffff
	0000 0000 ffff ffff f0f0 f0f0 f0f0 f0f0
	0f0f 0f0f 0f0f 0f0f ffff ffff 0000 0000
	0000 324a 4444 3a00 0038 445c 4262 5c40
	007e 4240 4040 4000 0000 7c28 2828 2400
	007e 2210 1022 7e00 0000 3e44 4444 3800
	0000 4444 4444 7a40 0000 7c10 1010 0800
	0010 3854 5438 1000 003c 4242 7e42 3c00
	003c 4242 4224 6600 7820 1844 4444 3800
	0000 6c92 926c 0000 0000 1854 5438 1000
	003e 407e 4040 3e00 003c 4242 4242 4200
	0000 7e00 7e00 7e00 0008 083e 0800 3e00
	0010 0804 0810 3c00 0008 1020 1008 3c00
	0000 0814 1010 1010 1010 1010 5020 0000
	0000 0800 3e00 0800 0000 324c 0032 4c00
	0018 2424 1800 0000 0000 0018 1800 0000
	0000 0000 1000 0000 000e 0808 4828 1800
	0050 6848 4800 0000 0060 1020 7000 0000
	0000 3c3c 3c3c 0000 0000 3c3c 3c3c 0000

@MEMORY-LEN $2

@MEMORY
\ No newline at end of file

A src/font.tal => src/font.tal +257 -0
@@ 0,0 1,257 @@
@font ( msx816 )
	0000 0000 0000 0000 0000 0000 0000 0000
	1818 1818 1818 1010 1010 1000 0010 1010
	0000 2828 0000 0000 0000 0000 0000 0000
	2828 282e 38e8 2828 2828 2e38 e828 2828
	1038 5454 5450 5030 1814 1454 5454 3810
	42a2 a4a4 4808 1010 1020 244a 4a8a 8400
	0010 2828 2828 1030 504a 4a44 443a 0000
	1010 1020 0000 0000 0000 0000 0000 0000
	0204 0408 0808 0808 0808 0808 0804 0402
	4020 2010 1010 1010 1010 1010 1020 2040
	0000 1010 5454 3810 3854 5410 1000 0000
	0000 0010 1010 107c 1010 1010 0000 0000
	0000 0000 0000 0000 0000 0000 1010 1020
	0000 0000 0000 007c 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0020 2000
	0202 0404 0808 1010 2020 4040 8080 0000
	0018 2442 4242 4242 4242 4242 4224 1800
	0008 1828 0808 0808 0808 0808 0808 1c00
	0018 2442 4202 0202 0408 1020 4040 7e00
	0018 2442 0202 0438 0402 0202 0204 7800
	000c 0c14 1414 2424 2444 447e 0404 0e00
	007e 4040 4040 5864 4202 0202 0204 7800
	000c 1020 4040 5864 4242 4242 4224 1800
	007e 4202 0204 0404 0808 0810 1010 1000
	0018 2442 4242 2418 2442 4242 4224 1800
	0018 2442 4242 4242 261a 0202 0408 3000
	0000 0000 0010 1000 0000 0000 1010 0000
	0000 0000 0010 1000	0000 0000 1010 1020
	0000 0204 0810 2040	2010 0804 0200 0000
	0000 0000 0000 7c00	007c 0000 0000 0000
	0000 4020 1008 0402	0408 1020 4000 0000
	1824 4242 4204 0408	0810 1010 0010 1010
	3844 8282 9aaa aaaa	aaaa aa96 8082 4438
	0010 1028 2844 4444	8282 fe82 8282 0000
	00f8 4442 4242 4478	4442 4242 44f8 0000
	003c 4282 8280 8080	8080 8282 423c 0000
	00f8 4442 4242 4242	4242 4242 44f8 0000
	00fc 4240 4040 4878 4840 4040 42fc 0000
	80fe 4240 4040 447c 4440 4040 40e0 0000
	003a 4682 8080 8e82 8282 8282 463a 0000
	00ee 4444 4444 447c 4444 4444 44ee 0000
	0038 1010 1010 1010 1010 1010 1038 0000
	000e 0404 0404 0404 0404 4444 2810 0000
	00ee 4448 4850 5060 5050 4848 44ee 0000
	00e0 4040 4040 4040 4040 4040 42fe 0000
	0082 c6c6 c6aa aaaa 9292 9282 8282 0000
	00e2 4262 6262 5252 4a4a 4646 42e2 0000
	0038 4482 8282 8282 8282 8282 4438 0000
	00f8 4442 4242 4244 7840 4040 40f0 0000
	0038 4482 8282 8282 8282 829a 643a 0000
	00f8 4442 4242 4478 4844 4442 42e2 0000
	0010 2844 4440 2010 0804 4444 2810 0000
	00fe 9210 1010 1010 1010 1010 1038 0000
	00ee 4444 4444 4444 4444 4444 4438 0000
	0082 8282 8282 8244 4444 2828 1010 0000
	0082 8292 9292 9292 92ba aa44 4444 0000
	0042 4242 2424 1818 1824 2442 4242 0000
	0082 8282 4444 2828 1010 1010 1038 0000
	007e 4204 0408 0810 1020 2040 427e 0000
	0e08 0808 0808 0808 0808 0808 0808 080e
	0082 8282 4444 fe28 10fe 1010 1010 1000
	7010 1010 1010 1010 1010 1010 1010 1070
	1028 4400 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 00fe
	1010 1008 0000 0000 0000 0000 0000 0000
	0000 0000 0030 0808 3848 4848 4834 0000
	0060 2020 202c 3222 2222 2222 322c 0000
	0000 0000 001c 2240 4040 4040 221c 0000
	000c 0404 0434 4c44 4444 4444 4c36 0000
	0000 0000 0018 2424 3c20 2020 2418 0000
	000c 1210 1038 1010 1010 1010 1038 0000
	0000 0000 0034 4a48 4830 4038 4444 4438
	00c0 4040 4058 6444 4444 4444 44ee 0000
	0010 0000 0030 1010 1010 1010 1038 0000
	0008 0000 0018 0808 0808 0808 0808 2810
	0060 2020 2022 2224 2438 2424 2272 0000
	0030 1010 1010 1010 1010 1010 1038 0000
	0000 0000 00a4 da92 9292 9292 9292 0000
	0000 0000 00d8 6444 4444 4444 44ee 0000
	0000 0000 0038 4482 8282 8282 4438 0000
	0000 0000 00d8 6442 4242 4242 6458 40e0
	0000 0000 0034 4c84 8484 8484 4c34 040e
	0000 0000 0068 3420 2020 2020 2070 0000
	0000 0000 0018 2424 1008 0424 2418 0000
	0010 1010 107c 1010 1010 1010 1408 0000
	0000 0000 00cc 4444 4444 4444 4c36 0000
	0000 0000 00ee 4444 4428 2828 1010 0000
	0000 0000 0092 9292 9292 92aa 4444 0000
	0000 0000 00ee 4428 1010 1028 44ee 0000
	0000 0000 00ee 4444 4448 2828 1010 2040
	0000 0000 007c 4408 0810 2020 447c 0000
	0204 0404 0404 0408 0804 0404 0404 0402
	1010 1010 1010 1010 1010 1010 1010 1010
	4020 2020 2020 2010 1020 2020 2020 2040
	fe00 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0030 4848 3000
	001e 1010 1010 1010 0000 0000 0000 0000
	0000 0000 0000 0000 0808 0808 0808 7800
	0000 0000 0000 0000 0000 0000 4020 3000
	0000 0000 0000 183c 3c18 0000 0000 0000
	0808 087c 1010 2a34 4c94 1424 2020 1c00
	0000 0000 0010 107c 103c 5652 4a52 2408
	0000 0000 0000 0040 4442 4242 4250 2000
	0000 0000 0020 1800 7804 0404 0408 0810
	0000 0000 0000 1800 3c08 1010 2848 4600
	0000 0000 0000 1014 3a10 1c32 5252 3400
	0000 0000 1048 5068 c444 4428 2010 1000
	0000 0000 0848 485c 6a4a 4a4a 5c08 0810
	0000 0000 1010 101c 1010 1070 9894 6000
	0000 0000 0000 0000 1c62 0202 0404 0810
	0000 0000 0000 0040 3e00 0000 0000 0000
	0010 1010 7e20 3c66 aaaa 92aa a244 0800
	0000 8080 8482 8282 8282 a0a0 4040 0000
	0030 0c00 007c 0202 0202 0202 0408 3000
	2018 0000 007c 0808 1020 3048 8888 0600
	0020 2c26 203c e020 2c32 62a2 a262 2400
	2020 2422 f22a 2a2a 4a48 4848 8898 3000
	0020 2020 fc10 10fc 0804 7c82 8040 3800
	0202 0408 0810 2040 2010 1008 0804 0202
	0004 4444 449e 8484 8484 84a4 4444 0810
	0000 7c00 0000 0000 0080 8080 403e 0000
	0010 1010 fc10 0808 047c 8280 8040 3800
	0040 4040 4040 4040 4040 4040 4244 3800
	0808 08fe 0808 3848 4858 2808 0810 1020
	0008 4848 48fe 4848 4848 4858 4040 3c00
	007e 0408 1020 40fe 0810 1010 1008 0400
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0030 4848 3000
	001e 1010 1010 1010 0000 0000 0000 0000
	0000 0000 0000 0000 0808 0808 0808 7800
	0000 0000 0000 0000 0000 0000 4020 3000
	0000 0000 0000 183c 3c18 0000 0000 0000
	0000 00fc 0404 047c 0404 0808 1010 2000
	0000 0000 0000 007e 0214 1810 1020 2040
	0000 0000 0000 0408 0810 2848 0808 0808
	0000 0000 0000 1010 7c44 4404 0808 1010
	0000 0000 0000 0000 0038 1010 1010 7c00
	0000 0000 0000 0808 7e18 2828 4848 8818
	0000 0000 0000 2020 3ce4 2820 1010 1010
	0000 0000 0000 0000 3808 0808 087c 0000
	0000 0000 0000 003c 0404 3c04 0404 3c00
	0000 0000 0000 0024 9454 4404 0808 1020
	0000 0000 0000 0040 3e00 0000 0000 0000
	0000 00fe 0202 1418 1010 1010 2020 4000
	0004 0408 0810 1828 4888 0808 0808 0800
	0000 1010 fe82 8282 0204 0404 0808 1000
	0000 0000 0000 7c10 1010 1010 1010 fe00
	0008 0808 08fe 0818 2828 4848 8888 1800
	0020 2020 fc24 2424 2444 4484 8404 1800
	0040 2020 3ed0 101e e808 0804 0404 0202
	0000 2020 3c24 2444 4488 0810 1060 8000
	0000 2020 203e 4444 4484 0808 1010 2000
	0000 0000 fe02 0202 0202 0202 fe00 0000
	0000 0424 2424 fe24 2424 0404 0808 1000
	0000 2010 0000 8242 0204 0408 1060 8000
	0000 0078 0808 0808 1010 2828 4482 0000
	0000 2020 2026 3ae2 2420 2020 201e 0000
	0000 0202 0242 2222 0404 0808 1020 4000
	0000 2020 3c24 2444 6498 0810 1060 8000
	0000 0c70 0808 08fe 0808 0808 1010 2000
	0000 0022 9252 4202 0404 0808 1020 0000
	0000 007c 0000 fe08 0808 0810 1020 4000
	0040 4040 4040 7058 4c46 4040 4040 4000
	0008 0808 0808 fe08 0808 0810 1020 4000
	0000 0000 007c 0000 0000 00fe 0000 0000
	0000 007c 0404 0428 1808 1412 2040 0000
	1010 0800 7c04 0808 1014 3252 9010 1000
	0000 0002 0204 0408 0810 1020 20c0 0000
	0000 0048 4844 4442 4242 8282 8282 0000
	0000 4040 424c 7040 4040 4040 3c00 0000
	0000 007e 0202 0202 0404 0808 1020 0000
	0000 0000 2050 5088 8804 0200 0000 0000
	0010 1010 10fe 1010 1452 5252 9210 3000
	0000 0000 fe02 0404 4830 1008 0400 0000
	0000 3018 0c00 3018 0400 3018 0c00 0000
	0000 0008 0810 1020 2024 424e f202 0000
	0000 0202 0444 2810 1028 2440 4080 0000
	0000 0000 7c20 20ff 2020 2020 1e00 0000
	0020 2026 3ae2 2428 2010 1010 1010 0000
	0000 0000 7808 0808 0808 fe00 0000 0000
	0000 0000 7e02 0202 7e02 0202 7e00 0000
	0000 003c 0000 fe02 0204 0408 0810 2000
	0002 2222 2222 2222 2222 0204 0408 1000
	0000 0000 1010 5050 5252 5454 9890 0000
	0000 0040 4040 4042 4244 4448 5060 0000
	0000 0000 007e 4242 4242 4242 7e00 0000
	0000 00fe 8282 8202 0404 0808 1020 4000
	0000 0040 2012 0202 0204 0408 30c0 0000
	0000 3008 6010 0000 0000 0000 0000 0000
	0000 3048 4830 0000 0000 0000 0000 0000
	0020 2020 f820 2e40 4040 5050 908e 8000
	0010 1010 fc20 2020 2c32 4202 0204 3800
	0000 0000 0834 c202 0202 0204 0418 2000
	0000 fe04 0810 2040 4040 4020 2010 0c00
	0000 8040 2022 1c30 4040 8080 8040 3e00
	2020 2824 f222 4848 4888 8898 2424 1a00
	0000 405e 8080 8080 8080 9090 d08e 0000
	0000 0444 443c 6aaa aa92 92a6 aaaa 4400
	0040 4044 6ad2 5262 6242 4ad6 d24c 4200
	0000 1824 5292 9292 a2a2 a2a2 a244 0800
	0004 4444 5e44 8484 8484 848c 9694 4800
	0000 e028 4844 4684 8484 8484 8448 3000
	0000 2018 0c00 2020 1412 8a8a ca88 3000
	0000 0000 2050 5088 8804 0200 0000 0000
	0000 5e44 445e 8484 8484 848c 94d4 4a00
	0808 087e 0808 087e 0808 0838 4c4a 3000
	0078 0808 1012 1234 6ea4 a444 0408 1000
	3010 1010 f824 2262 a0a0 a262 2222 1c00
	0008 0888 4858 6cea ba92 aaa2 a444 0800
	1010 1010 fc20 20fc 2020 2222 2222 1c00
	0008 0804 805c 62c2 4242 2c20 1010 1000
	0008 089c aaaa ca8a 8a8a aa9c 0808 1000
	0010 1010 101e 1010 1010 1070 9894 6000
	2018 0c00 4040 4080 9ca2 c282 0204 3800
	0000 4242 4242 4242 4252 2202 0404 1800
	0000 7e04 0810 207c 62c2 821a 2624 1800
	2020 2028 f434 2424 2464 64a4 a422 2000
	0000 3c08 0810 102c 2222 4242 0204 1800
	0020 2020 e02c 3222 6262 a2a2 2224 2000
	0008 0808 1010 1020 2030 5252 928c 0000
	0000 3008 6010 0000 0000 0000 0000 0000
	0000 3048 4830 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
	0000 0000 0000 0000 0000 0000 0000 0000
\ No newline at end of file

M src/main.tal => src/main.tal +96 -140
@@ 75,6 75,12 @@
	&name $20
@frame
	&x $2 &y $2 &x2 $2 &y2 $2 
@byte-frame
	&x $2 &y $2 &x2 $2 &y2 $2 
@char-frame
	&x $2 &y $2 &x2 $2 &y2 $2 
@tile-frame
	&x $2 &y $2 &x2 $2 &y2 $2 

( program )



@@ 98,6 104,27 @@
	.Screen/height DEI2 2// #0080 -- DUP2 .frame/y STZ2
		#0100 ++ .frame/y2 STZ2

	.frame/x LDZ2 
		DUP2 .byte-frame/x STZ2
		#00c0 ++ .byte-frame/x2 STZ2
	.frame/y LDZ2 
		DUP2 .byte-frame/y STZ2
		#0100 ++ .byte-frame/y2 STZ2

	.byte-frame/x2 LDZ2 
		DUP2 .char-frame/x STZ2
		#0040 ++ .char-frame/x2 STZ2
	.byte-frame/y LDZ2 
		DUP2 .char-frame/y STZ2
		#0100 ++ .char-frame/y2 STZ2

	.char-frame/x2 LDZ2 #0008 ++
		DUP2 .tile-frame/x STZ2
		#0008 ++ .tile-frame/x2 STZ2
	.byte-frame/y LDZ2 
		DUP2 .tile-frame/y STZ2
		#0100 ++ .tile-frame/y2 STZ2

	( load bytes )
	;untitled-txt .File/name DEO2
	#1000         .File/length DEO2


@@ 128,15 155,38 @@ BRK
	.Mouse/y DEI2 DUP2 .cursor/y STZ2 .Screen/y DEO2
	;cursor-icn .Screen/addr DEO2
	.Mouse/state DEI #00 ! #41 + .Screen/sprite DEO

	.Mouse/x DEI2 .Mouse/y DEI2 
	( begin with canvas )
	OVR2 OVR2 .byte-frame ;within-rect JSR2
		;on-touch-byte JCN2
	OVR2 OVR2 .char-frame ;within-rect JSR2
		;on-touch-char JCN2
	OVR2 OVR2 .tile-frame ;within-rect JSR2
		;on-touch-tile JCN2
	POP2 POP2
	
BRK

@on-touch-byte ( x* y* -> )

BRK

@on-touch-char ( x* y* -> )

BRK

@on-touch-tile ( x* y* -> )

BRK


@redraw ( -- )

	#0020 #0000 
	#0010 #0000 
	&loop
		( addr ) DUP2 8** ;MEMORY ++ STH2
		( y ) DUP2 8** .frame/y LDZ2 ++
		( y ) DUP2 10** .frame/y LDZ2 ++
		STH2r ;draw-row JSR2
		INC2 GTH2k ,&loop JCN
	POP2 POP2


@@ 151,24 201,25 @@ RTN
	#08 #00
	&bytes-loop
		( color ) #01 STH
		( byte ) DUP TOS ;&row LDA2 ++ LDA DUP DEBUG STH
		( byte ) DUP TOS ;&row LDA2 ++ LDA STH
		( y ) ;&y LDA2 STH2
		( x-block ) DUP TOS ;byte-spacing ++ LDA TOS 8** .frame/x LDZ2 ++
		( x-block ) DUP #03 MUL TOS 8** .frame/x LDZ2 ++
		STH2r STHr STHr ;draw-byte JSR2
		INC GTHk ,&bytes-loop JCN
	POP2

	#08 #00
	&chars-loop
		( color ) #08 STH
		( color ) #01 STH
		( byte ) DUP TOS ;&row LDA2 ++ LDA STH
		( y ) ;&y LDA2 STH2
		( x-block ) DUP TOS 8** .frame/x LDZ2 ++ #00a0 ++
		( x-block ) DUP TOS 8** .frame/x LDZ2 ++ #00c0 ++
		STH2r STHr STHr ;draw-char JSR2
		INC GTHk ,&chars-loop JCN
	POP2

	#00e8 .frame/x LDZ2 ++ .Screen/x DEO2
	.Screen/y DEI2 #0010 -- .Screen/y DEO2
	#0108 .frame/x LDZ2 ++ .Screen/x DEO2
	;&row LDA2 .Screen/addr DEO2
	#01 .Screen/sprite DEO



@@ 177,30 228,46 @@ RTN

@draw-byte ( x* y* byte color -- )

	#06 .Screen/auto DEO
	STH STH
	.Screen/y DEO2
	.Screen/x DEO2
	STHr
	DUP
		( hn )
		#0f AND TOS 8** ;font-hex ++ .Screen/addr DEO2
		#04 SFT ,&parse JSR #18 - TOS 10** ;font-hex ++ .Screen/addr DEO2
		STHkr .Screen/sprite DEO
		STHkr .Screen/sprite DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	.Screen/y DEI2 #0010 -- .Screen/y DEO2
		( ln )
		#04 SFT TOS 8** ;font-hex ++ .Screen/addr DEO2
		#0f AND ,&parse JSR #18 - TOS 10** ;font-hex ++ .Screen/addr DEO2
		STHkr .Screen/sprite DEO
		STHr .Screen/sprite DEO
	#00 .Screen/auto DEO
	RTN
	&parse ( value -- char )
		DUP #09 > ,&above JCN 
			#30 + RTN 
		&above 
			#09 - #60 + RTN

RTN

@draw-char ( x* y* char color -- )

	#06 .Screen/auto DEO

	STH STH
	.Screen/y DEO2
	.Screen/x DEO2
	STHr
	TOS 8** ;font ++ .Screen/addr DEO2
	STHr #7f AND
	#20 - TOS 10** ;font ++ .Screen/addr DEO2
	STHkr .Screen/sprite DEO
	STHr .Screen/sprite DEO

	#00 .Screen/auto DEO

RTN

@line-rect ( rect color -- )


@@ 235,6 302,23 @@ RTN

RTN

@within-rect ( x* y* rect -- flag )
	
	STH
	( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 << ,&skip JCN
	( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 >> ,&skip JCN
	SWP2
	( x < rect.x1 ) DUP2 STHkr LDZ2 << ,&skip JCN
	( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 >> ,&skip JCN
	POP2 POP2 POPr
	#01 
RTN
	&skip
	POP2 POP2 POPr
	#00

RTN

@print-hex ( value* -- )
	
	&short ( value* -- )


@@ 275,135 359,7 @@ RTN
	007c 8280 8080 827c 00fc 8282 8282 82fc
	007c 8280 f080 827c 007c 8280 f080 8080 

@font ( specter8 font )
	0000 0000 0000 0000 0000 2400 7e3c 0000
	0000 2400 3c42 0000 0000 6c7c 7c38 1000
	0010 387c 7c38 1000 0038 387c 6c10 3800
	0010 387c 7c10 3800 0000 0018 1800 0000
	007e 4242 4242 7e00 0000 1824 2418 0000
	003c 665a 5a66 3c00 001e 063a 4a48 3000
	0038 446c 107c 1000 000e 0808 0838 3800
	003e 3e22 2266 6600 0000 1044 0044 1000
	0000 1018 1c18 1000 0000 0818 3818 0800
	0008 1c00 001c 0800 0028 2828 2800 2800
	003e 4a4a 3a0a 0a00 000c 3046 620c 3000
	0000 0000 0000 ffff 0010 3800 3810 0038
	0010 3854 1010 1000 0010 1010 5438 1000
	0000 0804 7e04 0800 0000 1020 7e20 1000
	0000 4040 7e00 0000 0000 0024 6624 0000
	0000 1038 7c00 0000 0000 007c 3810 0000
	0000 0000 0000 0000 0008 0808 0800 0800
	0014 1400 0000 0000 0024 7e24 247e 2400
	0008 1e28 1c0a 3c08 0000 2204 0810 2200
	0030 4832 4c44 3a00 0008 1000 0000 0000
	0004 0808 0808 0400 0020 1010 1010 2000
	0000 2214 0814 2200 0000 0808 3e08 0800
	0000 0000 0000 0810 0000 0000 3e00 0000
	0000 0000 0000 0800 0000 0204 0810 2000
	003c 464a 5262 3c00 0018 0808 0808 1c00
	003c 4202 3c40 7e00 003c 421c 0242 3c00
	000c 1424 447e 0400 007e 407c 0242 3c00
	003c 407c 4242 3c00 007e 0204 0810 1000
	003c 423c 4242 3c00 003c 4242 3e02 3c00
	0000 0010 0000 1000 0000 1000 0010 1020
	0000 0810 2010 0800 0000 003e 003e 0000
	0000 1008 0408 1000 003c 420c 1000 1000
	003c 4232 4a42 3c00 003c 4242 7e42 4200
	007c 427c 4242 7c00 003c 4240 4042 3c00
	007c 4242 4242 7c00 007e 4078 4040 7e00
	007e 4078 4040 4000 003c 4240 4642 3c00
	0042 427e 4242 4200 001c 0808 0808 1c00
	007e 0202 0242 3c00 0042 4478 4442 4200
	0040 4040 4040 7e00 0042 665a 4242 4200
	0042 6252 4a46 4200 003c 4242 4242 3c00
	007c 4242 7c40 4000 003c 4242 4244 3a00
	007c 4242 7c44 4200 003e 403c 0242 3c00
	007e 0808 0808 1000 0042 4242 4244 3a00
	0042 4242 4224 1800 0042 4242 5a66 4200
	0042 423c 4242 4200 0042 423e 0242 3c00
	007e 020c 3040 7e00 000c 0808 0808 0c00
	0040 2010 0804 0200 0030 1010 1010 3000
	0008 1400 0000 0000 0000 0000 0000 7e00
	0008 0400 0000 0000 0000 3c02 3e42 3a00
	0040 407c 4242 7c00 0000 3c42 4042 3c00
	0002 023e 4242 3e00 0000 3c42 7e40 3e00
	0000 3e40 7840 4000 0000 3c42 3e02 3c00
	0040 405c 6242 4200 0008 0018 0808 0400
	0008 0018 0808 4830 0040 4244 7844 4200
	0010 1010 1010 0c00 0000 6c52 5252 5200
	0000 5c62 4242 4200 0000 3c42 4242 3c00
	0000 7c42 427c 4040 0000 3e42 423e 0202
	0000 5c62 4040 4000 0000 3e40 3c02 7c00
	0008 7e08 0808 1000 0000 4242 4244 3a00
	0000 4242 4224 1800 0000 5252 5252 2e00
	0000 4224 1824 4200 0000 4242 3e02 7c00
	0000 7e02 3c40 7e00 000c 0810 1008 0c00
	0008 0808 0808 0800 0030 1008 0810 3000
	0000 0032 4c00 0000 3c42 99a1 a199 423c
	003c 4240 423c 1070 0044 0044 4444 3800
	0810 3844 7840 3c00 0814 3c02 3e42 3a00
	1400 3c02 3e42 3a00 0804 3c02 3e42 3a00
	0814 2c02 3e42 3a00 0000 1c20 201c 0818
	1028 3844 7840 3c00 2800 3844 7840 3c00
	2010 3c44 7840 3c00 0028 0030 1010 0c00
	1028 0030 1010 0c00 2010 0030 1010 0c00
	423c 4242 7e42 4200 0814 3c42 7e42 4200
	0810 7e40 7c40 7e00 0000 6c12 3c50 6e00
	003e 507c 5050 5e00 1028 0038 4444 3800
	2800 3844 4444 3800 2010 3844 4444 3800
	1028 0044 4444 3800 2010 4444 4444 3800
	4400 4444 443c 0438 423c 4242 4242 3c00
	4200 4242 4242 3c00 0010 3840 4038 1000
	001c 2278 2020 7e00 0044 287c 107c 1000
	007c 4252 7c50 4c00 000c 107c 1010 6000
	0810 3c02 3e42 3a00 0810 0030 1010 0c00
	0810 3844 4444 3800 0810 4444 4444 3800
	324c 005c 6242 4200 324c 0062 524a 4600
	3848 5828 0078 0000 3048 4830 0078 0000
	0008 0008 3042 3c00 0000 0000 7c40 4000
	0000 0000 7c04 0400 4448 502c 4204 0e00
	4448 5024 541e 0400 0010 0010 1010 1000
	0000 1224 4824 1200 0000 4824 1224 4800
	8844 2211 8844 2211 aa55 aa55 aa55 aa55
	4411 4411 4411 4411 1010 1010 1010 1010
	1010 1010 f010 1010 1010 10f0 10f0 1010
	2828 2828 e828 2828 0000 0000 f828 2828
	0000 00f0 10f0 1010 2828 28e8 08e8 2828
	2828 2828 2828 2828 0000 00f8 08e8 2828
	2828 28e8 08f8 0000 2828 2828 f800 0000
	1010 10f0 10f0 0000 0000 0000 f010 1010
	1010 1010 1f00 0000 1010 1010 ff00 0000
	0000 0000 ff10 1010 1010 1010 1f10 1010
	0000 0000 ff00 0000 1010 1010 ff10 1010
	1010 101f 101f 1010 2828 2828 2f28 2828
	2828 282f 203f 0000 0000 003f 202f 2828
	2828 28ef 00ff 0000 0000 00ff 00ef 2828
	2828 282f 202f 2828 0000 00ff 00ff 0000
	2828 28ef 00ef 2828 1010 10ff 00ff 0000
	2828 2828 ff00 0000 0000 00ff 00ff 1010
	0000 0000 ff28 2828 2828 2828 3f00 0000
	1010 101f 101f 0000 0000 001f 101f 1010
	0000 0000 3f28 2828 2828 2828 ef28 2828
	1010 10ff 00ff 1010 1010 1010 f000 0000
	0000 0000 1f10 1010 ffff ffff ffff ffff
	0000 0000 ffff ffff f0f0 f0f0 f0f0 f0f0
	0f0f 0f0f 0f0f 0f0f ffff ffff 0000 0000
	0000 324a 4444 3a00 0038 445c 4262 5c40
	007e 4240 4040 4000 0000 7c28 2828 2400
	007e 2210 1022 7e00 0000 3e44 4444 3800
	0000 4444 4444 7a40 0000 7c10 1010 0800
	0010 3854 5438 1000 003c 4242 7e42 3c00
	003c 4242 4224 6600 7820 1844 4444 3800
	0000 6c92 926c 0000 0000 1854 5438 1000
	003e 407e 4040 3e00 003c 4242 4242 4200
	0000 7e00 7e00 7e00 0008 083e 0800 3e00
	0010 0804 0810 3c00 0008 1020 1008 3c00
	0000 0814 1010 1010 1010 1010 5020 0000
	0000 0800 3e00 0800 0000 324c 0032 4c00
	0018 2424 1800 0000 0000 0018 1800 0000
	0000 0000 1000 0000 000e 0808 4828 1800
	0050 6848 4800 0000 0060 1020 7000 0000
	0000 3c3c 3c3c 0000 0000 3c3c 3c3c 0000
include src/font.tal

@MEMORY-LEN $2