• Please review our updated Terms and Rules here

Turbo C: "setvect()" crashes some emulators

Mills32

Experienced Member
Joined
Sep 25, 2018
Messages
149
Location
Spain
I made a very simple adlib music player that plays imf files using interrupts.

Some emulators and real PC's have no issues. But dosbox and some PCem configs (that use 386+ CPU's) just crash and the emulator hangs.

Dosbox shows this error: "PIC: 4 byte interval not handled"

Maybe I'm doing something wrong, so here's the relevant code:

Code:
//Store the original timer here
void interrupt (*old_time_handler)(void); 

void interrupt play_music(void){
	//Some code to write music data to opl2 registers and play the music
	while (!imfwait){
		imfwait = music_sdata[music_offset+2];
		opl2_out(music_sdata[music_offset], music_sdata[music_offset+1]);
		music_offset+=3;
	}
	
	imfwait--;
	asm mov al,020h
	asm mov dx,020h
	asm out dx, al	//PIC, EOI
}

//set interrupt to play the music
void Start_Music(){
	unsigned long speed = 1193182/50;
	asm CLI //disable interrupts
	old_time_handler = getvect(0x1C);
	setvect(0x1C, play_music); //[B]This is what causes the crash[/B]
	outportb(0x43, 0x36);
	outportb(0x40, speed);	//lo-byte
	outportb(0x40, speed >> 8);	//hi-byte	
	asm STI  //enable interrupts	 
}

//Restore original timer
void Stop_Music(){
	asm CLI //disable interrupts
	//reset interrupt
	outportb(0x43, 0x36);
	outportb(0x40, 0xFF);	//lo-byte
	outportb(0x40, 0xFF);	//hi-byte
	setvect(0x1C, old_time_handler);
	opl2_clear();
	music_offset = 0;
	asm STI  //enable interrupts
}


EDIT: I realized the problem is inside play_music function, but still don't know what it is.

EDIT2: I spent a lot of time and it was a stupid typo, i was writting an undefined value to dx at the end of play_music :blush:

Well , I'll leave the code just in case someone finds it usefull.
 
Last edited:
Back
Top