code wiki / (root) / nx_fb_1bpp_test.nx

nx_fb_1bpp_test.nx source

↩ module page · 68 lines · 2380 B

1// nx_fb_1bpp_test.nx -- smoke for nx_fb_1bpp. 2 3import "nx_syscalls.nx" 4import "nx_fb_1bpp.nx" 5 6func main() -> i64 { 7 // 16x8 = 16 bytes (1 page) 8 let f: *NxFb1bpp = nx_fb_1bpp_new(16, 8) 9 if (f as i64) == 0 { return 1 } 10 if f.width != 16 { return 2 } 11 if f.height != 8 { return 3 } 12 if f.byte_count != 16 { return 4 } 13 14 // Bad dim refused (height not multiple of 8) 15 let bad: *NxFb1bpp = nx_fb_1bpp_new(16, 5) 16 if (bad as i64) != 0 { return 5 } 17 let bad2: *NxFb1bpp = nx_fb_1bpp_new(0, 8) 18 if (bad2 as i64) != 0 { return 6 } 19 20 // Clear -> 0 pixels on 21 nx_fb_1bpp_clear(f) 22 if nx_fb_1bpp_count_on(f) != 0 { return 7 } 23 24 // Fill -> 16*8 = 128 pixels on 25 nx_fb_1bpp_fill(f) 26 if nx_fb_1bpp_count_on(f) != 128 { return 8 } 27 28 // Set / get single pixel 29 nx_fb_1bpp_clear(f) 30 nx_fb_1bpp_set_pixel(f, 5, 3, 1) 31 if nx_fb_1bpp_get_pixel(f, 5, 3) != 1 { return 9 } 32 if nx_fb_1bpp_get_pixel(f, 5, 4) != 0 { return 10 } 33 if nx_fb_1bpp_count_on(f) != 1 { return 11 } 34 35 // Turn off 36 nx_fb_1bpp_set_pixel(f, 5, 3, 0) 37 if nx_fb_1bpp_get_pixel(f, 5, 3) != 0 { return 12 } 38 39 // Out-of-bounds set returns BAD_COORD; doesn't crash 40 if nx_fb_1bpp_set_pixel(f, 99, 99, 1) != NX_FB_ERR_BAD_COORD { return 13 } 41 if nx_fb_1bpp_get_pixel(f, 99, 99) != 0 { return 14 } 42 43 // Fill rect 4x4 -> 16 pixels 44 nx_fb_1bpp_clear(f) 45 nx_fb_1bpp_fill_rect(f, 2, 0, 4, 4, 1) 46 if nx_fb_1bpp_count_on(f) != 16 { return 15 } 47 if nx_fb_1bpp_get_pixel(f, 2, 0) != 1 { return 16 } 48 if nx_fb_1bpp_get_pixel(f, 5, 3) != 1 { return 17 } 49 if nx_fb_1bpp_get_pixel(f, 6, 3) != 0 { return 18 } 50 if nx_fb_1bpp_get_pixel(f, 2, 4) != 0 { return 19 } 51 52 // Dither brightness levels in a 4x4 region (subset of fb) 53 nx_fb_1bpp_clear(f) 54 nx_fb_1bpp_dither_4(f, 0, 0, 4, 4, 0) // all off 55 if nx_fb_1bpp_count_on(f) != 0 { return 20 } 56 nx_fb_1bpp_dither_4(f, 0, 0, 4, 4, 3) // all on 57 if nx_fb_1bpp_count_on(f) != 16 { return 21 } 58 nx_fb_1bpp_clear(f) 59 nx_fb_1bpp_dither_4(f, 0, 0, 4, 4, 2) // half on (diagonal) 60 let half_on: nx_int = nx_fb_1bpp_count_on(f) 61 if half_on != 8 { return 22 } 62 nx_fb_1bpp_clear(f) 63 nx_fb_1bpp_dither_4(f, 0, 0, 4, 4, 1) // quarter on 64 let quarter_on: nx_int = nx_fb_1bpp_count_on(f) 65 if quarter_on != 4 { return 23 } 66 67 return 0 68}