1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
| ;----------Définition de la structure--------
Sprite STRUC
X DW ?
Y DW ?
W DB ?
H DB ?
Spr DW ?
Sprite ENDS
DATA SEGMENT
include fantome.spr
include voiture.spr
AdrEcrGraph DW 0A000h
DATA ENDS
BufferEcran SEGMENT
ECRAN DB 320*200 DUP (0)
BufferEcran ENDS
;-------------------------------------------
CODE SEGMENT
ASSUME CS: Code, DS: Data, SS: Stk
;-------------------------------
;code du programme
main:
Mov ax,data ;on met le data segment dans ax
mov DS,ax ; on met ax dans le DATA
Mov ah,0 ;on initialise la mémoire vidéo
Mov al,13h
Int 10h
mov AX,bufferEcran ;on place le pointeur a l'extrémiter haut gauche
mov es,ax
touche:
CALL FOND1
LEA BX, fantome
CALL affiche
LEA BX, voiture
CALL affiche
call AttenteVBL
CALL transfer
Mov AH,08h
int 21h
cmp al, 53
JE chgsprite
cmp al, 54
JE droite
cmp al, 52
JE gauche
cmp al, 50
JE bas
cmp al, 56
JE haut
cmp al, 27
JNE tests_suivants
jmp fin
tests_suivants:
cmp al, 55
JNE testa
jmp hg
testa:
cmp al,57
JNE testo
jmp hd
testo:
cmp al,51
JNE testi
jmp bd
testi:
cmp al,49
JNE testu
jmp bg
testu:
;--------------------------------------------------
chgsprite:
LEA BX, fantome
droite:
cmp [BX].x,300
JE touche
inc [BX].x
jmp touche
gauche:
cmp [BX].x, 00
JE touche
dec [BX].x
jmp touche
haut:
cmp [BX].y, 00
JE touche
dec [BX].y
jmp touche
bas:
cmp [BX].y, 180
JE touche
inc [BX].y
jmp touche
hg:
call teste
cmp [BX].x, 00
JNE ri
call touche
ri:
dec [BX].x
dec [BX].y
jmp touche
hd:
call hd1
inc [BX].x
dec [BX].y
jmp touche
bg:
call bg1
dec [BX].x
inc [BX].y
jmp touche
bd:
call bd1
inc [BX].x
inc [BX].y
jmp touche
fin:
MOV AH, 0
MOV AL, 3
INT 10h
MOV AH,4ch
INT 21h
teste PROC
cmp [BX].y, 00
JE hg
teste ENDP
hd1 PROC
cmp [BX].y, 00
JNE tutu
call touche
tutu:
cmp [BX].x,300
JNE titi
call touche
titi:
hd1 ENDP
bg1 PROC
cmp [BX].y, 180
JNE tu
call touche
tu:
cmp [BX].x, 00
JNE ti
call touche
ti:
bg1 ENDP
bd1 PROC
cmp [BX].y, 180
JNE to
call touche
to:
cmp [BX].x,300
JNE ta
call touche
ta:
bd1 ENDP
;-----------------------------------------------------------
FOND1 PROC
mov CX, 64000
mov DI,0
fond2:
mov es:[di],CL
inc di
loop fond2
ret
FOND1 ENDP
;-----------------------------------------------------
transfer PROC
PUSH DS
PUSH ES
PUSH AdrEcrGraph
PUSH ES
POP DS
POP ES
XOR DI, DI
XOR SI, SI
CLD
MOV CX, 32000
REP MOVSW
POP ES
POP DS
RET
transfer ENDP
;--------------------------------------------------------
affiche PROC
Mov AX,[BX].y
MOV DI, AX
SHL AX, 6
SHL DI, 8
ADD DI, AX ;fantome.y
ADD DI, [BX].x
XOR CX, CX
MOV CL, [BX].H
MOV SI, [BX].Spr
Ligne:
PUSH CX
PUSH DI
MOV CL, [BX].W
Colonne:
MOV AL, [SI]
cmp al,00
JE trans
MOV ES:[DI], AL
trans:
INC DI
INC SI
LOOP Colonne
POP DI
ADD DI, 320
POP CX
LOOP Ligne
RET
affiche ENDP
;------------------------------------------------------
; Attente VBL
AttenteVBL PROC
PUSH AX
PUSH DX
MOV DX, 3DAh
Sp1:
IN AL, DX
TEST AL, 8
JZ Sp1
MOV DX, 3DAh
Sp2:
IN AL, DX
TEST AL, 1
JZ Sp2
POP DX
POP AX
RET
AttenteVBL ENDP
CODE ENDS
;-------------------------------------------
end main |
Partager