music initialization function, sets up subblock array, tempo, instrument addreses and samples
| 699 | // music initialization function, sets up subblock array, |
| 700 | // tempo, instrument addreses and samples |
| 701 | void init_music_data(unsigned char* music_ptr,int length) |
| 702 | { |
| 703 | unsigned int i, to_add, j; |
| 704 | unsigned char* start=music_ptr; |
| 705 | for (i=0; i<16; ++i) |
| 706 | { |
| 707 | instruments[i].start_address = 0; |
| 708 | } |
| 709 | adl_gv_subtracks_count = 0; |
| 710 | |
| 711 | i = *music_ptr; |
| 712 | if (i>56) adl_gv_FORMAT=0; //switch to old |
| 713 | else adl_gv_FORMAT=1; |
| 714 | if (adl_gv_FORMAT==1) music_ptr += (*music_ptr )+1; //skip name |
| 715 | adl_gv_tempo = *(music_ptr++); |
| 716 | adl_gv_samples_addr = music_ptr+1; //samples |
| 717 | music_ptr += ((*music_ptr) * 24) +1; //moving to next section - subtracks |
| 718 | adl_gv_subtracks_count = *(music_ptr++); |
| 719 | for(i=0; i<adl_gv_subtracks_count; ++i) |
| 720 | { |
| 721 | to_add = *((unsigned short*)music_ptr); //reading 16bit length |
| 722 | adl_gv_subtracks[i] = music_ptr+4; //store subtrack pointers |
| 723 | music_ptr += to_add; |
| 724 | } |
| 725 | adl_gv_instruments_count = *(music_ptr++); |
| 726 | for (i=0; i<adl_gv_instruments_count; ++i) |
| 727 | { |
| 728 | to_add = *((unsigned short*)music_ptr); //reading 16bit length |
| 729 | if (adl_gv_FORMAT==1) |
| 730 | { |
| 731 | j = *(music_ptr+4); |
| 732 | if (j>16) j=16; |
| 733 | instruments[j].start_address = music_ptr+5; |
| 734 | } |
| 735 | else |
| 736 | if (adl_gv_FORMAT==0) |
| 737 | { |
| 738 | j = i; |
| 739 | instruments[j].start_address = music_ptr+4; //old format, without title |
| 740 | } |
| 741 | music_ptr += to_add; |
| 742 | if (music_ptr-start>=length) |
| 743 | { |
| 744 | //printf("DATA ERROR: track number %d has a length of %d, and gone to offset %d\n",i,to_add,music_ptr-start); |
| 745 | break; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | |
| 751 | //initialize music tracks, prepare for playing |