nx_browser_demo_hello.nx source
↩ module page · 57 lines · 1966 B
1// nx_browser_demo_hello.nx -- visible demo program. Paints
2// "HELLO WORLD" into a 96x16 framebuffer using the expanded 5x7
3// font (now supports H E L O W R D plus the digits/period/space
4// from the prior subset). Dumps to stdout as ASCII art.
5//
6// Composes the same Phase 4 + 5 stack as nx_browser_demo_42 but
7// renders English text instead of digits, proving the font
8// expansion works end-to-end.
9
10import "nx_syscalls.nx"
11import "nx_css_color_decode.nx"
12import "nx_paint_solid_rect.nx"
13import "nx_paint_text.nx"
14import "nx_paint_fb_ascii_dump.nx"
15const K_MAGIC_2048: i64 = 2048
16
17func _put_byte(buf: *u8, i: i64, v: i64) -> i64 {
18 buf[i] = v as u8
19 return 0
20}
21
22func main() -> i64 {
23 let w: i64 = 96
24 let h: i64 = 10
25 let pixels: *u8 = (sys_mmap((w * h * 4) as nx_size)) as *u8
26 let fb: *Framebuffer = (sys_mmap(NX_FRAMEBUFFER_BYTES as nx_size)) as *Framebuffer
27 nx_framebuffer_init(fb, pixels, w, h)
28 nx_framebuffer_clear(fb)
29
30 let white: *CssColor = (sys_mmap(NX_CSS_COLOR_BYTES as nx_size)) as *CssColor
31 white.r = 255
32 white.g = 255
33 white.b = 255
34 white.a = 255
35
36 // "HELLO WORLD" (11 bytes)
37 let text: *u8 = (sys_mmap(16)) as *u8
38 _put_byte(text, 0, 72) // 'H'
39 _put_byte(text, 1, 69) // 'E'
40 _put_byte(text, 2, 76) // 'L'
41 _put_byte(text, 3, 76) // 'L'
42 _put_byte(text, 4, 79) // 'O'
43 _put_byte(text, 5, 32) // ' '
44 _put_byte(text, 6, 87) // 'W'
45 _put_byte(text, 7, 79) // 'O'
46 _put_byte(text, 8, 82) // 'R'
47 _put_byte(text, 9, 76) // 'L'
48 _put_byte(text, 10, 68) // 'D'
49
50 nx_paint_text(fb, 2, 2, text, 11, white)
51
52 let out_buf: *u8 = (sys_mmap(K_MAGIC_2048)) as *u8
53 let n: i64 = nx_paint_fb_ascii_dump(fb, out_buf, K_MAGIC_2048)
54 if n < 0 { return 1 }
55 sys_write(1, out_buf, n)
56 return 0
57}