============== UTOPIA SPOILER ============== (c) Daniel Vik and Vinvent van Dam 2007. Contact: daniel@vik.cc vincentd@erg.verweg.com The content of this document may not be published in part or as a whole without permission from Daniel or Vincent. The document may not be mirrored on other websites. This document tries to explain the key features of the MSX1 demo UTOPIA that was released simultaneously at The Vintage Computer Festival Europa (VCFe8.0) and at the 31st MSX Users Meeting in Barcelona (31st RU of BCN). Logo ==== The black and white dvik & joyrex logo is made in screen 0 and uses code synchronized to VBLANK interrupt to get the split between white and black at the correct location. The color change is simply an update of VDP register #7. Intro Scroller ============== The intro scroller is basically a very efficient blitter that copies all visible characters from an offscreen bitmap to the screen on every second frame. To get as much time as possible for the blitting without causing any flickering, a sprite collision is set at the top of the display area to simulate a horizontal interrupt. When the collision is detected, the blitting is started and continues on to the next frame and ends at the bottom scanline of the next frame. So the enitre blitting takes around 1.3 frames but since its synchronized the way it is, it is flicker free. Fish Video ========== The video runs at 12fps but each frame is made up of two screen 3 images that are switched every vdp frame to generate the illusion of more colors than the 15 colors available on the MSX. The big challenge with this part was to find a video clip that would look interesting and fit withing the memory limitations. This video clip is almost 9 seconds and is approximately 250kB uncompressed. The compression algorithm is custom made to this part and is basically a lossless compression that does a combination of rle, diff to previous frame and uncompressed data. The compression is done in a custom made PC tool that generates an output file with a suitable format for the MSX. Big Eyes ======== The graphics in this part is basically a simple 2-D transformation effect doing offset, rotation and scaling. The part uses screen 2 characters with dithered patterns to simulate different color tones. The source image is a 256x128 pixel image with 8 bit color depth. The transormation matrix is | x' | | x0 | | dx -dy | | x | | | = | | + | | | | | y' | | y0 | | dy dx | | y | To make the math easy on the Z80, fix point arithmetics is used. 16 bit registers are used in the calculation and the high 8 bits are the integer part. Each source pixel (x, y) represents one character on the MSX screen. The character shown depends on the pixel in the source image closest to (x', y'). Each frame in the animation is defined by four values. x0, y0 is the top left corner and dx, dy which are the transformation parameters. So each frame, the engine reads the transformation data from a table and renders the output image. Big Scroller ============ Although it may not look as much, this is one of the more advanced parts in the demo. Moving vertical bars that spans all the way from left border through display area to the right border is nothing new. The effect is seen in many MSX2 demos but the bars are syncrhonized with HINT which don't allow the bars to go on top or bottom border. MSX1 only have one good synchronization point, which is the VBLANK interrupt. To do bars that move across the entire screen, all code needs to be cycle exact to get the color change at the desired location. The hard part is that conditional code needs to take equally long depending on the condition, so components like the music player was rewritten so that it requires exactly 2900 cycles to execute no matter of what notes, envelopes or patterns are being played. The same goes for the text scroller so regardless of what character or position the scroll has, it always executes the same number of instructions. The theme of the text is inspired from Starship Troopers. Fullscreen Images ================= This is another technically advanced effect. Its most likely the only effect produced on any MSX system that uses three screen modes at the same time. The basic idea is quite simple. Its a mix of two images to create an illusion of more colors than available on the MSX. Now to the tricky part. One image is a plain screen 2 image which requires about 13kB VRAM. So for the second image we have 3kB VRAM. This is almost enough to fit two screen 3 images and we get there by swapping about 1kB of RAM to VRAM every frame. With two screen 3 images, we can switch between the screen 3 images every second scan line and get 4x2 pixel blocks instead of the standard 4x4 pixel blocks. So the resulting image consists of a screen 2 image shown on even frames and the 4x2 pixel block screen 3 image on odd frames. To do the fade in and fade out effect, we use a different trick. Instead of copying data to VDP to fill the image when fading in or to clear data when fading out, we use screen 0 for the top black part of the display (both forground and background color in VDP register 7 is set to black). So each frame has a screen split from screen 0 to screen 2 or screen 3 at the top of the shown image. To convert a regular windows bitmap to the very custom made screen 2/3 format, a PC tool was developed. The encoding is similar to the 105 color images in MSX Unleashed but requires a lot more processing time to finish, mainly due to the number of combinations each 8x2 pixel block can have. Since the part also requires a screen split from screen 3 to screen 3 every second scan line, the code needs to be synchronized and cycle exact. So its using the custom made music replayer that always use the same number of cycles no matter of what notes are played. Old School Tunnel ================= This is another classic demo effect but as with all dvik & joyrex productions with an extra touch. Its basically another 2-D transformation with a sprite overlay. What makes the part unique on MSX systems is that it is an animated bitmapped tunnel effect. So on top of the standard bitmapped tunnel, the bitmaps changes over time to change the shape of the tunnel. Although, fitted for screen 3, the part is implemented in screen 2. The main reason is that it speeds up the runtime calculations a bit but it also makes it possible to add the black 'scan lines'. Sample Player ============= The original song was made in reason, and was split up into 256 1/16 samples using perl. After that all samples were loaded in impulse tracker, and every bar was reproduced identifying the smallest usable samples. Once these samples were identified, there were concatenated again using another perl script and the actual track was reproduced using our own custom made sample player tracker. Once the original was finished, some variation was added to the original loop for a second run. The samples are encoded using the Chrystal Clear PSG Encoder and replayed with one PSG transition each 1/19000 second, i.e. 4 bits/sample at 19kHz. The graphics is a simple screen 1 image with transparent forground color, so color changes can be made with one write to VDP register #7. The sinus curve is a 32 frame sprite animation. Each frame has its own Sprite Attribute Table, so changing frame only requires one write to VDP register #4. These minimal updates are made both to save CPU time for the sample player and to minimize RAM usage. All data, both the image and sprite animation are stored in VRAM. Bonus Part ========== The bonus part is a quite simple trick but the effect is quite interesting. The background is a screen 0 image and the idea is to switch background and forground colors as quick as possible. Each scanline switches color exactly eight times. The code is timed so that the eight color switches takes 228 Z80 cycles. Then the code is repeated to make two rows of squares. Furthermore the square size is made to get a slow one pixel vertical scrolling. The effect only works as intended on MSXes where a scanline takes exactly 228 Z80 cycles. There are some MSXese where this is not the case and it would be interesting to investigate why this isn't the case. It seems like most MSX1 machines and all MSX2 machines behaves as intended. MSX2+ and TR machines have an extra wait state on VDP outs so they won't show the effect as intended. But the big question is why some MSX1 machines don't have the expected 228 cpu cycles per scan line.