#include "stdio.h"
#define MAX_BUF_LEN 512
char buf[MAX_BUF_LEN];
void set_buf()
{
int bufpoint=0;
while(1)
{
char c=get_the_char();
if(c=='\b')
{
if(bufpoint==0)
continue;
putch('\b');
putch(' ');
putch('\b');
bufpoint--;
}
else if(c==10||c==13)
{
putch(10);
buf[bufpoint]=0;
bufpoint++;
break;
}
else
{
putch(c);
buf[bufpoint]=c;
bufpoint++;
}
if(bufpoint==MAX_BUF_LEN-1)
{
buf[bufpoint]=0;
break;
}
}
}
void putch(char c)
{
int position=get_cursor();
if(c==13)
c=10;
if(c==10)
{
int currow=position/80;
position=80*currow;
position+=80;
}
else
{
put_the_char(c,position);
position++;
}
if(position>1999)
{
roll_screen();
position=1920;
}
set_curson(position);
}
int get_cursor()
{
int position;
asm push ax
asm push dx
asm mov dx,3d4h
asm mov al,0eh
asm out dx,al
asm mov dx,3d5h
asm in al,dx
asm mov ah,al
asm mov dx,3d4h
asm mov al,0fh
asm out dx,al
asm mov dx,3d5h
asm in al,dx
asm mov position,ax
asm pop dx
asm pop ax
return position;
}
void set_curson(int position)
{
asm push ax
asm push bx
asm push dx
asm mov bx,position
asm mov dx,3d4h
asm mov al,0eh
asm out dx,al
asm mov dx,3d5h
asm mov al,bh
asm out dx,al
asm mov dx,3d4h
asm mov al,0fh
asm out dx,al
asm mov dx,3d5h
asm mov al,bl
asm out dx,al
asm pop dx
asm pop bx
asm pop ax
}
void put_the_char(char c,int position)
{
position*=2;
asm push ax
asm push cx
asm push bx
asm push ds
asm push si
asm mov cl,c
asm mov ax,0b800h
asm mov ds,ax
asm mov bx,position
asm mov si,bx
asm mov byte ptr [si],cl
asm pop si
asm pop ds
asm pop bx
asm pop cx
asm pop ax
}
void roll_screen()
{
asm push ax
asm push ds
asm push es
asm push si
asm push di
asm push cx
asm push bx
asm mov ax,0xb800
asm mov ds,ax
asm mov es,ax
asm cld
asm mov si,0xa0
asm mov di,0x00
asm mov cx,1920
asm rep movsw
asm mov bx,3840
asm mov cx,80
last_row_cls:
asm mov word ptr [bx],0x0720
asm add bx,2
asm loop last_row_cls
asm pop bx
asm pop cx
asm pop di
asm pop si
asm pop es
asm pop ds
asm pop ax
}
void puts(char* str)
{
while(*str)
{
putch(*str);
str++;
}
}
char getch()
{
char c;
char curchar;
while(1)
{
curchar=get_the_char();
if(curchar==32||curchar==10||curchar==13)
{
putch(curchar);
continue;
}
else
{
putch(curchar);
c=curchar;
break;
}
}
return c;
}
char get_the_char()
{
char the_char;
asm mov ah,0
asm int 16h
asm mov the_char, al
return the_char;
}
void gets(char* str)
{
char curchar;
while(1)
{
curchar=get_the_char();
putch(curchar);
if(curchar!=32&&curchar!=10&&curchar!=13)
break;
}
(*str)=curchar;
str++;
while(1)
{
curchar=get_the_char();
putch(curchar);
if(curchar!=10&&curchar!=13)
{
(*str)=curchar;
str++;
}
else
break;
}
(*str)=0;
}
void printfint(int num)
{
char buffer[8];
int point=0;
if(num==0)
{
putch('0');
}
else
{
while(num)
{
buffer[point]=(num%10)+'0';
num/=10;
point++;
}
while(point)
{
putch(buffer[point-1]);
point--;
}
}
}
void printf(char* format, ...)
{
int stackptr =(&format);
int data;
while(*format)
{
if((*format)=='%')
{
format++;
stackptr+=2;
asm push ax
asm push bp
asm mov ax,word ptr stackptr
asm mov bp,ax
asm mov ax,word ptr [bp]
asm pop bp
asm mov word ptr data,ax
asm pop ax
if((*format)=='c')
{
char c=(char )data;
putch(c);
}
else if((*format)=='d')
{
printfint(data);
}
else if((*format)=='s')
{
char* s=(char* )data;
puts(s);
}
else
{
format--;
stackptr-=2;
}
}
else
{
putch(*format);
}
format++;
}
}
void scanf(char* format, ...)
{
int stackptr=(&format);
int* data;
char* temp;
int pos;
pos=0;
set_buf();
while((*format))
{
if((*format)=='%')
{
format++;
stackptr+=2;
asm push ax
asm push bp
asm mov ax,word ptr stackptr
asm mov bp,ax
asm mov ax,word ptr [bp]
asm pop bp
asm mov word ptr data,ax
asm pop ax
if((*format)=='c')
{
while(pos<MAX_BUF_LEN&&buf[pos])
{
if(buf[pos]!=32&&buf[pos]!=10&&buf[pos]!=13)
break;
pos++;
}
temp=(char* )data;
(*temp)=buf[pos];
pos++;
}
else if((*format)=='d')
{
int num=0;
while(buf[pos]>'9'||buf[pos]<'0')
{
pos++;
}
while(buf[pos]>='0'&&buf[pos]<='9')
{
num=num*10+buf[pos]-'0';
pos++;
}
(*data)=num;
}
else if((*format)=='s')
{
while(buf[pos]==32||buf[pos]==10||buf[pos]==13)
{
pos++;
}
temp=(char* )data;
while(pos<MAX_BUF_LEN&&buf[pos]!=0&&buf[pos]!=32&&buf[pos]!=10&&buf[pos]!=13)
{
(*temp)=buf[pos];
temp++;
pos++;
}
(*temp)=0;
}
else
{
format--;
stackptr-=2;
}
}
format++;
}
}
操作系统实验五、实现系统调用
5星 · 超过95%的资源 需积分: 31 186 浏览量
2016-02-19
23:09:18
上传
评论 1
收藏 142KB RAR 举报
log16
- 粉丝: 17
- 资源: 13
最新资源
- 基于双向 LSTM 中文微博情感分类项目功能实现
- PHP新闻管理系统设计与实现 毕业设计
- 基于Springboot+Vue+Python水质管理和预报系统
- STM32单片机FPGA毕设电路原理论文报告汽车电动助力转向单片机控制系统设计与试验研究
- STM32单片机FPGA毕设电路原理论文报告气压传感器神经网络算法及单片机实现
- 西南交大-大学物理A作业-2019-带参考答案
- c++语言大作业,校区人员管理系统framework.zip
- 多目标优化算法集合,包含使用手册
- c语言程序设计大作业 课程设计 高分大作业98分.zip
- STM32单片机FPGA毕设电路原理论文报告频率的测量在单片机设计中的应用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈