Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: motorollin on May 24, 2006, 06:46:09 PM
-
I'm trying to compile this example in AmiBlitz:
;-- Parallel port Blitz example..
;-- No more stupid Poking/peeking...
;-- remember to use all.res !
NEWTYPE .byte
b.b
End NEWTYPE
*PPort_Dir.byte = $BFE301
*PPort_Bits.byte = $BFE101
If AllocMiscResource_(#MR_PARALLELPORT,"MyAppName") = 0
*PPort_Dir\b= %11111111 ; set all bits direction to output
;-- Ready to rock and roll..
*PPort_Bits\b=%01010101 ; set the little buggers
FreeMiscResource_ #MR_PARALLELPORT
Else
NPrint "Crap, somethings already got the port :("
EndIf
End
I added blitzlibs:all.res in the compiler options and tried to compile, but I just get an error message with a title of "0", stating "Type Not Found". When I click OK I get "program failed (error #80000003)".
I'm completely new to AmiBlitz so have no idea what I can do :-(
--
moto
-
Gah... looks like somethings wrong with the way blitz calls the two misc.resource functions :-(
They were only added for completeness, and don't stop you from banging the hardware.
This is really all you need for testing your relay
NEWTYPE .byte
b.b
End NEWTYPE
*PPort_Dir.byte = $BFE301
*PPort_Bits.byte = $BFE101
*PPort_Dir\b= %11111111 ; set all bits direction to output
*PPort_Bits\b=%01010101 ; set the output of each pin
End
-
Yup, it's a bug in the way Blitz calls the resource.
I just cobbled together 2 funcs that call it directly and it doesn't crash.
Function.l AllocMiscResource{unit.l,name.l}
SHARED MiscBase.l
GetReg d0,unit
GetReg a1,name
GetReg a6,MiscBase
JSR -6(a6)
AsmExit
End Function
Statement FreeMiscResource{unit.l}
SHARED MiscBase.l
GetReg d0,unit
GetReg a6,MiscBase
JSR -12(a6)
End Statement
;-- No more stupid Poking/peeking...
NEWTYPE .byte
b.b
End NEWTYPE
MiscBase.l=0
*PPort_Dir.byte=$bfe301
*PPort_Bits.byte=$bfe101
MiscBase.l=OpenResource_("misc.resource")
If MiscBase
If AllocMiscResource{#MR_PARALLELPORT,"MyAppName"}=0
*PPort_Dir\b= %11111111 ; set all bits to output
*PPort_Bits\b=%01010101
FreeMiscResource {#MR_PARALLELPORT}
Else
NPrint "Crap!"
EndIf
EndIf
End
-
You rock :-) Your first example worked!!! I'll try the longer one later - first thing I have to try to get user input working so I can specify the state of the relays in an argument :idea:
--
moto
-
How can I convert between types in Blitz? I want to pass a string variable to the port, e.g. *PPort_Bits\b=bits$, but when I try this I get an "incompatible types" error. I also want to convert back the other way so I can read the bits from the port, but I get the same error when doing bits$=*PPort_Bits\b
--
moto
-
Bin$(number) converts from an integar to string showing the binary representation.
Str$(number) converts from integar to string.
bit$=Right$(Bin$(*PPort_Bits\b),8) should give you the lower 8 bits...assuming you're trying to read the current state of the relays.
If you're using the relays the other way around to input into the Amiga, then you'll need to set each direction bit to 0 (*PPort_Dir\b=%xxxxxxxx) before reading the bits
As for the other way around, I dunno if blitz has a function to do it..been a while since I did anything with it.
I'll have a look and see what I can find, but I'm a bit preoccupied with Remus at the moment.... it might not live to see v1.0 :madashell:
BTW, why's this page soooooo wide?
-
Great, thanks! One more question and then I should be able to work the rest out for myself. I have looked through the Blitz II manual, but I can't find out how to read arguments from the command line.
What's going wrong with Remus then? I'm still meaning to create a v3.9 ROM but can't quite find the time :-)
No idea why the page has gone so wide. I can't see anything making it like that :-?
--
moto