src/emu/machine/pit8253.c
| r2234 | r2235 | |
| 8 | 8 | * 8254 has an additional readback feature |
| 9 | 9 | * |
| 10 | 10 | * Revision History |
| 11 | * 1-Apr-2008 - WFP: Changed the implementation into a device. |
| 11 | 12 | * 8-Jul-2004 - AJ: Fixed some bugs. Styx now runs correctly. |
| 12 | 13 | * Implemented 8254 features. |
| 13 | 14 | * 1-Mar-2004 - NPW: Did an almost total rewrite and cleaned out much |
| r2234 | r2235 | |
| 19 | 20 | |
| 20 | 21 | #include <math.h> |
| 21 | 22 | #include "driver.h" |
| 22 | | #include "memconv.h" |
| 23 | #include "devconv.h" |
| 23 | 24 | #include "machine/pit8253.h" |
| 24 | 25 | |
| 25 | 26 | |
| r2234 | r2235 | |
| 41 | 42 | |
| 42 | 43 | #define CYCLES_NEVER ((UINT32) -1) |
| 43 | 44 | |
| 45 | /* device types */ |
| 46 | enum { |
| 47 | TYPE_PIT8253 = 0, |
| 48 | TYPE_PIT8254, |
| 49 | |
| 50 | NUM_TYPES |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | /* device tags */ |
| 55 | static const char * const device_tags[NUM_TYPES] = { "pit8253", "pit8254" }; |
| 56 | |
| 57 | |
| 44 | 58 | struct pit8253_timer |
| 45 | 59 | { |
| 46 | 60 | double clockin; /* input clock frequency in Hz */ |
| 47 | 61 | |
| 48 | | void (*output_callback_func)(int); /* callback function for when output changes */ |
| 49 | | void (*freq_callback)(double); /* callback function for when output frequency changes */ |
| 62 | pit8253_output_changed_func output_changed; /* callback function for when output changes */ |
| 63 | pit8253_frequency_changed_func frequency_changed; /* callback function for when output frequency changes */ |
| 50 | 64 | |
| 51 | 65 | attotime last_updated; /* time when last updated */ |
| 52 | 66 | |
| r2234 | r2235 | |
| 74 | 88 | UINT32 freq_count; /* counter period for periodic modes, 0 if counter non-periodic */ |
| 75 | 89 | }; |
| 76 | 90 | |
| 77 | | struct pit8253 |
| 91 | typedef struct _pit8253_t pit8253_t; |
| 92 | struct _pit8253_t |
| 78 | 93 | { |
| 79 | 94 | const struct pit8253_config *config; |
| 95 | int device_type; |
| 80 | 96 | struct pit8253_timer timers[MAX_TIMER]; |
| 81 | 97 | }; |
| 82 | 98 | |
| r2234 | r2235 | |
| 85 | 101 | #define CTRL_BCD(control) (((control) >> 0) & 0x01) |
| 86 | 102 | |
| 87 | 103 | |
| 88 | | static int pit_count; |
| 89 | | static struct pit8253 *pits; |
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | 104 | /*************************************************************************** |
| 94 | 105 | |
| 95 | 106 | Functions |
| 96 | 107 | |
| 97 | 108 | ***************************************************************************/ |
| 98 | 109 | |
| 99 | | static struct pit8253 *get_pit(int which) |
| 100 | | { |
| 101 | | return &pits[which]; |
| 110 | /* makes sure that the passed in device is of the right type */ |
| 111 | INLINE pit8253_t *get_safe_token(const device_config *device) { |
| 112 | assert( device != NULL ); |
| 113 | assert( device->token != NULL ); |
| 114 | assert( ( device->type == DEVICE_GET_INFO_NAME(pit8253) ) || |
| 115 | ( device->type == DEVICE_GET_INFO_NAME(pit8254) ) ); |
| 116 | return ( pit8253_t * ) device->token; |
| 102 | 117 | } |
| 103 | 118 | |
| 104 | 119 | |
| 105 | | static struct pit8253_timer *get_timer(struct pit8253 *pit,int which) |
| 120 | static struct pit8253_timer *get_timer(struct _pit8253_t *pit,int which) |
| 106 | 121 | { |
| 107 | 122 | which &= 3; |
| 108 | 123 | if (which < MAX_TIMER) |
| r2234 | r2235 | |
| 111 | 126 | } |
| 112 | 127 | |
| 113 | 128 | |
| 114 | | static UINT32 decimal_from_bcd(UINT16 val) |
| 129 | INLINE UINT32 decimal_from_bcd(UINT16 val) |
| 115 | 130 | { |
| 116 | 131 | /* In BCD mode, a nybble loaded with value A-F counts down the same as in |
| 117 | 132 | binary mode, but wraps around to 9 instead of F after 0, so loading the |
| r2234 | r2235 | |
| 208 | 223 | { |
| 209 | 224 | LOG2(("pit8253: freq_callback_in(): %d cycles\n",cycles)); |
| 210 | 225 | |
| 211 | | if (timer->freq_callback == NULL) |
| 226 | if (timer->frequency_changed == NULL) |
| 212 | 227 | { |
| 213 | 228 | return; |
| 214 | 229 | } |
| r2234 | r2235 | |
| 225 | 240 | } |
| 226 | 241 | |
| 227 | 242 | |
| 228 | | static void set_freq_count(struct pit8253_timer *timer) |
| 243 | static void set_freq_count(const device_config *device, struct pit8253_timer *timer) |
| 229 | 244 | { |
| 230 | 245 | int mode = CTRL_MODE(timer->control); |
| 231 | 246 | UINT32 freq_count; |
| r2234 | r2235 | |
| 242 | 257 | if (freq_count != timer->freq_count) |
| 243 | 258 | { |
| 244 | 259 | timer->freq_count = freq_count; |
| 245 | | if (timer->freq_callback != NULL) |
| 260 | if (timer->frequency_changed != NULL) |
| 246 | 261 | { |
| 247 | | timer->freq_callback(get_frequency(timer)); |
| 262 | timer->frequency_changed(device, get_frequency(timer)); |
| 248 | 263 | freq_callback_in(timer,CYCLES_NEVER); |
| 249 | 264 | } |
| 250 | 265 | } |
| r2234 | r2235 | |
| 254 | 269 | |
| 255 | 270 | |
| 256 | 271 | /* Call the output callback in "cycles" cycles */ |
| 257 | | static void trigger_countdown(struct pit8253_timer *timer) |
| 272 | static void trigger_countdown(const device_config *device, struct pit8253_timer *timer) |
| 258 | 273 | { |
| 259 | 274 | LOG2(("pit8253: trigger_countdown()\n")); |
| 260 | 275 | |
| r2234 | r2235 | |
| 263 | 278 | if (CTRL_MODE(timer->control) == 3 && timer->output == 0) |
| 264 | 279 | timer->value &= 0xfffe; |
| 265 | 280 | |
| 266 | | set_freq_count(timer); |
| 281 | set_freq_count(device, timer); |
| 267 | 282 | } |
| 268 | 283 | |
| 269 | 284 | |
| 270 | | static void set_output(struct pit8253_timer *timer,int output) |
| 285 | static void set_output(const device_config *device, struct pit8253_timer *timer,int output) |
| 271 | 286 | { |
| 272 | 287 | if (output != timer->output) |
| 273 | 288 | { |
| 274 | 289 | timer->output = output; |
| 275 | | if (timer->output_callback_func != NULL) |
| 290 | if (timer->output_changed != NULL) |
| 276 | 291 | { |
| 277 | | timer->output_callback_func(output); |
| 292 | timer->output_changed(device, output); |
| 278 | 293 | } |
| 279 | 294 | } |
| 280 | 295 | } |
| r2234 | r2235 | |
| 282 | 297 | |
| 283 | 298 | /* This emulates timer "timer" for "elapsed_cycles" cycles and assumes no |
| 284 | 299 | callbacks occur during that time. */ |
| 285 | | static void simulate2(struct pit8253_timer *timer,UINT64 elapsed_cycles) |
| 300 | static void simulate2(const device_config *device, struct pit8253_timer *timer,UINT64 elapsed_cycles) |
| 286 | 301 | { |
| 287 | 302 | UINT32 adjusted_value; |
| 288 | 303 | int bcd = CTRL_BCD(timer->control); |
| r2234 | r2235 | |
| 358 | 373 | } |
| 359 | 374 | } |
| 360 | 375 | |
| 361 | | set_output(timer,timer->phase == 3 ? 1 : 0); |
| 376 | set_output(device, timer, timer->phase == 3 ? 1 : 0); |
| 362 | 377 | break; |
| 363 | 378 | |
| 364 | 379 | |
| r2234 | r2235 | |
| 397 | 412 | decrease_counter_value(timer,elapsed_cycles); |
| 398 | 413 | cycles_to_output = CYCLES_NEVER; |
| 399 | 414 | } |
| 400 | | set_output(timer,timer->phase == 0 ? 1 : 0); |
| 415 | set_output(device, timer, timer->phase == 0 ? 1 : 0); |
| 401 | 416 | break; |
| 402 | 417 | |
| 403 | 418 | |
| r2234 | r2235 | |
| 427 | 442 | if (timer->gate == 0 || timer->phase == 0) |
| 428 | 443 | { |
| 429 | 444 | /* Gate low or mode control write forces output high */ |
| 430 | | set_output(timer,1); |
| 445 | set_output(device, timer, 1); |
| 431 | 446 | cycles_to_output = CYCLES_NEVER; |
| 432 | 447 | } |
| 433 | 448 | else |
| r2234 | r2235 | |
| 442 | 457 | { |
| 443 | 458 | /* Counter wrapped around one or more times */ |
| 444 | 459 | elapsed_cycles -= adjusted_value; |
| 445 | | trigger_countdown(timer); |
| 460 | trigger_countdown(device, timer); |
| 446 | 461 | decrease_counter_value(timer,elapsed_cycles % adjusted_count(bcd,timer->count)); |
| 447 | 462 | } |
| 448 | 463 | cycles_to_output = (timer->value == 1 ? 1 : (adjusted_count(bcd,timer->value) - 1)); |
| 449 | 464 | |
| 450 | | set_output(timer,timer->value != 1 ? 1 : 0); |
| 465 | set_output(device, timer, timer->value != 1 ? 1 : 0); |
| 451 | 466 | } |
| 452 | 467 | break; |
| 453 | 468 | |
| r2234 | r2235 | |
| 477 | 492 | if (timer->gate == 0 || timer->phase == 0) |
| 478 | 493 | { |
| 479 | 494 | /* Gate low or mode control write forces output high */ |
| 480 | | set_output(timer,1); |
| 495 | set_output(device, timer, 1); |
| 481 | 496 | cycles_to_output = CYCLES_NEVER; |
| 482 | 497 | } |
| 483 | 498 | else |
| r2234 | r2235 | |
| 493 | 508 | /* Counter wrapped around one or more times */ |
| 494 | 509 | elapsed_cycles -= ((adjusted_value+1)>>1); |
| 495 | 510 | |
| 496 | | set_output(timer,1 - timer->output); |
| 497 | | trigger_countdown(timer); |
| 511 | set_output(device, timer, 1 - timer->output); |
| 512 | trigger_countdown(device, timer); |
| 498 | 513 | |
| 499 | 514 | elapsed_cycles %= adjusted_count(bcd,timer->count); |
| 500 | 515 | adjusted_value = adjusted_count(bcd,timer->value); |
| r2234 | r2235 | |
| 503 | 518 | /* Counter wrapped around an even number of times */ |
| 504 | 519 | elapsed_cycles -= ((adjusted_value+1)>>1); |
| 505 | 520 | |
| 506 | | set_output(timer,1 - timer->output); |
| 507 | | trigger_countdown(timer); |
| 521 | set_output(device, timer, 1 - timer->output); |
| 522 | trigger_countdown(device, timer); |
| 508 | 523 | } |
| 509 | 524 | decrease_counter_value(timer,elapsed_cycles<<1); |
| 510 | 525 | } |
| r2234 | r2235 | |
| 598 | 613 | break; |
| 599 | 614 | } |
| 600 | 615 | } |
| 601 | | set_output(timer,timer->phase != 3 ? 1 : 0); |
| 616 | set_output(device, timer, timer->phase != 3 ? 1 : 0); |
| 602 | 617 | break; |
| 603 | 618 | } |
| 604 | 619 | |
| 605 | | if (timer->output_callback_func != NULL) |
| 620 | if (timer->output_changed != NULL) |
| 606 | 621 | { |
| 607 | 622 | timer->cycles_to_output = cycles_to_output; |
| 608 | 623 | if (cycles_to_output == CYCLES_NEVER || timer->clockin == 0) |
| r2234 | r2235 | |
| 638 | 653 | inaccurate by more than one cycle, and the output changed multiple |
| 639 | 654 | times during the discrepancy. In practice updates should still be O(1). |
| 640 | 655 | */ |
| 641 | | static void simulate(struct pit8253_timer *timer,UINT64 elapsed_cycles) |
| 656 | static void simulate(const device_config *device, struct pit8253_timer *timer,UINT64 elapsed_cycles) |
| 642 | 657 | { |
| 643 | 658 | while ((timer->cycles_to_output != CYCLES_NEVER && |
| 644 | 659 | timer->cycles_to_output <= elapsed_cycles) || |
| r2234 | r2235 | |
| 657 | 672 | cycles_to_callback = timer->cycles_to_freq; |
| 658 | 673 | } |
| 659 | 674 | |
| 660 | | simulate2(timer,cycles_to_callback); |
| 675 | simulate2(device, timer, cycles_to_callback); |
| 661 | 676 | elapsed_cycles -= cycles_to_callback; |
| 662 | 677 | } |
| 663 | | simulate2(timer,elapsed_cycles); |
| 678 | simulate2(device, timer, elapsed_cycles); |
| 664 | 679 | } |
| 665 | 680 | |
| 666 | 681 | |
| 667 | 682 | /* This brings timer "timer" up to date */ |
| 668 | | static void update(struct pit8253_timer *timer) |
| 683 | static void update(const device_config *device, struct pit8253_timer *timer) |
| 669 | 684 | { |
| 670 | 685 | /* With the 82C54's maximum clockin of 10MHz, 64 bits is nearly 60,000 |
| 671 | 686 | years of time. Should be enough for now. */ |
| r2234 | r2235 | |
| 675 | 690 | |
| 676 | 691 | timer->last_updated = attotime_add(timer->last_updated,double_to_attotime(elapsed_cycles/timer->clockin)); |
| 677 | 692 | |
| 678 | | simulate(timer,elapsed_cycles); |
| 693 | simulate(device, timer,elapsed_cycles); |
| 679 | 694 | } |
| 680 | 695 | |
| 681 | 696 | |
| 682 | | void pit8253_reset(int which) |
| 697 | static TIMER_CALLBACK( frequency_changed ) |
| 683 | 698 | { |
| 684 | | struct pit8253 *pit = get_pit(which); |
| 685 | | struct pit8253_timer *timer; |
| 686 | | int i; |
| 687 | | |
| 688 | | LOG1(("pit8253_reset(): resetting pit %d\n", which)); |
| 689 | | |
| 690 | | for (i = 0; i < MAX_TIMER; i++) |
| 691 | | { |
| 692 | | timer = get_timer(pit,i); |
| 693 | | /* According to Intel's 8254 docs, the state of a timer is undefined |
| 694 | | until the first mode control word is written. Here we define this |
| 695 | | undefined behaviour */ |
| 696 | | timer->control = timer->status = 0x30; |
| 697 | | timer->rmsb = timer->wmsb = 0; |
| 698 | | timer->count = timer->value = timer->latch = 0; |
| 699 | | timer->lowcount = 0; |
| 700 | | timer->gate = 1; |
| 701 | | timer->output = 0; |
| 702 | | timer->latched_count = 0; |
| 703 | | timer->latched_status = 0; |
| 704 | | timer->null_count = 1; |
| 705 | | timer->cycles_to_output = timer->cycles_to_freq = CYCLES_NEVER; |
| 706 | | |
| 707 | | timer->last_updated = timer_get_time(); |
| 708 | | |
| 709 | | update(timer); |
| 710 | | } |
| 711 | | } |
| 712 | | |
| 713 | | |
| 714 | | static TIMER_CALLBACK( freqcallback ) |
| 715 | | { |
| 716 | | struct pit8253_timer *timer = get_timer(get_pit(param & 0x0F),(param >> 4) & 0x0F); |
| 699 | const device_config *device = ptr; |
| 700 | pit8253_t *pit8253 = get_safe_token(device); |
| 701 | struct pit8253_timer *timer = get_timer(pit8253,param); |
| 717 | 702 | INT64 cycles = timer->cycles_to_freq; |
| 718 | 703 | double t; |
| 719 | 704 | |
| 720 | | LOG2(("pit8253: freqcallback(): pit %d, timer %d, %d cycles\n",param & 0xf,(param >> 4) & 0xf,(UINT32)cycles)); |
| 705 | LOG2(("pit8253: frequency_changed(): timer %d, %d cycles\n",param,(UINT32)cycles)); |
| 721 | 706 | |
| 722 | | simulate(timer,cycles); |
| 707 | simulate(device, timer,cycles); |
| 723 | 708 | |
| 724 | 709 | t = cycles / timer->clockin; |
| 725 | 710 | |
| r2234 | r2235 | |
| 727 | 712 | } |
| 728 | 713 | |
| 729 | 714 | |
| 730 | | static TIMER_CALLBACK( outputcallback ) |
| 715 | static TIMER_CALLBACK( output_changed ) |
| 731 | 716 | { |
| 732 | | struct pit8253_timer *timer = get_timer(get_pit(param & 0x0F),(param >> 4) & 0x0F); |
| 717 | const device_config *device = ptr; |
| 718 | pit8253_t *pit8253 = get_safe_token(device); |
| 719 | struct pit8253_timer *timer = get_timer(pit8253,param); |
| 733 | 720 | INT64 cycles = timer->cycles_to_output; |
| 734 | 721 | double t; |
| 735 | 722 | |
| 736 | | LOG2(("pit8253: outputcallback(): pit %d, timer %d, %d cycles\n",param & 0xf,(param >> 4) & 0xf,(UINT32)cycles)); |
| 723 | LOG2(("pit8253: output_changed(): timer %d, %d cycles\n",param,(UINT32)cycles)); |
| 737 | 724 | |
| 738 | | simulate(timer,cycles); |
| 725 | simulate(device, timer,cycles); |
| 739 | 726 | |
| 740 | 727 | t = cycles / timer->clockin; |
| 741 | 728 | |
| r2234 | r2235 | |
| 743 | 730 | } |
| 744 | 731 | |
| 745 | 732 | |
| 746 | | int pit8253_init(int count, const struct pit8253_config *config) |
| 747 | | { |
| 748 | | int i, timerno, n=0; |
| 749 | | struct pit8253 *pit; |
| 750 | | struct pit8253_timer *timer; |
| 751 | | |
| 752 | | LOG2(("pit8253_init(): initializing %d pit(s)\n", count)); |
| 753 | | |
| 754 | | pit_count = count; |
| 755 | | pits = auto_malloc(count * sizeof(struct pit8253)); |
| 756 | | |
| 757 | | memset(pits, 0, count * sizeof(struct pit8253)); |
| 758 | | |
| 759 | | for (i = 0; i < count; i++) |
| 760 | | { |
| 761 | | pit = get_pit(i); |
| 762 | | pit->config = &config[i]; |
| 763 | | |
| 764 | | for (timerno = 0; timerno < MAX_TIMER; timerno++) |
| 765 | | { |
| 766 | | timer = get_timer(pit,timerno); |
| 767 | | |
| 768 | | timer->clockin = pit->config->timer[timerno].clockin; |
| 769 | | timer->output_callback_func = pit->config->timer[timerno].output_callback_func; |
| 770 | | timer->freq_callback = pit->config->timer[timerno].clock_callback; |
| 771 | | |
| 772 | | if (timer->output_callback_func == NULL) |
| 773 | | timer->outputtimer = NULL; |
| 774 | | else |
| 775 | | { |
| 776 | | timer->outputtimer = timer_alloc(outputcallback, NULL); |
| 777 | | timer_adjust_oneshot(timer->outputtimer, attotime_never, i | (timerno<<4)); |
| 778 | | } |
| 779 | | if (timer->freq_callback == NULL) |
| 780 | | timer->freqtimer = NULL; |
| 781 | | else |
| 782 | | { |
| 783 | | timer->freqtimer = timer_alloc(freqcallback, NULL); |
| 784 | | timer_adjust_oneshot(timer->freqtimer, attotime_never, i | (timerno<<4)); |
| 785 | | } |
| 786 | | |
| 787 | | /* set up state save values */ |
| 788 | | state_save_register_item("pit8253", n, timer->clockin); |
| 789 | | state_save_register_item("pit8253", n, timer->control); |
| 790 | | state_save_register_item("pit8253", n, timer->status); |
| 791 | | state_save_register_item("pit8253", n, timer->lowcount); |
| 792 | | state_save_register_item("pit8253", n, timer->latch); |
| 793 | | state_save_register_item("pit8253", n, timer->count); |
| 794 | | state_save_register_item("pit8253", n, timer->value); |
| 795 | | state_save_register_item("pit8253", n, timer->wmsb); |
| 796 | | state_save_register_item("pit8253", n, timer->rmsb); |
| 797 | | state_save_register_item("pit8253", n, timer->output); |
| 798 | | state_save_register_item("pit8253", n, timer->gate); |
| 799 | | state_save_register_item("pit8253", n, timer->latched_count); |
| 800 | | state_save_register_item("pit8253", n, timer->latched_status); |
| 801 | | state_save_register_item("pit8253", n, timer->null_count); |
| 802 | | state_save_register_item("pit8253", n, timer->phase); |
| 803 | | state_save_register_item("pit8253", n, timer->cycles_to_output); |
| 804 | | state_save_register_item("pit8253", n, timer->cycles_to_freq); |
| 805 | | state_save_register_item("pit8253", n, timer->freq_count); |
| 806 | | state_save_register_item("pit8253", n, timer->last_updated.seconds); |
| 807 | | state_save_register_item("pit8253", n, timer->last_updated.attoseconds); |
| 808 | | ++n; |
| 809 | | } |
| 810 | | pit8253_reset(i); |
| 811 | | } |
| 812 | | |
| 813 | | LOG1(("pit8253_init(): initialized successfully\n")); |
| 814 | | |
| 815 | | return 0; |
| 816 | | } |
| 817 | | |
| 818 | | |
| 819 | 733 | /* We recycle bit 0 of timer->value to hold the phase in mode 3 when count is |
| 820 | 734 | odd. Since read commands in mode 3 always return even numbers, we need to |
| 821 | 735 | mask this bit off. */ |
| r2234 | r2235 | |
| 833 | 747 | latched_count |
| 834 | 748 | rmsb |
| 835 | 749 | so they don't affect any timer operations except other reads. */ |
| 836 | | static UINT8 pit8253_read(int which,offs_t offset) |
| 750 | READ8_DEVICE_HANDLER( pit8253_r ) |
| 837 | 751 | { |
| 838 | | struct pit8253 *pit = get_pit(which); |
| 839 | | struct pit8253_timer *timer = get_timer(pit,offset); |
| 752 | pit8253_t *pit8253 = get_safe_token(device); |
| 753 | struct pit8253_timer *timer = get_timer(pit8253,offset); |
| 840 | 754 | UINT8 data; |
| 841 | 755 | UINT16 value; |
| 842 | 756 | |
| 843 | | LOG2(("pit8253_read(): pit %d, offset %d\n",which,offset)); |
| 757 | LOG2(("pit8253_r(): offset %d\n", offset)); |
| 844 | 758 | |
| 845 | 759 | if (timer == NULL) |
| 846 | 760 | { |
| r2234 | r2235 | |
| 850 | 764 | } |
| 851 | 765 | else |
| 852 | 766 | { |
| 853 | | update(timer); |
| 767 | update(device, timer); |
| 854 | 768 | |
| 855 | 769 | if (timer->latched_status) |
| 856 | 770 | { |
| r2234 | r2235 | |
| 898 | 812 | } |
| 899 | 813 | } |
| 900 | 814 | |
| 901 | | LOG2(("pit8253_read(): PIT #%d offset=%d data=0x%02x\n", which, (int) offset, (unsigned) data)); |
| 815 | LOG2(("pit8253_r(): offset=%d data=0x%02x\n", offset, data)); |
| 902 | 816 | return data; |
| 903 | 817 | } |
| 904 | 818 | |
| 905 | 819 | |
| 906 | 820 | /* Loads a new value from the bus to the count register (CR) */ |
| 907 | | static void load_count(struct pit8253_timer *timer, UINT16 newcount) |
| 821 | static void load_count(const device_config *device, struct pit8253_timer *timer, UINT16 newcount) |
| 908 | 822 | { |
| 909 | 823 | int mode = CTRL_MODE(timer->control); |
| 910 | 824 | |
| r2234 | r2235 | |
| 925 | 839 | { |
| 926 | 840 | if (timer->phase == 0) |
| 927 | 841 | { |
| 928 | | trigger_countdown(timer); |
| 842 | trigger_countdown(device, timer); |
| 929 | 843 | } |
| 930 | 844 | else |
| 931 | 845 | { |
| r2234 | r2235 | |
| 944 | 858 | { |
| 945 | 859 | if (mode == 0 || mode == 4) |
| 946 | 860 | { |
| 947 | | trigger_countdown(timer); |
| 861 | trigger_countdown(device, timer); |
| 948 | 862 | } |
| 949 | 863 | } |
| 950 | 864 | } |
| 951 | 865 | |
| 952 | 866 | |
| 953 | | static void readback(struct pit8253_timer *timer,int command) |
| 867 | static void readback(const device_config *device, struct pit8253_timer *timer,int command) |
| 954 | 868 | { |
| 955 | 869 | UINT16 value; |
| 956 | | update(timer); |
| 870 | update(device, timer); |
| 957 | 871 | |
| 958 | 872 | if ((command & 1) == 0) |
| 959 | 873 | { |
| r2234 | r2235 | |
| 1002 | 916 | } |
| 1003 | 917 | |
| 1004 | 918 | |
| 1005 | | static void pit8253_write(int which, offs_t offset, int data) |
| 919 | WRITE8_DEVICE_HANDLER( pit8253_w ) |
| 1006 | 920 | { |
| 1007 | | struct pit8253 *pit = get_pit(which); |
| 1008 | | struct pit8253_timer *timer = get_timer(pit,offset); |
| 921 | pit8253_t *pit8253 = get_safe_token(device); |
| 922 | struct pit8253_timer *timer = get_timer(pit8253,offset); |
| 1009 | 923 | int read_command; |
| 1010 | 924 | |
| 1011 | | LOG2(("pit8253_write(): PIT #%d offset=%d data=0x%02x\n", which, (int) offset, (unsigned) data)); |
| 925 | LOG2(("pit8253_w(): offset=%d data=0x%02x\n", offset, data)); |
| 1012 | 926 | |
| 1013 | 927 | if (timer == NULL) { |
| 1014 | 928 | /* Write to mode control register */ |
| 1015 | | timer = get_timer(pit, (data >> 6) & 3); |
| 929 | timer = get_timer(pit8253, (data >> 6) & 3); |
| 1016 | 930 | if (timer == NULL) |
| 1017 | 931 | { |
| 1018 | 932 | /* Readback command. Illegal on 8253 */ |
| 1019 | 933 | /* Todo: find out what (if anything) the 8253 hardware actually does here. */ |
| 1020 | | if (pit->config->type == TYPE8254) |
| 934 | if (pit8253->device_type == TYPE_PIT8254) |
| 1021 | 935 | { |
| 1022 | | LOG1(("pit8253_write(): PIT #%d readback %02x\n", which, data & 0x3f)); |
| 936 | LOG1(("pit8253_w(): readback %02x\n", data & 0x3f)); |
| 1023 | 937 | |
| 1024 | 938 | /* Bit 0 of data must be 0. Todo: find out what the hardware does if it isn't. */ |
| 1025 | 939 | read_command = (data >> 4) & 3; |
| 1026 | 940 | if ((data & 2) != 0) |
| 1027 | | readback(get_timer(pit,0),read_command); |
| 941 | readback(device, get_timer(pit8253,0), read_command); |
| 1028 | 942 | if ((data & 4) != 0) |
| 1029 | | readback(get_timer(pit,1),read_command); |
| 943 | readback(device, get_timer(pit8253,1), read_command); |
| 1030 | 944 | if ((data & 8) != 0) |
| 1031 | | readback(get_timer(pit,2),read_command); |
| 945 | readback(device, get_timer(pit8253,2), read_command); |
| 1032 | 946 | } |
| 1033 | 947 | return; |
| 1034 | 948 | } |
| 1035 | 949 | |
| 1036 | | update(timer); |
| 950 | update(device, timer); |
| 1037 | 951 | |
| 1038 | 952 | if (CTRL_ACCESS(data) == 0) |
| 1039 | 953 | { |
| 1040 | | LOG1(("pit8253_write(): PIT #%d timer=%d readback\n", which, (data >> 6) & 3)); |
| 954 | LOG1(("pit8253_write(): timer=%d readback\n", (data >> 6) & 3)); |
| 1041 | 955 | |
| 1042 | 956 | /* Latch current timer value */ |
| 1043 | 957 | /* Experimentally verified: this command does not affect the mode control register */ |
| 1044 | | readback(timer,1); |
| 958 | readback(device, timer, 1); |
| 1045 | 959 | } |
| 1046 | 960 | else { |
| 1047 | | LOG1(("pit8253_write(): PIT #%d timer=%d bytes=%d mode=%d bcd=%d\n", which, (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7,data & 1)); |
| 961 | LOG1(("pit8253_write(): timer=%d bytes=%d mode=%d bcd=%d\n", (data >> 6) & 3, (data >> 4) & 3, (data >> 1) & 7,data & 1)); |
| 1048 | 962 | |
| 1049 | 963 | timer->control = (data & 0x3f); |
| 1050 | 964 | timer->null_count = 1; |
| 1051 | 965 | timer->wmsb = timer->rmsb = 0; |
| 1052 | 966 | /* Phase 0 is always the phase after a mode control write */ |
| 1053 | 967 | timer->phase = 0; |
| 1054 | | set_output(timer,1); |
| 1055 | | set_freq_count(timer); |
| 968 | set_output(device, timer, 1); |
| 969 | set_freq_count(device, timer); |
| 1056 | 970 | } |
| 1057 | 971 | } |
| 1058 | 972 | else |
| 1059 | 973 | { |
| 1060 | | update(timer); |
| 974 | update(device, timer); |
| 1061 | 975 | |
| 1062 | 976 | switch(CTRL_ACCESS(timer->control)) { |
| 1063 | 977 | case 0: |
| r2234 | r2235 | |
| 1066 | 980 | |
| 1067 | 981 | case 1: |
| 1068 | 982 | /* read/write counter bits 0-7 only */ |
| 1069 | | load_count(timer,data); |
| 983 | load_count(device, timer, data); |
| 1070 | 984 | break; |
| 1071 | 985 | |
| 1072 | 986 | case 2: |
| 1073 | 987 | /* read/write counter bits 8-15 only */ |
| 1074 | | load_count(timer,data << 8); |
| 988 | load_count(device, timer, data << 8); |
| 1075 | 989 | break; |
| 1076 | 990 | |
| 1077 | 991 | case 3: |
| 1078 | 992 | /* read/write bits 0-7 first, then 8-15 */ |
| 1079 | 993 | if (timer->wmsb != 0) |
| 1080 | 994 | { |
| 1081 | | load_count(timer,timer->lowcount | (data << 8)); |
| 995 | load_count(device, timer,timer->lowcount | (data << 8)); |
| 1082 | 996 | } |
| 1083 | 997 | else |
| 1084 | 998 | { |
| r2234 | r2235 | |
| 1095 | 1009 | break; |
| 1096 | 1010 | } |
| 1097 | 1011 | } |
| 1098 | | update(timer); |
| 1012 | update(device, timer); |
| 1099 | 1013 | } |
| 1100 | 1014 | |
| 1101 | 1015 | |
| 1102 | | static void pit8253_gate_write(int which,int offset,int data) |
| 1016 | WRITE8_DEVICE_HANDLER( pit8253_gate_w ) |
| 1103 | 1017 | { |
| 1104 | | struct pit8253_timer *timer = get_timer(get_pit(which),offset); |
| 1018 | pit8253_t *pit8253 = get_safe_token(device); |
| 1019 | struct pit8253_timer *timer = get_timer(pit8253,offset); |
| 1105 | 1020 | int mode; |
| 1106 | 1021 | int gate = (data!=0 ? 1 : 0); |
| 1107 | 1022 | |
| 1108 | | LOG2(("pit8253_gate_write(): PIT #%d offset=%d gate=%d\n", which, (int) offset, (unsigned) data)); |
| 1023 | LOG2(("pit8253_gate_w(): offset=%d gate=%d\n", offset, data)); |
| 1109 | 1024 | |
| 1110 | 1025 | if (timer == NULL) |
| 1111 | 1026 | return; |
| r2234 | r2235 | |
| 1114 | 1029 | |
| 1115 | 1030 | if (gate != timer->gate) |
| 1116 | 1031 | { |
| 1117 | | update(timer); |
| 1032 | update(device, timer); |
| 1118 | 1033 | timer->gate = gate; |
| 1119 | | set_freq_count(timer); |
| 1034 | set_freq_count(device, timer); |
| 1120 | 1035 | if (gate != 0 && |
| 1121 | 1036 | (mode == 1 || mode == 5 || |
| 1122 | 1037 | (timer->phase == 1 && (mode == 2 || mode == 3)))) |
| 1123 | 1038 | { |
| 1124 | | trigger_countdown(timer); |
| 1039 | trigger_countdown(device, timer); |
| 1125 | 1040 | } |
| 1126 | | update(timer); |
| 1041 | update(device, timer); |
| 1127 | 1042 | } |
| 1128 | 1043 | } |
| 1129 | 1044 | |
| r2234 | r2235 | |
| 1131 | 1046 | |
| 1132 | 1047 | /* ----------------------------------------------------------------------- */ |
| 1133 | 1048 | |
| 1134 | | int pit8253_get_frequency(int which, int timerno) |
| 1049 | int pit8253_get_frequency(const device_config *device, int timerno) |
| 1135 | 1050 | { |
| 1136 | | struct pit8253_timer *timer = get_timer(get_pit(which),timerno); |
| 1051 | pit8253_t *pit8253 = get_safe_token(device); |
| 1052 | struct pit8253_timer *timer = get_timer(pit8253,timerno); |
| 1137 | 1053 | |
| 1138 | | update(timer); |
| 1054 | update(device, timer); |
| 1139 | 1055 | return get_frequency(timer); |
| 1140 | 1056 | } |
| 1141 | 1057 | |
| 1142 | 1058 | |
| 1143 | 1059 | |
| 1144 | | int pit8253_get_output(int which, int timerno) |
| 1060 | int pit8253_get_output(const device_config *device, int timerno) |
| 1145 | 1061 | { |
| 1146 | | struct pit8253_timer *timer = get_timer(get_pit(which),timerno); |
| 1062 | pit8253_t *pit8253 = get_safe_token(device); |
| 1063 | struct pit8253_timer *timer = get_timer(pit8253,timerno); |
| 1147 | 1064 | int result; |
| 1148 | 1065 | |
| 1149 | | update(timer); |
| 1066 | update(device, timer); |
| 1150 | 1067 | result = timer->output; |
| 1151 | | LOG2(("pit8253_get_output(): PIT #%d timer=%d result=%d\n", which, timerno, result)); |
| 1068 | LOG2(("pit8253_get_output(): PIT timer=%d result=%d\n", timerno, result)); |
| 1152 | 1069 | return result; |
| 1153 | 1070 | } |
| 1154 | 1071 | |
| 1155 | 1072 | |
| 1156 | 1073 | |
| 1157 | | void pit8253_set_clockin(int which, int timerno, double new_clockin) |
| 1074 | void pit8253_set_clockin(const device_config *device, int timerno, double new_clockin) |
| 1158 | 1075 | { |
| 1159 | | struct pit8253_timer *timer = get_timer(get_pit(which),timerno); |
| 1076 | pit8253_t *pit8253 = get_safe_token(device); |
| 1077 | struct pit8253_timer *timer = get_timer(pit8253,timerno); |
| 1160 | 1078 | |
| 1161 | | LOG2(("pit8253_set_clockin(): PIT #%d timer=%d, clockin = %lf\n", which, (int) timerno,new_clockin)); |
| 1079 | LOG2(("pit8253_set_clockin(): PIT timer=%d, clockin = %lf\n", timerno,new_clockin)); |
| 1162 | 1080 | |
| 1163 | | update(timer); |
| 1081 | update(device, timer); |
| 1164 | 1082 | timer->clockin = new_clockin; |
| 1165 | | update(timer); |
| 1083 | update(device, timer); |
| 1166 | 1084 | |
| 1167 | | if (timer->freq_callback != NULL) |
| 1085 | if (timer->frequency_changed != NULL) |
| 1168 | 1086 | { |
| 1169 | | timer->freq_callback(get_frequency(timer)); |
| 1087 | timer->frequency_changed(device, get_frequency(timer)); |
| 1170 | 1088 | if (timer->cycles_to_freq != CYCLES_NEVER) |
| 1171 | 1089 | { |
| 1172 | 1090 | freq_callback_in(timer,timer->cycles_to_freq); |
| r2234 | r2235 | |
| 1175 | 1093 | } |
| 1176 | 1094 | |
| 1177 | 1095 | |
| 1096 | static void common_start( const device_config *device, int device_type ) { |
| 1097 | pit8253_t *pit8253 = get_safe_token(device); |
| 1098 | char unique_tag[30]; |
| 1099 | int timerno; |
| 1178 | 1100 | |
| 1179 | | /* ----------------------------------------------------------------------- */ |
| 1101 | pit8253->config = device->static_config; |
| 1102 | pit8253->device_type = device_type; |
| 1180 | 1103 | |
| 1181 | | READ8_HANDLER ( pit8253_0_r ) { return pit8253_read(0, offset); } |
| 1182 | | READ8_HANDLER ( pit8253_1_r ) { return pit8253_read(1, offset); } |
| 1183 | | WRITE8_HANDLER ( pit8253_0_w ) { pit8253_write(0, offset, data); } |
| 1184 | | WRITE8_HANDLER ( pit8253_1_w ) { pit8253_write(1, offset, data); } |
| 1104 | /* register for state saving */ |
| 1105 | state_save_combine_module_and_tag(unique_tag, device_tags[device_type], device->tag); |
| 1185 | 1106 | |
| 1186 | | READ16_HANDLER ( pit8253_0_lsb_r ) { return pit8253_read(0, offset); } |
| 1187 | | READ16_HANDLER ( pit8253_1_lsb_r ) { return pit8253_read(1, offset); } |
| 1188 | | WRITE16_HANDLER ( pit8253_0_lsb_w ) { if (ACCESSING_LSB) pit8253_write(0, offset, data); } |
| 1189 | | WRITE16_HANDLER ( pit8253_1_lsb_w ) { if (ACCESSING_LSB) pit8253_write(1, offset, data); } |
| 1107 | for (timerno = 0; timerno < MAX_TIMER; timerno++) |
| 1108 | { |
| 1109 | struct pit8253_timer *timer = get_timer(pit8253,timerno); |
| 1190 | 1110 | |
| 1191 | | READ16_HANDLER ( pit8253_16le_0_r ) { return read16le_with_read8_handler(pit8253_0_r, machine, offset, mem_mask); } |
| 1192 | | READ16_HANDLER ( pit8253_16le_1_r ) { return read16le_with_read8_handler(pit8253_1_r, machine, offset, mem_mask); } |
| 1193 | | WRITE16_HANDLER ( pit8253_16le_0_w ) { write16le_with_write8_handler(pit8253_0_w, machine, offset, data, mem_mask); } |
| 1194 | | WRITE16_HANDLER ( pit8253_16le_1_w ) { write16le_with_write8_handler(pit8253_1_w, machine, offset, data, mem_mask); } |
| 1111 | timer->clockin = pit8253->config->timer[timerno].clockin; |
| 1112 | timer->output_changed = pit8253->config->timer[timerno].output_changed; |
| 1113 | timer->frequency_changed = pit8253->config->timer[timerno].frequency_changed; |
| 1195 | 1114 | |
| 1196 | | READ32_HANDLER ( pit8253_32le_0_r ) { return read32le_with_read8_handler(pit8253_0_r, machine, offset, mem_mask); } |
| 1197 | | READ32_HANDLER ( pit8253_32le_1_r ) { return read32le_with_read8_handler(pit8253_1_r, machine, offset, mem_mask); } |
| 1198 | | WRITE32_HANDLER ( pit8253_32le_0_w ) { write32le_with_write8_handler(pit8253_0_w, machine, offset, data, mem_mask); } |
| 1199 | | WRITE32_HANDLER ( pit8253_32le_1_w ) { write32le_with_write8_handler(pit8253_1_w, machine, offset, data, mem_mask); } |
| 1115 | if (timer->output_changed == NULL) |
| 1116 | timer->outputtimer = NULL; |
| 1117 | else |
| 1118 | { |
| 1119 | timer->outputtimer = timer_alloc(output_changed, (void *)device); |
| 1120 | timer_adjust_oneshot(timer->outputtimer, attotime_never, timerno); |
| 1121 | } |
| 1122 | if (timer->frequency_changed == NULL) |
| 1123 | timer->freqtimer = NULL; |
| 1124 | else |
| 1125 | { |
| 1126 | timer->freqtimer = timer_alloc(frequency_changed, (void *)device); |
| 1127 | timer_adjust_oneshot(timer->freqtimer, attotime_never, timerno); |
| 1128 | } |
| 1200 | 1129 | |
| 1201 | | READ64_HANDLER ( pit8253_64be_0_r ) { return read64be_with_read8_handler(pit8253_0_r, machine, offset, mem_mask); } |
| 1202 | | READ64_HANDLER ( pit8253_64be_1_r ) { return read64be_with_read8_handler(pit8253_1_r, machine, offset, mem_mask); } |
| 1203 | | WRITE64_HANDLER ( pit8253_64be_0_w ) { write64be_with_write8_handler(pit8253_0_w, machine, offset, data, mem_mask); } |
| 1204 | | WRITE64_HANDLER ( pit8253_64be_1_w ) { write64be_with_write8_handler(pit8253_1_w, machine, offset, data, mem_mask); } |
| 1130 | /* set up state save values */ |
| 1131 | state_save_register_item(unique_tag, timerno, timer->clockin); |
| 1132 | state_save_register_item(unique_tag, timerno, timer->control); |
| 1133 | state_save_register_item(unique_tag, timerno, timer->status); |
| 1134 | state_save_register_item(unique_tag, timerno, timer->lowcount); |
| 1135 | state_save_register_item(unique_tag, timerno, timer->latch); |
| 1136 | state_save_register_item(unique_tag, timerno, timer->count); |
| 1137 | state_save_register_item(unique_tag, timerno, timer->value); |
| 1138 | state_save_register_item(unique_tag, timerno, timer->wmsb); |
| 1139 | state_save_register_item(unique_tag, timerno, timer->rmsb); |
| 1140 | state_save_register_item(unique_tag, timerno, timer->output); |
| 1141 | state_save_register_item(unique_tag, timerno, timer->gate); |
| 1142 | state_save_register_item(unique_tag, timerno, timer->latched_count); |
| 1143 | state_save_register_item(unique_tag, timerno, timer->latched_status); |
| 1144 | state_save_register_item(unique_tag, timerno, timer->null_count); |
| 1145 | state_save_register_item(unique_tag, timerno, timer->phase); |
| 1146 | state_save_register_item(unique_tag, timerno, timer->cycles_to_output); |
| 1147 | state_save_register_item(unique_tag, timerno, timer->cycles_to_freq); |
| 1148 | state_save_register_item(unique_tag, timerno, timer->freq_count); |
| 1149 | state_save_register_item(unique_tag, timerno, timer->last_updated.seconds); |
| 1150 | state_save_register_item(unique_tag, timerno, timer->last_updated.attoseconds); |
| 1151 | } |
| 1152 | } |
| 1205 | 1153 | |
| 1206 | | WRITE8_HANDLER ( pit8253_0_gate_w ) { pit8253_gate_write(0, offset, data); } |
| 1207 | | WRITE8_HANDLER ( pit8253_1_gate_w ) { pit8253_gate_write(1, offset, data); } |
| 1208 | 1154 | |
| 1155 | static DEVICE_START( pit8253 ) { |
| 1156 | common_start( device, TYPE_PIT8253 ); |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | static DEVICE_START( pit8254 ) { |
| 1161 | common_start( device, TYPE_PIT8254 ); |
| 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | static DEVICE_RESET( pit8253 ) { |
| 1166 | pit8253_t *pit = get_safe_token(device); |
| 1167 | int i; |
| 1168 | |
| 1169 | for (i = 0; i < MAX_TIMER; i++) |
| 1170 | { |
| 1171 | struct pit8253_timer *timer = get_timer(pit,i); |
| 1172 | /* According to Intel's 8254 docs, the state of a timer is undefined |
| 1173 | until the first mode control word is written. Here we define this |
| 1174 | undefined behaviour */ |
| 1175 | timer->control = timer->status = 0x30; |
| 1176 | timer->rmsb = timer->wmsb = 0; |
| 1177 | timer->count = timer->value = timer->latch = 0; |
| 1178 | timer->lowcount = 0; |
| 1179 | timer->gate = 1; |
| 1180 | timer->output = 0; |
| 1181 | timer->latched_count = 0; |
| 1182 | timer->latched_status = 0; |
| 1183 | timer->null_count = 1; |
| 1184 | timer->cycles_to_output = timer->cycles_to_freq = CYCLES_NEVER; |
| 1185 | |
| 1186 | timer->last_updated = timer_get_time(); |
| 1187 | |
| 1188 | update(device, timer); |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | static DEVICE_SET_INFO( pit8253 ) { |
| 1194 | switch ( state ) { |
| 1195 | /* no parameters to set */ |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | DEVICE_GET_INFO( pit8253 ) { |
| 1201 | switch ( state ) { |
| 1202 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1203 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(pit8253_t); break; |
| 1204 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 1205 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 1206 | |
| 1207 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1208 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(pit8253); break; |
| 1209 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(pit8253); break; |
| 1210 | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 1211 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(pit8253); break; |
| 1212 | |
| 1213 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1214 | case DEVINFO_STR_NAME: info->s = "Intel PIT8253"; break; |
| 1215 | case DEVINFO_STR_FAMILY: info->s = "PIT8253"; break; |
| 1216 | case DEVINFO_STR_VERSION: info->s = "1.00"; break; |
| 1217 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 1218 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MAME and MESS Teams"; break; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | DEVICE_GET_INFO( pit8254 ) { |
| 1224 | switch ( state ) { |
| 1225 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1226 | case DEVINFO_STR_NAME: info->s = "Intel PIT8254"; break; |
| 1227 | |
| 1228 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1229 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(pit8254); break; |
| 1230 | |
| 1231 | default: DEVICE_GET_INFO_CALL(pit8253); break; |
| 1232 | } |
| 1233 | } |
| 1234 | |
src/emu/devconv.h
| r0 | r2235 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | devconv.h |
| 4 | |
| 5 | Functions which help convert between different device handlers. |
| 6 | |
| 7 | Copyright Nicola Salmoria and the MAME Team. |
| 8 | Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | |
| 10 | **************************************************************************** |
| 11 | |
| 12 | ***** VERY IMPORTANT NOTICE ***** |
| 13 | |
| 14 | These functions and macros are provided to facilitate the mapping |
| 15 | of devices on cpus with different data bus widths. |
| 16 | Devices should be implemented using their native data bus width, |
| 17 | since that ensures that read/write operations are kept atomic. |
| 18 | If we discover you have abused the functionality presented in this |
| 19 | file, you *will* be publicly humiliated and your code submission |
| 20 | will probably not be accepted. Seriously, please do not abuse these |
| 21 | functions/macros. |
| 22 | |
| 23 | **************************************************************************** |
| 24 | |
| 25 | Conversions supported: |
| 26 | |
| 27 | CW = CPU Data Bus Width in bits |
| 28 | CBO = CPU Byte Order |
| 29 | DW = Device Data Bus Width in bits |
| 30 | DBO = Device Byte Order |
| 31 | |
| 32 | CW | CBO | DW | DBO | Functions to use |
| 33 | ---+--------+----+--------+----------------------------------------------------------- |
| 34 | 16 | Big | 8 | N/A | read16be_with_read8_device_handler,write16be_with_write8_device_handler |
| 35 | 16 | Little | 8 | N/A | read16le_with_read8_device_handler,write16le_with_write8_device_handler |
| 36 | ---+--------+----+--------+----------------------------------------------------------- |
| 37 | 32 | Big | 8 | N/A | read32be_with_read8_device_handler,write32be_with_write8_device_handler |
| 38 | 32 | Little | 8 | N/A | read32le_with_read8_device_handler,write32le_with_write8_device_handler |
| 39 | 32 | Big | 16 | Big | read32be_with_16be_device_handler,write32be_with_16be_device_handler |
| 40 | 32 | Little | 16 | Little | read32le_with_16le_device_handler,write32le_with_16le_device_handler |
| 41 | 32 | Big | 16 | Little | read32be_with_16le_device_handler,write32be_with_16le_device_handler |
| 42 | 32 | Little | 16 | Big | read32le_with_16be_device_handler,write32le_with_16be_device_handler |
| 43 | ---+--------+----+--------+----------------------------------------------------------- |
| 44 | 64 | Big | 8 | N/A | read64be_with_read8_device_handler,write64be_with_write8_device_handler |
| 45 | 64 | Little | 8 | N/A | read64le_with_read8_device_handler,write64le_with_write8_device_handler |
| 46 | 64 | Big | 16 | Big | read64be_with_16be_device_handler,write64be_with_16be_device_handler |
| 47 | 64 | Little | 16 | Little | read64le_with_16le_device_handler,write64le_with_16le_device_handler |
| 48 | 64 | Big | 16 | Little | read64be_with_16le_device_handler,write64be_with_16le_device_handler |
| 49 | 64 | Little | 16 | Big | read64le_with_16be_device_handler,write64le_with_16be_device_handler |
| 50 | 64 | Big | 32 | Big | read64be_with_32be_device_handler,write64be_with_32be_device_handler |
| 51 | 64 | Little | 32 | Little | read64le_with_32le_device_handler,write64le_with_32le_device_handler |
| 52 | 64 | Big | 32 | Little | read64be_with_32le_device_handler,write64be_with_32le_device_handler |
| 53 | 64 | Little | 32 | Big | read64le_with_32be_device_handler,write64le_with_32be_device_handler |
| 54 | |
| 55 | You can also find at the bottom of this file a few convernient |
| 56 | macros that will create the stub read and/or write handlers for |
| 57 | the most common mappings, that will use the functions above. |
| 58 | Here's an example on how to use them: Say you have a 8 bit device |
| 59 | whose handlers are device8_r and device8_w, and you want to connect |
| 60 | it to a 16 bit, big endian cpu. We'll say the device is mapped on |
| 61 | the least significant byte of the data bus (LSB). |
| 62 | |
| 63 | In your driver, you would add: |
| 64 | |
| 65 | DEV_READWRITE8TO16BE_LSB( device16, device8_r, device8_w ) |
| 66 | |
| 67 | which will create two 16 bit memory handlers, one for read, called |
| 68 | device16_r, and one for write, called device16_w, with the proper |
| 69 | mapping. |
| 70 | |
| 71 | then in the MEMORY_MAP you would specify: |
| 72 | |
| 73 | AM_RANGE(0x000000, 0x0000ff) AM_DEVREADWRITE( DEVICE, "device", device16_r, device16_w ) |
| 74 | |
| 75 | And that is all. Your device should be mapped properly. |
| 76 | If you need to do custom mappings, or a mapping that is not currently |
| 77 | supported in this file, you can always write the stub yourself, and |
| 78 | call the above functions to invoke the base handlers. |
| 79 | |
| 80 | ***************************************************************************/ |
| 81 | |
| 82 | /************************************* |
| 83 | * |
| 84 | * 16-bit BE using 8-bit handlers |
| 85 | * |
| 86 | *************************************/ |
| 87 | |
| 88 | INLINE UINT16 read16be_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT16 mem_mask) |
| 89 | { |
| 90 | UINT16 result = 0; |
| 91 | if ((mem_mask & 0xff00) != 0xff00) |
| 92 | result |= ((UINT16)(*handler)(param, offset * 2 + 0)) << 8; |
| 93 | if ((mem_mask & 0x00ff) != 0x00ff) |
| 94 | result |= ((UINT16)(*handler)(param, offset * 2 + 1)) << 0; |
| 95 | return result; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | INLINE void write16be_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 100 | { |
| 101 | if ((mem_mask & 0xff00) != 0xff00) |
| 102 | (*handler)(param, offset * 2 + 0, data >> 8); |
| 103 | if ((mem_mask & 0x00ff) != 0x00ff) |
| 104 | (*handler)(param, offset * 2 + 1, data >> 0); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /************************************* |
| 109 | * |
| 110 | * 16-bit LE using 8-bit handlers |
| 111 | * |
| 112 | *************************************/ |
| 113 | |
| 114 | INLINE UINT16 read16le_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT16 mem_mask) |
| 115 | { |
| 116 | UINT16 result = 0; |
| 117 | if ((mem_mask & 0x00ff) != 0x00ff) |
| 118 | result |= ((UINT16) (*handler)(param, offset * 2 + 0)) << 0; |
| 119 | if ((mem_mask & 0xff00) != 0xff00) |
| 120 | result |= ((UINT16) (*handler)(param, offset * 2 + 1)) << 8; |
| 121 | return result; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | INLINE void write16le_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 126 | { |
| 127 | if ((mem_mask & 0x00ff) != 0x00ff) |
| 128 | (*handler)(param, offset * 2 + 0, data >> 0); |
| 129 | if ((mem_mask & 0xff00) != 0xff00) |
| 130 | (*handler)(param, offset * 2 + 1, data >> 8); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /************************************* |
| 135 | * |
| 136 | * 32-bit BE using 8-bit handlers |
| 137 | * |
| 138 | *************************************/ |
| 139 | |
| 140 | INLINE UINT32 read32be_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT32 mem_mask) |
| 141 | { |
| 142 | UINT32 result = 0; |
| 143 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 144 | result |= read16be_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask >> 16) << 16; |
| 145 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 146 | result |= read16be_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask) << 0; |
| 147 | return result; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | INLINE void write32be_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask) |
| 152 | { |
| 153 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 154 | write16be_with_write8_device_handler(handler, param, offset * 2 + 0, data >> 16, mem_mask >> 16); |
| 155 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 156 | write16be_with_write8_device_handler(handler, param, offset * 2 + 1, data, mem_mask); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /************************************* |
| 161 | * |
| 162 | * 32-bit LE using 8-bit handlers |
| 163 | * |
| 164 | *************************************/ |
| 165 | |
| 166 | INLINE UINT32 read32le_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT32 mem_mask) |
| 167 | { |
| 168 | UINT32 result = 0; |
| 169 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 170 | result |= read16le_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask) << 0; |
| 171 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 172 | result |= read16le_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask >> 16) << 16; |
| 173 | return result; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | INLINE void write32le_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask) |
| 178 | { |
| 179 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 180 | write16le_with_write8_device_handler(handler, param, offset * 2 + 0, data, mem_mask); |
| 181 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 182 | write16le_with_write8_device_handler(handler, param, offset * 2 + 1, data >> 16, mem_mask >> 16); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /************************************* |
| 187 | * |
| 188 | * 32-bit BE using 16-bit BE handlers |
| 189 | * |
| 190 | *************************************/ |
| 191 | |
| 192 | INLINE UINT32 read32be_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask) |
| 193 | { |
| 194 | UINT32 result = 0; |
| 195 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 196 | result |= (*handler)(param, offset * 2 + 0, mem_mask >> 16) << 16; |
| 197 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 198 | result |= (*handler)(param, offset * 2 + 1, mem_mask) << 0; |
| 199 | return result; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | INLINE void write32be_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask) |
| 204 | { |
| 205 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 206 | (*handler)(param, offset * 2 + 0, data >> 16, mem_mask >> 16); |
| 207 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 208 | (*handler)(param, offset * 2 + 1, data, mem_mask); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | /************************************* |
| 213 | * |
| 214 | * 32-bit LE using 16-bit LE handlers |
| 215 | * |
| 216 | *************************************/ |
| 217 | |
| 218 | INLINE UINT32 read32le_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask) |
| 219 | { |
| 220 | UINT32 result = 0; |
| 221 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 222 | result |= (*handler)(param, offset * 2 + 0, mem_mask) << 0; |
| 223 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 224 | result |= (*handler)(param, offset * 2 + 1, mem_mask >> 16) << 16; |
| 225 | return result; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | INLINE void write32le_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask) |
| 230 | { |
| 231 | if ((mem_mask & 0x0000ffff) != 0x0000ffff) |
| 232 | (*handler)(param, offset * 2 + 0, data, mem_mask); |
| 233 | if ((mem_mask & 0xffff0000) != 0xffff0000) |
| 234 | (*handler)(param, offset * 2 + 1, data >> 16, mem_mask >> 16); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /************************************* |
| 239 | * |
| 240 | * 32-bit BE using 16-bit LE handlers |
| 241 | * |
| 242 | *************************************/ |
| 243 | |
| 244 | INLINE UINT32 read32be_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask) |
| 245 | { |
| 246 | UINT32 result = 0; |
| 247 | mem_mask = FLIPENDIAN_INT32(mem_mask); |
| 248 | result = read32le_with_16le_device_handler(handler, param, offset, mem_mask); |
| 249 | return FLIPENDIAN_INT32(result); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | INLINE void write32be_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask) |
| 254 | { |
| 255 | data = FLIPENDIAN_INT32(data); |
| 256 | mem_mask = FLIPENDIAN_INT32(mem_mask); |
| 257 | write32le_with_16le_device_handler(handler, param, offset, data, mem_mask); |
| 258 | } |
| 259 | |
| 260 | |
| 261 | /************************************* |
| 262 | * |
| 263 | * 32-bit LE using 16-bit BE handlers |
| 264 | * |
| 265 | *************************************/ |
| 266 | |
| 267 | INLINE UINT32 read32le_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT32 mem_mask) |
| 268 | { |
| 269 | UINT32 result = 0; |
| 270 | mem_mask = FLIPENDIAN_INT32(mem_mask); |
| 271 | result = read32be_with_16be_device_handler(handler, param, offset, mem_mask); |
| 272 | return FLIPENDIAN_INT32(result); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | INLINE void write32le_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT32 data, UINT32 mem_mask) |
| 277 | { |
| 278 | data = FLIPENDIAN_INT32(data); |
| 279 | mem_mask = FLIPENDIAN_INT32(mem_mask); |
| 280 | write32be_with_16be_device_handler(handler, param, offset, data, mem_mask); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | /************************************* |
| 285 | * |
| 286 | * 64-bit BE using 8-bit handlers |
| 287 | * |
| 288 | *************************************/ |
| 289 | |
| 290 | INLINE UINT64 read64be_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 291 | { |
| 292 | UINT64 result = 0; |
| 293 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 294 | result |= (UINT64)read32be_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask >> 32) << 32; |
| 295 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 296 | result |= (UINT64)read32be_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask) << 0; |
| 297 | return result; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | INLINE void write64be_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 302 | { |
| 303 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 304 | write32be_with_write8_device_handler(handler, param, offset * 2 + 0, data >> 32, mem_mask >> 32); |
| 305 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 306 | write32be_with_write8_device_handler(handler, param, offset * 2 + 1, data, mem_mask); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /************************************* |
| 311 | * |
| 312 | * 64-bit LE using 8-bit handlers |
| 313 | * |
| 314 | *************************************/ |
| 315 | |
| 316 | INLINE UINT64 read64le_with_read8_device_handler(read8_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 317 | { |
| 318 | UINT64 result = 0; |
| 319 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 320 | result |= (UINT64)read32le_with_read8_device_handler(handler, param, offset * 2 + 0, mem_mask >> 0) << 0; |
| 321 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 322 | result |= (UINT64)read32le_with_read8_device_handler(handler, param, offset * 2 + 1, mem_mask >> 32) << 32; |
| 323 | return result; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | INLINE void write64le_with_write8_device_handler(write8_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 328 | { |
| 329 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 330 | write32le_with_write8_device_handler(handler, param, offset * 2 + 0, data >> 0, mem_mask >> 0); |
| 331 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 332 | write32le_with_write8_device_handler(handler, param, offset * 2 + 1, data >> 32, mem_mask >> 32); |
| 333 | } |
| 334 | |
| 335 | |
| 336 | /************************************* |
| 337 | * |
| 338 | * 64-bit BE using 16-bit BE handlers |
| 339 | * |
| 340 | *************************************/ |
| 341 | |
| 342 | INLINE UINT32 read64be_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 343 | { |
| 344 | UINT64 result = 0; |
| 345 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 346 | result |= (UINT64)read32be_with_16be_device_handler(handler, param, offset * 2 + 0, mem_mask >> 32) << 32; |
| 347 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 348 | result |= (UINT64)read32be_with_16be_device_handler(handler, param, offset * 2 + 1, mem_mask >> 0) << 0; |
| 349 | return result; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | INLINE void write64be_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 354 | { |
| 355 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 356 | write32be_with_16be_device_handler(handler, param, offset * 2 + 0, data >> 32, mem_mask >> 32); |
| 357 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 358 | write32be_with_16be_device_handler(handler, param, offset * 2 + 1, data >> 0, mem_mask >> 0); |
| 359 | } |
| 360 | |
| 361 | |
| 362 | /************************************* |
| 363 | * |
| 364 | * 64-bit LE using 16-bit LE handlers |
| 365 | * |
| 366 | *************************************/ |
| 367 | |
| 368 | INLINE UINT32 read64le_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 369 | { |
| 370 | UINT64 result = 0; |
| 371 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 372 | result |= (UINT64)read32le_with_16le_device_handler(handler, param, offset * 2 + 0, mem_mask >> 0) << 0; |
| 373 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 374 | result |= (UINT64)read32le_with_16le_device_handler(handler, param, offset * 2 + 1, mem_mask >> 32) << 32; |
| 375 | return result; |
| 376 | } |
| 377 | |
| 378 | |
| 379 | INLINE void write64le_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 380 | { |
| 381 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 382 | write32le_with_16le_device_handler(handler, param, offset * 2 + 0, data >> 0, mem_mask >> 0); |
| 383 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 384 | write32le_with_16le_device_handler(handler, param, offset * 2 + 1, data >> 32, mem_mask >> 32); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | /************************************* |
| 389 | * |
| 390 | * 64-bit BE using 16-bit LE handlers |
| 391 | * |
| 392 | *************************************/ |
| 393 | |
| 394 | INLINE UINT32 read64be_with_16le_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 395 | { |
| 396 | UINT64 result = 0; |
| 397 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 398 | result |= (UINT64)read32be_with_16le_device_handler(handler, param, offset * 2 + 0, mem_mask >> 32) << 32; |
| 399 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 400 | result |= (UINT64)read32be_with_16le_device_handler(handler, param, offset * 2 + 1, mem_mask >> 0) << 0; |
| 401 | return result; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | INLINE void write64be_with_16le_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 406 | { |
| 407 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 408 | write32be_with_16le_device_handler(handler, param, offset * 2 + 0, data >> 32, mem_mask >> 32); |
| 409 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 410 | write32be_with_16le_device_handler(handler, param, offset * 2 + 1, data >> 0, mem_mask >> 0); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | /************************************* |
| 415 | * |
| 416 | * 64-bit LE using 16-bit BE handlers |
| 417 | * |
| 418 | *************************************/ |
| 419 | |
| 420 | INLINE UINT32 read64le_with_16be_device_handler(read16_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 421 | { |
| 422 | UINT64 result = 0; |
| 423 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 424 | result |= (UINT64)read32le_with_16be_device_handler(handler, param, offset * 2 + 0, mem_mask >> 0) << 0; |
| 425 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 426 | result |= (UINT64)read32le_with_16be_device_handler(handler, param, offset * 2 + 1, mem_mask >> 32) << 32; |
| 427 | return result; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | INLINE void write64le_with_16be_device_handler(write16_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 432 | { |
| 433 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 434 | write32le_with_16be_device_handler(handler, param, offset * 2 + 0, data >> 0, mem_mask >> 0); |
| 435 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 436 | write32le_with_16be_device_handler(handler, param, offset * 2 + 1, data >> 32, mem_mask >> 32); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | /************************************* |
| 441 | * |
| 442 | * 64-bit BE using 32-bit BE handlers |
| 443 | * |
| 444 | *************************************/ |
| 445 | |
| 446 | INLINE UINT64 read64be_with_32be_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 447 | { |
| 448 | UINT64 result = 0; |
| 449 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 450 | result |= (UINT64)(*handler)(param, offset * 2 + 0, mem_mask >> 32) << 32; |
| 451 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 452 | result |= (UINT64)(*handler)(param, offset * 2 + 1, mem_mask >> 0) << 0; |
| 453 | return result; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | INLINE void write64be_with_32be_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 458 | { |
| 459 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 460 | (*handler)(param, offset * 2 + 0, data >> 32, mem_mask >> 32); |
| 461 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 462 | (*handler)(param, offset * 2 + 1, data >> 0, mem_mask >> 0); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | /************************************* |
| 467 | * |
| 468 | * 64-bit LE using 32-bit LE handlers |
| 469 | * |
| 470 | *************************************/ |
| 471 | |
| 472 | INLINE UINT64 read64le_with_32le_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 473 | { |
| 474 | UINT64 result = 0; |
| 475 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 476 | result |= (UINT64)(*handler)(param, offset * 2 + 0, mem_mask >> 0) << 0; |
| 477 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 478 | result |= (UINT64)(*handler)(param, offset * 2 + 1, mem_mask >> 32) << 32; |
| 479 | return result; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | INLINE void write64le_with_32le_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 484 | { |
| 485 | if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff)) |
| 486 | (*handler)(param, offset * 2 + 0, data >> 0, mem_mask >> 0); |
| 487 | if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000)) |
| 488 | (*handler)(param, offset * 2 + 1, data >> 32, mem_mask >> 32); |
| 489 | } |
| 490 | |
| 491 | |
| 492 | /************************************* |
| 493 | * |
| 494 | * 64-bit BE using 32-bit LE handlers |
| 495 | * |
| 496 | *************************************/ |
| 497 | |
| 498 | INLINE UINT64 read64be_with_32le_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 499 | { |
| 500 | UINT64 result; |
| 501 | mem_mask = FLIPENDIAN_INT64(mem_mask); |
| 502 | result = read64le_with_32le_device_handler(handler, param, offset, mem_mask); |
| 503 | return FLIPENDIAN_INT64(result); |
| 504 | } |
| 505 | |
| 506 | |
| 507 | INLINE void write64be_with_32le_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 508 | { |
| 509 | data = FLIPENDIAN_INT64(data); |
| 510 | mem_mask = FLIPENDIAN_INT64(mem_mask); |
| 511 | write64le_with_32le_device_handler(handler, param, offset, data, mem_mask); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /************************************* |
| 516 | * |
| 517 | * 64-bit LE using 32-bit BE handlers |
| 518 | * |
| 519 | *************************************/ |
| 520 | |
| 521 | INLINE UINT64 read64le_with_32be_device_handler(read32_device_func handler, void *param, offs_t offset, UINT64 mem_mask) |
| 522 | { |
| 523 | UINT64 result; |
| 524 | mem_mask = FLIPENDIAN_INT64(mem_mask); |
| 525 | result = read64be_with_32be_device_handler(handler, param, offset, mem_mask); |
| 526 | return FLIPENDIAN_INT64(result); |
| 527 | } |
| 528 | |
| 529 | |
| 530 | INLINE void write64le_with_32be_device_handler(write32_device_func handler, void *param, offs_t offset, UINT64 data, UINT64 mem_mask) |
| 531 | { |
| 532 | data = FLIPENDIAN_INT64(data); |
| 533 | mem_mask = FLIPENDIAN_INT64(mem_mask); |
| 534 | write64be_with_32be_device_handler(handler, param, offset, data, mem_mask); |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| 539 | /************************************************************************** |
| 540 | |
| 541 | Utility macros |
| 542 | |
| 543 | **************************************************************************/ |
| 544 | |
| 545 | #define DEV_READ_TEMPLATE(bits, name, handler, func) \ |
| 546 | READ##bits##_DEVICE_HANDLER( name##_r ) \ |
| 547 | { \ |
| 548 | return func(handler, device, offset, mem_mask); \ |
| 549 | } |
| 550 | |
| 551 | #define DEV_READ_TEMPLATE_COND(bits, name, handler, func, cond) \ |
| 552 | READ##bits##_DEVICE_HANDLER( name##_r ) \ |
| 553 | { \ |
| 554 | if (cond) \ |
| 555 | return func(handler, device, offset, mem_mask); \ |
| 556 | return 0; \ |
| 557 | } |
| 558 | |
| 559 | #define DEV_WRITE_TEMPLATE(bits, name, handler, func) \ |
| 560 | WRITE##bits##_DEVICE_HANDLER( name##_w ) \ |
| 561 | { \ |
| 562 | func(handler, device, offset, data, mem_mask); \ |
| 563 | } |
| 564 | |
| 565 | #define DEV_WRITE_TEMPLATE_COND(bits, name, handler, func, cond) \ |
| 566 | WRITE##bits##_DEVICE_HANDLER( name##_w ) \ |
| 567 | { \ |
| 568 | if (cond) \ |
| 569 | return func(handler, device, offset, data, mem_mask); \ |
| 570 | } |
| 571 | |
| 572 | |
| 573 | |
| 574 | /************************************************************************** |
| 575 | |
| 576 | Generic conversions macros |
| 577 | |
| 578 | **************************************************************************/ |
| 579 | |
| 580 | |
| 581 | /************************************* |
| 582 | * 8->16be, 1:1 mapping |
| 583 | ************************************/ |
| 584 | |
| 585 | #define DEV_READ8TO16BE( name, read8 ) \ |
| 586 | DEV_READ_TEMPLATE( 16, name, read8, read16be_with_read8_device_handler ) |
| 587 | |
| 588 | |
| 589 | #define DEV_WRITE8TO16BE( name, write8 ) \ |
| 590 | DEV_WRITE_TEMPLATE( 16, name, write8, write16be_with_write8_device_handler ) |
| 591 | |
| 592 | |
| 593 | #define DEV_READWRITE8TO16BE( name, read8, write8 ) \ |
| 594 | DEV_READ8TO16BE(name,read8) \ |
| 595 | DEV_WRITE8TO16BE(name,write8) |
| 596 | |
| 597 | |
| 598 | /************************************* |
| 599 | * 8->16le, 1:1 mapping |
| 600 | ************************************/ |
| 601 | |
| 602 | #define DEV_READ8TO16LE( name, read8 ) \ |
| 603 | DEV_READ_TEMPLATE( 16, name, read8, read16le_with_read8_device_handler ) |
| 604 | |
| 605 | |
| 606 | #define DEV_WRITE8TO16LE( name, write8 ) \ |
| 607 | DEV_WRITE_TEMPLATE( 16, name, write8, write16le_with_write8_device_handler ) |
| 608 | |
| 609 | |
| 610 | #define DEV_READWRITE8TO16LE( name, read8, write8 ) \ |
| 611 | DEV_READ8TO16LE(name,read8) \ |
| 612 | DEV_WRITE8TO16LE(name,write8) |
| 613 | |
| 614 | |
| 615 | /************************************* |
| 616 | * 8->16be, MSB mapping |
| 617 | ************************************/ |
| 618 | |
| 619 | #define DEV_READ8TO16BE_MSB( name, read8 ) \ |
| 620 | DEV_READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_device_handler, ACCESSING_MSB ) |
| 621 | |
| 622 | |
| 623 | #define DEV_WRITE8TO16BE_MSB( name, write8 ) \ |
| 624 | DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_device_handler, ACCESSING_MSB ) |
| 625 | |
| 626 | |
| 627 | #define DEV_READWRITE8TO16BE_MSB( name, read8, write8 ) \ |
| 628 | DEV_READ8TO16BE_MSB(name,read8) \ |
| 629 | DEV_WRITE8TO16BE_MSB(name,write8) |
| 630 | |
| 631 | |
| 632 | /************************************* |
| 633 | * 8->16le, MSB mapping |
| 634 | ************************************/ |
| 635 | |
| 636 | #define DEV_READ8TO16LE_MSB( name, read8 ) \ |
| 637 | DEV_READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_device_handler, ACCESSING_MSB ) |
| 638 | |
| 639 | |
| 640 | #define DEV_WRITE8TO16LE_MSB( name, write8 ) \ |
| 641 | DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_device_handler, ACCESSING_MSB ) |
| 642 | |
| 643 | |
| 644 | #define DEV_READWRITE8TO16LE_MSB( name, read8, write8 ) \ |
| 645 | DEV_READ8TO16LE_MSB(name,read8) \ |
| 646 | DEV_WRITE8TO16LE_MSB(name,write8) |
| 647 | |
| 648 | |
| 649 | /************************************* |
| 650 | * 8->16be, LSB mapping |
| 651 | ************************************/ |
| 652 | |
| 653 | #define DEV_READ8TO16BE_LSB( name, read8 ) \ |
| 654 | DEV_READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_device_handler, ACCESSING_LSB ) |
| 655 | |
| 656 | |
| 657 | #define DEV_WRITE8TO16BE_LSB( name, write8 ) \ |
| 658 | DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_device_handler, ACCESSING_LSB ) |
| 659 | |
| 660 | |
| 661 | #define DEV_READWRITE8TO16BE_LSB( name, read8, write8 ) \ |
| 662 | DEV_READ8TO16BE_LSB(name,read8) \ |
| 663 | DEV_WRITE8TO16BE_LSB(name,write8) |
| 664 | |
| 665 | |
| 666 | /************************************* |
| 667 | * 8->16le, LSB mapping |
| 668 | ************************************/ |
| 669 | |
| 670 | #define DEV_READ8TO16LE_LSB( name, read8 ) \ |
| 671 | DEV_READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_device_handler, ACCESSING_LSB ) |
| 672 | |
| 673 | |
| 674 | #define DEV_WRITE8TO16LE_LSB( name, write8 ) \ |
| 675 | DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_device_handler, ACCESSING_LSB ) |
| 676 | |
| 677 | |
| 678 | #define DEV_READWRITE8TO16LE_LSB( name, read8, write8 ) \ |
| 679 | DEV_READ8TO16LE_LSB(name,read8) \ |
| 680 | DEV_WRITE8TO16LE_LSB(name,write8) |
| 681 | |
| 682 | |
| 683 | /************************************* |
| 684 | * 8->32be, 1:1 mapping |
| 685 | ************************************/ |
| 686 | |
| 687 | #define DEV_READ8TO32BE( name, read8 ) \ |
| 688 | DEV_READ_TEMPLATE( 32, name, read8, read32be_with_read8_device_handler ) |
| 689 | |
| 690 | |
| 691 | #define DEV_WRITE8TO32BE( name, write8 ) \ |
| 692 | DEV_WRITE_TEMPLATE( 32, name, write8, write32be_with_write8_device_handler ) |
| 693 | |
| 694 | |
| 695 | #define DEV_READWRITE8TO32BE( name, read8, write8 ) \ |
| 696 | DEV_READ8TO32BE(name,read8) \ |
| 697 | DEV_WRITE8TO32BE(name,write8) |
| 698 | |
| 699 | |
| 700 | /************************************* |
| 701 | * 8->32le, 1:1 mapping |
| 702 | ************************************/ |
| 703 | |
| 704 | #define DEV_READ8TO32LE( name, read8 ) \ |
| 705 | DEV_READ_TEMPLATE( 32, name, read8, read32le_with_read8_device_handler ) |
| 706 | |
| 707 | |
| 708 | #define DEV_WRITE8TO32LE( name, write8 ) \ |
| 709 | DEV_WRITE_TEMPLATE( 32, name, write8, write32le_with_write8_device_handler ) |
| 710 | |
| 711 | |
| 712 | #define DEV_READWRITE8TO32LE( name, read8, write8 ) \ |
| 713 | DEV_READ8TO32LE(name,read8) \ |
| 714 | DEV_WRITE8TO32LE(name,write8) |
| 715 | |
| 716 | |
| 717 | /************************************* |
| 718 | * 8->32be, MSB mapping |
| 719 | ************************************/ |
| 720 | |
| 721 | #define DEV_READ8TO32BE_MSB( name, read8 ) \ |
| 722 | DEV_READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_device_handler, ACCESSING_MSB32 ) |
| 723 | |
| 724 | |
| 725 | #define DEV_WRITE8TO32BE_MSB( name, write8 ) \ |
| 726 | DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_device_handler, ACCESSING_MSB32 ) |
| 727 | |
| 728 | |
| 729 | #define DEV_READWRITE8TO32BE_MSB( name, read8, write8 ) \ |
| 730 | DEV_READ8TO32BE_MSB(name,read8) \ |
| 731 | DEV_WRITE8TO32BE_MSB(name,write8) |
| 732 | |
| 733 | |
| 734 | /************************************* |
| 735 | * 8->32le, MSB mapping |
| 736 | ************************************/ |
| 737 | |
| 738 | #define DEV_READ8TO32LE_MSB( name, read8 ) \ |
| 739 | DEV_READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_device_handler, ACCESSING_MSB32 ) |
| 740 | |
| 741 | |
| 742 | #define DEV_WRITE8TO32LE_MSB( name, write8 ) \ |
| 743 | DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_device_handler, ACCESSING_MSB32 ) |
| 744 | |
| 745 | |
| 746 | #define DEV_READWRITE8TO32LE_MSB( name, read8, write8 ) \ |
| 747 | DEV_READ8TO32LE_MSB(name,read8) \ |
| 748 | DEV_WRITE8TO32LE_MSB(name,write8) |
| 749 | |
| 750 | |
| 751 | /************************************* |
| 752 | * 8->32be, LSB mapping |
| 753 | ************************************/ |
| 754 | |
| 755 | #define DEV_READ8TO32BE_LSB( name, read8 ) \ |
| 756 | DEV_READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_device_handler, ACCESSING_LSB32 ) |
| 757 | |
| 758 | |
| 759 | #define DEV_WRITE8TO32BE_LSB( name, write8 ) \ |
| 760 | DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_device_handler, ACCESSING_LSB32 ) |
| 761 | |
| 762 | |
| 763 | #define DEV_READWRITE8TO32BE_LSB( name, read8, write8 ) \ |
| 764 | DEV_READ8TO32BE_LSB(name,read8) \ |
| 765 | DEV_WRITE8TO32BE_LSB(name,write8) |
| 766 | |
| 767 | |
| 768 | /************************************* |
| 769 | * 8->32le, LSB mapping |
| 770 | ************************************/ |
| 771 | |
| 772 | #define DEV_READ8TO32LE_LSB( name, read8 ) \ |
| 773 | DEV_READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_device_handler, ACCESSING_LSB32 ) |
| 774 | |
| 775 | |
| 776 | #define DEV_WRITE8TO32LE_LSB( name, write8 ) \ |
| 777 | DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_device_handler, ACCESSING_LSB32 ) |
| 778 | |
| 779 | |
| 780 | #define DEV_READWRITE8TO32LE_LSB( name, read8, write8 ) \ |
| 781 | DEV_READ8TO32LE_LSB(name,read8) \ |
| 782 | DEV_WRITE8TO32LE_LSB(name,write8) |
| 783 | |
| 784 | |
| 785 | /************************************* |
| 786 | * 8->64be, 1:1 mapping |
| 787 | ************************************/ |
| 788 | |
| 789 | #define DEV_READ8TO64BE( name, read8 ) \ |
| 790 | DEV_READ_TEMPLATE( 64, name, read8, read64be_with_read8_device_handler ) |
| 791 | |
| 792 | |
| 793 | #define DEV_WRITE8TO64BE( name, write8 ) \ |
| 794 | DEV_WRITE_TEMPLATE( 64, name, write8, write64be_with_write8_device_handler ) |
| 795 | |
| 796 | |
| 797 | #define DEV_READWRITE8TO64BE( name, read8, write8 ) \ |
| 798 | DEV_READ8TO64BE(name,read8) \ |
| 799 | DEV_WRITE8TO64BE(name,write8) |
| 800 | |
| 801 | |
| 802 | /************************************* |
| 803 | * 8->64le, 1:1 mapping |
| 804 | ************************************/ |
| 805 | |
| 806 | #define DEV_READ8TO64LE( name, read8 ) \ |
| 807 | DEV_READ_TEMPLATE( 64, name, read8, read64le_with_read8_device_handler ) |
| 808 | |
| 809 | |
| 810 | #define DEV_WRITE8TO64LE( name, write8 ) \ |
| 811 | DEV_WRITE_TEMPLATE( 64, name, write8, write64le_with_write8_device_handler ) |
| 812 | |
| 813 | |
| 814 | #define DEV_READWRITE8TO64LE( name, read8, write8 ) \ |
| 815 | DEV_READ8TO64LE(name,read8) \ |
| 816 | DEV_WRITE8TO64LE(name,write8) |
| 817 | |
| 818 | |
| 819 | /************************************* |
| 820 | * 16be->32be, 1:1 mapping |
| 821 | *************************************/ |
| 822 | |
| 823 | #define DEV_READ16BETO32BE( name, read16 ) \ |
| 824 | DEV_READ_TEMPLATE( 32, name, read16, read32be_with_16be_device_handler ) |
| 825 | |
| 826 | |
| 827 | #define DEV_WRITE16BETO32BE( name, write16 ) \ |
| 828 | DEV_WRITE_TEMPLATE( 32, name, write16, write32be_with_16be_device_handler ) |
| 829 | |
| 830 | |
| 831 | #define DEV_READWRITE16BETO32BE( name, read16, write16 ) \ |
| 832 | DEV_READ16BETO32BE(name,read16) \ |
| 833 | DEV_WRITE16BETO32BE(name,write16) |
| 834 | |
| 835 | |
| 836 | /************************************* |
| 837 | * 16le->32be, 1:1 mapping |
| 838 | *************************************/ |
| 839 | |
| 840 | #define DEV_READ16LETO32BE( name, read16 ) \ |
| 841 | DEV_READ_TEMPLATE( 32, name, read16, read32be_with_16le_device_handler ) |
| 842 | |
| 843 | |
| 844 | #define DEV_WRITE16LETO32BE( name, write16 ) \ |
| 845 | DEV_WRITE_TEMPLATE( 32, name, write16, write32be_with_16le_device_handler ) |
| 846 | |
| 847 | |
| 848 | #define DEV_READWRITE16LETO32BE( name, read16, write16 ) \ |
| 849 | DEV_READ16LETO32BE(name,read16) \ |
| 850 | DEV_WRITE16LETO32BE(name,write16) |
| 851 | |
| 852 | |
| 853 | /************************************* |
| 854 | * 16be->32le, 1:1 mapping |
| 855 | *************************************/ |
| 856 | |
| 857 | #define DEV_READ16BETO32LE( name, read16 ) \ |
| 858 | DEV_READ_TEMPLATE( 32, name, read16, read32le_with_16be_device_handler ) |
| 859 | |
| 860 | |
| 861 | #define DEV_WRITE16BETO32LE( name, write16 ) \ |
| 862 | DEV_WRITE_TEMPLATE( 32, name, write16, write32le_with_16be_device_handler ) |
| 863 | |
| 864 | |
| 865 | #define DEV_READWRITE16BETO32LE( name, read16, write16 ) \ |
| 866 | DEV_READ16BETO32LE(name,read16) \ |
| 867 | DEV_WRITE16BETO32LE(name,write16) |
| 868 | |
| 869 | |
| 870 | /************************************* |
| 871 | * 16le->32le, 1:1 mapping |
| 872 | *************************************/ |
| 873 | |
| 874 | #define DEV_READ16LETO32LE( name, read16 ) \ |
| 875 | DEV_READ_TEMPLATE( 32, name, read16, read32le_with_16le_device_handler ) |
| 876 | |
| 877 | |
| 878 | #define DEV_WRITE16LETO32LE( name, write16 ) \ |
| 879 | DEV_WRITE_TEMPLATE( 32, name, write16, write32le_with_16le_device_handler ) |
| 880 | |
| 881 | |
| 882 | #define DEV_READWRITE16LETO32LE( name, read16, write16 ) \ |
| 883 | DEV_READ16LETO32LE(name,read16) \ |
| 884 | DEV_WRITE16LETO32LE(name,write16) |
| 885 | |
| 886 | |
| 887 | /************************************* |
| 888 | * 16be->32be, MSW mapping |
| 889 | *************************************/ |
| 890 | |
| 891 | #define DEV_READ16BETO32BE_MSW( name, read16 ) \ |
| 892 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_device_handler, ACCESSING_MSW32 ) |
| 893 | |
| 894 | |
| 895 | #define DEV_WRITE16BETO32BE_MSW( name, write16 ) \ |
| 896 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_device_handler, ACCESSING_MSW32 ) |
| 897 | |
| 898 | |
| 899 | #define DEV_READWRITE16BETO32BE_MSW( name, read16, write16 ) \ |
| 900 | DEV_READ16BETO32BE_MSW(name,read16) \ |
| 901 | DEV_WRITE16BETO32BE_MSW(name,write16) |
| 902 | |
| 903 | |
| 904 | /************************************* |
| 905 | * 16le->32be, MSW mapping |
| 906 | *************************************/ |
| 907 | |
| 908 | #define DEV_READ16LETO32BE_MSW( name, read16 ) \ |
| 909 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_device_handler, ACCESSING_MSW32 ) |
| 910 | |
| 911 | |
| 912 | #define DEV_WRITE16LETO32BE_MSW( name, write16 ) \ |
| 913 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_device_handler, ACCESSING_MSW32 ) |
| 914 | |
| 915 | |
| 916 | #define DEV_READWRITE16LETO32BE_MSW( name, read16, write16 ) \ |
| 917 | DEV_READ16LETO32BE_MSW(name,read16) \ |
| 918 | DEV_WRITE16LETO32BE_MSW(name,write16) |
| 919 | |
| 920 | |
| 921 | /************************************* |
| 922 | * 16be->32le, MSW mapping |
| 923 | *************************************/ |
| 924 | |
| 925 | #define DEV_READ16BETO32LE_MSW( name, read16 ) \ |
| 926 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_device_handler, ACCESSING_MSW32 ) |
| 927 | |
| 928 | |
| 929 | #define DEV_WRITE16BETO32LE_MSW( name, write16 ) \ |
| 930 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_device_handler, ACCESSING_MSW32 ) |
| 931 | |
| 932 | |
| 933 | #define DEV_READWRITE16BETO32LE_MSW( name, read16, write16 ) \ |
| 934 | DEV_READ16BETO32LE_MSW(name,read16) \ |
| 935 | DEV_WRITE16BETO32LE_MSW(name,write16) |
| 936 | |
| 937 | |
| 938 | /************************************* |
| 939 | * 16le->32le, MSW mapping |
| 940 | *************************************/ |
| 941 | |
| 942 | #define DEV_READ16LETO32LE_MSW( name, read16 ) \ |
| 943 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_device_handler, ACCESSING_MSW32 ) |
| 944 | |
| 945 | |
| 946 | #define DEV_WRITE16LETO32LE_MSW( name, write16 ) \ |
| 947 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_device_handler, ACCESSING_MSW32 ) |
| 948 | |
| 949 | |
| 950 | #define DEV_READWRITE16LETO32LE_MSW( name, read16, write16 ) \ |
| 951 | DEV_READ16LETO32LE_MSW(name,read16) \ |
| 952 | DEV_WRITE16LETO32LE_MSW(name,write16) |
| 953 | |
| 954 | /************************************* |
| 955 | * 16be->32be, LSW mapping |
| 956 | *************************************/ |
| 957 | |
| 958 | #define DEV_READ16BETO32BE_LSW( name, read16 ) \ |
| 959 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_device_handler, ACCESSING_LSW32 ) |
| 960 | |
| 961 | |
| 962 | #define DEV_WRITE16BETO32BE_LSW( name, write16 ) \ |
| 963 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_device_handler, ACCESSING_LSW32 ) |
| 964 | |
| 965 | |
| 966 | #define DEV_READWRITE16BETO32BE_LSW( name, read16, write16 ) \ |
| 967 | DEV_READ16BETO32BE_LSW(name,read16) \ |
| 968 | DEV_WRITE16BETO32BE_LSW(name,write16) |
| 969 | |
| 970 | |
| 971 | /************************************* |
| 972 | * 16le->32be, LSW mapping |
| 973 | *************************************/ |
| 974 | |
| 975 | #define DEV_READ16LETO32BE_LSW( name, read16 ) \ |
| 976 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_device_handler, ACCESSING_LSW32 ) |
| 977 | |
| 978 | |
| 979 | #define DEV_WRITE16LETO32BE_LSW( name, write16 ) \ |
| 980 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_device_handler, ACCESSING_LSW32 ) |
| 981 | |
| 982 | |
| 983 | #define DEV_READWRITE16LETO32BE_LSW( name, read16, write16 ) \ |
| 984 | DEV_READ16LETO32BE_LSW(name,read16) \ |
| 985 | DEV_WRITE16LETO32BE_LSW(name,write16) |
| 986 | |
| 987 | |
| 988 | /************************************* |
| 989 | * 16be->32le, LSW mapping |
| 990 | *************************************/ |
| 991 | |
| 992 | #define DEV_READ16BETO32LE_LSW( name, read16 ) \ |
| 993 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_device_handler, ACCESSING_LSW32 ) |
| 994 | |
| 995 | |
| 996 | #define DEV_WRITE16BETO32LE_LSW( name, write16 ) \ |
| 997 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_device_handler, ACCESSING_LSW32 ) |
| 998 | |
| 999 | |
| 1000 | #define DEV_READWRITE16BETO32LE_LSW( name, read16, write16 ) \ |
| 1001 | DEV_READ16BETO32LE_LSW(name,read16) \ |
| 1002 | DEV_WRITE16BETO32LE_LSW(name,write16) |
| 1003 | |
| 1004 | |
| 1005 | /************************************* |
| 1006 | * 16le->32le, LSW mapping |
| 1007 | *************************************/ |
| 1008 | |
| 1009 | #define DEV_READ16LETO32LE_LSW( name, read16 ) \ |
| 1010 | DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_device_handler, ACCESSING_LSW32 ) |
| 1011 | |
| 1012 | |
| 1013 | #define DEV_WRITE16LETO32LE_LSW( name, write16 ) \ |
| 1014 | DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_device_handler, ACCESSING_LSW32 ) |
| 1015 | |
| 1016 | |
| 1017 | #define DEV_READWRITE16LETO32LE_LSW( name, read16, write16 ) \ |
| 1018 | DEV_READ16LETO32LE_LSW(name,read16) \ |
| 1019 | DEV_WRITE16LETO32LE_LSW(name,write16) |
| 1020 | |