import: blit code generator (WIP) pei code-gen can be optmized more
This commit is contained in:
parent
0f4346d382
commit
7ad65f0f9c
|
@ -0,0 +1,151 @@
|
|||
#--------------------------------------------------------
|
||||
# $File: Makefile,v $
|
||||
#
|
||||
# $Date: 2018/08/21 $
|
||||
# $Author: jandersen $
|
||||
# $Revision: #1 $
|
||||
#--------------------------------------------------------
|
||||
#
|
||||
# blit GCC-Gnu Makefile
|
||||
#
|
||||
# Generate Back Buffer Blit Code
|
||||
#
|
||||
SHELL = /bin/sh
|
||||
MKDIR = mkdir
|
||||
|
||||
TARGET = blit
|
||||
|
||||
PROJROOT = .
|
||||
|
||||
#SYSTEM = /usr
|
||||
#SYSLIBDIR = $(SYSTEM)/lib
|
||||
#SYSINCDIR = $(SYSTEM)/include
|
||||
|
||||
INCCMD = -I$(SYSINCDIR)
|
||||
INCCMD += -I$(PROJROOT)/source
|
||||
INCCMD += -I$(PROJROOT)/include
|
||||
|
||||
OBJDIR = $(PROJROOT)/obj
|
||||
DEPDIR = $(PROJROOT)/dep
|
||||
LSTDIR = $(PROJROOT)/lst
|
||||
|
||||
#
|
||||
# Special GnuMake Search Path Directive
|
||||
#
|
||||
VPATH = $(PROJROOT)/source
|
||||
|
||||
#
|
||||
# Dedicated Search Paths for Specific Types
|
||||
#
|
||||
# Can be used to speed up compile by using this feature
|
||||
# for each filetype (reducing the amount of searching)
|
||||
#
|
||||
vpath %.o $(OBJDIR)
|
||||
vpath %.d $(DEPDIR)
|
||||
|
||||
LIBCMD +=-lm
|
||||
|
||||
OBJS := blit.o
|
||||
OBJS += rawdata.o
|
||||
|
||||
# change list of .o's into a list of .d's
|
||||
|
||||
DEPS := $(OBJS:%.o=%.d)
|
||||
|
||||
AS = gcc
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
RM = /bin/rm -rfv
|
||||
|
||||
CFLAGS = -O2 -Wall -Werror -Wa,-al -fno-common
|
||||
CXXFLAGS = -O2 -Wall -Werror -Wa,-al -fno-common
|
||||
ASFLAGS = -c -xassembler-with-cpp -Wa,-al
|
||||
LDFLAGS = -Wl,-Map,$(TARGET).map $(LIBCMD)
|
||||
|
||||
# Clear Default Suffixes
|
||||
.SUFFIXES:
|
||||
# Set my Own Suffixes
|
||||
.SUFFIXES: .c .s .cc .d .o
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(DEPS) $(OBJS) $(LIBS)
|
||||
$(LD) -o $@ $(addprefix $(OBJDIR)/,$(OBJS)) $(LIBS) $(LDFLAGS)
|
||||
|
||||
# Object Rules
|
||||
|
||||
.s.o:
|
||||
$(AS) $(ASFLAGS) $(TMPFLAGS) $(INCCMD) -o $(OBJDIR)/$@ $< > $(LSTDIR)/$*.lst
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(TMPFLAGS) $(INCCMD) -c $< -o $(OBJDIR)/$*.o > $(LSTDIR)/$*.lst
|
||||
|
||||
.cc.o:
|
||||
$(CC) $(CXXFLAGS) $(TMPFLAGS) $(INCCMD) -c $< -o $(OBJDIR)/$*.o > $(LSTDIR)/$*.lst
|
||||
|
||||
# Dependencie Rules
|
||||
#
|
||||
# for now just touch, to create the file if its not defined
|
||||
#
|
||||
.s.d:
|
||||
touch $(DEPDIR)/$*.d
|
||||
|
||||
.c.d:
|
||||
set -e; $(CC) -M $(CFLAGS) $(INCCMD) $< \
|
||||
| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $(DEPDIR)/$@; \
|
||||
[ -s $(DEPDIR)/$@ ] || rm -f $(DEPDIR)/$@
|
||||
|
||||
.cc.d:
|
||||
set -e; $(CC) -M $(CXXFLAGS) $(INCCMD) $< \
|
||||
| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $(DEPDIR)/$@; \
|
||||
[ -s $(DEPDIR)/$@ ] || rm -f $(DEPDIR)/$@
|
||||
|
||||
.PHONY: install
|
||||
install: $(TARGET)
|
||||
cp $(TARGET).exe $(PROJROOT)/../bin
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(RM) $(OBJDIR) *.o $(DEPDIR) *.map $(LSTDIR) $(TARGET) $(TARGET).exe
|
||||
|
||||
|
||||
########################################
|
||||
#
|
||||
# HELPER TARGET RULES
|
||||
#
|
||||
########################################
|
||||
|
||||
#
|
||||
# Target that forces all of the objects to be rebuilt if the makefile changes
|
||||
#
|
||||
|
||||
$(OBJS) : Makefile
|
||||
$(DEPS) : Makefile
|
||||
#
|
||||
# Targets that create the output object directory if it doesn't already exist
|
||||
#
|
||||
|
||||
Makefile : $(OBJDIR) $(DEPDIR) $(LSTDIR)
|
||||
|
||||
$(OBJDIR) :
|
||||
$(MKDIR) $(OBJDIR)
|
||||
|
||||
#
|
||||
# Targets that create the output dependency directory if it doesn't already exist
|
||||
#
|
||||
|
||||
$(DEPDIR) :
|
||||
$(MKDIR) $(DEPDIR)
|
||||
|
||||
#
|
||||
# Targets that create the output list directory if it doesn't already exist
|
||||
#
|
||||
|
||||
$(LSTDIR) :
|
||||
$(MKDIR) $(LSTDIR)
|
||||
|
||||
#
|
||||
# Generated Dependencie Files
|
||||
#
|
||||
-include $(wildcard $(DEPDIR)/*.d)
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
bctypes.h
|
||||
|
||||
Budcat Standard Types
|
||||
|
||||
(c) 2001-2006 Budcat Creations, LLC.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _bctypes_h
|
||||
#define _bctypes_h
|
||||
|
||||
typedef signed char i8;
|
||||
typedef unsigned char u8;
|
||||
typedef signed short i16;
|
||||
typedef unsigned short u16;
|
||||
typedef signed long i32;
|
||||
typedef unsigned long u32;
|
||||
|
||||
#if !_MSVC
|
||||
typedef signed long long i64;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
//typedef int i128 __attribute__ ((__mode__(__TI__))); // 128 bit integer
|
||||
//typedef int s128 __attribute__ ((__mode__(__TI__))); // 128 bit signed integer
|
||||
//typedef unsigned int u128 __attribute__ ((__mode__(__TI__))); // 128 bit unsigned integer
|
||||
#endif
|
||||
|
||||
typedef i32 bool;
|
||||
|
||||
typedef float f32;
|
||||
typedef float r32;
|
||||
typedef double f64;
|
||||
typedef double r64;
|
||||
|
||||
|
||||
#define false (0)
|
||||
#define true (!false)
|
||||
|
||||
#define null (0)
|
||||
|
||||
// Odd Types
|
||||
typedef union {
|
||||
// u128 ul128;
|
||||
u64 ul64[2];
|
||||
u32 ui32[4];
|
||||
} QWdata;
|
||||
|
||||
|
||||
#endif // _bctypes_h
|
||||
|
||||
// EOF - bctypes.h
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
#--------------------------------------------------------
|
||||
# $File: blit.c,v $
|
||||
#--------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "bctypes.h"
|
||||
#include "blit.h"
|
||||
#include "rawdata.h"
|
||||
|
||||
RAWDATA* gResult = NULL;
|
||||
|
||||
void AddString(RAWDATA* pRaw, char* pString)
|
||||
{
|
||||
size_t len = strlen(pString);
|
||||
|
||||
size_t newlen = len+pRaw->size;
|
||||
|
||||
pRaw->data = (unsigned char*) realloc(pRaw->data, newlen);
|
||||
|
||||
memcpy(pRaw->data + pRaw->size, pString, len);
|
||||
|
||||
pRaw->size = newlen;
|
||||
}
|
||||
|
||||
int AddLine(char*pLabel,char*pInst,char*pExp,int val,int clocks)
|
||||
{
|
||||
if (gResult)
|
||||
{
|
||||
char temp[256];
|
||||
char pArg[256];
|
||||
|
||||
memset(pArg,0,256);
|
||||
sprintf(pArg,pExp,val);
|
||||
|
||||
sprintf(temp, "%8s %3s %s\n", pLabel,pInst,pArg);
|
||||
|
||||
AddString(gResult, temp);
|
||||
}
|
||||
|
||||
return clocks;
|
||||
}
|
||||
|
||||
//
|
||||
// Call it with A = 0
|
||||
// And the S set to the DPage Table in memory
|
||||
//
|
||||
void CompileBlockTRB(RAWDATA *result, int x, int width)
|
||||
{
|
||||
int clocks = 0;
|
||||
|
||||
//clocks += AddLine("","TCD"," ; Set DP ",0,2);
|
||||
//clocks += AddLine("","TXA"," ; Zero out A", 0,2);
|
||||
clocks += AddLine("","PLD"," ; Set DP", 0,4);
|
||||
|
||||
|
||||
for (int y = 0; y < 8; ++y)
|
||||
{
|
||||
int p = y * 160;
|
||||
|
||||
//for (int xs = x; xs < (x+width) ; xs+=4)
|
||||
for (int xs = 0; xs < 320; xs+=4)
|
||||
{
|
||||
int xbyte = (xs>>1) + p;
|
||||
|
||||
if ((0 == (xbyte&0xFF)) && y)
|
||||
{
|
||||
clocks += AddLine("","PLD"," ; Set DP", 0,4);
|
||||
|
||||
//clocks += AddLine("","TDC"," ; Set DP ",0,2);
|
||||
//clocks += AddLine("","ADC","#$100",0,3);
|
||||
//clocks += AddLine("","TCD"," ; Set DP ",0,2);
|
||||
//clocks += AddLine("","TXA"," ; Zero out A", 0,2);
|
||||
}
|
||||
|
||||
if ((xs>=x)&&(xs<(x+width)))
|
||||
{
|
||||
clocks += AddLine("","TRB","$%02X",xbyte&0xFF,7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clocks += AddLine("","RTL"," ;%d cycles",clocks+6,6);
|
||||
}
|
||||
|
||||
RAWDATA* CompileTRB()
|
||||
{
|
||||
RAWDATA* result = (RAWDATA*)malloc(sizeof(RAWDATA));
|
||||
memset(result, 0, sizeof(RAWDATA));
|
||||
|
||||
char temp_label[256];
|
||||
|
||||
gResult = result;
|
||||
|
||||
int screen_width = 320;
|
||||
int width = 320;
|
||||
int pixel_step = 8; // x position granularity
|
||||
int pixel_block = 8; // min width
|
||||
|
||||
while (width >= pixel_block)
|
||||
{
|
||||
for (int x = 0; x <= (screen_width - width); x+=pixel_step)
|
||||
{
|
||||
printf(temp_label,"blit%d_%d\n", x, width);
|
||||
sprintf(temp_label,"blit%d_%d\n", x, width);
|
||||
AddString(result, temp_label);
|
||||
CompileBlockTRB(result, x, width);
|
||||
}
|
||||
width -= pixel_block;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
lda #$2000
|
||||
tcd
|
||||
lda #$20FF
|
||||
tcs
|
||||
pei $fe
|
||||
pei $fc
|
||||
pei $f8
|
||||
....
|
||||
....
|
||||
pei $02
|
||||
pei $00
|
||||
inc
|
||||
tcd
|
||||
adc #$FF
|
||||
tcs
|
||||
..........
|
||||
|
||||
For regions less than the page width, go line by line
|
||||
|
||||
call with X
|
||||
|
||||
*/
|
||||
void CompileBlockPEI(RAWDATA *result, int x, int width)
|
||||
{
|
||||
int clocks = 0;
|
||||
|
||||
clocks += AddLine("","TCD"," ; Set DP ",0,2);
|
||||
clocks += AddLine("","ADC","#%d",((x+width)>>1)+1,3);
|
||||
clocks += AddLine("","TCS","",0,2);
|
||||
|
||||
int dp = 0;
|
||||
|
||||
for (int y = 0; y < 8; ++y)
|
||||
{
|
||||
int p = y * 160;
|
||||
|
||||
//for (int xs = x; xs < (x+width) ; xs+=4)
|
||||
for (int xs = 316; xs >= 0; xs-=4)
|
||||
{
|
||||
int xbyte = (xs>>1) + p;
|
||||
|
||||
#if 0
|
||||
if ((0 == (xbyte&0xFF)) && y)
|
||||
{
|
||||
clocks += AddLine("","TDC"," ; Set DP ",0,2);
|
||||
clocks += AddLine("","ADC","#$100",0,3);
|
||||
clocks += AddLine("","TCD"," ; Set DP ",0,2);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((xs>=x)&&(xs<(x+width)))
|
||||
{
|
||||
if ((dp & 0xFF00) != (xbyte & 0xFF00))
|
||||
{
|
||||
int delta = (xbyte&0xFF00) - (dp & 0xFF00);
|
||||
if (delta < 0)
|
||||
{
|
||||
delta--; // need a fudge because of carry
|
||||
}
|
||||
clocks += AddLine("", "TDC", " ; Set DP ", 0, 2);
|
||||
clocks += AddLine("","ADC","#%d",delta,3);
|
||||
clocks += AddLine("","TCD"," ; Set DP ",0,2);
|
||||
}
|
||||
clocks += AddLine("", "PEI", "$%02X", xbyte & 0xFF, 6);
|
||||
dp = xbyte;
|
||||
}
|
||||
}
|
||||
|
||||
if (y < 7)
|
||||
{
|
||||
clocks += AddLine("","TSC"," ;",0,2);
|
||||
clocks += AddLine("","ADC","#%d",160+(width>>1),3);
|
||||
clocks += AddLine("","TCS"," ; Set Stack ",0,2);
|
||||
}
|
||||
}
|
||||
|
||||
clocks += AddLine("","RTL"," ;%d cycles",clocks+6,6);
|
||||
}
|
||||
|
||||
RAWDATA* CompilePEI()
|
||||
{
|
||||
RAWDATA* result = (RAWDATA*)malloc(sizeof(RAWDATA));
|
||||
memset(result, 0, sizeof(RAWDATA));
|
||||
|
||||
char temp_label[256];
|
||||
|
||||
gResult = result;
|
||||
|
||||
int screen_width = 320;
|
||||
int width = 320;
|
||||
int pixel_step = 8; // x position granularity
|
||||
int pixel_block = 8; // min width
|
||||
|
||||
while (width >= pixel_block)
|
||||
{
|
||||
for (int x = 0; x <= (screen_width - width); x+=pixel_step)
|
||||
{
|
||||
printf(temp_label,"blit%d_%d\n", x, width);
|
||||
sprintf(temp_label,"blit%d_%d\n", x, width);
|
||||
AddString(result, temp_label);
|
||||
CompileBlockPEI(result, x, width);
|
||||
}
|
||||
width -= pixel_block;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void _usage()
|
||||
{
|
||||
printf("blit v%s\n\n", VERSION);
|
||||
printf("Usage: blit\n"
|
||||
"Written by Jason Andersen\n"
|
||||
"Copyright (c) 2018 Jason Andersen.\n"
|
||||
"Unauthorized use prohibited\n");
|
||||
|
||||
exit(1);
|
||||
|
||||
} // usage
|
||||
|
||||
|
||||
//
|
||||
// Parse command line options
|
||||
//
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Check Arguments
|
||||
while (--argc > 0 && (*++argv)[0] == '-')
|
||||
{
|
||||
*argv+=1;
|
||||
|
||||
if (strcmp("v", *argv) == 0)
|
||||
{
|
||||
printf("blit v%s\n", VERSION);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
*argv+= strlen(*argv); // skip rest of string
|
||||
}
|
||||
|
||||
if (argc) _usage();
|
||||
|
||||
RAWDATA* pBlitTRB = CompileTRB();
|
||||
saveRaw(pBlitTRB, "trb.txt");
|
||||
|
||||
RAWDATA* pBlitPEI = CompilePEI();
|
||||
saveRaw(pBlitPEI, "pei.txt");
|
||||
|
||||
printf("\nblit - Processing complete.\n");
|
||||
|
||||
exit(0);
|
||||
|
||||
} // main
|
||||
|
||||
// eof - blit.c
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
#--------------------------------------------------------
|
||||
# $File: blit.h,v $
|
||||
# $Author: jandersen $
|
||||
# $Revision: #1 $
|
||||
#--------------------------------------------------------
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _blit_h
|
||||
#define _blit_h
|
||||
|
||||
#define VERSION "1.00"
|
||||
|
||||
#endif // _blit_h
|
||||
|
||||
// EOF - blit.h
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "rawdata.h"
|
||||
|
||||
|
||||
RAWDATA* loadRaw(const char* path)
|
||||
{
|
||||
FILE* rawFile = fopen( path, "rb" );
|
||||
|
||||
if (rawFile)
|
||||
{
|
||||
RAWDATA* pData = (RAWDATA*)malloc(sizeof(RAWDATA));
|
||||
|
||||
fseek(rawFile, 0, SEEK_END);
|
||||
pData->size = ftell(rawFile);
|
||||
|
||||
fseek(rawFile, 0, SEEK_SET);
|
||||
|
||||
pData->data = (unsigned char*)malloc(pData->size);
|
||||
|
||||
size_t read_size = fread(pData->data, 1, pData->size, rawFile);
|
||||
|
||||
if (read_size != pData->size)
|
||||
{
|
||||
printf("WARNING: read %ld of %ld bytes\n", read_size, pData->size);
|
||||
}
|
||||
|
||||
fclose(rawFile);
|
||||
|
||||
return pData;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void saveRaw(RAWDATA* pData, const char* path)
|
||||
{
|
||||
FILE* rawFile = fopen( path, "wb" );
|
||||
|
||||
if (rawFile)
|
||||
{
|
||||
fwrite(pData->data, 1, pData->size, rawFile);
|
||||
fclose(rawFile);
|
||||
}
|
||||
}
|
||||
|
||||
// rawdata.c
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
#ifndef _rawdata_h_
|
||||
#define _rawdata_h_
|
||||
|
||||
#include "bctypes.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned char* data; // pointer to data
|
||||
size_t size; // size in bytes
|
||||
} RAWDATA;
|
||||
|
||||
|
||||
RAWDATA* loadRaw(const char* path);
|
||||
void saveRaw(RAWDATA* pData, const char* path);
|
||||
|
||||
#endif //_rawdata_h_
|
Loading…
Reference in New Issue