Skip to content

Commit

Permalink
inital commit of elkscmd/beep
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Zimmermann committed Feb 4, 2024
1 parent 6e68513 commit 395264b
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The ELKS kernel is licensed under the GNU General Public License version 2.

Software incldued beside the ELKS kernel (i.e. elkscmd) may be under different licensing terms, but all licenses are free software licenses that are legally permissible to distribute with the GPLv2 kernel code. If you are interested in the license information for a particular component, check its subdirectory or the top of its source code file(s) for its individual licensing details.
Software included beside the ELKS kernel (i.e. elkscmd) may be under different licensing terms, but all licenses are free software licenses that are legally permissible to distribute with the GPLv2 kernel code. If you are interested in the license information for a particular component, check its subdirectory or the top of its source code file(s) for its individual licensing details.

In the unlikely event that you discover a component with unclear, contradictory, or missing license information, please email Jody Bruchon <[email protected]> to resolve the issue.
1 change: 1 addition & 0 deletions elkscmd/Applications
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ sys_utils/sercat :sysutil :1200k
sys_utils/console :sysutil :1200k
#sys_utils/who :sysutil :1200k
sys_utils/unreal16 :sysutil
beep/beep :sysutil
screen/screen :screen :1200k
cron/cron :cron :1200k
cron/crontab :cron :1200k
Expand Down
37 changes: 37 additions & 0 deletions elkscmd/beep/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
BASEDIR=..

include $(BASEDIR)/Make.defs

###############################################################################
#
# Include standard packaging commands.

include $(BASEDIR)/Make.rules

CFLAGS += -Wno-maybe-uninitialized

###############################################################################

PRGS = beep
OBJS = beep.o
#MAPFILE = -Wl,-Map=romprWg.map

#HOSTPRGS = hostromprg

all: $(PRGS) $(HOSTPRGS)

beep: $(OBJS)
$(LD) $(LDFLAGS) $(MAPFILE) -o beep $(OBJS) $(LDLIBS)

HOSTSRC = beep.c
hostromprg: $(HOSTSRC)
$(HOSTCC) $(HOSTCFLAGS) $(HOSTSRC) -o $@

install: $(PRGS)
$(INSTALL) $(PRGS) $(DESTDIR)/bin

clean:
rm -f $(PRGS) $(HOSTPRGS) *.o *.map



74 changes: 74 additions & 0 deletions elkscmd/beep/beep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* beep - This file is part of the ELKS project
* authors: Florian Zimmermann et al.
* Free software "as-is"
* Takes one optional parameter: the beep duration
*/
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "signal.h"

#if 1
void outb(unsigned short port, unsigned char val)
{
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port) );
}

unsigned char inb(unsigned short port)
{
unsigned char ret;
asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
return ret;
}
#else
#include "arch/io.h"
#endif

static void beep(int freq)
{
//Set the PIT to the desired frequency
unsigned int d = 1193180 / freq;
outb(0x43, 0xb6);
outb(0x42, (unsigned int)(d));
outb(0x42, (unsigned int)(d >> 8));

//And play the sound using the PC speaker
unsigned int tmp = inb(0x61);
if (tmp != (tmp | 3)) {
outb(0x61, tmp | 3);
}
}

static void silent()
{
unsigned int tmp = inb(0x61) & 0xFC;
outb(0x61, tmp);
}

void beep_signal(int sig)
{
switch(sig) {
case SIGKILL: /* I'm falling */
case SIGTERM: /* I'm falling */
case SIGINT:
silent();
exit(sig);
}
}

int main(int ac, char **av)
{
long duration = 333L;
if(ac >= 2) {
duration = atoi(av[1]);
}

signal(SIGINT, beep_signal);
signal(SIGTERM, beep_signal);

beep(1000);
usleep(duration * 1000L);
silent();

return 0;
}
5 changes: 4 additions & 1 deletion qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ NET="-netdev user,id=mynet,$FWD -device ne2k_isa,irq=12,netdev=mynet"
# Enable network dump here:
# NETDUMP="-net dump"

# Enable PC-Speaker here:
AUDIO="-audiodev pa,id=speaker -machine pcspk-audiodev=speaker"

# Determine display type ("Darwin" = OSX)
[ `uname` != 'Darwin' ] && QDISPLAY="-display sdl"

# Configure QEMU as pure ISA system

exec $QEMU $CONSOLE -nodefaults -name ELKS -machine isapc -cpu 486,tsc -m 4M \
exec $QEMU $AUDIO $CONSOLE -nodefaults -name ELKS -machine isapc -cpu 486,tsc -m 4M \
$KEYBOARD $QDISPLAY -vga std -rtc base=utc $SERIAL \
$NET $NETDUMP $IMAGE $DISK2 $@

0 comments on commit 395264b

Please sign in to comment.