gbdk-n icon indicating copy to clipboard operation
gbdk-n copied to clipboard

gotoxy

Open konsumer opened this issue 4 years ago • 17 comments

It seems like gotoxy() isn't working.

I compile this:

#include <stdio.h>
#include <gb/gb.h>
#include <gb/console.h>

// clear the screen
void cls (void) NONBANKED;

void main () {
    DISPLAY_ON;
    cls();
    gotoxy(11, 8);
    printf("O HAI!");
}

with this:

BIN=/opt/gbdk/bin
OBJ=./obj

build:
	mkdir -p $(OBJ)
	$(BIN)/gbdk-n-compile.sh demo.c -o $(OBJ)/demo.rel
	$(BIN)/gbdk-n-link.sh $(OBJ)/demo.rel -o $(OBJ)/demo.ihx
	$(BIN)/gbdk-n-make-rom.sh $(OBJ)/demo.ihx demo.gb

clean:
	rm -rf $(OBJ)
	rm -f demo.gb

and I get this:

Screenshot from 2020-03-13 22-41-33

Am I doing it wrong?

Info:

I'm running in this docker environment.

Debian GNU/Linux 10 (buster) SDCC : 3.8.0 #10562 (Linux)

konsumer avatar Mar 14 '20 05:03 konsumer

I think gotoxy makes the top left corner of the screen those coordinates and then printf prints at the top left.

JL2210 avatar Apr 23 '20 21:04 JL2210

I think gotoxy makes the top left corner of the screen those coordinates and then printf prints at the top left.

Hmm, not in other versions of gbdk. Normally, this puts the text in the middle of the screen.

If the API is meant to be changed from the original, how would you accomplish centering this text on the screen?

konsumer avatar Apr 23 '20 22:04 konsumer

I don't know, then. But also, older versions of gbdk have issues with multiplying 1 by 32, so it could've been a bug. Not sure.

JL2210 avatar Apr 23 '20 23:04 JL2210

I don't know, then. But also, older versions of gbdk have issues with multiplying 1 by 32, so it could've been a bug. Not sure.

I'm not sure I understand. So you are saying, first that it works differently than documented, and also differently than gotoxy works in standard C library? and also that the correct behavior in the non -n version of gbdk is a bug? That seriously makes no sense.

konsumer avatar Apr 24 '20 00:04 konsumer

Sorry, you're right. I don't know what I was thinking. I wonder why this is. As far as I know, the library hasn't been changed that much from the official release of GBDK.

JL2210 avatar Apr 24 '20 01:04 JL2210

No prob.

Basically, I'm trying to figure out if I should switch to standard gbdk in my fancy docker-based gameboy dev-environment. I like that gbdk-n uses modern SDCC from the OS, rather than including a copy of an old SDCC that needs to be compiled. I wrote some code that stopped working correctly, because gotoxy doesn't work the same, which brought me here to make an issue. I think I'll make the switch, but I appreciate you taking a look.

konsumer avatar Apr 24 '20 01:04 konsumer

It might be worthwhile trying to fix the issue. The newer SDCC seems to have better optimizations and support for newer features of C.

JL2210 avatar Apr 24 '20 01:04 JL2210

I might've found the source; see https://github.com/andreasjhkarlsson/gbdk-n/commit/da61fac4066a9db3f6a208aa78526d49bd21990e#commitcomment-38708912 (and I'll go ahead and process it with maccer and create a pull request with the output if it changes anything).

JL2210 avatar Apr 24 '20 01:04 JL2210

wasn't the issue but see new https://github.com/Zal0/gbdk-2020

JL2210 avatar May 04 '20 02:05 JL2210

https://github.com/andreasjhkarlsson/gbdk-n/blob/master/libc/font.s#L514:

	.area	_CODE
	; Support routines
_gotoxy::			; Banked
	lda	hl,.BANKOV(sp)
	ld	a,(hl+)
	ld	(.curx),a
	ld	a,(hl)
	ld	(.cury),a
	ret

gotoxy() is quite short, it just sets two variables and nothing more. I stepped through it in BGB and it sets them to the correct values.

So I guess something else is broken and ignore those variables.

basxto avatar May 08 '20 02:05 basxto

I have reason to believe it's caused by the org directive. There's a Game Boy development Discord channel that I can send the link to if you're interested.

JL2210 avatar May 08 '20 02:05 JL2210

gotoxy(11, 8);
setchar('h');

This one works without a problem.

void main () {
    DISPLAY_ON;
    cls();
    printf(" ");
    gotoxy(11, 8);
    printf("O HAI!");
}

gotoxy totally works if there was a print before. What’s an org directive?

basxto avatar May 08 '20 02:05 basxto

#include <gb/drawing.h>
void main () {
    DISPLAY_ON;
    cls();
    gotogxy(11, 8);
    gprintf("O HAI!");
}

I think this is what you are looking for? I never worked with these functions, I always write my own print functions. printf is from sdcc, gotoxy, gotogxy and gprintf are from gdbk.

basxto avatar May 08 '20 02:05 basxto

@baxto that doesn't work. In my docker-env, with gbdk-n I get this:

mkdir -p ./obj
/opt/gbdk/bin/gbdk-n-compile.sh demo.c -o ./obj/demo.rel
+ sdcc -mgbz80 --no-std-crt0 -I /opt/gbdk/bin/../include -I /opt/gbdk/bin/../include/asm -c demo.c -o ./obj/demo.rel
demo.c:5: warning 112: function 'cls' implicit declaration
demo.c:4: error 20: Undefined identifier 'DISPLAY_ON'
make: *** [Makefile:6: build] Error 1

If I compile the code at the top of this issue, it doesn't error, it just doesn't work right.

Screen Shot 2020-05-08 at 3 10 31 AM

konsumer avatar May 08 '20 10:05 konsumer

This seems to work:

#include <gb/gb.h>
#include <gb/drawing.h>

void main () {
    gotogxy(7, 8);
    gprintf("O HAI!");
}
Screen Shot 2020-05-08 at 5 21 59 AM

I could have sworn that the other code worked on an old version of gbdk, but maybe not. For my own project, I'm using a tile-font and custom goto/print anyway, like you, so I suppose it doesn't matter.

konsumer avatar May 08 '20 12:05 konsumer

It would've worked in old versions if GBDK. The old GBDK had its own printf, but the printf in GBDK-n is from SDCC.

JL2210 avatar May 08 '20 13:05 JL2210

but the printf in GBDK-n is from SDCC.

That is only partially true. printf() relies on putchar() and that is implemented by gbdk-n.

basxto avatar Feb 17 '21 04:02 basxto