diff --git a/programs/games/solitare/solitare.asm b/programs/games/solitare/solitare.asm index f6b898858..8da904563 100644 --- a/programs/games/solitare/solitare.asm +++ b/programs/games/solitare/solitare.asm @@ -1,6 +1,7 @@ -; Solitare V1.5.1 - KOSfuncs Edition +; Solitare V1.5.2 ; Platform: KolibriOS / MenuetOS -; Author: Max +; Author: Max (Refactored/Fixed) +; Scoring Fix: Cards only give points ONCE, even if moved back and forth. format binary as 'run' use32 @@ -30,8 +31,8 @@ COL_SLOT equ 0x185018 CARD_STRUCT_SIZE equ 12 CARD_VALUE equ 0 CARD_SUIT equ 1 -CARD_STATE equ 2 -CARD_LOC equ 3 +CARD_STATE equ 2 ; Bit 0: Face-up, Bit 7: Already Scored +CARD_LOC equ 3 ; 0-6: Tableau, 7: Stock, 8: Foundation, 9: Waste CARD_X equ 4 CARD_Y equ 6 CARD_OLD_X equ 8 @@ -55,7 +56,7 @@ dd 0, 0 start: mov esp, stacktop - ; Get skin height using KOSfuncs constant + ; Get system skin height mcall SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT mov [skin_h], eax @@ -67,16 +68,16 @@ start: event_loop: mcall SF_CHECK_EVENT - cmp eax, 1 ; Redraw + cmp eax, 1 ; Redraw event je on_redraw - cmp eax, 2 ; Key + cmp eax, 2 ; Key event je on_key - cmp eax, 3 ; Button + cmp eax, 3 ; Button event je on_button call handle_mouse - ; Logic for active card movement or forced update + ; Update display if dragging or forced cmp dword [active_card_count], 0 ja update_screen_only cmp byte [force_redraw], 1 @@ -92,25 +93,18 @@ on_key: on_button: mcall SF_GET_BUTTON shr eax, 8 - cmp eax, 1 ; Close button ID + cmp eax, 1 ; Window close button jne event_loop mcall SF_TERMINATE_PROCESS on_redraw: mcall SF_REDRAW, SSF_BEGIN_DRAW - - ; EBX: Window position and width mov ebx, 100 shl 16 + (WIN_W + 9) - - ; ECX: Window position and height mov eax, [skin_h] add eax, WIN_H + 5 mov ecx, 100 shl 16 mov cx, ax - - ; Draw window with skin flag mcall SF_CREATE_WINDOW, , , 0x14000000 or COL_TABLE, , title - mcall SF_REDRAW, SSF_END_DRAW mov byte [force_redraw], 1 jmp update_screen_only @@ -118,11 +112,8 @@ on_redraw: update_screen_only: mov byte [force_redraw], 0 call prepare_buffer - - ; EDX: coordinates for blit mov edx, 4 shl 16 add dx, word [skin_h] - mcall SF_PUT_IMAGE, screen_buffer, WIN_W shl 16 + WIN_H, edx jmp event_loop @@ -133,14 +124,14 @@ handle_mouse: mcall SF_MOUSE_GET, SSF_WINDOW_POSITION mov ebp, eax shr ebp, 16 - sub ebp, 5 ; X correction + sub ebp, 5 ; Mouse X correction and eax, 0xFFFF sub eax, [skin_h] - mov edi, eax ; EDI = Mouse Y relative to workspace + mov edi, eax ; Mouse Y in workspace mcall SF_MOUSE_GET, SSF_BUTTON - test eax, 1 ; Check Left Button + test eax, 1 ; Left click? jnz .dragging_state cmp dword [mouse_lock], 1 @@ -160,7 +151,7 @@ handle_mouse: cmp dword [mouse_lock], 1 je .no_deal_click - ; Stock pile click detection + ; Stock pile interaction cmp ebp, STOCK_X jb .find_card cmp ebp, STOCK_X+CARD_W @@ -195,8 +186,8 @@ handle_mouse: cmp edi, ecx jae .next_s - cmp byte [edx+CARD_STATE], 1 - jne .next_s + test byte [edx+CARD_STATE], 1 ; Is card face up? + jz .next_s mov dword [mouse_lock], 1 mov [active_stack], ebx @@ -317,8 +308,8 @@ draw_card_to_buffer: mov edi, CARD_W-2 mov ebp, CARD_H-2 call fill_rect_buf - cmp byte [esi+CARD_STATE], 1 - je .face_up + test byte [esi+CARD_STATE], 1 + jnz .face_up add ebx, 4 add ecx, 4 mov edx, COL_REVERSE @@ -781,7 +772,12 @@ check_stack_move: popad ret .found_match: + ; FIXED SCORING: Check Bit 7 of STATE (Scored flag) + test byte [esi+CARD_STATE], 0x80 + jnz .already_scored add dword [score], 10 + or byte [esi+CARD_STATE], 0x80 ; Set Scored Flag +.already_scored: mov word [esi+CARD_X], bx mov word [esi+CARD_Y], FOUND_Y mov byte [esi+CARD_LOC], 8 @@ -953,7 +949,7 @@ auto_reveal_all: jl .find_lowest cmp dword [temp_val], -1 je .next_col - mov byte [esi+CARD_STATE], 1 + or byte [esi+CARD_STATE], 1 ; Reveal face up .next_col: add ebx, 100 cmp ebx, 740 @@ -995,15 +991,10 @@ deal_from_stock: add esi, deck_data cmp byte [esi+CARD_LOC], 7 jne .n - cmp byte [esi+CARD_STATE], 0 - je .o -.n: dec ecx - jns .f - call reset_stock - popad - ret + test byte [esi+CARD_STATE], 1 ; Already visible? + jnz .n .o: - mov byte [esi+CARD_STATE], 1 + or byte [esi+CARD_STATE], 1 mov byte [esi+CARD_LOC], 9 mov word [esi+CARD_X], WASTE_X mov word [esi+CARD_Y], FOUND_Y @@ -1011,6 +1002,11 @@ deal_from_stock: call move_single_to_top popad ret +.n: dec ecx + jns .f + call reset_stock + popad + ret reset_stock: sub dword [score], 20 @@ -1020,7 +1016,7 @@ reset_stock: add esi, deck_data cmp byte [esi+CARD_LOC], 9 jne .s - mov byte [esi+CARD_STATE], 0 + and byte [esi+CARD_STATE], 0xFE ; Set face down mov byte [esi+CARD_LOC], 7 mov word [esi+CARD_X], STOCK_X mov word [esi+CARD_Y], FOUND_Y @@ -1036,7 +1032,7 @@ init_deck: .r: inc ebx mov byte [edi+CARD_VALUE], bl mov byte [edi+CARD_SUIT], al - mov byte [edi+CARD_STATE], 0 + mov byte [edi+CARD_STATE], 0 ; Face down, Not Scored mov byte [edi+CARD_LOC], 7 add edi, CARD_STRUCT_SIZE cmp ebx, 13 @@ -1087,10 +1083,10 @@ layout_tableau: mov byte [edi+CARD_LOC], dl dec ebp jnz .h - mov byte [edi+CARD_STATE], 1 + or byte [edi+CARD_STATE], 1 ; Top card face up jmp .nx .h: - mov byte [edi+CARD_STATE], 0 + and byte [edi+CARD_STATE], 0xFE ; Other cards face down .nx: add edi, CARD_STRUCT_SIZE add ecx, STACK_OFFSET @@ -1110,13 +1106,13 @@ layout_tableau: mov word [edi+CARD_X], STOCK_X mov word [edi+CARD_Y], FOUND_Y mov byte [edi+CARD_LOC], 7 - mov byte [edi+CARD_STATE], 0 + and byte [edi+CARD_STATE], 0xFE add edi, CARD_STRUCT_SIZE jmp .sf .fin: ret ; --- DATA & FONTS --- -title db 'Solitare V1.5.1', 0 +title db 'Solitare V1.5.2', 0 score dd 0 game_won db 0 mouse_lock dd 0 @@ -1133,6 +1129,7 @@ active_stack rd 13 skin_h dd 0 font_8x12: +; S, C, O, R, E, -, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 db 01111100b,10000010b,10000000b,10000000b,01111100b,00000010b,00000010b,10000010b,01111100b,00000000b,00000000b,00000000b ; S db 01111100b,10000010b,10000000b,10000000b,10000000b,10000000b,10000000b,10000010b,01111100b,00000000b,00000000b,00000000b ; C db 01111100b,10000010b,10000010b,10000010b,10000010b,10000010b,10000010b,10000010b,01111100b,00000000b,00000000b,00000000b ; O @@ -1151,6 +1148,7 @@ db 01111100b,10000010b,10000010b,10000010b,01111100b,10000010b,10000010b,1000001 db 01111100b,10000010b,10000010b,10000010b,10000010b,01111110b,00000010b,10000010b,01111100b,00000000b,00000000b,00000000b ; 9 font_5x7: +; A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, Hearts, Diamonds, Clubs, Spades db 01110000b,10001000b,10001000b,11111000b,10001000b,10001000b,10001000b ; A db 11110000b,00001000b,00010000b,00100000b,01000000b,10000000b,11111000b ; 2 db 11110000b,00001000b,00001000b,01110000b,00001000b,00001000b,11110000b ; 3