Subversion Repositories SvarDOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2017 bernd.boec 1
; This file is part of the svarlang project and is distributed onder the
2
; terms of the MIT license
3
;
4
; Copyright (C) 2024 Bernd Boeckmann
5
; 
6
; Permission is hereby granted, free of charge, to any person obtaining a
7
; copy of this software and associated documentation files (the "Software"),
8
; to deal in the Software without restriction, including without limitation
9
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
; and/or sell copies of the Software, and to permit persons to whom the
11
; Software is furnished to do so, subject to the following conditions:
12
; 
13
; The above copyright notice and this permission notice shall be included in
14
; all copies or substantial portions of the Software.
15
; 
16
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
; DEALINGS IN THE SOFTWARE.
23
 
24
	EXTRN svarlang_mem:BYTE;
25
	EXTRN svarlang_dict:WORD;
26
	EXTRN svarlang_memsz:WORD;
27
	EXTRN svarlang_string_count:WORD;
28
 
29
.CODE
30
 
31
	PUBLIC	svarlang_strid
32
	PUBLIC	svarlang_load
33
 
34
;--------------------------------------------------------------------------
35
; svarlang_strid - return translation string identified by id
36
; performs a binary search of svarlang_dict
37
;--------------------------------------------------------------------------
38
; IN:  ax = string id
39
; OUT: ds:si -> string if found, otherwise si = zero
40
;--------------------------------------------------------------------------
41
svarlang_strid PROC
42
	push	bx
43
	push	cx
44
	push	dx
45
 
46
	xor	si,si			; si -> NULL string
47
	mov	cx,OFFSET svarlang_dict	; cx left search bounds into dict
48
	mov	dx,svarlang_string_count
49
	dec	dx
50
	shl	dx,1			; dx = dx * 4, as dict entry is
51
	shl	dx,1			; 4 bytes in size (id, offset)
52
	add	dx,cx			; dx right search bounds into dict
53
@@search:
54
	cmp	dx,cx			; right index < left index?
55
	 jb	@@not_found		;  then string id not found in dict
56
	mov	bx,dx			; bx = right
57
	sub	bx,cx			; bx = right - left
58
	shr	bx,1			; bx = (right - left) / 2
59
	and	bx,not 3		; take care of special case r-l=4
60
	add	bx,cx			; bx = left + (right - left) / 2
61
	cmp	ax,[bx]			; is it the searched dict id?
62
	 je	@@found
63
	 jb	@@below
64
@@above:				; current id is less then the one
65
	mov	cx,bx			; we search, continue search in
66
	add	cx,4			; right interval
67
	jmp	@@search
68
@@below:				; current id is greater than the one
69
	mov	dx,bx			; we search, continue searching left
70
	sub	dx,4			; interval
71
	jmp	@@search
72
@@found:
73
	mov	si,OFFSET svarlang_mem
74
	add	si,[bx+2]		; get string offset
75
@@not_found:
76
	pop	dx
77
	pop	cx
78
	pop	bx
79
	ret
80
svarlang_strid ENDP
81
 
82
;--------------------------------------------------------------------------
83
; svarlang_load - loads lang translations from file
84
;--------------------------------------------------------------------------
85
; IN:  ds:dx -> language file name
86
; OUT: flags: nc on success, cy on failure
87
;--------------------------------------------------------------------------
88
svarlang_load PROC
89
	ret
90
svarlang_load ENDP
91
 
92
	END