mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 12:54:29 +01:00
MENU, now a scrolling list: STYLE (FLAT / LINE, #57), ANIM (#46), KNOB ACCEL (#52), FX LATCH (#40), BPM LOCK (#58), USB LEVEL (MASTER / FIXED), LEDS OFF / DIM LO / DIM HI / INV; SPEAKER is SPEAKER EQ (FLAT / LOWCUT / BASS+, #42). Palettes: GREY (the former MONO), a black-and-white MONO and NIGHT (#50, #57). Tracks numbered 1-4 on cushions (#50); the motion icon on the cards MOTION drives (#63). Divisions listed by length (#48). Fixed: knob turns as a layer is let go no longer edit the page under it (#39); FX DEPTH turns the right way (#40); BASS+ no longer cancels the mids (#42); live sync keeps pending pushes on WATCH and no longer echoes the editor's own loads as RELOAD (#64, #65). SAMPLE's PERC kit is retired: its sounds load as the DRUM engine's kit.
613 lines
30 KiB
C
613 lines
30 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
|
|
/* The firmware editor handler, USB framing and UART recovery against RAM flash.
|
|
* Build with the generated tables and the same flags as hostsim.c. */
|
|
static unsigned char host_samples[3][0x14000];
|
|
#define SMP_USER_XIP(k) host_samples[k]
|
|
#define FELUCCA_OTA 1
|
|
#define FELUCCA_FLASH 0
|
|
#define FELUCCA_VERSION "TEST"
|
|
#define main hostsim_main
|
|
#include "hostsim.c"
|
|
#undef main
|
|
|
|
static uint32_t host_progress = 1, host_erases, host_writes;
|
|
static uint8_t host_wire[4096];
|
|
static uint32_t host_wire_n;
|
|
static void host_drain(void)
|
|
{
|
|
while (so_r != so_w) {
|
|
uint32_t p = sx_out_q[so_r++ % SXQ], cin = p & 15u, i;
|
|
uint32_t n = cin == 4u || cin == 7u ? 3u : cin == 6u ? 2u : 1u;
|
|
for (i = 0; i < n && host_wire_n < sizeof host_wire; i++)
|
|
host_wire[host_wire_n++] = (uint8_t)(p >> (8u * (i + 1u)));
|
|
}
|
|
}
|
|
static uint32_t ota_now_ms(void) { return fm1_ms; }
|
|
static void ota_idle(void) { host_drain(); fm1_ms++; }
|
|
static void fm1_wdt_feed(void)
|
|
{
|
|
fm1_ms++;
|
|
if (host_progress && transport_req == 2u) { seq_stop(); transport_req = 0; }
|
|
}
|
|
static void fm1_irq_off(void) {}
|
|
static void fm1_irq_on(void) {}
|
|
static int32_t fm1_enc_take(uint32_t e) { (void)e; return 0; }
|
|
static void lcd_sync(void) {}
|
|
static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
|
|
{ (void)x; (void)y; (void)w; (void)h; (void)p; }
|
|
#include "../firmware/src/gfx.c"
|
|
#include "../firmware/src/panel.c"
|
|
#include "../firmware/src/ui.c"
|
|
static void panel_setup(void) {}
|
|
#include "../firmware/src/upreset.c"
|
|
#include "../firmware/src/project.c"
|
|
|
|
static uint32_t flash_ok = 1;
|
|
static void audio_silence(void) {}
|
|
static void fl_inval(uint32_t off, uint32_t n) { (void)off; (void)n; }
|
|
static uint8_t *host_flash_ptr(uint32_t off) { return &host_samples[0][0] + off - SMP_USER_BASE; }
|
|
static int fl_erase4k(uint32_t off, uint32_t *took)
|
|
{
|
|
memset(host_flash_ptr(off), 0xFF, 4096); *took = 0; host_erases++; return 0;
|
|
}
|
|
static int fl_write(uint32_t off, const void *p, uint32_t n)
|
|
{
|
|
memcpy(host_flash_ptr(off), p, n); host_writes++; return 0;
|
|
}
|
|
static int st_read(uint32_t off, void *p, uint32_t n) { (void)off; (void)p; (void)n; return -1; }
|
|
static int st_prog(uint32_t off, const void *p, uint32_t n) { (void)off; (void)p; (void)n; return -1; }
|
|
static int st_erase(uint32_t off) { (void)off; return -1; }
|
|
#include "../firmware/src/storage.c"
|
|
#include "../firmware/src/editor.c"
|
|
|
|
static int check(const char *what, int ok)
|
|
{
|
|
printf("editor: %-70s %s\n", what, ok ? "ok" : "FAIL");
|
|
return !ok;
|
|
}
|
|
static void reset(void)
|
|
{
|
|
uint32_t t, i;
|
|
memset(&song, 0, sizeof song); memset(trk, 0, sizeof trk);
|
|
memset(&chain, 0, sizeof chain); chain_defaults(&chain_config);
|
|
memset(&ed_w, 0, sizeof ed_w); memset(&ui, 0, sizeof ui);
|
|
memset(&favorites, 0, sizeof favorites); memset(&settings, 0, sizeof settings); settings_init();
|
|
memset(proj_slot, 0, sizeof proj_slot); memset(up_bank, 0, sizeof up_bank);
|
|
memset(&um, 0, sizeof um); memset(usr_nz, 0, sizeof usr_nz);
|
|
host_progress = 1; host_erases = host_writes = host_wire_n = 0;
|
|
transport_req = panic_req = 0; sx_ready = sx_collect = sx_busy = 0;
|
|
so_r = so_w = mi_r = mi_w = 0; midi_in_overflow = 0; usb.config = 1;
|
|
for (i = 0; i < G_COUNT; i++) song.g[i] = GP[i].def;
|
|
for (t = 0; t < NTRK; t++) {
|
|
track_defaults(&trk[t]); set_engine_of(&trk[t], 0); apply_preset_to(&trk[t], 0);
|
|
trk[t].engine = trk[t].eng_req; track_defaults_steps(&trk[t]);
|
|
}
|
|
}
|
|
static uint32_t request(uint32_t cmd, const uint8_t *a, uint32_t n)
|
|
{
|
|
uint32_t i;
|
|
host_wire_n = 0; ota_frame_done();
|
|
sysex_byte(0xF0); sysex_byte(ED_HDR0); sysex_byte(ED_HDR1); sysex_byte(ED_HDR2); sysex_byte((uint8_t)cmd);
|
|
for (i = 0; i < n; i++) sysex_byte(a[i]);
|
|
sysex_byte(0xF7); ed_service(); host_drain();
|
|
return host_wire_n;
|
|
}
|
|
static uint32_t pack7(const uint8_t *p, uint32_t n, uint8_t *a)
|
|
{
|
|
uint32_t o = 0, i;
|
|
while (n) {
|
|
uint32_t k = n > 7u ? 7u : n, m = o++;
|
|
a[m] = 0;
|
|
for (i = 0; i < k; i++, n--) { a[m] |= (*p >> 7) << i; a[o++] = *p++ & 127u; }
|
|
}
|
|
return o;
|
|
}
|
|
|
|
static int preferences(void)
|
|
{
|
|
int bad = 0;
|
|
uint8_t a[4] = {0, 7, 0, 0};
|
|
reset();
|
|
uint32_t n = request(ED_INFO, a, 0);
|
|
bad += check("INFO explicitly tags display capabilities after SONG without changing command 33",
|
|
ED_SONG == 33 && ED_UI_STATE == 34 && ED_FAV_SET == 38 &&
|
|
host_wire[n - 19] == CHAIN_ROWS && host_wire[n - 18] == 0x55 &&
|
|
host_wire[n - 17] == 1 && host_wire[n - 16] == 9 &&
|
|
host_wire[n - 15] == 0x4d && host_wire[n - 14] == 1 &&
|
|
host_wire[n - 13] == MOTION_MAX && host_wire[n - 12] == 1 &&
|
|
host_wire[n - 11] == 0x42 && host_wire[n - 10] == 1 && host_wire[n - 9] == 3 &&
|
|
host_wire[n - 8] == 0x46 && host_wire[n - 7] == 1 && host_wire[n - 6] == FM6_NFACTORY &&
|
|
host_wire[n - 5] == FM6_BANK_N &&
|
|
host_wire[n - 4] == 0x53 && host_wire[n - 3] == 1 && host_wire[n - 2] == 3);
|
|
request(ED_UI_SET, a, 2);
|
|
bad += check("UI_SET updates the actual palette and reports RAM-only saving",
|
|
host_wire[5] == 3 && settings.palette == 7 && T_BG == UI_PALETTES[7].bg);
|
|
a[1] = NPALETTES; request(ED_UI_SET, a, 2);
|
|
bad += check("out-of-range palette leaves the display unchanged", host_wire[5] == 1 && settings.palette == 7);
|
|
a[0] = 1; a[1] = 1; request(ED_UI_SET, a, 2);
|
|
bad += check("the retired font weight is not supported (rc 2), UI_STATE says 127",
|
|
host_wire[5] == 2 && host_wire[8] == 9 && host_wire[10] == 127);
|
|
a[0] = 2; request(ED_UI_SET, a, 2);
|
|
bad += check("unsupported preference is reported without applying it", host_wire[5] == 2);
|
|
a[0] = ENGI_DRUM; a[1] = 0; a[2] = 64; a[3] = 1;
|
|
request(ED_FAV_SET, a, 4);
|
|
bad += check("FAV_SET marks DRUM as a normal engine", host_wire[5] == 3 && favorite_has(ENGI_DRUM, 0));
|
|
request(ED_FAV_GET, a, 4);
|
|
bad += check("FAV_GET reads the bounded favorite range", host_wire[5] == 0 && host_wire[10] == 1);
|
|
a[0] = NENGINES; a[1] = 31; request(ED_FAV_SET, a, 4);
|
|
bad += check("empty user slot cannot be starred", host_wire[5] == 1 && !favorite_has(NENGINES, 31));
|
|
up_store(31, "Saved"); request(ED_FAV_SET, a, 4);
|
|
bad += check("saved user slot can be starred without changing its sound", host_wire[5] == 3 && favorite_has(NENGINES, 31));
|
|
a[3] = 32; request(ED_FAV_GET, a, 4);
|
|
bad += check("favorite range cannot cross the end of user slots", host_wire[5] == 1);
|
|
request(ED_FAV_SET, a, 3);
|
|
bad += check("short favorite writes return an error without reading absent bytes", host_wire[5] == 1);
|
|
bad += check("UI_STATE rejects unexpected request bytes", request(ED_UI_STATE, a, 1) == 0);
|
|
a[0] = 0; request(ED_SONG, a, 1);
|
|
bad += check("SONG still responds through its original command", host_wire_n > 6 && host_wire[4] == 33 && host_wire[5] == 0);
|
|
return bad;
|
|
}
|
|
|
|
static int framing(void)
|
|
{
|
|
uint32_t i, bad = 0;
|
|
static const uint8_t rt[] = {0xF0, 0x7D, 0xF8, 0x46, 0xFE, 0x4C, ED_PING, 0xFF, 0xF7};
|
|
static const uint8_t aborted[] = {0xF0, 0x7D, 0x46, 0x4C, ED_SET, 0, P_LEVEL, 0x90, 0, 64, 0xF7};
|
|
reset();
|
|
for (i = 0; i < sizeof rt; i++) sysex_byte(rt[i]);
|
|
ed_service(); host_drain();
|
|
bad += check("realtime bytes interleaved in SysEx do not enter the editor frame",
|
|
host_wire_n == 7u && host_wire[4] == ED_PING && host_wire[5] == 0);
|
|
ota_frame_done(); host_wire_n = 0;
|
|
for (i = 0; i < sizeof aborted; i++) sysex_byte(aborted[i]);
|
|
ed_service(); host_drain();
|
|
bad += check("a non-realtime status aborts SysEx without changing parameters",
|
|
!sx_ready && !host_wire_n && TSEL->p[P_LEVEL] == TP[P_LEVEL].def);
|
|
bad += check("a valid request works after an aborted frame", request(ED_PING, 0, 0) == 7u);
|
|
ota_frame_done();
|
|
midi_in_event(0x467DF004u); /* F0 7D 46 */
|
|
midi_in_event(0x00004C04u); /* unfinished SysEx */
|
|
midi_in_event(0x643C9009u);
|
|
sysex_byte(0xF7);
|
|
bad += check("a channel event in another USB packet aborts an unfinished SysEx",
|
|
!sx_ready && mi_w == 1u && midi_in_q[0] == 0x643C9009u);
|
|
midi_in_event(0x643C8009u); /* wrong CIN */
|
|
midi_in_event(0x643CFF09u); /* wrong status */
|
|
midi_in_event(0xFF3C9009u); /* not a seven-bit velocity */
|
|
midi_in_event(0x64FF9009u); /* not a seven-bit note */
|
|
bad += check("USB channel packets reject mismatched CIN and high data bits", mi_w == 1u);
|
|
midi_in_event(0xFF05C00Cu); /* one-byte status: padding is ignored */
|
|
midi_in_event(0xFF07D00Du);
|
|
bad += check("USB program and channel pressure keep their one-byte payload", mi_w == 3u);
|
|
mi_w = UINT32_MAX - 5u; mi_r = mi_w;
|
|
for (i = 0; i < MQ + 8u; i++) midi_in_event(0x643C9009u);
|
|
bad += check("USB MIDI ring stops at capacity across counter wrap", mi_w - mi_r == MQ && midi_in_overflow);
|
|
mi_r = mi_w; midi_in_event(0x643C9009u);
|
|
bad += check("USB rejects new messages until the audio consumer clears overflow", mi_w == mi_r);
|
|
midi_in_overflow = 0; midi_in_event(0x643C9009u);
|
|
bad += check("USB resumes after the audio consumer clears overflow", mi_w - mi_r == 1u);
|
|
return bad;
|
|
}
|
|
|
|
static int uart_recovery(void)
|
|
{
|
|
uint32_t i;
|
|
int bad = 0;
|
|
reset();
|
|
um_byte(0x90); um_byte(50);
|
|
for (i = 0; i < UM_RING; i++) um_ring[i] = 0;
|
|
um_ring[126] = 0x90; um_ring[127] = 72; um_ring[0] = 99;
|
|
uart_midi_take(UM_RING + 1u);
|
|
bad += check("UART DMA overrun never combines a stale partial note with new data",
|
|
!mi_w && midi_in_overflow && um.drops == 2u && um.bytes == UM_RING && !um.pend);
|
|
midi_in_overflow = 0; um_byte(0x90); um_byte(72); um_byte(99);
|
|
bad += check("UART receives a complete fresh note after DMA recovery",
|
|
mi_w == 1u && midi_in_q[0] == 0x63489009u);
|
|
reset();
|
|
um_byte(0x90); um_byte(50);
|
|
for (i = 0; i < UM_RING; i++) um_ring[i] = 60;
|
|
uart_midi_take(UM_RING + 2u);
|
|
bad += check("UART discards running-status data after lost bytes until a new status",
|
|
!mi_w && midi_in_overflow && um.drops == 2u && !um.st && !um.got);
|
|
midi_in_overflow = 0;
|
|
um_byte(0x91); um_byte(70); um_byte(100);
|
|
bad += check("UART recovers immediately on a complete channel message", mi_w == 1u && midi_in_q[0] == 0x64469109u);
|
|
reset(); mi_w = MQ;
|
|
um_byte(0x90); um_byte(60); um_byte(100);
|
|
bad += check("UART queue overflow latches the same recovery flag as USB", midi_in_overflow && um.drops == 1u && mi_w == MQ);
|
|
mi_r = mi_w; um_byte(61); um_byte(101);
|
|
bad += check("UART rejects a new stream until audio clears overflow", mi_w == mi_r && um.drops == 2u);
|
|
midi_in_overflow = 0; um_byte(62); um_byte(102);
|
|
bad += check("UART resumes valid running status after audio clears overflow",
|
|
mi_w - mi_r == 1u && midi_in_q[mi_r % MQ] == 0x663E9009u);
|
|
return bad;
|
|
}
|
|
|
|
static int steps(void)
|
|
{
|
|
uint8_t a[80] = {0, 1, 60, 0, 0, 0, ST_NOTE, SF_ACCENT, 100, 0x12, 0x02, 1};
|
|
step_t before;
|
|
uint32_t n, ok = 1;
|
|
int bad = 0;
|
|
reset();
|
|
TSEL->step[0].hit = TSEL->step[0].acc = 0x80;
|
|
bad += check("legacy 8-byte step writes preserve lane data",
|
|
request(ED_STEP_SET, a, 9) == 19u && TSEL->step[0].note[0] == 60 &&
|
|
TSEL->step[0].hit == 0x80 && TSEL->step[0].acc == 0x80);
|
|
bad += check("full grid step writes preserve high lane bits and constrain accents",
|
|
request(ED_STEP_SET, a, 12) == 19u && TSEL->step[0].hit == 0x92 && TSEL->step[0].acc == 2);
|
|
before = TSEL->step[0]; a[2] = 71;
|
|
for (n = 2; n <= sizeof a; n++) {
|
|
if (n == 9u || n == 12u || n == 13u) continue;
|
|
ok &= !request(ED_STEP_SET, a, n) && !memcmp(&before, &TSEL->step[0], sizeof before);
|
|
}
|
|
bad += check("partial or oversized step payloads never mutate a valid step", ok);
|
|
a[0] = 1; a[1] = 0; memcpy(a + 2, (const uint8_t[]){1,64,0,0,0,ST_NOTE,0,99}, 8);
|
|
bad += check("TRACK_STEP accepts its legacy payload on an unselected track",
|
|
request(ED_TRACK_STEP, a, 10) == 20u && trk[1].step[0].note[0] == 64 && song.sel == 0);
|
|
before = trk[1].step[0]; a[3] = 65;
|
|
bad += check("TRACK_STEP rejects an incomplete grid extension",
|
|
!request(ED_TRACK_STEP, a, 11) && !memcmp(&before, &trk[1].step[0], sizeof before));
|
|
return bad;
|
|
}
|
|
|
|
static int samples(void)
|
|
{
|
|
uint8_t a[640] = {0}, data[257], short_group[] = {0, 0, 4, 0, 1};
|
|
uint32_t n, i;
|
|
int bad = 0;
|
|
smp_user_hdr_t h;
|
|
reset(); memset(host_samples, 0, sizeof host_samples);
|
|
for (i = 0; i < sizeof data; i++) data[i] = (uint8_t)(i * 37u);
|
|
song.playing = 1; host_progress = 0;
|
|
bad += check("sample erase waits for STOP and refuses a stalled audio ISR",
|
|
request(ED_SMP_BEGIN, a, 1) == 8u && host_wire[6] != 0 && !host_erases && song.playing);
|
|
host_progress = 1;
|
|
bad += check("sample erase stops transport before touching flash",
|
|
request(ED_SMP_BEGIN, a, 1) == 8u && !host_wire[6] && host_erases == 1 && !song.playing);
|
|
a[0] = 0; a[1] = 0; a[2] = 4; a[3] = 0;
|
|
n = pack7(data, 257, a + 4) + 4u;
|
|
bad += check("257 decoded sample bytes are rejected without a truncated write",
|
|
request(ED_SMP_WRITE, a, n) == 11u && host_wire[9] == 1 && !host_writes);
|
|
bad += check("a dangling packed-data mask is rejected",
|
|
request(ED_SMP_WRITE, short_group, sizeof short_group) == 11u && host_wire[9] == 1 && !host_writes);
|
|
n = pack7(data, 256, a + 4) + 4u;
|
|
transport_req = 1;
|
|
bad += check("sample writes cancel a pending PLAY before flash access",
|
|
request(ED_SMP_WRITE, a, n) == 11u && !host_wire[9] && transport_req != 1u && host_writes == 1);
|
|
memset(&h, 0, sizeof h); h.magic = SMP_USER_MAGIC; h.version = 1; h.nz = 1;
|
|
h.data_len = 256; h.crc = st_crc32(data, 256); h.zone[0].n = 512; h.zone[0].le = 511;
|
|
h.zone[0].rate = 65536; h.zone[0].hi = 127;
|
|
a[0] = 0; n = pack7((const uint8_t *)&h, sizeof h, a + 1) + 1u;
|
|
a[n] = 0; a[n + 1u] = 0;
|
|
bad += check("an oversized sample header is rejected without programming flash",
|
|
request(ED_SMP_END, a, n + 2u) == 8u && host_wire[6] == 1 && host_writes == 1);
|
|
bad += check("complete sample header and CRC publish a valid slot",
|
|
request(ED_SMP_END, a, n) == 8u && !host_wire[6] && usr_nz[0] == 1 && host_writes == 2);
|
|
bad += check("repeated END of the same published header does not rewrite live zones",
|
|
request(ED_SMP_END, a, n) == 8u && !host_wire[6] && host_writes == 2);
|
|
h.zone[0].rate = 131072;
|
|
n = pack7((const uint8_t *)&h, sizeof h, a + 1) + 1u;
|
|
bad += check("END cannot change published sample zones without BEGIN",
|
|
request(ED_SMP_END, a, n) == 8u && host_wire[6] == 2 && host_writes == 2 &&
|
|
usr_zone[0][0].rate == 65536u);
|
|
song.playing = 1; host_progress = 0; a[0] = 0; a[1] = 0;
|
|
bad += check("user-preset STORE does not mutate RAM when audio cannot stop",
|
|
request(ED_UP_STORE, a, 2) == 8u && host_wire[6] == 2 && !up_used(0));
|
|
bad += check("user-preset ERASE reports failure when audio cannot stop",
|
|
request(ED_UP_ERASE, a, 1) == 8u && host_wire[6] == 2);
|
|
return bad;
|
|
}
|
|
|
|
static int song_protocol(void)
|
|
{
|
|
uint8_t a[] = {1, 1, 0, 2};
|
|
chain_config_t before;
|
|
int bad = 0;
|
|
reset();
|
|
bad += check("SONG sets and queries the complete chain without changing selection",
|
|
request(ED_SONG, a, sizeof a) == 14u && !host_wire[6] && chain_config.count == 1 && song.sel == 0);
|
|
before = chain_config; a[3] = 0;
|
|
bad += check("SONG invalid repeats leave the chain unchanged",
|
|
request(ED_SONG, a, sizeof a) == 14u && host_wire[6] == 1 && !memcmp(&before, &chain_config, sizeof before));
|
|
a[3] = 2; chain.armed = 1;
|
|
bad += check("SONG cannot replace a chain while its start is pending",
|
|
request(ED_SONG, a, sizeof a) == 14u && host_wire[6] == 2 && !memcmp(&before, &chain_config, sizeof before));
|
|
chain.armed = 0; a[0] = 2;
|
|
bad += check("SONG PLAY refuses extra argument bytes", !request(ED_SONG, a, 2) && !transport_req);
|
|
return bad;
|
|
}
|
|
|
|
static int malformed_saves(void)
|
|
{
|
|
static const uint8_t slot[] = {1, 4}, name[] = {0, 'X', 0, 'Y'};
|
|
const uint8_t save[] = {1, 0};
|
|
project_store_t old;
|
|
int bad = 0;
|
|
reset();
|
|
bad += check("PROJECT refuses an invalid slot instead of wrapping to slot 0",
|
|
!request(ED_PROJECT, slot, sizeof slot) && !project_used(0));
|
|
bad += check("UP_STORE rejects bytes after its name terminator without saving",
|
|
request(ED_UP_STORE, name, sizeof name) == 8u && host_wire[6] == 1 && !up_used(0));
|
|
bad += check("a successful PROJECT save confirms its slot", request(ED_PROJECT, save, sizeof save) == 9u && project_used(0));
|
|
old = proj_slot[0];
|
|
TSEL->p[P_LEVEL] = 21; song.playing = 1; host_progress = 0;
|
|
bad += check("PROJECT never confirms an old used slot when STOP timed out",
|
|
!request(ED_PROJECT, save, sizeof save) && !memcmp(&old, &proj_slot[0], sizeof old));
|
|
return bad;
|
|
}
|
|
|
|
/* FM6 patches (cmds 68..71): a track's own patch, the bank (RAM here), the factory patches, malformed frames */
|
|
static int fm6_patches(void)
|
|
{
|
|
int bad = 0;
|
|
uint8_t a[2 + FM6_PACKED], pk[FM6_PACKED];
|
|
uint32_t n, i;
|
|
reset();
|
|
fm6_bank_check(-1);
|
|
a[0] = ED_FM6_FACTORY; a[1] = 3;
|
|
n = request(ED_FM6_GET, a, 2);
|
|
bad += check("FM6_GET factory 4: the packed record", n == 5u + 3u + FM6_PACKED + 1u && host_wire[7] == 0 &&
|
|
!memcmp(host_wire + 8, FM6_FACTORY[3], FM6_PACKED));
|
|
memcpy(pk, FM6_FACTORY[3], FM6_PACKED);
|
|
memcpy(pk + 118, "MY PATCH ", 10);
|
|
a[0] = ED_FM6_TRACK; a[1] = 2; memcpy(a + 2, pk, FM6_PACKED);
|
|
n = request(ED_FM6_PUT, a, sizeof a);
|
|
bad += check("FM6_PUT track 3: rc 0, the track's patch", n == 9u && host_wire[7] == 0 &&
|
|
!memcmp(fm6_patch[2] + FP_NAME, "MY PATCH ", 10));
|
|
a[1] = 2;
|
|
n = request(ED_FM6_GET, a, 2);
|
|
bad += check("FM6_GET track 3: as sent", host_wire[7] == 0 && !memcmp(host_wire + 8, pk, FM6_PACKED));
|
|
a[0] = ED_FM6_BANK; a[1] = 4;
|
|
n = request(ED_FM6_GET, a, 2);
|
|
bad += check("FM6_GET of an empty bank slot: rc 2, no record", n == 9u && host_wire[7] == 2);
|
|
a[0] = ED_FM6_BANK; a[1] = 4; memcpy(a + 2, pk, FM6_PACKED);
|
|
a[2 + 14] = 120; /* OP6 output level 120: stored as 99 */
|
|
n = request(ED_FM6_PUT, a, sizeof a);
|
|
a[0] = ED_FM6_BANK; a[1] = 4;
|
|
request(ED_FM6_GET, a, 2);
|
|
bad += check("FM6_PUT bank B5, then GET: stored in range (a level of 120 -> 99)", host_wire[7] == 0 &&
|
|
host_wire[8 + 14] == 99 && !memcmp(host_wire + 8 + 118, "MY PATCH ", 10) && fm6_bank_used(4));
|
|
n = request(ED_FM6_LIST, a, 0);
|
|
{ /* factory 8, bank 27, then used + name per slot */
|
|
uint32_t p = 7, k, ok = host_wire[5] == FM6_NFACTORY && host_wire[6] == FM6_BANK_N, named = 0;
|
|
for (k = 0; k < FM6_NFACTORY + FM6_BANK_N && p < n; k++) {
|
|
uint32_t used = host_wire[p++];
|
|
if (k == FM6_NFACTORY + 4u) named = used && !memcmp(host_wire + p, "MY PATCH", 9);
|
|
if (k < FM6_NFACTORY) ok &= used == 1u;
|
|
while (host_wire[p]) p++;
|
|
p++;
|
|
}
|
|
bad += check("FM6_LIST: 8 factory names, the bank's used slots by name", ok && named && k == FM6_NSLOT);
|
|
}
|
|
trk[1].eng_req = ENGI_FM6;
|
|
trk[1].p[P_E7] = FM6_NFACTORY + 4;
|
|
fm6_poll();
|
|
bad += check("PTCH B5 loads the bank patch into the track", !memcmp(fm6_patch[1] + FP_NAME, "MY PATCH ", 10));
|
|
a[0] = 4;
|
|
n = request(ED_FM6_ERASE, a, 1);
|
|
bad += check("FM6_ERASE B5: empty; PTCH B5 plays the init voice", host_wire[6] == 0 && !fm6_bank_used(4) &&
|
|
(fm6_poll(), !memcmp(fm6_patch[1] + FP_NAME, "INIT VOICE", 10)));
|
|
a[0] = ED_FM6_TRACK; a[1] = 4;
|
|
request(ED_FM6_PUT, a, sizeof a);
|
|
i = host_wire[7];
|
|
request(ED_FM6_PUT, a, 20);
|
|
bad += check("FM6_PUT: a fifth track or a short record: rc 1", i == 1u && host_wire[7] == 1u);
|
|
a[0] = ED_FM6_BANK; a[1] = FM6_BANK_N;
|
|
request(ED_FM6_GET, a, 2);
|
|
bad += check("FM6_GET past the bank: rc 1", host_wire[7] == 1u);
|
|
return bad;
|
|
}
|
|
|
|
/* UP_PUT -> UP_GET: every value round-trips through the v4 record (a byte each), negative ones too */
|
|
static int user_preset_roundtrip(void)
|
|
{
|
|
static uint8_t a[16 + 2u * P_COUNT + 32u];
|
|
int16_t want[P_COUNT], got[P_COUNT];
|
|
uint32_t k = 0, i, p, ok;
|
|
int bad = 0;
|
|
reset();
|
|
a[k++] = 3; a[k++] = 0; /* slot U04, ANALOG */
|
|
memcpy(a + k, "ROUND", 5); k += 5; a[k++] = 0;
|
|
for (i = 0; i < P_COUNT; i++) {
|
|
const param_desc_t *d = param_desc_of(0, i);
|
|
int16_t v = d->def;
|
|
uint32_t u;
|
|
if (i == P_LEVEL) v = 90;
|
|
if (i == P_PAN) v = -20;
|
|
if (i == P_ED_FLT) v = -40;
|
|
if (i == P_LD_FLT) v = d->min;
|
|
if (i == P_E1) v = d->max;
|
|
want[i] = v; u = (uint32_t)(v + 8192);
|
|
a[k++] = u & 127u; a[k++] = (u >> 7) & 127u;
|
|
}
|
|
for (i = 0; i < 16u; i++) { a[k++] = i & 1u ? 0u : (uint8_t)(48u + i); a[k++] = 0; }
|
|
request(ED_UP_PUT, a, k);
|
|
bad += check("UP_PUT stores a v4 record (no flash here: kept in RAM)",
|
|
host_wire[6] != 1u && up_used(3) && up_rec(3)->ver == UP_VER);
|
|
up_values(up_rec(3), got);
|
|
for (i = 0, ok = 1; i < P_COUNT; i++) ok &= got[i] == want[i];
|
|
bad += check("UP_PUT keeps every value (PAN -20, FLT -40, min and max)", ok);
|
|
a[0] = 3;
|
|
request(ED_UP_GET, a, 1);
|
|
ok = host_wire[5] == 3 && host_wire[6] == 1 && host_wire[7] == 0 && !memcmp(host_wire + 8, "ROUND", 6);
|
|
for (i = 0, p = 14; i < P_COUNT; i++, p += 2u)
|
|
ok &= (int32_t)(host_wire[p] | host_wire[p + 1] << 7) - 8192 == want[i];
|
|
for (i = 0; i < 16u; i++, p += 2u)
|
|
ok &= host_wire[p] == (i & 1u ? 0u : 48u + i);
|
|
bad += check("UP_GET returns the values and the pattern UP_PUT sent", ok);
|
|
return bad;
|
|
}
|
|
|
|
/* the frames of cmd in host_wire: how many, and the args of the last (into *args) */
|
|
static uint32_t wire_frames(uint32_t cmd, const uint8_t **args)
|
|
{
|
|
uint32_t i, k = 0;
|
|
for (i = 0; i + 5u < host_wire_n; i++)
|
|
if (host_wire[i] == 0xF0 && host_wire[i + 1] == ED_HDR0 && host_wire[i + 4] == cmd) {
|
|
k++;
|
|
if (args) *args = host_wire + i + 5;
|
|
}
|
|
return k;
|
|
}
|
|
static uint32_t sync_pass(void) /* one main-loop pass of the pushes */
|
|
{
|
|
host_wire_n = 0;
|
|
fm1_ms += 30u;
|
|
ed_sync();
|
|
host_drain();
|
|
return host_wire_n;
|
|
}
|
|
|
|
/* #65: WATCH while watching keeps what is not pushed yet; the editor's own sound load is not echoed as RELOAD */
|
|
static int live_sync(void)
|
|
{
|
|
int bad = 0;
|
|
uint8_t a[4] = {1, 0, 0, 0};
|
|
uint32_t i, other = 0;
|
|
const uint8_t *x = 0;
|
|
reset();
|
|
usb.resets = 0;
|
|
request(ED_WATCH, a, 1);
|
|
bad += check("WATCH 1 starts watching", host_wire[5] == 1 && ed_w.on && !sync_pass());
|
|
TSEL->p[P_LEVEL] = 77; /* a device change, not pushed yet */
|
|
request(ED_WATCH, a, 1);
|
|
bad += check("WATCH 1 while watching keeps a pending change: CHANGED still goes out",
|
|
sync_pass() && wire_frames(ED_CHANGED, &x) == 1u && x[1] == P_LEVEL && ed_rv(x + 2) == 77);
|
|
TSEL->p[P_LEVEL] = 66;
|
|
a[0] = 0; request(ED_WATCH, a, 1);
|
|
a[0] = 1; request(ED_WATCH, a, 1);
|
|
bad += check("WATCH 0 then WATCH 1 starts from the values as they are (no push)", !sync_pass());
|
|
TSEL->p[P_LEVEL] = 55; trk[1].p[P_PAN] = 3;
|
|
a[0] = 3; request(ED_WATCH, a, 1);
|
|
sync_pass();
|
|
bad += check("WATCH 3 while watching: CHANGED kept, TRACK_CHANGED from the mix as it is",
|
|
host_wire_n && wire_frames(ED_CHANGED, 0) == 1u && !wire_frames(ED_TRACK_CHANGED, 0) && ed_w.v4);
|
|
usb.resets++;
|
|
TSEL->p[P_LEVEL] = 44;
|
|
request(ED_WATCH, a, 1);
|
|
bad += check("WATCH after a USB reset starts over", !sync_pass());
|
|
|
|
/* PRESET */
|
|
TSEL->p[P_LEVEL] = 33; /* pending; a sound load keeps P_LEVEL */
|
|
a[0] = 0; a[1] = 2;
|
|
request(ED_PRESET, a, 2);
|
|
sync_pass();
|
|
bad += check("the editor's own PRESET: no RELOAD, no CHANGED for what it loaded, a pending CHANGED stays",
|
|
TSEL->preset == 2 && !wire_frames(ED_RELOAD, 0) && wire_frames(ED_CHANGED, &x) == 1u &&
|
|
x[1] == P_LEVEL && !sync_pass());
|
|
for (i = 0; i < 3u; i++) { /* any preset of any engine */
|
|
a[0] = (uint8_t)(i ? 12u : 4u); a[1] = (uint8_t)i;
|
|
request(ED_PRESET, a, 2);
|
|
other += sync_pass() != 0;
|
|
}
|
|
bad += check("PRESET of other engines: no push at all", !other && ed_w.eng == ed_eng(TSEL));
|
|
a[0] = 1; a[1] = G_ENGSEL; a[2] = (8192 + 5) & 127; a[3] = (8192 + 5) >> 7;
|
|
request(ED_SET, a, 4);
|
|
bad += check("SET of G_ENGSEL: no RELOAD", ed_eng(TSEL) == 5u && !sync_pass());
|
|
sync_reload = 1; /* a load on the device, not pushed yet */
|
|
a[0] = 0; a[1] = 1;
|
|
request(ED_PRESET, a, 2);
|
|
sync_pass();
|
|
bad += check("a RELOAD due before the editor's PRESET still goes out", wire_frames(ED_RELOAD, 0) == 1u);
|
|
a[0] = 0; request(ED_WATCH, a, 1);
|
|
sync_reload = 0;
|
|
a[0] = 0; a[1] = 3;
|
|
request(ED_PRESET, a, 2);
|
|
a[0] = 1; request(ED_WATCH, a, 1);
|
|
bad += check("not watching: PRESET as before, WATCH then starts from it", !sync_pass() && TSEL->preset == 3);
|
|
return bad;
|
|
}
|
|
|
|
/* #64: SysEx through the USB packet path (ep1_take) at full speed: a 256-byte BACKUP_PUT piece (293 pack7 bytes, 101
|
|
* event packets, 7 USB packets) arrives whole; one request at a time always works, a frame sent before the reply
|
|
* to the one before is dropped whole (no reply; never a partial frame) */
|
|
static uint32_t usb_frame(const uint8_t *f, uint32_t n, uint8_t *usbp) /* F0..F7 -> USB-MIDI event packets */
|
|
{
|
|
uint32_t i = 0, o = 0;
|
|
while (i < n) {
|
|
uint32_t k = n - i >= 3u ? 3u : n - i, cin = k == 3u && i + 3u < n ? 4u : k == 3u ? 7u : 4u + k;
|
|
usbp[o++] = (uint8_t)cin;
|
|
usbp[o++] = f[i];
|
|
usbp[o++] = k > 1u ? f[i + 1] : 0;
|
|
usbp[o++] = k > 2u ? f[i + 2] : 0;
|
|
i += k;
|
|
}
|
|
return o;
|
|
}
|
|
static uint32_t usb_feed(const uint8_t *p, uint32_t n) /* whole 64-byte USB packets, as the host sends them */
|
|
{
|
|
uint32_t o, refused = 0;
|
|
for (o = 0; o < n; o += 64u)
|
|
while (!ep1_take(p + o, n - o > 64u ? 64u : n - o))
|
|
refused++; /* NAK: the host sends it again */
|
|
return refused;
|
|
}
|
|
static uint32_t put_frame(uint8_t *f, uint32_t op, uint32_t off, uint32_t count)
|
|
{
|
|
static const uint8_t zero[256];
|
|
uint32_t n = 0, i;
|
|
f[n++] = 0xF0; f[n++] = ED_HDR0; f[n++] = ED_HDR1; f[n++] = ED_HDR2; f[n++] = ED_BACKUP_PUT;
|
|
f[n++] = (uint8_t)op; f[n++] = 2;
|
|
if (op == 0u) {
|
|
for (i = 0; i < 5u; i++) f[n++] = (uint8_t)((sizeof(project_store_t) >> (7u * i)) & (i == 4u ? 15u : 127u));
|
|
for (i = 0; i < 5u; i++) f[n++] = 0;
|
|
} else if (op == 1u) {
|
|
for (i = 0; i < 5u; i++) f[n++] = (uint8_t)((off >> (7u * i)) & (i == 4u ? 15u : 127u));
|
|
n += pack7(zero, count, f + n);
|
|
}
|
|
f[n++] = 0xF7;
|
|
return n;
|
|
}
|
|
static int usb_burst(void)
|
|
{
|
|
static uint8_t f[700], u[1000], u2[2000];
|
|
uint32_t off, n, k, ok = 1, max = 0;
|
|
const uint8_t *x = 0;
|
|
int bad = 0;
|
|
reset();
|
|
usb.rx_pend = 0;
|
|
n = put_frame(f, 0, 0, 0);
|
|
usb_feed(u, usb_frame(f, n, u)); host_wire_n = 0; ed_service(); host_drain();
|
|
bad += check("BACKUP_PUT begin through ep1_take", wire_frames(ED_BACKUP_PUT, &x) == 1u && !x[2]);
|
|
for (off = 0; off < sizeof(project_store_t); off += 256u) {
|
|
uint32_t c = sizeof(project_store_t) - off > 256u ? 256u : sizeof(project_store_t) - off;
|
|
n = put_frame(f, 1, off, c);
|
|
if (n > max) max = n;
|
|
k = usb_frame(f, n, u);
|
|
usb_feed(u, k);
|
|
host_wire_n = 0; ed_service(); host_drain();
|
|
ok &= wire_frames(ED_BACKUP_PUT, &x) == 1u && !x[2] && sx_ready == 0;
|
|
}
|
|
bad += check("256-byte pieces in 64-byte USB packets at full speed: every piece taken (rc 0)",
|
|
ok && ed_bk_pos == sizeof(project_store_t) && max == 4u + 1u + 7u + 293u + 1u && max <= sizeof sx_frame);
|
|
n = put_frame(f, 3, 0, 0);
|
|
usb_feed(u, usb_frame(f, n, u)); host_wire_n = 0; ed_service(); host_drain();
|
|
bad += check("abort through ep1_take", wire_frames(ED_BACKUP_PUT, &x) == 1u && !x[2] && !ed_bk_put);
|
|
|
|
/* two frames back to back, before the reply: the second is dropped whole, the first answered intact */
|
|
n = put_frame(f, 0, 0, 0);
|
|
usb_feed(u, usb_frame(f, n, u)); host_wire_n = 0; ed_service(); host_drain();
|
|
k = usb_frame(f, put_frame(f, 1, 0, 256), u2);
|
|
k += usb_frame(f, put_frame(f, 1, 256, 256), u2 + k);
|
|
usb_feed(u2, k);
|
|
host_wire_n = 0; ed_service(); ed_service(); host_drain();
|
|
bad += check("pipelined: the first piece is taken, the second (sent before its reply) dropped whole",
|
|
wire_frames(ED_BACKUP_PUT, &x) == 1u && !x[2] && ed_bk_pos == 256u && !sx_ready);
|
|
n = put_frame(f, 1, 512, 256);
|
|
usb_feed(u, usb_frame(f, n, u)); host_wire_n = 0; ed_service(); host_drain();
|
|
bad += check("... so the next piece is refused (rc 1, offset), as a host that waits never sees",
|
|
wire_frames(ED_BACKUP_PUT, &x) == 1u && x[2] == 1u && ed_bk_pos == 256u);
|
|
request(ED_BACKUP_PUT, (const uint8_t[]){3, 2}, 2);
|
|
return bad;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int bad = preferences() + framing() + uart_recovery() + steps() + samples() + song_protocol() + malformed_saves() +
|
|
fm6_patches() + user_preset_roundtrip() + live_sync() + usb_burst();
|
|
printf("%s\n", bad ? "EDITOR TEST FAILED" : "editor test passed");
|
|
return bad != 0;
|
|
}
|