@@ -346,19 +346,19 @@ inline void Chip8EmulatorFP::executeInstruction()
346346 if (_options.optTraceLog && _cpuState != eWAITING)
347347 Logger::log (Logger::eCHIP8, _cycleCounter, {_frameCounter, int (_cycleCounter % 9999 )}, dumpStateLine ().c_str ());
348348 uint16_t opcode = (_memory[_rPC] << 8 ) | _memory[_rPC + 1 ];
349- ++_cycleCounter;
350349 _rPC = (_rPC + 2 ) & ADDRESS_MASK;
351350 (this ->*_opcodeHandler[opcode])(opcode);
351+ ++_cycleCounter;
352352 }
353353 else {
354354 if (_execMode == ePAUSED || _cpuState == eERROR)
355355 return ;
356356 if (_options.optTraceLog )
357357 Logger::log (Logger::eCHIP8, _cycleCounter, {_frameCounter, int (_cycleCounter % 9999 )}, dumpStateLine ().c_str ());
358358 uint16_t opcode = (_memory[_rPC] << 8 ) | _memory[_rPC + 1 ];
359- ++_cycleCounter;
360359 _rPC = (_rPC + 2 ) & ADDRESS_MASK;
361360 (this ->*_opcodeHandler[opcode])(opcode);
361+ ++_cycleCounter;
362362 if (_execMode == eSTEP || (_execMode == eSTEPOVER && _rSP <= _stepOverSP)) {
363363 _execMode = ePAUSED;
364364 }
@@ -1417,6 +1417,32 @@ void Chip8EmulatorFP::opFxFB_c8x(uint16_t opcode)
14171417 // still nop
14181418}
14191419
1420+ static uint16_t g_hp48Wave[] = {
1421+ 0x99 , 0x4cd , 0x2df , 0xfbc3 , 0xf1e3 , 0xe747 , 0xddef , 0xd866 , 0xda5c , 0xdef1 , 0xe38e , 0xe664 , 0xe9eb , 0xefd3 , 0xf1fe , 0xf03a , 0xef66 , 0xf1aa , 0xf7d1 , 0x13a , 0xadd , 0x102d , 0xe8d , 0xb72 , 0xa58 , 0xe80 , 0x17af , 0x21d1 , 0x2718 , 0x2245 , 0x15f3 ,
1422+ 0x5a0 , 0xfc82 , 0xfef5 , 0x6f7 , 0xd5f , 0xac7 , 0xfe89 , 0xef7c , 0xe961 , 0xef4e , 0xfba7 , 0x440 , 0x452 , 0xfc8a , 0xf099 , 0xe958 , 0xeceb , 0xf959 , 0x6f3 , 0xcfd , 0x92f , 0x3c8 , 0x2cd , 0x733 , 0xd94 , 0x12f0 , 0x1531 , 0x1147 , 0x73d , 0xfbaf , 0xf3fb ,
1423+ 0xf2e5 , 0xf8d1 , 0x2e , 0x3fb , 0x25c , 0xfc35 , 0xf222 , 0xe88f , 0xe260 , 0xdf64 , 0xe0f0 , 0xe306 , 0xe5e6 , 0xe965 , 0xed55 , 0xf203 , 0xf662 , 0xfb37 , 0x12c , 0x926 , 0xf66 , 0x10ac , 0xdd5 , 0xa2b , 0xb84 , 0x13b6 , 0x1fe4 , 0x2bef , 0x3168 , 0x2dfc , 0x2380 ,
1424+ 0x1859 , 0x1368 , 0x14d1 , 0x18ab , 0x190d , 0x141f , 0xa63 , 0xfd36 , 0xee1f , 0xe39e , 0xe201 , 0xe4dc , 0xe7dd , 0xe748 , 0xe452 , 0xde58 , 0xd77d , 0xd3e4 , 0xd695 , 0xde34 , 0xe593 , 0xec3e , 0xf229 , 0xf714 , 0xf841 , 0xf93b , 0xfcdd , 0x671 , 0x1661 , 0x24fb , 0x2c00 ,
1425+ 0x27ce , 0x1dcb , 0x11bb , 0xb89 , 0xfc6 , 0x1991 , 0x219c , 0x1fa7 , 0x132d , 0x278 , 0xf9df , 0xfd50 , 0x566 , 0x8c5 , 0x33f , 0xf846 , 0xeb34 , 0xe28b , 0xe365 , 0xeda5 , 0xfb18 , 0x1b3 , 0xfe67 , 0xf754 , 0xf34f , 0xf63e , 0xff4c , 0x997 , 0xea5 , 0xb0c , 0x247 ,
1426+ 0xf98f , 0xf5af , 0xf914 , 0x2e8 , 0xd0b , 0x10ab , 0xbab , 0x145 , 0xf7db , 0xf1ab , 0xedf7 , 0xec64 , 0xebb5 , 0xea7b , 0xea61 , 0xeb9b , 0xebad , 0xea86 , 0xec28 , 0xf2c9 , 0xfc97 , 0x688 , 0xb10 , 0x80e , 0xfff8 , 0xfa73 , 0xfd43 , 0xa97 , 0x20a1 , 0x3393 , 0x3a6d ,
1427+ 0x3376 , 0x256e , 0x1b72 , 0x1a9f , 0x200a , 0x2470 , 0x23bc , 0x1c60 , 0x1091 , 0x45 , 0xee38 , 0xe370 , 0xe2d0 , 0xe694 , 0xe851 , 0xe591 , 0xdf8c , 0xd829 , 0xd063 , 0xcc6c , 0xcf8e , 0xd7ed , 0xdf45 , 0xe306 , 0xe752 , 0xed90 , 0xf362 , 0xf85d , 0xfed5 , 0x8df , 0x17dd ,
1428+ 0x2691 , 0x2daa , 0x2a67 , 0x2132 , 0x1755 , 0x1288 , 0x1816 , 0x220b , 0x2981 , 0x262f , 0x17f0 , 0x6d2 , 0xfc48 , 0xfecb , 0x722 , 0xc3d , 0x6e6 , 0xf975 , 0xe96f , 0xdd92 , 0xdd6b , 0xe701 , 0xf560 , 0xfd48 , 0xfa18 , 0xf1db , 0xec67 , 0xeea1 , 0xf8c0 , 0x5df , 0xdb2 ,
1429+ 0xbcb , 0x2f4 , 0xfa82 , 0xf691 , 0xf960 , 0x24d , 0xceb , 0x12a4 , 0x1085 , 0x82f , 0xfdc7 , 0xf5dc , 0xf073 , 0xed9d , 0xebec , 0xea65 , 0xea44 , 0xec13 , 0xed4b , 0xeb5e , 0xeaa6 , 0xeef3 , 0xf8dd , 0x488 , 0xc0c , 0xb48 , 0x3b5 , 0xfc88 , 0xfd06 , 0x881 , 0x1dfb ,
1430+ 0x32fb , 0x3c79 , 0x37b2 , 0x2964 , 0x1d15 , 0x19bd , 0x1e2d , 0x22d7 , 0x22a8 , 0x1c7a , 0x113a , 0x1aa , 0xef17 , 0xe247 , 0xdf2c , 0xe10d , 0xe1af , 0xdf86 , 0xdb90 , 0xd5bc , 0xcf35 , 0xcb60 , 0xcdd2 , 0xd420 , 0xdbff , 0xe438 , 0xed32 , 0xf5f9 , 0xfb2e , 0xfcdb , 0xff15 ,
1431+ 0x77d , 0x183c , 0x2b67 , 0x3764 , 0x366f , 0x298d , 0x19d5 , 0xfc3 , 0x1274 , 0x1e3b , 0x2745 , 0x2505 , 0x1596 , 0x3d0 , 0xfa58 , 0xfc12 , 0x1aa , 0x321 , 0xfe2b , 0xf496 , 0xe971 , 0xe181 , 0xe1c4 , 0xe94d , 0xf25e , 0xf450 , 0xf102 , 0xeea0 , 0xf1b1 , 0xf932 , 0x189 ,
1432+ 0x947 , 0xcb3 , 0xa84 , 0x358 , 0xfcac , 0xfa52 , 0xff5b , 0x81f , 0xe37 , 0xf9b , 0xbf3 , 0x549 , 0xfd0a , 0xf663 , 0xf073 , 0xecb1 , 0xe9fc , 0xe70a , 0xe615 , 0xe874 , 0xec79 , 0xecc6 , 0xec80 , 0xef6d , 0xf711 , 0x108 , 0x8e9 , 0xb25 , 0x6a4 , 0x1a8 , 0x2bf ,
1433+ 0xd5b , 0x20d1 , 0x33c0 , 0x3b9c , 0x36bc , 0x293d , 0x1e71 , 0x1c18 , 0x2000 , 0x245c , 0x22dd , 0x1b4f , 0xe5c , 0xff5d , 0xee97 , 0xe1d2 , 0xdd18 , 0xdcb1 , 0xdd6f , 0xdc59 , 0xda44 , 0xd6ad , 0xd1de , 0xce00 , 0xcf2d , 0xd481 , 0xdbc7 , 0xe3d1 , 0xec8a , 0xf597 , 0xfb18 ,
1434+ 0xfdaa , 0x2b , 0x7bc , 0x173c , 0x29ba , 0x35c2 , 0x3574 , 0x2a46 , 0x1bd4 , 0x11ee , 0x1326 , 0x1e20 , 0x2725 , 0x2582 , 0x1618 , 0x2f3 , 0xf88a , 0xfa7b , 0x18e , 0x36b , 0xfde8 , 0xf3a2 , 0xe8ad , 0xe077 , 0xe02d , 0xe784 , 0xf15b , 0xf4a5 , 0xf147 , 0xee3a , 0xf029 ,
1435+ 0xf7cf , 0x8f , 0x90b , 0xdce , 0xd5e , 0x739 , 0xff63 , 0xfb1a , 0xfdc8 , 0x66c , 0xd8e , 0x1090 , 0xe3e , 0x834 , 0xff66 , 0xf71d , 0xf009 , 0xeb4d , 0xe950 , 0xe6f7 , 0xe60f , 0xe79b , 0xebe7 , 0xecd2 , 0xebe0 , 0xee31 , 0xf4ed , 0xff03 , 0x747 , 0xaa4 , 0x743 ,
1436+ 0x28c , 0x301 , 0xc51 , 0x1ecd , 0x3286 , 0x3c24 , 0x38de , 0x2bdf , 0x1ff0 , 0x1c87 , 0x1f36 , 0x23e7 , 0x2371 , 0x1d31 , 0x1172 , 0x268 , 0xf09b , 0xe118 , 0xdacd , 0xda75 , 0xdc8e , 0xdccd , 0xdb5f , 0xd81e , 0xd297 , 0xccc6 , 0xcba7 , 0xd022 , 0xd7a6 , 0xe132 , 0xeb51 ,
1437+ 0xf532 , 0xfb7c , 0xfe72 , 0xaf , 0x67c , 0x144a , 0x26f7 , 0x3551 , 0x37ff , 0x2eaa , 0x1fcb , 0x13e2 , 0x1243 , 0x1c21 , 0x2667 , 0x276f , 0x1a44 , 0x660 , 0xf95a , 0xf943 , 0x64 , 0x31c , 0xfe5e , 0xf4b4 , 0xea60 , 0xe1b4 , 0xdf56 , 0xe45a , 0xed0c , 0xf19c , 0xefb1 ,
1438+ 0xed9f , 0xef71 , 0xf730 , 0x0a , 0x806 , 0xc69 , 0xc0c , 0x6af , 0xff72 , 0xfb45 , 0xfd51 , 0x5e8 , 0xdc1 , 0x118e , 0xfb9 , 0x9f1 , 0x176 , 0xf949 , 0xf26f , 0xed26 , 0xeaf5 , 0xe82b , 0xe6fe , 0xe86b , 0xed04 , 0xeec0 , 0xeda5 , 0xef61 , 0xf512 , 0xfe8a , 0x6d3 ,
1439+ 0xada , 0x81d , 0x36e , 0x3d4 , 0xcca , 0x1e53 , 0x30fb , 0x3a79 , 0x381e , 0x2c2b , 0x1f66 , 0x1bbc , 0x1f93 , 0x23c7 , 0x1f81 , 0x1567 , 0x881 , 0xfa5b , 0xec75 , 0xe003 , 0xd911 , 0xd540 , 0xd3de , 0xd1cc , 0xcfaa , 0xd06d , 0xd255 , 0xd551 , 0xda96 , 0xe16d , 0xe908 ,
1440+ 0xef9c , 0xf3f2 , 0xf659 , 0xf6db , 0xfc6e , 0x8c4 , 0x1911 , 0x2a0c , 0x3669 , 0x386e , 0x2e5c , 0x1f11 , 0x1075 , 0xab4 , 0x1117 , 0x1e06 , 0x264a , 0x21df , 0x1021 , 0xfb78 , 0xf08e , 0xf1ee , 0xfc98 , 0x69b , 0xb1d , 0x359 , 0xef05 , 0xda37 , 0xd05a , 0xd614 , 0xe2f4 ,
1441+ 0xee1b , 0xf226 , 0xf0d5 , 0xeead , 0xee2d , 0xf1d0 , 0xf8ec , 0x38a , 0xd39 , 0x100b , 0xc8e , 0x7f9 , 0x60c , 0x7a9 , 0xc0b , 0x1125 , 0x15bc , 0x1847 , 0x162b , 0xfb9 , 0x8b7 , 0x421 , 0x98 , 0xfbca , 0xf691 , 0xf1cd , 0xeda5 , 0xeb83 , 0xeba0 , 0xed32 , 0xef40 ,
1442+ 0xf0b5 , 0xf25b , 0xf4e8 , 0xf71e , 0xf9bf , 0xfdf7 , 0x255 , 0x6f6 , 0xc7a , 0xfc6 , 0xdfc , 0x8d1 , 0x727 , 0xbf5 , 0x1648 , 0x1ef6 , 0x1e58 , 0x1419 , 0x58e , 0xfb3a , 0xf7a7 , 0xfe29 , 0x8f0 , 0xe36 , 0xbd2 , 0x1ec , 0xf764 , 0xf2c7 , 0xf5d6 , 0xfa03 , 0xf84e ,
1443+ 0xf2ce , 0xedbb , 0xe9ee , 0xe59c , 0xe3eb , 0xe7b5 , 0xed9d , 0xf2c8 , 0xf6af , 0xfac1
1444+ };
1445+
14201446void Chip8EmulatorFP::renderAudio (int16_t * samples, size_t frames, int sampleFrequency)
14211447{
14221448 if (_isMegaChipMode && _sampleLength) {
@@ -1433,8 +1459,14 @@ void Chip8EmulatorFP::renderAudio(int16_t* samples, size_t frames, int sampleFre
14331459 _wavePhase = std::fmod (_wavePhase + step, 1 .0f );
14341460 }
14351461 }
1462+ else if (_options.behaviorBase >= Chip8EmulatorOptions::eCHIP48 && _options.behaviorBase <= Chip8EmulatorOptions::eSCHPC) {
1463+ for (int i = 0 ; i < frames; ++i) {
1464+ *samples++ = g_hp48Wave[(int )_wavePhase];
1465+ _wavePhase = std::fmod (_wavePhase + 1 , sizeof (g_hp48Wave) / 2 );
1466+ }
1467+ }
14361468 else {
1437- auto audioFrequency = _options.behaviorBase == Chip8EmulatorOptions::eCHIP8X ? 27535 .0f / ((unsigned )_vp595Frequency + 1 ) : 1400 . 0f ;
1469+ auto audioFrequency = _options.behaviorBase == Chip8EmulatorOptions::eCHIP8X ? 27535 .0f / ((unsigned )_vp595Frequency + 1 ) : 1531 . 555f ;
14381470 const float step = audioFrequency / sampleFrequency;
14391471 for (int i = 0 ; i < frames; ++i) {
14401472 *samples++ = (_wavePhase > 0 .5f ) ? 16384 : -16384 ;
0 commit comments