]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/z180-serv.c
56852cb4e4bb29e484cd63548a345a5b6ce60a52
5 #include <util/atomic.h>
7 #include "background.h"
11 #include "z180-serv.h"
15 /*--------------------------------------------------------------------------*/
18 uint8_t z80_get_byte(uint32_t adr
)
30 /*--------------------------------------------------------------------------*/
34 uint8_t sub_min
, sub_max
;
35 void (*func
)(uint8_t, int, uint8_t *);
38 uint32_t msg_to_addr(uint8_t *msg
)
54 void do_msg_ini_memfifo(uint8_t subf
, int len
, uint8_t * msg
)
58 z80_memfifo_init(subf
, msg_to_addr(msg
));
62 void do_msg_char_out(uint8_t subf
, int len
, uint8_t * msg
)
71 const FLASH
struct msg_item z80_messages
[] =
74 1, 3, /* sub fct nr. from, to */
79 { 0xff, /* end mark */
88 void do_message(int len
, uint8_t *msg
)
98 while (fct
!= z80_messages
[i
].fct
) {
99 if (z80_messages
[i
].fct
== 0xff) {
100 DBG_P(1, "do_message: Unknown function: %i, %i\n",
102 return; /* TODO: unknown message # */
108 while (fct
== z80_messages
[i
].fct
) {
109 if (sub_fct
>= z80_messages
[i
].sub_min
&&
110 sub_fct
<= z80_messages
[i
].sub_max
)
115 if (z80_messages
[i
].fct
!= fct
) {
116 DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
118 return; /* TODO: unknown message sub# */
121 (z80_messages
[i
].func
)(sub_fct
, len
, msg
);
126 DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len
);
132 #define CTRBUF_LEN 256
134 void check_msg_fifo(void)
137 static int_fast8_t state
;
138 static int msglen
,idx
;
139 static uint8_t buffer
[CTRBUF_LEN
];
141 while ((ch
= z80_memfifo_getc(fifo_msgin
)) >= 0) {
143 case 0: /* wait for start of message */
150 case 1: /* get msg len */
151 if (ch
> 0 && ch
<= CTRBUF_LEN
) {
157 case 2: /* get message */
160 do_message(msglen
, buffer
);
169 int msg_handling(int state
)
173 ATOMIC_BLOCK(ATOMIC_RESTORESTATE
) {
174 pending
= (Stat
& S_MSG_PENDING
) != 0;
175 Stat
&= ~S_MSG_PENDING
;
181 z80_bus_cmd(Request
);
182 uint32_t addr
= z80_read(0x40) +
183 ((uint16_t) z80_read(0x41) << 8) +
184 ((uint32_t) z80_read(0x42) << 16);
185 z80_bus_cmd(Release
);
187 z80_memfifo_init(fifo_msgin
, addr
);
201 int console_handling(int state
)
206 ATOMIC_BLOCK(ATOMIC_RESTORESTATE
) {
207 pending
= (Stat
& S_CON_PENDING
) != 0;
208 Stat
&= ~S_CON_PENDING
;
212 while ((ch
= z80_memfifo_getc(fifo_conout
)) >= 0) {
223 static int handle_msg_handling
;
225 void setup_z180_serv(void)
228 handle_msg_handling
= bg_register(msg_handling
, 0);
229 // bg_register(console_handling, 0);
232 void restart_z180_serv(void)
234 z80_bus_cmd(Request
);
238 z80_bus_cmd(Release
);
240 bg_setstat(handle_msg_handling
, 0);
243 /*--------------------------------------------------------------------------*/
246 void dump_mem(const FLASH
uint8_t *addr
, uint32_t len
)
248 DBG_P(1, "hdrom dump:");
250 DBG_P(1, "\n %.5x:", addr
);
251 for (unsigned i
= 0; i
<16; i
++)
252 DBG_P(1, " %.2x", *addr
++);
253 len
-= len
> 16 ? 16 : len
;
258 /*--------------------------------------------------------------------------*/
261 const FLASH
uint8_t iniprog
[] = {
263 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
264 0x3E, 0x30, // ld a,030h
265 0xED, 0x39, 0x32 //out0 (dcntl),a ;0 mem, max i/0 wait states
268 const FLASH
uint8_t sertest
[] = {
270 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
271 0x3E, 0x30, // ld a,030h
272 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
273 0x3E, 0x80, // ld a,M_MPBT ;no MP, PS=10, DR=16, SS=0
274 0xED, 0x39, 0x03, // out0 (cntlb1),a
275 0x3E, 0x64, // ld a,M_RE + M_TE + M_MOD2 ;
276 0xED, 0x39, 0x01, // out0 (cntla1),a
277 0x3E, 0x00, // ld a,0
278 0xED, 0x39, 0x05, // out0 (stat1),a ;Enable rx interrupts
279 0xED, 0x38, 0x05, //l0:in0 a,(stat1)
280 0xE6, 0x80, // and 80h
281 0x28, 0xF9, // jr z,l0
282 0xED, 0x00, 0x09, // in0 b,(rdr1)
283 0xED, 0x38, 0x05, //l1:in0 a,(stat1)
284 0xE6, 0x02, // and 02h
285 0x28, 0xF9, // jr z,l1
286 0xED, 0x01, 0x07, // out0 (tdr1),b
290 const FLASH
uint8_t test1
[] = {
292 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
293 0x3E, 0x30, // ld a,030h
294 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
295 0x21, 0x1E, 0x00, // ld hl,dmclrt ;load DMA registers
296 0x06, 0x08, // ld b,dmct_e-dmclrt
297 0x0E, 0x20, // ld c,sar0l
299 0x3E, 0xC3, // ld a,0c3h ;dst +1, src +1, burst
300 0xED, 0x39, 0x31, // out0 (dmode),a ;
301 0x3E, 0x62, // ld a,062h ;enable dma0,
302 0xED, 0x39, 0x30, //cl_1: out0 (dstat),a ;copy 64k
303 0x18, 0xFB, // jr cl_1 ;
304 0x00, 0x00, //dmclrt: dw 0 ;src (inc)
306 0x00, 0x00, // dw 0 ;dst (inc),
308 0x00, 0x00, // dw 0 ;count (64k)