{"id":237,"date":"2021-04-25T11:50:04","date_gmt":"2021-04-25T10:50:04","guid":{"rendered":"http:\/\/jaerder.videmogroup.org\/blog\/?p=237"},"modified":"2021-04-25T13:18:41","modified_gmt":"2021-04-25T12:18:41","slug":"getting-started-on-sega-saturn-development-part-2","status":"publish","type":"post","link":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/2021\/04\/25\/getting-started-on-sega-saturn-development-part-2\/","title":{"rendered":"Getting started on  SEGA saturn development \u2013 Part 2"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">After the Hello World<\/h2>\n\n\n\n<p>After writing a simple hello world, 2 things are needed before proceeding : <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Get the execution time, (and in turn, frame times)  in order to properly write time based animations<\/li><li>How to get simple primitives drawn on the screen<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Getting execution time<\/h3>\n\n\n\n<p>libyaul supplies following function<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">static uint16_t cpu_frt_count_get(void);<\/pre>\n\n\n\n<p>However the return type is a problem : it quickly overflows.<br>After some digging on discord, as well as examples provided with libyaul:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include &lt;yaul.h&gt;\n\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nuint32_t elapsed_time = 0;\nstatic void _frt_ovi_handler(void);\nstatic uint16_t _frt_overflow_count = 0;\n\nvoid main(void)\n{\n    \/\/initialize dbgio\n    dbgio_dev_default_init(DBGIO_DEV_VDP2_SIMPLE);\n    dbgio_dev_font_load();\n    dbgio_dev_font_load_wait();\n    vdp2_tvmd_display_set();\n\n    cpu_frt_init(CPU_FRT_CLOCK_DIV_32);\n\n    uint32_t frame_time = 0 ;\n    uint32_t frame_start = 0 ;\n    uint32_t frame_end = 0 ;\n\n    \/\/init\n\n    cpu_frt_ovi_set(_frt_ovi_handler);\n    cpu_frt_count_set(0);\n\n    \/* Reset overflow counter after setting the FRT count to zero in case\n     * there's an FRT overflow interrupt *\/\n    \n    _frt_overflow_count = 0;\n\n    while(1)\n    {\n        elapsed_time += frame_time;\n        frame_start = ((65536 * _frt_overflow_count) + (uint32_t) cpu_frt_count_get()) \/ CPU_FRT_PAL_320_32_COUNT_1MS;\n        \n        dbgio_printf(\"\\x1b[H\\x1b[2J\");\n        dbgio_printf(\"Elapsed time :\\t %u\n        \\nFrame_time :\\t %u\n        \\nFrame Start :\\t %u\n        \\nFrame End :\\t %u\n        \\noverflow cnt :\\t %u\\n\", \n        (unsigned int) elapsed_time,\n        (unsigned int) frame_time, \n        (unsigned int) frame_start,\n        (unsigned int) frame_end,\n        (unsigned int) _frt_overflow_count);\n        dbgio_flush();\n        vdp_sync();\n\n        frame_end = ((65536 * _frt_overflow_count) + (uint32_t) cpu_frt_count_get()) \/ CPU_FRT_PAL_320_32_COUNT_1MS;\n        frame_time = (frame_end - frame_start) ; \/\/ get tick count at start \n    }\n}\n\nstatic void _frt_ovi_handler(void)\n{\n        _frt_overflow_count++;\n}\n<\/pre>\n\n\n\n<p><br>Now I&#8217;m able to measure the render time and also have the elapsed time.<br><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After the Hello World After writing a simple hello world, 2 things are needed before proceeding : Get the execution time, (and in turn, frame times) in order to properly write time based animations How to get simple primitives drawn on the screen Getting execution time libyaul supplies following function static uint16_t cpu_frt_count_get(void); However the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/2021\/04\/25\/getting-started-on-sega-saturn-development-part-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Getting started on  SEGA saturn development \u2013 Part 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,25,14],"tags":[26,27,28],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-development","category-libyaul","category-software","tag-libyaul","tag-saturn","tag-yaul"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":5,"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":243,"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/237\/revisions\/243"}],"wp:attachment":[{"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaerder.videmogroup.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}