We're looking for your comments on how to best organize the wiki's content.

HWI

From 0x10c Wiki
Jump to: navigation, search

HWI (Hardware Interrupt) is one of the Special opcodes in the DCPU-16 specification. It sends an interrupt to a hardware device and waits for a response.

Contents

[edit] Usage

 HWI arg1

Sends an interrupt to device number arg1. The device may modify any registers or addresses in memory in response; the exact behavior varies depending on the device.

[edit] Peripheral-controlled (Hardware) interrupts vs. Processor-controlled Interrupts

Main article: Interrupt

The usage of the term "interrupt" here is different from the usual meaning. Whereas a usual, processor-controlled interrupt causes the DCPU to jump into the Interrupt Service Routine referenced by IA, a peripheral-controlled interrupt does not change the PC unless the hardware device does so itself. Instead, the DCPU waits for the device to finish processing before continuing execution.

Peripheral-controlled interrupt Processor-controlled interrupt
Triggered by Software (HWI) External hardware, or software (INT)
Program execution Halts until the device finishes Jumps to IA
Memory and register access As defined by the device As defined by the code at IA

In summary, a peripheral-controlled interrupt is where the computer tells the device, "I'm ready," and lets the device take over. In a processor-controlled interrupt, the device tells the computer, "I've got data for you!" and the computer handles it itself.

[edit] Processing

In binary machine code, this Special opcode's five-bit representation is: 0b1 0010 (0x12)

The instruction has a takes four cycles to execute, plus the device response latency, plus any additional cycles necessary to evaluate the argument. The exact amount of time varies depending on the device.

[edit] Example

:load_devices
HWN I    ; Store the number of devices in I.
:load_devices_loop   ; Enter the loop
SUB I, 1 ; Hardware array is 0 based, so subtract 1.
HWQ I    ; Query for hardware info.
IFE A, [dev_monitor + 1]  ; Check if this is the monitor device. Device ID part 1
IFE B, [dev_monitor + 2]  ; Check if this is the monitor device. Device ID part 2
SET PC, monitor_loaded    ; Monitor has loaded!

IFE I, 0    ; If we've reached 0 and still haven't found the monitor
SET PC, exit    ; Exit the program.

SET PC, load_devices_loop    ; Otherwise, continue looping.

:monitor_loaded
SET [dev_monitor], I      ; Store the device ID for the monitor.

:dump_font
SET A, 4    ; Set the hardware interrupt code. 4 is 'dump font data to memory'
SET B, [font_old]    ; Set the memory location to dump to.
HWI [dev_monitor]    ; Call HWI and pass in the ID of the monitor location (which we found earlier).

:exit

:dev_monitor
DAT 0, 0xf615, 0x7349, "LEM Monitor", 0   ; Store information relative to the monitor device.

:font_old
DAT 0x1000

[edit] References

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox