Parallel Programming #4

Blitz3D Forums/Blitz3D Beginners Area/Parallel Programming #4

None(Posted 2004) [#1]
soja,

OK, here is where I am at (I feel more behind than ahead!).

1. I made all the changes to the .decls file, including the boolean (%) expressions and pointer (*) expression.

2. I did a test for the return value for InstallWinIoDriver. I guess the test passed -- I didn't get any "bad news".

3. I created (I think) the peekbyte method to read the data for GetPortVal.

4. Thanks for finding my boo-boo on SetPortVal... I think I fixed it.

5. I did not understand your PPS at all!

Anyway, here is where I am currently at...
When I run the program the error message I get is "Type can only appear in main program.". Here is the current files:

Again, thanks!


.DECLS FILE

.lib "winio.dll"

;Initializes the WinIo library (boolean). Does not have to be used with Windows XP.
InitializeWinIo%():"InitializeWinIo"

;Performs shutdown of the WinIo library. Must be called before terminiating an application or when no longer using the WinIo library.
ShutdownWinIo():"ShutdownWinIo"

;Calls the WinIo driver (boolean). Parameters: (Points to a null-terminated string to specify the winio.sys driver path, Set to false).
InstallWinIoDriver%(WinIoDriverPath$, IsDemandLoaded):"InstallWinIoDriver"

;Removes the WinIo driver (boolean).
RemoveWinIoDriver%():"RemoveWinIoDriver"

;Reads a 1, 2, or 4 byte value from specifies I/O port (pointer). Parameters: (Input port $379, DWORD variable, BYTE = 1).
GetPortVal*(PortAddr, PortVal, Size):"GetPortVal"

;Writes a 1, 2, or 4 byte value to an I/O port (boolean). Parameters: (Output port $378, Hex value written to port, BYTE = 1).
SetPortVal%(PortAddr, PortVal, Size):"SetPortVal"


BLITZBASIC FILE

;The BlitzBASIC code for:
;Direct Port access from BlitzBASIC using WinIo.

;Set graphics mode.
Graphics 800, 600, 16, 2
SetBuffer BackBuffer()

;Initializes the WinIo library.
;InitializeWinIo()

;Call the WinIo driver
If Not InstallWinIoDriver(".\", False) Then
Print "Initialization failed."
End
EndIf

Repeat

Type PortVal
Field val
End Type
p.PortVal = New PortVal
;Read a 1 byte value from the specified port and place in variable DWORD.
GetPortVal($379, p, 4)
DebugLog p\val

;Print variable p
Print p

Until KeyDown(1)

;Removes the WinIo driver.
RemoveWinIoDriver()

;Shutsdown the WinIo library.
;ShutdownWinIo()

End


soja(Posted 2004) [#2]
Like I said, I was getting into more advanced stuff (all at once) but you seem to have handled everything well. You might read the documentation on (custom) types.

Basically, since Blitz only has a few built-in types (int%, string$, float#), it also allows you to create your own. (They're analogous to structs in C.) Custom types are like bllueprints for containers for a set of related variables. Once you define the type, you can create as many instances as you like, and they automatically get stored in an internal linked-list. Anyway, I'm confident you'll understand them after reading the documentation on them a few times. The only point I need to make right now is that the type definition, e.g.:
Type name_of_custom_type
    Field field1%
    Field field2$
    Field field3#
    Field field4%
End Type
...must be defined outside of a function/loop/etc, in other words, at the "root" scope. So just copy and paste that part of your program (and also the part where a New Portval is created -- you only need one -- you shouldn't have it inside the Repeat loop) at the top or bottom.

Everything else looks like it should work.

By the <code> stuff, I was letting you know that if you wanted to post your program code to the forum in
    this kind of formatting
...that you could do it by putting it between these two formatting codes:
<code>
(insert blitz code here)
</code>
-- but replace the < with [ and the > with ].

Also, if you scroll down to the bottom of the message, you can post a reply directly to that thread, and it will go to the top of the queue -- so you don't have to create a new topic each time.


Ice9(Posted 2004) [#3]
you are defining a type inside a loop
pull these lines

Type PortVal
Field val
End Type

above your Repeat


soja(Posted 2004) [#4]
Wait a second -- I spoke too soon. This line:
GetPortVal*(PortAddr, PortVal, Size):"GetPortVal"

...should be:
GetPortVal%(PortAddr, PortVal*, Size):"GetPortVal"

...because we want the return value type (specified by the % right after GetPortVal) to be an int (compatible with bool in C), and we want to PortVal parameter to be passed as a pointer -- not an int. Because if you look at the WinIo documentation, it tells you that GetPortVal expects a *pointer* to a DWORD (int). That's why we have to do the custom type thing (or alternatively, the Bank thing... let me know if you want me to explain that).