Image Map Image Map
Results 1 to 2 of 2

Thread: Turbo C: "setvect()" crashes some emulators

  1. #1

    Default Turbo C: "setvect()" crashes some emulators

    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:

    //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]);
    	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); //This is what causes the crash
    	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);
    	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

    Well , I'll leave the code just in case someone finds it usefull.
    Last edited by Mills32; November 21st, 2020 at 04:24 AM.

  2. #2
    Join Date
    Dec 2008
    libtard capital, California


    is your music_data volatile?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts