smoketest.c (2323B)
1#include <gbdk/platform.h> 2 3BANKREF_EXTERN(earth_data) 4extern const unsigned char earth_data[]; 5 6BANKREF_EXTERN(earth_data_size) 7extern const unsigned int earth_data_size; 8 9const uint8_t tilemap[] = {2, 4, 6, 8, 3, 5, 7, 9}; 10const uint16_t tilemapw[] = {2, 4, 6, 8, 3, 5, 7, 9}; 11 12uint16_t banked_func(uint8_t be, uint8_t ef) __banked; 13 14int16_t x = 8 << 4, y = 0; 15int8_t xspd = 0, yspd = 0; 16 17uint8_t anim = 0, tick = 0; 18 19joypads_t joy; 20void main() { 21 HIDE_LEFT_COLUMN; 22 SPRITES_8x16; 23 DISPLAY_ON; 24 25// vmemcpy(0x4000, earth_data, sizeof(earth_data)); 26 27 SWITCH_ROM(BANK(earth_data)); 28 if (banked_func(0xBE, 0xEF) == 0xBEEF) { 29 set_bkg_data(2, earth_data_size >> 4, earth_data); 30 set_sprite_data(0, earth_data_size >> 4, earth_data); 31 set_sprite_tile(0, 0); 32 set_sprite_tile(1, 2); 33 } 34 35 set_bkg_tiles(4, 10, 4, 2, tilemap); 36 37 set_tile_map(4, 16, 4, 2, tilemapw); 38 39 joypad_init(2, &joy); 40 41 while(TRUE) { 42 joypad_ex(&joy); 43 44 if (joy.joy0 & J_LEFT) { 45 if (xspd > -32) xspd -= 2; 46 } else if (joy.joy0 & J_RIGHT) { 47 if (xspd < 32) xspd += 2; 48 } else { 49 if (xspd < 0) xspd++; else if (xspd > 0) xspd--; 50 } 51 52 if (joy.joy0 & J_UP) { 53 if (yspd > -32) yspd -= 2; 54 } else if (joy.joy0 & J_DOWN) { 55 if (yspd < 32) yspd += 2; 56 } else { 57 if (yspd < 0) yspd++; else if (yspd > 0) yspd--; 58 } 59 60 x += xspd; 61 if (x < (8 << 4)) x = 8 << 4; else if (x > (30 * 8) << 4) x = (30 * 8) << 4; 62 63 64 y += yspd; 65 if (y < 0) y = 0; else if (y > (22 * 8) << 4) y = (22 * 8) << 4; 66 67 tick++; tick &= 7; 68 if (!tick) { 69 anim++; if (anim == 7) anim = 0; 70 set_sprite_tile(0, anim << 2); 71 set_sprite_tile(1, (anim << 2) + 2); 72 } 73 74 move_sprite(0, x >> 4, y >> 4); 75 move_sprite(1, (x >> 4) + 8, y >> 4); 76 77 if (joy.joy1 & J_LEFT) { 78 scroll_bkg(-1, 0); 79 } else if (joy.joy1 & J_RIGHT) { 80 scroll_bkg(1, 0); 81 } 82 if (joy.joy1 & J_UP) { 83 scroll_bkg(0, -1); 84 } else if (joy.joy1 & J_DOWN) { 85 scroll_bkg(0, 1); 86 } 87 88 wait_vbl_done(); 89 } 90}