Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nanochess/raytracer
Ray Tracer in 484 bytes (x86 boot sector)
https://github.com/nanochess/raytracer
Last synced: 2 days ago
JSON representation
Ray Tracer in 484 bytes (x86 boot sector)
- Host: GitHub
- URL: https://github.com/nanochess/raytracer
- Owner: nanochess
- License: other
- Created: 2024-04-12T16:19:06.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-04-13T17:20:41.000Z (7 months ago)
- Last Synced: 2024-04-14T13:16:07.340Z (7 months ago)
- Language: Assembly
- Homepage: https://nanochess.org/
- Size: 1.15 MB
- Stars: 151
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ray Tracer in a boot sector
*by Oscar Toledo G. Apr/12/2024*
http://nanochess.org
https://github.com/nanochess
### What is this?
This is a port of the amazing Ray Tracer in Atari 8-bit BASIC by D. Scott Williamson. You can see it at [https://bunsen.itch.io/raytrace-movie-atari-8bit-by-d-scott-williamson](https://bunsen.itch.io/raytrace-movie-atari-8bit-by-d-scott-williamson)
This was based on a static BBC micro version by [@coprolite9000](https://mastodon.social/@[email protected]) (see [https://bbcmic.ro/?t=9ctpk](https://bbcmic.ro/?t=9ctpk)) that was based on [@kweepa](https://twitter.com/Kweepa)'s original one (see [whole X thread](https://x.com/bbcmicrobot/status/1322988586828849152)), however at this point it looks like the program cannot be decoded back.
I asked Williamson for permission to make a port to a boot sector, and here it is. I was running around 590 bytes until I found a duplicated calculation that could be made into a subroutine. The code isn't exactly the same because I changed some constants to adapt it, and also collapsed some to save bytes. Anyway, I'm pretty happy I finally found good use for the VGA palette!
If you are going to run it in real hardware it requires a minimum of a Pentium Pro, otherwise most modern emulators will be able to run it.
One of the biggest surprises is how so fast are modern computers so technically the animation is real-time in my Macbook Air running the ray tracer in Windows XP under VirtualBox. You can see it on [Youtube](https://www.youtube.com/watch?v=AZdzECF2Huw).
![Ray tracer in a boot sector animation](RayTracer_animated.gif)
### How to use it.
If you want to assemble it, you must download the Netwide Assembler (NASM) from www.nasm.us
Use this command line:
nasm -f bin ray.asm -Dcom_file=1 -o ray.com
nasm -f bin ray.asm -Dcom_file=0 -o ray.imgTested with VirtualBox for macOS running Windows XP and also executing directly the bootsector. For QEMU, recommended run with KVM (Linux) or Hyper-V (Windows) accelerator for better performance:
Run with KVM:
qemu-system-x86_64 -machine accel=kvm ray.img
Run with Hyper-V:
qemu-system-x86_64 -machine accel=whpx ray.img
Run without accelerator (TCG):
qemu-system-x86_64 ray.img
Because DOSBox-X runs very slowly, I further tested with VirtualBox over Windows 11 (Asus TUF F17), created a Windows XP 32-bit machine (you don't need to install Windows nor a hard disk image), in Configuration/Storage in the bottom there is a icon saying "Add controller", choose I82078 (floppy), then click "Add floppy drive", and select the boot sector as image (ray.img).
![Ray tracer in a boot sector](RayTracer.png)
## Acknowledgments
Thanks to Peter Ferrie for helping me to save 23 bytes (my original program was 506 bytes, now it is 483 bytes).
Thanks to birdie-github for contributing the animated GIF of the ray tracer.
Thanks to SuperMaxusa for contributing the Qemu acceleration notes.
Do you want to learn 8086/8088 assembler? Get my books Programming Boot Sector Games containing an 8086/8088 crash course! Also available More Boot Sector Games. Now available from Lulu and Amazon!