tutorial: improve task 14 based on sejo's feedback
This commit is contained in:
parent
ad2dd26ed4
commit
3ca102f015
|
@ -81,13 +81,6 @@ fn move-cursor-to-left-margin-of-next-line screen: (addr screen) {
|
||||||
set-cursor-position screen, cursor-x, cursor-y
|
set-cursor-position screen, cursor-x, cursor-y
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw-code-point-at-cursor screen: (addr screen), c: code-point, color: int, background-color: int {
|
|
||||||
var cursor-x/eax: int <- copy 0
|
|
||||||
var cursor-y/ecx: int <- copy 0
|
|
||||||
cursor-x, cursor-y <- cursor-position screen
|
|
||||||
var dummy/eax: int <- draw-code-point screen, c, cursor-x, cursor-y, color, background-color
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw-code-point-at-cursor-over-full-screen screen: (addr screen), c: code-point, color: int, background-color: int {
|
fn draw-code-point-at-cursor-over-full-screen screen: (addr screen), c: code-point, color: int, background-color: int {
|
||||||
var cursor-x/eax: int <- copy 0
|
var cursor-x/eax: int <- copy 0
|
||||||
var cursor-y/ecx: int <- copy 0
|
var cursor-y/ecx: int <- copy 0
|
||||||
|
|
|
@ -142,7 +142,6 @@ sig move-cursor-right screen: (addr screen)
|
||||||
sig move-cursor-up screen: (addr screen)
|
sig move-cursor-up screen: (addr screen)
|
||||||
sig move-cursor-down screen: (addr screen)
|
sig move-cursor-down screen: (addr screen)
|
||||||
sig move-cursor-to-left-margin-of-next-line screen: (addr screen)
|
sig move-cursor-to-left-margin-of-next-line screen: (addr screen)
|
||||||
sig draw-code-point-at-cursor screen: (addr screen), c: code-point, color: int, background-color: int
|
|
||||||
sig draw-code-point-at-cursor-over-full-screen screen: (addr screen), c: code-point, color: int, background-color: int
|
sig draw-code-point-at-cursor-over-full-screen screen: (addr screen), c: code-point, color: int, background-color: int
|
||||||
sig draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int
|
sig draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int
|
||||||
sig draw-stream-rightward screen: (addr screen), stream: (addr stream byte), x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int
|
sig draw-stream-rightward screen: (addr screen), stream: (addr stream byte), x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int
|
||||||
|
|
|
@ -561,8 +561,14 @@ give yourself a sense of what you can do with them. Does the above program
|
||||||
make sense now? Feel free to experiment to make sense of it.
|
make sense now? Feel free to experiment to make sense of it.
|
||||||
|
|
||||||
Can you modify it to print out the line a second time, after you've typed it
|
Can you modify it to print out the line a second time, after you've typed it
|
||||||
out until the `Enter` key? Can you print a space after every character
|
out until the `Enter` key? Can you print a space after every grapheme when you
|
||||||
(grapheme) when you print the line out a second time?
|
print the line out a second time? You'll need to skim the section on
|
||||||
|
[printing to screen](https://github.com/akkartik/mu/blob/main/vocabulary.md#printing-to-screen)
|
||||||
|
from Mu's vocabulary. Pay particular attention to the difference between a
|
||||||
|
grapheme and a _code-point_. Mu programs often read characters in units of
|
||||||
|
graphemes, but they must draw in units of code-points that the font manages.
|
||||||
|
(This adds some complexity but helps combine multiple code-points into a
|
||||||
|
single glyph as needed for some languages.)
|
||||||
|
|
||||||
## Task 15: generating cool patterns
|
## Task 15: generating cool patterns
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,10 @@ how they work under the hood.
|
||||||
By default, writes to a stream abort if it's full. Reads to a stream abort
|
By default, writes to a stream abort if it's full. Reads to a stream abort
|
||||||
if it's empty.
|
if it's empty.
|
||||||
|
|
||||||
- Graphemes: 32-bit fragments of utf-8 that encode a single Unicode code-point.
|
- Graphemes: a sequence of up to 4 utf-8 bytes that encode a single Unicode
|
||||||
- Code-points: 32-bit integers representing a Unicode character.
|
code-point.
|
||||||
|
- Code-points: integer representing a Unicode character. Must be representable
|
||||||
|
in 32 bits as utf-8; largest supported value is 0x10000.
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
|
|
||||||
|
@ -114,8 +116,8 @@ signatures.mu for their full type signatures.
|
||||||
- `append-byte-hex`: writes textual representation of lowest byte in hex to
|
- `append-byte-hex`: writes textual representation of lowest byte in hex to
|
||||||
a stream of bytes. Does not write a '0x' prefix.
|
a stream of bytes. Does not write a '0x' prefix.
|
||||||
- `read-byte`: reads a single byte from a stream of bytes.
|
- `read-byte`: reads a single byte from a stream of bytes.
|
||||||
- `read-grapheme`: reads a single unicode grapheme (up to 4 bytes containing a
|
- `read-grapheme`: reads a single unicode grapheme (up to 4 bytes) from a
|
||||||
single code-point encoded in utf-8) from a stream of bytes.
|
stream of bytes.
|
||||||
|
|
||||||
#### reading/writing hex representations of integers
|
#### reading/writing hex representations of integers
|
||||||
|
|
||||||
|
@ -141,14 +143,15 @@ All text-mode screen primitives require a screen object, which can be either
|
||||||
the real screen on the computer or a fake screen for tests.
|
the real screen on the computer or a fake screen for tests.
|
||||||
|
|
||||||
The real screen on the Mu computer can currently display a subset of Unicode.
|
The real screen on the Mu computer can currently display a subset of Unicode.
|
||||||
There is only one font, and it's mostly fixed-width, with graphemes being
|
There is only one font, and it's mostly fixed-width, with individual glyphs
|
||||||
either 8 or 16 pixels wide.
|
for code-points being either 8 or 16 pixels wide.
|
||||||
|
|
||||||
- `draw-grapheme`: draws a single grapheme at a given coordinate, with given
|
- `draw-code-point`: draws a single code-point at a given coordinate, with
|
||||||
foreground and background colors.
|
given foreground and background colors. Returns the number of 8-pixel wide
|
||||||
- `render-grapheme`: like `draw-grapheme` and can also handle newlines
|
grid locations used (either 1 or 2).
|
||||||
assuming text is printed left-to-right, top-to-bottom.
|
- `render-code-point`: like `draw-code-point`, but handles newlines and
|
||||||
- `draw-code-point`
|
updates cursor position. Assumes text is printed left-to-right,
|
||||||
|
top-to-bottom.
|
||||||
- `clear-screen`
|
- `clear-screen`
|
||||||
|
|
||||||
- `draw-text-rightward`: draws a single line of text, stopping when it reaches
|
- `draw-text-rightward`: draws a single line of text, stopping when it reaches
|
||||||
|
@ -176,12 +179,13 @@ Similar primitives for writing text top-to-bottom, left-to-right.
|
||||||
- `draw-int32-decimal-wrapping-down-then-right`
|
- `draw-int32-decimal-wrapping-down-then-right`
|
||||||
- `draw-int32-decimal-wrapping-down-then-right-over-full-screen`
|
- `draw-int32-decimal-wrapping-down-then-right-over-full-screen`
|
||||||
|
|
||||||
Screens remember the current cursor position.
|
Screens remember the current cursor position. The following primitives
|
||||||
|
automatically read and update the cursor position in various ways.
|
||||||
|
|
||||||
- `cursor-position`
|
- `cursor-position`
|
||||||
- `set-cursor-position`
|
- `set-cursor-position`
|
||||||
- `draw-grapheme-at-cursor`
|
- `draw-code-point-at-cursor-over-full-screen`: `render-code-point` at
|
||||||
- `draw-code-point-at-cursor`
|
cursor position.
|
||||||
- `draw-cursor`: highlights the current position of the cursor. Programs must
|
- `draw-cursor`: highlights the current position of the cursor. Programs must
|
||||||
pass in the grapheme to draw at the cursor position, and are responsible for
|
pass in the grapheme to draw at the cursor position, and are responsible for
|
||||||
clearing the highlight when the cursor moves.
|
clearing the highlight when the cursor moves.
|
||||||
|
@ -191,16 +195,21 @@ Screens remember the current cursor position.
|
||||||
- `move-cursor-to-left-margin-of-next-line`
|
- `move-cursor-to-left-margin-of-next-line`
|
||||||
- `move-cursor-rightward-and-downward`: move cursor one grapheme to the right
|
- `move-cursor-rightward-and-downward`: move cursor one grapheme to the right
|
||||||
|
|
||||||
- `draw-text-rightward-from-cursor`
|
- `draw-text-rightward-from-cursor`: truncate at some right margin.
|
||||||
- `draw-text-wrapping-right-then-down-from-cursor`
|
- `draw-text-rightward-from-cursor-over-full-screen`: truncate at right edge
|
||||||
- `draw-text-wrapping-right-then-down-from-cursor-over-full-screen`
|
of screen.
|
||||||
|
- `draw-text-wrapping-right-then-down-from-cursor`: wrap at some right margin.
|
||||||
|
- `draw-text-wrapping-right-then-down-from-cursor-over-full-screen`: wrap at
|
||||||
|
right edge of screen.
|
||||||
- `draw-int32-hex-wrapping-right-then-down-from-cursor`
|
- `draw-int32-hex-wrapping-right-then-down-from-cursor`
|
||||||
- `draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen`
|
- `draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen`
|
||||||
- `draw-int32-decimal-wrapping-right-then-down-from-cursor`
|
- `draw-int32-decimal-wrapping-right-then-down-from-cursor`
|
||||||
- `draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen`
|
- `draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen`
|
||||||
|
|
||||||
- `draw-text-wrapping-down-then-right-from-cursor`
|
- `draw-text-wrapping-down-then-right-from-cursor`: wrap at some bottom
|
||||||
- `draw-text-wrapping-down-then-right-from-cursor-over-full-screen`
|
margin.
|
||||||
|
- `draw-text-wrapping-down-then-right-from-cursor-over-full-screen`: wrap at
|
||||||
|
bottom edge of screen.
|
||||||
|
|
||||||
Assertions for tests:
|
Assertions for tests:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue