src/build/makedep.c
| r0 | r9148 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | MAME source code dependency generator |
| 4 | |
| 5 | **************************************************************************** |
| 6 | |
| 7 | Copyright Aaron Giles |
| 8 | All rights reserved. |
| 9 | |
| 10 | Redistribution and use in source and binary forms, with or without |
| 11 | modification, are permitted provided that the following conditions are |
| 12 | met: |
| 13 | |
| 14 | * Redistributions of source code must retain the above copyright |
| 15 | notice, this list of conditions and the following disclaimer. |
| 16 | * Redistributions in binary form must reproduce the above copyright |
| 17 | notice, this list of conditions and the following disclaimer in |
| 18 | the documentation and/or other materials provided with the |
| 19 | distribution. |
| 20 | * Neither the name 'MAME' nor the names of its contributors may be |
| 21 | used to endorse or promote products derived from this software |
| 22 | without specific prior written permission. |
| 23 | |
| 24 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 27 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 28 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 31 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 33 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | POSSIBILITY OF SUCH DAMAGE. |
| 35 | |
| 36 | ***************************************************************************/ |
| 37 | |
| 38 | #include <stdio.h> |
| 39 | #include <stdlib.h> |
| 40 | #include <string.h> |
| 41 | #include <ctype.h> |
| 42 | #include <zlib.h> |
| 43 | #include "osdcore.h" |
| 44 | #include "astring.h" |
| 45 | #include "corefile.h" |
| 46 | #include "tagmap.h" |
| 47 | |
| 48 | |
| 49 | /*************************************************************************** |
| 50 | CONSTANTS |
| 51 | ***************************************************************************/ |
| 52 | |
| 53 | #define HASH_SIZE 193 |
| 54 | |
| 55 | |
| 56 | /*************************************************************************** |
| 57 | TYPE DEFINITIONS |
| 58 | ***************************************************************************/ |
| 59 | |
| 60 | typedef struct _include_path include_path; |
| 61 | struct _include_path |
| 62 | { |
| 63 | include_path * next; |
| 64 | const astring * path; |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | typedef struct _exclude_path exclude_path; |
| 69 | struct _exclude_path |
| 70 | { |
| 71 | exclude_path * next; |
| 72 | const astring * path; |
| 73 | int pathlen; |
| 74 | UINT8 recursive; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | typedef struct _list_entry list_entry; |
| 79 | struct _list_entry |
| 80 | { |
| 81 | list_entry * next; |
| 82 | const astring * name; |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | typedef struct _file_entry file_entry; |
| 87 | |
| 88 | typedef struct _dependency dependency; |
| 89 | struct _dependency |
| 90 | { |
| 91 | dependency * next; |
| 92 | file_entry * file; |
| 93 | }; |
| 94 | |
| 95 | |
| 96 | struct _file_entry |
| 97 | { |
| 98 | astring * name; |
| 99 | dependency * deplist; |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | |
| 104 | /*************************************************************************** |
| 105 | GLOBAL VARIABLES |
| 106 | ***************************************************************************/ |
| 107 | |
| 108 | static include_path *incpaths; |
| 109 | static exclude_path *excpaths; |
| 110 | static tagmap *file_map; |
| 111 | |
| 112 | |
| 113 | |
| 114 | /*************************************************************************** |
| 115 | PROTOTYPES |
| 116 | ***************************************************************************/ |
| 117 | |
| 118 | /* core output functions */ |
| 119 | static int recurse_dir(int srcrootlen, const astring *srcdir); |
| 120 | static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile); |
| 121 | |
| 122 | /* path helpers */ |
| 123 | static astring *find_include_file(int srcrootlen, const astring *srcfile, const astring *filename); |
| 124 | |
| 125 | |
| 126 | |
| 127 | /*************************************************************************** |
| 128 | INLINE FUNCTIONS |
| 129 | ***************************************************************************/ |
| 130 | |
| 131 | /* core output functions */ |
| 132 | static int recurse_dir(int srcrootlen, const astring *srcdir); |
| 133 | static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile); |
| 134 | |
| 135 | /* path helpers */ |
| 136 | static astring *find_include_file(int srcrootlen, const astring *srcfile, const astring *filename); |
| 137 | |
| 138 | |
| 139 | |
| 140 | /*************************************************************************** |
| 141 | MAIN |
| 142 | ***************************************************************************/ |
| 143 | |
| 144 | /*------------------------------------------------- |
| 145 | main - main entry point |
| 146 | -------------------------------------------------*/ |
| 147 | |
| 148 | int main(int argc, char *argv[]) |
| 149 | { |
| 150 | include_path **incpathhead = &incpaths; |
| 151 | exclude_path **excpathhead = &excpaths; |
| 152 | astring *srcdir = NULL; |
| 153 | int unadorned = 0; |
| 154 | int result; |
| 155 | int argnum; |
| 156 | |
| 157 | /* loop over arguments */ |
| 158 | for (argnum = 1; argnum < argc; argnum++) |
| 159 | { |
| 160 | char *arg = argv[argnum]; |
| 161 | |
| 162 | /* include path? */ |
| 163 | if (arg[0] == '-' && arg[1] == 'I') |
| 164 | { |
| 165 | *incpathhead = (include_path *)malloc(sizeof(**incpathhead)); |
| 166 | if (*incpathhead != NULL) |
| 167 | { |
| 168 | (*incpathhead)->next = NULL; |
| 169 | (*incpathhead)->path = astring_replacechr(astring_dupc(&arg[2]), '/', PATH_SEPARATOR[0]); |
| 170 | incpathhead = &(*incpathhead)->next; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* exclude path? */ |
| 175 | else if (arg[0] == '-' && arg[1] == 'X') |
| 176 | { |
| 177 | *excpathhead = (exclude_path *)malloc(sizeof(**excpathhead)); |
| 178 | if (*excpathhead != NULL) |
| 179 | { |
| 180 | astring *path; |
| 181 | (*excpathhead)->next = NULL; |
| 182 | path = astring_replacechr(astring_dupc(&arg[2]), PATH_SEPARATOR[0], '/'); |
| 183 | (*excpathhead)->recursive = (astring_replacec(path, astring_len(path) - 4, "/...", "") != 0); |
| 184 | (*excpathhead)->path = path; |
| 185 | (*excpathhead)->pathlen = astring_len(path); |
| 186 | excpathhead = &(*excpathhead)->next; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /* other parameter */ |
| 191 | else if (arg[0] != '-' && unadorned == 0) |
| 192 | { |
| 193 | srcdir = astring_replacechr(astring_dupc(arg), '/', PATH_SEPARATOR[0]); |
| 194 | unadorned++; |
| 195 | } |
| 196 | else |
| 197 | goto usage; |
| 198 | } |
| 199 | |
| 200 | /* make sure we got 1 parameter */ |
| 201 | if (srcdir == NULL) |
| 202 | goto usage; |
| 203 | |
| 204 | /* create a tagmap for tracking files we've visited */ |
| 205 | file_map = tagmap_alloc(); |
| 206 | |
| 207 | /* recurse over subdirectories */ |
| 208 | result = recurse_dir(astring_len(srcdir), srcdir); |
| 209 | |
| 210 | /* free source and destination directories */ |
| 211 | tagmap_free(file_map); |
| 212 | astring_free(srcdir); |
| 213 | return result; |
| 214 | |
| 215 | usage: |
| 216 | fprintf(stderr, "Usage:\n%s <srcroot> [-Iincpath [-Iincpath [...]]]\n", argv[0]); |
| 217 | return 1; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | |
| 222 | /*************************************************************************** |
| 223 | CORE OUTPUT FUNCTIONS |
| 224 | ***************************************************************************/ |
| 225 | |
| 226 | static int compare_list_entries(const void *p1, const void *p2) |
| 227 | { |
| 228 | const list_entry *entry1 = *(const list_entry **)p1; |
| 229 | const list_entry *entry2 = *(const list_entry **)p2; |
| 230 | return strcmp(astring_c(entry1->name), astring_c(entry2->name)); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /*------------------------------------------------- |
| 235 | recurse_dependencies - recurse through the |
| 236 | dependencies found, adding the mto the tagmap |
| 237 | unless we already exist in the map |
| 238 | -------------------------------------------------*/ |
| 239 | |
| 240 | static void recurse_dependencies(file_entry *file, tagmap *map) |
| 241 | { |
| 242 | int filelen = astring_len(file->name); |
| 243 | exclude_path *exclude; |
| 244 | dependency *dep; |
| 245 | |
| 246 | /* skip if we're in an exclude path */ |
| 247 | for (exclude = excpaths; exclude != NULL; exclude = exclude->next) |
| 248 | if (exclude->pathlen < filelen && strncmp(astring_c(file->name), astring_c(exclude->path), exclude->pathlen) == 0) |
| 249 | if (exclude->recursive || astring_chr(file->name, exclude->pathlen + 1, '/') == -1) |
| 250 | return; |
| 251 | |
| 252 | /* attempt to add; if we get an error, we're already present */ |
| 253 | if (tagmap_add(map, astring_c(file->name), file->name, FALSE) != TMERR_NONE) |
| 254 | return; |
| 255 | |
| 256 | /* recurse the list from there */ |
| 257 | for (dep = file->deplist; dep != NULL; dep = dep->next) |
| 258 | recurse_dependencies(dep->file, map); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /*------------------------------------------------- |
| 263 | recurse_dir - recurse through a directory |
| 264 | -------------------------------------------------*/ |
| 265 | |
| 266 | static int recurse_dir(int srcrootlen, const astring *srcdir) |
| 267 | { |
| 268 | static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; |
| 269 | int result = 0; |
| 270 | int entindex; |
| 271 | |
| 272 | /* iterate first over directories, then over files */ |
| 273 | for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) |
| 274 | { |
| 275 | osd_dir_entry_type entry_type = typelist[entindex]; |
| 276 | const osd_directory_entry *entry; |
| 277 | list_entry **listarray = NULL; |
| 278 | list_entry *list = NULL; |
| 279 | list_entry *curlist; |
| 280 | osd_directory *dir; |
| 281 | int found = 0; |
| 282 | |
| 283 | /* open the directory and iterate through it */ |
| 284 | dir = osd_opendir(astring_c(srcdir)); |
| 285 | if (dir == NULL) |
| 286 | { |
| 287 | result = 1; |
| 288 | goto error; |
| 289 | } |
| 290 | |
| 291 | /* build up the list of files */ |
| 292 | while ((entry = osd_readdir(dir)) != NULL) |
| 293 | if (entry->type == entry_type && entry->name[0] != '.') |
| 294 | { |
| 295 | list_entry *lentry = (list_entry *)malloc(sizeof(*lentry)); |
| 296 | lentry->name = astring_dupc(entry->name); |
| 297 | lentry->next = list; |
| 298 | list = lentry; |
| 299 | found++; |
| 300 | } |
| 301 | |
| 302 | /* close the directory */ |
| 303 | osd_closedir(dir); |
| 304 | |
| 305 | /* skip if nothing found */ |
| 306 | if (found == 0) |
| 307 | continue; |
| 308 | |
| 309 | /* allocate memory for sorting */ |
| 310 | listarray = (list_entry **)malloc(sizeof(list_entry *) * found); |
| 311 | found = 0; |
| 312 | for (curlist = list; curlist != NULL; curlist = curlist->next) |
| 313 | listarray[found++] = curlist; |
| 314 | |
| 315 | /* sort the list */ |
| 316 | qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); |
| 317 | |
| 318 | /* rebuild the list */ |
| 319 | list = NULL; |
| 320 | while (--found >= 0) |
| 321 | { |
| 322 | listarray[found]->next = list; |
| 323 | list = listarray[found]; |
| 324 | } |
| 325 | free(listarray); |
| 326 | |
| 327 | /* iterate through each file */ |
| 328 | for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) |
| 329 | { |
| 330 | astring *srcfile; |
| 331 | |
| 332 | /* build the source filename */ |
| 333 | srcfile = astring_alloc(); |
| 334 | astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); |
| 335 | |
| 336 | /* if we have a file, output it */ |
| 337 | if (entry_type == ENTTYPE_FILE) |
| 338 | { |
| 339 | /* make sure we care, first */ |
| 340 | if (core_filename_ends_with(astring_c(curlist->name), ".c")) |
| 341 | { |
| 342 | tagmap *depend_map = tagmap_alloc(); |
| 343 | tagmap_entry *entry; |
| 344 | file_entry *file; |
| 345 | astring *target; |
| 346 | int taghash; |
| 347 | |
| 348 | /* find dependencies */ |
| 349 | file = compute_dependencies(srcrootlen, srcfile); |
| 350 | recurse_dependencies(file, depend_map); |
| 351 | |
| 352 | /* convert the target from source to object (makes assumptions about rules) */ |
| 353 | target = astring_dup(file->name); |
| 354 | astring_replacec(target, 0, "src/", "$(OBJ)/"); |
| 355 | astring_replacec(target, 0, ".c", ".o"); |
| 356 | printf("\n%s : \\\n", astring_c(target)); |
| 357 | |
| 358 | /* iterate over the hashed dependencies and output them as well */ |
| 359 | for (taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++) |
| 360 | for (entry = depend_map->table[taghash]; entry != NULL; entry = entry->next) |
| 361 | printf("\t%s \\\n", astring_c((astring *)entry->object)); |
| 362 | |
| 363 | astring_free(target); |
| 364 | tagmap_free(depend_map); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /* if we have a directory, recurse */ |
| 369 | else |
| 370 | result = recurse_dir(srcrootlen, srcfile); |
| 371 | |
| 372 | /* free memory for the names */ |
| 373 | astring_free(srcfile); |
| 374 | } |
| 375 | |
| 376 | /* free all the allocated entries */ |
| 377 | while (list != NULL) |
| 378 | { |
| 379 | list_entry *next = list->next; |
| 380 | astring_free((astring *)list->name); |
| 381 | free(list); |
| 382 | list = next; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | error: |
| 387 | return result; |
| 388 | } |
| 389 | |
| 390 | |
| 391 | /*------------------------------------------------- |
| 392 | output_file - output a file, converting to |
| 393 | HTML |
| 394 | -------------------------------------------------*/ |
| 395 | |
| 396 | static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile) |
| 397 | { |
| 398 | astring *normalfile; |
| 399 | UINT32 filelength; |
| 400 | file_entry *file; |
| 401 | char *filedata; |
| 402 | int index; |
| 403 | |
| 404 | /* see if we already have an entry */ |
| 405 | normalfile = astring_dup(srcfile); |
| 406 | astring_replacechr(normalfile, PATH_SEPARATOR[0], '/'); |
| 407 | file = (file_entry *)tagmap_find(file_map, astring_c(normalfile)); |
| 408 | if (file != NULL) |
| 409 | return file; |
| 410 | |
| 411 | /* create a new header entry */ |
| 412 | file = (file_entry *)malloc(sizeof(*file)); |
| 413 | file->deplist = NULL; |
| 414 | file->name = normalfile; |
| 415 | tagmap_add(file_map, astring_c(file->name), file, FALSE); |
| 416 | |
| 417 | /* read the source file */ |
| 418 | if (core_fload(astring_c(srcfile), (void **)&filedata, &filelength) != FILERR_NONE) |
| 419 | { |
| 420 | fprintf(stderr, "Unable to read file '%s'\n", astring_c(srcfile)); |
| 421 | return file; |
| 422 | } |
| 423 | |
| 424 | /* find the #include directives in this file */ |
| 425 | for (index = 0; index < filelength; index++) |
| 426 | if (filedata[index] == '#' && strncmp(&filedata[index + 1], "include", 7) == 0) |
| 427 | { |
| 428 | astring *filename, *target; |
| 429 | int scan = index; |
| 430 | dependency *dep; |
| 431 | int start; |
| 432 | |
| 433 | /* first make sure we're not commented or quoted */ |
| 434 | for (scan = index; scan > 2 && filedata[scan] != 13 && filedata[scan] != 10; scan--) |
| 435 | if ((filedata[scan] == '/' && filedata[scan - 1] == '/') || filedata[scan] == '"') |
| 436 | break; |
| 437 | if (filedata[scan] != 13 && filedata[scan] != 10) |
| 438 | continue; |
| 439 | |
| 440 | /* scan forward to find the quotes or bracket */ |
| 441 | index += 7; |
| 442 | for (scan = index; scan < filelength && filedata[scan] != '<' && filedata[scan] != '"' && filedata[scan] != 13 && filedata[scan] != 10; scan++) ; |
| 443 | |
| 444 | /* ignore if not found or if it's bracketed */ |
| 445 | if (scan >= filelength || filedata[scan] != '"') |
| 446 | continue; |
| 447 | start = ++scan; |
| 448 | |
| 449 | /* find the closing quote */ |
| 450 | while (scan < filelength && filedata[scan] != '"') |
| 451 | scan++; |
| 452 | if (scan >= filelength) |
| 453 | continue; |
| 454 | |
| 455 | /* find the include file */ |
| 456 | filename = astring_dupch(&filedata[start], scan - start); |
| 457 | target = find_include_file(srcrootlen, srcfile, filename); |
| 458 | |
| 459 | /* create a new dependency */ |
| 460 | if (target != NULL) |
| 461 | { |
| 462 | dep = (dependency *)malloc(sizeof(*dep)); |
| 463 | dep->next = file->deplist; |
| 464 | file->deplist = dep; |
| 465 | dep->file = compute_dependencies(srcrootlen, target); |
| 466 | astring_free(target); |
| 467 | } |
| 468 | |
| 469 | astring_free(filename); |
| 470 | } |
| 471 | |
| 472 | free(filedata); |
| 473 | return file; |
| 474 | } |
| 475 | |
| 476 | |
| 477 | |
| 478 | /*************************************************************************** |
| 479 | HELPERS |
| 480 | ***************************************************************************/ |
| 481 | |
| 482 | /*------------------------------------------------- |
| 483 | find_include_file - find an include file |
| 484 | -------------------------------------------------*/ |
| 485 | |
| 486 | static astring *find_include_file(int srcrootlen, const astring *srcfile, const astring *filename) |
| 487 | { |
| 488 | include_path *curpath; |
| 489 | |
| 490 | /* iterate over include paths and find the file */ |
| 491 | for (curpath = incpaths; curpath != NULL; curpath = curpath->next) |
| 492 | { |
| 493 | astring *srcincpath = astring_dup(curpath->path); |
| 494 | core_file *testfile; |
| 495 | int lastsepindex = 0; |
| 496 | int sepindex; |
| 497 | |
| 498 | /* a '.' include path is specially treated */ |
| 499 | if (astring_cmpc(curpath->path, ".") == 0) |
| 500 | astring_cpysubstr(srcincpath, srcfile, 0, astring_rchr(srcfile, 0, PATH_SEPARATOR[0])); |
| 501 | |
| 502 | /* append the filename piecemeal to account for directories */ |
| 503 | while ((sepindex = astring_chr(filename, lastsepindex, '/')) != -1) |
| 504 | { |
| 505 | astring *pathpart = astring_dupsubstr(filename, lastsepindex, sepindex - lastsepindex); |
| 506 | |
| 507 | /* handle .. by removing a chunk from the incpath */ |
| 508 | if (astring_cmpc(pathpart, "..") == 0) |
| 509 | { |
| 510 | int sepindex = astring_rchr(srcincpath, 0, PATH_SEPARATOR[0]); |
| 511 | if (sepindex != -1) |
| 512 | astring_substr(srcincpath, 0, sepindex); |
| 513 | } |
| 514 | |
| 515 | /* otherwise, append a path separator and the pathpart */ |
| 516 | else |
| 517 | astring_cat(astring_catc(srcincpath, PATH_SEPARATOR), pathpart); |
| 518 | |
| 519 | /* advance past the previous index */ |
| 520 | lastsepindex = sepindex + 1; |
| 521 | |
| 522 | /* free the path part we extracted */ |
| 523 | astring_free(pathpart); |
| 524 | } |
| 525 | |
| 526 | /* now append the filename */ |
| 527 | astring_catsubstr(astring_catc(srcincpath, PATH_SEPARATOR), filename, lastsepindex, -1); |
| 528 | |
| 529 | /* see if we can open it */ |
| 530 | if (core_fopen(astring_c(srcincpath), OPEN_FLAG_READ, &testfile) == FILERR_NONE) |
| 531 | { |
| 532 | /* close the file */ |
| 533 | core_fclose(testfile); |
| 534 | return srcincpath; |
| 535 | } |
| 536 | |
| 537 | /* free our include path */ |
| 538 | astring_free(srcincpath); |
| 539 | } |
| 540 | return NULL; |
| 541 | } |
src/emu/machine/mc146818.h
| r9147 | r9148 | |
| 11 | 11 | |
| 12 | 12 | *********************************************************************/ |
| 13 | 13 | |
| 14 | | #ifndef MC146818_H |
| 15 | | #define MC146818_H |
| 14 | #ifndef __MC146818_H__ |
| 15 | #define __MC146818_H__ |
| 16 | 16 | |
| 17 | | typedef enum |
| 17 | |
| 18 | //************************************************************************** |
| 19 | // INTERFACE CONFIGURATION MACROS |
| 20 | //************************************************************************** |
| 21 | |
| 22 | #define MDRV_MC146818_ADD(_tag, _type) \ |
| 23 | MDRV_DEVICE_ADD(_tag, MC146818, 0) \ |
| 24 | mc146818_device_config::static_set_type(device, mc146818_device_config::_type); \ |
| 25 | |
| 26 | |
| 27 | |
| 28 | //************************************************************************** |
| 29 | // TYPE DEFINITIONS |
| 30 | //************************************************************************** |
| 31 | |
| 32 | class mc146818_device; |
| 33 | |
| 34 | |
| 35 | // ======================> mc146818_device_config |
| 36 | |
| 37 | class mc146818_device_config : public device_config, |
| 38 | public device_config_nvram_interface |
| 18 | 39 | { |
| 19 | | MC146818_STANDARD, |
| 20 | | MC146818_IGNORE_CENTURY, // century is NOT set, for systems having other usage of this byte |
| 21 | | MC146818_ENHANCED |
| 22 | | } MC146818_TYPE; |
| 40 | friend class mc146818_device; |
| 23 | 41 | |
| 42 | // construction/destruction |
| 43 | mc146818_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 24 | 44 | |
| 45 | public: |
| 46 | // values |
| 47 | enum mc146818_type |
| 48 | { |
| 49 | MC146818_STANDARD, |
| 50 | MC146818_IGNORE_CENTURY, // century is NOT set, for systems having other usage of this byte |
| 51 | MC146818_ENHANCED |
| 52 | }; |
| 25 | 53 | |
| 26 | | /* initialize mc146818 emulation, call only once at beginning */ |
| 27 | | void mc146818_init(running_machine *machine, MC146818_TYPE type); |
| 54 | // allocators |
| 55 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 56 | virtual device_t *alloc_device(running_machine &machine) const; |
| 28 | 57 | |
| 29 | | /* loads data from standard nvram file */ |
| 30 | | void mc146818_load(running_machine *machine); |
| 58 | // inline configuration helpers |
| 59 | static void static_set_type(device_config *device, mc146818_type type); |
| 31 | 60 | |
| 32 | | /* loads data from file stream */ |
| 33 | | void mc146818_load_stream(mame_file *file); |
| 61 | protected: |
| 62 | // internal state |
| 63 | mc146818_type m_type; |
| 64 | }; |
| 34 | 65 | |
| 35 | | /* saves data into standard nvram file */ |
| 36 | | void mc146818_save(running_machine *machine); |
| 37 | 66 | |
| 38 | | /* saves data into file stream */ |
| 39 | | void mc146818_save_stream(mame_file *file); |
| 67 | // ======================> mc146818_device |
| 40 | 68 | |
| 41 | | NVRAM_HANDLER( mc146818 ); |
| 69 | class mc146818_device : public device_t, |
| 70 | public device_nvram_interface |
| 71 | { |
| 72 | friend class mc146818_device_config; |
| 42 | 73 | |
| 43 | | READ8_HANDLER(mc146818_port_r); |
| 44 | | WRITE8_HANDLER(mc146818_port_w); |
| 74 | // construction/destruction |
| 75 | mc146818_device(running_machine &_machine, const mc146818_device_config &config); |
| 45 | 76 | |
| 46 | | READ16_HANDLER(mc146818_port16le_r); |
| 47 | | WRITE16_HANDLER(mc146818_port16le_w); |
| 77 | public: |
| 78 | // read/write access |
| 79 | DECLARE_READ8_MEMBER( read ); |
| 80 | DECLARE_WRITE8_MEMBER( write ); |
| 48 | 81 | |
| 49 | | READ32_HANDLER(mc146818_port32le_r); |
| 50 | | WRITE32_HANDLER(mc146818_port32le_w); |
| 82 | protected: |
| 83 | // device-level overrides |
| 84 | virtual void device_start(); |
| 85 | virtual void device_timer(emu_timer &timer, int param, void *ptr); |
| 51 | 86 | |
| 52 | | READ64_HANDLER(mc146818_port64be_r); |
| 53 | | WRITE64_HANDLER(mc146818_port64be_w); |
| 87 | // device_mc146818_interface overrides |
| 88 | virtual void nvram_default(); |
| 89 | virtual void nvram_read(mame_file &file); |
| 90 | virtual void nvram_write(mame_file &file); |
| 54 | 91 | |
| 55 | | #endif /* MC146818_H */ |
| 92 | // internal helpers |
| 93 | int dec_2_local(int a); |
| 94 | void set_base_datetime(); |
| 95 | |
| 96 | // internal state |
| 97 | static const int MC146818_DATA_SIZE = 0x80; |
| 98 | |
| 99 | const mc146818_device_config & m_config; |
| 100 | |
| 101 | UINT8 m_index; |
| 102 | UINT8 m_data[MC146818_DATA_SIZE]; |
| 103 | |
| 104 | UINT16 m_eindex; |
| 105 | UINT8 m_edata[0x2000]; |
| 106 | |
| 107 | bool m_updated; /* update ended interrupt flag */ |
| 108 | |
| 109 | attotime m_last_refresh; |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | // device type definition |
| 114 | extern const device_type MC146818; |
| 115 | |
| 116 | |
| 117 | #endif /* __MC146818_H__ */ |
src/emu/machine/mc146818.c
| r9147 | r9148 | |
| 72 | 72 | *********************************************************************/ |
| 73 | 73 | |
| 74 | 74 | #include "emu.h" |
| 75 | | #include "memconv.h" |
| 76 | 75 | #include "coreutil.h" |
| 77 | 76 | #include "machine/mc146818.h" |
| 78 | 77 | |
| 79 | 78 | |
| 79 | //************************************************************************** |
| 80 | // DEBUGGING |
| 81 | //************************************************************************** |
| 82 | |
| 80 | 83 | #define LOG_MC146818 0 |
| 81 | | #define MC146818_DATA_SIZE 0x80 |
| 82 | 84 | |
| 83 | | struct mc146818_chip |
| 85 | |
| 86 | |
| 87 | //************************************************************************** |
| 88 | // MACROS |
| 89 | //************************************************************************** |
| 90 | |
| 91 | #define HOURS_24 (m_data[0xb]&2) |
| 92 | #define BCD_MODE !(m_data[0xb]&4) // book has other description! |
| 93 | #define CENTURY m_data[50] |
| 94 | #define YEAR m_data[9] |
| 95 | #define MONTH m_data[8] |
| 96 | #define DAY m_data[7] |
| 97 | #define WEEK_DAY m_data[6] |
| 98 | |
| 99 | |
| 100 | |
| 101 | //************************************************************************** |
| 102 | // DEVICE DEFINITIONS |
| 103 | //************************************************************************** |
| 104 | |
| 105 | const device_type MC146818 = mc146818_device_config::static_alloc_device_config; |
| 106 | |
| 107 | |
| 108 | |
| 109 | //************************************************************************** |
| 110 | // DEVICE CONFIGURATION |
| 111 | //************************************************************************** |
| 112 | |
| 113 | //------------------------------------------------- |
| 114 | // mc146818_device_config - constructor |
| 115 | //------------------------------------------------- |
| 116 | |
| 117 | mc146818_device_config::mc146818_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 118 | : device_config(mconfig, static_alloc_device_config, "NVRAM", tag, owner, clock), |
| 119 | device_config_nvram_interface(mconfig, *this), |
| 120 | m_type(MC146818_STANDARD) |
| 84 | 121 | { |
| 85 | | MC146818_TYPE type; |
| 122 | } |
| 86 | 123 | |
| 87 | | UINT8 index; |
| 88 | | UINT8 data[MC146818_DATA_SIZE]; |
| 89 | 124 | |
| 90 | | UINT16 eindex; |
| 91 | | UINT8 edata[0x2000]; |
| 125 | //------------------------------------------------- |
| 126 | // static_alloc_device_config - allocate a new |
| 127 | // configuration object |
| 128 | //------------------------------------------------- |
| 92 | 129 | |
| 93 | | int updated; /* update ended interrupt flag */ |
| 130 | device_config *mc146818_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 131 | { |
| 132 | return global_alloc(mc146818_device_config(mconfig, tag, owner, clock)); |
| 133 | } |
| 94 | 134 | |
| 95 | | attotime last_refresh; |
| 96 | | }; |
| 97 | 135 | |
| 98 | | static struct mc146818_chip *mc146818; |
| 136 | //------------------------------------------------- |
| 137 | // alloc_device - allocate a new device object |
| 138 | //------------------------------------------------- |
| 99 | 139 | |
| 140 | device_t *mc146818_device_config::alloc_device(running_machine &machine) const |
| 141 | { |
| 142 | return auto_alloc(&machine, mc146818_device(machine, *this)); |
| 143 | } |
| 100 | 144 | |
| 101 | 145 | |
| 102 | | #define HOURS_24 (mc146818->data[0xb]&2) |
| 103 | | #define BCD_MODE !(mc146818->data[0xb]&4) // book has other description! |
| 104 | | #define CENTURY mc146818->data[50] |
| 105 | | #define YEAR mc146818->data[9] |
| 106 | | #define MONTH mc146818->data[8] |
| 107 | | #define DAY mc146818->data[7] |
| 108 | | #define WEEK_DAY mc146818->data[6] |
| 146 | //------------------------------------------------- |
| 147 | // static_set_interface - configuration helper |
| 148 | // to set the interface |
| 149 | //------------------------------------------------- |
| 109 | 150 | |
| 151 | void mc146818_device_config::static_set_type(device_config *device, mc146818_type type) |
| 152 | { |
| 153 | downcast<mc146818_device_config *>(device)->m_type = type; |
| 154 | } |
| 110 | 155 | |
| 111 | 156 | |
| 112 | | static void mc146818_set_base_datetime(running_machine *machine); |
| 113 | 157 | |
| 114 | | static TIMER_CALLBACK( mc146818_timer ) |
| 158 | //************************************************************************** |
| 159 | // LIVE DEVICE |
| 160 | //************************************************************************** |
| 161 | |
| 162 | //------------------------------------------------- |
| 163 | // mc146818_device - constructor |
| 164 | //------------------------------------------------- |
| 165 | |
| 166 | mc146818_device::mc146818_device(running_machine &_machine, const mc146818_device_config &config) |
| 167 | : device_t(_machine, config), |
| 168 | device_nvram_interface(_machine, config, *this), |
| 169 | m_config(config), |
| 170 | m_index(0), |
| 171 | m_eindex(0), |
| 172 | m_updated(false), |
| 173 | m_last_refresh(attotime_zero) |
| 115 | 174 | { |
| 175 | } |
| 176 | |
| 177 | |
| 178 | //------------------------------------------------- |
| 179 | // device_start - device-specific startup |
| 180 | //------------------------------------------------- |
| 181 | |
| 182 | void mc146818_device::device_start() |
| 183 | { |
| 184 | m_last_refresh = timer_get_time(&m_machine); |
| 185 | emu_timer *timer = device_timer_alloc(*this); |
| 186 | timer_adjust_periodic(timer, ATTOTIME_IN_HZ(1), 0, ATTOTIME_IN_HZ(1)); |
| 187 | set_base_datetime(); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | //------------------------------------------------- |
| 192 | // device_timer - handler timer events |
| 193 | //------------------------------------------------- |
| 194 | |
| 195 | void mc146818_device::device_timer(emu_timer &timer, int param, void *ptr) |
| 196 | { |
| 116 | 197 | int year/*, month*/; |
| 117 | 198 | |
| 118 | 199 | if (BCD_MODE) |
| 119 | 200 | { |
| 120 | | mc146818->data[0]=bcd_adjust(mc146818->data[0]+1); |
| 121 | | if (mc146818->data[0]>=0x60) |
| 201 | m_data[0]=bcd_adjust(m_data[0]+1); |
| 202 | if (m_data[0]>=0x60) |
| 122 | 203 | { |
| 123 | | mc146818->data[0]=0; |
| 124 | | mc146818->data[2]=bcd_adjust(mc146818->data[2]+1); |
| 125 | | if (mc146818->data[2]>=0x60) |
| 204 | m_data[0]=0; |
| 205 | m_data[2]=bcd_adjust(m_data[2]+1); |
| 206 | if (m_data[2]>=0x60) |
| 126 | 207 | { |
| 127 | | mc146818->data[2]=0; |
| 128 | | mc146818->data[4]=bcd_adjust(mc146818->data[4]+1); |
| 208 | m_data[2]=0; |
| 209 | m_data[4]=bcd_adjust(m_data[4]+1); |
| 129 | 210 | // different handling of hours |
| 130 | | if (mc146818->data[4]>=0x24) |
| 211 | if (m_data[4]>=0x24) |
| 131 | 212 | { |
| 132 | | mc146818->data[4]=0; |
| 213 | m_data[4]=0; |
| 133 | 214 | WEEK_DAY=bcd_adjust(WEEK_DAY+1)%7; |
| 134 | 215 | DAY=bcd_adjust(DAY+1); |
| 135 | 216 | //month=bcd_2_dec(MONTH); |
| 136 | 217 | year=bcd_2_dec(YEAR); |
| 137 | | if (mc146818->type!=MC146818_IGNORE_CENTURY) year+=bcd_2_dec(CENTURY)*100; |
| 218 | if (m_config.m_type!=mc146818_device_config::MC146818_IGNORE_CENTURY) year+=bcd_2_dec(CENTURY)*100; |
| 138 | 219 | else year+=2000; // save for julian_days_in_month calculation |
| 139 | 220 | DAY=bcd_adjust(DAY+1); |
| 140 | 221 | if (DAY>gregorian_days_in_month(MONTH, year)) |
| r9147 | r9148 | |
| 145 | 226 | { |
| 146 | 227 | MONTH=1; |
| 147 | 228 | YEAR=year=bcd_adjust(YEAR+1); |
| 148 | | if (mc146818->type!=MC146818_IGNORE_CENTURY) |
| 229 | if (m_config.m_type!=mc146818_device_config::MC146818_IGNORE_CENTURY) |
| 149 | 230 | { |
| 150 | 231 | if (year>=0x100) |
| 151 | 232 | { |
| r9147 | r9148 | |
| 160 | 241 | } |
| 161 | 242 | else |
| 162 | 243 | { |
| 163 | | mc146818->data[0]=mc146818->data[0]+1; |
| 164 | | if (mc146818->data[0]>=60) |
| 244 | m_data[0]=m_data[0]+1; |
| 245 | if (m_data[0]>=60) |
| 165 | 246 | { |
| 166 | | mc146818->data[0]=0; |
| 167 | | mc146818->data[2]=mc146818->data[2]+1; |
| 168 | | if (mc146818->data[2]>=60) { |
| 169 | | mc146818->data[2]=0; |
| 170 | | mc146818->data[4]=mc146818->data[4]+1; |
| 247 | m_data[0]=0; |
| 248 | m_data[2]=m_data[2]+1; |
| 249 | if (m_data[2]>=60) { |
| 250 | m_data[2]=0; |
| 251 | m_data[4]=m_data[4]+1; |
| 171 | 252 | // different handling of hours //? |
| 172 | | if (mc146818->data[4]>=24) { |
| 173 | | mc146818->data[4]=0; |
| 253 | if (m_data[4]>=24) { |
| 254 | m_data[4]=0; |
| 174 | 255 | WEEK_DAY=(WEEK_DAY+1)%7; |
| 175 | 256 | year=YEAR; |
| 176 | | if (mc146818->type!=MC146818_IGNORE_CENTURY) year+=CENTURY*100; |
| 257 | if (m_config.m_type!=mc146818_device_config::MC146818_IGNORE_CENTURY) year+=CENTURY*100; |
| 177 | 258 | else year+=2000; // save for julian_days_in_month calculation |
| 178 | 259 | if (++DAY>gregorian_days_in_month(MONTH, year)) { |
| 179 | 260 | DAY=1; |
| 180 | 261 | if (++MONTH>12) { |
| 181 | 262 | MONTH=1; |
| 182 | 263 | YEAR++; |
| 183 | | if (mc146818->type!=MC146818_IGNORE_CENTURY) { |
| 264 | if (m_config.m_type!=mc146818_device_config::MC146818_IGNORE_CENTURY) { |
| 184 | 265 | if (YEAR>=100) { CENTURY++;YEAR=0; } |
| 185 | 266 | } else { |
| 186 | 267 | YEAR%=100; |
| r9147 | r9148 | |
| 191 | 272 | } |
| 192 | 273 | } |
| 193 | 274 | } |
| 194 | | mc146818->updated = 1; /* clock has been updated */ |
| 195 | | mc146818->last_refresh = timer_get_time(machine); |
| 275 | m_updated = true; /* clock has been updated */ |
| 276 | m_last_refresh = timer_get_time(&m_machine); |
| 196 | 277 | } |
| 197 | 278 | |
| 198 | 279 | |
| 199 | 280 | |
| 200 | | void mc146818_init(running_machine *machine, MC146818_TYPE type) |
| 281 | //------------------------------------------------- |
| 282 | // nvram_default - called to initialize NVRAM to |
| 283 | // its default state |
| 284 | //------------------------------------------------- |
| 285 | |
| 286 | void mc146818_device::nvram_default() |
| 201 | 287 | { |
| 202 | | mc146818 = auto_alloc_clear(machine, struct mc146818_chip); |
| 203 | | mc146818->type = type; |
| 204 | | mc146818->last_refresh = timer_get_time(machine); |
| 205 | | timer_pulse(machine, ATTOTIME_IN_HZ(1), NULL, 0, mc146818_timer); |
| 206 | | mc146818_set_base_datetime(machine); |
| 288 | set_base_datetime(); |
| 207 | 289 | } |
| 208 | 290 | |
| 209 | 291 | |
| 292 | //------------------------------------------------- |
| 293 | // nvram_read - called to read NVRAM from the |
| 294 | // .nv file |
| 295 | //------------------------------------------------- |
| 210 | 296 | |
| 211 | | void mc146818_load(running_machine *machine) |
| 297 | void mc146818_device::nvram_read(mame_file &file) |
| 212 | 298 | { |
| 213 | | mame_file *file; |
| 214 | | |
| 215 | | file = nvram_fopen(machine, OPEN_FLAG_READ); |
| 216 | | if (file) |
| 217 | | { |
| 218 | | mc146818_load_stream(file); |
| 219 | | mame_fclose(file); |
| 220 | | } |
| 299 | mame_fread(&file, m_data, sizeof(m_data)); |
| 221 | 300 | } |
| 222 | 301 | |
| 223 | 302 | |
| 303 | //------------------------------------------------- |
| 304 | // nvram_write - called to write NVRAM to the |
| 305 | // .nv file |
| 306 | //------------------------------------------------- |
| 224 | 307 | |
| 225 | | void mc146818_load_stream(mame_file *file) |
| 308 | void mc146818_device::nvram_write(mame_file &file) |
| 226 | 309 | { |
| 227 | | mame_fread(file, mc146818->data, sizeof(mc146818->data)); |
| 310 | mame_fwrite(&file, m_data, sizeof(m_data)); |
| 228 | 311 | } |
| 229 | 312 | |
| 230 | 313 | |
| 314 | //------------------------------------------------- |
| 315 | // dec_2_local - convert from decimal to BCD if |
| 316 | // necessary |
| 317 | //------------------------------------------------- |
| 231 | 318 | |
| 232 | | static int dec_2_local(int a) |
| 319 | inline int mc146818_device::dec_2_local(int a) |
| 233 | 320 | { |
| 234 | 321 | return BCD_MODE ? dec_2_bcd(a) : a; |
| 235 | 322 | } |
| 236 | 323 | |
| 237 | 324 | |
| 325 | //------------------------------------------------- |
| 326 | // dec_2_local - convert from decimal to BCD if |
| 327 | // necessary |
| 328 | //------------------------------------------------- |
| 238 | 329 | |
| 239 | | static void mc146818_set_base_datetime(running_machine *machine) |
| 330 | void mc146818_device::set_base_datetime() |
| 240 | 331 | { |
| 241 | 332 | system_time systime; |
| 242 | 333 | |
| 243 | | machine->base_datetime(systime); |
| 334 | m_machine.base_datetime(systime); |
| 244 | 335 | |
| 245 | 336 | if (HOURS_24 || (systime.local_time.hour < 12)) |
| 246 | | mc146818->data[4] = dec_2_local(systime.local_time.hour); |
| 337 | m_data[4] = dec_2_local(systime.local_time.hour); |
| 247 | 338 | else |
| 248 | | mc146818->data[4] = dec_2_local(systime.local_time.hour - 12) | 0x80; |
| 339 | m_data[4] = dec_2_local(systime.local_time.hour - 12) | 0x80; |
| 249 | 340 | |
| 250 | | if (mc146818->type != MC146818_IGNORE_CENTURY) |
| 341 | if (m_config.m_type != mc146818_device_config::MC146818_IGNORE_CENTURY) |
| 251 | 342 | CENTURY = dec_2_local(systime.local_time.year /100); |
| 252 | 343 | |
| 253 | | mc146818->data[0] = dec_2_local(systime.local_time.second); |
| 254 | | mc146818->data[2] = dec_2_local(systime.local_time.minute); |
| 344 | m_data[0] = dec_2_local(systime.local_time.second); |
| 345 | m_data[2] = dec_2_local(systime.local_time.minute); |
| 255 | 346 | DAY = dec_2_local(systime.local_time.day); |
| 256 | 347 | MONTH = dec_2_local(systime.local_time.month + 1); |
| 257 | 348 | YEAR = dec_2_local(systime.local_time.year % 100); |
| 258 | 349 | |
| 259 | 350 | WEEK_DAY = systime.local_time.weekday; |
| 260 | 351 | if (systime.local_time.is_dst) |
| 261 | | mc146818->data[0xb] |= 1; |
| 352 | m_data[0xb] |= 1; |
| 262 | 353 | else |
| 263 | | mc146818->data[0xb] &= ~1; |
| 354 | m_data[0xb] &= ~1; |
| 264 | 355 | } |
| 265 | 356 | |
| 266 | 357 | |
| 358 | //------------------------------------------------- |
| 359 | // read - I/O handler for reading |
| 360 | //------------------------------------------------- |
| 267 | 361 | |
| 268 | | void mc146818_save(running_machine *machine) |
| 362 | READ8_MEMBER( mc146818_device::read ) |
| 269 | 363 | { |
| 270 | | mame_file *file; |
| 271 | | |
| 272 | | file = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 273 | | if (file) |
| 274 | | { |
| 275 | | mame_fwrite(file, mc146818->data, sizeof(mc146818->data)); |
| 276 | | mame_fclose(file); |
| 277 | | } |
| 278 | | } |
| 279 | | |
| 280 | | |
| 281 | | |
| 282 | | void mc146818_save_stream(mame_file *file) |
| 283 | | { |
| 284 | | mame_fwrite(file, mc146818->data, sizeof(mc146818->data)); |
| 285 | | } |
| 286 | | |
| 287 | | |
| 288 | | |
| 289 | | NVRAM_HANDLER( mc146818 ) |
| 290 | | { |
| 291 | | if (file == NULL) |
| 292 | | { |
| 293 | | mc146818_set_base_datetime(machine); |
| 294 | | // init only |
| 295 | | } |
| 296 | | else if (read_or_write) |
| 297 | | { |
| 298 | | mc146818_save_stream(file); |
| 299 | | } |
| 300 | | else |
| 301 | | { |
| 302 | | mc146818_load_stream(file); |
| 303 | | } |
| 304 | | } |
| 305 | | |
| 306 | | |
| 307 | | |
| 308 | | READ8_HANDLER(mc146818_port_r) |
| 309 | | { |
| 310 | 364 | UINT8 data = 0; |
| 311 | 365 | switch (offset) { |
| 312 | 366 | case 0: |
| 313 | | data = mc146818->index; |
| 367 | data = m_index; |
| 314 | 368 | break; |
| 315 | 369 | |
| 316 | 370 | case 1: |
| 317 | | switch (mc146818->index % MC146818_DATA_SIZE) { |
| 371 | switch (m_index % MC146818_DATA_SIZE) { |
| 318 | 372 | case 0xa: |
| 319 | | data = mc146818->data[mc146818->index % MC146818_DATA_SIZE]; |
| 320 | | if (attotime_compare(attotime_sub(timer_get_time(space->machine), mc146818->last_refresh), ATTOTIME_IN_HZ(32768)) < 0) |
| 373 | data = m_data[m_index % MC146818_DATA_SIZE]; |
| 374 | if (attotime_compare(attotime_sub(timer_get_time(space.machine), m_last_refresh), ATTOTIME_IN_HZ(32768)) < 0) |
| 321 | 375 | data |= 0x80; |
| 322 | 376 | #if 0 |
| 323 | 377 | /* for pc1512 bios realtime clock test */ |
| 324 | | mc146818->data[mc146818->index % MC146818_DATA_SIZE] ^= 0x80; /* 0x80 update in progress */ |
| 378 | m_data[m_index % MC146818_DATA_SIZE] ^= 0x80; /* 0x80 update in progress */ |
| 325 | 379 | #endif |
| 326 | 380 | break; |
| 327 | 381 | |
| 328 | 382 | case 0xc: |
| 329 | | if(mc146818->updated != 0) /* the clock has been updated */ |
| 383 | if (m_updated) /* the clock has been updated */ |
| 330 | 384 | data = 0x10; |
| 331 | 385 | else |
| 332 | 386 | data = 0x00; |
| 333 | 387 | break; |
| 334 | 388 | case 0xd: |
| 335 | 389 | /* battery ok */ |
| 336 | | data = mc146818->data[mc146818->index % MC146818_DATA_SIZE] | 0x80; |
| 390 | data = m_data[m_index % MC146818_DATA_SIZE] | 0x80; |
| 337 | 391 | break; |
| 338 | 392 | |
| 339 | 393 | default: |
| 340 | | data = mc146818->data[mc146818->index % MC146818_DATA_SIZE]; |
| 394 | data = m_data[m_index % MC146818_DATA_SIZE]; |
| 341 | 395 | break; |
| 342 | 396 | } |
| 343 | 397 | break; |
| 344 | 398 | } |
| 345 | 399 | |
| 346 | 400 | if (LOG_MC146818) |
| 347 | | logerror("mc146818_port_r(): index=0x%02x data=0x%02x\n", mc146818->index, data); |
| 401 | logerror("mc146818_port_r(): index=0x%02x data=0x%02x\n", m_index, data); |
| 348 | 402 | return data; |
| 349 | 403 | } |
| 350 | 404 | |
| 351 | 405 | |
| 406 | //------------------------------------------------- |
| 407 | // write - I/O handler for writing |
| 408 | //------------------------------------------------- |
| 352 | 409 | |
| 353 | | WRITE8_HANDLER(mc146818_port_w) |
| 410 | WRITE8_MEMBER( mc146818_device::write ) |
| 354 | 411 | { |
| 355 | 412 | if (LOG_MC146818) |
| 356 | | logerror("mc146818_port_w(): index=0x%02x data=0x%02x\n", mc146818->index, data); |
| 413 | logerror("mc146818_port_w(): index=0x%02x data=0x%02x\n", m_index, data); |
| 357 | 414 | |
| 358 | 415 | switch (offset) { |
| 359 | 416 | case 0: |
| 360 | | mc146818->index = data; |
| 417 | m_index = data; |
| 361 | 418 | break; |
| 362 | 419 | |
| 363 | 420 | case 1: |
| 364 | | switch(mc146818->index % MC146818_DATA_SIZE) |
| 421 | switch(m_index % MC146818_DATA_SIZE) |
| 365 | 422 | { |
| 366 | 423 | case 0x0b: |
| 367 | 424 | if(data & 0x80) |
| 368 | | mc146818->updated = 0; |
| 369 | | mc146818->data[mc146818->index % MC146818_DATA_SIZE] = data; |
| 425 | m_updated = false; |
| 426 | m_data[m_index % MC146818_DATA_SIZE] = data; |
| 370 | 427 | break; |
| 371 | 428 | default: |
| 372 | | mc146818->data[mc146818->index % MC146818_DATA_SIZE] = data; |
| 429 | m_data[m_index % MC146818_DATA_SIZE] = data; |
| 373 | 430 | } |
| 374 | 431 | break; |
| 375 | 432 | } |
| 376 | 433 | } |
| 377 | | |
| 378 | | |
| 379 | | |
| 380 | | READ16_HANDLER(mc146818_port16le_r) |
| 381 | | { |
| 382 | | return read16le_with_read8_handler(mc146818_port_r, space, offset, mem_mask); |
| 383 | | } |
| 384 | | |
| 385 | | WRITE16_HANDLER(mc146818_port16le_w) |
| 386 | | { |
| 387 | | write16le_with_write8_handler(mc146818_port_w, space, offset, data, mem_mask); |
| 388 | | } |
| 389 | | |
| 390 | | READ32_HANDLER(mc146818_port32le_r) |
| 391 | | { |
| 392 | | return read32le_with_read8_handler(mc146818_port_r, space, offset, mem_mask); |
| 393 | | } |
| 394 | | |
| 395 | | WRITE32_HANDLER(mc146818_port32le_w) |
| 396 | | { |
| 397 | | write32le_with_write8_handler(mc146818_port_w, space, offset, data, mem_mask); |
| 398 | | } |
| 399 | | |
| 400 | | READ64_HANDLER(mc146818_port64be_r) |
| 401 | | { |
| 402 | | return read64be_with_read8_handler(mc146818_port_r, space, offset, mem_mask); |
| 403 | | } |
| 404 | | |
| 405 | | WRITE64_HANDLER(mc146818_port64be_w) |
| 406 | | { |
| 407 | | write64be_with_write8_handler(mc146818_port_w, space, offset, data, mem_mask); |
| 408 | | } |
src/mess/drivers/at.c
| r9147 | r9148 | |
| 171 | 171 | AM_RANGE(0x0020, 0x003f) AM_DEVREADWRITE8("pic8259_master", pic8259_r, pic8259_w, 0xffff) |
| 172 | 172 | AM_RANGE(0x0040, 0x005f) AM_DEVREADWRITE8("pit8254", pit8253_r, pit8253_w, 0xffff) |
| 173 | 173 | AM_RANGE(0x0060, 0x006f) AM_READWRITE8(at_kbdc8042_r, at_kbdc8042_w, 0xffff) |
| 174 | | AM_RANGE(0x0070, 0x007f) AM_READWRITE8(mc146818_port_r, mc146818_port_w, 0xffff) |
| 174 | AM_RANGE(0x0070, 0x007f) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write , 0xffff) |
| 175 | 175 | AM_RANGE(0x0080, 0x009f) AM_READWRITE8(at_page8_r, at_page8_w, 0xffff) |
| 176 | 176 | AM_RANGE(0x00a0, 0x00bf) AM_DEVREADWRITE8("pic8259_slave", pic8259_r, pic8259_w, 0xffff) |
| 177 | 177 | AM_RANGE(0x00c0, 0x00df) AM_DEVREADWRITE8("dma8237_2", at_dma8237_1_r, at_dma8237_1_w, 0xffff) |
| r9147 | r9148 | |
| 199 | 199 | AM_RANGE(0x0020, 0x003f) AM_DEVREADWRITE8("pic8259_master", pic8259_r, pic8259_w, 0xffffffff) |
| 200 | 200 | AM_RANGE(0x0040, 0x005f) AM_DEVREADWRITE8("pit8254", pit8253_r, pit8253_w, 0xffffffff) |
| 201 | 201 | AM_RANGE(0x0060, 0x006f) AM_READWRITE(at_kbdc8042_32le_r, at_kbdc8042_32le_w) |
| 202 | | AM_RANGE(0x0070, 0x007f) AM_READWRITE(mc146818_port32le_r, mc146818_port32le_w) |
| 202 | AM_RANGE(0x0070, 0x007f) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write , 0xffffffff) |
| 203 | 203 | AM_RANGE(0x0080, 0x009f) AM_READWRITE8(at_page8_r, at_page8_w, 0xffffffff) |
| 204 | 204 | AM_RANGE(0x00a0, 0x00bf) AM_DEVREADWRITE8("pic8259_slave", pic8259_r, pic8259_w, 0xffffffff) |
| 205 | 205 | AM_RANGE(0x00c0, 0x00df) AM_DEVREADWRITE8("dma8237_2", at_dma8237_1_r, at_dma8237_1_w, 0xffffffff) |
| r9147 | r9148 | |
| 221 | 221 | AM_RANGE(0x0020, 0x003f) AM_DEVREADWRITE8("pic8259_master", pic8259_r, pic8259_w, 0xffffffff) |
| 222 | 222 | AM_RANGE(0x0040, 0x005f) AM_DEVREADWRITE8("pit8254", pit8253_r, pit8253_w, 0xffffffff) |
| 223 | 223 | AM_RANGE(0x0060, 0x006f) AM_READWRITE(at_kbdc8042_32le_r, at_kbdc8042_32le_w) |
| 224 | | AM_RANGE(0x0070, 0x007f) AM_READWRITE(mc146818_port32le_r, mc146818_port32le_w) |
| 224 | AM_RANGE(0x0070, 0x007f) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write , 0xffffffff) |
| 225 | 225 | AM_RANGE(0x0080, 0x009f) AM_READWRITE8(at_page8_r, at_page8_w, 0xffffffff) |
| 226 | 226 | AM_RANGE(0x00a0, 0x00bf) AM_DEVREADWRITE8("pic8259_slave", pic8259_r, pic8259_w, 0xffffffff) |
| 227 | 227 | AM_RANGE(0x00c0, 0x00df) AM_DEVREADWRITE8("dma8237_2", at_dma8237_1_r, at_dma8237_1_w, 0xffffffff) |
| r9147 | r9148 | |
| 274 | 274 | AM_RANGE(0x0020, 0x003f) AM_DEVREADWRITE8("pic8259_master", pic8259_r, pic8259_w, 0xffffffff) |
| 275 | 275 | AM_RANGE(0x0040, 0x005f) AM_DEVREADWRITE8("pit8254", pit8253_r, pit8253_w, 0xffffffff) |
| 276 | 276 | //AM_RANGE(0x0060, 0x006f) AM_READWRITE(at_kbdc8042_32le_r, at_kbdc8042_32le_w) |
| 277 | | AM_RANGE(0x0070, 0x007f) AM_READWRITE(mc146818_port32le_r, mc146818_port32le_w) |
| 277 | AM_RANGE(0x0070, 0x007f) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write , 0xffffffff) |
| 278 | 278 | AM_RANGE(0x0080, 0x009f) AM_READWRITE8(at_page8_r, at_page8_w, 0xffffffff) |
| 279 | 279 | AM_RANGE(0x00a0, 0x00bf) AM_DEVREADWRITE8("pic8259_slave", pic8259_r, pic8259_w, 0xffffffff) |
| 280 | 280 | AM_RANGE(0x00c0, 0x00df) AM_DEVREADWRITE8("dma8237_2", at_dma8237_1_r, at_dma8237_1_w, 0xffffffff) |
| r9147 | r9148 | |
| 534 | 534 | |
| 535 | 535 | MDRV_KB_KEYTRONIC_ADD("keyboard", at_keytronic_intf) |
| 536 | 536 | |
| 537 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 537 | MDRV_MC146818_ADD( "rtc", MC146818_STANDARD ) |
| 538 | 538 | |
| 539 | 539 | /* printers */ |
| 540 | 540 | MDRV_PC_LPT_ADD("lpt_0", at_lpt_config) |
| r9147 | r9148 | |
| 607 | 607 | |
| 608 | 608 | MDRV_KB_KEYTRONIC_ADD("keyboard", at_keytronic_intf) |
| 609 | 609 | |
| 610 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 610 | MDRV_MC146818_ADD( "rtc", MC146818_STANDARD ) |
| 611 | 611 | |
| 612 | 612 | /* printers */ |
| 613 | 613 | MDRV_PC_LPT_ADD("lpt_0", at_lpt_config) |
| r9147 | r9148 | |
| 678 | 678 | |
| 679 | 679 | MDRV_KB_KEYTRONIC_ADD("keyboard", at_keytronic_intf) |
| 680 | 680 | |
| 681 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 681 | MDRV_MC146818_ADD( "rtc", MC146818_STANDARD ) |
| 682 | 682 | |
| 683 | 683 | /* printers */ |
| 684 | 684 | MDRV_PC_LPT_ADD("lpt_0", at_lpt_config) |
| r9147 | r9148 | |
| 751 | 751 | |
| 752 | 752 | MDRV_KB_KEYTRONIC_ADD("keyboard", at_keytronic_intf) |
| 753 | 753 | |
| 754 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 754 | MDRV_MC146818_ADD( "rtc", MC146818_STANDARD ) |
| 755 | 755 | |
| 756 | 756 | /* printers */ |
| 757 | 757 | MDRV_PC_LPT_ADD("lpt_0", at_lpt_config) |
| r9147 | r9148 | |
| 825 | 825 | |
| 826 | 826 | MDRV_KB_KEYTRONIC_ADD("keyboard", at_keytronic_intf) |
| 827 | 827 | |
| 828 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 828 | MDRV_MC146818_ADD( "rtc", MC146818_STANDARD ) |
| 829 | 829 | // MDRV_NVRAM_ADD_0FILL("nvram") |
| 830 | 830 | |
| 831 | 831 | /* printers */ |
src/mess/drivers/pc.c
| r9147 | r9148 | |
| 497 | 497 | AM_RANGE(0x0020, 0x0021) AM_DEVREADWRITE8("pic8259", pic8259_r, pic8259_w, 0xffff) |
| 498 | 498 | AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE8("pit8253", pit8253_r, pit8253_w, 0xffff) |
| 499 | 499 | AM_RANGE(0x0060, 0x0065) AM_READWRITE(pc1640_16le_port60_r, pc1640_16le_port60_w) |
| 500 | | AM_RANGE(0x0070, 0x0071) AM_READWRITE(mc146818_port16le_r, mc146818_port16le_w) |
| 500 | AM_RANGE(0x0070, 0x0071) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write, 0xffff) |
| 501 | 501 | AM_RANGE(0x0078, 0x0079) AM_READWRITE(pc1640_16le_mouse_x_r, pc1640_16le_mouse_x_w) |
| 502 | 502 | AM_RANGE(0x007a, 0x007b) AM_READWRITE(pc1640_16le_mouse_y_r, pc1640_16le_mouse_y_w) |
| 503 | 503 | AM_RANGE(0x0080, 0x0087) AM_READWRITE8(pc_page_r, pc_page_w, 0xffff) |
| r9147 | r9148 | |
| 561 | 561 | AM_RANGE(0x0020, 0x0021) AM_DEVREADWRITE8("pic8259", pic8259_r, pic8259_w, 0xffff) |
| 562 | 562 | AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE8("pit8253", pit8253_r, pit8253_w, 0xffff) |
| 563 | 563 | AM_RANGE(0x0060, 0x0065) AM_READWRITE(pc1640_16le_port60_r, pc1640_16le_port60_w) |
| 564 | | AM_RANGE(0x0070, 0x0071) AM_READWRITE(mc146818_port16le_r, mc146818_port16le_w) |
| 564 | AM_RANGE(0x0070, 0x0071) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write, 0xffff) |
| 565 | 565 | AM_RANGE(0x0078, 0x0079) AM_READWRITE(pc1640_16le_mouse_x_r, pc1640_16le_mouse_x_w) |
| 566 | 566 | AM_RANGE(0x007a, 0x007b) AM_READWRITE(pc1640_16le_mouse_y_r, pc1640_16le_mouse_y_w) |
| 567 | 567 | AM_RANGE(0x0080, 0x0087) AM_READWRITE8(pc_page_r, pc_page_w, 0xffff) |
| r9147 | r9148 | |
| 592 | 592 | AM_RANGE(0x0020, 0x0021) AM_DEVREADWRITE8("pic8259", pic8259_r, pic8259_w, 0xffff) |
| 593 | 593 | AM_RANGE(0x0040, 0x0043) AM_DEVREADWRITE8("pit8253", pit8253_r, pit8253_w, 0xffff) |
| 594 | 594 | AM_RANGE(0x0060, 0x0065) AM_READWRITE(pc1640_16le_port60_r, pc1640_16le_port60_w) |
| 595 | | AM_RANGE(0x0070, 0x0071) AM_READWRITE(mc146818_port16le_r, mc146818_port16le_w) |
| 595 | AM_RANGE(0x0070, 0x0071) AM_DEVREADWRITE8_MODERN("rtc", mc146818_device, read, write, 0xffff) |
| 596 | 596 | AM_RANGE(0x0078, 0x0079) AM_READWRITE(pc1640_16le_mouse_x_r, pc1640_16le_mouse_x_w) |
| 597 | 597 | AM_RANGE(0x007a, 0x007b) AM_READWRITE(pc1640_16le_mouse_y_r, pc1640_16le_mouse_y_w) |
| 598 | 598 | AM_RANGE(0x0080, 0x0087) AM_READWRITE8(pc_page_r, pc_page_w, 0xffff) |
| r9147 | r9148 | |
| 2137 | 2137 | MDRV_SOUND_ADD("speaker", SPEAKER_SOUND, 0) |
| 2138 | 2138 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 2139 | 2139 | |
| 2140 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 2140 | MDRV_MC146818_ADD( "rtc", MC146818_IGNORE_CENTURY ) |
| 2141 | 2141 | |
| 2142 | 2142 | /* printer */ |
| 2143 | 2143 | MDRV_PC_LPT_ADD("lpt_0", pc_lpt_config) |
| r9147 | r9148 | |
| 2186 | 2186 | MDRV_SOUND_ADD("speaker", SPEAKER_SOUND, 0) |
| 2187 | 2187 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 2188 | 2188 | |
| 2189 | | MDRV_NVRAM_HANDLER( mc146818 ) |
| 2189 | MDRV_MC146818_ADD( "rtc", MC146818_IGNORE_CENTURY ) |
| 2190 | 2190 | |
| 2191 | 2191 | /* printer */ |
| 2192 | 2192 | MDRV_PC_LPT_ADD("lpt_0", pc_lpt_config) |