Accueil > > > GAME OF LIFE
GAME OF LIFE
Information sur la source
Description
Source
- ;The Game of Life is a cellular automata program, where each pixel on the screen
- ;will live or die in each generation based upon some arbitrary rules.
- ;Specifically, if a pixel has three neighbors, it lives to the next generation.
- ;If an empty cell has two neighbors, it becomes populated in the next generation.
- ;Otherwise, that pixel gets cleared for the next generation. In this program, we
- ;generate an initial screen image using the paint program from last class. We
- ;then make a future image of the video screen in our offscreen buffer, then when
- ;complete, copy to the video.
- ; source file for assembling to binary files
- ; build with:
- ; nasmw -f bin -o life.com life.asm
-
- org 100h
-
- section .text
-
- mov ax,13h
- int 10h ;256 color graphics mode
-
- mov ax,0a000h ;video buffer
- mov es,ax ;pointer for segment
- xor di,di ;offset
- mov cx,32000 ;number of words in video
- xor ax,ax ;clear AX
- rep stosw ;and store in video buffer
-
- mov ax,1 ;show mouse
- int 33h
-
- M0:
- mov ax,0b21h ;check keyboard status
- int 21h
- cmp al,0 ;are any characters pending?
- jne Game
-
- mov ax,3 ;get mouse status call
- int 33h
- cmp bx,0 ;is mouse up
- je M0 ;loop till pressed
-
- M1: mov ax,0b21h ;check keyboard status
- int 21h
- cmp al,0 ;are any characters pending?
- jne Game
-
- mov ax,3 ;get fresh copy of mouse coordinates
- int 33h
-
- mov ah,0ch ;write dot at coordinate
- mov al,1 ;color value
- shr cx,1 ;mouse scale offset fix
- dec cx ;escape mouse overwrite in win95
- int 10h
-
- mov ax,3
- int 33h
- cmp bx,0
- jne M1
-
- mov ax,0b21h ;check keyboard status
- int 21h
- cmp al,0 ;are any characters pending?
- je M0
-
- Game:
-
- mov ax,2 ;hide cursor function
- int 33h
- mov cx,100
-
- G1: mov ax,ds ;segment address
- mov es,ax ;now pointed to by ES
- push cx
- mov di,Screen
- mov cx,32000 ;number of words in video
- xor ax,ax ;clear AX
- rep stosw ;and store in video buffer (cleared)
-
- mov word [X],318 ;X goes from 1 to 318 (0 to 319 excluding boundaries)
- G2: mov word [Y],198 ;Y goes from 1 to 198 (0 to 199 excluding boundaries)
- G3: call Count ;count of neighbors lands in AX
- cmp AX,2 ;survive threshold
- jne G4 ;if not, check for three
- call GetDot ;do we have a current cell here to survive?
- je G4 ;if not, don't set
- call SetDot ;make color 2
- G4: cmp AX,3 ;check generation
- jne G5 ;no spawn if not 3
- call SetDot ;else set color 3
- G5: dec word[Y] ;move up
- jne G3 ;if not at top
- dec word[X] ;move left
- jne G2 ;if not at left
-
- mov ax,0a000h ;video buffer
- mov es,ax
- xor di,di ;destination pointer
-
- mov si,Screen ;source pointer
-
- mov cx,32000
- rep movsw ;copy to video
-
- mov ax,ds ;reset extra segment to data segment
- mov es,ax
-
- pop cx
- loop G1
-
- mov ax,3 ;put video back into text mode
- int 10h
- mov ax,4c00h
- int 21h
-
- GetDot: ;check for cell on screen at coordinates in X and Y
- push ax
- push bx
- push dx
- push es
-
- mov ax,0a000h ;video segment
- mov es,ax ;pointer
- mov ax,[Y] ;y coord
- mov bx,320 ;dots per Y
- mul bx ;DX:AX has answer (DX = 0, AX = row offset)
- add ax,[X] ;add X coordinate
- mov bx,ax ;use BX as pointer
- mov al,[es:bx] ;get
- cmp al,0 ;is cell zero? return in flag
-
- pop es
- pop dx
- pop bx
- pop ax
- ret
-
- SetDot: ;mov al to coordinates in X and Y
- push ax
- push bx
- push dx
-
- push ax ;store data on stack
- mov ax,[Y] ;y coord
- mov bx,320 ;dots per Y
- mul bx ;DX:AX has answer (DX = 0, AX = row offset)
- add ax,[X] ;add X coordinate
- mov bx,ax ;use BX as pointer
- add bx,Screen ;add in offset of screen buffer
- pop ax ;get count value as color
- mov [es:bx],al ;store
-
- pop dx
- pop bx
- pop ax
- ret
-
- Count:
- push bx
- push cx
- push dx
- push es
-
- mov ax,0a000h ;video buffer segment
- mov es,ax
- mov ax,[Y] ;y coord
- mov bx,320 ;dots per Y
- mul bx ;DX:AX has answer (DX = 0, AX = row offset)
- add ax,[X] ;add X coordinate
- mov bx,ax ;use BX as pointer
- xor ax,ax ;clear AX
-
- xor dx,dx ;just a convenient zero
-
- ; 2 3 4
- ; 0 1
- ; 5 6 7
-
- cmp dl,[es:bx-1] ;check left
- je C1 ;if clear, skip add
- inc ax
-
- C1: cmp dl,[es:bx+1] ;check right
- je C2 ;if clear, skip add
- inc ax
-
- C2: cmp dl,[es:bx-321] ;check top left
- je C3 ;if clear, skip add
- inc ax
-
- C3: cmp dl,[es:bx-320] ;check above
- je C4 ;if clear, skip add
- inc ax
-
- C4: cmp dl,[es:bx-319] ;check upper right
- je C5 ;if clear, skip add
- inc ax
-
- C5: cmp dl,[es:bx+319] ;check below left
- je C6 ;if clear, skip add
- inc ax
-
- C6: cmp dl,[es:bx+320] ;check below
- je C7 ;if clear, skip add
- inc ax
-
- C7: cmp dl,[es:bx+321] ;check below right
- je C8 ;if clear, skip add
- inc ax
-
-
- C8: pop es
- pop dx
- pop cx
- pop bx
- ret
-
- section .data
- X dw 0 ;X coordinate during regeneration
- Y dw 0 ;Y coordinate during regeneration
-
- section .bss
- Screen resb 64000 ;copy of screen in mode 13H
;The Game of Life is a cellular automata program, where each pixel on the screen
;will live or die in each generation based upon some arbitrary rules.
;Specifically, if a pixel has three neighbors, it lives to the next generation.
;If an empty cell has two neighbors, it becomes populated in the next generation.
;Otherwise, that pixel gets cleared for the next generation. In this program, we
;generate an initial screen image using the paint program from last class. We
;then make a future image of the video screen in our offscreen buffer, then when
;complete, copy to the video.
; source file for assembling to binary files
; build with:
; nasmw -f bin -o life.com life.asm
org 100h
section .text
mov ax,13h
int 10h ;256 color graphics mode
mov ax,0a000h ;video buffer
mov es,ax ;pointer for segment
xor di,di ;offset
mov cx,32000 ;number of words in video
xor ax,ax ;clear AX
rep stosw ;and store in video buffer
mov ax,1 ;show mouse
int 33h
M0:
mov ax,0b21h ;check keyboard status
int 21h
cmp al,0 ;are any characters pending?
jne Game
mov ax,3 ;get mouse status call
int 33h
cmp bx,0 ;is mouse up
je M0 ;loop till pressed
M1: mov ax,0b21h ;check keyboard status
int 21h
cmp al,0 ;are any characters pending?
jne Game
mov ax,3 ;get fresh copy of mouse coordinates
int 33h
mov ah,0ch ;write dot at coordinate
mov al,1 ;color value
shr cx,1 ;mouse scale offset fix
dec cx ;escape mouse overwrite in win95
int 10h
mov ax,3
int 33h
cmp bx,0
jne M1
mov ax,0b21h ;check keyboard status
int 21h
cmp al,0 ;are any characters pending?
je M0
Game:
mov ax,2 ;hide cursor function
int 33h
mov cx,100
G1: mov ax,ds ;segment address
mov es,ax ;now pointed to by ES
push cx
mov di,Screen
mov cx,32000 ;number of words in video
xor ax,ax ;clear AX
rep stosw ;and store in video buffer (cleared)
mov word [X],318 ;X goes from 1 to 318 (0 to 319 excluding boundaries)
G2: mov word [Y],198 ;Y goes from 1 to 198 (0 to 199 excluding boundaries)
G3: call Count ;count of neighbors lands in AX
cmp AX,2 ;survive threshold
jne G4 ;if not, check for three
call GetDot ;do we have a current cell here to survive?
je G4 ;if not, don't set
call SetDot ;make color 2
G4: cmp AX,3 ;check generation
jne G5 ;no spawn if not 3
call SetDot ;else set color 3
G5: dec word[Y] ;move up
jne G3 ;if not at top
dec word[X] ;move left
jne G2 ;if not at left
mov ax,0a000h ;video buffer
mov es,ax
xor di,di ;destination pointer
mov si,Screen ;source pointer
mov cx,32000
rep movsw ;copy to video
mov ax,ds ;reset extra segment to data segment
mov es,ax
pop cx
loop G1
mov ax,3 ;put video back into text mode
int 10h
mov ax,4c00h
int 21h
GetDot: ;check for cell on screen at coordinates in X and Y
push ax
push bx
push dx
push es
mov ax,0a000h ;video segment
mov es,ax ;pointer
mov ax,[Y] ;y coord
mov bx,320 ;dots per Y
mul bx ;DX:AX has answer (DX = 0, AX = row offset)
add ax,[X] ;add X coordinate
mov bx,ax ;use BX as pointer
mov al,[es:bx] ;get
cmp al,0 ;is cell zero? return in flag
pop es
pop dx
pop bx
pop ax
ret
SetDot: ;mov al to coordinates in X and Y
push ax
push bx
push dx
push ax ;store data on stack
mov ax,[Y] ;y coord
mov bx,320 ;dots per Y
mul bx ;DX:AX has answer (DX = 0, AX = row offset)
add ax,[X] ;add X coordinate
mov bx,ax ;use BX as pointer
add bx,Screen ;add in offset of screen buffer
pop ax ;get count value as color
mov [es:bx],al ;store
pop dx
pop bx
pop ax
ret
Count:
push bx
push cx
push dx
push es
mov ax,0a000h ;video buffer segment
mov es,ax
mov ax,[Y] ;y coord
mov bx,320 ;dots per Y
mul bx ;DX:AX has answer (DX = 0, AX = row offset)
add ax,[X] ;add X coordinate
mov bx,ax ;use BX as pointer
xor ax,ax ;clear AX
xor dx,dx ;just a convenient zero
; 2 3 4
; 0 1
; 5 6 7
cmp dl,[es:bx-1] ;check left
je C1 ;if clear, skip add
inc ax
C1: cmp dl,[es:bx+1] ;check right
je C2 ;if clear, skip add
inc ax
C2: cmp dl,[es:bx-321] ;check top left
je C3 ;if clear, skip add
inc ax
C3: cmp dl,[es:bx-320] ;check above
je C4 ;if clear, skip add
inc ax
C4: cmp dl,[es:bx-319] ;check upper right
je C5 ;if clear, skip add
inc ax
C5: cmp dl,[es:bx+319] ;check below left
je C6 ;if clear, skip add
inc ax
C6: cmp dl,[es:bx+320] ;check below
je C7 ;if clear, skip add
inc ax
C7: cmp dl,[es:bx+321] ;check below right
je C8 ;if clear, skip add
inc ax
C8: pop es
pop dx
pop cx
pop bx
ret
section .data
X dw 0 ;X coordinate during regeneration
Y dw 0 ;Y coordinate during regeneration
section .bss
Screen resb 64000 ;copy of screen in mode 13H
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[MIX10] KEYNOTE DEUXIèME JOURNéE - INTERNET EXPLORER 9, HTML5, VISUAL STUDIO 2010, ODATA[MIX10] KEYNOTE DEUXIèME JOURNéE - INTERNET EXPLORER 9, HTML5, VISUAL STUDIO 2010, ODATA par cyril
Le deuxième keynote du mix fut très riche en contenu. Internet Explorer 9 Juste un après le lancement de Internet Explorer 8, Microsoft a dévoilé les nouveautés de Internet Explorer 9. Désormais, IE supportera HTML5, SVG et CSS3. L'élément ...
Cliquez pour lire la suite de l'article par cyril CERTIFICATIONS BETA .NET 4CERTIFICATIONS BETA .NET 4 par KooKiz
Les inscriptions pour les certifications beta .NET 4 ont commencé. L'inscription est offerte pour les examens suivants : - 71-511, TS: Windows Applications Development with Microsoft .NET Framework 4 - 71-515, TS: Web Applications Development with...
Cliquez pour lire la suite de l'article par KooKiz [MIX 2010] - MICROSOFT TRANSLATOR TECHNOLOGY PREVIEW V2[MIX 2010] - MICROSOFT TRANSLATOR TECHNOLOGY PREVIEW V2 par redo
J'imagine que la plupart d'entre vous connaissent bien et utilisent le service de traduction de Google, mais connaissez-vous celui de Microsoft . Microsoft Translator ? Effectivement, Microsoft nous annoncé le lancement version 2 de la Technologie Preview...
Cliquez pour lire la suite de l'article par redo LANCEMENT EN PREVIEW DE CYCLONE LORS DES TECHDAYS 2010!LANCEMENT EN PREVIEW DE CYCLONE LORS DES TECHDAYS 2010! par MPOWARE
Toutes les vidéos de ce lancement sont en ligne!
Partie I - Intro
http://www.youtube.com/watch?v=LkQzTQ8T6CA
Partie II - Démo 1
http://www.youtube.com/watch?v=drAhYQ7lqvo
Partie III - Démo 2
http://www.youtube.com/watch?v=c8KM_1Gqybc...
Cliquez pour lire la suite de l'article par MPOWARE [WP7] JE NE VEUX PAS D'UN NOUVEL IPHONE[WP7] JE NE VEUX PAS D'UN NOUVEL IPHONE par FREMYCOMPANY
Je pense qu'ils ont besoin d'une piqure de rappel chez Microsoft : c'est bien gentil d'avoir une interface jolie, mais si c'est pour avoir un truc qui ne convainct pas dedans, c'est peine perdue.
---->
Système ouvert ----> Fermé ?
P...
Cliquez pour lire la suite de l'article par FREMYCOMPANY
Forum
RE : CSHARPRE : CSHARP par ghuysmans99
Cliquez pour lire la suite par ghuysmans99
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|