kolibrios/programs/games/sq_game/trunk/SQ_GAME.ASM

247 lines
6.3 KiB
NASM
Raw Normal View History

; SQ_game for MenuetOS
; Author: Alexei Ershov aka ealex
; E-mail: e-al[at]yandex[dot]ru
; Fidonet: 2:469/335.38
; slightly optimized by diamond
; english translation by diamond (two strings in end of source)
BtnSize equ 32 ; ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BtnSpace equ 10 ; <20><EFBFBD><E0AEAC><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
NofBtn equ 4 ; ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD><EFBFBD> (3-15)
Color1 equ 0xcc0000
Color2 equ 0x00cc00
FieldSize = (BtnSize+BtnSpace)*NofBtn + BtnSpace*3
center = FieldSize / 2
use32 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 32-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <><E0A5A6> <20><><EFBFBD><E1A5AC><EFBFBD><EFBFBD><EFBFBD>
org 0x0 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>
db 'MENUET01' ; 8-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4A8AA><EFBFBD><EFBFBD> MenuetOS
dd 0x01 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><EFBFBD><E1A5A3> 1)
dd START ; <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
dd I_END ; ࠧ<><E0A0A7><EFBFBD> <20>ணࠬ<E0AEA3><E0A0AC>
dd 0x1000 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
dd 0x1000 ; <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
dd 0x0 ; <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><E0A0AC>஢ (<28><> <20><EFBFBD><E1AFAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
dd 0x0 ; <20><><EFBFBD>ࢨ஢<E0A2A8><E0AEA2><EFBFBD>
include 'lang.inc'
include 'MACROS.INC' ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><E1A5AC><EFBFBD><EFBFBD><EFBFBD><E9A8AA>!
START:
call Game_Init
red:
call Draw_Window
still:
mcall 10 ; <20><EFBFBD><E3ADAA><EFBFBD> 10 - <20><><EFBFBD><EFBFBD><EFBFBD><><E1AEA1><EFBFBD><EFBFBD>
dec eax
jz red
dec eax
jnz button
key: ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mov al, 2
int 0x40
jmp still
;---------------------------------------------------------------------
button:
mov al, 17 ; 17 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4A8AA><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int 0x40
cmp ah, 1 ; <20><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>஬ 1, <20><><EFBFBD><E5AEA4>
je .exit
cmp ah, 2 ; <20><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2, <20><><EFBFBD><E7A8AD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
je START
; <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
inc dword [moves] ; 㢥<><E3A2A5><EFBFBD><E7A8A2><EFBFBD> <20><>᫮ 室<><E5AEA4>
shr eax, 8 ; <20> eax <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4A8AA><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mov dh, NofBtn
div dh ; al = ax(<28><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) / NofBtn
; ah = <20><><EFBFBD><EFBFBD>⮪ (<28><>. <20><><EFBFBD><EFBFBD>)
mov ebx, eax ; <20><><EFBFBD><EFBFBD><E0A0AD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><20> ebx
; al\ah 0 1 2 3
; +-+ +-+ +-+ +-+
; 1 |4| |5| |6| |7|
; +-+ +-+ +-+ +-+
; +-+ +-+ +-+ +-+
; 2 |8| |9| |10 |11
; +-+ +-+ +-+ +-+
; +-+ +-+ +-+ +-+
; 3 |12 |13 |14 |15
; +-+ +-+ +-+ +-+
; +-+ +-+ +-+ +-+
; 4 |16 |17 |18 |19
; +-+ +-+ +-+ +-+
; <20><><EFBFBD>塞 梥<> <20><EFBFBD><E2AEAB><EFBFBD><EFBFBD>
shr eax, 8 ; eax = ah
mov edi, field
add edi, eax ; edi 㪠<><E3AAA0><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><EFBFBD><E1AAAE><EFBFBD> <20><EFBFBD><E2ABA1>
mov ecx, NofBtn
@@:
not byte[edi] ; <20><><EFBFBD>塞 梥<> <20><> <20><20><EFBFBD><E2AEAB><EFBFBD><EFBFBD>
dec ecx
add edi, NofBtn
test ecx, ecx
jnz @r
; <20><><EFBFBD>塞 梥<> <20><><EFBFBD>
mov eax, ebx ; <20><><EFBFBD><EFBFBD><EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> eax
dec eax
mov dl, NofBtn
mul dl ; ax = al * NofBtn
mov edi, field
add edi, eax ; edi 㪠<><E3AAA0><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><EFBFBD><E1AAAE><EFBFBD> <20><><EFBFBD>
mov ecx, NofBtn
@@:
not byte [edi] ; <20><><EFBFBD>塞 梥<> <20><> <20><20><><EFBFBD>
dec ecx
inc edi
test ecx, ecx
jnz @r
; <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2 ࠧ<> (<28><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><E0A0A1><EFBFBD><EBA2A0> <20><><EFBFBD> <20> <20><EFBFBD><E2AEAB><EFBFBD>),
; <20>.<2E>. <20><><EFBFBD><E2A0AB> <20><><EFBFBD><E0A2AE><EFBFBD><E7A0AB><EFBFBD>
; <20><><EFBFBD>塞 梥<> <20><><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
shr ebx, 8 ; ebx = <20><><EFBFBD><EFBFBD>⮪ (ah <20><> <20><><EFBFBD><EFBFBD>)
not byte [field+eax+ebx]
jmp red
.exit:
mcall -1 ; <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20>ணࠬ<E0AEA3><E0A0AC>
;----------------------------------------------------------------------------
; Draw_Window
;----------------------------------------------------------------------------
Draw_Window:
mcall 12, 1
mcall 0, 200*65536+FieldSize,\
200*65536+FieldSize+20+20+20,\
0x03AABBCC, 0x805080D0, 0x005080D0
mcall 4, 8*65536+8, 0x10DDEEFF, header, header_e - header
mcall 8, BtnSpace*2*65536 + 83,\
(FieldSize+BtnSpace+20)*65536+ 15, 2
mcall 4, (BtnSpace*2+3)*65536+(BtnSize+BtnSpace)*NofBtn+BtnSpace*4+20+4,\
0x10DDEEFF, strNew, strNew_e - strNew
mcall 4, (center - 25) * 65536 + 30, 0, strMovs, strMovs_e - strMovs
mcall 47, 4*65536+1, moves, (center + 2 ) * 65536 + 30, 0
mov ecx, (20+20+BtnSpace-BtnSize)*65536+BtnSize
mov edx, NofBtn ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4A8AA><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
; <20><> <20><><EFBFBD><EFBFBD>
buttons: ; <20><><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD>
mov eax, edx
mov dh, NofBtn
div dh ; al = ax / dh, ah - <20><><EFBFBD><EFBFBD>
mov dh, 0
test ah, ah ; <20>᫨ ah = 0, <20><><EFBFBD><E7A8AD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>
jnz @f
add ecx, (BtnSize+BtnSpace)*65536
mov ebx, BtnSpace*2*65536+BtnSize
@@:
mov esi, Color1 ; <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cmp byte [field-NofBtn+edx], 0 ; field-NofBtn+<2B><><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
jz @f ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><><E6A2A5>
mov esi, Color2
@@:
mcall 8,
add ebx, (BtnSize+BtnSpace)*65536
inc edx ; <20><><EFBFBD><EFBFBD><EFBFBD><E5AEA4> <20><><E1ABA5><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cmp edx, NofBtn*(NofBtn+1)
jb buttons
mcall 12, 2 ; <20><EFBFBD><E3ADAA><EFBFBD> 12: ᮮ<><E1AEAE><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><E1AEA2> <20><><EFBFBD><EFBFBD>
ret
;----------------------------------------------------------------------------
; Game_Init
;----------------------------------------------------------------------------
Game_Init:
and [moves], 0 ; <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⢮ 室<><E5AEA4>
call random ; <20> eax <20><><EFBFBD><EFBFBD><E7A0A9><EFBFBD> <20><>
mov ecx, NofBtn * NofBtn ; <20> ecx <20><><EFBFBD>-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
mov bh, 0 ; <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
; 1 <20><><EFBFBD> <20><> eax, bh - ᪮<>
button_init: ; <20><><EFBFBD><20><EFBFBD><EFBFBD><ECA7AE><EFBFBD><EFBFBD>
shr eax, 1 ; <20><><EFBFBD><EFBFBD><20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> CF
; <20> <20><><EFBFBD><EFBFBD><EFBFBD><E1A8AC><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><E7A5AD>
; <20> bl <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA2A0><EFBFBD><EFBFBD> -1 <20><><EFBFBD> 0
sbb bl, bl
mov [field + ecx - 1], bl
inc bh
cmp bh, 32 ; <20><20><EFBFBD><EFBFBD><ECA7AE><EFBFBD><EFBFBD> <20><><EFBFBD> 32 <20><><EFBFBD><EFBFBD> <20><> eax
jb @f ; <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><E7A0A9><EFBFBD> <20><>
call random
mov bh, 0
@@:
loop button_init
ret
;----------------------------------------------------------------------------
; random - <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
;----------------------------------------------------------------------------
random: mov eax,[generator]
add eax,-43ab45b5h
ror eax,1
xor eax,32c4324fh
ror eax,1
mov [generator],eax
; --- IVAN ---
mov eax,26
mov ebx,9
int 0x40
xor eax,0xdeadbeef
add eax,[generator]
; --- IVAN ---
ret
;============================================================================
field db NofBtn * NofBtn dup(0)
moves dd 0
generator dd 0
if lang eq ru
header db 'Game'
header_e:
strMovs db '<27><><EFBFBD>' ; '<27><><EFBFBD>'
strMovs_e:
strNew db '<27><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>' ; '<27><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'
strNew_e:
else
header db 'Game'
header_e:
strMovs db 'MOVE'
strMovs_e:
strNew db ' New game'
strNew_e:
end if
I_END: ; <20><><20><><EFBFBD><EFBFBD><EFBFBD> <20>ணࠬ<E0AEA3><E0A0AC>