English Amiga Board


Go Back   English Amiga Board > Requests > request.Apps

 
 
Thread Tools
Old 10 October 2011, 02:28   #1
olesio
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 */
These joyXdat cannot be read. I changed it to other way like CIA struct but it always read the same direction without pressing. Or maybe someone have example of code for HSPascal to read a joystick buttons and directions? Or maybe someone have some free time to code simple application which can be run from cli without any Window and wait for joystick direction or fire and return some digit on CLI? For Example: 1st fire = 0, 2nd fire = 1, left = 2, up = 3 right = 4, down = 5 or something like that. I want to add this program to my real Amiga 1200 startup-sequence to handle boot without mouse interaction - only for joy usage and for example if I press Left Joy Direction = Classic WB runs or Right Joy Direction = run Tiny Launcher 1.3 by Gibs. If program can return these digits which I mentioned above - I can handle it with eq comparsion in script. Or maybe it is some ready proggy like in my description available on Aminet? I searched but did not find it. And sorry for my bad English.
olesio is offline  
Old 10 October 2011, 08:35   #2
Minuous
Coder/webmaster/gamer
 
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,681
>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.
Minuous is offline  
Old 10 October 2011, 11:36   #3
chiark
Needs a life
 
chiark's Avatar
 
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?
chiark is offline  
Old 10 October 2011, 12:08   #4
pmc
gone
 
pmc's Avatar
 
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:
Originally Posted by olesio
1st fire = 0, 2nd fire = 1, left = 2, up = 3 right = 4, down = 5
I haven't implemented a check for joystick button 2 yet - no time right now - have to go out.

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
pmc is offline  
Old 10 October 2011, 14:14   #5
olesio
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
I try maybe StormC if I find it. Like I wrote - I'm total newbie in C language and in C compilers for Amiga. I only know Pascal and Delphi for PC Windows.

@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
olesio is offline  
Old 10 October 2011, 14:34   #6
pmc
gone
 
pmc's Avatar
 
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
pmc is offline  
Old 10 October 2011, 15:11   #7
olesio
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?
Attached Files
File Type: uae !_classic_wb.uae (16.7 KB, 156 views)

Last edited by olesio; 10 October 2011 at 15:17.
olesio is offline  
Old 10 October 2011, 15:32   #8
pmc
gone
 
pmc's Avatar
 
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.
pmc is offline  
Old 10 October 2011, 15:58   #9
olesio
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
After pressign fire, reboot I got "Warn returned!" message. Even when I using your latest joyread version ;/
olesio is offline  
Old 10 October 2011, 16:33   #10
pmc
gone
 
pmc's Avatar
 
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.
pmc is offline  
Old 10 October 2011, 17:19   #11
chiark
Needs a life
 
chiark's Avatar
 
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.
chiark is offline  
Old 10 October 2011, 17:24   #12
olesio
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.
olesio is offline  
Old 10 October 2011, 17:35   #13
chiark
Needs a life
 
chiark's Avatar
 
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
Attached Files
File Type: zip joytest2.zip (7.6 KB, 158 views)
chiark is offline  
Old 10 October 2011, 22:24   #14
pmc
gone
 
pmc's Avatar
 
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.
pmc is offline  
Old 11 October 2011, 17:29   #15
olesio
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:
But one more question. Is it possible to your code detect when joystick is unconnected and n that case return 6 for example and program will exit? I'm asking because under WinUAE I may run sometimes configuration wtihout joystick or real Amiga withour joystick (in most cases I have joystick connected on real my Amiga) and in that case program will execute ClassicWB after "endif". But if it some problem I will be satisfied with current version of joyread.

@chiark: Thanks, your modification of code also will be useful for me in future.

Last edited by olesio; 11 October 2011 at 18:04.
olesio is offline  
Old 11 October 2011, 19:00   #16
chiark
Needs a life
 
chiark's Avatar
 
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.
chiark is offline  
Old 11 October 2011, 20:04   #17
olesio
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.
olesio is offline  
Old 12 October 2011, 10:36   #18
chiark
Needs a life
 
chiark's Avatar
 
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?
chiark is offline  
Old 12 October 2011, 10:53   #19
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,574
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.
Toni Wilen is offline  
Old 12 October 2011, 13:32   #20
chiark
Needs a life
 
chiark's Avatar
 
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.
chiark is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:54.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11188 seconds with 14 queries