📄 main.c
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-2000 Microsoft Corporation. All rights reserved.
Module Name:
Abstract:
Functions:
Notes:
--*/
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "loadcepc.h"
#include "xmsapi.h"
#include "ethernet.h"
#include "..\inc\bootarg.h"
#pragma warning(disable: 4001)
#define CHUNKSIZE 32768
#define COPY_FLAG_UPDATE_EXISTING 0x0001
#define COPY_FLAG_UPDATE_OR_ADD 0x0002
int LoadImage(BOOL bVerbose, BOOL bParallelDownload, char *pszFileName, PULONG pulEntryAddress);
int ExecuteImage(BOOL bVerbose, ULONG ulEntryPoint);
void Launch(ULONG ulEntryPoint, ULONG ulArguments);
UCHAR SetVideoMode(int iDesiredMode);
BOOL ParseVESAOptions(char * params);
UCHAR GetPCIConfigMechanism();
BOOL ParseEthernetOptions(char * argstr);
extern int NoPPFS; // parallel port not present flag
int OEMParallelPortGetByte(void);
void OEMParallelPortSendByte(UCHAR chData);
void OEMParallelPortInit(void);
void DisplayDirectory(char *pszPath);
void GetFile(char *pszSource, char *pszDestination, USHORT usCopyFlags);
BOOL SMCDetect(BYTE **ppbBaseAddress, USHORT *pwIrq);
const unsigned char BootHeader[] = {
0xAA, // header = 4 bytes
0x55,
0x55,
0xAA,
0x00, // opcode = 2 bytes (0 = BOOT)
0x00,
};
#define BOOT_HEADER_SIZE (sizeof(BootHeader) / sizeof(BootHeader[0]))
const unsigned char BootTail[] = {
0x5A, // trail = 4 bytes
0xA5,
0x0A,
0x1A
};
#define BOOT_TAIL_SIZE (sizeof(BootTail) / sizeof(BootTail[0]))
#define BOOT_TYPE -4 // boot type for x86
struct
{
ULONG ulRate;
UCHAR ucDivisor;
} BaudTable[] =
{
{ 9600, 12 },
{ 19200, 6 },
{ 38400, 3 },
{ 57600, 2 },
{ 115200, 1 }
};
#define NUM_BAUD_RATES (sizeof(BaudTable) / sizeof(BaudTable[0]))
BOOT_ARGS BootArgs;
USHORT usBlockHandle; // XMS memory handle
BOOL bSerialDownload=FALSE;
extern int OEMReadDebugByte(void);
extern void OEMReadDebugBytes(unsigned char * ucBuffer, int usReadSize);
extern void OEMWriteDebugByte(unsigned char ch);
void
usage(char *pszProgramNameArg)
{
char * pszProgram;
pszProgram = strrchr(pszProgramNameArg, '\\');
if (pszProgram != NULL)
{
pszProgram++;
}
else
{
pszProgram = pszProgramNameArg;
}
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
printf(
"\n"
"%s: Loads an NK ROM image into memory and boots it\n"
"\n"
"Usage:%s [/B:baud] [/C:port] [/D:display] [/P] [/Q] [/H] [/V]\n"
" [/E:Card:IO:IRQ[:<dotted IP>]] [/L:VX:VY:BPP[:PX:PY]] [<file name>]\n"
"\n"
" /B Baudrate - 9600, 19200, 38400, 57600, or 115200 (default 19200)\n"
"\n"
" /C COM Port - 1 = COM1, 2 = COM2 (default COM1)\n"
"\n"
" /D Display Resolution - 0 = 320x200x256 (default), 1 = 480x240x256,\n"
" 2 = 640x480x256, 3 = 800x600x256, 4 = 1024x768x256\n"
" 5 = 240x320x256, 6 = 208x240x256\n"
"\n"
" /P Parallel port boot download.\n"
"\n"
" /Q Serial port boot download.\n"
"\n"
" /H Help - displays this message\n"
"\n"
" /V Verbose - displays extra status information during boot\n"
"\n"
" Default <file name> is NK.BIN except for /P option which uses\n"
" default on host unless <file name> specified.\n"
"\n"
"Press any key for more options..."
,pszProgram, pszProgram);
__asm
{
push dx
xor ax,ax
int 0x16
pop dx
}
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
printf(
"\n"
"\n"
"\n"
"Usage:%s [/B:baud] [/C:port] [/D:display] [/P] [/Q] [/H] [/V]\n"
" [/E:Card:IO:IRQ[:<dotted IP>]] [/L:VX:VY:BPP[:PX:PY]] [<file name>]\n"
"\n"
"\n"
" /E:Card:IO:IRQ[:<dotted IP>] (Debug Ethernet Card parameters)\n"
" Card (Type) - 0 = SMC9000, 1 = NE2000 \n"
" IO (Base Address in hexidecimal) - 0 = Find PCI Card with matching IRQ\n"
" IRQ - Interrupt (specified in hexidecimal or decimal)\n"
" Dotted IP - Optional static IP address (No DHCP)\n"
"\n"
"\n"
" /L:DX:DY:BPP[:PX:PY] (Use VESA VBE Linear/Flat Framebuffer video mode)\n"
" DX - Display X Size\n"
" DY - Display Y Size\n"
" BPP - Bits Per Pixel Color Depth (8, 16, 24, or 32)\n"
" PX - Optional Physical Screen X Size\n"
" PY - Optional Physical Screen Y Size\n"
"\n"
"\n"
"\n"
"\n"
"Press any key for more options..."
,pszProgram);
__asm
{
push dx
xor ax,ax
int 0x16
pop dx
}
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
printf(
"\n"
"Usage: %s -s[:]<pattern> -(g|r|u)[[:]<pattern> [<destination>]\n"
"-s Show a directory of files matching <pattern>.\n"
"\n"
"-g Get files matching <pattern> and copy them to the\n"
" optionally specified <destination>. Any existing file with\n"
" the same name will be overwritten.\n"
"\n"
"-r Refresh files matching <pattern> which already exist in <destination>\n"
" and have a timestamp newer than the one in <destination>.\n"
"\n"
"-u Update files matching <pattern> which don't already exist in\n"
" <destination> or those that have a timestamp newer than those\n"
" in <destination>.\n"
"\n"
"<pattern> Windows filename path with optional wildcard characters.\n"
"\n"
"<destination> If not specified then the current directory is the default.\n"
" If specified and it doesn't exist and the last character is \\,\n"
" then the directory is created. Otherwise <destination> is\n"
" treated as the name of the file.\n"
" It is an error for <pattern> to match multiple files\n"
" when <destination> specifies a file.\n"
,pszProgram);
}
void DrawPoint(short x,short y,char color)
{
__asm
{
mov dx, y
mov cx, x
mov al, color
mov ah, 0cH
int 10h
}
}
void DrawLog(WORD sWidth,WORD sHeight)
{
USHORT i,j,Width,Height,posx,posy,cnt=0;
BYTE aByte,tempByte,cl;
FILE * f;
BYTE * byteData;
ULONG DataIndex=0;
f=fopen("logmap","rb");
if (!f)
{
printf("Can not open log file");
}
fread(&Height,sizeof(USHORT),1,f);
fread(&Width,sizeof(USHORT),1,f);
//byteData=(BYTE *)malloc(sizeof(BYTE)*Height*Width/8+1);
//memset(byteData,0,sizeof(BYTE)*Height*Width/8+1);
//fread(byteData,sizeof(BYTE),Height*Width/8+1,f);
//fclose(f);
/*printf("sHeight:%d\n",sHeight);
printf("sWidth:%d\n",sWidth);
printf("Height:%d\n",Height);
printf("Width:%d\n",Width);
*/
if (Width>sWidth || Height>sHeight)
{
//printf("Log file size to big!\n");
posy=0;
//return;
}
posx=(sWidth-Width)/2;
posy=(sHeight-Height)/2;
if (Width>sWidth)
{
//printf("Log file size too Wide!\n");
posx=0;
}
if (Height>sHeight)
{
printf("Log file size too Hight!\n");
posy=0;
}
for (i=0;i<Height;i++)
{
for (j=0;j<Width;j++)
{
if (cnt==0)
{
fread(&aByte,sizeof(BYTE),1,f);
//aByte=byteData[DataIndex];
//DataIndex++;
}
cl=aByte & 0x80;
if (cl)
{
DrawPoint(j+posx,i+posy,0xFF);
}
aByte=aByte<<1;
cnt++;
if (cnt==8)
{
cnt=0;
}
}
}
//free(byteData);
fclose(f);
}
int
main(int argc, char **argv)
{
char * pszFileName = "nk.bin";
ULONG ulEntryPoint;
ULONG ulArguments;
int xmsError;
BOOL bEnabled;
BOOL bVerbose = FALSE;
BOOL bParallelDownload=FALSE;
int iDesiredMode = 0;
ULONG ulBaudRate;
char cOption;
int i;
int ret;
int iPpfstool=0;
unsigned char list[20];
/* Set up boot args struct */
BootArgs.ucVideoMode = 0;
BootArgs.ucComPort = 1;
BootArgs.ucBaudDivisor = 6;
BootArgs.ucPCIConfigType = 0;
BootArgs.dwSig = BOOTARG_SIG;
BootArgs.dwLen = sizeof(BOOT_ARGS);
usBlockHandle = 0;
OEMParallelPortInit(); // initialize parallel port
/*
** Parse arguments
*/
if (argc > 1)
{
int iArgIndex;
for (iArgIndex = 1; iArgIndex < argc; iArgIndex++)
{
if (argv[iArgIndex][0] != '/' && argv[iArgIndex][0] != '-')
{
break;
}
cOption = (char)tolower(argv[iArgIndex][1]);
switch (cOption)
{
case 'b': /* Baud rate */
if (argv[iArgIndex][2] != ':' ||
argv[iArgIndex][3] < '0' || argv[iArgIndex][3] > '9')
{
printf("Invalid option - %s\n", argv[iArgIndex]);
usage(argv[0]);
ret = 1;
goto main_error;
}
ulBaudRate = atol(&argv[iArgIndex][3]);
for (i = 0; i < NUM_BAUD_RATES; i++)
{
if (BaudTable[i].ulRate == ulBaudRate)
{
BootArgs.ucBaudDivisor = BaudTable[i].ucDivisor;
break;
}
}
if (i >= NUM_BAUD_RATES)
{
printf("Unsupported baud rate - %s\n", argv[iArgIndex]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -