Virtual Devices for emu8086

Hi there,

I am trying to develop a virtual device for emu 8086.
They have a header file for that purpose:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 this header file can be used to implement your own external devices for
 emu8086 - 8086 microprocessor emulator.
 devices can be written in borland turbo c, visual c++
 (for visual basic use io.bas instead).

 supported input / output addresses:
                  0 to 65535 (0x0 - 0xFFFF)

 most recent version of emu8086 is required,
 check this url for the latest version:
 http://www.emu8086.com

 you don't need to understand the code of this
 module, just include this file (io.h) into your
 project, and use these functions:

    unsigned char READ_IO_BYTE(long lPORT_NUM)
    short int READ_IO_WORD(long lPORT_NUM)

    void WRITE_IO_BYTE(long lPORT_NUM, unsigned char uValue)
    void WRITE_IO_WORD(long lPORT_NUM, short int iValue)

 where:
  lPORT_NUM - is a number in range: from 0 to 65535.
  uValue    - unsigned byte value to be written to a port.
  iValue    - signed word value to be written to a port.
*/

const char sIO_FILE[] = "C:\emu8086.io";

unsigned char READ_IO_BYTE(long lPORT_NUM)
{
	unsigned char tb;

	char buf[500];
	unsigned int ch;

	strcpy(buf, sIO_FILE);

	FILE *fp;

	fp = fopen(buf,"r+");

	// Read byte from port:
	fseek(fp, lPORT_NUM, SEEK_SET);
    ch = fgetc(fp);

	fclose(fp);

	tb = ch;

	return tb;
}

short int READ_IO_WORD(long lPORT_NUM)
{
	short int ti;
	unsigned char tb1;
	unsigned char tb2;

	tb1 = READ_IO_BYTE(lPORT_NUM);
	tb2 = READ_IO_BYTE(lPORT_NUM + 1);

	// Convert 2 bytes to a 16 bit word:
	ti = tb2;
    ti = ti << 8;
	ti = ti + tb1;

	return ti;
}

void WRITE_IO_BYTE(long lPORT_NUM, unsigned char uValue)
{
	char buf[500];
	unsigned int ch;

	strcpy(buf, sIO_FILE);

	FILE *fp;

	fp = fopen(buf,"r+");

    ch = uValue;

	// Write byte to port:
	fseek(fp, lPORT_NUM, SEEK_SET);
	fputc(ch, fp);

	fclose(fp);
}

void WRITE_IO_WORD(long lPORT_NUM, short int iValue)
{
	WRITE_IO_BYTE (lPORT_NUM, iValue & 0x00FF);
	WRITE_IO_BYTE (lPORT_NUM + 1, (iValue & 0xFF00) >> 8);
}


My Problem is that when I try to read a Byte from a port my programm crashes because of an adress violation.
1
2
3
4
5
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
        sysIn = READ_IO_BYTE(4);
}


It says there is an Access Violation in module 'CC326MT.DLL'.

I have no idea why I get this violation.
Maybe someone can help me?
Last edited on
Topic archived. No new replies allowed.