main decode function - reads data from stream and decodes it accordingly
| 554 | |
| 555 | // main decode function - reads data from stream and decodes it accordingly |
| 556 | int decode_op(int instrument, bool* another_loop) |
| 557 | { |
| 558 | // const track=2; |
| 559 | struc_instruments* instr1 = &instruments[instrument]; |
| 560 | struc_instruments* instr2; |
| 561 | unsigned char* music_ptr = instr1->cur_address; |
| 562 | unsigned char opcode,arg1,arg2; |
| 563 | int delay = 0; |
| 564 | |
| 565 | do { |
| 566 | opcode = *(music_ptr++); |
| 567 | if (opcode == 0xfe) //call for subtrack |
| 568 | { |
| 569 | arg1 = *(music_ptr++); |
| 570 | //printf("Call for subtrack [%d] %d\n",instrument,arg1); |
| 571 | instr1->return_address = music_ptr; |
| 572 | music_ptr = adl_gv_subtracks[arg1]; |
| 573 | } |
| 574 | else if (opcode == 0xfd) //return from subtrack |
| 575 | { |
| 576 | if (instr1->return_address == 0) |
| 577 | { |
| 578 | //printf("Return from subtrack [%d] -> DOUBLE RETURN - ERROR\n",instrument); |
| 579 | } |
| 580 | else |
| 581 | { |
| 582 | music_ptr = instr1->return_address; |
| 583 | //printf("Return from subtrack [%d] -> %x\n",instrument,instr1->return_address); |
| 584 | instr1->return_address = 0; |
| 585 | } |
| 586 | } |
| 587 | else if (opcode == 0xff) //finishing track |
| 588 | { |
| 589 | //printf("Track finish [%d]\n",instrument); |
| 590 | adl_gv_music_playing = false; |
| 591 | delay = 0; |
| 592 | break; |
| 593 | } |
| 594 | else if (opcode >= 0x80) //opcode |
| 595 | { |
| 596 | instr1->prev_cmd = opcode; |
| 597 | //printf("Opcode [%d]: %02Xh\n", instrument, opcode); |
| 598 | opcode = *(music_ptr++); //read "repeated" opcode which goes to arg |
| 599 | } |
| 600 | |
| 601 | if (opcode<0x80) //can be not a opcode, just the repeated command |
| 602 | { |
| 603 | arg1 = opcode; |
| 604 | opcode = instr1->prev_cmd; |
| 605 | switch (opcode & 0xf0) { |
| 606 | case 0x80: //note off |
| 607 | arg2 = *(music_ptr++); |
| 608 | //printf("Opcode [%d] NOTE OFF: %d\n", instrument, arg1); |
| 609 | adlib_play_note(arg1,0,instrument); |
| 610 | --adl_gv_polyphony_level; |
| 611 | if (adl_gv_chorus_instruments[instrument] != 0) |
| 612 | { |
| 613 | adlib_play_note(arg1,0,adl_gv_chorus_instruments[instrument]); |
no test coverage detected