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)
68 dbg = ccdbg_open("/dev/ttyUSB0");
72 ccdbg_manual(dbg, stdin);
76 ccdbg_debug_mode(dbg);
77 status = ccdbg_read_status(dbg);
78 printf("Status: 0x%02x\n", status);
79 chip_id = ccdbg_get_chip_id(dbg);
80 printf("Chip id: 0x%04x\n", chip_id);
81 status = ccdbg_halt(dbg);
82 printf ("halt status: 0x%02x\n", status);
83 /* ccdbg_execute(dbg, instructions); */
84 ccdbg_write_memory(dbg, 0xf000, mem_instr, sizeof (mem_instr));
85 ccdbg_read_memory(dbg, 0xf000, memory, sizeof (memory));
86 for (i = 0; i < sizeof (memory); i++)
87 printf (" %02x", memory[i]);
89 ccdbg_execute(dbg, jump_mem);
90 pc = ccdbg_get_pc(dbg);
91 printf ("pc starts at 0x%04x\n", pc);
92 status = ccdbg_resume(dbg);
93 printf ("resume status: 0x%02x\n", status);