Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make interrupts work when OS is on #209

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
243fbb2
fix showcase asset copy
tehKaiN Jul 19, 2023
a62f4b4
add input handler for reading keyboard state when os is alive
tehKaiN Jul 19, 2023
a6c3da4
removed keyboard hack :tada:
tehKaiN Jul 19, 2023
efcdce3
simplify handler code
tehKaiN Jul 19, 2023
352d78b
remove vbcc defines because it's unsupported anyway
tehKaiN Jul 19, 2023
c41ba12
added os-friendly CIA handling
tehKaiN Jul 19, 2023
67daa09
add os-friendly audio interrupt handling
tehKaiN Jul 28, 2023
e21a7b2
tools: rename trimExt() to removeExt()
tehKaiN Jul 28, 2023
f0b30ed
audio_conv: add -fpt, -fpad and -sa options
tehKaiN Jul 28, 2023
90b5f23
add bobSetCurrentBuffer()
tehKaiN Aug 20, 2023
c2ad369
Merge branch 'master' into os-cia
tehKaiN Sep 23, 2023
eb67b42
add os-friendly vblank handling
tehKaiN Sep 24, 2023
de6a3c8
make file functions work without blitter, if possible
tehKaiN Sep 24, 2023
43d3cc6
tilebuffer: add missing cbTileDraw call in tileBufferRedrawAll()
tehKaiN Sep 26, 2023
ee3316f
optimize blitter waiting a bit
tehKaiN Sep 28, 2023
2e143b0
fix DMAF_BLTDONE check polarity
tehKaiN Sep 28, 2023
2ca091c
add null check in bitmapLoadFromFile()
tehKaiN Oct 1, 2023
11d864f
add checks for tile redraw queue overflow
tehKaiN Oct 9, 2023
c0b79fc
add ptplayerSetE8Callback()
tehKaiN Oct 14, 2023
2599005
Merge remote-tracking branch 'origin/master' into os-cia
tehKaiN Dec 7, 2023
6209f4a
add paletteColorMix()
tehKaiN Jan 16, 2024
c14598b
optimize bitmapLoadFromFile offset calcs
tehKaiN Feb 4, 2024
1448fe0
optimize bitmapLoadFromFile() for full width interleaved reads
tehKaiN Feb 4, 2024
9b0d7c4
tools: use std namespace for cstdint types
tehKaiN Feb 10, 2024
3f07d75
ptplayer: fix duplicate pointer for current mod, cleanups
tehKaiN Feb 11, 2024
7b7d47f
simplebuffer: calc bpl offs/shift only when they're actually used
tehKaiN Apr 16, 2024
f30b8fe
add paletteSave()
tehKaiN Apr 16, 2024
f60f6f8
bitmap_transform: specify rotation center point
tehKaiN Apr 21, 2024
c72dcd1
Merge remote-tracking branch 'origin/master' into os-cia
MarcinNowosad-RG Aug 22, 2024
5dae631
Merge branch 'master' into os-cia
tehKaiN Aug 27, 2024
9080ed1
remove debug print
tehKaiN Jan 14, 2025
1198cbb
add debug print for bobCalcFrameAddress() going out of bounds
tehKaiN Jan 18, 2025
6e89411
Merge branch 'main' into os-cia
tehKaiN Jan 19, 2025
cfb5c8f
add logs for bobInit() to make catching non-intentional bob inits aft…
tehKaiN Jan 19, 2025
82fcd27
make diskFileExists() not print the error if file doesn't exist
tehKaiN Jan 19, 2025
51a1ecb
change order of DisownBlitter() in systemReleaseBlitterToOs() to some…
tehKaiN Jan 20, 2025
736ca93
fix systemGetBlitterFromOs() updating s_wSystemBlitterUses too early
tehKaiN Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/ace/managers/blit.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void blitManagerDestroy(void);
/**
* @brief Checks if blitter is idle.
*
* Polls 2 times, taing A1000 Agnus bug workaround into account.
* Polls 2 times, taking A1000 Agnus bug workaround into account.
*
* @return 1 if blitter is idle, otherwise 0.
*
Expand All @@ -84,6 +84,8 @@ UBYTE blitIsIdle(void);
/**
* @brief Waits until blitter finishes its work.
*
* Polls at least 2 times, taking A1000 Agnus bug workaround into account.
*
* @todo Investigate if autosetting BLITHOG inside it is beneficial.
*
* @see blitIsIdle()
Expand Down
9 changes: 9 additions & 0 deletions include/ace/managers/bob.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ void bobEnd(void);

void bobDiscardUndraw(void);

/**
* @brief Sets the current buffer to given bitmap in case it loses sync.
* Usually used in tandem with bobDiscardUndraw() when bob system was disabled
* for some time.
*
* @param pCurrent Current buffer to use. Must be same as one of passed
* in bobManagerCreate().
*/
void bobSetCurrentBuffer(tBitMap *pCurrent);

#ifdef __cplusplus
}
Expand Down
9 changes: 9 additions & 0 deletions include/ace/managers/ptplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef struct tPtplayerSamplePack {
} tPtplayerSamplePack;

typedef void (*tPtplayerCbSongEnd)(void);
typedef void (*tPtplayerCbE8)(UBYTE ubE8);

/**
* @brief Install a CIA-B interrupt for calling _mt_music or mt_sfxonly.
Expand Down Expand Up @@ -346,6 +347,14 @@ tPtplayerSamplePack *ptplayerSampleDataCreateFromFd(tFile *pFileSamples);
*/
void ptplayerSamplePackDestroy(tPtplayerSamplePack *pSamplePack);

/**
* @brief Sets the function to call on parsing the E8 command.
*
* @param cbOnE8 Function to be called. E8 argument nibble is passed
* as argument. Set to zero if not needed.
*/
void ptplayerSetE8Callback(tPtplayerCbE8 cbOnE8);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 5 additions & 1 deletion include/ace/managers/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef void (*tAceIntHandler)(
REGARG(volatile tCustom *pCustom, "a0"), REGARG(volatile void *pData, "a1")
);

typedef void (*tKeyInputHandler)(UBYTE ubRawKeyCode);

//-------------------------------------------------------------------- FUNCTIONS

/**
Expand Down Expand Up @@ -54,10 +56,12 @@ UBYTE systemBlitterIsUsed(void);

void systemDump(void);

void systemSetKeyInputHandler(tKeyInputHandler cbKeyInputHandler);

void systemSetInt(UBYTE ubIntNumber, tAceIntHandler pHandler, void *pIntData);

void systemSetCiaInt(
UBYTE ubCia, UBYTE ubIntBit, tAceIntHandler pHandler, void *pIntData
UBYTE ubCia, UBYTE ubIntBit, tAceIntHandler cbHandler, void *pIntData
);

void systemSetCiaCr(UBYTE ubCia, UBYTE isCrB, UBYTE ubCrValue);
Expand Down
18 changes: 0 additions & 18 deletions include/ace/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ typedef int32_t LONG;
#define FN_HOTSPOT
#define FN_COLDSPOT
#define BITFIELD_STRUCT struct __attribute__((packed))
#elif defined(__VBCC__)
#if defined(CONFIG_SYSTEM_OS_FRIENDLY)
#define INTERRUPT __amigainterrupt __saveds
#define INTERRUPT_END do {} while(0)
#elif defined(CONFIG_SYSTEM_OS_TAKEOVER)
#define INTERRUPT
#define INTERRUPT_END do {} while(0)
#endif

#define HWINTERRUPT __interrupt __saveds
#define UNUSED_ARG
#define REGARG(arg, reg) __reg(reg) arg
#define CHIP __chip
#define FAR
#define INTERRUPT_END do {} while(0)
#define FN_HOTSPOT
#define FN_COLDSPOT
#define BITFIELD_STRUCT struct
#elif defined(BARTMAN_GCC)
#define INTERRUPT
#define INTERRUPT_END do {} while(0)
Expand Down
22 changes: 22 additions & 0 deletions include/ace/utils/palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ extern "C" {
*/
void paletteLoadFromPath(const char *szPath, UWORD *pPalette, UBYTE ubMaxLength);

/**
* @brief Saves given palette into .plt file.
* @param pPalette Palette to save.
* @param ubColorCnt Number of colors in palette.
* @param szPath Destination path.
*/
void paletteSave(UWORD *pPalette, UBYTE ubColorCnt, char *szPath);

/**
* @brief Loads palette from supplied .plt file to given address.
* @param pFile Handle to the palette file. Will be closed on function return.
Expand Down Expand Up @@ -62,9 +70,23 @@ void paletteDim(
* @brief Dims a single input color to given brightness level.
* @param uwFullColor Full color used as a base to calculate percentage.
* @param ubLevel Brightness level - 15 for no dim, 0 for total blackness.
*
* @see paletteColorMix()
*/
UWORD paletteColorDim(UWORD uwFullColor, UBYTE ubLevel);

/**
* @brief Interpolates two colors at given level.
* @param uwColorPrimary Primary color in the mix.
* @param uwColorSecondary Secondary color in the mix.
* @param ubLevel Mix ratio - 15 results in primary color, 0 in secondary.
* @return Mixed color between uwColorPrimary and uwColorSecondary.
*
* @note This function is slower than paletteColorDim().
* @see paletteColorDim()
*/
UWORD paletteColorMix(UWORD uwColorPrimary, UWORD uwColorSecondary, UBYTE ubLevel);

/**
* @brief Writes given palette to debug .bmp file.
*
Expand Down
20 changes: 10 additions & 10 deletions src/ace/managers/blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ UBYTE _blitCheck(
#endif // defined(ACE_DEBUG)

void blitWait(void) {
while(!blitIsIdle()) continue;
// A1000 Blitter done bug:
// The solution is to read hardware register before testing the bit.
(void)g_pCustom->dmaconr;
while(g_pCustom->dmaconr & DMAF_BLTDONE) continue;
}

/**
* Checks if blitter is idle
* Polls 2 times - A1000 Agnus bug workaround
*/
UBYTE blitIsIdle(void) {
if(!(g_pCustom->dmaconr & DMAF_BLTDONE)) {
if(!(g_pCustom->dmaconr & DMAF_BLTDONE)) {
return 1;
}
// A1000 Blitter done bug:
// The solution is to read hardware register before testing the bit.
(void)g_pCustom->dmaconr;
if(g_pCustom->dmaconr & DMAF_BLTDONE) {
return 0;
}
return 0;
return 1;
}

UBYTE blitUnsafeCopy(
Expand Down
15 changes: 14 additions & 1 deletion src/ace/managers/bob.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ void bobInit(
tBob *pBob, UWORD uwWidth, UWORD uwHeight, UBYTE isUndrawRequired,
UBYTE *pFrameData, UBYTE *pMaskData, UWORD uwX, UWORD uwY
) {
logBlockBegin(
"bobInit(pBob: %p, uwWidth: %hu, uwHeight: %hu, isUndrawRequired: %hhu, pFrameData: %p, pMaskData: %p, uwX: %hu, uwY: %hu)",
pBob, uwWidth, uwHeight, isUndrawRequired, pFrameData, pMaskData, uwX, uwY
);
#if defined(ACE_DEBUG)
pBob->_uwOriginalWidth = uwWidth;
pBob->_uwOriginalHeight = uwHeight;
Expand Down Expand Up @@ -238,7 +242,7 @@ void bobInit(
}
#endif
++s_ubMaxBobCount;
// logWrite("Added bob, now max: %hhu\n", s_ubMaxBobCount);
logBlockEnd("bobInit()");
}

void bobSetFrame(tBob *pBob, UBYTE *pFrameData, UBYTE *pMaskData) {
Expand Down Expand Up @@ -279,6 +283,9 @@ void bobSetHeight(tBob *pBob, UWORD uwHeight)
}

UBYTE *bobCalcFrameAddress(tBitMap *pBitmap, UWORD uwOffsetY) {
if(uwOffsetY >= pBitmap->Rows) {
logWrite("ERR: bobCalcFrameAddress() OffsY %hu > bitmap height: %hu", uwOffsetY, pBitmap->Rows);
}
return &pBitmap->Planes[0][pBitmap->BytesPerRow * uwOffsetY];
}

Expand Down Expand Up @@ -550,3 +557,9 @@ void bobDiscardUndraw(void) {
s_pQueues[0].ubUndrawCount = 0;
s_pQueues[1].ubUndrawCount = 0;
}

void bobSetCurrentBuffer(tBitMap *pCurrent) {
if(s_pQueues[!s_ubBufferCurr].pDst == pCurrent) {
s_ubBufferCurr = !s_ubBufferCurr;
}
}
17 changes: 13 additions & 4 deletions src/ace/managers/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <ace/managers/system.h>
#include <ace/utils/custom.h>
#include <hardware/intbits.h> // INTB_PORTS
#define KEY_RELEASED_BIT 1
#define KEY_INTERRUPT_RELEASED_BIT 1
#define KEY_INPUT_HANDLER_RELEASED_MASK BV(7)

#if defined ACE_DEBUG
static UBYTE s_bInitCount = 0;
Expand All @@ -35,13 +36,19 @@ void keySetState(UBYTE ubKeyCode, UBYTE ubKeyState) {
keyIntSetState(&g_sKeyManager, ubKeyCode, ubKeyState);
}

void onRawKeyInput(UBYTE ubRawKey) {
UBYTE isKeyReleased = ubRawKey & KEY_INPUT_HANDLER_RELEASED_MASK;
ubRawKey &= ~KEY_INPUT_HANDLER_RELEASED_MASK;
keySetState(ubRawKey, isKeyReleased ? KEY_NACTIVE : KEY_ACTIVE);
}

/**
* Key interrupt server
* Gets key press/release from kbd controller and confirms reception
* by handshake
*/
FN_HOTSPOT
void INTERRUPT keyIntServer(
void INTERRUPT onKeyInterrupt(
REGARG(volatile tCustom *pCustom, "a0"),
REGARG(volatile void *pData, "a1")
) {
Expand All @@ -54,7 +61,7 @@ void INTERRUPT keyIntServer(
UWORD uwStart = pRayPos->bfPosY;

// Get keypress flag and shift key code
UBYTE ubKeyReleased = ubKeyCode & KEY_RELEASED_BIT;
UBYTE ubKeyReleased = ubKeyCode & KEY_INTERRUPT_RELEASED_BIT;
ubKeyCode >>= 1;
keyIntSetState(
pKeyManager, ubKeyCode, ubKeyReleased ? KEY_NACTIVE : KEY_ACTIVE
Expand Down Expand Up @@ -99,7 +106,8 @@ void keyCreate(void) {
logWrite("ERR: Keyboard already initialized\n");
}
#endif
systemSetCiaInt(CIA_A, CIAICRB_SERIAL, keyIntServer, &g_sKeyManager);
systemSetCiaInt(CIA_A, CIAICRB_SERIAL, onKeyInterrupt, &g_sKeyManager);
systemSetKeyInputHandler(onRawKeyInput);
logBlockEnd("keyCreate()");
}

Expand All @@ -112,6 +120,7 @@ void keyDestroy(void) {
}
#endif
systemSetCiaInt(CIA_A, CIAICRB_SERIAL, 0, 0);
systemSetKeyInputHandler(0);
logBlockEnd("keyDestroy()");
}

Expand Down
Loading