Mercurial > repos > blastem
comparison genesis.c @ 2429:da3dc881d3f0
Initial implementation of storbook artwork display
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 04 Feb 2024 20:11:39 -0800 |
parents | 65c2e4d990cc |
children | 61c0bfe10887 |
comparison
equal
deleted
inserted
replaced
2428:65c2e4d990cc | 2429:da3dc881d3f0 |
---|---|
1391 case 5: | 1391 case 5: |
1392 return gen->pico_pen_y; | 1392 return gen->pico_pen_y; |
1393 case 6: | 1393 case 6: |
1394 return gen->pico_page; | 1394 return gen->pico_page; |
1395 case 8: | 1395 case 8: |
1396 printf("uPD7759 data read @ %u\n", m68k->current_cycle); | 1396 //printf("uPD7759 data read @ %u\n", m68k->current_cycle); |
1397 return 0xFF; | 1397 return 0xFF; |
1398 case 9: | 1398 case 9: |
1399 printf("uPD7759 contro/status read @ %u\n", m68k->current_cycle); | 1399 //printf("uPD7759 contro/status read @ %u\n", m68k->current_cycle); |
1400 return 0; | 1400 return 0; |
1401 default: | 1401 default: |
1402 printf("Unknown Pico IO read %X @ %u\n", location, m68k->current_cycle); | 1402 printf("Unknown Pico IO read %X @ %u\n", location, m68k->current_cycle); |
1403 return 0xFF; | 1403 return 0xFF; |
1404 } | 1404 } |
1991 if (gen->mapper_type == MAPPER_JCART) { | 1991 if (gen->mapper_type == MAPPER_JCART) { |
1992 jcart_gamepad_up(gen, gamepad_num, button); | 1992 jcart_gamepad_up(gen, gamepad_num, button); |
1993 } | 1993 } |
1994 } | 1994 } |
1995 | 1995 |
1996 static void pico_update_page(genesis_context *gen) | |
1997 { | |
1998 #ifndef IS_LIB | |
1999 uint8_t page_num = 0; | |
2000 uint8_t page = gen->pico_page; | |
2001 while (page) | |
2002 { | |
2003 page_num++; | |
2004 page >>= 1; | |
2005 } | |
2006 render_clear_window(gen->pico_story_window, 236, 205, 27); | |
2007 int x, width; | |
2008 if (page_num) { | |
2009 x = 0; | |
2010 width = 640; | |
2011 } else { | |
2012 render_fill_rect(gen->pico_story_window, 50, 29, 96, 0, 0, 320, 320); | |
2013 x = 320; | |
2014 width = 320; | |
2015 } | |
2016 if (gen->pico_story_pages[page_num] == 0xFF && page_num == 6 && gen->pico_story_pages[page_num - 1]) { | |
2017 //repeat last page if storybook doesn't have a full 6 pages | |
2018 //hack to deal with storybooks that skip page 5 | |
2019 page_num--; | |
2020 } | |
2021 if (gen->pico_story_pages[page_num] != 0xFF) { | |
2022 render_draw_image(gen->pico_story_window, gen->pico_story_pages[page_num], x, 0, width, 320); | |
2023 } else { | |
2024 uint8_t grey = page * (255 / 5); | |
2025 render_fill_rect(gen->pico_story_window, grey, grey, grey, x, 0, width, 320); | |
2026 } | |
2027 render_window_refresh(gen->pico_story_window); | |
2028 #endif | |
2029 } | |
2030 | |
1996 static void gamepad_down_pico(system_header *system, uint8_t gamepad_num, uint8_t button) | 2031 static void gamepad_down_pico(system_header *system, uint8_t gamepad_num, uint8_t button) |
1997 { | 2032 { |
1998 genesis_context *gen = (genesis_context *)system; | 2033 genesis_context *gen = (genesis_context *)system; |
1999 if (gamepad_num != 1) { | 2034 if (gamepad_num != 1) { |
2000 return; | 2035 return; |
2002 //TODO: storyware display | 2037 //TODO: storyware display |
2003 if (button == BUTTON_C) { | 2038 if (button == BUTTON_C) { |
2004 gen->pico_page <<= 1; | 2039 gen->pico_page <<= 1; |
2005 gen->pico_page |= 1; | 2040 gen->pico_page |= 1; |
2006 gen->pico_page &= 0x3F; | 2041 gen->pico_page &= 0x3F; |
2042 pico_update_page(gen); | |
2007 } else if (button == BUTTON_Z) { | 2043 } else if (button == BUTTON_Z) { |
2008 gen->pico_page >>= 1; | 2044 gen->pico_page >>= 1; |
2045 pico_update_page(gen); | |
2009 } else if (button < BUTTON_B) { | 2046 } else if (button < BUTTON_B) { |
2010 gen->pico_button_state &= ~(1 << (button - 1)); | 2047 gen->pico_button_state &= ~(1 << (button - 1)); |
2011 } | 2048 } |
2012 } | 2049 } |
2013 | 2050 |
2064 } | 2101 } |
2065 | 2102 |
2066 static void mouse_motion_absolute_pico(system_header *system, uint8_t mouse_num, uint16_t x, uint16_t y) | 2103 static void mouse_motion_absolute_pico(system_header *system, uint8_t mouse_num, uint16_t x, uint16_t y) |
2067 { | 2104 { |
2068 genesis_context *gen = (genesis_context *)system; | 2105 genesis_context *gen = (genesis_context *)system; |
2069 //TODO: scale properly | 2106 //FIXME: coordinate translation feels a little off for storybook area |
2070 //TODO: limit to mouse motion on emulated storyware/drawing area | 2107 //TODO: limit to mouse motion on emulated storyware/drawing area |
2071 gen->pico_pen_x = (x >> 1) + 0x3C; | 2108 if (y < 24) { |
2072 gen->pico_pen_y = y + 0x1FC; | 2109 y = 24; |
2110 } | |
2111 gen->pico_pen_x = x * (0x17D - 0x3C) / 640 + 0x3C; | |
2112 if (y < 320) { | |
2113 gen->pico_pen_y = (y-24) * (0x3F4-0x2F8) / (320-24) + 0x2F8; | |
2114 } else { | |
2115 gen->pico_pen_y = (y - 320) * (0x2f8-0x1FC) / 320 + 0x1FC; | |
2116 } | |
2073 } | 2117 } |
2074 | 2118 |
2075 static void mouse_motion_relative_pico(system_header *system, uint8_t mouse_num, int32_t x, int32_t y) | 2119 static void mouse_motion_relative_pico(system_header *system, uint8_t mouse_num, int32_t x, int32_t y) |
2076 { | 2120 { |
2077 genesis_context *gen = (genesis_context *)system; | 2121 genesis_context *gen = (genesis_context *)system; |
2957 } | 3001 } |
2958 gen->reset_cycle = CYCLE_NEVER; | 3002 gen->reset_cycle = CYCLE_NEVER; |
2959 | 3003 |
2960 set_audio_config(gen); | 3004 set_audio_config(gen); |
2961 bindings_set_mouse_mode(MOUSE_ABSOLUTE); | 3005 bindings_set_mouse_mode(MOUSE_ABSOLUTE); |
3006 memset(gen->pico_story_pages, 0xFF, sizeof(gen->pico_story_pages)); | |
3007 #ifndef IS_LIB | |
3008 gen->pico_story_window = render_create_window("Pico Storybook & Pad", 640, 640, NULL); | |
3009 const char *parts[] = {current_media()->dir, PATH_SEP, current_media()->name, ".manifest"}; | |
3010 char *manifest_path = alloc_concat_m(sizeof(parts)/sizeof(*parts), parts); | |
3011 tern_node *manifest = parse_config_file(manifest_path); | |
3012 if (!manifest) { | |
3013 printf("Manifest not found at %s\n", manifest_path); | |
3014 } | |
3015 if (manifest) { | |
3016 tern_node *pages = tern_find_node(manifest, "pages"); | |
3017 if (pages) { | |
3018 char numkey[13]; | |
3019 for (int i = 0; i < 7; i++) { | |
3020 sprintf(numkey, "%d", i); | |
3021 char *page_path = tern_find_ptr(pages, numkey); | |
3022 if (page_path) { | |
3023 printf("page %d: %s\n", i, page_path); | |
3024 } else { | |
3025 continue; | |
3026 } | |
3027 char *img_path; | |
3028 if (is_absolute_path(current_media()->dir)) { | |
3029 const char *img_parts[] = {current_media()->dir, PATH_SEP, page_path}; | |
3030 img_path = alloc_concat_m(sizeof(img_parts)/sizeof(*img_parts), img_parts); | |
3031 } else { | |
3032 const char *img_parts[] = {path_current_dir(), PATH_SEP, current_media()->dir, PATH_SEP, page_path}; | |
3033 img_path = alloc_concat_m(sizeof(img_parts)/sizeof(*img_parts), img_parts); | |
3034 } | |
3035 gen->pico_story_pages[i] = render_static_image(gen->pico_story_window, img_path); | |
3036 if (gen->pico_story_pages[i] == 0xFF) { | |
3037 printf("Failed to load page %d from %s\n", i, img_path); | |
3038 } | |
3039 free(img_path); | |
3040 } | |
3041 } else { | |
3042 printf("No pages key in %s\n", manifest_path); | |
3043 } | |
3044 tern_free(manifest); | |
3045 } | |
3046 free(manifest_path); | |
3047 pico_update_page(gen); | |
3048 #endif | |
2962 return gen; | 3049 return gen; |
2963 } | 3050 } |