[SMS] VRAM tiles and palettes quick swap.

Post Reply
VasiliyFamiliya
Member
Posts: 22
Joined: Tue Oct 04, 2022 4:25 am

[SMS] VRAM tiles and palettes quick swap.

Post by VasiliyFamiliya »

I tried to overcome the SMS VDP free tiles RAM cells amount and palettes number hardware limitation through the swapping of VRAM and palettes content before each screen refresh. Sega-Retro says, that it can be achieved with a various interrupt tricks. I found an add_pause_int and add_raster_int functions in the SMS lib, and I'd like to ask - how should I use them for the things I going to do?
My test program, which I need help with, is attached below.
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 1702
Joined: Sun Jul 15, 2007 10:01 pm

Re: [SMS] VRAM tiles and palettes quick swap.

Post by dom »

There's an example of using the rater int here: https://github.com/z88dk/z88dk/blob/mas ... bpsgtest.c

I can't at the moment remember which registers are automatically saved for you.
VasiliyFamiliya
Member
Posts: 22
Joined: Tue Oct 04, 2022 4:25 am

Re: [SMS] VRAM tiles and palettes quick swap.

Post by VasiliyFamiliya »

Chaotic flashing has ceased, but there is no any text shown.

Code: Select all

#include <stdlib.h>
#include <sms.h>
#include <stdio.h>

unsigned char title_pal[] = {0x01, 0x01, 0x3F, 0x06, 0x05, 0x16, 0x1A, 0x00,
				0x16, 0x2A, 0x1A, 0x1B, 0x3F, 0x2A, 0x2F, 0x2F};

unsigned char text1_pal[] = {0x3F, 0x00, 0x3F, 0x3E, 0x3C, 0x3D, 0x2B, 0x02,
				0x38, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

unsigned char pal2[] = {0x00, 0x03, 0x08, 0x28, 0x02, 0x22, 0x0A, 0x2A,
				0x15, 0x35, 0x1D, 0x3D, 0x17, 0x37, 0x1F, 0x3F};

extern unsigned char fontEnDe[];

extern unsigned char title[];

extern unsigned char title_map[];

void isr(void)
{
    clear_vram();
	
	load_tiles(fontEnDe, 0, 255, 4);
	load_palette(text1_pal, 0, 16);
}

void main() {
	int y = 0;

        //clear_vram();
	//load_tiles(title, 0, 143, 4);
	//load_palette(title_pal, 0, 16);
	//load_palette(pal2, 16, 16);
        set_vdp_reg(VDP_REG_FLAGS1, VDP_REG_FLAGS1_BIT7 | VDP_REG_FLAGS1_SCREEN);

	/*printf("Hello, stdio!\nIs it working?\nI hope so.");
	gotoxy(5, 5);
	printf("Hello, gotoxy(%d, %d)!", 5, 5);*/
	
	//set_bkg_map(title_map,10,8,12,12);
	
	add_raster_int(isr);

	for (;;) {
		clear_vram();
		
		load_tiles(title, 0, 143, 4);
		load_palette(title_pal, 0, 16);
		set_bkg_map(title_map,10,8,12,12);
		
		__asm__("halt");
		
		printf("Hello, stdio!\nIs it working?\nI hope so.");
		gotoxy(5, 5);
		printf("Hello, gotoxy(%d, %d)!", 5, 5);
		
		//wait_vblank_noint();
	}
}
Post Reply