flat assembler
Message board for the users of flat assembler.

Index > DOS > TASM to FASM. Snake.

Author
Thread Post new topic Reply to topic
S3nsitive



Joined: 11 Apr 2011
Posts: 2
S3nsitive
Hello! I need help! How to translate that TASM code in FASM? At me it turns out nothing Sad

Code:
        .model     tiny
        .code
        .186                     
        org        100h         

start:
        mov        ax,cs         
        add        ax,1000h      
        mov        ds,ax         
                                
        push       0A000h       
        pop        es         
        mov        ax,13h        
        int        10h

        mov        di,320*200
        mov        cx,600h       
        rep        stosb         
                                 
        xor        si,si   
        mov        bp,10  
        jmp        init_food 

main_cycle:
        call delay
        mov        ah,1                
        int        16h
        jz         short no_keypress 
        xor        ah,ah             
        int        16h                 
        cmp        ah,48h             
        jne        short not_up
        mov        word ptr cs:move_direction,-320

not_up:
        cmp        ah,50h             
        jne        short not_down
        mov        word ptr cs:move_direction,320

not_down:
        cmp        ah,4Bh 
        jne        short not_left
        mov        word ptr cs:move_direction,-1

not_left:
        cmp        ah,4Dh   
        jne        short no_keypress
        mov        word ptr cs:move_direction,1

no_keypress:
        and        bp,bp     
        jnz        short advance_head  
        lodsw   
        xchg       bx,ax
        mov        byte ptr es:[bx],0 
        mov        bx,ax
        inc        bp

advance_head:
        dec        bp
        add        bx,word ptr cs:move_direction
        mov        al,es:[bx]  
        and        al,al            
        jz         short move_worm    
        cmp        al,0Dh     
        je         short grow_worm   
        mov        ax,3      
        int        10h     
        retn    

move_worm:
        mov        [di],bx    
        inc        di
        inc        di    
        mov        byte ptr es:[bx],09 
        cmp        byte ptr cs:eaten_food,1
        je         if_eaten_food 
        jmp        short main_cycle 

grow_worm:
        push       bx             
        mov        bx,word ptr cs:food_at 
        xor        ax,ax            
        call       draw_food          
        call       random           
        and        ax,3Fh          
        mov        bp,ax  
        mov        byte ptr cs:eaten_food,1 
        pop        bx              
        jmp        short move_worm  

if_eaten_food:          
        mov        byte ptr cs:eaten_food,0

init_food:                            
        push       bx                 

make_food:
        call       random      
        and        ax,0FFFEh        
        mov        bx,ax      
        xor        ax,ax
        cmp        word ptr es:[bx],ax
        jne        make_food 
        cmp        word ptr es:[bx+320],ax 
        jne        make_food           
        mov        word ptr cs:food_at,bx 
        mov        ax,0D0Dh     
        call       draw_food    
        pop        bx
        jmp        main_cycle

delay proc
        pusha
        mov ah, 0
        int 1ah
        mov bx,dx
        add bx, 1 
    d1:
        int 1ah
        cmp dx, bx
        jb d1
        popa
     ret
delay endp

draw_food:
        mov        es:[bx],ax
        mov        word ptr es:[bx+320],ax
        retn

random: mov        ax,word ptr cs:seed
        mov        dx,8E45h
        mul        dx
        inc        ax
        mov        cs:word ptr seed,ax
        retn

eaten_food         db            0
move_direction     dw            1   ;1 - left, -1 - right, 320 - down, -320 - up
seed:                                
food_at equ        seed+2           
        
end        start
    
Post 18 May 2011, 15:40
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Hi,

Try now,

Code:


        org        100h

start:
        mov        ax,cs
        add        ax,1000h
        mov        ds,ax

        push       0A000h
        pop        es
        mov        ax,13h
        int        10h

        mov        di,320*200
        mov        cx,600h
        rep        stosb

        xor        si,si
        mov        bp,10
        jmp        init_food

main_cycle:
        call delay
        mov        ah,1
        int        16h
        jz         short no_keypress
        xor        ah,ah
        int        16h
        cmp        ah,48h
        jne        short not_up
        mov        word [cs:move_direction],-320

not_up:
        cmp        ah,50h
        jne        short not_down
        mov        word [cs:move_direction],320

not_down:
        cmp        ah,4Bh
        jne        short not_left
        mov        word [cs:move_direction],-1

not_left:
        cmp        ah,4Dh
        jne        short no_keypress
        mov        word [cs:move_direction],1

no_keypress:
        and        bp,bp
        jnz        short advance_head
        lodsw
        xchg       bx,ax
        mov        byte [es:bx],0
        mov        bx,ax
        inc        bp

advance_head:
        dec        bp
        add        bx,word [cs:move_direction]
        mov        al,[es:bx]
        and        al,al
        jz         short move_worm
        cmp        al,0Dh
        je         short grow_worm
        mov        ax,3
        int        10h
        ret

move_worm:
        mov        [di],bx
        inc        di
        inc        di
        mov        byte [es:bx],09
        cmp        byte [cs:eaten_food],1
        je         if_eaten_food
        jmp        short main_cycle

grow_worm:
        push       bx
        mov        bx,word [cs:food_at]
        xor        ax,ax
        call       draw_food
        call       random
        and        ax,3Fh
        mov        bp,ax
        mov        byte [cs:eaten_food],1
        pop        bx
        jmp        short move_worm

if_eaten_food:
        mov        byte [cs:eaten_food],0

init_food:
        push       bx

make_food:
        call       random
        and        ax,0FFFEh
        mov        bx,ax
        xor        ax,ax
        cmp        word [es:bx],ax
        jne        make_food
        cmp        word [es:bx+320],ax
        jne        make_food
        mov        word [cs:food_at],bx
        mov        ax,0D0Dh
        call       draw_food
        pop        bx
        jmp        main_cycle

delay:
        pusha
        mov ah, 0
        int 1ah
        mov bx,dx
        add bx, 1
    d1:
        int 1ah
        cmp dx, bx
        jb d1
        popa
             ret


draw_food:
        mov        [es:bx],ax
        mov        word [es:bx+320],ax
        retn

random: mov        ax,word [cs:seed]
        mov        dx,8E45h
        mul        dx
        inc        ax
        mov        word [seed],ax
        ret

eaten_food         db            0
move_direction     dw            1   ;1 - left, -1 - right, 320 - down, -320 - up
seed:
food_at dw        seed+2
    
Post 18 May 2011, 16:00
View user's profile Send private message Reply with quote
S3nsitive



Joined: 11 Apr 2011
Posts: 2
S3nsitive
Oh thx!!! U r genius! Wink
Post 18 May 2011, 16:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.