VOGONS

Common searches


First post, by luc7

User metadata
Rank Newbie
Rank
Newbie

Hello.

Below is my attempt in changing the command TIME so it accepts hh🇲🇲ss user supplied.
I dont really know if a dos_call 0x2D works in this context or it should be a "mem_writed(BIOS_TIMER,ticks)"
in order to set the running time in the dosbox engine.

So I wrote OPTION 1 and OPTION2...
How to have this code to reach the active developers of DOSBox for their valuable comments/help ? (is posting here sufficient?)

I can go on and just make a build for myself but I think this would very be nice to get into the official sources.

Thanks.
luis/luc7.

the code for the CMD_TIME() modified is below, still with option 1 and option 2, one of them to be commented
or deleted.

void DOS_Shell::CMD_TIME(char * args) {
HELP("TIME");
if(ScanCMDBool(args,"H")) {
// synchronize time with host parameter
time_t curtime;
struct tm *loctime;
curtime = time (NULL);
loctime = localtime (&curtime);

//reg_cx = loctime->;
//reg_dh = loctime->;
//reg_dl = loctime->;

// reg_ah=0x2d; // set system time TODO
// CALLBACK_RunRealInt(0x21);

Bit32u ticks=(Bit32u)(((double)(loctime->tm_hour*3600+
loctime->tm_min*60+
loctime->tm_sec))*18.206481481);
mem_writed(BIOS_TIMER,ticks);
return;
}

bool timeonly = ScanCMDBool(args,"T");

// luc7 OPTION 1
// check if a time was passed in command line
Bit32u newhour,newminute,newsecond;
if(sscanf(args,"%u:%u:%u",&newhour,&newminute,&newsecond)==3) {
reg_ch = static_cast<Bit8u>(newhour);
reg_cl = static_cast<Bit8u>(newminuts);
reg_dh = static_cast<Bit8u>(newseconds);
reg_dl = 0x00;

reg_ah=0x2d; // set system time
CALLBACK_RunRealInt(0x21);
if(reg_al==0xff) WriteOut(MSG_Get("SHELL_CMD_TIME_ERROR"));
return;
}
// end OPTION 1

// luc7 OPTION 2
// check if a time was passed in command line
Bit32u newhour,newminute,newsecond;
if(sscanf(args,"%u:%u:%u",&newhour,&newminute,&newsecond)==3) {
Bit32u ticks=(Bit32u)(((double)(newhour*3600+
newminute*60+
newsecond))*18.206481481);
mem_writed(BIOS_TIMER,ticks);
return;
// end OPTION 2

reg_ah=0x2c; // get system time
CALLBACK_RunRealInt(0x21);
/*
reg_dl= // 1/100 seconds
reg_dh= // seconds
reg_cl= // minutes
reg_ch= // hours
*/
if(timeonly) {
WriteOut("%2u:%02u\n",reg_ch,reg_cl);
} else {
WriteOut(MSG_Get("SHELL_CMD_TIME_NOW"));
WriteOut("%2u:%02u:%02u,%02u\n",reg_ch,reg_cl,reg_dh,reg_dl);
}
};

Reply 1 of 3, by luc7

User metadata
Rank Newbie
Rank
Newbie

Oh.. I hate to reply to myself, but it is just to close the topic.

I have modified/rewrote the TIME function, "DOS_Shell::CMD_TIME()" in the file "shell_cmds.cpp".

The TIME command now accepts the /T /H as before and add HH:MM:SS or HH:NN or Just HH
which would be the behaviour of a DOS machine.

I have compiled DOSBox and...
All is working fine. TIME command now has it all.

My problem is solved so I am happy, but I would be happier if this contribution is integrated in DOSBox future.
For this I need that someone kindly tells me where I can upload or send the code as I have no clue.

All the best.
lc

Reply 2 of 3, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Here is fine,
it's common to post a diff/patch file though, but these code changes are rather small. So don't worry too much about it.

I have moved it to the patches forum, so it won't be forgotten.

Thanks!

Water flows down the stream
How to ask questions the smart way!

Reply 3 of 3, by luc7

User metadata
Rank Newbie
Rank
Newbie

Thanks.
Actually I ended up changing the TIME function much more than the suggested patches of my first post so that it handles properly all the variants as I listed in the second post.
After testing/revising to ensure that all is working as expected it ended up sort of rewritten.
The final version of the TIME command is as below.

(there is also a change in the help text for the TIME command to show the user the correct usage, albeit the partial usage of the time argument is not shown in the help text).

Many thanks.
--------
//shell.cpp
//messages section

MSG_Add("SHELL_CMD_TIME_HELP","Displays or changes the internal time.\n");
MSG_Add("SHELL_CMD_TIME_NOW","Current time: ");
MSG_Add("SHELL_CMD_TIME_HELP_LONG","TIME [[/T] [/H] | HH:MM:SS]\n"\
" HH:MM:SS: new time to set\n"\
" /T: Display simple time\n"\
" /H: Synchronize with host\n");

----------------
//shell_cmnds.cpp

// TIME cmnd - L.Cupido Dec.2024
void DOS_Shell::CMD_TIME(char * args) {

HELP("TIME");

// synchronize time with host
if(ScanCMDBool(args,"H")) {
time_t curtime;
struct tm *loctime;
curtime = time (NULL);
loctime = localtime (&curtime);

// set time using int21
//reg_cx = loctime->;
//reg_dh = loctime->;
//reg_dl = loctime->;
//reg_ah=0x2d;
//CALLBACK_RunRealInt(0x21);

// set time with bios timer
Bit32u ticks=(Bit32u)(((double)(loctime->tm_hour*3600+
loctime->tm_min*60+
loctime->tm_sec))*18.206481481);
mem_writed(BIOS_TIMER,ticks);
return;
}

// simple display w/ time only
if(ScanCMDBool(args,"T")) {
reg_ah=0x2c; // get system time
CALLBACK_RunRealInt(0x21);

WriteOut("%2u:%02u\n",reg_ch,reg_cl);
return;
}

// check if a time was passed in command line
// allows passing HH:MM:SS or HH:MM or HH
// there is no sanity check about these numbers etc TODO

bool timeset = false;
Bit32u newhour,newminute,newsecond;

if( sscanf(args,"%u:%u:%u",&newhour,&newminute,&newsecond) == 3 ) {
timeset = true;
}
else if( sscanf(args,"%u:%u",&newhour,&newminute) == 2 ) {
newsecond = 0;
timeset = true;
}
else if( sscanf(args,"%u",&newhour) == 1 ) {
newminute = 0;
newsecond = 0;
timeset = true;
}

if (timeset == true) {

// set time using int 21
//reg_ch = static_cast<Bit8u>(newhour);
//reg_cl = static_cast<Bit8u>(newminuts);
//reg_dh = static_cast<Bit8u>(newseconds);
//reg_dl = 0x00;
//reg_ah=0x2d; // set system time
//CALLBACK_RunRealInt(0x21);
//if(reg_al==0xff) WriteOut(MSG_Get("SHELL_CMD_TIME_ERROR"));

// set time using bios timer
Bit32u ticks=(Bit32u)(((double)(newhour*3600+
newminute*60+
newsecond))*18.206481481);
mem_writed(BIOS_TIMER,ticks);
return;
}

reg_ah=0x2c; // get system time
CALLBACK_RunRealInt(0x21);

WriteOut(MSG_Get("SHELL_CMD_TIME_NOW"));
// WriteOut("%2u:%02u:%02u,%02u\n",reg_ch,reg_cl,reg_dh,reg_dl); // seconds with 2 decimal places
WriteOut("%2u:%02u:%02u\n",reg_ch,reg_cl,reg_dh); // seconds
}