• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

MOT6502 assembler, disassembler and linker


Commit MetaInfo

修订版6a5659c85194e76ee15b1da179a1467c00f58a2a (tree)
时间2013-02-16 13:41:02
作者astoria-d <astoria-d@mail...>
Commiterastoria-d

Log Message

branch instruction bug fix

更改概述

差异

--- a/assembler/6502inst.c
+++ b/assembler/6502inst.c
@@ -90,7 +90,7 @@ static int inst_tbl_init(void) {
9090 }
9191
9292 static void inst_tbl_free(void) {
93- dprint ("inst_tbl_free.\n");
93+ //dprint ("inst_tbl_free.\n");
9494
9595 int index = 0;
9696
@@ -397,7 +397,7 @@ void write_str(const char* str) {
397397 //dprint("write_str:%s\n", str);
398398 int len = strlen(str) + 1;
399399 FILE* fp = get_current_file();
400- char* p = str;
400+ const char* p = str;
401401 while (len-- > 0)
402402 fwrite(str++, 1, 1, fp);
403403 deb_print_str(p);
@@ -443,6 +443,22 @@ void deb_print_nl(void) {
443443 #endif /*DEB_PRINT*/
444444 }
445445
446+int is_branch_inst(const char* mnemonic) {
447+ if (!strcasecmp(mnemonic, "BPL") ||
448+ !strcasecmp(mnemonic, "BMI") ||
449+ !strcasecmp(mnemonic, "BVC") ||
450+ !strcasecmp(mnemonic, "BVS") ||
451+ !strcasecmp(mnemonic, "BCC") ||
452+ !strcasecmp(mnemonic, "BCS") ||
453+ !strcasecmp(mnemonic, "BNE") ||
454+ !strcasecmp(mnemonic, "BEQ")
455+ ) {
456+ return TRUE;
457+ }
458+ else
459+ return FALSE;
460+}
461+
446462
447463 int inst_encode_init() {
448464 inst_tbl_init();
--- a/assembler/nesas-main.c
+++ b/assembler/nesas-main.c
@@ -121,6 +121,8 @@ int main (int argc, char** argv) {
121121 return RT_ERROR;
122122 }
123123
124+ printf("assemble succeeded.\n");
125+
124126 done:
125127
126128 if (need_close)
--- a/assembler/nesas.y
+++ b/assembler/nesas.y
@@ -16,6 +16,7 @@ int dir_data_size = 0;
1616
1717 void add_unresolved_ref(const char* symbol);
1818 int get_abs_addr(unsigned short abs_addr);
19+int is_branch_inst(const char* mnemonic);
1920
2021 #if 1
2122 #define dprint(...)
@@ -318,7 +319,12 @@ inst_param
318319 }
319320 else {
320321 add_unresolved_ref($<str>1);
321- num = 0xFFFF;
322+
323+ ///branch instruction has 1 byte operand
324+ if (is_branch_inst(cur_inst) )
325+ num = 0xFF;
326+ else
327+ num = 0xFFFF;
322328 }
323329
324330 if (!write_inst(cur_inst, PARAM_NUM, num)) {
--- a/assembler/segment.c
+++ b/assembler/segment.c
@@ -94,8 +94,11 @@ int addr_lookup(const char* symbol, unsigned short* return_addr) {
9494 struct symmap* pp = psym;
9595
9696 if (!strcmp(symbol, psym->symbol)) {
97+ /*
9798 dprint("addr_lookup %s found %04x, current:%08x\n", psym->symbol,
9899 psym->addr, get_current_pc());
100+ */
101+
99102 found = TRUE;
100103 *return_addr = psym->addr;
101104 break;
@@ -198,7 +201,7 @@ unsigned short get_current_pc(void) {
198201 static void clear_seglist(struct seginfo* sg_head) {
199202 struct seginfo* pseg;
200203
201- dprint("clear_seglist.\n");
204+ //dprint("clear_seglist.\n");
202205 pseg = sg_head;
203206 while (pseg != NULL) {
204207 struct seginfo* pp = pseg;
@@ -263,8 +266,10 @@ int finalize_segment(void) {
263266 return FALSE;
264267 }
265268 addr = get_abs_addr(addr);
269+ /*
266270 dprint("symbol ref at %04x to %s resolved, %04x.\n",
267- unres->addr, unres->symbol, addr);/**/
271+ unres->addr, unres->symbol, addr);
272+ */
268273 fseek(fp, unres->addr, SEEK_SET);
269274 fwrite(&addr, 2, 1, fp);
270275 }