Skip to content

Commit

Permalink
update README & deets
Browse files Browse the repository at this point in the history
  • Loading branch information
logicplace committed Sep 20, 2022
1 parent 56486b0 commit 4bbef11
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ __pycache__
cpu/pm

obj
out
*.min
*.sym
pmas
pmdis
pmas.exe
pmdis.exe

.vscode/c_cpp_properties.json
36 changes: 26 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ CXXFLAGS := $(INCLUDES)
LD := $(CXX)
LDFLAGS := $(INCLUDES)
COMPARE = diff -q --binary
PMAS = pmas$(MODIFIER)
PMDIS = ./pmdis
OUTPUTS := pmas$(MODIFIER)
ifeq "$(CPU)" "pm"
OUTPUTS += cpu/$(CPU)/pm.s
OUTPUTS := cpu/$(CPU)/pm.s
else
OUTPUTS += $(shell find cpu/$(CPU) -name "*.s")
OUTPUTS := $(shell find cpu/$(CPU) -name "*.s")
endif
OUTPUTS += $(PMAS)
OUTPUTS += pmdis
AWK := awk
PY := python
Expand All @@ -29,6 +30,7 @@ help:
@echo " help This list."
@echo " release Build release version of pmas."
@echo " debug Build debug version of pmas."
@echo " bundle Bundle a release build into a tar.gz"
@echo " releasetest Run some tests."
@echo " debugtest Run some tests under gdb to find bugs."
@echo " clean Delete intermediate files."
Expand Down Expand Up @@ -56,6 +58,12 @@ obj/%.d: obj src/%.cpp cpu/$(CPU)/cpu.h
obj:
mkdir obj

out:
mkdir out

out/cpu:
mkdir out/cpu

.PHONY: debug
debug: CFLAGS += -g -DDEBUG
debug: $(OUTPUTS)
Expand All @@ -66,13 +74,16 @@ release: CFLAGS += -O3
release: LDFLAGS += #-Wl,-s
release: $(OUTPUTS)

.PHONY: bundle
bundle: pmas.tar.gz

.PHONY: debugtest
debugtest: PMAS = echo r | gdb -q -x - --args pmas$(MODIFIER)
debugtest: PMAS = echo r | gdb -q -x - --args $(PMAS)
debugtest: debug
$(PMAS) test/test.s test/test.min

.PHONY: releasetest
releasetest: PMAS = ./pmas$(MODIFIER)
releasetest: PMAS = ./$(PMAS)
releasetest: release test/readme.min test/test1.min test/test2.min test/test3.min test/test4.min test/opcodes1.min test/opcodes2.min test/opcodes3.min
$(COMPARE) test/opcodes1.min test/opcodes2.min
$(COMPARE) test/opcodes1.min test/opcodes3.min
Expand All @@ -84,14 +95,19 @@ releasetest: release test/readme.min test/test1.min test/test2.min test/test3.mi
# $(PMAS) test/opcodes2.dis.s test/opcodes2.as.min test/opcodes2.as.sym
# $(COMPARE) test/opcodes2.min test/opcodes2.as.min

pmas.tar.gz: release out out/cpu $(OUTPUTS)
-cp $(PMAS)* $(PMDIS)* README out
-cp cpu/$(CPU)/* out/cpu
cd out && tar -czf ../$@ *

##############
# pmas/pmdis #
##############

PMAS_SOURCES := src/pmas$(MODIFIER).cpp src/eval.cpp src/misc.cpp src/symbol.cpp src/stack.cpp src/valuetype.cpp src/macrolist.cpp src/instruction.cpp src/mem.cpp src/tmplabel.cpp
PMAS_SOURCES := src/$(PMAS).cpp src/eval.cpp src/misc.cpp src/symbol.cpp src/stack.cpp src/valuetype.cpp src/macrolist.cpp src/instruction.cpp src/mem.cpp src/tmplabel.cpp
PMAS_OBJECTS := $(patsubst src/%.cpp,obj/%.o,$(PMAS_SOURCES))

pmas$(MODIFIER): obj $(PMAS_OBJECTS)
$(PMAS): obj $(PMAS_OBJECTS)
$(LD) $(LDFLAGS) -o $@ $(filter %.o,$+)

pmdis: obj obj/pmdis.o cpu/$(CPU)/cpu.h
Expand All @@ -110,10 +126,10 @@ cpu/pm:
# tests #
#########

test/%.min: test/%.s pmas$(MODIFIER)
test/%.min: test/%.s $(PMAS)
$(PMAS) $< $@ $(@:min=sym)

test/%.min: test/%.S pmas$(MODIFIER)
test/%.min: test/%.S $(PMAS)
$(CPP) $< | $(PMAS) - $@ $(@:min=sym)

########
Expand All @@ -133,6 +149,6 @@ clean:

.PHONY: cleanall
cleanall: clean
-rm -f *.tar.gz pmas$(MODIFIER) pmas$(MODIFIER).exe pmdis pmdis.exe cpu/pm/*
-rm -f *.tar.gz $(PMAS) $(PMAS).exe pmdis pmdis.exe cpu/pm/*
-rmdir cpu/pm

12 changes: 9 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
Pika Macro ASsembler
by darkfader
originally by darkfader

A simple 2-pass assembler with a customizable instruction set.

Executables:
pmas assembler
pmdis disassembler (not maintained anymore)
pmdis disassembler

Further information:
test/readme.S a quick reference of directives and required syntax
cpu/*.s CPU specific stuff
cpu/**.s CPU specific stuff

Changelog:

v1.0
add support for S1C88 ops
change CPU system a bit
consistency improvements for minx (original) target
get disassembler building again
add `make bundle` command
2 changes: 1 addition & 1 deletion src/pmas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ int main(int argc, char *argv[])
// show title when not stdout
if ((argc < 3) || strcmp(argv[2], "-"))
{
printf("Pika Macro ASsembler v" VERSION " (build " __DATE__ ") by Rafael Vuijk. http://darkfader.net/pm/\n");
printf("Pika Macro ASsembler v" VERSION " (build " __DATE__ ") originally by Rafael Vuijk. https://github.com/logicplace/PMAS\n");
}

// show help
Expand Down
79 changes: 38 additions & 41 deletions src/pmdis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,56 +91,53 @@ unsigned int Disassemble(char *q, unsigned char *memory, unsigned int addr)
default: instruction = instructions_00 + memory[addr++]; break;
}

if (instruction->fmt)
//unsigned char argbytes[MAX_ARGS];
//for (unsigned int j=0; j<instruction->argbytes; j++) argbytes[j] = memory[addr++];

char *s = instruction->fmt;
while (*s)
{
//unsigned char argbytes[MAX_ARGS];
//for (unsigned int j=0; j<instruction->argbytes; j++) argbytes[j] = memory[addr++];

char *s = instruction->fmt;
while (*s)
if (*s == '~')
{
if (*s == '~')
s++;
int argsrc = *s++ - '0';
unsigned int argflags = instruction->argInfo[argsrc].flags;
unsigned int tmp = *(unsigned int *)(memory + addr);
unsigned int bitmask = ~(0xFFFFFFFF << (argflags & ARGFLAG_BITS));
int value = tmp & bitmask;

if (argflags & ARGFLAG_HIGH) value <<= 8;

if (argflags & ARGFLAG_S)
{
if (value & ((argflags & ARGFLAG_BITS)-1)) value -= (1 << (argflags & ARGFLAG_BITS));
}

if (argflags & ARGFLAG_REL)
{
value += instruction->size - 1;
qp += sprintf(qp, ".%+d ", value);
value += opcode_addr - 1;
qp += sprintf(qp, ";@%06X", value);
}
else if ((argflags & ARGFLAG_BITS) >= 16)
{
s++;
int argsrc = *s++ - '0';
unsigned int argflags = instruction->argInfo[argsrc].flags;
unsigned int tmp = *(unsigned int *)(memory + addr);
unsigned int bitmask = ~(0xFFFFFFFF << (argflags & ARGFLAG_BITS));
int value = tmp & bitmask;

if (argflags & ARGFLAG_HIGH) value <<= 8;

if (argflags & ARGFLAG_S)
{
if (value & ((argflags & ARGFLAG_BITS)-1)) value -= (1 << (argflags & ARGFLAG_BITS));
}

if (argflags & ARGFLAG_REL)
{
value += instruction->size - 1;
qp += sprintf(qp, ".%+d ", value);
value += opcode_addr - 1;
qp += sprintf(qp, ";@%06X", value);
}
else if ((argflags & ARGFLAG_BITS) >= 16)
{
qp += sprintf(qp, "$%04X", value);
}
else
{
qp += sprintf(qp, "$%02X", value);
}
qp += sprintf(qp, "$%04X", value);
}
else
{
*qp++ = tolower2(*s++);
*qp = 0;
qp += sprintf(qp, "$%02X", value);
}
}

if (!*s) return opcode_addr + instruction->size;
else
{
*qp++ = tolower2(*s++);
*qp = 0;
}
}

if (!*s) return opcode_addr + instruction->size;

qp = q;
qp += sprintf(qp, ".db $%02X", memory[opcode_addr]);
return opcode_addr + 1;
Expand All @@ -156,7 +153,7 @@ int main(int argc, char *argv[])
InitInstructions();

fprintf(stderr,
"Pika Macro DISassembler " VERSION " (build " __DATE__ ") by Rafael Vuijk. http://darkfader.net/pm/\n"
"Pika Macro DISassembler " VERSION " (build " __DATE__ ") originallyby Rafael Vuijk. http://darkfader.net/pm/\n"
);

if (argc < 3)
Expand Down

0 comments on commit 4bbef11

Please sign in to comment.