Genesis raster skew/scale demo + source code
Months ago, I made a program for the genesis showing a picture of a gnome getting stretched and skewed. I don't think I ever formally "released" it, and I even had someone tell me it was fake. I guess now is as good a time as ever. I'm sure someone will have fun playing it with, and maybe someone can incorporate the effect into their own homebrew.
Here is the old video clip that I've shown off in the past:
http://gfycat.com/ScentedIncomparableGosling
Here is a new improved version:
http://gfycat.com/GoldenFineAustraliankestrel
It runs at 60FPS (50 for PAL), and only uses 7 bytes of RAM not including the stack. It uses somewhere around 60%-75% of the genesis's CPU cycles.
But ComradeOj, how could you warp those high res images like rubber at 60FPS, using only 7 bytes of RAM? Raster trickery! My program takes advantage of the Genesis's natural scrolling abilities. It continuously scrolls farther and farther as the TV draws the image (from top to bottom). It then resets the scrolling when the TV draws the entire thing. The result is a natural looking skewing and scaling. This is also why it can only scale vertically, and not horizontally.
I'm including a version with the gnome, and a version with the SEGA-16 logo. The source code is also included. The source is super easy to alter, even if your not much of a programmer. Just make tiny changes, build a new copy of the program, and try it! Just have fun with it, I was able to get all sorts of neat effects by inserting random instructions into the skew routines.
Controls
Use the D-pad to warp the image, and use A, B, C to toggle slow, medium, or fast movement speed.
You can press START to reset the image.
Building the source
To build the program from the source, simply double click the "make.bat".
It will output a ROM called "Genesis raster FX test.bin"
It's as easy as that.
How it works:
Here is the meat of the source code. Hblanks, skewamount, vertskewamount, and speed are all just labelled locations in RAM. VDP control is loaded into A3, and VDP data is loaded into A4.
Here is the routine for horizontal skewing. It gets called once per Hblank along with an almost identical routine for vertical scaling. "speed" is 7, 5, or 3 depending on what the player sets it to. In addition the "hblanks" variable gets counted up by one every hblank.
Code:
skew_H:
move.l #$40000003,(a3) ;set VRAM write at $C000 (scroll data)
move.w hblanks,d0 ;increase skew the farther down
muls.w skewamount,d0 ;Calculate scroll distance
move.b speed,d1 ;add controllable speed factor
sub.b #$01,d1 ;make H speed more closely match V speed
lsr d1,d0 ;speed adjustment
move.w d0,(a4) ;write scroll data
move.w d0,(a4)
rts
On the Vblank, we have:
Code:
move.w #$0000,hblanks
...and the controller input reading routine. That's pretty much it.