initial import
[picodrive.git] / Pico / cd / Sek.c
1 // This is part of Pico Library
2
3 // (c) Copyright 2004 Dave, All rights reserved.
4 // (c) Copyright 2006 notaz, All rights reserved.
5 // Free for non-commercial use.
6
7 // For commercial use, separate licencing terms must be obtained.
8
9
10 #include "../PicoInt.h"
11
12
13 int SekCycleCntS68k=0; // cycles done in this frame
14 int SekCycleAimS68k=0; // cycle aim
15
16 #ifdef EMU_M68K
17 // ---------------------- MUSASHI 68000 ----------------------
18 m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU
19 #endif
20
21
22 #ifdef EMU_M68K
23 int SekIntAckS68k(int level)
24 {
25   dprintf("s68k: int %i ack [%i|%i]", level, Pico.m.scanline, SekCyclesDone());
26   CPU_INT_LEVEL = 0;
27   return M68K_INT_ACK_AUTOVECTOR;
28 }
29 #endif
30
31
32 int SekInitS68k()
33 {
34 #ifdef EMU_M68K
35   {
36     // Musashi is not very context friendly..
37     void *oldcontext = m68ki_cpu_p;
38     m68k_set_context(&PicoS68kCPU);
39     m68k_set_cpu_type(M68K_CPU_TYPE_68000);
40     m68k_init();
41     m68k_set_int_ack_callback(SekIntAckS68k);
42 //  m68k_pulse_reset(); // not yet, memmap is not set up
43     m68k_set_context(oldcontext);
44   }
45 #endif
46
47   return 0;
48 }
49
50 // Reset the 68000:
51 int SekResetS68k()
52 {
53   if (Pico.rom==NULL) return 1;
54
55 #ifdef EMU_M68K
56   {
57     void *oldcontext = m68ki_cpu_p;
58
59     m68k_set_context(&PicoS68kCPU);
60     m68k_pulse_reset();
61     m68k_set_context(oldcontext);
62   }
63 #endif
64
65   return 0;
66 }
67
68 int SekInterruptS68k(int irq)
69 {
70 #ifdef EMU_M68K
71   void *oldcontext = m68ki_cpu_p;
72   m68k_set_context(&PicoS68kCPU);
73   m68k_set_irq(irq); // raise irq (gets lowered after taken or must be done in ack)
74   m68k_set_context(oldcontext);
75 #endif
76   return 0;
77 }
78