News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

A fast typing toy.

Started by hutch--, May 01, 2017, 10:47:22 PM

Previous topic - Next topic

hutch--

I though this may amuse someone.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    msc equ <50>

entry_point proc

    invoke type_this,"Friends, Romans, countrymen, lend me your ears;",msc
    invoke type_this,"I come to bury Caesar, not to praise him.",msc
    invoke type_this,"The evil that men do lives after them;",msc
    invoke type_this,"The good is oft interred with their bones;",msc

    waitkey " "

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

type_this proc ptxt:QWORD,msdelay:QWORD

    LOCAL .r14  :QWORD
    LOCAL pbuf  :QWORD
    LOCAL buf[8]:BYTE

    mov .r14, r14
    mov pbuf, ptr$(buf)
    mov r14, ptxt
    sub r14, 1

  @@:
    add r14, 1
    mov al, BYTE PTR [r14]
    test al, al
    jz bye
    mov rdx, pbuf
    mov BYTE PTR [rdx], al
    mov BYTE PTR [rdx+1], 0
    invoke StdOut, pbuf
    invoke SleepEx,msdelay,0
    jne @B

  bye:
    invoke StdOut,chr$(13,10)
    mov r14, .r14

    ret

type_this endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

hutch--

Here is a better version, it has had a few things done to reduce the instruction count in the typing loop but it probably does not matter as there are API calls in the loop code. Zip file attached.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    msc equ <30>    ; milliseconds delay between characters

entry_point proc

    invoke type_this,"The time has come, the Walrus said,",msc
    invoke type_this,"To talk of many things.",msc
    invoke type_this,"Of shoes and ships and sealing-wax,",msc
    invoke type_this,"Of cabbages and kings.",msc
    invoke type_this,"And why the sea is boiling hot,",msc
    invoke type_this,"And whether pigs have wings.",msc

    waitkey " "

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

type_this proc ptxt:QWORD,msdelay:QWORD

    LOCAL .r14  :QWORD
    LOCAL .r15  :QWORD
    LOCAL pbuf  :QWORD
    LOCAL buf[8]:BYTE

    mov .r14, r14               ; preserve r14 & r15
    mov .r15, r15

    mov pbuf, ptr$(buf)         ; set pointer to "buf"
    mov r15, pbuf               ; load r15 outside of the loop
    mov r14, ptxt               ; load text address into r14
    sub r14, 1

  @@:
    add r14, 1
    movzx rax, BYTE PTR [r14]   ; read each BYTE into AL
    test rax, rax               ; exit loop on zero terminator
    jz bye
    mov BYTE PTR [r15], al      ; load AL into 1st BYTE of pbuf
    invoke StdOut, pbuf         ; output single character to console
    invoke SleepEx,msdelay,0    ; set delay between characters
    jne @B

  bye:
    invoke StdOut,chr$(13,10)   ; append the CRLF at the end of the line

    mov r14, .r14               ; restore r14 & r15
    mov r15, .r15

    ret

type_this endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

Magnum

Quote from: hutch-- on May 01, 2017, 10:47:22 PM
I though this may amuse someone.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    msc equ <50>

entry_point proc

    invoke type_this,"Friends, Romans, countrymen, lend me your ears;",msc
    invoke type_this,"I come to bury Caesar, not to praise him.",msc
    invoke type_this,"The evil that men do lives after them;",msc
    invoke type_this,"The good is oft interred with their bones;",msc

    waitkey " "

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

type_this proc ptxt:QWORD,msdelay:QWORD

    LOCAL .r14  :QWORD
    LOCAL pbuf  :QWORD
    LOCAL buf[8]:BYTE

    mov .r14, r14
    mov pbuf, ptr$(buf)
    mov r14, ptxt
    sub r14, 1

  @@:
    add r14, 1
    mov al, BYTE PTR [r14]
    test al, al
    jz bye
    mov rdx, pbuf
    mov BYTE PTR [rdx], al
    mov BYTE PTR [rdx+1], 0
    invoke StdOut, pbuf
    invoke SleepEx,msdelay,0
    jne @B

  bye:
    invoke StdOut,chr$(13,10)
    mov r14, .r14

    ret

type_this endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end


Sorry, but I am a perfectionist.

Thought has a "t" on the end.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

I am also a perfectionist: How does one call somebody who quotes over 60 lines of text in order to complain about one single line?

(hint: the word starts with "tr" and ends with "oll").

Magnum

It is late.

Can you simplify your answer ?

Have you had Alaskan King Crab with butter ?



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

hutch--

If all you have to say is a comment about a typo (missing "t") then you don't have much to say but then that is normal for Andy.

> Have you had Alaskan King Crab with butter ?

Have you been sniffing gasoline to say something that stupid ? Perhaps a therapeutic dose of loco weed.  :P

I post the CODE for people who write software who may have been interested, not to listen to drivel.