]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/z180-serv.c
5 //#include <avr/power.h>
6 //#include <avr/pgmspace.h>
7 //#include <util/atomic.h>
8 //#include <avr/sleep.h>
17 /* ugly hack to get Z180 loadfile into flash memory */
18 #define const const FLASH
19 #include "../z180/hdrom.h"
23 /*--------------------------------------------------------------------------*/
25 uint32_t z80_sram_cmp(uint32_t addr
, uint32_t length
, uint8_t wval
, int inc
)
28 int_fast8_t errors
= 0;
30 DBG_P(1, "SRAM: Check 0x%.5lx byte... ", length
);
32 if ((rval
= z80_read(addr
)) != wval
) {
34 DBG_P(1, "\nSRAM: Address W R\n" \
35 " ------------------\n");
42 DBG_P(1, " 0x%.5lx 0x%.2x 0x%.2x\n", addr
, wval
, rval
);
52 void z80_sram_fill(uint32_t addr
, uint32_t length
, uint8_t startval
, int inc
)
54 printf("SRAM: Write 0x%.5lx byte... ", length
);
56 z80_write(addr
, startval
);
65 void z80_sram_fill_string(uint32_t addr
, int length
, const char *text
)
71 z80_write(addr
++, c
= *p
++);
78 uint32_t z80_sram_cmp_string(uint32_t addr
, int length
, const char *text
)
85 if (z80_read(addr
) != c
)
94 const char * const qbfox
= "Zhe quick brown fox jumps over the lazy dog!";
95 const char * const qbcat
= "Zhe quick brown fox jumps over the lazy cat!";
99 uint8_t z80_get_byte(uint32_t adr
)
104 data
= z80_read(adr
),
111 /*--------------------------------------------------------------------------*/
115 uint8_t sub_min
, sub_max
;
116 void (*func
)(uint8_t, int, uint8_t *);
119 uint32_t msg_to_addr(uint8_t *msg
)
126 addr
.as8
[0] = msg
[0];
127 addr
.as8
[1] = msg
[1];
128 addr
.as8
[2] = msg
[2];
134 void do_msg_ini_msgfifo(uint8_t subf
, int len
, uint8_t * msg
)
136 (void)subf
; (void)len
;
138 z80_init_msg_fifo(msg_to_addr(msg
));
142 void do_msg_ini_memfifo(uint8_t subf
, int len
, uint8_t * msg
)
146 z80_memfifo_init(subf
- 1, msg_to_addr(msg
));
150 void do_msg_char_out(uint8_t subf
, int len
, uint8_t * msg
)
159 const FLASH
struct msg_item z80_messages
[] =
162 0, 0, /* sub fct nr. from, to */
170 { 0xff, /* end mark */
179 void do_message(int len
, uint8_t *msg
)
181 uint8_t fct
, sub_fct
;
189 while (fct
!= z80_messages
[i
].fct
)
192 if (z80_messages
[i
].fct
== 0xff) {
193 DBG_P(1, "do_message: Unknown function: %i, %i\n",
195 return; /* TODO: unknown message # */
198 while (fct
== z80_messages
[i
].fct
) {
199 if (sub_fct
>= z80_messages
[i
].sub_min
&& sub_fct
<= z80_messages
[i
].sub_max
)
204 if (z80_messages
[i
].fct
!= fct
) {
205 DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
207 return; /* TODO: unknown message sub# */
210 (z80_messages
[i
].func
)(sub_fct
, len
, msg
);
215 DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len
);
221 #define CTRBUF_LEN 256
223 void check_msg_fifo(void)
226 static int_fast8_t state
;
227 static int msglen
,idx
;
228 static uint8_t buffer
[CTRBUF_LEN
];
230 while (state
!= 3 && (ch
= z80_msg_fifo_getc()) >= 0) {
232 case 0: /* wait for start of message */
239 case 1: /* get msg len */
240 if (ch
> 0 && ch
<= CTRBUF_LEN
) {
246 case 2: /* get message */
255 do_message(msglen
, buffer
);
261 /*--------------------------------------------------------------------------*/
263 void dump_mem(const FLASH
uint8_t *addr
, uint32_t len
)
265 DBG_P(1, "hdrom dump:");
267 DBG_P(1, "\n %.5x:", addr
);
268 for (unsigned i
= 0; i
<16; i
++)
269 DBG_P(1, " %.2x", *addr
++);
270 len
-= len
> 16 ? 16 : len
;
275 /*--------------------------------------------------------------------------*/
277 void z80_load_mem(void)
280 uint32_t sec_base
= hdrom_start
;
282 DBG_P(1, "Loading z80 memory... \n");
284 while (sec
< hdrom_sections
) {
285 DBG_P(2, " From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n",
287 hdrom_address
[sec
]+hdrom_length_of_sections
[sec
] - 1,
288 hdrom_length_of_sections
[sec
]);
290 z80_write_block((const FLASH
unsigned char *) &hdrom
[sec_base
], /* src */
291 hdrom_address
[sec
], /* dest */
292 hdrom_length_of_sections
[sec
]); /* len */
293 sec_base
+=hdrom_length_of_sections
[sec
];
298 /*--------------------------------------------------------------------------*/
301 const FLASH
uint8_t iniprog
[] = {
303 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
304 0x3E, 0x30, // ld a,030h
305 0xED, 0x39, 0x32 //out0 (dcntl),a ;0 mem, max i/0 wait states
308 const FLASH
uint8_t sertest
[] = {
310 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
311 0x3E, 0x30, // ld a,030h
312 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
313 0x3E, 0x80, // ld a,M_MPBT ;no MP, PS=10, DR=16, SS=0
314 0xED, 0x39, 0x03, // out0 (cntlb1),a
315 0x3E, 0x64, // ld a,M_RE + M_TE + M_MOD2 ;
316 0xED, 0x39, 0x01, // out0 (cntla1),a
317 0x3E, 0x00, // ld a,0
318 0xED, 0x39, 0x05, // out0 (stat1),a ;Enable rx interrupts
319 0xED, 0x38, 0x05, //l0:in0 a,(stat1)
320 0xE6, 0x80, // and 80h
321 0x28, 0xF9, // jr z,l0
322 0xED, 0x00, 0x09, // in0 b,(rdr1)
323 0xED, 0x38, 0x05, //l1:in0 a,(stat1)
324 0xE6, 0x02, // and 02h
325 0x28, 0xF9, // jr z,l1
326 0xED, 0x01, 0x07, // out0 (tdr1),b
330 const FLASH
uint8_t test1
[] = {
332 0xED, 0x39, 0x36, // out0 (rcr),a ;disable DRAM refresh
333 0x3E, 0x30, // ld a,030h
334 0xED, 0x39, 0x32, // out0 (dcntl),a ;0 mem, max i/0 wait states
335 0x21, 0x1E, 0x00, // ld hl,dmclrt ;load DMA registers
336 0x06, 0x08, // ld b,dmct_e-dmclrt
337 0x0E, 0x20, // ld c,sar0l
339 0x3E, 0xC3, // ld a,0c3h ;dst +1, src +1, burst
340 0xED, 0x39, 0x31, // out0 (dmode),a ;
341 0x3E, 0x62, // ld a,062h ;enable dma0,
342 0xED, 0x39, 0x30, //cl_1: out0 (dstat),a ;copy 64k
343 0x18, 0xFB, // jr cl_1 ;
344 0x00, 0x00, //dmclrt: dw 0 ;src (inc)
346 0x00, 0x00, // dw 0 ;dst (inc),
348 0x00, 0x00, // dw 0 ;count (64k)