- Add midnight/next day increment
- Add date and time commands (functionality limited) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3715
This commit is contained in:
parent
1887b2590b
commit
a5ee614503
5 changed files with 218 additions and 26 deletions
|
@ -464,6 +464,23 @@ void SHELL_Init() {
|
|||
MSG_Add("SHELL_CMD_CHDIR_HINT","To change to different drive type \033[31m%c:\033[0m\n");
|
||||
MSG_Add("SHELL_CMD_CHDIR_HINT_2","directoryname is longer than 8 characters and/or contains spaces.\nTry \033[31mcd %s\033[0m\n");
|
||||
MSG_Add("SHELL_CMD_CHDIR_HINT_3","You are still on drive Z:, change to a mounted drive with \033[31mC:\033[0m.\n");
|
||||
MSG_Add("SHELL_CMD_DATE_HELP","Displays or changes the internal date.\n");
|
||||
MSG_Add("SHELL_CMD_DATE_ERROR","The specified date is not correct.\n");
|
||||
MSG_Add("SHELL_CMD_DATE_DAYS","3SunMonTueWedThuFriSat"); // "2SoMoDiMiDoFrSa"
|
||||
MSG_Add("SHELL_CMD_DATE_NOW","Current date: ");
|
||||
MSG_Add("SHELL_CMD_DATE_SETHLP","Type 'date MM-DD-YYYY' to change.\n");
|
||||
MSG_Add("SHELL_CMD_DATE_FORMAT","M/D/Y");
|
||||
MSG_Add("SHELL_CMD_DATE_HELP_LONG","DATE [[/T] [/H] [/S] | MM-DD-YYYY]\n"\
|
||||
" MM-DD-YYYY: new date to set\n"\
|
||||
" /S: Permanently use host time and date as DOS time\n"\
|
||||
" /F: Switch back to DOSBox internal time (opposite of /S)\n"\
|
||||
" /T: Only display date\n"\
|
||||
" /H: Synchronize with host\n");
|
||||
MSG_Add("SHELL_CMD_TIME_HELP","Displays the internal time.\n");
|
||||
MSG_Add("SHELL_CMD_TIME_NOW","Current time: ");
|
||||
MSG_Add("SHELL_CMD_TIME_HELP_LONG","TIME [/T] [/H]\n"\
|
||||
" /T: Display simple time\n"\
|
||||
" /H: Synchronize with host\n");
|
||||
MSG_Add("SHELL_CMD_MKDIR_ERROR","Unable to make: %s.\n");
|
||||
MSG_Add("SHELL_CMD_RMDIR_ERROR","Unable to remove: %s.\n");
|
||||
MSG_Add("SHELL_CMD_DEL_ERROR","Unable to delete: %s.\n");
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
static SHELL_Cmd cmd_list[]={
|
||||
{ "DIR", 0, &DOS_Shell::CMD_DIR, "SHELL_CMD_DIR_HELP"},
|
||||
|
@ -39,6 +40,7 @@ static SHELL_Cmd cmd_list[]={
|
|||
{ "CHOICE", 1, &DOS_Shell::CMD_CHOICE, "SHELL_CMD_CHOICE_HELP"},
|
||||
{ "CLS", 0, &DOS_Shell::CMD_CLS, "SHELL_CMD_CLS_HELP"},
|
||||
{ "COPY", 0, &DOS_Shell::CMD_COPY, "SHELL_CMD_COPY_HELP"},
|
||||
{ "DATE", 0, &DOS_Shell::CMD_DATE, "SHELL_CMD_DATE_HELP"},
|
||||
{ "DEL", 0, &DOS_Shell::CMD_DELETE, "SHELL_CMD_DELETE_HELP"},
|
||||
{ "DELETE", 1, &DOS_Shell::CMD_DELETE, "SHELL_CMD_DELETE_HELP"},
|
||||
{ "ERASE", 1, &DOS_Shell::CMD_DELETE, "SHELL_CMD_DELETE_HELP"},
|
||||
|
@ -61,6 +63,7 @@ static SHELL_Cmd cmd_list[]={
|
|||
{ "SET", 1, &DOS_Shell::CMD_SET, "SHELL_CMD_SET_HELP"},
|
||||
{ "SHIFT", 1, &DOS_Shell::CMD_SHIFT, "SHELL_CMD_SHIFT_HELP"},
|
||||
{ "SUBST", 1, &DOS_Shell::CMD_SUBST, "SHELL_CMD_SUBST_HELP"},
|
||||
{ "TIME", 0, &DOS_Shell::CMD_TIME, "SHELL_CMD_TIME_HELP"},
|
||||
{ "TYPE", 0, &DOS_Shell::CMD_TYPE, "SHELL_CMD_TYPE_HELP"},
|
||||
{ "VER", 0, &DOS_Shell::CMD_VER, "SHELL_CMD_VER_HELP"},
|
||||
{0,0,0,0}
|
||||
|
@ -937,6 +940,107 @@ void DOS_Shell::CMD_CALL(char * args){
|
|||
this->call=false;
|
||||
}
|
||||
|
||||
void DOS_Shell::CMD_DATE(char * args) {
|
||||
HELP("DATE");
|
||||
if(ScanCMDBool(args,"h")) {
|
||||
// synchronize date with host parameter
|
||||
time_t curtime;
|
||||
struct tm *loctime;
|
||||
curtime = time (NULL);
|
||||
loctime = localtime (&curtime);
|
||||
|
||||
reg_cx = loctime->tm_year+1900;
|
||||
reg_dh = loctime->tm_mon+1;
|
||||
reg_dl = loctime->tm_mday;
|
||||
|
||||
reg_ah=0x2b; // set system date
|
||||
CALLBACK_RunRealInt(0x21);
|
||||
return;
|
||||
}
|
||||
// check if a date was passed in command line
|
||||
Bitu newday,newmonth,newyear;
|
||||
if(sscanf(args,"%u-%u-%u",&newmonth,&newday,&newyear)==3) {
|
||||
reg_cx = newyear;
|
||||
reg_dh = newmonth;
|
||||
reg_dl = newday;
|
||||
|
||||
reg_ah=0x2b; // set system date
|
||||
CALLBACK_RunRealInt(0x21);
|
||||
if(reg_al==0xff) WriteOut(MSG_Get("SHELL_CMD_DATE_ERROR"));
|
||||
return;
|
||||
}
|
||||
// display the current date
|
||||
reg_ah=0x2a; // get system date
|
||||
CALLBACK_RunRealInt(0x21);
|
||||
|
||||
const char* datestring = MSG_Get("SHELL_CMD_DATE_DAYS");
|
||||
Bit8u length;
|
||||
char day[6] = {0};
|
||||
if(sscanf(datestring,"%u",&length) && (length<5) && (strlen(datestring)==(length*7+1))) {
|
||||
// date string appears valid
|
||||
for(int i = 0; i < length; i++) day[i] = datestring[reg_al*length+1+i];
|
||||
}
|
||||
bool dateonly = ScanCMDBool(args,"t");
|
||||
if(!dateonly) WriteOut(MSG_Get("SHELL_CMD_DATE_NOW"));
|
||||
|
||||
const char* formatstring = MSG_Get("SHELL_CMD_DATE_FORMAT");
|
||||
if(strlen(formatstring)!=5) return;
|
||||
char buffer[15] = {0};
|
||||
Bitu bufferptr=0;
|
||||
for(Bitu i = 0; i < 5; i++) {
|
||||
if(i==1 || i==3) {
|
||||
buffer[bufferptr] = formatstring[i];
|
||||
bufferptr++;
|
||||
} else {
|
||||
if(formatstring[i]=='M') bufferptr += sprintf(buffer+bufferptr,"%02u",(Bitu)reg_dh);
|
||||
if(formatstring[i]=='D') bufferptr += sprintf(buffer+bufferptr,"%02u",(Bitu)reg_dl);
|
||||
if(formatstring[i]=='Y') bufferptr += sprintf(buffer+bufferptr,"%04u",(Bitu)reg_cx);
|
||||
}
|
||||
}
|
||||
WriteOut("%s %s\n",day, buffer);
|
||||
if(!dateonly) WriteOut(MSG_Get("SHELL_CMD_DATE_SETHLP"));
|
||||
};
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
void DOS_Shell::CMD_SUBST (char * args) {
|
||||
/* If more that one type can be substed think of something else
|
||||
* E.g. make basedir member dos_drive instead of localdrive
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue