/* * Copyright (c) 1987 Fujitsu * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /* emitBranch_6502.c -- Routines to deal with code generation for branches and jumps in the Macross assembler (6502 version). Chip Morningstar -- Lucasfilm Ltd. 23-April-1985 */ #include "macrossTypes.h" #include "macrossGlobals.h" #include "buildStuff.h" #include "emitStuff.h" #include "parserMisc.h" #include "semanticMisc.h" /* emitRelativeBranch emits a relative branch instruction for the 6502, branching from the current location given a condition to branch upon and a target address. */ void emitRelativeBranch(conditionType condition, valueType *target, valueType *fixupLocation) { int i; #define COMPOUND 0x00 #define BPL_OPCODE 0x10 #define BMI_OPCODE 0x30 #define BVC_OPCODE 0x50 #define BVS_OPCODE 0x70 #define BCC_OPCODE 0x90 #define BCS_OPCODE 0xB0 #define BNE_OPCODE 0xD0 #define NOP_OPCODE 0xEA #define BEQ_OPCODE 0xF0 static byte conditionalBranchOpcodes[] = { /* CARRY_COND */ BCS_OPCODE, /* ZERO_COND */ BEQ_OPCODE, /* NEGATIVE_COND */ BMI_OPCODE, /* OVERFLOW_COND */ BVS_OPCODE, /* LT_COND */ BCC_OPCODE, /* LEQ_COND */ COMPOUND, /* SLT_COND */ COMPOUND, /* SLEQ_COND */ COMPOUND, /* ALWAYS_COND */ NOP_OPCODE, /* NOT_CARRY_COND */ BCC_OPCODE, /* NOT_ZERO_COND */ BNE_OPCODE, /* NOT_NEGATIVE_COND */ BPL_OPCODE, /* NOT_OVERFLOW_COND */ BVC_OPCODE, /* GEQ_COND */ BCS_OPCODE, /* GT_COND */ COMPOUND, /* SGEQ_COND */ COMPOUND, /* SGT_COND */ COMPOUND, /* NEVER_COND */ NOP_OPCODE }; #define conditionalFixup(n) if (fixupLocation != NULL) \ fixupLocation[n] = currentLocationCounter; \ emitRelativeByteOffset(target); if (fixupLocation != NULL) for (i=0; ikindOfValue != ABSOLUTE_VALUE) noteAnonymousReference(); emitWordValue(target); } } return(result); }