10 October 2011, 02:28 | #1 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
CLI program to resturn joy direction or fire button.
Hello. I'm trying compile this http://cd.textfiles.com/aminet0294/A...C/JOYSTICK.LHA under DICE and WinUAE, but I'm totally Amiga C newbie. I only know HSPascal a bit, but I don't know how to read joystick under it. Can saomeone compile code above or tell me how to do it under DICE in Classic WB? Dice do not accept this code:
Code:
extern struct Custom far custom; UBYTE ret = 0; UWORD joy; if(joynum == 0) /* JoyPort 0? */ joy = custom.joy0dat; /* If so, use joyport 0 */ else joy = custom.joy1dat; /* Otherwise, default to joyport 1 */ |
10 October 2011, 08:35 | #2 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,686
|
>Dice do not accept this code
You should at least list the error messages you are getting. Also, switching to a better and more widely used compiler (eg. SAS/C or StormC) would be a good idea, there is no reason to want to use DICE. |
10 October 2011, 11:36 | #3 |
Needs a life
Join Date: Jan 2008
Location: England
Posts: 1,707
|
Off the top of my head I can't see why that wouldn't work - it's also an example of how to read the joystick registers that would be easy to translate in to HSPascal.
Have you got the right include files? |
10 October 2011, 12:08 | #4 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Check the attached little executable.
It currently just sits there and waits for input from a joystick in port 2 and outputs a number based on up, down, left, right or fire as per your numbering system: Quote:
Let me know if it works OK Oh, and just to be clear (and to make sure I don't get shouted at by Toni or one of the other gurus ) I make no promises as to how system friendly or not the way I've done things is but it shouldn't kill anything horribly I don't think Last edited by pmc; 10 October 2011 at 15:33. Reason: removed old version of joyread |
|
10 October 2011, 14:14 | #5 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
@Minuous: i got following errors when compiling with DCC:
Code:
New Shell process 7 7.System:> dh1:dice 7.Programs:dice> bin/dcc joy.c DC1: "joy.c" L:77 Warning:68 expected semicolon extern struct Custom far custom; ^ DC1: "joy.c" L:82 Error:30 undefined symbol: custom joy = custom->joy0dat; ^ DC1: "joy.c" L:82 Error:46 not structure or union type joy = custom->joy0dat; ^ DC1: "joy.c" L:84 Error:46 not structure or union type joy = custom->joy1dat; ^ Exit code 20 @pmc: big thanks - your code work almost ok - executable file is small but I have one problem. After first reboot under WinUAE joyread always return 5 vaslue (Warn). I did not rested on real Amiga yet. But maybe you can fix it somehow to reset joy state and do not return 5. Thanks in advice. Cut of my script Code:
cls echo "" echo " Press Fire button to run Tiny Launcher or a" echo " right Joystick direction to load ClassicWB." echo "" set Reply `joyread` if $Reply eq 5 echo " Warn returned!" endif if $Reply eq 0 DH1:TINYLAUNCHER/TinyLauncher.exe endif if $Reply eq 3 C:LoadWB EndCLI >NIL: endif |
10 October 2011, 14:34 | #6 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
olesio: I tested on WinUAE KS 2.04 A500+ and I tested on a real Amiga KS 3.1 A1200 and it works OK for me.
I'll check using your script and see what happens EDIT: I tested using your script and it worked OK for me - I always got a different number output to match the joystick direction (or firebutton) I chose. If you still find it's not working for you, post a few more details of your setup and I'll try to test further. Last edited by pmc; 10 October 2011 at 14:47. Reason: Added update |
10 October 2011, 15:11 | #7 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
I tested under KS 3.1 and latest WinUAE plus Classic WB. My configuration attached. I try under real Amiga 1200 later. Also I installed Storm C and I wanted to compile joy.c from joystick.lha at link above but I have error with unknonw _main by Linker. I tested version 1.1 of Strom C installed from adfs at: http://www.theoldcomputer.com should I try new version on seven adfs?
Last edited by olesio; 10 October 2011 at 15:17. |
10 October 2011, 15:32 | #8 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
olesio: check new version attached with number output corrected slightly to match your original numbering scheme - I'd mixed up right and up originally, sorry. Now fixed.
Also, check the screenshot - you can see the script sensing each joystick direction pressed correctly. Last edited by pmc; 09 November 2011 at 08:30. |
10 October 2011, 15:58 | #9 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
You did not understand me good. In method which you show everything is ok. But please download latest TinyLauncher and read topic: http://eab.abime.net/showthread.php?...=tiny+launcher to know how to use it and try execute following script. Press fire to run TinyLauncher press Amiga+Amiga+Ctrl to reboot and joyread will return 5 (probable warn). After loading ClassicWB all is ok. I tested only WinUAE already but maybe under real Amiga 1200 it will work different.
Code:
cls echo "" echo " Press Fire button to run Tiny Launcher or a" echo " right Joystick direction to load ClassicWB." echo "" set Reply `joyread` if $Reply eq 5 echo " Warn returned!" endif if $Reply eq 0 DH1:TINYLAUNCHER/TinyLauncher.exe endif if $Reply eq 3 C:LoadWB EndCLI >NIL: endif |
10 October 2011, 16:33 | #10 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
olesio: sorry, that was my misunderstanding. I recreated your error here. I'll try to fix it for you.
|
10 October 2011, 17:19 | #11 |
Needs a life
Join Date: Jan 2008
Location: England
Posts: 1,707
|
It's because the includes don't have a custom struct defined.
I've compiled using DICE, and replacing joy0dat with 0xDFF00A / joy1dat with 0xDFF00C... Will post the exe in a few minutes. |
10 October 2011, 17:24 | #12 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
@pmc: ok, no problem. I will test new version if it will be available, but I do this tomorrow . Now I must go to work. Thank you.
@chiark: I did not know how to replace these values. Now I know that from your reply. I try to replaceid by these hex values also tomorrow. Thanks to you too. |
10 October 2011, 17:35 | #13 |
Needs a life
Join Date: Jan 2008
Location: England
Posts: 1,707
|
here you go...
added 2 defines to access the custom registers for JOY0DAT/JOY1DAT and changed the reading loop to remove reference to custom structure / replace with JOY0DAT and JOY1DAT defines seems to work. You can modify it to return a value based on the press if you like |
10 October 2011, 22:24 | #14 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
ooops, took so long to post the fixed version I was beaten to it by chiark
anyways, fixed (I hope...) version attached. Last edited by pmc; 04 November 2011 at 12:05. Reason: EDIT: this version of joyread removed - smaller version attached below. |
11 October 2011, 17:29 | #15 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
@pmc: big thanks, now everything works fine. I made following entry to s-s:
Code:
LAB ASKFORTL cls echo "" echo " Press Fire button to run Tiny Launcher or" echo " some Joystick direction to load ClassicWB" echo "" set Reply `joyread` if $Reply eq 0 DH1:TINYLAUNCHER/TinyLauncher.exe skip ASKFORTL BACK endif C:LoadWB EndCLI >NIL: @chiark: Thanks, your modification of code also will be useful for me in future. Last edited by olesio; 11 October 2011 at 18:04. |
11 October 2011, 19:00 | #16 |
Needs a life
Join Date: Jan 2008
Location: England
Posts: 1,707
|
no, there's no status to show whether a joystick is connected or not unfortunately... That would be the difficult bit. Only thing to do would be to allow space to load tiny launcher or any other key to not... That would be a simple modification.
|
11 October 2011, 20:04 | #17 |
Registered User
Join Date: Apr 2007
Location: Poland
Posts: 337
|
Ok, thanks for info. I thought it is possible, because some games detect joy in second port, so maybe it can also detect in first port somehow.
|
12 October 2011, 10:36 | #18 |
Needs a life
Join Date: Jan 2008
Location: England
Posts: 1,707
|
Do they? Without any movement? OK, in that case I'm wrong - I'll look into it again but I can't see any status register that would flag the presence of a passive device (joystick).
Can you let me know which game detects a joystick without having to move anything and I'll see how it does it? |
12 October 2011, 10:53 | #19 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,575
|
There is no way to detect a standard joystick. Joystick not connected and joystick connected without movement or pressing a button is electrically identical (all switches open circuit).
CD32 pad can be detected. It is designed to be detected. Some Amiga-compatible gamepads and third party mice can be sort of detected ("something" is connected, perhaps a pad, perhaps a third party mouse or perhaps something else) because some of them have pullup resistors in button lines. |
12 October 2011, 13:32 | #20 |
Needs a life
Join Date: Jan 2008
Location: England
Posts: 1,707
|
Cheers Toni. I've just spent a fruitless 15 minutes googling for the inner workings of ReadJoyPort from Lowlevel.library to see how it detects, but to no avail... I guess the source of WinUAE will explain .
Looks like pin5 is part of detection, plus a set of tests in lowlevel.library to work out what exactly is there. If it's a CD32 joypad, P6 then acts as a clock for the shift register - aside from its duties as fire button 1 - , and P9 is where the results are sent... That's really quite a neat hack! I wonder if it was ever envisioned for this purpose? Guess it must have been given the in/out status of the pins... void handle_cd32_joystick_cia (uae_u8 pra, uae_u8 dra) - is this what shifts the results from the CD32 buttons into the appropriate place? Sorry, this is somewhat off topic now! Last edited by chiark; 12 October 2011 at 14:01. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
edit joy 2nd button ? | turrican3 | support.WinUAE | 4 | 15 November 2012 10:30 |
Possible to run a program from CLI in background? | VoltureX | support.Apps | 17 | 14 January 2012 03:16 |
CLI program to make mouse pointer dissapear on KS 3.X | Gaula92 | request.Apps | 5 | 21 October 2011 14:49 |
cd32 problem phantom joy button action | heerschop | support.Hardware | 5 | 19 September 2010 06:09 |
'Wait' program that checks for a joy button press instead of 'Return' key... | Heavy Stylus | request.Apps | 7 | 10 May 2009 19:01 |
|
|