git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/examples/cross-platform/platformer_template/src/common.c

      1 
      2 #include <gbdk/platform.h>
      3 #include <gbdk/metasprites.h>
      4 #include <stdint.h>
      5 #include "common.h"
      6 
      7 uint8_t joypadCurrent=0, joypadPrevious=0;
      8 
      9 void WaitForStartOrA(void){
     10     while(1){
     11 
     12         // Get the joypad input
     13         joypadPrevious = joypadCurrent;
     14         joypadCurrent = joypad();
     15 
     16         if((joypadCurrent & J_START) && !(joypadPrevious & J_START))break;
     17         if((joypadCurrent & J_A) && !(joypadPrevious & J_A))break;
     18 
     19         vsync();
     20         
     21     }
     22 }
     23 
     24 void setBKGPalettes(uint8_t count, const palette_color_t *palettes) NONBANKED{
     25     // Set up color palettes
     26     #if defined(SEGA)
     27         //__WRITE_VDP_REG(VDP_R2, R2_MAP_0x3800);
     28         //__WRITE_VDP_REG(VDP_R5, R5_SAT_0x3F00);
     29         set_bkg_palette(0, count, palettes);
     30     #elif defined(NINTENDO) // With NINTENDO meaning GAMEBOY, ANALOGUEPOCKET, MEGADUCK
     31         if (_cpu == CGB_TYPE) {
     32             set_bkg_palette(OAMF_CGB_PAL0, count, palettes);
     33         }
     34     #elif defined(NINTENDO_NES)
     35         set_bkg_palette(0, count, palettes);
     36     #endif
     37 }
     38 
     39 
     40 void ShowCentered(uint8_t width,uint8_t height,uint8_t bank, uint8_t* tileData, uint8_t tileCount, uint8_t* mapData, const palette_color_t* palettes) NONBANKED{
     41 
     42 
     43     DISPLAY_OFF;
     44 
     45     uint8_t _previous_bank = CURRENT_BANK;
     46     
     47 
     48     // Hide any remainder sprites
     49     hide_sprites_range(0,MAX_HARDWARE_SPRITES);
     50 
     51     move_bkg(0,0);
     52 
     53     // Make sure the graphic is centered on the screen
     54     uint8_t titleRow = (DEVICE_SCREEN_HEIGHT-(height>>3))/2;
     55     uint8_t titleColumn = (DEVICE_SCREEN_WIDTH-(width>>3))/2;
     56 
     57     SWITCH_ROM(bank);
     58 
     59     setBKGPalettes(1,palettes);
     60 
     61     set_native_tile_data(0,tileCount,tileData);
     62     fill_bkg_rect(0,0,DEVICE_SCREEN_WIDTH,DEVICE_SCREEN_HEIGHT,0);
     63     set_bkg_tiles(titleColumn,titleRow,width>>3,height>>3,mapData);
     64     SWITCH_ROM(_previous_bank);
     65 
     66     DISPLAY_ON;
     67 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.