]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/z180-serv.c
c9203263ff7c67b56e7bd30e465fb63d673224dd
5 //#include <avr/power.h>
6 //#include <avr/pgmspace.h>
7 //#include <util/atomic.h>
8 //#include <avr/sleep.h>
18 /*--------------------------------------------------------------------------*/
21 uint8_t z80_get_byte(uint32_t adr
)
33 /*--------------------------------------------------------------------------*/
37 uint8_t sub_min
, sub_max
;
38 void (*func
)(uint8_t, int, uint8_t *);
41 uint32_t msg_to_addr(uint8_t *msg
)
56 void do_msg_ini_msgfifo(uint8_t subf
, int len
, uint8_t * msg
)
58 (void)subf
; (void)len
;
60 z80_init_msg_fifo(msg_to_addr(msg
));
64 void do_msg_ini_memfifo(uint8_t subf
, int len
, uint8_t * msg
)
68 z80_memfifo_init(subf
- 1, msg_to_addr(msg
));
72 void do_msg_char_out(uint8_t subf
, int len
, uint8_t * msg
)
81 const FLASH
struct msg_item z80_messages
[] =
84 0, 0, /* sub fct nr. from, to */
92 { 0xff, /* end mark */
101 void do_message(int len
, uint8_t *msg
)
103 uint8_t fct
, sub_fct
;
111 while (fct
!= z80_messages
[i
].fct
)
114 if (z80_messages
[i
].fct
== 0xff) {
115 DBG_P(1, "do_message: Unknown function: %i, %i\n",
117 return; /* TODO: unknown message # */
120 while (fct
== z80_messages
[i
].fct
) {
121 if (sub_fct
>= z80_messages
[i
].sub_min
&& sub_fct
<= z80_messages
[i
].sub_max
)
126 if (z80_messages
[i
].fct
!= fct
) {
127 DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
129 return; /* TODO: unknown message sub# */
132 (z80_messages
[i
].func
)(sub_fct
, len
, msg
);
137 DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len
);
143 #define CTRBUF_LEN 256
145 void check_msg_fifo(void)
148 static int_fast8_t state
;
149 static int msglen
,idx
;
150 static uint8_t buffer
[CTRBUF_LEN
];
152 while (state
!= 3 && (ch
= z80_msg_fifo_getc()) >= 0) {
154 case 0: /* wait for start of message */
161 case 1: /* get msg len */
162 if (ch
> 0 && ch
<= CTRBUF_LEN
) {
168 case 2: /* get message */
177 do_message(msglen
, buffer
);
183 /*--------------------------------------------------------------------------*/
186 void dump_mem(const FLASH
uint8_t *addr
, uint32_t len
)
188 DBG_P(1, "hdrom dump:");
190 DBG_P(1, "\n %.5x:", addr
);
191 for (unsigned i
= 0; i
<16; i
++)
192 DBG_P(1, " %.2x", *addr
++);
193 len
-= len
> 16 ? 16 : len
;
198 /*--------------------------------------------------------------------------*/
201 const FLASH
uint8_t iniprog
[] = {
203 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
204 0x3E, 0x30, // ld a,030h
205 0xED, 0x39, 0x32 //out0 (dcntl),a ;0 mem, max i/0 wait states
208 const FLASH
uint8_t sertest
[] = {
210 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
211 0x3E, 0x30, // ld a,030h
212 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
213 0x3E, 0x80, // ld a,M_MPBT ;no MP, PS=10, DR=16, SS=0
214 0xED, 0x39, 0x03, // out0 (cntlb1),a
215 0x3E, 0x64, // ld a,M_RE + M_TE + M_MOD2 ;
216 0xED, 0x39, 0x01, // out0 (cntla1),a
217 0x3E, 0x00, // ld a,0
218 0xED, 0x39, 0x05, // out0 (stat1),a ;Enable rx interrupts
219 0xED, 0x38, 0x05, //l0:in0 a,(stat1)
220 0xE6, 0x80, // and 80h
221 0x28, 0xF9, // jr z,l0
222 0xED, 0x00, 0x09, // in0 b,(rdr1)
223 0xED, 0x38, 0x05, //l1:in0 a,(stat1)
224 0xE6, 0x02, // and 02h
225 0x28, 0xF9, // jr z,l1
226 0xED, 0x01, 0x07, // out0 (tdr1),b
230 const FLASH
uint8_t test1
[] = {
232 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
233 0x3E, 0x30, // ld a,030h
234 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
235 0x21, 0x1E, 0x00, // ld hl,dmclrt ;load DMA registers
236 0x06, 0x08, // ld b,dmct_e-dmclrt
237 0x0E, 0x20, // ld c,sar0l
239 0x3E, 0xC3, // ld a,0c3h ;dst +1, src +1, burst
240 0xED, 0x39, 0x31, // out0 (dmode),a ;
241 0x3E, 0x62, // ld a,062h ;enable dma0,
242 0xED, 0x39, 0x30, //cl_1: out0 (dstat),a ;copy 64k
243 0x18, 0xFB, // jr cl_1 ;
244 0x00, 0x00, //dmclrt: dw 0 ;src (inc)
246 0x00, 0x00, // dw 0 ;dst (inc),
248 0x00, 0x00, // dw 0 ;count (64k)