Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - SMS Programming Guide

Reply to topic
Author Message
  • Joined: 20 Dec 2004
  • Posts: 187
Reply with quote
SMS Programming Guide
Post Posted: Fri Jun 06, 2008 5:59 pm
Hey, in case anyone here is not aware, I'm currently writing a SMS Programming Tutorial on sega8bit. I'd hope other people would jump in to help and offer advice (like Maxim and Bock already) or even ideas. If not, that's fine. Just wanted to post about it. I'm currently in the middle of writing the Z80 architecture part, which is mainly for informational purposes. After this Z80 Assembly and then some code. I'm currently writing a tutorial for changing screen color to start (a 'milestone' suggested to me by Scott), and then after this backgrounds, sprites, etc. If anyone is looking to write some code or help out, let me know here or check out what I currently have up here. It still needs work, of course, but just so you can see the layout. I'm also looking for a list or some sort of information on the sounds of the SMS and how they relate to middle C (meaning, where they are on the treble and bass clefs). If it doesn't exist, I'll make it, but I want to use a music to programming idea for the tutorial so people, if musically inclined, can write first on a piano or something based on the SMS' abilities, and then translate it to code. So, similar to how Bock and Maxim put up the code for colors, I'm looking for something for sounds that also includes information on respective notes. Anyway, thanks for any interest!
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Fri Jun 06, 2008 6:46 pm
If you have a table of frequencies for each note (there's lots online) you can pass them through the calculation

PSG value = 111861 / frequency

and the results will be the numbers you need to feed the PSG. All I can remember off the top of my head is A4 = 440Hz = 0xfe. Notes follow a rather complicated logarithmic scale in terms of frequency.
  View user's profile Send private message Visit poster's website
  • Joined: 20 Dec 2004
  • Posts: 187
Reply with quote
Post Posted: Fri Jun 06, 2008 6:50 pm
Awesome, thanks. I'll check that out and see if I can't come up with a similar chart as you did for the colors.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Mon Jun 09, 2008 9:09 am
Here's a JavaScript-generated chart for PSG notes:

http://www.smspower.org/maxim/forumstuff/psgtable.html

It only shows notes the PSG can play. The error column is in cents; 100 cents = 1 semitone (note). You can see that at the higher frequencies, the errors are large and the music is more likely to sound "off-key", although vibrato effects can reduce that effect. MIDI note names are what you might call "normal notes" - middle C is C4, for example.

The source might be useful for people wanting to convert between frequency and PSG notes, as well as MIDI numbers and names.
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 731
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Mon Jun 09, 2008 10:05 am
Sounds great! I have always wanted to see a more comprehensive tutorial on programming the SMS. Maxim's couple of tutorials are great but leave a person wanting for more, yes it does arm you with enough knowledge to read the documentation and probably figure the rest out yourself but sometimes it helps to have a guide to refer back to at times.

What I would ultimately like to see is a tutorial that builds upon itself to form essentially a complete game engine, doesn't have to be anything fancy but enough to show the functional flow of a working game.

I do have one sugestion though, given the narrow format of the main column on your site it does make large paragraphs difficult to read, wouldn't hurt to break them up a bit.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Mon Jun 09, 2008 10:37 am
My tutorial would end up as a complete game if I had unlimited free time.

Based on my experience, writing a tutorial takes approximately 10 times longer than doing the thing in the tutorial. A "real game" might take 40 or 50 hours of development, 400-500 hours is a lot to find.
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 731
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Mon Jun 09, 2008 11:21 am
That's why one does these things in baby steps dear Maxim :)

Probably not disimular to yourself I have a number of projects I work on and nowehere near enough hours in the day to get them all done, but I constantly shift between projects adding little bits at a time as I can afford.

It might only mean spending 1 hour on a weekend or somesuch, but its better than nothing. Often I find I will become particularly inspired by a project and I end up doing much more than I anticipated possible.
  View user's profile Send private message
  • Joined: 20 Dec 2004
  • Posts: 187
Reply with quote
Post Posted: Mon Jun 09, 2008 7:36 pm
Again, I think Maxim's tutorial is great, this is just meant to avoid needing to learn things on your own, condensing everything into one source. I gladly welcome help from him or anyone, including code or awesome charts like he provided up there. I've gotten some complaints about the paragraph thing, I need to figure out a way to fix that overall. It's not my site, by the way, I just help with some things there. I myself also don't have unlimited time, but I devote a good portion of my week to doing this because it's a hobby to me and I like it. I probably spend about 1 hour each day maximum and more on the weekend or if I have extra time. It really doesn't take that long if you just sit down to do it. It's just a matter of getting motivated. After I finish this Z80 section, I plan on going into basic assembly (really only so much you can show without getting in to actual examples), followed by programming sections that very slowly show how to manipulate data. As I mentioned, this is going to start with showing how to change screen color, explaning EVERY bit of code in the program so that the reader understands fully what's working and why and how. After that, backgrounds, sprites and eventually some sort of simple game. It always seems best to start with a Pong type game, but I decided to go with a more Kaboom! style game for a little more fun and maybe even a decent homebrew in the process. Get some more use out of that paddle or Sports Pad. But I must stress, it still requires a good bit of dedication on the part of the reader, I'm just trying to make it as easy as possible and not seem as daunting, but in the end it's just like learning anything else. I've learned as much as I have thus far from a lot of reading and help from Maxim's tutorial, as well as code provided on this site by Bock.
  View user's profile Send private message Visit poster's website
  • Joined: 20 Dec 2004
  • Posts: 187
Reply with quote
Post Posted: Tue Jun 10, 2008 1:24 am
By the way, bass, if you want, show me exactly what you mean. I've written it and read it so many times I'm not sure where it would be best to break.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Tue Jun 10, 2008 8:03 am
How about this as an example:

Stan wrote
Again, I think Maxim's tutorial is great, this is just meant to avoid needing to learn things on your own, condensing everything into one source. I gladly welcome help from him or anyone, including code or awesome charts like he provided up there.

I've gotten some complaints about the paragraph thing, I need to figure out a way to fix that overall.

It's not my site, by the way, I just help with some things there. I myself also don't have unlimited time, but I devote a good portion of my week to doing this because it's a hobby to me and I like it. I probably spend about 1 hour each day maximum and more on the weekend or if I have extra time. It really doesn't take that long if you just sit down to do it. It's just a matter of getting motivated.

After I finish this Z80 section, I plan on going into basic assembly (really only so much you can show without getting in to actual examples), followed by programming sections that very slowly show how to manipulate data. As I mentioned, this is going to start with showing how to change screen color, explaning EVERY bit of code in the program so that the reader understands fully what's working and why and how. After that, backgrounds, sprites and eventually some sort of simple game.

It always seems best to start with a Pong type game, but I decided to go with a more Kaboom! style game for a little more fun and maybe even a decent homebrew in the process. Get some more use out of that paddle or Sports Pad.

But I must stress, it still requires a good bit of dedication on the part of the reader, I'm just trying to make it as easy as possible and not seem as daunting, but in the end it's just like learning anything else. I've learned as much as I have thus far from a lot of reading and help from Maxim's tutorial, as well as code provided on this site by Bock.


By the way, 99% of homebrew use is on an emulator and paddles/sports pads are hard to emulate using a keyboard/mouse. The remaining 1% is still unlikely to actually have one of those devices.
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 731
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Tue Jun 10, 2008 12:52 pm
To further elaborate on Maxim's example, each paragraph should convey a particular idea or point. When a sentence is no longer relevant to the initial point made at the start of the paragraph, it is time to begin a new paragraph.

While there is no formal limit on how many sentences should make up a paragraph, keeping a limit of no more than seven sentences per paragraph greatly enchances the readability of the text.

A good test has always been to read your sentences aloud. If you find you are struggling to repeat sections without taking a breath or rambling then it is a sign you need to break that section up a bit.
  View user's profile Send private message
  • Joined: 20 Dec 2004
  • Posts: 187
Reply with quote
Post Posted: Wed Jun 11, 2008 5:07 am
Sounds good, I've made some changes thus far. Finished writing the rest of this section and I'll have it up tomorrow. The final image I keep going on about is quite blurry because I had to shrink it, but oh well, good enough for the moment until I feel like coloring and writing everything all over it again. Thanks again, guys.
  View user's profile Send private message Visit poster's website
  • Joined: 26 Apr 2008
  • Posts: 16
  • Location: France
Reply with quote
Post Posted: Sat Jun 28, 2008 1:26 pm
Hey hi,

interesting, i'm writing a collection of SMS tutorial too with both full ASM code and C code explained, it's in my native language but maybe ill translate it in english one day, actually there is two tutorial released but i'm not far to finish the third.

The first tutorial explain a little bit some z80 instructions and how to load and display hardcoded tiles.

The second explain how to load/display a bmp (with bmp2tile), modify a color in the palette for create a tiny effect on the image, how inputs work and how the stack/functions work.

The 3° will explain some basic PSG stuff, pause int example, how to make a tiny timer for displaying two image and a advanced color effect (with vsync).

The finality of this will be a tiny platform game.

All tutorials are available here (Tuto1 and Tuto2), maybe it can be usefull to give you some ideas.
  View user's profile Send private message Visit poster's website
  • Joined: 20 Dec 2004
  • Posts: 187
Reply with quote
Post Posted: Sat Jun 28, 2008 2:32 pm
Yeah, that's awesome. I'll check them out and see if I can get some ideas. If I happen to want to use anything in particular, I'll obviously ask you.
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!