;----------------------------------------------------------------------------
	IFNE	NEW_crew_rules
;----------------------------------------------------------------------------
crewfix6_mod_beg:
pay_wages:				;originally L7ED02
	lea 	$337C(a6),a0	;4	;a0 -> employees.crew_list
	move 	(a0)+,d2	;2	;d2 = employees  a0 -> crew_list
	beq.s	pay_wages_RTS	;2	;if no employees, go RTS
	movem 	d0-d1,-(sp)	;4	;push d0/d1
;-------
	moveq	#20,d1		;2	;d1 = 20,  listed employees
	sub	d1,d2		;2	;d2 = employees-20,  unlisted_employees
	bhs.s	.calc_wages	;2	;if positive, go calc wages
	add	d2,d1		;2	;d1 = employees,  listed_employees
	clr	d2		;2	;d2 = 0,  unlisted_employees
.calc_wages:
	moveq	#$00,d6		;2	;d6 = 0  total_wages
	move	d1,d0		;2	;d0 = listed_employees
	subq 	#1,d1		;2	;d1 = listed_employees-1
L7ED14:					;loop start
	add	4(a0),d6	;4	;total_wages += employee wage
	addq	#6,a0		;2	;a0 -> next employee
	dbra	d1,L7ED14	;4	;loop back for each listed employee
;-------
	move.l	d6,d5		;2	;d5 = d6,  listed_wages
	mulu	d2,d5		;2	;d5 = unlisted_employees * listed_wages
	divu	d0,d5		;2	;d5 = unlisted_employees * average_wage
	add	d0,d6		;2	;d6 = total wages
;-------
	add.l	$33F6(a6),d6	;4	;d6 = wages + crewdebt
	move.l	$02DE(a6),d0	;4	;d0 = money
	clr.l	d5		;2	;d5 = 0  as crewdebt if payment succeeds
	sub.l	d6,d0		;2	;d0 = money - (wages + crewdebt)
	bpl.s	.store_result	;2	;on payment success, go store results
	swap	d5		;2	;d0 = 0  d5 = negative diff
	neg	d5		;2	;d5 = positive diff
.store_result:
	move.l	d0,$02DE(a6)	;4	;money = remaining money
	move.l	d5,$3FF6(a6)	;4	;crewdebt = remaining crewdebt
L7ED54:
	tst.b	$0082(a6)	;4
	beq.s	L7ED62		;2
	move.b	$3278(a6),d0	;4
	bsr.w	L7E2EE		;4
L7ED62:
	movem 	(sp)+,d0-d1	;4
pay_wages_RTS:
	rts			;2
;-------------------------------------
;Partial byte count of pay_wages	;92
;-------------------------------------
;----------------------------------------------------------------------------
;Block start was pay_wages, originally at L7ED02
;Next label was originally L7ED68
;Original byte count  = 102
;Reused byte count    =  92
;remaining byte count = 010
;-------------------------------------
crewfix6_mod_end:
crewfix6_mod_size	= (crewfix6_mod_end-crewfix6_mod_beg)
	sz_pad	crewfix6,102,crewfix6_mod_size
;-------------------------------------
;Next label is L7ED68
;----------------------------------------------------------------------------
	ELSE
;----------------------------------------------------------------------------
pay_wages:				;originally L7ED02
	move 	$337C(a6),d2		;d2 = employees
	beq.s	L7ED00			;if no employees, go RTS
	movem 	d0-d1,-(sp)		;push d0/d1
	lea 	$337E(a6),a0		;a0 -> crew_list
	moveq	#$00,d6			;d6 = 0  total_wages
	subq 	#1,d2			;d2 = employees-1
L7ED14:					;loop start
	movem 	(a0)+,d3-d5		;d3-d5 = employee
	add.l	d5,d6			;total_wages += employee wage
	dbra	d2,L7ED14		;loop back for each employee
	sub.l	d6,$02DE(a6)		;money -= total_wages
	bcc.s	L7ED32			;negative result ?
	move.l	$02DE(a6),d6		;d6 = money
	neg.l	d6
	add.l	d6,$33F6(a6)		;crewdebt += d6
	clr.l	$02DE(a6)		;money = 0
L7ED32:	move.l	$33F6(a6),d0		;d0 = crewdebt
	beq.s	L7ED54			;any crewdebt ?
	move.l	$02DE(a6),d1		;d1 = money
	beq.s	L7ED54			;any money ?
	cmp.l	d0,d1			;money < crewdebt ?
	bcc.s	L7ED4C			;if not, go pay entire crewdebt
	sub.l	d0,$33F6(a6)		;crewdebt -= crewdebt BUG
	clr.l	$02DE(a6)		;money = 0
	bra.s	L7ED54

L7ED4C:	sub.l	d0,$02DE(a6)		;money -= crewdebt
	clr.l	$33F6(a6)		;crewdebt = 0
L7ED54:	tst.b	$0082(a6)
	beq.s	L7ED62
	move.b	$3278(a6),d0
	bsr.w	L7E2EE
L7ED62:	movem 	(sp)+,d0-d1
	rts
;-------------------------------------
;Next label is L7ED68
;----------------------------------------------------------------------------
	ENDC
;----------------------------------------------------------------------------
