mirror of
https://github.com/gungwald/alarm-clock-6502.git
synced 2024-09-09 18:54:46 +00:00
355 lines
6.9 KiB
C
355 lines
6.9 KiB
C
#include <stdio.h> /* scanf */
|
|
#include <stdint.h> /* uint8_t */
|
|
#include <stdbool.h> /* true */
|
|
#include <ctype.h> /* toupper */
|
|
#include <conio.h> /* clrscr, kbhit */
|
|
#include <time.h> /* time_t, struct tm */
|
|
|
|
#include "noslotclock.h"
|
|
#include "time.h"
|
|
#include "trace.h"
|
|
|
|
#define CLOCK_FREQUENCY 1023000L
|
|
#define CYCLES_PER_NOOP 2
|
|
#define NOOPS_PER_SEC 511500
|
|
#define CTRL_C '\x03'
|
|
#define ESC '\x1B'
|
|
#define FMTD_TIME_SIZE 16
|
|
|
|
void read_inputs(void);
|
|
void sleep_one_second(void);
|
|
void do_nothing_for_one_second(void);
|
|
void run_clock(void);
|
|
|
|
static struct tm G_Current_Time;
|
|
static struct tm G_Alarm_Time;
|
|
|
|
void main(void)
|
|
{
|
|
TRACE_ENTER("main");
|
|
|
|
load_driver();
|
|
clrscr();
|
|
read_inputs();
|
|
|
|
clrscr();
|
|
printf("\nAlarm Time: ");
|
|
print_12_hour_time(&G_Alarm_Time);
|
|
|
|
printf("\nCurrent Time: ");
|
|
|
|
run_clock();
|
|
|
|
TRACE_EXIT("main");
|
|
}
|
|
|
|
void read_inputs()
|
|
{
|
|
TRACE_ENTER("read_inputs");
|
|
read_time(&G_Current_Time);
|
|
puts("Alarm Time");
|
|
read_time_interactively(&G_Alarm_Time);
|
|
TRACE_EXIT("read_inputs");
|
|
}
|
|
|
|
void run_clock()
|
|
{
|
|
char c;
|
|
|
|
TRACE_ENTER("run_clock");
|
|
print_12_hour_time(&G_Current_Time);
|
|
while (true) {
|
|
sleep_one_second();
|
|
reprint_12_hour_time(&G_Current_Time);
|
|
if (kbhit()) {
|
|
c = cgetc();
|
|
if (c == ESC || toupper(c) == 'Q' || c == CTRL_C) {
|
|
puts("");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
TRACE_EXIT("run_clock");
|
|
}
|
|
|
|
/**
|
|
* Waits for one second. Modifies the global G_Current_Time.
|
|
*/
|
|
void sleep_one_second()
|
|
{
|
|
time_t old_time;
|
|
|
|
TRACE_ENTER("sleep_one_second");
|
|
old_time = mktime(read_time(&G_Current_Time));
|
|
|
|
while (mktime(read_time(&G_Current_Time)) <= old_time) {
|
|
do_nothing_for_one_second();
|
|
}
|
|
TRACE_EXIT("sleep_one_second");
|
|
}
|
|
|
|
void do_nothing_for_one_second()
|
|
{
|
|
int i = 0;
|
|
int max_loops;
|
|
|
|
TRACE_ENTER("do_nothing_for_one_second");
|
|
max_loops = NOOPS_PER_SEC / 250;
|
|
|
|
for ( ; i < max_loops; ++i) {
|
|
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
}
|
|
TRACE_EXIT("do_nothing_for_one_second");
|
|
}
|
|
|