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); + } +}