ccps icon indicating copy to clipboard operation
ccps copied to clipboard

Add support for SCR3

Open fabiensanglard opened this issue 2 years ago • 5 comments

fabiensanglard avatar Apr 18 '22 05:04 fabiensanglard

Hello, is there any chance of implementing this? I am trying to port a small demo to this platform, I've got all the sprites working as I want them to, but whatever I tried so far didn't mange to turn on the SCROLL3 layer (or any other layer in fact!)

So far I've tried the following in a project derived from post (by mostly reading the book):

  • I've put the background I want to use in the project's gfx/scr3 folder. (actually I have 2 and put them both inside the folder but I think that should be ok)
  • I've set up a struct for the SCROLL3 layer:
#define MAXSCROLL 64*64
typedef struct {
    WORD	tile;		// Sprite tile

    // 0..2 CB[0..3] Palette ID used to render the tile
    // 3 X Flip Mirrored horizontally
    // 4 Y Flip Mirrored vertically
    // 5-6 Priority group (See priority mask)
    // 7 Unused
    WORD	attributes;   	// Sprite attribute
} Scroll3;
GFXRAM Scroll3 scroll3 [MAXSCROLL] __attribute__ ((aligned (0x100))) = {};
  • I defined the layer control define:
#define CPSA_REG_SCROLL3_BASE (0x6 / 2)
// Layer control
// bit 3: Enable SCROLL1
// bit 4: Enable SCROLL2
// bit 5: Enable SCROLL3
// Cannot control STAR1
// Cannot control STAR2
// Bit 6-7: Layer to draw first
// Bit 8-9: Layer to draw second
// Bit 10-11: Layer to draw third
// Bit 12-13: Layer to draw last
// Layer IDs : OBJ=0 , SCROLL1=1 , SCROLL2=2 , SRCOLL3=3
  • In OnVsync() I added a line that (at least from what I gather from the book) should turn SCROLL3 on:
   cpsb_reg[CPSB_REG_LAYER_CONTROL] = (1 << 5) | (0 << 6) | (3 << 8);

(I also set OBJ as first layer, then SCROLL3 as second layer)

  • Then inside Draw() I added something like:
    setPalette(8, 2, &pdeka);
    int i = 0;
    for (; i < deka.numTiles; i++) {
        Scroll3* s = &scroll3[i];
        GFXShapeTile* t = &(deka.tiles[i]);
        //s->x = 196 + t->x * 16;
        //s->y = 100 + t->y * 16;
        s->tile = t->id;
        s->attributes = 2;//|  0x7 << 1 | 0x3 << 1; // Use palette 2 dim 5+1x3+1 = 6x4 tiles
    }
    scroll3[i].attributes	= 0xFF00; // Last sprite marker
  • Lastly, I modified setPalette to actually use the page parameter:
void setPalette(int page, int paletteID, const Palette* palette) {

   for (int j = 0 ; j < 16 ; j++) {
  	  palettes[paletteID].colors[j] = (*palette).colors[j];
   }

   // Request upload palette page to sprites
   cpsb_reg[CPSB_REG_PALETTE_CONTROL] = page;

   // Set palette base
   cpsa_reg[CPSA_REG_PALETTE_BASE] = (WORD)(((DWORD)palettes) >> 8);
}

Unfortunately, this still leaves me with... darkness. Only the sprite layer is visible. I am not sure if I am setting the correct palette, or the format I use for palette3 is correct, or anything other really.

Thanks in advance! I also wrote a palette fader, if you are interested I can share it with you so you can add it as a utility function.

ggnkua avatar Feb 15 '23 19:02 ggnkua

I am not actively working on scr3 but I am delighted to see you seem to be 99% there and I will help as much as I can with the time I have.

When I was working on the sprites, I found three categories of reason for darkness.

1/ The data is not in gfxrom as expected.

To solve this, I suggest to add some logs in ccps to make sure the background assets are picked up.

There is also the dumpgfx capability of ccps that should let you see if the scr3 data is there

2/ The gfxram describing the screen is not picked up by the cps-a.

For this I recompile mame with my custom printf in the Capcom cps1 video driver. If you are using Linux that should be easy to do.

3/ The scr3 palette page contains only black.

Again for this, I would have a printf to dump the palettes in mame and verify it is there.

Hope this helps. Please let me know if you have any questions.

Also, when you inevitably solve this problem, post a link to your demo. I would love to advertise what you created.

On Wed, Feb 15, 2023, 9:01 AM ggnkua @.***> wrote:

Hello, is there any chance of implementing this? I am trying to port a small demo to this platform, I've got all the sprites working as I want them to, but whatever I tried so far didn't mange to turn on the SCROLL3 layer (or any other layer in fact!)

So far I've tried the following in a project derived from post (by mostly reading the book):

  • I've put the background I want to use in the project's gfx/scr3 folder. (actually I have 2 and put them both inside the folder but I think that should be ok)
  • I've set up a struct for the SCROLL3 layer:

#define MAXSCROLL 64*64 typedef struct { WORD tile; // Sprite tile

// 0..2 CB[0..3] Palette ID used to render the tile
// 3 X Flip Mirrored horizontally
// 4 Y Flip Mirrored vertically
// 5-6 Priority group (See priority mask)
// 7 Unused
WORD	attributes;   	// Sprite attribute

} Scroll3; GFXRAM Scroll3 scroll3 [MAXSCROLL] attribute ((aligned (0x100))) = {};

  • I defined the layer control define:

#define CPSA_REG_SCROLL3_BASE (0x6 / 2) // Layer control // bit 3: Enable SCROLL1 // bit 4: Enable SCROLL2 // bit 5: Enable SCROLL3 // Cannot control STAR1 // Cannot control STAR2 // Bit 6-7: Layer to draw first // Bit 8-9: Layer to draw second // Bit 10-11: Layer to draw third // Bit 12-13: Layer to draw last // Layer IDs : OBJ=0 , SCROLL1=1 , SCROLL2=2 , SRCOLL3=3

  • In OnVsync() I added a line that (at least from what I gather from the book) should turn SCROLL3 on:

cpsb_reg[CPSB_REG_LAYER_CONTROL] = (1 << 5) | (0 << 6) | (3 << 8);

(I also set OBJ as first layer, then SCROLL3 as second layer)

  • Then inside Draw() I added something like:
setPalette(8, 2, &pdeka);
int i = 0;
for (; i < deka.numTiles; i++) {
    Scroll3* s = &scroll3[i];
    GFXShapeTile* t = &(deka.tiles[i]);
    //s->x = 196 + t->x * 16;
    //s->y = 100 + t->y * 16;
    s->tile = t->id;
    s->attributes = 2;//|  0x7 << 1 | 0x3 << 1; // Use palette 2 dim 5+1x3+1 = 6x4 tiles
}
scroll3[i].attributes	= 0xFF00; // Last sprite marker
  • Lastly, I modified setPalette to actually use the page parameter:

void setPalette(int page, int paletteID, const Palette* palette) {

for (int j = 0 ; j < 16 ; j++) { palettes[paletteID].colors[j] = (*palette).colors[j]; }

// Request upload palette page to sprites cpsb_reg[CPSB_REG_PALETTE_CONTROL] = page;

// Set palette base cpsa_reg[CPSA_REG_PALETTE_BASE] = (WORD)(((DWORD)palettes) >> 8); }

Unfortunately, this still leaves me with... darkness. Only the sprite layer is visible. I am not sure if I am setting the correct palette, or the format I use for palette3 is correct, or anything other really.

Thanks in advance! I also wrote a palette fader, if you are interested I can share it with you so you can add it as a utility function.

— Reply to this email directly, view it on GitHub https://github.com/fabiensanglard/ccps/issues/3#issuecomment-1431863475, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJJXEFCKY6XNAJH2QMJ5OTWXURXTANCNFSM5TU7I6YQ . You are receiving this because you authored the thread.Message ID: @.***>

fabiensanglard avatar Feb 15 '23 20:02 fabiensanglard

Hi again,

I made a few more experiments, so this is where I got so far:

  1. I took your advice and used dumpgfx and then inspected the generated files. Most were empty (white tiles), in a few all the tiles were filled with black colour. But the two images I used were not present anywhere
  2. As an experiment I moved my PNG images over to scr1 folder. This time dumpgfx showed the tiles from one of the images in 1-0.svg. I don't think the second image's tiles are shown. But fair enough, if I can get one image to show it would be at least progress
  3. I added some more code, equivalent to the above but relevant to SCROLL1. No luck
  4. I tried setting all palettes of the hardware to non-black. Still nothing
  5. I tried filling the SCROLL1 buffer with all tiles from 0 to 64*64-1 in hopes of it showing something, even if skewed. Sadly no luck again

This is where I'm at right now and I'm out of ideas. I suppose that the next thing to try would be to manually fill the rom files with junk, see if I can get it to show anything at all on screen.

ggnkua avatar Feb 19 '23 19:02 ggnkua

  1. I can take a look at ccps this weekend and see why the tile are not making their way to the GFX Rom.

  2. I propose that you reduce the scope of "things that may not work" and get ccps out for now. Use the project generated from post and make sure you get Ryu to show up in mame like this.

Ryu

Since post only generates a m68k rom, you can focus on getting this working while being sure the gfxrom is good. Now tweak your code until you manage to show a background tile from eithersrc1, scr2, or scr3. Again, put some printf or use mame debugger to verify that what you are doing is picked up properly.

Once you have a post project able to handle sc1/2/3 with sf2 gfxrom, we can focus on debugging further.

fabiensanglard avatar Feb 21 '23 02:02 fabiensanglard

Hi,

As suggested, I tried to modify the post example in order to enable scroll1/2/3, but unfortunately I didn't manage to succeed. Just to be sure, my modifications include:

  • Setting all palettes to non-black
  • Fill in a tileset for scroll1/2/3 and point the graphics pointers to it
  • Tried enabling all 3 layers
  • Set the scrollx/y registers
  • Set the layer order

I also tried various other things like changing the tiles attributes, writing to the hardware registers as addresses, etc. I still didn't get far.

I'm attaching the modified main.c here in hopes of someone picking up where I left it and try to fix it (or learn from my mistakes): main.zip. Otherwise, I'm afraid I'm stumped here (and don't have the time to start fiddling with the mame source code to debug this).

Thanks.

ggnkua avatar Feb 27 '23 11:02 ggnkua