minipro-query-db.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <strings.h>
  5. #include <unistd.h>
  6. #include "minipro.h"
  7. #include "byte_utils.h"
  8. #include "database.h"
  9. #include "error.h"
  10. void print_help_and_exit(const char *progname) {
  11. fprintf(stderr, "Usage: %s [-s search] [<device>]\n", progname);
  12. exit(-1);
  13. }
  14. void print_device_info(device_t *device) {
  15. printf("Name: %s\n", device->name);
  16. /* Memory shape */
  17. printf("Memory: %d", device->code_memory_size / WORD_SIZE(device));
  18. switch(device->opts4 & 0xFF000000) {
  19. case 0x00000000:
  20. printf(" Bytes");
  21. break;
  22. case 0x01000000:
  23. printf(" Words");
  24. break;
  25. case 0x02000000:
  26. printf(" Bits");
  27. break;
  28. default:
  29. ERROR2("Unknown memory shape: 0x%x\n", device->opts4 & 0xFF000000);
  30. }
  31. if(device->data_memory_size) {
  32. printf(" + %d Bytes", device->data_memory_size);
  33. }
  34. if(device->data_memory2_size) {
  35. printf(" + %d Bytes", device->data_memory2_size);
  36. }
  37. printf("\n");
  38. unsigned char package_details[4];
  39. format_int(package_details, device->package_details, 4, MP_LITTLE_ENDIAN);
  40. /* Package info */
  41. printf("Package: ");
  42. if(package_details[0]) {
  43. printf("Adapter%03d.JPG\n", package_details[0]);
  44. } else if(package_details[3]) {
  45. printf("DIP%d\n", package_details[3] & 0x7F);
  46. } else {
  47. printf("ISP only\n");
  48. }
  49. /* ISP connection info */
  50. printf("ISP: ");
  51. if(package_details[1]) {
  52. printf("ICP%03d.JPG\n", package_details[1]);
  53. } else {
  54. printf("-\n");
  55. }
  56. printf("Protocol: 0x%02x\n", device->protocol_id);
  57. printf("Read buffer size: %d Bytes\n", device->read_buffer_size);
  58. printf("Write buffer size: %d Bytes\n", device->write_buffer_size);
  59. }
  60. int main(int argc, char **argv) {
  61. if(argc < 2) {
  62. print_help_and_exit(argv[0]);
  63. }
  64. if(!strcmp(argv[1], "-s")) {
  65. if(argc < 3) {
  66. print_help_and_exit(argv[0]);
  67. }
  68. // Listing all devices that starts with argv[2]
  69. device_t *device;
  70. for(device = &(devices[0]); device[0].name; device = &(device[1])) {
  71. if(!strncasecmp(device[0].name, argv[2], strlen(argv[2]))) {
  72. printf("%s\n", device[0].name);
  73. }
  74. }
  75. return(0);
  76. }
  77. device_t *device = get_device_by_name(argv[1]);
  78. if(!device) {
  79. ERROR("Unknown device");
  80. }
  81. print_device_info(device);
  82. return(0);
  83. }