The perfect "Hello World" example for new starters

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

The perfect "Hello World" example for new starters

Post by BigEvilCorporation » Sun Apr 02, 2017 12:56 pm

I keep getting asked to re-upload my Hello World sample from my blog, but it was a learning experience riddled with bad practices so letting it circulate further wouldn't do anyone any good.

5 years on I'm now experienced and would like to rewrite every article into proper tutorials, but as a stop-gap measure I'd like to throw the idea of coming up with the perfect Hello World sample we can point newcomers at to get them started quickly. Existing examples are hard to find, aren't very beginner friendly, are poorly documented, or target specific toolchains.

I ran a workshop on Mega Drive coding at the NVA last year, which ended up with this: https://pastebin.com/kJC99PA7 (and the workshop slides to go with it: https://docs.google.com/presentation/d/ ... sp=sharing).

It might be a good base to start, I'll do some cleanup and add extra comments, but does anyone have any thoughts?

Since it's aimed at beginners, I propose the following:

- Target Motorola syntax
- Compatible with most major assemblers (asm68k, snasm68k, asmx, vasm) with example command lines for each
- Comments for every line (i.e., remind the reader what a particular register is currently being used for every time it's written to)
- Prefer verbose methods that teach, over high performance code that obfuscates (within reason, see next point)
- Shouldn't show or encourage "newbie mistakes" or bad practices
- Should be reusable and extendable
- Define/equate all "magic numbers" or addresses
- Must work on all revisions of real hardware (my original didn't)

Most importantly, it needs to be an example we all agree on as being clean, and won't teach any bad practices.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

ob1
Very interested
Posts: 463
Joined: Wed Dec 06, 2006 9:01 am
Location: Aix-en-Provence, France

Re: The perfect "Hello World" example for new starters

Post by ob1 » Sun Apr 02, 2017 3:23 pm

Thank you very much. I've always thought this was much needed ^^

Montserrat
Very interested
Posts: 115
Joined: Fri Sep 18, 2015 2:56 pm

Re: The perfect "Hello World" example for new starters

Post by Montserrat » Mon Apr 17, 2017 11:35 am

This is much needed. I finally got some time to get back to megadrive and i was learning from your blog and other sources. Thanks for the effort.

Also again, your vdp commands in p57 are wrong,(or i am wrong?) like in your blog:

Commands:
100000 – VRAM Write
110000 – CRAM Write

and should be:

Commands:
000001 – VRAM Write
000011 – CRAM Write

source: sega2.doc

BTW got stuck cant make planes scroll for some reason :( , would you expand your new guide?

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: The perfect "Hello World" example for new starters

Post by BigEvilCorporation » Mon Apr 17, 2017 12:47 pm

Montserrat wrote: Commands:
100000 – VRAM Write
110000 – CRAM Write

and should be:

Commands:
000001 – VRAM Write
000011 – CRAM Write
Oops, looks like I just wrote the bits from the wrong end.
Montserrat wrote: BTW got stuck cant make planes scroll for some reason :( , would you expand your new guide?
Yeah I'll add to that snippet and make it scroll. Once the next demo for my game is out of the way I'll get to work on this new Hello World business properly.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: The perfect "Hello World" example for new starters

Post by BigEvilCorporation » Mon Apr 17, 2017 2:34 pm

Ok here's an updated version with better comments, all magic numbers defined using EQU, and a simple V/H scrolling example:

https://pastebin.com/FfaVsrFm

I should add a disclaimer at the top saying it's for learning purposes only and may not be the most performant or organised code. I'll continue to add improvements when I get some spare time back.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

Montserrat
Very interested
Posts: 115
Joined: Fri Sep 18, 2015 2:56 pm

Re: The perfect "Hello World" example for new starters

Post by Montserrat » Mon Apr 17, 2017 3:23 pm

thanks for the new code! ill try to get my scroll working.

Ill wait patiently for more guides ;D

MattM
Newbie
Posts: 2
Joined: Thu Apr 20, 2017 3:02 pm

Re: The perfect "Hello World" example for new starters

Post by MattM » Thu Apr 20, 2017 8:37 pm

Thanks for posting this! I had been trying out some code based on your original blog posts, which was working fine on emulators but wouldn't boot on actual hardware.

Looking forward to any updated tips.

-Matt

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: The perfect "Hello World" example for new starters

Post by BigEvilCorporation » Thu Apr 20, 2017 8:42 pm

MattM wrote:Thanks for posting this! I had been trying out some code based on your original blog posts, which was working fine on emulators but wouldn't boot on actual hardware.

Looking forward to any updated tips.

-Matt
Yeah that stuff is so old and I only had a vague idea of what I was doing, I really need to start writing them again as actual tutorials (peer reviewed and fact checked). It was more of a diary.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

MattM
Newbie
Posts: 2
Joined: Thu Apr 20, 2017 3:02 pm

Re: The perfect "Hello World" example for new starters

Post by MattM » Fri Apr 21, 2017 2:03 pm

BigEvilCorporation wrote: Yeah that stuff is so old and I only had a vague idea of what I was doing, I really need to start writing them again as actual tutorials (peer reviewed and fact checked). It was more of a diary.
It was still very useful and I learned a lot from it. Out of curiosity, what was the issue that prevented it from booting on actual hardware? I ended up borrowing some init/header code from another source which worked for me at the time, but I spent a lot of time trying to figure out the difference and wasn't able to track it down.

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: The perfect "Hello World" example for new starters

Post by BigEvilCorporation » Fri Apr 21, 2017 2:57 pm

MattM wrote:
BigEvilCorporation wrote: Yeah that stuff is so old and I only had a vague idea of what I was doing, I really need to start writing them again as actual tutorials (peer reviewed and fact checked). It was more of a diary.
It was still very useful and I learned a lot from it. Out of curiosity, what was the issue that prevented it from booting on actual hardware? I ended up borrowing some init/header code from another source which worked for me at the time, but I spent a lot of time trying to figure out the difference and wasn't able to track it down.
It was all down to the VDP registers if I remember correctly, it was a while ago though
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: The perfect "Hello World" example for new starters

Post by BigEvilCorporation » Mon Apr 02, 2018 2:37 pm

I've improved this, and started adding samples to GitHub to replace the old/buggy/poorly-informed/missing ones on my site: https://github.com/BigEvilCorporation/megadrive_samples
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

ComradeOj
Interested
Posts: 27
Joined: Sun Jun 28, 2015 4:18 pm
Contact:

Re: The perfect "Hello World" example for new starters

Post by ComradeOj » Mon Apr 16, 2018 12:43 am

I made a "hello world" assembly demo a year or two ago when working on a few programming tutorials, but never ended up posting it anywhere.
I'm not sure how it stacks up against others. I'm not really a programmer, so I have tons of bad practices. I'm sure it could have been done better, but I maybe it will help someone some day.

It can be compiled by simply running the make.bat

http://mode5.net/download/hello%20world%20example.zip
Visit my web site at http://www.mode5.net/!

Post Reply