Skip to content

Commit

Permalink
Merge pull request #5 from chrismaltby/feature/gbdk-2020
Browse files Browse the repository at this point in the history
Feature/gbdk 2020
  • Loading branch information
chrismaltby committed Jul 9, 2020
2 parents b4c07fd + 3c5b77a commit 5bde52d
Show file tree
Hide file tree
Showing 1,863 changed files with 34,227 additions and 271,865 deletions.
2 changes: 1 addition & 1 deletion appData/src/gb/include/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct {
UBYTE frame_offset;
UBYTE rerender;
UBYTE moving;
BYTE move_speed;
UBYTE move_speed;
UBYTE anim_speed;
UBYTE pinned;
UBYTE collisionsEnabled;
Expand Down
4 changes: 1 addition & 3 deletions appData/src/gb/include/BankData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <gb/gb.h>
#include <gbdkjs.h>

#include "data_ptrs.h"

#ifdef __EMSCRIPTEN__
#define BankDataPtr(bank) ((UBYTE *)bank_data_ptrs[(bank)])
#else
Expand All @@ -25,6 +23,6 @@ UBYTE ReadBankedUBYTE(UBYTE bank, unsigned char *ptr);
void ReadBankedUBYTEArray(UBYTE bank, unsigned char *out, unsigned char *ptr, UBYTE size);
UWORD ReadBankedUWORD(UBYTE bank, unsigned char *ptr);
void StrCpyBanked(UBYTE bank, char *to, char *from);
void ReadBankedBankPtr(UBYTE bank, BANK_PTR *to, unsigned char *from);
void ReadBankedBankPtr(UBYTE bank, BankPtr *to, BankPtr *from);

#endif
2 changes: 1 addition & 1 deletion appData/src/gb/include/Projectiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef struct _PROJECTILE {
UBYTE frame;
UBYTE frames_len;
UBYTE animate;
BYTE move_speed;
UBYTE move_speed;
UBYTE sprite_index;
UBYTE time;
UBYTE life_time;
Expand Down
4 changes: 2 additions & 2 deletions appData/src/gb/include/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#define UI_BANK 3
#define MENU_OPEN_Y 112
#define WIN_LEFT_X 7
#define MENU_CLOSED_Y (MAXWNDPOSY + 1)
#define TEXT_BUFFER_START 0xCC
#define MENU_CLOSED_Y (MAXWNDPOSY + 1U)
#define TEXT_BUFFER_START 0xCCU
#define MENU_LAYOUT_INITIAL_X 88
#define MENU_CANCEL_ON_LAST_OPTION 0x01U
#define MENU_CANCEL_ON_B_PRESSED 0x02U
Expand Down
14 changes: 6 additions & 8 deletions appData/src/gb/src/core/Actor_b.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// clang-format off
#pragma bank=1
// clang-format on
#pragma bank 1

#include "Actor.h"
#include "Sprite.h"
Expand All @@ -21,7 +19,6 @@ UBYTE actors_active_delete[MAX_ACTIVE_ACTORS];
void MoveActors_b() {
UBYTE i, a;
UBYTE actor_time;

actor_time = game_time >> 2;

for (i = 0; i != actors_active_size; i++) {
Expand All @@ -31,12 +28,12 @@ void MoveActors_b() {
if (actors[a].move_speed == 0) {
// Half speed only move every other frame
if (IS_FRAME_2) {
actors[a].pos.x += actors[a].dir.x;
actors[a].pos.y += actors[a].dir.y;
actors[a].pos.x += (WORD)actors[a].dir.x;
actors[a].pos.y += (WORD)actors[a].dir.y;
}
} else {
actors[a].pos.x += actors[a].dir.x * actors[a].move_speed;
actors[a].pos.y += actors[a].dir.y * actors[a].move_speed;
actors[a].pos.x += (WORD)(actors[a].dir.x * actors[a].move_speed);
actors[a].pos.y += (WORD)(actors[a].dir.y * actors[a].move_speed);
}
}
}
Expand Down Expand Up @@ -383,6 +380,7 @@ UBYTE CheckCollisionInDirection_b(UBYTE start_x, UBYTE start_y, UBYTE end_tile,
}
return end_tile;
}
return end_tile;
}

UBYTE ActorAtTile_b(UBYTE tx, UBYTE ty, UBYTE inc_noclip) {
Expand Down
8 changes: 4 additions & 4 deletions appData/src/gb/src/core/BankData.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ UBYTE ReadBankedUBYTE(UBYTE bank, unsigned char* ptr) {
// strcpy(to, buffer);
// }

void ReadBankedBankPtr(UBYTE bank, BANK_PTR* to, unsigned char* from) {
BANK_PTR bank_ptr;
void ReadBankedBankPtr(UBYTE bank, BankPtr* to, BankPtr* from) {
BankPtr bank_ptr;
PUSH_BANK(bank);
memcpy(&bank_ptr, from, sizeof(BANK_PTR));
memcpy(&bank_ptr, from, sizeof(BankPtr));
POP_BANK;
memcpy(to, &bank_ptr, sizeof(BANK_PTR));
memcpy(to, &bank_ptr, sizeof(BankPtr));
}
2 changes: 1 addition & 1 deletion appData/src/gb/src/core/Camera_b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
#pragma bank=1
#pragma bank 1
// clang-format on

#include "Actor.h"
Expand Down
27 changes: 20 additions & 7 deletions appData/src/gb/src/core/Collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,59 @@
#define MAX_UINT16 0xFFFF

UBYTE TileAt(UINT16 tx, UINT16 ty) {
UWORD y_offset;
UBYTE tile;
// Check tile outside of bounds
if (tx == MAX_UINT16 || tx == image_tile_width || ty == image_tile_height || ty == MAX_UINT16) {
return OUT_OF_BOUNDS;
}

y_offset = ty * (UINT16)image_tile_width;

PUSH_BANK(collision_bank);
tile = (UBYTE) * (collision_ptr + (ty * image_tile_width) + tx);
tile = (UBYTE) * (collision_ptr + y_offset + tx);
POP_BANK;
return tile;
}

UBYTE TileAt2x1(UINT16 tx, UINT16 ty) {
UWORD y_offset;
UBYTE tile;
// Check tile outside of bounds
if (tx == MAX_UINT16 || tx == image_tile_width || ty == image_tile_height || ty == MAX_UINT16) {
return OUT_OF_BOUNDS;
}

y_offset = ty * (UINT16)image_tile_width;

PUSH_BANK(collision_bank);
tile = (UBYTE) * (collision_ptr + (ty * image_tile_width) + tx);
tile = (UBYTE) * (collision_ptr + y_offset + tx);
if (!tile) {
tile = (UBYTE) * (collision_ptr + (ty * image_tile_width) + (tx + 1));
tile = (UBYTE) * (collision_ptr + y_offset + (tx + 1U));
}
POP_BANK;
return tile;
}

UBYTE TileAt2x2(UINT16 tx, UINT16 ty) {
UWORD y_offset, y1_offset;
UBYTE tile;
// Check tile outside of bounds
if (tx == MAX_UINT16 || tx == image_tile_width || ty == image_tile_height || ty == MAX_UINT16) {
return OUT_OF_BOUNDS;
}

y_offset = ty * (UINT16)image_tile_width;
y1_offset = (ty + 1U) * (UINT16)image_tile_width;

PUSH_BANK(collision_bank);
tile = (UBYTE) * (collision_ptr + (ty * image_tile_width) + tx);
tile = (UBYTE) * (collision_ptr + y_offset + tx);
if (!tile) {
tile = (UBYTE) * (collision_ptr + (ty * image_tile_width) + (tx + 1));
tile = (UBYTE) * (collision_ptr + y_offset + (tx + 1U));
if (!tile) {
tile = (UBYTE) * (collision_ptr + ((ty + 1) * image_tile_width) + (tx));
tile = (UBYTE) * (collision_ptr + y1_offset + (tx));
if (!tile) {
tile = (UBYTE) * (collision_ptr + ((ty + 1) * image_tile_width) + (tx + 1));
tile = (UBYTE) * (collision_ptr + y1_offset + (tx + 1U));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions appData/src/gb/src/core/Core_Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Sprite.h"
#include "UI.h"
#include "gbt_player.h"
#include "data_ptrs.h"
#include "main.h"

#ifdef __EMSCRIPTEN__
Expand Down Expand Up @@ -115,7 +116,7 @@ int core_start() {

// Position Window Layer
WX_REG = 7;
WY_REG = MAXWNDPOSY + 1;
WY_REG = MAXWNDPOSY + 1U;

// Initialise Player
player.sprite = 0;
Expand Down Expand Up @@ -236,8 +237,8 @@ void game_loop() {
// Disable timer script
timer_script_duration = 0;

BGP_REG = PAL_DEF(0, 1, 2, 3);
OBP0_REG = OBP1_REG = PAL_DEF(0, 0, 1, 3);
BGP_REG = PAL_DEF(0U, 1U, 2U, 3U);
OBP0_REG = OBP1_REG = PAL_DEF(0U, 0U, 1U, 3U);

LoadScene(current_state);

Expand Down
2 changes: 1 addition & 1 deletion appData/src/gb/src/core/DataManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "Input.h"
#include "data_ptrs.h"

BANK_PTR bank_ptr;
BankPtr bank_ptr;
UBYTE image_bank;
UBYTE image_attr_bank;
UBYTE collision_bank;
Expand Down
4 changes: 2 additions & 2 deletions appData/src/gb/src/core/FadeManager_b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
#pragma bank=1
// clang-formatoff
#pragma bank 1
// clang-format on

#include "FadeManager.h"
Expand Down
12 changes: 6 additions & 6 deletions appData/src/gb/src/core/MusicManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void MusicPlay(UBYTE index, UBYTE loop, UBYTE return_bank) {
PUSH_BANK(return_bank);
#ifndef __EMSCRIPTEN__
PUSH_BANK(DATA_PTRS_BANK);
gbt_play(music_tracks[index], music_bank, 7);
gbt_play((void*)music_tracks[index], music_bank, 7);
gbt_loop(loop);
POP_BANK;
#endif
Expand Down Expand Up @@ -59,10 +59,10 @@ void SoundPlayTone(UWORD tone, UBYTE frames) {

// play tone on channel 1
NR10_REG = 0x00;
NR11_REG = (0x00 << 6) | 0x01;
NR12_REG = (0x0F << 4) | 0x00;
NR11_REG = (0x0U << 6U) | 0x01U;
NR12_REG = (0x0FU << 4U) | 0x00U;
NR13_REG = (tone & 0x00FF);
NR14_REG = 0x80 | ((tone & 0x0700) >> 8);
NR14_REG = 0x80 | ((tone & 0x0700) >> 8U);

// enable volume
NR50_REG = 0x77;
Expand All @@ -82,7 +82,7 @@ void SoundPlayBeep(UBYTE pitch) {

// play beep sound on channel 4
NR41_REG = 0x01;
NR42_REG = (0x0F << 4);
NR42_REG = (0x0FU << 4U);
NR43_REG = 0x20 | 0x08 | pitch;
NR44_REG = 0x80 | 0x40;

Expand All @@ -101,7 +101,7 @@ void SoundPlayCrash() {

// play crash sound on channel 4
NR41_REG = 0x01;
NR42_REG = (0x0F << 4) | 0x02;
NR42_REG = (0x0FU << 4U) | 0x02U;
NR43_REG = 0x13;
NR44_REG = 0x80;

Expand Down
2 changes: 1 addition & 1 deletion appData/src/gb/src/core/Projectiles_b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
#pragma bank=1
#pragma bank 1
// clang-format on

#include "Projectiles.h"
Expand Down
7 changes: 4 additions & 3 deletions appData/src/gb/src/core/ScriptRunner.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Input.h"
#include "Math.h"
#include "UI.h"
#include "data_ptrs.h"

DECLARE_STACK(script_ctx_pool, MAX_BG_SCRIPT_CONTEXTS);
// UINT8 script_ctx_active_pool[MAX_SCRIPT_CONTEXTS];
Expand All @@ -17,18 +18,18 @@ UBYTE script_await_next_frame;
UBYTE script_actor;
UBYTE script_main_ctx_actor;
UBYTE script_ptr_bank = 0;
UBYTE* script_ptr = 0;
UBYTE* script_ptr = {0};
UWORD script_ptr_x = 0;
UWORD script_ptr_y = 0;
UBYTE* script_start_ptr = 0;
UBYTE* script_start_ptr = {0};
UBYTE script_cmd_args[7] = {0};
UBYTE script_cmd_args_len;
UBYTE (*script_update_fn)();
UBYTE script_stack_ptr = 0;
UBYTE* script_stack[STACK_SIZE] = {0};
UBYTE script_bank_stack[STACK_SIZE] = {0};
UBYTE* script_start_stack[STACK_SIZE] = {0};
ScriptContext script_ctxs[MAX_SCRIPT_CONTEXTS] = {0};
ScriptContext script_ctxs[MAX_SCRIPT_CONTEXTS] = {{0}};
UBYTE current_script_ctx = 0;
// ScriptContext *main_script_ctx;
UBYTE timer_script_duration = 0;
Expand Down
13 changes: 6 additions & 7 deletions appData/src/gb/src/core/ScriptRunner_b.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// clang-format off
#pragma bank=4
// clang-format on
#pragma bank 4

#include "ScriptRunner.h"
#include "MusicManager.h"
Expand All @@ -18,6 +16,7 @@
#include "Sprite.h"
#include "Scroll.h"
#include "Camera.h"
#include "data_ptrs.h"
#include "Projectiles.h"
#include "states/Platform.h"
#include <rand.h>
Expand Down Expand Up @@ -1081,14 +1080,14 @@ void Script_ActorSetSprite_b() {
* Change sprite used by player
*/
void Script_PlayerSetSprite_b() {
BANK_PTR sprite_bank_ptr;
BankPtr sprite_bank_ptr;
UBYTE* sprite_ptr;
UWORD sprite_index;
UBYTE sprite_frames, sprite_len;

// Load Player Sprite
sprite_index = (script_cmd_args[0] * 256) + script_cmd_args[1];
ReadBankedBankPtr(DATA_PTRS_BANK, &sprite_bank_ptr, &sprite_bank_ptrs[sprite_index]);
ReadBankedBankPtr(DATA_PTRS_BANK, &sprite_bank_ptr, (BankPtr*)&sprite_bank_ptrs[sprite_index]);
sprite_ptr = (BankDataPtr(sprite_bank_ptr.bank)) + sprite_bank_ptr.offset;
sprite_frames = ReadBankedUBYTE(sprite_bank_ptr.bank, sprite_ptr);
sprite_len = MUL_4(sprite_frames);
Expand Down Expand Up @@ -1449,9 +1448,9 @@ void Script_ActorMoveRel_b() {
if (script_cmd_args[1] == 1) {
actor_move_dest_x = actor_move_dest_x - (script_cmd_args[0] * 8);
// If destination wrapped past left edge set to min X
if (actor_move_dest_x > actors[script_actor].pos.x) {
if (U_LESS_THAN(actors[script_actor].pos.x, actor_move_dest_x)) {
actor_move_dest_x = ACTOR_MIN_X;
} else if (actor_move_dest_x < ACTOR_MIN_X) {
} else if (U_LESS_THAN(actor_move_dest_x, ACTOR_MIN_X)) {
actor_move_dest_x = ACTOR_MIN_X;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion appData/src/gb/src/core/Scroll_b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
#pragma bank=1
#pragma bank 1
// clang-format on

#include "Scroll.h"
Expand Down
2 changes: 1 addition & 1 deletion appData/src/gb/src/core/Sprite_b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
#pragma bank=1
#pragma bank 1
// clang-format on

#include "Sprite.h"
Expand Down
2 changes: 1 addition & 1 deletion appData/src/gb/src/core/Trigger_b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
#pragma bank=1
#pragma bank 1
// clang-format on
#include "Trigger.h"

Expand Down
10 changes: 5 additions & 5 deletions appData/src/gb/src/core/UI.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void UIShowText(UBYTE bank, UWORD bank_offset) {
}

void UIShowAvatar(UBYTE avatar_index) {
BANK_PTR avatar_bank_ptr;
BankPtr avatar_bank_ptr;
UBYTE* avatar_ptr;
UBYTE avatar_len;
UBYTE tile1, tile2, tile3, tile4;
Expand All @@ -121,12 +121,12 @@ void UIShowAvatar(UBYTE avatar_index) {
PUSH_BANK(avatar_bank_ptr.bank);
memcpy(tmp_avatar_ptr, avatar_ptr + 1, avatar_len * 16);
POP_BANK
SetBankedBkgData(FONT_BANK, TEXT_BUFFER_START, avatar_len, tmp_avatar_ptr);
SetBankedBkgData(FONT_BANK, TEXT_BUFFER_START, avatar_len, (unsigned char *)tmp_avatar_ptr);

tile1 = TEXT_BUFFER_START;
tile2 = TEXT_BUFFER_START + 1;
tile3 = TEXT_BUFFER_START + 2;
tile4 = TEXT_BUFFER_START + 3;
tile2 = TEXT_BUFFER_START + 1U;
tile3 = TEXT_BUFFER_START + 2U;
tile4 = TEXT_BUFFER_START + 3U;

set_win_tiles(1, 1, 1, 1, &tile1);
set_win_tiles(2, 1, 1, 1, &tile2);
Expand Down
Loading

0 comments on commit 5bde52d

Please sign in to comment.