ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
raze.h
Go to the documentation of this file.
1 /*
2  * RAZE-x86 Z80 emulator.
3  *
4  * Copyright (c) 1999 Richard Mitton
5  *
6  * This may only be distributed as part of the complete RAZE package.
7  * See RAZE.TXT for license information.
8  */
9 
10 #ifndef __RAZE_H_INCLUDED__
11 #define __RAZE_H_INCLUDED__
12 
13 #include "types.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 
20  /* Memory map constants */
21  #define Z80_MAP_DIRECT 0 /* Reads/writes are done directly */
22  #define Z80_MAP_HANDLED 1 /* Reads/writes use a function handler */
23 
24  /* Z80 registers */
25  typedef enum {
38  Z80_REG_IFF1, /* boolean - 1 or 0 */
39  Z80_REG_IFF2, /* boolean - 1 or 0 */
41  Z80_REG_IM, /* 0, 1, or 2 */
42  Z80_REG_IRQVector, /* 0x00 to 0xff */
43  Z80_REG_IRQLine, /* boolean - 1 or 0 */
44  Z80_REG_Halted /* boolean - 1 or 0 */
45  } z80_register;
46 
47  /* Z80 main functions */
48  void z80_reset(void);
49  int z80_emulate(int cycles);
50  void z80_raise_IRQ(tUBYTE vector);
51  void z80_lower_IRQ(void);
52  void z80_cause_NMI(void);
53 
54  /* Z80 context functions */
55  int z80_get_context_size(void);
56  void z80_set_context(void *context);
57  void z80_get_context(void *context);
58  tUWORD z80_get_reg(z80_register reg);
59  void z80_set_reg(z80_register reg, tUWORD value);
60 
61  /* Z80 cycle functions */
62  int z80_get_cycles_elapsed(void);
63  void z80_stop_emulating(void);
64  void z80_skip_idle(void);
65  void z80_do_wait_states(int n);
66 
67  /* Z80 I/O functions */
68  void z80_init_memmap(void);
69  void z80_map_fetch(tUWORD start, tUWORD end, tUBYTE *memory);
70  void z80_map_read(tUWORD start, tUWORD end, tUBYTE *memory);
71  void z80_map_write(tUWORD start, tUWORD end, tUBYTE *memory);
72  void z80_add_read(tUWORD start, tUWORD end, int method, void *data);
73  void z80_add_write(tUWORD start, tUWORD end, int method, void *data);
74  void z80_set_in(tUBYTE (*handler)(tUWORD port));
75  void z80_set_out(void (*handler)(tUWORD port, tUBYTE value));
76  void z80_set_reti(void (*handler)(void));
77  void z80_set_av(void (*handler)(void));
78  void z80_set_fetch_callback(void (*handler)(tUWORD pc));
79  void z80_end_memmap(void);
80 
81 #ifdef __cplusplus
82 };
83 #endif
84 
85 class Raze
86 {
87 
88 public:
90  ~Raze() {}
91 
92  typedef tUBYTE (*Z80_IN_Handler) (tREGPAIR port);
93  typedef void (*Z80_OUT_Handler)(tREGPAIR port, tUBYTE value);
94 
95  void setInHandler (Z80_IN_Handler handler) {}
96  void setOutHandler(Z80_OUT_Handler handler) {}
97 
99 
102 
103  void setMembank_read (tUBYTE bank, tUBYTE* ptr)
104  {
105  if (bank==0) {z80_map_read(0x0000, 0x3fff, ptr); z80_map_fetch(0x0000, 0x3fff, ptr); return;}
106  if (bank==1) {z80_map_read(0x4000, 0x7fff, ptr); z80_map_fetch(0x4000, 0x7fff, ptr); return;}
107  if (bank==2) {z80_map_read(0x8000, 0xbfff, ptr); z80_map_fetch(0x8000, 0xbfff, ptr); return;}
108  if (bank==3) {z80_map_read(0xc000, 0xffff, ptr); z80_map_fetch(0xc000, 0xffff, ptr); return;}
109  }
110  void setMembank_write(tUBYTE bank, tUBYTE* ptr)
111  {
112  if (bank==0) {z80_map_write(0x0000, 0x3fff, ptr); return;}
113  if (bank==1) {z80_map_write(0x4000, 0x7fff, ptr); return;}
114  if (bank==2) {z80_map_write(0x8000, 0xbfff, ptr); return;}
115  if (bank==3) {z80_map_write(0xc000, 0xffff, ptr); return;}
116  }
117 
119  void setIntPending(tUBYTE ip) {/*mIntPending=ip;*/if (ip) {z80_raise_IRQ(0xff); z80_lower_IRQ();}}
121 
122  void setInHandler (tUBYTE (*handler)(tUWORD port)) {z80_set_in(handler);}
123  void setOutHandler(void (*handler)(tUWORD port, tUBYTE value)) {z80_set_out(handler);}
124  void setWsHandler (void (*handler)(void)) {z80_set_av(handler);}
125 
126  int execute(int i) {mLastCyclecount=0; mCycleCountInit=i; return z80_emulate(i);}
128 
129 private:
130  //Z80_IN_Handler IN_handler;
131  //Z80_OUT_Handler OUT_handler;
132 
133  //tUBYTE z80_in_handler(tREGPAIR port)
134  //void z80_out_handler(tREGPAIR port, tUBYTE value)
138 
139 };
140 
141 
142 #endif /* __RAZE_H_INCLUDED__ */
143 
GLuint GLfloat GLenum cap GLsizei n
Definition: glfunclist.h:13
Definition: raze.h:36
void z80_set_reti(void(*handler)(void))
void initMemMap()
Definition: raze.h:100
Definition: raze.h:29
void z80_raise_IRQ(tUBYTE vector)
Definition: raze.h:38
void z80_cause_NMI(void)
void(* Z80_OUT_Handler)(tREGPAIR port, tUBYTE value)
Definition: raze.h:93
int cyclecount()
Definition: raze.h:118
int mLastCyclecount
Definition: raze.h:135
Definition: raze.h:30
void z80_add_write(tUWORD start, tUWORD end, int method, void *data)
tUBYTE intPending()
Definition: raze.h:120
void z80_set_in(tUBYTE(*handler)(tUWORD port))
Definition: raze.h:39
void z80_reset(void)
tUBYTE mIntPending
Definition: raze.h:137
void z80_set_av(void(*handler)(void))
void init()
Definition: raze.h:98
void z80_end_memmap(void)
void stop()
Definition: raze.h:127
void z80_set_out(void(*handler)(tUWORD port, tUBYTE value))
Definition: raze.h:35
tUWORD z80_get_reg(z80_register reg)
Definition: raze.h:40
void z80_skip_idle(void)
void z80_map_read(tUWORD start, tUWORD end, tUBYTE *memory)
void setInHandler(Z80_IN_Handler handler)
Definition: raze.h:95
Get byte from port
Definition: 8255.txt:134
void z80_set_reg(z80_register reg, tUWORD value)
int z80_emulate(int cycles)
void z80_set_context(void *context)
void z80_set_fetch_callback(void(*handler)(tUWORD pc))
void z80_lower_IRQ(void)
Definition: raze.h:26
tUBYTE(* Z80_IN_Handler)(tREGPAIR port)
Definition: raze.h:92
void setIntPending(tUBYTE ip)
Definition: raze.h:119
void setMembank_read(tUBYTE bank, tUBYTE *ptr)
Definition: raze.h:103
void setInHandler(tUBYTE(*handler)(tUWORD port))
Definition: raze.h:122
Definition: raze.h:43
Definition: raze.h:37
Definition: raze.h:41
int mCycleCountInit
Definition: raze.h:136
void z80_add_read(tUWORD start, tUWORD end, int method, void *data)
Raze()
Definition: raze.h:89
Definition: raze.h:31
int z80_get_context_size(void)
void z80_get_context(void *context)
Definition: raze.h:27
Definition: raze.h:85
Definition: raze.h:42
int execute(int i)
Definition: raze.h:126
~Raze()
Definition: raze.h:90
void z80_map_fetch(tUWORD start, tUWORD end, tUBYTE *memory)
z80_register
Definition: raze.h:25
Definition: raze.h:34
void endMemMap()
Definition: raze.h:101
int z80_get_cycles_elapsed(void)
uint8_t tUBYTE
Definition: types.h:74
void setMembank_write(tUBYTE bank, tUBYTE *ptr)
Definition: raze.h:110
void z80_init_memmap(void)
void z80_do_wait_states(int n)
void setOutHandler(Z80_OUT_Handler handler)
Definition: raze.h:96
Definition: raze.h:33
uint16_t tUWORD
Definition: types.h:80
void setWsHandler(void(*handler)(void))
Definition: raze.h:124
Definition: raze.h:28
Definition: raze.h:44
void z80_stop_emulating(void)
void setOutHandler(void(*handler)(tUWORD port, tUBYTE value))
Definition: raze.h:123
Definition: raze.h:32
void z80_map_write(tUWORD start, tUWORD end, tUBYTE *memory)