Long hello

For general discussion related FlowStone
Post Reply
User avatar
HughBanton
Posts: 268
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire
Contact:

Long hello

Post by HughBanton »

Oh wow .. I didn't realise this forum was functioning again. I've periodically been checking but always either got a '404' or else it wouldn't let me in, password lockout or whatever.

I believe I can claim to be one of the earliest members here, 2008 it sez - although I dare say I'll get told otherwise ;-) However I did go silent between 2010 & 2015 I recall.

Well here we are. Just like the old days!

So now I'd better think of something useful to contribute then :lol:
RJHollins
Posts: 1574
Joined: Thu Mar 08, 2012 7:58 pm

Re: Long hello

Post by RJHollins »

welcome back Hugh :)
User avatar
HughBanton
Posts: 268
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire
Contact:

Re: Long hello

Post by HughBanton »

Thanks!
Here's some Ruby that's potentially useful. I'll explain after ..


################################
require "Win32API"
OpenClipboard = Win32API.new("user32", "OpenClipboard", "L", "I")
EmptyClipboard = Win32API.new("user32", "EmptyClipboard", "", "I")
SetClipboardData = Win32API.new("user32", "SetClipboardData", "IL", "I")
CloseClipboard = Win32API.new("user32", "CloseClipboard", "", "I")
GlobalAlloc = Win32API.new("kernel32", "GlobalAlloc", "II", "I")
GlobalLock = Win32API.new("kernel32", "GlobalLock", "I", "I")
GlobalUnlock = Win32API.new("kernel32", "GlobalUnlock", "I", "I")
RtlMoveMemory = Win32API.new("kernel32", "RtlMoveMemory", "IPI", "V")
GMEM_MOVEABLE = 0x0002
CF_TEXT = 1
#################################

def copy_to_clipboard(text)
OpenClipboard.call(0)
EmptyClipboard.call

# Allocate global memory for the string + null terminator
mem = GlobalAlloc.call(GMEM_MOVEABLE, text.bytesize + 1)
ptr = GlobalLock.call(mem)

# Copy bytes into the allocated memory
RtlMoveMemory.call(ptr, text, text.bytesize)

GlobalUnlock.call(mem)
SetClipboardData.call(CF_TEXT, mem)
CloseClipboard.call
end

# removes all //comment lines UNLESS they contain
# a 'keep word'. Edit keep_words as required.

keep_words = [
"Assignment",
"Hop",
"Loop",
# "Operator",
# "Comparison",
# "Cast",
# "Function",
"NOTE"
]

lines = @text.split(/\r?\n/)
filtered = []
filtered << "// Paste text to an ASSEMBLER prim : " << ""

lines.each_with_index do |line, i|
s = line.strip
is_comment = s.start_with?("//")
keep_comment = keep_words.any? { |w| s.include?(w) }

if is_comment && !keep_comment
# Remove the comment & remove previous line if it's blank
if !filtered.empty? && filtered.last.strip.empty?
filtered.pop
end
next
end

filtered << line
end

result = filtered.join("\n")
output result # no longer required
copy_to_clipboard(result) # direct to Windows clipboard
User avatar
HughBanton
Posts: 268
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire
Contact:

Re: Long hello

Post by HughBanton »

OK .. wot it does.

When converting DSP to assembler you traditionally attach a text prim to the DSP's 'S' output, copy the entire text contents and then paste inside an Assem prim. Very neat, but can get tedious.

First thing .. the result is quite verbose, lots of automatic comments are generated. That's very useful when you're just starting out with Assembler but pretty soon you have to spend 10 minutes every time just editing out all the obvious statements that tell you "it's an ADD" , or "it's being NORed" or whatever.

So in this Ruby code you can customise your level by getting it to leave out the comments you don't want. By default I've set it to only keep "Assignment", "Hop", and "Loop". But 'keep_words' can be edited to suit personal skill level.

(Trogg made me a basic version of the same thing years back .. but I lost it!)

Second thing .. I've got it to automatically copy to the clipboard using the Win32API. So all you need to do now is bring up an empty assembler prim and paste inside it - done.

Did I get AI help? Course I did :oops:
Post Reply