Page 1 of 2
Text mode after tilemaps?
Posted: Fri Sep 08, 2023 9:58 am
by Dacobi
I'm trying to create a sort of "load screen" in my game and thought about a simple black screen with just the text "LOADING".
However I can't seem to return to text mode after having used one of the layers in VERA. I tried just setting DC_VIDEO = 1, but that just gives black screen.
On the other hand it could be that the code I use to write characters to the screen is the problem.
This is my current test code:
Code: Select all
char jj,ii;
VERA.display.video = 1;
VERA.address_hi = VERA_INC_1 + 0x1;
VERA.address = 0xB000;
for(jj = 0; jj < 60; jj++){
for(ii = 0; ii < 80; ii++){
VERA.data0 = 'B';
}
}
If anyone could explain the process of setting text mode and writing chars directly to VRAM I'd really appreciate it.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 2:04 pm
by Daedalus
You can use both layers at once. If you're using both layers for your own custom tilemap and a bitmap, then use some of the tiles to spell "Loading."
In any case, the "text screen" is just a specialized tilemap. (See the VERA documentation for all the details.) It uses the second byte of the map for the colors, so you need to set the address increment to 2.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 2:33 pm
by Dacobi
You can use both layers at once. If you're using both layers for your own custom tilemap and a bitmap, then use some of the tiles to spell "Loading."
The problem is that my game uses both layers and almost all the VRAM.
I didn't know text mode was just a tilemap.
I guess I could make a 32x32 1 bpp tilemap with only 2 tiles, one with all pixels set and one with all off, and then use them to spell "LOADING". That should be a little over 2KB of VRAM.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 3:15 pm
by DragWx
The way text usually works in games is, your tile bank needs to contain alphanumeric letters, and then you just arrange those tiles onto the screen just like any other tile-based graphics. You don't need the full alphabet, just the characters necessary to display the messages you need, like "PRESS START" only needs the letters AEPRST.
"LOADING" unfortunately is seven unique letters, but if it's the only message you'd ever need to show, you can "squish" the letters together more, so they don't take up 7 tiles.
Finally, as you mentioned, if text is the only thing you need to display, you can flip the screen into 1-bit mode, and then switch to a 1-bit tile bank containing the alphanumeric characters you need to display your message. It doesn't need to be a full tile bank, it just needs to point somewhere that contains some valid 1-bit tiles, so there can be some overlap with other tile banks. Remember that one 8x8 8-bit tile uses the same memory as eight 8x8 1-bit tiles, so you might have more memory than you think.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 3:22 pm
by Dacobi
LOADING" unfortunately is seven unique letters, but if it's the only message you'd ever need to show, you can "squish" the letters together more, so they don't take up 7 tiles.
The way I meant it was to use the two tiles as pixels and then write "LOADING" as much larger letters.
Am I correct that tile and tilemap data has to be before sprite data in VRAM?
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 3:56 pm
by DragWx
Dacobi wrote: ↑Fri Sep 08, 2023 3:22 pm
Am I correct that tile and tilemap data has to be before sprite data in VRAM?
I'm not aware of any such limitation; sprite graphics supposedly can mingle with all of the rest of your data, because each sprite bitmap can be put at any address, in increments of 32 bytes. In fact, if your sprites and tiles have the same bit depth and size, you can point a sprite to data in your tile bank and it'll display just fine and vice versa, as long as the addresses line up.
Another thing is, you don't have to reserve the entire tile bank if you're not going to use all of it. Each tile in the tilemap can use one of 1024 tiles from the tile bank in 2/4/8 bit mode, but if you're only ever going to use 256 of those tiles for example, the memory for tiles 256-1023 can be reused for something else.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 4:55 pm
by Dacobi
I'm not aware of any such limitation; sprite graphics supposedly can mingle with all of the rest of your data, because each sprite bitmap can be put at any address, in increments of 32 bytes.
Ok, not sure where I got that idea.
Edit: It was this bit about sprite rendering order a long with a problem in my code that gave me the idea that sprites had to be at the end of VRAM.
Rendering Priority The sprite memory location dictates the order in which it is rendered. The sprite whose attributes are at the lowest location will be rendered in front of all other sprites; the sprite at the highest location will be rendered behind all other sprites, and so forth
Another thing is, you don't have to reserve the entire tile bank if you're not going to use all of it. Each tile in the tilemap can use one of 1024 tiles from the tile bank in 2/4/8 bit mode, but if you're only ever going to use 256 of those tiles for example, the memory for tiles 256-1023 can be reused for something else.
This I knew or to be more precise I never considered otherwise : )
The way TilemapEd stores tile data is only the tiles that are used.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 9:42 pm
by Dacobi
In any case, the "text screen" is just a specialized tilemap. (See the VERA documentation for all the details.) It uses the second byte of the map for the colors, so you need to set the address increment to 2.
Btw, where is the default character map stored? Is it a part of the ROM?
What part of the kernel will reload the character map when returning to BASIC?
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 11:02 pm
by DragWx
Dacobi wrote: ↑Fri Sep 08, 2023 9:42 pm
Btw, where is the default character map stored? Is it a part of the ROM?
What part of the kernel will reload the character map when returning to BASIC?
Calling
CINT ($FF81) will completely reset the VERA back to a Kernal-friendly text mode, including initializing VRAM and uploading the character set. This is probably the most forward-compatible thing to do.
Or, calling
screen_set_charset will upload a text-mode character set into VRAM. At the time of this writing, it gets loaded to $1F000, but the VRAM layout for Kernal routines has changed once before.
Or, at the time of this writing, ROM bank 6 contains the character sets used by the Kernal. The first 256 tiles are PETSCII (in "screen code" order, not in PETSCII order!), with the first 128 being upper/graphics, and the second 128 being lower/upper. The second 256 tiles are the ISO set. The next 512 tiles are the "thin" variants of both character sets. I don't know if the ROM banks or this data layout are final.
Re: Text mode after tilemaps?
Posted: Fri Sep 08, 2023 11:15 pm
by Daedalus
Dacobi wrote: ↑Fri Sep 08, 2023 9:42 pm
In any case, the "text screen" is just a specialized tilemap. (See the VERA documentation for all the details.) It uses the second byte of the map for the colors, so you need to set the address increment to 2.
Btw, where is the default character map stored? Is it a part of the ROM?
What part of the kernel will reload the character map when returning to BASIC?
The default character map is stored in ROM, but it's not used from there, it's copied to VRAM on startup. Restarting the machine through the SMC will restore the default map and return to BASIC.
You can also just reset the system through the System Management Controller.
Do this when you exit your program:
ldx #$42 ; I2C address
ldy #$02 ; offset for the System Management Controller
lda #$00 ; Code to reset the system
jsr $fec9 ; Execute command through the I2C.
That should reset everything to the defaults, and return to BASIC.