#include "stdio.h"
#include "string.h"
char _szTitle[] = " Welcome to WuHuayue DOS System";
char _szDefaultDirPath[10] = "C:\\";
char _szCurrentPath[100] = "C:\\";
char _szAllFile[50] = "*.*";
char _DTA[100];
char _szBuffer[100];
int _restart[2];
void _ShowDirectory()
{
//get current path
char *_p;
_p = _szCurrentPath;
asm{
mov ah,47h
mov dl,0
mov si,_p
add si,3
int 21h
}
//show path
strcpy(_szBuffer,_szCurrentPath);
strcat(_szBuffer,">");
printf("%s",_szBuffer);
}
void _initscreen()
{
asm{
push ds
mov ax,0B800H
mov ds,ax
mov cx,80 * 25 * 2
mov si,0
}
_1:
asm{
mov BYTE PTR [si],' '
add si,2
LOOP _1
}
//set backgound color
asm{
mov ax,0B800H
mov ds,ax
mov cx,80
mov si,1
}
_2:
asm{
mov BYTE PTR [si],00011100B
add si,2
LOOP _2
pop ds
}
//set cursor position
asm{
mov ah,02h
mov bh,0
mov dh,0
mov dl,0
int 10h
}
//show title
printf("%s\n",_szTitle);
//set default directory path
char *_p;
_p = _szDefaultDirPath;
asm{
mov ah,3BH
mov dx,_p
int 21h
}
//show default path
strcpy(_szBuffer,_szDefaultDirPath);
strcat(_szBuffer,">");
printf("%s",_szBuffer);
}
void _CLS()
{
//clear screen
asm{
push ds
mov ax,0B800H
mov ds,ax
mov cx,80 * 25 * 2
mov si,0
}
_1:
asm{
mov BYTE PTR [si],' '
add si,2
LOOP _1
pop ds
}
//set cursor position
asm{
mov ah,02h
mov bh,0
mov dh,1
mov dl,0
int 10h
}
//show directory
_ShowDirectory();
}
void _CD()
{
int i = 0;
//get command line
while(_szBuffer[i] != 0)
{
i++;
}
i++;
//set directory
char *_p;
_p = &_szBuffer[i];
int _i;
_i = strlen(_p);
_szBuffer[i + _i] = 0;
asm{
mov ah,3BH
mov dx,_p
int 21h
}
//check if success
asm{
jc _ERROR
}
//success,show directory
goto _end;
_ERROR:
printf("Specified path not existed!\n\n");
_end: _ShowDirectory();
}
void _MD()
{
int i = 0;
//get command line
while(_szBuffer[i] != 0)
{
i++;
}
i++;
//set directory
char *_p;
_p = &_szBuffer[i];
i = strlen(_szBuffer);
int _i;
_i = strlen(_p);
_szBuffer[i + _i + 1] = 0;
asm{
mov ah,39H
mov dx,_p
int 21h
}
//check if success
asm{
jc _ERROR
}
//success,show directory
goto _end;
_ERROR:
printf("Cannot create new directory!\n\n");
_end: _ShowDirectory();
}
void _RD()
{
int i = 0;
//get command line
while(_szBuffer[i] != 0)
{
i++;
}
i++;
//set directory
char *_p;
_p = &_szBuffer[i];
i = strlen(_szBuffer);
int _i;
_i = strlen(_p);
_szBuffer[i + _i + 1] = 0;
asm{
mov ah,3AH
mov dx,_p
int 21h
}
//check if success
asm{
jc _ERROR
}
//success,show directory
goto _end;
_ERROR:
printf("Cannot delete specified directory!\n\n");
_end: _ShowDirectory();
}
void _DEL()
{
int i = 0;
//get command line
while(_szBuffer[i] != 0)
{
i++;
}
i++;
//set directory
char *_p;
_p = &_szBuffer[i];
i = strlen(_szBuffer);
int _i;
_i = strlen(_p);
_szBuffer[i + _i + 1] = 0;
asm{
mov ah,41H
mov dx,_p
int 21h
}
//check if success
asm{
jc _ERROR
}
//success,show directory
goto _end;
_ERROR:
printf("Cannot delete specified file!\n\n");
_end: _ShowDirectory();
}
void _TIME()
{
//get time
char _hour,_min,_sec;
asm{
mov ah,2CH
int 21h
mov _hour,ch
mov _min,cl
mov _sec,dl
}
printf("Local Time is %u:%u:%u\n\n",_hour,_min,_sec);
_ShowDirectory();
}
void _DATE()
{
//get time
short _year;
short _month,_day,_week;
asm{
mov ah,2AH
int 21h
mov _year,cx
mov BYTE PTR _month,dh
mov BYTE PTR _day,dl
mov BYTE PTR _week,al
}
printf("Local date is %u/%u/%u ",_year,_month,_day);
switch(_week)
{
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
}
printf("Change date?");
char _c;
scanf("%c",&_c);
if(_c == 'y' || _c == 'Y')
{
printf("Enter year:");
scanf("%u",&_year);
printf("Enter month:");
scanf("%u",&_month);
printf("Enter day:");
scanf("%u",&_day);
if(_year < 1980 || _year > 2099)
{
printf("Incorrect year!\n");
goto _end;
}
else if(_month < 1 || _month > 12)
{
printf("Incorrect month!\n");
goto _end;
}
else if(_day < 1 || _day > 31)
{
printf("Incorrect day!\n");
goto _end;
}
asm{
mov ah,2BH
mov cx,_year
mov bx,_day
mov dl,bl
mov bx,_month
mov dh,bl
int 21h
}
asm{
cmp al,0FFH
je _ERROR
jmp _end
}
_ERROR: printf("Cannot set date!\n\n");
}
_end: _ShowDirectory();
}
void _VER()
{
char _c,_c1,_OEM;
asm{
mov ah,30H
int 21h
mov _c,al
mov _c1,ah
mov _OEM,bh
}
switch(_c)
{
case 1:
strcpy(_szBuffer,"Version of DOS is v1.");
break;
case 2:
strcpy(_szBuffer,"Version of DOS is v2.");
break;
case 3:
strcpy(_szBuffer,"Version of DOS is v3.");
break;
case 4:
strcpy(_szBuffer,"Version of DOS is v4.");
break;
case 5:
strcpy(_szBuffer,"Version of DOS is v5.");
break;
case 6:
strcpy(_szBuffer,"Version of DOS is v6.");
break;
case 7:
strcpy(_szBuffer,"Version of DOS is v7.");
break;
case 8:
strcpy(_szBuffer,"Version of DOS is v8.");
break;
case 9:
strcpy(_szBuffer,"Version of DOS is v9.");
break;
case 10:
strcpy(_szBuffer,"Version of DOS is v10.");
break;
case 11:
strcpy(_szBuffer,"Version of DOS is v11.");
break;
}
switch(_c1)
{
case 10:
strcat(_szBuffer,"1");
break;
case 11:
strcat(_szBuffer,"2");
break;
case 12:
strcat(_szBuffer,"3");
break;
case 13:
strcat(_szBuffer,"4");
break;
case 14:
strcat(_szBuffer,"5");
break;
case 15:
strcat(_szBuffer,"6");
break;
case 16:
strcat(_szBuffer,"7");
break;
case 17:
strcat(_szBuffer,"8");
break;
case 18:
strcat(_szBuffer,"9");
break;
case 19:
strcat(_szBuffer,"10");
break;
case 20:
strcat(_szBuffer,"11");
break;
}
printf("%s\n",_szBuffer);
printf("OEM SN is %u\n\n",_OEM);
_end: _ShowDirectory();
}
void _DIR()
{
long _lSize;
int i;
char _temp;
char *_p;
_lSize = 0;
//set DTA address
_p = _DTA;
asm{
mov ah,1AH
mov dx,_p
int 21h
}
_p = _szAllFile;
asm{
mov ah,4EH
mov dx,_p
mov cx,00111111B
int 21h
jc _ERROR
//save ax
mov _temp,al
}
//all size
if((_DTA[0x15] & 0x10) == 0)
{
_lSize += (long)_DTA[0x1A];
}
//Found first file,look for next file
while(1)
{
i++;
//all size
if((_DTA[0x15] & 0x10) == 0)
{
_lSize += (long)_DTA[0x1A];
}
//check if this file is a directory
if(_DTA[0x15] & 0x10)
{
printf("[");
}
_p = &_DTA[0x1E];
printf("%s",_p);
//check if this file is a directory
if(_DTA[0x15] & 0x10)
{
printf("]");
}
printf(" ");
if(i >= 6)
{
i = 0;
printf("\n");
}
asm{
mov ah,4FH
mov al,_temp
int 21h
//finished
jc _end
}
}
_ERROR: printf("Cannot scan this directory!\n\n");
_end: printf("\n\n Total size is %uByte(s)",_lSize);
printf("\n\n");
_ShowDirectory();
}
void _ToRestart()
{
_restart[0] = 0;
_restart[1] = 0xFFFF;
asm{
lea bx,_restart
jmp DWORD PTR [bx]
}
}
void main()
{
//clear screen
_initscreen();
//read command
_InputCommand:
for(int _i=0;_i<100;_i++)
{
_szBuffer[_i] = 0;
}
for(int j=0;(_szBuffer[j] = getchar()) != '\n';j++);
_i = strlen(_szBuffer);
_szBuffer[_i - 1] = 0;
//analyse command
for(int i=0;i<strlen(_szBuffer);i++)
{
if(_szBuffer[i] == ' ')
{
_szBu