New terminal outputs using serial: morse and spkmodem.
This commit is contained in:
parent
34f71cb866
commit
b78d6c32e3
10 changed files with 512 additions and 132 deletions
|
@ -28,80 +28,12 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/speaker.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define BASE_TEMPO (60 * 1000)
|
||||
|
||||
/* The speaker port. */
|
||||
#define SPEAKER 0x61
|
||||
|
||||
/* If 0, follow state of SPEAKER_DATA bit, otherwise enable output
|
||||
from timer 2. */
|
||||
#define SPEAKER_TMR2 0x01
|
||||
|
||||
/* If SPEAKER_TMR2 is not set, this provides direct input into the
|
||||
speaker. Otherwise, this enables or disables the output from the
|
||||
timer. */
|
||||
#define SPEAKER_DATA 0x02
|
||||
|
||||
/* The PIT channel value ports. You can write to and read from them.
|
||||
Do not mess with timer 0 or 1. */
|
||||
#define PIT_COUNTER_0 0x40
|
||||
#define PIT_COUNTER_1 0x41
|
||||
#define PIT_COUNTER_2 0x42
|
||||
|
||||
/* The frequency of the PIT clock. */
|
||||
#define PIT_FREQUENCY 0x1234dd
|
||||
|
||||
/* The PIT control port. You can only write to it. Do not mess with
|
||||
timer 0 or 1. */
|
||||
#define PIT_CTRL 0x43
|
||||
#define PIT_CTRL_SELECT_MASK 0xc0
|
||||
#define PIT_CTRL_SELECT_0 0x00
|
||||
#define PIT_CTRL_SELECT_1 0x40
|
||||
#define PIT_CTRL_SELECT_2 0x80
|
||||
|
||||
/* Read and load control. */
|
||||
#define PIT_CTRL_READLOAD_MASK 0x30
|
||||
#define PIT_CTRL_COUNTER_LATCH 0x00 /* Hold timer value until read. */
|
||||
#define PIT_CTRL_READLOAD_LSB 0x10 /* Read/load the LSB. */
|
||||
#define PIT_CTRL_READLOAD_MSB 0x20 /* Read/load the MSB. */
|
||||
#define PIT_CTRL_READLOAD_WORD 0x30 /* Read/load the LSB then the MSB. */
|
||||
|
||||
/* Mode control. */
|
||||
#define PIT_CTRL_MODE_MASK 0x0e
|
||||
|
||||
/* Interrupt on terminal count. Setting the mode sets output to low.
|
||||
When counter is set and terminated, output is set to high. */
|
||||
#define PIT_CTRL_INTR_ON_TERM 0x00
|
||||
|
||||
/* Programmable one-shot. When loading counter, output is set to
|
||||
high. When counter terminated, output is set to low. Can be
|
||||
triggered again from that point on by setting the gate pin to
|
||||
high. */
|
||||
#define PIT_CTRL_PROGR_ONE_SHOT 0x02
|
||||
|
||||
/* Rate generator. Output is low for one period of the counter, and
|
||||
high for the other. */
|
||||
#define PIT_CTRL_RATE_GEN 0x04
|
||||
|
||||
/* Square wave generator. Output is low for one half of the period,
|
||||
and high for the other half. */
|
||||
#define PIT_CTRL_SQUAREWAVE_GEN 0x06
|
||||
|
||||
/* Software triggered strobe. Setting the mode sets output to high.
|
||||
When counter is set and terminated, output is set to low. */
|
||||
#define PIT_CTRL_SOFTSTROBE 0x08
|
||||
|
||||
/* Hardware triggered strobe. Like software triggered strobe, but
|
||||
only starts the counter when the gate pin is set to high. */
|
||||
#define PIT_CTRL_HARDSTROBE 0x0a
|
||||
|
||||
/* Count mode. */
|
||||
#define PIT_CTRL_COUNT_MASK 0x01
|
||||
#define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */
|
||||
#define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */
|
||||
|
||||
#define T_REST ((grub_uint16_t) 0)
|
||||
#define T_FINE ((grub_uint16_t) -1)
|
||||
|
@ -112,39 +44,6 @@ struct note
|
|||
grub_uint16_t duration;
|
||||
};
|
||||
|
||||
static void
|
||||
beep_off (void)
|
||||
{
|
||||
unsigned char status;
|
||||
|
||||
status = grub_inb (SPEAKER);
|
||||
grub_outb (status & ~(SPEAKER_TMR2 | SPEAKER_DATA), SPEAKER);
|
||||
}
|
||||
|
||||
static void
|
||||
beep_on (grub_uint16_t pitch)
|
||||
{
|
||||
unsigned char status;
|
||||
unsigned int counter;
|
||||
|
||||
if (pitch < 20)
|
||||
pitch = 20;
|
||||
else if (pitch > 20000)
|
||||
pitch = 20000;
|
||||
|
||||
counter = PIT_FREQUENCY / pitch;
|
||||
|
||||
/* Program timer 2. */
|
||||
grub_outb (PIT_CTRL_SELECT_2 | PIT_CTRL_READLOAD_WORD
|
||||
| PIT_CTRL_SQUAREWAVE_GEN | PIT_CTRL_COUNT_BINARY, PIT_CTRL);
|
||||
grub_outb (counter & 0xff, PIT_COUNTER_2); /* LSB */
|
||||
grub_outb ((counter >> 8) & 0xff, PIT_COUNTER_2); /* MSB */
|
||||
|
||||
/* Start speaker. */
|
||||
status = grub_inb (SPEAKER);
|
||||
grub_outb (status | SPEAKER_TMR2 | SPEAKER_DATA, SPEAKER);
|
||||
}
|
||||
|
||||
/* Returns whether playing should continue. */
|
||||
static int
|
||||
play (unsigned tempo, struct note *note)
|
||||
|
@ -160,11 +59,11 @@ play (unsigned tempo, struct note *note)
|
|||
switch (note->pitch)
|
||||
{
|
||||
case T_REST:
|
||||
beep_off ();
|
||||
grub_speaker_beep_off ();
|
||||
break;
|
||||
|
||||
default:
|
||||
beep_on (note->pitch);
|
||||
grub_speaker_beep_on (note->pitch);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -263,7 +162,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
|
|||
}
|
||||
}
|
||||
|
||||
beep_off ();
|
||||
grub_speaker_beep_off ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue