1 // adac-driver.cxx - description. -*- C++ -*-
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
7 #include "adac-driver.h"
12 adac_driver::write_codec (enum codec_regs regno, unsigned value)
15 unsigned char* be_value_bytes = (unsigned char *) & be_value;
17 be_value_bytes[0] = (value >> 24) & 0xFF;
18 be_value_bytes[1] = (value >> 16) & 0xFF;
19 be_value_bytes[2] = (value >> 8) & 0xFF;
20 be_value_bytes[3] = (value >> 0) & 0xFF;
22 codec_base [regno] = be_value;
27 adac_driver::read_codec (enum codec_regs regno)
30 unsigned char* be_value_bytes = (unsigned char *) & be_value;
33 be_value = codec_base [regno];
35 value = ((be_value_bytes[0] << 24) | (be_value_bytes[1] << 16)
36 | (be_value_bytes[2] << 8) | (be_value_bytes[3]));
41 adac_driver::adac_driver()
47 codec_base = (unsigned*) CODEC_BASE;
49 write_codec (config, 134291264); // 8-bit uLaw mono 8000Hz
53 adac_driver::~adac_driver()
55 write_codec (tx_count, 0);
56 write_codec (rx_count, 0);
61 adac_driver::begin_read ()
63 write_codec (rx_count, -1);
68 adac_driver::poll_read ()
70 unsigned iterations = 1000;
71 while (--iterations && read_codec (status) & (0xFF << 16))
72 rx_buf += (unsigned char)(read_codec (data) >> 24);
77 adac_driver::finish_read ()
79 write_codec (rx_count, 0);
87 adac_driver::begin_write (const string& sample)
92 write_codec (tx_count, -1);
97 adac_driver::poll_write ()
99 unsigned iterations = 1000;
100 if (tx_buf_ptr < tx_buf.size())
101 while (--iterations && read_codec (status) & (0xFF << 24))
103 write_codec (data, tx_buf[tx_buf_ptr] << 24);
110 adac_driver::finish_write ()
112 /* wait for codec to flush previous bytes */
116 unsigned s = read_codec (status);
117 pending = (s & (0xFF << 8));
120 write_codec (tx_count, 0);