DOOM64-RE

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

wessarc.c (10907B)


      1 
      2 #include "wessapi.h"
      3 #include "wessarc.h"
      4 #include "wessint_s.h"
      5 #ifndef NOUSEWESSCODE
      6 extern void(*DrvFunctions[36])(track_status *);
      7 extern void(*drv_cmds[19])(track_status *);
      8 
      9 void (**CmdFuncArr[10])(track_status *) = {
     10     DrvFunctions,
     11     drv_cmds,
     12     DrvFunctions,
     13     DrvFunctions,
     14     DrvFunctions,
     15     DrvFunctions,
     16     DrvFunctions,
     17     DrvFunctions,
     18     DrvFunctions,
     19     DrvFunctions
     20     };
     21 
     22 int wess_driver_num_dma_buffers = 24;       // 8005D948
     23 int wess_driver_num_dma_messages = 32;      // 8005D94C
     24 int wess_driver_dma_buffer_length = 0x800;   // 8005D950
     25 int wess_driver_extra_samples = 80;         // 8005D954
     26 int wess_driver_frame_lag = 1;              // 8005D958
     27 int wess_driver_voices = 24;                // 8005D95C
     28 int wess_driver_updates = 48;               // 8005D960
     29 int wess_driver_sequences = 26;             // 8005D964
     30 int wess_driver_tracks = 25;                // 8005D968
     31 int wess_driver_gates = 0;                  // 8005D96C
     32 int wess_driver_iters = 0;                  // 8005D970
     33 int wess_driver_callbacks = 0;              // 8005D974
     34 int wess_driver_max_trks_per_seq = 16;      // 8005D978                                                                                        load_sequence_data:80039868(R),
     35 int wess_driver_max_subs_per_trk = 0;       // 8005D97C
     36 
     37 
     38 int WessTimerActive = 0;        // 8005D984
     39 int T2counter = 0;              // 8005D988
     40 unsigned long millicount = 0;   // 8005D98C
     41 int SeqOn = 0;                  // 8005D990
     42 unsigned long accmpi = 0;       // 8005D994
     43 int disabledeep = 0;            // 8005D998
     44 
     45 WessErrorCallbackProc wesserr;  // 800B4210
     46 WessDecompCallbackProc wessdecomp; // 800B4214
     47 long imask; // 800B4218
     48 
     49 void wess_set_error_callback(WessErrorCallbackProc errcall) // 80035290
     50 {
     51 	wesserr = errcall;
     52 }
     53 
     54 void wess_error_callback(char *errstring, int errnum1, int errnum2) // 8003529C
     55 {
     56 	if (wesserr)
     57 	{
     58 		wesserr(errstring, errnum1, errnum2);
     59 	}
     60 }
     61 
     62 void wess_set_decomp_callback(WessDecompCallbackProc decompcall) // 800352C8
     63 {
     64 	wessdecomp = decompcall;
     65 }
     66 
     67 int wess_decomp(unsigned char decomp_type,
     68 	char          *fileref,
     69 	unsigned long file_offset,
     70 	char          *ramdest,
     71 	unsigned long uncompressed_size) // 800352D4
     72 {
     73 	if (wessdecomp != 0)
     74 	{
     75 		return wessdecomp(decomp_type, fileref, file_offset, ramdest, uncompressed_size);
     76 	}
     77 
     78 	return(-1);
     79 }
     80 
     81 void wess_low_level_init(void) // 8003531C
     82 {
     83 	//Nothing
     84 }
     85 
     86 void wess_low_level_exit(void) // 80035324
     87 {
     88 	//Nothing
     89 }
     90 
     91 char *wess_malloc(char *mem) // 8003532C
     92 {
     93 	return NULL;
     94 }
     95 
     96 void wess_free(char *mem) // 80035338
     97 {
     98 	//Nothing
     99 }
    100 
    101 void wess_engine_off(void) // 80035340
    102 {
    103 	SeqOn = 0;
    104 }
    105 
    106 void wess_engine_on(void) // 8003534C
    107 {
    108 	SeqOn = 1;
    109 }
    110 
    111 void wess_disable(void) // 8003535C
    112 {
    113 	if (disabledeep == 0)
    114 	{
    115 		imask = wesssys_disable_ints();
    116 	}
    117 	disabledeep += 1;
    118 }
    119 
    120 void wess_enable(void) // 8003539C
    121 {
    122 	disabledeep += -1;
    123 	if (disabledeep == 0)
    124 	{
    125 		wesssys_restore_ints(imask);
    126 	}
    127 }
    128 
    129 short GetIntsPerSec(void) // 800353DC
    130 {
    131 	return(120);
    132 }
    133 
    134 
    135 unsigned long CalcPartsPerInt(short ips, short ppq, short qpm) // 800353E4
    136 {
    137 	register unsigned long arg0;
    138 	register unsigned long ppi;
    139 
    140     __ll_mul((s32) qpm >> 31, qpm, 0, (1<<16));
    141     asm("move	%0,$2":"=r"(arg0) : );
    142 	asm("move	%0,$3":"=r"(ppi) : );
    143     __ll_mul(arg0, (u32) ppi, (s32) ppq >> 31, ppq);
    144     asm("move	%0,$2":"=r"(arg0) : );
    145 	asm("move	%0,$3":"=r"(ppi) : );
    146     __ull_div(arg0, (u32) ppi, 0, 60);
    147     asm("move	%0,$2":"=r"(arg0) : );
    148 	asm("move	%0,$3":"=r"(ppi) : );
    149 	__ull_div(arg0, (u32) ppi, (s32) ips >> 31, ips);
    150 	asm("move	%0,$2":"=r"(arg0) : );
    151 	asm("move	%0,$3":"=r"(ppi) : );
    152     return (u32) ppi;
    153 }
    154 
    155 long WessInterruptHandler(void) // 80035458
    156 {
    157 	accmpi += 0x85555;
    158 	millicount += (accmpi >> 16);
    159 	accmpi &= 65535;
    160 
    161 	T2counter++;
    162 	if (SeqOn)
    163 	{
    164 		process_function_queue();
    165 		SeqEngine();
    166 	}
    167 	return(0);
    168 }
    169 
    170 void init_WessTimer(void) // 800354DC
    171 {
    172 	SeqOn = 0;
    173 	WessTimerActive = 1;
    174 }
    175 
    176 void exit_WessTimer(void) // 800354F4
    177 {
    178 	WessTimerActive = 0;
    179 }
    180 
    181 int Wess_init_for_LoadFileData(char *filename) // 80035500
    182 {
    183 	return(1);
    184 }
    185 
    186 char alignbuf[28]; // 800B41E4 unused
    187 Wess_File_IO_Struct module_fileref; // 800B4200
    188 Wess_Data_IO_Struct data_fileref; // 800B4208
    189 
    190 Wess_File_IO_Struct *module_open(char *filename) // 8003550C
    191 {
    192 	module_fileref.start = filename;
    193 	module_fileref.src = filename;
    194 	return &module_fileref;
    195 }
    196 
    197 int module_read(void *destptr, int readbytes, Wess_File_IO_Struct *fileptr) // 80035520
    198 {
    199 	wess_rom_copy(fileptr->src, (char *)destptr, readbytes);
    200 	fileptr->src += readbytes;
    201 	return readbytes;
    202 }
    203 
    204 int module_seek(Wess_File_IO_Struct *fileptr, int seekpos, int seekmode) // 80035574
    205 {
    206 	if (seekmode == SEEK_SET)
    207 	{
    208 		fileptr->src = fileptr->start + seekpos;
    209 	}
    210 	else if (seekmode == SEEK_CUR)
    211 	{
    212 		fileptr->src += seekpos;
    213 	}
    214 	return 0;
    215 }
    216 
    217 unsigned long module_tell(Wess_File_IO_Struct *fileptr) // 800355B0
    218 {
    219 	return (unsigned long)fileptr->src;
    220 }
    221 
    222 void module_close(Wess_File_IO_Struct *fileptr) // 800355BC
    223 {
    224 	return;
    225 }
    226 
    227 int get_num_Wess_Sound_Drivers(int **settings_tag_lists) // 800355C4
    228 {
    229 	return(1);
    230 }
    231 
    232 Wess_File_IO_Struct *data_open(char *filename) // 800355D0
    233 {
    234 	return &data_fileref;
    235 }
    236 
    237 int data_read(Wess_Data_IO_Struct *fileptr, void *destptr, int readbytes, int filepos) //800355E0
    238 {
    239 	return 0;
    240 }
    241 
    242 void data_close(Wess_Data_IO_Struct *fileptr) // 800355F8
    243 {
    244 	return;
    245 }
    246 
    247 static unsigned char sequence_table[128]; // 800B4220
    248 
    249 char *get_sequence_table(void) // 80035600
    250 {
    251 	master_status_structure *pm_stat_ptr;
    252 	int sequences;
    253 	int i;
    254 
    255 	pm_stat_ptr = (master_status_structure *)wess_get_master_status();
    256 
    257 	sequences = wess_driver_sequences;
    258 	if (sequences > 127)
    259 		sequences = 127;
    260 
    261 	if (pm_stat_ptr)
    262 	{
    263 		i = 0;
    264 		if (sequences > 0)
    265 		{
    266 			if (sequences & 3)
    267 			{
    268 				do
    269 				{
    270 					if ((pm_stat_ptr->pseqstattbl + i)->flags & SEQ_ACTIVE)
    271 						sequence_table[i] = '1';
    272 					else
    273 						sequence_table[i] = '0';
    274 
    275 					i++;
    276 				} while (sequences & 3 != i);
    277 			}
    278 		}
    279 
    280 		if (i != sequences)
    281 		{
    282 			do
    283 			{
    284 				if ((pm_stat_ptr->pseqstattbl + i)->flags & SEQ_ACTIVE)
    285 					sequence_table[i] = '1';
    286 				else
    287 					sequence_table[i] = '0';
    288 
    289 				if ((pm_stat_ptr->pseqstattbl + (i + 1))->flags & SEQ_ACTIVE)
    290 					sequence_table[i + 1] = '1';
    291 				else
    292 					sequence_table[i + 1] = '0';
    293 
    294 				if ((pm_stat_ptr->pseqstattbl + (i + 2))->flags & SEQ_ACTIVE)
    295 					sequence_table[i + 2] = '1';
    296 				else
    297 					sequence_table[i + 2] = '0';
    298 
    299 				if ((pm_stat_ptr->pseqstattbl + (i + 3))->flags & SEQ_ACTIVE)
    300 					sequence_table[i + 3] = '1';
    301 				else
    302 					sequence_table[i + 3] = '0';
    303 
    304 				i += 4;
    305 			} while (sequences != i);
    306 		}
    307 
    308 		sequence_table[sequences] = '\0';
    309 	}
    310 
    311 	return (char *)&sequence_table;
    312 }
    313 
    314 static unsigned char tracks_table[128]; // 800B42A0
    315 
    316 char *get_tracks_table(void) // 800357A0
    317 {
    318 	master_status_structure *pm_stat_ptr;
    319 	int tracks;
    320 	int i;
    321 
    322 	pm_stat_ptr = (master_status_structure *)wess_get_master_status();
    323 
    324 	tracks = wess_driver_tracks;
    325 	if (tracks > 127)
    326 		tracks = 127;
    327 
    328 	if (pm_stat_ptr)
    329 	{
    330 		i = 0;
    331 		if (tracks > 0)
    332 		{
    333 			if (tracks & 3)
    334 			{
    335 				do
    336 				{
    337 					if ((pm_stat_ptr->ptrkstattbl + i)->flags & TRK_ACTIVE)
    338 						tracks_table[i] = '1';
    339 					else
    340 						tracks_table[i] = '0';
    341 
    342 					i++;
    343 				} while (tracks & 3 != i);
    344 			}
    345 		}
    346 
    347 		if (i != tracks)
    348 		{
    349 			do
    350 			{
    351 				if ((pm_stat_ptr->ptrkstattbl + i)->flags & TRK_ACTIVE)
    352 					tracks_table[i] = '1';
    353 				else
    354 					tracks_table[i] = '0';
    355 
    356 				if ((pm_stat_ptr->ptrkstattbl + (i + 1))->flags & TRK_ACTIVE)
    357 					tracks_table[i + 1] = '1';
    358 				else
    359 					tracks_table[i + 1] = '0';
    360 
    361 				if ((pm_stat_ptr->ptrkstattbl + (i + 2))->flags & TRK_ACTIVE)
    362 					tracks_table[i + 2] = '1';
    363 				else
    364 					tracks_table[i + 2] = '0';
    365 
    366 				if ((pm_stat_ptr->ptrkstattbl + (i + 3))->flags & TRK_ACTIVE)
    367 					tracks_table[i + 3] = '1';
    368 				else
    369 					tracks_table[i + 3] = '0';
    370 
    371 				i += 4;
    372 			} while (tracks != i);
    373 		}
    374 
    375 		tracks_table[tracks] = '\0';
    376 	}
    377 
    378 	return (char *)&tracks_table;
    379 }
    380 
    381 int get_track_volume_cntrl(int track) // 8003593C
    382 {
    383 	master_status_structure *pm_stat_ptr;
    384 
    385 	pm_stat_ptr = (master_status_structure *)wess_get_master_status();
    386 
    387 	if (pm_stat_ptr)
    388 	{
    389 		return (pm_stat_ptr->ptrkstattbl + track)->volume_cntrl;
    390 	}
    391 
    392 	return -1;
    393 }
    394 
    395 static unsigned char voices_active_table[128]; // 800B4320
    396 
    397 char *get_voices_active_table(void) // L80035988
    398 {
    399 	master_status_structure *pm_stat_ptr;
    400 	int voices;
    401 	int i;
    402 
    403 	pm_stat_ptr = (master_status_structure *)wess_get_master_status();
    404 
    405 	voices = wess_driver_voices;
    406 
    407 	if (!(voices < 128))
    408 		voices = 127;
    409 
    410 	if (pm_stat_ptr)
    411 	{
    412 		i = 0;
    413 		if (voices > 0)
    414 		{
    415 			if (voices & 3)
    416 			{
    417 				do
    418 				{
    419 					if ((pm_stat_ptr->pvoicestattbl + i)->flags & VOICE_ACTIVE)
    420 						voices_active_table[i] = '1';
    421 					else
    422 						voices_active_table[i] = '0';
    423 
    424 					i++;
    425 				} while (voices & 3 != i);
    426 			}
    427 		}
    428 
    429 		if (i != voices)
    430 		{
    431 			do
    432 			{
    433 				if ((pm_stat_ptr->pvoicestattbl + i)->flags & VOICE_ACTIVE)
    434 					voices_active_table[i] = '1';
    435 				else
    436 					voices_active_table[i] = '0';
    437 
    438 				if ((pm_stat_ptr->pvoicestattbl + (i + 1))->flags & VOICE_ACTIVE)
    439 					voices_active_table[i + 1] = '1';
    440 				else
    441 					voices_active_table[i + 1] = '0';
    442 
    443 				if ((pm_stat_ptr->pvoicestattbl + (i + 2))->flags & VOICE_ACTIVE)
    444 					voices_active_table[i + 2] = '1';
    445 				else
    446 					voices_active_table[i + 2] = '0';
    447 
    448 				if ((pm_stat_ptr->pvoicestattbl + (i + 3))->flags & VOICE_ACTIVE)
    449 					voices_active_table[i + 3] = '1';
    450 				else
    451 					voices_active_table[i + 3] = '0';
    452 
    453 				i += 4;
    454 			} while (voices != i);
    455 		}
    456 
    457 		voices_active_table[voices] = '\0';
    458 	}
    459 
    460 	return (char *)&voices_active_table;
    461 }
    462 
    463 static unsigned char voices_handle_table[128]; // 800B43A0
    464 
    465 char *get_voices_handle_table(void) // 80035B24
    466 {
    467 	master_status_structure *pm_stat_ptr;
    468 	int voices;
    469 	int i;
    470 
    471 	pm_stat_ptr = (master_status_structure *)wess_get_master_status();
    472 
    473 	voices = wess_driver_voices;
    474 
    475 	if (!(voices < 128))
    476 		voices = 127;
    477 
    478 	if (pm_stat_ptr)
    479 	{
    480 		i = 0;
    481 		if (voices > 0)
    482 		{
    483 			if (voices & 3)
    484 			{
    485 				do
    486 				{
    487 					if ((pm_stat_ptr->pvoicestattbl + i)->flags & VOICE_RELEASE)
    488 						voices_handle_table[i] = '1';
    489 					else
    490 						voices_handle_table[i] = '0';
    491 
    492 					i++;
    493 				} while (voices & 3 != i);
    494 			}
    495 		}
    496 
    497 		if (i != voices)
    498 		{
    499 			do
    500 			{
    501 				if ((pm_stat_ptr->pvoicestattbl + i)->flags & VOICE_RELEASE)
    502 					voices_handle_table[i] = '1';
    503 				else
    504 					voices_handle_table[i] = '0';
    505 
    506 				if ((pm_stat_ptr->pvoicestattbl + (i + 1))->flags & VOICE_RELEASE)
    507 					voices_handle_table[i + 1] = '1';
    508 				else
    509 					voices_handle_table[i + 1] = '0';
    510 
    511 				if ((pm_stat_ptr->pvoicestattbl + (i + 2))->flags & VOICE_RELEASE)
    512 					voices_handle_table[i + 2] = '1';
    513 				else
    514 					voices_handle_table[i + 2] = '0';
    515 
    516 				if ((pm_stat_ptr->pvoicestattbl + (i + 3))->flags & VOICE_RELEASE)
    517 					voices_handle_table[i + 3] = '1';
    518 				else
    519 					voices_handle_table[i + 3] = '0';
    520 
    521 				i += 4;
    522 			} while (voices != i);
    523 		}
    524 
    525 		voices_handle_table[voices] = '\0';
    526 	}
    527 
    528 	return (char *)&voices_handle_table;
    529 }
    530 #endif