copyboot.cpp

来自「(汇编源代码)编写一个简单的操作系统 By Vivek Mohan」· C++ 代码 · 共 51 行

CPP
51
字号
/*********************
 * BOOT SECTOR WRITER
 * ------------------
 * by Vivek Mohan
 * http://www.geocities.com/cppresources/
 * If you are new to this stuff I'd strongly recommend you
 * experiment with floppies only.
 *********************/

 #include <bios.h>
 #include <stdio.h>

 /* Different Drives */

 #define _floppy1	0x0
 #define _floppy2	0x1

 #define _hd1		0x80
 #define _hd2		0x81
 #define _hd3		0x82

 /* Writes the boot sector */

 void writebootsector(char *buffer,int drive = _floppy1)
 {  printf("\nWriting....");
    int result;
    if((result=biosdisk(3,drive,0,0,1,1,buffer))==0)
    {   printf("1 sector copied successfully !");  }
    else
    {	printf("Error %d",result); }
 }

 int main(int argc,char* argv[])
 {	if(argc>1)
	{       FILE *fin = fopen(argv[1],"rb");
		if(fin)
		{       /* Buffer which stores the data 	*/
			char buffer[512];

			/* Read 512 bytes into the buffer 	*/
			fread(&buffer,512,1,fin);

			/* Write the 512 bytes */
			writebootsector(buffer,_floppy1);
			fclose(fin);
			return 1;
		}
	}
	printf("\ncopyboot.exe <filename>");
	return 0;
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?