diff --git a/src/main.cc b/src/main.cc index b8affa7..5cfd214 100644 --- a/src/main.cc +++ b/src/main.cc @@ -111,9 +111,44 @@ static int text_size(char const *str, int length) #include #include #include +#include +#include #include #define vram gint_vram +bool videocapture = false; + +static void hook_prefrag(int id, void *fragment, int size) +{ + if(!videocapture) + return; + + if(!usb_is_open()) { + static usb_interface_t const *intf[] = { &usb_ff_bulk, NULL }; + usb_open(intf, GINT_CALL_NULL); + usb_open_wait(); + } + int pipe = usb_ff_bulk_output(); + + if(id == 0) { + usb_fxlink_header_t h; + usb_fxlink_image_t sh; + int size = azrp_width * azrp_height * 2; + + usb_fxlink_fill_header(&h, "fxlink", "video", size + sizeof sh); + sh.width = htole32(azrp_width); + sh.height = htole32(azrp_height); + sh.pixel_format = htole32(USB_FXLINK_IMAGE_RGB565); + + usb_write_sync(pipe, &h, sizeof h, false); + usb_write_sync(pipe, &sh, sizeof sh, false); + } + + usb_write_sync(pipe, fragment, size, false); + if(id == azrp_frag_count - 1) + usb_commit_sync(pipe); +} + static int platform_update(struct input *input) { key_event_t e; @@ -132,6 +167,8 @@ static int platform_update(struct input *input) input->roll_left = true; if(e.key == KEY_F2) input->roll_right = true; + if(e.key == KEY_F6 && keydown(KEY_VARS)) + videocapture = !videocapture; if(e.key == KEY_EXE && keydown(KEY_VARS)) input->RESET_LEVEL = true; if(e.key == KEY_MINUS && keydown(KEY_VARS)) @@ -171,6 +208,7 @@ static void init(void) cd_vfx_configure(); azrp_shader_clear_configure(); azrp_shader_image_p8_configure(); + azrp_hook_set_prefrag(hook_prefrag); } static void quit(void)