Add initial source files for Tic-Tac-Toe game implementation
Signed-off-by: Elmar Kresse <elmar.kresse@stud.htwk-leipzig.de>
This commit is contained in:
140
logic.asm
Normal file
140
logic.asm
Normal file
@ -0,0 +1,140 @@
|
||||
;****************************************
|
||||
; Elmar Kresse 19-INB-1 (2021)
|
||||
; logic.asm
|
||||
; file contains source code for the
|
||||
; logic (mouse, timer, programm)
|
||||
;
|
||||
; - handle_timer_tick PROC
|
||||
; - prepare_timer_tick PROC
|
||||
; - prepare_mouse PROC
|
||||
; - mouseProc PROC FAR
|
||||
; - start_programm PROC
|
||||
;****************************************
|
||||
|
||||
handle_timer_tick PROC
|
||||
; Call the original interrupt vector
|
||||
; by pushing flags register and doing a FAR CALL to old vector
|
||||
PUSHF
|
||||
CALL DWORD ptr [CS:old_timer]
|
||||
INC WORD ptr [CS:timer_ticks] ; Increase timer counter
|
||||
|
||||
IRET
|
||||
handle_timer_tick ENDP
|
||||
|
||||
prepare_timer_tick PROC
|
||||
|
||||
PUSH DS
|
||||
MOV AX, 351Ch ; Get user timer interrupt vector
|
||||
INT 21h
|
||||
; ES:BX now has the address of the interrupt vector
|
||||
MOV [CS:old_timer], BX
|
||||
MOV AX, ES
|
||||
MOV [CS:old_segment], AX
|
||||
|
||||
MOV AX, 251ch ; Set user timer interrupt vector
|
||||
PUSH CS
|
||||
POP DS
|
||||
MOV DX, OFFSET handle_timer_tick
|
||||
INT 21h
|
||||
|
||||
POP ds
|
||||
|
||||
ret
|
||||
prepare_timer_tick ENDP
|
||||
|
||||
prepare_mouse PROC
|
||||
|
||||
mov dx, OFFSET mouseProc ;jump to click_event_handler
|
||||
mov ax, 0Ch
|
||||
mov cx, 00000010b ; on left click
|
||||
push cs ;es:dx
|
||||
pop es
|
||||
int 33h
|
||||
|
||||
mov ax, 1 ;show cursor
|
||||
int 33h
|
||||
|
||||
ret
|
||||
prepare_mouse ENDP
|
||||
|
||||
mouseProc PROC FAR ;other doc segment therefore FAR
|
||||
enter 0, 0
|
||||
push ax
|
||||
push bx
|
||||
push cx
|
||||
push dx
|
||||
push es
|
||||
push ds
|
||||
|
||||
mov ax, 2 ;hide cursor
|
||||
int 33h
|
||||
|
||||
;dx contains coordinates of "rows"
|
||||
mov y_wert, dx ;save y coordinate in variable
|
||||
;cx contains coordinates of "columns"
|
||||
mov x_wert, cx ;save y coordinate in variable
|
||||
|
||||
call game_logic
|
||||
|
||||
xor bx, bx ;button pressed clear result
|
||||
|
||||
mov ax, 1 ;show cursor
|
||||
int 33h
|
||||
|
||||
pop ds
|
||||
pop es
|
||||
pop dx
|
||||
pop cx
|
||||
pop bx
|
||||
pop ax
|
||||
leave
|
||||
ret
|
||||
mouseProc ENDP
|
||||
|
||||
start_programm PROC
|
||||
|
||||
mov AX, video_seg
|
||||
mov es, AX
|
||||
|
||||
|
||||
mov ax, @DATA
|
||||
mov ds, ax
|
||||
|
||||
|
||||
mov ax, 12h
|
||||
int 10h
|
||||
|
||||
mov dx, 03C4h ;address of the index port (share)
|
||||
mov al, 2 ;index of control register
|
||||
out dx, al ;Set index: output out :: dx to port al(2)
|
||||
inc dx ;index of dataport
|
||||
mov al, 0Fh ;value (1 = bit plane enabled, here all) fi
|
||||
out dx, al
|
||||
|
||||
|
||||
call prepare_timer_tick
|
||||
|
||||
mov ax,0Dh
|
||||
int 10h
|
||||
|
||||
call paint_menu
|
||||
|
||||
check_mode_loop:
|
||||
xor ax, ax ;delete ah
|
||||
int 16h ;keyboard query
|
||||
|
||||
cmp al,'1'
|
||||
je short playgame
|
||||
|
||||
cmp al,'2'
|
||||
je ende
|
||||
|
||||
jmp check_mode_loop
|
||||
|
||||
playgame:
|
||||
call start_game
|
||||
|
||||
|
||||
ret
|
||||
start_programm ENDP
|
||||
|
Reference in New Issue
Block a user