From 4041ad4032f25e8632bb8877b6ee5a9c09f1b808 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 7 May 2019 17:02:25 +0200 Subject: [PATCH] Star Wars Returns --- include/kernel/speaker.h | 3 +++ include/kernel/time.h | 1 + kaleid/kernel/init/init.c | 2 +- kaleid/kernel/io/rtc.c | 8 ++++++++ kaleid/kernel/io/spkr.c | 42 ++++++++++++++++++++++++++++++++++----- 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/include/kernel/speaker.h b/include/kernel/speaker.h index d898953..4b5cd1e 100644 --- a/include/kernel/speaker.h +++ b/include/kernel/speaker.h @@ -34,6 +34,9 @@ void IoStartSpeaker(int freq); void IoQuietSpeaker(void); void IoDoBeep(void); +void IoDoTone(uint tone, uint time); + +void IoDoStarWars(void); //----------------------------------------------------------------------------// diff --git a/include/kernel/time.h b/include/kernel/time.h index a15a5c9..bd29043 100644 --- a/include/kernel/time.h +++ b/include/kernel/time.h @@ -49,6 +49,7 @@ extern void IoPrintRtcTime(void); extern ulong IoGetRtcTicks(void); extern Time_t* IoGetRtcTime(void); extern char* IoGetRtcTimeChar(void); +extern void IoRtcWait(uint time); // time in ms //static char* WeekDays[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index e955dac..4e88cd9 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -87,7 +87,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) IoPrintRtcTime(); - IoDoBeep(); + IoDoStarWars(); KernLog("Goodbye at %s\n", IoGetRtcTimeChar()); // End this machine's suffering diff --git a/kaleid/kernel/io/rtc.c b/kaleid/kernel/io/rtc.c index 8722206..a201b99 100644 --- a/kaleid/kernel/io/rtc.c +++ b/kaleid/kernel/io/rtc.c @@ -252,4 +252,12 @@ void IoEnableRtc(void) IoEnableNMI(); } +void IoRtcWait(uint time) // time in ms +{ + ulong frequency = 32768 >> (RtcRate-1); + ulong beginTick = IoGetRtcTicks(); + while(IoGetRtcTicks() < beginTick + (frequency/1000) * time) { + KePauseCPU(); + } +} diff --git a/kaleid/kernel/io/spkr.c b/kaleid/kernel/io/spkr.c index b4d87b2..877d8d9 100644 --- a/kaleid/kernel/io/spkr.c +++ b/kaleid/kernel/io/spkr.c @@ -4,7 +4,7 @@ // Desc: Speaker functions // // // // // -// Copyright © 2018-2019 The OS/K Team // +// Copyright © 4018-4019 The OS/K Team // // // // This file is part of OS/K. // // // @@ -53,12 +53,44 @@ void IoDoBeep(void) IoStartSpeaker(1000); - // Worst possible way of waiting - // We need actual timers - ulong ticks = IoGetRtcTicks(); - while (IoGetRtcTicks() < ticks + 512); + IoRtcWait(100); IoQuietSpeaker(); } +void IoDoTone(uint tone, uint time) +{ + + IoStartSpeaker(tone); + + IoRtcWait(time); + + IoQuietSpeaker(); + +} + +void IoDoStarWars(void) +{ + struct Note { + uint tone; + uint time; + }; + + struct Note Score[36] = { {440, 200}, {110, 200}, {440, 200}, {110, 200}, + {440, 200}, {110, 200}, {349, 140}, {110, 100}, + {523, 60}, {110, 100}, {440, 200}, {110, 200}, + {349, 140}, {110, 100}, {523, 60}, {110, 100}, + {440, 200}, {110, 200}, + + {659, 200}, {110, 200}, {659, 200}, {110, 200}, + {659, 200}, {110, 200}, {698, 140}, {110, 100}, + {523, 60}, {110, 100}, {415, 200}, {110, 200}, + {349, 140}, {110, 100}, {523, 60}, {110, 100}, + {440, 200}, {110, 200} + } ; + + for (int i=0; i<36 ; i++) { + IoDoTone(Score[i].tone, Score[i].time); + } +}