--- bios.asm	2014-03-17 21:40:14.000000000 +0800
+++ bios.qhack.asm	2014-03-20 14:01:48.624641600 +0800
@@ -5,10 +5,20 @@
 ;
 ; This work is licensed under the MIT License. See included LICENSE.TXT.
 
 	cpu	8086
 
+%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
+%else
+%define	dispmem 	0xb800 ; Display 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
@@ -261,11 +271,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
@@ -1116,11 +1126,15 @@
 	mov	ax, 0x30
 	jmp	svmn_exit
 
   int10_set_vm_3:
 
+%if videotype == 0
+	mov	al, 7
+%else
 	mov	al, 3
+%endif
 
   int10_set_vm_continue:
 
 	mov	bx, 0x40
 	mov	es, bx
@@ -1405,11 +1419,11 @@
 
 	mov	byte [cs:vram_dirty], 1
 
 	push	bx
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, bx
 	mov	ds, bx
 
 	pop	bx
 	mov	bl, al
@@ -1647,11 +1661,11 @@
 
 	mov	byte [cs:vram_dirty], 1
 
 	push	bx
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, bx
 	mov	ds, bx
 
 	pop	bx
 	mov	bl, al
@@ -3088,11 +3102,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
@@ -3227,11 +3241,11 @@
 
 	mov	di, [vmem_offset-bios_data] ; Adjust for CRTC video memory offset register
 	shl	di, 1
 	push	di
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, bx
 	mov	cx, 0x7d0
 	mov	ax, 0x0700
 
 	cld
@@ -3288,11 +3302,11 @@
 
 	mov	di, [es:vmem_offset-bios_data] ; Adjust for CRTC video memory offset register
 	shl	di, 1
 	sub	di, 2		; Combined offset
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	es, 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
 
@@ -3326,11 +3340,11 @@
 	je	cont
 
 	push	si
 	push	di
 
-	mov	bx, 0xb800
+	mov	bx, dispmem
 	mov	ds, bx
 	mov	bx, 0xc800
 	mov	es, bx
 	mov	si, di
 
@@ -3614,11 +3628,15 @@
 com4addr	dw	0
 lpt1addr	dw	0
 lpt2addr	dw	0
 lpt3addr	dw	0
 lpt4addr	dw	0
+%if videotype == 0
+equip		dw	0b0000000000110001
+%else
 equip		dw	0b0000000000100001
+%endif
 ;equip		dw	0b0000000100100001
 		db	0
 memsize		dw	0x280
 		db	0
 		db	0
@@ -3631,21 +3649,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
