diff --git a/src/spice2x/games/popn/bi3a_hook.cpp b/src/spice2x/games/popn/bi3a_hook.cpp index 18acaa0..5d2e3a4 100644 --- a/src/spice2x/games/popn/bi3a_hook.cpp +++ b/src/spice2x/games/popn/bi3a_hook.cpp @@ -484,7 +484,7 @@ namespace games::popn { const auto data_size = std::min(map.data.capacity(), (size_t)number_of_leds / 3); // pick a color to use - const auto rgb = tapeledutils::pick_color_from_led_tape((uint8_t *)i_pData, data_size); + const auto rgb = tapeledutils::pick_color_from_led_tape(map, (uint8_t *)i_pData, data_size); // program the lights into API auto &lights = get_lights(); diff --git a/src/spice2x/games/popn/io.cpp b/src/spice2x/games/popn/io.cpp index c4c156d..091b432 100644 --- a/src/spice2x/games/popn/io.cpp +++ b/src/spice2x/games/popn/io.cpp @@ -136,6 +136,18 @@ std::vector &games::popn::get_lights() { {"Pika", "IC Card R"}, {"Pika", "IC Card G"}, {"Pika", "IC Card B"}, + {"Pika", "Speakers R"}, + {"Pika", "Speakers G"}, + {"Pika", "Speakers B"}, + {"Pika", "Monitor R"}, + {"Pika", "Monitor G"}, + {"Pika", "Monitor B"}, + {"Pika", "Control Panel R"}, + {"Pika", "Control Panel G"}, + {"Pika", "Control Panel B"}, + {"Pika", "Cabinet R"}, + {"Pika", "Cabinet G"}, + {"Pika", "Cabinet B"}, }); } diff --git a/src/spice2x/games/popn/io.h b/src/spice2x/games/popn/io.h index e2f1393..36345cd 100644 --- a/src/spice2x/games/popn/io.h +++ b/src/spice2x/games/popn/io.h @@ -121,6 +121,18 @@ namespace games::popn { IC_Card_R, IC_Card_G, IC_Card_B, + Speaker_R, + Speaker_G, + Speaker_B, + Monitor_R, + Monitor_G, + Monitor_B, + ControlPanel_R, + ControlPanel_G, + ControlPanel_B, + Cabinet_R, + Cabinet_G, + Cabinet_B, } popn_lights_t; } diff --git a/src/spice2x/games/popn/popn.cpp b/src/spice2x/games/popn/popn.cpp index 0ae443e..c6b4fe6 100644 --- a/src/spice2x/games/popn/popn.cpp +++ b/src/spice2x/games/popn/popn.cpp @@ -38,39 +38,83 @@ namespace games::popn { // pin 1 = left pop (red pop kun), size 16, values 0-0xFF // pin 2 = right pop (blue pop kun), size 16, values 0-0xFF // pin 3 = title, size 44, values 0-0xFF - // pin 4 = speaker, size 40, values 0-0xFF - U region only + // pin 4 = speaker, size 40, values 0-0x7F - U region only // pin 5 = monitor, size 18, values 0-0x7F - U region only // pin 6 = control panel, size 28, values 0-0x7F - U region only // pin 7 = cabinet, size 22, values 0-0x7F - U region only tapeledutils::tape_led TAPELED_MAPPING[POPN_TAPELED_TOTAL] = { { - 0, // these are button lights and handled specially + // [0] button lights: these are button lights and handled specially + 0, + 0, 0, 0, 0, "Invalid" }, { + // [1] red pop-kun 5, // 5*3; game reports 16 but make it 15 Lights::popn_lights_t::RedPopKun_R, Lights::popn_lights_t::RedPopKun_G, Lights::popn_lights_t::RedPopKun_B, + 0xFF, "Red Pop-Kun" }, { + // [2] blue pop-kun 5, // 5*3; game reports 16 but make it 15 Lights::popn_lights_t::BluePopKun_R, Lights::popn_lights_t::BluePopKun_G, Lights::popn_lights_t::BluePopKun_B, + 0xFF, "Blue Pop-Kun" }, { - 14, // 14*3; game reports 44 but make it 42; these are lights above the banner + // [3] top LED + 14, // 14*3; game reports 44 but make it 42 Lights::popn_lights_t::TopLED_R, Lights::popn_lights_t::TopLED_G, Lights::popn_lights_t::TopLED_B, + 0xFF, "Top" }, + { + // [4] speakers + 13, // 13*3; game reports 40 but make it 39 + Lights::popn_lights_t::Speaker_G, + Lights::popn_lights_t::Speaker_R, + Lights::popn_lights_t::Speaker_B, + 0x7F, + "Speakers" + }, + { + // [5] monitor + 6, + Lights::popn_lights_t::Monitor_G, + Lights::popn_lights_t::Monitor_R, + Lights::popn_lights_t::Monitor_B, + 0x7F, + "Monitor" + }, + { + // [6] control panel + 9, // 9*3; game reports 28 + Lights::popn_lights_t::ControlPanel_G, + Lights::popn_lights_t::ControlPanel_R, + Lights::popn_lights_t::ControlPanel_B, + 0x7F, + "Control Panel" + }, + { + // [7] Cabinet + 7, // 7*3; game reports 22 + Lights::popn_lights_t::Cabinet_G, + Lights::popn_lights_t::Cabinet_R, + Lights::popn_lights_t::Cabinet_B, + 0x7F, + "Cabinet" + }, }; diff --git a/src/spice2x/games/popn/popn.h b/src/spice2x/games/popn/popn.h index 2e57706..105e3b9 100644 --- a/src/spice2x/games/popn/popn.h +++ b/src/spice2x/games/popn/popn.h @@ -17,7 +17,7 @@ namespace games::popn { } #if SPICE64 - constexpr int POPN_TAPELED_TOTAL = 4; + constexpr int POPN_TAPELED_TOTAL = 8; extern tapeledutils::tape_led TAPELED_MAPPING[POPN_TAPELED_TOTAL]; #endif diff --git a/src/spice2x/util/tapeled.cpp b/src/spice2x/util/tapeled.cpp index 195f077..12adf43 100644 --- a/src/spice2x/util/tapeled.cpp +++ b/src/spice2x/util/tapeled.cpp @@ -9,7 +9,7 @@ namespace tapeledutils { } // for bi2x-style byte array of all colors and LEDs at once - rgb_float3_t pick_color_from_led_tape(uint8_t *data, size_t data_size) { + static rgb_float3_t pick_color_from_led_tape_internal(uint8_t *data, size_t data_size, uint8_t divisor) { rgb_float3_t result = {0.f, 0.f, 0.f}; if (TAPE_LED_ALGORITHM == TAPE_LED_USE_AVERAGE) { @@ -25,7 +25,7 @@ namespace tapeledutils { } // normalize - const float avg_mult = 1.f / (data_size * 255); + const float avg_mult = 1.f / (data_size * divisor); result.r = avg_ri * avg_mult; result.g = avg_gi * avg_mult; result.b = avg_bi * avg_mult; @@ -50,7 +50,7 @@ namespace tapeledutils { } // normalize - const float single_mult = 1.f / 255; + const float single_mult = 1.f / divisor; result.r = color[0] * single_mult; result.g = color[1] * single_mult; result.b = color[2] * single_mult; @@ -58,6 +58,15 @@ namespace tapeledutils { return result; } + rgb_float3_t pick_color_from_led_tape(tape_led &light, uint8_t *data, size_t data_size) { + const auto max_value = (light.max_value > 0) ? light.max_value : 0xFF; + return pick_color_from_led_tape_internal(data, data_size, max_value); + } + + rgb_float3_t pick_color_from_led_tape(uint8_t *data, size_t data_size) { + return pick_color_from_led_tape_internal(data, data_size, 0xFF); + } + // for bi2a-style that calls for each individual LED size_t get_led_index_using_avg_algo(size_t data_size) { size_t index_to_use; diff --git a/src/spice2x/util/tapeled.h b/src/spice2x/util/tapeled.h index 6687bca..6fec5f3 100644 --- a/src/spice2x/util/tapeled.h +++ b/src/spice2x/util/tapeled.h @@ -25,13 +25,33 @@ namespace tapeledutils { struct tape_led { std::vector data; int index_r, index_g, index_b; // Averaged RGB light output indexes + uint8_t max_value; std::string lightName; - tape_led(size_t data_size, int index_r, int index_g, int index_b, std::string lightName) - : data(std::vector(data_size)), index_r(index_r), index_g(index_g), index_b(index_b), lightName(std::move(lightName)) {} + tape_led( + size_t data_size, + int index_r, int index_g, int index_b, + std::string lightName) + : data( + std::vector(data_size)), + index_r(index_r), index_g(index_g), index_b(index_b), + max_value(0), + lightName(std::move(lightName)) {} + + tape_led( + size_t data_size, + int index_r, int index_g, int index_b, + uint8_t max_value, + std::string lightName) + : data( + std::vector(data_size)), + index_r(index_r), index_g(index_g), index_b(index_b), + max_value(max_value), + lightName(std::move(lightName)) {} }; bool is_enabled(); + rgb_float3_t pick_color_from_led_tape(tape_led &light, uint8_t *data, size_t data_size); rgb_float3_t pick_color_from_led_tape(uint8_t *data, size_t data_size); size_t get_led_index_using_avg_algo(size_t data_size); }