]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/z180-stamp-avr.c
6 //#include <avr/power.h>
7 //#include <avr/pgmspace.h>
8 //#include <avr/interrupt.h>
9 //#include <util/atomic.h>
10 //#include <avr/sleep.h>
20 #define const const __flash
21 #include "../z180/hdrom.h"
26 #define ESCCHAR ('^'-0x40)
28 #define S_10MS_TO (1<<0)
31 static volatile int_fast8_t timeout_1s
;
32 static volatile uint_least8_t Stat
;
35 /*--------------------------------------------------------------------------*/
38 void sys_tick_handler(void)
40 static int_fast8_t tick_10ms
= 0;
41 static int_fast16_t count_ms
= 0;
50 /* Drive timer procedure of low level disk I/O module */
55 if (count_ms
== 1000) {
65 static void do_10ms(void)
69 /*--------------------------------------------------------------------------*/
71 static uint32_t z80_sram_cmp(uint32_t addr
, uint32_t length
, uint8_t wval
, int inc
)
74 int_fast8_t errors
= 0;
76 DBG_P(1, "SRAM: Check 0x%.5lX byte... ", length
);
78 if ((rval
= z80_read(addr
)) != wval
) {
80 printf("\nSRAM: Address W R\n" \
84 printf(" %.5lx %.2x %.2x\n", addr
, wval
, rval
);
98 static void z80_sram_fill(uint32_t addr
, int length
, uint8_t startval
, int inc
)
100 printf("SRAM: Write %#.5x byte... ", length
); //fflush(stdout);
102 z80_write(addr
, startval
);
110 void z80_sram_fill_string(uint32_t addr
, int length
, const char *text
)
113 const char *p
= text
;
116 z80_write(addr
++, c
= *p
++);
123 uint32_t z80_sram_cmp_string(uint32_t addr
, int length
, const char *text
)
126 const char *p
= text
;
130 if (z80_read(addr
) != c
)
139 const char * const qbfox
= "Zhe quick brown fox jumps over the lazy dog!";
140 const char * const qbcat
= "Zhe quick brown fox jumps over the lazy cat!";
144 /*--------------------------------------------------------------------------*/
146 uint8_t z80_get_byte(uint32_t adr
)
151 data
= z80_read(adr
),
157 /*--------------------------------------------------------------------------*/
161 uint8_t sub_min
, sub_max
;
162 void (*func
)(uint8_t, int, uint8_t *);
166 uint32_t msg_to_addr(uint8_t *msg
)
173 addr
.as8
[0] = msg
[0];
174 addr
.as8
[1] = msg
[1];
175 addr
.as8
[2] = msg
[2];
182 void do_msg_ini_msgfifo(uint8_t subf
, int len
, uint8_t * msg
)
184 (void)subf
; (void)len
;
186 z80_init_msg_fifo(msg_to_addr(msg
));
191 void do_msg_ini_memfifo(uint8_t subf
, int len
, uint8_t * msg
)
195 z80_memfifo_init(subf
- 1, msg_to_addr(msg
));
200 void do_msg_char_out(uint8_t subf
, int len
, uint8_t * msg
)
210 const FLASH
struct msg_item z80_messages
[] =
213 0, 0, /* sub fct nr. from, to */
214 &do_msg_ini_msgfifo
},
217 &do_msg_ini_memfifo
},
221 { 0xff, /* end mark */
229 void do_message(int len
, uint8_t *msg
)
231 uint8_t fct
, sub_fct
;
239 while (fct
!= z80_messages
[i
].fct
)
242 if (z80_messages
[i
].fct
== 0xff) {
243 DBG_P(1, "do_message: Unknown function: %i, %i\n",
245 return; /* TODO: unknown message # */
248 while (fct
== z80_messages
[i
].fct
) {
249 if (sub_fct
>= z80_messages
[i
].sub_min
&& sub_fct
<= z80_messages
[i
].sub_max
)
254 if (z80_messages
[i
].fct
!= fct
) {
255 DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
257 return; /* TODO: unknown message sub# */
260 (z80_messages
[i
].func
)(sub_fct
, len
, msg
);
265 DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len
);
271 #define CTRBUF_LEN 256
274 void check_msg_fifo(void)
277 static int_fast8_t state
;
278 static int msglen
,idx
;
279 static uint8_t buffer
[CTRBUF_LEN
];
281 while (state
!= 3 && (ch
= z80_msg_fifo_getc()) >= 0) {
283 case 0: /* wait for start of message */
290 case 1: /* get msg len */
291 if (ch
> 0 && ch
<= CTRBUF_LEN
) {
297 case 2: /* get message */
306 do_message(msglen
, buffer
);
313 void z80_load_mem(void)
316 uint32_t sec_base
= hdrom_start
;
318 DBG_P(1, "Loading z80 memory... \n");
320 while (sec
< hdrom_sections
) {
321 DBG_P(2, " From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n",
323 hdrom_address
[sec
]+hdrom_length_of_sections
[sec
] - 1,
324 hdrom_length_of_sections
[sec
]);
326 z80_write_block((unsigned char *) &hdrom
[sec_base
], /* src */
327 hdrom_address
[sec
], /* dest */
328 hdrom_length_of_sections
[sec
]); /* len */
329 sec_base
+=hdrom_length_of_sections
[sec
];
334 /*--------------------------------------------------------------------------*/
338 int_fast8_t state
= 0;
341 // setvbuf(stdout, NULL, _IONBF, 0);
343 printf("\n(ATMEGA1281+HD64180)_stamp Tester\n");
345 DBG_P(1, "z80_setup_bus... ");
346 z80_setup_msg_fifo();
350 DBG_P(1, "Get bus... ");
354 DBG_P(1, "got it!\n");
356 z80_memset(0, 0x76, 0x80000);
357 //z80_sram_fill(0, 512 * 1024, 0x76, 0);
358 z80_sram_cmp(0, (uint32_t)512 * 1024, 0x76, 0);
362 DBG_P(1, "Bus released!\n");
365 DBG_P(1, "Reset released!\n");
370 if (Stat
& S_10MS_TO
) {
376 if ((ch
= serial_getc()) >= 0) {
381 /* TODO: Timer starten */
383 z80_memfifo_putc(fifo_out
, ch
);
394 z80_memfifo_putc(fifo_out
, ch
);