diff --git a/data/Tupfile.lua b/data/Tupfile.lua index d621b0e2a..4a6e32f65 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -498,6 +498,7 @@ tup.append_table(img_files, { {"GAMES/SW", VAR_PROGS .. "/games/sw/sw"}, {"GAMES/TANKS", VAR_PROGS .. "/games/tanks/tanks"}, {"GAMES/TETRIS", VAR_PROGS .. "/games/tetris/tetris"}, + {"GAMES/C4", VAR_PROGS .. "/games/c4/c4"}, {"LIB/ARCHIVER.OBJ", VAR_PROGS .. "/fs/kfar/trunk/kfar_arc/kfar_arc.obj"}, {"LIB/BOX_LIB.OBJ", VAR_PROGS .. "/develop/libraries/box_lib/trunk/box_lib.obj"}, {"LIB/BUF2D.OBJ", VAR_PROGS .. "/develop/libraries/buf2d/trunk/buf2d.obj"}, @@ -648,7 +649,6 @@ tup.append_table(img_files, { {"TINFO", VAR_PROGS .. "/system/tinfo/tinfo"}, {"DEVELOP/MSTATE", VAR_PROGS .. "/develop/mstate/mstate"}, {"DEVELOP/GENFILES", VAR_PROGS .. "/testing/genfiles/GenFiles"}, - {"GAMES/C4", VAR_PROGS .. "/games/c4/c4"}, {"MEDIA/FILLSCR", VAR_PROGS .. "/media/FillScr/fillscr"}, }) tup.append_table(extra_files, { diff --git a/programs/games/c4/Tupfile.lua b/programs/games/c4/Tupfile.lua index 7d087b234..a31601da4 100644 --- a/programs/games/c4/Tupfile.lua +++ b/programs/games/c4/Tupfile.lua @@ -1,7 +1,7 @@ -if tup.getconfig("NO_NASM") ~= "" then return end --- tup.rule is too unmannerly to %define -tup.definerule{ - command = "echo %%define lang '" .. ((tup.getconfig("LANG") == "") and "en_US" or tup.getconfig("LANG")) .. "'> %o", - outputs = {"lang_nasm.inc"} -} -tup.rule({"c4.asm", extra_inputs = {"lang_nasm.inc"}}, "nasm -I" .. tup.getvariantdir() .. "/ -f bin -o %o %f " .. tup.getconfig("KPACK_CMD"), "c4") +if tup.getconfig("NO_FASM") ~= "" then return end +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") +tup.include(HELPERDIR .. "/use_fasm.lua") +add_include(tup.getvariantdir()) + +tup.rule("echo lang fix " .. ((tup.getconfig("LANG") == "") and "en_US" or tup.getconfig("LANG")) .. " > %o", {"lang.inc"}) +tup.rule({"c4.asm", extra_inputs = {"lang.inc"}}, FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "c4") diff --git a/programs/games/c4/ai.inc b/programs/games/c4/ai.inc index 517bb2328..61f84cc5d 100644 --- a/programs/games/c4/ai.inc +++ b/programs/games/c4/ai.inc @@ -18,16 +18,11 @@ ; along with C4; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -%ifndef _AI_INC -%define _AI_INC - INFTY equ 1000000000 - section .data - ; table used to perform some primitive move "ordering": ; middle columns which are usually more important are ; searched first. @@ -46,18 +41,10 @@ evaltable: dd 0, 0, 0, 0, 0, 0, 0, 0, 0 dd 0, 0, 0, 0, 0, 0, 0, 0, 0 - - section .bss - -cpulevel resd 1 ; level of current cpu player -bestval resd 1 ; value of best move found so far -nbestmoves resd 1 ; # of best moves found so far -bestmoves resd 7 ; array to hold all best moves - - - - section .text - +cpulevel rd 1 ; level of current cpu player +bestval rd 1 ; value of best move found so far +nbestmoves rd 1 ; # of best moves found so far +bestmoves rd 7 ; array to hold all best moves ;********************************************************** @@ -148,15 +135,16 @@ aiGetMove: ; output : eax = move value ; destroys : everything ;********************************************************** +align 4 alphabeta: -%define ply (ebp+20) -%define player (ebp+16) -%define alpha (ebp+12) -%define beta (ebp+ 8) - - enter 0,0 +ply equ (ebp+20) +player equ (ebp+16) +alpha equ (ebp+12) +beta equ (ebp+ 8) + push ebp + mov ebp,esp ; win for other player -> end search mov eax,[player] BOARDGETOTHERPLAYER eax @@ -262,9 +250,8 @@ alphabeta: leave ; eax contains static value ret 4*4 -%undef ply -%undef player -%undef alpha -%undef beta +purge ply +purge player +purge alpha +purge beta -%endif diff --git a/programs/games/c4/board.inc b/programs/games/c4/board.inc index 6bf1ccd2b..dffea64de 100644 --- a/programs/games/c4/board.inc +++ b/programs/games/c4/board.inc @@ -18,9 +18,6 @@ ; along with C4; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -%ifndef _BOARD_INC -%define _BOARD_INC - ;********************************************************** ; magic numbers @@ -36,27 +33,15 @@ BHEIGHT equ 8 -;********************************************************** -; uninitialized data -;********************************************************** - - section .bss - -board resd BHEIGHT*BWIDTH ; the board -free resd BWIDTH ; # of free fields for each column -totalfree resd 1 ; total # of free fields -currentplayer resd 1 ; player to make next move -lastmove resd 1 ; last move done on the board +board rd BHEIGHT*BWIDTH ; the board +free rd BWIDTH ; # of free fields for each column +totalfree rd 1 ; total # of free fields +currentplayer rd 1 ; player to make next move +lastmove rd 1 ; last move done on the board ; (0 if no last move available) -;********************************************************** -; code -;********************************************************** - - section .text - ;********************************************************** ; boardReset @@ -102,9 +87,9 @@ boardReset: ; zero flag clear -> move is valid ; destroys : nothing ;********************************************************** -%macro BOARDISVALIDMOVE 1 - cmp dword [free+%1*4],0 -%endmacro +macro BOARDISVALIDMOVE p1 { + cmp dword [free+p1*4],0 +} @@ -160,9 +145,9 @@ boardUndoMove: ; output : current player is switched ; destroys : flags ;********************************************************** -%macro BOARDSWITCHPLAYERS 0 - xor dword [currentplayer],(PLAYER1 ^ PLAYER2) -%endmacro +macro BOARDSWITCHPLAYERS { + xor dword [currentplayer],(PLAYER1 xor PLAYER2) +} @@ -174,9 +159,9 @@ boardUndoMove: ; output : player changed ; destroys : flags ;********************************************************** -%macro BOARDGETOTHERPLAYER 1 - xor %1,(PLAYER1 ^ PLAYER2) -%endmacro +macro BOARDGETOTHERPLAYER r1 { + xor r1,(PLAYER1 xor PLAYER2) +} @@ -188,9 +173,9 @@ boardUndoMove: ; output : zero flag set -> board is full ; zero flag clear -> board isn't full ;********************************************************** -%macro BOARDISFULL 0 +macro BOARDISFULL { cmp dword [totalfree],0 -%endmacro +} @@ -313,6 +298,3 @@ boardIsWin: ; no win for this player xor eax,eax ret - - -%endif \ No newline at end of file diff --git a/programs/games/c4/build.bat b/programs/games/c4/build.bat deleted file mode 100644 index eb2e7b3c7..000000000 --- a/programs/games/c4/build.bat +++ /dev/null @@ -1,2 +0,0 @@ -@nasmw -f bin -o c4 c4.asm -@pause \ No newline at end of file diff --git a/programs/games/c4/build_en.bat b/programs/games/c4/build_en.bat new file mode 100644 index 000000000..aeaf367d6 --- /dev/null +++ b/programs/games/c4/build_en.bat @@ -0,0 +1,4 @@ +@echo lang fix en_EN >lang.inc +@fasm.exe -m 16384 c4.asm c4.kex +@kpack c4.kex +pause diff --git a/programs/games/c4/build_ru.bat b/programs/games/c4/build_ru.bat new file mode 100644 index 000000000..3fdd81844 --- /dev/null +++ b/programs/games/c4/build_ru.bat @@ -0,0 +1,4 @@ +@echo lang fix ru_RU >lang.inc +@fasm.exe -m 16384 c4.asm c4.kex +@kpack c4.kex +pause diff --git a/programs/games/c4/c4.asm b/programs/games/c4/c4.asm index e130210b5..b13b8b2b8 100644 --- a/programs/games/c4/c4.asm +++ b/programs/games/c4/c4.asm @@ -18,14 +18,15 @@ ; along with C4; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - bits 32 - %include 'mos.inc' - section .text - %include 'lang_nasm.inc' ;fedesco - - - MOS_HEADER01 start,end +use32 + org 0 + db 'MENUET01' + dd 1,start,i_end,mem,stacktop,0,0 +include '../../macros.inc' +include '../../proc32.inc' +include '../../KOSfuncs.inc' +include 'lang.inc' ;fedesco ;********************************************************** @@ -46,11 +47,20 @@ BUTTON_HEIGHT equ 12 BUTTON_NEW_X equ 14 BUTTON_NEW_Y equ 30 -%ifidn lang, 'it_IT' - BUTTON_NEW_WIDTH equ 56 + 28 -%else - BUTTON_NEW_WIDTH equ 56 -%endif +BUTTON_NEW_HEIGHT equ 32 +if lang eq it_IT + BUTTON_NEW_WIDTH = 56 + 28 + LABEL_PL1_X = 90 + 10 + LABEL_PL1TYPE_X = (LABEL_PL1_X + 10*6 - 4) +else if lang eq ru_RU + BUTTON_NEW_WIDTH = 56 + 12 + LABEL_PL1_X = 90 + LABEL_PL1TYPE_X = (LABEL_PL1_X + 10*6) +else + BUTTON_NEW_WIDTH = 56 + LABEL_PL1_X = 90 + LABEL_PL1TYPE_X = (LABEL_PL1_X + 10*6) +end if BUTTON_SPIN_WIDTH equ 8 BUTTON_PL1DN_X equ 228 @@ -64,19 +74,9 @@ BUTTON_PL2UP_X equ (BUTTON_PL2DN_X + BUTTON_SPIN_WIDTH + 1) BUTTON_PL2UP_Y equ BUTTON_PL2DN_Y ; label dimensions -%ifidn lang, 'it_IT' - LABEL_PL1_X equ 90 + 10 -%else - LABEL_PL1_X equ 90 -%endif LABEL_PL1_Y equ (1 + BUTTON_PL1DN_Y + (BUTTON_HEIGHT-8)/2) LABEL_PL2_X equ LABEL_PL1_X LABEL_PL2_Y equ (1 + BUTTON_PL2DN_Y + (BUTTON_HEIGHT-8)/2) -%ifidn lang, 'it_IT' - LABEL_PL1TYPE_X equ (LABEL_PL1_X + 10*6 - 4) -%else - LABEL_PL1TYPE_X equ (LABEL_PL1_X + 10*6) -%endif LABEL_PL1TYPE_Y equ LABEL_PL1_Y LABEL_PL2TYPE_X equ LABEL_PL1TYPE_X LABEL_PL2TYPE_Y equ LABEL_PL2_Y @@ -94,9 +94,7 @@ GRIDY equ 70 GRIDSPACING equ (STONESIZE + 1) ; space between lines GRIDHEIGHT equ (6*GRIDSPACING+1) ; total grid width and height GRIDWIDTH equ (7*GRIDSPACING+1) -GRIDCOLOR equ MOS_RGB(128,128,128) - - +GRIDCOLOR equ 0x808080 ; button id's BT_QUIT equ 1 @@ -106,55 +104,170 @@ BT_PLAYER1UP equ 4 BT_PLAYER2DN equ 5 BT_PLAYER2UP equ 6 +include "pcx.inc" +include "windows.inc" +include "board.inc" +include "rng.inc" +;include "randomai.inc" +include "ai.inc" +; +; label table +; + +if lang eq it_IT + newgame db "Nuova partita",0 + down db "<",0 + up db ">",0 + pl1 db "Giocatore 1:",0 + pl2 db "Giocatore 2:",0 + + playertypes: + db "Umano ",0 + .e1: + db "CPU 1 ",0 + db "CPU 2 ",0 + db "CPU 3 ",0 + db "CPU 4 ",0 + db "CPU 5 ",0 + db "CPU 6 ",0 + db "CPU 7 ",0 + db "CPU 8 ",0 +else if lang eq ru_RU + newgame db "Новая игра",0 + down db "<",0 + up db ">",0 + pl1 db "Игрок 1:",0 + pl2 db "Игрок 2:",0 + + playertypes: + db "Человек ",0 + .e1: + db "Процессор 1 ",0 + db "Процессор 2 ",0 + db "Процессор 3 ",0 + db "Процессор 4 ",0 + db "Процессор 5 ",0 + db "Процессор 6 ",0 + db "Процессор 7 ",0 + db "Процессор 8 ",0 +else + newgame db "New game",0 + down db "<",0 + up db ">",0 + pl1 db "Player 1:",0 + pl2 db "Player 2:",0 + + playertypes: + db "Human ",0 + .e1: + db "CPU level 1 ",0 + db "CPU level 2 ",0 + db "CPU level 3 ",0 + db "CPU level 4 ",0 + db "CPU level 5 ",0 + db "CPU level 6 ",0 + db "CPU level 7 ",0 + db "CPU level 8 ",0 +end if +playertypes_end: + +PLAYERTYPELEN equ (playertypes.e1 - playertypes) +NPLAYERTYPES equ ((playertypes_end-playertypes)/PLAYERTYPELEN) + +; +; button table +; +align 4 +buttons: +; new +BUTTON (BUTTON_NEW_X shl 16) + BUTTON_NEW_WIDTH, (BUTTON_NEW_Y shl 16) + BUTTON_NEW_HEIGHT, BT_NEW, BUTTON_COLOR_WORK +; player 1 down +BUTTON (BUTTON_PL1DN_X shl 16) + BUTTON_SPIN_WIDTH, (BUTTON_PL1DN_Y shl 16) + BUTTON_HEIGHT, BT_PLAYER1DN, BUTTON_COLOR_WORK +; player 1 up +BUTTON (BUTTON_PL1UP_X shl 16) + BUTTON_SPIN_WIDTH, (BUTTON_PL1UP_Y shl 16) + BUTTON_HEIGHT, BT_PLAYER1UP, BUTTON_COLOR_WORK +; player 2 down +BUTTON (BUTTON_PL2DN_X shl 16) + BUTTON_SPIN_WIDTH, (BUTTON_PL2DN_Y shl 16) + BUTTON_HEIGHT, BT_PLAYER2DN, BUTTON_COLOR_WORK +; player 2 up +BUTTON (BUTTON_PL2UP_X shl 16) + BUTTON_SPIN_WIDTH, (BUTTON_PL2UP_Y shl 16) + BUTTON_HEIGHT, BT_PLAYER2UP, BUTTON_COLOR_WORK +buttons_end: + +NBUTTONS equ ((buttons_end-buttons)/sizeof.BUTTON) + +align 4 +labels: +; new +LABEL ((BUTTON_NEW_X+4) shl 16) + (1+BUTTON_NEW_Y+(BUTTON_NEW_HEIGHT-8)/2), newgame,LABEL_COLOR_WORKBUTTON,LABEL_BGCOLOR_TRANSPARENT +; player 1 down +LABEL ((BUTTON_PL1DN_X+(BUTTON_SPIN_WIDTH-4)/2) shl 16) + (1+BUTTON_PL1DN_Y+(BUTTON_HEIGHT-8)/2), down,LABEL_COLOR_WORKBUTTON,LABEL_BGCOLOR_TRANSPARENT +; player 1 up +LABEL ((1+BUTTON_PL1UP_X+(BUTTON_SPIN_WIDTH-4)/2) shl 16) + (1+BUTTON_PL1UP_Y+(BUTTON_HEIGHT-8)/2), up,LABEL_COLOR_WORKBUTTON,LABEL_BGCOLOR_TRANSPARENT +; player 2 down +LABEL ((BUTTON_PL2DN_X+(BUTTON_SPIN_WIDTH-4)/2) shl 16) + (1+BUTTON_PL2DN_Y+(BUTTON_HEIGHT-8)/2), down,LABEL_COLOR_WORKBUTTON,LABEL_BGCOLOR_TRANSPARENT +; player 2 up +LABEL ((1+BUTTON_PL2UP_X+(BUTTON_SPIN_WIDTH-4)/2) shl 16) + (1+BUTTON_PL2UP_Y+(BUTTON_HEIGHT-8)/2), up,LABEL_COLOR_WORKBUTTON,LABEL_BGCOLOR_TRANSPARENT +; player 1 +LABEL (LABEL_PL1_X shl 16) + LABEL_PL1_Y, pl1,0xffffff,LABEL_BGCOLOR_TRANSPARENT +; player 2 +LABEL (LABEL_PL2_X shl 16) + LABEL_PL2_Y, pl2,0xffffff,LABEL_BGCOLOR_TRANSPARENT +; status bar +statusbar LABEL (LABEL_STATUS_X shl 16) + LABEL_STATUS_Y, 0,0xffffff,LABEL_BGCOLOR_TRANSPARENT + +if lang eq it_IT +label_pl1type LABEL ((LABEL_PL1TYPE_X + 18) shl 16) + LABEL_PL1TYPE_Y, playertypes+PL1TYPE_INIT*PLAYERTYPELEN,0xffffff,0 +label_pl2type LABEL ((LABEL_PL2TYPE_X + 18) shl 16) + LABEL_PL2TYPE_Y, playertypes+PL2TYPE_INIT*PLAYERTYPELEN,0xffffff,0 +else +label_pl1type LABEL (LABEL_PL1TYPE_X shl 16) + LABEL_PL1TYPE_Y, playertypes+PL1TYPE_INIT*PLAYERTYPELEN,0xffffff,0 +label_pl2type LABEL (LABEL_PL2TYPE_X shl 16) + LABEL_PL2TYPE_Y, playertypes+PL2TYPE_INIT*PLAYERTYPELEN,0xffffff,0 +end if +labels_end: + +NLABELS equ ((labels_end-labels)/sizeof.LABEL) + + +; button images +redpcx: +file "red.pcx" +REDPCXSIZE equ (bluepcx - redpcx) +bluepcx: +file "blue.pcx" +pcx_end: +BLUEPCXSIZE equ (pcx_end - bluepcx) + + +align 4 start: - jmp main - -%include "pcx.inc" -%include "windows.inc" -%include "board.inc" -%include "rng.inc" -; %include "randomai.inc" -%include "ai.inc" - - - -;********************************************************** -; main program -;********************************************************** -main: call randomize call defineWindow call decrunchImages call newGame +align 16 .msgpump: ; wait for event - mov ebx,1 - mov eax,MOS_SC_WAITEVENTTIMEOUT - int 0x40 + mcall SF_WAIT_EVENT_TIMEOUT,1 ; process events - cmp eax,MOS_EVT_REDRAW - je short .redraw - cmp eax,MOS_EVT_KEY - je short .key - cmp eax,MOS_EVT_BUTTON - je short .button + cmp eax,EV_REDRAW + je .redraw + cmp eax,EV_KEY + je .key + cmp eax,EV_BUTTON + je .button call pollMouse call gameLoop - jmp short .msgpump + jmp .msgpump .redraw: call defineWindow - jmp short .msgpump + jmp .msgpump .key: call keyboardInput - jmp short .msgpump + jmp .msgpump .button: call handleButton - jmp short .msgpump + jmp .msgpump @@ -162,28 +275,27 @@ main: ; button handling function ;********************************************************** handleButton: - mov eax,MOS_SC_GETPRESSEDBUTTON ; get button id - int 0x40 + mcall SF_GET_BUTTON ; get button id cmp al,1 ; button pressed ? - je short .bye ; nope -> nothing to do + je .bye ; nope -> nothing to do cmp ah,BT_QUIT ; which button has been pressed ? - je short .quit + je .quit cmp ah,BT_NEW - je short .new + je .new cmp ah,BT_PLAYER1DN - je short .player1dn + je .player1dn cmp ah,BT_PLAYER1UP - je short .player1up + je .player1up cmp ah,BT_PLAYER2DN - je short .player2dn + je .player2dn cmp ah,BT_PLAYER2UP - je short .player2up + je .player2up .bye: ret .quit: - MOS_EXIT + mcall SF_TERMINATE_PROCESS .new: call newGame ret @@ -234,7 +346,7 @@ handleButton: ; window definition function ;********************************************************** defineWindow: - MOS_STARTREDRAW + mcall SF_REDRAW,SSF_BEGIN_DRAW mov edi,window call drawWindow @@ -250,7 +362,7 @@ defineWindow: xor eax,eax call drawBoard - MOS_ENDREDRAW + mcall SF_REDRAW,SSF_END_DRAW ret @@ -270,11 +382,10 @@ updateStatusText: mov dword [statusbar + LABEL.caption],esi ; yeah -> save & redraw ; clear background - mov ebx,MOS_DWORD(LABEL_STATUS_X,LABEL_STATUS_WIDTH) - mov ecx,MOS_DWORD(LABEL_STATUS_Y,LABEL_STATUS_HEIGHT) + mov ebx, LABEL_STATUS_X shl 16 + LABEL_STATUS_WIDTH + mov ecx, LABEL_STATUS_Y shl 16 + LABEL_STATUS_HEIGHT xor edx,edx - mov eax,MOS_SC_DRAWBAR - int 0x40 + mcall SF_DRAW_RECT ; redraw label mov edi,statusbar @@ -310,50 +421,50 @@ updatePlayerType: ; draw whole board ; ; input : eax nonzero = clear board background +align 4 drawBoard: ; clear background ? or eax,eax jz .noclear - mov ebx,MOS_DWORD(GRIDX,GRIDWIDTH) - mov ecx,MOS_DWORD(GRIDY,GRIDHEIGHT) + mov ebx, GRIDX shl 16 + GRIDWIDTH + mov ecx, GRIDY shl 16 + GRIDHEIGHT mov edx,WND_WORKCOLOR - mov eax,MOS_SC_DRAWBAR - int 0x40 + mcall SF_DRAW_RECT .noclear: call drawGrid call drawStones ret - +align 4 drawGrid: ; vertical lines - mov ebx,MOS_DWORD(GRIDX,GRIDX) - mov ecx,MOS_DWORD(GRIDY,GRIDY+GRIDHEIGHT-1) + mov ebx, GRIDX shl 16 + GRIDX + mov ecx, GRIDY shl 16 + GRIDY+GRIDHEIGHT-1 mov edx,GRIDCOLOR - mov eax,MOS_SC_DRAWLINE + mcall SF_DRAW_LINE mov esi,8 .vlines: int 0x40 - add ebx,MOS_DWORD(GRIDSPACING,GRIDSPACING) + add ebx, GRIDSPACING shl 16 + GRIDSPACING dec esi jnz .vlines ; horizontal lines - mov ebx,MOS_DWORD(GRIDX,GRIDX+GRIDWIDTH-1) - mov ecx,MOS_DWORD(GRIDY,GRIDY) + mov ebx, GRIDX shl 16 + GRIDX+GRIDWIDTH-1 + mov ecx, GRIDY shl 16 + GRIDY mov esi,7 .hlines: int 0x40 - add ecx,MOS_DWORD(GRIDSPACING,GRIDSPACING) + add ecx, GRIDSPACING shl 16 + GRIDSPACING dec esi jnz .hlines ret - +align 4 drawStones: mov ebx,6 .col: @@ -369,6 +480,7 @@ drawStones: ; ecx = column (1..7) ; ebx = row (1..6) +align 4 drawStone: pushad @@ -402,9 +514,8 @@ drawStone: ; put image (position is already in edx) mov ebx,ebp ; image address - mov ecx,MOS_DWORD(STONESIZE,STONESIZE) ; image dimensions - mov eax,MOS_SC_PUTIMAGE - int 0x40 + mov ecx, (STONESIZE shl 16) + STONESIZE ; image dimensions + mcall SF_PUT_IMAGE .bye: popad @@ -461,9 +572,8 @@ newGame: ; destroys : everything ;********************************************************** pollMouse: - mov ebx,2 - mov eax,MOS_SC_GETMOUSEPOSITION - int 0x40 + mcall SF_MOUSE_GET,SSF_BUTTON + and eax,1 jz .mousenotpressed .mousepressed: @@ -502,10 +612,8 @@ pollMouse: ; destroys : everything ;********************************************************** getMouseCol: - - mov ebx,1 ; get mouse position, window relative - mov eax,MOS_SC_GETMOUSEPOSITION - int 0x40 + + mcall SF_MOUSE_GET,SSF_WINDOW_POSITION ; get mouse position, window relative movzx ebx,ax ; y clipping cmp ebx,GRIDY @@ -539,24 +647,15 @@ getMouseCol: ; destroys : everything ;********************************************************** isActiveApp: - -%define PROCINFO (ebp-MOS_PROCESSINFO_size) - - enter MOS_PROCESSINFO_size,0 - ; get process information - mov eax,MOS_SC_GETPROCESSINFO - lea ebx,[ebp-MOS_PROCESSINFO_size] - mov ecx,-1 - int 0x40 + mcall SF_THREAD_INFO,procinfo,-1 ; set al to 1 if we are the active application - cmp ax,[PROCINFO+MOS_PROCESSINFO.windowStackPos] + cmp ax,[procinfo+process_information.window_stack_position] sete al - leave + ;;;leave ret -%undef PROCINFO @@ -569,8 +668,7 @@ isActiveApp: ; destroys : everything ;********************************************************** keyboardInput: - mov eax,MOS_SC_GETKEY ; get key - int 0x40 + mcall SF_GET_KEY ; get key or al,al ; key available ? jnz .bye ; no -> bye cmp dword [playerinput],0 ; unprocessed input available ? @@ -698,7 +796,7 @@ updatePlayerStatusText: cmp dword [player1_type],0 je .statustextok mov esi,player1cpuprmpt - jmp short .statustextok + jmp .statustextok .player2: mov esi,player2hmnprmpt cmp dword [player2_type],0 @@ -714,196 +812,11 @@ updatePlayerStatusText: ; initialized data ;********************************************************** - section .data - ; ; window definition ; windowtitle db "C4",0 -window: -istruc WND - at WND.xposandsize, dd MOS_DWORD(0,WND_WIDTH) - at WND.yposandsize, dd MOS_DWORD(0,WND_HEIGHT) - at WND.workcolor, dd 0x14000000 | WND_WORKCOLOR - at WND.grabcolor, dd 0 - at WND.framecolor, dd 0 - at WND.caption, dd windowtitle - at WND.captioncolor, dd 0 - at WND.flags, dd WND_CENTER | WND_DEFAULT_GRABCOLOR | WND_DEFAULT_FRAMECOLOR | WND_DEFAULT_CAPTIONCOLOR -iend - -; -; button table -; -buttons: -istruc BUTTON ; new - at BUTTON.xposandsize - dd MOS_DWORD(BUTTON_NEW_X,BUTTON_NEW_WIDTH) - dd MOS_DWORD(BUTTON_NEW_Y,BUTTON_HEIGHT) - dd BT_NEW - dd BUTTON_COLOR_WORK -iend -istruc BUTTON ; player 1 down - at BUTTON.xposandsize - dd MOS_DWORD(BUTTON_PL1DN_X,BUTTON_SPIN_WIDTH) - dd MOS_DWORD(BUTTON_PL1DN_Y,BUTTON_HEIGHT) - dd BT_PLAYER1DN - dd BUTTON_COLOR_WORK -iend -istruc BUTTON ; player 1 up - at BUTTON.xposandsize - dd MOS_DWORD(BUTTON_PL1UP_X,BUTTON_SPIN_WIDTH) - dd MOS_DWORD(BUTTON_PL1UP_Y,BUTTON_HEIGHT) - dd BT_PLAYER1UP - dd BUTTON_COLOR_WORK -iend -istruc BUTTON ; player 2 down - at BUTTON.xposandsize - dd MOS_DWORD(BUTTON_PL2DN_X,BUTTON_SPIN_WIDTH) - dd MOS_DWORD(BUTTON_PL2DN_Y,BUTTON_HEIGHT) - dd BT_PLAYER2DN - dd BUTTON_COLOR_WORK -iend -istruc BUTTON ; player 2 up - at BUTTON.xposandsize - dd MOS_DWORD(BUTTON_PL2UP_X,BUTTON_SPIN_WIDTH) - dd MOS_DWORD(BUTTON_PL2UP_Y,BUTTON_HEIGHT) - dd BT_PLAYER2UP - dd BUTTON_COLOR_WORK -iend -NBUTTONS equ (($-buttons)/BUTTON_size) - - -; -; label table -; -%ifidn lang, 'it_IT' - newgame db "Nuova partita",0 -%else - newgame db "New game",0 -%endif -down db "<",0 -up db ">",0 -%ifidn lang, 'it_IT' - pl1 db "Giocatore 1:",0 - pl2 db "Giocatore 2:",0 -%else - pl1 db "Player 1:",0 - pl2 db "Player 2:",0 -%endif - -%ifidn lang, 'it_IT' - playertypes: - db "Umano",0 - PLAYERTYPELEN equ ($ - playertypes) - db "CPU 1 ",0 - db "CPU 2 ",0 - db "CPU 3 ",0 - db "CPU 4 ",0 - db "CPU 5 ",0 - db "CPU 6 ",0 - db "CPU 7 ",0 - db "CPU 8 ",0 -%else - playertypes: - db "Human ",0 - PLAYERTYPELEN equ ($ - playertypes) - db "CPU level 1 ",0 - db "CPU level 2 ",0 - db "CPU level 3 ",0 - db "CPU level 4 ",0 - db "CPU level 5 ",0 - db "CPU level 6 ",0 - db "CPU level 7 ",0 - db "CPU level 8 ",0 -%endif - -NPLAYERTYPES equ (($-playertypes)/PLAYERTYPELEN) - - -labels: -istruc LABEL ; new - at LABEL.position - dd MOS_DWORD(BUTTON_NEW_X+4,1+BUTTON_NEW_Y+(BUTTON_HEIGHT-8)/2) - dd newgame - dd LABEL_COLOR_WORKBUTTON - dd LABEL_BGCOLOR_TRANSPARENT -iend -istruc LABEL ; player 1 down - at LABEL.position - dd MOS_DWORD(BUTTON_PL1DN_X+(BUTTON_SPIN_WIDTH-4)/2,1+BUTTON_PL1DN_Y+(BUTTON_HEIGHT-8)/2) - dd down - dd LABEL_COLOR_WORKBUTTON - dd LABEL_BGCOLOR_TRANSPARENT -iend -istruc LABEL ; player 1 up - at LABEL.position - dd MOS_DWORD(1+BUTTON_PL1UP_X+(BUTTON_SPIN_WIDTH-4)/2,1+BUTTON_PL1UP_Y+(BUTTON_HEIGHT-8)/2) - dd up - dd LABEL_COLOR_WORKBUTTON - dd LABEL_BGCOLOR_TRANSPARENT -iend -istruc LABEL ; player 2 down - at LABEL.position - dd MOS_DWORD(BUTTON_PL2DN_X+(BUTTON_SPIN_WIDTH-4)/2,1+BUTTON_PL2DN_Y+(BUTTON_HEIGHT-8)/2) - dd down - dd LABEL_COLOR_WORKBUTTON - dd LABEL_BGCOLOR_TRANSPARENT -iend -istruc LABEL ; player 2 up - at LABEL.position - dd MOS_DWORD(1+BUTTON_PL2UP_X+(BUTTON_SPIN_WIDTH-4)/2,1+BUTTON_PL2UP_Y+(BUTTON_HEIGHT-8)/2) - dd up - dd LABEL_COLOR_WORKBUTTON - dd LABEL_BGCOLOR_TRANSPARENT -iend -istruc LABEL ; player 1 - at LABEL.position - dd MOS_DWORD(LABEL_PL1_X,LABEL_PL1_Y) - dd pl1 - dd MOS_RGB(255,255,255) - dd LABEL_BGCOLOR_TRANSPARENT -iend -istruc LABEL ; player 2 - at LABEL.position - dd MOS_DWORD(LABEL_PL2_X,LABEL_PL2_Y) - dd pl2 - dd MOS_RGB(255,255,255) - dd LABEL_BGCOLOR_TRANSPARENT -iend -statusbar: ; status bar -istruc LABEL - at LABEL.position - dd MOS_DWORD(LABEL_STATUS_X,LABEL_STATUS_Y) - dd 0 - dd MOS_RGB(255,255,255) - dd LABEL_BGCOLOR_TRANSPARENT -iend -label_pl1type: -istruc LABEL - at LABEL.position - %ifidn lang, 'it_IT' - dd MOS_DWORD(LABEL_PL1TYPE_X + 18,LABEL_PL1TYPE_Y) - %else - dd MOS_DWORD(LABEL_PL1TYPE_X,LABEL_PL1TYPE_Y) - %endif - dd playertypes+PL1TYPE_INIT*PLAYERTYPELEN - dd MOS_RGB(255,255,255) - dd MOS_RGB(0,0,0) -iend -label_pl2type: -istruc LABEL - at LABEL.position - %ifidn lang, 'it_IT' - dd MOS_DWORD(LABEL_PL2TYPE_X + 18,LABEL_PL2TYPE_Y) - %else - dd MOS_DWORD(LABEL_PL2TYPE_X,LABEL_PL2TYPE_Y) - %endif - dd playertypes+PL2TYPE_INIT*PLAYERTYPELEN - dd MOS_RGB(255,255,255) - dd MOS_RGB(0,0,0) -iend -NLABELS equ (($-labels)/LABEL_size) +window WND WND_WIDTH, WND_HEIGHT, 0x14000000 or WND_WORKCOLOR, 0,0,windowtitle,0, WND_CENTER or WND_DEFAULT_GRABCOLOR or WND_DEFAULT_FRAMECOLOR or WND_DEFAULT_CAPTIONCOLOR ; player types @@ -912,23 +825,31 @@ player2_type dd PL2TYPE_INIT ; status messages -%ifidn lang, 'it_IT' +if lang eq it_IT player1hmnprmpt db "Turno del giocatore 1",0 player2hmnprmpt db "Turno del giocatore 2",0 player1cpuprmpt db "Attendi, giocatore 1 sta pensando...",0 player2cpuprmpt db "Attendi, giocatore 2 sta pensando...",0 itisadraw db "Pareggio",0 player1wins db "Vince giocatore 1",0 - player2wins db "Vince Giocatore 2",0 -%else - player1hmnprmpt db "Make your move, player 1.",0 - player2hmnprmpt db "Make your move, player 2.",0 + player2wins db "Vince giocatore 2",0 +else if lang eq ru_RU + player1hmnprmpt db "Игрок 1 сделайте ход",0 + player2hmnprmpt db "Игрок 2 сделайте ход",0 + player1cpuprmpt db "Подождите, игрок 1 думает......",0 + player2cpuprmpt db "Подождите, игрок 2 думает......",0 + itisadraw db "Это ничья",0 + player1wins db "Игрок 1 выиграл",0 + player2wins db "Игрок 2 выиграл",0 +else + player1hmnprmpt db "Make your move, player 1",0 + player2hmnprmpt db "Make your move, player 2",0 player1cpuprmpt db "Player 1 is thinking, please wait...",0 player2cpuprmpt db "Player 2 is thinking, please wait...",0 - itisadraw db "It's a draw.",0 - player1wins db "Player 1 wins.",0 - player2wins db "Player 2 wins.",0 -%endif + itisadraw db "It's a draw",0 + player1wins db "Player 1 wins",0 + player2wins db "Player 2 wins",0 +end if ; pointer to ai player. future releases C4 might @@ -936,29 +857,22 @@ player2_type dd PL2TYPE_INIT aicode dd aiGetMove -; button images -redpcx: incbin "red.pcx" -REDPCXSIZE equ ($ - redpcx) -bluepcx: incbin "blue.pcx" -BLUEPCXSIZE equ ($ - bluepcx) +align 16 +i_end: + sc system_colors + procinfo process_information + rb 1024 +align 16 +stacktop: + ; player input + ; 0 : no input available + ; 1..7 : column to drop stone into + playerinput rd 1 + mouseinput rd 1 + gameover rd 1 + redstone rb STONESIZE*STONESIZE*3 + bluestone rb STONESIZE*STONESIZE*3 +mem: -;********************************************************** -; uninitialized data -;********************************************************** - - section .bss - -; player input -; 0 : no input available -; 1..7 : column to drop stone into -playerinput resd 1 - -mouseinput resd 1 -gameover resd 1 - -redstone resb STONESIZE*STONESIZE*3 -bluestone resb STONESIZE*STONESIZE*3 - -end: diff --git a/programs/games/c4/mos.inc b/programs/games/c4/mos.inc deleted file mode 100644 index 72ab5ba7c..000000000 --- a/programs/games/c4/mos.inc +++ /dev/null @@ -1,305 +0,0 @@ -; mos.inc 0.0.2 -; Copyright (c) 2002 Thomas Mathys -; killer@vantage.ch -; -; This program is free software; you can redistribute it and/or modify -; it under the terms of the GNU General Public License as published by -; the Free Software Foundation; either version 2 of the License, or -; (at your option) any later version. -; -; This program is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this program; if not, write to the Free Software -; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -; -; -; -; revision history -; ---------------- -; -; 10-04-2002 version 0.0.2 -; - removed MOS_WNDCOLORS_SIZE and similar constants. -; while reading the docs i realized that NASM creates -; such symbols already itself... -; + macros: MOS_WAITEVENT, MOS_WAITEVENT_S, MOS_STARTREDRAW, -; MOS_STARTREDRAW_S, MOS_ENDREDRAW, MOS_ENDREDRAW_S, -; MOS_GETSCREENMAX, MOS_GETSCREENMAX_S, MOS_EXIT, MOS_EXIT_S -; + event bit masks -; + some syscall numbers -; + process info structure -; -; 08-??-2002 version 0.0.1 -; first release -; -%ifndef _MOS_INC -%define _MOS_INC - - - -;********************************************************** -; generates a menuetos 01 header -; takes 2-6 parameters: -; -; MOS_HEADER01 start,end[,appmem,esp,i_param,i_icon] -;********************************************************** - -%macro MOS_HEADER01 2-6 0x100000,0x7fff0,0,0 - org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd %1 ; start of code - dd %2 ; image size - dd %3 ; application memory - dd %4 ; esp - dd %5 ; i_param - dd %6 ; i_icon -%endmacro - - -;********************************************************** -; MOS_DWORD -; packs 2 words into a double word -;********************************************************** - -%define MOS_DWORD(hi,lo) ((((hi) & 0xffff) << 16) + ((lo) & 0xffff)) - - -;********************************************************** -; MOS_RGB -; creates a menuet os compatible color (0x00RRGGBB) -;********************************************************** - -%define MOS_RGB(r,g,b) ((((r) & 255) << 16) + (((g) & 255) << 8) + ((b) & 255)) - - -;********************************************************** -; window color structure -;********************************************************** - -struc MOS_WNDCOLORS - .frame: resd 1 - .grab: resd 1 - .grabButton: resd 1 - .grabButtonText: resd 1 - .grabText: resd 1 - .work: resd 1 - .workButton: resd 1 - .workButtonText: resd 1 - .workText: resd 1 - .workGraphics: resd 1 -endstruc - - -;********************************************************** -; process info structure -;********************************************************** - -struc MOS_PROCESSINFO - .CPUUsage: resd 1 ; cpu usage - .windowStackPos: resw 1 ; process' position in windowing stack - .windowStackVal: resw 1 ; window stack value at ecx - .reserved1: resw 1 - .processName: resb 12 ; process name - .memStart: resd 1 ; start of process memory - .memUsed: resd 1 ; memory used by the process - .pid: resd 1 ; process id - .reserved2: resb (1024-34) -endstruc - - - -;********************************************************** -; system call numbers -;********************************************************** - -MOS_SC_EXIT equ -1 -MOS_SC_DEFINEWINDOW equ 0 -MOS_SC_PUTPIXEL equ 1 -MOS_SC_GETKEY equ 2 -MOS_SC_GETSYSCLOCK equ 3 -MOS_SC_WRITETEXT equ 4 -MOS_SC_DELAY equ 5 -MOS_SC_OPENFILEFLOPPY equ 6 -MOS_SC_PUTIMAGE equ 7 -MOS_SC_DEFINEBUTTON equ 8 -MOS_SC_GETPROCESSINFO equ 9 -MOS_SC_WAITEVENT equ 10 -MOS_SC_CHECKEVENT equ 11 -MOS_SC_REDRAWSTATUS equ 12 -MOS_SC_DRAWBAR equ 13 -MOS_SC_GETSCREENMAX equ 14 -MOS_SC_SETBACKGROUND equ 15 -MOS_SC_GETPRESSEDBUTTON equ 17 -MOS_SC_SYSTEMSERVICE equ 18 -MOS_SC_STARTPROGRAM equ 19 -MOS_SC_MIDIINTERFACE equ 20 -MOS_SC_DEVICESETUP equ 21 -MOS_SC_WAITEVENTTIMEOUT equ 23 -MOS_SC_CDAUDIO equ 24 -MOS_SC_SB16MIXER1 equ 25 -MOS_SC_GETDEVICESETUP equ 26 -MOS_SC_WSS equ 27 -MOS_SC_SB16MIXER2 equ 28 -MOS_SC_GETDATE equ 29 -MOS_SC_READHD equ 30 -MOS_SC_STARTPROGRAMHD equ 31 -MOS_SC_GETSCREENPIXEL equ 35 -MOS_SC_GETMOUSEPOSITION equ 37 -MOS_SC_DRAWLINE equ 38 -MOS_SC_GETBACKGROUND equ 39 -MOS_SC_SETEVENTMASK equ 40 -MOS_SC_WRITENUMBER equ 47 -MOS_SC_WINDOWPROPERTIES equ 48 - - -;********************************************************** -; event numbers -;********************************************************** - -MOS_EVT_NONE equ 0 -MOS_EVT_REDRAW equ 1 -MOS_EVT_KEY equ 2 -MOS_EVT_BUTTON equ 3 - - -;********************************************************** -; event bits -;********************************************************** - -MOS_EVTBIT_REDRAW equ (1 << 0) -MOS_EVTBIT_KEY equ (1 << 1) -MOS_EVTBIT_BUTTON equ (1 << 2) -MOS_EVTBIT_ENDREQUEST equ (1 << 3) -MOS_EVTBIT_BGDRAW equ (1 << 4) -MOS_EVTBIT_MOUSECHANGE equ (1 << 5) -MOS_EVTBIT_IPCEVENT equ (1 << 6) -MOS_EVTBIT_IRQ0 equ (1 << 16) -MOS_EVTBIT_IRQ1 equ (1 << 17) -MOS_EVTBIT_IRQ2 equ (1 << 18) -MOS_EVTBIT_IRQ3 equ (1 << 19) -MOS_EVTBIT_IRQ4 equ (1 << 20) -MOS_EVTBIT_IRQ5 equ (1 << 21) -MOS_EVTBIT_IRQ6 equ (1 << 22) -MOS_EVTBIT_IRQ7 equ (1 << 23) -MOS_EVTBIT_IRQ8 equ (1 << 24) -MOS_EVTBIT_IRQ9 equ (1 << 25) -MOS_EVTBIT_IRQ10 equ (1 << 26) -MOS_EVTBIT_IRQ11 equ (1 << 27) -MOS_EVTBIT_IRQ12 equ (1 << 28) -MOS_EVTBIT_IRQ13 equ (1 << 29) -MOS_EVTBIT_IRQ14 equ (1 << 30) -MOS_EVTBIT_IRQ15 equ (1 << 31) - - -;********************************************************** -; exit application (syscall -1) -;********************************************************** - -; exit application -%macro MOS_EXIT 0 - mov eax,MOS_SC_EXIT - int 0x40 -%endmacro - -; exit application, smaller version -%macro MOS_EXIT_S 0 - xor eax,eax - dec eax - int 0x40 -%endmacro - - -;********************************************************** -; wait event stuff -; (MOS_SC_WAITEVENT, syscall 10) -;********************************************************** - -; wait for event -; destroys : nothing -; returns : eax = event type -%macro MOS_WAITEVENT 0 - mov eax,MOS_SC_WAITEVENT - int 0x40 -%endmacro - -; wait for event, smaller version -; destroys : flags -; returns : eax = event type -%macro MOS_WAITEVENT_S 0 - xor eax,eax - mov al,MOS_SC_WAITEVENT - int 0x40 -%endmacro - - -;********************************************************** -; window redraw status stuff -; (MOS_SC_REDRAWSTATUS, syscall 12) -;********************************************************** - -MOS_RS_STARTREDRAW equ 1 -MOS_RS_ENDREDRAW equ 2 - -; start window redraw -; destroys: eax,ebx -%macro MOS_STARTREDRAW 0 - mov ebx,MOS_RS_STARTREDRAW - mov eax,MOS_SC_REDRAWSTATUS - int 0x40 -%endmacro - -; start window redraw, smaller version -; destroys: eax,ebx,flags -%macro MOS_STARTREDRAW_S 0 - xor ebx,ebx - inc ebx - xor eax,eax - mov al,MOS_SC_REDRAWSTATUS - int 0x40 -%endmacro - -; end window redraw -; destroys: eax,ebx -%macro MOS_ENDREDRAW 0 - mov ebx,MOS_RS_ENDREDRAW - mov eax,MOS_SC_REDRAWSTATUS - int 0x40 -%endmacro - -; end window redraw, smaller version -; destroys: eax,ebx,flags -%macro MOS_ENDREDRAW_S 0 - xor ebx,ebx - mov bl,MOS_RS_ENDREDRAW - xor eax,eax - mov al,MOS_SC_REDRAWSTATUS - int 0x40 -%endmacro - - -;********************************************************** -; get screen max stuff (syscall 14) -;********************************************************** - -; get screen dimensions in eax -; destroys: nothing -%macro MOS_GETSCREENMAX 0 - mov eax,MOS_SC_GETSCREENMAX - int 0x40 -%endmacro - -; get screen dimensions in eax, smaller version -; destroys: flags -%macro MOS_GETSCREENMAX_S 0 - xor eax,eax - mov al,MOS_SC_GETSCREENMAX - int 0x40 -%endmacro - - - -%endif \ No newline at end of file diff --git a/programs/games/c4/pcx.inc b/programs/games/c4/pcx.inc index 5b9755b14..973b56a4f 100644 --- a/programs/games/c4/pcx.inc +++ b/programs/games/c4/pcx.inc @@ -16,38 +16,32 @@ ; along with this program; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -%ifndef _PCX_INC -%define _PCX_INC - ;********************************************************** ; pcx header ;********************************************************** PCXHEADER_SIZE equ 128 -struc PCXHEADER - .id: resb 1 ; id, should be 10 - .version: resb 1 ; pcx version - .encoding: resb 1 ; 1 = rle - .bpp: resb 1 ; bits per pixel - .xmin: resw 1 ; image dimensions - .ymin: resw 1 - .xmax: resw 1 - .ymax: resw 1 - .hdpi: resw 1 ; horizontal resolution in dpi - .vdpi: resw 1 ; verttical resolution in dpi - .colormap: resb 48 ; 16 color palette - .reserved1: resb 1 - .nplanes: resb 1 ; # of color planes - .bytesperline: resw 1 ; # of bytes per scanline. always even - .palinfo: resw 1 ; 1 = color/bw, 2 = grayscale - .hscreensize: resw 1 ; horizontal screen size - .vscreensize: resw 1 ; vertical screen size - .reserved2: resb 54 -endstruc - - -section .text +struct PCXHEADER + id rb 1 ; id, should be 10 + version rb 1 ; pcx version + encoding rb 1 ; 1 = rle + bpp rb 1 ; bits per pixel + xmin rw 1 ; image dimensions + ymin rw 1 + xmax rw 1 + ymax rw 1 + hdpi rw 1 ; horizontal resolution in dpi + vdpi rw 1 ; verttical resolution in dpi + colormap rb 48 ; 16 color palette + reserved1 rb 1 + nplanes rb 1 ; # of color planes + bytesperline rw 1 ; # of bytes per scanline. always even + palinfo rw 1 ; 1 = color/bw, 2 = grayscale + hscreensize rw 1 ; horizontal screen size + vscreensize rw 1 ; vertical screen size + reserved2 rb 54 +ends @@ -98,7 +92,7 @@ loadPCX: .decode: lodsb ; read byte from input stream cmp al,192 ; encoded/unencoded byte ? - jae short .encoded + jae .encoded lea edx,[eax*2+eax] ; read color values from mov al,[ebx+edx+2] ; palette and store them stosb ; in the destination image @@ -107,7 +101,7 @@ loadPCX: mov al,[ebx+edx+0] stosb dec ebp ; one less to go... - jmp short .continue + jmp .continue .encoded: and al,00111111b ; calc # of times to repeat mov cl,al @@ -127,11 +121,8 @@ loadPCX: xor ah,ah ; reset ah to 0 ! .continue: or ebp,ebp ; all pixels decoded ? - jnz short .decode + jnz .decode popfd popad ret - - -%endif \ No newline at end of file diff --git a/programs/games/c4/randomai.inc b/programs/games/c4/randomai.inc index 5fedd0b62..298c03cad 100644 --- a/programs/games/c4/randomai.inc +++ b/programs/games/c4/randomai.inc @@ -18,12 +18,6 @@ ; along with C4; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -%infdef _RANDOMAI_INC -%define _RANDOMAI_INC - - section .text - - ;********************************************************** ; randomaiGetMove @@ -47,4 +41,3 @@ randomaiGetMove mov eax,edx ; return move ret -%endif \ No newline at end of file diff --git a/programs/games/c4/rng.inc b/programs/games/c4/rng.inc index c175218d1..e8c04ef62 100644 --- a/programs/games/c4/rng.inc +++ b/programs/games/c4/rng.inc @@ -18,10 +18,6 @@ ; along with C4; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -%ifndef _RNG_INC -%define _RNG_INC - - section .data ; random seed @@ -29,9 +25,6 @@ seed dd 0 - section .text - - ;********************************************************** ; randomize ; initialize random number generator. @@ -43,8 +36,7 @@ seed dd 0 ;********************************************************** randomize: push eax - mov eax,MOS_SC_GETSYSCLOCK - int 0x40 + mcall SF_GET_SYS_TIME mov [seed],eax pop eax ret @@ -72,5 +64,3 @@ rand: pop edx popfd ret - -%endif \ No newline at end of file diff --git a/programs/games/c4/windows.inc b/programs/games/c4/windows.inc index 05cd588c6..2e287aa41 100644 --- a/programs/games/c4/windows.inc +++ b/programs/games/c4/windows.inc @@ -16,63 +16,52 @@ ; along with this program; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -%ifndef _WINDOWS_INC -%define _WINDOWS_INC - -WND_CENTER equ (1 << 0) -WND_DEFAULT_WORKCOLOR equ (1 << 1) -WND_DEFAULT_GRABCOLOR equ (1 << 2) -WND_DEFAULT_FRAMECOLOR equ (1 << 3) -WND_DEFAULT_CAPTIONCOLOR equ (1 << 4) +WND_CENTER equ (1 shl 0) +WND_DEFAULT_WORKCOLOR equ (1 shl 1) +WND_DEFAULT_GRABCOLOR equ (1 shl 2) +WND_DEFAULT_FRAMECOLOR equ (1 shl 3) +WND_DEFAULT_CAPTIONCOLOR equ (1 shl 4) WND_DEFAULT_COLORS equ (WND_DEFAULT_WORKCOLOR | WND_DEFAULT_GRABCOLOR | WND_DEFAULT_FRAMECOLOR | WND_DEFAULT_CAPTIONCOLOR) -struc WND - .xposandsize resd 1 ; x position and size (like syscall) - .yposandsize resd 1 ; y position and size (like syscall) - .workcolor resd 1 ; work area color (like syscall) - .grabcolor resd 1 ; grab bar color (like syscall) - .framecolor resd 1 ; frame color (like syscall) - .caption resd 1 ; pointer to caption (zero terminated) +struct WND + xposandsize rd 1 ; x position and size (like syscall) + yposandsize rd 1 ; y position and size (like syscall) + workcolor rd 1 ; work area color (like syscall) + grabcolor rd 1 ; grab bar color (like syscall) + framecolor rd 1 ; frame color (like syscall) + caption rd 1 ; pointer to caption (zero terminated) ; can be zero, if no caption is desired. - .captioncolor resd 1 ; caption color - .flags resd 1 ; combination of WND_xxx flags, or zero. -endstruc + captioncolor rd 1 ; caption color + flags rd 1 ; combination of WND_xxx flags, or zero. +ends + +USE_SYSTEM_COLORS equ 0 ;0 or 1 +BUTTON_COLOR_WORK equ 0x505050 -BUTTON_COLOR_GRAB equ 0x01000000 -BUTTON_COLOR_WORK equ 0x02000000 - - -struc BUTTON - .xposandsize resd 1 ; x position and size (like syscall) - .yposandsize resd 1 ; y position and size (like syscall) - .id resd 1 ; button id - .color resd 1 ; button color. can be a real color +struct BUTTON + xposandsize rd 1 ; x position and size (like syscall) + yposandsize rd 1 ; y position and size (like syscall) + id rd 1 ; button id + color rd 1 ; button color. can be a real color ; or one of the BUTTON_COLOR_xxx constants -endstruc +ends -LABEL_COLOR_GRABBUTTON equ 0x01000000 ; use grab button text default color -LABEL_COLOR_GRAB equ 0x02000000 ; use grab text default color -LABEL_COLOR_WORKBUTTON equ 0x03000000 ; use work button text default color -LABEL_COLOR_WORK equ 0x04000000 ; use work text default color +LABEL_COLOR_WORKBUTTON equ 0xffffff ; use work button text default color LABEL_BGCOLOR_TRANSPARENT equ 0x01000000 ; transparent -LABEL_BGCOLOR_WORK equ 0x02000000 ; use work area color -struc LABEL - .position resd 1 ; position, x in upper word, y in lower word - .caption resd 1 ; pointer to caption (zero terminated) +struct LABEL + position rd 1 ; position, x in upper word, y in lower word + caption rd 1 ; pointer to caption (zero terminated) ; if this is field is zero, the label will ; not be drawn. - .color resd 1 ; text color, or a LABEL_COLOR_xxx constant - .bgcolor resd 1 ; background color, or a LABEL_BGCOLOR_xxx constant -endstruc - - - section .text + color rd 1 ; text color, or a LABEL_COLOR_xxx constant + bgcolor rd 1 ; background color, or a LABEL_BGCOLOR_xxx constant +ends ;*********************************************************** @@ -87,61 +76,47 @@ endstruc ;*********************************************************** drawWindow: - -%define WNDCOLORS ebp-MOS_WNDCOLORS_size - - enter MOS_WNDCOLORS_size,0 pushfd pushad ; get default window colors - mov ebx,3 - lea ecx,[WNDCOLORS] - mov edx,MOS_WNDCOLORS_size - mov eax,MOS_SC_WINDOWPROPERTIES - int 0x40 + mcall SF_STYLE_SETTINGS,3,sc,sizeof.system_colors ; ; window position ; test dword [edi + WND.flags],WND_CENTER ; center window ? - jnz short .center + jnz .center mov ebx,[edi + WND.xposandsize] ; nope -> just load dimensions mov ecx,[edi + WND.yposandsize] - jmp short .positionok + jmp .positionok .center: ; so let's center this window... - MOS_GETSCREENMAX ; get screen dimensions + mcall SF_GET_SCREEN_SIZE ; get screen dimensions mov ebx,eax ; xpos = (screenx-width)/2 shr ebx,16 - sub bx,[edi + WND.xposandsize] - jns short .xok + sub bx,word[edi + WND.xposandsize] + jns .xok xor ebx,ebx .xok: shl ebx,15 ; / 2, move result to hi-word - mov bx,[edi + WND.xposandsize] + mov bx,word[edi + WND.xposandsize] movzx ecx,ax ; same for ypos - sub cx,[edi + WND.yposandsize] - jns short .yok + sub cx,word[edi + WND.yposandsize] + jns .yok xor ecx,ecx .yok: shl ecx,15 - mov cx,[edi + WND.yposandsize] + mov cx,word[edi + WND.yposandsize] .positionok: ; ebx/ecx contain dimensions - push edi - ; define window - mov eax,MOS_SC_DEFINEWINDOW mov edx,[edi + WND.workcolor] mov edi,windowtitle - int 0x40 - pop edi + mcall SF_CREATE_WINDOW popad popfd - leave ret -%undef WNDCOLORS ;*********************************************************** @@ -153,53 +128,40 @@ drawWindow: ; destroys: nothing ; notes: you must call begin redraw/end redraw yourself ;*********************************************************** - +align 4 drawButtons: - -%define WNDCOLORS ebp-MOS_WNDCOLORS_size - or ecx,ecx - jnz short .ok + jnz .ok ret .ok: - enter MOS_WNDCOLORS_size,0 pushfd pushad ; get default window colors + if USE_SYSTEM_COLORS eq 1 push ecx - mov ebx,3 - lea ecx,[WNDCOLORS] - mov edx,MOS_WNDCOLORS_size - mov eax,MOS_SC_WINDOWPROPERTIES - int 0x40 + mcall SF_STYLE_SETTINGS,3,sc,sizeof.system_colors pop ecx - + end if +align 4 .drawall: push ecx mov ebx,[edi + BUTTON.xposandsize] mov ecx,[edi + BUTTON.yposandsize] mov edx,[edi + BUTTON.id] - mov esi,[edi + BUTTON.color] - cmp esi,BUTTON_COLOR_GRAB ; use a default color ? - jne .ok1 - mov esi,[WNDCOLORS + MOS_WNDCOLORS.grabButton] -.ok1: - cmp esi,BUTTON_COLOR_WORK - jne .ok2 - mov esi,[WNDCOLORS + MOS_WNDCOLORS.workButton] -.ok2: - mov eax,MOS_SC_DEFINEBUTTON - int 0x40 - add edi,BUTTON_size + if USE_SYSTEM_COLORS eq 1 + mov esi,[sc.work_button] ; use a system color + else + mov esi,[edi + BUTTON.color] ; use a default color + end if + mcall SF_DEFINE_BUTTON + add edi,sizeof.BUTTON pop ecx loop .drawall popad popfd - leave ret -%undef WNDCOLORS ;*********************************************************** @@ -210,33 +172,27 @@ drawButtons: ; output: nothing ; destroys: nothing ;*********************************************************** - +align 4 drawLabels: - -%define WNDCOLORS ebp-MOS_WNDCOLORS_size - or ecx,ecx - jnz short .ok + jnz .ok ret .ok: - enter MOS_WNDCOLORS_size,0 pushfd pushad ; get default window colors + if USE_SYSTEM_COLORS eq 1 push ecx - mov ebx,3 - lea ecx,[WNDCOLORS] - mov edx,MOS_WNDCOLORS_size - mov eax,MOS_SC_WINDOWPROPERTIES - int 0x40 + mcall SF_STYLE_SETTINGS,3,sc,sizeof.system_colors pop ecx + end if .drawall: push ecx cmp dword [edi + LABEL.caption],0 - jne short .notnull + jne .notnull jmp .next .notnull: @@ -261,41 +217,28 @@ drawLabels: mov bx,ax mov ecx,[edi + LABEL.position] ; ecx = ystart/height shl ecx,16 - mov cx,8 + mov cx,8 + if USE_SYSTEM_COLORS eq 1 + mov edx,[sc.work] + else mov edx,[edi + LABEL.bgcolor] - cmp edx,LABEL_BGCOLOR_WORK - jne short .bgcolorok - mov edx,[WNDCOLORS + MOS_WNDCOLORS.work] -.bgcolorok: - mov eax,MOS_SC_DRAWBAR - int 0x40 + end if + mcall SF_DRAW_RECT .clearok: ; draw label mov ebx,[edi + LABEL.position] ; ebx = label position mov edx,[edi + LABEL.caption] ; edx -> caption + + if USE_SYSTEM_COLORS eq 1 + mov ecx,[sc.work_button_text] + else mov ecx,[edi + LABEL.color] ; ecx = color - cmp ecx,LABEL_COLOR_GRABBUTTON - jne short .ok1 - mov ecx,[WNDCOLORS + MOS_WNDCOLORS.grabButtonText] -.ok1: - cmp ecx,LABEL_COLOR_GRAB - jne short .ok2 - mov ecx,[WNDCOLORS + MOS_WNDCOLORS.grabText] -.ok2: - cmp ecx,LABEL_COLOR_WORKBUTTON - jne short .ok3 - mov ecx,[WNDCOLORS + MOS_WNDCOLORS.workButtonText] -.ok3: - cmp ecx,LABEL_COLOR_WORK - jne short .ok4 - mov ecx,[WNDCOLORS + MOS_WNDCOLORS.workText] -.ok4: - mov eax,MOS_SC_WRITETEXT - int 0x40 + end if + mcall SF_DRAW_TEXT .next: - add edi,LABEL_size ; next label + add edi,sizeof.LABEL ; next label pop ecx dec ecx jz .done @@ -304,9 +247,5 @@ drawLabels: popad popfd - leave ret -%undef WNDCOLORS - -%endif \ No newline at end of file