import: sample OMF application

This commit is contained in:
dwsJason 2020-02-25 21:11:24 -05:00
parent fd1bc0ba76
commit 1f61d948fb
32 changed files with 37978 additions and 0 deletions

View File

@ -0,0 +1,91 @@
#
# fun2gs/Makefile
#
# This makefile was created by Jason Andersen
#
# I build on Windows-10 64-bit, this makefile is designed to run under
# a Windows-10 Command Prompt, and makes use of DOS shell commands
#
# In order to build this you need x65
#
# https://github.com/Sakrac/x65
#
# As far a free stuff, I setup a c:\bin directory, in my path
# the following packages and executables are in there
#
# Fine Tools from Brutal Deluxe
# http://www.brutaldeluxe.fr/products/crossdevtools/
# Cadius.exe
# Merlin32.exe
# OMFAnalyzer.exe
# LZ4.exe
#
# gnumake-4.2.1-x64.exe (with a symbolic link that aliases this to "make")
#
# https://apple2.gs/plus/
# gsplus32.exe (KEGS based GS Emulator fork by Dagen Brock)
# I configure this to boot the xrick.po image directly
# once that's done "make run" will build, update the disk image
# and boot into xrick2gs.
#
# Make and Build Variables
TARGETNAME = fun2gs
VPATH = src:obj
ASMFILES = $(wildcard asm/*.s)
OBJFILES += $(patsubst asm/%.s,obj/%.x65,$(ASMFILES))
ASM = x65
ASMFLAGS = -lst
# List of directories to create
DIRS=obj
help:
@echo.
@echo $(TARGETNAME) Makefile
@echo -------------------------------------------------
@echo build commands:
@echo make gs - Apple IIgs
@echo make image - Build Bootable .PO File
@echo make run - Build / Run IIgs on emulator
@echo make clean - Clean intermediate/target files
@echo make depend - Build dependencies
@echo -------------------------------------------------
@echo.
$(TARGETNAME).sys16: $(OBJFILES)
$(ASM) link.s $(TARGETNAME).sys16 -iobj -a2o -sym x65.sym -lst
gs: $(TARGETNAME).sys16
disk image: gs
@echo Updating $(TARGETNAME).po
@echo Remove $(TARGETNAME).sys16
cadius deletefile $(TARGETNAME).po /$(TARGETNAME)/$(TARGETNAME).sys16
@echo Add $(TARGETNAME).sys16
cadius addfile $(TARGETNAME).po /$(TARGETNAME) ./$(TARGETNAME).sys16
run: image
gsplus32
clean:
@echo Remove $(TARGETNAME).sys16
$(shell if exist $(TARGETNAME).sys16 echo Y | del $(TARGETNAME).sys16)
@echo Remove Intermediate Files
@del /q obj\*
depend:
@echo TODO - make dependencies
# Generic Rules
#objdir: obj
obj/%.x65 : asm/%.s
@echo Assembling $(<F)
$(ASM) $< -cpu=65816 -imacros -idata -obj $@ $(ASMFLAGS)
# Create all the directories
$(shell if not exist $(DIRS) mkdir $(DIRS))

View File

@ -0,0 +1 @@
FUN2GS.SYS16=Type(B3),AuxType(DB07),VersionCreate(24),MinVersion(00),Access(21),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000)

View File

@ -0,0 +1,7 @@
xdef background.c1
section background, Data
background.c1:
incbin "background.c1"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,173 @@
*
* ORCA/M Format!!
* LZ4 Decompress by Brutal Deluxe!!!
*
include common.i
include dp.s
mx %00
xdef unpacklz4
xdef LZ4_Unpack
unpacklz4:
{
if 1
phb
phk
plb
sep #$20
lda dp.source+2
xba
lda dp.dest+2
rep #$31
tax
lda dp.dest
sta LZ4_Dst+1
plb
endif
rts
}
*
* int LZ4_Unpack(u8* pDest, u8* pPackedSource);
*
LZ4_Unpack start ASMCODE
pDest equ 5
pPackedSource equ 9
phb
phk
plb
sep #$20
lda pPackedSource+2,s ; Pull out the src/dst banks
xba
lda pDest+2,s ; Pull out the src/dst banks
rep #$31
tax ; Temp save in X
lda pDest,s
sta LZ4_Dst+1
lda pPackedSource+1,s ; address of packed source + 4, is the unpacked len
sta upl+2
lda pPackedSource,s
adc #12
sta upl+1
upl lda >0 ; packed length
adc #16 ; 16 bytes for packed buffer header
adc pPackedSource,s ; start of packed buffer
tay ; y has the pack data stop address
anop ; 1st packed Byte offset
lda pPackedSource,s ; skip 16 byte header on the source
adc #16
pha
txa
plx
jsr ASM_LZ4_Unpack
tay
anop ; Copy the Return address
lda 1,s
sta pPackedSource,s
lda 3,s
sta pPackedSource+2,s
tsc
sec
sbc #-8
tcs
tya ; return length
plb
rtl
*-------------------------------------------------------------------------------
ASM_LZ4_Unpack STA LZ4_Literal_3+1 ; Uncompress a LZ4 Packed Data buffer (64 KB max)
SEP #$20 ; A = Bank Src,Bank Dst
STA LZ4_Match_5+1 ; X = Header Size = 1st Packed Byte offset
STA LZ4_Match_5+2 ; Y = Pack Data Size
XBA ; => Return in A the length of unpacked Data
STA LZ4_ReadToken+3
STA LZ4_Match_1+3
STA LZ4_GetLength_1+3
REP #$30
STY LZ4_Limit+1
*--
LZ4_Dst LDY #$0000 ; Init Target unpacked Data offset
LZ4_ReadToken LDA >$AA0000,X ; Read Token Byte
INX
STA LZ4_Match_2+1
*----------------
LZ4_Literal AND #$00F0 ; >>> Process Literal Bytes <<<
BEQ LZ4_Limit ; No Literal
CMP #$00F0
BNE LZ4_Literal_1
JSR LZ4_GetLengthLit ; Compute Literal Length with next bytes
BRA LZ4_Literal_2
LZ4_Literal_1 LSR A ; Literal Length use the 4 bit
LSR A
LSR A
LSR A
*--
LZ4_Literal_2 DEC A ; Copy A+1 Bytes
LZ4_Literal_3 MVN $AA,$BB ; Copy Literal Bytes from packed data buffer
PHK ; X and Y are auto incremented
PLB
*----------------
LZ4_Limit CPX #$AAAA ; End Of Packed Data buffer ?
BEQ LZ4_End
*----------------
LZ4_Match TYA ; >>> Process Match Bytes <<<
SEC
LZ4_Match_1 SBC >$AA0000,X ; Match Offset
INX
INX
STA LZ4_Match_4+1
*--
LZ4_Match_2 LDA #$0000 ; Current Token Value
AND #$000F
CMP #$000F
BNE LZ4_Match_3
JSR LZ4_GetLengthMat ; Compute Match Length with next bytes
LZ4_Match_3 CLC
ADC #$0003 ; Minimum Match Length is 4 (-1 for the MVN)
*--
PHX
LZ4_Match_4 LDX #$AAAA ; Match Byte Offset
LZ4_Match_5 MVN $BB,$BB ; Copy Match Bytes from unpacked data buffer
PHK ; X and Y are auto incremented
PLB
PLX
*----------------
BRA LZ4_ReadToken
*----------------
LZ4_GetLengthLit LDA #$000F ; Compute Variable Length (Literal or Match)
LZ4_GetLengthMat STA LZ4_GetLength_2+1
LZ4_GetLength_1 LDA >$AA0000,X ; Read Length Byte
INX
AND #$00FF
CMP #$00FF
BNE LZ4_GetLength_3
CLC
LZ4_GetLength_2 ADC #$000F
STA LZ4_GetLength_2+1
BRA LZ4_GetLength_1
LZ4_GetLength_3 ADC LZ4_GetLength_2+1
RTS
*----------------
LZ4_End TYA ; A = Length of Unpack Data
RTS
*-------------------------------------------------------------------------------
end

View File

@ -0,0 +1,380 @@
*----- Merlin 16+ Directives
rel
dsk start.l
include common.i
; SECTION code
dbg XREF dbgprint_char
XREF background.c1
STRING FontOrder = " !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
start ent
mx %00 ; assemble in 16 bit
rel ; Build a relocated S16 file
include Locator.Macs.s ; Macro Definition Files
include Mem.Macs.s
include Misc.Macs.s
include Util.Macs.s
include Sound.Macs.s
*----- Begin Of Program ----------
PHK ; Data Bank Register = Program Bank Register
PLB
; A has UserID
sta myID
bra .next
; work around OMF export bug
dc.t start
.next
; D = direct page address
; S = Stack Pointer
tsx
stx |mySP
tdc
sta |myDP
sec
tsc
sbc |myDP
inc ; Count byte # 0
sta |myBank0Size
JSR ToolInit ; Init Tools + Compact Memory + Ask Shadowing
JSR BackupEnv ; Backup environment (colors...)
*----- Your Code Starts Here ----------
phb
lda #$7FFF ; Length - 1
ldx #<background.c1 ; source address
ldy #$2000 ; dest address
mvn ^$e12000,^background.c1 ; dst/src addresses
plb
{
ldy #$2000+(32*160)
jsr PrintE1
text "Stack ADDR:"
dc.b 0
ldy #$2000+(40*160)
jsr PrintE1
text " DP ADDR:"
dc.b 0
ldy #$2000+(48*160)
jsr PrintE1
text "Bank0 Size:"
dc.b 0
ldy #$2000+(80*160)+(4*0)
jsr PrintE1
text "[Press any key to Quit]"
dc.b 0
ldy #$2000+(16*160)
jsr PrintE1
text "x65 OMF Test App"
dc.b 0
}
{
pool zpWork $e0-$100
zpWork zpCharNum.w
phb
* get us into bank e1
pea $e1e1
plb
plb
lda #32
ldy #$2000
clc
.loop
sta <zpCharNum
jsr dbgprint_char
tya
adc #4
tay
lda <zpCharNum
inc
cmp #64
bcc .loop
plb
}
{
pea $e1e1
plb
plb
ldy #$2000+(32*160)+(4*12)
lda >mySP
jsr PrintHEX
ldy #$2000+(40*160)+(4*12)
lda >myDP
jsr PrintHEX
ldy #$2000+(48*160)+(4*12)
lda >myBank0Size
jsr PrintHEX
phk
plb
}
JSR WaitForKey ; Wait until a Key is pressed
*----- End Of Program ---------
End JSR RestoreEnv ; Restore environment (colors...)
JSR ToolTerm ; End up Tools
JMP Exit ; Quit to the Launcher
************************************************************
******* INIT TOOL SET/ FREE TOOL CODE *******
************************************************************
ToolInit
; _TLStartUp ; Start Tools
; PHA
; _MMStartUp ; Start Memory Manager Tool Set
; PLA
; STA myID ; Get current ID
*--
_MTStartUp ; Start Miscellaneous Tool Set
*--
* clc ; grab the memory next to my DP
* lda |myDP
* adc #$100
* pha
* _SoundStartUp ; Start Sound Tool Set
*--
PushLong #0 ; Compact Memory
PushLong #$8fffff
PushWord myID
PushWord #%11000000_00000000
PushLong #0
_NewHandle
_DisposeHandle
_CompactMem
*--
// Allocate Bank 01 memory + 4K before and after (25 lines pre flow)
// $012000-$019BFF pixel data
// $019D00-$019DC7 SCB data
// $019E00-$019FFF Clut data
// $900 bytes afer, (14 lines buffer on the bottom, which will wreck SCB+CLUT
PushLong #0 ; Ask Shadowing Screen ($8000 bytes from $01/2000)
PushLong #$9600
PushWord myID
PushWord #%11000000_00000011
PushLong #$011000
_NewHandle
PLA
PLA
BCC :NoError
*--
:NoError
RTS
*-------
ToolTerm:
* _SoundShutDown ; Stop Tools
_MTShutDown
PushWord myID
_DisposeAll
; PushWord myID
; _MMShutDown
; _TLShutDown
RTS
myID ds 2 ; ID of this Program in memory
mySP ds 2
myDP ds 2
myBank0Size ds 2
*---------------------------------------
BackupEnv SEP #$30 ; Backup Environment values (color, border...)
LDAL $00C022
STA BE_C022
LDAL $00C029
STA BE_C029
LDAL $00C034
STA BE_C034
LDAL $00C035
STA BE_C035
REP #$30
RTS
*-----
RestoreEnv SEP #$30 ; Restore Environment values (color, border...)
LDA BE_C035
STAL $00C035
LDA BE_C034
STAL $00C034
LDA BE_C029
STAL $00C029
LDA BE_C022
STAL $00C022
REP #$30
RTS
BE_C022 byte 00 ; Background Color
BE_C029 byte 00 ; Linearization of the Graphic Page
BE_C034 byte 00 ; Border Color
BE_C035 byte 00 ; Shadowing
************************************************************
******* GS/OS CODE *******
************************************************************
GSOS = $E100A8
*-------
Exit JSL GSOS ; Quit Program
dc.w $2029
dc.l gsosQUIT
*-------
gsosQUIT ds.w 2 ; pCount
ds.b 4 ; pathname
ds.b 2 ; flags
************************************************************
******* EVENT HANDLER CODE *******
************************************************************
WaitForKey SEP #$30 ; Wait for a Key Press
WFK_1 LDAL $00c000
BPL WFK_1
STAL $00c010
REP #$30
RTS
************************************************************
*
* Print out a TEXT String, at memory location Y
* in Bank E1
*
PrintE1:
mx %00
{
pool zpWork $e0-$100
zpWork pString.l
* Setup pString as pointer to the string
plx
inx
stx <pString
phk
phk
pla
sta <pString+2
* Font render bank
pea $e1e1
plb
plb
clc
.loop
lda [pString]
and #$00FF
beq .done
sbc #31
jsr dbgprint_char
tya
adc #4
tay
inc <pString
bra .loop
.done
pei <pString
rts
}
************************************************************
*
* Print out a 16 bit hex number, at memory location Y
* in the current bank
*
PrintHEX:
mx %00
{
pha
xba
lsr
lsr
lsr
lsr
and #$000F
tax
lda >chartable,x
and #$00FF
jsr dbgprint_char
tya
adc #4
tay
lda 2,s
and #$000F
tax
lda >chartable,x
and #$00FF
jsr dbgprint_char
tya
adc #4
tay
lda 1,s
lsr
lsr
lsr
lsr
and #$000F
tax
lda >chartable,x
and #$00FF
jsr dbgprint_char
tya
adc #4
tay
pla
and #$000F
tax
lda >chartable,x
and #$00FF
jsr dbgprint_char
rts
chartable dc.b 16,17,18,19,20,21,22,23,24,25,33,34,35,36,37,38
}
************************************************************

View File

@ -0,0 +1,153 @@
#--------------------------------------------------------
# $File: Makefile,v $
#
# $Date: 2019/10/20 $
# $Author: jandersen $
# $Revision: #1 $
#--------------------------------------------------------
#
# ftile GCC-Gnu Makefile
#
# compile under *nix, or Windows Subsystem for Linux
SHELL = /bin/sh
MKDIR = mkdir
TARGET = ftile
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 := ftile.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)

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
/*
bctypes.h
Because Standard Types
*/
#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;
#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 {
u64 ul64[2];
u32 ui32[4];
} QWdata;
#endif // _bctypes_h
// EOF - bctypes.h

View File

@ -0,0 +1,187 @@
/*
#--------------------------------------------------------
# $File: ftile.c,v $
#--------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "bctypes.h"
#include "ftile.h"
#include "rawdata.h"
u16 GetBest16(unsigned char* pFrame, int width, int height)
{
return 0;
}
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;
}
void CompileTile(RAWDATA *result, u8* pTile)
{
static int offsets[16] =
{
(160 * 0) + 0, (160 * 0) + 2,
(160 * 1) + 0, (160 * 1) + 2,
(160 * 2) + 0, (160 * 2) + 2,
(160 * 3) + 0, (160 * 3) + 2,
(160 * 4) + 0, (160 * 4) + 2,
(160 * 5) + 0, (160 * 5) + 2,
(160 * 6) + 0, (160 * 6) + 2,
(160 * 7) + 0, (160 * 7) + 2
};
int clocks = 0;
u16 *pData = (u16*) pTile;
bool slots[16];
memset(slots, 0, sizeof(bool) * 16);
bool done = false;
while (!done)
{
u16 pixel = 0;
done = true;
// Load a cached Pixel
for (int idx = 0; idx < 16; ++idx)
{
if (slots[idx])
continue;
done = false;
pixel = pData[idx];
clocks += AddLine("","LDA","#$%04X",pixel,3);
break;
}
for (int outIdx = 0; outIdx < 16; ++outIdx)
{
if (slots[outIdx])
continue;
if (pixel == pData[outIdx])
{
clocks += AddLine("","STA","$%04X,Y",offsets[outIdx],6);
slots[outIdx] = true;
}
}
}
clocks += AddLine("","RTL"," ;%d cycles",clocks+6,6);
}
RAWDATA* CompileTiles(RAWDATA* pTilesData, int bank)
{
RAWDATA* result = (RAWDATA*)malloc(sizeof(RAWDATA));
memset(result, 0, sizeof(RAWDATA));
gResult = result;
int numTiles = pTilesData->size / 32; // (32 bytes per tile)
char temp_label[256];
for (int idx = 0; idx < numTiles; ++idx)
{
sprintf(temp_label," da tile%d_%d\n", bank, idx);
AddString(result, temp_label);
}
for (int tileNo = 0; tileNo < numTiles; ++tileNo)
{
sprintf(temp_label,"tile%d_%d\n", bank, tileNo);
AddString(result, temp_label);
CompileTile(result, &pTilesData->data[ tileNo * 32 ]);
}
return result;
}
static void _usage()
{
printf("ftile v%s\n\n", VERSION);
printf("Usage: ftile <input_raw8x8_tile_file>\n"
"Written by Jason Andersen\n"
"Copyright (c) 2019 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("ftile v%s\n", VERSION);
exit(0);
}
*argv+= strlen(*argv); // skip rest of string
}
if (argc != 1) _usage();
RAWDATA* pData = loadRaw(argv[0]);
RAWDATA* pSource = CompileTiles(pData,0);
char outname[256];
strcpy(outname, argv[0]);
int len = strlen(outname);
strcpy(outname+(len-2), "txt");
saveRaw(pSource, outname);
printf("\nftile - Processing complete.\n");
exit(0);
} // main
// eof - xrick2png.c

View File

@ -0,0 +1,19 @@
/*
#--------------------------------------------------------
# $File: ftile.h,v $
# $Author: jandersen $
# $Revision: #1 $
#--------------------------------------------------------
*/
#ifndef _ftile_h
#define _ftile_h
#define VERSION "1.00"
#endif // _ftile_h
// EOF - ftile.h

View File

@ -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

View File

@ -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_

View File

@ -0,0 +1,249 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
namespace png2c1
{
class Program
{
public class spPalette
{
public List<Color> colors = new List<Color>();
}
public class spPixels
{
public int m_width;
public int m_height;
public List<byte> m_pixels = new List<byte>();
public spPixels(int width, int height, List<byte> pixels)
{
m_width = width;
m_height = height;
m_pixels = pixels;
}
}
static void Main(string[] args)
{
List<spPalette> pals = new List<spPalette>();
List<spPixels> pics = new List<spPixels>();
Console.WriteLine("png2c1");
Console.WriteLine("{0}", args.Length);
byte[] scbs = new byte[200]; // 200 scanlines
byte scb_index = 0;
foreach(string arg in args)
{
String pngPath = arg;
String palPath = Path.ChangeExtension(pngPath, ".pal");
//--------------------------------------------------------------
// Read in the palette file (thanks Pro Motion)
Console.WriteLine($"Loading {palPath}");
spPalette pal = new spPalette();
using (FileStream palStream = new FileStream(palPath, FileMode.Open, FileAccess.Read))
{
for(int idx = 0; idx < 16; ++idx)
{
int r = palStream.ReadByte();
int g = palStream.ReadByte();
int b = palStream.ReadByte();
pal.colors.Add(Color.FromArgb(255, r, g, b));
}
}
// Put it in the list
pals.Add(pal);
//--------------------------------------------------------------
// Read in the image file
Console.WriteLine($"Loading {pngPath}");
using (var image = new Bitmap(System.Drawing.Image.FromFile(pngPath)))
{
//Bitmap image = new Bitmap(pngStream);
Console.WriteLine("{0} width={1}, height={2}",pngPath, image.Width, image.Height);
List<byte> pixels = new List<byte>();
for (int y = 0; y < image.Height; ++y)
{
Color p = image.GetPixel(0,y);
if (255 == p.A)
{
scbs[ y ] = scb_index;
}
for (int x = 0; x < image.Width; x+=2)
{
Color p0 = image.GetPixel(x,y);
Color p1 = image.GetPixel(x+1,y);
int idx0 = GetIndex(ref pal.colors, p0);
int idx1 = GetIndex(ref pal.colors, p1);
byte pb = (byte)((idx0<<4) | (idx1));
pixels.Add( pb );
}
}
spPixels pic = new spPixels(image.Width, image.Height, pixels);
pics.Add(pic);
}
scb_index++;
}
//foreach (byte scb in scbs)
//{
// Console.WriteLine("{0:X2}", scb);
//}
String outPath = Path.ChangeExtension(args[0], ".c1");
Console.WriteLine("Saving {0}", outPath);
using (BinaryWriter b = new BinaryWriter(
File.Open(outPath, FileMode.Create)))
{
for (int y = 0; y < scbs.Length; ++y)
{
int imageIdx = scbs[ y ];
spPixels pix = pics[ imageIdx ];
int pixIndex = 160 * y;
// Write out the scanline of pix
for (int idx = 0; idx < 160; ++idx)
{
b.Write((byte)pix.m_pixels[ pixIndex + idx ]);
}
}
// Save out the scbs
b.Write(scbs);
// Pad out the page
for (int idx = 0; idx < 56; ++idx)
{
b.Write((byte)0x00);
}
// Save out the palettes
for (int palIdx = 0; palIdx < 16; ++palIdx)
{
if (palIdx < pals.Count)
{
spPalette pal = pals[ palIdx ];
for (int idx = 0; idx < 16; ++idx)
{
UInt16 rgb = ToGSColor(pal.colors[idx]);
b.Write(rgb);
}
}
else
{
for (int idx = 0; idx < 16; ++idx)
{
b.Write((UInt16)0);
}
}
}
}
    
}
//
// Get a IIgs color
//
static UInt16 ToGSColor( Color pixel )
{
int red = pixel.R;
int green = pixel.G;
int blue = pixel.B;
// we want to round up if it's needed
red+=8;
green+=8;
blue+=8;
if (red > 255) red = 255;
if (green > 255) green = 255;
if (blue > 255) blue = 255;
red >>= 4;
green >>= 4;
blue >>= 4;
int color = (red << 8) |
(green << 4) |
(blue);
return (UInt16)color;
}
//
// Get the Closest Matching Palette Index
//
static int GetIndex(ref List<Color> pal, Color pixel)
{
byte result_index = 0;
if (pal.Count > 0)
{
List<float> dist = new List<float>();
for (int idx = 0; idx < pal.Count; ++idx)
{
float delta = ColorDelta(pal[idx], pixel);
dist.Add(delta);
// Make sure the result_index is the one
// with the least amount of error
if (dist[idx] < dist[result_index])
{
result_index = (byte)idx;
}
}
}
return result_index;
}
static float ColorDelta(Color c0, Color c1)
{
// Y=0.2126R+0.7152G+0.0722B
float r = (c0.R-c1.R);
r = r * r;
r *= 0.2126f;
float g = (c0.G-c1.G);
g = g * g;
g *= 0.7152f;
float b = (c0.B-c1.B);
b = b * b;
b *= 0.0722f;
return r + g + b;
}
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,202 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
namespace png2tiles
{
class Program
{
public class spPalette
{
public List<Color> colors = new List<Color>();
}
public class spPixels
{
public int m_width;
public int m_height;
public List<byte> m_pixels = new List<byte>();
public spPixels(int width, int height, List<byte> pixels)
{
m_width = width;
m_height = height;
m_pixels = pixels;
}
}
static void Main(string[] args)
{
List<spPalette> pals = new List<spPalette>();
List<spPixels> pics = new List<spPixels>();
Console.WriteLine("png2tiles");
Console.WriteLine("{0}", args.Length);
foreach(string arg in args)
{
String pngPath = arg;
String palPath = Path.ChangeExtension(pngPath, ".pal");
//--------------------------------------------------------------
// Read in the palette file (thanks Pro Motion)
Console.WriteLine($"Loading {palPath}");
spPalette pal = new spPalette();
using (FileStream palStream = new FileStream(palPath, FileMode.Open, FileAccess.Read))
{
for(int idx = 0; idx < 16; ++idx)
{
int r = palStream.ReadByte();
int g = palStream.ReadByte();
int b = palStream.ReadByte();
pal.colors.Add(Color.FromArgb(255, r, g, b));
}
}
// Put it in the list
pals.Add(pal);
//--------------------------------------------------------------
// Read in the image file
Console.WriteLine($"Loading {pngPath}");
using (var image = new Bitmap(System.Drawing.Image.FromFile(pngPath)))
{
//Bitmap image = new Bitmap(pngStream);
Console.WriteLine("{0} width={1}, height={2}",pngPath, image.Width, image.Height);
List<byte> pixels = new List<byte>();
for (int y = 0; y < image.Height; ++y)
{
for (int x = 0; x < image.Width; x+=2)
{
Color p0 = image.GetPixel(x,y);
Color p1 = image.GetPixel(x+1,y);
int idx0 = GetIndex(ref pal.colors, p0);
int idx1 = GetIndex(ref pal.colors, p1);
byte pb = (byte)((idx0<<4) | (idx1));
pixels.Add( pb );
}
}
spPixels pic = new spPixels(image.Width, image.Height, pixels);
pics.Add(pic);
}
}
String outPath = Path.ChangeExtension(args[0], ".gs");
Console.WriteLine("Saving {0}", outPath);
using (BinaryWriter b = new BinaryWriter(
File.Open(outPath, FileMode.Create)))
{
spPixels pix = pics[ 0 ];
for (int y = 0; y < pix.m_height; y+=8)
{
for (int x = 0; x<pix.m_width; x+=8)
{
int offset = y * (pix.m_width>>1) + (x >> 1);
for (int idy = 0; idy < 8; ++idy)
{
int boffset = offset + (idy * (pix.m_width>>1));
for (int idx = 0; idx < 4; ++idx)
{
b.Write((byte)pix.m_pixels[ boffset + idx ]);
}
}
}
}
}
}
//
// Get a IIgs color
//
static UInt16 ToGSColor( Color pixel )
{
int red = pixel.R;
int green = pixel.G;
int blue = pixel.B;
// we want to round up if it's needed
red+=8;
green+=8;
blue+=8;
if (red > 255) red = 255;
if (green > 255) green = 255;
if (blue > 255) blue = 255;
red >>= 4;
green >>= 4;
blue >>= 4;
int color = (red << 8) |
(green << 4) |
(blue);
return (UInt16)color;
}
//
// Get the Closest Matching Palette Index
//
static int GetIndex(ref List<Color> pal, Color pixel)
{
byte result_index = 0;
if (pal.Count > 0)
{
List<float> dist = new List<float>();
for (int idx = 0; idx < pal.Count; ++idx)
{
float delta = ColorDelta(pal[idx], pixel);
dist.Add(delta);
// Make sure the result_index is the one
// with the least amount of error
if (dist[idx] < dist[result_index])
{
result_index = (byte)idx;
}
}
}
return result_index;
}
static float ColorDelta(Color c0, Color c1)
{
// Y=0.2126R+0.7152G+0.0722B
float r = (c0.R-c1.R);
r = r * r;
r *= 0.2126f;
float g = (c0.G-c1.G);
g = g * g;
g *= 0.7152f;
float b = (c0.B-c1.B);
b = b * b;
b *= 0.0722f;
return r + g + b;
}
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>
</Project>

View File

@ -0,0 +1 @@
dotnet run null_terminator.png

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,17 @@
//
// fun2gs linker file
//
; Stack, and Direct page space
; in Bank0
section DirectPage_Stack,BSS
ds.b 1024
incobj "start.x65"
incobj "dbgfnt.x65"
incobj "lz4.x65"
incobj "blit.x65"
incobj "background.x65"
; Get these things in the same bank
;Merge start,dbgfont

View File

@ -0,0 +1,48 @@
;
; common.i
;
; merlin mx macro
macro mx mx
{
if (0 == (mx&%10))
A16
else
A8
endif
if (0 == (mx&%01))
I16
else
I8
endif
}
macro _shadowON
{
lda >$00C035
and #$FFF7
sta >$00C035
}
macro _shadowOFF
{
lda >$00C035
ora #$0008
sta >$00C035
}
macro _auxON
{
lda >$00C068
ora #$0030
sta >$00C068
}
macro _auxOFF
{
lda >$00C068
and #$FFCF
sta >$00C068
}