• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Emily's Z80 assembler for the Gameboy.


Commit MetaInfo

Revisionb5e4f452f17581fdc39d0dc4a09daf6643b88681 (tree)
Zeit2021-02-09 11:46:58
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Add relative addressing for jr opcodes

Ändern Zusammenfassung

Diff

--- a/em_gb_asm.py
+++ b/em_gb_asm.py
@@ -116,6 +116,10 @@ class Block:
116116 self._pushReloc(l, self.relocs8l)
117117 self.pushByte(0)
118118
119+ def pushRelocRel(self, l):
120+ self._pushReloc(l, self.relocsRel)
121+ self.pushByte(0)
122+
119123 def pushASCII(self, s):
120124 self.ascii.append((len(self.data), len(s)))
121125 for c in s:
@@ -151,6 +155,15 @@ class Block:
151155 for addr in self.relocs8l[l]:
152156 dest = self.resolveReloc(l, addr, all_blocks)
153157 self.data[addr] = dest & 0xFF
158+ for l in self.relocsRel:
159+ for addr in self.relocsRel[l]:
160+ dest = self.resolveReloc(l, addr, all_blocks) - 1
161+ # Validate the distance...
162+ abs_addr = self.base + addr
163+ if dest - 128 > abs_addr or dest + 127 < abs_addr:
164+ self.error("Relative jump is too far")
165+ else:
166+ self.data[addr] = (dest - abs_addr) & 0xFF
154167
155168 def evalBinop(self, expr, i, oplist, func):
156169 i, val = func(self, expr, i)
@@ -294,7 +307,12 @@ SOME_ARGS = {
294307 "l":0x85,
295308 "(hl)":0x86,
296309 "a":0x87,
297- "hl":{ "sp":0x39 },
310+ "hl":{
311+ "bc":0x09,
312+ "de":0x19,
313+ "hl":0x29,
314+ "sp":0x39
315+ },
298316 "sp":{ "r8":0xE9 },
299317 "d8":0xC6
300318 },
@@ -500,12 +518,15 @@ SOME_ARGS["ld"]["e"]["d8"] = 0x1E
500518 SOME_ARGS["ld"]["l"]["d8"] = 0x2E
501519 SOME_ARGS["ld"]["a"]["d8"] = 0x3E
502520
503-def locateOperand(op, ptr, allow=(8,16)):
504- for p in "adri":
521+def locateOperand(op, ptr, allow=(8,16,'r')):
522+ prefix_opts = "adi"
523+ if 'r' in allow:
524+ prefix_opts += 'r'
525+ for p in prefix_opts:
505526 opts = []
506527 if 16 in allow:
507528 opts.append(("16", Block.pushShort))
508- if 8 in allow:
529+ if 8 in allow or p == 'r':
509530 opts.append(("8", Block.pushByte))
510531 for t in opts:
511532 s, func = t
@@ -516,6 +537,7 @@ def locateOperand(op, ptr, allow=(8,16)):
516537 o = "(" + o + ")"
517538 if o in op:
518539 return (o, func)
540+
519541 print("Error in " + str(op))
520542 return (None, None)
521543
@@ -538,14 +560,14 @@ def writeOpcode(mnemonic, block, ops, i, operands):
538560 num = block.eval(operand[1:-1])
539561 # print("INFO: Evaluated " + operand[1:-1] + " as " + hex(num))
540562 else:
541- if operand[0] in "<>=":
563+ if operand[0] in "<>=@":
542564 c = operand[0]
543565 operand = operand[1:]
544566 operand = c + block.equ.get(operand, operand)
545567 else:
546568 operand = block.equ.get(operand, operand)
547569 try:
548- if operand[0] in "<>=":
570+ if operand[0] in "<>=@":
549571 c = operand[0]
550572 num = int(operand[1:], 0)
551573 if c == '>':
@@ -571,11 +593,14 @@ def writeOpcode(mnemonic, block, ops, i, operands):
571593 elif operand[0] == '<':
572594 pushReloc = Block.pushReloc8l
573595 allow = [8]
596+ elif operand[0] == '@':
597+ pushReloc = Block.pushRelocRel
598+ allow = ['r']
574599 else:
575600 pushReloc = Block.pushReloc16
576601 allow = [16]
577602
578- if operand[0] in "=<>":
603+ if operand[0] in "=<>@":
579604 operand = operand[1:]
580605
581606 key, func = locateOperand(ops, ptr, allow)