Mercurial > repos > blastem
comparison cpu_dsl.py @ 1709:9c058ea77b7a
Implementation of carry/overflow flags for adc instructions in CPU DSL
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jan 2019 22:49:02 -0800 |
parents | 5bfed2eedc9d |
children | 2344b3650b38 |
comparison
equal
deleted
inserted
replaced
1708:5bfed2eedc9d | 1709:9c058ea77b7a |
---|---|
418 reg = prog.resolveReg(reg, None, (), False) | 418 reg = prog.resolveReg(reg, None, (), False) |
419 return '({reg} & 1 << {bit})'.format(reg=reg, bit=bit) | 419 return '({reg} & 1 << {bit})'.format(reg=reg, bit=bit) |
420 else: | 420 else: |
421 return prog.resolveReg(carryStorage, None, (), False) | 421 return prog.resolveReg(carryStorage, None, (), False) |
422 | 422 |
423 def _adcCImpl(prog, params, rawParams): | 423 def _adcCImpl(prog, params, rawParams, flagUpdates): |
424 | 424 needsCarry = needsOflow = needsHalf = False |
425 return '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = params[2], | 425 if flagUpdates: |
426 a = params[0], b = params[1], check=_getCarryCheck(prog) | 426 for flag in flagUpdates: |
427 calc = prog.flags.flagCalc[flag] | |
428 if calc == 'carry': | |
429 needsCarry = True | |
430 elif calc == 'half-carry': | |
431 needsHalf = True | |
432 elif calc == 'overflow': | |
433 needsOflow = True | |
434 decl = '' | |
435 carryCheck = _getCarryCheck(prog) | |
436 if needsCarry or needsOflow or needsHalf: | |
437 size = prog.paramSize(rawParams[2]) | |
438 if needsCarry: | |
439 size *= 2 | |
440 decl,name = prog.getTemp(size) | |
441 dst = prog.carryFlowDst = name | |
442 prog.lastA = params[0] | |
443 prog.lastB = '({b} ^ ({check} ? 1 : 0))'.format(b = params[1], check = carryCheck) | |
444 prog.lastBFlow = prog.lastB | |
445 else: | |
446 dst = params[2] | |
447 return decl + '\n\t{dst} = {a} + {b} + ({check} ? 1 : 0);'.format(dst = dst, | |
448 a = params[0], b = params[1], check = carryCheck | |
427 ) | 449 ) |
428 | 450 |
429 def _sbcCImpl(prog, params, rawParams): | 451 def _sbcCImpl(prog, params, rawParams): |
430 return '\n\t{dst} = {a} - {b} - ({check} ? 1 : 0);'.format(dst = params[2], | 452 return '\n\t{dst} = {a} - {b} - ({check} ? 1 : 0);'.format(dst = params[2], |
431 a = params[0], b = params[1], check=_getCarryCheck(prog) | 453 a = params[0], b = params[1], check=_getCarryCheck(prog) |