diff --git a/.github/workflows/samples.yml b/.github/workflows/samples.yml index a8e7b1c..7f265f0 100644 --- a/.github/workflows/samples.yml +++ b/.github/workflows/samples.yml @@ -68,7 +68,7 @@ jobs: strategy: fail-fast: false matrix: - group: [basics, games, services] + group: [ipl, basics, games, services] steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 @@ -95,7 +95,8 @@ jobs: case "$SAMPLE_GROUP" in basics) samples="HelloGameCube ManagedGameCube ShaderDemo VideoMode Pong GreenMen" ;; games) samples="Fox Kart Snake DiscBrowser StorageIntegrity" ;; - services) samples="AsyncNetworking AudioDemo IplResources GoogleLogoAram HttpTexture HardwareDiagnostics" ;; + services) samples="AsyncNetworking AudioDemo GoogleLogoAram HttpTexture HardwareDiagnostics" ;; + ipl) samples="IplResources" ;; *) echo "Unexpected sample group $SAMPLE_GROUP" >&2; exit 1 ;; esac mkdir -p "$RUNNER_TEMP/dnd-aot" @@ -122,3 +123,29 @@ jobs: */bin/Release/net8.0/*.elf if-no-files-found: error retention-days: 14 + - name: Stage IPL resource demo download + if: matrix.group == 'ipl' + shell: bash + run: | + mkdir -p "$RUNNER_TEMP/ipl-resources-dol" + cp IplResources/bin/Release/net8.0/IplResources.dol "$RUNNER_TEMP/ipl-resources-dol/IplResources-early-ipl.dol" + sha256sum "$RUNNER_TEMP/ipl-resources-dol/IplResources-early-ipl.dol" + - name: Build IPL hardware diagnostic from the published SDK + if: matrix.group == 'ipl' + run: python3 tools/ipl-diagnostics/build.py --output "${{ runner.temp }}/ipl-diagnostics" + - uses: actions/upload-artifact@v4 + if: matrix.group == 'ipl' + with: + name: ipl-hardware-diagnostic + path: | + ${{ runner.temp }}/ipl-diagnostics/IplDiagnostics-check01.dol + ${{ runner.temp }}/ipl-diagnostics/build.json + if-no-files-found: error + retention-days: 14 + - uses: actions/upload-artifact@v4 + if: matrix.group == 'ipl' + with: + name: ipl-resources-dol + path: ${{ runner.temp }}/ipl-resources-dol/IplResources-early-ipl.dol + if-no-files-found: error + retention-days: 14 diff --git a/Directory.Build.props b/Directory.Build.props index 438cc23..5c90bf9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 0.1.0-preview.333.1 + 0.1.0-preview.343.1 true diff --git a/IplResources/IplResources.csproj b/IplResources/IplResources.csproj index 3222f35..bd1f53f 100644 --- a/IplResources/IplResources.csproj +++ b/IplResources/IplResources.csproj @@ -8,4 +8,10 @@ + + + + diff --git a/IplResources/IplSelection.cs b/IplResources/IplSelection.cs index 7939b38..087e7a5 100644 --- a/IplResources/IplSelection.cs +++ b/IplResources/IplSelection.cs @@ -7,7 +7,7 @@ internal sealed class IplSelection internal static readonly SystemMenuSound[] Effects={SystemMenuSound.TurnSide,SystemMenuSound.TurnCenter,SystemMenuSound.Select,SystemMenuSound.Back,SystemMenuSound.OptionCancel,SystemMenuSound.OptionConfirm,SystemMenuSound.OptionMove1,SystemMenuSound.OptionMove2,SystemMenuSound.OptionMove3,SystemMenuSound.OptionSelect}; internal static readonly SystemTexture[] Textures={SystemTexture.LogoTop,SystemTexture.LogoLeft,SystemTexture.LogoRight,SystemTexture.Environment,SystemTexture.Tiles,SystemTexture.Wordmark}; internal static readonly string[] TextureNames={"Logo top","Logo left","Logo right","Environment","Tiles","Wordmark"}; - internal int Selected {get;private set;}=4; + internal int Selected {get;private set;} internal int Texture {get;private set;} internal void Move(int direction)=>Selected=(Selected+direction+Names.Length)%Names.Length; internal void NextTexture()=>Texture=(Texture+1)%Textures.Length; diff --git a/IplResources/Program.cs b/IplResources/Program.cs index 0687655..c5d04da 100644 --- a/IplResources/Program.cs +++ b/IplResources/Program.cs @@ -24,6 +24,7 @@ internal static IplAudioResources Prepare(CancellationToken cancellation) using var image=SystemFirmware.ReadConsole(cancellation); result.Catalog=image.CreateCatalog(FirmwareCatalogOptions.IncludeMenuAudio,cancellation); if(image.Revision.Contains("Revision 1.2"))result.Revision=image.Revision.Contains("PAL")?"PAL 1.2":"NTSC 1.2"; + else result.Revision="EARLY IPL"; for(int i=0;i Main() Audio.Initialize();DebugOverlay.TextVisible=false; using var draw=new Draw2D(GraphicsDevice.Default,new Draw2DOptions{Width=640,Height=480}); using var text=new IplText();using var cancellation=new CancellationTokenSource(); + string buildLabel="SDK "+IplBuildInfo.SdkVersion+(text.Original?" / IPL font":" / sample font"); var selection=new IplSelection();var textures=new Texture2D?[IplSelection.Textures.Length]; Task? loading=Task.Run(()=>IplAudioResources.Prepare(cancellation.Token)); - IplAudioResources? resources=null;SoundChannel? voice=null;string state="LOADING IPL",detail="Reading console resources"; + IplAudioResources? resources=null;SoundChannel? voice=null;string state="LOADING IPL",detail="Reading console resources",failureDetail=""; bool exit=false;int playing=-1;bool stickUp=false,stickDown=false;Exception? failure=null; var rows=new string[IplSelection.Names.Length];var titles=new string[rows.Length]; for(int i=0;i Main() } } catch(OperationCanceledException){state="CANCELLED";} - catch(Exception error){state="IPL UNAVAILABLE";detail=Short(error.Message,27);} + catch(Exception error) + { + state="IPL UNAVAILABLE";detail=Short(error.Message,27); + failureDetail=error.Message.Length>27?Short(error.Message.Substring(27),27):""; + DebugOverlay.WriteLine("IPL LOAD FAILED "+error.Message); + } loading=null; } if(exit&&loading==null)break; @@ -147,8 +154,8 @@ private static async Task Main() } int selected=selection.Selected;var texture=textures[selection.Texture]; var device=GraphicsDevice.Default;device.BeginFrame(Background);draw.Begin(); - text.Draw(draw,"IPL RESOURCES",24,24,25,Color32.White); - text.Draw(draw,text.Original?"Original system font, textures and audio":"System textures and audio - sample font",24,61,12,Muted); + text.Draw(draw,"IPL RESOURCES B03",24,24,25,Color32.White); + text.Draw(draw,buildLabel,24,61,12,Muted); draw.DrawRectangle(new RectF(465,22,151,29),Muted); text.Draw(draw,resources?.Revision??"CONSOLE IPL",475,30,12,Muted); draw.DrawRectangle(new RectF(24,98,290,286),Muted); @@ -177,6 +184,8 @@ private static async Task Main() text.Draw(draw,resources==null?detail:resources.Details[selected],348,328,12,Muted); if(resources!=null&&resources.Sources[selected]!=null) text.Draw(draw,resources.Sources[selected],348,347,10,Muted); + else if(resources==null&&failureDetail.Length!=0) + text.Draw(draw,failureDetail,348,347,12,Muted); text.Draw(draw,"A PLAY",348,367,11,Color32.White); draw.DrawLine(new Vector2(24,414),new Vector2(616,414),Muted); text.Draw(draw,"UP DOWN SELECT A PLAY B STOP X TEXTURE START EXIT",24,436,10,Color32.White); diff --git a/IplResources/README.md b/IplResources/README.md index a801ac7..8aeec7b 100644 --- a/IplResources/README.md +++ b/IplResources/README.md @@ -17,10 +17,27 @@ authored notes and tails. The three movement identities map to `OptionMove1`, `OptionMove2` and `OptionMove3` respectively. `SystemFirmware.ReadConsole` reads the configured console ROM through EXI. +On a real GameCube, that ROM is built in: no IPL file needs to be installed. +Build B03 consumes public NuGet SDK/runtime `0.1.0-preview.343.1`, published +after [SDK PR #180](https://github.com/capz/DolphinDotNet/pull/180). +The SDK uses continuous DMA for each 1 KiB ROM page, following libogc's ROM +transfer method. The demo shows the actual published SDK version below the title, +starts with Startup selected, and displays load errors across two lines. +The [hardware diagnostic](../tools/ipl-diagnostics/README.md) found identical +ROM bytes through all five read methods on the reporting PAL console with +GC Loader / CubiBoot: CRC-32 `6DAC1F2A`, matching the early NTSC 1.0 reference. +The console's region alone therefore does not select its resource profile. +The user confirmed Startup and textures working on that console with B02 / +SDK 339. B03 adds the early firmware's ten menu effects through the existing +SDK APIs; no sample-side mapping or replacement audio is needed. In Dolphin, configure an appropriate original IPL in its regional `GC` user directory. The app does not download firmware or probe storage for `ipl.bin`. -The menu profile supports NTSC 1.2 and PAL 1.2; other firmware can report -individual resources unavailable. Without an IPL the app shows the failure and +The menu profiles support early NTSC 1.0, NTSC 1.2 and PAL 1.2. The early +profile has its own velocity, envelope clock, effects-send settings and +three-second delay tail. Unknown menu profiles say `Menu profile unsupported`; +this is separate from an `IPL unavailable` acquisition failure. +Other firmware can report individual +resources unavailable. Without an IPL the app shows the failure and retains the sample font. No firmware, original textures, samples or recordings are bundled, and no generated tone substitutes for an unavailable effect. @@ -43,7 +60,14 @@ The SDK's [API guide](https://github.com/capz/DolphinDotNet/blob/main/docs/syste and [audio qualification report](https://github.com/capz/DolphinDotNet/blob/main/docs/system-menu-audio-research.md) describe the supported profiles, preparation budgets and measured output differences. Menu rendering is deterministic; bit-identical IPL DSP output and -physical-console playback have not been established. +physical-console playback of the ten newly enabled early effects have not +been established. Overlapping short effects can differ in level from the +running IPL because they start at a deterministic sequence phase. + +The `ipl-resources-dol` CI artifact contains `IplResources-early-ipl.dol`. +Its dedicated native build group makes this download available while the +other sample builds finish. Confirm `IPL RESOURCES B03` and SDK +`0.1.0-preview.343.1` on screen when testing it. ```sh dotnet build IplResources/IplResources.sln -c Release diff --git a/README.md b/README.md index 0a6afd8..f4c4a5e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DolphinDotNet Samples -Run commands from the repository root. These are independent NuGet consumers of [`DolphinDotNet.Sdk`](https://www.nuget.org/packages/DolphinDotNet.Sdk/) and [`DolphinDotNet.GameCube`](https://www.nuget.org/packages/DolphinDotNet.GameCube/). Both are pinned to preview `0.1.0-preview.333.1` in `global.json` and `Directory.Build.props`; the `DolphinDotNet.Core` dependency is resolved transitively. No checkout of the compiler/runtime repository is required. All examples target .NET 8 for compilation; +Run commands from the repository root. These are independent NuGet consumers of [`DolphinDotNet.Sdk`](https://www.nuget.org/packages/DolphinDotNet.Sdk/) and [`DolphinDotNet.GameCube`](https://www.nuget.org/packages/DolphinDotNet.GameCube/). Both are pinned to preview `0.1.0-preview.343.1` in `global.json` and `Directory.Build.props`; the `DolphinDotNet.Core` dependency is resolved transitively. No checkout of the compiler/runtime repository is required. All examples target .NET 8 for compilation; the GameCube runs generated native code, using only the supported AOT API subset. | Sample | Demonstrates | Setup / result | diff --git a/ci/validate_samples.py b/ci/validate_samples.py index 85229ce..6522f8e 100644 --- a/ci/validate_samples.py +++ b/ci/validate_samples.py @@ -6,7 +6,7 @@ import xml.etree.ElementTree as ET ROOT = pathlib.Path(__file__).resolve().parents[1] -VERSION = "0.1.0-preview.333.1" +VERSION = "0.1.0-preview.343.1" sdk = json.loads((ROOT / "global.json").read_text())["msbuild-sdks"]["DolphinDotNet.Sdk"] props = ET.parse(ROOT / "Directory.Build.props").getroot() version = props.find(".//DndPackageVersion").text @@ -29,7 +29,7 @@ assert not re.search(r"\.\.\\\.\.\\src\\", source), str(sln) # The required native matrix must explicitly cover all migrated applications. workflow = (ROOT / ".github/workflows/samples.yml").read_text() -for group in ("basics", "games", "services"): +for group in ("basics", "games", "services", "ipl"): assert group in workflow, group for name in sorted(path.stem for path in projects): assert name in workflow, f"{name} missing from packaged AOT build matrix" diff --git a/global.json b/global.json index 17cd52d..506f5cd 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "msbuild-sdks": { - "DolphinDotNet.Sdk": "0.1.0-preview.333.1" + "DolphinDotNet.Sdk": "0.1.0-preview.343.1" } } diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 5ae98e3..bd50430 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -3,6 +3,6 @@ it includes Common/*.cs in every game, while host tests compile only targeted sample sources and sometimes supply fake platform dependencies. --> - 0.1.0-preview.333.1 + 0.1.0-preview.343.1 diff --git a/tools/ipl-diagnostics/IplDiagnostics.csproj b/tools/ipl-diagnostics/IplDiagnostics.csproj new file mode 100644 index 0000000..6f0ed27 --- /dev/null +++ b/tools/ipl-diagnostics/IplDiagnostics.csproj @@ -0,0 +1,9 @@ + + + Exe + net8.0 + + + + + diff --git a/tools/ipl-diagnostics/LICENSE.cipher.txt b/tools/ipl-diagnostics/LICENSE.cipher.txt new file mode 100644 index 0000000..522329d --- /dev/null +++ b/tools/ipl-diagnostics/LICENSE.cipher.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 supertazon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tools/ipl-diagnostics/Program.cs b/tools/ipl-diagnostics/Program.cs new file mode 100644 index 0000000..e2887e5 --- /dev/null +++ b/tools/ipl-diagnostics/Program.cs @@ -0,0 +1,40 @@ +using System; +using Dolphin.Diagnostics; +using Dolphin.System; + +// Run the published managed cipher on the actual PowerPC target, independently +// of EXI and Dolphin's already-decoded ROM. Only generated data is used here. +internal static class Program +{ + private static int Main() + { + DebugOverlay.WriteLine("IPL CHECK 01 - CHECKING PUBLISHED SDK CIPHER"); + var bytes=new byte[FirmwareImage.ImageBytes]; + FirmwareImage.Transform(bytes); + uint hash=2166136261; + for(int i=0;i +#include + +#define IPL_BYTES 0x200000u +#define IPL_CIPHER_END 0x1aff00u + +static uint32_t ipl_crc32(const uint8_t *bytes,unsigned count) +{ + uint32_t table[256]; + for(unsigned i=0;i<256;i++){ + uint32_t v=i; + for(unsigned bit=0;bit<8;bit++)v=(v>>1)^((v&1)?0xedb88320u:0); + table[i]=v; + } + uint32_t crc=0xffffffffu; + for(unsigned i=0;i>8)^table[(crc^bytes[i])&255]; + return ~crc; +} + +// IPL cipher reversed by Segher Boessenkool, copyright 2008. +// Same MIT-licensed reference as the SDK; see LICENSE.cipher.txt. +static void ipl_descramble(uint8_t *bytes) +{ + uint16_t t=0x2953,u=0xd9c2,v=0x3ff1; + unsigned x=1; + for(unsigned at=0x100;at>1)&1,u0=u&1,u1=(u>>1)&1,v0=v&1; + x^=t1^v0^(u0|u1)^((t0^u1^v0)&(t0^u0)); + if(t0==u0){v>>=1;if(v0)v^=0xb3d0;} + if(!t0){u>>=1;if(u0)u^=0xfb10;} + t>>=1;if(t0)t^=0xa740; + acc=(acc<<1)|x; + } + bytes[at]^=(uint8_t)acc; + } +} + +// CRC-32 over decoded [0x100, 0x200000), checked against the same three private +// reference revisions used for SDK validation. Unknown is not proof of damage: +// other legitimate revisions are not represented in this small diagnostic map. +// These fingerprints contain no firmware or resources. +static const char *ipl_profile(uint32_t crc) +{ + switch(crc){ + case 0x8f87bdb8:return "NTSC10"; + case 0xf4fa4503:return "NTSC12"; + case 0x23072730:return "PAL12"; + default:return "UNKNOWN"; + } +} + +// Signature counts are diagnostic hints, not validation or SDK acceptance. +static unsigned ipl_yay0_count(const uint8_t *bytes) +{ + unsigned count=0; + for(unsigned at=0x100;at+4<=IPL_CIPHER_END;at++) + if(!memcmp(bytes+at,"Yay0",4))count++; + return count; +} +#endif diff --git a/tools/ipl-diagnostics/ipl_probe.c b/tools/ipl-diagnostics/ipl_probe.c new file mode 100644 index 0000000..550240b --- /dev/null +++ b/tools/ipl-diagnostics/ipl_probe.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include "dnd_console.h" +#include "dnd_graphics.h" +#include "dnd_platform.h" +#include "dnd_system_firmware.h" +#include "ipl_analysis.h" + +#ifndef IPL_DIAG_SDK_VERSION +#define IPL_DIAG_SDK_VERSION "UNKNOWN" +#endif +static uint8_t rom[IPL_BYTES] ATTRIBUTE_ALIGN(32); +// DMA storage has static lifetime, including every timeout/error path. +static uint8_t page[1024] ATTRIBUTE_ALIGN(32); +static char results[5][79]; +static char revision[79]="HEADER UNAVAILABLE"; +static const char *labels[]={"SDK32","DMA32","IMM16","DMA16","AGAIN"}; + +static void frame(void) +{ + dnd_graphics_begin_frame(.025f,.035f,.06f,1); + dnd_graphics_begin_overlay();dnd_console_render();dnd_graphics_end_frame(); +} +static uint64_t now_us(void){return ticks_to_microsecs(gettime());} +static void reg_write(unsigned reg,uint32_t value) +{ + ((volatile uint32_t*)0xcc006800)[reg]=value; + __asm__ volatile("eieio" ::: "memory"); +} +static uint32_t reg_read(unsigned reg){return ((volatile uint32_t*)0xcc006800)[reg];} +static int wait_transfer(uint64_t deadline) +{ + for(unsigned polls=0;polls<1000000;polls++){ + if(!(reg_read(3)&1))return 1; + if(now_us()>=deadline)return 0; + } + return 0; +} + +// Bounded equivalents of libogc's ROM transaction, comparing DMA and immediate +// reads. Never call __SYS_ReadROM: its retry loop has no deadline. +static int alternate_page(unsigned offset,int dma,int speed) +{ + if(!EXI_Lock(EXI_CHANNEL_0,EXI_DEVICE_1,NULL))return -1; + int selected=0,result=-2; + uint64_t deadline=now_us()+20000; + if(!EXI_Select(EXI_CHANNEL_0,EXI_DEVICE_1,speed)){result=-1;goto cleanup;} + selected=1; + reg_write(4,offset<<6);reg_write(3,0x35); + if(!wait_transfer(deadline))goto cleanup; + if(dma){ + DCInvalidateRange(page,sizeof(page)); + reg_write(1,(uint32_t)MEM_VIRTUAL_TO_PHYSICAL(page)); + reg_write(2,sizeof(page));reg_write(3,3); + if(!wait_transfer(deadline))goto cleanup; + __asm__ volatile("sync" ::: "memory"); + }else{ + for(unsigned at=0;at>24;page[at+1]=value>>16; + page[at+2]=value>>8;page[at+3]=value; + } + } + result=sizeof(page); +cleanup: + if(selected){ + if(result<0)reg_write(3,0); + if(!EXI_Deselect(EXI_CHANNEL_0)&&result>=0)result=-1; + } + EXI_Unlock(EXI_CHANNEL_0); + return result; +} + +static void read_mode(unsigned mode) +{ + char text[79]; + snprintf(text,sizeof(text),"READING %s - PLEASE WAIT",labels[mode]); + dnd_console_write_line(text);frame(); + unsigned quantum=(mode==0||mode==4)?4096:1024; + for(unsigned at=0;at52?end-52:0; + unsigned i=0; + for(;start+i=32&&c<127?(char)c:' '; + } + revision[i]=0; + } + } + uint32_t raw=ipl_crc32(rom,IPL_BYTES),plain=ipl_crc32(rom+0x100,IPL_BYTES-0x100); + unsigned before=ipl_yay0_count(rom); + const char *profile=ipl_profile(plain);char encoding='P'; + ipl_descramble(rom); + uint32_t decoded=ipl_crc32(rom+0x100,IPL_BYTES-0x100); + unsigned after=ipl_yay0_count(rom); + if(!strcmp(profile,"UNKNOWN")){profile=ipl_profile(decoded);encoding='S';} + if(!strcmp(profile,"UNKNOWN"))encoding='?'; + snprintf(results[mode],sizeof(results[mode]),"%-5s %08X %08X %02u/%02u %s/%c",labels[mode],raw,decoded,before,after,profile,encoding); + // No raw bytes or extracted assets are displayed, persisted or sent. + memset(rom,0,sizeof(rom));memset(page,0,sizeof(page)); +} + +void dnd_ipl_probe_run(intptr_t cipher_result) +{ + dnd_console_set_visible(1); + for(unsigned mode=0;mode<5;mode++)read_mode(mode); + dnd_console_init(); + char text[79]; + snprintf(text,sizeof(text),"IPL CHECK 01 - SDK %s - CIPHER %s %ld",IPL_DIAG_SDK_VERSION,cipher_result?"FAIL":"PASS",(long)cipher_result); + dnd_console_write_line(text); + dnd_console_write_line(revision); + dnd_console_write_line("MODE ROM CRC XOR CRC YAY P/S PROFILE"); + for(unsigned mode=0;mode<5;mode++)dnd_console_write_line(results[mode]); + dnd_console_write_line("P PLAIN S SCRAMBLED ? UNKNOWN - START EXIT"); + dnd_platform_wait_forever(); +}