From 65f9982ba6992e62960d20bb690cf29ef60e835c Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Wed, 8 Mar 2023 15:37:25 +0100 Subject: spelling correction --- src/stm32/TODO/hh_entity.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/stm32/TODO/hh_entity.h b/src/stm32/TODO/hh_entity.h index 82d75c5..768b2e6 100644 --- a/src/stm32/TODO/hh_entity.h +++ b/src/stm32/TODO/hh_entity.h @@ -7,10 +7,10 @@ typedef struct hh_entity //armor/block? }; -/// @brief detect for collision enity and eviroment +/// @brief detect for collision entity and environment /// @param environment position of tile to be checked /// @param entity position entity -/// @return true if collision between enity and environment +/// @return true if collision between entity and environment bool hh_collision(const vec2& environment, const vec2& entity); /// @brief solve collisions -- cgit v1.2.3 From 0ce1adac6d80bf69e3a03891879d9445698300bc Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Fri, 10 Mar 2023 11:55:46 +0100 Subject: nope --- src/stm32/TODO/hh_entity.c | 6 ++++++ src/stm32/TODO/maths.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/stm32/TODO/hh_entity.c create mode 100644 src/stm32/TODO/maths.c (limited to 'src') diff --git a/src/stm32/TODO/hh_entity.c b/src/stm32/TODO/hh_entity.c new file mode 100644 index 0000000..492ca67 --- /dev/null +++ b/src/stm32/TODO/hh_entity.c @@ -0,0 +1,6 @@ +#include "maths.h" +#include "hh_entity.h" + +bool hh_collision(const vec2& environment, const vec2& entity){ + +} \ No newline at end of file diff --git a/src/stm32/TODO/maths.c b/src/stm32/TODO/maths.c new file mode 100644 index 0000000..ef3698b --- /dev/null +++ b/src/stm32/TODO/maths.c @@ -0,0 +1,12 @@ +#include "maths.h" + +#include + +float clamp( float x, float min, float max ){ + if (x > max) + return max; + else if (x < min) + return min; + else + return x; +} -- cgit v1.2.3 From e3e0feb56340a72545b6fd38f22e134cf2e3509a Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Fri, 10 Mar 2023 14:23:05 +0100 Subject: fixed code styles --- .editorconfig | 4 ++-- src/engine/TODO/combat.h | 9 +++++++++ src/engine/TODO/draw_screen.h | 1 + src/engine/TODO/entity.c | 41 ++++++++++++++++++++++++++++++++++++++++ src/engine/TODO/entity.h | 24 +++++++++++++++++++++++ src/engine/TODO/hh_combat.h | 9 --------- src/engine/TODO/hh_draw_screen.h | 1 - src/engine/TODO/hh_entity.c | 41 ---------------------------------------- src/engine/TODO/hh_entity.h | 24 ----------------------- src/engine/TODO/hh_level.h | 1 - src/engine/TODO/hh_rand.h | 1 - src/engine/TODO/level.h | 4 ++++ src/engine/TODO/maths.c | 1 - src/engine/TODO/maths.h | 3 ++- src/entity.h | 1 - src/input.h | 1 - src/ppu/ppu.h | 3 --- src/ppusim/sim.c | 5 +++++ src/ppusim/sim.h | 3 +++ src/stm32/main.c | 3 +++ 20 files changed, 94 insertions(+), 86 deletions(-) create mode 100644 src/engine/TODO/combat.h create mode 100644 src/engine/TODO/draw_screen.h create mode 100644 src/engine/TODO/entity.c create mode 100644 src/engine/TODO/entity.h delete mode 100644 src/engine/TODO/hh_combat.h delete mode 100644 src/engine/TODO/hh_draw_screen.h delete mode 100644 src/engine/TODO/hh_entity.c delete mode 100644 src/engine/TODO/hh_entity.h delete mode 100644 src/engine/TODO/hh_level.h delete mode 100644 src/engine/TODO/hh_rand.h create mode 100644 src/engine/TODO/level.h delete mode 100644 src/engine/TODO/maths.c (limited to 'src') diff --git a/.editorconfig b/.editorconfig index fece754..1f4a360 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,10 +2,10 @@ root = true [*] indent_style = tab -indent_size = 2 +indent_size = 3 end_of_line = lf insert_final_newline = true [*.md] indent_style = space -indent_size = 2 +indent_size = 3 diff --git a/src/engine/TODO/combat.h b/src/engine/TODO/combat.h new file mode 100644 index 0000000..16c41f5 --- /dev/null +++ b/src/engine/TODO/combat.h @@ -0,0 +1,9 @@ +#include "hh_entity.h" + + +// attacktypes: + +/// @brief basic attack +/// @param dmg damage number +/// @param target entity under attack (damage changes this hp value) +void hh_attack_basic( int8_t dmg, hh_entity* target ); diff --git a/src/engine/TODO/draw_screen.h b/src/engine/TODO/draw_screen.h new file mode 100644 index 0000000..f5d7507 --- /dev/null +++ b/src/engine/TODO/draw_screen.h @@ -0,0 +1 @@ +// every function call for drawing the screen goes here. diff --git a/src/engine/TODO/entity.c b/src/engine/TODO/entity.c new file mode 100644 index 0000000..fa550d5 --- /dev/null +++ b/src/engine/TODO/entity.c @@ -0,0 +1,41 @@ +#include + +#include "hh_entity.h" +#include "maths.h" + +/* + PLAYER: (pos on X) + ,___, + | | + | X | + |___| + +*/ + +bool hh_collision(vec2* pos1, vec2* pos2){ + if (pos2->x == CLAMP(pos2->x,pos1->x,pos1->x+1.0f)){// hit x + return true; + } + + if (pos2->y == CLAMP(pos2->y,pos1->y,pos1->y+0.99f)){// hit y + return true; + } + return false; +} + +void hh_solve_collision(vec2* pos_environment, hh_entity* entity){ + if (entity->vec.x > 0.0f){ + entity->pos.x = MIN(entity->pos.x,pos_environment->x-1.0f); + entity->vec.x = 0.0f; + } else if (entity->vec.x < 0.0f){ + entity->pos.x = MAX(entity->pos.x,pos_environment->x+1.0f); + entity->vec.x = 0.0f; + } else if (entity->vec.y > 0.0f){ + entity->pos.x = MIN(entity->pos.x,pos_environment->x-1.0f); + entity->vec.x = 0.0f; + } else if (entity->vec.y < 0.0f){ + entity->pos.x = MAX(entity->pos.x,pos_environment->x+1.0f); + entity->vec.x = 0.0f; + } +} + diff --git a/src/engine/TODO/entity.h b/src/engine/TODO/entity.h new file mode 100644 index 0000000..fdbeb8a --- /dev/null +++ b/src/engine/TODO/entity.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "maths.h" + +typedef struct { + vec2 pos, vec; + bool is_grounded; + int8_t hp; + //armor/block? +}hh_entity; + +/// @brief detect for collision enity and eviroment +/// @param pos1 position of environment tile to be checked +/// @param pos2 position entity +/// @return true if collision between enity and environment +bool hh_collision(vec2* pos1, vec2* pos2); + +/// @brief solve collisions +/// @param environment position +/// @param entity position +/// @return solved new entity position +void hh_solve_collision(vec2* pos_environment, hh_entity* entity); diff --git a/src/engine/TODO/hh_combat.h b/src/engine/TODO/hh_combat.h deleted file mode 100644 index 16c41f5..0000000 --- a/src/engine/TODO/hh_combat.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "hh_entity.h" - - -// attacktypes: - -/// @brief basic attack -/// @param dmg damage number -/// @param target entity under attack (damage changes this hp value) -void hh_attack_basic( int8_t dmg, hh_entity* target ); diff --git a/src/engine/TODO/hh_draw_screen.h b/src/engine/TODO/hh_draw_screen.h deleted file mode 100644 index f5d7507..0000000 --- a/src/engine/TODO/hh_draw_screen.h +++ /dev/null @@ -1 +0,0 @@ -// every function call for drawing the screen goes here. diff --git a/src/engine/TODO/hh_entity.c b/src/engine/TODO/hh_entity.c deleted file mode 100644 index fa550d5..0000000 --- a/src/engine/TODO/hh_entity.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#include "hh_entity.h" -#include "maths.h" - -/* - PLAYER: (pos on X) - ,___, - | | - | X | - |___| - -*/ - -bool hh_collision(vec2* pos1, vec2* pos2){ - if (pos2->x == CLAMP(pos2->x,pos1->x,pos1->x+1.0f)){// hit x - return true; - } - - if (pos2->y == CLAMP(pos2->y,pos1->y,pos1->y+0.99f)){// hit y - return true; - } - return false; -} - -void hh_solve_collision(vec2* pos_environment, hh_entity* entity){ - if (entity->vec.x > 0.0f){ - entity->pos.x = MIN(entity->pos.x,pos_environment->x-1.0f); - entity->vec.x = 0.0f; - } else if (entity->vec.x < 0.0f){ - entity->pos.x = MAX(entity->pos.x,pos_environment->x+1.0f); - entity->vec.x = 0.0f; - } else if (entity->vec.y > 0.0f){ - entity->pos.x = MIN(entity->pos.x,pos_environment->x-1.0f); - entity->vec.x = 0.0f; - } else if (entity->vec.y < 0.0f){ - entity->pos.x = MAX(entity->pos.x,pos_environment->x+1.0f); - entity->vec.x = 0.0f; - } -} - diff --git a/src/engine/TODO/hh_entity.h b/src/engine/TODO/hh_entity.h deleted file mode 100644 index fdbeb8a..0000000 --- a/src/engine/TODO/hh_entity.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#include "maths.h" - -typedef struct { - vec2 pos, vec; - bool is_grounded; - int8_t hp; - //armor/block? -}hh_entity; - -/// @brief detect for collision enity and eviroment -/// @param pos1 position of environment tile to be checked -/// @param pos2 position entity -/// @return true if collision between enity and environment -bool hh_collision(vec2* pos1, vec2* pos2); - -/// @brief solve collisions -/// @param environment position -/// @param entity position -/// @return solved new entity position -void hh_solve_collision(vec2* pos_environment, hh_entity* entity); diff --git a/src/engine/TODO/hh_level.h b/src/engine/TODO/hh_level.h deleted file mode 100644 index 43b19a3..0000000 --- a/src/engine/TODO/hh_level.h +++ /dev/null @@ -1 +0,0 @@ -//deal with loading/saving the correct level diff --git a/src/engine/TODO/hh_rand.h b/src/engine/TODO/hh_rand.h deleted file mode 100644 index ea7c1d4..0000000 --- a/src/engine/TODO/hh_rand.h +++ /dev/null @@ -1 +0,0 @@ -// deal with Pseudo random number generation here. diff --git a/src/engine/TODO/level.h b/src/engine/TODO/level.h new file mode 100644 index 0000000..09f77e7 --- /dev/null +++ b/src/engine/TODO/level.h @@ -0,0 +1,4 @@ +//deal with loading/saving the correct level + +/** @brief */ +void hh_map_load(); diff --git a/src/engine/TODO/maths.c b/src/engine/TODO/maths.c deleted file mode 100644 index d1bb089..0000000 --- a/src/engine/TODO/maths.c +++ /dev/null @@ -1 +0,0 @@ -#include "maths.h" diff --git a/src/engine/TODO/maths.h b/src/engine/TODO/maths.h index 032e56d..c7f1b44 100644 --- a/src/engine/TODO/maths.h +++ b/src/engine/TODO/maths.h @@ -9,7 +9,8 @@ typedef struct { typedef vec2 vec_cen;//centered typedef vec2 vec_cor;//left upper corner -#define HH_MATH_FIXED_POINT 7 //fixed point at decimal 7lsb (world positions in pixels (with fixed decimal point)) +//fixed point at decimal 7lsb (world positions in pixels (with fixed decimal point)) +#define HH_MATH_FIXED_POINT 7 #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) diff --git a/src/entity.h b/src/entity.h index 20cbf42..181182b 100644 --- a/src/entity.h +++ b/src/entity.h @@ -12,4 +12,3 @@ typedef struct { 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 index adacba2..90f0c61 100644 --- a/src/input.h +++ b/src/input.h @@ -19,4 +19,3 @@ 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/ppu/ppu.h b/src/ppu/ppu.h index 18b58a2..75d97c1 100644 --- a/src/ppu/ppu.h +++ b/src/ppu/ppu.h @@ -9,9 +9,6 @@ void hh_ppu_init(); /** @brief deinitialize ppu interface */ void hh_ppu_deinit(); -/** @brief */ -void hh_ppu_load_tilemap(); - /** @brief update single foreground sprite */ void hh_ppu_update_foreground(unsigned index, hh_s_ppu_loc_fam_entry e); /** @brief update single background sprite */ diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 449b78d..7d56d2d 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -22,6 +22,11 @@ void hh_ppu_init() { g_hh_ppusim_vram = malloc(sizeof(hh_ppu_data_t) * 0xffff); memset(g_hh_ppusim_vram, 0x0000, 0xffff); + hh_ppu_load_tilemap(); +} + +void hh_ppu_load_tilemap() { + } void hh_ppu_deinit() { diff --git a/src/ppusim/sim.h b/src/ppusim/sim.h index 73f4b23..4d1d718 100644 --- a/src/ppusim/sim.h +++ b/src/ppusim/sim.h @@ -4,3 +4,6 @@ #define HH_PPUSIM_UPSCALE_FACTOR 3 /** @brief max framerate for PPUSIM */ #define HH_PPUSIM_FRAMERATE 60 + +/** @brief pump tilemap from rom to ppu ram */ +void hh_ppu_load_tilemap(); //ppu sim? diff --git a/src/stm32/main.c b/src/stm32/main.c index 735b378..d381d35 100644 --- a/src/stm32/main.c +++ b/src/stm32/main.c @@ -1,4 +1,7 @@ #include "main.h" +#include "ppu/ppu.h" + +void hh_ppu_load_tilemap() {} void hh_loop() { while(g_hh_run); -- cgit v1.2.3 From 8670e4bb2bdaf46399830d9c4d413705ae01dc40 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Fri, 10 Mar 2023 16:32:50 +0100 Subject: ppusim read sprites from file and put into vram --- src/ppusim/sim.c | 25 +++++++++++++++++++++++- test/bin/test_file_read.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test/bin/test_file_read.c (limited to 'src') diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 7d56d2d..1fceb82 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -1,9 +1,12 @@ #include #include #include +#include #include "main.h" #include "ppu/ppu.h" +#include "ppu/consts.h" +#include "ppu/internals.h" #include "ppusim/mem.h" #include "ppusim/sim.h" #include "ppusim/work.h" @@ -26,7 +29,27 @@ void hh_ppu_init() { } void hh_ppu_load_tilemap() { - + char* filename = "tiles.bin"; + FILE* fp = fopen(filename,"rb"); + if (!fp){ + return;//error + } + + fseek(fp, 0, SEEK_END);//goto EOF + int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; + fseek(fp, 0, 0);//goto start of file + + for (int i = 0; i < _size; i++) { + uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; + + fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + + hh_s_ppu_vram_data sprite = hh_ppu_2nat_sprite(data); + sprite.offset = i*HH_PPU_VRAM_TMM_SPRITE_SIZE; + hh_ppu_vram_write(sprite); + free(sprite.data); + } + fclose(fp); } void hh_ppu_deinit() { diff --git a/test/bin/test_file_read.c b/test/bin/test_file_read.c new file mode 100644 index 0000000..6357feb --- /dev/null +++ b/test/bin/test_file_read.c @@ -0,0 +1,48 @@ + +#include +#include +#include + + +#define HH_PPU_VRAM_TMM_SPRITE_SIZE 52 + + +void printData(uint8_t* in) { + for (int i = 0; i < HH_PPU_VRAM_TMM_SPRITE_SIZE; i++) + { + printf("%02x ",in[i]); + } + printf("\n"); +} + +void hh_ppu_load_tilemap() { + + //TODO: lees bestand in mem + char* filename = "tiles.bin"; + FILE* fp = fopen(filename,"rb"); + if (!fp){ + return;//error + } + + fseek(fp, 0, SEEK_END); + int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; + fseek(fp, 0, 0); + // printf("%i",_size); + for (int i = 0; i < _size; i++) { + uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; + // for (int i = 0; i < 255; i++) { + // buffer[i] = 0; //TODO: vullen + fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + // } + + printData(data); + } + fclose(fp); + +} + + +int main(){ +hh_ppu_load_tilemap(); + return 0; +} -- cgit v1.2.3 From 148db0e330e158381bf2b5b39e139d75c55088b2 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:36:21 +0100 Subject: Delete c_cpp_properties.json --- src/.vscode/c_cpp_properties.json | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/.vscode/c_cpp_properties.json (limited to 'src') diff --git a/src/.vscode/c_cpp_properties.json b/src/.vscode/c_cpp_properties.json deleted file mode 100644 index 359928d..0000000 --- a/src/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "c17", - "cppStandard": "c++14", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 -} \ No newline at end of file -- cgit v1.2.3 From 233b2e7a0743935db145f921dd49756248aaee58 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:36:38 +0100 Subject: Delete settings.json --- src/.vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/.vscode/settings.json (limited to 'src') diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json deleted file mode 100644 index d485e2c..0000000 --- a/src/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "hh_entity.h": "c", - "maths.h": "c" - } -} \ No newline at end of file -- cgit v1.2.3