DOOM64-RE

DOOM 64 Reverse Engineering
Log | Files | Refs | README | LICENSE

wessseq.c (21188B)


      1 // Reconstruido por Erick Vasquez Garcia 16/05/2019 [GEC]
      2 // Update_1 20/10/2019 [GEC]
      3 // Update_2 31/01/2020 [GEC]
      4 
      5 #include "wessseq.h"
      6 
      7 #include "graph.h"
      8 #ifndef NOUSEWESSCODE
      9 extern void (**CmdFuncArr[10])(track_status *);
     10 extern void(*DrvFunctions[36])(track_status *);
     11 
     12 char *Read_Vlq(char *pstart, void *deltatime);
     13 char *Write_Vlq(char *dest, unsigned int value);
     14 int Len_Vlq(unsigned int value);
     15 
     16 void Eng_DriverInit (track_status *ptk_stat);//(master_status_structure *pm_stat);
     17 void Eng_DriverExit (track_status *ptk_stat);
     18 void Eng_DriverEntry1 (track_status *ptk_stat);
     19 void Eng_DriverEntry2 (track_status *ptk_stat);
     20 void Eng_DriverEntry3 (track_status *ptk_stat);
     21 void Eng_TrkOff (track_status *ptk_stat);
     22 void Eng_TrkMute (track_status *ptk_stat);
     23 void Eng_PatchChg (track_status *ptk_stat);
     24 void Eng_PatchMod (track_status *ptk_stat);
     25 void Eng_PitchMod (track_status *ptk_stat);
     26 void Eng_ZeroMod (track_status *ptk_stat);
     27 void Eng_ModuMod (track_status *ptk_stat);
     28 void Eng_VolumeMod (track_status *ptk_stat);
     29 void Eng_PanMod (track_status *ptk_stat);
     30 void Eng_PedalMod (track_status *ptk_stat);
     31 void Eng_ReverbMod (track_status *ptk_stat);
     32 void Eng_ChorusMod (track_status *ptk_stat);
     33 void Eng_NoteOn (track_status *ptk_stat);
     34 void Eng_NoteOff (track_status *ptk_stat);
     35 void Eng_StatusMark (track_status *ptk_stat);
     36 void Eng_GateJump (track_status *ptk_stat);
     37 void Eng_IterJump (track_status *ptk_stat);
     38 void Eng_ResetGates (track_status *ptk_stat);
     39 void Eng_ResetIters (track_status *ptk_stat);
     40 void Eng_WriteIterBox (track_status *ptk_stat);
     41 void Eng_SeqTempo (track_status *ptk_stat);
     42 void Eng_SeqGosub (track_status *ptk_stat);
     43 void Eng_SeqJump (track_status *ptk_stat);
     44 void Eng_SeqRet (track_status *ptk_stat);
     45 void Eng_SeqEnd (track_status *ptk_stat);
     46 void Eng_TrkTempo (track_status *ptk_stat);
     47 void Eng_TrkGosub (track_status *ptk_stat);
     48 void Eng_TrkJump (track_status *ptk_stat);
     49 void Eng_TrkRet (track_status *ptk_stat);
     50 void Eng_TrkEnd (track_status *ptk_stat);
     51 void Eng_NullEvent (track_status *ptk_stat);
     52 
     53 void(*DrvFunctions[36])(track_status *) =
     54 {
     55 	Eng_DriverInit,
     56 	Eng_DriverExit,
     57 	Eng_DriverEntry1,
     58 	Eng_DriverEntry2,
     59 	Eng_DriverEntry3,
     60 	Eng_TrkOff,
     61 	Eng_TrkMute,
     62 	Eng_PatchChg,
     63 	Eng_PatchMod,
     64 	Eng_PitchMod,
     65 	Eng_ZeroMod,
     66 	Eng_ModuMod,
     67 	Eng_VolumeMod,
     68 	Eng_PanMod,
     69 	Eng_PedalMod,
     70 	Eng_ReverbMod,
     71 	Eng_ChorusMod,
     72 	Eng_NoteOn,
     73 	Eng_NoteOff,
     74 	Eng_StatusMark,     //0x13
     75 	Eng_GateJump,       //0x14
     76 	Eng_IterJump,       //0x15
     77 	Eng_ResetGates,     //0x16
     78 	Eng_ResetIters,     //0x17
     79 	Eng_WriteIterBox,   //0x18
     80 	Eng_SeqTempo,       //0x19
     81 	Eng_SeqGosub,       //0x1A
     82 	Eng_SeqJump,        //0x1B
     83 	Eng_SeqRet,         //0x1C
     84 	//SeqFunctions ??
     85 	Eng_SeqEnd,         //0x1D
     86 	Eng_TrkTempo,       //0x1E
     87 	Eng_TrkGosub,       //0x1F
     88 	Eng_TrkJump,        //0x20
     89 	Eng_TrkRet,         //0x21
     90 	Eng_TrkEnd,         //0x22
     91 	Eng_NullEvent       //0x23
     92 };
     93 
     94 unsigned char CmdLength[36] = { // 8005D9F0
     95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
     96 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
     97 0x02, 0x03, 0x02, 0x04, 0x05, 0x05, 0x02, 0x02,
     98 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03,
     99 0x03, 0x01, 0x01, 0x01
    100 };
    101 
    102 unsigned char CmdSort[44] = { // 8005DA14
    103 0x00, 0x01, 0x02, 0x03, 0x04, 0x07, 0x06, 0x16,
    104 0x17, 0x18, 0x15, 0x1A, 0x1E, 0x19, 0x1B, 0x1D,
    105 0x1C, 0x1F, 0x05, 0x0F, 0x08, 0x09, 0x12, 0x11,
    106 0x10, 0x14, 0x0D, 0x0B, 0x22, 0x23, 0x13, 0x0C,
    107 0x0A, 0x20, 0x21, 0x0E, 0x00, 0x00, 0x00, 0x00,
    108 0x00, 0x00, 0x00, 0x00
    109 };
    110 
    111 //-----------------------------------------------------------
    112 // Vlq System
    113 //-----------------------------------------------------------
    114 
    115 //extern unsigned int data01;    //L8007F024
    116 //extern unsigned char data02;    //L8007F028
    117 
    118 char *Read_Vlq(char *pstart, void *deltatime)//L80035F80()
    119 {
    120 	static int v;//800B6630
    121 	static char c;//800B6634
    122 
    123 	v = *pstart++;
    124 	if (v & 0x80)
    125 	{
    126 		v &= 0x7f;
    127 		do
    128 		{
    129 			c = *pstart++;
    130 			v = (c & 0x7f) + (v << 7);
    131 		} while (c & 0x80);
    132 	}
    133 	*(int*)deltatime = v;
    134 
    135 	return pstart;
    136 }
    137 
    138 char *Write_Vlq(char *dest, unsigned int value)//L8004744C()
    139 {
    140 	char data[10];
    141 	char *ptr;
    142 
    143 	data[0] = (value & 0x7f);
    144 	ptr = (char*)&data + 1;
    145 
    146 	value >>= 7;
    147 	if (value)
    148 	{
    149 		do
    150 		{
    151 			*ptr++ = ((value & 0x7f) | 0x80);
    152 			value >>= 7;
    153 		} while (value);
    154 	}
    155 
    156 	do
    157 	{
    158 		ptr--;
    159 		*dest++ = *ptr;
    160 	} while (*ptr & 0x80);
    161 
    162 	return dest;
    163 }
    164 
    165 int Len_Vlq(unsigned int value)//L800474AC()
    166 {
    167     char buff[16];
    168 	char data[10];
    169 	char *ptr;
    170 	char *dest, *start;
    171 
    172 	dest = start = (char*)&buff;
    173 
    174 	data[0] = (value & 0x7f);
    175 	ptr = (char*)&data + 1;
    176 
    177 	value >>= 7;
    178 	if (value)
    179 	{
    180 		do
    181 		{
    182 			*ptr++ = ((value & 0x7f) | 0x80);
    183 			value >>= 7;
    184 		} while (value);
    185 	}
    186 
    187 	do
    188 	{
    189 		ptr--;
    190 		*dest++ = *ptr;
    191 	} while (*ptr & 0x80);
    192 
    193 	return (int)(dest - start);
    194 }
    195 //-----------------------------------------------------------
    196 // Engine System
    197 //-----------------------------------------------------------
    198 
    199 static unsigned char			ntwa = 0;		//8005DAD4
    200 static track_status				*ptsbase = 0;	//8005DAD8
    201 static sequence_status			*pssbase = 0;	//8005DADC
    202 static master_status_structure	*pmsbase = 0;	//8005DAE0
    203 
    204 void Eng_DriverInit (track_status *ptk_stat) // 800360C4
    205 {
    206 	master_status_structure *pm_stat;
    207 
    208 	pm_stat = (master_status_structure*)ptk_stat;
    209 
    210 	//PRINTF_D2(WHITE,0,10,"Eng_DriverInit");
    211     ntwa = wess_driver_tracks;
    212 	ptsbase = pm_stat->ptrkstattbl;
    213 	pssbase = pm_stat->pseqstattbl;
    214 	pmsbase = pm_stat;
    215 
    216 	//PRINTF_D(WHITE,"ntwa %d\n", ntwa);
    217 	//PRINTF_D(WHITE,"ptsbase %x\n", (int)&ptsbase);
    218 	//PRINTF_D(WHITE,"pssbase %x\n", (int)&pssbase);
    219 	//PRINTF_D(WHITE,"pmsbase %x\n", (int)&pmsbase);
    220 }
    221 
    222 void Eng_DriverExit (track_status *ptk_stat) // 800360FC
    223 {
    224     //PRINTF_D2(WHITE,0,10,"Eng_DriverExit");
    225 }
    226 
    227 void Eng_DriverEntry1 (track_status *ptk_stat) // 80036104
    228 {
    229     //PRINTF_D2(WHITE,0,10,"Eng_DriverEntry1");
    230 }
    231 
    232 void Eng_DriverEntry2 (track_status *ptk_stat) // 8003610C
    233 {
    234     //PRINTF_D2(WHITE,0,10,"Eng_DriverEntry2");
    235 }
    236 
    237 void Eng_DriverEntry3 (track_status *ptk_stat) // 80036114
    238 {
    239     //PRINTF_D2(WHITE,0,10,"Eng_DriverEntry3");
    240 }
    241 
    242 void Eng_TrkOff (track_status *ptk_stat) // 8003611C
    243 {
    244 	static sequence_status	*lpseq;	//800B6638
    245 	static char				*lpdest;//800B663C
    246 	static unsigned long	lj;		//800B6640
    247 
    248 	//PRINTF_D2(WHITE,0,10,"Eng_TrkOff");
    249 
    250 	lpseq = (pmsbase->pseqstattbl + ptk_stat->seq_owner);
    251 
    252 	if (!(ptk_stat->flags & TRK_STOPPED))
    253 	{
    254 		ptk_stat->flags |= TRK_STOPPED;
    255 
    256 		if (!--lpseq->tracks_playing)
    257 		{
    258 			lpseq->playmode = SEQ_STATE_STOPPED;
    259 		}
    260 	}
    261 
    262 	if (!(ptk_stat->flags & TRK_HANDLED))
    263 	{
    264 		lj = pmsbase->max_trks_perseq;
    265 		lpdest = lpseq->ptrk_indxs;
    266 
    267 		while (lj--)
    268 		{
    269 			if (ptk_stat->refindx == *lpdest)
    270 			{
    271 				*lpdest++ = 0xff;
    272 				break;
    273 			}
    274 			lpdest++;
    275 		}
    276 
    277 		ptk_stat->flags &= ~TRK_ACTIVE;
    278 		pmsbase->trks_active--;
    279 
    280 		if (!--lpseq->tracks_active)
    281 		{
    282 			lpseq->flags &= ~SEQ_ACTIVE;
    283 			pmsbase->seqs_active--;
    284 		}
    285 	}
    286 
    287 	ptk_stat->flags &= ~TRK_TIMED;
    288 }
    289 
    290 void Eng_TrkMute (track_status *ptk_stat) // 80036298
    291 {
    292     //PRINTF_D2(WHITE,0,10,"Eng_TrkMute");
    293 }
    294 
    295 void Eng_PatchChg (track_status *ptk_stat) // 800362A0
    296 {
    297 	static unsigned char thepatch;//800B6644
    298 
    299 	//PRINTF_D2(WHITE,0,10,"Eng_PatchChg");
    300 
    301 	thepatch = (*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    302 	ptk_stat->patchnum = (unsigned short)thepatch;
    303 }
    304 
    305 
    306 void Eng_PatchMod (track_status *ptk_stat) // 800362C8
    307 {
    308     //PRINTF_D2(WHITE,0,10,"Eng_PatchMod");
    309 }
    310 
    311 void Eng_PitchMod (track_status *ptk_stat) // 800362D0
    312 {
    313     static short thepitchmod;//800B6646
    314 
    315 	//PRINTF_D2(WHITE,0,10,"Eng_PitchMod");
    316 
    317 	thepitchmod = (*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    318 	ptk_stat->pitch_cntrl = thepitchmod;
    319 }
    320 
    321 void Eng_ZeroMod (track_status *ptk_stat) // 800362F4
    322 {
    323     //PRINTF_D2(WHITE,0,10,"Eng_ZeroMod");
    324 }
    325 
    326 void Eng_ModuMod (track_status *ptk_stat) // 800362FC
    327 {
    328     //PRINTF_D2(WHITE,0,10,"Eng_ModuMod");
    329 }
    330 
    331 void Eng_VolumeMod (track_status *ptk_stat) // 80036304
    332 {
    333     static unsigned char thevolume; //800B6648
    334 
    335 	//PRINTF_D2(WHITE,0,10,"Eng_VolumeMod");
    336 
    337 	thevolume = *(ptk_stat->ppos + 1);
    338 	ptk_stat->volume_cntrl = thevolume;
    339 }
    340 
    341 void Eng_PanMod (track_status *ptk_stat) // 80036320
    342 {
    343     static unsigned char thepan; //0x800B6649
    344 
    345 	//PRINTF_D2(WHITE,0,10,"Eng_PanMod");
    346 	thepan = *(ptk_stat->ppos + 1);
    347 	ptk_stat->pan_cntrl = thepan;
    348 }
    349 
    350 void Eng_PedalMod (track_status *ptk_stat) // 8003633C
    351 {
    352     //PRINTF_D2(WHITE,0,10,"Eng_PedalMod");
    353 }
    354 
    355 void Eng_ReverbMod (track_status *ptk_stat) // 80036344
    356 {
    357     //PRINTF_D2(WHITE,0,10,"Eng_ReverbMod");
    358 }
    359 
    360 void Eng_ChorusMod (track_status *ptk_stat) // 8003634C
    361 {
    362     //PRINTF_D2(WHITE,0,10,"Eng_ChorusMod");
    363 }
    364 
    365 void Eng_NoteOn (track_status *ptk_stat) // 80036354
    366 {
    367     //PRINTF_D2(WHITE,0,10,"Eng_NoteOn");
    368 }
    369 
    370 void Eng_NoteOff (track_status *ptk_stat) // 8003635C
    371 {
    372     //PRINTF_D2(WHITE,0,10,"Eng_NoteOff");
    373 }
    374 
    375 void Eng_StatusMark (track_status *ptk_stat) // 80036364
    376 {
    377 	static char si, sn;				//800B664A, 800B664B
    378 	static callback_status *cbs;	//800B664C
    379 
    380 	//PRINTF_D2(WHITE,0,10,"Eng_StatusMark");
    381 
    382 	sn = pmsbase->callbacks_active;
    383 	if (sn)
    384 	{
    385 		cbs = pmsbase->pcalltable;
    386 		si = wess_driver_callbacks;
    387 		if(wess_driver_callbacks)
    388 		{
    389 			while (si--)
    390 			{
    391 				if (cbs->active)
    392 				{
    393 					if (cbs->type == *(ptk_stat->ppos + 1))
    394 					{
    395 						cbs->curval = (*(ptk_stat->ppos + 2) | (*(ptk_stat->ppos + 3) << 8));
    396 						cbs->callfunc(cbs->type, cbs->curval);
    397 						break;
    398 					}
    399 
    400 					if (!--sn) break;
    401 				}
    402 
    403 				cbs++;
    404 			}
    405 		}
    406 	}
    407 }
    408 
    409 void Eng_GateJump (track_status *ptk_stat) // 80036488
    410 {
    411 	static short lindex;	//800B6650
    412 	static char *laboff;	//800B6654
    413 	static char *pgate;		//800B6658
    414 
    415 	//PRINTF_D2(WHITE,0,10,"Eng_GateJump");
    416 	pgate = (pssbase + ptk_stat->seq_owner)->pgates + *(ptk_stat->ppos + 1);
    417 
    418 	if (*pgate != 0)
    419 	{
    420 		if (*pgate == 0xff)
    421 		{
    422 			*pgate = *(ptk_stat->ppos + 2);
    423 		}
    424 
    425 		lindex = (*(ptk_stat->ppos + 3) | (*(ptk_stat->ppos + 4) << 8));
    426 
    427 		if (lindex >= 0)
    428 		{
    429 			if (lindex < ptk_stat->labellist_count)
    430 			{
    431 				laboff = ptk_stat->pstart + *(ptk_stat->plabellist + lindex);
    432 				ptk_stat->ppos = laboff;
    433 				ptk_stat->deltatime = 0;
    434 				ptk_stat->flags |= TRK_SKIP;
    435 			}
    436 		}
    437 	}
    438 }
    439 
    440 void Eng_IterJump (track_status *ptk_stat) // 80036568
    441 {
    442 	static short lindex;	//800B665C
    443 	static char	*laboff;	//800B6660
    444 	static char	*piter;		//800B6664
    445 
    446 	//PRINTF_D2(WHITE,0,10,"Eng_IterJump");
    447 	piter = (pssbase + ptk_stat->seq_owner)->piters + *(ptk_stat->ppos + 1);
    448 
    449 	if (*piter != 0)
    450 	{
    451 		if (*piter == 0xFF)
    452 		{
    453 			*piter = *(ptk_stat->ppos + 2);
    454 		}
    455 		else
    456 		{
    457 			*piter = *piter + 0xFF;
    458 		}
    459 
    460 		lindex = (*(ptk_stat->ppos + 3) | (*(ptk_stat->ppos + 4) << 8));
    461 
    462 		if (lindex >= 0)
    463 		{
    464 			if (lindex < ptk_stat->labellist_count)
    465 			{
    466 				laboff = ptk_stat->pstart + *(ptk_stat->plabellist + lindex);
    467 				ptk_stat->ppos = laboff;
    468 				ptk_stat->deltatime = 0;
    469 				ptk_stat->flags |= TRK_SKIP;
    470 			}
    471 		}
    472 	}
    473 }
    474 
    475 void Eng_ResetGates (track_status *ptk_stat) // 80036654
    476 {
    477 	static unsigned char	gi;		//800B6668
    478 	static char				*pgate;	//800B666C
    479 
    480 	//PRINTF_D2(WHITE,0,10,"Eng_ResetGates");
    481 	if (*(ptk_stat->ppos + 1) == 0xff)
    482 	{
    483 		gi = wess_driver_gates;
    484 		pgate = (pssbase + ptk_stat->seq_owner)->pgates;
    485 
    486 		while (gi--)
    487 		{
    488 			*pgate++ = 0xFF;
    489 		}
    490 	}
    491 	else
    492 	{
    493 		pgate = (pssbase + ptk_stat->seq_owner)->pgates + *(ptk_stat->ppos + 1);
    494 		*pgate = 0xff;
    495 	}
    496 }
    497 
    498 void Eng_ResetIters (track_status *ptk_stat) // 80036720
    499 {
    500 	static unsigned char	ii;		//800B6670
    501 	static char				*piter;	//800B6674
    502 
    503 	//PRINTF_D2(WHITE,0,10,"Eng_ResetIters");
    504 	if (*(ptk_stat->ppos + 1) == 0xff)
    505 	{
    506 		ii = wess_driver_iters;
    507 		piter = (pssbase + ptk_stat->seq_owner)->piters;
    508 
    509 		while (ii--)
    510 		{
    511 			*piter++ = 0xFF;
    512 		}
    513 	}
    514 	else
    515 	{
    516 		piter = (pssbase + ptk_stat->seq_owner)->piters + *(ptk_stat->ppos + 1);
    517 		*piter = 0xff;
    518 	}
    519 }
    520 
    521 void Eng_WriteIterBox (track_status *ptk_stat) // 800367EC
    522 {
    523 	static char	*piter;//800B6678
    524 
    525 	//PRINTF_D2(WHITE,0,10,"Eng_WriteIterBox");
    526 	piter = (pssbase + ptk_stat->seq_owner)->piters + *(ptk_stat->ppos + 1);
    527 	*piter = *(ptk_stat->ppos + 2);
    528 }
    529 
    530 void Eng_SeqTempo (track_status *ptk_stat) // 8003682C
    531 {
    532 	static unsigned short	ntracks;		//800B667C
    533 	static unsigned char	nactive;		//800B667E
    534 	static unsigned char	*ptindxs;					//800B6680
    535 	static track_status		*ptstemp;		//800B6684
    536 	static sequence_status	*psstemp;		//800B6688
    537 
    538 	//PRINTF_D2(WHITE,0,10,"Eng_SeqTempo");
    539 
    540 	psstemp = (pssbase + ptk_stat->seq_owner);
    541 	ptindxs = (unsigned char *)psstemp->ptrk_indxs;
    542 	nactive = psstemp->tracks_active;
    543 	ntracks = (pmsbase->pmod_info->pseq_info + psstemp->seq_num)->seq_hdr.tracks;
    544 
    545 	while (ntracks--)
    546 	{
    547 		if (*ptindxs != 0xff)
    548 		{
    549 			ptstemp = (ptsbase + (*ptindxs));
    550 			ptstemp->qpm = (unsigned short)(*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    551 			ptstemp->ppi = CalcPartsPerInt(GetIntsPerSec(), ptstemp->ppq, ptstemp->qpm);
    552 
    553 			if (!--nactive) break;
    554 		}
    555 		ptindxs++;
    556 	}
    557 }
    558 
    559 void Eng_SeqGosub (track_status *ptk_stat) // 800369C8
    560 {
    561 	static short			lindex;			//800B668C
    562 	static unsigned short	ntracks;		//800B668E
    563 	static char				*laboff;		//800B6690
    564 	static unsigned char	nactive;		//800B6694
    565 	static unsigned char	*ptindxs;		//800B6698
    566 	static track_status		*ptstemp;		//800B669C
    567 	static sequence_status	*psstemp;		//800B66A0
    568 
    569 	//PRINTF_D2(WHITE,0,10,"Eng_SeqGosub");
    570 
    571 	lindex = (*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    572 
    573 	if ((lindex >= 0) && (lindex < ptk_stat->labellist_count))
    574 	{
    575 		psstemp = (pssbase + ptk_stat->seq_owner);
    576 		ptindxs = (unsigned char *)psstemp->ptrk_indxs;
    577 		nactive = psstemp->tracks_active;
    578 		ntracks = (pmsbase->pmod_info->pseq_info + psstemp->seq_num)->seq_hdr.tracks;
    579 
    580 		while (ntracks--)
    581 		{
    582 			if (*ptindxs != 0xFF)
    583 			{
    584 				ptstemp = (ptsbase + (*ptindxs));
    585 
    586 				ptstemp->psp = (unsigned char*)ptstemp->ppos + CmdLength[26];
    587 				ptstemp->psp++;
    588 				laboff = ptstemp->pstart + *(ptstemp->plabellist + lindex);
    589 				ptstemp->ppos = laboff;
    590 				ptstemp->deltatime = 0;
    591 				ptstemp->flags |= TRK_SKIP;
    592 
    593 				if (!--nactive) break;
    594 			}
    595 			ptindxs++;
    596 		}
    597 	}
    598 }
    599 
    600 void Eng_SeqJump (track_status *ptk_stat) // 80036B80
    601 {
    602 	static short			lindex;			//800B66A4
    603 	static unsigned short	ntracks;		//800B66A6
    604 	static char				*laboff;		//800B66A8
    605 	static unsigned char	nactive;		//800B66AC
    606 	static unsigned char	*ptindxs;		//800B66B0
    607 	static track_status		*ptstemp;		//800B66B4
    608 	static sequence_status	*psstemp;		//800B66B8
    609 
    610 	//PRINTF_D2(WHITE,0,10,"Eng_SeqJump");
    611 
    612 	lindex = (*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    613 
    614 	if ((lindex >= 0) && (lindex < ptk_stat->labellist_count))
    615 	{
    616 		psstemp = (pssbase + ptk_stat->seq_owner);
    617 		ptindxs = (unsigned char *)psstemp->ptrk_indxs;
    618 		nactive = psstemp->tracks_active;
    619 		ntracks = (pmsbase->pmod_info->pseq_info + psstemp->seq_num)->seq_hdr.tracks;
    620 
    621 		while (ntracks--)
    622 		{
    623 			if (*ptindxs != 0xFF)
    624 			{
    625 				ptstemp = (ptsbase + (*ptindxs));
    626 				laboff = ptstemp->pstart + *(ptstemp->plabellist + lindex);
    627 				ptstemp->ppos = laboff;
    628 				ptstemp->deltatime = 0;
    629 				ptstemp->flags |= TRK_SKIP;
    630 
    631 				if (!--nactive) break;
    632 			}
    633 			ptindxs++;
    634 		}
    635 	}
    636 }
    637 
    638 void Eng_SeqRet (track_status *ptk_stat) // 80036D10
    639 {
    640 	static unsigned short	ntracks;		//800B66BC
    641 	static unsigned char	nactive;		//800B66BE
    642 	static unsigned char	*ptindxs;		//800B66C0
    643 	static track_status		*ptstemp;		//800B66C4
    644 	static sequence_status	*psstemp;		//800B66C8
    645 
    646 	//PRINTF_D2(WHITE,0,10,"Eng_SeqRet");
    647 
    648 	psstemp = (pssbase + ptk_stat->seq_owner);
    649 	ptindxs = (unsigned char *)psstemp->ptrk_indxs;
    650 	nactive = psstemp->tracks_active;
    651 	ntracks = (pmsbase->pmod_info->pseq_info + psstemp->seq_num)->seq_hdr.tracks;
    652 
    653 	while (ntracks--)
    654 	{
    655 		if (*ptindxs != 0xFF)
    656 		{
    657 			ptstemp = (ptsbase + (*ptindxs));
    658 			ptstemp->psp--;
    659 			ptstemp->deltatime = 0;
    660 			ptstemp->flags |= TRK_SKIP;
    661 			ptstemp->ppos = (unsigned char*)ptstemp->psp;
    662 
    663 			if (!--nactive) break;
    664 		}
    665 		ptindxs++;
    666 	}
    667 }
    668 
    669 void Eng_SeqEnd (track_status *ptk_stat) // 80036E48
    670 {
    671 	static sequence_status	*lpseq;		//800B66CC
    672 	static track_status		*ptmp;		//800B66D0
    673 	static unsigned char	*lpdest;	//800B66D4
    674 	static unsigned char	li;			//800B66D8
    675 	static unsigned long	lj;			//800B66DC
    676 
    677 	//PRINTF_D2(WHITE,0,10,"Eng_SeqEnd");
    678 
    679 	if (ptk_stat->flags & TRK_HANDLED)
    680 	{
    681 		lpseq = (pmsbase->pseqstattbl + ptk_stat->seq_owner);
    682 		lpdest = (unsigned char	*)lpseq->ptrk_indxs;
    683 		li = lpseq->tracks_active;
    684 		lj = pmsbase->max_trks_perseq;
    685 
    686 		while (lj--)
    687 		{
    688 			if (*lpdest != 0xFF)
    689 			{
    690 				ptmp = (ptsbase + *lpdest);
    691 				CmdFuncArr[ptmp->patchtype][TrkOff]((track_status *)ptmp);
    692 
    693 				if (!--li) break;
    694 			}
    695 
    696 			lpdest++;
    697 		}
    698 
    699 		ptk_stat->flags |= TRK_SKIP;
    700 	}
    701 	else
    702 	{
    703 		lpseq = (pmsbase->pseqstattbl + ptk_stat->seq_owner);
    704 		lpdest = (unsigned char	*)lpseq->ptrk_indxs;
    705 		li = lpseq->tracks_active;
    706 		lj = pmsbase->max_trks_perseq;
    707 
    708 		while (lj--)
    709 		{
    710 			if (*lpdest != 0xFF)
    711 			{
    712 				ptmp = (ptsbase + *lpdest);
    713 				CmdFuncArr[ptmp->patchtype][TrkOff]((track_status *)ptmp);
    714 
    715 				if (!--li) break;
    716 			}
    717 
    718 			lpdest++;
    719 		}
    720 	}
    721 }
    722 
    723 void Eng_TrkTempo (track_status *ptk_stat) // 800370D8
    724 {
    725 	//PRINTF_D2(WHITE,0,10,"Eng_TrkTempo");
    726 	ptk_stat->qpm = *(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8);
    727 	ptk_stat->ppi = CalcPartsPerInt(GetIntsPerSec(), ptk_stat->ppq, ptk_stat->qpm);
    728 }
    729 
    730 void Eng_TrkGosub (track_status *ptk_stat) // 8003713C
    731 {
    732 	unsigned int position;
    733 
    734 	//PRINTF_D2(WHITE,0,10,"Eng_TrkGosub");
    735 
    736 	position = (unsigned int)(*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    737 	if ((position >= 0) && (position < ptk_stat->labellist_count))
    738 	{
    739 		ptk_stat->psp = (unsigned char*)ptk_stat->ppos + CmdLength[26];
    740 		ptk_stat->psp++;
    741 		ptk_stat->ppos = ptk_stat->pstart + *(ptk_stat->plabellist + position);
    742 		ptk_stat->deltatime = 0;
    743 		ptk_stat->flags |= TRK_SKIP;
    744 	}
    745 }
    746 
    747 void Eng_TrkJump (track_status *ptk_stat) // 800371C4
    748 {
    749 	unsigned int position;
    750 
    751 	//PRINTF_D2(WHITE,0,10,"Eng_TrkJump");
    752 
    753 	position = (unsigned int)(*(ptk_stat->ppos + 1) | (*(ptk_stat->ppos + 2) << 8));
    754 	if ((position >= 0) && (position < ptk_stat->labellist_count))
    755 	{
    756 		ptk_stat->ppos = ptk_stat->pstart + *(ptk_stat->plabellist + position);
    757 		ptk_stat->deltatime = 0;
    758 		ptk_stat->flags |= TRK_SKIP;
    759 	}
    760 }
    761 
    762 void Eng_TrkRet (track_status *ptk_stat) // 80037230
    763 {
    764     //PRINTF_D2(WHITE,0,10,"Eng_TrkRet");
    765 	ptk_stat->psp--;
    766 	ptk_stat->ppos = (unsigned char*)ptk_stat->psp;
    767 	ptk_stat->ppos = Read_Vlq(ptk_stat->ppos, &ptk_stat->deltatime);
    768 	ptk_stat->deltatime = 0;
    769 	ptk_stat->flags |= TRK_SKIP;
    770 }
    771 
    772 void Eng_TrkEnd (track_status *ptk_stat) // 8003728C
    773 {
    774 	//PRINTF_D2(WHITE,0,10,"Eng_TrkEnd");
    775 
    776 	if (ptk_stat->flags & TRK_HANDLED)
    777 	{
    778 		if ((ptk_stat->flags & TRK_LOOPED) && (ptk_stat->totppi > 15))
    779 		{
    780 			ptk_stat->flags |= TRK_SKIP;
    781 			ptk_stat->ppos = ptk_stat->pstart;
    782 			ptk_stat->ppos = Read_Vlq(ptk_stat->pstart, &ptk_stat->deltatime);
    783 		}
    784 		else
    785 		{
    786 			CmdFuncArr[ptk_stat->patchtype][TrkOff](ptk_stat);
    787 			ptk_stat->flags |= TRK_SKIP;
    788 		}
    789 	}
    790 	else
    791 	{
    792 		if ((ptk_stat->flags & TRK_LOOPED) && (ptk_stat->totppi > 15))
    793 		{
    794 			ptk_stat->flags |= TRK_SKIP;
    795 			ptk_stat->ppos = ptk_stat->pstart;
    796 			ptk_stat->ppos = Read_Vlq(ptk_stat->pstart, &ptk_stat->deltatime);
    797 		}
    798 		else
    799 		{
    800 			CmdFuncArr[ptk_stat->patchtype][TrkOff](ptk_stat);
    801 		}
    802 	}
    803 }
    804 
    805 void Eng_NullEvent (track_status *ptk_stat) // 800373A4
    806 {
    807     //PRINTF_D2(WHITE,0,10,"Eng_NullEvent");
    808 }
    809 
    810 void SeqEngine(void) // 800373AC
    811 {
    812 	static track_status		*pts;	//800B66E0
    813 	static unsigned char	na;		//800B66E4
    814 	static unsigned int		ni;		//800B66E8
    815 	static char				*nn;	//800B66EC
    816 
    817 	track_status *ptrkstattbl;
    818 	//PRINTF_D2(WHITE,0,9,"SeqEngine %d\n",SeqOn);
    819 
    820 	na = pmsbase->trks_active;
    821 	//PRINTF_D2(WHITE,0,4,"trks_active %d",na);
    822 	//PRINTF_D2(WHITE,0,5,"ptsbase->patchtype %d",ptsbase->patchtype);
    823 
    824 	if (na)
    825 	{
    826 		//printf("trks_active %d\n",na);
    827 		pts = ptsbase;
    828 		ni = ntwa;
    829 
    830 		while (ni--)
    831 		{
    832 			if ((pts->flags & TRK_ACTIVE))
    833 			{
    834 				if (!(pts->flags & TRK_STOPPED))
    835 				{
    836 					pts->starppi += pts->ppi;
    837 					pts->totppi += (pts->starppi >> 16);
    838 					pts->accppi += (pts->starppi >> 16);
    839 					pts->starppi &= 65535;
    840 					//printf("totppi %d\n",pts->totppi);
    841 					//printf("accppi %d\n",pts->accppi);
    842 					//printf("starppi %d\n",pts->starppi);
    843 
    844 					if (!(pts->flags & TRK_TIMED) || (pts->totppi < pts->endppi))
    845 					{
    846 						/*printf("totppi %d\n",pts->totppi);
    847 						printf("accppi %d\n",pts->accppi);
    848 						printf("starppi %d\n",pts->starppi);
    849 						printf("deltatime %d\n",pts->deltatime);*/
    850 
    851 						while (pts->deltatime <= pts->accppi &&
    852 							((pts->flags & (TRK_STOPPED | TRK_ACTIVE)) == TRK_ACTIVE))
    853 						{
    854 							pts->accppi -= pts->deltatime;
    855 							nn = (pts->ppos);
    856 
    857 							if (!(*nn < 7) && (*nn < 19))
    858 							{
    859 								CmdFuncArr[pts->patchtype][*nn]((track_status *)pts);
    860 
    861 								pts->ppos += CmdLength[*nn];
    862 								pts->ppos = Read_Vlq(pts->ppos, &pts->deltatime);
    863 							}
    864 							else if (!(*nn < 19) && (*nn < 36))
    865 							{
    866 								DrvFunctions[*nn]((track_status *)pts);
    867 
    868 								if ((pts->flags & (TRK_ACTIVE | TRK_SKIP)) == TRK_ACTIVE)
    869 								{
    870 									pts->ppos += CmdLength[*nn];
    871 									pts->ppos = Read_Vlq(pts->ppos, &pts->deltatime);
    872 								}
    873 								else
    874 								{
    875 									pts->flags &= ~TRK_SKIP;
    876 								}
    877 							}
    878 							else
    879 							{
    880 								Eng_SeqEnd((track_status *)pts);
    881 							}
    882 						}
    883 					}
    884 					else
    885 					{
    886 						CmdFuncArr[pts->patchtype][TrkOff]((track_status *)pts);
    887 					}
    888 				}
    889 
    890 				if (!--na) break;
    891 			}
    892 
    893 			pts++;
    894 		}
    895 	}
    896 
    897 	CmdFuncArr[ptsbase->patchtype][2](ptsbase);
    898 }
    899 
    900 #endif