1 /*************************************************************************** 2 Interface to Ported Z80 Code. 3 Handles the interface between 68000 program code and Z80. 4 5 Also abstracted here, so the more complex OSound class isn't exposed 6 to the main code directly 7 8 Copyright Chris White. 9 See license.txt for more details. 10 ***************************************************************************/ 11 12 #pragma once 13 14 #include "hwaudio/segapcm.hpp" 15 #include "hwaudio/ym2151.hpp" 16 #include "engine/audio/commands.hpp" 17 18 class OSoundInt 19 { 20 public: 21 // SoundChip: Sega Custom Sample Generator 22 SegaPCM* pcm; 23 24 // SoundChip: Yamaha YM2151 25 YM2151* ym; 26 27 const static uint16_t PCM_RAM_SIZE = 0x100; 28 29 // Note whether the game has booted 30 bool has_booted; 31 32 // [+0] Unused 33 // [+1] Engine pitch high 34 // [+2] Engine pitch low 35 // [+3] Engine pitch vol 36 // [+4] Traffic data #1 37 // [+5] Traffic data #2 38 // [+6] Traffic data #3 39 // [+7] Traffic data #4 40 uint8_t engine_data[8]; 41 42 OSoundInt(); 43 ~OSoundInt(); 44 45 void init(); 46 void reset(); 47 void tick(); 48 49 void play_queued_sound(); 50 void queue_sound_service(uint8_t snd); 51 void queue_sound(uint8_t snd); 52 void queue_clear(); 53 54 private: 55 // 4 MHz 56 static const uint32_t SOUND_CLOCK = 4000000; 57 58 // Fractionally counts number of times audio code must be called 59 // We call the audio code 125 times per frame from a timing perspective. 60 double audio_ticks; 61 62 // Reference to 0xFF bytes of PCM Chip RAM 63 uint8_t* pcm_ram; 64 65 // Controls what type of sound we're going to process in the interrupt routine 66 uint8_t sound_counter; 67 68 static const uint8_t QUEUE_LENGTH = 0x1F; 69 uint8_t queue[QUEUE_LENGTH + 1]; 70 71 // Number of sounds queued 72 uint8_t sounds_queued; 73 74 // Positions in the queue 75 uint8_t sound_head, sound_tail; 76 77 void add_to_queue(uint8_t snd); 78 }; 79 80 extern OSoundInt osoundint;