Cannot figure out how to read SMS input

Post Reply
Fabrizio
Member
Posts: 58
Joined: Tue Jul 11, 2017 9:28 pm

Cannot figure out how to read SMS input

Post by Fabrizio »

I am trying to understand how to read the SMS gamepad input.

What is wrong with the code below code?
My code does not detect any key-press.
What do I need to do? Any initialization required?

Code: Select all

#include <arch/sms/SMSLib.h>
...

int main(void)
{
        unsigned int status;
                                
        INIT_GRAPHICS();
        
        while(1)
        {
                status = SMS_getKeysStatus();

                if(status & PORT_A_KEY_1)
                {
                        printf("status FIRE 1\n");                        
                }
                else if(status & PORT_A_KEY_2)
                {
                        printf("status FIRE 2\n");                        
                }                                                
        }
        
        return 0;
}
which I compile with:

Code: Select all

        $(Z88DK_PATH)$(MYZ88DK) +sms -clib=sdcc_iy -startup=1 -v \
        -pragma-include:$(CFG_PATH)/z88dk/zpragma_sms.inc \
        -create-app \
        $(SOURCE_PATH)/../experiments/sms_joy_test.c \
        -o $(BUILD_PATH)/sms_joy_test.bin
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

If you're using devkitsms (SMSlib and PSGlib are its two parts), the controller scan is done in the interrupt service routine:

https://github.com/z88dk/z88dk/blob/mas ... sr.asm#L38

This isr is automatically put in place if you compile using a devkitsms crt. The crt is the code at address 0 that puts in code for the restarts, im1, nmi etc and devkitsms provides this for its api. The devkitsms crts are actually 16,17,18 (not 0,1,2 which are crts without devkitsms).

divkitsms page zero code:

https://github.com/z88dk/z88dk/blob/mas ... kitSMS.inc

the sms crts:

https://github.com/z88dk/z88dk/tree/mas ... ms/startup

16 = devkitsms, no printf driver
17 = devkitsms, printf driver without control codes
18 = devkitsms, printf driver with control codes

Unlike most targets, on the sms, printf is not immediately functional as you have to load a font into tile memory. This is described in the helloworld example:

https://github.com/z88dk/z88dk/tree/mas ... helloworld

A nice example of using devkitsms can be seen in astroforce although the source code organization is not ideal (there should never be code in header files):

https://github.com/z88dk/z88dk/tree/mas ... AstroForce

----

So I think you need to use startup=17 to get a devkitsms compile with printf driver. And then you'll need some code to load a font in and you'll need to separate the font's use of tiles from the tiles used for the game itself.
Fabrizio
Member
Posts: 58
Joined: Tue Jul 11, 2017 9:28 pm

Post by Fabrizio »

@alvin

I have no problem with printf.
I can print stuff.

My problem is that no keys are ever detected.
Fabrizio
Member
Posts: 58
Joined: Tue Jul 11, 2017 9:28 pm

Post by Fabrizio »

@alvin!

Thanks Alvin! startup=17 solved my input problem!! (printf was already working)
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Good! startup=18 contains printf control codes if you need that. The hello world example uses ioctl() to send the driver instructions to clear the window but that can also be done by sending an appropriate control code in the text stream. Without bankswitching, the sms target is 32k rom and 8k ram.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Or maybe I should say 48k.. usually the 32k-48k region is used to page in other 16k banks but you could out something there and not page anything else there. I think this is automatically handled by appmake with a warning about not putting the sms header in (it's been a while).
Post Reply