diff options
author | Nao Pross <naopross@thearcway.org> | 2017-03-23 20:42:26 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-03-23 20:42:26 +0100 |
commit | 70b8b7f2d766f4ca131f9fa299546eb3697db8d4 (patch) | |
tree | 12db7c7402f06409cef1828ee49748c70b8e3325 /res/ATFBlast_ALL/userport/UserPort/Examples | |
parent | hardware nearly finished (diff) | |
download | z80uPC-70b8b7f2d766f4ca131f9fa299546eb3697db8d4.tar.gz z80uPC-70b8b7f2d766f4ca131f9fa299546eb3697db8d4.zip |
changed scheme layout
hw: changed scheme and annotated components
doc: added build script for windows
sw: added res/ folder with blaster and created jedec document for
address decoder pld
Diffstat (limited to '')
-rw-r--r-- | res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.c | 76 | ||||
-rw-r--r-- | res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.h | 18 | ||||
-rw-r--r-- | res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.pas | 72 |
3 files changed, 166 insertions, 0 deletions
diff --git a/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.c b/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.c new file mode 100644 index 0000000..7cef182 --- /dev/null +++ b/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.c @@ -0,0 +1,76 @@ +#include <windows.h> +static BOOL bPrivException = FALSE; + +void outport(UINT portid, UINT value) +{ + __asm mov edx,portid; + __asm mov eax,value; + __asm out dx,ax; +} +void outportb(UINT portid, BYTE value) +{ + __asm mov edx,portid + __asm mov al,value + __asm out dx,al +} + +BYTE inportb(UINT portid) +{ + unsigned char value; + + __asm mov edx,portid + __asm in al,dx + __asm mov value,al + return value; +} + +UINT inport(UINT portid) +{ + int value=0; + __asm mov edx,portid + __asm in ax,dx + __asm mov value,eax + return value; +} + +LONG WINAPI HandlerExceptionFilter ( EXCEPTION_POINTERS *pExPtrs ) +{ + + if (pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION) + { + pExPtrs->ContextRecord->Eip ++; // Skip the OUT or IN instruction that caused the exception + bPrivException = TRUE; + return EXCEPTION_CONTINUE_EXECUTION; + } + else + return EXCEPTION_CONTINUE_SEARCH; +} + +BOOL StartUpIoPorts(UINT PortToAccess, BOOL bShowMessageBox, HWND hParentWnd) +{ + HANDLE hUserPort; + + hUserPort = CreateFile("\\\\.\\UserPort", GENERIC_READ, 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + CloseHandle(hUserPort); // Activate the driver + Sleep(100); // We must make a process switch + + SetUnhandledExceptionFilter(HandlerExceptionFilter); + + bPrivException = FALSE; + inportb(PortToAccess); // Try to access the given port address + + if (bPrivException) + { + if (bShowMessageBox) + { + MessageBox(hParentWnd,"Privileged instruction exception has occured!\r\n\r\n" + "To use this program under Windows NT or Windows 2000\r\n" + "you need to install the driver 'UserPort.SYS' and grant\r\n" + "access to the ports used by this program.", + NULL,MB_OK); + } + return FALSE; + } + return TRUE; +} + diff --git a/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.h b/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.h new file mode 100644 index 0000000..2fd3bf9 --- /dev/null +++ b/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.h @@ -0,0 +1,18 @@ +#ifndef IOPORTH +#define IOPORTH + +#ifdef __cplusplus +extern "C" { +#endif + +void outport(UINT portid, UINT value); +void outportb(UINT portid, BYTE value); +BYTE inportb(UINT portid); +UINT inport(UINT portid); +BOOL StartUpIoPorts(UINT PortToAccess, BOOL bShowMessageBox, HWND hParentWnd); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.pas b/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.pas new file mode 100644 index 0000000..941240c --- /dev/null +++ b/res/ATFBlast_ALL/userport/UserPort/Examples/IOPort.pas @@ -0,0 +1,72 @@ +unit IOPort; + +interface +uses windows; + +procedure outport(portid : integer; value : integer); +procedure outportb(portid : integer; value : BYTE); +function inportb(portid : integer) : byte; +function inport(portid : integer) : integer; +function StartUpIoPorts(PortToAccess : integer) : boolean; + +implementation + +var + bPrivException : boolean; + +procedure outport(portid : integer; value : integer); +Begin + asm + mov edx,portid; + mov eax,value; + out dx,ax; + end; +end; + +procedure outportb(portid : integer; value : BYTE); +Begin + asm + mov edx,portid + mov al,value + out dx,al + end; +end; + +function inportb(portid : integer) : byte; +Var value : byte; +Begin + asm + mov edx,portid + in al,dx + mov value,al + end; + inportb := value; +end; + +function inport(portid : integer) : integer; +Var value : integer; +Begin + value := 0; + asm + mov edx,portid + in ax,dx + mov value,eax + end; + inport := value; +end; + +function StartUpIoPorts(PortToAccess : integer) : boolean; +Var hUserPort : THandle; +Begin + hUserPort := CreateFile('\\.\UserPort', GENERIC_READ, 0, nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(hUserPort); // Activate the driver + Sleep(100); // We must make a process switch + + try + inportb(PortToAccess); // Try to access the given port address + except + MessageBox(0,'fel','fel',MB_OK); + end; +end; + +end.
\ No newline at end of file |