diff --git a/pcm/start3.adpcm b/pcm/start3.adpcm new file mode 100644 index 0000000..6dd5c99 Binary files /dev/null and b/pcm/start3.adpcm differ diff --git a/pcm/start3.adpcm.h b/pcm/start3.adpcm.h new file mode 100644 index 0000000..32e0d96 --- /dev/null +++ b/pcm/start3.adpcm.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_pcm_start3_adpcm_start __asm("_binary_pcm_start3_adpcm_start"); +extern uint32_t _binary_pcm_start3_adpcm_end __asm("_binary_pcm_start3_adpcm_end"); +extern uint32_t _binary_pcm_start3_adpcm_size __asm("_binary_pcm_start3_adpcm_size"); + +#ifdef __cplusplus +} +#endif diff --git a/pcm/start3.pcm b/pcm/start3.pcm new file mode 100644 index 0000000..6d06bc7 Binary files /dev/null and b/pcm/start3.pcm differ diff --git a/pcm/start3.wav b/pcm/start3.wav new file mode 100644 index 0000000..5e93a59 Binary files /dev/null and b/pcm/start3.wav differ diff --git a/src/cursor.cpp b/src/cursor.cpp index 3b56d99..f2f00c0 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -45,6 +45,7 @@ namespace cursor { float dy = static_cast(data.analog_coordinate_axis[3] - 0x80) * 0.015; state[port_ix].x += dx; state[port_ix].y += dy; + state[port_ix].a = ft0::data_transfer::digital_button::a(data.digital_button) == 0; state[port_ix].b = ft0::data_transfer::digital_button::b(data.digital_button) == 0; diff --git a/src/graphics.cpp b/src/graphics.cpp index bfc35fb..9f90720 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -126,14 +126,18 @@ void graphics_cursor(ta_multiwriter& multi) para_control::list_type::opaque, tsp_instruction_word::dst_alpha_instr::zero); - const cursor::cursor& c = cursor::state[0]; + for (int i = 0; i < 4; i++) { + const cursor::cursor& c = cursor::state[i]; + if (!c.active) + continue; - quad_type_0(multi.op, - {c.x - 1, c.y - 1, 10}, - {c.x + 1, c.y - 1, 10}, - {c.x + 1, c.y + 1, 10}, - {c.x - 1, c.y + 1, 10}, - 0xffffff); + quad_type_0(multi.op, + {c.x - 1, c.y - 1, 10}, + {c.x + 1, c.y - 1, 10}, + {c.x + 1, c.y + 1, 10}, + {c.x - 1, c.y + 1, 10}, + 0xffffff); + } } void graphics_event(ta_multiwriter& multi) diff --git a/src/interpreter.cpp b/src/interpreter.cpp index a7c4022..defcc86 100644 --- a/src/interpreter.cpp +++ b/src/interpreter.cpp @@ -208,6 +208,9 @@ void execute_line(int line_index) void interrupt() { + if (state.paused) + return; + state.interrupt_clock += 1; // execute keyons for (int ch = 0; ch < 64; ch++) { @@ -298,4 +301,20 @@ void init(float clock_multiplier) printf("tick_rate %d\n", state.tick_rate); } +void pause() +{ + state.tmp_paused = state.paused; + state.paused = true; +} + +void unpause() +{ + state.paused = false; +} + +void resume() +{ + state.paused = state.tmp_paused; +} + } diff --git a/src/interpreter.hpp b/src/interpreter.hpp index d716c0d..0465282 100644 --- a/src/interpreter.hpp +++ b/src/interpreter.hpp @@ -21,6 +21,8 @@ struct interpreter_state { int pattern_index; int line_index; int next_line_index; // within the current pattern + bool paused; + bool tmp_paused; struct xm_state xm; @@ -30,5 +32,7 @@ struct interpreter_state { extern struct interpreter_state state; void interrupt(); void init(float clock_multiplier); +void pause(); +void unpause(); } diff --git a/src/main.cpp b/src/main.cpp index ab01360..a0cb425 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,9 +9,6 @@ #include "cursor.hpp" #include "input.hpp" -#include "xm/milkypack01.xm.h" -#include "xm.h" - void vbr100() { serial::string("vbr100\n"); @@ -59,24 +56,6 @@ void vbr600() asm volatile ("ldc %0,sr" : : "r" (sr)); } -void load_xm(float clock_multiplier) -{ - using namespace interpreter; - - int buf = (int)&_binary_xm_milkypack01_xm_start; - - static uint8_t __attribute__((aligned(32))) sample_data[1024 * 1024 * 2]; - const int sample_data_length = (sizeof (sample_data)); - - int sample_data_ix = xm_init(&state.xm, - buf, - sample_data, - sample_data_length); - interpreter::init(clock_multiplier); - sound::transfer(sample_data, sample_data_ix); - printf("tick_rate %d\n", state.tick_rate); -} - #include "memorymap.hpp" #include "holly/texture_memory_alloc9.hpp" #include "holly/holly.hpp" @@ -119,9 +98,6 @@ void main() input::state_init(); cursor::init(); - const float aica_clock_multiplier = 44.1; - load_xm(aica_clock_multiplier); - //test_pattern(); interrupt_init(); diff --git a/src/playlist.cpp b/src/playlist.cpp new file mode 100644 index 0000000..e078123 --- /dev/null +++ b/src/playlist.cpp @@ -0,0 +1,34 @@ +#include "xm.h" +#include "xm/milkypack01.xm.h" + +const float aica_clock_multiplier = 44.1; + +namespace playlist { + + static playlist_item playlist[] = { + { + "milkypack01" + } + }; + + + void load_xm(float clock_multiplier, int buf) + { + using namespace interpreter; + + static uint8_t __attribute__((aligned(32))) sample_data[1024 * 1024 * 2]; + const int sample_data_length = (sizeof (sample_data)); + + interpreter::pause(); + + int sample_data_ix = xm_init(&state.xm, + buf, + sample_data, + sample_data_length); + interpreter::init(clock_multiplier); + sound::transfer(sample_data, sample_data_ix); + //printf("tick_rate %d\n", state.tick_rate); + + interpreter::resume(); + } +} diff --git a/src/playlist.hpp b/src/playlist.hpp new file mode 100644 index 0000000..6c304aa --- /dev/null +++ b/src/playlist.hpp @@ -0,0 +1,6 @@ +namespace playlist { + struct playlist_item { + const char * const name; + const int start; + }; +} diff --git a/src/scene/logo/scene.cpp b/src/scene/logo/scene.cpp index c5a9bc8..31d722e 100644 --- a/src/scene/logo/scene.cpp +++ b/src/scene/logo/scene.cpp @@ -32,7 +32,27 @@ static inline float light_intensity(vec3 n, vec3 l) vec3 light_vec = (vec3){-1, -1, -1} - (vec3){0, 0, 0}; -static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat4x4& trans, float base_intensity, bool wireframe) +using vec3i = vec<3, int>; + +static inline vec3i color_lerp(const vec3i& a, const vec3i& b, float f) +{ + float dr = b.x - a.x; + float dg = b.y - a.y; + float db = b.z - a.z; + + return { + (int)((float)a.x + dr * f), + (int)((float)a.y + dg * f), + (int)((float)a.z + db * f), + }; +} + +static inline int vec3i_to_int(const vec3i& a) +{ + return (a.x << 16) | (a.y << 8) | (a.z << 0); +} + +static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat4x4& trans, float base_intensity, bool wireframe, bool diffuse) { if (wireframe) { global_polygon_untextured(writer, @@ -58,7 +78,12 @@ static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat normal_cache[i] = normal_multiply(trans, mesh.polygon_normal[i]); } - const int green = (int)(255.f * base_intensity) << 8; + const vec3i white = vec3i(0xc0, 0xbe, 0xbc); + const vec3i green = vec3i(0x33, 0xd1, 0x7a); + + const int wireframe_color = vec3i_to_int(color_lerp(white, green, base_intensity)); + + //const int green = (int)(255.f * base_intensity) << 8; for (int i = 0; i < mesh.polygons_length; i++) { const polygon& p = mesh.polygons[i]; @@ -69,13 +94,13 @@ static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat vec3 dp = position_cache[p.d]; if (wireframe) { - line_type_0(writer, ap, bp, green); - line_type_0(writer, bp, cp, green); + line_type_0(writer, ap, bp, wireframe_color); + line_type_0(writer, bp, cp, wireframe_color); if (p.d == -1) { - line_type_0(writer, cp, ap, green); + line_type_0(writer, cp, ap, wireframe_color); } else { - line_type_0(writer, cp, dp, green); - line_type_0(writer, dp, ap, green); + line_type_0(writer, cp, dp, wireframe_color); + line_type_0(writer, dp, ap, wireframe_color); } } else { vec2 at = mesh.uv_layers[0][p.uv_index + 0]; @@ -83,7 +108,7 @@ static void render_mesh(ta_parameter_writer& writer, const mesh& mesh, const mat vec2 ct = mesh.uv_layers[0][p.uv_index + 2]; vec2 dt = mesh.uv_layers[0][p.uv_index + 3]; - float intensity = light_intensity(normal_cache[i], light_vec); + float intensity = diffuse ? light_intensity(normal_cache[i], light_vec) : 1.0; if (p.d == -1) { tri_type_7(writer, @@ -139,19 +164,19 @@ namespace scene::logo { .rx = 0, .ry = pi, .s = 0.01, - .duration = 1.0 / (5.2 * 60), + .duration = 1.0 / (3.670 * 60), }, { .i = 1, .rx = 0, .ry = pi, .s = 0.1, - .duration = 1.0 / (4.5 * 60), + .duration = 1.0 / (10.988 * 60), }, { .i = 1, .rx = pi / 4, - .ry = pi + pi / 4, + .ry = -(pi - pi / 4), .s = 0.7, .duration = 1.0 / (10 * 60), }, @@ -215,10 +240,16 @@ namespace scene::logo { * rotate_y(k.ry) * scale((vec3){-1, -1, 1}); - render_mesh(multi.op, mesh_thirty_two, trans, k.i, tick < (9.85 * 60)); + bool _32_wf = tick < (10.988 * 60); + bool bit_wf = tick < (11.908 * 60); + bool jam_wf = tick < (12.825 * 60); + + bool diffuse = tick >= (14.608 * 60); + + render_mesh(multi.op, mesh_thirty_two, trans, k.i, _32_wf, diffuse); if (keyframe_ix > 0) { - render_mesh(multi.op, mesh_bit, trans, k.i, tick < (10.85 * 60)); - render_mesh(multi.op, mesh_jam, trans, k.i, tick < (11.85 * 60)); + render_mesh(multi.op, mesh_bit, trans, k.i, bit_wf, diffuse); + render_mesh(multi.op, mesh_jam, trans, k.i, jam_wf, diffuse); } tick += 1; diff --git a/src/scene/logo/sound.cpp b/src/scene/logo/sound.cpp index d8cc7af..37b4e46 100644 --- a/src/scene/logo/sound.cpp +++ b/src/scene/logo/sound.cpp @@ -2,16 +2,21 @@ #include "../../sound.hpp" #include "scene/logo/sound.hpp" #include "pcm/jingle.adpcm.h" +#include "pcm/start3.adpcm.h" #include "printf/printf.h" namespace scene::logo::sound { - const static void * start = reinterpret_cast(&_binary_pcm_jingle_adpcm_start); - const static int size = reinterpret_cast(&_binary_pcm_jingle_adpcm_size); + //const static void * start = reinterpret_cast(&_binary_pcm_jingle_adpcm_start); + //const static int size = reinterpret_cast(&_binary_pcm_jingle_adpcm_size); + + const static void * start = reinterpret_cast(&_binary_pcm_start3_adpcm_start); + const static int size = reinterpret_cast(&_binary_pcm_start3_adpcm_size); const static int sample_count = size * 2; const static int loop_length = 65528; const static int segment_count = sample_count / loop_length; + const static int last_loop = (sample_count % loop_length) & (~0b11); void init() { @@ -31,7 +36,7 @@ namespace scene::logo::sound { wait(); aica_sound.channel[0].RR(0x1f); wait(); aica_sound.channel[0].AR(0x1f); - wait(); aica_sound.channel[0].OCT(0); + wait(); aica_sound.channel[0].OCT(-1); wait(); aica_sound.channel[0].FNS(0); wait(); aica_sound.channel[0].DISDL(0xf); wait(); aica_sound.channel[0].DIPAN(0x0); @@ -43,6 +48,7 @@ namespace scene::logo::sound { void interrupt() { static int segment = 0; + static bool last = false; wait(); int lp_sgc_eg = aica_sound.common.lp_sgc_eg; @@ -60,9 +66,15 @@ namespace scene::logo::sound { if (aica::lp_sgc_eg::LP(lp_sgc_eg)) { segment += 1; if (segment >= segment_count) { - wait(); aica_sound.channel[0].KYONB(0); - wait(); aica_sound.channel[0].KYONEX(1); - return; + if (last || last_loop == 0) { + wait(); aica_sound.channel[0].KYONB(0); + wait(); aica_sound.channel[0].KYONEX(1); + return; + } else { + printf("last loop\n", segment); + last = true; + wait(); aica_sound.channel[0].LEA(last_loop); + } } printf("loop %d\n", segment); diff --git a/xm_player.mk b/xm_player.mk index 5a2dabd..3cec341 100644 --- a/xm_player.mk +++ b/xm_player.mk @@ -6,7 +6,7 @@ TEXTURE_OBJ = \ model/32bitlogo/colors.data.o PCM_OBJ = \ - pcm/jingle.adpcm.o + pcm/start3.adpcm.o XM_PLAYER_OBJ = \ $(LIB)/holly/core.o \