table sound.get()
| 4847 | |
| 4848 | // table sound.get() |
| 4849 | static int sound_get(lua_State *L) |
| 4850 | { |
| 4851 | extern ENVUNIT EnvUnits[3]; |
| 4852 | extern int CheckFreq(uint32 cf, uint8 sr); |
| 4853 | extern int32 curfreq[2]; |
| 4854 | extern uint8 PSG[0x10]; |
| 4855 | extern int32 lengthcount[4]; |
| 4856 | extern uint8 TriCount; |
| 4857 | extern const uint32 NoiseFreqTableNTSC[0x10]; |
| 4858 | extern const uint32 NoiseFreqTablePAL[0x10]; |
| 4859 | extern int32 DMCPeriod; |
| 4860 | extern uint8 DMCAddressLatch, DMCSizeLatch; |
| 4861 | extern uint8 DMCFormat; |
| 4862 | extern char DMCHaveSample; |
| 4863 | extern uint8 InitialRawDALatch; |
| 4864 | |
| 4865 | int freqReg; |
| 4866 | double freq; |
| 4867 | bool shortMode; |
| 4868 | |
| 4869 | lua_newtable(L); |
| 4870 | |
| 4871 | // rp2a03 start |
| 4872 | lua_newtable(L); |
| 4873 | // rp2a03 info setup |
| 4874 | double nesVolumes[3]; |
| 4875 | for (int i = 0; i < 3; i++) |
| 4876 | { |
| 4877 | if ((EnvUnits[i].Mode & 1) != 0) |
| 4878 | nesVolumes[i] = EnvUnits[i].Speed; |
| 4879 | else |
| 4880 | nesVolumes[i] = EnvUnits[i].decvolume; |
| 4881 | nesVolumes[i] /= 15.0; |
| 4882 | } |
| 4883 | // rp2a03/square1 |
| 4884 | lua_newtable(L); |
| 4885 | if((curfreq[0] < 8 || curfreq[0] > 0x7ff) || |
| 4886 | (CheckFreq(curfreq[0], PSG[1]) == 0) || |
| 4887 | (lengthcount[0] == 0)) |
| 4888 | lua_pushnumber(L, 0.0); |
| 4889 | else |
| 4890 | lua_pushnumber(L, nesVolumes[0]); |
| 4891 | lua_setfield(L, -2, "volume"); |
| 4892 | freq = ((PAL?PAL_CPU:NTSC_CPU)/16.0) / (curfreq[0] + 1); |
| 4893 | lua_pushnumber(L, freq); |
| 4894 | lua_setfield(L, -2, "frequency"); |
| 4895 | lua_pushnumber(L, (log(freq / 440.0) * 12 / log(2.0)) + 69); |
| 4896 | lua_setfield(L, -2, "midikey"); |
| 4897 | lua_pushinteger(L, (PSG[0] & 0xC0) >> 6); |
| 4898 | lua_setfield(L, -2, "duty"); |
| 4899 | lua_newtable(L); |
| 4900 | lua_pushinteger(L, curfreq[0]); |
| 4901 | lua_setfield(L, -2, "frequency"); |
| 4902 | lua_setfield(L, -2, "regs"); |
| 4903 | lua_setfield(L, -2, "square1"); |
| 4904 | // rp2a03/square2 |
| 4905 | lua_newtable(L); |
| 4906 | if((curfreq[1] < 8 || curfreq[1] > 0x7ff) || |
nothing calls this directly
no test coverage detected