分享
 
 
 

Windows 95 VxD C Source Code for VANYDEVD

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Listing 3

/// VANYDEVDc.c

// --------------------------------------------

// Dynamically loadable VxD for ANYDEV board

// --------------------------------------------

#define WIN32_LEAN_AND_MEAN // Excludes un-needed parts of windows.h

#include "windows.h"

#include <e:\ddk95\inc32\vmm.h>

#include <e:\ddk95\inc32\vwin32.h>

#include <e:\ddk95\inc32\debug.h>

#include "VANYDEVD.H"

// -------------------------------------

// Externs defined in assembly module

// -------------------------------------

// These defined in assembly for the VMM.INC or VPICD.INC file inclusion

extern DWORD GET_BD_MEM(void);

extern DWORD Virt_IRQ(void);

extern DWORD Get_IRQ_Status(void);

extern void UNVirt_IRQ(DWORD IRQhandle);

extern void End_ISR(DWORD IRQhandle);

extern void Physically_Mask_IRQ(DWORD IRQhandle);

extern void Physically_UNMask_IRQ(DWORD IRQhandle);

// ------------------------

// PRAGMA for this DATA

// ------------------------

// Establish segment

#pragma data_seg ( "_LDATA","_LCODE")

// ------------------------------------

// Data structures MUST be INITIALIZED

// ------------------------------------

ADEV ANYDEVX = {0}; // Main structure for ANYDEV -- shared by app

// ------------------------

// PRAGMAS for this CODE

// ------------------------

// Establish segment

#pragma code_seg ( "_LTEXT", "_LCODE" )

//No stack checking for routines in this module

#pragma check_stack(off)

// ----------------

// Disable hardware

// ----------------

void Disable_AnyDev(void)

{

//This would likely be a port WRITE to DISABLE the board's interrupt

}

// ----------------

// Enable hardware

// ----------------

void Enable_AnyDev(void)

{

//This would likely be a port WRITE to ENABLE the board's interrupt

}

// --------------------------

// ISR Processing for ANYDEV

// --------------------------

void Process_ISR(void)

{

//This is where the user might SET FLAGS and indicators in the ANYDEVX structure

//in order to notify the application that data is available below 1MB

}

// -----------------

// ISR for ANYDEV

// -----------------

void _declspec(naked)ISR_ANYDEV(void)

{

// Save registers

_asm sti

_asm pushad

_asm pushfd

//Process the ISR

Process_ISR();

//End ISR

_asm clc

End_ISR(ANYDEVX.IRQhandle);

//Set GOOD return code

_asm clc

//Restore saved registers

_asm popfd

_asm popad

_asm ret;

}

// -------------------

// Virtualize the IRQ

// -------------------

DWORD CVirt_IRQ(void)

{

// If in use by an instance of this program, RETURN with BAD code

if (ANYDEVX.IRQcount)

return (BOGUSADDRESS);

// If in use by another program, RETURN with BAD code

ANYDEVX.IRQstatus = Get_IRQ_Status();

if (ANYDEVX.IRQstatus)

return (BOGUSADDRESS);

// If IRQ NOT in use this point is reached

// Set BAD return code

ANYDEVX.IRQhandle = BOGUSADDRESS;

// Disable ANYDEV hardware

Disable_AnyDev();

// Get global memory address below 1mb

ANYDEVX.Global_addr_1MB = GET_BD_MEM();

if (ANYDEVX.Global_addr_1MB != BOGUSADDRESS)

{

// Virtualize the IRQ

ANYDEVX.IRQhandle = Virt_IRQ();

if (ANYDEVX.IRQhandle != BOGUSADDRESS)

{

// unmask the IRQ, set OK flag & increment IRQ count

Physically_UNMask_IRQ(ANYDEVX.IRQhandle);

ANYDEVX.IRQflags |= IRQ_VIRT_OK;

++(ANYDEVX.IRQcount);

}

}

return(ANYDEVX.IRQhandle);

}

// ----------------------

// UN Virtualize the IRQ

// ----------------------

void CUNVirt_IRQ(DWORD IRQhandle)

{

// if IRQ has been successfully virtualized

if ((ANYDEVX.IRQhandle != 0)

&& (ANYDEVX.IRQhandle != BOGUSADDRESS))

{

// Physically mask the IRQ and UN virtualized it

Physically_Mask_IRQ(ANYDEVX.IRQhandle);

UNVirt_IRQ(ANYDEVX.IRQhandle);

}

// Set UNvirtualized flags and indicators

ANYDEVX.IRQhandle = BOGUSADDRESS;

ANYDEVX.IRQflags &= ~IRQ_VIRT_OK;

return;

}

// ---------------------------------------

// Set Good Return code for DIOC requests

// ---------------------------------------

void _declspec(naked)GoodReturnDIOC(void)

{

// Clear eax and carry flag for GOOD return

_asm xor eax,eax

_asm clc

_asm ret;

}

// ---------------------------------------

// Set Bad Return code for DIOC requests

// ---------------------------------------

void _declspec(naked) BadReturnDIOC(void)

{

// NOTE: 50 is a FCN NOT SUPPORTED code -- ok to use

// SET carry flag for BAD return

_asm mov eax,50

_asm stc

_asm ret;

}

// ------------------------------

// Routine for ANYDEV Device UNINIT

// ------------------------------

void CVANYDEVD_Device_UNInit()

{

// Disable ANYDEV, Unvirtualize IRQ, set GOOD return code

Disable_AnyDev();

CUNVirt_IRQ(ANYDEVX.IRQhandle);

GoodReturnDIOC();

return;

}

// ------------------------------

// Routine for ANYDEV Device INIT

// ------------------------------

void CVANYDEVD_Device_Init()

{

DWORD retcode;

// Try to virtualize the IRQ

retcode = CVirt_IRQ();

// Set GOOD or BAD return code based on success

if (retcode == BOGUSADDRESS)

BadReturnDIOC();

else

GoodReturnDIOC();

return;

}

// --------------------------------

// Routine for ANYDEV Device IO ctrl

// --------------------------------

void CVANYDEVD_Device_IOctrl(PDIOCPARAMETERS ptr)

{

DWORD *obuf1;

// Field the DEV IO requests from VMM

switch(ptr->dwIoControlCode)

{

case(VANYDEVD_INIT_ADEV_HARDWARE):

ANYDEVX.flags = 0;

//User likely to require other initialization here

break;

case(VANYDEVD_GRAB_ADDRESSES):

// Point to Output buffer

obuf1 = (DWORD *) ptr->lpvOutBuffer;

// Return GLOBAL 1MB addr, addr of data structure

// and return indicators of IRQ virtuaization request

*obuf1 = ANYDEVX.Global_addr_1MB;

*(obuf1+1) = (DWORD) &ANYDEVX;

*(obuf1+2) = (DWORD) ANYDEVX.IRQhandle;

*(obuf1+3) = (DWORD) ANYDEVX.IRQflags;

//User might want to return other/different values here

break;

case(VANYDEVD_ENABLE_ANYDEV_HDWR):

//Call routine to enable interrupt

Enable_AnyDev();

break;

case(VANYDEVD_DISABLE_ANYDEV_HWR):

//Call routine to disable interrupt

Disable_AnyDev();

break;

//The below DIOC_GETVERSION is a part of the dynamic load protocol

//It MUST return a GOOD code (all codes here use GoodReturnDIOC()

case(DIOC_GETVERSION):

case(DIOC_CLOSEHANDLE):

default:

break;

}

GoodReturnDIOC();

return;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有