2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 #define MOV_direct_data 0x75
23 #define MOV_Rn_data(n) (0x78 | (n))
24 #define DJNZ_Rn_rel(n) (0xd8 | (n))
27 static uint8_t instructions[] = {
28 3, MOV_direct_data, 0xfe, 0x02,
29 3, MOV_direct_data, 0x90, 0xff,
34 static uint8_t mem_instr[] = {
35 MOV_direct_data, 0xfe, 0x02,
36 MOV_direct_data, 0x90, 0xff,
43 MOV_direct_data, 0x90, 0xfd,
53 static uint8_t jump_mem[] = {
59 main (int argc, char **argv)
69 dbg = ccdbg_open("/dev/ttyUSB0");
73 ccdbg_manual(dbg, stdin);
75 hex = ccdbg_hex_file_read(stdin, "<stdin>");
79 ccdbg_debug_mode(dbg);
80 status = ccdbg_read_status(dbg);
81 printf("Status: 0x%02x\n", status);
82 chip_id = ccdbg_get_chip_id(dbg);
83 printf("Chip id: 0x%04x\n", chip_id);
84 status = ccdbg_halt(dbg);
85 printf ("halt status: 0x%02x\n", status);
87 ccdbg_write_hex(dbg, hex);
88 ccdbg_hex_file_free(hex);
89 for (i = 0; i < sizeof (memory); i++)
90 printf (" %02x", memory[i]);
92 ccdbg_execute(dbg, jump_mem);
93 pc = ccdbg_get_pc(dbg);
94 printf ("pc starts at 0x%04x\n", pc);
95 status = ccdbg_resume(dbg);
96 printf ("resume status: 0x%02x\n", status);
98 /* ccdbg_execute(dbg, instructions); */
99 ccdbg_write_memory(dbg, 0xf000, mem_instr, sizeof (mem_instr));
100 ccdbg_read_memory(dbg, 0xf000, memory, sizeof (memory));