aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/demo.c153
-rw-r--r--src/demo.h35
-rw-r--r--src/ds.mk4
-rw-r--r--src/entity.h15
-rw-r--r--src/input.h22
-rw-r--r--src/main.c248
-rw-r--r--src/ppusim/input.c16
-rw-r--r--src/stm32.mk3
-rw-r--r--src/stm32/input.c13
9 files changed, 256 insertions, 253 deletions
diff --git a/src/demo.c b/src/demo.c
index 019750a..c4e4d7a 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -2,10 +2,36 @@
#include "demo.h"
#include "ppu/ppu.h"
+#include "input.h"
+#include "entity.h"
-#define HH_DEMO_BALL_COUNT 5
+#define HH_DEMO_BALL_COUNT 1
hh_s_ppu_loc_fam_entry g_hh_demo_balls[HH_DEMO_BALL_COUNT];
+hh_s_entity_player g_hh_player_1 = {
+ .pos_x = 31000, //0b0000 0001 0011 0110
+ .pos_y = 21000,
+ .radius = 8,
+ .speed = 1,
+ .direction_x = 1,
+ .rotation = 8,
+ .in_air = false,
+};
+
+void playerMovement();
+
+uint16_t pos_x; //0b0000 0001 0011 0110
+uint16_t pos_y;
+uint8_t left = 0;
+uint8_t right = 0;
+uint8_t up = 0;
+uint8_t down = 0;
+uint8_t pos_x_bit[2];
+uint8_t pos_y_bit[2];
+uint8_t data_send[3];
+int tileX;
+int tileY;
+
void hh_demo_setup() {
// load sprites
hh_ppu_update_sprite(0, HH_DBG_SPRITE_BALL);
@@ -39,6 +65,22 @@ void hh_demo_setup() {
}
void hh_demo_loop(unsigned long frame) {
+ playerMovement();
+
+ //adjust map size
+ pos_x = g_hh_player_1.pos_x / 100;
+ pos_y = g_hh_player_1.pos_y / 100;
+
+ // input testing (no hitbox stuff)
+ // pos_x += (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); // -1 = L || 1 == R
+ // pos_y += (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down); // -1 = D || 1 == U
+
+ // update player sprite on ppu
+ g_hh_demo_balls[0].position_x = pos_x;
+ g_hh_demo_balls[0].position_y = pos_y;
+ hh_ppu_update_foreground(0, g_hh_demo_balls[0]);
+
+
// set background pattern position
hh_ppu_update_aux((hh_s_ppu_loc_aux) {
.bg_shift_x = (frame / 2) % HH_PPU_SPRITE_WIDTH,
@@ -46,10 +88,111 @@ void hh_demo_loop(unsigned long frame) {
.fg_fetch = 0,
.sysreset = 0,
});
+}
+
+// void sendData(uint8_t address, uint16_t data) {
+// uint8_t bitData[3];
+// bitData[2] = data & 0xff;
+// bitData[1] = (data >> 8);
+// bitData[0] = address; // first byte is address
+//
+// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);
+// HAL_SPI_Transmit(&hspi1, bitData, 3, 100); //2*8 bit data
+// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET);
+// }
+
+void playerMovement() {
+ int8_t directionX = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); // -1 = L || 1 == R
+ int8_t directionY = (-1 * g_hh_controller_p1.dpad_down) + (1 * g_hh_controller_p1.dpad_up); // -1 = D || 1 == U
+
+ uint8_t i,j;
+ uint8_t rotation = 0; // 0-7
+
+ //rotation calc
+ for(i = -1; i < 2;i++)
+ {
+ for(j = -1; j < 2; j++)
+ {
+ if(directionX == i)
+ {
+ if(directionY == j)
+ {
+ if(i != 0 && j != 0) //dont update when player idle
+ {
+ g_hh_player_1.rotation = rotation;
+ }
+ }
+ }
+ rotation++;
+ }
+ }
+ //direction calc
+ if(directionX != 0) //update direction if player is not idle
+ {
+ g_hh_player_1.direction_x = directionX;
+ }
+ //collision map x-axis
+
+ //tile calc including radius and direction for background coliision
+
+ uint16_t tileColX;
+ uint16_t tileColY = ( g_hh_player_1.pos_y / 100) / 16; ;
+
+ // remaining space between grid and exact
+ uint8_t modTileX;
+ uint8_t modTileY;
+
+ if(g_hh_player_1.in_air == false && directionX != 0)
+ {
+ if(directionX == 1)
+ {
+ tileColX = ( ( g_hh_player_1.pos_x / 100) + g_hh_player_1.radius ) / 20;
+ modTileX = ( g_hh_player_1.pos_x + ( 100 * g_hh_player_1.radius ) ) % 2000;
+ }
+ else if(directionX == -1)
+ {
+ tileColX = ( ( g_hh_player_1.pos_x / 100) - g_hh_player_1.radius ) / 20;
+ modTileX = ( g_hh_player_1.pos_x - ( 100 * g_hh_player_1.radius ) ) % 2000;
+ }
+
+ if(HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] != 1)
+ {
+ g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * g_hh_player_1.speed); // NEW x set
+ }
+
+ else if(HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] == 1)
+ {
+ if(modTileX < g_hh_player_1.speed)
+ {
+ g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * modTileX); // NEW x set
+ }
+ else
+ {
+ g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * g_hh_player_1.speed); // NEW x set
+ }
+ }
+
+ }
+ else //if in air different all borders have to be checked
+ {
- for (unsigned i = 0; i < HH_DEMO_BALL_COUNT; i++) {
- g_hh_demo_balls[i].position_x = HH_PPU_SCREEN_WIDTH/2 - HH_PPU_SPRITE_WIDTH/2 + (int)(60 * (double)sin((1*(double)frame / 10) + (double)i * 12));
- g_hh_demo_balls[i].position_y = HH_PPU_SCREEN_HEIGHT/2 - HH_PPU_SPRITE_HEIGHT/2 + (int)(30 * (double)sin((2*(double)frame / 10) + (double)i * 12));
- hh_ppu_update_foreground(i, g_hh_demo_balls[i]);
}
+
+ //collision map floor (y-axis) (falling)
+ // if falling no jump press (implement)
+ /*
+ tileColY = (( g_hh_player_1.pos_y / 100) + g_hh_player_1.radius) / 16; //bottom of player box
+ modTileY = 1;
+ if(HH_DEMO_HITBOX_TILEMAP[tileColY+1][tileColX] != 1) //rework after jumping
+ {
+ g_hh_player_1.pos_y = g_hh_player_1.pos_y + 5 ;// NEW y set //makew var gravity
+ //playerStat = falling; //for later use of graphics/sound
+ }
+ */
+ //else if(HH_DEMO_HITBOX_TILEMAP[])
+
+
+
+
+
}
diff --git a/src/demo.h b/src/demo.h
index 89436b5..ddf8403 100644
--- a/src/demo.h
+++ b/src/demo.h
@@ -42,3 +42,38 @@ static const hh_s_ppu_loc_sprite HH_DBG_SPRITE_CHECKERBOARD = {
0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0
};
+
+static const uint8_t HH_DEMO_HITBOX_TILEMAP[30][40] =
+ {
+ {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0 ,1,1,1,1,1,1,1,1,1,1 },
+ {1,1,1,1,1,1,1,1,1,1 ,0,0,0,0,0,0,0,0,0,0 ,0,0,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diff --git a/src/ds.mk b/src/ds.mk
index b5633b3..57d1776 100644
--- a/src/ds.mk
+++ b/src/ds.mk
@@ -11,5 +11,5 @@ DESKTOP_SRCS += ppusim/sim.c \
ppusim/mem.c \
ppusim/pixel.c \
ppusim/work.c \
- ds.c
-
+ ds.c \
+ ppusim/input.c
diff --git a/src/entity.h b/src/entity.h
new file mode 100644
index 0000000..20cbf42
--- /dev/null
+++ b/src/entity.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef struct {
+ uint16_t pos_x;
+ uint16_t pos_y;
+ uint8_t radius;
+ uint8_t rotation; //45 degrees steps 0 == right 2 == down 4 == left 6 == up
+ uint8_t direction_x; //direction where its looking at in case no input;
+ int8_t speed; //10 default L/R MODifier
+ bool in_air;
+} hh_s_entity_player;
+
diff --git a/src/input.h b/src/input.h
new file mode 100644
index 0000000..adacba2
--- /dev/null
+++ b/src/input.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <stdbool.h>
+
+/** @brief game controller state */
+typedef struct {
+ bool dpad_up;
+ bool dpad_down;
+ bool dpad_left;
+ bool dpad_right;
+ bool button_primary;
+ bool button_secondary;
+} hh_s_gamepad;
+
+/** @brief player 1's controller */
+extern hh_s_gamepad g_hh_controller_p1;
+/** @brief player 2's controller */
+extern hh_s_gamepad g_hh_controller_p2;
+
+/** @brief update g_hh_controller_p1 and 2 by reading buttons */
+void hh_input_read();
+
diff --git a/src/main.c b/src/main.c
index ee6125f..fa63aa2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,97 +2,12 @@
#include "main.h"
#include "demo.h"
+#include "input.h"
bool g_hh_run = true;
-static int8_t buttonDPAD[] = {0,0,0,0}; //1left 2right 3down 4up
-
-struct playerData{
- uint16_t posX;
- uint16_t posY;
- uint8_t radius;
- uint8_t rotation; //45 degrees steps 0 == right 2 == down 4 == left 6 == up
- uint8_t directionX; //direction where its looking at in case no input;
- int8_t speed; //10 default L/R MODifier
- bool inAir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,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 },
- {1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 }
-
-
-
- };
-
-void buttonRead();
-void playerMovement();
-void sendData(uint8_t, uint16_t);
-
- uint16_t pos_x; //0b0000 0001 0011 0110
- uint16_t pos_y;
-
- uint8_t left = 0;
- uint8_t right = 0;
- uint8_t up = 0;
- uint8_t down = 0;
-
-
-
- uint8_t pos_x_bit[2];
- uint8_t pos_y_bit[2];
- uint8_t data_send[3];
-
- int tileX;
- int tileY;
-// struct playerData player1;
- //int buttons[] = {GPIO_PIN_4,GPIO_PIN_5,GPIO_PIN_6,GPIO_PIN_8}; // 1 left // 2 right // 3 up // 4 down
-
-
int main() {
hh_setup();
-
-/// init struct
- player1.posX = 31000; //0b0000 0001 0011 0110
- player1.posY = 21000;
- player1.radius = 8;
- player1.speed = 1;
- player1.directionX = 1;
- player1.rotation = 8;
- player1.inAir = false;
-
hh_loop();
hh_exit();
return 0;
@@ -100,165 +15,8 @@ int main() {
void hh_ppu_vblank_interrupt() {
static unsigned long frame = 0;
+ hh_input_read();
+ hh_demo_loop(frame);
frame++;
-
- buttonRead();
- playerMovement();
-
-
- // send data via SPI //adjust map size
- pos_x = player1.posX / 100;
- pos_y = player1.posY / 100;
-
- sendData(0b01000000,pos_x);
- sendData(0b00000000,pos_y);
-
- // hh_demo_loop(frame);
}
-void sendData(uint8_t address, uint16_t data)
-{
- uint8_t bitData[3];
- bitData[2] = data & 0xff;
- bitData[1] = (data >> 8);
- bitData[0] = address; // first byte is address
-
-
-
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);
- HAL_SPI_Transmit(&hspi1, bitData, 3, 100); //2*8 bit data
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET);
-
-}
-
-void buttonRead()
-{
- //int buttons[] = {GPIO_PIN_4,GPIO_PIN_5,GPIO_PIN_6,GPIO_PIN_8}; // 1 left // 2 right // 3 down // 4 up 8-6-4-5
- uint16_t buttons[] = {0x0100U,0x0040U,0x0010U,0x0020U}; // 1 left // 2 right // 3 down // 4 up
-
- for(int i = 0; i < 4; i++)
- {
- if(HAL_GPIO_ReadPin(GPIOB, buttons[i]) == 1)
- {
- if((i+2) % 2 == 0)
- {
- buttonDPAD[i] = 1;
- }
- else
- {
- buttonDPAD[i] = -1;
- }
- }
- else
- {
- buttonDPAD[i] = 0;
- }
- }
-}
-
-void playerMovement()
-{
-
- int8_t directionX = 0; // -1 = L || 1 == R
- int8_t directionY = 0; // -1 = D || 1 == U
-
- uint8_t i,j;
- uint8_t rotation = 0; // 0-7
- //temp var for testing
-
-
-
- // direction calc
- directionX = buttonDPAD[0] + buttonDPAD[1];
- directionY = buttonDPAD[2] + buttonDPAD[3];
-
- //rotation calc
- for(i = -1; i < 2;i++)
- {
- for(j = -1; j < 2; j++)
- {
- if(directionX == i)
- {
- if(directionY == j)
- {
- if(i != 0 && j != 0) //dont update when player idle
- {
- player1.rotation = rotation;
- }
- }
- }
- rotation++;
- }
- }
- //direction calc
- if(directionX != 0) //update direction if player is not idle
- {
- player1.directionX = directionX;
- }
- //collision map x-axis
-
- //tile calc including radius and direction for background coliision
-
- uint16_t tileColX;
- uint16_t tileColY = ( player1.posY / 100) / 16; ;
-
- // remaining space between grid and exact
- uint8_t modTileX;
- uint8_t modTileY;
-
-
-
- if(player1.inAir == false && directionX != 0)
- {
- if(directionX == 1)
- {
- tileColX = ( ( player1.posX / 100) + player1.radius ) / 20;
- modTileX = ( player1.posX + ( 100 * player1.radius ) ) % 2000;
- }
- else if(directionX == -1)
- {
- tileColX = ( ( player1.posX / 100) - player1.radius ) / 20;
- modTileX = ( player1.posX - ( 100 * player1.radius ) ) % 2000;
- }
-
- if(tileMap[tileColY][tileColX + directionX] != 1)
- {
- player1.posX = player1.posX + (directionX * player1.speed); // NEW x set
- }
-
- else if(tileMap[tileColY][tileColX + directionX] == 1)
- {
- if(modTileX < player1.speed)
- {
- player1.posX = player1.posX + (directionX * modTileX); // NEW x set
- }
- else
- {
- player1.posX = player1.posX + (directionX * player1.speed); // NEW x set
- }
- }
-
- }
- else //if in air different all borders have to be checked
- {
-
- }
-
- //collision map floor (y-axis) (falling)
- // if falling no jump press (implement)
- /*
- tileColY = (( player1.posY / 100) + player1.radius) / 16; //bottom of player box
- modTileY = 1;
- if(tileMap[tileColY+1][tileColX] != 1) //rework after jumping
- {
- player1.posY = player1.posY + 5 ;// NEW y set //makew var gravity
- //playerStat = falling; //for later use of graphics/sound
- }
- */
- //else if(tileMap[])
-
-
-
-
-
-}
diff --git a/src/ppusim/input.c b/src/ppusim/input.c
new file mode 100644
index 0000000..bdb94ac
--- /dev/null
+++ b/src/ppusim/input.c
@@ -0,0 +1,16 @@
+#include <SDL2/SDL.h>
+
+#include "input.h"
+
+hh_s_gamepad g_hh_controller_p1 = { 0 };
+hh_s_gamepad g_hh_controller_p2 = { 0 };
+
+void hh_input_read() {
+ // SDL_PumpEvents();
+ const Uint8* kb = SDL_GetKeyboardState(NULL);
+ g_hh_controller_p1.dpad_up = kb[SDL_SCANCODE_W];
+ g_hh_controller_p1.dpad_down = kb[SDL_SCANCODE_S];
+ g_hh_controller_p1.dpad_left = kb[SDL_SCANCODE_A];
+ g_hh_controller_p1.dpad_right = kb[SDL_SCANCODE_D];
+}
+
diff --git a/src/stm32.mk b/src/stm32.mk
index eab34a4..3b5ccb9 100644
--- a/src/stm32.mk
+++ b/src/stm32.mk
@@ -62,5 +62,6 @@ STM_SRCS += lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal.c \
STM_SRCS += stm32/idle_task_static_memory.c \
stm32/main.c \
stm32/setup.c \
- ppu/stm.c
+ ppu/stm.c \
+ stm32/input.c
diff --git a/src/stm32/input.c b/src/stm32/input.c
new file mode 100644
index 0000000..e2d07cb
--- /dev/null
+++ b/src/stm32/input.c
@@ -0,0 +1,13 @@
+#include <stm32f0xx_hal_gpio.h>
+
+#include "input.h"
+
+hh_s_gamepad g_hh_controller_p1 = { 0 };
+hh_s_gamepad g_hh_controller_p2 = { 0 };
+
+void hh_input_read() {
+ g_hh_controller_p1.dpad_left = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4);
+ g_hh_controller_p1.dpad_right = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5);
+ g_hh_controller_p1.dpad_down = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6);
+ g_hh_controller_p1.dpad_up = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8);
+}