Hello world. It works, but... (controller interrupts?)

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

colonthree
Interested
Posts: 18
Joined: Fri Aug 07, 2009 4:07 am

Hello world. It works, but... (controller interrupts?)

Post by colonthree » Thu Feb 03, 2011 2:48 am

So I finally got a little hello world working in emulators, thought I'd try it on hardware via Everdrive, and to my delight, it worked!

A little HELLO WORLD is printed in the top left of plane a :)
However, for some reason, the Licensed by Sega Enterprises Ltd remains in the middle of the screen. Not only that, but it's fontset is replaced by mine (loaded into VRAM:0).

Is it my responsibilty to clear the message off the screen? Is it a requirement to initialise VRAM always?

Thanks
Last edited by colonthree on Sat Apr 02, 2011 1:34 am, edited 3 times in total.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Feb 03, 2011 3:17 am

:lol:

Yes, you should assume that you have to do EVERYTHING. Clear memory, clear vram, set the palettes, init the joysticks, etc. This is a console, and an old one at that. If it wasn't for the TMSS in the "newer" MegaDrives, you would really HAVE to do EVERYTHING yourself.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu Feb 03, 2011 4:05 pm

on MD1 you indeed have to clear up everything otherwise nothing will work :P
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Thu Feb 03, 2011 9:42 pm

So I finally got a little hello world working in emulators, thought I'd try it on hardware via Everdrive, and to my delight, it worked!
Have you tried Everdrive SDK ?
http://krikzz.com/pub/support/everdrive ... dk-v1.0.7z

It's very to install and it took me less than 5 minutes to compile my first app, by copying one of the example and adapt to your project. There are some basic functions to call in main() then you are set.

Here is a basic Hello world for example:

Code: Select all

int main() 
{
    VDP_init();
    VDP_loadFont(font_base, 0);
    VDP_setPaletteColor(0, 15, 0xfff);//font color (white)
    VDP_setPaletteColor(0,  0, 0x505);//bg color (purple)

    //clean screen
    VDP_fillTileRect(APLAN, 0, 0, 0, 40, 27);
    VDP_fillTileRect(BPLAN, 0, 0, 0, 40, 27);

    VDP_drawText(APLAN, "Hello World !", 0, 2, 10);
   
    while(1) VDP_waitVSync();

    return 0;
}

colonthree
Interested
Posts: 18
Joined: Fri Aug 07, 2009 4:07 am

Post by colonthree » Tue Feb 08, 2011 12:48 am

Sorry for the late reply,

Thanks for all the info!

About the everdrive sdk; i'll definitely be looking into it (right now.)
Although I'm trying to use asm over c, I'm sure the sdk will be useful :)
On that topic, why does the sdk come with some assembly apps if it's all in c?

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue Feb 08, 2011 7:23 am

because ASM rules :P

More likely because ASM is faster and its useful for some intensive tasks.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

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

Post by ob1 » Wed Feb 09, 2011 5:14 am

TmEE co.(TM) wrote:because ASM rules :P
Indeed !!!
8)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Feb 09, 2011 6:34 am

Well, it rules on GOOD processors like the 68000. :wink:

It really bites on pathetic processors like the x86. :lol:

colonthree
Interested
Posts: 18
Joined: Fri Aug 07, 2009 4:07 am

Post by colonthree » Wed Feb 09, 2011 9:21 pm

I'm familiar with the potential for efficiency when coding with asm, otherwise probably no one would still use it (?)
I was asking why there are asm compilers bundled with the sdk, considering all of the code files are written in c. Are the asm comilers still required to compile c to binary somewhere inbetween? (I've only ever compiled C on windows outputting to the command prompt.)

Oh yeah and another question came to mind;
If it wasn't for the TMSS in the "newer" MegaDrives, you would really HAVE to do EVERYTHING yourself.
What do you have to do without the TMSS? I used to have a commented disassembly of the MD2 'OS' which I guess would answer this (but I can only seem to find the bindump of it) anyone have a copy of a commented one? THanks again :)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Feb 09, 2011 10:15 pm

colonthree wrote:I'm familiar with the potential for efficiency when coding with asm, otherwise probably no one would still use it (?)
I was asking why there are asm compilers bundled with the sdk, considering all of the code files are written in c. Are the asm comilers still required to compile c to binary somewhere inbetween? (I've only ever compiled C on windows outputting to the command prompt.)
No such thing as an "asm compiler", but there are assemblers. The assembler converts assembly language into machine language. And yes, an assembler is needed because the compiler outputs assembly language.

Oh yeah and another question came to mind;
If it wasn't for the TMSS in the "newer" MegaDrives, you would really HAVE to do EVERYTHING yourself.
What do you have to do without the TMSS?
What do you have to do? Everything, of course. :lol:

Regardless of TMSS, you should always just do EVERYTHING. Clear work ram, clear vram, clear the PSG, clear the FM, set up the VDP, yada, yada, yada...

I used to have a commented disassembly of the MD2 'OS' which I guess would answer this (but I can only seem to find the bindump of it) anyone have a copy of a commented one? THanks again :)
http://www.atariage.com/forums/topic/98 ... p__1193987

colonthree
Interested
Posts: 18
Joined: Fri Aug 07, 2009 4:07 am

Post by colonthree » Wed Feb 09, 2011 10:25 pm

Chilly Willy wrote:No such thing as an "asm compiler", but there are assemblers. The assembler converts assembly language into machine language. And yes, an assembler is needed because the compiler outputs assembly language.
Ah yes, I initially wrote "assembler" and for some reason it didn't look right so I changed it.... :roll:
And good to clear that up, I assumed the C was somehow compiled directly into correctly formatted binary.
Chilly Willy wrote:Regardless of TMSS, you should always just do EVERYTHING. Clear work ram, clear vram, clear the PSG, clear the FM, set up the VDP, yada, yada, yada...
Ah so if I code with MD2 in mind, doing all the proper clearing/initialising, it should be more or less 'backwards compatible' with MD1? I'm sure there will be differences in some areas that I've read about but forgot now! >_<

Clearly, I still have much to learn :D

And thanks for the link, that's where I'd originally found it :)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Feb 09, 2011 11:58 pm

colonthree wrote:
Chilly Willy wrote:No such thing as an "asm compiler", but there are assemblers. The assembler converts assembly language into machine language. And yes, an assembler is needed because the compiler outputs assembly language.
Ah yes, I initially wrote "assembler" and for some reason it didn't look right so I changed it.... :roll:
And good to clear that up, I assumed the C was somehow compiled directly into correctly formatted binary.
Lots of words that look "funny" in programming. 8)

And there are some compilers that do output machine code... and others that output some odd intermediate language that's neither assembly, nor a "normal" language.
Chilly Willy wrote:Regardless of TMSS, you should always just do EVERYTHING. Clear work ram, clear vram, clear the PSG, clear the FM, set up the VDP, yada, yada, yada...
Ah so if I code with MD2 in mind, doing all the proper clearing/initialising, it should be more or less 'backwards compatible' with MD1? I'm sure there will be differences in some areas that I've read about but forgot now! >_<
And emulators as well.

And thanks for the link, that's where I'd originally found it :)
No problemo.

colonthree
Interested
Posts: 18
Joined: Fri Aug 07, 2009 4:07 am

Post by colonthree » Fri Feb 11, 2011 1:41 pm

Thanks again Chilly Willy!

I have other more general questions relating to programming in assembly. Probably best not to start a new thread since it follows on from my hello world thing.

I'm wondering about why programmers seem to do things like use bsr for subroutines that are only run once at the start of the ROM to initialise parts of hardware, why not just code inline? And I read it is best to use registers whenever possible over RAM access, but if you're just doing one operation to the data before putting it back into RAM, isn't it going to actually take longer?
example:

Code: Select all

move.l $ff0000, d0
addq.l #1, d0
move.l d0, $ff0000
I have seen things similar to that^ in code, but for this particular example is it not more efficient to avoid registers and just use:

Code: Select all

addq.l #1, $ff0000
i.e. how do you decide when it is best to use registers over RAM access?

I have lots of little questions like this, since this is my first asm language! :shock:

too long/noob questions/didn't read above:
How did you guys learn good asm coding practices? from example/others' work? by reading lots of asm docs? trial and error?

Any links to materials on this much appreciated! If not I'll have to keep bugging you all with noob questions!! :P
I've read quite a bit of md asm docs a lot of them might mention that it's better to use one programming method over another, but not fully go in detail why.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Feb 11, 2011 9:36 pm

colonthree wrote: I'm wondering about why programmers seem to do things like use bsr for subroutines that are only run once at the start of the ROM to initialise parts of hardware, why not just code inline? And I read it is best to use registers whenever possible over RAM access, but if you're just doing one operation to the data before putting it back into RAM, isn't it going to actually take longer?
example:

Code: Select all

move.l $ff0000, d0
addq.l #1, d0
move.l d0, $ff0000
I have seen things similar to that^ in code, but for this particular example is it not more efficient to avoid registers and just use:

Code: Select all

addq.l #1, $ff0000
i.e. how do you decide when it is best to use registers over RAM access?
The example may be compiled code - compilers often generate code that may look "odd" in assembly. Back when I worked on the Amiga, I could tell which compiler someone used just by looking at the assembly code. Compilers like to leave intermediate results in registers just in case they're used elsewhere. In the above example, maybe $ff0000 + 1 was used in the code a little further down, so it saved time OVERALL to add 1 in d0 instead of adding 1 to the memory.
I have lots of little questions like this, since this is my first asm language! :shock:

too long/noob questions/didn't read above:
How did you guys learn good asm coding practices? from example/others' work? by reading lots of asm docs? trial and error?
All of the above. :lol:

Practice... lots and lots of practice.

Any links to materials on this much appreciated! If not I'll have to keep bugging you all with noob questions!! :P
I've read quite a bit of md asm docs a lot of them might mention that it's better to use one programming method over another, but not fully go in detail why.
I just tell people to get the user manual for the CPU, then look at open source that's available.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Sat Feb 12, 2011 6:09 pm

I had prior ASM knowledge before doing 68K so it was easier for me. I started with programming in QB45 but my programs were not always fastest so I needed something to enhance them and found out how to use x86 ASM in the programs. I used some tutorials specifically made to get ASM work in the programs. Simple stuff and well written, good for me ^^

Then when I looked at MD I saw BEX and tried it but did not like it as its too far form QB45 so I went with ASM. I grabbed a bunch of Amiga newbie docs to see how code looks like and what is possible and here I am :P
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Post Reply