Author Topic: Miscellaneous snippets  (Read 2465 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8251
  • Assembler is fun ;-)
    • MasmBasic
GetRandomStrings
« Reply #30 on: March 15, 2018, 01:30:08 AM »
Could be useful for testing sort algos etc:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Dll "RandomStrings"                   ; the DLL must be in the same folder
  Declare RandomString
  .Repeat
        For_ ecx=0 To 5
                Print RandomString(), " "
        Next
        Inkey cfm$("- more (no=n)?\n")
  .Until eax=="n" || eax==VK_ESCAPE
EndOfCode


Output:
Code: [Select]
imprisoning barked channel superstitious practical spectre - more (no=n)?
currants shower agitation lions motherly forces - more (no=n)?
negus proofs devil chose observation individuals - more (no=n)?
quarrelled whistled place commanded stipulation cannot - more (no=n)?
deeds settled taught verdict unsocial goeth - more (no=n)?
nefarious herald extinguishes accounted system military - more (no=n)?
worse colouring attacks transfixed hearts binding - more (no=n)?
instruments rally singly sword until profit - more (no=n)?
tranquilly luring convinced unchecked trade hears - more (no=n)?
violent packet sternly tearing kneeled crumbled - more (no=n)?
... etc ...

anunitu

  • Member
  • ****
  • Posts: 992
Re: Miscellaneous snippets
« Reply #31 on: March 15, 2018, 03:33:13 AM »
i am thinking JJ is the REAL MASM Wizard for sure.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8251
  • Assembler is fun ;-)
    • MasmBasic
Re: Miscellaneous snippets
« Reply #32 on: March 15, 2018, 05:37:33 AM »
Thanks - too much honour :icon_redface:

Here is version 2, with pseudo and real random modes (and 20,000 words for choice):

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Dll "RandomStrings"                   ; the DLL must be in the same folder
  Declare RandomString, 1
  .Repeat
        For_ ecx=0 To 5
                Print RandomString(0), " "      ; 0=pseudo, 1=real random
        Next
        Inkey cfm$("- more (no=n)?\n")
  .Until eax=="n" || eax==VK_ESCAPE
EndOfCode


In mode 0, the sequence is always identical. It looks random, and is random according to some popular measures of randomness, but you'll always see the same strings. This is particular useful if, for example, your sort algo stumbles over a specific word, and you want to debug that event. It's also a bit faster - in "real" mode, one Million strings need almost one second on my i5. The pseudo mode is 70 times faster.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8251
  • Assembler is fun ;-)
    • MasmBasic
Tweety rotates
« Reply #33 on: April 26, 2018, 12:24:16 PM »
Little demo for image rotation (strangely enough, this GdiPlus function has never been used in this forum ::)):

GuiParas equ "Image rotation demo", w400, h440
include \masm32\MasmBasic\Res\MbGui.asm
  GuiImageCallback Rotate       ; user-defined function
  SetGlobals halfWidth, halfHeight, REAL4:rotateAngle, movX, movY
Event Paint
  imul eax, GuiWidth, 100       ; width*100/128
  sar eax, 8
  add eax, 20
  mov halfWidth, eax
  imul eax, GuiHeight, 100      ; height*100/128
  sar eax, 8
  mov halfHeight, eax
  GuiImage 99, 0, 0, halfWidth, halfHeight      ; res ID, x, y, w, h 
  GuiCls                               ; trigger next paint event
EndOfEvents
Rotate:
  fild halfWidth                        ; an integer
  fadd FP4(35.0)                        ; add a fixed x offset
  fstp movX                             ; Gdi+ needs a float
  fild halfHeight
  fadd FP4(32.0)
  fstp movY
  gdi+ GdipTranslateWorldTransform, giGraphics, movX, movY, MatrixOrderPrepend  ; move to the middle
  gdi+ GdipRotateWorldTransform, giGraphics, rotateAngle, MatrixOrderPrepend    ; rotate
  fld rotateAngle                       ; add one degree for next paint event
  fadd FP4(1.0)
  fstp rotateAngle
  ret
GuiEnd