iCade for all platforms

Previous topic - Next topic

Kitty Hello

iCade is natively built into iOS. But for other platforms it works, too.
We just need to work with INKEY$, which is buffered in V11+.

Code (glbasic) Select

// --------------------------------- //
// Project: iCade
// Start: Monday, September 02, 2013
// IDE Version: 11.458

// There are three main latin keyboard layouts: QWERTY, QWERTZ AND AZERTY US keyboard layouts.
// The QWERTZ layout switches Y - Z
// The AZERTY layout switches A - Q AND Z - W
// // iCade events:
//   WE    YT UF IM OG
// AQ  DC
//   XZ    HR JN KP LV
// QUERTZ/AZERTY: W w/o Z (UP,   pressed w/  DOWN, pressed)
// AZERTY:        Q w/o A (LEFT, release w/o LEFT, pressed)
//    Z w/o X (DOWN, release w/o DOWN, pressed)

TYPE TiCadeInfo
dx%; dy% // D-Pad

GLOBAL iCade AS TiCadeInfo

FUNCTION iCadeUpdate%:
STATIC on$, off$
STATIC iLayout% =0 // 0:querty 1:qwertz 2:azerty

STATIC pins%[]

IF LEN(on$) =0
SELECT iLayout%
CASE 0 // querty
on$ = "wdxayhujikol";
off$= "eczqtrfnmpgv";
CASE 1 // quertz
on$ = "wdxazhujikol";
off$= "ecyqtrfnmpgv";
CASE 2 // azerty
on$ = "zdxqwhujikol";
off$= "ecyatrfnmpgv";
IF LEN(pins%[]) = 0 THEN DIM pins%[LEN(on$)]

LOCAL bChange% = FALSE
a$ = LCASE$(INKEY$())

i=INSTR(on$, a$)
IF i>=0
pins[i] = 1
bChange =TRUE
i=INSTR(off$, a$)
IF i>=0
pins[i] = 0
bChange = TRUE
// uh-oh real-key event!!!

// check if it's qwertz or azerty, based on possible logic combinations.
IF iLayout% = 0 AND pins[2]=1 AND a$="w" // must be quertZ or azerty!!
iLayout% = 1
FOREACH p% IN pins%[]; p=0; NEXT
pins[0] = 1
pins[4] = 0
on$="" // re-fill
ELSEIF iLayout% = 1 AND pins[3]=0 AND a$="a" // azerty: aq is swapped!
iLayout% = 2
FOREACH p% IN pins%[]; p=0; NEXT
on$="" // re-fill

IF bChange%
iCade.dx = pins[1]-pins[3]
iCade.dy = pins[2]-pins[0]
FOR i%=0 TO 7
iCade.buttons%[i] = pins[i%+4]


It's TESTED now and really works.
Test with:
Code (glbasic) Select

iCadeUpdate() // update status from inkey$ messages
PRINT "iCade: DX:"+iCade.dx+" DY:"+iCade.dy, 0,50 // D-Pad
FOR i=0 TO 7
PRINT "button "+i+" = "+iCade.buttons[i], 0, i*20+70 // Buttons


except Android, which the current keyevent() system dont work very well at all. Howover iCade in the querty mode is supported in Android using the GameController API im made for AndroidExtras.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello

blimey. What do I have to change to make INKEY$ work?


im dont known what you uses in those functions in sdlactivity.java:

    public static native void onNativeKeyDown(int keycode);
    public static native void onNativeKeyUp(int keycode);

Those have never really worked well and cause many "unknown" key sent back and rejected it. Im thinks you use some convert code in the c++ code inside those, which is completly wrong. All those functions should do is sendt its output directly to the KEYS() with the keycode its got and not try to convert it. There is also a inkey code thing in java, im could send to a another c++ code (etc as public static native void onNativeInkey(String charcode), if you which for uses with INKEY$() from the KeyDown() events. Howover Android uses Unicode, but glbasic dont support that.

Due that im could not use those functions at all, and implemented my own GameController stuff for Android, included in ANDROIDEXTRAS. This do also supports iCade, but have no idea around germany keyboard, because its was some dispatch code im found and used.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello

Updated tested code. One thing: If you let the user type with a keyboard, and he writes: x..w the iCade switches to QWERTZ mode (you can't get x..w on QWERTY). After that, if you get q..a, it flips to AZERTY.
So, make sure if the user selects iCade, it's really iCade and the pad is being held still when you start and put some WHILE LEN(INKEY$()); WEND before your first call to flush the inkey buffer.