67f4f45976a6aa2c025923de4ba461fb2e6bb7d6
[picodrive.git] / pico / carthw / svp / ssp16.h
1 /* 
2  * basic, incomplete SSP160x (SSP1601?) interpreter
3  *
4  * Copyright (c) GraÅžvydas "notaz" Ignotas, 2008
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in the
12  *       documentation and/or other materials provided with the distribution.
13  *     * Neither the name of the organization nor the
14  *       names of its contributors may be used to endorse or promote products
15  *       derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 // register names
30 enum {
31         SSP_GR0, SSP_X,     SSP_Y,   SSP_A,
32         SSP_ST,  SSP_STACK, SSP_PC,  SSP_P,
33         SSP_PM0, SSP_PM1,   SSP_PM2, SSP_XST,
34         SSP_PM4, SSP_gr13,  SSP_PMC, SSP_AL
35 };
36
37 typedef union
38 {
39         unsigned int v;
40         struct {
41 #if CPU_IS_LE
42                 unsigned short l;
43                 unsigned short h;
44 #else
45                 unsigned short h;
46                 unsigned short l;
47 #endif
48         };
49 } ssp_reg_t;
50
51 typedef struct
52 {
53         union {
54                 unsigned short RAM[256*2];      // 000 2 internal RAM banks
55                 struct {
56                         unsigned short RAM0[256];
57                         unsigned short RAM1[256];
58                 };
59         };
60         ssp_reg_t gr[16];                       // 400 general registers
61         union {
62                 unsigned char r[8];             // 440 BANK pointers
63                 struct {
64                         unsigned char r0[4];
65                         unsigned char r1[4];
66                 };
67         };
68         unsigned short stack[6];                // 448
69         unsigned int pmac_read[6];              // 454 read modes/addrs for PM0-PM5
70         unsigned int pmac_write[6];             // 46c write ...
71         //
72         #define SSP_PMC_HAVE_ADDR       0x0001  // address written to PMAC, waiting for mode
73         #define SSP_PMC_SET             0x0002  // PMAC is set
74         #define SSP_WAIT_PM0            0x2000  // bit1 in PM0
75         #define SSP_WAIT_30FE06         0x4000  // ssp tight loops on 30FE06 to become non-zero
76         #define SSP_WAIT_30FE08         0x8000  // same for 30FE06
77         #define SSP_WAIT_MASK           0xe000
78         unsigned int emu_status;                // 484
79         /* used by recompiler only: */
80         struct {
81                 unsigned int ptr_rom;           // 488
82                 unsigned int ptr_iram_rom;      // 48c
83                 unsigned int ptr_dram;          // 490
84                 unsigned int iram_dirty;        // 494
85                 unsigned int iram_context;      // 498
86                 unsigned int ptr_btable;        // 49c
87                 unsigned int ptr_btable_iram;   // 4a0
88                 unsigned int tmp0;              // 4a4
89                 unsigned int tmp1;              // 4a8
90                 unsigned int tmp2;              // 4ac
91         } drc;
92 } ssp1601_t;
93
94
95 void ssp1601_reset(ssp1601_t *ssp);
96 void ssp1601_run(int cycles);
97