]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/z180-serv.c
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <util/atomic.h>
10 #include "background.h"
14 #include "z180-serv.h"
16 /*--------------------------------------------------------------------------*/
19 uint8_t z80_get_byte(uint32_t adr
)
31 /*--------------------------------------------------------------------------*/
35 uint8_t sub_min
, sub_max
;
36 void (*func
)(uint8_t, int, uint8_t *);
39 uint32_t msg_to_addr(uint8_t *msg
)
55 void do_msg_ini_memfifo(uint8_t subf
, int len
, uint8_t * msg
)
59 z80_memfifo_init(subf
, msg_to_addr(msg
));
63 void do_msg_char_out(uint8_t subf
, int len
, uint8_t * msg
)
72 const FLASH
struct msg_item z80_messages
[] =
75 1, 3, /* sub fct nr. from, to */
80 { 0xff, /* end mark */
89 void do_message(int len
, uint8_t *msg
)
99 while (fct
!= z80_messages
[i
].fct
) {
100 if (z80_messages
[i
].fct
== 0xff) {
101 DBG_P(1, "do_message: Unknown function: %i, %i\n",
103 return; /* TODO: unknown message # */
109 while (fct
== z80_messages
[i
].fct
) {
110 if (sub_fct
>= z80_messages
[i
].sub_min
&&
111 sub_fct
<= z80_messages
[i
].sub_max
)
116 if (z80_messages
[i
].fct
!= fct
) {
117 DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
119 return; /* TODO: unknown message sub# */
122 (z80_messages
[i
].func
)(sub_fct
, len
, msg
);
127 DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len
);
133 #define CTRBUF_LEN 256
135 void check_msg_fifo(void)
138 static int_fast8_t state
;
139 static int msglen
,idx
;
140 static uint8_t buffer
[CTRBUF_LEN
];
142 while ((ch
= z80_memfifo_getc(fifo_msgin
)) >= 0) {
144 case 0: /* wait for start of message */
145 if (ch
== 0xAE) { /* TODO: magic number */
151 case 1: /* get msg len */
152 if (ch
> 0 && ch
<= CTRBUF_LEN
) {
158 case 2: /* get message */
161 do_message(msglen
, buffer
);
170 int msg_handling(int state
)
174 ATOMIC_BLOCK(ATOMIC_FORCEON
) {
175 pending
= (Stat
& S_MSG_PENDING
) != 0;
176 Stat
&= ~S_MSG_PENDING
;
182 z80_bus_cmd(Request
);
183 uint32_t addr
= z80_read(0x40) +
184 ((uint16_t) z80_read(0x41) << 8) +
185 ((uint32_t) z80_read(0x42) << 16);
186 z80_bus_cmd(Release
);
188 z80_memfifo_init(fifo_msgin
, addr
);
202 static int handle_msg_handling
;
204 void setup_z180_serv(void)
207 handle_msg_handling
= bg_register(msg_handling
, 0);
210 void restart_z180_serv(void)
212 z80_bus_cmd(Request
);
216 z80_bus_cmd(Release
);
218 for (int i
= 0; i
< NUM_FIFOS
; i
++)
219 z80_memfifo_init(i
, 0);
220 bg_setstat(handle_msg_handling
, 0);
223 /*--------------------------------------------------------------------------*/
225 const FLASH
uint8_t iniprog
[] = {
227 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
228 0x3E, 0x30, // ld a,030h
229 0xED, 0x39, 0x32 //out0 (dcntl),a ;0 mem, max i/0 wait states
232 const FLASH
uint8_t sertest
[] = {
234 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
235 0x3E, 0x30, // ld a,030h
236 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
237 0x3E, 0x80, // ld a,M_MPBT ;no MP, PS=10, DR=16, SS=0
238 0xED, 0x39, 0x03, // out0 (cntlb1),a
239 0x3E, 0x64, // ld a,M_RE + M_TE + M_MOD2 ;
240 0xED, 0x39, 0x01, // out0 (cntla1),a
241 0x3E, 0x00, // ld a,0
242 0xED, 0x39, 0x05, // out0 (stat1),a ;Enable rx interrupts
243 0xED, 0x38, 0x05, //l0:in0 a,(stat1)
244 0xE6, 0x80, // and 80h
245 0x28, 0xF9, // jr z,l0
246 0xED, 0x00, 0x09, // in0 b,(rdr1)
247 0xED, 0x38, 0x05, //l1:in0 a,(stat1)
248 0xE6, 0x02, // and 02h
249 0x28, 0xF9, // jr z,l1
250 0xED, 0x01, 0x07, // out0 (tdr1),b
254 const FLASH
uint8_t test1
[] = {
256 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
257 0x3E, 0x30, // ld a,030h
258 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
259 0x21, 0x1E, 0x00, // ld hl,dmclrt ;load DMA registers
260 0x06, 0x08, // ld b,dmct_e-dmclrt
261 0x0E, 0x20, // ld c,sar0l
263 0x3E, 0xC3, // ld a,0c3h ;dst +1, src +1, burst
264 0xED, 0x39, 0x31, // out0 (dmode),a ;
265 0x3E, 0x62, // ld a,062h ;enable dma0,
266 0xED, 0x39, 0x30, //cl_1: out0 (dstat),a ;copy 64k
267 0x18, 0xFB, // jr cl_1 ;
268 0x00, 0x00, //dmclrt: dw 0 ;src (inc)
270 0x00, 0x00, // dw 0 ;dst (inc),
272 0x00, 0x00, // dw 0 ;count (64k)