Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../include/main.h"
- #define _RETURN(x) if ( !(x) ) return;
- #define _RETURN_N(x,ret) if ( !(x) ) return (ret);
- #define _AB_PLAN(x) u8 _plan = ( x == APLAN ) ? 0 : 1;
- #define SCR _scroll [ _plan ]
- #define RES _scroll [ _plan ].res
- #define COLS VDP_getScreenWidth() / 8
- #define ROWS VDP_getScreenHeight() / 8
- static SCROLL _scroll[2];
- u16 scroll_init ( u16 plan, MAPPY_RES *res, u16 pal )
- {
- _AB_PLAN(plan);
- SCR.x = 0;
- SCR.y = 0;
- SCR.res = res;
- SCR.pal = pal;
- SCR.vram = vram_new ( RES->nbTiles );
- SCR.plan = plan;
- SCR.level = 0;
- SCR.scrollH = 0;
- SCR.scrollV = 0;
- SCR.plan_x = 0;
- SCR.plan_y = 0;
- //VDP_setPalette ( SCR.pal, (u16*) RES->ptrPal );
- VDP_setPalette ( SCR.pal, palette_black );
- VDP_loadTileData ( (u32*) RES->ptrTiles, SCR.vram, RES->nbTiles, TRUE );
- return SCR.vram;
- }
- void scroll_show ( u16 plan )
- {
- _AB_PLAN(plan);
- s16 i;
- for ( i=-1; i<ROWS+1; i++ )
- {
- _row ( SCR, i );
- }
- VDP_setHorizontalScroll ( SCR.plan, SCR.x );
- VDP_setVerticalScroll ( SCR.plan, SCR.y );
- VDP_setPalette ( SCR.pal, (u16*) RES->ptrPal );
- }
- s8 scroll_move_x ( u16 plan, s8 value )
- {
- _RETURN_N(value,0);
- _AB_PLAN(plan);
- return SCR.scrollH = value ;
- }
- s8 scroll_move_y ( u16 plan, s8 value )
- {
- _RETURN_N(value,0);
- _AB_PLAN(plan);
- return SCR.scrollV = value ;
- }
- void scroll_update ( u16 plan )
- {
- _AB_PLAN ( plan );
- _RETURN ( ( SCR.scrollH + SCR.scrollV ) );
- VDP_setHorizontalScroll ( plan, SCR.x+=SCR.scrollH );
- VDP_setVerticalScroll ( plan, SCR.y+=SCR.scrollV );
- s8 inc_x = 0;
- s8 inc_y = 0;
- if ( SCR.plan_x != -SCR.x/8 ) SCR.plan_x += ( inc_x = ( SCR.scrollH > 0 ) ? -1 : 1 );
- if ( SCR.plan_y != +SCR.y/8 ) SCR.plan_y -= ( inc_y = ( SCR.scrollV > 0 ) ? -1 : 1 );
- if ( inc_x < 0 ) _col ( SCR, SCR.plan_x - 1 ) ;
- else if ( inc_x > 0 ) _col ( SCR, SCR.plan_x + COLS ) ;
- if ( inc_y > 0 ) _row ( SCR, SCR.plan_y - 1 ) ;
- else if ( inc_y < 0 ) _row ( SCR, SCR.plan_y + ROWS ) ;
- SCR.scrollH = 0;
- SCR.scrollV = 0;
- }
- static void _col ( SCROLL scr, s32 x )
- {
- s16 i;
- s32 v1 = _trunc ( x, scr.res->width );
- s32 v2 = _trunc ( x, VDP_getPlanWidth() );
- u16 *mp = (u16*) scr.res->maps [ scr.level ];
- u16 t;
- for ( i=-1 ; i<ROWS+1; i++ )
- {
- s32 aux = i + scr.plan_y;
- s32 aux2 = _trunc ( aux, VDP_getPlanHeight() );
- t = aux * scr.res->width + v1;
- t = TILE_ATTR_FULL ( scr.pal, 0, 0, 0, mp[t] ) + scr.vram ;
- VDP_setTileMap ( scr.plan, t, v2, aux2 ) ;
- }
- }
- static void _row ( SCROLL scr, s32 y )
- {
- s16 i;
- s32 v1 = _trunc ( y, scr.res->height );
- s32 v2 = _trunc ( y, VDP_getPlanHeight() );
- u16 *mp = (u16*) scr.res->maps [ scr.level ];
- u16 t;
- for ( i=-1 ; i<COLS+1; i++ )
- {
- s32 aux = i + scr.plan_x;
- s32 aux2 = _trunc ( aux, VDP_getPlanWidth() );
- t = v1 * scr.res->width + aux;
- t = TILE_ATTR_FULL ( scr.pal, 0, 0, 0, mp[t] ) + scr.vram ;
- VDP_setTileMap ( scr.plan, t, aux2, v2 ) ;
- }
- }
- static s32 _trunc ( s32 value, s32 max )
- {
- volatile register s32 v = value % max;
- if ( v < 0 )
- return v + max;
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement