--- run32.asm	Fri Dec 14 12:23:35 2001
+++ run32.asm	Fri Dec 14 15:55:55 2001
@@ -227,17 +227,20 @@
 ; os code
 
 
+%include "cfgsys.inc"
 
-
+; these are needed even if !CFG_FAT32 for UNSUPPORTED
 SET_FAT32_DATA      equ 0xd0000000
 READ_HD_FAT32_FILE  equ 0xd0000001
 WRITE_HD_FAT32_FILE equ 0xd0000002
 
+; these are needed even if !CFG_SOUND_SB16 for UNSUPPORTED
 SB16_load_music     equ 0xc0000000
 SB16_play_music     equ 0xc0000001
 
 
 
+%ifdef CFG_SOUND_SB16
 DMA             equ 1                   ;SB - your DMA 8 bit [0,1,3]
 DMAPage         equ 0x2A                ;first page of 64K in phisical RAM
 
@@ -247,6 +250,7 @@
 SB16_Status     equ SB16Buffer+65536    ;byte = 0  driver=not free
 					;     = 1  driver=free
 
+%endif ; CFG_SOUND_SB16
 
 
 
@@ -263,12 +267,16 @@
 linef     db      13,10,0
 
 okt       db      " ... OK",0
-
+%ifdef CFG_VIDEO_TEST_VESA
 novesa    db      "Display: EGA/CGA",13,10,0
 vervesa   db      "Display bios: Vesa x.x ",13,10,0
-
+%endif
+%ifdef CFG_LEAVE_UNUSED_CODE
 modena    db      "Fatal - VBE 0x112+ required.",0
+%endif
+%ifdef CFG_TEST_386
 not386    db      "Fatal - CPU 386+ required.",0
+%endif
 btns      db      "Fatal - 24 or 32 bpp.",0
 fatalsel  db      "Fatal - Graphics mode not supported by hardware.",0
 badsect   db      "Fatal - Bad sector. Replace floppy. ",0
@@ -276,25 +284,61 @@
 bt24      db      "   Bits per pixel: 24",13,10,0
 bt32      db      "   Bits per pixel: 32",13,10,0
 
+%ifdef CFG_VIDMODE_ASK
 gr_modes  
+%ifdef CFG_VIDEO_VESA12
 	  db      " Define set_bank function for Vesa1.2",13,10          
+%endif
+%ifdef CFG_VIDEO_VESA20
+%ifdef CFG_VIDMODE_VESA20_640x480x24
 	  db      " [1] Vesa2.0  640 x  480 x 16.7M  LFB",13,10
+%endif
+%ifdef CFG_VIDMODE_VESA20_800x600x24
 	  db      " [2] Vesa2.0  800 x  600 x 16.7M  LFB",13,10
+%endif
+%ifdef CFG_VIDMODE_VESA20_1024x768x24
 	  db      " [3] Vesa2.0 1024 x  768 x 16.7M  LFB",13,10
+%endif
+%ifdef CFG_VIDMODE_VESA20_1280x1024x24
 	  db      " [4] Vesa2.0 1280 x 1024 x 16.7M  LFB",13,10
+%endif
+%endif ; CFG_VIDEO_VESA20
+%ifdef CFG_VIDEO_VESA12
+%ifdef CFG_VIDMODE_VESA12_640x480x24
 	  db      " [5] Vesa1.2  640 x  480 x 16.7M  Bnk",13,10
+%endif
+%ifdef CFG_VIDMODE_VESA12_800x600x24
 	  db      " [6] Vesa1.2  800 x  600 x 16.7M  Bnk",13,10
+%endif
+%ifdef CFG_VIDMODE_VESA12_1024x768x24
 	  db      " [7] Vesa1.2 1024 x  768 x 16.7M  Bnk",13,10
+%endif
+%ifdef CFG_VIDMODE_VESA12_1280x1024x24
 	  db      " [8] Vesa1.2 1280 x 1024 x 16.7M  Bnk",13,10
+%endif
+%endif ; CFG_VIDEO_VESA12
+%ifdef CFG_VIDMODE_320x200
 	  db      " [9] EGA/CGA  320 x  200 x 8 bit",13,10
+%endif
 	  db      0          
 
 askmode   db      "Select mode ? ",0
+%endif ; CFG_VIDMODE_ASK
 
+%ifdef CFG_MOUSE_ASK
 askmouse  db      "Mouse hardware ports:",13,10
-	  db      " [1] PS/2 (USB),  [2] Com1,  [3] Com2 ",13,10
+%ifdef CFG_MOUSE_PS2
+	  db      " [1] PS/2 (USB),"
+%endif
+%ifdef CFG_MOUSE_COM1
+	  db "  [2] Com1,  "
+%endif
+%ifdef CFG_MOUSE_COM2
+	  db "[3] Com2 "
+%endif
+	  db 13,10
 	  db      " Select port ? ",0
-
+%endif ; CFG_MOUSE_ASK
 
 diskload  db      "Loading diskette: 00 %",8,8,8,8,0
 backspace db      8,0
@@ -308,11 +352,22 @@
 	  db       '                                                                              '
 	  db       'ĺ'
 	  db       '                                                                              '
+%ifdef CFG_IDE
 	  db       '                                           Primary Master   :                 '
 	  db       '                                           Primary Slave    :                 '
 	  db       '                                           Secondary Master :                 '
 	  db       '                                           Secondary Slave  :                 '
+%else
+	  db       '                                                                              '
+	  db       '                                                                              '
+	  db       '                                                                              '
+	  db       '                                                                              '
+%endif
+%ifdef CFG_SOUND_SB16
 	  db       '                                           Sound Blaster    :                 '
+%else
+	  db       '                                                                              '
+%endif
 	  db       '                                                                              '
 	  db       '                                                                              '
 	  db       '                                                                              '
@@ -330,8 +385,6 @@
 	  db       'ͼ'
 
 
-
-
 ; display text
 
 print:
@@ -361,9 +414,6 @@
 	popa
 	ret
 
-
-
-
 ; start of code
 
 
@@ -404,6 +454,7 @@
 	mov     si,linef
 	call    printplain
 
+%ifdef CFG_TEST_386
 
 ; test for 386+
 
@@ -424,8 +475,9 @@
 	jmp     $
       cpugood:
 
+%endif ; CFG_TEST_386
 
-
+%ifdef CFG_VIDEO_TEST_VESA
 ; test for vesa 2.0
 
 	mov     ax,0x4f00
@@ -456,10 +508,9 @@
 	call    print
 
       vesaerr:
+%endif ; CFG_VIDEO_TEST_VESA
 
-
-
-
+%ifdef CFG_VIDMODE_ASK
 ; Ask user graphics mode
 
 
@@ -481,6 +532,43 @@
 	jb      sgml1
 	cmp     eax,9
 	jg      sgml1
+%ifdef CFGSYS_VIDMODE_SOME_UNSUPPORTED
+; FIXME: there is a better way to do this
+%ifdef CFG_VIDMODE_VESA20_640x480x24
+	cmp     eax,2
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA20_800x600x24
+	cmp     eax,3
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA20_1024x768x24
+	cmp     eax,4
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA20_1280x1024x24
+	cmp     eax,5
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA12_640x480x24
+	cmp     eax,6
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA12_800x600x24
+	cmp     eax,7
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA12_1024x768x24
+	cmp     eax,8
+	je vidmode_supported
+%endif
+%ifdef CFG_VIDMODE_VESA12_1280x1024x24
+	cmp     eax,9
+	je vidmode_supported
+%endif
+	jmp gml0
+	vidmode_supported:
+%endif ; CFG_VIDMODE_SOME_UNSUPPORTED
 	mov     si,ax
 	sub     si,2
 	shl     si,4
@@ -490,7 +578,7 @@
 	mov     dx,[es:si+8]
 	jmp     gml10
       sgml1:
-
+%ifdef CFG_VIDMODE_320x200
 	cmp     al,10
 	jnz     gml00
 	mov     bx,0x13
@@ -502,10 +590,39 @@
 	push    word 0x1000
 	pop     es
 	jmp     gml10
+%endif ; CFG_VIDMODE_320x200
       gml00:
 
 	jmp     gml0
 
+%else ; ! CFG_VIDMODE_ASK
+	xor eax,eax
+	mov al,CFG_VIDMODE_ASSUME
+%ifdef CFG_VIDMODE_320x200
+	cmp al,8
+	jnz other_vidmode
+	mov     bx,0x13
+	mov     cx,640
+	mov     dx,480
+	push    word 0x0
+	pop     es
+	mov     [es:0x9000],byte 32
+	push    word 0x1000
+	pop     es
+	jmp vidmode_cont
+other_vid_mode:	
+%endif
+
+
+	mov     si,ax
+	shl     si,4
+	add     si,gr_table
+	mov     bx,[es:si+0]
+	mov     cx,[es:si+4]
+	mov     dx,[es:si+8]
+	jmp     vidmode_cont
+
+%endif ; CFG_VIDMODE_ASK
      gr_table:
 
 	dd      0x112+0100000000000000b ,  640 ,  480 , 0
@@ -517,12 +634,16 @@
 	dd      0x118                   , 1024 ,  768 , 0
 	dd      0x11B                   , 1280 , 1024 , 0
 
+%ifdef CFG_VIDMODE_ASK
       gml10:
 
 	add     al,47
 	mov     [keyin],al
 	mov     si,keyin
 	call    printplain
+%else
+      vidmode_cont:
+%endif ; CFG_VIDMODE_ASK
 
 	push    word 0x0000
 	pop     es
@@ -542,7 +663,7 @@
 	je      nov
 
 
-
+%ifdef CFG_VIDEO_VESA20
 ; Find Vesa 2.0 LFB & BPP
 
 
@@ -572,7 +693,7 @@
 	mov [es:0x9001],ax
 	pop ax
 	; -----
-
+%endif ; CFG_VIDEO_VESA20
       nov:
 
 	cmp     ax,24             ; 24 ?
@@ -596,8 +717,7 @@
 	mov     si,linef
 	call    print
 
-
-
+%ifdef CFG_VIDEO_VESA12
 ; Find Vesa 1.2 pm bank switch address
 
 	mov     ax,0x4f0A
@@ -615,10 +735,10 @@
 	push    word 0x0
 	pop     es
 	mov     [es:0x9014],eax
+%endif ; CFG_VIDEO_VESA12
 
 
-
-
+%ifdef CFG_MOUSE_ASK
 ; get mouse port
 
 	mov     si,askmouse
@@ -628,17 +748,25 @@
       getmouseport:
 
 	in      al,0x60
-
+%ifdef CFG_MOUSE_PS2
 	cmp     al,2
 	je      mselected
+%endif
+%ifdef CFG_MOUSE_COM1
 	cmp     al,3
 	je      mselected
+%endif
+%ifdef CFG_MOUSE_COM2
 	cmp     al,4
 	je      mselected
+%endif
 
 	jmp     getmouseport
-
       mselected:
+%else
+	mov al,CFG_MOUSE_ASSUME
+	inc al
+%endif ; CFG_MOUSE_ASK
 
 	push    word 0x0000
 	pop     es
@@ -648,6 +776,7 @@
 	pop     es
 
 
+%ifdef CFG_MOUSE_ASK
 	add     al,48
 	mov     [keyin],al
 
@@ -662,7 +791,7 @@
 	mov     si,linef
 	call    printplain
 	call    printplain
-
+%endif ; CFG_MOUSE_ASK
 
 
 ; read diskette to memory
@@ -1027,9 +1156,10 @@
 	movzx eax,word [0x2f0000+0x9008]  ; screen mode
 	mov   [0xFE0C],eax
 
+%ifdef CFG_VIDEO_VESA12
 	mov   eax,[0x2f0000+0x9014]       ; Vesa 1.2 bnk sw add
 	mov   [0xE030],eax
-
+%endif
 					  ; BytesPerScanLine 
 	mov   [0xfe08],word 640*4         ; for 320x200 
 	cmp   [0xFE0C],word 0x13
@@ -1041,11 +1171,16 @@
 
 ; Graphics addresses
 
+%ifdef CFGSYS_VIDEO_VESA_12AND20
+
 	cmp     [0xfe0c],word 0100000000000000b
 	jge     setvesa20
 	cmp     [0xfe0c],word 0x13
 	je      v20ga32
 
+%endif
+
+%ifdef CFG_VIDEO_VESA12
 	mov     [0xe020],dword Vesa12_putpixel24
 	mov     [0xe024],dword Vesa12_getpixel24
 	cmp     [0xfbf1],byte 24
@@ -1054,7 +1189,9 @@
 	mov     [0xe024],dword Vesa12_getpixel32
       ga24:
 	jmp     v20ga24
+%endif
 
+%ifdef CFG_VIDEO_VESA20
       setvesa20:
 	mov     [0xe020],dword Vesa20_putpixel24
 	mov     [0xe024],dword Vesa20_getpixel24
@@ -1063,9 +1200,11 @@
       v20ga32:
 	mov     [0xe020],dword Vesa20_putpixel32
 	mov     [0xe024],dword Vesa20_getpixel32
-      v20ga24:
-
+%endif
 
+%ifdef CFG_VIDEO_VESA20 CFG_VIDEO_VESA12
+      v20ga24:
+%endif
 
 
 ; tss's in gdt table
@@ -1140,7 +1279,7 @@
 	call  fileread
 
 
-
+%ifdef CFG_TEST_RDTSC
 ; RDTSC availability - bit 4 in edx
 
 
@@ -1172,6 +1311,10 @@
 
       nordtsc:
       nopentium:
+%elifdef CFG_RDTSC
+	mov     [0xfbf3],byte 1
+%endif ; CFG_TEST_RDTSC
+
 
 
 
@@ -1345,17 +1488,17 @@
 
 	call   set_variables
 
-
+%ifdef CFG_VIDMODE_320x200
 ; palette for 320x200
 
 	call   palette320x200
-
+%endif
 
 ; start multitasking
 
 	mov   [0xe000],byte 1        ; multitasking enabled
 
-	mov   eax,mbar               ; load 'mbar'
+	mov   eax,init_task    ; load initial task
 	call  start_application_fl   ; enables ints
 
 
@@ -1386,8 +1529,8 @@
 
 char
 	db    'CHAR    MT '
-mbar
-	db    'MBAR       '
+init_task
+	db    CFG_INIT_TASK
 
 
 ; SUBS
@@ -1427,8 +1570,9 @@
 
 	mov  [irq_owner+4*0],byte 1    ; timer
 	mov  [irq_owner+4*1],byte 1    ; keyboard
-
+%ifdef CFG_SOUND_SB16
 	mov  [irq_owner+4*5],byte 1    ; sound blaster
+%endif
 	mov  [irq_owner+4*6],byte 1    ; floppy diskette
 
 	mov  [irq_owner+4*13],byte 1   ; math co-pros
@@ -1453,6 +1597,7 @@
 	mov   [edi+4],dword 0x0
 	mov   [edi+8],dword 0xff
 
+%ifdef CFG_MOUSE_COM1
 	cmp   [0xf604],byte 2          ; com1 mouse ?  -> 0x3f0-0x3ff
 	jne   ripl1
 	mov   edi,[0x2d0000]
@@ -1464,7 +1609,9 @@
 	mov   [edi+4],dword 0x3f0
 	mov   [edi+8],dword 0x3ff
       ripl1:
+%endif ; CFG_MOUSE_COM1
 
+%ifdef CFG_MOUSE_COM2
 	cmp   [0xf604],byte 3          ; com2 mouse ?  -> 0x2f0-0x2ff
 	jne   ripl2
 	mov   edi,[0x2d0000]
@@ -1476,12 +1623,13 @@
 	mov   [edi+4],dword 0x2f0
 	mov   [edi+8],dword 0x2ff
       ripl2:
+%endif ; CFG_MOUSE_COM2
 
 	popa
 
 	ret
 
-
+; Note this is a table, so all entries must be here, regardless of config.
 mouseirqtable   db  12    ; ps2
 		db  4     ; com1
 		db  3     ; com2
@@ -1517,9 +1665,9 @@
 	mov   [0xf500],byte 0                 ; button buffer
 
 	mov   [0xfb0a],dword 100*65536+100    ; mouse x/y
-
+%ifdef CFG_SOUND_SB16
 	mov   byte [SB16_Status],0            ; Minazzi Paolo
-
+%endif
 	mov   [0x400000-12],dword 1           ; tiled background
 
 	mov   [0xfe80],dword 0x100000*8       ; LFB address
@@ -1667,7 +1815,7 @@
 
 	ret
 
-
+%ifdef CFG_VIDMODE_320x200
 palette320x200:
 
 
@@ -1723,7 +1871,7 @@
        loop palnew 
 
        ret
-
+%endif ; CFG_VIDMODE_320x200
 
 
 ; find free memory area
@@ -1879,6 +2027,8 @@
 
     pusha
 
+%ifdef CFG_HEADER_00
+
     cmp  [0x90000+6],word '00'
     jne  no_first_header
 
@@ -1901,6 +2051,9 @@
 
   no_first_header:
 
+%endif ; CFG_HEADER_00
+
+%ifdef CFG_HEADER_01
 
     cmp  [0x90000+6],word '01'
     jne  no_second_header
@@ -1924,6 +2077,7 @@
 
   no_second_header:
 
+%endif ; CFG_HEADER_01
 
     popa
 
@@ -2140,7 +2294,7 @@
     ret
 
 
-
+%ifdef CFG_HD
 start_application_hd:
 
 
@@ -2215,7 +2369,7 @@
     jmp   file_in_place             ; use start_application_fl
 				    ; for the parameters
 
-
+%endif ; CFG_HD
 
 sys_outport:
 
@@ -2327,10 +2481,13 @@
     mov   edx,ecx
     shl   edx,8
     add   edx,0x80000+0x80
+%ifdef CFG_RANDOM_WIN
     cmp   [edx],dword 0
     jne   rand_shaped
+%endif
     jmp   rect_shaped
 
+%ifdef CFG_RANDOM_WIN
   rand_shaped:
 
     pusha
@@ -2368,6 +2525,7 @@
   rand_window_pixel:
 
     popa
+%endif ; CFG_RANDOM_WIN
 
   rect_shaped:
 
@@ -2490,7 +2648,7 @@
 
 
 
-
+%ifdef CFG_SOUND_SB16
 sys_sb16:
 
      cmp  [sb16],word 0
@@ -2635,9 +2793,9 @@
      mov  eax,2  ; invalid command
      ret
 
+%endif ; CFG_SOUND_SB16
 
-
-
+%ifdef CFG_SOUND_WSS
 sys_wss:
 
      cmp  [wss],word 0
@@ -2691,6 +2849,7 @@
 
      mov  eax,2  ; invalid command
      ret
+%endif ; CFG_SOUND_WSS
 
 
 display_number:
@@ -3154,23 +3313,33 @@
 
 read_screen_pixel:
 
+%ifdef CFGSYS_VIDEO_VESA_12AND20
+
      cmp   [0xfe0c],word 0100000000000000b
      jge   rspv20
      cmp   [0xfe0c],word 0x13
      je    rspv20
 
-     call  vesa12_read_screen_pixel
+%endif
 
+%ifdef CFG_VIDEO_VESA12
+     call  vesa12_read_screen_pixel
      ret
+%endif
+
+%ifdef CFGSYS_VIDEO_VESA_12AND20
 
    rspv20:
 
-     call  vesa20_read_screen_pixel
+%endif
 
+%ifdef CFG_VIDEO_VESA20
+     call  vesa20_read_screen_pixel
      ret
+%endif
 
 
-
+%ifdef CFG_VIDEO_VESA20
 vesa20_read_screen_pixel:
 
 
@@ -3203,9 +3372,10 @@
      and   eax,0x00ffffff
 
      ret
+%endif ; CFG_VIDEO_VESA20
 
 
-
+%ifdef CFG_VIDEO_VESA12
 vesa12_read_screen_pixel:
 
 
@@ -3247,10 +3417,10 @@
      and   eax,0x00ffffff
 
      ret
+%endif ; CFG_VIDEO_VESA12
 
 
-
-
+%ifdef CFG_READSTRING
 read_string:
 
     ; eax  read_area
@@ -3260,6 +3430,7 @@
     ; esi  [x start]*65536 + [y_start]
 
     ret
+%endif ; CFG_READSTRING
 
 display_settings:
 
@@ -3353,7 +3524,7 @@
 
 
 
-
+%ifdef CFG_SOUND_MIDI
 is_input:
 
    push edx
@@ -3437,7 +3608,6 @@
 
    ret
 
-
 sys_midi:
 
      cmp  [mididp],word 0
@@ -3488,7 +3658,7 @@
 
      mov  eax,0
      ret
-
+%endif ; CFG_SOUND_MIDI
 
 
 
@@ -3599,7 +3769,7 @@
      ret
 
 
-
+%ifdef CFG_CDAUDIO
 sys_cd_audio:
 
      cmp  [cdbase],word 0
@@ -3954,7 +4124,7 @@
      mov  eax,0
      ret
 
-
+%endif ; CFG_CDAUDIO
 
 
 sys_cachetodiskette:
@@ -4352,27 +4522,36 @@
 
 	ret
 
-
-
 sys_putimage:
 
+%ifdef CFGSYS_VIDEO_VESA_12AND20
+
      cmp   [0xfe0c],word 0100000000000000b
      jge   piv20
      cmp   [0xfe0c],word 0x13
      je    piv20
 
-     call  vesa12_putimage
+%endif
 
+%ifdef CFG_VIDEO_VESA12
+     call  vesa12_putimage
      ret
+%endif
+
+%ifdef CFGSYS_VIDEO_VESA_12AND20
 
    piv20:
 
-     call  vesa20_putimage
+%endif
 
+%ifdef CFG_VIDEO_VESA20
+     call  vesa20_putimage
      ret
+%endif
 
 
 
+%ifdef CFG_VIDEO_VESA20
 vesa20_putimage:
 
 
@@ -4635,10 +4814,10 @@
       mov eax,0
 
       ret
+%endif ; CFG_VIDEO_VESA20
 
 
-
-
+%ifdef CFG_VIDEO_VESA12
 vesa12_putimage:
 
 ;    mov  ebx,image
@@ -4940,7 +5119,7 @@
     mov   eax,0
 
     ret
-
+%endif ; CFG_VIDEO_VESA12
 
 
 
@@ -6349,7 +6528,7 @@
 	popa
 	ret
 
-
+%ifdef CFG_VIDEO_VESA20
 Vesa20_putpixel24:
 
 	mov  edi,eax ; x
@@ -6381,7 +6560,7 @@
 	mov  [edi],ecx
 
 	ret
-
+%endif ; CFG_VIDEO_VESA20
 
 
 
@@ -6412,7 +6591,7 @@
 
 	ret
 
-
+%ifdef CFG_VIDEO_VESA20
 Vesa20_getpixel24:
 
 	mov  edi,eax ; x
@@ -6441,10 +6620,11 @@
 	and  ecx,0xffffff
 
 	ret
+%endif ; CFG_VIDEO_VESA20
 
 
 
-
+%ifdef CFG_VIDEO_VESA12
 
 ; ***************************************
 ; ********* BANKED PIXEL RELATED ********
@@ -6587,6 +6767,7 @@
 	sti
 
 	ret
+%endif ; CFG_VIDEO_VESA12
 
 
 
@@ -6721,23 +6902,32 @@
 
 
 drawbar:
-    
+%ifdef CFGSYS_VIDEO_VESA_12AND20
+
     cmp  [0xfe0c],word 0100000000000000b
     jge  dbv20
     cmp  [0xfe0c],word 0x13
     je   dbv20
 
-    call vesa12_drawbar
+%endif
 
+%ifdef CFG_VIDEO_VESA12
+    call vesa12_drawbar
     ret
+%endif
+
+%ifdef CFGSYS_VIDEO_VESA_12AND20
 
   dbv20:
 
-    call vesa20_drawbar
+%endif
 
+%ifdef CFG_VIDEO_VESA20
+    call vesa20_drawbar
     ret
+%endif
 
-
+%ifdef CFG_VIDEO_VESA20
 vesa20_drawbar:
 
 
@@ -7025,7 +7215,6 @@
      ret
 
 
-
 voodoodbcplimit:
 
 ; ebp:=(y+Ywin)*(ScreenXSize+1)+(x+Xwin)+AddrBuffer
@@ -7052,9 +7241,10 @@
      popa
      stc
      ret
+%endif ; CFG_VIDEO_VESA20
 
 
-
+%ifdef CFG_VIDEO_VESA12
 dbcplimit:
 
 	pusha
@@ -7415,7 +7605,7 @@
     add  esp,7*4
 
     ret
-
+%endif ; CFG_VIDEO_VESA12
 
 
 
@@ -7823,9 +8013,10 @@
 
 system_shutdown:
 
-
+%ifdef CFG_CDAUDIO
     mov  eax,3            ; stop playing cd
     call sys_cd_audio
+%endif
 
     cli
     cld
@@ -7923,14 +8114,14 @@
     jnz  newsdt
 
 
-    mov  eax,rosef          ; load rose.txt
+    mov  eax,endsplash_img          ; load endsplash image
     mov  ebx,0
     mov  ecx,16800
     mov  edx,0x90000
     mov  esi,0
     call fileread
 
-    mov  esi,[0xfe00]       ; draw rose
+    mov  esi,[0xfe00]       ; draw endsplash image
     shr  esi,1
     add  esi,20
     shl  esi,16
@@ -8019,16 +8210,20 @@
 
     sub  ax,128
 
+%ifdef CFG_FLOPPY_WRITE
     cmp  al,2              ; write floppy
     jnz  no_floppy_write
     call floppy_write
     jmp  nbw2
   no_floppy_write:
+%endif
 
+%ifdef CFG_APM_POWEROFF
     cmp  al,3              ; poweroff
     jnz  no_apm_off
     call APM_PowerOff
   no_apm_off:
+%endif
 
     cmp  al,4              ; boot
     jnz  no_sys_boot
@@ -8044,6 +8239,7 @@
     jmp  nbw
 
 
+%ifdef CFG_APM_POWEROFF
 APM_PowerOff:
 
 	mov     ax,5304h
@@ -8073,9 +8269,10 @@
 	mov     cx,3
 	int     15h
 	ret
+%endif ; CFG_APM_POWEROFF
 
 
-
+%ifdef CFG_FLOPPY_WRITE
 ; write diskette image to physical floppy
 
 
@@ -8173,8 +8370,7 @@
 	popa
 
 	ret
-
-
+%endif ; CFG_FLOPPY_WRITE
 
 
 BITS 32
@@ -8189,8 +8385,8 @@
     db   '2) APM - POWEROFF                       '
     db   '3) REBOOT                               '
 
-rosef
-    db 'ROSE    TXT'
+endsplash_img
+    db CFG_ENDSPLASH_IMG
 
 
 
@@ -9412,17 +9608,20 @@
 
 	mov    [mousecount],dword 0x2e0000+12*4096
 	mov    [mousedata],dword 0x2e0000+12*4096+0x10
+%ifdef CFG_MOUSE_COM1
 	cmp    [0xF604],byte 2
 	jne    nocom1mouse
 	mov    [mousecount],dword 0x2e0000+4*4096
 	mov    [mousedata],dword 0x2e0000+4*4096+0x10
       nocom1mouse:
+%endif
+%ifdef CFG_MOUSE_COM2
 	cmp    [0xF604],byte 3
 	jne    nocom2mouse
 	mov    [mousecount],dword 0x2e0000+3*4096
 	mov    [mousedata],dword 0x2e0000+3*4096+0x10
       nocom2mouse:
-
+%endif
 
 
       uusicheckmouse:
@@ -9438,8 +9637,14 @@
 	; first byte of comX or ps2 ?
 
 	cmp    [0xF604],byte 2
+%ifdef CFG_MOUSE_COM1 CFG_MOUSE_COM2
 	jge    com1mousefirst
+%endif
+%ifdef CFG_MOUSE_PS2
 	jmp    ps2mousefirst
+%endif
+
+%ifdef CFG_MOUSE_COM1 CFG_MOUSE_COM2
 
 	; ******************************************
 	; *********** COMX mouse driver ************
@@ -9550,8 +9755,9 @@
 
 	; end of com1 mouse
 
+%endif ; CFG_MOUSE_COM1 or CFG_MOUSE_COM2
 
-
+%ifdef CFG_MOUSE_PS2
 	; ******************************************
 	; ********  PS2 MOUSE DRIVER  **************
 	; ******************************************
@@ -9634,8 +9840,9 @@
 
 
 	; end of ps2 mouse
+%endif ; CFG_MOUSE_PS2
 
-
+	; FIXME: no mouse needs testing: probably have to push some values etc.
 
 
 	; ****************************
@@ -9946,18 +10153,29 @@
 
 drawbackground:
 
+%ifdef CFGSYS_VIDEO_VESA_12AND20
+
        cmp  [0xfe0c],word 0100000000000000b
        jge  dbrv20
        cmp  [0xfe0c],word 0x13
        je   dbrv20
 
-       call  vesa12_drawbackground
+%endif
 
+%ifdef CFG_VIDEO_VESA12
+       call  vesa12_drawbackground
        ret
+%endif
+
 
+%ifdef CFGSYS_VIDEO_VESA_12AND20
 
      dbrv20:
 
+%endif
+
+%ifdef CFG_VIDEO_VESA20
+
        cmp   [0x400000-12],dword 1
        jne   bgrstr
 
@@ -9970,7 +10188,7 @@
        call  vesa20_drawbackground_stretch
 
        ret
-
+%endif ; CFG_VIDEO_VESA20
 
 calculate_edi_esi:
 
@@ -10278,7 +10496,7 @@
 
 
 
-
+%ifdef CFG_VIDEO_VESA12
 vesa12_drawbackground:
 
 
@@ -10410,7 +10628,7 @@
 	pop   eax
 
 	ret
-
+%endif ; CFG_VIDEO_VESA12
 
 
 imax    dd 0x0
@@ -10513,7 +10731,7 @@
     ret
 
 
-
+%ifdef CFG_RANDOM_WIN
 random_shaped_window:
 
 ;
@@ -10538,7 +10756,7 @@
    rsw_no_scale:
 
      ret
-
+%endif ; CFG_RANDOM_WIN
 
 ; calculate fat chain
 
@@ -10687,7 +10905,7 @@
 
 
 
-
+%ifdef CFG_HD
 read_hd_file:
 
 ; as input
@@ -10826,8 +11044,6 @@
     ret
 
 
-; read fat32 file
-
 read_fat32_file:
 
   mov  esi,[esp+8]        ; fat start cluster
@@ -11274,6 +11490,7 @@
     pop   esi
 
     ret
+%endif ; CFG_HD
 
 
 sys_programirq:
@@ -11535,6 +11752,7 @@
      ret
 
 
+%ifdef CFG_FAT32
 
 ;***************************************
 ; BEGIN FAT32 by Paolo Minazzi
@@ -12475,6 +12693,9 @@
     pop eax
     pop esi
     ret
+%endif ; CFG_FAT32
+
+%ifdef CFG_SOUND_SB16
     
 ;***********************************************************
 ;*************   SB16-CODE-by-Paolo-Minazzi   **************
@@ -12487,7 +12708,6 @@
 %endm
 
 
-
 code_SB16_load_music:
 
      cmp byte [SB16_Status],1
@@ -12610,12 +12830,11 @@
 ; END CODE SB16 by Minazzi Paolo
 ;***************************************
 
+%endif ; CFG_SOUND_SB16
 
 
 
-
-
-
+%ifdef CFG_LEAVE_UNUSED_CODE
 ; system manegement mode
 
 smm:
@@ -12627,7 +12846,7 @@
 
      jmp $
 
-
+%endif ; CFG_LEAVE_UNUSED_CODE
 
 
 
@@ -12756,11 +12975,11 @@
 
      mov     [0xf200],dword mousepointer
 
+     cli
 
+%ifdef CFG_MOUSE_PS2
      ; ps2 mouse enable
 
-     cli
-
      mov     bl,0a8h                 ; enable mouse cmd
      call    keyboard_cmd
      call    keyboard_read           ; read status return
@@ -12780,8 +12999,9 @@
      mov     al,0f4h                 ; enable mouse device
      call    keyboard_write
      call    keyboard_read           ; read status return
+%endif ; CFG_MOUSE_PS2
 
-
+%ifdef CFG_MOUSE_COM1
      ; com1 mouse enable
 
      mov   bx,0x3f8 ; combase
@@ -12815,8 +13035,9 @@
      add   dx,1
      mov   al,1
      out   dx,al
+%endif ; CFG_MOUSE_COM1
 
-
+%ifdef CFG_MOUSE_COM2
      ; com2 mouse enable
 
      mov   bx,0x2f8 ; combase
@@ -12851,6 +13072,7 @@
      mov   al,1
      out   dx,al
 
+%endif ; CFG_MOUSE_COM2
 
      ret
 
@@ -13107,12 +13329,16 @@
      ret
    nostart:
 
+%ifdef CFG_SOUND_MIDI
      cmp   edi,20                ; ResetMidi and OutputMidi
      jnz   nomidi
      call  sys_midi
      mov   [esp+26],eax
      ret
    nomidi:
+%else
+	CFGSYS_UNSUPPORTED 20
+%endif
 
 				 ; SetMidiBase, SetKeymap, SetShiftKeymap,
 				 ; SetKeyLayout, SetCdBase, SetSb16Base,
@@ -13137,19 +13363,27 @@
      ret
    nowaitforeventwithtimeout:
 
+%ifdef CFG_CDAUDIO
      cmp   edi,24                ; PlayCdTrack, StopCd and GetCdPlaylist
      jnz   nocdaudio
      call  sys_cd_audio
      mov   [esp+26],eax
      ret
    nocdaudio:
+%else
+	CFGSYS_UNSUPPORTED 24
+%endif
 
+%ifdef CFG_SOUND_SB16
      cmp   edi,25                ; SetSb16MixerIMainVol and SetSb16MixerICdVol
      jnz   nosb16
      call  sys_sb16
      mov   [esp+26],eax
      ret
    nosb16:
+%else
+	CFGSYS_UNSUPPORTED 25
+%endif
 
 				 ; GetMidiBase, GetKeymap, GetShiftKeymap,
 				 ; GetKeyLayout, GetCdBase, GetSb16Base,
@@ -13161,19 +13395,28 @@
      ret
    nogetsetup:
 
+
+%ifdef CFG_SOUND_WSS
      cmp   edi,27                ; SetWssMainVol and SetWssCdVol
      jnz   nowss
      call  sys_wss
      mov   [esp+26],eax
      ret
    nowss:
+%else
+	CFGSYS_UNSUPPORTED 27
+%endif
 
+%ifdef CFG_SOUND_SB16
      cmp   edi,28                ; SetSb16MixerIIMainVol and SetSb16MixerIICdVol
      jnz   nosb16II
      call  sys_sb16II
      mov   [esp+26],eax
      ret
    nosb16II:
+%else
+	CFGSYS_UNSUPPORTED 28
+%endif
 
      cmp   edi,29                ; GetDate
      jnz   nodate
@@ -13182,6 +13425,7 @@
      ret
    nodate:
 
+%ifdef CFG_HD
      cmp   edi,30                ; ReadHd
      jnz   nohdread
      mov   edi,[0x3010]
@@ -13193,7 +13437,11 @@
      mov   [esp+22],ebx
      ret
    nohdread:
+%else
+	CFGSYS_UNSUPPORTED 30
+%endif
 
+%ifdef CFG_HD
      cmp   edi,31                ; StartHdApp
      jnz   nostarthd
      mov   edi,[0x3010]
@@ -13204,6 +13452,9 @@
      mov   [esp+26],eax
      ret
    nostarthd:
+%else
+	CFGSYS_UNSUPPORTED 31
+%endif
 
      cmp   edi,32                ; DelRamdiskFile
      jnz   nofiledelete          
@@ -13243,6 +13494,7 @@
      ret
    noreadscreen:
 
+%ifdef CFG_READSTRING
      cmp   edi,36                ; ReadString (not yet ready
      jnz   noreadstring
      mov   edi,[0x3010]
@@ -13252,6 +13504,9 @@
      mov   [esp+26],eax
      ret
    noreadstring:
+%else
+	CFGSYS_UNSUPPORTED 36
+%endif
 
 				 ; GetMousePosition_ScreenRelative,
 				 ; GetMousePosition_WindowRelative and
@@ -13365,12 +13620,17 @@
      ret
    no_app_ints:
 
+%ifdef CFG_RANDOM_WIN
      cmp   edi,50                    ; SetRandomShapeWindow and
      jne   no_random_shaped_window   ; SetRandomShapeScale
      call  random_shaped_window
      ret
    no_random_shaped_window:
+%else
+	CFGSYS_UNSUPPORTED 50
+%endif
 
+%ifdef CFG_SOUND_SB16
      cmp   edi,SB16_load_music       ; LoadSb16Music
      jnz   noSB16_load_music
      push  ebx
@@ -13381,19 +13641,31 @@
      call  code_SB16_load_music
      ret
    noSB16_load_music:
+%else
+	CFGSYS_UNSUPPORTED SB16_load_music
+%endif
 
+%ifdef CFG_SOUND_SB16
      cmp   edi,SB16_play_music       ; PlaySb16Music
      jnz   noSB16_play_music
      call  code_SB16_play_music
      ret
    noSB16_play_music:
+%else
+	CFGSYS_UNSUPPORTED SB16_play_music
+%endif
 
+%ifdef CFG_FAT32
      cmp   edi,SET_FAT32_DATA        ; SetFat32Data
      jnz   noSET_FAT32_DATA
      call  set_FAT32_variables
      ret
    noSET_FAT32_DATA:
+%else
+	CFGSYS_UNSUPPORTED SET_FAT32_DATA
+%endif
 
+%ifdef CFG_FAT32
      cmp   edi,READ_HD_FAT32_FILE     ; ReadFat32File
      jnz   noREAD_HD_FAT32_FILE  
      push  ebx
@@ -13405,7 +13677,11 @@
      call  file_read
      ret
    noREAD_HD_FAT32_FILE:
+%else
+	CFGSYS_UNSUPPORTED READ_HD_FAT32_FILE
+%endif
 
+%ifdef CFG_FAT32
      cmp   edi,WRITE_HD_FAT32_FILE     ; WriteFat32File
      jnz   noWRITE_HD_FAT32_FILE  
      push  ebx
@@ -13417,6 +13693,9 @@
      call  file_write
      ret
    noWRITE_HD_FAT32_FILE:
+%else
+	CFGSYS_UNSUPPORTED WRITE_HD_FAT32_FILE
+%endif
 
      cmp   edi,-1                       ; EndApp
      jnz   noend
@@ -13480,7 +13759,7 @@
 
       iret
 
-
+%ifdef CFG_LINUX_EMULATION
 i_Linux_sys:
 
       cli
@@ -13529,7 +13808,7 @@
       sti
 
       jmp   $ 
-
+%endif ; CFG_LINUX_EMULATION
 
 
 ; cpu ints
@@ -14110,7 +14389,8 @@
 
 sys_panic  db   'TIMES      '
 
-
+%ifdef CFG_LEAVE_UNUSED_CODE
+%ifdef CFG_SOUND_SB16
 
 irq5 ; SB16
 
@@ -14143,7 +14423,8 @@
 
 	iret
 
-
+%endif ; CFG_SOUND_SB16
+%endif ; CFG_LEAVE_UNUSED_CODE
 
 
 
@@ -14759,10 +15040,13 @@
 	push  dword $
 	jmp   i_u_errorhandle
 
-
+; note original kernel included this even though it was unused.
+%ifdef CFG_LEAVE_UNUSED_CODE CFGSYS_NO_LINUX_EMULATION
 i_unknown80
 	push  dword $
 	jmp   i_u_errorhandle
+%endif ; CFG_LEAVE_UNUSED_CODE or CFGSYS_NO_LINUX_EMULATION
+
 i_unknown81
 	push  dword $
 	jmp   i_u_errorhandle
@@ -15309,7 +15593,14 @@
     dd   i_unknown70,i_unknown71,i_unknown72,i_unknown73,i_unknown74,i_unknown75,i_unknown76,i_unknown77
     dd   i_unknown78,i_unknown79,i_unknown7a,i_unknown7b,i_unknown7c,i_unknown7d,i_unknown7e,i_unknown7f
 
-    dd   i_Linux_sys,i_unknown81,i_unknown82,i_unknown83,i_unknown84,i_unknown85,i_unknown86,i_unknown87
+%ifdef CFG_LINUX_EMULATION
+    dd   i_Linux_sys
+%else
+    dd   i_unknown80
+%endif
+
+    dd      i_unknown81,i_unknown82,i_unknown83,i_unknown84,i_unknown85,i_unknown86,i_unknown87
+
     dd   i_unknown88,i_unknown89,i_unknown8a,i_unknown8b,i_unknown8c,i_unknown8d,i_unknown8e,i_unknown8f
 
     dd   i_unknown90,i_unknown91,i_unknown92,i_unknown93,i_unknown94,i_unknown95,i_unknown96,i_unknown97
@@ -15446,7 +15737,7 @@
 sb16       dd 0x0
 wss        dd 0x0
 
-syslang    dd 0x1
+syslang    dd CFG_DEFAULT_LANGUAGE
 
 ; display
 
