Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2018-02-16 15:40:11

GuybrushThreepwood
Member
From: NYC
Registered: 2018-02-12
Posts: 13

Can I mix this ASM into my GBDK C so I can use this ASM Macro/Method?

It seems like BGB has a debug logger, and I'd love to use it from C.

I found this bit of ASM:

https://arvid.io/2016/03/12/debug-messa … b-and-bgb/

But I'm a total n00b at ASM, so I'm not sure what to do with it or how to compile it.

I would assume I could compile it to a .o and link it somehow, but not really sure how to go about that.

Also, I'm really confused about the ASM in general (but again, n00b)

Why does it do a LD D, D? Doesn't that do... nothing? Or am I missing something?

It seems like after that it puts two values back to back, 6446 and 0000, which I assume BGB uses to determine this is is a debug log.

Finally, I see that it copies the first parameter of the macro (which is a null terminated string IIRC), and copies it straight inline.

But, I don't really get the LD D, D and also, I'm wondering if it would be possible to somehow recreate this in C?

It seems like it relies on adding inline data in the assembly, so I looked that up.

I can't seem to get the _asm / _endasm; pair or asm() method to work. LCC seems to understand _asm and _endasm but tells me a parse error before LD.
LCC doesnt find an asm() method, and I'm not sure what header I would include for that method.

Thanks,

- Greg

Offline

 

#2 2018-02-16 16:23:11

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: Can I mix this ASM into my GBDK C so I can use this ASM Macro/Method?

Yes you can use ASM with C...
...But I don't recommend it. You'd be better off working entirely with ASM. (Since once familiar with ASM, C becomes more of a burden than a convenience)


Anyways, I'll tell you waht I know.
`ld d, d` is a convention ; the Game Boy has no built-in debug messages, so it still runs this as code. This is why it starts with a harmless operation followed by a jump to the end of the message, then some values that tell what follows (in this case, an immediate string).

It is possible to recreate this in C, Dovuro made something for that.

GBDK has its own ASM spec, whereas this one follows RGBDS' spec. This is probably why you got a parse error.

Also, to declare in-line ASM, you should see how this is done in C -- this is standard. Unless SDCC decided to do things in its own way, I don't know.


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#3 2018-02-16 17:04:24

GuybrushThreepwood
Member
From: NYC
Registered: 2018-02-12
Posts: 13

Re: Can I mix this ASM into my GBDK C so I can use this ASM Macro/Method?

ISSOtm wrote:

Yes you can use ASM with C...
...But I don't recommend it. You'd be better off working entirely with ASM. (Since once familiar with ASM, C becomes more of a burden than a convenience)

Good point. Right now I only understand assembly in principal, never actually written anything and I'm not that familiar. Only a cursory understanding. However, this game is almost done, so I would like to finish it as-is. However, I think my next GB game will be a vehicle for me to learn ASM, so I look forward to that!

ISSOtm wrote:

Anyways, I'll tell you waht I know.
`ld d, d` is a convention ; the Game Boy has no built-in debug messages, so it still runs this as code. This is why it starts with a harmless operation followed by a jump to the end of the message, then some values that tell what follows (in this case, an immediate string).

It is possible to recreate this in C, Dovuro made something for that.

Can you link me?

EDIT: NVM, found it: https://github.com/DonaldHays/bubblefac … e/src/gb.h

ISSOtm wrote:

GBDK has its own ASM spec, whereas this one follows RGBDS' spec. This is probably why you got a parse error.

Makes sense. I was looking at some GBDK examples and noticed some differences (like #0x0000 vs $0000)

ISSOtm wrote:

Also, to declare in-line ASM, you should see how this is done in C -- this is standard. Unless SDCC decided to do things in its own way, I don't know.

So two things:

1) I'm using LCC, but the GBDK BIN folder has both LCC and SDCC. I've never used SDCC before, and when I tried to compile with it, it doesn't find the GBDK libs, and doesn't accept some of the GBDK flags, for banks and such. If I need to use SDCC how do I go about it?

2) After my initial post, I did some more research and found some info on this page:

http://gbdk.sourceforge.net/guidelines.html

Which is unfortunately down for the moment, luckily I saved a copy, and it says the following regarding mixing ASM and C:

http://gbdk.sourceforge.net/guidelines.html wrote:

For mixing C and assembly, you must use one file per language (you cannot embed C code with assembly) and link both files together.

So looks like the inline stuff wont work.

Can you give me an example of how to compile an O file from the snippet I linked earlier? I'll try to change it to the GBDK asm spec, but I just don't know about compiling assembly at all.

When I tried to compile the s file, it says:

lcc.exe wrote:

$ lcc test.s
test.s:1: Error: <o> .org in REL area or directive / mnemonic error

So... idk what those mean, and also, what other things I would need to put above or below that snippit, or if it's good as-is.

Also, that snippet is apparently an Assembly macro, and from what I've read you can't call ASM macros in C. So in that case, would it need to be an ASM function? If so, that might not work since the macro needs to copy the string in-line for the ASM, if I'm understanding correctly. HMMM.


Thanks,

- Greg

Last edited by GuybrushThreepwood (2018-02-16 18:11:15)

Offline

 

#4 2018-02-17 05:26:56

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: Can I mix this ASM into my GBDK C so I can use this ASM Macro/Method?

Ah, I didn't know about LCC. I have no idea what this LCC error means. As I think is obvious enough, I hate GBDK with a burning passion, so I'm not an expert at it :p
Maybe you should look up LCC's docs ?


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#5 2018-02-24 11:02:06

Mills
Member
Registered: 2012-12-21
Posts: 132

Re: Can I mix this ASM into my GBDK C so I can use this ASM Macro/Method?

GuybrushThreepwood wrote:

When I tried to compile the s file, it says:

lcc.exe wrote:

$ lcc test.s
test.s:1: Error: <o> .org in REL area or directive / mnemonic error

I mixed a lot of asm in gbdk, that error is just a syntax error, If you upload the source I might try and compile it, but I don't have much time these days.

Last edited by Mills (2018-02-24 11:03:40)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson