Extend .advance to allow a filler expression.

This commit is contained in:
Michael C. Martin 2012-05-30 20:45:37 -07:00
parent e58d5ccaac
commit eae4ea7dcd
4 changed files with 11 additions and 5 deletions

View File

@ -94,8 +94,13 @@ def pragmaOrg(ppt, line, result):
def pragmaAdvance(ppt, line, result): def pragmaAdvance(ppt, line, result):
"Outputs filler until reaching the target PC" "Outputs filler until reaching the target PC"
newPC = FE.parse_expr(line) newPC = FE.parse_expr(line)
if str(line.lookahead(0)) == ",":
line.pop()
fillexpr = FE.parse_expr(line)
else:
fillexpr = IR.ConstantExpr(0)
line.expect("EOL") line.expect("EOL")
result.append(IR.Node(ppt, "Advance", newPC)) result.append(IR.Node(ppt, "Advance", newPC, fillexpr))
def pragmaCheckpc(ppt, line, result): def pragmaCheckpc(ppt, line, result):
"Enforces that the PC has not exceeded a certain point" "Enforces that the PC has not exceeded a certain point"

View File

@ -575,7 +575,6 @@ class Assembler(Pass):
if (pc > target): if (pc > target):
Err.log("Attempted to .advance backwards: $%x to $%x" % (pc, target)) Err.log("Attempted to .advance backwards: $%x to $%x" % (pc, target))
else: else:
zero = IR.ConstantExpr(0) for i in xrange(target-pc): self.outputbyte(node.data[1], env)
for i in xrange(target-pc): self.outputbyte(zero, env)
self.filler += target-pc self.filler += target-pc
env.setPC(target) env.setPC(target)

Binary file not shown.

View File

@ -1,7 +1,9 @@
; This data file just dumps out $00-$0F repeatedly with different forms. ; This data file just dumps out $00-$0F repeatedly with different forms,
; bracketed by $00s and then $60s.
.advance $10, ^
.byte 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 .byte 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
.word 256, $0302, $0504, $0706, $0908, $0b0a, $0d0c, $0f0e .word 256, $0302, $0504, $0706, $0908, $0b0a, $0d0c, $0f0e
.dword $03020100, $07060504, $0b0a0908, $0f0e0d0c .dword $03020100, $07060504, $0b0a0908, $0f0e0d0c
.wordbe 1, $0203, $0405, $0607, $0809, $0a0b, $0c0d, $0e0f .wordbe 1, $0203, $0405, $0607, $0809, $0a0b, $0c0d, $0e0f
.dwordbe $010203, $04050607, $08090a0b, $0c0d0e0f .dwordbe $010203, $04050607, $08090a0b, $0c0d0e0f
.advance $70, ^