--- bios.asm	2014-02-05 11:40:22.000000000 +0800
+++ bios.qhack.asm	2014-02-06 09:22:46.700750000 +0800
@@ -9,10 +9,22 @@
 
 ; Defines
 
 %define	biosbase 0x000f			; BIOS loads at segment 0xF000
 
+%ifndef videotype
+%define	videotype	1 ; Video Type (0=Hercules as Primary, 1=CGA as Primary)
+%endif
+
+%if videotype == 0
+%define	dispmem 	0xb000 ; Display memory address
+%define	dispback	0xb800 ; Display backed memory address
+%else
+%define	dispmem 	0xb800 ; Display memory address
+%define	dispback	0xb000 ; Display backed memory address
+%endif
+
 ; Here we define macros for some custom instructions that help the emulator talk with the outside
 ; world. They are described in detail in the hint.html file, which forms part of the emulator
 ; distribution.
 
 %macro	extended_putchar_al 0
@@ -120,10 +132,13 @@
 
 	; Now we can do whatever we want! DL starts off being the boot disk.
 
 	mov	[cs:boot_device], dl
 
+	; set hostiswin for int10
+	mov	[cs:hostiswin], dh
+
 	; Set up Hercules graphics support. We start with the adapter in text mode
 
 	push	dx
 
 	mov	dx, 0x3b8
@@ -291,11 +306,11 @@
 	mov	cx, 0x100
 	rep	movsb
 
 ; Clear video memory
 
-	mov	ax, 0xb800
+	mov	ax, dispmem
 	mov	es, ax
 	mov	di, 0
 	mov	cx, 80*25
 	mov	ax, 0x0700
 	rep	stosw
@@ -793,11 +808,15 @@
 
 	jmp	int10_set_vm_continue
 
   int10_set_vm_3:
 
+%if videotype == 0
+	mov	al, 7
+%else
 	mov	al, 3
+%endif
 
   int10_set_vm_continue:
 
 	mov	[cs:vidmode], al
 
@@ -1080,11 +1099,11 @@
 	push	si
 	push	di
 
 	push	bx
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, bx
 	mov	ds, bx
 
 	pop	bx
 
@@ -1328,11 +1347,11 @@
 	push	si
 	push	di
 
 	push	bx
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, bx
 	mov	ds, bx
 
 	pop	bx
 
@@ -1426,11 +1445,11 @@
 	push	bx
 
 	mov	bx, 0x40
 	mov	es, bx
 
-	mov	bx, 0xb000
+	mov	bx, dispback
 	mov	ds, bx
 
 	mov	bx, 0
 	add	bl, [es:curpos_x-bios_data]
 	add	bl, [es:curpos_x-bios_data]
@@ -1459,11 +1478,11 @@
 	push	bx
 
 	mov	bx, 0x40
 	mov	es, bx
 
-	mov	bx, 0xb000
+	mov	bx, dispback
 	mov	ds, bx
 
 	mov	bx, 0
 	mov	bl, [es:curpos_x-bios_data]
 	shl	bx, 1
@@ -1551,11 +1570,11 @@
 	push	bx
 
 	mov	bx, 0x40
 	mov	es, bx
 
-	mov	bx, 0xb000
+	mov	bx, dispback
 	mov	ds, bx
 
 	mov	bx, 0
 	mov	bl, [es:curpos_x-bios_data]
 	shl	bx, 1
@@ -2493,10 +2512,11 @@
 drive_sectors_temp dw 0
 drive_heads_temp  dw 0
 drive_num_temp    dw 0
 boot_state	db 0
 cga_refresh_reg	db 0
+hostiswin	db	0
 
 ; Default interrupt handlers
 
 int0:
 int1:
@@ -2788,11 +2808,11 @@
 	push	es
 	push	di
 	push	cx
 
 	cld
-	mov	ax, 0xb800
+	mov	ax, dispmem
 	mov	es, ax
 	mov	di, 0
 	mov	al, 0
 	mov	ah, bh
 	mov	cx, 80*25
@@ -2896,11 +2916,11 @@
 	mov	byte [cs:in_update], 1
 
 	sti
 
 	cld
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, bx
 	mov	cx, 0x7d0
 	mov	ax, 0x0700
 	mov	di, 0
 
@@ -2937,11 +2957,11 @@
 
 dont_hide_cursor:
 
 	mov	byte [cs:last_attrib], 0xff
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	ds, bx
 
 	; Set up the initial cursor coordinates. Since the first thing we do is increment the cursor
 	; position, this initial position is actually off the screen
 
@@ -3064,10 +3084,13 @@
 
 skip_attrib:
 
 	mov	al, [di]
 
+	cmp	byte [cs:hostiswin], 1
+	je	just_show_it
+
 	cmp	al, 32		; Non-printable ASCII? (< 32 decimal)
 	jae	just_show_it
 
 	mov	bx, low_ascii_conv
 	cs	xlat		; Convert to printable representation (mostly spaces)
@@ -3147,11 +3170,15 @@
 com4addr	dw	0
 lpt1addr	dw	0
 lpt2addr	dw	0
 lpt3addr	dw	0
 lpt4addr	dw	0
+%if videotype == 0
+equip		dw	0b0000000100110001
+%else
 equip		dw	0b0000000100100001
+%endif
 		db	0
 memsize		dw	0x280
 		db	0
 		db	0
 keyflags1	db	0
@@ -3163,21 +3190,29 @@
 drivecal	db	0
 diskmotor	db	0
 motorshutoff	db	0x07
 disk_laststatus	db	0
 times 7		db	0
+%if videotype == 0
+vidmode		db	0x07
+%else
 vidmode		db	0x03
+%endif
 vid_cols	dw	80
 page_size	dw	0x1000
 		dw	0
 curpos_x	db	0
 curpos_y	db	0
 times 7		dw	0
 cur_v_end	db	7
 cur_v_start	db	6
 disp_page	db	0
+%if videotype == 0
+crtport		dw	0x3c0
+%else
 crtport		dw	0x3d4
+%endif
 		db	10
 		db	0
 times 5		db	0
 clk_dtimer	dd	0
 clk_rollover	db	0
