|
View Message | Back to Messages |
Peter Swinkels Fri Oct 11 2024 at 2:52 pm And here is a version written in C->
/*Does not work in DOSBox without booting into actual MS-DOS.*/
#define TRUE 1
#include <conio.h>
#include <dos.h>
#include <stdio.h>
struct ClockStr {
unsigned short Days;
unsigned char Minutes;
unsigned char Hours;
unsigned char Seconds100ths;
unsigned char Seconds;
};
void HideCursor ();
void ReadClock ();
struct ClockStr Clock;
int main() {
clrscr();
HideCursor();
while (TRUE) {
if (kbhit()) {
if (getch() == 27) break;
}
ReadClock();
gotoxy(1, 1);
printf(" Days since 01-jan-1980: %hun", Clock.Days);
printf(" Hours: %hhun", Clock.Hours);
printf(" Minutes: %hhun", Clock.Minutes);
printf(" Seconds: %hhun", Clock.Seconds);
printf(" Hundreths of seconds: %hhun", Clock.Seconds100ths);
}
}
void HideCursor() {
union REGS regs;
regs.h.ah = 0x01;
regs.h.ch = 0x20;
regs.h.cl = 0x00;
int86(0x10, ®s, ®s);
}
void ReadClock () {
FILE *file = fopen("CLOCK$", "rb");
if (file != NULL) {
fread(&Clock, sizeof(Clock), 1, file);
fclose(file);
}
}
The only issue I have with it is that I can't get it to work when passing the Clock structure as a parameter. The values don't get updated... The signature should be "struct ClockStr Clock" with the structure's pointer being passed like this: "&Clock", but somehow I can't get fread to write the values or something. *sigh*
|
|