Something went wrong. Try again.
A Playstation One (PS1) emulator fully written in Jam
Something went wrong. Try again.
jamstation spu.jam
38 kB · 971 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972// SPDX-License-Identifier: MIT// Copyright (c) 2026 Raphael Amorim
const { irqRaise, IC_SPU } = import("irq");
const { Vec } = import("std/collections");
const SPU_REG_SIZE: u32 = 0x400;const VS_SIZE: u32 = 256;const VOICE_COUNT: u32 = 24;const VOICE_BASE: u32 = 0x400;const GLOBAL_BASE: u32 = 0x400 + 24 * 256;const CD_FIFO_BASE: u32 = 0x1D00;const CD_FIFO_CAP: u32 = 1024;const CD_FIFO_MASK: u32 = 1023;const SPU_GAUSS_OFF: u32 = 0x6D00;const SPU_STATE_SIZE: u32 = 0x6D00 + 1024;const SPU_RAM_SIZE: u32 = 0x80000;
const VR_VOLUMEL: u32 = 0x0;const VR_VOLUMER: u32 = 0x2;const VR_ADSAMPR: u32 = 0x4;const VR_ADSADDR: u32 = 0x6;const VR_ENVCTL1: u32 = 0x8;const VR_ENVCTL2: u32 = 0xA;const VR_ENVCVOL: u32 = 0xC;const VR_ADRADDR: u32 = 0xE;
const R_MAINLVOL: u32 = 0x180;const R_MAINRVOL: u32 = 0x182;const R_VLOUT: u32 = 0x184;const R_VROUT: u32 = 0x186;const R_KONL: u32 = 0x188;const R_KONH: u32 = 0x18A;const R_KOFFL: u32 = 0x18C;const R_KOFFH: u32 = 0x18E;const R_PMONL: u32 = 0x190;const R_PMONH: u32 = 0x192;const R_NONL: u32 = 0x194;const R_NONH: u32 = 0x196;const R_EONL: u32 = 0x198;const R_EONH: u32 = 0x19A;const R_ENDXL: u32 = 0x19C;const R_ENDXH: u32 = 0x19E;const R_MBASE: u32 = 0x1A2;const R_IRQADDR: u32 = 0x1A4;const R_TADDR: u32 = 0x1A6;const R_TFIFO: u32 = 0x1A8;const R_SPUCNT: u32 = 0x1AA;const R_TCTRL: u32 = 0x1AC;const R_SPUSTAT: u32 = 0x1AE;const R_CDVOLL: u32 = 0x1B0;const R_CDVOLR: u32 = 0x1B2;
const R_DAPF1: u32 = 0x1C0;const R_DAPF2: u32 = 0x1C2;const R_VIIR: u32 = 0x1C4;const R_VCOMB1: u32 = 0x1C6;const R_VCOMB2: u32 = 0x1C8;const R_VCOMB3: u32 = 0x1CA;const R_VCOMB4: u32 = 0x1CC;const R_VWALL: u32 = 0x1CE;const R_VAPF1: u32 = 0x1D0;const R_VAPF2: u32 = 0x1D2;const R_MLSAME: u32 = 0x1D4;const R_MRSAME: u32 = 0x1D6;const R_MLCOMB1: u32 = 0x1D8;const R_MRCOMB1: u32 = 0x1DA;const R_MLCOMB2: u32 = 0x1DC;const R_MRCOMB2: u32 = 0x1DE;const R_DLSAME: u32 = 0x1E0;const R_DRSAME: u32 = 0x1E2;const R_MLDIFF: u32 = 0x1E4;const R_MRDIFF: u32 = 0x1E6;const R_MLCOMB3: u32 = 0x1E8;const R_MRCOMB3: u32 = 0x1EA;const R_MLCOMB4: u32 = 0x1EC;const R_MRCOMB4: u32 = 0x1EE;const R_DLDIFF: u32 = 0x1F0;const R_DRDIFF: u32 = 0x1F2;const R_MLAPF1: u32 = 0x1F4;const R_MRAPF1: u32 = 0x1F6;const R_MLAPF2: u32 = 0x1F8;const R_MRAPF2: u32 = 0x1FA;const R_VLIN: u32 = 0x1FC;const R_VRIN: u32 = 0x1FE;
const D_PLAYING: u32 = 0x00;const D_COUNTER: u32 = 0x04;const D_CURADDR: u32 = 0x08;const D_REPADDR: u32 = 0x0C;const D_PREVSI: u32 = 0x10;const D_S0: u32 = 0x14;const D_S1: u32 = 0x18;const D_S2: u32 = 0x1C;const D_S3: u32 = 0x20;const D_BFLAGS: u32 = 0x24;const D_BUF0: u32 = 0x28;const D_H0: u32 = 0x60;const D_H1: u32 = 0x64;const D_LVOL: u32 = 0x68;const D_RVOL: u32 = 0x6C;const D_CVOL: u32 = 0x70;const D_APHASE: u32 = 0x74;const D_ACYRELOAD: u32 = 0x78;const D_ACYCLES: u32 = 0x7C;const D_AMODE: u32 = 0x80;const D_ADIR: u32 = 0x84;const D_ASHIFT: u32 = 0x88;const D_ASTEP: u32 = 0x8C;const D_APENDSTEP: u32 = 0x90;const D_ASUSLVL: u32 = 0x94;const D_ENVCTL: u32 = 0x98;
const G_TADDR: u32 = 0x00;const G_TFIFO: u32 = 0x04;const G_TFIFO_IDX: u32 = 0x44;const G_EVEN_CYC: u32 = 0x48;const G_REVBADDR: u32 = 0x4C;const G_LRSL: u32 = 0x50;const G_LRSR: u32 = 0x54;const G_CD_HEAD: u32 = 0x60;const G_CD_TAIL: u32 = 0x64;const G_NOISE_LEVEL: u32 = 0x70;const G_NOISE_COUNT: u32 = 0x74;
const ADSR_ATTACK: u32 = 0;const ADSR_DECAY: u32 = 1;const ADSR_SUSTAIN: u32 = 2;const ADSR_RELEASE: u32 = 3;const ADSR_END: u32 = 4;
const ADPCM_POS_0: i32 = 0;const ADPCM_POS_1: i32 = 60;const ADPCM_POS_2: i32 = 115;const ADPCM_POS_3: i32 = 98;const ADPCM_POS_4: i32 = 122;const ADPCM_NEG_0: i32 = 0;const ADPCM_NEG_1: i32 = 0;const ADPCM_NEG_2: i32 = -52;const ADPCM_NEG_3: i32 = -55;const ADPCM_NEG_4: i32 = -60;
pub fn adpcmPos(f: u32) i32 { match (f) { 1 { return ADPCM_POS_1; } 2 { return ADPCM_POS_2; } 3 { return ADPCM_POS_3; } 4 { return ADPCM_POS_4; } _ { return ADPCM_POS_0; } }}pub fn adpcmNeg(f: u32) i32 { match (f) { 2 { return ADPCM_NEG_2; } 3 { return ADPCM_NEG_3; } 4 { return ADPCM_NEG_4; } _ { return 0; } }}
fn noiseFreqAdd(step: u32) u32 { match (step) { 1 { return 84; } 2 { return 140; } 3 { return 180; } _ { return 0; } }}
fn noiseWaveAdd(idx: u32) u32 { const j: u32 = idx & 7; if ((idx & 0x20) != 0) { return (0x96 >> j) & 1; } return (0x69 >> j) & 1;}
fn spuStepNoise(s: *mut[] u8, spucnt: u32) { const shift: u32 = (spucnt >> 10) & 0xF; const step: u32 = (spucnt >> 8) & 3; const freq: u32 = (0x8000 >> shift) << 16; var count: u32 = getU32(s, GLOBAL_BASE + G_NOISE_COUNT); count = count + 0x10000 + noiseFreqAdd(step); if ((count & 0xFFFF) >= 210) { count = count + 0x10000 - noiseFreqAdd(step); } if (count >= freq) { count = count & (freq - 1); var level: u32 = getU16(s, GLOBAL_BASE + G_NOISE_LEVEL); level = (level << 1) | noiseWaveAdd((level >> 10) & 0x3F); setU16(s, GLOBAL_BASE + G_NOISE_LEVEL, level & 0xFFFF); } setU32(s, GLOBAL_BASE + G_NOISE_COUNT, count);}
pub fn createSpu() Vec(u8) { var b: Vec(u8) = Vec(u8).filled(0, SPU_STATE_SIZE); var p: *mut[] u8 = b.ptr; setU16(p, R_ENDXL, 0xFFFF); setU16(p, R_ENDXH, 0x00FF); setU16(p, R_IRQADDR, 0xFFFF); spuGaussInit(p); return b;}
pub fn createSpuRam() Vec(u8) { return Vec(u8).filled(0, SPU_RAM_SIZE); }
pub fn spuPushCdSample(s: *mut[] u8, leftI16: u32, rightI16: u32) { const head: u32 = getU32(s, GLOBAL_BASE + G_CD_HEAD); const tail: u32 = getU32(s, GLOBAL_BASE + G_CD_TAIL); if ((head - tail) >= CD_FIFO_CAP) { return; } const slot: u32 = CD_FIFO_BASE + ((head & CD_FIFO_MASK) << 2); setU16(s, slot, leftI16 & 0xFFFF); setU16(s, slot + 2, rightI16 & 0xFFFF); setU32(s, GLOBAL_BASE + G_CD_HEAD, head + 1);}
pub fn sat16i32(v: i32) i32 { if (v < -32768) { return -32768; } if (v > 32767) { return 32767; } return v;}
pub fn mulVol(v: i32, vol: i32) i32 { return (v * vol) >> 15;}
pub fn spuReadReverb(s: *mut[] u8, ram: *mut[] u8, addr: u32) i32 { const mbase: u32 = getU16(s, R_MBASE) << 3; const revb: u32 = getU32(s, GLOBAL_BASE + G_REVBADDR); const span: u32 = 0x80000 - mbase; var rel: u32 = (addr + revb - mbase); rel = rel % span; const wrapped: u32 = (mbase + rel) & 0x7FFFE; var w: u32 = (ram[wrapped] as u32) | ((ram[wrapped + 1] as u32) << 8); if ((w & 0x8000) != 0) { w = w | 0xFFFF0000; } return w as i32;}
pub fn spuWriteReverb(s: *mut[] u8, ram: *mut[] u8, addr: u32, v: i32) { const mbase: u32 = getU16(s, R_MBASE) << 3; const revb: u32 = getU32(s, GLOBAL_BASE + G_REVBADDR); const span: u32 = 0x80000 - mbase; var rel: u32 = (addr + revb - mbase); rel = rel % span; const wrapped: u32 = (mbase + rel) & 0x7FFFE; const w: u32 = (v as u32) & 0xFFFF; ram[wrapped] = (w & 0xFF) as u8; ram[wrapped + 1] = ((w >> 8) & 0xFF) as u8;}
pub fn spuGetReverbSample(s: *mut[] u8, ram: *mut[] u8, inL: i32, inR: i32) u32 { const dapf1: u32 = (getU16(s, R_DAPF1)) << 3; const dapf2: u32 = (getU16(s, R_DAPF2)) << 3; const mlsame: u32 = (getU16(s, R_MLSAME)) << 3; const mrsame: u32 = (getU16(s, R_MRSAME)) << 3; const dlsame: u32 = (getU16(s, R_DLSAME)) << 3; const drsame: u32 = (getU16(s, R_DRSAME)) << 3; const mldiff: u32 = (getU16(s, R_MLDIFF)) << 3; const mrdiff: u32 = (getU16(s, R_MRDIFF)) << 3; const dldiff: u32 = (getU16(s, R_DLDIFF)) << 3; const drdiff: u32 = (getU16(s, R_DRDIFF)) << 3; const mlcomb1: u32 = (getU16(s, R_MLCOMB1)) << 3; const mlcomb2: u32 = (getU16(s, R_MLCOMB2)) << 3; const mlcomb3: u32 = (getU16(s, R_MLCOMB3)) << 3; const mlcomb4: u32 = (getU16(s, R_MLCOMB4)) << 3; const mrcomb1: u32 = (getU16(s, R_MRCOMB1)) << 3; const mrcomb2: u32 = (getU16(s, R_MRCOMB2)) << 3; const mrcomb3: u32 = (getU16(s, R_MRCOMB3)) << 3; const mrcomb4: u32 = (getU16(s, R_MRCOMB4)) << 3; const mlapf1: u32 = (getU16(s, R_MLAPF1)) << 3; const mlapf2: u32 = (getU16(s, R_MLAPF2)) << 3; const mrapf1: u32 = (getU16(s, R_MRAPF1)) << 3; const mrapf2: u32 = (getU16(s, R_MRAPF2)) << 3;
const vlin: i32 = getI16(s, R_VLIN); const vrin: i32 = getI16(s, R_VRIN); const viir: i32 = getI16(s, R_VIIR); const vwall: i32 = getI16(s, R_VWALL); const vcomb1: i32 = getI16(s, R_VCOMB1); const vcomb2: i32 = getI16(s, R_VCOMB2); const vcomb3: i32 = getI16(s, R_VCOMB3); const vcomb4: i32 = getI16(s, R_VCOMB4); const vapf1: i32 = getI16(s, R_VAPF1); const vapf2: i32 = getI16(s, R_VAPF2); const vlout: i32 = getI16(s, R_VLOUT); const vrout: i32 = getI16(s, R_VROUT);
const lin: i32 = mulVol(inL, vlin); const rin: i32 = mulVol(inR, vrin);
const sLsamePrev: i32 = spuReadReverb(s, ram, mlsame - 2); const sRsamePrev: i32 = spuReadReverb(s, ram, mrsame - 2); const sLsameNow: i32 = sat16i32(lin + mulVol(spuReadReverb(s, ram, dlsame), vwall) - mulVol(sLsamePrev, viir) + sLsamePrev); const sRsameNow: i32 = sat16i32(rin + mulVol(spuReadReverb(s, ram, drsame), vwall) - mulVol(sRsamePrev, viir) + sRsamePrev); spuWriteReverb(s, ram, mlsame, sLsameNow); spuWriteReverb(s, ram, mrsame, sRsameNow);
const sLdiffPrev: i32 = spuReadReverb(s, ram, mldiff - 2); const sRdiffPrev: i32 = spuReadReverb(s, ram, mrdiff - 2); const sLdiffNow: i32 = sat16i32(lin + mulVol(spuReadReverb(s, ram, drdiff), vwall) - mulVol(sLdiffPrev, viir) + sLdiffPrev); const sRdiffNow: i32 = sat16i32(rin + mulVol(spuReadReverb(s, ram, dldiff), vwall) - mulVol(sRdiffPrev, viir) + sRdiffPrev); spuWriteReverb(s, ram, mldiff, sLdiffNow); spuWriteReverb(s, ram, mrdiff, sRdiffNow);
var l: i32 = sat16i32( mulVol(spuReadReverb(s, ram, mlcomb1), vcomb1) + mulVol(spuReadReverb(s, ram, mlcomb2), vcomb2) + mulVol(spuReadReverb(s, ram, mlcomb3), vcomb3) + mulVol(spuReadReverb(s, ram, mlcomb4), vcomb4)); var r: i32 = sat16i32( mulVol(spuReadReverb(s, ram, mrcomb1), vcomb1) + mulVol(spuReadReverb(s, ram, mrcomb2), vcomb2) + mulVol(spuReadReverb(s, ram, mrcomb3), vcomb3) + mulVol(spuReadReverb(s, ram, mrcomb4), vcomb4));
l = sat16i32(l - sat16i32(mulVol(spuReadReverb(s, ram, mlapf1 - dapf1), vapf1))); r = sat16i32(r - sat16i32(mulVol(spuReadReverb(s, ram, mrapf1 - dapf1), vapf1))); spuWriteReverb(s, ram, mlapf1, l); spuWriteReverb(s, ram, mrapf1, r); l = sat16i32(mulVol(l, vapf1) + spuReadReverb(s, ram, mlapf1 - dapf1)); r = sat16i32(mulVol(r, vapf1) + spuReadReverb(s, ram, mrapf1 - dapf1));
l = sat16i32(l - sat16i32(mulVol(spuReadReverb(s, ram, mlapf2 - dapf2), vapf2))); r = sat16i32(r - sat16i32(mulVol(spuReadReverb(s, ram, mrapf2 - dapf2), vapf2))); spuWriteReverb(s, ram, mlapf2, l); spuWriteReverb(s, ram, mrapf2, r); l = sat16i32(mulVol(l, vapf2) + spuReadReverb(s, ram, mlapf2 - dapf2)); r = sat16i32(mulVol(r, vapf2) + spuReadReverb(s, ram, mrapf2 - dapf2));
const outL: i32 = sat16i32(mulVol(l, vlout)); const outR: i32 = sat16i32(mulVol(r, vrout));
const mbase: u32 = getU16(s, R_MBASE) << 3; var revb: u32 = getU32(s, GLOBAL_BASE + G_REVBADDR); revb = (revb + 2) & 0x7FFFE; if (revb < mbase) { revb = mbase; } setU32(s, GLOBAL_BASE + G_REVBADDR, revb);
return ((outL as u32) & 0xFFFF) | (((outR as u32) & 0xFFFF) << 16);}
pub fn spuPopCdSample(s: *mut[] u8) u32 { const head: u32 = getU32(s, GLOBAL_BASE + G_CD_HEAD); const tail: u32 = getU32(s, GLOBAL_BASE + G_CD_TAIL); if (head == tail) { return 0; } const slot: u32 = CD_FIFO_BASE + ((tail & CD_FIFO_MASK) << 2); const l: u32 = getU16(s, slot); const r: u32 = getU16(s, slot + 2); setU32(s, GLOBAL_BASE + G_CD_TAIL, tail + 1); return l | (r << 16);}
pub fn getU16(s: *mut[] u8, off: u32) u32 { return (s[off] as u32) | ((s[off + 1] as u32) << 8);}pub fn setU16(s: *mut[] u8, off: u32, v: u32) { s[off] = (v & 0xFF) as u8; s[off + 1] = ((v >> 8) & 0xFF) as u8;}pub fn getU32(s: *mut[] u8, off: u32) u32 { return (s[off] as u32) | ((s[off + 1] as u32) << 8) | ((s[off + 2] as u32) << 16) | ((s[off + 3] as u32) << 24);}pub fn setU32(s: *mut[] u8, off: u32, v: u32) { s[off] = (v & 0xFF) as u8; s[off + 1] = ((v >> 8) & 0xFF) as u8; s[off + 2] = ((v >> 16) & 0xFF) as u8; s[off + 3] = ((v >> 24) & 0xFF) as u8;}pub fn getI16(s: *mut[] u8, off: u32) i32 { const u: u32 = getU16(s, off); if ((u & 0x8000) != 0) { return (u | 0xFFFF0000) as i32; } return u as i32;}pub fn setI16(s: *mut[] u8, off: u32, v: i32) { setU16(s, off, (v as u32) & 0xFFFF);}pub fn getI32(s: *mut[] u8, off: u32) i32 { return getU32(s, off) as i32; }pub fn setI32(s: *mut[] u8, off: u32, v: i32) { setU32(s, off, v as u32); }
pub fn voiceRegBase(v: u32) u32 { return v * 0x10; }pub fn voiceRTBase(v: u32) u32 { return VOICE_BASE + v * VS_SIZE; }
pub fn endx(s: *mut[] u8) u32 { return getU16(s, R_ENDXL) | (getU16(s, R_ENDXH) << 16);}pub fn setEndx(s: *mut[] u8, v: u32) { setU16(s, R_ENDXL, v & 0xFFFF); setU16(s, R_ENDXH, (v >> 16) & 0xFF);}
pub fn sat16(v: i32) i32 { if (v < -32768) { return -32768; } if (v > 32767) { return 32767; } return v;}
pub fn wrap16(v: i32) i32 { return ((v & 0xFFFF) ^ 0x8000) - 0x8000;}pub fn clamp7fff(v: i32) i32 { if (v < 0) { return 0; } if (v > 0x7FFF) { return 0x7FFF; } return v;}pub fn maxI(a: i32, b: i32) i32 { if (a > b) { return a; } return b; }
pub fn spuReadBlock(s: *mut[] u8, ram: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); const addr: u32 = getU32(s, base + D_CURADDR); const hdr: u32 = ram[addr] as u32; setU32(s, base + D_BFLAGS, ram[addr + 1] as u32);
var hdrShift: u32 = hdr & 0xF; if (hdrShift > 12) { hdrShift = 9; } const shift: u32 = 12 - hdrShift; const filter: u32 = (hdr >> 4) & 7;
const f0: i32 = adpcmPos(filter); const f1: i32 = adpcmNeg(filter);
var h0: i32 = getI32(s, base + D_H0); var h1: i32 = getI32(s, base + D_H1);
var j: u32 = 0; while (j < 28) { const byte: u32 = ram[addr + 2 + (j >> 1)] as u32; const nibble: u32 = (byte >> ((j & 1) * 4)) & 0xF; var t: i32 = nibble as i32; if ((nibble & 0x8) != 0) { t = t - 16; } const tShifted: i32 = t << shift; const pred: i32 = ((h0 * f0) + (h1 * f1) + 32) / 64; const sample: i32 = wrap16(tShifted + pred);
h1 = h0; h0 = sample; setI16(s, base + D_BUF0 + j * 2, sample); j = j + 1; }
setI32(s, base + D_H0, h0); setI32(s, base + D_H1, h1);}
pub fn adsrCalcValues(s: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); const shift: i32 = getI32(s, base + D_ASHIFT); const step: i32 = getI32(s, base + D_ASTEP); const mode: u32 = getU32(s, base + D_AMODE); const dir: u32 = getU32(s, base + D_ADIR); const level: i32 = getI32(s, base + D_CVOL);
var cycles: i32 = 1 << maxI(0, shift - 11); var stepShifted: i32 = step << maxI(0, 11 - shift);
if (mode != 0 && level > 0x6000 && dir == 0) { cycles = cycles * 4; } if (mode != 0 && dir != 0) { stepShifted = (stepShifted * level) >> 15; }
setI32(s, base + D_ACYCLES, cycles); setI32(s, base + D_ACYRELOAD, cycles); setI32(s, base + D_APENDSTEP, stepShifted);}
pub fn adsrLoadAttack(s: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); const envctl: u32 = getU32(s, base + D_ENVCTL); setU32(s, base + D_AMODE, (envctl >> 15) & 1); setU32(s, base + D_ADIR, 0); setI32(s, base + D_ASHIFT, ((envctl >> 10) & 0x1F) as i32); setI32(s, base + D_ASTEP, 7 - (((envctl >> 8) & 3) as i32)); setI32(s, base + D_CVOL, 0); setU32(s, base + D_APHASE, ADSR_ATTACK); adsrCalcValues(s, v);}
pub fn adsrLoadDecay(s: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); const envctl: u32 = getU32(s, base + D_ENVCTL); setU32(s, base + D_AMODE, 1); setU32(s, base + D_ADIR, 1); setI32(s, base + D_ASHIFT, ((envctl >> 4) & 0xF) as i32); setI32(s, base + D_ASTEP, -8); setI32(s, base + D_CVOL, 0x7FFF); setU32(s, base + D_APHASE, ADSR_DECAY); adsrCalcValues(s, v);}
pub fn adsrLoadSustain(s: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); const envctl: u32 = getU32(s, base + D_ENVCTL); setU32(s, base + D_AMODE, (envctl >> 31) & 1); setU32(s, base + D_ADIR, (envctl >> 30) & 1); setI32(s, base + D_ASHIFT, ((envctl >> 24) & 0x1F) as i32); var stepRaw: i32 = ((envctl >> 22) & 3) as i32; if (((envctl >> 30) & 1) != 0) { stepRaw = -8 + stepRaw; } else { stepRaw = 7 - stepRaw; } setI32(s, base + D_ASTEP, stepRaw); setI32(s, base + D_CVOL, getI32(s, base + D_ASUSLVL)); setU32(s, base + D_APHASE, ADSR_SUSTAIN); adsrCalcValues(s, v);}
pub fn adsrLoadRelease(s: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); const envctl: u32 = getU32(s, base + D_ENVCTL); setU32(s, base + D_AMODE, (envctl >> 21) & 1); setU32(s, base + D_ADIR, 1); setI32(s, base + D_ASHIFT, ((envctl >> 16) & 0x1F) as i32); setI32(s, base + D_ASTEP, -8); setU32(s, base + D_APHASE, ADSR_RELEASE); setEndx(s, endx(s) | (1 << v)); adsrCalcValues(s, v);}
pub fn spuHandleAdsr(s: *mut[] u8, v: u32) { const base: u32 = voiceRTBase(v); var cycles: i32 = getI32(s, base + D_ACYCLES); if (cycles > 0) { setI32(s, base + D_ACYCLES, cycles - 1); return; }
adsrCalcValues(s, v); var level: i32 = getI32(s, base + D_CVOL); level = level + getI32(s, base + D_APENDSTEP); level = clamp7fff(level);
const phase: u32 = getU32(s, base + D_APHASE); if (phase == ADSR_ATTACK) { setI32(s, base + D_CVOL, level); if (level == 0x7FFF) { adsrLoadDecay(s, v); } } else if (phase == ADSR_DECAY) { setI32(s, base + D_CVOL, level); if (level <= getI32(s, base + D_ASUSLVL)) { adsrLoadSustain(s, v); } } else if (phase == ADSR_SUSTAIN) { setI32(s, base + D_CVOL, level); } else if (phase == ADSR_RELEASE) { setI32(s, base + D_CVOL, level); if (level == 0) { setU32(s, base + D_APHASE, ADSR_END); setI32(s, base + D_ACYCLES, 0); setI32(s, base + D_APENDSTEP, 0); setU32(s, base + D_PLAYING, 0); } } else { setU32(s, base + D_PLAYING, 0); }
setU16(s, voiceRegBase(v) + VR_ENVCVOL, getI32(s, base + D_CVOL) as u32); setI32(s, base + D_ACYCLES, getI32(s, base + D_ACYRELOAD));}
pub fn spuKon(s: *mut[] u8, ram: *mut[] u8, value: u32) { var i: u32 = 0; while (i < VOICE_COUNT) { if ((value & (1 << i)) != 0) { const vr: u32 = voiceRegBase(i); const rt: u32 = voiceRTBase(i); setU32(s, rt + D_PLAYING, 1); setU32(s, rt + D_CURADDR, getU16(s, vr + VR_ADSADDR) << 3); setU32(s, rt + D_REPADDR, getU16(s, vr + VR_ADRADDR) << 3); setI32(s, rt + D_LVOL, getI16(s, vr + VR_VOLUMEL) * 2); setI32(s, rt + D_RVOL, getI16(s, vr + VR_VOLUMER) * 2); setI32(s, rt + D_ASUSLVL, (((getU16(s, vr + VR_ENVCTL1) & 0xF) + 1) * 0x800) as i32); const envctl: u32 = (getU16(s, vr + VR_ENVCTL2) << 16) | getU16(s, vr + VR_ENVCTL1); setU32(s, rt + D_ENVCTL, envctl);
adsrLoadAttack(s, i); spuReadBlock(s, ram, i); setU16(s, vr + VR_ENVCVOL, 0x7FFF); } i = i + 1; } setEndx(s, endx(s) & (~(value & 0x00FFFFFF)));}
pub fn spuKoff(s: *mut[] u8, value: u32) { var i: u32 = 0; while (i < VOICE_COUNT) { if ((value & (1 << i)) != 0) { adsrLoadRelease(s, i); } i = i + 1; }}
pub fn spuHandleWrite(s: *mut[] u8, ram: *mut[] u8, off: u32, val: u32) i32 { if (off == R_KONL || off == R_KONH) { if (val == 0) { return 1; } const high: u32 = ((off & 2) != 0) as u32; spuKon(s, ram, val << (16 * high)); return 1; } if (off == R_KOFFL || off == R_KOFFH) { if (val == 0) { return 1; } const high: u32 = ((off & 2) != 0) as u32; spuKoff(s, val << (16 * high)); return 1; } if (off == R_TADDR) { setU16(s, R_TADDR, val); setU32(s, GLOBAL_BASE + G_TADDR, val << 3); return 1; } if (off == R_TFIFO) { setU16(s, R_TFIFO, val); const idx: u32 = getU32(s, GLOBAL_BASE + G_TFIFO_IDX); setU16(s, GLOBAL_BASE + G_TFIFO + idx * 2, val); setU32(s, GLOBAL_BASE + G_TFIFO_IDX, idx + 1); if (idx + 1 == 32) { const spucnt: u32 = getU16(s, R_SPUCNT); if (((spucnt >> 4) & 3) == 2) { var ta: u32 = getU32(s, GLOBAL_BASE + G_TADDR); var i: u32 = 0; while (i < 32) { const t: u32 = getU16(s, GLOBAL_BASE + G_TFIFO + i * 2); ram[ta] = (t & 0xFF) as u8; ram[ta + 1] = ((t >> 8) & 0xFF) as u8; ta = ta + 2; i = i + 1; } setU32(s, GLOBAL_BASE + G_TADDR, ta); setU32(s, GLOBAL_BASE + G_TFIFO_IDX, 0); } } return 1; } if (off == R_SPUCNT) { setU16(s, R_SPUCNT, val); var stat: u32 = getU16(s, R_SPUSTAT); stat = (stat & 0xFFC0) | (val & 0x3F); setU16(s, R_SPUSTAT, stat); if (true) { var ta: u32 = getU32(s, GLOBAL_BASE + G_TADDR); const idx: u32 = getU32(s, GLOBAL_BASE + G_TFIFO_IDX); var i: u32 = 0; while (i < idx) { const t: u32 = getU16(s, GLOBAL_BASE + G_TFIFO + i * 2); ram[ta] = (t & 0xFF) as u8; ram[ta + 1] = ((t >> 8) & 0xFF) as u8; ta = ta + 2; i = i + 1; } setU32(s, GLOBAL_BASE + G_TADDR, ta); setU32(s, GLOBAL_BASE + G_TFIFO_IDX, 0); } return 1; } if (off == R_MBASE) { setU16(s, R_MBASE, val); setU32(s, GLOBAL_BASE + G_REVBADDR, val << 3); return 1; } return 0;}
pub fn spuReadTfifo(s: *mut[] u8, ram: *mut[] u8) u32 { var ta: u32 = getU32(s, GLOBAL_BASE + G_TADDR); const lo: u32 = ram[ta] as u32; const hi: u32 = ram[ta + 1] as u32; setU32(s, GLOBAL_BASE + G_TADDR, ta + 2); return lo | (hi << 8);}
pub fn spuRead8(s: *mut[] u8, ram: *mut[] u8, off: u32) u32 { if (off >= SPU_REG_SIZE) { return 0; } return s[off] as u32;}
pub fn spuRead16(s: *mut[] u8, ram: *mut[] u8, off: u32) u32 { if (off + 1 >= SPU_REG_SIZE) { return 0; } if (off == R_TFIFO) { return spuReadTfifo(s, ram); } return getU16(s, off);}
pub fn spuRead32(s: *mut[] u8, ram: *mut[] u8, off: u32) u32 { if (off + 3 >= SPU_REG_SIZE) { return 0; } return getU32(s, off);}
pub fn spuWrite8(s: *mut[] u8, ram: *mut[] u8, off: u32, val: u32) { if (off >= SPU_REG_SIZE) { return; } s[off] = (val & 0xFF) as u8;}
pub fn spuWrite16(s: *mut[] u8, ram: *mut[] u8, off: u32, val: u32) { if (off + 1 >= SPU_REG_SIZE) { return; } if (spuHandleWrite(s, ram, off, val & 0xFFFF) != 0) { return; } if ((off & 0xF) == 0xC && off < 0x180) { return; } setU16(s, off, val & 0xFFFF);}
pub fn spuWrite32(s: *mut[] u8, ram: *mut[] u8, off: u32, val: u32) { if (off + 3 >= SPU_REG_SIZE) { return; } if (spuHandleWrite(s, ram, off, val & 0xFFFF) != 0) { setU16(s, off + 2, (val >> 16) & 0xFFFF); return; } setU16(s, off, val & 0xFFFF); setU16(s, off + 2, (val >> 16) & 0xFFFF);}
pub fn spuGetSample(s: *mut[] u8, ram: *mut[] u8, ic: *mut[] u32, cop0: *mut[] u32) u32 { const even: u32 = getU32(s, GLOBAL_BASE + G_EVEN_CYC) ^ 1; setU32(s, GLOBAL_BASE + G_EVEN_CYC, even);
var left: i32 = 0; var right: i32 = 0;
setU16(s, R_KONL, 0); setU16(s, R_KONH, 0); setU16(s, R_KOFFL, 0); setU16(s, R_KOFFH, 0);
const pmon: u32 = getU16(s, R_PMONL) | (getU16(s, R_PMONH) << 16); const non: u32 = getU16(s, R_NONL) | (getU16(s, R_NONH) << 16); const eon: u32 = getU16(s, R_EONL) | (getU16(s, R_EONH) << 16);
const cnt0: u32 = getU16(s, R_SPUCNT); spuStepNoise(s, cnt0); const noiseLvl: i32 = getI16(s, GLOBAL_BASE + G_NOISE_LEVEL);
var revL: i32 = 0; var revR: i32 = 0; var prevOut: i32 = 0;
var v: u32 = 0; while (v < VOICE_COUNT) { var thisMod: i32 = 0; if (getU32(s, voiceRTBase(v) + D_PLAYING) != 0) { const rt: u32 = voiceRTBase(v); const vr: u32 = voiceRegBase(v);
spuHandleAdsr(s, v);
var counter: u32 = getU32(s, rt + D_COUNTER); var sampleIdx: u32 = counter >> 12;
if (sampleIdx > 27) { sampleIdx = sampleIdx - 28; counter = (counter & 0xFFF) | (sampleIdx << 12); setU32(s, rt + D_COUNTER, counter);
const flags: u32 = getU32(s, rt + D_BFLAGS); if ((flags & 4) != 0) { setU32(s, rt + D_REPADDR, getU32(s, rt + D_CURADDR)); } const lp: u32 = flags & 3; if (lp == 0 || lp == 2) { const irq9: u32 = getU16(s, R_IRQADDR) << 3; const spucnt: u32 = getU16(s, R_SPUCNT); if (irq9 == getU32(s, rt + D_CURADDR) && (spucnt & 0x40) != 0) { irqRaise(ic, cop0, IC_SPU); } setU32(s, rt + D_CURADDR, getU32(s, rt + D_CURADDR) + 0x10); if (irq9 == getU32(s, rt + D_CURADDR) && (spucnt & 0x40) != 0) { irqRaise(ic, cop0, IC_SPU); } } else if (lp == 1) { setU32(s, rt + D_CURADDR, getU32(s, rt + D_REPADDR)); setU32(s, rt + D_PLAYING, 0); setU16(s, vr + VR_ENVCVOL, 0); adsrLoadRelease(s, v); } else { setEndx(s, endx(s) | (1 << v)); setU32(s, rt + D_CURADDR, getU32(s, rt + D_REPADDR)); } spuReadBlock(s, ram, v); }
const prev: u32 = getU32(s, rt + D_PREVSI); if (prev != sampleIdx) { setI32(s, rt + D_S3, getI32(s, rt + D_S2)); setI32(s, rt + D_S2, getI32(s, rt + D_S1)); setI32(s, rt + D_S1, getI32(s, rt + D_S0)); } const cur: i32 = getI16(s, rt + D_BUF0 + sampleIdx * 2); setI32(s, rt + D_S0, cur); const gIdx: u32 = (counter >> 4) & 0xFF; const g0: i32 = spuGaussLookup(s, 0x0FF - gIdx); const g1: i32 = spuGaussLookup(s, 0x1FF - gIdx); const g2: i32 = spuGaussLookup(s, 0x100 + gIdx); const g3: i32 = spuGaussLookup(s, 0x000 + gIdx); var out: i32 = (g0 * getI32(s, rt + D_S3)) >> 15; out = out + ((g1 * getI32(s, rt + D_S2)) >> 15); out = out + ((g2 * getI32(s, rt + D_S1)) >> 15); out = out + ((g3 * cur) >> 15);
if (((non >> v) & 1) != 0) { out = noiseLvl; }
const envc: i32 = getI16(s, vr + VR_ENVCVOL); const lvol: i32 = getI32(s, rt + D_LVOL); const rvol: i32 = getI32(s, rt + D_RVOL); const sl: i32 = (((out as i64) * (lvol as i64) * (envc as i64)) >> 30) as i32; const sr: i32 = (((out as i64) * (rvol as i64) * (envc as i64)) >> 30) as i32; left = left + sl; right = right + sr; if (((eon >> v) & 1) != 0) { revL = revL + sl; revR = revR + sr; }
var step: u32 = getU16(s, vr + VR_ADSAMPR); if (v > 0 && ((pmon >> v) & 1) != 0) { const factor: i32 = prevOut + 0x8000; var sStep: i32 = step as i32; if ((step & 0x8000) != 0) { sStep = (step | 0xFFFF0000) as i32; } step = ((((sStep as i64) * (factor as i64)) >> 15) as u32) & 0xFFFF; } if (step > 0x3FFF) { step = 0x3FFF; } setU32(s, rt + D_PREVSI, counter >> 12); setU32(s, rt + D_COUNTER, counter + step);
thisMod = (((out as i64) * (envc as i64)) >> 15) as i32; } prevOut = thisMod; v = v + 1; }
const spucnt: u32 = getU16(s, R_SPUCNT); if ((spucnt & 0x4000) == 0) { const _drain: u32 = spuPopCdSample(s); return 0; }
const cd: u32 = spuPopCdSample(s); if ((spucnt & 0x0001) != 0) { var cdl: i32 = (cd & 0xFFFF) as i32; if ((cdl & 0x8000) != 0) { cdl = (cdl as u32 | 0xFFFF0000) as i32; } var cdr: i32 = ((cd >> 16) & 0xFFFF) as i32; if ((cdr & 0x8000) != 0) { cdr = (cdr as u32 | 0xFFFF0000) as i32; } const cdvL: i32 = getI16(s, R_CDVOLL); const cdvR: i32 = getI16(s, R_CDVOLR); const cdMixL: i32 = (cdl * cdvL) >> 15; const cdMixR: i32 = (cdr * cdvR) >> 15; left = left + cdMixL; right = right + cdMixR; if ((spucnt & 0x0004) != 0) { revL = revL + cdMixL; revR = revR + cdMixR; } }
if ((spucnt & 0x0080) != 0) { const even: u32 = getU32(s, GLOBAL_BASE + G_EVEN_CYC); if (even != 0) { const sl16: i32 = sat16(revL); const sr16: i32 = sat16(revR); const rv: u32 = spuGetReverbSample(s, ram, sl16, sr16); var rl: i32 = (rv & 0xFFFF) as i32; if ((rl & 0x8000) != 0) { rl = (rl as u32 | 0xFFFF0000) as i32; } var rr: i32 = ((rv >> 16) & 0xFFFF) as i32; if ((rr & 0x8000) != 0) { rr = (rr as u32 | 0xFFFF0000) as i32; } setI32(s, GLOBAL_BASE + G_LRSL, rl); setI32(s, GLOBAL_BASE + G_LRSR, rr); } left = left + getI32(s, GLOBAL_BASE + G_LRSL); right = right + getI32(s, GLOBAL_BASE + G_LRSR); }
const mainl: i32 = getI16(s, R_MAINLVOL); const mainr: i32 = getI16(s, R_MAINRVOL); const cl: i32 = (sat16(left) * mainl) >> 15; const cr: i32 = (sat16(right) * mainr) >> 15; const packed: u32 = (cl as u32 & 0xFFFF) | ((cr as u32 & 0xFFFF) << 16); return packed;}
const G_SAMPLE_ACC: u32 = 0x58;const CYC_PER_SAMPLE: u32 = 768;
pub fn spuUpdate(s: *mut[] u8, ram: *mut[] u8, ic: *mut[] u32, cop0: *mut[] u32, cyc: u32) { var acc: u32 = getU32(s, GLOBAL_BASE + G_SAMPLE_ACC) + cyc; while (acc >= CYC_PER_SAMPLE) { spuGetSample(s, ram, ic, cop0); acc = acc - CYC_PER_SAMPLE; } setU32(s, GLOBAL_BASE + G_SAMPLE_ACC, acc);}
pub fn spuGaussRow(s: *mut[] u8, off: u32, a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) { const base: u32 = SPU_GAUSS_OFF + off * 2; setI16(s, base + 0, a); setI16(s, base + 2, b); setI16(s, base + 4, c); setI16(s, base + 6, d); setI16(s, base + 8, e); setI16(s, base + 10, f); setI16(s, base + 12, g); setI16(s, base + 14, h);}
pub fn spuGaussLookup(s: *mut[] u8, idx: u32) i32 { return getI16(s, SPU_GAUSS_OFF + (idx & 0x1FF) * 2);}
pub fn spuGaussInit(s: *mut[] u8) { spuGaussRow(s, 0, -0x001, -0x001, -0x001, -0x001, -0x001, -0x001, -0x001, -0x001); spuGaussRow(s, 8, -0x001, -0x001, -0x001, -0x001, -0x001, -0x001, -0x001, -0x001); spuGaussRow(s, 16, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001); spuGaussRow(s, 24, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0002, 0x0003, 0x0003); spuGaussRow(s, 32, 0x0003, 0x0004, 0x0004, 0x0005, 0x0005, 0x0006, 0x0007, 0x0007); spuGaussRow(s, 40, 0x0008, 0x0009, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E); spuGaussRow(s, 48, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0015, 0x0016, 0x0018); spuGaussRow(s, 56, 0x0019, 0x001B, 0x001C, 0x001E, 0x0020, 0x0021, 0x0023, 0x0025); spuGaussRow(s, 64, 0x0027, 0x0029, 0x002C, 0x002E, 0x0030, 0x0033, 0x0035, 0x0038); spuGaussRow(s, 72, 0x003A, 0x003D, 0x0040, 0x0043, 0x0046, 0x0049, 0x004D, 0x0050); spuGaussRow(s, 80, 0x0054, 0x0057, 0x005B, 0x005F, 0x0063, 0x0067, 0x006B, 0x006F); spuGaussRow(s, 88, 0x0074, 0x0078, 0x007D, 0x0082, 0x0087, 0x008C, 0x0091, 0x0096); spuGaussRow(s, 96, 0x009C, 0x00A1, 0x00A7, 0x00AD, 0x00B3, 0x00BA, 0x00C0, 0x00C7); spuGaussRow(s, 104, 0x00CD, 0x00D4, 0x00DB, 0x00E3, 0x00EA, 0x00F2, 0x00FA, 0x0101); spuGaussRow(s, 112, 0x010A, 0x0112, 0x011B, 0x0123, 0x012C, 0x0135, 0x013F, 0x0148); spuGaussRow(s, 120, 0x0152, 0x015C, 0x0166, 0x0171, 0x017B, 0x0186, 0x0191, 0x019C); spuGaussRow(s, 128, 0x01A8, 0x01B4, 0x01C0, 0x01CC, 0x01D9, 0x01E5, 0x01F2, 0x0200); spuGaussRow(s, 136, 0x020D, 0x021B, 0x0229, 0x0237, 0x0246, 0x0255, 0x0264, 0x0273); spuGaussRow(s, 144, 0x0283, 0x0293, 0x02A3, 0x02B4, 0x02C4, 0x02D6, 0x02E7, 0x02F9); spuGaussRow(s, 152, 0x030B, 0x031D, 0x0330, 0x0343, 0x0356, 0x036A, 0x037E, 0x0392); spuGaussRow(s, 160, 0x03A7, 0x03BC, 0x03D1, 0x03E7, 0x03FC, 0x0413, 0x042A, 0x0441); spuGaussRow(s, 168, 0x0458, 0x0470, 0x0488, 0x04A0, 0x04B9, 0x04D2, 0x04EC, 0x0506); spuGaussRow(s, 176, 0x0520, 0x053B, 0x0556, 0x0572, 0x058E, 0x05AA, 0x05C7, 0x05E4); spuGaussRow(s, 184, 0x0601, 0x061F, 0x063E, 0x065C, 0x067C, 0x069B, 0x06BB, 0x06DC); spuGaussRow(s, 192, 0x06FD, 0x071E, 0x0740, 0x0762, 0x0784, 0x07A7, 0x07CB, 0x07EF); spuGaussRow(s, 200, 0x0813, 0x0838, 0x085D, 0x0883, 0x08A9, 0x08D0, 0x08F7, 0x091E); spuGaussRow(s, 208, 0x0946, 0x096F, 0x0998, 0x09C1, 0x09EB, 0x0A16, 0x0A40, 0x0A6C); spuGaussRow(s, 216, 0x0A98, 0x0AC4, 0x0AF1, 0x0B1E, 0x0B4C, 0x0B7A, 0x0BA9, 0x0BD8); spuGaussRow(s, 224, 0x0C07, 0x0C38, 0x0C68, 0x0C99, 0x0CCB, 0x0CFD, 0x0D30, 0x0D63); spuGaussRow(s, 232, 0x0D97, 0x0DCB, 0x0E00, 0x0E35, 0x0E6B, 0x0EA1, 0x0ED7, 0x0F0F); spuGaussRow(s, 240, 0x0F46, 0x0F7F, 0x0FB7, 0x0FF1, 0x102A, 0x1065, 0x109F, 0x10DB); spuGaussRow(s, 248, 0x1116, 0x1153, 0x118F, 0x11CD, 0x120B, 0x1249, 0x1288, 0x12C7); spuGaussRow(s, 256, 0x1307, 0x1347, 0x1388, 0x13C9, 0x140B, 0x144D, 0x1490, 0x14D4); spuGaussRow(s, 264, 0x1517, 0x155C, 0x15A0, 0x15E6, 0x162C, 0x1672, 0x16B9, 0x1700); spuGaussRow(s, 272, 0x1747, 0x1790, 0x17D8, 0x1821, 0x186B, 0x18B5, 0x1900, 0x194B); spuGaussRow(s, 280, 0x1996, 0x19E2, 0x1A2E, 0x1A7B, 0x1AC8, 0x1B16, 0x1B64, 0x1BB3); spuGaussRow(s, 288, 0x1C02, 0x1C51, 0x1CA1, 0x1CF1, 0x1D42, 0x1D93, 0x1DE5, 0x1E37); spuGaussRow(s, 296, 0x1E89, 0x1EDC, 0x1F2F, 0x1F82, 0x1FD6, 0x202A, 0x207F, 0x20D4); spuGaussRow(s, 304, 0x2129, 0x217F, 0x21D5, 0x222C, 0x2282, 0x22DA, 0x2331, 0x2389); spuGaussRow(s, 312, 0x23E1, 0x2439, 0x2492, 0x24EB, 0x2545, 0x259E, 0x25F8, 0x2653); spuGaussRow(s, 320, 0x26AD, 0x2708, 0x2763, 0x27BE, 0x281A, 0x2876, 0x28D2, 0x292E); spuGaussRow(s, 328, 0x298B, 0x29E7, 0x2A44, 0x2AA1, 0x2AFF, 0x2B5C, 0x2BBA, 0x2C18); spuGaussRow(s, 336, 0x2C76, 0x2CD4, 0x2D33, 0x2D91, 0x2DF0, 0x2E4F, 0x2EAE, 0x2F0D); spuGaussRow(s, 344, 0x2F6C, 0x2FCC, 0x302B, 0x308B, 0x30EA, 0x314A, 0x31AA, 0x3209); spuGaussRow(s, 352, 0x3269, 0x32C9, 0x3329, 0x3389, 0x33E9, 0x3449, 0x34A9, 0x3509); spuGaussRow(s, 360, 0x3569, 0x35C9, 0x3629, 0x3689, 0x36E8, 0x3748, 0x37A8, 0x3807); spuGaussRow(s, 368, 0x3867, 0x38C6, 0x3926, 0x3985, 0x39E4, 0x3A43, 0x3AA2, 0x3B00); spuGaussRow(s, 376, 0x3B5F, 0x3BBD, 0x3C1B, 0x3C79, 0x3CD7, 0x3D35, 0x3D92, 0x3DEF); spuGaussRow(s, 384, 0x3E4C, 0x3EA9, 0x3F05, 0x3F62, 0x3FBD, 0x4019, 0x4074, 0x40D0); spuGaussRow(s, 392, 0x412A, 0x4185, 0x41DF, 0x4239, 0x4292, 0x42EB, 0x4344, 0x439C); spuGaussRow(s, 400, 0x43F4, 0x444C, 0x44A3, 0x44FA, 0x4550, 0x45A6, 0x45FC, 0x4651); spuGaussRow(s, 408, 0x46A6, 0x46FA, 0x474E, 0x47A1, 0x47F4, 0x4846, 0x4898, 0x48E9); spuGaussRow(s, 416, 0x493A, 0x498A, 0x49D9, 0x4A29, 0x4A77, 0x4AC5, 0x4B13, 0x4B5F); spuGaussRow(s, 424, 0x4BAC, 0x4BF7, 0x4C42, 0x4C8D, 0x4CD7, 0x4D20, 0x4D68, 0x4DB0); spuGaussRow(s, 432, 0x4DF7, 0x4E3E, 0x4E84, 0x4EC9, 0x4F0E, 0x4F52, 0x4F95, 0x4FD7); spuGaussRow(s, 440, 0x5019, 0x505A, 0x509A, 0x50DA, 0x5118, 0x5156, 0x5194, 0x51D0); spuGaussRow(s, 448, 0x520C, 0x5247, 0x5281, 0x52BA, 0x52F3, 0x532A, 0x5361, 0x5397); spuGaussRow(s, 456, 0x53CC, 0x5401, 0x5434, 0x5467, 0x5499, 0x54CA, 0x54FA, 0x5529); spuGaussRow(s, 464, 0x5558, 0x5585, 0x55B2, 0x55DE, 0x5609, 0x5632, 0x565B, 0x5684); spuGaussRow(s, 472, 0x56AB, 0x56D1, 0x56F6, 0x571B, 0x573E, 0x5761, 0x5782, 0x57A3); spuGaussRow(s, 480, 0x57C3, 0x57E2, 0x57FF, 0x581C, 0x5838, 0x5853, 0x586D, 0x5886); spuGaussRow(s, 488, 0x589E, 0x58B5, 0x58CB, 0x58E0, 0x58F4, 0x5907, 0x5919, 0x592A); spuGaussRow(s, 496, 0x593A, 0x5949, 0x5958, 0x5965, 0x5971, 0x597C, 0x5986, 0x598F); spuGaussRow(s, 504, 0x5997, 0x599E, 0x59A4, 0x59A9, 0x59AD, 0x59B0, 0x59B2, 0x59B3);}