Interactive Raycaster For the Commodore 64 Under 256 Bytes
New submitter Wisdom writes "1bir (1 Block Interactive Raycaster) is a simple ray casting engine implemented only in 254 bytes to run on a stock, unexpanded Commodore 64. The name comes from the fact that on a C64 floppy disk, 1 block is equivalent to 254 bytes stored on a disk sector. In 254 bytes, 1bir sets up the screen for drawing, creates sine and cosine tables for 256 brads based on a simple approximation, casts rays into a 2D map that lives inside the C64 KERNAL ROM, renders the screen in coordination with KERNAL, evaluates 8-way joystick input and detects collision against walls. The ray casting core employs a brute force algorithm to determine visible walls, while the mapping portion supports both open-ended (infinitely looped) and traditional, closed maps. The source code in 6502 assembly is available, with extensive comments. A YouTube video showcases 1bir in a detailed manner with both kind of maps and more information, while a Vimeo video presents a shorter demonstration."
The c=64 ain't dead yet ??
I work with a health IT company that's trying to give doctors better tools to solve and treat disease. Our project could improve the lives of lots of folks, and its quite difficult to find talented technical folks to join the team.
I appreciate this is a cool hobby project, I just wish the guy would use his not inconsiderable talents to work on something that has a more obvious real-world payoff (unless this is all a hologram running on 4x10^16 Commadore 64s).
Good thing it only took him 30 years of development to come up with this. Had the software been around when I used a C64 (when they were the state of the art) I would probably still be looping around inside those maps.
Yew hearte me! Mods, yes!
The source code is zipped. For a 254 byte program. This just tickles me for some reason.
It's not news but it's a story about technology!
The vimeo link leads to this article.
It is nice to see that in this world of plenty (at least as far as system memory and CPU speed goes) some people find joy in efficiency; and they go so far as to pull something like that off, just for the fun of it. Needless to say, the dude that did this is a real programmer.
Dunno if the link was bad for anyone else, but here's the actual vimeo link.
The next time you churn your next 500MB printer driver think about programs like this. Think long and hard.
It's interesting to note that the code uses two "undocumented" 6510 instructions:
These instructions are undefined; they work by taking advantage of the internal CPU architecture to execute a hybrid of other legal opcodes. A lot of other older processors have such behavior, such as the Z80. Even the 8086 had a bit of this: "pop cs" and the second encoding of "sar" come to mind. (The 8086's "pop cs" was stolen by the 286 to mean an escape to a second opcode page.)
"Screw Sun, cross-platform will never work. Let's move on and steal the Java language." - Visual J++ Product Manager
The Vimeo link in the story somehow became broken, the correct link is as follows:
http://vimeo.com/66004524
Shit. I meant "thou" not "though"... damn muscle memory.
Projects like this are a great way to train new engineers for small embedded systems. There is a lot of work out there on 8-bit systems with a couple k of program space and a few hundred bytes of ram. At my place we actively collect books that targeted advanced computer programming techniques in the early 80's, because they line up good with the resources we typically have on a microcontroller that costs $1.27 now .
For example, given a 128x96 black and white LCD, create an algorithm that will draw a line between any two points. Oh, and you can only use integer math, and we'd prefer it if you kept division operations to a minimum, because we have to do division through a software library call...
The old-timers did that stuff in their spare time 30 years ago.
This reminds me of a raycaster for the NES. http://www.youtube.com/watch?v=po69zgqyFWM
It works on real hardware too. Sadly, not under 256 bytes though.
Wow... perhaps there is some hope for Doom 2600 after all...
and the second encoding of "sar" come to mind
Sorry, but it's "SHL" that has a duplicate encoding on x86. There are four slots for non-rotating shift instructions in "group 2": 4=SHL, 5=SHR, 6=???, 7=SAR. The /6 variant looks like it ought to be "SAL", and it is. However, unsigned left shifting is equivalent to signed left shifting, and thus the two opcodes end up doing the same thing. The original 8086 happy processed this instruction as a signed left shift because of how it interpreted the opcode bits, but that's the same as an unsigned left shift.
This was retained in modern processors, whereas "pop cs" was not.
"Screw Sun, cross-platform will never work. Let's move on and steal the Java language." - Visual J++ Product Manager
I knew it would happen. My C64 just became immensely valuable, right?
right?
Will this run on my VIC-20?
Otherwise, meh.
"I believe in Karma. That means I can do bad things to people all day long and I assume they deserve it." : Dogbert
My 6502 is not completely lost.
Here is how to optimize the code a little bit:
Replace:
with:
This saves 2 bytes and a few cycles.
Amazing how a bunch of internet lamers can turn such an awesome small piece of code, and accompanying story... into a tl;dr thread about postscript printer drivers and complain about how old the 64 is. As for the vic20... source is there, port it.
I don't want to live on this planet anymore.
This was done a decade ago for the Color Computer (6809). A self-modifying 3d engine in ~256 bytes was turned into a full "doom" style 3d game.
http://members.optusnet.com.au/nickma/ProjectArchive/crasher.html
With video!
https://www.youtube.com/watch?v=jVFn_djQ6EY
I got a kick out of the use of bytes already in ROM as the map. I did something similar for an old DOS game of mine, Tunneler, where I used bytes taken from IBM PC ROM to replace the player's usual game view with a TV static/snow effect (simulated loss of signal). I grabbed bytes from an address in ROM that resulted in random-looking values interspersed with a few horizontal streaks. Know of any other games that made unusual use of ROM data?
254 bytes? that sounds like black magic:)
r a f t
Having seen so many killer C-64 demo vids on YouTube, my expectations for this demo were much higher. I regard it as a PoC. Let's see what they can do when they throw some sprites in there with raster interrupts to display more than 8. Get the perspective for the sprites in that LUT, throw some SID music on top, and really blow us away!
No disrespect. Mad respect actually, from somebody who played with the C-64 back in the day and never got that far. If you don't believe me, search YouTube and prepare to have your mind absolutely blown.
bir means 1 in Turkish. Kudos to the guy who named so this program.
Awesome! If only we could teleport today's knowledge back to 1983! =)
I had been looking for a small demo to include with our Android .TAP-file renderer https://play.google.com/store/apps/details?id=co.kica.tapdancer, and this will be perfect! (Assuming it's free to distribute -- demos usually are but I'm attempting to clarify this...)
This uses a C64 font among others for generating captchas
I wish I had kept all of that old stuff through moves and... life :)
My karma is bad because I'm a bad person.
I own HP printers and scanners, I know what I am saying is a fact. HP printer drivers are still stupidly oversized. If you're using a real printer that speaks a real language you don't even need a driver, just the PPD, and that is actually provided for some models. But for their more primitive printers (like personal laserwriters, which for the most part don't even speak PCL) you need to download a massive driver that probably won't work on the next version of Windows. I've owned several HP printers specifically because the prior owners could no longer use them due to an OS upgrade.
Nice to see there's an HP shill here, though. I wouldn't have thought they could afford them any longer.
"You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
640k would still be enough for everyone.
In all fairness, here's the best the Commies have to offer:
M.O.O.D.
http://www.youtube.com/watch?v=X3Oqz5WjDPI
And here's the Atarians best attempt at a Wolfenstein 3D clone:
Project-M
http://www.youtube.com/watch?v=Z3-J2-VeoH8
You be the judge.
Daniel Klugh