supercic-key.asm 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. #include <p12f629.inc>
  2. processor p12f629
  3. ; ---------------------------------------------------------------------
  4. ; SNES CIC clone for PIC Microcontroller (key mode only)
  5. ;
  6. ; Copyright (C) 2010 by Maximilian Rehkopf (ikari_01) <otakon@gmx.net>
  7. ; This software is part of the sd2snes project.
  8. ;
  9. ; This program is free software; you can redistribute it and/or modify
  10. ; it under the terms of the GNU General Public License as published by
  11. ; the Free Software Foundation; version 2 of the License only.
  12. ;
  13. ; This program is distributed in the hope that it will be useful,
  14. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ; GNU General Public License for more details.
  17. ;
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. ;
  22. ; ---------------------------------------------------------------------
  23. ;
  24. ; pin configuration: (cartridge pin) [key CIC pin]
  25. ;
  26. ; ,---_---.
  27. ; +5V (27,58) [16] |1 8| GND (5,36) [8]
  28. ; CIC clk (56) [6] |2 7| CIC data i/o 0 (55) [2]
  29. ; status out |3 6| CIC data i/o 1 (24) [1]
  30. ; /PAIR |4 5| CIC slave reset (25) [7]
  31. ; `-------'
  32. ;
  33. ;
  34. ; Status out can be connected to a LED. It indicates:
  35. ;
  36. ; state | output
  37. ; -------------------------+----------------------------
  38. ; OK or no lock CIC | high
  39. ; error | low
  40. ; SuperCIC pair mode | 148.75kHz / 50% duty cycle
  41. ;
  42. ; In case lockout fails, the region is switched automatically and
  43. ; will be used after the next reset.
  44. ;
  45. ; The /PAIR pin can be used to enable or disable SuperCIC pair mode.
  46. ; It can be tied low or high to statically enable or disable pair mode
  47. ; detection, or connected to a switch or MCU to dynamically enable pair
  48. ; mode detection (it should then be connected to a pull-up resistor to
  49. ; Vcc). Pair mode detection can be enabled during operation,
  50. ; but pair mode cannot be left until the next power cycle.
  51. ; See SuperCIC lock documentation for a more detailed description of
  52. ; pair mode.
  53. ;
  54. ; memory usage:
  55. ;
  56. ; 0x20 buffer for seed calc and transfer
  57. ; 0x21 - 0x2f seed area (lock seed)
  58. ; 0x30 buffer for seed calc
  59. ; 0x31 - 0x3f seed area (key seed; 0x31 filled in by lock)
  60. ; 0x40 - 0x41 buffer for seed calc
  61. ; 0x4d buffer for eeprom access
  62. ; 0x4e loop variable for longwait
  63. ; 0x4f loop variable for wait
  64. ; 0x5e SuperCIC pair mode detect (phase 1)
  65. ; 0x5f SuperCIC pair mode detect (phase 2)
  66. ; ---------------------------------------------------------------------
  67. ; -----------------------------------------------------------------------
  68. __CONFIG _EC_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF
  69. ; -----------------------------------------------------------------------
  70. ; code memory
  71. org 0x0000
  72. nop
  73. nop
  74. nop
  75. goto init
  76. isr
  77. org 0x0004
  78. bcf INTCON, 1 ; clear interrupt cause
  79. bcf GPIO, 0
  80. bcf GPIO, 1
  81. bsf GPIO, 4 ; LED on
  82. clrf 0x5e ; clear pair mode detect
  83. clrf 0x5f ; clear pair mode detect
  84. bsf 0x5f, 1 ;
  85. nop
  86. nop
  87. nop
  88. bsf INTCON, 7 ; re-enable interrupts (ISR will continue as main)
  89. goto main
  90. init
  91. org 0x0010
  92. banksel GPIO
  93. clrf GPIO
  94. movlw 0x07 ; GPIO2..0 are digital I/O (not connected to comparator)
  95. movwf CMCON
  96. movlw 0x90 ; global enable interrupts + enable external interrupt
  97. movwf INTCON
  98. banksel TRISIO
  99. movlw 0x2d ; in out in in out in
  100. movwf TRISIO
  101. movlw 0x24 ; pullups for reset+clk to avoid errors when no CIC in host
  102. movwf WPU
  103. movlw 0x00 ; 0x80 for global pullup disable
  104. movwf OPTION_REG
  105. banksel GPIO
  106. bsf GPIO, 4 ; LED on
  107. idle
  108. goto idle ; wait for interrupt from lock
  109. main
  110. banksel TRISIO
  111. bsf TRISIO, 0
  112. bcf TRISIO, 1
  113. banksel GPIO
  114. ; --------INIT LOCK SEED (what the lock sends)--------
  115. movlw 0xb
  116. movwf 0x21
  117. movlw 0x1
  118. movwf 0x22
  119. movlw 0x4
  120. movwf 0x23
  121. movlw 0xf
  122. movwf 0x24
  123. movlw 0x4
  124. movwf 0x25
  125. movlw 0xb
  126. movwf 0x26
  127. movlw 0x5
  128. movwf 0x27
  129. movlw 0x7
  130. movwf 0x28
  131. movlw 0xf
  132. movwf 0x29
  133. movlw 0xd
  134. movwf 0x2a
  135. movlw 0x6
  136. movwf 0x2b
  137. movlw 0x1
  138. movwf 0x2c
  139. movlw 0xe
  140. movwf 0x2d
  141. movlw 0x9
  142. movwf 0x2e
  143. movlw 0x8
  144. movwf 0x2f
  145. ; --------INIT KEY SEED (what we must send)--------
  146. banksel EEADR ; D/F411 and D/F413
  147. clrf EEADR ; differ in 2nd seed nibble
  148. bsf EECON1, RD ; of key stream,
  149. movf EEDAT, w ; restore saved nibble from EEPROM
  150. banksel GPIO
  151. movwf 0x32
  152. movlw 0xa
  153. movwf 0x33
  154. movlw 0x1
  155. movwf 0x34
  156. movlw 0x8
  157. movwf 0x35
  158. movlw 0x5
  159. movwf 0x36
  160. movlw 0xf
  161. movwf 0x37
  162. movlw 0x1
  163. movwf 0x38
  164. movwf 0x39
  165. movlw 0xe
  166. movwf 0x3a
  167. movlw 0x1
  168. movwf 0x3b
  169. movlw 0x0
  170. movwf 0x3c
  171. movlw 0xd
  172. movwf 0x3d
  173. movlw 0xe
  174. movwf 0x3e
  175. movlw 0xc
  176. movwf 0x3f
  177. ; --------wait for stream ID--------
  178. movlw 0xb5
  179. call wait
  180. clrf 0x31 ; clear lock stream ID
  181. ; --------lock sends stream ID. 15 cycles per bit--------
  182. ; bsf GPIO, 0 ; (debug marker)
  183. ; bcf GPIO, 0 ;
  184. btfsc GPIO, 0 ; check stream ID bit
  185. bsf 0x31, 3 ; copy to lock seed
  186. movlw 0x2 ; wait=3*W+5
  187. call wait ; burn 11 cycles
  188. nop
  189. nop
  190. ; bsf GPIO, 0
  191. ; bcf GPIO, 0
  192. btfsc GPIO, 0 ; check stream ID bit
  193. bsf 0x31, 0 ; copy to lock seed
  194. movlw 0x2 ;
  195. call wait ; burn 11 cycles
  196. nop
  197. nop
  198. ; bsf GPIO, 0
  199. ; bcf GPIO, 0
  200. btfsc GPIO, 0 ; check stream ID bit
  201. bsf 0x31, 1 ; copy to lock seed
  202. movlw 0x2 ;
  203. call wait ; burn 11 cycles
  204. nop
  205. nop
  206. ; bsf GPIO, 0
  207. ; bcf GPIO, 0
  208. btfsc GPIO, 0 ; check stream ID bit
  209. bsf 0x31, 2 ; copy to lock seed
  210. banksel TRISIO
  211. bcf TRISIO, 0
  212. bsf TRISIO, 1
  213. banksel GPIO
  214. nop
  215. movlw 0x27 ; "wait" 1
  216. call wait ; wait 121
  217. ; --------main loop--------
  218. loop
  219. movlw 0x1
  220. loop0
  221. addlw 0x30 ; key stream
  222. movwf FSR ; store in index reg
  223. loop1
  224. nop
  225. nop
  226. movf INDF, w ; load seed value
  227. movwf 0x20
  228. bcf 0x20, 1 ; clear bit 1
  229. btfsc 0x20, 0 ; copy from bit 0
  230. bsf 0x20, 1 ; (if set)
  231. bsf 0x20, 4 ; LED on
  232. movf 0x20, w
  233. movwf GPIO
  234. nop
  235. movlw 0x10
  236. movwf GPIO ; reset GPIO
  237. movlw 0x14
  238. call wait
  239. nop
  240. nop
  241. nop
  242. nop
  243. nop
  244. btfsc GPIO, 0 ; both pins must be low...
  245. goto die
  246. btfsc GPIO, 1 ; ...when no bit transfer takes place
  247. goto die ; if not -> lock cic error state -> die
  248. incf FSR, f ; next one
  249. movlw 0xf
  250. andwf FSR, w
  251. btfss STATUS, Z
  252. goto loop1
  253. call mangle
  254. call mangle
  255. call mangle
  256. movlw 0x2 ; wait 10
  257. call wait ;
  258. nop
  259. nop
  260. btfsc 0x37, 0
  261. goto swap
  262. banksel TRISIO
  263. bcf TRISIO, 0
  264. bsf TRISIO, 1
  265. goto swapskip
  266. swap
  267. banksel TRISIO
  268. bsf TRISIO, 0
  269. bcf TRISIO, 1
  270. nop
  271. swapskip
  272. banksel GPIO
  273. movf 0x37, w
  274. andlw 0xf
  275. btfss STATUS, Z
  276. goto loop0
  277. goto loop
  278. ; --------calculate new seeds--------
  279. ; had to be unrolled because PIC has an inefficient way of handling
  280. ; indirect access, no post increment, etc.
  281. mangle
  282. call mangle_lock
  283. nop
  284. nop
  285. mangle_key
  286. movf 0x2f, w
  287. movwf 0x20
  288. mangle_key_loop
  289. addlw 0x1
  290. addwf 0x21, f
  291. movf 0x22, w
  292. movwf 0x40
  293. movf 0x21, w
  294. addwf 0x22, f
  295. incf 0x22, f
  296. comf 0x22, f
  297. movf 0x23, w
  298. movwf 0x41 ; store 23 to 41
  299. movlw 0xf
  300. andwf 0x23, f
  301. movf 0x40, w ; add 40(22 old)+23+#1 and skip if carry
  302. andlw 0xf
  303. addwf 0x23, f
  304. incf 0x23, f
  305. btfsc 0x23, 4
  306. goto mangle_key_withskip
  307. mangle_key_withoutskip
  308. movf 0x41, w ; restore 23
  309. addwf 0x24, f ; add to 24
  310. movf 0x25, w
  311. movwf 0x40 ; save 25 to 40
  312. movf 0x24, w
  313. addwf 0x25, f
  314. movf 0x26, w
  315. movwf 0x41 ; save 26 to 41
  316. movf 0x40, w ; restore 25
  317. andlw 0xf ; mask nibble
  318. addlw 0x8 ; add #8 to HIGH nibble
  319. movwf 0x40
  320. btfss 0x40, 4 ; skip if carry to 5th bit
  321. addwf 0x26, w
  322. movwf 0x26
  323. movf 0x41, w ; restore 26
  324. addlw 0x1 ; inc
  325. addwf 0x27, f ; add to 27
  326. movf 0x27, w ;
  327. addlw 0x1 ; inc
  328. addwf 0x28, f ; add to 28
  329. movf 0x28, w ;
  330. addlw 0x1 ; inc
  331. addwf 0x29, f ; add to 29
  332. movf 0x29, w ;
  333. addlw 0x1 ; inc
  334. addwf 0x2a, f ; add to 2a
  335. movf 0x2a, w ;
  336. addlw 0x1 ; inc
  337. addwf 0x2b, f ; add to 2b
  338. movf 0x2b, w ;
  339. addlw 0x1 ; inc
  340. addwf 0x2c, f ; add to 2c
  341. movf 0x2c, w ;
  342. addlw 0x1 ; inc
  343. addwf 0x2d, f ; add to 2d
  344. movf 0x2d, w ;
  345. addlw 0x1 ; inc
  346. addwf 0x2e, f ; add to 2e
  347. movf 0x2e, w ;
  348. addlw 0x1 ; inc
  349. addwf 0x2f, f ; add to 2f
  350. movf 0x20, w ; restore original 0xf
  351. andlw 0xf
  352. addlw 0xf
  353. movwf 0x20
  354. nop
  355. nop
  356. nop
  357. nop
  358. nop
  359. nop
  360. nop
  361. nop
  362. nop
  363. btfss 0x20, 4 ; skip if half-byte carry
  364. goto mangle_return ; +2 cycles in return
  365. nop
  366. goto mangle_key_loop
  367. ; 69 when goto, 69 when return
  368. ; CIC has 78 -> 9 nops
  369. mangle_key_withskip
  370. movf 0x41, w ; restore 23
  371. addwf 0x23, f ; add to 23
  372. movf 0x24, w
  373. movwf 0x40 ; save 24 to 40
  374. movf 0x23, w
  375. addwf 0x24, f
  376. movf 0x25, w
  377. movwf 0x41 ; save 25 to 41
  378. movf 0x40, w ; restore 24
  379. andlw 0xf ; mask nibble
  380. addlw 0x8 ; add #8 to HIGH nibble
  381. movwf 0x40
  382. btfss 0x40, 4 ; skip if carry to 5th bit
  383. addwf 0x25, w
  384. movwf 0x25
  385. movf 0x41, w ; restore 25
  386. addlw 0x1 ; inc
  387. addwf 0x26, f ; add to 26
  388. movf 0x26, w ;
  389. addlw 0x1 ; inc
  390. addwf 0x27, f ; add to 27
  391. movf 0x27, w ;
  392. addlw 0x1 ; inc
  393. addwf 0x28, f ; add to 28
  394. movf 0x28, w ;
  395. addlw 0x1 ; inc
  396. addwf 0x29, f ; add to 29
  397. movf 0x29, w ;
  398. addlw 0x1 ; inc
  399. addwf 0x2a, f ; add to 2a
  400. movf 0x2a, w ;
  401. addlw 0x1 ; inc
  402. addwf 0x2b, f ; add to 2b
  403. movf 0x2b, w ;
  404. addlw 0x1 ; inc
  405. addwf 0x2c, f ; add to 2c
  406. movf 0x2c, w ;
  407. addlw 0x1 ; inc
  408. addwf 0x2d, f ; add to 2d
  409. movf 0x2d, w ;
  410. addlw 0x1 ; inc
  411. addwf 0x2e, f ; add to 2e
  412. movf 0x2e, w ;
  413. addlw 0x1 ; inc
  414. addwf 0x2f, f ; add to 2f
  415. movf 0x20, w ; restore original 0xf
  416. andlw 0xf
  417. addlw 0xf
  418. movwf 0x20
  419. bcf GPIO, 0
  420. movf GPIO, w
  421. btfss GPIO, 3
  422. bsf GPIO, 0
  423. movwf 0x5e
  424. movf GPIO, w
  425. movwf 0x5f
  426. bcf GPIO, 0
  427. btfsc GPIO, 3
  428. clrf 0x5e
  429. nop
  430. btfss 0x20, 4 ; skip if half-byte carry
  431. goto mangle_return ; +2 cycles in return
  432. movf 0x20, w ; restore w (previously destroyed)
  433. goto mangle_key_loop
  434. mangle_return
  435. return
  436. ; 73 when goto, 73 when return
  437. ; CIC has 84 -> 11 nops
  438. mangle_lock
  439. movf 0x3f, w
  440. movwf 0x30
  441. mangle_lock_loop
  442. addlw 0x1
  443. addwf 0x31, f
  444. movf 0x32, w
  445. movwf 0x40
  446. movf 0x31, w
  447. addwf 0x32, f
  448. incf 0x32, f
  449. comf 0x32, f
  450. movf 0x33, w
  451. movwf 0x41 ; store 33 to 41
  452. movlw 0xf
  453. andwf 0x33, f
  454. movf 0x40, w ; add 40(32 old)+33+#1 and skip if carry
  455. andlw 0xf
  456. addwf 0x33, f
  457. incf 0x33, f
  458. btfsc 0x33, 4
  459. goto mangle_lock_withskip
  460. mangle_lock_withoutskip
  461. movf 0x41, w ; restore 33
  462. addwf 0x34, f ; add to 34
  463. movf 0x35, w
  464. movwf 0x40 ; save 35 to 40
  465. movf 0x34, w
  466. addwf 0x35, f
  467. movf 0x36, w
  468. movwf 0x41 ; save 36 to 41
  469. movf 0x40, w ; restore 35
  470. andlw 0xf ; mask nibble
  471. addlw 0x8 ; add #8 to HIGH nibble
  472. movwf 0x40
  473. btfss 0x40, 4 ; skip if carry to 5th bit
  474. addwf 0x36, w
  475. movwf 0x36
  476. movf 0x41, w ; restore 36
  477. addlw 0x1 ; inc
  478. addwf 0x37, f ; add to 37
  479. movf 0x37, w ;
  480. addlw 0x1 ; inc
  481. addwf 0x38, f ; add to 38
  482. movf 0x38, w ;
  483. addlw 0x1 ; inc
  484. addwf 0x39, f ; add to 39
  485. movf 0x39, w ;
  486. addlw 0x1 ; inc
  487. addwf 0x3a, f ; add to 3a
  488. movf 0x3a, w ;
  489. addlw 0x1 ; inc
  490. addwf 0x3b, f ; add to 3b
  491. movf 0x3b, w ;
  492. addlw 0x1 ; inc
  493. addwf 0x3c, f ; add to 3c
  494. movf 0x3c, w ;
  495. addlw 0x1 ; inc
  496. addwf 0x3d, f ; add to 3d
  497. movf 0x3d, w ;
  498. addlw 0x1 ; inc
  499. addwf 0x3e, f ; add to 3e
  500. movf 0x3e, w ;
  501. addlw 0x1 ; inc
  502. addwf 0x3f, f ; add to 3f
  503. movf 0x30, w ; restore original 0xf
  504. andlw 0xf
  505. addlw 0xf
  506. movwf 0x30
  507. nop
  508. nop
  509. nop
  510. nop
  511. nop
  512. nop
  513. nop
  514. nop
  515. nop
  516. btfss 0x30, 4 ; skip if half-byte carry
  517. goto mangle_return
  518. nop
  519. goto mangle_lock_loop
  520. ; 69 when goto, 69 when return
  521. ; CIC has 78 -> 9 nops
  522. mangle_lock_withskip
  523. movf 0x41, w ; restore 33
  524. addwf 0x33, f ; add to 33
  525. movf 0x34, w
  526. movwf 0x40 ; save 34 to 40
  527. movf 0x33, w
  528. addwf 0x34, f
  529. movf 0x35, w
  530. movwf 0x41 ; save 35 to 41
  531. movf 0x40, w ; restore 34
  532. andlw 0xf ; mask nibble
  533. addlw 0x8 ; add #8 to HIGH nibble
  534. movwf 0x40
  535. btfss 0x40, 4 ; skip if carry to 5th bit
  536. addwf 0x35, w
  537. movwf 0x35
  538. movf 0x41, w ; restore 35
  539. addlw 0x1 ; inc
  540. addwf 0x36, f ; add to 36
  541. movf 0x36, w ;
  542. addlw 0x1 ; inc
  543. addwf 0x37, f ; add to 37
  544. movf 0x37, w ;
  545. addlw 0x1 ; inc
  546. addwf 0x38, f ; add to 38
  547. movf 0x38, w ;
  548. addlw 0x1 ; inc
  549. addwf 0x39, f ; add to 39
  550. movf 0x39, w ;
  551. addlw 0x1 ; inc
  552. addwf 0x3a, f ; add to 3a
  553. movf 0x3a, w ;
  554. addlw 0x1 ; inc
  555. addwf 0x3b, f ; add to 3b
  556. movf 0x3b, w ;
  557. addlw 0x1 ; inc
  558. addwf 0x3c, f ; add to 3c
  559. movf 0x3c, w ;
  560. addlw 0x1 ; inc
  561. addwf 0x3d, f ; add to 3d
  562. movf 0x3d, w ;
  563. addlw 0x1 ; inc
  564. addwf 0x3e, f ; add to 3e
  565. movf 0x3e, w ;
  566. addlw 0x1 ; inc
  567. addwf 0x3f, f ; add to 3f
  568. movf 0x30, w ; restore original 0xf
  569. andlw 0xf
  570. addlw 0xf
  571. movwf 0x30
  572. btfss 0x5e, 1
  573. goto scic_pair_skip1
  574. btfsc 0x5f, 1
  575. goto scic_pair_skip2
  576. btfsc GPIO, 3
  577. goto scic_pair_skip3
  578. goto supercic_pairmode
  579. scic_pair_skip1
  580. nop
  581. nop
  582. scic_pair_skip2
  583. nop
  584. nop
  585. scic_pair_skip3
  586. nop
  587. nop
  588. nop
  589. nop
  590. btfss 0x30, 4 ; skip if half-byte carry
  591. goto mangle_return
  592. nop
  593. goto mangle_lock_loop
  594. ; 73 when goto, 73 when return
  595. ; CIC has 84 -> 11 nops
  596. ; --------wait: 3*(W-1)+7 cycles (including call+return). W=0 -> 256!--------
  597. wait
  598. movwf 0x4f
  599. wait0 decfsz 0x4f, f
  600. goto wait0
  601. return
  602. ; --------wait long: 8+(3*(w-1))+(772*w). W=0 -> 256!--------
  603. longwait
  604. movwf 0x4e
  605. clrw
  606. longwait0
  607. call wait
  608. decfsz 0x4e, f
  609. goto longwait0
  610. return
  611. ; --------change region in eeprom and die--------
  612. die
  613. movlw 0x3a ;wait 50ms before writing
  614. call longwait ;("error" might be due to power loss)
  615. banksel EEADR
  616. clrw
  617. movwf EEADR
  618. bsf EECON1, RD
  619. movf EEDAT, w
  620. banksel GPIO
  621. movwf 0x4d
  622. btfsc 0x4d, 0
  623. goto die_reg_6
  624. die_reg_9
  625. movlw 0x9 ; died with PAL, fall back to NTSC
  626. goto die_reg_cont
  627. die_reg_6
  628. movlw 0x6 ; died with NTSC, fall back to PAL
  629. die_reg_cont
  630. banksel EEADR
  631. movwf EEDAT
  632. bsf EECON1, WREN
  633. die_intloop
  634. bcf INTCON, GIE
  635. btfsc INTCON, GIE
  636. goto die_intloop
  637. movlw 0x55
  638. movwf EECON2
  639. movlw 0xaa
  640. movwf EECON2
  641. bsf EECON1, WR
  642. bsf INTCON, GIE
  643. banksel GPIO
  644. bcf GPIO, 4
  645. ; --------get caught up--------
  646. die_trap
  647. goto die_trap
  648. ; -----------------------------------------------------------------------
  649. supercic_pairmode
  650. banksel TRISIO
  651. bsf TRISIO, 0
  652. bsf TRISIO, 1
  653. banksel GPIO
  654. bcf INTCON, GIE
  655. supercic_pairmode_loop
  656. bsf GPIO, 4
  657. nop
  658. nop
  659. bcf GPIO, 4
  660. goto supercic_pairmode_loop
  661. ; eeprom memory
  662. DEEPROM CODE
  663. de 0x09 ; D411 (NTSC)
  664. end