Skip to content

Commit

Permalink
Merge pull request pce-devel#37 from jbrandwood/master
Browse files Browse the repository at this point in the history
Remove debug printout from PCEAS .incchrpal, plus a bunch of other incremental improvements.
  • Loading branch information
jbrandwood authored Apr 11, 2024
2 parents 36774e4 + 875e362 commit a627890
Show file tree
Hide file tree
Showing 27 changed files with 849 additions and 447 deletions.
6 changes: 4 additions & 2 deletions examples/asm/elmer/cd-core-scsitest/scsitest.asm
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ log_tag: php

; Table of event tag strings to be printed.

.ifdef tag_number ; Not defined yet in pass1.
MAX_TAGS = tag_number + 1 ; #events in previous pass.
.ifdef tag_number ; Not defined yet in 1st pass.
.ifndef MAX_TAGS
MAX_TAGS = tag_number + 1 ; #events defined in 1st pass.
.endif
.endif

tag_number .set -1 ; Next TAG will be 0.
Expand Down
9 changes: 5 additions & 4 deletions examples/asm/elmer/include/ted2-fat32.asm
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ FLAG_Last_Ord = $40



.procgroup ; Group ted2-fat32 in 1 bank!
ted2_fat32 .procgroup ; Group ted2-fat32 in 1 bank!

; ***************************************************************************
; ***************************************************************************
Expand Down Expand Up @@ -481,9 +481,6 @@ f32_mount_vol .proc

f32_minimum_cnt:dd $0000FFF5 ; 65525 clusters
f32_illegal_cnt:dd $0FFFFFF5 ; Too many clusters.
f32_cluster_bad:dd $0FFFFFF7 ; Test if == val.
f32_cluster_eoc:dd $0FFFFFF8 ; Test if >= val.
f32_cluster_msk:dd $0FFFFFFF ; Mask out the top 4-bits.

.endp ; f32_mount_vol

Expand Down Expand Up @@ -769,6 +766,10 @@ f32_use_cluster:ldy #3 ; Copy the cluster # from the
.bad_cluster: ldy #F32_ERR_INVALID ; Invalid cluster.
rts

f32_cluster_bad:dd $0FFFFFF7 ; Test if == val.
f32_cluster_eoc:dd $0FFFFFF8 ; Test if >= val.
f32_cluster_msk:dd $0FFFFFFF ; Mask out the top 4-bits.



; ***************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion examples/asm/elmer/include/ted2-sd.asm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ _disk_write_err:db " SDC write sector failed!",$0D,0
.endif SDC_PRINT_MESSAGES


.procgroup ; Group ted2-sd in 1 bank!
ted2_sd .procgroup ; Group ted2-sd in 1 bank!

; Use const_0000 from core-kernal.asm if possible!

Expand Down
42 changes: 30 additions & 12 deletions src/mkit/as/assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ assemble(int do_label)
if (oplook(&i) >= 0) {
if (opflg == PSEUDO) {
if (opval == P_MACRO) {
error("Can not nest macro definitions!");
error("Cannot nest macro definitions!");
return;
}
if (opval == P_ENDM) {
Expand Down Expand Up @@ -86,6 +86,28 @@ assemble(int do_label)
return;
}

/* unused PROC/PROCGROUP that has been stripped out;
* check for a '.endp' or '.endprocgroup'
* to toggle state
*/
if (skipping_stripped) {
i = preproc_sfield;
while (isspace(prlnbuf[i])) { i++; }
if ((oplook(&i) >= 0) && (opflg == PSEUDO)) {
switch (opval) {

case P_ENDP: // .endp
case P_ENDPG: // .endprocgroup
if (optype != skipping_stripped)
break;
skipping_stripped = 0;
if (pass == LAST_PASS)
println();
}
}
return;
}

/* IF/ELSE section;
* check for a '.else' or '.endif'
* to toggle state
Expand Down Expand Up @@ -113,9 +135,7 @@ assemble(int do_label)
/* check that expression matches if_level */
save_if_expr(&i);
if (strcmp(if_txt[if_level], if_txt[if_level-1]) != 0) {
char message [128];
sprintf(message, "Condition does not match \".if %s\" at line %d!", if_txt[if_level-1], if_line[if_level-1]);
fatal_error(message);
fatal_error("Condition does not match \".IF %s\" at line %d!", if_txt[if_level-1], if_line[if_level-1]);
return;
}
}
Expand All @@ -132,9 +152,7 @@ assemble(int do_label)
/* check that expression matches if_level */
save_if_expr(&i);
if (strcmp(if_txt[if_level], if_txt[if_level-1]) != 0) {
char message [128];
sprintf(message, "Condition does not match \".if %s\" at line %d!", if_txt[if_level-1], if_line[if_level-1]);
fatal_error(message);
fatal_error("Condition does not match \".IF %s\" at line %d!", if_txt[if_level-1], if_line[if_level-1]);
return;
}
}
Expand Down Expand Up @@ -282,7 +300,7 @@ assemble(int do_label)

/* check if we are in the CODE section */
if ((section_flags[section] & S_IS_CODE) == 0)
fatal_error("Instructions not allowed in this section!");
fatal_error("Instructions are not allowed in this section!");

/* generate code */
opproc(&ip);
Expand Down Expand Up @@ -502,7 +520,7 @@ do_if(int *ip)

/* check for '.if' stack overflow */
if (if_level == 255) {
fatal_error("Too many nested IF/ENDIF!");
fatal_error("Too many nested .IF/.ENDIF!");
return;
}
in_if = 1;
Expand All @@ -523,7 +541,7 @@ void
do_else(int *ip)
{
if (!in_if)
fatal_error("Unexpected ELSE!");
fatal_error("Unexpected .ELSE!");
}

/* .endif pseudo */
Expand All @@ -532,7 +550,7 @@ void
do_endif(int *ip)
{
if (!in_if)
fatal_error("Unexpected ENDIF!");
fatal_error("Unexpected .ENDIF!");
}

/* .ifdef/.ifndef pseudo */
Expand Down Expand Up @@ -566,7 +584,7 @@ do_ifdef(int *ip)

/* check for '.if' stack overflow */
if (if_level == 255) {
fatal_error("Too many nested IF/ENDIF!");
fatal_error("Too many nested .IF/.ENDIF!");
return;
}
in_if = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/mkit/as/atari.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fuji_pack_8x8_tile(unsigned char *buffer, void *data, int line_offset, int forma

default:
/* other formats not supported */
error("Internal error: unsupported format passed to 'pack_8x8_tile'!");
error("Unsupported format passed to 'pack_8x8_tile'!");
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mkit/as/atari.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct t_opcode fuji_pseudo[3] = {
/* *INDENT-ON* */

const char defdirs_fuji[] =
#ifdef WIN32
#ifdef _WIN32
"c:\\huc\\include\\atari"
#else
"/usr/local/lib/huc/include/atari;" \
Expand Down
84 changes: 53 additions & 31 deletions src/mkit/as/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ class2(int *ip)
return;

/* all branches tracked for long-branch handling */
if ((branch = getbranch(2)) == NULL)
return;
branch = getbranch(2);

/* need more space for a long-branch */
if (branch->convert) {
if ((branch) && (branch->convert)) {
if ((opval & 0x1F) == 0x10)
/* conditional branch */
loccnt += 3;
Expand All @@ -125,7 +124,7 @@ class2(int *ip)

/* generate code */
if (pass == LAST_PASS) {
if (branch->convert) {
if ((branch) && (branch->convert)) {
/* long-branch opcode */
if ((opval & 0x1F) == 0x10) {
/* conditional-branch */
Expand Down Expand Up @@ -344,16 +343,15 @@ class5(int *ip)
return;

/* all branches tracked for long-branch handling */
if ((branch = getbranch(3)) == NULL)
return;
branch = getbranch(3);

/* need more space for a long-branch */
if (branch->convert)
if ((branch) && (branch->convert))
loccnt += 3;

/* generate code */
if (pass == LAST_PASS) {
if (branch->convert) {
if ((branch) && (branch->convert)) {
/* long-branch opcode */
putbyte(data_loccnt, opval ^ 0x80);
putbyte(data_loccnt + 1, zp);
Expand Down Expand Up @@ -610,11 +608,10 @@ class10(int *ip)
return;

/* all branches tracked for long-branch handling */
if ((branch = getbranch(3)) == NULL)
return;
branch = getbranch(3);

/* need more space for a long-branch */
if (branch->convert)
if ((branch) && (branch->convert))
loccnt += 3;

/* generate code */
Expand All @@ -625,7 +622,7 @@ class10(int *ip)
return;
}

if (branch->convert) {
if ((branch) && (branch->convert)) {
/* long-branch opcode */
putbyte(data_loccnt, (opval + (bit << 4)) ^ 0x80);
putbyte(data_loccnt + 1, zp);
Expand Down Expand Up @@ -1052,8 +1049,21 @@ getbranch(int opcode_length)
struct t_branch * branch;
unsigned int addr;

#if 1
/* do not track yet, because .ifref can change after the first */
/* pass which can then change the sequence of tracked branches */
if (pass == FIRST_PASS)
return (NULL);

/* no tracking info if transitioned from FIRST_PASS to LAST_PASS */
if ((branchlst == NULL) && (pass == LAST_PASS))
return (NULL);

/* track all branches for long-branch handling */
if (pass_count == 2) {
#else
if (pass == FIRST_PASS) {
#endif
/* remember this branch instruction */
if ((branch = malloc(sizeof(struct t_branch))) == NULL) {
error("Out of memory!");
Expand All @@ -1078,7 +1088,7 @@ getbranch(int opcode_length)
} else {
/* update this branch instruction */
if (branchptr == NULL) {
error("Untracked branch instruction!");
fatal_error("Untracked branch instruction!");
return NULL;
}

Expand All @@ -1087,15 +1097,20 @@ getbranch(int opcode_length)

/* sanity check */
if ((branch->label != NULL) && (branch->label != expr_lablptr)) {
#if 0
if (branch->label == expr_toplabl) {
/* resolve branch outside of label-scope */
/* disable for now, because this is more */
/* likely to be an error than deliberate */
// branch->label = expr_lablptr;
} else {
error("Branch label mismatch!");
fatal_error("Branch label mismatch!");
return NULL;
}
#else
fatal_error("Branch label mismatch!");
return NULL;
#endif
}
}

Expand All @@ -1106,22 +1121,22 @@ getbranch(int opcode_length)
/* display the branches that have been converted */
if (branch->convert && asm_opt[OPT_WARNING]) {
loccnt -= opcode_length;
warning("Warning: Converted to long-branch!\n");
warning("Converted to long-branch!\n");
loccnt += opcode_length;
}
} else {
/* has target already been defined (this pass)? */
if ((branch->convert == 0) &&
(branch->label != NULL) &&
(branch->label->defthispass != 0) &&
/* check if it is outside short-branch range */
if ((branch->label != NULL) &&
(branch->label->defthispass) &&
(branch->label->type == DEFABS)) {
/* check if it is outside short-branch range */
addr = (branch->label->value & 0xFFFF) - branch->addr;

if (addr > 0x7Fu && addr < ~0x7Fu) {
if (branch->convert == 0)
++branches_changed;
branch->convert = 1;
++xvertlong;
}

branch->checked = 1;
}
}
Expand All @@ -1133,40 +1148,47 @@ getbranch(int opcode_length)
/* ----
* branchopt()
* ----
* convert out-of-range short-branches into long-branches
* convert out-of-range short-branches into long-branches, also
* convert incorrectly-guessed long-branches back to short-branches
*/

int
branchopt(void)
{
struct t_branch * branch;
unsigned int addr;
int changed = 0;
int just_changed = 0;

/* look through the entire list of branch instructions */
for (branch = branchlst; branch != NULL; branch = branch->next) {

/* check to see if a short-branch needs to be converted */
if ((branch->convert == 0) &&
(branch->checked == 0) &&
/* check to see if a branch needs to be converted */
if ((branch->checked == 0) &&
(branch->label != NULL) &&
(branch->label->type == DEFABS)) {
/* check if it is outside short-branch range */
addr = (branch->label->value & 0xFFFF) - branch->addr;

if (addr > 0x7Fu && addr < ~0x7Fu) {
if (branch->convert == 0)
++just_changed;
branch->convert = 1;
++changed;
#if 0 /* This saving just doesn't seem to be worth an extra pass */
} else {
if (branch->convert == 1)
++just_changed;
branch->convert = 0;
#endif
}
}
}

/* report total changes this pass */
xvertlong += changed;
if (xvertlong)
printf("Changed %d branches from short to long.\n", xvertlong);
branches_changed += just_changed;
if (branches_changed)
printf(" Changed %3d branches from short to long.\n", branches_changed);

/* do another pass if anything just changed, except if KickC because */
/* any changes during the pass itself can change a forward-reference */
return ((kickc_opt) ? xvertlong : changed);
return ((kickc_opt) ? branches_changed : just_changed);
}
Loading

0 comments on commit a627890

Please sign in to comment.