const std = @import("std"); // ============================================================================ // Types & Enums // ============================================================================ /// RGB565 Color Format (16-bit) pub const Color = u16; /// Transformation flags for hardware-accelerated sprite operations. pub const Transform = packed struct(u32) { flip_h: bool = false, flip_v: bool = false, rot_90: bool = false, rot_180: bool = false, rot_270: bool = false, _padding: u27 = 0, }; // Common Transform Constants pub const TRANSFORM_NONE = Transform{}; pub const TRANSFORM_FLIP_H = Transform{ .flip_h = true }; pub const TRANSFORM_FLIP_V = Transform{ .flip_v = true }; // ============================================================================ // Low-Level C-Imports (Raw WAMR Native Symbol Bindings) // ============================================================================ pub extern "nova64" fn nova64_yield(timeout_ms: u32) void; pub extern "nova64" fn nova64_log(message: [*:0]const u8) void; // Framebuffer Controls pub extern "nova64" fn nova64_ppu_clear(color: u32) void; pub extern "nova64" fn nova64_framebuffer_swap() void; // PPU Drawing Primitives pub extern "nova64" fn nova64_ppu_fill_rect(x: i32, y: i32, w: i32, h: i32, color: u32) void; pub extern "nova64" fn nova64_ppu_blit( src_ptr: [*]const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, ) void; pub extern "nova64" fn nova64_ppu_blit_colorkey( src_ptr: [*]const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, key_color: u32, ) void; pub extern "nova64" fn nova64_ppu_blend( src_ptr: [*]const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, global_alpha: u32, ) void; pub extern "nova64" fn nova64_ppu_blit_transform( src_ptr: [*]const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, transform: Transform, ) void; pub extern "nova64" fn nova64_ppu_blit_scale( src_ptr: [*]const Color, src_stride: u32, src_w: i32, src_h: i32, dst_x: i32, dst_y: i32, dst_w: i32, dst_h: i32, ) void; // Hardware Sync pub extern "nova64" fn nova64_ppu_wait_idle() void; pub extern "nova64" fn nova64_ppu_is_busy() u32; // ============================================================================ // High-Level Idiomatic Zig API // ============================================================================ pub fn log(message: [*:0]const u8) void { nova64_log(message); } pub fn sleep(timeout_ms: u32) void { nova64_yield(timeout_ms); } pub fn yield() void { nova64_yield(0); } /// Swaps the front and back buffer to display the rendered frame. pub fn ppuSwapBuffers() void { nova64_framebuffer_swap(); } /// Clears the back buffer with a solid RGB565 color. pub fn ppuClear(color: Color) void { nova64_ppu_clear(@as(u32, color)); } /// Fills a rectangle on the back buffer with a solid RGB565 color. pub fn ppuFillRect(x: i32, y: i32, w: i32, h: i32, color: Color) void { nova64_ppu_fill_rect(x, y, w, h, @as(u32, color)); } /// Opaque block image transfer from a pixel buffer to the back buffer. pub fn ppuBlit( src: []const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, ) void { nova64_ppu_blit(src.ptr, src_stride, src_x, src_y, dst_x, dst_y, w, h); } /// Transparent sprite blitting using color keying. pub fn ppuBlitColorKey( src: []const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, key_color: Color, ) void { nova64_ppu_blit_colorkey(src.ptr, src_stride, src_x, src_y, dst_x, dst_y, w, h, @as(u32, key_color)); } /// Alpha-blended sprite composition (alpha: 0 = transparent, 255 = opaque). pub fn ppuBlend( src: []const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, alpha: u8, ) void { nova64_ppu_blend(src.ptr, src_stride, src_x, src_y, dst_x, dst_y, w, h, @as(u32, alpha)); } /// Transformed image transfer (rotation & flipping). pub fn ppuBlitTransform( src: []const Color, src_stride: u32, src_x: i32, src_y: i32, dst_x: i32, dst_y: i32, w: i32, h: i32, transform: Transform, ) void { nova64_ppu_blit_transform(src.ptr, src_stride, src_x, src_y, dst_x, dst_y, w, h, transform); } /// Hardware-accelerated image scaling/resizing. pub fn ppuBlitScale( src: []const Color, src_stride: u32, src_w: i32, src_h: i32, dst_x: i32, dst_y: i32, dst_w: i32, dst_h: i32, ) void { nova64_ppu_blit_scale(src.ptr, src_stride, src_w, src_h, dst_x, dst_y, dst_w, dst_h); } /// Blocks execution until the PPU/DMA2D hardware engine finishes all operations. pub fn ppuWaitIdle() void { nova64_ppu_wait_idle(); } /// Checks if the PPU hardware engine is currently busy. pub fn ppuIsBusy() bool { return nova64_ppu_is_busy() != 0; }