New version onlineHere is an attempt to use an I/O library to communicate with ports, inspired by
this FreeBasic thread:
include \masm32\MasmBasic\MasmBasic.inc ; download
Init
Cls
if 0
Dll "InpOut32" ; WikiDll; first three functions
else
Dll "DlPortIO" ; Scientific Software Tools at WikiDll ; next four
endif
Declare void Out32, 2 ; ushort port, data
Declare void Inp32, 2 ; ushort port, data
Declare IsInpOutDriverOpen ; no args
Declare DlPortReadPortUshort, 1 ; ushort port
Declare DlPortReadPortUlong, 1 ; int port
Declare DlPortWritePortUshort, 2 ; int port, data
Declare DlPortWritePortUlong, 2 ; int port, data
PrintLine Str$("Out32: %i", Out32(?)) ; prints the address or zero if the function was not found
If_ IsInpOutDriverOpen(?) Then <Print Str$("driver open: %i\n", IsInpOutDriverOpen())> ; crashes
If_ Out32(?) Then <Out32(111h, 222h)> ; crashes
If_ DlPortReadPortUshort(?) Then <Print Str$("read port: %i\n", DlPortReadPortUshort(99))> ; error message
PrintLine "done"
EndOfCodeThe DLLs are available at various places, see links above, but it is unclear how they actually work. Inp32 and Out32 are actually straightforward, under the hood you see in
al, dx and
out dx, al, but the rest is badly documented.
What's new in MasmBasic then?
- SomeFunction(?) checks if the function has been loaded - see IsInpOutDriverOpen(?) above
- in console mode, you get feedback on
Declare:
not found (line 9): Out32
not found (line 10): Inp32
not found (line 11): IsInpOutDriverOpen
Unrelated:
$Data accepts now empty strings. This was inspired by Guga's
Resource String Table thread. If, for example, you copy \Masm32\include\masm32rt.inc into a source (to display the strings, whatever), there are some empty strings, and they used to choke with $Data. This little problem has been solved
*)In case you want a huge string table copied from a text file:
- File/New/Masm source: pick the Console example
- between the include line and Init, paste the lines from the text file
- select the whole block
- press Alt R
- insert
$Data ]#[ into the replace edit control, hit Return and confirm
- insert these three lines under
Init:
Read my$()
For_ ecx=0 To eax-1
PrintLine my$(ecx)
Next
*) at least for UAsm and AsmC - M$ MASM misbehaves on this one, and for ML there is no workaround other than deleting the offending empty line; otherwise, the whole MasmBasic library is fully compatible with ML versions 6.15 ... 14 or so, but attention, some recent ML versions have
ugly bugs. I strongly recommend to use
UAsm.