From fc559b9f637156ab3df9e299166d8e1d65a12897 Mon Sep 17 00:00:00 2001 From: GrenderG Date: Thu, 14 Sep 2023 23:58:47 +0200 Subject: [PATCH] Some refactors. --- .gitignore | 1 + mewdistro.c | 148 ++++++++++++++++++++++++---------------------------- 2 files changed, 69 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index fa1624a..199900f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.gb *.noi *.map +*.sav .idea cmake-build-debug \ No newline at end of file diff --git a/mewdistro.c b/mewdistro.c index 6232a98..29f706a 100644 --- a/mewdistro.c +++ b/mewdistro.c @@ -1,9 +1,10 @@ #include #include -//#include #include #include #include +//#include + #include "gen1.h" #define PARTY_SIZE 6 @@ -18,65 +19,60 @@ #define SER_REG_DIR (*(uint8_t *)0xFF01) #define SER_OPT_REG_DIR (*(uint8_t *)0xFF02) -const unsigned char MewTiles[] = + +const unsigned char mew_tiles[] = { - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x01,0x03,0x06,0x01,0x08,0x09,0x09, - 0x02,0x12,0x1A,0x12,0x08,0x11,0x09,0x09, - 0x00,0x09,0x07,0x04,0x03,0x04,0x03,0x02, - 0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x01,0x03,0x03,0x07,0x00,0x00, - 0x30,0x78,0x66,0x47,0x50,0x60,0x28,0x30, - 0x20,0x30,0x00,0x20,0x25,0x46,0x46,0x49, - 0x47,0x4B,0x22,0x4A,0x23,0x23,0x21,0x21, - 0xD3,0xE0,0xF4,0x18,0xF8,0x7E,0x02,0x83, - 0x00,0x00,0x01,0x01,0x07,0x0F,0x03,0x11, - 0x13,0x11,0x87,0x8E,0xC7,0x46,0x2F,0xFE, - 0x96,0xFF,0x77,0x7F,0x13,0x1F,0x0B,0x0F, - 0x7F,0xFF,0xE7,0xFF,0xFF,0xFF,0x00,0x00, - 0xFC,0xFE,0x83,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x02,0x01,0x85,0x02, - 0x43,0x87,0x85,0x85,0x87,0x87,0x7A,0x86, - 0xFE,0x00,0x01,0x00,0x00,0x01,0x03,0x03, - 0xFC,0xFF,0x87,0xF8,0x08,0xF0,0x30,0xC0, - 0xC0,0x00,0x00,0x00,0x01,0x00,0x00,0x02, - 0x84,0x04,0x44,0x84,0xB8,0xC4,0xF3,0xFA, - 0xC1,0xE1,0x81,0x81,0x00,0x00,0x00,0x00, - 0x00,0x01,0x02,0x06,0x00,0x08,0x10,0x10, - 0x00,0x10,0x06,0x0E,0x00,0x01,0x00,0x00, - 0x1C,0x1C,0x64,0xE4,0xCC,0x44,0x14,0x0C, - 0x10,0x0C,0x18,0x08,0x88,0x84,0x84,0x44, - 0x8E,0x47,0x0F,0x44,0x09,0x07,0x18,0x08, - 0x30,0x10,0x40,0x60,0x80,0x80,0x00,0x00, - 0x80,0x80,0xC0,0x60,0xF8,0x18,0x7C,0x84, - 0xBE,0x42,0xFC,0x64,0xD8,0x58,0xC0,0x20, - 0x60,0x20,0x60,0x20,0xE0,0x20,0xD0,0x70, - 0x7C,0x8C,0x63,0x83,0xC9,0xC0,0x1F,0x3F, - 0x80,0xC0,0x20,0x30,0x08,0x08,0x08,0x04, - 0x0C,0x04,0x1C,0x02,0xFE,0xE2,0x0E,0x12, - 0x06,0x0A,0x0A,0x0A,0x0A,0x0A,0x08,0x0A, - 0x04,0x12,0x14,0x14,0x28,0x24,0x98,0xC8, - 0xF0,0x10,0xC0,0x60,0x00,0x80,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x80,0xC0,0x40,0x00,0x80, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x01,0x03,0x06,0x01,0x08,0x09,0x09, + 0x02,0x12,0x1A,0x12,0x08,0x11,0x09,0x09, + 0x00,0x09,0x07,0x04,0x03,0x04,0x03,0x02, + 0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x03,0x03,0x07,0x00,0x00, + 0x30,0x78,0x66,0x47,0x50,0x60,0x28,0x30, + 0x20,0x30,0x00,0x20,0x25,0x46,0x46,0x49, + 0x47,0x4B,0x22,0x4A,0x23,0x23,0x21,0x21, + 0xD3,0xE0,0xF4,0x18,0xF8,0x7E,0x02,0x83, + 0x00,0x00,0x01,0x01,0x07,0x0F,0x03,0x11, + 0x13,0x11,0x87,0x8E,0xC7,0x46,0x2F,0xFE, + 0x96,0xFF,0x77,0x7F,0x13,0x1F,0x0B,0x0F, + 0x7F,0xFF,0xE7,0xFF,0xFF,0xFF,0x00,0x00, + 0xFC,0xFE,0x83,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x02,0x01,0x85,0x02, + 0x43,0x87,0x85,0x85,0x87,0x87,0x7A,0x86, + 0xFE,0x00,0x01,0x00,0x00,0x01,0x03,0x03, + 0xFC,0xFF,0x87,0xF8,0x08,0xF0,0x30,0xC0, + 0xC0,0x00,0x00,0x00,0x01,0x00,0x00,0x02, + 0x84,0x04,0x44,0x84,0xB8,0xC4,0xF3,0xFA, + 0xC1,0xE1,0x81,0x81,0x00,0x00,0x00,0x00, + 0x00,0x01,0x02,0x06,0x00,0x08,0x10,0x10, + 0x00,0x10,0x06,0x0E,0x00,0x01,0x00,0x00, + 0x1C,0x1C,0x64,0xE4,0xCC,0x44,0x14,0x0C, + 0x10,0x0C,0x18,0x08,0x88,0x84,0x84,0x44, + 0x8E,0x47,0x0F,0x44,0x09,0x07,0x18,0x08, + 0x30,0x10,0x40,0x60,0x80,0x80,0x00,0x00, + 0x80,0x80,0xC0,0x60,0xF8,0x18,0x7C,0x84, + 0xBE,0x42,0xFC,0x64,0xD8,0x58,0xC0,0x20, + 0x60,0x20,0x60,0x20,0xE0,0x20,0xD0,0x70, + 0x7C,0x8C,0x63,0x83,0xC9,0xC0,0x1F,0x3F, + 0x80,0xC0,0x20,0x30,0x08,0x08,0x08,0x04, + 0x0C,0x04,0x1C,0x02,0xFE,0xE2,0x0E,0x12, + 0x06,0x0A,0x0A,0x0A,0x0A,0x0A,0x08,0x0A, + 0x04,0x12,0x14,0x14,0x28,0x24,0x98,0xC8, + 0xF0,0x10,0xC0,0x60,0x00,0x80,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0xC0,0x40,0x00,0x80, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -#define MewMapWidth 5 -#define MewMapHeight 5 -#define MewMapBank 0 - -/*const unsigned char MewMap[] = +// It has +128 since we are loading Mew sprites starting at position 128 +// to prevent collisions with the font sprites. +const unsigned char mew_map[] = { - 0x14,0x14,0x14,0x0B,0x10,0x14,0x03,0x07,0x0C,0x11, - 0x00,0x04,0x08,0x0D,0x12,0x01,0x05,0x09,0x0E,0x14, - 0x02,0x06,0x0A,0x0F,0x13 -};*/ -const unsigned char MewMap[] = -{ -0x94,0x94,0x94,0x8b,0x90,0x94,0x83,0x87,0x8c,0x91,0x80,0x84,0x88,0x8d,0x92,0x81,0x85,0x89,0x8e,0x94,0x82,0x86,0x8a,0x8f,0x93 + 0x94,0x94,0x94,0x8b,0x90,0x94,0x83,0x87,0x8c,0x91, + 0x80,0x84,0x88,0x8d,0x92,0x81,0x85,0x89,0x8e,0x94, + 0x82,0x86,0x8a,0x8f,0x93 }; enum connection_state_t connection_state = NOT_CONNECTED; @@ -114,7 +110,7 @@ unsigned char nicknames[11] = { typedef struct TraderPacket { // Name must not exceed 10 characters + 1 STOP_BYTE - // Any leftover space after STOP_BYTE must be filled with NULL_BYTE + // Any leftover space must be filled with STOP_BYTE unsigned char name[11]; struct SelectedPokemon selected_pokemon; struct PartyMember pokemon[6]; @@ -480,25 +476,15 @@ void main(void) } set_interrupts(SIO_IFLAG); // disable other interrupts. note: this disables sprite movement - puts(""); - puts(" Mew Distribution"); - puts(" Madrid 2000"); - puts(""); - puts(""); - puts(" Reset: Press Start"); - puts(""); - puts(""); - puts(""); - puts(""); - puts(""); - puts(""); - puts(""); - puts(""); - puts(""); - puts(" by @GrenderG"); - - set_bkg_data(128, 20, MewTiles); - set_bkg_tiles(7, 8, 5, 5, MewMap); + puts("\n Mew Distribution"); + puts(" Madrid 2000\n\n"); + puts(" Reset: Press Start\n\n\n\n\n\n\n\n\n"); + puts(" by @GrenderG"); + + // Load Mew tiles starting at position 128. + set_bkg_data(128, 20, mew_tiles); + // Draw Mew figure in the middle of the screen (more or less). + set_bkg_tiles(7, 8, 5, 5, mew_map); fill_pokemon_team(); //printf("%u\n", (randw() % (65535 - 60000 + 1)) + 60000); @@ -518,15 +504,17 @@ void main(void) __endasm; } + // See https://www.reddit.com/r/retrogamedev/comments/16f4myt/i_homebrewed_a_pokemon_gen_1_mew_distribution/ + // and https://github.com/gbdk-2020/gbdk-2020/pull/577 __asm - LD A,#0x02 + LD A,#0x02 ; .IO_RECEIVING LD (__io_status),A ; Store status LD A,#0x01 - LDH (0x02),A ; Use external clock + LDH (0x02),A ; (.SC) Use external clock LD A,(__io_out) - LDH (0x01),A ; Send __io_out byte + LDH (0x01),A ; (.SB) Send __io_out byte LD A,#0x81 - LDH (0x02),A ; Use external clock + LDH (0x02),A ; (.SC) Use external clock __endasm; while(_io_status == IO_RECEIVING || _io_status == IO_SENDING);