From: ljsebald <ljs...@us...> - 2023-09-10 16:42:36
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 0f3b4d559a693ff6144272bf75bd98f09a849be5 (commit) via 5817cc42b7d7148fef6f796e4ef9cac3fc19c8fd (commit) via 4465add7249f76c027db209d06c09bddfa8d9a57 (commit) via 3c150f183684879573bf48f0a5c22df5ff489b40 (commit) via 77ad50af334469644b4514fdb48bbec94963ee30 (commit) via bd55ad32452e34df1e927cf131a1e1b09b7e4e06 (commit) via f3fa9d3c047873389289f1ec1cd32cfc713a90cc (commit) via 27ca4d99ca5f4a09596fa1fbc52d6f663f25a78a (commit) from 0974fbe0bc8701012e4f5a2896265109104ca394 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0f3b4d559a693ff6144272bf75bd98f09a849be5 Merge: 5817cc4 27ca4d9 Author: Lawrence Sebald <ljs...@us...> Date: Sun Sep 10 12:41:35 2023 -0400 Merge pull request #298 from KallistiOS/c99_atomics Enabled atomics support in environ_dreamcast.h commit 5817cc42b7d7148fef6f796e4ef9cac3fc19c8fd Merge: 4465add f3fa9d3 Author: Lawrence Sebald <ljs...@us...> Date: Sun Sep 10 12:40:55 2023 -0400 Merge pull request #300 from KallistiOS/thd_each_retval Modified thd_each() to support early exit + retval commit 4465add7249f76c027db209d06c09bddfa8d9a57 Merge: 3c150f1 bd55ad3 Author: Lawrence Sebald <ljs...@us...> Date: Sun Sep 10 12:38:41 2023 -0400 Merge pull request #302 from KallistiOS/wav_warnings wav2adpcm: Fixed 2 warnings, WAV verification errors mapped to stderr commit 3c150f183684879573bf48f0a5c22df5ff489b40 Merge: 0974fbe 77ad50a Author: Lawrence Sebald <ljs...@us...> Date: Sun Sep 10 12:35:21 2023 -0400 Merge pull request #303 from pcercuei/update-libtsunami-examples examples: tsunami: Update examples to latest API commit 77ad50af334469644b4514fdb48bbec94963ee30 Author: Paul Cercueil <pa...@cr...> Date: Sun Sep 3 12:15:16 2023 +0200 examples: tsunami: Update examples to latest API Signed-off-by: Paul Cercueil <pa...@cr...> commit bd55ad32452e34df1e927cf131a1e1b09b7e4e06 Author: Falco Girgis <gyr...@gm...> Date: Sat Sep 9 14:57:27 2023 -0500 wav2adpcm: Fixed 2 warnings, error logs to stderr - Fixed two warnings which popped up about not using the return value from fread() when reading the next wave chunk and its sizes - Noticed while validating the wav header, we were writing error messagse to stdout instead of stderr commit f3fa9d3c047873389289f1ec1cd32cfc713a90cc Author: Falco Girgis <gyr...@gm...> Date: Fri Sep 8 12:06:26 2023 -0500 Modified thd_each() to support early exit + retval It is often the case that iteration over a thread is doing a search for a particular thread or group of threads, allowing iteration to halt early. It is also the case that frequently the user may wish to return different values from their callback depending on the results. Presently we take a user callback whose return value is simply ignored and we return a "result code" that is hardcoded to always be zero. - Modified thd_each() to cease iteration early upon encountering a non-zero return value from the user's callback - Modified thd_each() to return the callback's return value commit 27ca4d99ca5f4a09596fa1fbc52d6f663f25a78a Author: Falco Girgis <gyr...@gm...> Date: Fri Sep 8 09:27:16 2023 -0500 Enabled atomics support in environ_dreamcast.h - Using the soft-imask model for SH, which essentially does "atomic" operations between disabling and reenabling interrupts - This gives us basic C99 atomic support and C++11 atomics support for types of size byte, short, or word, but additional libatomics back-end implementation is required for generic types and for dwords. ----------------------------------------------------------------------- Summary of changes: environ_dreamcast.sh | 2 +- examples/dreamcast/tsunami/banner/banner.cpp | 38 ++++++++++++++------------ examples/dreamcast/tsunami/font/font.cpp | 6 ++-- examples/dreamcast/tsunami/genmenu/genmenu.cpp | 38 ++++++++++++++------------ include/kos/thread.h | 6 ++-- kernel/thread/thread.c | 4 ++- utils/wav2adpcm/wav2adpcm.c | 27 ++++++++++++------ 7 files changed, 70 insertions(+), 51 deletions(-) diff --git a/environ_dreamcast.sh b/environ_dreamcast.sh index 3182bc6..ec68262 100644 --- a/environ_dreamcast.sh +++ b/environ_dreamcast.sh @@ -1,7 +1,7 @@ # KallistiOS environment variable settings. These are the shared pieces # for the Dreamcast(tm) platform. -export KOS_CFLAGS="${KOS_CFLAGS} -ml -m4-single-only -ffunction-sections -fdata-sections" +export KOS_CFLAGS="${KOS_CFLAGS} -ml -m4-single-only -ffunction-sections -fdata-sections -matomic-model=soft-imask" export KOS_AFLAGS="${KOS_AFLAGS} -little" if [ x${KOS_SUBARCH} = xnaomi ]; then diff --git a/examples/dreamcast/tsunami/banner/banner.cpp b/examples/dreamcast/tsunami/banner/banner.cpp index d46425c..514aef9 100644 --- a/examples/dreamcast/tsunami/banner/banner.cpp +++ b/examples/dreamcast/tsunami/banner/banner.cpp @@ -42,6 +42,8 @@ even the main loop and user input eventually. #include <tsu/triggers/chainanim.h> #include <tsu/triggers/death.h> +#include <memory> + extern uint8 romdisk[]; KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS); KOS_INIT_ROMDISK(romdisk); @@ -117,34 +119,34 @@ int main(int argc, char **argv) { pvr_init_defaults(); // Load a texture for our banner - RefPtr<Texture> txr = new Texture("/rd/logo.png", true); + auto txr = std::make_shared<Texture>("/rd/logo.png", true); // Setup a scene and place a banner in it - RefPtr<Scene> sc = new Scene(); - RefPtr<Banner> b = new Banner(PVR_LIST_TR_POLY, txr); + auto sc = std::make_shared<Scene>(); + auto b = std::make_shared<Banner>(PVR_LIST_TR_POLY, txr); sc->subAdd(b); // Put the banner off-screen to begin with, and attach a LogXYMover // animation to move it to 320,240 b->setTranslate(Vector(800, 600, 10)); - RefPtr<LogXYMover> mover = new LogXYMover(320, 240); + auto mover = std::make_shared<LogXYMover>(320, 240); b->animAdd(mover); // Add a trigger to the LogXYMover to chain to our Circler animation. - RefPtr<Circler> circ = new Circler(320, 240, 10, 75, 30); - mover->triggerAdd(new ChainAnimation(circ)); + auto circ = std::make_shared<Circler>(320, 240, 10, 75, 30); + mover->triggerAdd(std::make_shared<ChainAnimation>(circ)); // Add a couple of labels with explanation. Set each one's // initial alpha to 0 and fade them in over 30 frames. - RefPtr<Font> fnt = new Font("/rd/typewriter.txf"); - RefPtr<Label> lbl1 = new Label(fnt, "Use the joystick to control the size", 24, true, true); + auto fnt = std::make_shared<Font>("/rd/typewriter.txf"); + auto lbl1 = std::make_shared<Label>(fnt, "Use the joystick to control the size", 24, true, true); lbl1->setTranslate(Vector(320, 360, 20)); sc->subAdd(lbl1); lbl1->setAlpha(0.0f); - RefPtr<AlphaFader> fader = new AlphaFader(1.0f, 1.0f / 30.0f); + auto fader = std::make_shared<AlphaFader>(1.0f, 1.0f / 30.0f); lbl1->animAdd(fader); - RefPtr<Label> lbl2 = new Label(fnt, "of the circle. Press START to quit.", 24, true, true); + auto lbl2 = std::make_shared<Label>(fnt, "of the circle. Press START to quit.", 24, true, true); lbl2->setTranslate(Vector(320, 360 + 24, 20)); sc->subAdd(lbl2); lbl2->setAlpha(0.0f); @@ -193,21 +195,21 @@ int main(int argc, char **argv) { printf("Starting exodus...\n"); // Create an ExpXYMover heading off-screen and chain it to the Circler - RefPtr<ExpXYMover> mover2 = new ExpXYMover(-1.0f, -1.0f, 320 - 800, 240 - 600); - circ->triggerAdd(new ChainAnimation(mover2)); + auto mover2 = std::make_shared<ExpXYMover>(-1.0f, -1.0f, 320 - 800, 240 - 600); + circ->triggerAdd(std::make_shared<ChainAnimation>(mover2)); // Add a trigger to the ExpXYMover that will signal that the banner // is finished once it reaches the animation endpoint. - mover2->triggerAdd(new Death()); + mover2->triggerAdd(std::make_shared<Death>()); // Add faders with triggers; note we use two separate alpha faders // this time so we have two triggers (one per label) - fader = new AlphaFader(0.0f, -1.0f / 30.0f); - fader->triggerAdd(new Death()); + fader = std::make_shared<AlphaFader>(0.0f, -1.0f / 30.0f); + fader->triggerAdd(std::make_shared<Death>()); lbl1->animAdd(fader); - fader = new AlphaFader(0.0f, -1.0f / 30.0f); - fader->triggerAdd(new Death()); + fader = std::make_shared<AlphaFader>(0.0f, -1.0f / 30.0f); + fader->triggerAdd(std::make_shared<Death>()); lbl2->animAdd(fader); // Tell the circler we're about to finish up @@ -243,7 +245,7 @@ int main(int argc, char **argv) { MAPLE_FOREACH_END() } - // Ok, we're all done! The RefPtrs will take care of mem cleanup. + // Ok, we're all done! The std::shared_ptrs will take care of mem cleanup. return 0; } diff --git a/examples/dreamcast/tsunami/font/font.cpp b/examples/dreamcast/tsunami/font/font.cpp index 8adcc29..b77935f 100644 --- a/examples/dreamcast/tsunami/font/font.cpp +++ b/examples/dreamcast/tsunami/font/font.cpp @@ -13,6 +13,8 @@ #include <tsu/texture.h> #include <plx/sprite.h> +#include <memory> + /* Shows off some very basic usage of the font and texture objects with Parallax as the vertex system rather than the Tsunami scene @@ -31,10 +33,10 @@ int main(int argc, char **argv) { pvr_init_defaults(); - RefPtr<Font> fnt = new Font("/rd/axaxax.txf"); + auto fnt = std::make_shared<Font>("/rd/axaxax.txf"); fnt->setSize(24.0f); - RefPtr<Texture> txr = new Texture("/rd/logo.png", true); + auto txr = std::make_shared<Texture>("/rd/logo.png", true); pvr_set_bg_color(0.2f, 0.0f, 0.4f); diff --git a/examples/dreamcast/tsunami/genmenu/genmenu.cpp b/examples/dreamcast/tsunami/genmenu/genmenu.cpp index faa3b1a..d6f18c3 100644 --- a/examples/dreamcast/tsunami/genmenu/genmenu.cpp +++ b/examples/dreamcast/tsunami/genmenu/genmenu.cpp @@ -27,13 +27,15 @@ basics. #include <tsu/anims/alphafader.h> #include <tsu/triggers/death.h> +#include <memory> + extern uint8 romdisk[]; KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS); KOS_INIT_ROMDISK(romdisk); -class MyMenu : public GenericMenu, public RefCnt { +class MyMenu : public GenericMenu { public: - MyMenu(Font * fnt) { + MyMenu(std::shared_ptr<Font> fnt) { // Offset our scene so 0,0,0 is the screen center with Z +10 m_scene->setTranslate(Vector(320, 240, 10)); @@ -44,21 +46,21 @@ public: m_gray = Color(1, 0.7f, 0.7f, 0.7f); // Setup three labels and have them zoom in. - m_options[0] = new Label(fnt, "Do Thing 1", 24, true, true); + m_options[0] = std::make_shared<Label>(fnt, "Do Thing 1", 24, true, true); m_options[0]->setTranslate(Vector(0, 400, 0)); - m_options[0]->animAdd(new LogXYMover(0, 0)); + m_options[0]->animAdd(std::make_shared<LogXYMover>(0, 0)); m_options[0]->setTint(m_white); m_scene->subAdd(m_options[0]); - m_options[1] = new Label(fnt, "Do Thing 2", 24, true, true); + m_options[1] = std::make_shared<Label>(fnt, "Do Thing 2", 24, true, true); m_options[1]->setTranslate(Vector(0, 400 + 400, 0)); - m_options[1]->animAdd(new LogXYMover(0, 24)); + m_options[1]->animAdd(std::make_shared<LogXYMover>(0, 24)); m_options[1]->setTint(m_gray); m_scene->subAdd(m_options[1]); - m_options[2] = new Label(fnt, "Quit", 24, true, true); + m_options[2] = std::make_shared<Label>(fnt, "Quit", 24, true, true); m_options[2]->setTranslate(Vector(0, 400 + 400 + 400, 0)); - m_options[2]->animAdd(new LogXYMover(0, 48)); + m_options[2]->animAdd(std::make_shared<LogXYMover>(0, 48)); m_options[2]->setTint(m_gray); m_scene->subAdd(m_options[2]); @@ -109,16 +111,16 @@ public: virtual void startExit() { // Apply some expmovers to the options. - ExpXYMover * m = new ExpXYMover(0, 1, 0, 400); - m->triggerAdd(new Death()); + auto m = std::make_shared<ExpXYMover>(0, 1, 0, 400); + m->triggerAdd(std::make_shared<Death>()); m_options[0]->animAdd(m); - m = new ExpXYMover(0, 1.2, 0, 400); - m->triggerAdd(new Death()); + m = std::make_shared<ExpXYMover>(0, 1.2, 0, 400); + m->triggerAdd(std::make_shared<Death>()); m_options[1]->animAdd(m); - m = new ExpXYMover(0, 1.4, 0, 400); - m->triggerAdd(new Death()); + m = std::make_shared<ExpXYMover>(0, 1.4, 0, 400); + m->triggerAdd(std::make_shared<Death>()); m_options[2]->animAdd(m); GenericMenu::startExit(); @@ -126,7 +128,7 @@ public: Color m_white, m_gray; - RefPtr<Label> m_options[3]; + std::shared_ptr<Label> m_options[3]; int m_cursel; }; @@ -140,16 +142,16 @@ int main(int argc, char **argv) { pvr_init_defaults(); // Load a font - RefPtr<Font> fnt = new Font("/rd/typewriter.txf"); + auto fnt = std::make_shared<Font>("/rd/typewriter.txf"); // Create a menu - RefPtr<MyMenu> mm = new MyMenu(fnt); + auto mm = std::make_shared<MyMenu>(fnt); // Do the menu mm->doMenu(); - // Ok, we're all done! The RefPtrs will take care of mem cleanup. + // Ok, we're all done! The std::shared_ptrs will take care of mem cleanup. return 0; } diff --git a/include/kos/thread.h b/include/kos/thread.h index d61a4cd..83dbba0 100644 --- a/include/kos/thread.h +++ b/include/kos/thread.h @@ -650,10 +650,12 @@ int thd_detach(kthread_t *thd); \ingroup threads \relatesalso kthread_t - \param cb The callback to call for each thread + \param cb The callback to call for each thread. + If a nonzero value is returned, iteration + ceases immediately. \param data User data to be passed to the callback - \retval 0 On success. + \retval 0 or the first nonzero value returned by \p cb. \sa thd_pslist */ diff --git a/kernel/thread/thread.c b/kernel/thread/thread.c index a0fa789..18843ba 100644 --- a/kernel/thread/thread.c +++ b/kernel/thread/thread.c @@ -92,9 +92,11 @@ static const char *thd_state_to_str(kthread_t *thd) { int thd_each(int (*cb)(kthread_t *thd, void *user_data), void *data) { kthread_t *cur; + int retval; LIST_FOREACH(cur, &thd_list, t_list) { - cb(cur, data); + if((retval = cb(cur, data))) + return retval; } return 0; diff --git a/utils/wav2adpcm/wav2adpcm.c b/utils/wav2adpcm/wav2adpcm.c index 2b4252d..13adf7e 100644 --- a/utils/wav2adpcm/wav2adpcm.c +++ b/utils/wav2adpcm/wav2adpcm.c @@ -186,32 +186,32 @@ int validate_wav_header(wavhdr_t *wavhdr, int format, int bits, FILE *in) { int result = 0; if(memcmp(wavhdr->hdr1, "RIFF", 4)) { - printf("Invalid RIFF header.\n"); + fprintf(stderr, "Invalid RIFF header.\n"); result = -1; } if(memcmp(wavhdr->hdr2, "WAVEfmt ", 8)) { - printf("Invalid WAVEfmt header.\n"); + fprintf(stderr, "Invalid WAVEfmt header.\n"); result = -1; } if(wavhdr->hdrsize != 0x10) { - printf("Invalid header size.\n"); + fprintf(stderr, "Invalid header size.\n"); result = -1; } if(wavhdr->format != format) { - printf("Unsupported format.\n"); + fprintf(stderr, "Unsupported format.\n"); result = -1; } if(wavhdr->channels != 1 && wavhdr->channels != 2) { - printf("Unsupported number of channels.\n"); + fprintf(stderr, "Unsupported number of channels.\n"); result = -1; } if(wavhdr->bits != bits) { - printf("Unsupported bit depth.\n"); + fprintf(stderr, "Unsupported bit depth.\n"); result = -1; } @@ -224,10 +224,18 @@ int validate_wav_header(wavhdr_t *wavhdr, int format, int bits, FILE *in) { do { /* Read the next chunk header */ - fread(wavhdr->hdr3, 1, 4, in); + if(fread(wavhdr->hdr3, 1, 4, in) != 4) { + fprintf(stderr, "Failed to read next chunk header!\n"); + result = -1; + break; + } /* Read the chunk size */ - fread(&wavhdr->datasize, 1, 4, in); + if(fread(&wavhdr->datasize, 1, 4, in) != 4) { + fprintf(stderr, "Failed to read chunk size!\n"); + result = -1; + break; + } /* Skip the chunk if it's not the "data" chunk. */ if(memcmp(wavhdr->hdr3, "data", 4)) @@ -294,11 +302,12 @@ int wav2adpcm(const char *infile, const char *outfile) { out = fopen(outfile, "wb"); if(fwrite(&wavhdr, sizeof(wavhdr), 1, out) != 1 || - fwrite(adpcmbuf, adpcmsize, 1, out) != 1) { + fwrite(adpcmbuf, adpcmsize, 1, out) != 1) { fprintf(stderr, "Cannot write ADPCM data.\n"); fclose(out); return -1; } + fclose(out); return 0; hooks/post-receive -- A pseudo Operating System for the Dreamcast. |