pr 38
This commit is contained in:
@@ -1,92 +1,3 @@
|
||||
## PR-02 — PBS Prelude: Add SAFE builtins for Color / ButtonState / Pad / Touch (bounded)
|
||||
|
||||
### Goal
|
||||
|
||||
Expose hardware types to PBS scripts as **value structs** using `bounded` (no `u16`).
|
||||
|
||||
### Required PBS definitions (in prelude / hardware module)
|
||||
|
||||
> Put these in the standard library surface that PBS sees without user creating them.
|
||||
|
||||
```pbs
|
||||
pub declare struct Color(value: bounded)
|
||||
[
|
||||
(r: int, g: int, b: int): (0b) as rgb
|
||||
{
|
||||
...
|
||||
}
|
||||
]
|
||||
[[
|
||||
BLACK: (...) {}
|
||||
WHITE: (...) {}
|
||||
RED: (...) {}
|
||||
GREEN: (...) {}
|
||||
BLUE: (...) {}
|
||||
MAGENTA: (...) {}
|
||||
TRANSPARENT: (...) {}
|
||||
COLOR_KEY: (...) {}
|
||||
]]
|
||||
{
|
||||
pub fn raw(self: Color): bounded;
|
||||
}
|
||||
|
||||
pub declare struct ButtonState(
|
||||
pressed: bool,
|
||||
released: bool,
|
||||
down: bool,
|
||||
hold_frames: bounded
|
||||
)
|
||||
|
||||
pub declare struct Pad(
|
||||
up: ButtonState,
|
||||
down: ButtonState,
|
||||
left: ButtonState,
|
||||
right: ButtonState,
|
||||
a: ButtonState,
|
||||
b: ButtonState,
|
||||
x: ButtonState,
|
||||
y: ButtonState,
|
||||
l: ButtonState,
|
||||
r: ButtonState,
|
||||
start: ButtonState,
|
||||
select: ButtonState
|
||||
)
|
||||
{
|
||||
pub fn any(self: Pad): bool;
|
||||
}
|
||||
|
||||
pub declare struct Touch(
|
||||
f: ButtonState,
|
||||
x: int,
|
||||
y: int
|
||||
)
|
||||
```
|
||||
|
||||
### Semantics / constraints
|
||||
|
||||
* `Color.value` stores the hardware RGB565 *raw* as `bounded`.
|
||||
* `hold_frames` is `bounded`.
|
||||
* `x/y` remain `int`.
|
||||
|
||||
### Implementation notes (binding)
|
||||
|
||||
* `Color.rgb(r,g,b)` must clamp inputs to 0..255 and then pack to RGB565.
|
||||
* `Color.raw()` returns the internal bounded.
|
||||
* `Pad.any()` must be a **pure SAFE** function compiled normally (no hostcall).
|
||||
|
||||
### Tests (mandatory)
|
||||
|
||||
* FE/typecheck: `Color.WHITE` is a `Color`.
|
||||
* FE/typecheck: `Gfx.clear(Color.WHITE)` typechecks.
|
||||
* FE/typecheck: `let p: Pad = Input.pad(); if p.any() { }` typechecks.
|
||||
|
||||
### Non-goals
|
||||
|
||||
* No heap types
|
||||
* No gates
|
||||
|
||||
---
|
||||
|
||||
## PR-03 — Lowering: Host Contracts for Gfx/Input using deterministic syscalls
|
||||
|
||||
### Goal
|
||||
|
||||
Reference in New Issue
Block a user