Friday, August 28, 2020

Bmax logo

 It is not a good app if it doesn't have a good logo, we had one for testing, today i wanted to make a representative one.

For that, i decided to use all the name letters and create a face for him in paper:

first draft in paper



And after that i give him the colors i used in the screen of the app to give him his own personality:




computerized logo with representative colors

Bmax part 1.5

Now that we have the basic estructure, we will create a mini function to print errors and dump the text into a readable file for future debugging purposes. we are going to call this function when we check for bad results.

Although a good debugger would be desirable, we use this as a temporal patch.

The function will be declare in the main.h and written in the "common.c" file.


debugLog function

Friday, August 14, 2020

Bmax part 1

 In the previous entry we got the basic environment of the homebrew, now we want to make it modular. This will make the project easier to mantain and upgrade.

For this goal, we have to make separate files for the headers and the main module (main.h and main.c). From now on, we are also going to do something similar for each "Bmax's function" (sub module).

At the end of this point we will have 4 files created/updated, but in the future will be adding more files.

In the main.c file we only leave the main function with: init, program_loop (currently redrectangle), and quit.

main.c step



In the main.h we will have definitions of data types, function prototypes and C preprocessor commands.
(How to write your own header file in C). (we surely need more files like this)

main.h step


In the common.c we will write the generic functions we are going to call (we surely need more files like this).

common.c step



In the makefile we are adding the new c files that we want to add to the compile process, in the "add executable" section

makefile step




Note: debugScreen is added for future debuggin purposes. also a function for that goal has been created.

Thursday, August 13, 2020

Bmax part 0.5

 In this entry we will create the basic folders and files. For that goal we are going to copy and modify the pretty_livearea and the sdl/rectangle.

 From the pretty_livearea we are going to copy the whole folder. After that, we modify the makefile, and later the pictures, and the template.xml to adapt to our homebrew.

 The changes to the makefile consist in changing: project name, app name, app title, and link libraries (to add the sdl since we are using the make file from the pretty live area).

makefile
Modifying the makefile step 1

makefile
Modifying the makefile step 2


The changes of the template.xml consist on changing some texts with our data:

Modyfing the template.xml




From the sdl/rectangle we are going to copy the src/main.c file to ours.

Since it is the first entry of the project, and creating new picutures is not part of the blog, we stop here for today.

In the next entry we will have those pics changed acording to their needs, and we will start with the new code.

As a prologue of the following entries of this project, we are going to use this tutorial as a helper for the sdl library:
http://lazyfoo.net/tutorials/SDL/index.php

Note: also we may need the sdl part of the game controller and the joystick mapping:
https://wiki.libsdl.org/CategoryGameController

 ---

Screenshot from the project in the current state running on the vita

Bmax livearea

 

Wednesday, August 12, 2020

Bmax part 0

 Here we will write the initial flowchart of the Bmax project.

The main program will be the one who start with the app and with the list of modules to load.
Each module will be like a mini app inside the main one.

draft idea
 

With that idea in mind, we have created a basic flowchart to implement later.
 
 
flowchart


The modules though at this moment are:

  - a help file (will be multilingual in the future)

  - button_dash minigame

  - whack-a-mole minigame (touch controlled)

  - a clock (it will have some events hour dependent). it may be included in the main as secondary image in the future

  - more TBD (To Be Determined)


Link to Source files: https://github.com/Bunkai9448/BMAX

main projects plan 000

After all these time, we have read almost all the samples and we have a brief understanding of the basics, now we have to plan ahead.

We have some "big" options to develop for the vita:
  - Unity for ps vita (we will talk about this later)
  - PSM (Play Station Mobile) .
  - Game Maker Studio (with gmx to vpk)
  - c/c++ as we have been reading
  - sdl (which we introduced with the rectangle sample).

With this in mind, we have decided to make 2 projects:
  - ice_puck which will be the one about hockey. Long term.
  This project will be probably made in unity because, we want it to be easy to port/help, and as widely known as posible.


  - Bmax which will be a launcher with a fakebot look. Short term to unknown.
    This project will be made with sdl because we want something in c/c++ but with graphic libraries. To practice
  coding and keep learning about everything. In this project we can also insert other simpler ones (and we will do).

For the blog, we will write each project in its own lables and entries.

Note: although we will explain everything about the progress of each project, the files will be always found in Bmax, and Ice_Puck.

Basics on the code PART 13

In this entry we are going to read about the microphone options on the vita. For that we are using the vitasdk audio section and more specificly the audioin library.

Note: With this entry we are finishing the samples reading for now, and will start with the next step in the future one.

There is not much new to say appart to comment that the info received in the mic port is save in a buffer.

SAMPLE "microphone"

microphone: Demonstration of microphone features.

/*
    Simple microphone test program
    - displays audio in data
    - displays small VU meter based on
      an average of the audioIn buffer
    - increase or decrease the sensitivity
      of the VU meter with up/down buttons
    - exit with select
    Enjoy,
        -pyroesp
*/


#include <psp2/kernel/threadmgr.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/audioin.h>
#include <psp2/ctrl.h>

#include <stdlib.h>
#include <string.h>

#include "debugScreen.h"

#define printf psvDebugScreenPrintf

#define SEC_MULTIPLIER 1000000
#define MAX_WORDS_PER_LINE 23
#define MAX_VU 32

/* Tested sample rates - grain */
/* 16kHz ; 256 */
/* 48kHz ; 768  (= 16kHz*3 ; 256*3) */

int main(int argc, char *argv[]){
    int exit = 0;
    /* sample rate */
    int freq = 16000;
    /* grain */
    int grain = 256;
    /* audio in port */
    int port = 0;

    /* If size > grain */
    /* audio buffer will be filled only up to [grain - 1] */
    int size = 256;
    short *audioIn = NULL;

    psvDebugScreenInit();
    printf("Microphone test:\n\n");
    printf("Press up/down for VU sensitivity.\nPress select to quit.\n\n");

    audioIn = (short*)malloc(sizeof(short) * size);
    memset(audioIn, 0, sizeof(short) * size);
    /* Open port */
    port = sceAudioInOpenPort(SCE_AUDIO_IN_PORT_TYPE_VOICE, grain, freq,
                SCE_AUDIO_IN_PARAM_FORMAT_S16_MONO);

    printf("Port value 0x%X - buff size %d\n", port, size);

    /* Check for SceAudioInErrorCode enums */
    if (0 > port){
        exit = 1;
    }

    printf("Audio buff address = 0x%X\n\n", audioIn);
    sceKernelDelayThread(2 * SEC_MULTIPLIER);
    printf("Read audio:\n");

    int i, j;
    int average;
    int audioInMax;
    int sensitivity = 3;
    int retVal;

    SceCtrlData ctrl, oldCtrl;

    printf("\e[s");  // save cursor position
    while (!exit){
        average = 0;
        audioInMax = 0;
        printf("\e[u");  // return to saved cursor position
        /* Read audio */
        retVal = sceAudioInInput(port, (void*)audioIn);
        if (retVal){
            exit = 1;
            break;
        }

        /* Print all values in audio buffer, 23 WORDs per line */
        for (i = 0; i < size; i += MAX_WORDS_PER_LINE){
            for (j = 0; j < MAX_WORDS_PER_LINE && size > (i + j); j++){
                /* remove unwanted values < 0 */
                if (0 > audioIn[i + j])
                    audioIn[i + j] = 0;

                printf("%04X ", audioIn[i + j] & 0xFFFF);
                average += audioIn[i + j];

                if (audioInMax < audioIn[i + j])
                    audioInMax = audioIn[i + j];
            }
            printf("\n");
        }

        average /= size;
        average = ((average * sensitivity) * MAX_VU) / audioInMax;
        /* Get microphone status */
        /* Other values than 1 in GetStatus returns 0x80260106 */
        printf("\nYour microphone is %s\n\n", sceAudioInGetStatus(1)?"disabled.": "enabled. ");
        printf("\nSimple VU meter: (sensitivity = %3d)\n\n\n", sensitivity);
        for (i = 0; i < MAX_VU; i++){
            printf("\e[7G");  // set cursor to column 7 (for 8x8 font)
            if (i < average){
                if (MAX_VU/2 > i)
                    psvDebugScreenSetBgColor(0xFF00FF00);
                else if (MAX_VU*3/4 > i)
                    psvDebugScreenSetBgColor(0xFF00FFFF);
                else
                    psvDebugScreenSetBgColor(0xFF0000FF);

            }else{
                psvDebugScreenSetBgColor(0xFF000000);
            }
            printf("   \n");
        }
        psvDebugScreenSetBgColor(0xFF000000);

        sceCtrlPeekBufferPositive(0, &ctrl, 1);

        if ((ctrl.buttons & SCE_CTRL_UP) && !(oldCtrl.buttons & SCE_CTRL_UP))
            sensitivity++;
        else if ((ctrl.buttons & SCE_CTRL_DOWN) && !(oldCtrl.buttons & SCE_CTRL_DOWN))
            sensitivity--;
        else if (ctrl.buttons & SCE_CTRL_SELECT)
            exit = 1;

        if (0 >= sensitivity)
            sensitivity = 1;

        memcpy(&oldCtrl, &ctrl, sizeof(SceCtrlData));

        sceKernelDelayThread(10000);
    }

    free(audioIn);
    sceAudioInReleasePort(port);
    sceKernelExitProcess(0);
    return 0;
}



-----------

Screenshot from the sample running on the vita:




And that's all for this sample.

Tuesday, August 4, 2020

Samples common files & code PART 2

In today's entry we are going to read about the net conexions and the ps vita (sockets). For that matter, we are using the Vita SDK documentation, network section.

This section gets into net modules on the vita, and its conections with everything related to sockets and HTTP.

Our project doesn't involve any of that, that is why this is a brief entry of the samples that cover this modules. If we need some of this code later we can go back and take a more deep aproach.

Note: the samples download the data in the ux0:data/ directory.


SAMPLE "socket_ping"

socket_ping: ICMP ping using raw sockets.

In its main.c you can read mostly about structs with the icmp datagrams and the ping data.

Note: These are to test if your connexion is active, and if the dns you are trying to connect is on (the sample use the google dns because is public, wide and "always" online). You can read more about this on their wikipedia pages: wikipedia icmp, wikipedia ping.


SAMPLE "net_http"

net_http: A minimal HTTP download sample.

In its main.c it shows how to load the module and download an html file from its web

Note: this is the basic function of a web browser.



SAMPLE "net_http_bsd"

net_http_bsd: A minimal HTTP download sample using BSD sockets.

This sample does the same as the net_http but using Berkeley Software Distribution Sockets. and shows the results on screen (the downloaded result generated a core dumped error to us tho).



SAMPLE "net_libcurl"

net_libcurl: A libcurl download sample.

Its main.cpp again shows how to load the module and use it to download a file from a webpage (specificaly the "vita_cord.vpk"), but this time use libcurl for the process.

Note: libcurl is a free and easy-to-use client-side URL transfer library.


-----------

Some screenshots from the samples running on the vita: 

And that's all for this entry.
net_http

net_http_bsd

net_libcurl