	SECTION _TEXT align=1 CLASS=CODE USE32
	SECTION _DATA align=16 CLASS=DATA USE32
	SECTION _BSS align=16 CLASS=BSS USE32
	SECTION _CONST align=16 CLASS=CONST USE32
	SECTION _STRING align=4 CLASS=STRING USE32
	SECTION cstartup align=4 CLASS=INITDATA USE32
	SECTION crundown align=4 CLASS=EXITDATA USE32
	SECTION cppinit  align=4 CLASS=CPPINIT USE32
	SECTION cppexit  align=4 CLASS=CPPEXIT USE32
	GROUP DGROUP _DATA _BSS _CONST _STRING

SECTION _TEXT
[GLOBAL	_SystemMenuProc]
;
; Line 5:	int SystemMenuProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
;
_SystemMenuProc:
	PUSH	EBP
	MOV	EBP,ESP
	SUB	ESP,BYTE 010H
	PUSH	EBX
	PUSH	ESI
	PUSH	EDI
	MOV	ESI,DWORD [EBP+08H]
	MOV	EBX,DWORD [EBP+014H]
	MOV	EDI,DWORD _classdefs
L_2:
;
; Line 6:	{
;
;
; Line 9:	switch (msg)    {
;
	MOV	EAX,DWORD [EBP+0CH]
	CMP	EAX,BYTE 024H
	JE	SHORT	L_6
	JA	SHORT	L_11
	CMP	EAX,BYTE 07H
	JE	NEAR	L_10
	JA	SHORT	L_12
	CMP	EAX,BYTE 03H
	JE	SHORT	L_5
	JMP	NEAR	L_4
L_12:
	CMP	EAX,BYTE 01EH
	JE	NEAR	L_9
	JMP	NEAR	L_4
L_11:
	CMP	EAX,BYTE 041H
	JE	SHORT	L_7
	JA	NEAR	L_4
	CMP	EAX,BYTE 025H
	JE	NEAR	L_8
	JMP	NEAR	L_4
L_5:
;
; Line 11:	wnd->holdmenu = ActiveMenuBar;
;
	MOV	EAX,DWORD [_ActiveMenuBar]
	MOV	DWORD [ESI+0114H],EAX
;
; Line 12:	ActiveMenuBar = &SystemMenu;
;
	MOV	DWORD [_ActiveMenuBar],DWORD _SystemMenu
;
; Line 13:	SystemMenu.PullDown[0].Selection = 0;
;
	MOV	DWORD [_SystemMenu+014H],00H
;
; Line 14:	break;
;
	JMP	NEAR	L_3
L_6:
;
; Line 16:	wnd1 = GetParent(wnd);
;
	MOV	EAX,DWORD [ESI+03CH]
	MOV	DWORD [EBP-04H],EAX
;
; Line 17:	mx = (int) p1 - GetLeft(wnd1);
;
	MOV	EAX,DWORD [EBP-04H]
	MOV	ECX,DWORD [EBP+010H]
	SUB	ECX,DWORD [EAX+0CH]
	MOV	DWORD [EBP-0CH],ECX
;
; Line 18:	my = (int) p2 - GetTop(wnd1);
;
	MOV	EAX,DWORD [EBP-04H]
	MOV	ECX,EBX
	SUB	ECX,DWORD [EAX+010H]
	MOV	DWORD [EBP-08H],ECX
;
; Line 19:	if (HitControlBox(wnd1, mx, my))
;
	MOV	EAX,DWORD [EBP-04H]
	MOV	EAX,DWORD [EAX+054H]
	AND	EAX,0200H
	JE	SHORT	L_13
	CMP	DWORD [EBP-0CH],BYTE 02H
	JNE	SHORT	L_13
	CMP	DWORD [EBP-08H],BYTE 00H
	JNE	SHORT	L_13
;
; Line 20:	return TRUE;
;
	MOV	EAX,01H
	JMP	NEAR	L_1
L_13:
;
; Line 21:	break;
;
	JMP	SHORT	L_3
L_7:
;
; Line 23:	PostMessage(wnd, CLOSE_WINDOW, 0, 0);
;
	PUSH	BYTE 00H
	PUSH	BYTE 00H
	PUSH	BYTE 07H
	PUSH	ESI
	CALL	_PostMessage
	ADD	ESP,BYTE 010H
;
; Line 24:	break;
;
	JMP	SHORT	L_3
L_8:
;
; Line 26:	if (p2 == GetTop(GetParent(wnd)))    {
;
	MOV	EAX,DWORD [ESI+03CH]
	CMP	EBX,DWORD [EAX+010H]
	JNE	SHORT	L_15
;
; Line 27:	PostMessage(GetParent(wnd), msg, p1, p2);
;
	PUSH	EBX
	PUSH	DWORD [EBP+010H]
	MOVSX	EAX,WORD [EBP+0CH]
	PUSH	EAX
	PUSH	DWORD [ESI+03CH]
	CALL	_PostMessage
	ADD	ESP,BYTE 010H
;
; Line 28:	SendMessage(wnd, CLOSE_WINDOW, TRUE, 0);
;
	PUSH	BYTE 00H
	PUSH	BYTE 01H
	PUSH	BYTE 07H
	PUSH	ESI
	CALL	_SendMessage
	ADD	ESP,BYTE 010H
L_15:
;
; Line 30:	return TRUE;
;
	MOV	EAX,01H
	JMP	SHORT	L_1
L_9:
;
; Line 32:	return TRUE;
;
	MOV	EAX,01H
	JMP	SHORT	L_1
L_10:
;
; Line 34:	ActiveMenuBar = wnd->holdmenu;
;
	MOV	EAX,DWORD [ESI+0114H]
	MOV	DWORD [_ActiveMenuBar],EAX
;
; Line 35:	break;
;
	JMP	SHORT	L_3
L_4:
;
; Line 37:	break;
;
	JMP	SHORT	L_3
L_3:
;
; Line 39:	return DefaultWndProc(wnd, msg, p1, p2);
;
	MOV	EAX,DWORD [ESI+00H]
	IMUL	EAX,BYTE 0CH
	LEA	EAX,[EDI+EAX+00H]
	CMP	DWORD [EAX+04H],BYTE 00H
	JNE	SHORT	L_17
	PUSH	EBX
	PUSH	DWORD [EBP+010H]
	MOVSX	EAX,WORD [EBP+0CH]
	PUSH	EAX
	PUSH	ESI
	MOV	EAX,DWORD [ESI+00H]
	IMUL	EAX,BYTE 0CH
	MOV	EAX,DWORD [EDI+EAX+00H]
	IMUL	EAX,BYTE 0CH
	LEA	EAX,[EDI+EAX+00H]
	CALL	DWORD [EAX+04H]
	ADD	ESP,BYTE 010H
	JMP	SHORT	L_18
L_17:
	PUSH	EBX
	PUSH	DWORD [EBP+010H]
	MOVSX	EAX,WORD [EBP+0CH]
	PUSH	EAX
	PUSH	ESI
	MOV	EAX,DWORD [ESI+00H]
	IMUL	EAX,BYTE 0CH
	LEA	EAX,[EDI+EAX+00H]
	CALL	DWORD [EAX+04H]
	ADD	ESP,BYTE 010H
L_18:
L_1:
	POP	EDI
	POP	ESI
	POP	EBX
	MOV	ESP,EBP
	POP	EBP
	RET
[GLOBAL	_BuildSystemMenu]
;
; Line 43:	void BuildSystemMenu(WINDOW wnd)
;
_BuildSystemMenu:
	PUSH	EBP
	MOV	EBP,ESP
	SUB	ESP,BYTE 014H
	PUSH	EBX
	PUSH	ESI
	PUSH	EDI
	MOV	ESI,DWORD [EBP+08H]
	MOV	EBX,DWORD _SystemMenu
L_20:
;
; Line 44:	{
;
;
; Line 48:	SystemMenu.PullDown[0].Selections[6].Accelerator =
;
	CMP	DWORD [ESI+00H],BYTE 01H
	JNE	SHORT	L_21
	MOV	EAX,010EBH
	JMP	SHORT	L_22
L_21:
	MOV	EAX,010E1H
L_22:
	MOV	DWORD [EBX+098H],EAX
;
; Line 51:	lf = GetLeft(wnd)+1;
;
	MOV	EAX,DWORD [ESI+0CH]
	INC	EAX
	MOV	DWORD [EBP-010H],EAX
;
; Line 52:	tp = GetTop(wnd)+1;
;
	MOV	EAX,DWORD [ESI+010H]
	INC	EAX
	MOV	DWORD [EBP-0CH],EAX
;
; Line 53:	ht = MenuHeight(SystemMenu.PullDown[0].Selections);
;
	MOV	EAX,EBX
	ADD	EAX,BYTE 018H
	PUSH	EAX
	CALL	_MenuHeight
	POP	ECX
	MOV	DWORD [EBP-08H],EAX
;
; Line 54:	wd = MenuWidth(SystemMenu.PullDown[0].Selections);
;
	MOV	EAX,EBX
	ADD	EAX,BYTE 018H
	PUSH	EAX
	CALL	_MenuWidth
	POP	ECX
	MOV	DWORD [EBP-04H],EAX
;
; Line 56:	if (lf+wd > SCREENWIDTH-1)
;
	MOV	EAX,04AH
	MOVZX	ECX,WORD [___seg0040]
	MOV	EDX,ECX
	MOV	FS,DX
	MOVSX	EAX,BYTE [FS:EAX+00H]
	MOVZX	EAX,AL
	DEC	EAX
	MOV	ECX,DWORD [EBP-010H]
	ADD	ECX,DWORD [EBP-04H]
	CMP	ECX,EAX
	JLE	SHORT	L_23
;
; Line 57:	lf = (SCREENWIDTH-1) - wd;
;
	MOV	EAX,04AH
	MOVZX	ECX,WORD [___seg0040]
	MOV	EDX,ECX
	MOV	FS,DX
	MOVSX	EAX,BYTE [FS:EAX+00H]
	MOVZX	EAX,AL
	DEC	EAX
	SUB	EAX,DWORD [EBP-04H]
	MOV	DWORD [EBP-010H],EAX
L_23:
;
; Line 58:	if (tp+ht > SCREENHEIGHT-2)
;
	CALL	_isVGA
	TEST	EAX,EAX
	JNE	SHORT	L_29
	CALL	_isEGA
	TEST	EAX,EAX
	JE	SHORT	L_27
L_29:
	MOV	EAX,084H
	MOVZX	ECX,WORD [___seg0040]
	MOV	EDX,ECX
	MOV	FS,DX
	MOVSX	EAX,BYTE [FS:EAX+00H]
	INC	EAX
	JMP	SHORT	L_28
L_27:
	MOV	EAX,019H
L_28:
	SUB	EAX,BYTE 02H
	MOV	ECX,DWORD [EBP-0CH]
	ADD	ECX,DWORD [EBP-08H]
	CMP	ECX,EAX
	JLE	SHORT	L_25
;
; Line 59:	tp = (SCREENHEIGHT-2) - ht;
;
	CALL	_isVGA
	TEST	EAX,EAX
	JNE	SHORT	L_32
	CALL	_isEGA
	TEST	EAX,EAX
	JE	SHORT	L_30
L_32:
	MOV	EAX,084H
	MOVZX	ECX,WORD [___seg0040]
	MOV	EDX,ECX
	MOV	FS,DX
	MOVSX	EAX,BYTE [FS:EAX+00H]
	INC	EAX
	JMP	SHORT	L_31
L_30:
	MOV	EAX,019H
L_31:
	SUB	EAX,BYTE 02H
	SUB	EAX,DWORD [EBP-08H]
	MOV	DWORD [EBP-0CH],EAX
L_25:
;
; Line 61:	SystemMenuWnd = CreateWindow(POPDOWNMENU, NULL,
;
	PUSH	BYTE 00H
	PUSH	DWORD _SystemMenuProc
	PUSH	ESI
	PUSH	BYTE 00H
	PUSH	DWORD [EBP-04H]
	PUSH	DWORD [EBP-08H]
	PUSH	DWORD [EBP-0CH]
	PUSH	DWORD [EBP-010H]
	PUSH	BYTE 00H
	PUSH	BYTE 07H
	CALL	_CreateWindow
	ADD	ESP,BYTE 028H
	MOV	EDI,EAX
;
; Line 65:	if (wnd->condition == ISRESTORED)
;
	CMP	DWORD [ESI+05CH],BYTE 00H
	JNE	SHORT	L_33
;
; Line 66:	DeactivateCommand(&SystemMenu, ID_SYSRESTORE);
;
	PUSH	BYTE 024H
	PUSH	EBX
	CALL	_DeactivateCommand
	ADD	ESP,BYTE 08H
	JMP	SHORT	L_34
L_33:
;
; Line 68:	ActivateCommand(&SystemMenu, ID_SYSRESTORE);
;
	PUSH	BYTE 024H
	PUSH	EBX
	CALL	_ActivateCommand
	ADD	ESP,BYTE 08H
L_34:
;
; Line 71:	if (TestAttribute(wnd, MOVEABLE)
;
	MOV	EAX,DWORD [ESI+054H]
	AND	EAX,BYTE 02H
	JE	SHORT	L_35
	CMP	DWORD [ESI+05CH],BYTE 02H
	JE	SHORT	L_35
;
; Line 76:	ActivateCommand(&SystemMenu, ID_SYSMOVE);
;
	PUSH	BYTE 025H
	PUSH	EBX
	CALL	_ActivateCommand
	ADD	ESP,BYTE 08H
	JMP	SHORT	L_36
L_35:
;
; Line 78:	DeactivateCommand(&SystemMenu, ID_SYSMOVE);
;
	PUSH	BYTE 025H
	PUSH	EBX
	CALL	_DeactivateCommand
	ADD	ESP,BYTE 08H
L_36:
;
; Line 80:	if (wnd->condition != ISRESTORED ||
;
	CMP	DWORD [ESI+05CH],BYTE 00H
	JNE	SHORT	L_39
	MOV	EAX,DWORD [ESI+054H]
	AND	EAX,BYTE 04H
	JNE	SHORT	L_37
L_39:
;
; Line 82:	DeactivateCommand(&SystemMenu, ID_SYSSIZE);
;
	PUSH	BYTE 026H
	PUSH	EBX
	CALL	_DeactivateCommand
	ADD	ESP,BYTE 08H
	JMP	SHORT	L_38
L_37:
;
; Line 84:	ActivateCommand(&SystemMenu, ID_SYSSIZE);
;
	PUSH	BYTE 026H
	PUSH	EBX
	CALL	_ActivateCommand
	ADD	ESP,BYTE 08H
L_38:
;
; Line 87:	if (wnd->condition == ISMINIMIZED ||
;
	CMP	DWORD [ESI+05CH],BYTE 01H
	JE	SHORT	L_42
	MOV	EAX,DWORD [ESI+054H]
	AND	EAX,0400H
	JNE	SHORT	L_40
L_42:
;
; Line 89:	DeactivateCommand(&SystemMenu, ID_SYSMINIMIZE);
;
	PUSH	BYTE 027H
	PUSH	EBX
	CALL	_DeactivateCommand
	ADD	ESP,BYTE 08H
	JMP	SHORT	L_41
L_40:
;
; Line 91:	ActivateCommand(&SystemMenu, ID_SYSMINIMIZE);
;
	PUSH	BYTE 027H
	PUSH	EBX
	CALL	_ActivateCommand
	ADD	ESP,BYTE 08H
L_41:
;
; Line 95:	if (wnd->condition != ISRESTORED ||
;
	CMP	DWORD [ESI+05CH],BYTE 00H
	JNE	SHORT	L_45
	MOV	EAX,DWORD [ESI+054H]
	AND	EAX,0400H
	JNE	SHORT	L_43
L_45:
;
; Line 97:	DeactivateCommand(&SystemMenu, ID_SYSMAXIMIZE);
;
	PUSH	BYTE 028H
	PUSH	EBX
	CALL	_DeactivateCommand
	ADD	ESP,BYTE 08H
	JMP	SHORT	L_44
L_43:
;
; Line 99:	ActivateCommand(&SystemMenu, ID_SYSMAXIMIZE);
;
	PUSH	BYTE 028H
	PUSH	EBX
	CALL	_ActivateCommand
	ADD	ESP,BYTE 08H
L_44:
;
; Line 102:	SendMessage(SystemMenuWnd, BUILD_SELECTIONS,
;
	PUSH	BYTE 00H
	MOV	EAX,EBX
	ADD	EAX,BYTE 04H
	PUSH	EAX
	PUSH	BYTE 03EH
	PUSH	EDI
	CALL	_SendMessage
	ADD	ESP,BYTE 010H
;
; Line 104:	SendMessage(SystemMenuWnd, SETFOCUS, TRUE, 0);
;
	PUSH	BYTE 00H
	PUSH	BYTE 01H
	PUSH	BYTE 08H
	PUSH	EDI
	CALL	_SendMessage
	ADD	ESP,BYTE 010H
;
; Line 105:	SendMessage(SystemMenuWnd, SHOW_WINDOW, 0, 0);
;
	PUSH	BYTE 00H
	PUSH	BYTE 00H
	PUSH	BYTE 05H
	PUSH	EDI
	CALL	_SendMessage
	ADD	ESP,BYTE 010H
;
; Line 106:	}
;
L_19:
	POP	EDI
	POP	ESI
	POP	EBX
	MOV	ESP,EBP
	POP	EBP
	RET
SECTION _CONST

SECTION _TEXT
[EXTERN	_MenuHeight]
[EXTERN	_DeactivateCommand]
[EXTERN	_CreateWindow]
[EXTERN	_isEGA]
[EXTERN	_ActiveMenuBar]
[EXTERN	_isVGA]
[EXTERN	_MenuWidth]
[EXTERN	_classdefs]
[EXTERN	_SendMessage]
[EXTERN	_SystemMenu]
[EXTERN	_PostMessage]
[EXTERN	___seg0040]
[EXTERN	_ActivateCommand]
