1 2 // Woohoo! 3 #define MAX_CHANNELS 16 4 5 // Some handy constants. Thanks eightbitbubsy. 6 #define AMIGA_PAL_XTAL 28375160 7 #define AMIGA_NTSC_XTAL 28636360 8 #define AMIGA_CPU_PAL_CLK ((AMIGA_PAL_XTAL / 4)) 9 #define AMIGA_CPU_NTSC_CLK ((AMIGA_NTSC_XTAL / 4)) 10 #define AMIGA_CIA_PAL_CLK ((AMIGA_CPU_PAL_CLK / 10)) 11 #define AMIGA_CIA_NTSC_CLK ((AMIGA_CPU_NTSC_CLK / 10)) 12 #define AMIGA_PAULA_PAL_CLK ((AMIGA_CPU_PAL_CLK / 2)) 13 #define AMIGA_PAULA_NTSC_CLK ((AMIGA_CPU_NTSC_CLK / 2)) 14 15 #define Period2Freq(period) ((AMIGA_PAULA_PAL_CLK * 65536.f) / (period)) 16 //#define Period2Freq(period) (3579545.25f / (period)) 17 18 struct ahx_envelope 19 { 20 int16 aFrames, aVolume; 21 int16 dFrames, dVolume; 22 int16 sFrames; 23 int16 rFrames, rVolume; 24 int16 pad; 25 }; 26 27 struct ahx_plsentry 28 { 29 uint8 ple_Note; 30 uint8 ple_Waveform; 31 int16 ple_Fixed; 32 int8 ple_FX[2]; 33 int8 ple_FXParam[2]; 34 }; 35 36 struct ahx_plist 37 { 38 int16 pls_Speed; 39 int16 pls_Length; 40 struct ahx_plsentry pls_Entries[256]; 41 }; 42 43 struct ahx_instrument 44 { 45 TEXT ins_Name[128]; 46 uint8 ins_Volume; 47 uint8 ins_WaveLength; 48 uint8 ins_FilterLowerLimit; 49 uint8 ins_FilterUpperLimit; 50 uint8 ins_FilterSpeed; 51 uint8 ins_SquareLowerLimit; 52 uint8 ins_SquareUpperLimit; 53 uint8 ins_SquareSpeed; 54 uint8 ins_VibratoDelay; 55 uint8 ins_VibratoSpeed; 56 uint8 ins_VibratoDepth; 57 uint8 ins_HardCutRelease; 58 uint8 ins_HardCutReleaseFrames; 59 struct ahx_envelope ins_Envelope; 60 struct ahx_plist ins_PList; 61 int32 ins_ptop; 62 int32 ins_pcurx; 63 int32 ins_pcury; 64 }; 65 66 struct ahx_position 67 { 68 uint8 pos_Track[MAX_CHANNELS]; 69 int8 pos_Transpose[MAX_CHANNELS]; 70 }; 71 72 struct ahx_step 73 { 74 uint8 stp_Note; 75 uint8 stp_Instrument; 76 uint8 stp_FX; 77 uint8 stp_FXParam; 78 uint8 stp_FXb; 79 uint8 stp_FXbParam; 80 }; 81 82 struct ahx_voice 83 { 84 int16 vc_Track; 85 int16 vc_NextTrack; 86 int16 vc_Transpose; 87 int16 vc_NextTranspose; 88 int16 vc_OverrideTranspose; 89 int32 vc_ADSRVolume; 90 struct ahx_envelope vc_ADSR; 91 struct ahx_instrument *vc_Instrument; 92 uint32 vc_SamplePos; 93 uint32 vc_Delta; 94 uint16 vc_InstrPeriod; 95 uint16 vc_TrackPeriod; 96 uint16 vc_VibratoPeriod; 97 uint16 vc_WaveLength; 98 int16 vc_NoteMaxVolume; 99 uint16 vc_PerfSubVolume; 100 uint8 vc_NewWaveform; 101 uint8 vc_Waveform; 102 uint8 vc_PlantPeriod; 103 uint8 vc_VoiceVolume; 104 uint8 vc_PlantSquare; 105 uint8 vc_IgnoreSquare; 106 uint8 vc_FixedNote; 107 int16 vc_VolumeSlideUp; 108 int16 vc_VolumeSlideDown; 109 int16 vc_HardCut; 110 uint8 vc_HardCutRelease; 111 int16 vc_HardCutReleaseF; 112 uint8 vc_PeriodSlideOn; 113 int16 vc_PeriodSlideSpeed; 114 int16 vc_PeriodSlidePeriod; 115 int16 vc_PeriodSlideLimit; 116 int16 vc_PeriodSlideWithLimit; 117 int16 vc_PeriodPerfSlideSpeed; 118 int16 vc_PeriodPerfSlidePeriod; 119 uint8 vc_PeriodPerfSlideOn; 120 int16 vc_VibratoDelay; 121 int16 vc_VibratoSpeed; 122 int16 vc_VibratoCurrent; 123 int16 vc_VibratoDepth; 124 int16 vc_SquareOn; 125 int16 vc_SquareInit; 126 int16 vc_SquareWait; 127 int16 vc_SquareLowerLimit; 128 int16 vc_SquareUpperLimit; 129 int16 vc_SquarePos; 130 int16 vc_SquareSign; 131 int16 vc_SquareSlidingIn; 132 int16 vc_SquareReverse; 133 uint8 vc_FilterOn; 134 uint8 vc_FilterInit; 135 int16 vc_FilterWait; 136 int16 vc_FilterSpeed; 137 int16 vc_FilterUpperLimit; 138 int16 vc_FilterLowerLimit; 139 int16 vc_FilterPos; 140 int16 vc_FilterSign; 141 int16 vc_FilterSlidingIn; 142 int16 vc_IgnoreFilter; 143 int16 vc_PerfCurrent; 144 int16 vc_PerfSpeed; 145 int16 vc_PerfWait; 146 struct ahx_plist *vc_PerfList; 147 int8 *vc_AudioPointer; 148 int8 *vc_AudioSource; 149 uint8 vc_NoteDelayOn; 150 uint8 vc_NoteCutOn; 151 int16 vc_NoteDelayWait; 152 int16 vc_NoteCutWait; 153 int16 vc_AudioPeriod; 154 int16 vc_AudioVolume; 155 int32 vc_WNRandom; 156 int8 *vc_MixSource; 157 int8 vc_SquareTempBuffer[0x80]; 158 int8 vc_VoiceBuffer[0x282*4]; 159 uint8 vc_VoiceNum; 160 uint8 vc_TrackMasterVolume; 161 uint8 vc_TrackOn; 162 uint8 vc_SetTrackOn; 163 int16 vc_VoicePeriod; 164 uint32 vc_Pan; 165 uint32 vc_SetPan; 166 uint32 vc_PanMultLeft; 167 uint32 vc_PanMultRight; 168 int32 vc_VUMeter; 169 170 /* Ring modulation! */ 171 uint32 vc_RingSamplePos; 172 uint32 vc_RingDelta; 173 int8 *vc_RingMixSource; 174 uint8 vc_RingPlantPeriod; 175 int16 vc_RingInstrPeriod; 176 int16 vc_RingBasePeriod; 177 int16 vc_RingAudioPeriod; 178 int8 *vc_RingAudioSource; 179 uint8 vc_RingNewWaveform; 180 uint8 vc_RingWaveform; 181 uint8 vc_RingFixedPeriod; 182 int8 vc_RingVoiceBuffer[0x282*4]; 183 }; 184 185 // Store all tunes in a list so we can have more than 186 // one loaded at once (= tabs!) 187 struct ahx_tune 188 { 189 struct Node at_ln; 190 191 struct List *at_undolist; 192 struct List *at_redolist; 193 uint32 at_undomem; 194 195 /**** 196 ***** Anything that can't just be copied from one ahx_tune structure 197 ***** into another with a single CopyMem call should be above at_Name 198 ****/ 199 200 TEXT at_Name[128]; 201 uint32 at_Time; 202 uint32 at_ExactTime; 203 uint16 at_LoopDetector; 204 uint16 at_SongNum; 205 uint32 at_Frequency; 206 float64 at_FreqF; 207 int8 *at_WaveformTab[MAX_CHANNELS]; 208 uint16 at_Restart; 209 uint16 at_PositionNr; 210 uint8 at_SpeedMultiplier; 211 uint8 at_TrackLength; 212 uint8 at_TrackNr; 213 uint8 at_InstrumentNr; 214 uint8 at_SubsongNr; 215 uint16 at_PosJump; 216 uint32 at_PlayingTime; 217 int16 at_Tempo; 218 int16 at_PosNr; 219 int16 at_NextPosNr; 220 int16 at_StepWaitFrames; 221 int16 at_NoteNr; 222 uint16 at_PosJumpNote; 223 uint8 at_GetNewPosition; 224 uint8 at_PatternBreak; 225 uint8 at_SongEndReached; 226 uint8 at_Stereo; 227 uint16 at_Subsongs[256]; 228 uint16 at_Channels; 229 struct ahx_position at_Positions[1000]; 230 struct ahx_step at_Tracks[256][64]; 231 struct ahx_instrument at_Instruments[64]; 232 struct ahx_voice at_Voices[MAX_CHANNELS]; 233 int32 at_posed_curs; 234 int32 at_tracked_curs; 235 int32 at_curins; 236 int32 at_drumpadnote; 237 BOOL at_drumpadmode; 238 int16 at_topins; 239 int16 at_topinsb; 240 int32 at_curss; 241 int32 at_curlch; 242 int32 at_baseins; 243 int32 at_curpanel; 244 BOOL at_modified; 245 int32 at_mixgain; 246 int32 at_mixgainP; 247 248 // Tracked mark 249 int16 at_cbmarkmarknote; 250 int16 at_cbmarkmarkx; 251 int16 at_cbmarkcurnote; 252 int16 at_cbmarkcurx; 253 int16 at_cbmarktrack; 254 int16 at_cbmarkstartnote; 255 int16 at_cbmarkendnote; 256 int16 at_cbmarkleftx; 257 int16 at_cbmarkrightx; 258 int16 at_cbmarkbits; 259 260 // Posed mark 261 int16 at_cbpmarkmarkpos; 262 int16 at_cbpmarkmarklft; 263 int16 at_cbpmarklft; 264 int16 at_cbpmarktop; 265 int16 at_cbpmarkrgt; 266 int16 at_cbpmarkbot; 267 int16 at_cbpmarklftcol; 268 int16 at_cbpmarkrgtcol; 269 270 int16 at_notejump; 271 int16 at_inotejump; 272 int16 at_rempos[5]; 273 int32 at_defstereo; 274 int32 at_defpanleft; 275 int32 at_defpanright; 276 uint8 at_ticks; 277 uint8 at_secs; 278 uint8 at_mins; 279 uint8 at_hours; 280 281 int32 at_doing; 282 int32 at_editing; 283 int32 at_idoing; 284 285 // Undo stuff 286 struct ahx_plsentry at_rem_pls_Entries[256]; 287 TEXT at_rem_string[128]; 288 struct ahx_step at_rem_track[64]; 289 uint8 at_rem_posbuf[1000*MAX_CHANNELS*2]; 290 int32 at_rem_pbleft, at_rem_pbpos; 291 int32 at_rem_pbchans, at_rem_pbrows; 292 293 uint8 at_stopnextrow; 294 }; 295 296 enum { 297 RPC_STOP, 298 RPC_PLAY_SONG, 299 RPC_PLAY_POS, 300 RPC_PLAY_NOTE, 301 RPC_CONT_SONG, 302 RPC_CONT_POS, 303 RPC_PLAY_ROW 304 }; 305 306 struct rp_command 307 { 308 #ifndef __SDL_WRAPPER__ 309 struct Message rpc_Message; 310 #endif 311 uint16 rpc_Command; 312 uint16 rpc_Data; 313 uint16 rpc_Data2; 314 struct ahx_tune *rpc_Tune; 315 }; 316 317 struct ahx_tune *rp_load_tune( const TEXT *name, struct ahx_tune *at ); 318 BOOL rp_init( void ); 319 void rp_shutdown( void ); 320 void rp_handler( uint32 gotsigs ); 321 void rp_stop( void ); 322 struct ahx_tune *rp_new_tune( BOOL addtolist ); 323 void rp_free_tune( struct ahx_tune *at ); 324 void rp_clear_tune( struct ahx_tune *at ); 325 BOOL rp_play_note( struct ahx_tune *at, int32 inst, int32 note, int32 channel ); 326 void rp_load_ins( const TEXT *name, struct ahx_tune *at, int32 in ); 327 void rp_save_ins( const TEXT *name, struct ahx_tune *at, int32 in ); 328 BOOL rp_play_song( struct ahx_tune *at, uint32 subsong, BOOL cont ); 329 BOOL rp_play_pos( struct ahx_tune *at, BOOL cont ); 330 BOOL rp_init_subsong( struct ahx_tune *at, uint32 nr ); 331 uint32 rp_ahx_test( const struct ahx_tune *at ); 332 void rp_save_ahx( const TEXT *name, struct ahx_tune *at ); 333 void rp_save_hvl( const TEXT *name, struct ahx_tune *at ); 334 int32 rp_find_loudest( struct ahx_tune *at ); 335 void rp_clear_instrument( struct ahx_instrument *ins ); 336 void rp_zap_tracks( struct ahx_tune * at ); 337 void rp_zap_positions( struct ahx_tune *at ); 338 void rp_zap_instruments( struct ahx_tune *at ); 339 BOOL rp_play_row( struct ahx_tune *at ); 340 341 #define SWB_DOUBLECMD 0 342 #define SWF_DOUBLECMD (1L<<SWB_DOUBLECMD) 343 #define SWB_NEWINSCMD 1 344 #define SWF_NEWINSCMD (1L<<SWB_NEWINSCMD) 345 #define SWB_MANYCHANS 2 346 #define SWF_MANYCHANS (1L<<SWB_MANYCHANS) 347 #define SWB_PANCMD 3 348 #define SWF_PANCMD (1L<<SWB_PANCMD) 349 #define SWB_EFXCMD 4 350 #define SWF_EFXCMD (1L<<SWB_EFXCMD) 351