dsound.c
Go to the documentation of this file.
1
6/*
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.0 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
14 * License for the specific language governing rights and limitations
15 * under the License.
16 *
17 * The Original Code is legOS code, released October 17, 1999.
18 *
19 * The Initial Developer of the Original Code is Markus L. Noga.
20 * Portions created by Markus L. Noga are Copyright (C) 1999
21 * Markus L. Noga. All Rights Reserved.
22 *
23 * Contributor(s): Markus L. Noga <markus@noga.de>
24 * Michael Nielsen <mic@daimi.aau.dk>
25 * Kyosuke Ishikawa <kyosuke@da2.so-net.ne.jp>
26 * Martin Cornelius <Martin.Cornelius@t-online.de>
27 */
28
29#include <sys/dsound.h>
30
31#ifdef CONF_DSOUND
32
33#include <sys/bitops.h>
34#include <sys/h8.h>
35#include <sys/irq.h>
36
37#include <conio.h>
38#include <sys/tm.h>
39
41//
42// Variables
43//
45
47static const unsigned pitch2freq[]={
48 0x8d03, 0x8603, 0x7d03, 0x7703, 0x7003, 0x6a03, 0x6303, 0x5e03,
49 0x5903, 0x5403, 0x4f03, 0x4a03, 0x4603, 0x4203, 0xfd83, 0xee83,
50 0xe083, 0xd483, 0xc783, 0xbc83, 0xb283, 0xa883, 0x9e83, 0x9583,
51 0x8d83, 0x8583, 0x7e83, 0x7683, 0x7083, 0x6983, 0x6383, 0x5e83,
52 0x5983, 0x5383, 0x4f83, 0x4a83, 0x4683, 0x4283, 0xfc02, 0xee02,
53 0xe102, 0xd402, 0xc802, 0xbd02, 0xb202, 0xa802, 0x9e02, 0x9502,
54 0x8d02, 0x8502, 0xfc82, 0xee82, 0xe082, 0xd482, 0xc882, 0xbd82,
55 0xb282, 0xa882, 0x9e82, 0x9682, 0x8d82, 0x8582, 0x7e82, 0x7682,
56 0x7082, 0x6982, 0x6382, 0x5e82, 0x5882, 0x5382, 0x4f82, 0x4a82,
57 0x4682, 0x4282, 0xfc01, 0xee01, 0xe001, 0xd401, 0xc801, 0xbd01,
58 0xb201, 0xa801, 0x9e01, 0x9501, 0x8d01, 0x8501, 0x7e01, 0x7601,
59 0x7001, 0x6901, 0x6301, 0x5e01, 0x5801, 0x5301, 0x4f01, 0x4a01,
60 0x4601
61};
62
64static const note_t sys_beep[]={
65 {PITCH_A4 , 1}, {PITCH_END, 0}
66};
67
70 sys_beep
71};
72
73unsigned dsound_16th_ms;
74unsigned dsound_internote_ms;
75volatile note_t *dsound_next_note;
76volatile time_t dsound_next_time;
77
78static volatile int internote;
79
80
82//
83// Internal Functions
84//
86
88static inline void play_freq(unsigned freq) {
89 unsigned char CKSmask = freq & 0xff;
90 unsigned char match = freq >> 8;
91
92 T0_CR = 0x00; // timer off
93 T0_CNT = 0x00; // counter reset
94
95#if 0
96 bit_load(CKSmask,0x7); // set ICKS0
97 bit_store(&STCR,0x0);
98#else
99 if (CKSmask & 0x80)
100 STCR |= 0x01; // ICKS0 = 1
101 else
102 STCR &= ~0x01; // ICKS0 = 0
103#endif
104
105 T0_CORA = match; // set compare match A
106 T0_CR = CR_CLEAR_ON_A | (CKSmask &0x3);
107}
108
110static inline void play_pause() {
111 T0_CR = 0x00; // timer 0 off
112}
113
114
116//
117// System functions
118//
120
122#ifdef CONF_RCX_COMPILER
123void dsound_handler(void) {
124#else
125HANDLER_WRAPPER("dsound_handler","dsound_core");
127void dsound_core(void) {
128#endif
130
131 if(internote) {
132 play_pause();
134
135 internote=0;
136 return;
137 }
138
139 if(dsound_next_note) {
140 unsigned char pitch =dsound_next_note->pitch;
141
142 if(pitch<PITCH_MAX) {
143 if(pitch!=PITCH_PAUSE)
144 play_freq(pitch2freq[pitch]);
145 else
146 play_pause();
147
151 internote=1;
152 return;
153 }
154 }
155
156 dsound_stop();
157 }
158}
159
161void dsound_init() {
164 dsound_stop();
165 T0_CSR = CSR_TOGGLE_ON_A; // Output toggles on compare Match A
166}
167
169void dsound_shutdown() {
170 dsound_stop();
171}
172
173
175//
176// User functions
177//
179
181void dsound_stop(void) {
182 play_pause();
184 dsound_next_time=0xffffffff;
185 internote=0;
186}
187
190 return !dsound_playing();
191}
192
193#endif // CONF_DSOUND
Internal Interface: H8/300 bit operations.
#define bit_load(mask, bit)
load a single bit from a mask to the carry flag
Definition: bitops.h:71
#define bit_store(byte, bit)
store the carry flag to a single single bit in memory
Definition: bitops.h:83
Interface: console input / output.
unsigned dsound_internote_ms
length of internote spacing in ms
const note_t * dsound_system_sounds[]
system sound data
volatile time_t dsound_next_time
when to play next note
#define PITCH_A4
Definition: dsound.h:134
#define DSOUND_DEFAULT_16th_ms
default duration of 1/16th note in ms
Definition: dsound.h:204
#define PITCH_MAX
maximum pitch value
Definition: dsound.h:190
#define DSOUND_DEFAULT_internote_ms
default duration internote spacing in ms
Definition: dsound.h:207
static int dsound_playing(void)
returns nonzero value if a sound is playing
Definition: dsound.h:260
#define PITCH_END
mark the end of a list of note_t entries
Definition: dsound.h:193
#define PITCH_PAUSE
specify a pause (rest)
Definition: dsound.h:187
wakeup_t dsound_finished(wakeup_t data)
sound finished event wakeup function
volatile note_t * dsound_next_note
pointer to current note
unsigned dsound_16th_ms
length of 1/16 note in ms
void dsound_stop(void)
stop playing sound
Internal Interface: H8/3297 processor registers.
volatile unsigned char T0_CNT
timer 0 counter register
#define CR_CLEAR_ON_A
Definition: h8.h:167
unsigned char STCR
serial / timer control register
volatile unsigned char T0_CSR
timer 0 control / status register
unsigned char T0_CORA
timer 0 constant A register
#define CSR_TOGGLE_ON_A
Definition: h8.h:190
unsigned char T0_CR
timer 0 control register
Internal LNP Interface: RCX redirected IRQ vectors.
HANDLER_WRAPPER("lcd_refresh_next_byte", "lcd_refresh_next_byte_core")
lcd refresh handler, called from system timer interrupt
the note structure describing a single note.
Definition: dsound.h:56
unsigned char pitch
note pitch, 0 ^= A_0 (~55 Hz)
Definition: dsound.h:57
unsigned char length
note length in 1/16ths
Definition: dsound.h:58
Internal Interface: direct sound control.
void dsound_handler()
sound handler, called from system timer interrupt
void dsound_init()
initialize sound driver
void dsound_shutdown()
shutdown sound driver
Internal Interface: task management.
time_t get_system_up_time(void)
retrieve the current system time
unsigned long time_t
time type
Definition: time.h:50
unsigned long wakeup_t
wakeup data area type
Definition: tm.h:57

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.9.4