I am a turncoat. A simple sprite demo for Sega Master System

Discussion of development of software for any "obsolete" computer or video game system.
tepples
Posts: 22017
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

I am a turncoat. A simple sprite demo for Sega Master System

Post by tepples » Mon Dec 16, 2019 8:18 pm

Lately every time I've learned a new retro console, I've ported a basic demo of drawing a background, controlling a character, and drawing its walk cycle with sprites. It's on NES and Super NES, and on Game Boy and Game Boy Advance as part of my ports of 240p Test Suite.

And now it's on the Sega Master System.
SMS_Move_Podge.png
SMS_Move_Podge.png (792 Bytes) Viewed 4682 times
This version posed some challenges:

Podge drove the snakes out of Templateland
I rewrote pilbmp2nes.py from my NES and Super NES project templates in C for two reasons: 1. to extract palettes from PNG files, and 2. to provide an example of avoiding a dependency on Python. I traded it for a dependency on GCC and LodePNG.

Facing the other way
Though I was able to paste my Game Boy movement code and see it run almost unchanged, drawing the sprite posed a trickier problem, as the VDP has no sprite flipping. I had to adapt the technique that I had previously used for horizontal shrinking just for flipping, but it loads tile data at almost the maximum speed that the VDP accepts during draw time.

A whole new palette
The palette is 2-bit-per-channel RGB, not HSV like the Atari 2600 and NES palettes. To help me choose colors, I did two things: created a macro to convert 8bpc web colors (e.g. #AAAAFF) to 2bpc, and rearranged the RGB palette by brightness (R+G+B) and hue. However, it doesn't show "this color is perceptually brighter than this color" quite as clearly as the NES palette does.
sms_hsv_palette.png
sms_hsv_palette.png (2.37 KiB) Viewed 4682 times
This tech demo is crossposted to SMS Power forums.
Attachments
sms-template-0.01.zip
(111.57 KiB) Downloaded 68 times

calima
Posts: 1158
Joined: Tue Oct 06, 2015 10:16 am

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by calima » Tue Dec 17, 2019 4:01 am

SMS is so painful to program that most new stuff is Alex Kidd hacks. You'll get attention just for making something new.

User avatar
TmEE
Posts: 753
Joined: Wed Feb 13, 2008 9:10 am
Location: Estonia, Rapla city (50 and 60Hz compatible :P)
Contact:

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by TmEE » Tue Dec 17, 2019 5:47 am

I haven't found SMS to be painful on any regard, the hardware is really straightforward...

As far as the color goes, SMS output is not linearly spaced though the difference is quite minor.

Code: Select all

+--------------------+---------------------+--------------------+
| SMS1 (315-5124)    | SMS2 (315-5246)     | MD (all of them)   |
+-----+-------+------+------+-------+------+-----+-------+------+
|  mV | Ratio | 8bit |   mV | Ratio | 8bit |  mV | Ratio | 8bit |
+-----+-------+------+------+-------+------+-----+-------+------+
|   0 | 0.000 |    0 |    0 | 0.000 |    0 |   0 | 0.000 |    0 |
| 324 | 0.354 |   90 |  364 | 0.350 |   89 | 368 | 0.387 |   99 |
| 620 | 0.677 |  173 |  729 | 0.684 |  174 | 604 | 0.634 |  162 |
| 916 | 1.000 |  255 | 1052 | 1.000 |  255 | 952 | 1.000 |  255 |
+-----+-------+------+------+-------+------+-----+-------+------+

turboxray
Posts: 82
Joined: Thu Oct 31, 2019 12:56 am

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by turboxray » Tue Dec 17, 2019 8:10 am

calima wrote:
Tue Dec 17, 2019 4:01 am
SMS is so painful to program that most new stuff is Alex Kidd hacks. You'll get attention just for making something new.
Compared to what? Surely not the NES haha. SMS is pretty straight forward.

turboxray
Posts: 82
Joined: Thu Oct 31, 2019 12:56 am

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by turboxray » Tue Dec 17, 2019 8:12 am

TmEE wrote:
Tue Dec 17, 2019 5:47 am
I haven't found SMS to be painful on any regard, the hardware is really straightforward...

As far as the color goes, SMS output is not linearly spaced though the difference is quite minor.

Code: Select all

+--------------------+---------------------+--------------------+
| SMS1 (315-5124)    | SMS2 (315-5246)     | MD (all of them)   |
+-----+-------+------+------+-------+------+-----+-------+------+
|  mV | Ratio | 8bit |   mV | Ratio | 8bit |  mV | Ratio | 8bit |
+-----+-------+------+------+-------+------+-----+-------+------+
|   0 | 0.000 |    0 |    0 | 0.000 |    0 |   0 | 0.000 |    0 |
| 324 | 0.354 |   90 |  364 | 0.350 |   89 | 368 | 0.387 |   99 |
| 620 | 0.677 |  173 |  729 | 0.684 |  174 | 604 | 0.634 |  162 |
| 916 | 1.000 |  255 | 1052 | 1.000 |  255 | 952 | 1.000 |  255 |
+-----+-------+------+------+-------+------+-----+-------+------+
Ohh hey. That's pretty interesting. Do emulators get this right?

lidnariq
Posts: 9506
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by lidnariq » Tue Dec 17, 2019 11:18 am

I wrote a very simple banking validation program when I was tasked with making a modern replacement for the banking IC. At the time, I decided I really didn't care for a number of decisions made by devkitSMS, but I found it really easy to get bare SDCC to generate something.

Of course, I didn't deal with sprites, VDP IRQs, the pause button (=NMI), the sound hardware, or having code across multiple banks, so this isn't exactly a ringing endorsement.

calima
Posts: 1158
Joined: Tue Oct 06, 2015 10:16 am

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by calima » Tue Dec 17, 2019 1:07 pm

turboxray wrote:
Tue Dec 17, 2019 8:10 am
Compared to what? Surely not the NES haha. SMS is pretty straight forward.
Yes, NES too. The existence of a decent C compiler makes all the difference, sdcc is just not that good. Z80 vs 6502 is mostly a matter of opinion. I do not want to restart that discussion though, we have done that enough times on this forum.

turboxray
Posts: 82
Joined: Thu Oct 31, 2019 12:56 am

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by turboxray » Tue Dec 17, 2019 2:35 pm

calima wrote:
Tue Dec 17, 2019 1:07 pm
turboxray wrote:
Tue Dec 17, 2019 8:10 am
Compared to what? Surely not the NES haha. SMS is pretty straight forward.
Yes, NES too. The existence of a decent C compiler makes all the difference, sdcc is just not that good. Z80 vs 6502 is mostly a matter of opinion. I do not want to restart that discussion though, we have done that enough times on this forum.
I meant Assembly. And I also mean hardware - nes video hardware and mapper stuff is convoluted and unnecessarily complex. Yeah, CPU's are a matter of opinion; I find 65x more comfortable than the z80. It feels less restrictive, but it's not like night and day difference. But yeah I wasn't referring to the CPUs.

lidnariq
Posts: 9506
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by lidnariq » Tue Dec 17, 2019 3:19 pm

calima wrote:
Tue Dec 17, 2019 1:07 pm
The existence of a decent C compiler makes all the difference, sdcc is just not that good.
Would you be willing to talk your experiences with SDCC? I'm curious.

User avatar
tokumaru
Posts: 11757
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by tokumaru » Tue Dec 17, 2019 7:58 pm

calima wrote:
Tue Dec 17, 2019 4:01 am
SMS is so painful to program that most new stuff is Alex Kidd hacks. You'll get attention just for making something new.
I disagree completely. I haven't done much with the SMS myself besides playing with the VDP a little bit, but from all the documents and resources I've had contact with, it looks like a pretty straightforward system to code for. There are certainly less "gotchas" than with the NES (timing is less critical, VDP/VRAM can be manipulated during rendering, mappers are more standardized, etc.). The reason for the lack of SMS homebrews is probably the fact that it doesn't have a strong following in North America, so its community is not as well established as that of the NES. Research and development efforts are less coordinated (Europe speaks lots of different languages, Brazil doesn't have many retro coders, etc.), and the market for new hardware and software is more scattered throughout the world.

I personally don't like to use C with these old machines anyway... From everything I've read in the forums it seems that getting working performant code out of the available compilers is an absolute nightmare, so I couldn't care less about which 8-bit CPU has the best C compiler. I have tons of fun coding in assembly, I wouldn't trade that for anything else (at the scale of 8 and 16-bit consoles, at least).

turboxray
Posts: 82
Joined: Thu Oct 31, 2019 12:56 am

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by turboxray » Tue Dec 17, 2019 8:10 pm

tokumaru wrote:
Tue Dec 17, 2019 7:58 pm
calima wrote:
Tue Dec 17, 2019 4:01 am
SMS is so painful to program that most new stuff is Alex Kidd hacks. You'll get attention just for making something new.
I disagree completely. I haven't done much with the SMS myself besides playing with the VDP a little bit, but from all the documents and resources I've had contact with, it looks like a pretty straightforward system to code for. There are certainly less "gotchas" than with the NES (timing is less critical, VDP/VRAM can be manipulated during rendering, mappers are more standardized, etc.). The reason for the lack of SMS homebrews is probably the fact that it doesn't have a strong following in North America, so its community is not as well established as that of the NES. Research and development efforts are less coordinated, and the market for new hardware and software is more scattered throughout the world.
It had a big following in EU, but history seems to have forgotten it (re-written?) with the rise of Nintendo's popularity over the years there. Is the same true for Brazil?

User avatar
TmEE
Posts: 753
Joined: Wed Feb 13, 2008 9:10 am
Location: Estonia, Rapla city (50 and 60Hz compatible :P)
Contact:

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by TmEE » Tue Dec 17, 2019 8:37 pm

turboxray wrote:
Tue Dec 17, 2019 8:12 am
Ohh hey. That's pretty interesting. Do emulators get this right?
Not that I know of, maybe Emulicious does since it tries to be the most accurate SMS/GG emulator but I haven't looked in any detail for a long while now... The difference is very small and probably makes no visual difference, unlike MD native output where its non linear ramp is very different from linear ramp that emulators used to use. I don't know how spread the info is though, I still see plenty of MD artists using the completely wrong ramp that Gens emulator used where there was no proper white lol.

User avatar
tokumaru
Posts: 11757
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by tokumaru » Tue Dec 17, 2019 8:43 pm

turboxray wrote:
Tue Dec 17, 2019 8:10 pm
It had a big following in EU, but history seems to have forgotten it (re-written?) with the rise of Nintendo's popularity over the years there. Is the same true for Brazil?
I don't think any "history rewriting" took place here... Nintendo was probably always held in higher regard than SEGA as a company in general, but since the NES wasn't around in the early years, the Master System had a stronger name and presence when compared to the multitude of Famiclones we had here, and I don't think anyone today disputes the popularity of the Master System. Nintendo probably won the 16-bit war here though, as I feel that the SNES is more often remembered and celebrated than the Mega Drive, but not by a huge margin.

Anyway, I'm sure that there are a lot of (former) gamers who are fond of all these platforms, we just don't have that many people in software development interested in learning how to code for ancient machines.

BTW, I know that the thread's title is a joke, but I don't see the act of coding for both Nintendo and SEGA systems as a kind of betrayal. It's not like any of these consoles are making their companies any real money anymore (and it's not like any of us is making any real money off of them either!), they are not at war anymore and they certainly don't depend on us humble retro coders for anything. We do what we do mostly for fun, so anything goes at this point.

Drag
Posts: 1314
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by Drag » Tue Dec 17, 2019 8:56 pm

If you're looking for some inspiration, the SMS's VDP is a derivative of the granddaddy ancestor, the TMS9918. You could try looking at how Colecovision and MSX games handled their sprite flipping (both systems use a z80 as well); you'd even be able to look at some Konami examples.

tepples
Posts: 22017
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: I am a turncoat. A simple sprite demo for Sega Master System

Post by tepples » Tue Dec 17, 2019 9:51 pm

ALF for SMS (Nexa, 1989) makes Gordon invisible while turning around, presumably while VRAM was being refilled with flipped cels. A "sniffing armpit" cel like the 2D Super Mario Bros. games or even just a "facing forward" cell like Dizzy would have worked better for turning around.

My paradigm of flipping cels on demand would avoid this. The 4-bit flipping routine and the 2-to-4bpp expansion and flipping routine each take an estimated 5 scanlines per 8x8-pixel tile. There are 70 lines of vblank, and VRAM updates are allowed to extend past vblank so long as you avoid (or tolerate) tearing and don't write twice in (I think) 26 cycles. I satisfied the latter constraint just by moving some inc hl instructions around. Overall, the architecture appears to encourage the sprite cel streaming that Battletoads and Haunted: Halloween '85 for NES are known for.

ColecoVision and MSX have it somewhat easier in a way, as they use 1bpp sprite cels. But then relying on TMS9918 video modes will fail when playing SMS games on a Genesis through a Power Base Converter, which doesn't support modes below 4.

With that out of the way, the next things to overcome are the CPU architecture, the lack of mid-screen vertical scroll position changes, and the lack of bass in non-Japanese consoles.

A Z80 reportedly takes 3 times as many cycles as a 6502 to get equivalent work done. This means the 3.6 MHz Z80 in the CV and SMS is roughly equivalent to a 1.2 MHz 6502. Having to drop to 30 fps might not be quite so bad on Game Gear, as I get the impression from reviews that the display on that thing has a response time as slow as a monochrome Game Boy's STN LCD. But at least there's no attribute table fyaykery.

Status bars are painful unless a game scrolls only horizontally. In an 8-way game, you have to either build the status bar out of sprites (magnification is tricky on the SMS1 VDP and fails entirely on PBC) or edit video memory every frame to counter-scroll the status bar.

The pulse waves in the 2A03 can go an octave lower than the square waves in the SN76489, and the triangle wave can go two octaves lower. Nor do SN7 square waves have duty cycle control, unless you mute square 3 and route its period to periodic noise to make a 1/16 duty pulse wave (which incidentally can go even lower than 2A03 but is out of tune at high pitches). You also need to briefly mute square 3 for its period in order to make nontrivial drums using anything other than the equivalent of NES noise periods $0D, $0B, or $09 (pitches 2-#, 4-#, or 6-# in FT or Pently). I imagine that the workarounds would resemble those of SID, where drums and the bass line are expected to share a channel.

Post Reply