From 72240cb601738695dcecd3e772b80b30ee08dfc8 Mon Sep 17 00:00:00 2001 From: sillysagiri Date: Sun, 26 Dec 2021 13:10:55 +0700 Subject: [PATCH] hopefully work --- .github/workflows/build.yml | 73 +++++++++++++++++++++++++++++++++++++ .gitignore | 5 +++ NDS/source/main.cpp | 71 ++++++++++++++++++------------------ assets/convert.sh | 2 +- encoder/index.js | 4 +- 5 files changed, 116 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cd2a5dd --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,73 @@ +name: CI + +on: + push: + branches: ["master"] + +jobs: + build: + runs-on: ubuntu-latest + container: devkitpro/devkitarm + name: "Build with devkitARM" + outputs: + commit_tag: ${{ steps.build.outputs.commit_tag }} + commit_message: ${{ steps.build.outputs.commit_message }} + steps: + - uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + + - name: Setup NodejS + uses: actions/setup-node@v2 + with: + node-version: '16' + + - name: Install dependency + run: | + sudo apt update -y + sudo apt install ffmpeg build-essential curl + + sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl + sudo chmod a+rx /usr/local/bin/youtube-dl + + - name: Prepare video + run: | + cd assets + youtube-dl -f 18 https://www.youtube.com/watch?v=FtutLA63Cp8 -o 'video.%(ext)s' + + sh convert.sh + + - name: Encode video + run: | + cd encoder + npm install + + cd cpp + g++ lzss.cpp -o lzss + cd .. + + node . + + - name: Build NDS + run: | + cp assets/music.raw NDS/nitrofiles/ + cp encoder/data_compress NDS/nitrofiles/ + + cd NDS + make + + - name: Prepare artefact + run: | + cd NDS/dist + mkdir -p dist + tar -czvf dist/${{ github.event.repository.name }}.tar.gz *.nds + + - name: Upload to basement + uses: SamKirkland/FTP-Deploy-Action@4.0.0 + with: + server: ${{ secrets.ftp_server }} + username: ${{ secrets.ftp_username }} + password: ${{ secrets.ftp_password }} + local-dir: ./NDS/dist/dist/ + server-dir: ./public_html/basement/${{ github.event.repository.name }}/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 34ce51f..d3080da 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,13 @@ !/NDS/nitrofiles/.gitignore /NDS/cmake /NDS/compile_commands.json +/NDS/.cache +/NDS/build +/NDS/dist /encoder/node_modules +/encoder/data_compress +/encoder/temp /encoder/cpp/lzss /temp diff --git a/NDS/source/main.cpp b/NDS/source/main.cpp index c464884..311fd80 100644 --- a/NDS/source/main.cpp +++ b/NDS/source/main.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #define TIMER_SPEED (BUS_CLOCK/1024) @@ -14,9 +13,23 @@ uint16_t blockSize; char buffer[256*192*2]; char buffer2[256*256*2]; +bool shouldDraw = false; +bool queueAvaible = false; + void VBlankProc() { - in.read((char*)&blockSize, sizeof(blockSize)); - in.read(buffer, blockSize); + if (shouldDraw) { + shouldDraw = false; + + if (queueAvaible) { + queueAvaible = false; + + dmaCopyWordsAsynch(3, buffer2, VRAM_A, 256*192*2); + } + } +} + +void TimerTick() { + shouldDraw = true; } mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format ) { @@ -42,7 +55,7 @@ mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats forma } int main(void) { - consoleDebugInit(DebugDevice_NOCASH); + consoleDemoInit(); videoSetMode(MODE_FB0); vramSetBankA(VRAM_A_LCD); @@ -51,60 +64,48 @@ int main(void) { // nitrofiles initialization - if (nitroFSInit(NULL)) { + if (!nitroFSInit(NULL)) { chdir("nitro:/"); std::cerr << "nitrofs init success" << std::endl; } else { consoleDemoInit(); - std::cout << "cannot init nitrofs" << std::endl; + std::cout << "failed to init nitrofs" << std::endl; + std::cout << "Please launch the game\nfrom nds-bootstrap from twilightmenu" << std::endl; while(1) { // freezee } } - in.open("output", std::ios::binary); - - uint16_t totalsize; - char buf[256*192*2]; - char buf2[256*256*2]; - - in.read((char*)&totalsize, sizeof(totalsize)); - in.read(buf, totalsize); - - swiDecompressLZSSWram(buf, buf2); - dmaCopyWordsAsynch(3, buf2, VRAM_A, 256*192*2); - - // for (int i=0; i<192*256; i++) { - // VRAM_A[i] = buf[i]; - // } - - while(1) { - // loop - } - mmInitDefault((char*)"soundbank.bin"); file = fopen("music.raw","rb"); mm_stream mystream; mystream.sampling_rate = 22050; // sampling rate = 25khz - mystream.buffer_length = 1200; // buffer length = 1200 samples + mystream.buffer_length = 2400; // buffer length = 1200 samples mystream.callback = on_stream_request; // set callback function mystream.format = MM_STREAM_16BIT_MONO; // format = stereo 16-bit mystream.timer = MM_TIMER0; // use hardware timer 0 - mystream.manual = false; // use manual filling + mystream.manual = true; // use manual filling mmStreamOpen( &mystream ); - irqSet(IRQ_VBLANK, VBlankProc); + // quick hack... sometime it need to update once? + mmStreamUpdate(); mmStreamUpdate(); - while(1) { - // loop - } + irqSet(IRQ_VBLANK, VBlankProc); + timerStart(2, ClockDivider_1024, TIMER_FREQ_1024(30), TimerTick); in.open("data_compress", std::ios::in | std::ios::binary); - while(1) { - swiDecompressLZSSWram(buffer, buffer2); - dmaCopyWordsAsynch(3, buffer2, VRAM_A, 256*192*2); + while(true) { + // timerElapsed(2); + mmStreamUpdate(); + + if (!in.eof() && !queueAvaible) { + in.read((char*)&blockSize, sizeof(blockSize)); + in.read(buffer, blockSize); + swiDecompressLZSSWram(buffer, buffer2); + queueAvaible = true; + } swiWaitForVBlank(); } diff --git a/assets/convert.sh b/assets/convert.sh index 9f8d06b..cc8dc86 100644 --- a/assets/convert.sh +++ b/assets/convert.sh @@ -15,4 +15,4 @@ ffmpeg -i $video -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse=dither=no # ffmpeg -i $video -vf "$filters" out/out_%d.bmp # audio -ffmpeg -i $video -f s16le -ac 1 -ar 48000 music.raw \ No newline at end of file +ffmpeg -i $video -f s16le -ac 1 -ar 22050 music.raw \ No newline at end of file diff --git a/encoder/index.js b/encoder/index.js index d904bd0..a2f3690 100644 --- a/encoder/index.js +++ b/encoder/index.js @@ -5,7 +5,7 @@ const { execSync } = require('child_process'); execSync("rm -rf data_compress") // load gif -const gif_raw = fs.readFileSync("../assets/out-60.gif"); +const gif_raw = fs.readFileSync("../assets/out.gif"); const gif_data = new omg.GifReader(gif_raw); const num_pixel = gif_data.width * gif_data.height; const num_frames = gif_data.numFrames(); @@ -66,8 +66,6 @@ for (let i=0; i