hwpm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Hey EMACS -*- linux-c -*- */
  2. /* $Id: hwpm.c 2385 2007-03-12 21:04:20Z roms $ */
  3. /* TiEmu - Tiemu Is an EMUlator
  4. *
  5. * Copyright (c) 2000-2001, Thomas Corvazier, Romain Lievin
  6. * Copyright (c) 2001-2003, Romain Lievin
  7. * Copyright (c) 2003, Julien Blache
  8. * Copyright (c) 2004, Romain Liévin
  9. * Copyright (c) 2005, Romain Liévin
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. /*
  26. This module manages Hardware Parameter Block. This is a 'C' structure like this:
  27. typedef struct {
  28. unsigned short len; // length of parameter block
  29. unsigned long hardwareID; // 1 = TI-92 Plus, 3 = TI-89
  30. unsigned long hardwareRevision; // hardware revision number
  31. unsigned long bootMajor; // boot code version number
  32. unsigned long bootRevision; // boot code revision number
  33. unsigned long bootBuild; // boot code build number
  34. unsigned long gateArray; // gate array version number
  35. unsigned long physDisplayBitsWide; // display width
  36. unsigned long physDisplayBitsTall; // display height
  37. unsigned long LCDBitsWide; // visible display width
  38. unsigned long LCDBitsTall; // visible display height
  39. } HARDWARE_PARM_BLOCK;
  40. */
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h> //memset
  44. #include "hwpm.h"
  45. #include "timem.h"
  46. #define _(x) (x)
  47. #define tiemu_info(x...) (fprintf(stderr, x),fprintf(stderr, "\n"))
  48. /* -- */
  49. /*
  50. Read hardware parameter block from image.
  51. */
  52. int ti68k_get_hw_param_block(uint8_t *rom_data, uint8_t rom_base, HW_PARM_BLOCK *s)
  53. {
  54. int i = 0;
  55. uint32_t addr;
  56. addr = rd_long(&rom_data[0x104]);
  57. addr &= 0x000fffff;
  58. memset(s, 0, sizeof(HW_PARM_BLOCK));
  59. s->len = rd_word(&(rom_data[addr+0]));
  60. if(s->len > 2+(4*i++))
  61. s->hardwareID = rd_long(&(rom_data[addr+2]));
  62. if(s->len > 2+(4*i++))
  63. s->hardwareRevision = rd_long(&(rom_data[addr+6]));
  64. if(s->len > 2+(4*i++))
  65. s->bootMajor = rd_long(&(rom_data[addr+10]));
  66. if(s->len > 2+(4*i++))
  67. s->bootRevision = rd_long(&(rom_data[addr+14]));
  68. if(s->len > 2+(4*i++))
  69. s->bootBuild = rd_long(&(rom_data[addr+18]));
  70. if(s->len > 2+(4*i++))
  71. s->gateArray = rd_long(&(rom_data[addr+22]));
  72. if(s->len > 2+(4*i++))
  73. s->physDisplayBitsWide = rd_long(&(rom_data[addr+26]));
  74. if(s->len > 2+(4*i++))
  75. s->physDisplayBitsTall = rd_long(&(rom_data[addr+30]));
  76. if(s->len > 2+(4*i++))
  77. s->LCDBitsWide = rd_long(&(rom_data[addr+34]));
  78. if(s->len > 2+(4*i++))
  79. s->LCDBitsTall = rd_long(&(rom_data[addr+38]));
  80. if((s->hardwareID == HWID_V200) && (rom_base == 0x40))
  81. {
  82. tiemu_info(_("/* Detected V200 patched ROM (ExtendeD): emulated as TI92+ by changing the hwID from 8 to 1. */"));
  83. s->hardwareID = HWID_TI92P;
  84. }
  85. if((s->hardwareID == HWID_TI89T) && (rom_base == 0x20))
  86. {
  87. tiemu_info(_("/* Detected TI89 Titanium patched ROM (ExtendeD): emulated as TI89 by changing the hwID from 9 to 3. */"));
  88. s->hardwareID = HWID_TI89;
  89. }
  90. return 0;
  91. }
  92. /*
  93. Write hardware parameter block into image.
  94. */
  95. int ti68k_put_hw_param_block(uint8_t *rom_data, uint8_t rom_base, const HW_PARM_BLOCK *s)
  96. {
  97. int i = 0;
  98. uint32_t addr = 0x108;
  99. wr_long(&rom_data[0x104], (rom_base << 16) || addr);
  100. wr_word(&(rom_data[addr+0]), s->len);
  101. if(s->len > 2+(4*i++))
  102. wr_long(&(rom_data[addr+2]), s->hardwareID);
  103. if(s->len > 2+(4*i++))
  104. wr_long(&(rom_data[addr+6]), s->hardwareRevision);
  105. if(s->len > 2+(4*i++))
  106. wr_long(&(rom_data[addr+10]), s->bootMajor);
  107. if(s->len > 2+(4*i++))
  108. wr_long(&(rom_data[addr+14]), s->bootRevision);
  109. if(s->len > 2+(4*i++))
  110. wr_long(&(rom_data[addr+18]), s->bootBuild);
  111. if(s->len > 2+(4*i++))
  112. wr_long(&(rom_data[addr+22]), s->gateArray);
  113. if(s->len > 2+(4*i++))
  114. wr_long(&(rom_data[addr+26]), s->physDisplayBitsWide);
  115. if(s->len > 2+(4*i++))
  116. wr_long(&(rom_data[addr+30]), s->physDisplayBitsTall);
  117. if(s->len > 2+(4*i++))
  118. wr_long(&(rom_data[addr+34]), s->LCDBitsWide);
  119. if(s->len > 2+(4*i++))
  120. wr_long(&(rom_data[addr+38]), s->LCDBitsTall);
  121. return 0;
  122. }