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 2022-12-12 12:34:04

Djoulz
New member
Registered: 2022-12-12
Posts: 5

How to get out of APA mode ?

Hello everyone,

I'm new here (and also in GB dev). So I hope I won't ask questions already answered elsewhere.

I'm trying to code a splashscreen in APA mode (which is quite straight forward with the draw_image func), but once the player quit the splash screen everything goes mad.
It seems that draw_image set some interrupts (LCDC and VBL) which cause the screen to but cut in the center.
How can I go back to normal "tile mode" and get rid those interrupts ?

Thank you in advance.

Offline

 

#2 2022-12-16 23:28:33

RonSpain
New member
From: North Carolina
Registered: 2022-10-16
Posts: 4

Re: How to get out of APA mode ?

Hi. Have you tried mode(M_TEXT_OUT); ?

According to the GBDK 2020 manual:

"APA Graphics Mode: When this mode is used (via drawing.h) custom VBL and LCD ISRs handlers will be installed ( drawing_vbl and drawing_lcd ). Changing the mode to ( mode(M_TEXT_OUT); ) will cause them to be de-installed. These handlers are used to change the tile data source at start-of-frame and mid-frame so that 384 background tiles can be used instead of the typical 256."

Offline

 

#3 2022-12-17 03:13:01

Djoulz
New member
Registered: 2022-12-12
Posts: 5

Re: How to get out of APA mode ?

Hello RonSpain and thank you for your message.

Yes, I've tried to switch to M_TEXT_OUT, and yes, the interrupts are erased. Unfortunately this mode is worse, the VRAM is completely scrambled, there's a bunch of new inetrrupts and I can't manage to get out of this mode also !
I also tried to remove_LCD(drawing_lcd) and remove_VBL(drawing_vbl) because I saw in these functions running the debugger. I declared them as extern but the compilator runs into errors !

Offline

 

#4 2022-12-17 14:24:24

RonSpain
New member
From: North Carolina
Registered: 2022-10-16
Posts: 4

Re: How to get out of APA mode ?

I wish I could be more help for you, but I'm also new to programming for the Game Boy and have little experience with APA mode. You probably know more about that than I do right now.

The thought occurred to me that you could probably do

void(*p)(void)=0x1a89;
remove_LCD(p);

to remove an interrupt handler if the address wouldn't change. But it does change.

The remove_LCD(drawing_lcd) and remove_VBL(drawing_vbl) might not work because I think the compiler prepends a '_', so drawing_lcd in C becomes _drawing_lcd in assembly. Maybe you could use inline assembly to do that. Or maybe there's a better solution that I don't know about.

Offline

 

#5 2022-12-17 14:48:13

RonSpain
New member
From: North Carolina
Registered: 2022-10-16
Posts: 4

Re: How to get out of APA mode ?

If APA is important to you, and if no one who is more knowledgeable about these matters has a solution after they finish their holiday shopping or whatever, I'd consider two options: Code your own APA mode so you know exactly what's going on, or study the heck out of the source code for the GBDK libraries with pen and paper and such so you know exactly what's going on.

Offline

 

#6 2022-12-17 15:34:24

RonSpain
New member
From: North Carolina
Registered: 2022-10-16
Posts: 4

Re: How to get out of APA mode ?

I tried switching out of APA mode from one of my APA test programs that I had started as a pong game, and I had problems too.

But when I add the following lines just before the infinite loop in the main of the apa_image example, it seems to work fine. So if all you want to do is show a full screen splash image, maybe try using that example with this code as a template (at gbdk/examples/gb/apa_image/src).

Code:

delay(500);
mode(M_TEXT_OUT);
for(uint8_t y=0;y<16;++y){
 gotoxy(6,y);
 printf("Hello #%d\n",y);
}

Offline

 

#7 2022-12-18 03:44:31

Djoulz
New member
Registered: 2022-12-12
Posts: 5

Re: How to get out of APA mode ?

Basicaly, I wanted to use APA mode just for a splash screen at the begening of my game, prompting for "start" button press, and then fire the game in standard tile/bkg/sprite mode.
That's why I can't use the M_TEXT_OUT mode, which is good for text display but not for tiles graphics.

I fact I can use the more conventionnal way to display image with tiles (limited to 250 tiles), and stick to the standard mode, but as I'm new to this GB things, I just wanted to test everything.
The APA mode seems to be designed to display fullscreen image so it's strange that there's no simple way to switch back to normal mode.

Anyway, you're right, I will wait for someone who knows and in the meantime I will skip this part to focus on the rest of my game.
And thank you for your time and your help !

Offline

 

#8 2023-01-04 02:32:05

bbbbbr
Member
Registered: 2019-03-04
Posts: 124

Re: How to get out of APA mode ?

Yes, changing the mode will allow it to exit APA.

Scroll down a little from the top of the docs page for drawing.h:
https://gbdk-2020.github.io/gbdk-2020/d … ng_8h.html

Note: Using drawing.h will cause it's custom VBL and LCD ISRs (drawing_vbl and drawing_lcd) to be installed.
Changing the mode (mode(M_TEXT_OUT); ) will cause them to be de-installed.

Offline

 

#9 2023-01-04 03:15:02

Djoulz
New member
Registered: 2022-12-12
Posts: 5

Re: How to get out of APA mode ?

Hi bbbbbr,
Yes mode(M_TEXT_OUT) will get you out of APA mode, but unfortunatly M_TEXT_OUT is even worst. I just want to go back to "normal" start-up mode.
It seems that there're is no easy way to reset all unwanted interrupts. And moreover I begin to think that nobody here has tryed to make a splash screen with this method !
Perhaps this APA mode is just not the good way of doing this thing.

Offline

 

#10 2023-01-09 23:45:11

bbbbbr
Member
Registered: 2019-03-04
Posts: 124

Re: How to get out of APA mode ?

Perhaps Toxa knows a better way to do it (other than writing a version in asm source file), but this might work:

Code:

    // Turn off LCD Interrupt
    // This disables and then re-enables interrupts so it must be outside the critical section.
    set_interrupts(IE_REG & ~LCD_IFLAG);

    // Remove the two APA interrupt routines
    // Turn off LCD Interrupt
    // This disables and then re-enables interrupts so it must be outside the critical section.
    set_interrupts(IE_REG & ~LCD_IFLAG);

    // Remove the two APA interrupt routines (with interrupts turned off)
    CRITICAL {
        __asm \
            push BC
            push HL
            LD      BC, #.drawing_vbl
            LD      HL, #.int_0x40
            CALL    .remove_int

            LD      BC, #.drawing_lcd
            LD      HL, #.int_0x48
            CALL    .remove_int
            pop HL
            pop BC
        __endasm;
    }

Last edited by bbbbbr (2023-01-09 23:47:14)

Offline

 

#11 2023-01-10 13:34:18

toxa
Member
Registered: 2020-02-13
Posts: 305

Re: How to get out of APA mode ?

just don't use drawing.h, implement your own "APA mode" for the splash screen, that is very simple, only few lines of code.

Offline

 

#12 2023-01-12 14:48:12

Djoulz
New member
Registered: 2022-12-12
Posts: 5

Re: How to get out of APA mode ?

@bbbbbr WOW ! Great ! Works !
Many thanks ... Perhaps people at GBDK should add this method to their lib for beginers like me ...

Offline

 

#13 2023-02-25 22:44:20

M2m
Member
Registered: 2021-02-18
Posts: 27

Re: How to get out of APA mode ?

Might also have a look at Jeff Frohwein's APA demo: http://www.devrs.com/gb/asmcode.php#asmgraf

I recently made copy and 'updated' it to compile on rgbds6:

https://github.com/sttng/Jeffs-APA-Demo … ain/rgbds6

Offline

 

#14 2023-11-03 05:07:18

Kitsune64
New member
Registered: 2023-10-30
Posts: 5

Re: How to get out of APA mode ?

Hi,

I search a way to exit APA mode too. I have used drawing.h and draw_image(). But I don't have good result to get out of this mode for simply drawing sprite and background tiles like in start of a game.

I have something simple here but I don't know Why I need to put printf(" "); (with a space character for make it work).

Code:

void disable_APA(void){
    DISPLAY_OFF;
    mode(M_TEXT_OUT); 
    printf(" ");
    DISPLAY_ON;
}

That can be done also with:

Code:

void disable_APA(void){
    DISPLAY_OFF;
    mode(M_TEXT_OUT); 
    putchar(' ');
}

After it make routines for load BKG and SPRITES and show it. If someones can explain me why somes sprites stay on memory when I don't use printf(" "); or putchar(' '); ?

Here is the result in video:
APA Mode to Tile Mode

Last edited by Kitsune64 (2023-11-03 16:18:28)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson