Skip to content

Commit

Permalink
Revert m68k drawing to fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nonarkitten committed Oct 6, 2019
1 parent 01751d2 commit 3579c80
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions src/draw_tile_m68k.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include <zlib.h>
#include "video.h"
#include "memory.h"
#include "emu.h"
#include "messages.h"
#include "screen.h"
// #include "frame_skip.h"
// #include "transpack.h"
//#include "frame_skip.h"
//#include "transpack.h"
#include <cybergraphx/cybergraphics.h>
#include <proto/cybergraphics.h>

#define PITCH 768

#define PEN_USAGE(tileno) ((((uint32_t*) memory.rom.spr_usage.p)[tileno>>4]>>((tileno&0xF)*2))&0x3)
#define PEN_USAGE(tileno) ((((Uint32*) memory.rom.spr_usage.p)[tileno>>4]>>((tileno&0xF)*2))&0x3)

typedef union {
struct {
Expand All @@ -32,20 +31,25 @@ typedef union {

extern const uint16_t ddaxskip_i[17];

//extern uint8_t line_limit[256], *limit;
extern uint8_t line_limit[256], *limit;
static uint32_t scalex;

#define DO_NOT_REORDER() asm volatile("": : :"memory")

static inline void draw_tile_m68k_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
#define INLINE static inline
#define Uint8 unsigned char
#define Uint32 unsigned long
#define TILE_INVISIBLE 1

INLINE void __attribute__((regparm(4))) draw_tile_m68k_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
packpix_t pixels0;
int16_t y = 16;
uint32_t pixel1, pixel2;

while(y--) {
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

if((pixels0.pixel = gfxdata[0])) { pixel1 = pixels0.p.p0; DO_NOT_REORDER();
pixel2 = pixels0.p.p1; DO_NOT_REORDER();
Expand All @@ -72,21 +76,21 @@ static inline void draw_tile_m68k_norm (uint32_t*palbase,uint16_t*screen,uint32
}
}
screen += PITCH / 2;
// limit++;
// }
limit++;
}
scaley <<= 1;
gfxdata += 2;
}
}
static inline void draw_tile_m68k_xflip_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_xflip_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
packpix_t pixels0;
uint16_t y = 16;
uint16_t pixel1, pixel2;

while(y--) {
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

if((pixels0.pixel = gfxdata[1])) { pixel1 = pixels0.p.p7; DO_NOT_REORDER();
pixel2 = pixels0.p.p6; DO_NOT_REORDER();
Expand All @@ -113,22 +117,22 @@ static inline void draw_tile_m68k_xflip_norm (uint32_t*palbase,uint16_t*screen,
}
}
screen += PITCH / 2;
// limit++;
// }
limit++;
}
scaley <<= 1;
gfxdata += 2;
}
}
static inline void draw_tile_m68k_yflip_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_yflip_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
packpix_t pixels0;
uint16_t y = 16;
uint16_t pixel1, pixel2;

gfxdata += 30;
while(y--) {
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

if((pixels0.pixel = gfxdata[0])) { pixel1 = pixels0.p.p0; DO_NOT_REORDER();
pixel2 = pixels0.p.p1; DO_NOT_REORDER();
Expand Down Expand Up @@ -156,22 +160,22 @@ static inline void draw_tile_m68k_yflip_norm (uint32_t*palbase,uint16_t*screen

}
screen += PITCH / 2;
// limit++;
// }
limit++;
}
scaley <<= 1;
gfxdata -= 2;
}
}
static inline void draw_tile_m68k_xyflip_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_xyflip_norm (uint32_t*palbase,uint16_t*screen,uint32_t*gfxdata,int scaley) {
packpix_t pixels0;
uint16_t y = 16;
uint16_t pixel1, pixel2;

gfxdata += 30;
while(y--) {
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

if((pixels0.pixel = gfxdata[1])) { pixel1 = pixels0.p.p7; DO_NOT_REORDER();
pixel2 = pixels0.p.p6; DO_NOT_REORDER();
Expand All @@ -198,22 +202,22 @@ static inline void draw_tile_m68k_xyflip_norm (uint32_t*palbase,uint16_t*screen
}
}
screen += PITCH / 2;
// limit++;
// }
limit++;
}
scaley <<= 1;
gfxdata -= 2;
}
}

static inline void draw_tile_m68k_xzoom (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_xzoom (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
packpix_t pixeldata;
uint16_t color, y = 16;
uint16_t* org_tilepos = tilepos;
for(;;) {
tilepos = org_tilepos;
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

pixeldata.pixel = gfxdata[0];
if(scalex & 0x8000) { if(pixeldata.p.p0) *tilepos = (uint16_t)palbase[pixeldata.p.p0]; tilepos++; }
Expand All @@ -237,24 +241,23 @@ static inline void draw_tile_m68k_xzoom (uint32_t*palbase,uint16_t*tilepos,uint

}
org_tilepos += PITCH / 2;
// limit++;
// }
limit++;
}
if(!y) break;
scaley <<= 1;
gfxdata += 2;

y -= 1;
}
}
static inline void draw_tile_m68k_xzoomX (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_xzoomX (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
packpix_t pixeldata;
uint16_t color, y = 16;
uint16_t* org_tilepos = tilepos;
for(;;) {
tilepos = org_tilepos;
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

pixeldata.pixel = gfxdata[1];
if(scalex & 0x0001) { if(pixeldata.p.p7) *tilepos = (uint16_t)palbase[pixeldata.p.p7]; tilepos++; }
Expand All @@ -278,15 +281,15 @@ static inline void draw_tile_m68k_xzoomX (uint32_t*palbase,uint16_t*tilepos,ui
}

org_tilepos += PITCH / 2;
// limit++;
// }
limit++;
}
if(!y) break;
scaley <<= 1;
gfxdata += 2;
y -= 1;
}
}
static inline void draw_tile_m68k_xzoomY (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_xzoomY (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
packpix_t pixeldata;
uint16_t color, y = 16;
uint16_t* org_tilepos = tilepos;
Expand All @@ -295,8 +298,8 @@ static inline void draw_tile_m68k_xzoomY (uint32_t*palbase,uint16_t*tilepos,ui
for(;;) {
tilepos = org_tilepos;
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

pixeldata.pixel = gfxdata[0];
if(scalex & 0x8000) { if(pixeldata.p.p0) *tilepos = (uint16_t)palbase[pixeldata.p.p0]; tilepos++; }
Expand All @@ -320,15 +323,15 @@ static inline void draw_tile_m68k_xzoomY (uint32_t*palbase,uint16_t*tilepos,ui
}

org_tilepos += PITCH / 2;
// limit++;
// }
limit++;
}
if(!y) break;
scaley <<= 1;
gfxdata -= 2;
y -= 1;
}
}
static inline void draw_tile_m68k_xzoomXY (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
INLINE void __attribute__((regparm(4))) draw_tile_m68k_xzoomXY (uint32_t*palbase,uint16_t*tilepos,uint32_t*gfxdata,int scaley) {
packpix_t pixeldata;
uint16_t color, y = 16;
uint16_t* org_tilepos = tilepos;
Expand All @@ -337,8 +340,8 @@ static inline void draw_tile_m68k_xzoomXY (uint32_t*palbase,uint16_t*tilepos,ui
for(;;) {
tilepos = org_tilepos;
if(scaley & 0x8000) {
// if(*limit < 96) {
// *limit += 1;
if(*limit < 96) {
*limit += 1;

pixeldata.pixel = gfxdata[1];
if(scalex & 0x0001) { if(pixeldata.p.p7) *tilepos = (uint16_t)palbase[pixeldata.p.p7]; tilepos++; }
Expand All @@ -361,8 +364,8 @@ static inline void draw_tile_m68k_xzoomXY (uint32_t*palbase,uint16_t*tilepos,ui
if(scalex & 0x8000) { if(pixeldata.p.p0) *tilepos = (uint16_t)palbase[pixeldata.p.p0]; tilepos++; }
}
org_tilepos += PITCH / 2;
// limit++;
// }
limit++;
}
if(!y) break;
scaley <<= 1;
gfxdata -= 2;
Expand All @@ -371,13 +374,14 @@ static inline void draw_tile_m68k_xzoomXY (uint32_t*palbase,uint16_t*tilepos,ui
}

void draw_tiles_m68k(void) {
//extern uint16_t *bufferpixels;
int sx = 0, sy = 0, oy = 0, my = 0, zx = 1, rzy = 1;
uint32_t offs, i, count, y;
uint32_t tileno, tileatr, t1, t2, t3;
unsigned int offs, i, count, y;
unsigned int tileno, tileatr, t1, t2, t3;
char fullmode = 0;
int ddax = 0, dday = 0, rzx = 15, yskip = 0;
uint8_t *vidram = memory.vid.ram;
uint8_t penusage;
Uint8 *vidram = memory.vid.ram;
Uint8 penusage;

for (count = 0; count < 0x300; count += 2) {
t3 = READ_WORD(&vidram[0x10000 + count]);
Expand Down Expand Up @@ -463,7 +467,7 @@ void draw_tiles_m68k(void) {
if (memory.nb_of_tiles > 0x40000 && tileatr & 0x40) tileno += 0x40000;

/* animation automatique */
/*if (tileatr&0x80) debug("PLOP\n");*/
/*if (tileatr&0x80) printf("PLOP\n");*/
if (tileatr & 0x8) {
tileno = (tileno&~7)+((tileno + neogeo_frame_counter)&7);
} else {
Expand Down Expand Up @@ -497,47 +501,43 @@ void draw_tiles_m68k(void) {
}

if (sx >= -16 && sx <= 336 && sy >= 0 && sy <= 240) {
if (PEN_USAGE(tileno) != 1) {
if (PEN_USAGE(tileno) != TILE_INVISIBLE) {
uint32_t color = tileatr >> 8;
uint32_t *palbase = (uint32_t*)&current_pc_pal[16 * color];
uint32_t *gfxdata = (uint32_t*)&memory.rom.tiles.p[(tileno % memory.nb_of_tiles)<<7];
uint16_t scaley = ddaxskip_i[yskip];
const int pitch = PITCH / 2;

// limit = &line_limit[sy];
if(sy < 16) {
gfxdata += (16 - sy) * 2;
sy = 16;
}
limit = &line_limit[sy];

if (rzx==16) {
if (tileatr & 0x01) {
if (tileatr & 0x02)
draw_tile_m68k_xyflip_norm(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_xyflip_norm(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
else
draw_tile_m68k_xflip_norm(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_xflip_norm(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);

} else {
if (tileatr & 0x02)
draw_tile_m68k_yflip_norm(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_yflip_norm(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
else
draw_tile_m68k_norm(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_norm(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
}
} else {
//dda_x_skip_i = ddaxskip_i[zx];
scalex = ddaxskip_i[rzx];

if (!(tileatr & 0x01)) {
if (!(tileatr & 0x02)) {
draw_tile_m68k_xzoom(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_xzoom(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
} else {
draw_tile_m68k_xzoomY(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_xzoomY(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
}
} else {
if (!(tileatr & 0x02)) {
draw_tile_m68k_xzoomX(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_xzoomX(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
} else {
draw_tile_m68k_xzoomXY(palbase, (uint16_t*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
draw_tile_m68k_xzoomXY(palbase, (unsigned short*) bufferpixels + (sy) * pitch + sx, gfxdata, scaley);
}
}
}
Expand All @@ -547,4 +547,4 @@ void draw_tiles_m68k(void) {
sy += yskip;
} /* for y */
} /* for count */
}
}

0 comments on commit 3579c80

Please sign in to comment.