http://deater.net/weave/vmwprod/second/ A Version of Future Crew's Second Reality for Apple II [sr_title] --------------------------------------------------------------------- Details Second Reality, the famous MS-DOS demo, but on an Apple II... Finished first place in the Retro Demo category at Demosplash 2023 --------------------------------------------------------------------- Videos Video capture from an actual Apple IIe: --------------------------------------------------------------------- System Requirements * An Apple IIe / IIc / IIgs with Mockingboard sound card and 128k total RAM * Note: the IIe and above requirement is because I use the extra RAM as a ramdisk, it's not using any other IIe features. --------------------------------------------------------------------- Downloads Disk Images * You will need both disk images. This is version 1.2 (12 November 2023) + second_d1.dsk (140k) + second_d2.dsk (140k) * You can get the original party release here: a2_reality.zip * If you don't have real hardware it should work in emulators. Applewin (be sure to enable mockingboard sound support) and MAME both tested. * Try it on the in-browser emulator at archive.org: disk1, disk2 Source * You can find it in the full git repository here: You'll need cc65 to build it. https://github.com/deater/dos33fsprogs/demos/second --------------------------------------------------------------------- You can vote for this on pouet (you'll see the crew there aren't big fans): Apple ][ Reality --------------------------------------------------------------------- Mini-faq * Q. I thought you said you weren't going to do this? A. I say a lot of things. * Q. Did you experience Second Reality back in the 90s? A. Yes, it managed to even find its way to my middle-of-nowhere part of the US. I saw it a few times, generally people downloading from a BBS and showing it off on their top-of-the-line 486 systems with sound cards. (I specifically remember a friend's high-end 486 system, he even had a double-speed CD-ROM drive he bought solely so they could play Wing Commander) I don't think I was that impressed, I mean it was sort of cool but also weird. Remember that a lot of the allure of the demo was "Wow, look, a PC can do Amiga effects" but I had never seen an Amiga so that didn't really grab me. * Q. Did you use graphics resources from the original demo? A. No. A lot of the graphics are actually hard-coded into the binaries and not separate files. The few standalone files are Deluxe-paint LBM files which are hard to work with these days. In the end I just used screen grabs from a youtube video of the demo. * Q. Did you use any code from the original demo? A. No. The original demo is doing a lot of really obscure x86 / VGA tricks which really don't map well to a 6502. * Q. Are you the first person to demake this demo? A. No, famously there was a version made for the Commodore 64 back in 1997. There's also an Atari ST version. And a Gameboy Color version. * Q. It looks like this demo only has a few actual effects and the rest are trickery or fakes? A. I guess that's one way of looking at it. The Apple II is so limited that even the trickery and fakes can be a significant amount of work. The "fake" 3d-rendered animation before the credits is indeed "just" a movie, but it's a minute long full-color movie rendered at 4fps in only 24k of RAM. * Q. Aren't Second Reality re-makes overdone? A. I'll admit that I feel that way too. At the same time, I have a lot of working Apple II machines I can run this on, while my old 486 from the 90s hasn't booted for years (also my 486 back in the day ran exclusively Linux, it never ran DOS while I owned it) * Q. This platform is too awful, you shouldn't have bothered A. Remember the Apple II graphics were designed in 1977. You should be comparing this to what would run on Commodore PET or TRS-80. This introduces some new effects that have never been done before on Apple II as far as I know (like full-screen Hi-res plasma). This is why I submitted this to an American demoparty, as it's more likely they'll have appreciation for the limitations of the platform. I'd like to think the results for some scenes compare favorably with the Commodore 64 version of Second Reality (though I realize the state of the art in C64 effects has improved a bit since 1997). Also note, Apple II graphics released 1977, C64 graphics 1982, VGA released 1987. * Q. Isn't it cheating to use a Mockingboard sound card? Weren't they somewhat rare? A. If you want to listen to demos with only beeper music (and remember, it's bitbanged, there's no helper hardware or timers to drive the speaker) then you're going to be disappointed in the sound quality possible on this platform. For a lot of Apple II software any music you got was appreciated because it was there at all, not because it was of amazing quality. The Mockingboard was popular enough that a few games supported it back in the day. I feel fine using is because while my family didn't have one, the kid across the street from us did and I saw it in action at his house. I could in similar fashion ask why it's fair for DOS demos (especially ones targeting early hardware) to have a soundblaster. My family's 386 didn't come with a sound card, and only after years of bugging my family, saving up, and buying a cheap knockoff clone at a computer/hamfest did we finally get one. When I went to college and got my own used 486 I soldered together a parallel port resistor-ladder DAC card to use for sound until I could scrounge up enough money for a real sound card. * Q. Do you plan to release a final version with fixes over the party version? A. I was thinking about it, but I managed to cram a lot of coding into the last few days before the deadline and implemented most of what I wanted to. Some things that could use improvement: better sound sync (especially the intro), better credits music, page-flipping during the scrolling, a proper tunnel effect, more frames in the cube rotozoom, proper falling chessboard animation, actual 3d polygon, complete the full 3d animation sequence, proper bounce effect for the polar bear lady picture. It might also be nice to do more accurate interference effect, though I always found that part to be tedious in the original. I guess also do a proper wrapped rotozoom rather than filling the edges with a solid color. And maybe fix the scrolling (or lack there of) issues during the thumbnail parts of the credits. Oh yeah maybe a proper lens effect. I also have graphics for a hi-res version of the transmission theme, but doing diagonal sprites in hi-res would be a huge pain. So in the end I guess there are a lot of improvements I could do. * Q. Can you reduce the memory usage to 64k? A. Yes, I'd actually like to run this on my Apple II+ with language card. It should be possible but might involve having to pause the music at times to do the disk reads. * Q. Can you make a version that doesn't require a Mockingboard? A. This would be trickier. I use the music interrupts for timing. Places that just busy wait we can replace with a CPU loop. However a lot of the timing is designed to sync up with certain locations in the music, we wait until the music code hits a certain pattern location. In theory we could fake something up and have all loops increment the FRAME count and do things based on that, but I'd essentially have to intrusively add this code everywhere and it would be a huge pain. * Q. I think the whole thing looks ugly and lazy A. Maybe. Like a lot of my retro projects, this started as a joke that got out of hand. Then I ended up spending 2 months working on it, which is a lot considering I don't even like Second Reality that much. Then finally, in typical demoscene fashion, the deadline was a week away so I worked late hours slapping together whatever effects I could manage and just barely got something reasonable together minutes before the deadline. The thing is even if I spent another few months perfecting the "transmission" scene, or doing a proper tunnel effect, I still don't think there'd be any less complaining so why would I bother. --------------------------------------------------------------------- Platform Notes Apple II limitations I'm sure I have long detailed explanations of the Apple II limitations elsewhere on this site, but a quick refresher. Apple II has a 1MHz 6502 processor. A "base" model can be assumed to have 48k of RAM and 16k of ROM (with a fairly popular bank-switched 16k RAM expansion available, although you can only have 12k of that active at once). Graphics RAM takes up a large chunk of this room, lo-res graphics has two 1k pages but hi-res takes up the whole range from $2000-$5FFF (16k) if you use both pages. A lot of my effects use page flipping so you often need another off-screen buffer (another 8k) only leaving around 16k for actual code. No hardware graphics acceleration of any sort except page flipping. Graphics are complicated but roughly you have hi-res which is 140x192 in 6 colors (with some color clash) and 40x48 in blocky lo-res with 16 colors. The memory map for the graphics modes is weird and interleaved. The hi-res mode is 3.5 pixels per byte, the high bit picks a palette, and it's NTSC artifact color so lots of other issues. Something as simple as trying to write orange ($AA) to all of the 8k hi-res frame buffer in order will actually give you 40 blue/ orange alternating columns that appear in a venetian blind effect, it takes a lot of work to just get a pixel of a color you want on the screen. Stock Apple II has just a bitbang speaker. To do any sort of interesting music generally requires most of the CPU. This is why most demos run on an optional sound card, in this case a Mockingboard which has a few AY-3-8910 sound chips. This has the added benefit of providing a regular timing interrupt too, something the Apple II doesn't have by default. Specific Model Support This currently requires an Apple IIe with 128k. I'm not actually using any advanced IIe features (65c02, double-graphics modes, lowercase, 80-column, etc). I'm mostly using the extra RAM like a ramdisk so I don't have to pause the music to read from disk. I'm hoping to maybe shrink things down so it will run on a 64k system (which would allow running on a II+ with language card) Disk II note The Apple Disk II drive is an amazing piece of Woz engineering, but it's controlled with cycle-accurate bitbanging of the hardware. It's essentially a hard real-time task. Having interrupts enabled would make disk accesses fail. There are two groups who've managed to get disk loads happening while playing music: Fast Loader by French Touch with and Low Tech by Imphobia. I should probably look into how they got things to work though I think it's complex. The disk code I use is by Qkumba. It's super fast. I'm using that with raw disk sector reads, there's no filesystem on the disk (no AppleDOS or ProDOS). --------------------------------------------------------------------- Code Notes Overall Framework This is the first demo I've written that was big enough to not all fit in memory at once. I have written Apple II games that needed some sort of overlay-style framework but usually those are more forgiving of pausing at some point for disk loads. The disk images are booters, there's no OS present. It uses qkumba's qboot boot sector which provides fast disk routines to load consecutive sectors into memory very quickly. Roughly 4k is loaded into the area of $1000-$1FFF which provides the disk loading code, the main framework code, lookup tables (mostly for hi-res row addresses as they are non-consecutive/interlaced), and some common routines. The music, music player, and the AUX memory copy routines are loaded into the ``language card'' bank switched area at $D000. The built in ROM firmware is swapped out and not used at all during the demo. A custom AUX (high 64k) copy routine is used as the ROM one is slow, and we put it in the language card because we use the ``keep the same stack page and zero-page while AUX mem is active '' mode which for some reason also leaves the language card memory alone when bank switching. Generally the effects are loaded to $6000 which is above the two hi-res pages. If we need an off-screen copy of graphics while page flipping we'll use $6000-$7FFF for that and load our code at $8000. For lo-res effects you can load lower, down to $2000, which provides a lot more room, and is why the 3d flyover code can be much larger than the other effects. For this code at least I tried to avoid reading from disk as much as possible, so the high memory was used as a sort of RAMDISK, at the start of the demo a lot of the effects were pre-loaded there, and then copied in while needed. The benefit of this is the music can keep playing while this is happening. As mentioned elsewhere in this page you can't really play music while the disk is being read. I might try to cram things to fit on a 64k Apple II+ but in that case there might be few second pauses when loads happen (the Disk II is much faster than the c64 floppy drive, but even with qkumba's code it takes a noticeable amount of time to load in a few tracks worth of data). PT3 Music Player The music is in the Vortex-tracker PT3 format (usually used for ZX-Spectrum music, the Mockingboard I use has the same AY-3-8910 sound chips). I have a library I made that plays PT3 files on 6502 processors. In the process of making this demo I found a bug (only shows up if you have more than 42 patterns in the sound file). My fix for that bug was flawed and made the credits music crash, which I was debugging late at night right before the deadline. Finding a PT3 copy of the main theme by z00m is what inspired me to do this whole project. Special thanks to mA2E for making a PT3 version of the into music at the very last minute. Compression I make a lot of use of ZX02 compression to make things fit. It's a wonder it all fits on just two 140k floppies (and the second floppy has a lot of spare room). Effects summary +-------------------------------------------------------------------+ | |Why not make an Apple II pretend to be a PC. Nothing | | |that exciting here though adapting an 8-pixel wide | |Fake Bios |font to the 7-pixel wide Apple II was a pain. | |[sr_bios] | | | |It actually is doing some system detection here so the| | |output varies based on your hardware setup. | |------------+------------------------------------------------------| | |The pan across the landscape is a 2-pixel horizontal | | |scroll which is really hard to do on Apple II. There's| | |no hardware scrolling. Each byte of hi-res memory is | | |3.5 pixels, so when scrolling you have to cross byte | | |boundaries. The bits are in LSB (least-significant | | |bit) order but also the top bit doesn't scroll (it's a| | |palette bit) and if you're not careful the colors will| | |swap. It's jerky because I'm not using page-flipping | |Intro |here (that would be even more complex). I'm using | |[sr_intro] |lookup tables. Oddly the technique I'm using is based | | |on a writeup I found on my system recently that I had | | |saved off of usenet in 1996 for some reason. | | | | | |No hardware sprites on the Apple II either. I'm | | |actually just moving chunks of memory here for ths | | |ships and not really doing sprites. I have the y-coord| | |a bit off which makes a bit of a warping effect but I | | |thought it looked cool and left it. | |------------+------------------------------------------------------| | |There were a lot of better ways I could have done | | |this, but I'm just using sprites to cheat a bit. I | | |didn't have time to hack up a real 3d-render, or even | | |some sort of triangle-drawing library. I made the | | |chessboard orange instead of purple as due to the | | |color palettes things interact better (you can't have | | |purple/green in the same 3.5 pixel chunk of screen as | |Chessboard |blue/orange). You still see some fringing at the | |[sr_chess] |edges, that's because the proper way to do this would | | |be to have a mask to mask off the transparent parts of| | |the sprite but that would make it slower and also use | | |a lot more RAM that what I'm doing which is doing | | |transparency at 3.5 pixel boundaries. Also while you | | |can only have your X-position be on multiples of 3.5 | | |pixels, it does handle automatically shifting the | | |sprite data to make sure the colors still look right | | |for both odd/even columns. | |------------+------------------------------------------------------| | |I wasted a week trying to get a good tunnel effect and| | |gave up (after some very interesting results ( 1 2 3 4| | |)) from buggy code. Drawing circles is a pain on 6502.| | |So for this I just took 2 screenshots and page flip. I| | |think this captures best the fast pace of the | | |original. | | | | |Tunnel |A lot of tunnel code involves multiply, divide, and | |[sr_tunnel] |trig functions and that all makes a 6502 assembly | | |programmer weep. Though the c64 people pulled it off | | |for their version so I should try to find out how they| | |did it. | | | | | |Note that the Second Reality effect is a bit more | | |interesting that a plain tunnel as it wiggles the | | |camera around too. | |------------+------------------------------------------------------| | |The circle code and some of the interference code are | | |based on code from Hellmood's famous Memories demo. I | | |should have tried to make actual circular interference| | |patterns but just cheated and used some existing code | |Circles / |that gave vaguely similar patterns. As I said before, | |Interference|drawing circles quickly when you don't have multiply | |[sr_interfe]|or trig functions is a pain. Lookup tables and | | |self-modifying code only get you so far. | | | | | |I did manage to get sound sync on the falling bars, | | |that was tricky (although depending how you watch the | | |video the sync might not match up for you) | |------------+------------------------------------------------------| | |The graphics are mostly automated conversions. I have | | |been using Kris Kennaway's iipix converter. However it| | |sometimes needs some tweaking and works better on | | |photos than on drawings. In the end I often just | |Monster |reduce images to a low number of colors and then fill | |Graphic |manually with dither patterns. | |[sr_monster]| | | |The scroll here is a quick hack, it needed to be fast.| | |It's actually going 7 color pixels at a time as the | | |naive 3.5 approach would make the colors swap each | | |step and I didn't have time to make a version that did| | |things properly. | |------------+------------------------------------------------------| | |Just two images with page flipping, didn't have time | |New Way to |to do this properly. | |Scroll | | |[sr_scroll] |Not only would I have to somehow map a font texture to| | |a 3d surface, but even just masking off the leaves | | |would be a pain. | |------------+------------------------------------------------------| | |Done in lo-res for speed. The lens part I meant to do | | |some sort of warping when drawing the transparent | | |sprite. I was going to use colors to specify an offset| | |to get when looking up the warped pixels from the | | |background. As a placeholder I was just anding the | | |colors in, and it actually looked OK as an effect and | | |I never had time to implement things properly. | |Lens/ | | |Rotozoom |You might miss it, but the music is paused so that a | |[sr_roto] |sound sample can be played out the speaker. | | | | | |Rotozoom is based on previous rotozoom code I had. | | |Instead of a color border I should wrap, it's just the| | |only fast way to do that is a power-of-two wrap but | | |the Apple II screen is 40x48 and I haven't had time to| | |figure out a good way of managing that. I could easily| | |do 32x32 but getting a smooth transition from 40x48 is| | |tricky. | |------------+------------------------------------------------------| | |I'd been trying for years to get a hi-res plasma going| | |on the Apple II. In the end this is based on French | |Plasma |Touch's Plasmagoria plasma code, but converted for | |[sr_plasma] |hi-res. It only draws ever other line for speed. As | | |far as I know no one has ever done full-screen hi-res | | |plasma on Apple II before. | |------------+------------------------------------------------------| | |I think this is my favorite effect. Again the French | | |Touch code, but with my own masking applied. The masks| |Plasmacube |have R/G/B components to apply different color lookups| |[sr_plasmac]|to the underlying plasma. The cubes are pre-rendered. | | |Only 8 steps, but they compress really well. I | | |probably have room for 16 steps but ran out of time. | |------------+------------------------------------------------------| | |I meant to do something fancier. In the end it looked | | |surprisingly well. It's not doing any of the fancy | | |patterns in the original though, but this is one case | |Bouncing |I might be able to approximate it with enough lookup | |Dots |tables. | |[sr_dots] | | | |This is a case I've since looked at the actual code | | |(and the modern remake) but everyone uses either | | |OpenGL or the original code is doing deep VGA tricks | | |so it'll be tricky to port over the exact algorithm. | |------------+------------------------------------------------------| | |I had a really nice hi-res version of the background, | | |but couldn't figure out a good way to do the sword in | | |hi-res without a huge amount of work (diagonal | | |sprites, color clash). So in the end I went with | |Transmission|lo-res which I think worked out OK. I even got the | |[sr_transmi]|"transmission" line said there if you listen closely. | | |There's a glitch at the start due to a disk access and| | |I didn't have time to fix it, I should have cleared | | |the screen to black before it happened, in fact I | | |thought I had so not sure why it didn't. | |------------+------------------------------------------------------| | |Fully cheating on this one. It's just screengrabs | |Ocean Voxels|hand-colored by me and being decompressed via ZX02 | |[sr_ocean] |full speed. This takes up 24k which is much larger | | |than most of the other effects. | |------------+------------------------------------------------------| | |I wanted to make it bounce, even had various plans for| |Polar Lady |trying to do it (it's not easy, again because of the | |[sr_polar] |weird way pixels work on hi-res, you can't just scale | | |them out slightly without weird color effects). In the| | |end I just had to settle for a quick vertical scroll. | |------------+------------------------------------------------------| | |As you might guess this is not rendered in 3d. It's a | | |bunch of rectangles being drawn really quickly. | | | | | |I started out optimizing the rectangle lists by hand, | | |this is something I did for a lot of my Apple II bot | | |entries. | |3D-scene | | |[sr_3d] |Hand optimizing took forever, so I wrote a program | | |that given a lo-res screen will attempt to find | | |optimal rectangle coverage. It's about 10-20 percent | | |worse than by hand, but so much faster. I still take | | |the 4fps screen grabs and convert them to 40x48 with | | |proper lo-res color selection by hand. You'll notice | | |it stops before the actual end, ran out of time. And | | |then it switches to hi-res and sprites for the finale.| |------------+------------------------------------------------------| | |Using 4am's font and libs here. The scroll in of the | |Credits |thumbnail is not perfect, didn't have time to scroll | |[sr_credits]|it in from off screen properly. The final credits are | | |again a little jerky as I'm not using page flipping. | +-------------------------------------------------------------------+ --------------------------------------------------------------------- Development Notes 12 November 2023 -- Release v1.2 Updated to include the full 3d scene in the credits (before stopped 2 /3 of the way through as I ran out of time). It just barely fits, I need to see if maybe using ZX02 compression instead would reduce the filesize. 8 November 2023 -- Release v1.1 Released an update, should now work on IIc and IIgs systems. Tested on MAME. On IIgs you'll need to make sure you have a Mockingboard enabled, then press ctrl-cmd-esc and select that you have your own card in Slot 4. 4 November 2023 Up late finding a bug in the music player which was introduced by my fix for large files a few days ago. During the competition their machine crashed due to music issues, hope my code isn't still buggy : ( 3 November 2023 After a lot of late nights managed to get something together just before the Demosplash deadline. 29 October 2023 I unwisely have spent the last month or so trying to put together a real version of this for Demosplash, so I guess watch this space. 15 August 2023 -- Release v0.1 I really should be working on other stuff. I stumbled across the AY-3-8910 PT3 music for this by z00m, and then of course needed some visuals. The graphics were converted using Kris Kennaway's ii-pix program though it was a hassle getting all the python dependencies going. I had pre-existing rotozoom code. Ideally I'd fix it to wrap at the edges but turns out that'd be a pain. --------------------------------------------------------------------- Other VMW Software Demos --------------------------------------------------------------------- Other Apple II Projects --------------------------------------------------------------------- Back to the VMW Software Productions Page