Skip to content

Commit 92672c9

Browse files
committed
V 1.17
Extended the -hv[clm] option. You can now limit the data export to (c)onstants, (l)abels and (m)acros. Or any combination of them. -hvcl exports constants and labels. By default all data is exported, same as -hvclm Used by the "Atasm-Altirra-Bridge" VSCode plugin (https://bit.ly/3ATTHVR) Breaking default behavior change: When running atasm without a target assembler file (was test.m65) the command line help is shown. Same when specifying -h on the command line.
1 parent 0412afb commit 92672c9

File tree

10 files changed

+199
-80
lines changed

10 files changed

+199
-80
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ATasm v1.16
1+
# ATasm v1.17
22
### A mostly Mac/65 compatible 6502 cross-assembler
3-
Copyright (c) 1998-2021 Mark Schmelzenbach, modified by Peter Hinz (2021)
3+
Copyright (c) 1998-2021 Mark Schmelzenbach, modified by Peter Hinz (2022)
44

55
*ATasm is a 6502 command-line cross-assembler that is compatible with the original Mac/65 macroassembler released by OSS software. Code development can now be performed using "modern" editors and compiles with lightning speed.*
66

VERSION.TXT

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,10 @@ Dec 22, 2021
139139
Code like this now assembles:
140140
lda #1<<4
141141
Fixed a bug in .LST output generator. Filenames were not tracked correctly which caused source lines
142-
to be allocated to the wrong source file. Thank you to Lars Langhans for reporting this.
142+
to be allocated to the wrong source file. Thank you to Lars Langhans for reporting this.
143+
Feb 2, 2022
144+
version 1.17 - Extended the -hv[clm] option. You can now limit the data export to (c)onstants, (l)abels and (m)acros.
145+
Or any combination of them. -hvcl exports constants and labels. By default all data is exported.
146+
Used by the "Atasm-Altirra-Bridge" VSCode plugin (https://bit.ly/3ATTHVR)
147+
Breaking default behavior change: When running atasm without a target assembler file (was test.m65)
148+
the command line help is shown. Same when specifying -h on the command line.

atasm.exe

512 Bytes
Binary file not shown.

docs/atasm.pdf

2.31 KB
Binary file not shown.

src/asm.c

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,31 @@ int find_extension(char *name) {
24572457
}
24582458
return end-name;
24592459
}
2460+
2461+
/*=========================================================================*
2462+
* Show command line help
2463+
*=========================================================================*/
2464+
void showHelp(char *executable)
2465+
{
2466+
fprintf(stderr, "\nUsage: %s [-v] [-s] [-r] [-d[symbol=value] [-o[fname.out] [-m[fname.state]] <fname.m65>\n", executable ? executable : "atasm");
2467+
fputs(" where -v: prints assembly trace\n", stderr);
2468+
fputs(" -s: prints symbol table\n", stderr);
2469+
fputs(" -u: enables undocumented opcodes\n", stderr);
2470+
fputs(" -m[fname]: defines template emulator state file\n", stderr);
2471+
fputs(" -x[fname]: saves object file to .XFD/.ATR disk image [fname]\n", stderr);
2472+
fputs(" -r: saves object code as a raw binary image\n", stderr);
2473+
fputs(" -f[value]: set raw binary fill byte to [value]\n", stderr);
2474+
fputs(" -o[fname]: saves object file to [fname] instead of <fname>.65o\n", stderr);
2475+
fputs(" -d[symbol=value]: pre-defines [symbol] to [value]\n", stderr);
2476+
fputs(" -l[fname]: dumps labels to file [fname]\n", stderr);
2477+
fputs(" -g[fname]: dumps debug list to file [fname]\n", stderr);
2478+
fputs(" -Idirectory: search [directory] for .INCLUDE files\n", stderr);
2479+
fputs(" -mae: treats local labels like MAE assembler\n", stderr);
2480+
fputs(" -hc[fname]: dumps equates and labels to header file for CC65\n", stderr);
2481+
fputs(" -ha[fname]: dumps equates and labels to header file for assembler\n", stderr);
2482+
fputs(" -hv[clm]: dumps all info for VSCode plugin. c=constants, l=labels, m=macros\n", stderr);
2483+
}
2484+
24602485
/*=========================================================================*
24612486
* function main
24622487
*
@@ -2474,7 +2499,7 @@ int main(int argc, char *argv[]) {
24742499

24752500
create_c_header_fn = create_asm_header_fn = 0;
24762501
dsymbol=state=0;
2477-
dumpVSCode = 0;
2502+
dumpVSCode = DUMP_NOTHING; /* No dumping of constant, label, macros, and includes to 'asm-symbols.json' file */
24782503
strcpy(snap,"atari800.a8s");
24792504
fname[0]=outfile[0]=labelfile[0]=listfile[0]=cheaderfile[0]=asmheaderfile[0]='\0';
24802505
opt.savetp=opt.verbose=opt.MAElocals=0;
@@ -2534,7 +2559,23 @@ int main(int argc, char *argv[]) {
25342559
}
25352560
}
25362561
else if (!STRNCASECMP(argv[i], "-hv", 3)) {
2537-
dumpVSCode = 1;
2562+
if (strlen(argv[i]) > 3) {
2563+
/* There are special selectors after the -hv switch */
2564+
/* c = constants, l = labels, m = macros */
2565+
char* param = argv[i];
2566+
for (int x = 3; x < strlen(param); ++x) {
2567+
if (!STRNCASECMP(&param[x], "c", 1)) { dumpVSCode |= DUMP_CONSTANTS; }
2568+
else if (!STRNCASECMP(&param[x], "l", 1)) { dumpVSCode |= DUMP_LABELS; }
2569+
else if (!STRNCASECMP(&param[x], "m", 1)) { dumpVSCode |= DUMP_MACROS; }
2570+
}
2571+
// Hmm, did not select anything useful, so dump it all
2572+
if (dumpVSCode == DUMP_NOTHING)
2573+
dumpVSCode = DUMP_ALL;
2574+
}
2575+
else {
2576+
/* Dump all the items */
2577+
dumpVSCode = DUMP_ALL; /* constants, labels, macros, (includes are always dumped) */
2578+
}
25382579
}
25392580
else if (!STRNCASECMP(argv[i],"-g",2)) {
25402581
if (strlen(argv[i])>2) {
@@ -2581,29 +2622,15 @@ int main(int argc, char *argv[]) {
25812622
fprintf(stderr,"Using default state file: '%s'\n",snap);
25822623
state=1;
25832624
} else if (!STRCASECMP(argv[i],"-h")) {
2584-
fprintf(stderr,"\nUsage: %s [-v] [-s] [-r] [-d[symbol=value] [-o[fname.out] [-m[fname.state]] <fname.m65>\n",argv[0]);
2585-
fputs(" where -v: prints assembly trace\n",stderr);
2586-
fputs(" -s: prints symbol table\n",stderr);
2587-
fputs(" -u: enables undocumented opcodes\n",stderr);
2588-
fputs(" -m[fname]: defines template emulator state file\n",stderr);
2589-
fputs(" -x[fname]: saves object file to .XFD/.ATR disk image [fname]\n",stderr);
2590-
fputs(" -r: saves object code as a raw binary image\n",stderr);
2591-
fputs(" -f[value]: set raw binary fill byte to [value]\n",stderr);
2592-
fputs(" -o[fname]: saves object file to [fname] instead of <fname>.65o\n",stderr);
2593-
fputs(" -d[symbol=value]: pre-defines [symbol] to [value]\n",stderr);
2594-
fputs(" -l[fname]: dumps labels to file [fname]\n",stderr);
2595-
fputs(" -g[fname]: dumps debug list to file [fname]\n",stderr);
2596-
fputs(" -Idirectory: search [directory] for .INCLUDE files\n",stderr);
2597-
fputs(" -mae: treats local labels like MAE assembler\n",stderr);
2598-
fputs(" -hc[fname]: dumps equates and labels to header file for CC65\n", stderr);
2599-
fputs(" -ha[fname]: dumps equates and labels to header file for assembler\n", stderr);
2600-
fputs(" -hv: dumps all info for VSCode plugin\n", stderr);
2625+
showHelp(argv[0]);
26012626
return 1;
26022627
} else strcpy(fname,argv[i]);
26032628
}
26042629

26052630
if (!strlen(fname)) {
2606-
strcpy(fname,"test.m65");
2631+
// strcpy(fname,"test.m65");
2632+
showHelp(argv[0]);
2633+
return 1;
26072634
}
26082635

26092636
/* If the -hc or -ha options did not specify a filename lets create them now */
@@ -2628,7 +2655,7 @@ int main(int argc, char *argv[]) {
26282655
dump_assembler_header(asmheaderfile);
26292656

26302657
if (dumpVSCode)
2631-
dump_VSCode(trackedFiles);
2658+
dump_VSCode(trackedFiles, dumpVSCode);
26322659

26332660
fputs("\nAssembly successful\n",stderr);
26342661
fprintf(stderr," Compiled %d bytes (~%dk)\n",bsize,bsize/1024);

src/symbol.c

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,17 @@ char* bestNameForSymbol(symbol* sym)
803803
return sym->name;
804804
}
805805

806-
void dump_VSCode(file_tracking* trackedFiles)
806+
/*
807+
* trackedFiles: linked list of files that have been included
808+
* parts: which data is to be dumped (CONSTANTS, LABEL, MACROS)
809+
*/
810+
void dump_VSCode(file_tracking* trackedFiles, int parts)
807811
{
808812
symbol* sym, * head;
809813
FILE* out;
810814
int count;
811815

812-
out = fopen("plugin.json", "wb");
816+
out = fopen("asm-symbols.json", "wb");
813817
if (!out)
814818
return;
815819

@@ -823,83 +827,91 @@ void dump_VSCode(file_tracking* trackedFiles)
823827

824828
fprintf(out, "{\n");
825829

830+
// Constants
826831
fprintf(out, "\"constants\":[\n");
827-
sym = head;
828-
count = 0;
829-
while (sym)
832+
if (parts & DUMP_CONSTANTS)
830833
{
831-
if (sym->tp == EQUATE)// && sym->name[0] && sym->name[0] != '=')
834+
sym = head;
835+
count = 0;
836+
while (sym)
832837
{
833-
if (count != 0)
834-
fprintf(out, ",\n");
835-
fprintf(out, "{");
836-
fprintf(out, "\"name\":\"%s\"", bestNameForSymbol(sym) );
837-
fprintf(out, ",\"addr\":%d", sym->addr & 0xffff);
838-
fprintf(out, ",\"file\":\"%s\"", sym->ftrack ? sym->ftrack->name : "-");
839-
fprintf(out, ",\"ln\":%d", sym->lineNr);
840-
fprintf(out, "}");
841-
++count;
838+
if (sym->tp == EQUATE)// && sym->name[0] && sym->name[0] != '=')
839+
{
840+
if (count != 0)
841+
fprintf(out, ",\n");
842+
fprintf(out, "{");
843+
fprintf(out, "\"name\":\"%s\"", bestNameForSymbol(sym));
844+
fprintf(out, ",\"addr\":%d", sym->addr & 0xffff);
845+
fprintf(out, ",\"file\":\"%s\"", sym->ftrack ? sym->ftrack->name : "-");
846+
fprintf(out, ",\"ln\":%d", sym->lineNr);
847+
fprintf(out, "}");
848+
++count;
849+
}
850+
sym = sym->lnk;
842851
}
843-
sym = sym->lnk;
844852
}
845853
fprintf(out, "\n]\n");
846854

855+
// Labels
847856
fprintf(out, ",\"labels\":[\n");
848-
sym = head;
849-
count = 0;
850-
while (sym)
857+
if (parts & DUMP_LABELS)
851858
{
852-
if (sym->tp == LABEL) // && sym->name[0] && sym->name[0] != '=')
859+
sym = head;
860+
count = 0;
861+
while (sym)
853862
{
854-
if (count != 0)
855-
fprintf(out, ",\n");
856-
fprintf(out, "{");
857-
fprintf(out, "\"name\":\"%s\"", bestNameForSymbol(sym) );
858-
fprintf(out, ",\"addr\":%d", sym->addr & 0xffff);
859-
if (sym->lineNr > 0)
863+
if (sym->tp == LABEL) // && sym->name[0] && sym->name[0] != '=')
860864
{
861-
fprintf(out, ",\"file\":\"%s\"", sym->ftrack ? sym->ftrack->name : "-");
862-
fprintf(out, ",\"ln\":%d", sym->lineNr);
863-
}
864-
else {
865-
fprintf(out, ",\"cmdln\":\"%s\"", sym->orig);
865+
if (count != 0)
866+
fprintf(out, ",\n");
867+
fprintf(out, "{");
868+
fprintf(out, "\"name\":\"%s\"", bestNameForSymbol(sym));
869+
fprintf(out, ",\"addr\":%d", sym->addr & 0xffff);
870+
if (sym->lineNr > 0)
871+
{
872+
fprintf(out, ",\"file\":\"%s\"", sym->ftrack ? sym->ftrack->name : "-");
873+
fprintf(out, ",\"ln\":%d", sym->lineNr);
874+
}
875+
else {
876+
fprintf(out, ",\"cmdln\":\"%s\"", sym->orig);
877+
}
878+
fprintf(out, "}");
879+
++count;
866880
}
867-
fprintf(out, "}");
868-
++count;
881+
sym = sym->lnk;
869882
}
870-
sym = sym->lnk;
871883
}
872884
fprintf(out, "\n]\n");
873885

874886
/* MACROS */
875887
fprintf(out, ",\"macros\":[\n");
876-
sym = head;
877-
count = 0;
878-
while (sym)
888+
if (parts & DUMP_MACROS)
879889
{
880-
if (sym->tp == MACRON) // && sym->name[0] && sym->name[0] != '=')
890+
sym = head;
891+
count = 0;
892+
while (sym)
881893
{
882-
if (count != 0)
883-
fprintf(out, ",\n");
884-
fprintf(out, "{");
885-
fprintf(out, "\"name\":\"%s\"", bestNameForSymbol(sym));
886-
fprintf(out, ",\"addr\":%d", sym->addr & 0xffff);
887-
if (sym->lineNr > 0)
894+
if (sym->tp == MACRON) // && sym->name[0] && sym->name[0] != '=')
888895
{
889-
fprintf(out, ",\"file\":\"%s\"", sym->ftrack ? sym->ftrack->name : "-");
890-
fprintf(out, ",\"ln\":%d", sym->lineNr);
896+
if (count != 0)
897+
fprintf(out, ",\n");
898+
fprintf(out, "{");
899+
fprintf(out, "\"name\":\"%s\"", bestNameForSymbol(sym));
900+
// fprintf(out, ",\"addr\":%d", sym->addr & 0xffff);
901+
if (sym->lineNr > 0)
902+
{
903+
fprintf(out, ",\"file\":\"%s\"", sym->ftrack ? sym->ftrack->name : "-");
904+
fprintf(out, ",\"ln\":%d", sym->lineNr);
905+
}
906+
fprintf(out, "}");
907+
++count;
891908
}
892-
else {
893-
fprintf(out, ",\"cmdln\":\"%s\"", sym->orig);
894-
}
895-
fprintf(out, "}");
896-
++count;
909+
sym = sym->lnk;
897910
}
898-
sym = sym->lnk;
899911
}
900912
fprintf(out, "\n]\n");
901913

902-
/* included files */
914+
/* Included files */
903915
fprintf(out, ",\"includes\":[\n");
904916
sym = head;
905917
count = 0;

src/symbol.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@
2222
#define SYMBOL_H
2323

2424
#define MAJOR_VER 1
25-
#define MINOR_VER 16
25+
#define MINOR_VER 17
2626
#define BETA_VER 0
2727

28-
2928
/*==========================================================================*/
29+
30+
#define DUMP_NOTHING 0
31+
#define DUMP_CONSTANTS 1
32+
#define DUMP_LABELS 2
33+
#define DUMP_MACROS 4
34+
#define DUMP_ALL (1|2|4)
35+
36+
37+
/*==========================================================================*/
3038
typedef struct file_tracking /* Track the filename */
3139
{
3240
char* name;
@@ -161,7 +169,7 @@ int dump_symbols();
161169
int dump_labels(char *fname);
162170
int dump_c_header(char *header_fname, char *asm_fname);
163171
int dump_assembler_header(char* header_fname);
164-
void dump_VSCode(file_tracking* trackedFiles);
172+
void dump_VSCode(file_tracking* trackedFiles, int partsToDump);
165173
macro_call *get_macro_call(char *name);
166174
int macro_subst(char *name, char *in, macro_line *cmd, int max);
167175
int create_macro(symbol *sym);

tests/incmany.asm.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _INCMANY_ASM_
2+
#define _INCMANY_ASM_
3+
4+
/* Constants */
5+
6+
/* Labels */
7+
#define INCMANY_BOOT_THIS 0x2000 /* tests/incmany.asm @ 4 */
8+
#define INCMANY_STOREIT 0x203A /* " @ 21 */
9+
10+
#endif

tests/incmany.asm.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
; CONSTANTS
3+
4+
; LABELS
5+
BOOT_THIS = $2000 ; tests/incmany.asm @ 4
6+
STOREIT = $203A ; " @ 21

tests/incmany.lst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
mads (generated by atasm)
2+
3+
Source: tests/incmany.asm
4+
5 2000 A9 00 BOOT_THIS lda #0
5+
6 2002 8D 3A 20 sta StoreIt
6+
7+
Source: incpart1.asm
8+
1 2005 A9 01 lda #1
9+
2 2007 8D 3A 20 sta StoreIt
10+
11+
Source: incpart2.asm
12+
1 200A A9 02 lda #2
13+
2 200C 8D 3A 20 sta StoreIt
14+
15+
Source: incpart3.asm
16+
1 200F A9 03 lda #3
17+
2 2011 8D 3A 20 sta StoreIt
18+
19+
Source: incpart4.asm
20+
1 2014 A9 04 lda #4
21+
2 2016 8D 3A 20 sta StoreIt
22+
23+
Source: incpart5.asm
24+
1 2019 A9 05 lda #5
25+
2 201B 8D 3A 20 sta StoreIt
26+
27+
Source: incpart6.asm
28+
1 201E A9 06 lda #6
29+
2 2020 8D 3A 20 sta StoreIt
30+
31+
Source: incpart7.asm
32+
1 2023 A9 07 lda #7
33+
2 2025 8D 3A 20 sta StoreIt
34+
35+
Source: incpart8.asm
36+
1 2028 A9 08 lda #8
37+
2 202A 8D 3A 20 sta StoreIt
38+
39+
Source: incpart9.asm
40+
1 202D A9 09 lda #9
41+
2 202F 8D 3A 20 sta StoreIt
42+
43+
Source: incpart10.asm
44+
1 2032 A9 0A lda #10
45+
2 2034 8D 3A 20 sta StoreIt
46+
47+
Source: tests/incmany.asm
48+
18 2037 4C 00 20 jmp BOOT_THIS
49+
22 203A 00 .byte 0
50+
26 02E0 00 20 .word BOOT_THIS

0 commit comments

Comments
 (0)