src/mess/eventlst.c
| r8394 | r8395 | |
| 1 | | #include "emu.h" |
| 2 | | #include "eventlst.h" |
| 3 | | |
| 4 | | /* current item */ |
| 5 | | static EVENT_LIST_ITEM *pCurrentItem; |
| 6 | | /* number of items in buffer */ |
| 7 | | static int NumEvents = 0; |
| 8 | | |
| 9 | | /* size of the buffer - used to prevent buffer overruns */ |
| 10 | | static int TotalEvents = 0; |
| 11 | | |
| 12 | | /* the buffer */ |
| 13 | | static char *pEventListBuffer = NULL; |
| 14 | | |
| 15 | | /* Cycle count at last frame draw - used for timing offset calculations */ |
| 16 | | static int LastFrameStartTime = 0; |
| 17 | | |
| 18 | | static int CyclesPerFrame=0; |
| 19 | | |
| 20 | | /* initialise */ |
| 21 | | |
| 22 | | /* if the CPU is the controlling factor, the size of the buffer |
| 23 | | can be setup as: |
| 24 | | |
| 25 | | Number_of_CPU_Cycles_In_A_Frame/Minimum_Number_Of_Cycles_Per_Instruction */ |
| 26 | | void EventList_Initialise(running_machine *machine, int NumEntries) |
| 27 | | { |
| 28 | | pEventListBuffer = auto_alloc_array(machine, char, NumEntries); |
| 29 | | TotalEvents = NumEntries; |
| 30 | | CyclesPerFrame = 0; |
| 31 | | EventList_Reset(); |
| 32 | | } |
| 33 | | |
| 34 | | /* reset the change list */ |
| 35 | | void EventList_Reset(void) |
| 36 | | { |
| 37 | | NumEvents = 0; |
| 38 | | pCurrentItem = (EVENT_LIST_ITEM *)pEventListBuffer; |
| 39 | | } |
| 40 | | |
| 41 | | |
| 42 | | /* add an event to the buffer */ |
| 43 | | void EventList_AddItem(int ID, int Data, int Time) |
| 44 | | { |
| 45 | | if (NumEvents < TotalEvents) |
| 46 | | { |
| 47 | | /* setup item only if there is space in the buffer */ |
| 48 | | pCurrentItem->Event_ID = ID; |
| 49 | | pCurrentItem->Event_Data = Data; |
| 50 | | pCurrentItem->Event_Time = Time; |
| 51 | | |
| 52 | | pCurrentItem++; |
| 53 | | NumEvents++; |
| 54 | | } |
| 55 | | } |
| 56 | | |
| 57 | | /* set the start time for use with EventList_AddItemOffset usually this will |
| 58 | | be cpu_getcurrentcycles() at the time that the screen is being refreshed */ |
| 59 | | void EventList_SetOffsetStartTime(int StartTime) |
| 60 | | { |
| 61 | | LastFrameStartTime = StartTime; |
| 62 | | } |
| 63 | | |
| 64 | | /* add an event to the buffer with a time index offset from a specified time */ |
| 65 | | void EventList_AddItemOffset(running_machine *machine, int ID, int Data, int Time) |
| 66 | | { |
| 67 | | |
| 68 | | if (!CyclesPerFrame) |
| 69 | | CyclesPerFrame = (int)(cpu_get_clock(machine->firstcpu) / machine->primary_screen->frame_period().attoseconds); //totalcycles(); //_(int)(cpunum_get_clock(0) / machine->config->frames_per_second); |
| 70 | | |
| 71 | | if (NumEvents < TotalEvents) |
| 72 | | { |
| 73 | | /* setup item only if there is space in the buffer */ |
| 74 | | pCurrentItem->Event_ID = ID; |
| 75 | | pCurrentItem->Event_Data = Data; |
| 76 | | |
| 77 | | Time -= LastFrameStartTime; |
| 78 | | if ((Time < 0) || ((Time == 0) && NumEvents)) |
| 79 | | Time+= CyclesPerFrame; |
| 80 | | pCurrentItem->Event_Time = Time; |
| 81 | | |
| 82 | | pCurrentItem++; |
| 83 | | NumEvents++; |
| 84 | | } |
| 85 | | } |
| 86 | | |
| 87 | | /* get number of events */ |
| 88 | | int EventList_NumEvents(void) |
| 89 | | { |
| 90 | | return NumEvents; |
| 91 | | } |
| 92 | | |
| 93 | | /* get first item in buffer */ |
| 94 | | EVENT_LIST_ITEM *EventList_GetFirstItem(void) |
| 95 | | { |
| 96 | | return (EVENT_LIST_ITEM *)pEventListBuffer; |
| 97 | | } |
src/mess/includes/spectrum.h
| r8394 | r8395 | |
| 127 | 127 | int LeftBorderPixels, int ScreenPixels, int RightBorderPixels, |
| 128 | 128 | int LeftBorderCycles, int ScreenCycles, int RightBorderCycles, |
| 129 | 129 | int HorizontalRetraceCycles, int VRetraceTime, int EventID); |
| 130 | |
| 131 | typedef struct EVENT_LIST_ITEM |
| 132 | { |
| 133 | /* driver defined ID for this write */ |
| 134 | int Event_ID; |
| 135 | /* driver defined data for this write */ |
| 136 | int Event_Data; |
| 137 | /* time at which this write occured */ |
| 138 | int Event_Time; |
| 139 | } EVENT_LIST_ITEM; |
| 140 | |
| 141 | void EventList_Initialise(running_machine *machine, int NumEntries); |
| 142 | void EventList_Reset(void); |
| 143 | void EventList_AddItem(int ID, int Data,int Time); |
| 144 | void EventList_SetOffsetStartTime(int StartTime); |
| 145 | void EventList_AddItemOffset(running_machine *machine, int ID, int Data,int Time); |
| 146 | int EventList_NumEvents(void); |
| 147 | EVENT_LIST_ITEM *EventList_GetFirstItem(void); |
| 130 | 148 | |
| 131 | 149 | /*----------- defined in video/timex.c -----------*/ |
| 132 | 150 | extern VIDEO_EOF( ts2068 ); |
src/mess/video/spectrum.c
| r8394 | r8395 | |
| 15 | 15 | |
| 16 | 16 | #include "emu.h" |
| 17 | 17 | #include "includes/spectrum.h" |
| 18 | | #include "eventlst.h" |
| 19 | 18 | |
| 20 | | |
| 21 | 19 | /*************************************************************************** |
| 22 | 20 | Start the video hardware emulation. |
| 23 | 21 | ***************************************************************************/ |
| r8394 | r8395 | |
| 531 | 529 | EventList_Reset(); |
| 532 | 530 | EventList_SetOffsetStartTime ( cpu_attotime_to_clocks(machine->firstcpu, attotime_mul(machine->primary_screen->scan_period(), machine->primary_screen->vpos())) ); |
| 533 | 531 | } |
| 532 | |
| 533 | /* current item */ |
| 534 | static EVENT_LIST_ITEM *pCurrentItem; |
| 535 | /* number of items in buffer */ |
| 536 | static int NumEvents = 0; |
| 537 | |
| 538 | /* size of the buffer - used to prevent buffer overruns */ |
| 539 | static int TotalEvents = 0; |
| 540 | |
| 541 | /* the buffer */ |
| 542 | static char *pEventListBuffer = NULL; |
| 543 | |
| 544 | /* Cycle count at last frame draw - used for timing offset calculations */ |
| 545 | static int LastFrameStartTime = 0; |
| 546 | |
| 547 | static int CyclesPerFrame=0; |
| 548 | |
| 549 | /* initialise */ |
| 550 | |
| 551 | /* if the CPU is the controlling factor, the size of the buffer |
| 552 | can be setup as: |
| 553 | |
| 554 | Number_of_CPU_Cycles_In_A_Frame/Minimum_Number_Of_Cycles_Per_Instruction */ |
| 555 | void EventList_Initialise(running_machine *machine, int NumEntries) |
| 556 | { |
| 557 | pEventListBuffer = auto_alloc_array(machine, char, NumEntries); |
| 558 | TotalEvents = NumEntries; |
| 559 | CyclesPerFrame = 0; |
| 560 | EventList_Reset(); |
| 561 | } |
| 562 | |
| 563 | /* reset the change list */ |
| 564 | void EventList_Reset(void) |
| 565 | { |
| 566 | NumEvents = 0; |
| 567 | pCurrentItem = (EVENT_LIST_ITEM *)pEventListBuffer; |
| 568 | } |
| 569 | |
| 570 | |
| 571 | /* add an event to the buffer */ |
| 572 | void EventList_AddItem(int ID, int Data, int Time) |
| 573 | { |
| 574 | if (NumEvents < TotalEvents) |
| 575 | { |
| 576 | /* setup item only if there is space in the buffer */ |
| 577 | pCurrentItem->Event_ID = ID; |
| 578 | pCurrentItem->Event_Data = Data; |
| 579 | pCurrentItem->Event_Time = Time; |
| 580 | |
| 581 | pCurrentItem++; |
| 582 | NumEvents++; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /* set the start time for use with EventList_AddItemOffset usually this will |
| 587 | be cpu_getcurrentcycles() at the time that the screen is being refreshed */ |
| 588 | void EventList_SetOffsetStartTime(int StartTime) |
| 589 | { |
| 590 | LastFrameStartTime = StartTime; |
| 591 | } |
| 592 | |
| 593 | /* add an event to the buffer with a time index offset from a specified time */ |
| 594 | void EventList_AddItemOffset(running_machine *machine, int ID, int Data, int Time) |
| 595 | { |
| 596 | |
| 597 | if (!CyclesPerFrame) |
| 598 | CyclesPerFrame = (int)(cpu_get_clock(machine->firstcpu) / machine->primary_screen->frame_period().attoseconds); //totalcycles(); //_(int)(cpunum_get_clock(0) / machine->config->frames_per_second); |
| 599 | |
| 600 | if (NumEvents < TotalEvents) |
| 601 | { |
| 602 | /* setup item only if there is space in the buffer */ |
| 603 | pCurrentItem->Event_ID = ID; |
| 604 | pCurrentItem->Event_Data = Data; |
| 605 | |
| 606 | Time -= LastFrameStartTime; |
| 607 | if ((Time < 0) || ((Time == 0) && NumEvents)) |
| 608 | Time+= CyclesPerFrame; |
| 609 | pCurrentItem->Event_Time = Time; |
| 610 | |
| 611 | pCurrentItem++; |
| 612 | NumEvents++; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | /* get number of events */ |
| 617 | int EventList_NumEvents(void) |
| 618 | { |
| 619 | return NumEvents; |
| 620 | } |
| 621 | |
| 622 | /* get first item in buffer */ |
| 623 | EVENT_LIST_ITEM *EventList_GetFirstItem(void) |
| 624 | { |
| 625 | return (EVENT_LIST_ITEM *)pEventListBuffer; |
| 626 | } |
src/mess/video/kc.c
| r8394 | r8395 | |
| 8 | 8 | |
| 9 | 9 | #include "emu.h" |
| 10 | 10 | #include "includes/kc.h" |
| 11 | | #include "eventlst.h" |
| 12 | 11 | #include "devices/messram.h" |
| 13 | 12 | |
| 14 | 13 | /* KC85/4 and KC85/3 common graphics hardware */ |
| r8394 | r8395 | |
| 112 | 111 | /* set new blink state - record blink state in event list */ |
| 113 | 112 | void kc85_video_set_blink_state(running_machine *machine, int data) |
| 114 | 113 | { |
| 115 | | EventList_AddItemOffset(machine, KC85_VIDEO_EVENT_SET_BLINK_STATE, ((data & 0x01)<<7), cpu_attotime_to_clocks(machine->firstcpu, attotime_mul(machine->primary_screen->scan_period(), machine->primary_screen->vpos()))); |
| 114 | // EventList_AddItemOffset(machine, KC85_VIDEO_EVENT_SET_BLINK_STATE, ((data & 0x01)<<7), cpu_attotime_to_clocks(machine->firstcpu, attotime_mul(machine->primary_screen->scan_period(), machine->primary_screen->vpos()))); |
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | |
| r8394 | r8395 | |
| 497 | 496 | { |
| 498 | 497 | int cycles_remaining_in_frame = KC85_CYCLES_PER_FRAME; |
| 499 | 498 | |
| 500 | | EVENT_LIST_ITEM *pItem; |
| 501 | | int NumItems; |
| 499 | // EVENT_LIST_ITEM *pItem; |
| 500 | // int NumItems; |
| 502 | 501 | |
| 503 | 502 | struct video_update_state video_update; |
| 504 | | int cycles_offset = 0; |
| 503 | // int cycles_offset = 0; |
| 505 | 504 | |
| 506 | 505 | video_update.render_x = 0; |
| 507 | 506 | video_update.render_y = 0; |
| r8394 | r8395 | |
| 517 | 516 | video_update.vertical.cycles_remaining_in_state = vertical_graphics_state_lines[video_update.vertical.state]; |
| 518 | 517 | video_update.vertical.cycles_remaining = KC85_CYCLES_PER_FRAME; |
| 519 | 518 | |
| 520 | | /* first item in list */ |
| 521 | | pItem = EventList_GetFirstItem(); |
| 522 | | /* number of items remaining */ |
| 523 | | NumItems = EventList_NumEvents(); |
| 519 | // /* first item in list */ |
| 520 | // pItem = EventList_GetFirstItem(); |
| 521 | // /* number of items remaining */ |
| 522 | // NumItems = EventList_NumEvents(); |
| 523 | // |
| 524 | // while (NumItems) |
| 525 | // { |
| 526 | // int delta_cycles; |
| 527 | // |
| 528 | // /* number of cycles until event will trigger */ |
| 529 | // delta_cycles = pItem->Event_Time - cycles_offset; |
| 530 | // |
| 531 | // //logerror("cycles between this event and next: %d\n",delta_cycles); |
| 532 | // kc85_common_vh_process_lines(&video_update, delta_cycles); |
| 533 | // |
| 534 | // /* update number of cycles remaining in frame */ |
| 535 | // cycles_remaining_in_frame -= delta_cycles; |
| 536 | // /* set new blink state */ |
| 537 | // kc85_blink_state = pItem->Event_Data; |
| 538 | // |
| 539 | // /* set new cycles into frame */ |
| 540 | // cycles_offset = pItem->Event_Time; |
| 541 | // /* next event */ |
| 542 | // pItem++; |
| 543 | // /* update number of events remaining */ |
| 544 | // NumItems--; |
| 545 | // } |
| 524 | 546 | |
| 525 | | while (NumItems) |
| 526 | | { |
| 527 | | int delta_cycles; |
| 528 | 547 | |
| 529 | | /* number of cycles until event will trigger */ |
| 530 | | delta_cycles = pItem->Event_Time - cycles_offset; |
| 531 | | |
| 532 | | //logerror("cycles between this event and next: %d\n",delta_cycles); |
| 533 | | kc85_common_vh_process_lines(&video_update, delta_cycles); |
| 534 | | |
| 535 | | /* update number of cycles remaining in frame */ |
| 536 | | cycles_remaining_in_frame -= delta_cycles; |
| 537 | | /* set new blink state */ |
| 538 | | kc85_blink_state = pItem->Event_Data; |
| 539 | | |
| 540 | | /* set new cycles into frame */ |
| 541 | | cycles_offset = pItem->Event_Time; |
| 542 | | /* next event */ |
| 543 | | pItem++; |
| 544 | | /* update number of events remaining */ |
| 545 | | NumItems--; |
| 546 | | } |
| 547 | | |
| 548 | | |
| 549 | 548 | /* process remainder */ |
| 550 | 549 | kc85_common_vh_process_lines(&video_update, cycles_remaining_in_frame); |
| 551 | | EventList_Reset(); |
| 552 | | EventList_SetOffsetStartTime ( cpu_attotime_to_clocks(machine->firstcpu, attotime_mul(machine->primary_screen->scan_period(), machine->primary_screen->vpos())) ); |
| 550 | // EventList_Reset(); |
| 551 | // EventList_SetOffsetStartTime ( cpu_attotime_to_clocks(machine->firstcpu, attotime_mul(machine->primary_screen->scan_period(), machine->primary_screen->vpos())) ); |
| 553 | 552 | } |
| 554 | 553 | |
| 555 | 554 | |
| r8394 | r8395 | |
| 557 | 556 | /*************************************************************************** |
| 558 | 557 | KC85/4 video hardware |
| 559 | 558 | ***************************************************************************/ |
| 560 | | |
| 561 | | #ifdef UNUSED_FUNCTION |
| 562 | | static void kc85_common_vh_eof_callback(void) |
| 563 | | { |
| 564 | | //EVENT_LIST_ITEM *pItem; |
| 565 | | int NumItems; |
| 566 | | |
| 567 | | /* Empty event buffer */ |
| 568 | | NumItems = EventList_NumEvents(); |
| 569 | | |
| 570 | | /* to do: the entries in this buffer are ignored. OK? */ |
| 571 | | if (NumItems) |
| 572 | | { |
| 573 | | //pItem = EventList_GetFirstItem(); |
| 574 | | EventList_Reset(); |
| 575 | | EventList_SetOffsetStartTime ( cpu_attotime_to_clocks(machine->firstcpu, attotime_mul(machine->primary_screen->scan_period(), machine->primary_screen->vpos())) ); |
| 576 | | logerror ("Event log reset in callback fn.\n"); |
| 577 | | } |
| 578 | | } |
| 579 | | #endif |
| 580 | | |
| 581 | 559 | static void kc85_common_vh_start(running_machine *machine) |
| 582 | 560 | { |
| 583 | 561 | kc85_blink_state = 0; |
| 584 | | EventList_Initialise(machine, 30000); |
| 562 | // EventList_Initialise(machine, 30000); |
| 585 | 563 | } |
| 586 | 564 | |
| 587 | 565 | static unsigned char *kc85_4_display_video_ram; |