Page 1 of 1

The perfect "Hello World" example for new starters

Posted: Sun Apr 02, 2017 12:56 pm
by BigEvilCorporation
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.

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

Posted: Sun Apr 02, 2017 3:23 pm
by ob1
Thank you very much. I've always thought this was much needed ^^

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

Posted: Mon Apr 17, 2017 11:35 am
by Montserrat
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?

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

Posted: Mon Apr 17, 2017 12:47 pm
by BigEvilCorporation
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.

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

Posted: Mon Apr 17, 2017 2:34 pm
by BigEvilCorporation
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.

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

Posted: Mon Apr 17, 2017 3:23 pm
by Montserrat
thanks for the new code! ill try to get my scroll working.

Ill wait patiently for more guides ;D

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

Posted: Thu Apr 20, 2017 8:37 pm
by MattM
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

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

Posted: Thu Apr 20, 2017 8:42 pm
by BigEvilCorporation
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.

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

Posted: Fri Apr 21, 2017 2:03 pm
by MattM
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.

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

Posted: Fri Apr 21, 2017 2:57 pm
by BigEvilCorporation
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

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

Posted: Mon Apr 02, 2018 2:37 pm
by BigEvilCorporation
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

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

Posted: Mon Apr 16, 2018 12:43 am
by ComradeOj
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