From 7a538295cd195f1baf40f4f5a2f736f13be8b94b Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Fri, 1 Aug 2025 01:23:26 -0500 Subject: [PATCH] speedrun edition --- src/demo/lizard/main.cpp | 35 ++++++++++++++++++++++++++++++++++- src/demo/lizard/main.hpp | 3 +++ src/platform/font.cpp | 4 ++-- src/platform/graphics.cpp | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/demo/lizard/main.cpp b/src/demo/lizard/main.cpp index 592c88d..ff8a6ca 100644 --- a/src/demo/lizard/main.cpp +++ b/src/demo/lizard/main.cpp @@ -10,6 +10,9 @@ #include "texture/igh25_box_top_32.data.h" +#include "sh7091/sh7091.hpp" +#include "sh7091/sh7091_bits.hpp" + #include "xm_player/playlist.hpp" #include "assert.h" @@ -63,7 +66,10 @@ namespace demo { mat4x4 lizard::init() { + button_press = false; + y_press_count = 0; platform_touch_count = 0; + total_tick = 0; vx = -pi / 3.5; vy = -pi / 8; @@ -98,6 +104,10 @@ namespace demo { void lizard::update() { + if (end_platform->touched) { + sh7091.TMU.TSTR &= (~tmu::tstr::str1::counter_start) & 0xff; // stop TCNT1 + } + lizard_rotation *= 0.8; lizard_turning_frame += lizard_rotation * 5; @@ -149,6 +159,7 @@ namespace demo { void lizard::y() { + y_press_count += 1; lizard_velocity = {0, 0, 0}; if (last_platform1 == nullptr) { lizard_position = {2.5, 1, 2.5}; @@ -164,6 +175,18 @@ namespace demo { void lizard::a() { + if (!button_press) { + button_press = true; + + sh7091.TMU.TSTR &= (~tmu::tstr::str1::counter_start) & 0xff; // stop TCNT1 + sh7091.TMU.TOCR = tmu::tocr::tcoe::tclk_is_external_clock_or_input_capture; + sh7091.TMU.TCR1 = tmu::tcr1::tpsc::p_phi_1024; // 1024 / 50MHz = 20.48 μs + sh7091.TMU.TCOR1 = 0xffff'ffff; + sh7091.TMU.TCNT1 = 0xffff'ffff; + sh7091.TMU.TSTR |= tmu::tstr::str1::counter_start; + + total_tick = 0xffff'ffff; + } //lizard_velocity.y -= 0.01; if (collided) { lizard_velocity.y = 30; @@ -280,7 +303,17 @@ namespace demo { font::ter_u12n.draw_string(writer, status_p, "score:", 0xffffffff); //font::ter_u12n.draw_float(writer, status_p, (float)last_drawn_frame, 0xffffffff, 10); status_p.x += font::ter_u12n.hori_advance * 7; - font::ter_u12n.draw_int(writer, status_p, (float)platform_touch_count, 0xffffffff, 4); + font::ter_u12n.draw_int(writer, status_p, platform_touch_count, 0xffffffff, 4); + + vec3 status_q = vec3(framebuffer::framebuffer.px_width - font::ter_u12n.hori_advance * 15, framebuffer::framebuffer.px_height - 24, 10); + font::ter_u12n.draw_string(writer, status_q, "y presses:", 0xffffffff); + status_q.x += font::ter_u12n.hori_advance * 11; + font::ter_u12n.draw_int(writer, status_q, y_press_count, 0xffffffff, 0); + + vec3 status_r = vec3(framebuffer::framebuffer.px_width - font::ter_u12n.hori_advance * 15, framebuffer::framebuffer.px_height - (24 + font::ter_u12n.height), 10); + font::ter_u12n.draw_string(writer, status_r, "time:", 0xffffffff); + float time = (float)(0xffffffff - sh7091.TMU.TCNT1) * (0.020480f / 1000.f); + font::ter_u12n.draw_float(writer, status_r, time, 0xffffffff, 12); const int height_2 = (font::ter_u32n.height * (emulator_speech_lines + 2)) >> 1; const int y = framebuffer_height_2 - height_2; diff --git a/src/demo/lizard/main.hpp b/src/demo/lizard/main.hpp index 343e6c3..6f30bef 100644 --- a/src/demo/lizard/main.hpp +++ b/src/demo/lizard/main.hpp @@ -17,7 +17,10 @@ namespace demo { float lizard_walking_frame; float lizard_turning_frame; int platform_touch_count; + int y_press_count; int end_platform_tick; + int total_tick; + bool button_press; int last_cover_texture_offset; float cover_ix_transition; diff --git a/src/platform/font.cpp b/src/platform/font.cpp index 4e8955d..442c78d 100644 --- a/src/platform/font.cpp +++ b/src/platform/font.cpp @@ -83,10 +83,10 @@ namespace font { int32_t whole = num; offset += unparse_base10_unsigned(&s[offset], whole, 0, 0); s[offset++] = '.'; - int32_t fraction = (int32_t)((num - (float)whole) * 1000000000.0); + int32_t fraction = (int32_t)((num - (float)whole) * 10.0); if (fraction < 0) fraction = -fraction; - offset += unparse_base10_unsigned(&s[offset], fraction, 9, '0'); + offset += unparse_base10_unsigned(&s[offset], fraction, 1, '0'); return offset; } diff --git a/src/platform/graphics.cpp b/src/platform/graphics.cpp index b2ae27a..3018ff1 100644 --- a/src/platform/graphics.cpp +++ b/src/platform/graphics.cpp @@ -224,7 +224,7 @@ namespace graphics { if (last[port_ix].a != a && a) current_scene->a(); if (b) current_scene->b(); if (last[port_ix].x != x && x) current_scene->x(); - if (y) current_scene->y(); + if (last[port_ix].y != y && y) current_scene->y(); if (ra) current_scene->ra(); if (la) current_scene->la();