PDA

Click to See Complete Forum and Search --> : Cellular Automata - Simple stuff...


Ecniv
Jan 2nd, 2001, 12:05 PM
.MODEL SMALL
.STACK 200h
.DATA
;----Texts to display----
FirstDisp DB 10,13,"Welcome to my attempt at cellular automata."
DB 10,13,"The basic concept is that depending on the total of the"
DB 10,13,"three colours in the pixels above the current pixel"
DB 10,13,"determines what the current pixels colour will be."
DB 10,13,10,13,"Written by Vincent Buckner - 13/11/00"
DB 10,13,"Enjoy...",10,13,"Press any key to continue...$"
PlsEnter DB 10,13,"Please enter a number...(0-9)...$"

;----Variables----
xpos DW ?
ypos DW ?

;----Constants----
ScrWidthp EQU 321
ScrWidth EQU 320
ScrHeight EQU 200

.CODE

PrintText MACRO TextHere
;----Macro to print to screen using text in data
;----goes through string until $ is found
MOV AX, Seg TextHere
MOV DS, AX
MOV DX, OFFSET TextHere
MOV AH, 09h
INT 21h
ENDM PrintText

PrintToo MACRO TextHere
;----Another macro to test printing on the screen
;----Either will do what is required, although this one takes more
;----instructions so MUST be slower... unless the interrupt is faster...
;----CX is the number of chars to print...
MOV AX, Seg TextHere
MOV DS, AX
MOV DX, OFFSET TextHere
MOV CX, 0018h
MOV BX, 0001h
MOV AH, 40h
INT 21h
ENDM


;*****\/**********\/********START**************\/**********\/*********
START:

;----Changes the mode to clear screen (although there is prolly a clear screen interrupt)
;----Print up first screen msg
;----wait for a keypress
MOV AX,0003h
INT 10h
PrintText FirstDisp
MOV AH, 01h
INT 21h

;----Change screen mode to 320x200
MOV AX,0013h
INT 10h

;----Set to screen
MOV AX,0A000h
MOV ES,AX

;----Plot a colour on the top row
MOV DI,160
MOV AL,01h
STOSB

; JMP ExitToDos

;----set the destination to one row down
MOV xpos,0h
MOV ypos,1h

;----Set the screen source
MOV AX,0A000h
MOV ES,AX

MainLoop:
;----Then move to the dest to READ
XOR SI,SI
MOV AX,ypos
MOV BX,AX
SHL AX,06h ;these two shifts should get to 320...
SHL BX,08h
ADD SI,BX
ADD SI,AX
MOV AX,xpos
ADD SI,AX
SUB SI,ScrWidth
MOV DI,SI

;----Pull byte
;----Store in BX (Temp)
;----Pull next two bytes adding to the one held in BX
XOR BX,BX
LODSB
STOSB
MOV BX,AX
LODSB
STOSB
ADD BX,AX
LODSB
STOSB
ADD BX,AX

;----Set initial colour to be 0
;----Chooses which colour to display here
MOV AX,00h
CMP BX,01h
JL ChoosenColour
MOV AL,03h

ChoosenColour:
;----Set destination for screen to WRITE
XOR DI,DI
MOV CX,ypos
MOV BX,CX
SHL CX,06h ;these two shifts should get to 320...
SHL BX,08h
ADD DI,BX
ADD DI,CX
MOV CX,xpos
ADD DI,CX
STOSB

;----Move to next destination pixel
;----Then store...
MOV AX,xpos
INC AX
MOV xpos,AX

CMP AX,ScrWidth
JL CheckForButton

JMP ExitToDos

MOV xpos,0h
MOV AX,ypos
INC AX
MOV ypos,AX

CMP AX,ScrHeight
JGE ExitToDos

CheckForButton:
;----Check for a button press
; MOV AH,01h
; INT 16H
; JNZ ExitToDos

JMP MainLoop

ExitToDos:
;---------\/------------EXIT-BIT---------\/---------------------
;----Wait for keypress and
;----Change the screen too
;----Exit to dos
MOV AH, 01h
INT 21h
MOV AX,0003h
INT 10h
MOV AX, 4C00h
INT 21h
END START

/\ This is the code I have used, but it does NOT seem to be reading from where it is writing (the code is modified atm to run just one line and rewrite back whatever it reads......)

Can anyone please help ??

Vince