summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/src/examples/cpp11/http/server/main.cpp
blob: b76044a96cd86608f9505d1b98d5121443877ecc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// main.cpp
// ~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <iostream>
#include <string>
#include <asio.hpp>
#include "server.hpp"

int main(int argc, char* argv[])
{
  try
  {
    // Check command line arguments.
    if (argc != 4)
    {
      std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
      std::cerr << "  For IPv4, try:\n";
      std::cerr << "    receiver 0.0.0.0 80 .\n";
      std::cerr << "  For IPv6, try:\n";
      std::cerr << "    receiver 0::0 80 .\n";
      return 1;
    }

    // Initialise the server.
    http::server::server s(argv[1], argv[2], argv[3]);

    // Run the server until stopped.
    s.run();
  }
  catch (std::exception& e)
  {
    std::cerr << "exception: " << e.what() << "\n";
  }

  return 0;
}
>[1] = 0xff; /* channel 1,2 frequency */ m_vol[0] = m_vol[1] = 0x07; /* channel 1,2 volume */ m_enable[0] = m_enable[1] = 0x01; /* channel 1,2 enable */ m_channel3 = 0x00; /* channel 3 weird register */ m_DAC_output = 0x00; /* output */ m_state[0] = m_state[1] = m_state[2] = 0; m_accum[0] = m_accum[1] = m_accum[2] = 0xFF; m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() ? clock() : machine().sample_rate()); } //------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- void socrates_snd_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { for (int i = 0; i < samples; i++) { snd_clock(); outputs[0][i] = ((int)m_DAC_output<<4); } } const uint8_t socrates_snd_device::s_volumeLUT[16] = { 0, 61, 100, 132, 158, 183, 201, 218, 233, 242, 253, 255, 250, 240, 224, 211 }; // this table is actually quite weird on the real console. // 0, 0.033, 0.055, 0.07175, 0.086, 0.1, 0.11, 0.119, 0.127, 0.132, 0.138, 0.139, 0.136, 0.131, 0.122, 0.115 are the voltage amplitudes for the steps on channel 2. the last four are particularly bizarre, probably caused by some sort of internal clipping. void socrates_snd_device::snd_clock() /* called once per clock */ { for (int channel = 0; channel < 2; channel++) { if ((m_accum[channel] == 0) && m_enable[channel]) { m_state[channel] = (m_state[channel]^0x1); m_accum[channel] = m_freq[channel]; } else if (m_enable[channel]) { m_accum[channel]--; } else { m_accum[channel] = 0; // channel is disabled m_state[channel] = 0; } } // handle channel 3 here m_DAC_output = (m_state[0]?(s_volumeLUT[m_vol[0]]*9.4):0); // channel 1 is ~2.4 times as loud as channel 2 m_DAC_output += (m_state[1]?(s_volumeLUT[m_vol[1]]<<2):0); // add channel 3 to dac output here } void socrates_snd_device::reg0_w(int data) { m_stream->update(); m_freq[0] = data; } void socrates_snd_device::reg1_w(int data) { m_stream->update(); m_freq[1] = data; } void socrates_snd_device::reg2_w(int data) { m_stream->update(); m_vol[0] = data&0xF; m_enable[0] = (data&0x10)>>4; } void socrates_snd_device::reg3_w(int data) { m_stream->update(); m_vol[1] = data&0xF; m_enable[1] = (data&0x10)>>4; } void socrates_snd_device::reg4_w(int data) { m_stream->update(); m_channel3 = data; }