Open konsumer opened 4 years ago
I think gotoxy
makes the top left corner of the screen those coordinates and then printf
prints at the top left.
I think
gotoxy
makes the top left corner of the screen those coordinates and thenprintf
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?
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 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.
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.
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.
It might be worthwhile trying to fix the issue. The newer SDCC seems to have better optimizations and support for newer features of C.
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).
wasn't the issue but see new https://github.com/Zal0/gbdk-2020
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.
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.
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?
#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.
@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.
This seems to work:
#include <gb/gb.h>
#include <gb/drawing.h>
void main () {
gotogxy(7, 8);
gprintf("O HAI!");
}
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.
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.
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.
It seems like
gotoxy()
isn't working.I compile this:
with this:
and I get this:
Am I doing it wrong?
Info:
I'm running in this docker environment.
Debian GNU/Linux 10 (buster) SDCC : 3.8.0 #10562 (Linux)