Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1805 | yogev_ezra | 1 | macro CODE_SECTION |
2 | |||
3 | { |
||
4 | ;+-----------------------------------+ Uses:eax,ebx,edx |
||
5 | ;|-------Random Number Generator-----|---------------------------| |
||
6 | ;+-----------------------------------+ |
||
7 | rndseed: ; |
||
8 | mov eax,26 ; func 26 subfunc 9 |
||
9 | mov ebx,9 ; |
||
10 | int 0x40 ; |
||
11 | mov dword[seed],eax ; system time from boot |
||
12 | random9: ; RND=[0..9] |
||
13 | mov eax,3 ; |
||
14 | int 0x40 ; get current time |
||
15 | shr eax,16 ; seconds in al |
||
16 | add eax,dword[seed] ; |
||
17 | imul eax,0x15a4e35 ; random formula rv=rv*0x15a4e35+1 |
||
18 | inc eax ; return (rv&0x7FFFFFFF)%N |
||
19 | mov dword[seed],eax ; |
||
20 | and eax,0x07FFFFFFF ; |
||
21 | mov ebx,10 ; N=10 |
||
22 | xor edx,edx ; |
||
23 | div bx ; eax/ebx= int[result]+rest |
||
24 | add dl,'0' ; DL='0'..'9' - rest |
||
25 | ret ; |
||
26 | ;================================================= |
||
27 | rnew: ; New Random Secret Number |
||
28 | xor esi,esi ;---------------------------- |
||
29 | LoopBegin lb1,0 ; |
||
30 | rn: call random9 ; DL=RND('0'..'9') |
||
31 | xor edi,edi ; |
||
32 | lb2: cmp byte[nA+edi],dl ; |
||
33 | je rn ; |
||
34 | inc edi ; |
||
35 | cmp edi,4 ; 4 digit |
||
36 | jne lb2 ; |
||
37 | mov byte[nA+esi],dl ;nA - secret number without double digits |
||
38 | inc esi ;nA - 4 bytes of non-repeated digits '0'..'9' |
||
39 | LoopEnd lb1,4 ; |
||
40 | ret ; |
||
41 | ;------------------------------------- |
||
42 | numStr: inc dword[turn] ; turn++ |
||
43 | mov ebx,dword[turn] ; |
||
44 | push ebx ; |
||
45 | pop ecx ; ebx=ecx=turn |
||
46 | add cl,'0' ; |
||
47 | add ch,':' ; |
||
48 | dec ebx ; -1 |
||
49 | shl ebx,4 ; *16 |
||
50 | mov word[tStr+ebx],cx; begin string by turn number +':' |
||
51 | ret |
||
52 | ;------------------------------------- |
||
53 | paint_list: |
||
54 | LoopBegin lbList,0 |
||
55 | mov ebx,ecx |
||
56 | shl ebx,4 ; *16 |
||
57 | mov edx,tStr |
||
58 | add edx,ebx |
||
59 | add ebx,25*65536 ;x |
||
60 | add ebx,45 ;y |
||
61 | mov eax,4 ;func 4 |
||
62 | mov ecx,cTxt ;color |
||
63 | mov esi,16 ;line length |
||
64 | int 0x40 |
||
65 | LoopEnd lbList,9 ; |
||
66 | ret |
||
67 | ;-INPUT------------------------------------ KEYBOARD INPUT ----------- |
||
68 | input: ;ah - key code |
||
69 | mov byte[char],ah ;char<-ah |
||
70 | cmp ah,13 ;13- enter |
||
71 | jne @f |
||
72 | jmp _enter |
||
73 | @@: |
||
74 | cmp ah,8 ;8 - del backSpace <=| |
||
75 | jne @f |
||
76 | jmp _back |
||
77 | @@: |
||
78 | |||
79 | cmp ah,'0' ; '0'..'9' |
||
80 | jae @f |
||
81 | ret |
||
82 | @@: cmp ah,'9' |
||
83 | jbe @f |
||
84 | ret ; if not - return subroutine |
||
85 | @@: |
||
86 | ;------------------------pressed:0123456789----------- |
||
87 | cmp byte[posn],4 |
||
88 | je @f ;full line - do nothing |
||
89 | call ptrStr ;esi - pointer at tStr |
||
90 | xor eax,eax |
||
91 | add al,byte[posn] |
||
92 | add esi,eax ;+posn |
||
93 | mov al,byte[char] |
||
94 | mov byte[esi+3],al ;esi+3 = place 4 digits |
||
95 | inc byte[posn] ;next digit |
||
96 | @@: ret |
||
97 | ;------------------------ |
||
98 | _enter: |
||
99 | cmp byte[posn],4 ; Enter Turn |
||
100 | je @f |
||
101 | ret |
||
102 | @@: |
||
103 | call check ; check input for difference |
||
104 | cmp eax,0 |
||
105 | je @f |
||
106 | ret |
||
107 | @@: |
||
108 | call bcalculate ; calc b+c |
||
109 | call numStr ; 'N:' next string number |
||
110 | mov byte[posn],0 ; new line |
||
111 | ret |
||
112 | ;------------------------ |
||
113 | _back: cmp byte[posn],0 ; empty input - do nothing |
||
114 | je @f |
||
115 | dec byte[posn] |
||
116 | call ptrStr ;esi = pointer at tStr |
||
117 | xor eax,eax |
||
118 | add al,byte[posn] ; byte of esi +posn |
||
119 | add esi,eax ;+posn |
||
120 | mov byte[esi+3],' ' |
||
121 | @@: ret |
||
122 | ;===========================================--end - input - |
||
123 | ptrStr: ; esi=tStr+turn*16 |
||
124 | mov esi,dword[turn] |
||
125 | shl esi,4 |
||
126 | add esi,tStr |
||
127 | ret |
||
128 | ;------------------------ |
||
129 | clears: mov ecx,160 |
||
130 | clr1: mov byte[tStr+ecx],0;' ' |
||
131 | loop clr1 |
||
132 | mov byte[tStr],0;' ' |
||
133 | mov byte[posn],0 |
||
134 | mov dword[turn],0 |
||
135 | ret |
||
136 | ;-------------------------CHECK---Input--[1234]------- |
||
137 | check: ; check for similar digits (equal) |
||
138 | call ptrStr ; esi ...pointer |
||
139 | ;mov esi,dword[turn] |
||
140 | ;shl esi,4 |
||
141 | ;add esi,tStr |
||
142 | xor eax,eax |
||
143 | xor edi,edi ; edi - counter 0..3 |
||
144 | xor ecx,ecx |
||
145 | lb4ch: mov dl,byte[esi+ecx+3] |
||
146 | cmp byte[esi+edi+3],dl |
||
147 | jne @f |
||
148 | inc eax ; =equivalent +1 |
||
149 | @@: |
||
150 | inc edi ; |
||
151 | cmp edi,4 ; cycle ,4 digits |
||
152 | jne lb4ch ; |
||
153 | xor edi,edi ; edi - counter 0..3 |
||
154 | |||
155 | inc ecx |
||
156 | cmp ecx,4 |
||
157 | jne lb4ch |
||
158 | |||
159 | sub eax,4 ; must be 4, if more - doubles present |
||
160 | ret |
||
161 | |||
162 | bcalculate: ;------------------; calc b:+c: |
||
163 | call ptrStr ; esi ... |
||
164 | add esi,3 |
||
165 | ;inc esi |
||
166 | ;inc esi ;+3 |
||
167 | ;inc esi ; ...- pointer to Line |
||
168 | LoopBegin lbBu1,0 ;bull count cycle ecx=0..3 |
||
169 | mov bl,byte[nA+ecx] |
||
170 | mov dl,byte[esi+ecx] |
||
171 | cmp bl,dl |
||
172 | jne @f |
||
173 | inc byte[nBul] |
||
174 | @@: |
||
175 | LoopEnd lbBu1,4 |
||
176 | |||
177 | mov ax,'B:' ; output Bulls |
||
178 | mov word[esi+6],ax |
||
179 | mov al,byte[nBul] |
||
180 | add al,'0' |
||
181 | mov byte[esi+8],al |
||
182 | |||
183 | LoopBegin lbCo2,0 ;Cows count cycle ecx=0..3 |
||
184 | mov dl,byte[esi+ecx] |
||
185 | xor edi,edi ; cycle edi=0..3 |
||
186 | lb3: mov bl,byte[nA+edi] |
||
187 | cmp bl,dl |
||
188 | jne @f |
||
189 | inc byte[nCow] ;Cows+Bulls |
||
190 | @@: inc edi ; |
||
191 | cmp edi,4 ; |
||
192 | jne lb3 ; |
||
193 | LoopEnd lbCo2,4 ;endcycle ecx |
||
194 | |||
195 | mov ax,'C:' ; output Cows |
||
196 | mov word[esi+10],ax |
||
197 | mov al,byte[nCow] |
||
198 | sub al,byte[nBul] |
||
199 | add al,'0' |
||
200 | mov byte[esi+12],al |
||
201 | mov dword[nBul],0 ;nCow=posn=char=0 |
||
202 | ret |
||
203 | ;-------------------------------------- |
||
204 | }=| |
||
205 |