Hello world syntax problems

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Hello world syntax problems

Post by Munkyears » Tue Apr 28, 2009 6:24 pm

Hi, Kinda new to the whole programming aspect on the megadrive, i like you absolutely love it! my dream has always been to get some code running on native hardware.

well i have started learning asm but compiling this is getting to be a problem.

for some reason no errors appear in several assemblers. would anyone mind looking at my code and telling me whats up

Many thanks

Code: Select all

        
main
        move.l  #str,a0         
        movem.l a0,-(sp)        
        bsr     _puts           
        bra     main            


        org     $20001
str     dc.b    'Hello world',10,0

        org     $3000

    movem.l d0-d1/d7/a0/a5/a6,-(sp)

    move.l  28(sp),a5  
    move.l  a5,a6
    move.b  (a6)+,d0    
    cmp.b   #0,d0       
    beq $2     
    jmp $1      

    subq    #1,a6          
    move.w  #227,d7         
    trap    #14

    
    movem.l (sp)+,d0-d1/d7/a0/a5/a6
    rts
	END

To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

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

Post by Chilly Willy » Tue Apr 28, 2009 7:59 pm

Looks like you're trying to call some kind of OS to do the string printing. The Genesis has no such OS. You have to do everything yourself. Stef did a mini DevKit (in C) that has some "helper" code for doing things, but it counts on you already being conversant with the Genesis.

viewtopic.php?t=14

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Thu Apr 30, 2009 11:44 pm

Your print string routine seems to be missing some code <_< (the VDP data port destination, the offset added to the ascii value for the tilemap to point to the fonts/tiles in vram. etc)

Also, I think you left out some labels (shouldn't _puts be the label right after the org declaration?).

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Hi,

Post by Munkyears » Fri May 01, 2009 3:10 pm

Thanks for your replys,

@chillywilly, Thanks but i would rather do ASM just because its a new language for me. but i will give it a try....

@tomaitheous Hi, I spotted the mistake with labels yesterday, i forgot to include

"org $1000"

before main.

As for the print string routine, can you give me an example. these docs im actually learning from are ones i managed to recieve from UNI, i have taken a look a several sites such as kaneda and hacking cult but they are very outdated docs.

Also can you recommend a specific book or something which is of good use...

Many thanks for both your replys with try playing around with my code
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Sun May 03, 2009 5:28 am

Well, one simple way to do a print routine is: have all the font tiles loaded into VRAM. Take the ASCII value, subtract 0x20, then add the offset of the location in vram(don't forget this needs to be shifted like a tilemap entry would need) to that value, then write it to the tilemap entry. That's called a FWF or fixed width font routine.

The other method requires reserving a chunk of vram, having a part of the tilemap point to it, then physically write tile data to the appropriate address in the reserved block. With this method, you can directly control the placing of the font spacing (requires realtime overlaying and crossing tile boundaries), i.e. VWF or variable width font routine.

FWF saves a lot of space and is fast to do. VWF requires more vram, is more complicated and slower to implement, but looks a lot better.

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Post by Munkyears » Wed May 27, 2009 1:24 pm

Trying to recompile my code in snasm68k and it spits out just 2 errors now

same error but on two different lines

btst.b #4,d0
and
btst.b #6,d0
"Bit operations are long on data registers and byte on memory"
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

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) » Wed May 27, 2009 10:22 pm

BTST on registers is always L
you can omit B/W/L on BTST

on regs its L and on memory its B
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

plee
Very interested
Posts: 66
Joined: Wed Nov 29, 2006 11:32 am
Location: Houston, Texas

Post by plee » Thu May 28, 2009 12:44 am

Make sure you restore the stack after your call to _puts, you'll eventually crash...

movem.l a0, -(sp)
bsr _puts
movem.l (sp)+,a0

Also, I'm assuming the $1, $2 labels are defined?!?

$1
move.b (a6)+,d0
cmp.b #0,d0
beq $2
jmp $1 (can use a 'bra' here also)
$2

You can also do this

$1
move.b (a6)+,d0
bne $1

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Post by Munkyears » Thu May 28, 2009 10:04 am

Thanks again guys.

no errors so far now. BTST is very handy.

it doesnt seem to like $1, $2 when defined so i changed them to num1, num2.

as for the actual VDP, this is where i get a bit sketchy.

does the font already exist or is that included when compiling?

sorry for noobness. ASM aint easy XD
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

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

Post by Chilly Willy » Thu May 28, 2009 10:16 am

Munkyears wrote: as for the actual VDP, this is where i get a bit sketchy.
does the font already exist or is that included when compiling?
The font is just pattern data (often called cells). The pattern name table is then set with the values at the proper place to reference those patterns to display the text. This is all just data you set in the vram. I suggest you read the Genesis hardware manual section on the VDP until you're familiar with most of the terms, then ask a few questions if you couldn't puzzle something out.

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Thu May 28, 2009 2:25 pm

Munkyears wrote: as for the actual VDP, this is where i get a bit sketchy.

does the font already exist or is that included when compiling?

sorry for noobness. ASM aint easy XD
The VDP has no built in font/rom data. It's all RAM. Just upload your own font into VRAM. What size font are you looking to do? I have an few 8x8s (which are easy to find) and a 8x16/8x12 laying around somewhere. You could probably find quite a bit of font sets over at RHDN (ask nicely in the appropriate sub section ;) ).

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Post by Munkyears » Thu May 28, 2009 6:37 pm

@Tomaitheous, what is the font used for "Produced by or under licensed by Sega enterprise" at startup. i understand that its stored in the hardware but would it be possible to call it?

also how would i use it? would i call it like a header file?

eg Font.H etc...

and call the routines from inside the header?

Thanks to you all XD
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

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

Post by Chilly Willy » Thu May 28, 2009 7:05 pm

Munkyears wrote:@Tomaitheous, what is the font used for "Produced by or under licensed by Sega enterprise" at startup. i understand that its stored in the hardware but would it be possible to call it?

also how would i use it? would i call it like a header file?

eg Font.H etc...

and call the routines from inside the header?

Thanks to you all XD
That's not available on all Genesis', so you'd be better off to ignore it. I'm sure it's also compressed. Just look at example code that's out and borrow a font and some print routines. Take a look at Stef's Mini-DevKit: viewtopic.php?t=14

Munkyears
Very interested
Posts: 54
Joined: Sat Mar 21, 2009 4:24 pm
Location: Sheffield, England

Post by Munkyears » Thu May 28, 2009 7:22 pm

Thanks, would you recommend me looking at the ASM output by the C conversion. say if i write some simple print routines in C and then look at the output ? or would it be too in depth because its gonna be too messy? sorry Steph not insulting your Dev kit. :D

Looking at TMEE's Dump of TMSS and reversed engineered code it would appear that all he is doing is calling it and reading it from memory and it doesnt appear to be editable.

Dont know about compression though. Maybe TMEE can give me some advice on how he wrote it
To be this good takes ages, To be this good takes Stef, Kanedafr, ChillyWilly & everyone who has helped me discover what hardwork is!

Dive into the SpritesMind! :)

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 May 28, 2009 7:28 pm

the font in TMSS is uncompressed straight 8x8 tiles to be loaded into VRAM without any modifications...
TMSS is not present in all MDs, and you cannot touch the TMSS as easily (you need to copy your code into RAM then execute it there, then page out the ROM so you can see TMSS and then do your magic... and that magic only works on later MD1s, MD2s and Genny3 only (and compatibles with TMSS)).

You can copy the DC.Ls though into your own ASM file and use it... you only have uppercase letters and nothing more...
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