Rev 2681 | Rev 5780 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ; |
2 | ; The famous game 15 |
||
3 | ; Author: Lloyd, coded by Ivushkin Andrey |
||
4 | ; Compile with FASM |
||
5 | ; |
||
3484 | fedesco | 6 | |
31 | halyavin | 7 | include 'lang.inc' |
485 | heavyiron | 8 | include '..\..\..\macros.inc' ; decreases program size (not required) |
31 | halyavin | 9 | |
10 | StatusColor equ 0x02ffffff |
||
11 | StatusColor2 equ 0x02dc1e14 |
||
2681 | leency | 12 | BgdColor equ 0x14aabbcc |
31 | halyavin | 13 | |
14 | ; Main window dimensions |
||
15 | XXwindow equ 200 shl 16+276 |
||
16 | YYwindow equ 200 shl 16+300 |
||
17 | ; Status bar |
||
18 | XYstatus equ 35 shl 16+283 |
||
19 | XXbar equ 35 shl 16+136 |
||
20 | YYbar equ 280 shl 16+15 |
||
21 | ; Buttons |
||
22 | BtnTop equ 28 |
||
23 | BtnLeft equ 13 |
||
24 | BtnSize equ 60 |
||
25 | BtnColor equ 0xafbb55 |
||
26 | BtnColor2 equ 0x0228c314 |
||
27 | |||
28 | NumColor equ 0x10000000 |
||
29 | ; Number shifting for nice look |
||
30 | NumShift equ 24 shl 16+27 |
||
31 | NumShift2 equ 4 shl 16 |
||
32 | ; Shuffle button |
||
33 | XXSh equ 202 shl 16+60 |
||
34 | YYSh equ 280 shl 16+12 |
||
35 | XYShText equ 212 shl 16+283 |
||
36 | |||
37 | ; Conf button |
||
38 | XXCnf equ 13 shl 16+13 |
||
39 | YYCnf equ 280 shl 16+12 |
||
40 | XYCnfText equ 18 shl 16+283 |
||
41 | |||
42 | ; Position of the 'hole' |
||
43 | null equ (curconf+16) |
||
44 | ; Amount of moves to perform shuffle |
||
45 | SH_CYCLES equ 400 |
||
46 | ; (Amount of tasks)-1 |
||
47 | CONF_COUNT equ 2 |
||
48 | |||
49 | use32 |
||
50 | |||
51 | org 0x0 |
||
52 | |||
53 | db 'MENUET01' |
||
54 | dd 0x01 |
||
55 | dd START |
||
56 | dd I_END |
||
57 | dd 0x2000 ; 8 Kb |
||
58 | dd 0x2000 |
||
59 | dd 0x0 |
||
60 | dd 0x0 |
||
61 | |||
62 | |||
63 | START: |
||
64 | mov [cptr],CONF_COUNT ; number of task |
||
65 | mov eax,3 |
||
485 | heavyiron | 66 | mcall |
31 | halyavin | 67 | mov cl,16 |
68 | ror eax,cl |
||
69 | mov [generator],eax ; random generator from Tetris |
||
70 | init: |
||
71 | mov ecx,17 |
||
72 | movzx eax,[cptr] |
||
73 | inc eax |
||
74 | cmp eax,CONF_COUNT |
||
75 | jna init_ok |
||
76 | xor eax,eax ; cycling 0..CONF_COUNT |
||
77 | init_ok: |
||
78 | mov [cptr],al |
||
79 | mov esi,eax |
||
80 | shl esi,4 |
||
81 | add esi,conf |
||
82 | add esi,eax |
||
83 | add al,0x31 |
||
2681 | leency | 84 | mov [txtTitle+17],al ;task number to program title |
31 | halyavin | 85 | mov [task],esi |
86 | mov edi,curconf |
||
87 | rep movsb ; initial configuration |
||
88 | |||
89 | mov [sts],4 |
||
90 | jmp red |
||
91 | SHUF: |
||
92 | call shuffle ; immediate shuffle |
||
93 | red: ; window redraw |
||
94 | |||
95 | call draw_window |
||
96 | |||
97 | still: ; MAIN PROGRAM CYCLE |
||
98 | |||
99 | mov eax,10 ; wait for event |
||
485 | heavyiron | 100 | mcall |
31 | halyavin | 101 | |
102 | cmp eax,1 ; redraw? - |
||
103 | je red ; goto red |
||
104 | cmp eax,2 ; key pressed? - |
||
105 | je key ; goto key |
||
106 | cmp eax,3 ; button pressed? - |
||
107 | je button ; goto button |
||
108 | |||
109 | jmp still ; no more events to process |
||
110 | |||
111 | key: ; Key pressed |
||
112 | mov eax,2 |
||
485 | heavyiron | 113 | mcall |
31 | halyavin | 114 | shr eax,8 |
115 | cmp eax,32 ; |
||
116 | je SHUF |
||
117 | cmp eax,13 ; |
||
118 | je init |
||
119 | cmp eax,176 |
||
120 | jl still |
||
121 | sub eax,176 |
||
122 | cmp eax,3 |
||
123 | ja still |
||
124 | movzx eax,byte [eax+correct] ; 'delta' value from correct[] |
||
125 | jmp m_check |
||
126 | |||
127 | button: ; Button pressed |
||
128 | mov eax,17 |
||
485 | heavyiron | 129 | mcall |
31 | halyavin | 130 | shr eax,8 |
131 | sub eax,2 |
||
132 | |||
133 | cmp eax,-1 ; id == 1 (closeme)? |
||
134 | jne noclose |
||
485 | heavyiron | 135 | mcall |
31 | halyavin | 136 | |
137 | noclose: |
||
138 | jl SHUF ; Shuffle (id=0) pressed |
||
139 | cmp eax,18 |
||
140 | je init ; Conf button pressed |
||
141 | sub al,byte [null] |
||
142 | mov edi,correct |
||
143 | mov ecx,4 |
||
144 | repne scasb ; checking for valid move-part 1 |
||
145 | jne fail |
||
146 | m_check: |
||
147 | cmp byte[sts],4 ; puzzle completed, blocking buttons |
||
148 | ja still |
||
149 | call move_check ; checking for valid move-part 2 |
||
150 | jnc fail |
||
151 | inc [move_count] |
||
152 | call draw_moves |
||
153 | fail: |
||
154 | jmp still ; возвращаемся |
||
155 | |||
156 | ; ******************************* |
||
157 | ; ******* WINDOW DRAWING ******* |
||
158 | ; ******************************* |
||
159 | |||
160 | draw_window: |
||
3484 | fedesco | 161 | |
2681 | leency | 162 | mcall 12, 1 ; begin draw |
163 | mcall 0, XXwindow, YYwindow, BgdColor,, txtTitle ; CREATING WINDOW |
||
31 | halyavin | 164 | |
165 | |||
166 | mov eax,8 ; SHUFFLE BUTTON |
||
167 | mov ebx,XXSh |
||
168 | mov ecx,YYSh |
||
169 | xor edx,edx |
||
170 | mov esi,BtnColor |
||
485 | heavyiron | 171 | mcall |
31 | halyavin | 172 | |
173 | mov ebx,XXCnf ; CONF BUTTON |
||
174 | mov ecx,YYCnf |
||
175 | mov edx,20 |
||
2681 | leency | 176 | ;mov esi,BtnColor |
485 | heavyiron | 177 | mcall |
31 | halyavin | 178 | |
179 | mov ebx, XYShText ; SHUFFLE TEXT |
||
180 | mov ecx, StatusColor |
||
181 | mov edx,txtSh |
||
182 | mov esi,lenSh-txtSh |
||
183 | mov eax,4 |
||
485 | heavyiron | 184 | mcall |
31 | halyavin | 185 | |
186 | mov ebx, XYCnfText ; CONF TEXT |
||
187 | mov edx,lenVictory-1 |
||
188 | mov esi,1 |
||
485 | heavyiron | 189 | mcall |
31 | halyavin | 190 | |
191 | mov ecx, 16 ; FIELD BUTTONS |
||
192 | dbut: |
||
193 | call draw_button |
||
194 | loop dbut |
||
195 | |||
196 | call draw_moves |
||
197 | |||
2681 | leency | 198 | mcall 12, 2 ; end of drawing |
31 | halyavin | 199 | ret |
200 | |||
201 | |||
202 | ; ********************************************* |
||
203 | ; ******* DRAWING A FIELD BUTTON ************** |
||
204 | ; ********************************************* |
||
205 | ; ECX - button number |
||
206 | |||
207 | draw_button: |
||
208 | pusha |
||
209 | dec ecx |
||
210 | ; calculating button dimensions |
||
211 | mov edi, ecx |
||
212 | lea edx,[ecx+2] |
||
213 | mov ebx,ecx |
||
214 | and ebx,11b |
||
215 | shr ecx,2 |
||
216 | |||
217 | imul ebx,BtnSize+3 |
||
218 | add ebx,BtnLeft |
||
219 | shl ebx,16 |
||
220 | add ebx,BtnSize |
||
221 | |||
222 | imul ecx,BtnSize+3 |
||
223 | add ecx,BtnTop |
||
224 | shl ecx,16 |
||
225 | add ecx,BtnSize |
||
226 | movzx eax,byte [null] |
||
227 | cmp eax,edi |
||
228 | jne no_hole |
||
229 | |||
230 | pusha |
||
231 | inc ebx |
||
232 | inc ecx |
||
233 | mov edx,BgdColor |
||
234 | mov eax,13 ; clearing - 'hole' |
||
485 | heavyiron | 235 | mcall |
31 | halyavin | 236 | popa |
237 | |||
238 | or edx,0x80000000 ; and removing button under it |
||
239 | no_hole: |
||
240 | mov al,byte[edi+curconf] |
||
241 | mov esi,[task] |
||
242 | cmp al,byte[edi+esi] |
||
243 | je highlight |
||
244 | mov esi,BtnColor |
||
245 | jmp s_rbutton |
||
246 | highlight: |
||
247 | mov esi,BtnColor2 |
||
248 | s_rbutton: |
||
249 | mov eax,8 ; set/remove button |
||
485 | heavyiron | 250 | mcall |