Search code examples
screensaverfasm

Fasm: How to move a string in x and y direction


I want to output a string say for example "hello", and I want to put that string into motion by moving it to x or y direction. How to do it using fasm ? Thank you.


Solution

  • To create the illusion of a string moving, you write the string on a selected position and shortly after you fill the same place on the screen with an equal amount of space characters.
    Having done that, you're ready to re-write the string at a position slightly to the left or to the right or above or below the current position.

    Here you can find info about the BIOS SetCursor function.

    Example starting from the middle of the 80x25 textscreen:

     mov  dx, 0C28h ;Row in DH is 12, Column in DL is 40
     call ShowString
     mov  dx, 0D29h ;Row in DH is 13, Column in DL is 41
     call ShowString
     mov  dx, 0E2Ah ;Row in DH is 14, Column in DL is 42
     call ShowString
     mov  dx, 0F2Bh ;Row in DH is 15, Column in DL is 43
     call ShowString
    
    ---
    
    ShowString:
     mov  bh, 0     ;Display page 0
     mov  ah, 02h   ;Set Cursor
     int  10h
     push dx
    
     mov  dx, String
     mov  ah, 09h
     int  21h
    
     !!! Here you wait a bit !!!
    
     pop  dx
     mov  ah, 02h   ;Set Cursor
     int  10h
    
     mov  dx, White
     mov  ah, 09h
     int  21h
     ret
    
    
     String db 'Title', '$'
     White  db '     ', '$'