vendredi 18 mai 2018

assembly project || how to move a character with random?

i need help to my assembly project. pls help.

look at my code and tell me pls how can i move my ghosts with random?

I built a character of spirit and now I want to make her move in random. How do I do this?

; This program demonstrait how to print an image on the screen in graphic mode IDEAL MODEL small

; Colors 
cBlack              EQU 0
cOrange             EQU 2Ah
cBlue               EQU 53
cCyan               EQU 51
cYellow             EQU 14
cRed                EQU 4
FrameColor          EQU 50
ScreenWidth         EQU 0140h ; 320 
ScreenHeight        EQU 00C8h ; 200

TopLeftCornetLine   EQU 014h
TopLeftCornetCol    EQU 0100Fh

  TopLeftCornetLine1   EQU 030h
  TopLeftCornetCol1    EQU 09Fh

  TopLeftCornetLine2   EQU 046h
  TopLeftCornetCol2    EQU 09Fh

  TopLeftCornetLine3   EQU 60h
  TopLeftCornetCol3    EQU 010Fh

  TopLeftCornetLine4   EQU 074h
  TopLeftCornetCol4    EQU 09Fh

DATASEG

TopLeftLine dw ? TopLeftCol dw ?

TopLeftLineblue dw ? TopLeftColblue dw ?

TopLeftLinered dw ? TopLeftColred dw ?

TopLeftLineyellow dw ? TopLeftColyellow dw ?

NumOfLines equ 12

pac db 480 dup(0)
db 10 dup(0), 8 dup (cBlack),12 dup (cYellow),8 dup (cBlack), 10 dup(0)
db  10 dup(0),4 dup (cBlack),20 dup (cYellow),4 dup (cBlack), 10 dup(0)
db  10 dup(0),8 dup (cYellow),4 dup (cBlue) ,16 dup (cYellow), 10 dup(0)
db  10 dup(0),28 dup (cYellow), 10 dup(0)
db 10 dup(0), 28 dup (cYellow), 10 dup(0)
db 10 dup(0), 8 dup (cBlack),20 dup (cYellow), 10 dup(0)      
db 10 dup(0), 8 dup (cBlack),20 dup (cYellow)  , 10 dup(0)
db  10 dup(0),28 dup (cYellow), 10 dup(0)
db  10 dup(0),28 dup (cYellow), 10 dup(0)
db  10 dup(0),28 dup (cYellow), 10 dup(0)
db 10 dup(0), 4 dup (cBlack),20 dup (cYellow),4 dup (cBlack), 10 dup(0)
db  10 dup(0),8 dup (cBlack),12 dup (cYellow),8 dup (cBlack), 10 dup(0)
db 480 dup(0)


   NumOfLines1 db 11

badpacred db 8 dup (cBlack),12 dup (cRed),8 dup (cBlack)
db 4 dup (cBlack),20 dup (cRed),4 dup (cBlack)
db 28 dup (cRed)
db ,4 dup (cRed),8 dup (cYellow),4 dup (cRed),8 dup (cYellow),4 dup (cRed)
db 28 dup (cRed)
db 28 dup (cRed)
db 28 dup (cRed)
db 28 dup (cRed)
db 28 dup (cRed)
db 28 dup (cRed)
db 4 dup (cRed),4 dup (cBlack),4 dup (cRed),4 dup (cBlack),4 dup (cRed),4 dup (cBlack),4 dup (cRed)



    NumOfLines2 db 11

badpacblue db 8 dup (cBlack),12 dup (cBlue),8 dup (cBlack)
db 4 dup (cBlack),20 dup (cBlue),4 dup (cBlack)
db 28 dup (cBlue)
db ,4 dup (cBlue),8 dup (cYellow),4 dup (cBlue),8 dup (cYellow),4 dup (cBlue)
db 28 dup (cBlue)
db 28 dup (cBlue)
db 28 dup (cBlue)
db 28 dup (cBlue)
db 28 dup (cBlue)
db 28 dup (cBlue)
db 4 dup (cBlue),4 dup (cBlack),4 dup (cBlue),4 dup (cBlack),4 dup (cBlue),4 dup (cBlack),4 dup (cBlue)

NumOfLines3 db 11

badpacyellow db 8 dup (cBlack),12 dup (cYellow),8 dup (cBlack)
db 4 dup (cBlack),20 dup (cYellow),4 dup (cBlack)
db 28 dup (cYellow)
db ,4 dup (cYellow),8 dup (cBlack),4 dup (cYellow),8 dup (cBlack),4 dup (cYellow)
db 28 dup (cYellow)
db 28 dup (cYellow)
db 28 dup (cYellow)
db 28 dup (cYellow)
db 28 dup (cYellow)
db 28 dup (cYellow)
db 4 dup (cYellow),4 dup (cBlack),4 dup (cYellow),4 dup (cBlack),4 dup (cYellow),4 dup (cBlack),4 dup (cYellow)

NumOfLines4 db 12

blackk db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)
db 28 dup (cBlack)

ends

STACK 100h

CODESEG jmp start

; ------------------------------- ; change screen mode to text mode ; ------------------------------- proc InitText push ax mov ah,0 mov al,3h ; text mode 80X25 int 10h pop ax ret endp

; ---------------------------------- ; change screen mode to graphic mode ; ---------------------------------- proc InitGraphics push ax mov ax , 13H int 10H ; graphical mode mov ax , 0A000H mov es , ax mov ax , 0 ; mouse initilization int 33h mov ax , 1 int 33h ; show mouse pointer pop ax ret endp

proc printimg mov ax,[TopLeftLine] mov bx,ScreenWidth mul bx add ax,[TopLeftCol] mov di,ax mov bx,32

cld ; set the dirction of copy of the image from left to right 


; Copy the pixcells one by one to their position on the screen
; The screen address itself is in register ES. register DI will hold the place on screen 
; The algorithm is to use the "rep movsb" to copy a line of pixcells of the image, to the screen
; then' update register DI to point to the position were the next line is to be printed
; then, continue and print the pixcells of the next line
;

LoopCircle_NextLine: mov cx, 48 ; How many times should the "rep movsb" should iterate push di ; Save in stack the calculated position indicating the begining of the current line

rep  movsb      ; copies bytes from si(image) to di (screen)

pop  di         ; di was changed during the movesb. I change it back to pint to the begin of the line
add  di, ScreenWidth ; by adding ScreenWidth (320)' I am moving the di to point to the next line
dec  bx  ; Check if I wrote all the lines of the image
jnz  LoopCircle_NextLine    ; IF there are still pixcells to print on the screen(image not ended), loop to next line

ret

endp

start: mov ax,@data mov ds,ax mov es,ax

call InitGraphics

;       middel of work...........................................................................................
mov [TopLeftLine],TopLeftCornetLine   
mov [TopLeftcol], TopLeftCornetCol 
mov [TopLeftLineblue],TopLeftCornetLine2
 mov [TopLeftColblue],TopLeftCornetCol2
 mov[TopLeftLinered],TopLeftCornetLine1
 mov[TopLeftColred],TopLeftCornetCol1
 mov[TopLeftLineyellow],TopLeftCornetLine3
 mov[TopLeftColyellow],TopLeftCornetCol3


MainLoop:
lea  si, [pac]
call printimg

call badpacyellow1
call badpacblue1
call badpacrad1

WaitForInput: ;call random mov ah,01h int 16h jz WaitForInput

mov ah,0 int 16h

cmp ah,4Bh je GoLeft

cmp ah,4Dh
je GoRight

cmp ah,48h je GoUp

cmp ah,50h

je GoDown

call moveblue

jmp WaitForInput

GoUp: sub [TopLeftLine],10 lea si, [pac] call printimg jmp WaitForInput GoDown: add [TopLeftLine],10 lea si, [pac] call printimg jmp WaitForInput GoLeft: sub [TopLeftCol],10 lea si, [pac] call printimg jmp WaitForInput GoRight: add [TopLeftCol],10 lea si, [pac] call printimg jmp WaitForInput

;GoUp1:
;sub [TopLeftCornetLine4],10
;call badpacyellow1
;call printimg

;GoDown1:
;add [TopLeftCornetLine4],10
;call badpacyellow1
;call printimg
; 
;GoLeft1:
;sub [TopLeftCornetCol4],10
;call badpacyellow1
;call printimg

;GoRight1:
;add [TopLeftCornetCol4],10
;call badpacyellow1
;call printimg






;random: 
;MOV AH, 00h  ; interrupts to get system time        
;INT 1AH      ; CX:DX now hold number of clock ticks since midnight      

;mov  ax, dx
;xor  dx, dx
;mov  cx, 4    
;div  cx       ; here dx contains the remainder of the division - from 0 to 9
;cmp dl, 0
;je GoLeft1
;cmp dl, 1
;je GoUp1
;cmp dl, 3
;je GoRight1
;cmp dl, 2
;je GoDown1

;  ret
 ;......................................................................................




 badpacrad1:
mov  di, ScreenWidth*TopLeftCornetLine1+TopLeftCornetCol1 ;offset on screen to start printing the image. Top left corner
lea  si, [badpacred]  

cld ; set the dirction of copy of the image from left to right 


; Copy the pixcells one by one to their position on the screen
; The screen address itself is in register ES. register DI will hold the place on screen 
; The algorithm is to use the "rep movsb" to copy a line of pixcells of the image, to the screen
; then' update register DI to point to the position were the next line is to be printed
; then, continue and print the pixcells of the next line
;
LoopCircle_NextLine1:
mov  cx, 28     ; How many times should the "rep movsb" should iterate
push di         ; Save in stack the calculated position indicating the begining of the current line

rep  movsb      ; copies bytes from si(image) to di (screen)

pop  di         ; di was changed during the movesb. I change it back to pint to the begin of the line
add  di, ScreenWidth ; by adding ScreenWidth (320)' I am moving the di to point to the next line
dec  [NumOfLines1]   ; Check if I wrote all the lines of the image
jnz  LoopCircle_NextLine1    ; IF there are still pixcells to print on the screen(image not ended), loop to next line
ret


badpacblue1:
mov  di, ScreenWidth*TopLeftCornetLine2+TopLeftCornetCol2 ;offset on screen to start printing the image. Top left corner
lea  si, [badpacblue]  

cld ; set the dirction of copy of the image from left to right 


; Copy the pixcells one by one to their position on the screen
; The screen address itself is in register ES. register DI will hold the place on screen 
; The algorithm is to use the "rep movsb" to copy a line of pixcells of the image, to the screen
; then' update register DI to point to the position were the next line is to be printed
; then, continue and print the pixcells of the next line
;
LoopCircle_NextLine2:
mov  cx, 28     ; How many times should the "rep movsb" should iterate
push di         ; Save in stack the calculated position indicating the begining of the current line

rep  movsb      ; copies bytes from si(image) to di (screen)

pop  di         ; di was changed during the movesb. I change it back to pint to the begin of the line
add  di, ScreenWidth ; by adding ScreenWidth (320)' I am moving the di to point to the next line
dec  [NumOfLines2]   ; Check if I wrote all the lines of the image
jnz  LoopCircle_NextLine2    ; IF there are still pixcells to print on the screen(image not ended), loop to next line

badpacyellow1:    
 mov  di, ScreenWidth*TopLeftCornetLine3+TopLeftCornetCol3 ;offset on screen to start printing the image. Top left corner
 lea  si, [badpacyellow]  

cld ; set the dirction of copy of the image from left to right 
ret

; Copy the pixcells one by one to their position on the screen
; The screen address itself is in register ES. register DI will hold the place on screen 
; The algorithm is to use the "rep movsb" to copy a line of pixcells of the image, to the screen
; then' update register DI to point to the position were the next line is to be printed
; then, continue and print the pixcells of the next line
;
LoopCircle_NextLine3:
mov  cx, 28     ; How many times should the "rep movsb" should iterate
push di         ; Save in stack the calculated position indicating the begining of the current line

rep  movsb      ; copies bytes from si(image) to di (screen)

pop  di         ; di was changed during the movesb. I change it back to pint to the begin of the line
add  di, ScreenWidth ; by adding ScreenWidth (320)' I am moving the di to point to the next line
dec  [NumOfLines3]   ; Check if I wrote all the lines of the image
jnz  LoopCircle_NextLine3    ; IF there are still pixcells to print on the screen(image not ended), loop to next line
mov [NumOfLines3] , 11
ret


 blackk1:    
 mov  di, ScreenWidth*TopLeftCornetLine4+TopLeftCornetCol4 ;offset on screen to start printing the image. Top left corner
 lea  si, [blackk]  

cld ; set the dirction of copy of the image from left to right 
ret

; Copy the pixcells one by one to their position on the screen
; The screen address itself is in register ES. register DI will hold the place on screen 
; The algorithm is to use the "rep movsb" to copy a line of pixcells of the image, to the screen
; then' update register DI to point to the position were the next line is to be printed
; then, continue and print the pixcells of the next line
;
LoopCircle_NextLine4:
mov  cx, 28     ; How many times should the "rep movsb" should iterate
push di         ; Save in stack the calculated position indicating the begining of the current line

rep  movsb      ; copies bytes from si(image) to di (screen)

pop  di         ; di was changed during the movesb. I change it back to pint to the begin of the line
add  di, ScreenWidth ; by adding ScreenWidth (320)' I am moving the di to point to the next line
dec  [NumOfLines4]   ; Check if I wrote all the lines of the image
jnz  LoopCircle_NextLine4    ; IF there are still pixcells to print on the screen(image not ended), loop to next line
mov [NumOfLines4] , 12
ret


; Wait for user to press a key
mov ah,1
int 21h

; move back to text mode
call InitText

; call the operating system to terminate this program
mov ax, 4c00h
int 21h  

ends

end start




Aucun commentaire:

Enregistrer un commentaire