0% found this document useful (0 votes)
76 views7 pages

Troubleshooting Virtual Device I/O Issues

The document explains how to create and manage virtual hardware devices using EMU8086, detailing the use of I/O ports and hardware interrupts. It provides examples of custom devices such as traffic lights, stepper motors, and robots, including specific instructions for controlling them via assembly language. Additionally, it covers the emulation of hardware interrupts and the importance of managing I/O addresses to avoid conflicts between devices.

Uploaded by

Anjan Sengupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views7 pages

Troubleshooting Virtual Device I/O Issues

The document explains how to create and manage virtual hardware devices using EMU8086, detailing the use of I/O ports and hardware interrupts. It provides examples of custom devices such as traffic lights, stepper motors, and robots, including specific instructions for controlling them via assembly language. Additionally, it covers the emulation of hardware interrupts and the importance of managing I/O addresses to avoid conflicts between devices.

Uploaded by

Anjan Sengupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming Virtual Hardware Devices

I/O ports and Hardware Interrupts

EMU8086 supports user-created virtual devices that can be


accessed from assembly language program
using in and out instructions.

Input / Output ports

Additional devices can be created using 8086 assembly, Java,


C/C++, Visual Basic or any other programming language. For
more information and sample source code look inside this
folder: c:\emu8086\DEVICES\DEVELOPER\

Input / output addresses for custom devices are from 0000 to


0FFFFh (0 to 65535)

It is important to avoid two devices using the same ports.

Port 100 corresponds to byte 100 in this file: c:\[Link] ,


port 0 to byte 0, port 101 to byte 101, etc...

Emulation of Hardware Interrupts

External hardware interrupts can be triggered by external


peripheral devices and microcontrollers or by the 8087
mathematical coprocessor.

Hardware interrupts are disabled when interrupt flag (IF) is set to


0. When interrupt flag is set to 1, the emulator continually checks
first 256 bytes of this filec:\[Link] if any of the bytes is
none-zero the microprocessor transfers control to an interrupt
handler that matches the triggering byte offset
[Link] file (0 to 255) according to the interrupt vector
table (memory 0000-0400h) and resets the byte in [Link] to 00.

These instructions can be used to disable and enable hardware


interrupts:

cli - clear interrupt flag (disable hardware interrupts).


sti - set interrupt flag (enable hardware interrupts).

by default hardware interrupts are enabled and are disabled


automatically when software or hardware interrupt is in the
middle of the execution.

Examples of Custom I/O Devices

Ready devices are available from virtual devices menu of the


emulator.

 Traffic Lights - port 4 (word)

The traffic lights are controlled by sending data to i/o port 4.


There are 12 lamps: 4 green, 4 yellow, and 4 red.

You can set the state of each lamp by setting its bit:

1 - the lamp is turned on.


0 - the lamp is turned off.

Only 12 low bits of a word are used (0 to 11), last bits (12 to
15) are unused.

For example:

MOV AX, 0000001011110100b


OUT 4, AX

We use yellow hexadecimal digits in caption (to achieve


compact view), here's a conversion:
 Hex - Decimal

 A - 10
 B - 11
 C - 12 (unused)
 D - 13 (unused)
 E - 14 (unused)
F - 15 (unused)
First operand for OUT instruction is a port number (4),
second operand is a word (AX) that is written to the port.
First operand must be an immediate byte value (0..255)
or DX register. Second operand must be AX or AL only.

See also traffic_lights.asm in c:\emu8086\examples.

If required you can read the data from port


using IN instruction, for example:

IN AX, 4

First operand of IN instruction (AX) receives the value from


port, second operand (4) is a port number. first operand
must be AX or AL only. Second operand must be an
immediate byte value (0..255) or DX register.

 Stepper Motor - port 7 (byte)

The stepper motor is controlled by sending data to i/o port 7.

stepper motor is electric motor that can be precisely


controlled by signals from a computer.

The motor turns through a precise angle each time it


receives a signal.

By varying the rate at which signal pulses are produced, the


motor can be run at different speeds or turned through an
exact angle and then stopped.

This is a basic 3-phase stepper motor, it has 3 magnets


controlled by bits 0, 1 and 2. other bits (3..7) are unused.

When magnet is working it becomes red. The arrow in the


left upper corner shows the direction of the last motor move.
Green line is here just to see that it is really rotating.
For example, the code below will do three clock-wise half-
steps:

MOV AL, 001b ; initialize.


OUT 7, AL

MOV AL, 011b ; half step 1.


OUT 7, AL

MOV AL, 010b ; half step 2.


OUT 7, AL

MOV AL, 110b ; half step 3.


OUT 7, AL

If you ever played with magnets you will understand how it


works. See also stepper_motor.asm in c:\emu8086\
examples.

If required you can read the data from port


using IN instruction, for example:

IN AL, 7

Stepper motor sets topmost bit of byte value in port 7 when


it's ready.
 Robot - port 9 (3 bytes)

The robot is controlled by sending data to i/o port 9.

The first byte (port 9) is a command register. Set values to


this port to make robot do something. Supported values:

decimal binary
action
value value

0 00000000 do nothing.

1 00000001 move forward.

2 00000010 turn left.

3 00000011 turn right.

examine. Examines an object in front using sensor. When


4 00000100 robot completes the task, result is set to data
register and bit #0 ofstatus register is set to 1.

5 00000101 switch on a lamp.

6 00000110 switch off a lamp.


The second byte (port 10) is a data register. This register is


set after robot completes the examine command:

decimal value binary value meaning

255 11111111 wall

0 00000000 nothing

7 00000111 switched-on lamp

8 00001000 switched-off lamp

The third byte (port 11) is a status register. Read values


from this port to determine the state of the robot. Each bit
has a specific property:

bit
description
number

zero when there is no new data in data register, one when there is new
bit #0
data in data register.

zero when robot is ready for next command, one when robot is busy doing
bit #1
some task.

zero when there is no error on last command execution, one when there is
bit #2 an error on command execution (when robot cannot complete the task:
move, turn, examine, switch on/off lamp).

example:

 MOV AL, 1 ; move forward.
 OUT 9, AL ;

 MOV AL, 3 ; turn right.
 OUT 9, AL ;

 MOV AL, 1 ; move forward.
 OUT 9, AL ;

 MOV AL, 2 ; turn left.
 OUT 9, AL ;

 MOV AL, 1 ; move forward.
 OUT 9, AL ;

keep in mind that robot is a mechanical creature and it takes
some time for it to complete a task. You should always
check bit#1 of status register before sending data to port
9, otherwise the robot will reject your command and "busy!"
will be shown. See also [Link] in c:\emu8086\
examples.


Creating Custom Robo-World Map

It is possible to change the default map for the robot using


the tool box.

If you click the robot button and place robot over existing
robot it will turn 90 degrees counter-clock-wise. To manually
move the robot just place it anywhere else on the map.

If you click lamp button and click switched-on lamp the lamp
will be switched-off, if lamp is already switched-off it will be
deleted. Click over empty space will create a new switched-
on lamp.

Placing wall over existing wall deletes the wall.

Current version is limited to a single robot only. If you forget


to place a robot on the map it will be placed in some random
coordinates.

When robot device is closed the map is automatically saved


inside this file: c:\emu8086\devices\robot_map.dat

The right-click over the map brings up a popup menu that


allows to switch-on or switch-off all the lamps at once.

Common questions

Powered by AI

The IN and OUT instructions in EMU8086 facilitate communication between the CPU and virtual I/O devices by allowing data transfer through specified ports. The OUT instruction writes data from a CPU register (like AX or AL) to an I/O port, while the IN instruction reads data from the port into a CPU register. The port number can be an immediate value (0-255) or the DX register, ensuring that specific ports are targeted for interactions. This mechanism allows the CPU to control devices by sending instructions and receiving feedback .

The EMU8086 interface leverages HCI principles by providing intuitive commands and structures that align with typical assembly language programming, maintaining user-friendliness for its target audience. Clear designation of ports and related documents allow advanced users to interact with custom devices efficiently. Nevertheless, these features require a foundational understanding of assembly programming and hardware architecture, which might pose accessibility challenges for novices. Language precision and structured documentation are crucial to facilitate usability .

The robot control system in EMU8086 uses three bytes at ports 9, 10, and 11, each serving distinct functions. Port 9 is the command register, where values set the robot's actions such as moving or turning. Port 10 is the data register, populated with results from the 'examine' command, indicating what is in front of the robot, such as a wall or lamp status. Port 11 is the status register, indicating robot readiness, new data availability, and error status. Together, these ports enable comprehensive control and feedback for robotic operations .

EMU8086 controls a traffic light system via I/O port 4 using a word to manage 12 lamps separated into green, yellow, and red groups. Each lamp's state is controlled by a bit in the word; a 1 turns on the lamp, and a 0 turns it off. Only the lower 12 bits of the word are used for controlling the lamps, making the system efficient in using binary data for real-world simulation .

The limitation of EMU8086 to support only a single robot per map restricts the complexity of scenarios developers can simulate. This limitation means interactions between multiple robots, such as coordination or conflict scenarios, cannot be directly programmed, thereby reducing the utility of the simulator for evaluating multi-agent systems. However, focusing on single-robot scenarios can enhance the precision and detail with which individual behaviors and interactions with static map elements are designed and analyzed .

Potential conflicts when using custom I/O ports in EMU8086 arise from overlapping port usage by different devices. As the input/output addresses range from 0000 to 0FFFFh (0 to 65535) for custom devices, developers must ensure that no two devices use the same ports to avoid conflicts. Developers should carefully assign and manage port numbers, using documentation and systematic allocation to prevent overlaps .

Automatic saving of the robot map file in EMU8086 upon device closure ensures changes are preserved without explicit user actions, enhancing convenience and minimizing data loss risks from unforeseen shutdowns. However, this feature might also overwrite previous map configurations unintentionally, leading to the loss of prior setups unless backed up manually. This functionality is beneficial for iterative developments but demands awareness from developers about automatic saving implications on data retention .

EMU8086 emulates hardware interrupts by using a specific file, c:\emu8086.hw. When the interrupt flag is set to 1, the emulator continuously checks the first 256 bytes of this file. If any byte is non-zero, it indicates a triggered interrupt, and the microprocessor shifts control to an interrupt handler that corresponds to the byte offset. This handler is determined according to the interrupt vector table located in memory addresses 0000-0400h. The triggering byte is then reset to 00 .

Customizing a robot world map in EMU8086 involves using the toolbox to manipulate elements like robots, lamps, and walls on the map grid. By placing or removing these elements, users can influence the robot's navigation paths and testing scenarios. Logical implications include the need for the robot to adapt its movements due to changes in map topology, such as avoiding newly placed walls or interacting with lamps. This feature allows tailored environments for testing robot commands systematically .

EMU8086 ensures precise movements of a stepper motor by sending specific binary data to I/O port 7, each bit controlling a magnet. For a 3-phase stepper motor, bits 0, 1, and 2 manage the magnets, determining the motor’s movement. By altering these bits sequentially, precise control over the motor's position is achieved, reflected by specific rotational steps, established by digital I/O commands like 001b, 011b, 010b, among others .

You might also like