fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 161 lines 3.5 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/cpu/e6502/ea.c * 7 * Created: 2004-05-25 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2004-2010 Hampa Hug <hampa@hampa.ch> * 9 *****************************************************************************/ 10 11/***************************************************************************** 12 * This program is free software. You can redistribute it and / or modify it * 13 * under the terms of the GNU General Public License version 2 as published * 14 * by the Free Software Foundation. * 15 * * 16 * This program is distributed in the hope that it will be useful, but * 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 * Public License for more details. * 20 *****************************************************************************/ 21 22 23#include "e6502.h" 24#include "internal.h" 25 26#include <stdlib.h> 27#include <stdio.h> 28#include <stdarg.h> 29 30 31unsigned char e6502_get_imm (e6502_t *c) 32{ 33 e6502_get_inst1 (c); 34 35 c->ea_page = 0; 36 37 return (c->inst[1]); 38} 39 40unsigned short e6502_get_ea_idx_ind_x (e6502_t *c) 41{ 42 unsigned ial, adl, adh; 43 44 e6502_get_inst1 (c); 45 46 ial = c->inst[1]; 47 ial = (ial + e6502_get_x (c)) & 0xff; 48 49 adl = e6502_get_mem8 (c, ial); 50 adh = e6502_get_mem8 (c, (ial + 1) & 0xff); 51 52 c->ea = (adh << 8) | adl; 53 c->ea_page = 0; 54 55 return (c->ea); 56} 57 58unsigned short e6502_get_ea_zpg (e6502_t *c) 59{ 60 e6502_get_inst1 (c); 61 62 c->ea = c->inst[1]; 63 c->ea_page = 0; 64 65 return (c->ea); 66} 67 68unsigned short e6502_get_ea_abs (e6502_t *c) 69{ 70 e6502_get_inst2 (c); 71 72 c->ea = ((unsigned short) c->inst[2] << 8) + c->inst[1]; 73 c->ea_page = 0; 74 75 return (c->ea); 76} 77 78unsigned short e6502_get_ea_ind_idx_y (e6502_t *c) 79{ 80 unsigned ial, adl, adh; 81 82 e6502_get_inst1 (c); 83 84 ial = c->inst[1]; 85 86 adl = e6502_get_mem8 (c, ial); 87 adh = e6502_get_mem8 (c, (ial + 1) & 0xff); 88 89 adl += e6502_get_y (c); 90 91 if (adl < 0x100) { 92 c->ea_page = 0; 93 } 94 else { 95 c->ea_page = 1; 96 adl = adl & 0xff; 97 adh = (adh + 1) & 0xff; 98 } 99 100 c->ea = (adh << 8) | adl; 101 102 return (c->ea); 103} 104 105unsigned short e6502_get_ea_zpg_x (e6502_t *c) 106{ 107 e6502_get_inst1 (c); 108 109 c->ea = (c->inst[1] + e6502_get_x (c)) & 0xff; 110 c->ea_page = 0; 111 112 return (c->ea); 113} 114 115unsigned short e6502_get_ea_zpg_y (e6502_t *c) 116{ 117 e6502_get_inst1 (c); 118 119 c->ea = (c->inst[1] + e6502_get_y (c)) & 0xff; 120 c->ea_page = 0; 121 122 return (c->ea); 123} 124 125unsigned short e6502_get_ea_abs_y (e6502_t *c) 126{ 127 unsigned short tmp; 128 129 e6502_get_inst2 (c); 130 131 tmp = e6502_mk_uint16 (c->inst[1], c->inst[2]); 132 c->ea = (tmp + e6502_get_y (c)) & 0xffff; 133 134 if ((tmp ^ c->ea) & 0xff00) { 135 c->ea_page = 1; 136 } 137 else { 138 c->ea_page = 0; 139 } 140 141 return (c->ea); 142} 143 144unsigned short e6502_get_ea_abs_x (e6502_t *c) 145{ 146 unsigned short tmp; 147 148 e6502_get_inst2 (c); 149 150 tmp = e6502_mk_uint16 (c->inst[1], c->inst[2]); 151 c->ea = (tmp + e6502_get_x (c)) & 0xffff; 152 153 if ((tmp ^ c->ea) & 0xff00) { 154 c->ea_page = 1; 155 } 156 else { 157 c->ea_page = 0; 158 } 159 160 return (c->ea); 161}