XForms: outb()) error:outb(inb(0x61) & ~3, 0x61);

Tano Fotang (M.Tano@FH-Wolfenbuettel.DE)
Fri, 03 Apr 1998 15:09:33 +0200

# To subscribers of the xforms list from Tano Fotang <M.Tano@FH-Wolfenbuettel.DE> :

does anyone have experience talking to the hardware using an xforms app?
I got a seg violation and wonder if this error is related to the forms library.
Example:
outb(inb(0x61) & ~3, 0x61); /* turn off internal speaker */
fl_finish();

result:
either
select: Bad file number
Segmentation fault (core dumped)
or just
Segmentation fault (core dumped).

however, using exit() instead of fl_finish() produces
no errors. Maybe calls to certain xforms routines after inb()/outb() will break
application?
A simple example is shown below.

Tano Fotang. linux, intel P100. xforms 0.88.
-----

/*--example start---
toy piano.
gcc -Wall -O2 -o demo demo.c -lforms -L/usr/X11R6/lib -lX11 -lm
*/
#include <asm/io.h>
#include <forms.h>
#include <stdio.h>
#include <unistd.h>

#define CLOCKFREQ 1193180L
#define PORT 0x42 /* channel 02 */
#define CTRL_PORT 0x43 /* control port */
#define nosound() outb(inb(0x61) & ~3, 0x61) /* turn off speaker*/

static unsigned f[]={440, 493, 523, 587, 659, 698, 784, 880, 988}; /* Freqs in Hz */
void sound(unsigned freq)
{
unsigned t= CLOCKFREQ/freq;
outb(0xB6,CTRL_PORT); /* mode 3*/
outb(t&0xFF, PORT), outb(t>>8, PORT); /* LSB, MSB */
outb( inb(0x61)|3, 0x61);/* speaker on */
}
void s_cb(FL_OBJECT *ob, long c){
if (c>=1 && c<=9) sound(f[c-1]);
else { nosound(),
#if 0
fl_finish(); /* seg fault */
#else
exit(0); /* ok */
#endif
}
}

void main(int argc, char **argv)
{
FL_FORM *form;
FL_OBJECT *obj;
char *label[]={"1","2","3","4","5","6","7","8","9"};
int i;

if(ioperm(PORT,1,1)) perror("ioperm"), exit(1);
ioperm(CTRL_PORT,1,1); ioperm(0x61,1,1);
fl_set_border_width(-1);
fl_initialize(&argc, argv,"toypiano",0,0);
form= fl_bgn_form(FL_NO_BOX, 320, 200);
fl_add_box(FL_UP_BOX,0,0,320,200,"");
for(i=0;i<9;i++){
obj = fl_add_button(FL_RADIO_BUTTON,20+i * 32,20,30,90,label[i]);
fl_set_button_shortcut(obj,label[i],1);
fl_set_object_callback(obj,s_cb,(long)(i+1));
}
obj = fl_add_button(FL_NORMAL_BUTTON,22,132,44,24,"Quit");
fl_set_button_shortcut(obj,"0",1);
fl_set_object_callback(obj,s_cb,(long)0);
fl_end_form();
fl_show_form(form,FL_PLACE_FREE, FL_TRANSIENT,"toy piano");
fl_do_forms();
}
/*------end-----*/

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/