Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <genesis.h>
- #include "State_vscroll.h"
- #include "../res/gfx.h"
- #include "Globals.h"
- typedef struct
- {
- s8 color;
- s16 position;
- } Segment;
- // road segments
- #define SEG_COUNT 64
- Segment s[SEG_COUNT];
- static int m_Size = 16;
- // lookup table to index into the road
- static int m_Index[112];
- // v-scroll offset
- static int m_Lines[112];
- static int m_Position = 0;
- static int m_Offset = 0;
- static int m_CurrentSegment = 0;
- void State_VScroll_Start()
- {
- fix32 size = FIX32(1.0f);
- fix32 amount = FIX32(0.055f);
- int i = 111;
- int place = -1;
- do
- {
- m_Index[i] = place + fix32ToInt(size);
- place++;
- if (place > 20)
- {
- size = fix32Add(size, fix32Mul(size, amount));
- }
- KLog_S2("i ", i, " index ", m_Index[i]);
- i--;
- } while (i >= 0);
- int co = 16;
- int pos = 0;
- for(i=0;i<SEG_COUNT;i++)
- {
- s[i].color = co;
- s[i].position = pos;
- co = co == 16? -112 : 16;
- pos += m_Size;
- }
- SYS_disableInts();
- // Set palette to black
- VDP_setPaletteColors(0, (u16*)palette_black, 63);
- int ind = TILE_USERINDEX;
- VDP_drawImageEx(PLAN_B, &gfx_outtest, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, DMA);
- VDP_setPalette(PAL0, gfx_outtest.palette->data);
- internalHIntCB = &State_HScroll_HInt;
- VDP_setHInterrupt(TRUE);
- VDP_setHIntCounter(0);
- SYS_enableInts();
- }
- fix16 inc = FIX16(0.33);
- void State_VScroll_Update()
- {
- if (Pad1.Down == PAD_HELD)
- {
- m_Position++;
- m_Offset++;
- }
- if (m_Offset == m_Size)
- {
- m_CurrentSegment++;
- if (m_CurrentSegment >= SEG_COUNT)
- {
- m_CurrentSegment = 0;
- m_Position = 0;
- }
- }
- int indexSegment = m_CurrentSegment;
- for (int i = 0; i < 112; ++i)
- {
- // % SEG_COUNT
- int index = ((m_Index[i] + m_Position) >> 3) & 0x3F;
- m_Lines[i] = s[index].color;
- }
- KLog_S1("fps ", getFPS());
- }
- void State_VScroll_End()
- {
- }
- void State_VScroll_VInt()
- {
- VDP_setVerticalScroll(PLAN_B, 256);
- }
- void State_HScroll_HInt()
- {
- if (GET_VCOUNTER > 111 && GET_VCOUNTER < 224)
- {
- VDP_setVerticalScroll(PLAN_B, m_Lines[GET_VCOUNTER - 112]);
- }
- }
- SimpleState VScroll_State =
- {
- State_VScroll_Start,
- State_VScroll_Update,
- State_VScroll_End,
- State_VScroll_VInt
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement