phat code Duct Tape is like the Force: It has a light side, a dark side, and it holds the universe together.
Main

Projects

Downloads

Articles

Links

Forum

 

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, &regs, &regs);
}

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*
 
 
 
 

Reply to this Message

Name
Subject
Message

No HTML is allowed, except for <code> <b> <i> <u> in the message only.
All URLs and email addresses will automatically be converted to hyperlinks.