fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 187 lines 4.5 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/arch/ibmpc/atari-pc.c * 7 * Created: 2018-09-01 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2018 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/* Atari PC specific code */ 23 24 25#include "main.h" 26#include "ibmpc.h" 27#include "atari-pc.h" 28 29#include <stdlib.h> 30#include <string.h> 31 32#ifdef HAVE_SYS_TIME_H 33#include <sys/time.h> 34#endif 35 36#include <chipset/clock/mc146818a.h> 37 38#include <lib/log.h> 39 40#include <libini/libini.h> 41 42 43#ifndef DEBUG_ATARI_PC 44#define DEBUG_ATARI_PC 0 45#endif 46 47 48static 49void atari_pc_set_turbo (ibmpc_t *pc, int val) 50{ 51 if (val) { 52 pc_set_speed (pc, pc->atari_pc_turbo); 53 } 54 else { 55 pc_set_speed (pc, 1); 56 } 57} 58 59static 60void atari_pc_set_port_34 (ibmpc_t *pc, unsigned char val) 61{ 62 if ((pc->atari_pc_port34 ^ val) & 1) { 63 atari_pc_set_turbo (pc, val & 1); 64 } 65 66#if DEBUG_ATARI_PC >= 1 67 pc_log_deb ("ATARI: 0034 <- %02X\n", val); 68#endif 69 70 pc->atari_pc_port34 = val; 71} 72 73int atari_pc_get_port8 (ibmpc_t *pc, unsigned long addr, unsigned char *val) 74{ 75 if ((pc->model & PCE_IBMPC_ATARI) == 0) { 76 return (1); 77 } 78 79 switch (addr) { 80 case 0x34: 81 *val = pc->atari_pc_port34; 82 return (0); 83 84 case 0x170: 85 *val = pc->atari_pc_rtc_port; 86 return (0); 87 88 case 0x171: 89 if (pc->atari_pc_rtc != NULL) { 90 *val = mc146818a_get_uint8 (pc->atari_pc_rtc, pc->atari_pc_rtc_port & 0x3f); 91 } 92 else { 93 *val = 0; 94 } 95 96 return (0); 97 98 case 0x3c2: 99 *val = pc->atari_pc_switches; 100 101#if DEBUG_ATARI_PC >= 1 102 fprintf (stderr, "ATARI: 03C2 <- %02X\n", *val); 103#endif 104 105 return (0); 106 } 107 108 return (1); 109} 110 111int atari_pc_set_port8 (ibmpc_t *pc, unsigned long addr, unsigned char val) 112{ 113 if ((pc->model & PCE_IBMPC_ATARI) == 0) { 114 return (1); 115 } 116 117 switch (addr) { 118 case 0x34: 119 atari_pc_set_port_34 (pc, val); 120 return (0); 121 122 case 0x170: 123 pc->atari_pc_rtc_port = val; 124 return (0); 125 126 case 0x171: 127 if (pc->atari_pc_rtc != NULL) { 128 mc146818a_set_uint8 (pc->atari_pc_rtc, pc->atari_pc_rtc_port & 0x3f, val); 129 } 130 return (0); 131 } 132 133 return (1); 134} 135 136void pc_setup_atari_pc (ibmpc_t *pc, ini_sct_t *ini) 137{ 138 ini_sct_t *sct; 139 unsigned switches, turbo; 140 const char *rtc, *start; 141 142 pc->atari_pc_turbo = 2; 143 pc->atari_pc_port34 = 0; 144 pc->atari_pc_switches = 0; 145 pc->atari_pc_rtc_port = 0; 146 pc->atari_pc_rtc = NULL; 147 148 if ((pc->model & PCE_IBMPC_ATARI) == 0) { 149 return; 150 } 151 152 sct = ini_next_sct (ini, NULL, "atari_pc"); 153 154 ini_get_uint16 (sct, "switches", &switches, 0); 155 ini_get_uint16 (sct, "turbo", &turbo, 2); 156 ini_get_string (sct, "rtc", &rtc, NULL); 157 ini_get_string (sct, "rtc_start", &start, NULL); 158 159 pce_log_tag (MSG_INF, "ATARI:", 160 "rtc=%s rtc start=%s switches=%02X turbo=%u\n", 161 (rtc == NULL) ? "<none>" : rtc, 162 (start == NULL) ? "now" : start, 163 switches, turbo 164 ); 165 166 pc->atari_pc_turbo = turbo; 167 pc->atari_pc_switches = switches; 168 169 if ((pc->atari_pc_rtc = mc146818a_new()) == NULL) { 170 return; 171 } 172 173 mc146818a_init (pc->atari_pc_rtc); 174 mc146818a_set_input_clock (pc->atari_pc_rtc, PCE_IBMPC_CLK2); 175 mc146818a_set_century_offset (pc->atari_pc_rtc, 0x32); 176 mc146818a_set_fname (pc->atari_pc_rtc, rtc); 177 mc146818a_load (pc->atari_pc_rtc); 178 mc146818a_set_time_string (pc->atari_pc_rtc, start); 179} 180 181void atari_pc_del (ibmpc_t *pc) 182{ 183 if (pc->atari_pc_rtc != NULL) { 184 mc146818a_save (pc->atari_pc_rtc); 185 mc146818a_free (pc->atari_pc_rtc); 186 } 187}