Author Topic: A fast typing toy.  (Read 550 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4886
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
A fast typing toy.
« 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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4886
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: A fast typing toy.
« Reply #1 on: May 03, 2017, 01:36:20 AM »
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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Magnum

  • Member
  • *****
  • Posts: 2237
Re: A fast typing toy.
« Reply #2 on: May 03, 2017, 04:44:12 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-16.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

  • Member
  • *****
  • Posts: 7666
  • Assembler is fun ;-)
    • MasmBasic
Re: A fast typing toy.
« Reply #3 on: May 03, 2017, 05:55:23 PM »
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

  • Member
  • *****
  • Posts: 2237
Re: A fast typing toy.
« Reply #4 on: May 03, 2017, 06:01:34 PM »
It is late.

Can you simplify your answer ?

Have you had Alaskan King Crab with butter ?



Take care,
                   Andy

Ubuntu-mate-16.04-desktop-amd64

http://www.goodnewsnetwork.org

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4886
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: A fast typing toy.
« Reply #5 on: May 03, 2017, 07:59:39 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: