;
;		ish file converter for MS-DOS  Ver 2.00 (90/3/27)
;
;
;		Copyright (c) 1986, 1987, 1989, 1990  by  M. ishizuka
;		All rights reserved.
;



;-----------------------------------------------;
;						;
;	@@get_tz				;
;						;
;	INPUT :	NON				;
;	OUTPUT:	NON				;
;	ERROR :	_error_40, error_41		;
;	BREAK : flags, ax, cx, dx, si, di	;
;						;
;-----------------------------------------------;

@@get_tz	macro
		mov	si, offset tz
		call	search_env
		jnz	get_tz_5
		mov	cx, 3
get_tz_1:	lodsb
		or	al, al
		jz	_error_40
		loop	get_tz_1
		lodsb
		cmp	al, '-'
		pushf
		jz	get_tz_1_1
		cmp	al, '+'
		jnz	get_tz_2
get_tz_1_1:	lodsb
get_tz_2:	sub	al, '0'
		mov	ah, al
		mov	al, 0
		jc	get_tz_3
		cmp	ah, 10
		jnc	get_tz_3
		lodsb
		sub	al, '0'
		xchg	ah, al
		jc	get_tz_3
		cmp	ah, 10
		jnc	get_tz_3
		add	al, al
		add	ah, al
		add	al, al
		add	al, al
		add	al, ah
get_tz_3:	popf
		jnz	get_tz_4
		neg	al
get_tz_4:	cbw
		mov	si, es
		mov	ds, si
		mov	dx, 3600d
		imul	dx
		mov	word ptr tz_low, ax
		mov	word ptr tz_high, dx
		mov	byte ptr tz_avail, 0ffh
get_tz_5:	mov	si, es
		mov	ds, si
		mov	si, offset ishtz
		call	search_env
		jnz	get_tz_6
		mov	ax, 3d00h
		mov	dx, si
		int	21h
		mov	si, es
		mov	ds, si
		jc	error_41
		mov	word ptr tz_handler, ax
get_tz_6:	mov	si, es
		mov	ds, si
		endm



;-----------------------------------------------;
;						;
;	@@set_difference_of_time		;
;						;
;	INPUT :	NON				;
;	OUTPUT:	NON				;
;	ERROR :	error_42			;
;	BREAK : flags, ax, bx, cx, dx, si, di	;
;						;
;-----------------------------------------------;

@@set_difference_of_time	macro
		mov	bx, word ptr tz_handler
		or	bx, bx
		jz	set_difference_of_time_6
		mov	ax, 4200h
		xor	cx, cx
		xor	dx, dx
		int	21h			; rewind
		jc	error_42
		mov	word ptr tag_work, 0
set_difference_of_time_0:
		call	skip_cr_lf
		jc	set_difference_of_time_6
		cmp	al, 1ah
		jz	set_difference_of_time_6
		call	get_num2		; year high
		cbw
		mov	cx, ax
		call	get_num2		; year low
		cbw
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	ax, cx
		cmp	ax, 2100d
		jnc	error_42
		sub	ax, 1980d
		jc	error_42
		mov	dh, al
		mov	cl, '-'
		call	get_and_check
		call	get_num2		; month
		cmp	al, 13d
		jnc	error_42
		shl	al, 1
		shl	al, 1
		shl	al, 1
		shl	al, 1
		mov	dl, al
		shl	dx, 1
		call	get_and_check
		call	get_num2		; date
		cmp	al, 32d
		jnc	error_42
		or	dl, al
		mov	di, dx
		call	get_and_check
		call	get_num2		; hour
		cmp	al, 24d
		jnc	error_42
		mov	dh, al
		mov	cl, ':'
		call	get_and_check
		call	get_num2		; minite
		cmp	al, 60d
		jnc	error_42
		shl	al, 1
		shl	al, 1
		mov	dl, al
		shl	dx, 1
		shl	dx, 1
		shl	dx, 1
		call	get_and_check
		call	get_num2		; second
		cmp	al, 60d
		jnc	error_42
		shr	al, 1
		or	dl, al
		cmp	di, word ptr work_table[29]
		jc	set_difference_of_time_1
		jnz	set_difference_of_time_5
		cmp	dx, word ptr work_table[27]
		jnbe	set_difference_of_time_5
set_difference_of_time_1:
		call	skip_space2
		call	get_num2		; year high
		cbw
		mov	cx, ax
		call	get_num2		; year low
		cbw
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	ax, cx
		cmp	ax, 2100d
		jnc	error_42
		sub	ax, 1980d
		jc	error_42
		mov	dh, al
		mov	cl, '-'
		call	get_and_check
		call	get_num2		; month
		cmp	al, 13d
		jnc	error_42
		shl	al, 1
		shl	al, 1
		shl	al, 1
		shl	al, 1
		mov	dl, al
		shl	dx, 1
		call	get_and_check
		call	get_num2		; date
		cmp	al, 32d
		jnc	error_42
		or	dl, al
		mov	di, dx
		call	get_and_check
		call	get_num2		; hour
		cmp	al, 24d
		jnc	error_42
		mov	dh, al
		mov	cl, ':'
		call	get_and_check
		call	get_num2		; minite
		cmp	al, 60d
		jnc	error_42
		shl	al, 1
		shl	al, 1
		mov	dl, al
		shl	dx, 1
		shl	dx, 1
		shl	dx, 1
		call	get_and_check
		call	get_num2		; second
		cmp	al, 60d
		jnc	error_42
		shr	al, 1
		or	dl, al
		cmp	word ptr work_table[29], di
		jc	set_difference_of_time_2
		jnz	set_difference_of_time_5
		cmp	word ptr work_table[27], dx
		jnbe	set_difference_of_time_5
set_difference_of_time_2:
		call	skip_space2
		call	get_para_char
		jc	error_42
		cmp	al, '-'
		pushf
		jz	set_difference_of_time_3
		cmp	al, '+'
		jz	set_difference_of_time_3
		dec	si
set_difference_of_time_3:
		call	get_num2		; hour
		mov	cx, 60d*256d + ':'
		mul	ch
		mov	dx, ax
		call	get_and_check
		call	get_num2		; minite
		cbw
		add	dx, ax
		call	get_and_check
		call	get_num2		; second
		cbw
		mov	cx, ax
		mov	ax, 60
		mul	dx
		add	ax, cx
		adc	dx, 0
		popf
		jnz	set_difference_of_time_7
		not	ax
		not	dx
		add	ax, 1
		adc	dx, 0
		jmp	set_difference_of_time_7

set_difference_of_time_5:
		call	skip_to_cr_lf
		jnc	set_difference_of_time_0
set_difference_of_time_6:
		cmp	byte ptr tz_avail, 0
		jz	set_difference_of_time_8
		mov	ax, word ptr tz_low
		mov	dl, byte ptr tz_high
set_difference_of_time_7:
		mov	word ptr work_table[31], ax
		mov	byte ptr work_table[33], dl
		or	byte ptr work_table[26], 2
set_difference_of_time_8:
		endm



;-----------------------------------------------;
;						;
;	@@set_local_time			;
;						;
;	INPUT :	ax (difference of time low)	;
;		dx (difference of time high)	;
;	OUTPUT:	NON				;
;	ERROR :	NON				;
;	BREAK : flags, ax, bx, cx, dx, si	;
;						;
;-----------------------------------------------;

@@set_local_time	macro
		not	ax
		not	dx
		add	ax, 1
		adc	dx, 0
		mov	si, offset utc
		call	local_time_to_utc
		mov	ax, word ptr utc
		mov	dx, word ptr utc[2]
		mov	cx, 60d
		div	cx
		div	cl
		xchg	ah, al
		shl	al, 1
		shl	al, 1
		shl	ax, 1
		shl	ax, 1
		shl	ax, 1
		shr	dl, 1
		or	al, dl
		mov	word ptr save_time, ax
		mov	ax, word ptr utc[4]
		add	ax, 101h
		mov	dx, word ptr utc[6]
		cmp	dx, 2099d
		jnbe	set_local_time_0
		sub	dx, 1980d
		jc	set_local_time_1
		xchg	al, dl
		xchg	ah, al
		shl	al, 1
		shl	al, 1
		shl	al, 1
		shl	al, 1
		shl	ax, 1
		or	al, dl
		jmp	set_local_time_2

set_local_time_0:
		mov	word ptr save_time, 0bd7dh	; 23:59:59
		mov	ax, 0ef9fh			; 2099-12-31
		jmp	set_local_time_1

set_local_time_1:
		mov	word ptr save_time, 0		; 00:00:00
		mov	ax, 21h				; 1980-01-01
set_local_time_2:
		mov	word ptr save_date, ax
		endm



;-----------------------------------------------;
;						;
;	@@get_local_time			;
;						;
;	INPUT :	NON				;
;	OUTPUT:	NON				;
;	ERROR :	error_42			;
;	BREAK : flags, ax, bx, cx, dx, si, di	;
;						;
;-----------------------------------------------;

@@get_local_time	macro
		mov	al, byte ptr date_time_flag
		and	al, 3
		cmp	al, 3
		jnz	get_local_time_10
		cmp	word ptr save_date, 0
		jz	get_local_time_10
		call	set_utc
		mov	bx, word ptr tz_handler
		or	bx, bx
		jz	get_local_time_8
		mov	ax, 4200h
		xor	cx, cx
		xor	dx, dx
		int	21h			; rewind
		jc	error_42
		mov	word ptr tag_work, 0
get_local_time_0:
		call	skip_cr_lf
		jc	get_local_time_8
		cmp	al, 1ah
		jz	get_local_time_8
		call	get_num2		; year high
		cbw
		mov	cx, ax
		call	get_num2		; year low
		cbw
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	ax, cx
		cmp	ax, 2100d
		jnc	error_42
		cmp	ax, 1980d
		jc	error_42
		mov	word ptr local_time_work[6], ax
		mov	cl, '-'
		call	get_and_check
		call	get_num2		; month
		dec	al
		cmp	al, 12d
		jnc	error_42
		mov	byte ptr local_time_work[5], al
		call	get_and_check
		call	get_num2		; date
		dec	al
		cmp	al, 31d
		jnc	error_42
		mov	byte ptr local_time_work[4], al
		call	get_and_check
		call	get_num2		; hour
		cmp	al, 24d
		jnc	error_42
		mov	cx, 60d*256d + ':'
		mul	ch
		mov	dx, ax
		call	get_and_check
		call	get_num2		; minite
		cmp	al, 60d
		jnc	error_42
		cbw
		add	dx, ax
		call	get_and_check
		call	get_num2		; second
		cmp	al, 60d
		jnc	error_42
		cbw
		mov	cx, ax
		mov	ax, 60d
		mul	dx
		add	ax, cx
		adc	dx, 0
		mov	word ptr local_time_work, ax
		mov	word ptr local_time_work[2], dx
		call	skip_space2
		call	get_num2		; year high
		cbw
		mov	cx, ax
		call	get_num2		; year low
		cbw
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	cx, cx
		add	cx, cx
		add	ax, cx
		add	cx, cx
		add	ax, cx
		cmp	ax, 2100d
		jnc	error_42
		cmp	ax, 1980d
		jc	error_42
		mov	word ptr local_time_work[14], ax
		mov	cl, '-'
		call	get_and_check
		call	get_num2		; month
		dec	al
		cmp	al, 12d
		jnc	error_42
		mov	byte ptr local_time_work[13], al
		call	get_and_check
		call	get_num2		; date
		dec	al
		cmp	al, 31d
		jnc	error_42
		mov	byte ptr local_time_work[12], al
		call	get_and_check
		call	get_num2		; hour
		cmp	al, 24d
		jnc	error_42
		mov	cx, 60d*256d + ':'
		mul	ch
		mov	dx, ax
		call	get_and_check
		call	get_num2		; minite
		cmp	al, 60d
		jnc	error_42
		cbw
		add	dx, ax
		call	get_and_check
		call	get_num2		; second
		cmp	al, 60d
		jnc	error_42
		cbw
		mov	cx, ax
		mov	ax, 60d
		mul	dx
		add	ax, cx
		adc	dx, 0
		mov	word ptr local_time_work[8], ax
		mov	word ptr local_time_work[10], dx
		call	skip_space2
		call	get_para_char
		jc	error_42
		cmp	al, '-'
		pushf
		jz	get_local_time_3
		cmp	al, '+'
		jz	get_local_time_3
		dec	si
get_local_time_3:
		call	get_num2		; hour
		mov	cx, 60d*256d + ':'
		mul	ch
		mov	dx, ax
		call	get_and_check
		call	get_num2		; minite
		cbw
		add	dx, ax
		call	get_and_check
		call	get_num2		; second
		cbw
		mov	cx, ax
		mov	ax, 60d
		mul	dx
		add	ax, cx
		adc	dx, 0
		popf
		jnz	get_local_time_4
		not	ax
		not	dx
		add	ax, 1
		adc	dx, 0
get_local_time_4:
		mov	word ptr local_time_work[16], ax
		mov	word ptr local_time_work[18], dx
		push	si
		mov	si, offset local_time_work[0]
		push	bx
		call	local_time_to_utc
		pop	bx
		pop	si
		mov	ax, word ptr local_time_work[6]
		cmp	ax, word ptr utc[6]
		jc	get_local_time_5
		jnz	get_local_time_7
		mov	ax, word ptr local_time_work[4]
		cmp	ax, word ptr utc[4]
		jc	get_local_time_5
		jnz	get_local_time_7
		mov	ax, word ptr local_time_work[2]
		cmp	ax, word ptr utc[2]
		jc	get_local_time_5
		jnz	get_local_time_7
		mov	ax, word ptr local_time_work
		cmp	ax, word ptr utc
		jnbe	get_local_time_7
get_local_time_5:
		mov	ax, word ptr local_time_work[16]
		mov	dx, word ptr local_time_work[18]
		push	si
		mov	si, offset local_time_work[8]
		push	bx
		call	local_time_to_utc
		pop	bx
		pop	si
		mov	ax, word ptr utc[6]
		cmp	ax, word ptr local_time_work[14]
		jc	get_local_time_6
		jnz	get_local_time_7
		mov	ax, word ptr utc[4]
		cmp	ax, word ptr local_time_work[12]
		jc	get_local_time_6
		jnz	get_local_time_7
		mov	ax, word ptr utc[2]
		cmp	ax, word ptr local_time_work[10]
		jc	get_local_time_6
		jnz	get_local_time_7
		mov	ax, word ptr utc
		cmp	ax, word ptr local_time_work[8]
		jnbe	get_local_time_7
get_local_time_6:
		mov	ax, word ptr local_time_work[16]
		mov	dx, word ptr local_time_work[18]
		jmp	get_local_time_9

get_local_time_7:
		call	skip_to_cr_lf
		jnc	get_local_time_0
get_local_time_8:
		cmp	byte ptr tz_avail, 0
		jz	get_local_time_10
		mov	ax, word ptr tz_low
		mov	dx, word ptr tz_high
get_local_time_9:
		@@set_local_time
get_local_time_10:
		endm
