00001 00006 /* 00007 * The contents of this file are subject to the Mozilla Public License 00008 * Version 1.0 (the "License"); you may not use this file except in 00009 * compliance with the License. You may obtain a copy of the License at 00010 * http://www.mozilla.org/MPL/ 00011 * 00012 * Software distributed under the License is distributed on an "AS IS" 00013 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 00014 * License for the specific language governing rights and limitations 00015 * under the License. 00016 * 00017 * The Original Code is legOS code, released October 17, 1999. 00018 * 00019 * The Initial Developer of the Original Code is Markus L. Noga. 00020 * Portions created by Markus L. Noga are Copyright (C) 1999 00021 * Markus L. Noga. All Rights Reserved. 00022 * 00023 * Contributor(s): Markus L. Noga <markus@noga.de> 00024 * Michael Nielsen <mic@daimi.aau.dk> 00025 * Kyosuke Ishikawa <kyosuke@da2.so-net.ne.jp> 00026 * Martin Cornelius <Martin.Cornelius@t-online.de> 00027 */ 00028 00029 #include <sys/dsound.h> 00030 00031 #ifdef CONF_DSOUND 00032 00033 #include <sys/bitops.h> 00034 #include <sys/h8.h> 00035 #include <sys/irq.h> 00036 00037 #include <conio.h> 00038 #include <sys/tm.h> 00039 00041 // 00042 // Variables 00043 // 00045 00047 static const unsigned pitch2freq[]={ 00048 0x8d03, 0x8603, 0x7d03, 0x7703, 0x7003, 0x6a03, 0x6303, 0x5e03, 00049 0x5903, 0x5403, 0x4f03, 0x4a03, 0x4603, 0x4203, 0xfd83, 0xee83, 00050 0xe083, 0xd483, 0xc783, 0xbc83, 0xb283, 0xa883, 0x9e83, 0x9583, 00051 0x8d83, 0x8583, 0x7e83, 0x7683, 0x7083, 0x6983, 0x6383, 0x5e83, 00052 0x5983, 0x5383, 0x4f83, 0x4a83, 0x4683, 0x4283, 0xfc02, 0xee02, 00053 0xe102, 0xd402, 0xc802, 0xbd02, 0xb202, 0xa802, 0x9e02, 0x9502, 00054 0x8d02, 0x8502, 0xfc82, 0xee82, 0xe082, 0xd482, 0xc882, 0xbd82, 00055 0xb282, 0xa882, 0x9e82, 0x9682, 0x8d82, 0x8582, 0x7e82, 0x7682, 00056 0x7082, 0x6982, 0x6382, 0x5e82, 0x5882, 0x5382, 0x4f82, 0x4a82, 00057 0x4682, 0x4282, 0xfc01, 0xee01, 0xe001, 0xd401, 0xc801, 0xbd01, 00058 0xb201, 0xa801, 0x9e01, 0x9501, 0x8d01, 0x8501, 0x7e01, 0x7601, 00059 0x7001, 0x6901, 0x6301, 0x5e01, 0x5801, 0x5301, 0x4f01, 0x4a01, 00060 0x4601 00061 }; 00062 00064 static const note_t sys_beep[]={ 00065 {PITCH_A4 , 1}, {PITCH_END, 0} 00066 }; 00067 00069 const note_t *dsound_system_sounds[]={ 00070 sys_beep 00071 }; 00072 00073 unsigned dsound_16th_ms; 00074 unsigned dsound_internote_ms; 00075 volatile note_t *dsound_next_note; 00076 volatile time_t dsound_next_time; 00077 00078 static volatile int internote; 00079 00080 00082 // 00083 // Internal Functions 00084 // 00086 00088 static inline void play_freq(unsigned freq) { 00089 unsigned char CKSmask = freq & 0xff; 00090 unsigned char match = freq >> 8; 00091 00092 T0_CR = 0x00; // timer off 00093 T0_CNT = 0x00; // counter reset 00094 00095 #if 0 00096 bit_load(CKSmask,0x7); // set ICKS0 00097 bit_store(&STCR,0x0); 00098 #else 00099 if (CKSmask & 0x80) 00100 STCR |= 0x01; // ICKS0 = 1 00101 else 00102 STCR &= ~0x01; // ICKS0 = 0 00103 #endif 00104 00105 T0_CORA = match; // set compare match A 00106 T0_CR = CR_CLEAR_ON_A | (CKSmask &0x3); 00107 } 00108 00110 static inline void play_pause() { 00111 T0_CR = 0x00; // timer 0 off 00112 } 00113 00114 00116 // 00117 // System functions 00118 // 00120 00122 #ifdef CONF_RCX_COMPILER 00123 void dsound_handler(void) { 00124 #else 00125 HANDLER_WRAPPER("dsound_handler","dsound_core"); 00127 void dsound_core(void) { 00128 #endif 00129 if (get_system_up_time() >= dsound_next_time) { 00130 00131 if(internote) { 00132 play_pause(); 00133 dsound_next_time = get_system_up_time() + dsound_internote_ms; 00134 00135 internote=0; 00136 return; 00137 } 00138 00139 if(dsound_next_note) { 00140 unsigned char pitch =dsound_next_note->pitch; 00141 00142 if(pitch<PITCH_MAX) { 00143 if(pitch!=PITCH_PAUSE) 00144 play_freq(pitch2freq[pitch]); 00145 else 00146 play_pause(); 00147 00148 dsound_next_time = get_system_up_time() + dsound_16th_ms * dsound_next_note->length 00149 - dsound_internote_ms; 00150 dsound_next_note++; 00151 internote=1; 00152 return; 00153 } 00154 } 00155 00156 dsound_stop(); 00157 } 00158 } 00159 00161 void dsound_init() { 00162 dsound_16th_ms=DSOUND_DEFAULT_16th_ms; 00163 dsound_internote_ms=DSOUND_DEFAULT_internote_ms; 00164 dsound_stop(); 00165 T0_CSR = CSR_TOGGLE_ON_A; // Output toggles on compare Match A 00166 } 00167 00169 void dsound_shutdown() { 00170 dsound_stop(); 00171 } 00172 00173 00175 // 00176 // User functions 00177 // 00179 00181 void dsound_stop(void) { 00182 play_pause(); 00183 dsound_next_note=0; 00184 dsound_next_time=0xffffffff; 00185 internote=0; 00186 } 00187 00189 wakeup_t dsound_finished(wakeup_t data) { 00190 return !dsound_playing(); 00191 } 00192 00193 #endif // CONF_DSOUND
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |