Skip to content

Commit

Permalink
Update PCEAS to generate up to 8MByte (1024 bank) ROMs.
Browse files Browse the repository at this point in the history
This also includes some small code-cleanup to remove a few of the magic-numbers.
  • Loading branch information
jbrandwood committed Mar 8, 2024
1 parent db42517 commit 125a869
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 259 deletions.
8 changes: 4 additions & 4 deletions src/mkit/as/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ getoperand(int *ip, int flag, int last_char)
if (mode == (ABS | ABS_X | ABS_Y | ZP | ZP_X | ZP_Y)) {
/* was there an undefined or undefined-this-pass symbol? */
if (undef || notyetdef ||
((value & 0x007FFF00) != machine->ram_base)) {
// ((value & 0x007FFF00) && ((value & 0x007FFF00) != machine->ram_base))) {
((value & 0x3FFFFF00) != machine->ram_base)) {
// ((value & 0x3FFFFF00) && ((value & 0x3FFFFF00) != machine->ram_base))) {
/* use ABS addressing, if available */
if (flag & ABS)
mode &= ~ZP;
Expand Down Expand Up @@ -896,7 +896,7 @@ getoperand(int *ip, int flag, int last_char)
value++;
}
/* check address validity */
if ((value & 0x007FFF00) && ((value & 0x007FFF00) != machine->ram_base))
if ((value & 0x3FFFFF00) && ((value & 0x3FFFFF00) != machine->ram_base))
error("Incorrect zero page address!");
}

Expand All @@ -911,7 +911,7 @@ getoperand(int *ip, int flag, int last_char)
error("Instruction extension not supported in immediate mode!");
else {
/* check value validity */
if (((value & 0x007FFF00) > 0xFF) && ((value & 0x007FFF00) < 0x007FFF00))
if (((value & 0x3FFFFF00) > 0xFF) && ((value & 0x3FFFFF00) < 0x3FFFFF00))
error("Incorrect immediate value!");
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/mkit/as/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ do_db(int *ip)
}

/* check for overflow */
if (((value & 0x007FFFFF) > 0xFF) && ((value & 0x007FFFFF) < 0x007FFF80)) {
if (((value & 0x3FFFFFFF) > 0xFF) && ((value & 0x3FFFFFFF) < 0x3FFFFF80)) {
error("Overflow error!");
return;
}
Expand Down Expand Up @@ -399,7 +399,7 @@ do_dw(int *ip)
}

/* check for overflow */
if (((value & 0x007FFFFF) > 0xFFFF) && ((value & 0x007FFFFF) < 0x007F8000)) {
if (((value & 0x3FFFFFFF) > 0xFFFF) && ((value & 0x3FFFFFFF) < 0x3FFF8000)) {
error("Overflow error!");
return;
}
Expand Down Expand Up @@ -482,7 +482,7 @@ do_dwl(int *ip)
}

/* check for overflow */
if (((value & 0x007FFFFF) > 0xFFFF) && ((value & 0x007FFFFF) < 0x007F8000)) {
if (((value & 0x3FFFFFFF) > 0xFFFF) && ((value & 0x3FFFFFFF) < 0x3FFF8000)) {
error("Overflow error!");
return;
}
Expand Down Expand Up @@ -565,7 +565,7 @@ do_dwh(int *ip)
}

/* check for overflow */
if (((value & 0x007FFFFF) > 0xFFFF) && ((value & 0x007FFFFF) < 0x007F8000)) {
if (((value & 0x3FFFFFFF) > 0xFFFF) && ((value & 0x3FFFFFFF) < 0x3FFF8000)) {
error("Overflow error!");
return;
}
Expand Down Expand Up @@ -799,15 +799,15 @@ do_org(int *ip)
switch (section) {
case S_ZP:
/* zero page section */
if ((value & 0x007FFF00) && ((value & 0x007FFF00) != machine->ram_base)) {
if ((value & 0x3FFFFF00) && ((value & 0x3FFFFF00) != machine->ram_base)) {
error("Invalid address!");
return;
}
break;

case S_BSS:
/* ram section */
if (((value & 0x007FFFFF) < machine->ram_base) || ((value & 0x007FFFFF) >= (machine->ram_base + machine->ram_limit))) {
if (((value & 0x3FFFFFFF) < machine->ram_base) || ((value & 0x3FFFFFFF) >= (machine->ram_base + machine->ram_limit))) {
error("Invalid address!");
return;
}
Expand Down Expand Up @@ -1034,13 +1034,7 @@ do_incbin(int *ip)
fseek(fp, 0, SEEK_SET);

/* check if it will fit in the rom */
if (bank >= RESERVED_BANK) {
if ((loccnt + size) > 0x2000) {
fclose(fp);
fatal_error("PROC overflow!");
return;
}
} else {
if ((section_flags[section] & S_IN_ROM) && (bank < RESERVED_BANK)) {
/* check if it will fit in the rom */
if (((bank << 13) + loccnt + size) > rom_limit) {
fclose(fp);
Expand Down Expand Up @@ -1072,6 +1066,12 @@ do_incbin(int *ip)
/* output line */
println();
}
} else {
if ((loccnt + size) > section_limit[section]) {
fclose(fp);
fatal_error("Too large to fit in the current section!");
return;
}
}

/* close file */
Expand All @@ -1093,7 +1093,7 @@ do_incbin(int *ip)
}

/* update rom size */
if (bank < RESERVED_BANK) {
if ((section_flags[section] & S_IN_ROM) && (bank < RESERVED_BANK)) {
if (bank > max_bank) {
if (loccnt)
max_bank = bank;
Expand Down Expand Up @@ -1581,7 +1581,7 @@ do_ds(int *ip)
}

/* update rom size */
if (bank < RESERVED_BANK) {
if ((section_flags[section] & S_IN_ROM) && (bank < RESERVED_BANK)) {
if (bank > max_bank) {
if (loccnt)
max_bank = bank;
Expand Down
26 changes: 21 additions & 5 deletions src/mkit/as/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@
#define MACHINE_NES 1
#define MACHINE_FUJI 2

/* maximum user rom size */
#define ROM_BANKS 1024

/* reserved bank index */
#define RESERVED_BANK 0xF0
#define PROC_BANK 0xF1
#define GROUP_BANK 0xF2
#define STRIPPED_BANK 0xF3
#define RESERVED_BANK (ROM_BANKS + 0)
#define PROC_BANK (ROM_BANKS + 1)
#define GROUP_BANK (ROM_BANKS + 2)
#define STRIPPED_BANK (ROM_BANKS + 3)

/* number of reserved banks used beyond ROM_BANKS */
#define RESERVED_BANKS 4

/* total number of banks to allocate for workspace */
#define MAX_BANKS (ROM_BANKS + RESERVED_BANKS)

/* tile format for encoder */
#define CHUNKY_TILE 1
Expand All @@ -50,8 +59,12 @@
#define S_BSS 1
#define S_CODE 2
#define S_DATA 3
#define MAX_S 4 /* selectable section types */
#define S_PROC 4 /* trampolines for .proc */

/* section flags */
#define S_IN_ROM 1

/* assembler options */
#define OPT_LIST 0
#define OPT_MACRO 1
Expand Down Expand Up @@ -178,6 +191,9 @@
#define BRANCH_PASS 1
#define LAST_PASS 2

/* size of various hashing tables */
#define HASH_COUNT 256

/* structs */
typedef struct t_opcode {
struct t_opcode *next;
Expand Down Expand Up @@ -289,6 +305,6 @@ typedef struct t_machine {
int (*pack_16x16_tile)(unsigned char *, void *, int, int);
int (*pack_16x16_sprite)(unsigned char *, void *, int, int);
void (*write_header)(FILE *, int);
} MACHINE;
} t_machine;

#endif // DEFS_H
15 changes: 8 additions & 7 deletions src/mkit/as/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ push_val(int type)
pc_symbol.tag = tag_value;
pc_symbol.page = page;

if (bank >= RESERVED_BANK)
pc_symbol.bank = bank;
else
if ((section_flags[section] & S_IN_ROM) && (bank < RESERVED_BANK))
pc_symbol.bank = bank + bank_base;
else
pc_symbol.bank = bank;

if (pc_symbol.value >= 0x2000) {
pc_symbol.bank = (pc_symbol.bank + 1);
Expand Down Expand Up @@ -1009,14 +1009,15 @@ do_op(void)
if (!check_func_args("BANK"))
return (0);
if (pass == LAST_PASS) {
if (expr_lablptr->bank == RESERVED_BANK) {
error("No BANK index for this symbol!");
if (expr_lablptr->bank >= RESERVED_BANK) {
if (expr_lablptr->bank == RESERVED_BANK)
error("No BANK index for this symbol!");
val[0] = 0;
break;
}
}
/* complicated math to deal with BANK(label+value) */
val[0] = (expr_lablptr->bank + (val[0] / 8192) - (expr_lablptr->value / 8192));
/* complicated math to deal with BANK(label+value), but keep it 8-bit */
val[0] = 0xFF & (expr_lablptr->bank + (val[0] / 8192) - (expr_lablptr->value / 8192));
break;

/* PAGE */
Expand Down
Loading

0 comments on commit 125a869

Please sign in to comment.