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:
Elmar Kresse
2025-07-03 15:53:46 +02:00
commit 2a94dfb8d5
10 changed files with 1121 additions and 0 deletions

344
draw.asm Normal file
View File

@ -0,0 +1,344 @@
;****************************************
; Elmar Kresse 19-INB-1 (2021)
; draw.asm
; file contains source code for
; drawing and maths for circle
;
; - draw_pixel MACRO x, y, c
; - circle_draw macro x, y, radius
; Reference Digital differential analyzer (graphics algorithm)
; https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
;
; - cross_draw MACRO x, y, d
; - rectangle_draw MACRO x, y, d
; - line_print_down PROC
; - line_print_straight PROC
; - paint_menu PROC FAR
; - prepare_display PROC
;****************************************
draw_pixel MACRO x, y, c
push ax
push bx
push cx
push dx
MOV AH, 0Ch ;setzen der Konfig fürs schreiben
MOV AL, c ; Farbe
MOV BH, 00h ;Set Seitennummber
MOV CX, x
MOV DX, y
INT 10h
pop dx
pop cx
pop bx
pop ax
ENDM
circle_draw macro x, y, radius
push dx
push cx
push bx
push ax
;Werte zurücksetzen
mov balance, 0
mov ax, 0
mov bx, 0
;Verschiebung Mitte
add x, 60
add y, 60
mov bx, radius
mov balance, radius
neg balance
zeichne_kreis_schleife:
;0 to 45
mov cx, x
add cx, bx
mov dx, y
sub dx, ax
draw_pixel cx, dx, 0Fh
;90 to 45
mov cx, x
add cx, ax
mov dx, y
sub dx, bx
draw_pixel cx, dx, 0Ch
;90 to 135
mov cx, x
sub cx, ax
mov dx, y
sub dx, bx
draw_pixel cx, dx, 04h
;180 to 135
mov cx, x
sub cx, bx
mov dx, y
sub dx, ax
draw_pixel cx, dx, 06h
;180 to 225
mov cx, x
sub cx, bx
mov dx, y
add dx, ax
draw_pixel cx, dx, 12h
;270 to 225
mov cx, x
sub cx, ax
mov dx, y
add dx, bx
draw_pixel cx, dx, 0Bh
;270 to 315
mov cx, x
add cx, ax
mov dx, y
add dx, bx
draw_pixel cx, dx, 01h
;360 to 315
mov cx, x
add cx, bx
mov dx, y
add dx, ax
draw_pixel cx, dx, 0Dh
push dx
mov dx, balance
add dx, ax
add dx, ax
mov balance, dx
pop dx
cmp balance, 0
jl balance_negative
;balance_positive:
dec bx
push dx
mov dx, balance
sub dx, bx
sub dx, bx
mov balance, dx
pop dx
balance_negative:
inc ax
cmp ax, bx
jg end_drawing
jmp zeichne_kreis_schleife
end_drawing:
; pause the screen for dos compatibility:
pop ax
pop bx
pop cx
pop dx
endm
cross_draw MACRO x, y, d
push ax
push bx
push cx
push dx
;Erste FOR Schleife nach rechts unten
mov cx, x
mov dx, y
xor cx,cx ; cx-register is the counter, setn to 0
loop1:
push cx
mov cx, cx
mov dx, y
add dx, cx
add cx, x
draw_pixel cx, dx, 0Fh
pop cx
inc cx
cmp cx, d ; cx vergleich mit der Größe (Dimension d)
jle loop1 ; Loop while less or equal
xor cx,cx ; cx-register is the counter, setn to 0
loop2:
push cx
mov cx, cx
mov dx, y
sub dx, cx
add cx, x
add dx, d
draw_pixel cx, dx, 0Dh
pop cx
inc cx
cmp cx, d ; cx vergleich mit der Größe (Dimension d)
jle loop2 ; Loop while less or equal
pop ax
pop bx
pop cx
pop dx
ENDM
rectangle_draw MACRO x, y, d
;Verwaltet move und call
mov cx, x
mov dx, y
mov x_wert, cx
mov y_wert, dx
mov d_wert, d
call line_print_down
call line_print_straight
ENDM
line_print_down PROC
xor cx,cx ; cx-register is the counter, setn to 0
loop3:
push cx
mov cx, cx
mov dx, y_wert
add cx, x_wert
draw_pixel cx, dx, 0Fh
add dx, d_wert
draw_pixel cx, dx, 0Fh
pop cx
inc cx
cmp cx, d_wert ; cx vergleich mit der Größe (Dimension d)
jle loop3 ; Loop while less or equal
ret
line_print_down endp
line_print_straight PROC
xor dx,dx ; cx-register is the counter, setn to 0
loop4:
push dx
mov dx, dx
mov cx, x_wert
add dx, y_wert
draw_pixel cx, dx, 0Fh
add cx, d_wert
draw_pixel cx, dx, 0Fh
pop dx
inc dx
cmp dx, d_wert ; cx vergleich mit der Größe (Dimension d)
jle loop4 ; Loop while less or equal
ret
line_print_straight endp
paint_menu PROC FAR
push ax
push bx
push dx
;set pointer
mov ah,2
mov dh,5
mov dl,14
mov bh,0
int 10h
mov dx,offset title_str
mov ah,9
int 21h
;set pointer
mov ah,2
mov dh,6
mov dl,10
mov bh,0
int 10h
mov dx,offset signature_str
mov ah,9
int 21h
;set pointer
mov ah,2
mov dh,7
mov dl,11
mov bh,0
int 10h
cmp cx, 2
mov dx,offset cross_win
je zeige_gewinner
cmp cx, 3
mov dx,offset circle_win
je zeige_gewinner
cmp cx, 4
jne kein_gewinner
mov ah,2
mov dh,7
mov dl,13
mov bh,0
int 10h
mov dx,offset draw
je zeige_gewinner
zeige_gewinner:
mov ah,9
int 21h
kein_gewinner:
;set pointer
mov ah,2
mov dh,9
mov dl,10
mov bh,0
int 10h
mov dx,offset choose1_str
mov ah,9
int 21h
;set pointer
mov ah,2
mov dh,10
mov dl,10
mov bh,0
int 10h
mov dx,offset choose2_str
mov ah,9
int 21h
pop ax
pop bx
pop dx
ret
paint_menu endp
prepare_display PROC
;Videomode clear alles entfernen
;Spielfeld initialisieren
rectangle_draw 80, 10, 405 ; Kreuz MACRO
rectangle_draw 84, 14, 130 ; 1
rectangle_draw 218, 14, 130 ; 2
rectangle_draw 352, 14, 130 ; 3
rectangle_draw 84, 148, 130 ; 4
rectangle_draw 218, 148, 130 ; 5
rectangle_draw 352, 148, 130 ; 6
rectangle_draw 84, 282, 130 ; 7
rectangle_draw 218, 282, 130 ; 8
rectangle_draw 352, 282, 130 ; 9
ret
prepare_display ENDP
;---------------------------------------- DRAW ENDE ---------------------------------------