<commit_before>#include "genesis.h"

#include "tile.h"
#include "tilemap.h"
#include "main.h"
#include "pcm.h"

#include "sound_res.h"
#include "movie.h"

// we have 2 data packet to handle for each frame: tileset and tilemap
// ts_trans --> nb tile to transfer
// ts_decomp, tm_decomp
// flip_done

// reset:
// flip = TRUE
// ts_decomp, tm_decomp = FALSE

// loop:
//
// while(ts_decomp);    //
// ts_trans = tsUnpack();
// ts_decomp = TRUE;
// while(tm_decomp);    //
// tmUnpack();
// tm_decomp = TRUE;

// vblank:

// if (flip && (ts_decomp || tm_trans))  --> mean we have data to transfer
// {
//   if (ts_decomp)
//   {
//     ts_decomp = !tsTransfer(ts_trans);
//     ts_trans = 0;    // so we don't re-initiate tile transfer on next frame
//   }
//   else if (tm_decomp)
//     tm_decomp = !tmTransfer();
//
//   // all decompression done --> time to flip
//   if(!tm_decomp)
//     flip = FALSE;
// }

// if (time_for_flip && !flip)
//{
//   doFlip();          // flip tilemap view and flip buffers
//   setEvenPal();      // set palette for even frame
//   flip = TRUE;
//   palFrame = 2;
//}
//else if (--palFrame == 0)
//  setOddPal();      // set palette oddeven frame


static char str1[32];

static u16 pal_even[16];
static u16 pal_odd[16];

static u16 pal_step[16] =
{
    0x555,
    0x055,
    0x550,
    0x505,
    0x005,
    0x050,
    0x500,
    0x355,
    0x553,
    0x535,
    0x335,
    0x353,
    0x533,
    0x333,
    0x033,
    0x330
};

static u16 pal_step_index;

static vu8 paused;

static u16 gen_frame;
static u16 int_frame;
static u16 mov_frame;

static vu8 ts_decomp;
static vu8 tm_decomp;
static vu16 ts_trans;
static vu8 flip_done;

static bool back;
static u16 transfer_phase;

static u32 wait;
static u16 fps;
static u16 show_fps;


static void joyEvent(u16 joy, u16 changed, u16 state);
static void vblank();
static void set_palette();
static void reset();


int main()
{
    fps = 0;
    show_fps = 0;

    VDP_setPlaneSize(64, 64, TRUE);

    JOY_setEventHandler(joyEvent);
    JOY_setSupport(PORT_1, JOY_SUPPORT_3BTN);
    JOY_setSupport(PORT_2, JOY_SUPPORT_OFF);

    PAL_setPalette(0, palette_black);

    VDP_drawText("Bad apple PV demo - SGDK sample", 2, 0);

    VDP_drawText("Video: 320x224 2bpp @30FPS", 9, 3);
    VDP_drawText("Audio: 4bit ADPCM @ 13 Khz", 9, 4);
    VDP_drawText("Duration: 3m39s", 6, 5);
    VDP_drawText("Raw size: 120 MB", 6, 6);
    VDP_drawText("Optimized size: 23 MB", 0, 7);
    VDP_drawText("Packed size: 10 MB (LZ4W compression)", 3, 8);

    VDP_drawText("A --> change palette", 4, 10);
    VDP_drawText("B --> display/hide FPS meter", 4, 11);

    VDP_drawText("Press START to continue.", 2, 14);

    PAL_fadeInPalette(PAL0, font_pal_lib.data, 20, FALSE);

    JOY_waitPress(JOY_1, BUTTON_START);

    PAL_fadeOutAll(20, FALSE);

    VDP_clearTileMapRect(BG_A, 0, 0, 64, 64);
    VDP_clearTileMapRect(BG_B, 0, 0, 64, 64);

    reset();

    SYS_setVIntCallback(vblank);

    while(mov_frame < 3235)
    {
        // do nothing on pause
        while(paused);

        // audio sync
        if (mov_frame == 5)
            startPlay(music, sizeof(music), 0);

        // unpack data (synched with vblank process)
        while(ts_decomp) wait++;
        ts_trans = ts_unpack(mov_frame);
        ts_decomp = TRUE;
        while(tm_decomp) wait++;
        tm_unpack(mov_frame);
        tm_decomp = TRUE;

        // decompression completed
        mov_frame++;
    }

    while(tm_decomp);

    waitMs(1500);

    SYS_setVIntCallback(NULL);

    VDP_init();
    VDP_setPlaneSize(64, 64, TRUE);
    PAL_setPalette(PAL0, palette_black);

    VDP_drawText("Hope you enjoyed :)", 5, 10);
    VDP_drawText("@2021  <NAME>", 9, 27);

    PAL_fadeInPalette(PAL0, font_pal_lib.data, 20, FALSE);

    SYS_setVIntCallback(vblank);

    while(TRUE);
}


static void reset()
{
    loadDriver();

    paused = FALSE;
    pal_step_index = 0;
    flip_done = TRUE;
    ts_decomp = FALSE;
    tm_decomp = FALSE;
    int_frame = 0;
    gen_frame = 0;
    mov_frame = 0;
    back = TRUE;
    transfer_phase = 0;<commit_msg>updated to last SGDK<commit_after>#include "genesis.h"

#include "tile.h"
#include "tilemap.h"
#include "main.h"
#include "pcm.h"

#include "sound_res.h"
#include "movie.h"

// we have 2 data packet to handle for each frame: tileset and tilemap
// ts_trans --> nb tile to transfer
// ts_decomp, tm_decomp
// flip_done

// reset:
// flip = TRUE
// ts_decomp, tm_decomp = FALSE

// loop:
//
// while(ts_decomp);    //
// ts_trans = tsUnpack();
// ts_decomp = TRUE;
// while(tm_decomp);    //
// tmUnpack();
// tm_decomp = TRUE;

// vblank:

// if (flip && (ts_decomp || tm_trans))  --> mean we have data to transfer
// {
//   if (ts_decomp)
//   {
//     ts_decomp = !tsTransfer(ts_trans);
//     ts_trans = 0;    // so we don't re-initiate tile transfer on next frame
//   }
//   else if (tm_decomp)
//     tm_decomp = !tmTransfer();
//
//   // all decompression done --> time to flip
//   if(!tm_decomp)
//     flip = FALSE;
// }

// if (time_for_flip && !flip)
//{
//   doFlip();          // flip tilemap view and flip buffers
//   setEvenPal();      // set palette for even frame
//   flip = TRUE;
//   palFrame = 2;
//}
//else if (--palFrame == 0)
//  setOddPal();      // set palette oddeven frame


static char str1[32];

static u16 pal_even[16];
static u16 pal_odd[16];

static u16 pal_step[16] =
{
    0x555,
    0x055,
    0x550,
    0x505,
    0x005,
    0x050,
    0x500,
    0x355,
    0x553,
    0x535,
    0x335,
    0x353,
    0x533,
    0x333,
    0x033,
    0x330
};

static u16 pal_step_index;

static vu8 paused;

static u16 gen_frame;
static u16 int_frame;
static u16 mov_frame;

static vu8 ts_decomp;
static vu8 tm_decomp;
static vu16 ts_trans;
static vu8 flip_done;

static bool back;
static u16 transfer_phase;

static u32 wait;
static u16 fps;
static u16 show_fps;


static void joyEvent(u16 joy, u16 changed, u16 state);
static void vblank();
static void set_palette();
static void reset();


int main()
{
    fps = 0;
    show_fps = 0;

    VDP_setPlaneSize(64, 64, TRUE);

    JOY_setEventHandler(joyEvent);
    JOY_setSupport(PORT_1, JOY_SUPPORT_3BTN);
    JOY_setSupport(PORT_2, JOY_SUPPORT_OFF);

    PAL_setPalette(0, palette_black, CPU);

    VDP_drawText("Bad apple PV demo - SGDK sample", 2, 0);

    VDP_drawText("Video: 320x224 2bpp @30FPS", 9, 3);
    VDP_drawText("Audio: 4bit ADPCM @ 13 Khz", 9, 4);
    VDP_drawText("Duration: 3m39s", 6, 5);
    VDP_drawText("Raw size: 120 MB", 6, 6);
    VDP_drawText("Optimized size: 23 MB", 0, 7);
    VDP_drawText("Packed size: 10 MB (LZ4W compression)", 3, 8);

    VDP_drawText("A --> change palette", 4, 10);
    VDP_drawText("B --> display/hide FPS meter", 4, 11);

    VDP_drawText("Press START to continue.", 2, 14);

    PAL_fadeInPalette(PAL0, font_pal_lib.data, 20, FALSE);

    JOY_waitPress(JOY_1, BUTTON_START);

    PAL_fadeOutAll(20, FALSE);

    VDP_clearTileMapRect(BG_A, 0, 0, 64, 64);
    VDP_clearTileMapRect(BG_B, 0, 0, 64, 64);

    reset();

    SYS_setVIntCallback(vblank);

    while(mov_frame < 3235)
    {
        // do nothing on pause
        while(paused);

        // audio sync
        if (mov_frame == 5)
            startPlay(music, sizeof(music), 0);

        // unpack data (synched with vblank process)
        while(ts_decomp) wait++;
        ts_trans = ts_unpack(mov_frame);
        ts_decomp = TRUE;
        while(tm_decomp) wait++;
        tm_unpack(mov_frame);
        tm_decomp = TRUE;

        // decompression completed
        mov_frame++;
    }

    while(tm_decomp);

    waitMs(1500);

    SYS_setVIntCallback(NULL);

    VDP_init();
    VDP_setPlaneSize(64, 64, TRUE);
    PAL_setPalette(PAL0, palette_black, CPU);

    VDP_drawText("Hope you enjoyed :)", 5, 10);
    VDP_drawText("@2021  <NAME>", 9, 27);

    PAL_fadeInPalette(PAL0, font_pal_lib.data, 20, FALSE);

    SYS_setVIntCallback(vblank);

    while(TRUE);
}


static void reset()
{
    loadDriver();

    paused = FALSE;
    pal_step_index = 0;
    flip_done = TRUE;
    ts_decomp = FALSE;
    tm_decomp = FALSE;
    int_frame = 0;
    gen_frame = 0;
    mov_frame = 0;
    back = TRUE;
    transfer_phase = 0;
{'fraction_non_alphanumeric': 0.13718058442352365, 'fraction_numerical': 0.05330725027509475, 'mean_word_length': 2.6880072137060416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5264704', 'n_tokens_mistral': 3516, 'n_tokens_neox': 3136, 'n_words': 780}