From 395264b702ab52414f59c1a9a9809513d3ba10e3 Mon Sep 17 00:00:00 2001 From: Florian Zimmermann Date: Sun, 4 Feb 2024 11:32:54 +0100 Subject: [PATCH] inital commit of elkscmd/beep --- LICENSE | 2 +- elkscmd/Applications | 1 + elkscmd/beep/Makefile | 37 ++++++++++++++++++++++ elkscmd/beep/beep.c | 74 +++++++++++++++++++++++++++++++++++++++++++ qemu.sh | 5 ++- 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 elkscmd/beep/Makefile create mode 100644 elkscmd/beep/beep.c diff --git a/LICENSE b/LICENSE index 7db5a4d90..7ddf81a24 100644 --- a/LICENSE +++ b/LICENSE @@ -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 to resolve the issue. diff --git a/elkscmd/Applications b/elkscmd/Applications index d41943b69..13a7ae329 100644 --- a/elkscmd/Applications +++ b/elkscmd/Applications @@ -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 diff --git a/elkscmd/beep/Makefile b/elkscmd/beep/Makefile new file mode 100644 index 000000000..c2759c374 --- /dev/null +++ b/elkscmd/beep/Makefile @@ -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 + + + diff --git a/elkscmd/beep/beep.c b/elkscmd/beep/beep.c new file mode 100644 index 000000000..01d3a87b9 --- /dev/null +++ b/elkscmd/beep/beep.c @@ -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; +} diff --git a/qemu.sh b/qemu.sh index 5cae08ab2..9547af29a 100755 --- a/qemu.sh +++ b/qemu.sh @@ -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 $@