|
View Message | Back to Messages |
Peter Swinkels Thu Oct 24 2024 at 1:09 pm Okay I figured it out.
Code with Clock as a local variable that works:
/*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 ();
int main() {
struct ClockStr Clock;
clrscr();
HideCursor();
while (TRUE) {
if (kbhit()) {
if (getch() == 27) break;
}
ReadClock(&Clock);
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 (struct ClockStr *Clock) {
FILE *file = fopen("CLOCK$", "rb");
if (file != NULL) {
fread(Clock, 1, 6, file);
fclose(file);
}
}
The issue was with the parameters indicating the amount of data to be read. SizeOf(Clock) or SizeOf(&Clock) would be interpreted as the size of the pointer, not the variable itself. Trying to use SizeOf(ClockStr) which ought to be valid imho doesn't work. I rarely do much with C so its subtleties can easily get to me. :-)
|
|