--- 8086tiny.c	2014-03-20 13:57:15.363400100 +0800
+++ 8086tiny.qhack.c	2014-03-20 14:29:08.716903200 +0800
@@ -15,10 +15,25 @@
 
 #ifndef _WIN32
 #include <fcntl.h>
 #else
 #include <conio.h>
+#include <windows.h>
+
+#define usleep compat_usleep
+void compat_usleep(__int64 usec)
+{
+	HANDLE timer;
+	LARGE_INTEGER ft;
+
+	ft.QuadPart = -(10*usec); // Convert to 100 nanosecond interval, negative value indicates relative time
+
+	timer = CreateWaitableTimer(NULL, TRUE, NULL);
+	SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
+	WaitForSingleObject(timer, INFINITE);
+	CloseHandle(timer);
+}
 #endif
 
 #ifndef NO_GRAPHICS
 #include "SDL.h"
 #endif
@@ -161,11 +176,11 @@
 
 // Global variable definitions
 unsigned char mem[RAM_SIZE], io_ports[IO_PORT_COUNT], *opcode_stream, *regs8, i_rm, i_w, i_reg, i_mod, i_mod_size, i_d, i_reg4bit, raw_opcode_id, xlat_opcode_id, extra, rep_mode, seg_override_en, rep_override_en, trap_flag, int8_asap, scratch_uchar, io_hi_lo, *vid_mem_base, spkr_en, bios_table_lookup[20][256];
 unsigned short *regs16, reg_ip, seg_override, file_index, wave_counter;
 unsigned int op_source, op_dest, rm_addr, op_to_addr, op_from_addr, i_data0, i_data1, i_data2, scratch_uint, scratch2_uint, inst_counter, set_flags_type, GRAPHICS_X, GRAPHICS_Y, pixel_colors[16], vmem_ctr;
-int op_result, disk[3], scratch_int;
+int op_result, disk[3], scratch_int, hltcnt;
 time_t clock_buf;
 struct timeb ms_clock;
 
 #ifndef NO_GRAPHICS
 SDL_AudioSpec sdl_audio = {44100, AUDIO_U8, 1, 0, 128};
@@ -173,10 +188,16 @@
 SDL_Event sdl_event;
 unsigned short vid_addr_lookup[VIDEO_RAM_SIZE], cga_colors[4] = {0 /* Black */, 0x1F1F /* Cyan */, 0xE3E3 /* Magenta */, 0xFFFF /* White */};
 #endif
 
 // Helper functions
+int hltloop()
+{
+       hltcnt= ++hltcnt % 32;
+       if(!hltcnt) usleep(500);
+       return 0;
+}
 
 // Set carry flag
 char set_CF(int new_CF)
 {
 	return regs8[FLAG_CF] = !!new_CF;
@@ -665,10 +686,12 @@
 				regs8[FLAG_CF] ^= 1
 			OPCODE 46: // CLC|STC|CLI|STI|CLD|STD
 				regs8[extra / 2] = extra & 1
 			OPCODE 47: // TEST AL/AX, immed
 				R_M_OP(regs8[REG_AL], &, i_data0)
+			OPCODE 49: // HLT
+				hltloop()
 			OPCODE 48: // Emulator-specific 0F xx opcodes
 				switch ((char)i_data0)
 				{
 					OPCODE_CHAIN 0: // PUTCHAR_AL
 						write(1, regs8, 1)
