load4.pde 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <SPI.h>
  2. #include <GD.h>
  3. #include "flashimg.h"
  4. #include "loadcommon.h"
  5. #include "reload.h"
  6. void reload()
  7. {
  8. GD.microcode(reload_code, sizeof(reload_code));
  9. }
  10. static unsigned long copy_page(int dst, int src)
  11. {
  12. int i;
  13. SEL_local();
  14. SPI.transfer(0x03);
  15. spipage(src);
  16. for (i = 0; i < 264; i++)
  17. history[i] = spix(0);
  18. UNSEL_local();
  19. SEL_local();
  20. SPI.transfer(0x82);
  21. spipage(dst);
  22. for (i = 0; i < 264; i++)
  23. spix(history[i]);
  24. UNSEL_local();
  25. while ((status() & 0x80) == 0)
  26. ;
  27. }
  28. void setup()
  29. {
  30. common_setup(4);
  31. if (!ready0123(STAGEBASE)) {
  32. GD.putstr(0, 20, "You must run load0, load1, load2, load3 first");
  33. for (;;)
  34. ;
  35. }
  36. common_show_status();
  37. do {
  38. page = P4OFF;
  39. GD_uncompress(part4);
  40. common_show_status();
  41. } while (!ready(4));
  42. do {
  43. GD.putstr(0, 20, "Parts ready. Copying...");
  44. GD.putstr(0, 22, "DO NOT INTERRUPT OR TURN OFF");
  45. int i;
  46. for (i = 0; i < P4OFF; i++)
  47. copy_page(i, STAGEBASE + i);
  48. } while (!ready0123(0));
  49. GD.putstr(25, 20, "Done!");
  50. GD.putstr(0, 27, "Now restarting...");
  51. delay(2000);
  52. reload();
  53. }
  54. void loop()
  55. {
  56. }