-
Notifications
You must be signed in to change notification settings - Fork 0
/
Z80_PIC.h
281 lines (226 loc) · 8.68 KB
/
Z80_PIC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//---------------------------------------------------------------------------
//
#ifndef _Z80_PIC_INCLUDED
#define _Z80_PIC_INCLUDED
#include <stdint.h>
//---------------------------------------------------------------------------
/* check if build is for a real debug tool */
#if defined(__DEBUG) && !defined(__MPLAB_ICD2_) && !defined(__MPLAB_ICD3_) && \
!defined(__MPLAB_PICKIT2__) && !defined(__MPLAB_PICKIT3__) && \
!defined(__MPLAB_REALICE__) && \
!defined(__MPLAB_DEBUGGER_REAL_ICE) && \
!defined(__MPLAB_DEBUGGER_ICD3) && \
!defined(__MPLAB_DEBUGGER_PK3) && \
!defined(__MPLAB_DEBUGGER_PICKIT2) && \
!defined(__MPLAB_DEBUGGER_PIC32MXSK)
#warning Debug with broken MPLAB simulator
#define USING_SIMULATOR
#endif
//#define REAL_SIZE
#define FCY 204000000ul //Oscillator frequency; ricontrollato con baud rate, pare giusto così!
#define CPU_CLOCK_HZ (FCY) // CPU Clock Speed in Hz
#define CPU_CT_HZ (CPU_CLOCK_HZ/2) // CPU CoreTimer in Hz
#define PERIPHERAL_CLOCK_HZ (FCY/2 /*100000000UL*/) // Peripheral Bus in Hz
#define GetSystemClock() (FCY) // CPU Clock Speed in Hz
#define GetPeripheralClock() (PERIPHERAL_CLOCK_HZ) // Peripheral Bus in Hz
#define FOSC 8000000ul
#define US_TO_CT_TICKS (CPU_CT_HZ/1000000UL) // uS to CoreTimer Ticks
#define VERNUML 9
#define VERNUMH 1
//#define ZX80 1
//#define ZX81 1 //
//#define SKYNET 1
//#define NEZ80 1
//#define GALAKSIJA 1 // emulatore online https://galaksija.net/?i=1
// https://www.kernelcrash.com/blog/making-a-galaksija/2020/03/02/
// CANCRO a antonio caradonna MORTE alla puglia!!!
#define MSX 1
// https://bluemsx.com/ emulatore
#ifdef MSX
#define TMS99xx_BASE 0x98
#define VIDEORAM_SIZE 16384
#define TMS_R0_MODE_GRAPHICS_I 0x00
#define TMS_R0_MODE_GRAPHICS_II 0x02
#define TMS_R0_MODE_MULTICOLOR 0x00
#define TMS_R0_MODE_TEXT 0x00
#define TMS_R0_EXT_VDP_ENABLE 0x01
#define TMS_R0_EXT_VDP_DISABLE 0x00
#define TMS_R1_RAM_16K 0x80
#define TMS_R1_RAM_4K 0x00
#define TMS_R1_DISP_BLANK 0x00
#define TMS_R1_DISP_ACTIVE 0x40
#define TMS_R1_INT_ENABLE 0x20
#define TMS_R1_INT_DISABLE 0x00
#define TMS_R1_MODE_GRAPHICS_I 0x00
#define TMS_R1_MODE_GRAPHICS_II 0x00
#define TMS_R1_MODE_MULTICOLOR 0x08
#define TMS_R1_MODE_TEXT 0x10
#define TMS_R1_SPRITE_8 0x00
#define TMS_R1_SPRITE_16 0x02
#define TMS_R1_SPRITE_MAG1 0x00
#define TMS_R1_SPRITE_MAG2 0x01
#define LAST_SPRITE_YPOS 0xD0
#define TMS_DEFAULT_VRAM_NAME_ADDRESS 0x3800
#define TMS_DEFAULT_VRAM_COLOR_ADDRESS 0x0000
#define TMS_DEFAULT_VRAM_PATT_ADDRESS 0x2000
#define TMS_DEFAULT_VRAM_SPRITE_ATTR_ADDRESS 0x3B00
#define TMS_DEFAULT_VRAM_SPRITE_PATT_ADDRESS 0x1800
extern uint8_t VideoRAM[VIDEORAM_SIZE];
struct __attribute__((__packed__)) SPRITE_ATTR {
uint8_t ypos,xpos; // v. sotto, a volte usato come signed
uint8_t name;
union __attribute__((__packed__)) {
struct __attribute__((__packed__)) {
unsigned int color:4;
unsigned int unused:3;
unsigned int eclock:1;
};
uint8_t tag;
};
};
#endif
//#define MSX2 1
typedef char BOOL;
typedef unsigned char UINT8;
typedef unsigned char BYTE;
typedef signed char INT8;
typedef unsigned short int WORD;
typedef unsigned short int SWORD; // v. C64: con int/32bit è più veloce!
typedef unsigned long UINT32;
typedef unsigned long DWORD;
typedef signed long INT32;
typedef unsigned short int UINT16;
typedef signed int INT16;
typedef DWORD COLORREF;
#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
#define TRUE 1
#define FALSE 0
enum {
DoReset=1,
DoNMI=2,
DoIRQ=4,
DoWait=8,
DoHalt=16
};
#ifdef ST7735
#define _TFTWIDTH 160 //the REAL W resolution of the TFT
#define _TFTHEIGHT 128 //the REAL H resolution of the TFT
typedef int8_t GRAPH_COORD_T;
typedef uint8_t UGRAPH_COORD_T;
#endif
#ifdef ILI9341
#define _TFTWIDTH 320 //the REAL W resolution of the TFT
#define _TFTHEIGHT 240 //the REAL H resolution of the TFT
typedef int16_t GRAPH_COORD_T;
typedef uint16_t UGRAPH_COORD_T;
#endif
void mySYSTEMConfigPerformance(void);
void myINTEnableSystemMultiVectoredInt(void);
#define ReadCoreTimer() _CP0_GET_COUNT() // Read the MIPS Core Timer
void ShortDelay(DWORD DelayCount);
//#define __delay_ms(n) ShortDelay(n*100000UL)
//#define __delay_ns(n) ShortDelay(n*100UL)
void DelayUs(unsigned int);
void DelayMs(unsigned int);
void __delay_us(unsigned int);
void __delay_ms(unsigned int);
#define ClrWdt() { WDTCONbits.WDTCLRKEY=0x5743; }
// PIC32 RTCC Structure
typedef union {
struct {
unsigned char weekday; // BCD codification for day of the week, 00-06
unsigned char mday; // BCD codification for day of the month, 01-31
unsigned char mon; // BCD codification for month, 01-12
unsigned char year; // BCD codification for years, 00-99
}; // field access
unsigned char b[4]; // byte access
unsigned short w[2]; // 16 bits access
unsigned long l; // 32 bits access
} PIC32_RTCC_DATE;
// PIC32 RTCC Structure
typedef union {
struct {
unsigned char reserved; // reserved for future use. should be 0
unsigned char sec; // BCD codification for seconds, 00-59
unsigned char min; // BCD codification for minutes, 00-59
unsigned char hour; // BCD codification for hours, 00-24
}; // field access
unsigned char b[4]; // byte access
unsigned short w[2]; // 16 bits access
unsigned long l; // 32 bits access
} PIC32_RTCC_TIME;
extern volatile PIC32_RTCC_DATE currentDate;
extern volatile PIC32_RTCC_TIME currentTime;
void Timer_Init(void);
void PWM_Init(void);
void UART_Init(DWORD);
void putsUART1(unsigned int *buffer);
int decodeKBD(int, long, BOOL);
BYTE GetValue(SWORD);
SWORD GetIntValue(SWORD);
void PutValue(SWORD, BYTE);
void PutIntValue(SWORD, SWORD);
BYTE InValue(SWORD);
void OutValue(SWORD, BYTE);
BYTE GetPipe(SWORD);
int Emulate(int);
#ifdef SKYNET
int UpdateScreen(WORD);
#endif
#ifdef ZX80
int UpdateScreen(SWORD rowIni, SWORD rowFin, BYTE _i);
#endif
#ifdef GALAKSIJA
int UpdateScreen(SWORD rowIni, SWORD rowFin);
#endif
#ifdef MSX
int UpdateScreen(SWORD rowIni, SWORD rowFin);
#endif
void LCDXY(BYTE, BYTE);
void LCDCls();
void LCDWrite(const char *s);
void drawBG();
unsigned int ReadUART1(void);
void WriteUART1(unsigned int);
#ifdef ST7735 // ST7735 160x128 su Arduino con dsPIC
#define LED1 LATEbits.LATE2
#define LED2 LATEbits.LATE3
#define LED3 LATEbits.LATE4
#define SW1 PORTDbits.RD2
#define SW2 PORTDbits.RD3
// pcb SDRradio 2019
#define SPISDITris 0 // niente qua
#define SPISDOTris TRISGbits.TRISG8 // SDO
#define SPISCKTris TRISGbits.TRISG6 // SCK
#define SPICSTris TRISGbits.TRISG7 // CS
#define LCDDCTris TRISEbits.TRISE7 // DC che su questo LCD è "A0" per motivi ignoti
//#define LCDRSTTris TRISBbits.TRISB7
#define m_SPISCKBit LATGbits.LATG6 // pin
#define m_SPISDOBit LATGbits.LATG8 // pin
#define m_SPISDIBit 0
#define m_SPICSBit LATGbits.LATG7 // pin
#define m_LCDDCBit LATEbits.LATE7 // pin
//#define m_LCDRSTBit LATBbits.LATB7 //FARE
//#define m_LCDBLBit LATBbits.LATB12
#endif
#ifdef ILI9341
#define LED1 LATEbits.LATE4
#define LED2 LATDbits.LATD0
#define LED3 LATDbits.LATD11
#define SW2 PORTFbits.RF0
#define SW1 PORTBbits.RB0 // bah uso AREF tanto per...
#define LCDDCTris TRISBbits.TRISB3 // http://attach01.oss-us-west-1.aliyuncs.com/IC/Datasheet/11009.zip?spm=a2g0o.detail.1000023.9.70352ae94rI9S1&file=11009.zip
#define LCDRSTTris TRISBbits.TRISB10
#define LCDRDTris TRISBbits.TRISB5 //
#define LCDWRTris TRISBbits.TRISB4 // WR per LCD parallelo
#define LCDSTRTris TRISBbits.TRISB4 // Strobe per LCD parallelo A3_TRIS (in pratica Write...)
#define LCDCSTris TRISBbits.TRISB2
#define m_LCDDCBit LATBbits.LATB3 //
#define m_LCDRSTBit LATBbits.LATB10
//#define m_LCDBLBit LATBbits.LATB12
#define m_LCDRDBit LATBbits.LATB5 //
#define m_LCDWRBit LATBbits.LATB4 // per LCD parallelo ILI
#define m_LCDSTRBit LATBbits.LATB4 // non è chiaro... m_A3_out; in pratica è WRITE
#define m_LCDCSBit LATBbits.LATB2
#endif
#endif