Skip to content

Commit

Permalink
Merge pull request #58 from AmigaPorts/dbl-bfr
Browse files Browse the repository at this point in the history
Dbl bfr
  • Loading branch information
tehKaiN authored May 7, 2019
2 parents 99a0ea0 + 5e20ad9 commit f50d520
Show file tree
Hide file tree
Showing 47 changed files with 1,538 additions and 742 deletions.
88 changes: 88 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8.5)
project(ACE)
set(ACE_DIR ${CMAKE_CURRENT_LIST_DIR} PARENT_SCOPE) # needed for helper fns

# Adhere to GNU filesystem layout conventions
include(GNUInstallDirs)
Expand Down Expand Up @@ -46,10 +47,97 @@ set(TARGET_NAME ${PROJECT_NAME_LOWER})
add_library(${TARGET_NAME} ${SOURCES} ${HEADERS})
target_link_libraries(${TARGET_NAME})

#----------------------------------------------------------------------- INSTALL

install(TARGETS ${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${HEADERS_ACE} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace)
install(FILES ${HEADERS_ACE_GENERIC} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/generic)
install(FILES ${HEADERS_ACE_UTILS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/utils)
install(FILES ${HEADERS_ACE_MANAGERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/managers)
install(FILES ${HEADERS_ACE_MANAGERS_VP} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/managers/viewport)
install(FILES ${HEADERS_FIXMATH} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fixmath)

#--------------------------------------------------------------------- FUNCTIONS

function(toAbsolute PATH_IN)
if(NOT IS_ABSOLUTE ${PATH_IN})
set(${PATH_IN} "${CMAKE_CURRENT_SOURCE_DIR}/${${PATH_IN}}" PARENT_SCOPE)
endif()
endfunction()

function(convertPalette TARGET PALETTE_IN PALETTE_OUT)
add_custom_command(
OUTPUT ${PALETTE_OUT}
COMMAND ${ACE_DIR}/tools/bin/palette_conv ${PALETTE_IN} ${PALETTE_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${PALETTE_IN}
)
target_sources(${TARGET} PUBLIC ${PALETTE_OUT})
endfunction()

function(convertBitmaps)
set(options INTERLEAVED)
set(oneValArgs TARGET PALETTE MASK_COLOR)
set(multiValArgs SOURCES DESTINATIONS MASKS)
cmake_parse_arguments(
convertBitmaps "${options}" "${oneValArgs}" "${multiValArgs}" ${ARGN}
)

if(${convertBitmaps_INTERLEAVED})
set(extraFlags -i)
endif()

list(LENGTH convertBitmaps_SOURCES srcCount)
list(LENGTH convertBitmaps_DESTINATIONS dstCount)
list(LENGTH convertBitmaps_MASKS maskCount)
if(NOT ${srcCount} EQUAL ${dstCount})
message(FATAL_ERROR "SOURCES count doesn't match DESTINATIONS count")
endif()
if(${maskCount} AND NOT ${maskCount} EQUAL ${srcCount})
message(FATAL_ERROR "MASKS count doesn't match SOURCES count")
endif()
if("${convertBitmaps_MASK_COLOR} " STREQUAL " ")
if(${maskCount} GREATER 0)
message(FATAL_ERROR "MASK_COLOR unspecified")
endif()
else()
string(REPLACE "#" "\\#" convertBitmaps_MASK_COLOR "${convertBitmaps_MASK_COLOR}")
endif()

MATH(EXPR srcCount "${srcCount}-1")
foreach(bitmap_idx RANGE ${srcCount}) # /path/file.png
list(GET convertBitmaps_SOURCES ${bitmap_idx} bitmapPath)
toAbsolute(bitmapPath)
list(GET convertBitmaps_DESTINATIONS ${bitmap_idx} outPath)
toAbsolute(outPath)
if(${maskCount} GREATER 0)
list(GET convertBitmaps_MASKS ${bitmap_idx} maskPath)
toAbsolute(maskPath)
endif()

if(NOT "${convertBitmaps_MASK_COLOR} " STREQUAL " ")
set(extraFlags ${extraFlags} -mc ${convertBitmaps_MASK_COLOR} -mo ${maskPath})
endif()
add_custom_command(
OUTPUT ${outPath} ${maskPath}
COMMAND ${ACE_DIR}/tools/bitmap_conv/bitmap_conv ${convertBitmaps_PALETTE} ${bitmapPath} -o ${outPath} ${extraFlags}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${convertBitmaps_PALETTE} ${bitmapPath}
)
target_sources(${convertBitmaps_TARGET} PUBLIC ${outPath} ${maskPath})
endforeach()
endfunction()

function(convertFont TARGET FONT_IN FONT_OUT)
toAbsolute(FONT_IN)
toAbsolute(FONT_OUT)
get_filename_component(ext ${FONT_OUT} EXT)
string(SUBSTRING ${ext} 1 -1 ext)
add_custom_command(
OUTPUT ${FONT_OUT}
COMMAND ${ACE_DIR}/tools/bin/font_conv ${FONT_IN} ${ext} -out ${FONT_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${FONT_IN}
)
target_sources(${TARGET} PUBLIC ${FONT_OUT})
endfunction()
18 changes: 18 additions & 0 deletions include/ace/generic/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ void genericCreate(void);
void genericProcess(void);
void genericDestroy(void);

#if defined(__GNUC__)
#include <stdint.h>

#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xe2dee396
#else
#define STACK_CHK_GUARD 0x595e9fbd94fda766
#endif

uintptr_t __stack_chk_guard = STACK_CHK_GUARD;

__attribute__((noreturn))
void __stack_chk_fail(void) {
logWrite("ERR: STACK SMASHED\n");
while(1) {}
}
#endif

int main(void) {
systemCreate();
memCreate();
Expand Down
4 changes: 2 additions & 2 deletions include/ace/managers/joy.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ typedef struct {
extern tJoyManager g_sJoyManager;

/* Functions */
void joyOpen(void);
void joyOpen(UBYTE is4joy);

void joySetState(UBYTE ubJoyCode, UBYTE ubJoyState);

UBYTE joyPeek(UBYTE ubJoyCode);
UBYTE joyCheck(UBYTE ubJoyCode);

UBYTE joyUse(UBYTE ubJoyCode);

Expand Down
13 changes: 8 additions & 5 deletions include/ace/managers/viewport/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@

typedef struct {
tVpManager sCommon;
tUwCoordYX uPos; /// Current camera pos
tUwCoordYX uLastPos; /// Previous camera pos
tUwCoordYX uMaxPos; /// Max camera pos: world W&H - camera W&H
tUwCoordYX uPos; ///< Current camera pos
tUwCoordYX uLastPos[2]; ///< Previous camera pos
tUwCoordYX uMaxPos; ///< Max camera pos: world W&H - camera W&H
UBYTE ubBfr;
UBYTE isDblBfr;
} tCameraManager;

tCameraManager *cameraCreate(
tVPort *pVPort, UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY
tVPort *pVPort, UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY,
UBYTE isDblBfr
);

void cameraDestroy(tCameraManager *pManager);
void cameraProcess(tCameraManager *pManager);

void cameraReset(
tCameraManager *pManager,
UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY
UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY, UBYTE isDblBfr
);

void cameraSetCoord(tCameraManager *pManager, UWORD uwX, UWORD uwY);
Expand Down
54 changes: 38 additions & 16 deletions include/ace/managers/viewport/scrollbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Scrollable buffer manager
* Uses scrolling-trick from aminet to achieve memory-efficient scroll
* Must be processed as last, because it calls WaitTOF
* Author: KaiN
* Requires viewport managers:
* - camera
* TODO: make it work without tileBuffer manager
Expand All @@ -28,40 +27,63 @@
#include <ace/managers/copper.h>
#include <ace/managers/viewport/camera.h>

// vPort ptr
#define TAG_SCROLLBUFFER_VPORT (TAG_USER|1)
// Scrollable area bounds, in pixels
#define TAG_SCROLLBUFFER_BOUND_WIDTH (TAG_USER|2)
#define TAG_SCROLLBUFFER_BOUND_HEIGHT (TAG_USER|3)
// Buffer bitmap creation flags
#define TAG_SCROLLBUFFER_BITMAP_FLAGS (TAG_USER|4)
#define TAG_SCROLLBUFFER_IS_DBLBUF (TAG_USER|5)
// If in raw mode, offset on copperlist for placing required copper
// instructions, specified in copper instruction count since beginning.
#define TAG_SCROLLBUFFER_COPLIST_OFFSET_START (TAG_USER|6)
#define TAG_SCROLLBUFFER_COPLIST_OFFSET_BREAK (TAG_USER|7)
#define TAG_SCROLLBUFFER_MARGIN_WIDTH (TAG_USER|8)

#define SCROLLBUFFER_FLAG_COPLIST_RAW 1

/* Types */

typedef struct {
tVpManager sCommon;
tCameraManager *pCameraManager; /// Quick ref to camera

tBitMap *pBuffer; /// Ptr to buffer bitmap
tCopBlock *pStartBlock; /// Initial data fetch
tCopBlock *pBreakBlock; /// Bitplane ptr reset
tUwCoordYX uBfrBounds; /// Real bounds of buffer (includes height reserved for x-scroll)
UWORD uwBmAvailHeight; /// Avail height of buffer to blit (excludes height reserved for x-scroll)
UWORD uwVpHeightPrev; /// Prev height of related VPort, used to force refresh on change
UWORD uwModulo; /// Bitplane modulo
tAvg *pAvg;
tCameraManager *pCamera; ///< Quick ref to camera

tBitMap *pFront; ///< Front buffer in double buffering
tBitMap *pBack; ///< Back buffer in double buffering
tCopBlock *pStartBlock; ///< Initial data fetch
tCopBlock *pBreakBlock; ///< Bitplane ptr reset
tUwCoordYX uBfrBounds; ///< Real bounds of buffer (includes height reserved for x-scroll)
UWORD uwBmAvailHeight; ///< Avail height of buffer to blit (excludes height reserved for x-scroll)
UWORD uwVpHeightPrev; ///< Prev height of related VPort, used to force refresh on change
UWORD uwModulo; ///< Bitplane modulo
UBYTE ubFlags;
} tScrollBufferManager;

/* Globals */

/* Functions */

tScrollBufferManager *scrollBufferCreate(
tVPort *pVPort, UBYTE ubMarginWidth,
UWORD uwBoundWidth, UWORD uwBoundHeight
);
/**
* Creates scroll manager
*/
tScrollBufferManager *scrollBufferCreate(void *pTags, ...);

void scrollBufferDestroy(tScrollBufferManager *pManager);

/**
* Scroll buffer process function
*/
void scrollBufferProcess(tScrollBufferManager *pManager);

void scrollBufferReset(
tScrollBufferManager *pManager, UBYTE ubMarginWidth,
UWORD uwBoundWidth, UWORD uwBoundHeight
UWORD uwBoundWidth, UWORD uwBoundHeight, UBYTE ubBitmapFlags, UBYTE isDblBfr
);

/**
* Uses unsafe blit copy for using out-of-bound X ccord
*/
void scrollBufferBlitMask(
tBitMap *pSrc, WORD wSrcX, WORD wSrcY,
tScrollBufferManager *pDstManager,
Expand Down
14 changes: 5 additions & 9 deletions include/ace/managers/viewport/simplebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
*/

#include <ace/types.h>
#include <ace/macros.h>
#include <ace/utils/bitmap.h>
#include <ace/utils/extview.h>
#include <ace/managers/viewport/camera.h>
#include <ace/utils/bitmap.h>
#include <ace/utils/tag.h>

// vPort ptr
Expand All @@ -26,19 +24,17 @@
#define TAG_SIMPLEBUFFER_BOUND_HEIGHT (TAG_USER|3)
// Buffer bitmap creation flags
#define TAG_SIMPLEBUFFER_BITMAP_FLAGS (TAG_USER|4)
#define TAG_SIMPLEBUFFER_IS_DBLBUF (TAG_USER|5)
// If in raw mode, offset on copperlist for placing required copper
// instructions, specified in copper instruction count since beginning.
#define TAG_SIMPLEBUFFER_COPLIST_OFFSET (TAG_USER|6)

// Flags for internal usage.
#define SIMPLEBUFFER_FLAG_X_SCROLLABLE 1
#define SIMPLEBUFFER_FLAG_COPLIST_RAW 2

typedef struct {
tVpManager sCommon;
tCameraManager *pCameraManager;
tCameraManager *pCamera;
// scroll-specific fields
tBitMap *pBuffer; ///< Bitmap buffer
tBitMap *pFront; ///< Currently displayed buffer.
tBitMap *pBack; ///< Buffer for drawing.
tCopBlock *pCopBlock; ///< CopBlock containing modulo/shift/bitplane cmds
tUwCoordYX uBfrBounds; ///< Buffer bounds in pixels
UBYTE ubFlags; ///< Read only. See SIMPLEBUFFER_FLAG_*.
Expand Down
Loading

0 comments on commit f50d520

Please sign in to comment.