61 lines
2.3 KiB
C
61 lines
2.3 KiB
C
/* Host check of the actual gfx_fill_rect arithmetic, with only the banked
|
|
hardware span writer substituted. check_graphics.py extracts the current
|
|
driver function into graphics_fill_under_test.h in a disposable build folder.
|
|
GPL-3.0-or-later. */
|
|
#include <assert.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "graphics.h"
|
|
typedef unsigned char byte;
|
|
#define WINDOW 0x8000
|
|
static byte back=0x1e;
|
|
static byte image[40960],reference_image[40960];
|
|
static void span(byte bank,unsigned address,byte firstMask,byte fullBytes,
|
|
byte lastMask,byte packed)
|
|
{
|
|
unsigned pos=(bank-back)*8192+address-WINDOW;
|
|
assert(pos<36000);
|
|
if(firstMask) {image[pos]=(image[pos]&~firstMask)|(packed&firstMask);++pos;}
|
|
while(fullBytes--) {assert(pos<36000);image[pos++]=packed;}
|
|
if(lastMask) {assert(pos<36000);image[pos]=(image[pos]&~lastMask)|(packed&lastMask);}
|
|
}
|
|
#include "graphics_fill_under_test.h"
|
|
|
|
static void reference(unsigned x,unsigned y,unsigned w,unsigned h,byte color)
|
|
{
|
|
unsigned xx,yy,pos,shift;
|
|
if(color>3 || x>=640 || y>=225 || !w || !h)return;
|
|
if(w>640-x)w=640-x;
|
|
if(h>225-y)h=225-y;
|
|
for(yy=y;yy<y+h;++yy)for(xx=x;xx<x+w;++xx) {
|
|
pos=yy*160+xx/4;shift=(3-xx%4)*2;
|
|
reference_image[pos]=(reference_image[pos]&~(3<<shift))|(color<<shift);
|
|
}
|
|
}
|
|
int main(void)
|
|
{
|
|
unsigned x,w,y,color,n;
|
|
uint32_t seed=12345;
|
|
static const unsigned rows[]={0,1,50,51,52,101,102,103,152,153,154,203,204,205,224};
|
|
memset(image,0x96,sizeof(image));
|
|
memset(reference_image,0x96,sizeof(reference_image));
|
|
for(n=0;n<sizeof(rows)/sizeof(rows[0]);++n) {
|
|
y=rows[n];
|
|
for(x=0;x<640;++x)for(w=1;w<=640-x;++w) {
|
|
color=(x+w+n)%4;gfx_fill_rect(x,y,w,1,color);reference(x,y,w,1,color);
|
|
assert(!memcmp(image,reference_image,sizeof(image)));
|
|
}
|
|
}
|
|
for(n=0;n<1000;++n) {
|
|
seed=seed*1664525u+1013904223u;x=seed%700;
|
|
seed=seed*1664525u+1013904223u;y=seed%260;
|
|
seed=seed*1664525u+1013904223u;w=seed%700;
|
|
seed=seed*1664525u+1013904223u;color=seed%5;
|
|
gfx_fill_rect(x,y,w,n%250,color);reference(x,y,w,n%250,color);
|
|
assert(!memcmp(image,reference_image,sizeof(image)));
|
|
}
|
|
puts("PASS graphics arithmetic: every x/width on15 edge/bank rows and1000 clipped multirow rectangles.");
|
|
return 0;
|
|
}
|