Slashdot Mirror


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."

46 of 143 comments (clear)

  1. Re:Real-work problem? by Deltaspectre · · Score: 5, Insightful

    Don't underestimate the productivity of being able to work on a hobby project you enjoy

    --
    My UID is prime... is yours?
  2. (oblig) Better late than never by jeffmeden · · Score: 3, Funny

    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.

    1. Re:(oblig) Better late than never by cold+fjord · · Score: 4, Interesting

      Had the software been around when I used a C64 (when they were the state of the art) . .

      What do you mean? C64 still is state of the art . . . for 1982.

      On the other hand, a clever hack borders on being timeless - for example and inspiration if nothing else.

      Certainly in a time of ever greater bloatware it can border on mind-blowing to consider what people used to do, and some still do, in handfuls or hundreds of bytes: The Puzzle

      Visual Transistor-level Simulation of the 6502 CPU

      --
      much of left-wing thought is a kind of playing with fire by people who don't even know that fire is hot - George Orwell
  3. Re:Real-work problem? by gl4ss · · Score: 5, Insightful

    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).

    I got an idea.Pay him to do it. Your company works for money.

    You wouldn't be working for one of the two dozen firms doing mobile apps for connecting doctors to patients, looking for funding, explaining how you work "with" and not "for"?

    --
    world was created 5 seconds before this post as it is.
  4. Zip? by ZahrGnosis · · Score: 5, Funny

    The source code is zipped. For a 254 byte program. This just tickles me for some reason.

    1. Re:Zip? by jeffmeden · · Score: 4, Funny

      The source code is zipped. For a 254 byte program. This just tickles me for some reason.

      When you have a 300 baud modem on your C64 and Delphi Online charges by the minute, every last byte adds up!

    2. Re:Zip? by tgd · · Score: 4, Interesting

      The source code is zipped. For a 254 byte program. This just tickles me for some reason.

      When you have a 300 baud modem on your C64 and Delphi Online charges by the minute, every last byte adds up!

      The funny thing is, back then the handy thing about 300 baud was there was no need to pipe things to more -- you could just cat a file and read it as it downloaded ...

      Stupid 1200 baud modems messed that all up ...

    3. Re:Zip? by jandrese · · Score: 2

      The worst part is that zip actually increased the size of the programs by a few bytes. It was counterproductive here, although it did help shrink that relatively gigantic disk image.

      --

      I read the internet for the articles.
    4. Re:Zip? by bill_mcgonigle · · Score: 2

      And the lameness filter prevents it from being posted here. Aptly named.

      --
      My God, it's Full of Source!
      OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
    5. Re:Zip? by greg1104 · · Score: 2

      The worst part is that zip actually increased the size of the programs by a few bytes.

      Of course it did. If it was possible to compress the program usefully and distribute a smaller version, he would have done that too!

    6. Re:Zip? by Trax3001BBS · · Score: 2

      The worst part is that zip actually increased the size of the programs by a few bytes. It was counterproductive here, although it did help shrink that relatively gigantic disk image.

      I thought no way, I had to see for myself. The zipped file crescent-1bir-src.zip is 8K, the three file files
      the zip contains add up to 25K so 1/3 it's original size. Your thinking of graphics files.

      If a file is already compressed (ie: graphics, zip) they can't get any smaller, another compression program
      will only increase it's size. Source code is text only and very compressible; all of your modem compression
      schemes to increase speeds are based on text only.

      The JSTOR files Aaron Swartz uploaded were 36 Gigs, uncompressed it was huge > 100 gig, as they were mostly in the text format.

      There are graphic formats that aren't compressed like .BMP files that will zip down to almost half it's size.
      You find graphics compressed with zip, arc, zoo what have you are to create a single file (while increasing it's size).
      To use a compression scheme on the hard drive you store your pr0n collection on, now that is counterproductive.

  5. kudos by excelsior_gr · · Score: 5, Informative

    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.

    1. Re:kudos by narcc · · Score: 2

      I was hoping for the story of Mel, a real programmer.

      On the article, it's fantastic. It puts me in mind of First & Third almost FORTH and the recent Fixing E.T. hack.

  6. Vimeo, Vimeo, wherefore art though, Vimeo? by Anonymous Coward · · Score: 4, Informative

    Dunno if the link was bad for anyone else, but here's the actual vimeo link.

    1. Re:Vimeo, Vimeo, wherefore art though, Vimeo? by innocent_white_lamb · · Score: 2
      --
      If you're a zombie and you know it, bite your friend!
  7. HP Printer Driver Developers Take Note by parlancex · · Score: 5, Insightful

    The next time you churn your next 500MB printer driver think about programs like this. Think long and hard.

    1. Re:HP Printer Driver Developers Take Note by Solandri · · Score: 4, Informative

      The printer driver itself wasn't 500 MB. What happened was that some manager at HP decided tech support was wasting too much time (money) instructing people on how to navigate their byzantine support website to find and download the correct drivers for their printer. So they glommed the drivers for all of their printers into one big binary and told people to just download that.

      IMHO the real lesson from the HP printer drive fiasco is that if it's quicker and easier to find something on your website by doing a Google search for it, you need to redesign your website. HP eventually did that, and their site now lets you just type the printer's name and it'll take you directly to its download page.

    2. Re:HP Printer Driver Developers Take Note by parlancex · · Score: 2

      Then you should be impressed. If you seriously are a developer who writes printer software for HP you are bad and you should feel bad.

  8. Uses two undocumented / illegal instructions by Myria · · Score: 5, Interesting

    It's interesting to note that the code uses two "undocumented" 6510 instructions:

    lax $91
    anc #$00 ; clears carry for sinadd below

    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
    1. Re:Uses two undocumented / illegal instructions by Wisdom · · Score: 2

      The alternative version (1bir-alt.prg/s) uses no illegal opcodes at all. :-)

  9. Correct link for Vimeo video by Wisdom · · Score: 2

    The Vimeo link in the story somehow became broken, the correct link is as follows:

    http://vimeo.com/66004524

  10. Re:Real-work problem? by Anonymous Coward · · Score: 5, Funny

    I work with an advanced robotics research firm that's trying to take humans out of fragile, disease-ridden bodies and put them in immortal robot bodies. Our project would allow humanity to transcend mortal existence, and it's quite difficult to find talented technical folks to join the team.

    I appreciate your cool hobby project, I just wish you would use your not inconsiderable talents to work on something that has a more obvious long-term payoff.

  11. Re:Real-work problem? by Samantha+Wright · · Score: 4, Interesting

    As a bioinformatician who's trying to give researchers better tools to identify disease, whose projects could also improve the lives of lots of folks: this is not that kind of programming. Demoscene programmers are generally hired by graphics companies and embedded systems development, where their formidable optimization abilities actually get put to use; those skills are not transferable to general high-performance computing. You'll have to keep hiring out of the general CS grad pool.

    --
    Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  12. Re:Real-work problem? by Tridus · · Score: 5, Insightful

    Can't find talented technical folks to join the team, or can't find talented technical folks to join the team for well below market wages?

    Usually when people say one, they really mean the other.

    --
    -- "So they told me that using the download page to download something was not something they anticipated." - Bill Gates
  13. Good Training for embedded systems by localman57 · · Score: 3, Insightful

    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.

    1. Re:Good Training for embedded systems by Citizen+of+Earth · · Score: 2

      No need to create one.

    2. Re:Good Training for embedded systems by greg1104 · · Score: 2

      Line drawing can have a lot of complexity to it beyond just picking the best of the usual approaches. A simple implemtnation of Bresenham's line algorithm may or may not be optimal given the system's other constraints. One common change is to recognize that horizontal and vertical lines are both common enough that they should get their own optimized code paths. If it's possible the code might run on a grey scale display one day, you might code in a way that later allows anti-aliasing. On a computer like the Apple ][, the odd mapping of video memory to the display can favor lookup table driven approaches. And on systems where the code has to run at a consistent speed on each loop to maintain vertical sync like the Atari 2600, you'll have to carefully modify the Bresenham approach, since the d>0 path has more computations than the other side. Those are just a few of the possibilities I remember from my 6502 coding days.

  14. Re:Real-work problem? by gr8_phk · · Score: 5, Insightful

    As a bioinformatician who's trying to give researchers better tools to identify disease, whose projects could also improve the lives of lots of folks: this is not that kind of programming. Demoscene programmers are generally hired by graphics companies and embedded systems development, where their formidable optimization abilities actually get put to use; those skills are not transferable to general high-performance computing.

    Actually the skills do transfer. The techniques of code optimization are many and universal. Which ones constitute acceptable use depends on the application (i.e. mathematical approximations are not always OK). From what I keep reading, HPC focuses a lot on matrix math - an area where some tricks can help a lot without affecting the results. I was manipulating 1GB 3d data sets interactively on a machine with 128M of RAM back in the day, and I suspect the technique has not gone mainstream yet.

  15. Re:Real-work problem? by localman57 · · Score: 2

    I work with a health IT company that's trying to give doctors better tools to solve and treat disease.

    That's cool. I'm between jobs right now, so I have a lot of time on my hands. But the bright side is that just a few dollars from my unemployment check will buy a whole bunch of eggs, so I'm cool.

    Say, why don't you tell me where you live, and I'll come over and we'll talk about that disease treating thingie you're interested in.

  16. Re:Real-work problem? by shreak · · Score: 2

    Hang on there. Why are you using your talents on a project that may save 1000s when you could be working in vaccination projects that could save 10s of 1000s? Wait! Forget that. You and those time wasting vaccination workers should be focused on biotechnology that could create crops to feed millions world wide!

    Hold it! Scratch that. Global warming will end up destroying the entire planet. Get those lay-about biotech-crop workers on that!

    Wait! Heat death of the universe. Only billions of years away and effects EVERYTHING. Stop wasting time on trivial projects and solve the most important problem in the universe! /thread

  17. Re:Bad link in summary by Solandri · · Score: 4, Funny

    Recursion is the key to generating small op code.

  18. Correcting myself by Myria · · Score: 3, Insightful

    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
  19. Re:Real-work problem? by Beorytis · · Score: 5, Insightful

    Do you visit model railroad clubs and chastise them for playing with toys when there's so much real freight to be moved?

  20. Re:OMFG !! by LocalH · · Score: 4, Insightful

    The C64 is worthy of fun.

    --
    FC Closer
  21. Will this run . . . by hduff · · Score: 3, Funny

    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
    1. Re:Will this run . . . by Wisdom · · Score: 5, Interesting

      It is quite possible that it will run on VIC20, but it will probably need some modification to the actual render code (I do not have a VIC20, so I am not sure). Other than that, it should work, as RAM usage is minimal (just needs 320 bytes for sine/cosine tables, ZeroPage and the 1K video RAM).

      Nevertheless, I will include it in the next release. Thanks for the idea.

  22. Re:Real-work problem? by Wycliffe · · Score: 2

    How do you even know what he is using his talents for at his day job? This type of project is
    fun, allows a programmers to relax, reduce stress, and unwind but also allows them to hone
    their skills so that there actually are "talented technical folks" for you to hire. I have yet to
    meet a great programmer that doesn't do this sort of thing in their spare time and therefore
    I honestly believe that eliminating this sort of behavior would actually reduce your ability to
    hire qualified candidates.

  23. Optimization by eulernet · · Score: 4, Interesting

    My 6502 is not completely lost.
    Here is how to optimize the code a little bit:

    Replace:

    loop_stepadd
                            lda stepx,x ; & y
                            ora #$7f ; sign extend 8 bit step value to 16 bit
                            bmi *+4
                            lda #$00
                            pha ;clc
                            lda stepx,x ; & y
                            adc rayposx,x ; & y
                            sta rayposx,x ; & y
                            pla

    with:

    loop_stepadd ;clc
                            lda stepx,x ; & y
                            adc rayposx,x ; & y
                            sta rayposx,x ; & y
                            lda stepx,x ; & y
                            ora #$7f ; sign extend 8 bit step value to 16 bit
                            bmi *+4
                            lda #$00

    This saves 2 bytes and a few cycles.

    1. Re:Optimization by Wisdom · · Score: 4, Funny

      Well spotted, I missed that one out. :-) Usual problem of looking at the same thing for so long, now it perplexes me how I missed such an easy one. :-)

    2. Re:Optimization by eulernet · · Score: 4, Interesting

      Well, it was not obvious.

      I originally wanted to optimize the sign extend using some carry tricks, like asl/lda #0/sbc #0, but realized that it was unnecessary.
      In fact, you can improve it even more, as follows:

      lda stepx,x ; & y
                              bpl *+4
                              dec rayposxh,x
                              adc rayposx,x
                              sta rayposx,x
                              bcc *+4
                              inc rayposxh,x

      Saving 6 bytes !

      This trick is mentioned here:
      http://forum.6502.org/viewtopic.php?p=5262

      BTW, your tsx/txs trick is really horrible, it forces the stack at the bottom of $100.

  24. Or, 2MHz 6809 with full 3d Game by Anonymous Coward · · Score: 2, Interesting

    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

  25. Re:Real-work problem? by Samantha+Wright · · Score: 2

    Which ones constitute acceptable use [...]

    And that's the trick. These people focus predominantly on mathematical approximations, extreme memory limitations, and knowing the ins-and-outs of the CPU itself, or the API they're using if it's a PC demo. All C64 demos are programmed in assembly. So while optimization is common to both fields, the level of detail is much too tight. In demo programming, effects are chosen because they optimize well. That doesn't fit with matrix programming or stats where accurately capturing an algorithm is the top priority—not just because mathematical approximations are undesirable, but because the complexity of many processes is the major bottleneck, and the operations themselves are simple and cannot be optimized through cheating.

    Even if a demoscener did, for example, rewrite BLAST, the result would be completely unmaintainable, which is no good to anyone. It's much better to leave the optimization of scientific software to the compiler.

    --
    Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  26. Re:Other creative uses of ROM data? by Hatta · · Score: 2

    Yars Revenge used its own game code as pseudorandom data to animate the neutral zone.

    --
    Give me Classic Slashdot or give me death!
  27. Re:My expectations were too high by Wisdom · · Score: 2

    Next version is coming up soon, with more features than you actually mentioned in your post. :-) (It will not be under 256 bytes, though). This was, as you said, made to prove that it can be done under 256 bytes. Therefore, the size limit does not really allow to add many more features than there are now (although it is still possible to add small improvements here and there, of course). Lastly, this does not utilize any LUT, except for the usual sine/cosine tables.

  28. Re: Real-work problem? by briancox2 · · Score: 4, Insightful

    Yeah. I'm also tired of self-righteous people claiming we shouldn't have fun because, somewhere there's a person with a need. Life isn't about sacrificing all your interests to the need of others. Even Jesus let his feet get washed from time to time.

    --
    We should learn what we need to know about issues, before we decide what we need to feel about them.
  29. Re:Real-work problem? by Samantha+Wright · · Score: 2

    Up to a point, I agree with you—I've even implemented some optimizations of Smith-Waterman myself, so I know how bad it can get. The thing is, to fully maximize the kinds of cheating that you typically see in demos, you usually have to sacrifice the flexibility of the algorithm itself. A lot of the genius in low-power C64 and Amiga demos comes from precalculating data and constraining the perspectives from which the image on screen is shown; they're illusions. While a demoscene programmer may be excellent at core optimization tasks, these abilities in particular would be go unused. (Metaphors about cutting raw meat with a bread knife come to mind.) It would be better to look for someone more dedicated to the job, especially if they have experience with parallel processing and high-performance computing.

    Of course, that's not to say there aren't individuals interested in all three categories—graphics tricks, code optimization, and high-performance computing—but the aptitudes aren't correlated. Demosceners are motivated by a strong sense of community, the audacity of their medium, and the gratification of seeing their work in action (see documentary), which doesn't jive well with what computational biology offers.

    ...that being said, I'm a computational biologist, I'm pretty fond of the demoscene, and I hate BLAST; where do I sign? :)

    --
    Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!