int main() { x=0; y=0; oldx=0; oldy=0; VDP_loadTileData( (const u32 *)tile1, 1, 1, 0); VDP_setTileMapXY(APLAN, 1, x+2, y+2); JOY_init(); JOY_setEventHandler( &myJoyHandler ); //VDP_drawText("Hello World!", x, y); while(1) { VDP_drawText(" ", oldx, oldy); VDP_drawText("Hello World!", x, y); VDP_setTileMapXY(APLAN, 1, x+2, y+2); VDP_waitVSync(); } return (0); }
void text_draw_sprite ( u8 *str, u16 x, u16 y, u16 ms ) { #define TILE _base + _positions[chr] * _width * _height #define ATTR TILE_ATTR_FULL ( _palette, 1, 0, 0, TILE ) u8 chr, i = 0; const u16 size = _genres->size >> 8; const u8 width = _genres->width; while ( (chr = *str++) ) { chr -= ' '; chr = ( chr >= 96 ) ? 0 : chr; if ( ! _positions[chr] ) { _positions[chr] = _counter++; VDP_loadTileData ( _genres->sprites[chr], TILE, size, TRUE ); VDP_waitVSync(); } VDP_setSprite ( i, x+i*width, y, size, ATTR, i+1 ); VDP_updateSprites(); waitMs ( ms ); ++i; } }
void FMP_load ( FMP *fmp, u8 dma ) { SYS_disableInts(); VDP_loadTileData ( fmp->map->tiles, fmp->vram, fmp->map->nbTiles, dma ); SYS_enableInts(); // if ( dma ) VDP_waitDMACompletion(); }
void HUD_init(){ VDP_loadTileData((const u32 *)circle, TILE_USERINDEX, 1, 0); VDP_loadTileData((const u32 *)circlePressed, TILE_USERINDEX+1, 1, 0); VDP_loadTileData((const u32 *)note, TILE_USERINDEX+2, 2, 0); VDP_loadTileData((const u32 *)overscore, TILE_USERINDEX+4, 2, 0); createHUDAll(); // VDP_setTileMap(APLAN, 5, 24); // u16 pal[16]; // VDP_getPalette(PAL0, pal); // for(i=0; i<16; i++){ // char text[5]; // intToHex(pal[i], text, 4); // VDP_drawText(text, 1 + (i/8 * 10), 17+ (i%8)); // } }
void showBmp ( u16 pal, struct genresTiles *grt, u16 tile, VDPPlan plan, u16 x, u16 y, u8 pal_steps ) { SYS_disableInts(); VDP_loadTileData ( grt->tiles, tile, grt->width * grt->height, 0 ); SYS_enableInts(); SYS_disableInts(); VDP_fillTileMapRectInc ( plan, TILE_ATTR_FULL ( pal, 1, 0, 0, tile ), x, y, grt->width, grt->height ); SYS_enableInts(); }
void text_draw ( u8 *str, u8 x, u8 y, u16 ms ) { #define POSITION _base + _positions[chr] * _tiles + inc u8 chr; u16 k; u16 j; u16 i = 0; u16 inc = 0; u8 *aux = str; while ( (chr = *aux++) ) { inc = 0; chr -= ' '; if ( chr >= 96 ) chr = 0; if ( ! _positions[chr] ) { _positions[chr] = _counter++; VDP_loadTileData ( _genres->sprites[chr], POSITION, _tiles, TRUE ); VDP_waitDMACompletion(); } } while ( (chr = *str++) ) { inc = 0; chr -= ' '; if ( chr >= 96 ) chr = 0; for ( j = 0; j < _height; j++ ) { for ( k = 0; k < _width; k++ ) { VDP_setTileMapXY ( BPLAN, TILE_ATTR_FULL ( _palette, TRUE, 0, 0, POSITION ), i*_width + x + j, y + k ); ++inc; } } waitMs ( ms ); ++i; } }
void titleScreen() { snowflake snowflakes[TITLE_SCREEN_SNOWFLAKES]; SpriteDef sfdefs[TITLE_SCREEN_SNOWFLAKES]; VDP_resetScreen(); VDP_resetSprites(); // Load Swirls VDP_loadTileData(swirls, TILE_USERINDEX, 20, TRUE); VDP_loadTileData(title_screen, TILE_USERINDEX + 20, 15, TRUE); VDP_loadTileData(swirl_spr, TILE_USERINDEX + 35, 20, TRUE); VDP_setPalette(PAL1, swirl_pal); VDP_setPalette(PAL2, sel_pal); VDP_setPalette(PAL3, ts_pal); JOY_init(); JOY_setEventHandler(titleHandler); ImageAsset* title = getImage(titlbg); VDP_setPalette(PAL0, title->palette); VDP_loadTileData(title->tiles, TILE_USERINDEX + 55, (title->xTiles * title->yTiles), TRUE); VDP_fillTileMapRectInc(VDP_PLAN_B, TILE_ATTR_FULL(PAL0, PRIORITY_LOW, FALSE, FALSE, TILE_USERINDEX + 55), 0, 0, title->xTiles, title->yTiles); MEM_free( title ); VDP_fillTileMapRectInc(VDP_PLAN_A, TILE_ATTR_FULL(PAL3, PRIORITY_LOW, FALSE, FALSE, TILE_USERINDEX + 20), 18, 3, 5, 3); VDP_drawText("Mega Swirl", 1, 7); VDP_drawText("Testing Demo", 1, 8); VDP_drawText(VERSION_STRING, 1, 9); VDP_drawText("Music from Deflemask by", 1, 11); VDP_drawText("Delek", 1, 12); VDP_drawText("Featuring artwork by", 1, 14); VDP_drawText("Radioactivemantaray", 1, 15); VDP_drawText("- Press Start to Play -", 1, 21); VDP_drawText(BUILD_DATE, 1, 24); u8 selected_swirl; for(int i = 0; i != TITLE_SCREEN_SNOWFLAKES; i++) { snowflakes[i].startedAt = snowflakes[i].startDelay = snowflakes[i].fallRate = snowflakes[i].swirltype = 0; sfdefs[i].posx = sfdefs[i].posy = sfdefs[i].tile_attr = sfdefs[i].size = sfdefs[i].link = 0; selected_swirl = (custrand() % 4); snowflakes[i].swirltype = selected_swirl; // Select one of four swirl types snowflakes[i].startDelay = ((custrand() % 3000) + 1) / 300; // Select between a 1-10 second delay (300 ticks per second) snowflakes[i].startedAt = getTick(); // Time when this snowflake was created snowflakes[i].fallRate = (custrand() % 2) + 1; // Select how fast this snowflake should fall to the bottom of the screen sfdefs[i].posx = (custrand() % 320); // Select X position for this swirl sfdefs[i].posy = -16; // Start it off screen sfdefs[i].size = SPRITE_SIZE(2, 2); sfdefs[i].tile_attr = TILE_ATTR_FULL(PAL1, PRIORITY_HIGH, FALSE, FALSE, TILE_USERINDEX + 35 + (4 * selected_swirl)); // This will need to be changed as we need tiles arranged for sprites if(i != 0) { sfdefs[i - 1].link = i; } } VDP_setSpritesDirect(0, sfdefs, TITLE_SCREEN_SNOWFLAKES); Z80_loadDriver(Z80_DRIVER_VGM, 1); Z80_requestBus(1); YM2612_enableDAC(); Z80_releaseBus(); SND_startPlay_VGM(muz_title); while (waitflag == FALSE) { for(int i = 0; i != TITLE_SCREEN_SNOWFLAKES; i++) { if(getTick() - snowflakes[i].startedAt >= snowflakes[i].startDelay) { if(sfdefs[i].posy != 240) { sfdefs[i].posy = sfdefs[i].posy + snowflakes[i].fallRate; } else { selected_swirl = (custrand() % 4); snowflakes[i].startDelay = ((custrand() % 3000) + 1) / 300; snowflakes[i].startedAt = getTick(); snowflakes[i].fallRate = (custrand() % 2) + 1; sfdefs[i].posx = (custrand() % 320); sfdefs[i].posy = -16; } } VDP_setSpritesDirect(0, sfdefs, TITLE_SCREEN_SNOWFLAKES); } } waitflag = FALSE; srand(GET_HVCOUNTER); VDP_clearPlan(APLAN, FALSE); JOY_setEventHandler(joyHandler); ImageAsset* test = getImage(swlspace); VDP_setPalette(PAL0, test->palette); VDP_loadTileData(test->tiles, TILE_USERINDEX + 55, (test->xTiles * test->yTiles), TRUE); VDP_fillTileMapRectInc(VDP_PLAN_B, TILE_ATTR_FULL(PAL0, PRIORITY_LOW, FALSE, FALSE, TILE_USERINDEX + 55), 0, 0, test->xTiles, test->yTiles); MEM_free( test ); SND_stopPlay_VGM(); }
s16 TC_alloc(TileCache *cache, TileSet *tileset, TCUpload upload) { TCBloc *bloc; // KDebug_Alert("Alloc TC"); // KDebug_AlertNumber(tileset); bloc = getBloc(cache, tileset); // bloc found if (bloc != NULL) { // get address of next fixed bloc u16 nextFixed = cache->nextFixed; TCBloc *nextFixedBloc = &cache->blocs[nextFixed]; // flushed bloc ? --> re allocate it if (bloc >= nextFixedBloc) { // need to swap blocs ? if (bloc != nextFixedBloc) { u16 tmpInd = bloc->index; bloc->index = nextFixedBloc->index; bloc->tileset = nextFixedBloc->tileset; nextFixedBloc->index = tmpInd; nextFixedBloc->tileset = tileset; bloc = nextFixedBloc; } // one more fixed bloc cache->nextFixed = nextFixed + 1; } return bloc->index; } // bloc not found --> alloc else { u16 index, size, lim; u16 nextFlush; // not more free bloc if (cache->nextFixed >= cache->numBloc) { if (LIB_DEBUG) KDebug_Alert("TC_alloc failed: no more free bloc !"); return -1; } size = tileset->numTile; // search for free region (this method can consume a lot of time :-/) index = findFreeRegion(cache, size); // not enough space in cache if ((s16) index == -1) return index; // process VDP upload if required if (upload != NO_UPLOAD) { // no compression if (tileset->compression == COMPRESSION_NONE) { // upload the tileset to VRAM now if (upload == UPLOAD_NOW) VDP_loadTileData(tileset->tiles, index, size, TRUE); // upload at VINT else addToUploadQueue(tileset, index); } else { // unpack tileset TileSet *unpacked = unpackTileSet(tileset, NULL); // error while unpacking tileset if (unpacked == NULL) return -1; // upload the tileset to VRAM now ? if (upload == UPLOAD_NOW) { // upload VDP_loadTileData(unpacked->tiles, index, size, TRUE); // and release memory MEM_free(unpacked); } // upload at VINT else { // we will use that to release automatically the TileSet after upload unpacked->compression = COMPRESSION_APLIB; // put in upload queue addToUploadQueue(unpacked, index); } } } lim = index + size; // update current position cache->current = lim; // release any previous flushable bloc in the allocated area releaseFlushable(cache, index, lim); // get new allocated bloc bloc = &cache->blocs[cache->nextFixed++]; // try to save flush bloc if we still have available bloc for that ? nextFlush = cache->nextFlush; if (nextFlush < cache->numBloc) { TCBloc *nextFlushBloc = &cache->blocs[nextFlush]; // test if we have something to save if (nextFlushBloc != bloc) { nextFlushBloc->index = bloc->index; nextFlushBloc->tileset = bloc->tileset; } // increase flush bloc address cache->nextFlush = nextFlush + 1; } // set bloc info bloc->tileset = tileset; bloc->index = index; } return bloc->index; }