prjbrook

forth85_25 Test1 worked live. Debugging work.

Aug 16th, 2014
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.26 KB | None | 0 0
  1. ;this is forth85_25 Tidies up forth85_24A. Staying with Notpad++ rather that avr studio 4
  2. ;did some avr studio debugging
  3. ;Issues below still on table. Need more debugging tools. Havee got d16, d1617, dlowR, ddhighR, dxyz. All dumps.
  4. ;today going to try .S , show stack in non-destructive way.
  5. ;Changed to Notepad++ and comand line asm. Having issues with rcall CR. Sends '\' sometimes. Solved.
  6. ;Nearly live. Probs with $0d on input line. Solved. Don't do st -x,r16 then st x+,r16.
  7. ;do and test BRANCH and 0 BRANCH NOT DONE
  8. ; Also calcjump for rjmp opcodes needs tsting. NOT DONE
  9. ;could try (begin .... again) loop. Kind of dione. Needs live run
  10. ;equ testing = 1 ;makes io verbose. comment out later
  11.  
  12. .NOLIST
  13. .include "tn85def.inc"
  14. .LIST
  15. ;.LISTMAC ;sometimes macro code gets in way of clarity in listing
  16. .MACRO header
  17. .db high(@0), low(@0), @1, @2
  18. .ENDMACRO
  19. .MACRO mypop
  20. ld @0,-y
  21. .ENDMACRO
  22. .MACRO mypush
  23. st y+, @0
  24. .ENDMACRO
  25. .MACRO mypop2
  26. mypop @0
  27. mypop @1
  28. .ENDMACRO
  29. .MACRO mypush2
  30. mypush @0
  31. mypush @1
  32. .ENDMACRO
  33. .MACRO pushx
  34. push xl
  35. push xh
  36. .ENDMACRO
  37. .MACRO popx
  38. pop xh
  39. pop xl
  40. .ENDMACRO
  41. .MACRO pushz
  42. push zl
  43. push zh
  44. .ENDMACRO
  45. .MACRO popz
  46. pop zh
  47. pop zl
  48. .ENDMACRO
  49. .MACRO mypopa ;call r16,17 the accumulator a, ditto for r18,r19 for b
  50. mypop r17
  51. mypop r16
  52. .ENDMACRO
  53. .MACRO mypopb
  54. mypop2 r19,r18
  55. .ENDMACRO
  56. .macro TAKEMEOUT
  57. ldi serialByteReg, @0
  58. rcall sendSerialByte
  59. ldi serialByteReg, @0
  60. rcall sendSerialByte
  61.  
  62. .endmacro
  63.  
  64.  
  65.  
  66.  
  67. .def mylatest =r2 ;r2,r3 is mylatest
  68. .def myhere =r4 ;r4,r5 is myhere. The pointer to flash copy in buf2.
  69. .def SOFPG=r6 ;start of flash page
  70. ;r6,r7 byte adr of flash page (11c0)
  71. ;r8,r9 (0012) offset when flash comes into buf2. r8 +E0 = myhere
  72. .def SECONDLETTER =r10 ;helpful for debugging
  73. .def FOUNDCOUNTER = r11 ;dealWithWord clicks this if found =1. Counts successful finds in dictionary.
  74. .def STATE = r12
  75. .def STOP = r13 ;stop interpreting line of words
  76. .def BOTTOM = r14 ;have hit the bottom of the dict and not found a match
  77. .def FOUND = r15 ;if found=1 we have a match of Ram word on dictionary
  78. .def spmcsr_val=r18
  79. .def buf_ctr =r19 ;for flash section
  80. ;r20 is length of word in WORD
  81. ;r21 is the flash length of word with immediate bit 8, if any, still there
  82.  
  83. .def vl = r22
  84. .def vh = r23 ; u,v,w,x,y,z are all pointers
  85. .def wl = r24 ;w=r24,25
  86. .def wh = r25
  87.  
  88. .equ TX_PIN = 0
  89. .equ RX_PIN = 2 ; Tx,Rx pins are PB0 and PB2 resp
  90.  
  91. .def serialByteReg = r16
  92. .def rxByte = r18
  93. .def counterReg = r17
  94.  
  95.  
  96.  
  97.  
  98. .eseg
  99. .org $10
  100. .dw HERE, LATEST ;these should be burned into tn85 with code
  101.  
  102. .DSEG
  103. .ORG 0x60
  104.  
  105. .equ BUF1LENGTH = 128
  106. .equ eHERE = $0010 ;eeprom adr of system varial eHere
  107. .equ eLATEST = $0012
  108.  
  109. buf1: .byte BUF1LENGTH ;input buffer. Lines max about 125
  110. buf2: .byte BUF1LENGTH ;this fits two flash buffers
  111. varSpace: .byte 64 ;might need more than 32 variables
  112. myStackStart: .byte 64 ;currently at $1E0.Meets return stack.
  113.  
  114. .CSEG
  115. .ORG 0x800 ;dictionary starts at 4K (2K words) mark
  116. ;----------------------------------------------------
  117. one_1:
  118. .db 0,0,3, "one" ;code for one
  119. one:
  120. ; rcall stackme
  121. rcall stackme_2
  122. .db 01, 00
  123. ret
  124. ;----------------------------------------------
  125. two_1:
  126. header one_1, 3, "two"
  127. two:
  128. rcall stackme_2
  129. .db 02,00
  130. ret
  131. ;------------------------------------------
  132. dup_1:
  133. header two_1,3,"dup"
  134. dup:
  135. mypop r17
  136. mypop r16
  137. mypush r16
  138. mypush r17
  139. mypush r16
  140. mypush r17
  141.  
  142. ret
  143. ;-------------------------------------------
  144. drop_1:
  145. header dup_1,4,"drop"
  146. drop:
  147. mypop r17
  148. mypop r16 ;TODO what if stack pointer goes thru floor?
  149. ret
  150. ;----------------------------------
  151. swapp_1: ;twp p's becasue assembler recognizes avr opcode swap
  152. header drop_1,5, "swapp"
  153. swapp:
  154. mypop2 r17,r16
  155. mypop2 r19,r18
  156. mypush2 r16,r17
  157. mypush2 r18,r19
  158. ret
  159.  
  160.  
  161. ;-------------------------------------------------
  162. ;shift this later
  163.  
  164. S_1:
  165. ;the EOL token that gets put into end of buf1 to stop parsing
  166. header swapp_1,$81,"S" ;NB always immediate
  167. S: ldi r16,02
  168. mov BOTTOM,r16 ;r14 =2 means a nice stop. EOL without errors
  169. clr STOP
  170. inc STOP ;set time-to-quit flag
  171. takemeout 's'
  172. ret
  173. ;------------------------------------------
  174.  
  175. fetch_1: ;doesn't like label = @-1
  176. ;classic fetch. (adr -- num). Only in RAM
  177. header S_1,1,"@"
  178. fetch:
  179. pushx ;going to use x to point so better save
  180. mypop xh
  181. mypop xl
  182. ld r16,x+
  183. ld r17,x
  184. mypush r16
  185. mypush r17 ; and put them on my stack
  186. popx ;return with x intact and RAM val on my stack
  187. ret
  188. ;dddddddddddddddddddddddddddddddddddddddddddddddd
  189.  
  190. cfetch_1: ;doesn't like label = c@-1
  191. ;classic fetch. (adr -- num). Only in RAM. Do I want y to advance just one byte on mystack
  192. header fetch_1,2,"c@"
  193. cfetch:
  194. pushx ;going to use x to point so better save
  195. mypop xh
  196. mypop xl
  197. ld r16,x+
  198. mypush r16
  199. popx ;return with x intact and RAM val on my stack
  200. ret
  201. ;dddddddddddddddddddddddddddddddddddddddddddddddd
  202.  
  203. store_1: ;classic != "store"(adr num --) . Num is now at cell adr.
  204. header cfetch_1,1,"!"
  205. store:
  206. mypop2 r17,r16 ;there goes the num
  207. pushx
  208. mypop2 xh,xl ;there goes the address
  209. st x+,r16
  210. st x,r17 ;num goes to cell with location=adr
  211. popx
  212. ret
  213. ;ddddddddddddddddddddddddddddddddddddddddddddddddddd
  214.  
  215. cstore_1: ;classic c!= "store"(adr 8-bitnum --) . 8 bit Num is now at cell adr.
  216. header store_1,2,"c!"
  217. cstore:
  218. mypop r16 ;there goes the num. Just 8 bits at this stage.
  219. pushx
  220. mypop2 xh,xl ;there goes the address
  221. st x+,r16
  222. ; st x,r17 ;num goes to cell with location=adr
  223. popx
  224. ret
  225. ;------------------------------------
  226.  
  227. star_1: ;classic 16*16 mulitply (n n -- n*n)
  228. header cstore_1,1,"*"
  229. star:
  230. mypop2 r17,r16
  231. mypop2 r19,r18 ;now have both numbers in r16..r19
  232. rcall mpy16s ; multiply them. Result in r18..r21. Overflow in r20,21
  233. mypush2 r18,r19
  234. ret
  235. ;-----------------------------------------
  236.  
  237. slashMod_1: ;classic /MOD (n m -- n/m rem)
  238. header star_1,4,"/mod"
  239. slashMod:
  240. push r13
  241. push r14 ;this is STOP but is used by div16s, so better save it
  242. mypop2 r19,r18 ; that's m
  243. mypop2 r17,r16 ;that's n
  244. rcall div16s ;the the 16 by 16 bit divsion
  245. mypush2 r16,r17 ;answer ie n/m
  246. mypush2 r14,r15 ;remainder
  247. pop r14
  248. pop r13
  249. ret
  250. ;dddddddddddddddddddddddddddddddddddddddddddd
  251.  
  252. plus_1: ;classic + ( n n -- n+n)
  253. header slashMod_1,1,"+"
  254. plus:
  255. mypop2 r17,r16
  256. mypop2 r19,r18
  257. clc
  258. add r16,r18
  259. adc r17,r19
  260. mypush2 r16,r17
  261. ret
  262. ;--
  263.  
  264. minus_1: ;classic - ( n m -- n-m)
  265. header plus_1,1,"-"
  266. minus:
  267. mypop2 r19,r18
  268. mypop2 r17,r16
  269. clc
  270. sub r16,r18
  271. sbc r17,r19
  272. mypush2 r16,r17
  273. ret
  274. ;dddddddddddddddddddddddddddddddddddddddddd
  275.  
  276. pstore_1: ;expects eg. 0003 PORTB P! etc, "output 3 via PORTB"
  277. header minus_1,2, "p!"
  278. pstore:
  279. mypopb ;get rid of PORTB number, not used for tiny85, just one port
  280. mypopa ; this is used. it's eg the 003 = R16 above
  281. out PORTB,r16
  282. ret
  283. ;ddddddddddddddddddddddddd
  284.  
  285. portblabel_1:
  286. header pstore_1,5,"PORTB" ; note caps just a filler that point 0b in stack for dropping
  287. portblabel:
  288. ; Extend later on to include perhaps other ports
  289. ; one:
  290. ; rcall stackme
  291.  
  292. rcall stackme_2
  293. .db $0b, 00
  294. ret
  295. ;---------------------
  296.  
  297. datadirstore_1: ;set ddrb. invioked like this 000f PORTB dd! to make pb0..pb3 all outputs
  298. header portblabel_1, 3, "dd!"
  299. datadirstore:
  300. mypopb ; there goes useless 0b = PORTB
  301. mypopa ; 000f now in r17:16
  302. out DDRB,r16
  303. ret
  304. ;dddddddddddddddddddddddddddddddddddd
  305. ;sbilabel_1 ;set bit in PORTB. Just a kludge at this stage
  306. ;header datadirstore_1,3,"sbi" TODO sort out sbi and delay later. Now get on with compiler.
  307. ;first need store system vars in the eeprom. Arbitrarily 0010 is HERE and 0012 (in eeprom) is LATEST
  308. ;----------------------------------------
  309.  
  310. percentcstore_1: ;(n16 adr16 --) %c! stores stack val LSbyte to eeprom adr
  311. ; eg 10 00 1234 stores 34 to 0010 <--eeprom adr
  312. header datadirstore_1,3,"%c!"
  313. percentcstore:
  314. mypopb ;adr in r18,19
  315. mypopa ;data. Lower byte into r16
  316.  
  317. rcall eewritebyte ;burn it into eeprom
  318. ret
  319. ;----------------------------------
  320.  
  321. percentstore_1: ; (n16 adr16 --) b16 stored at eeprom adr adr16 and adr16+1
  322. header percentcstore_1,2, "%!"
  323. percentstore:
  324. mypopb ;adr in b=r18,19
  325. mypopa ;n16 into r16,17 as data
  326.  
  327. rcall eewritebyte ;burn low data byte
  328. clc
  329. inc r18
  330. brne outpcs
  331. inc r17 ;sets up adr+1 for next byte
  332. outpcs:
  333. mov r16,r17 ;r16 now conatins hi byte
  334. rcall eewritebyte
  335. ret
  336. ;-------------------------------
  337.  
  338. percentcfetch_1: ;(eepromadr16--char). Fetch eeprom byte at adr on stack
  339. header percentstore_1,3,"%c@"
  340. percentcfetch:
  341. mypopb ;adr now in r18,19
  342. rcall eereadbyte
  343. mypush r16 ; there's the char going on stack. Should be n16? Not n8?
  344. ret
  345. ;-------------------
  346.  
  347. percentfetch_1: ;(adr16--n16) get 16bits at adr and adr+1
  348. header percentcfetch_1,2,"%@"
  349. percentfetch:
  350. rcall percentcfetch ;low byte now on stack
  351. inc r18
  352. brcc downpf
  353. inc r19
  354. downpf:
  355. rcall eereadbyte ;there's the high byte hitting the mystack
  356. mypush r16
  357. ret
  358. ;-------------------------------
  359. gethere_1: ; leaves current value of eHERE on stack
  360. header percentfetch_1,7,"gethere"
  361. gethere:
  362. rcall stackme_2
  363. .dw eHere
  364. rcall percentfetch
  365. ret
  366. ;--------------------
  367.  
  368. getlatest_1: ;leaves current value of latest on stack
  369. header gethere_1,9, "getlatest"
  370. getlatest:
  371. rcall stackme_2
  372. .dw eLATEST ;the address of the latest link lives in eeprom at address 0012
  373. rcall percentfetch ;get the val out of eeprom
  374. ret
  375. ;------------------
  376.  
  377. colon_1: ;classic ":"compiling new word marker
  378. header getlatest_1,1,":"
  379. rcall coloncode
  380. ret
  381. ;----------------------------------------
  382.  
  383. comma_1: ;classic comma. ;Put adr on stack into dictionary at myhere and bump myhere
  384. header colon_1,1,","
  385. comma:
  386. mypopa ;adr now in r16,17
  387. pushz ;save z
  388. movw zl,myhere ;z now pnts to next avail space in dic
  389. st z+,r16
  390. st z+,r17
  391. movw myhere,zl ;so that myhere is updated as ptr
  392. popz ;bring z back
  393. ret
  394. ;------------------------------------
  395.  
  396. tic_1: ;clasic tic('). Put cfa of next word on stack
  397. header comma_1,1, "'"
  398. tic:
  399. rcall word ;point to next word in input
  400. rcall findword ;leaving cfa in z
  401. mypush2 zl,zh
  402. rcall two ;but it's in bytes. Need words so / by 2
  403. rcall slashmod
  404. rcall drop ;that's the remainder dropped
  405. ;now have cfa of word after ' on stack in word-units.
  406. ret
  407. ;-----------------------
  408.  
  409. dummy_1: ;handy debugging place to put a break point
  410. header tic_1,$85,"dummy" ;first immediate word
  411. dummy:
  412. nop
  413. ret
  414. ;--------------------------------
  415.  
  416. compstackme_2_1: ;needed infront of every number compiled
  417. header dummy_1, $0d,"compstackme_2"
  418. compstackme_2:
  419. ldi r16,low(stackme_2)
  420. ldi r17,high(stackme_2)
  421. mypush2 r16,r17 ;in words need to *2 to convert to bytes
  422. rcall two
  423. rcall star
  424. rcall compileme
  425. ret
  426. ;-----------------------------------------
  427.  
  428. double_1: ;whatever's on stack gets doubled. Usful words-->bytes. (n...2*n)
  429. header compstackme_2_1, 6, "double"
  430. double:
  431. mypopa ;stk to r16,17
  432. clc ;going to do shifts
  433. rol r16
  434. rol r17 ;r16,17 now doubled
  435. mypush2 r16,r17
  436. ret ;with 2*n on my stk
  437. ;--------------------------------------
  438.  
  439. semi_1: ;classic ";". Immediate TODO compile a final ret
  440. header double_1,$81,";"
  441. semi:
  442. nop
  443. rcall insertret ;compile ret
  444. rcall burnbuf2and3
  445. rcall rbrac ;after semi w'got back to executing
  446. ; rcall updatevars ;update HERE and LATEST in eeprom
  447. rcall updatevars2 ;Better version. update HERE and LATEST in eeprom
  448.  
  449. ret
  450. ;---------------------------------------
  451.  
  452. rbrac_1: ;classic "]" ,immediate
  453. header semi_1,$81,"]"
  454. rbrac:
  455. clr STATE ;go to executing
  456. ret
  457. ;------------------------------------------------
  458.  
  459. immediate_1: ;classic IMMEDIATE. Redo len byte so MSbit =1
  460. header rbrac_1,$89,"immediate"
  461. immediate:
  462. mypush2 r2,r3 ;this is mylatest. pnts to link of new word
  463. rcall two
  464. rcall plus ;jmp over link to pnt to len byte
  465. pushx ;better save x
  466. mypop2 xh,xl ;x now pnts to len byte
  467. ld r16,x ; and put it into r6
  468. ldi r18,$80 ;mask
  469. or r16,r18 ;eg 03 --> 83 in hex
  470. st x,r16 ;put len byte back
  471. popx ;back where it was
  472. ret ;done now newly created word is immediate
  473. ;-------------------------------------------------
  474.  
  475. emit_1: ;(n8 --) classic emit
  476.  
  477. header immediate_1, 4, "emit"
  478. emit:
  479. rcall emitcode
  480. ret
  481. ;--------------------------------------
  482.  
  483. getline_1: ;rx a line of chars from serialin. eol = $0d
  484. ;this is the line that gets interpreted
  485. header emit_1,7, "getline"
  486. getline:
  487. rcall rxStrEndCR ;write 64 TODO 128? bytes into buf1 from serial io
  488. .ifdef testing
  489. rcall dumpbuf1
  490. .endif
  491. ret ;with buf1 ready to interpret
  492. ;-------------------------------------------------
  493.  
  494. zero_1: ;stack a zero
  495. header getline_1,4,"zero"
  496. zero:
  497. rcall stackme_2
  498. .db 0,0
  499. ret
  500. ;----------------------------------------
  501.  
  502. equal_1: ;(n1 n2 -- flag)
  503. header zero_1,1,"="
  504. equal:
  505. rcall equalcode
  506. ret
  507. ;----------------------------------------
  508.  
  509. zeroequal_1: ;(n -- flag)
  510. header equal_1,2,"0="
  511. zeroequal:
  512. rcall zero
  513. rcall equal
  514. ret
  515. ;-------------------------
  516.  
  517. over_1: ;(n1 n2 --n1 n2 n1)
  518. header zero_1,4,"over"
  519. over:
  520. mypopa
  521. mypopb
  522. mypush2 r18,r19 ;n1
  523. mypush2 r16,r17 ;n2
  524. mypush2 r18,r19 ;n1. so end up with (n1,n2,n1
  525. ret
  526. ;-----------------------------------
  527.  
  528. rot_1: ;classic (n1 n2 n3 -- n2 n3 n1)
  529. header over_1,3,"rot"
  530. rot:
  531. mypopa
  532. push r17
  533. push r16 ;save n3
  534. rcall swapp ; n2 n1
  535. pop r16
  536. pop r17
  537. mypush2 r16,r17 ;n2 n1 n3
  538. rcall swapp ;n2 n3 n1
  539. ret
  540. ;------------------------------------
  541.  
  542. reverse3_1: ;PB (n1 n2 n3 -- n3 n2 n1). Reverses top 3 order
  543. header rot_1,8,"reverse3"
  544. reverse3:
  545. rcall swapp ; n1 n3 n2
  546. rcall rot ; n3 n2 n1
  547. ret ;so (n1 n2 n3 -- n3 n2 n1)
  548. ;--------------------------------------------
  549.  
  550. unrot_1: ;PB (n1 n2 n3 -- n3 n1 n2) Buries topitem two down
  551. header reverse3_1,5,"unrot"
  552. unrot:
  553. rcall reverse3 ; (n1 n2 n3 -- n3 n2 n1)
  554. rcall swapp ; n3 n1 n2
  555. ret
  556. ;--------------------------------
  557.  
  558. andd_1: ;classic AND
  559. header unrot_1,4,"andd" ; two d's otherwise asm problems
  560. andd:
  561. mypopa
  562. mypopb
  563. and r16,r18
  564. and r17,r19
  565. mypush2 r16,r17
  566. ret
  567. ;----------------------------------------
  568.  
  569.  
  570. orr_1: ;classic OR
  571. header andd_1,3,"orr" ; two r's otherwise asm problems
  572. orr:
  573. mypopa
  574. mypopb
  575. or r16,r18
  576. or r17,r19
  577. mypush2 r16,r17
  578. ret
  579. ;------------------------
  580.  
  581. calcjump_1: ;(to from -- opcode)
  582. header orr_1,$88, "calcjump"
  583. calcjump:
  584. rcall calcjumpcode
  585. ret ;with opcode on stack
  586. ;-----------------------
  587.  
  588. begin_1: ;( -- adr) classic BEGIN. Used in most loops
  589. header calcjump_1,$85,"begin"
  590. begin:
  591. rcall stackmyhere ;put next adr on stack. For AGAIN etc
  592. ret ;with adr on stack
  593. ;---------------------------
  594. again_1: ; (to_adr -- ) classic AGAIN cts loop back to BEGIN
  595. header begin_1, $85,"again"
  596. rcall stackmyhere ; to_adr fr_adr
  597. rcall minus ;rel_adr_distance eg $ffdd
  598. rcall stackme_2
  599. .dw $0002
  600. rcall div ;now adr difference in words. Works better.
  601. rcall stackme_2
  602. .dw $0fff ;$ffdd $0fff
  603. rcall andd ;$0fdd eg.
  604. rcall stackme_2
  605. .dw $c000 ;$0fdd $c000
  606. rcall orr ;$cffdd = rjmp back_to_again
  607. rcall one
  608. rcall minus ;t0-fr-1 = the jump part of rjmp
  609. rcall comma ;insert into dic
  610. ret ;with rjmp opcode in next pos in dic
  611. ;------------------------------
  612.  
  613. div_1: ; (n1 n2 -- n1/n2) classic / Could make 2 / faster with >, one right shift
  614. header again_1,1,"/"
  615. div:
  616. rcall slashMod
  617. rcall drop
  618. ret
  619. ;---------------------------------
  620.  
  621. halve_1: ; (n -- n/2) use shifts to halve num on stack. Handy
  622. header div_1,5,"halve"
  623. halve:
  624. mypopa
  625. clc
  626. ror r17
  627. ror r16
  628. mypush2 r16,r17 ;now num on stack has been halved
  629. ret ;with n/2 on stk
  630. ;--------------------
  631.  
  632. dumpb1_1: ;dumpbuf1 to serial
  633. header halve_1,6,"dumpb1"
  634. dumpb1:
  635. rcall dumpbuf1
  636. ret
  637. ;---------------------
  638.  
  639. OK_1: ;classic "ok"
  640. header dumpb1_1,2,"OK"
  641. OK:
  642. ldi r16,'K'
  643. ldi r17,'O'
  644. mypush2 r16,r17
  645. rcall emitcode
  646. rcall emitcode
  647. ldi r16,'}' ;try this for a cursor prompt
  648. mypush r16
  649. rcall emitcode
  650.  
  651. ret ;after having emitted "OK" to terminal
  652. ;-------------------------------
  653.  
  654. CR_1: ;output a carriage return. Need $0d too?
  655. header OK_1,2, "CR"
  656. CR:
  657. ldi r16,$0d
  658. mypush r16
  659. rcall emitcode
  660. ret ;after sending CR to terminal
  661. ;--------------------------
  662. LATEST:
  663. test1_1: ;just need some dic word to try with new serialFill
  664. header CR_1,5,"test1"
  665. test1:
  666. ldi serialByteReg, '*'
  667. rcall sendSerialByte
  668. ldi serialByteReg, 'T'
  669. rcall sendSerialByte
  670. ldi serialByteReg, 'T'
  671. rcall sendSerialByte
  672. ldi serialByteReg, '*'
  673. rcall sendSerialByte
  674. inc r1
  675. inc r1 ;TESTING take out later TODO
  676. ret
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692. ;-----------------------------------------------
  693. HERE:
  694. .db "444444444444444444444444444444"
  695. rcall stackme_2
  696. .dw $1234
  697. rcall two
  698. rcall stackme_2
  699. .dw $2468
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719. ;---------------stackme_2 used to live here----------------------------------
  720.  
  721.  
  722.  
  723.  
  724. ;====================================================================================================
  725.  
  726. .ORG 0
  727. rjmp quit
  728. ; rjmp mainloop
  729. ; rjmp start
  730. ;typein: .db "11bb 0014 %! getlatest",$0d, "0013 %@",0x0d
  731. typein: .db "test1", $0d
  732. ;typein: .db " : qqq one two dup one ; qqq " ,$0d
  733. ;"11bb 0014 %! ", $0d ;%! getlatest",$0d, "0013 %@",0x0d
  734. ;" one 0010 00ab %c! 0012 cdef %! 0013 %c@ 0013 %@ 0987 drop ", 0x0d
  735.  
  736. ;stackme dropx onex stackme swap drop",0x0d
  737. ;-----------------------------------------------------
  738. ;start:
  739. quit:
  740. ldi r16, low(RAMEND)
  741. out SPL, r16
  742.  
  743.  
  744. ldi r16,high(RAMEND)
  745. out SPH, r16
  746.  
  747. ldi YL,low(myStackStart)
  748. ldi YH,high(myStackStart)
  749. ldi r16, 0xf9 ;PORTB setup
  750. out DDRB,r16 ;
  751. nop
  752. ldi r16, $ff
  753. out PORTB,r16
  754. .IFDEF testing ;testing = simulating on avrstudio4
  755. nop
  756. rcall burneepromvars ;not needed?
  757.  
  758. .ENDIF
  759. forthloop:
  760. ldi r16, low(RAMEND)
  761. out SPL, r16
  762.  
  763.  
  764. ldi r16,high(RAMEND)
  765. out SPH, r16
  766.  
  767. ldi YL,low(myStackStart)
  768. ldi YH,high(myStackStart)
  769.  
  770. try:
  771. ;--------------------test these------------------
  772. ;rcall dumpbuf1
  773. ;rcall test_dumpbuf1
  774. ;rcall waitForDDump
  775. ;rjmp testOKCR
  776. ;rjmp test_rxStrEndCR
  777. ;rcall test1
  778. ;rjmp test_d16
  779. ;rjmp test_d1617
  780. ;rjmp test_dlowR
  781. ;rjmp test_dhighR
  782. ;rjmp test_dxyz
  783. ;rjmp test_depthcode
  784. ;rjmp test_dotScode
  785. ;rjmp try
  786. .ifdef testing
  787. rcall getline0 ;This is FORTH
  788. .else
  789. rcall serialFill
  790. .endif
  791. ;TODO work out why this isn't working with test1
  792. rcall dumpbuf1 ;TAKE OUT
  793. rcall interpretLine
  794. rcall dumpbuf1
  795. .ifdef testing
  796. nop
  797. quithere:
  798. rjmp quithere ;only want one line interpreted when testing
  799. .else
  800. takemeout 'F'
  801. rjmp forthloop
  802. .endif
  803. ;-------------------------------------------------------
  804.  
  805.  
  806. ;rjmp test_interpretLine
  807. ;rjmp test_cfetch
  808. ;rjmp test_store
  809. ;rjmp test_cstore
  810. ;rjmp test_mpy16s
  811. ;rjmp test_mpy16s0
  812. ;rjmp test_star
  813. ;rjmp test_div16s
  814. ;rjmp test_slashMod
  815. ;rjmp test_Hex4ToBin2
  816. ;rjmp test_interpretLine
  817.  
  818. ;rjmp setupforflashin
  819. ;rcall coloncode
  820. ;rjmp test_buf2ToFlashBuffer
  821. ;rjmp serialTest0
  822. ;zzz
  823.  
  824. stopper: rjmp stopper
  825. ; rjmp start
  826. ;mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  827. mainloop: ;this is forth. This is run continuously. Needs two versions: live and simulation.
  828. ; rcall quit
  829. rcall getline0
  830. rcall interpretLine
  831. ret
  832. ;--------------------------------------------------------------
  833. getline0: ;force a line into buf1 via flash string. Simulates GETLINE
  834. ldi zl, low(typein<<1)
  835. ldi zh, high(typein<<1)
  836. ldi xl, low(buf1)
  837. ldi xh, high(buf1)
  838. type0:
  839. lpm r16,Z+
  840. st x+,r16
  841. cpi r16,0x0d ;have we got to the end of the line?
  842. brne type0
  843. ret
  844. ;--------------------------------------------
  845. ;WORD gets x to point to start of word (copy in w=r24,25) with the length in len = r20
  846. ;assume word points to somewhere in buf1. Should advance thru spaces=0x20 to first real char
  847. word: ;maybe give it a header later
  848. ld SECONDLETTER, x ;for debugging. TODO. Should be firstletter?
  849.  
  850. ld r16,x+ ;get char
  851.  
  852. cpi r16,0x20 ;is it a space?
  853. breq word ;if so get next char
  854. ;if here we're point to word start. so save this adr in w
  855. mov r24,xl
  856. mov r25,xh ;wordstart now saved in w
  857.  
  858.  
  859. clr r20 ;length initially 0
  860. nextchar:
  861. inc r20 ;r20 = word length
  862. ld r16,x+ ;get next char
  863. cpi r16,0x20
  864. brne nextchar
  865. dec r24 ;adjust start of word
  866. ;if here we've found a word.Starting at w length in r20.x points to space just past word
  867. ret
  868. ;----------------------------------------
  869.  
  870. compare: ;given a word in buf1 and a word in the dic are they the same? The word in the dic is pointed to by Z.
  871. ; and the word in buf1 is pointed to by w=r24,25. len = r20. Z on entry points to the link. Needs +2 to
  872. lpm r23,z+
  873. lpm r22,z+ ;store next link in v=r22,23. z now points to len byte
  874.  
  875. startc:
  876. ;TODO save copy of flash word in r21 and also do masking of immediates
  877. push r20 ;save length
  878. lpm r16,Z+ ;length of dictionary word, first entry now in r16
  879. mov r21,r16 ;copy length-in-flash to r21. May have immediate bit (bit 7)
  880. andi r16,$0f ;mask off top nibble before comparing
  881. cp r16,r20 ;same lengths?
  882. brne outcom ;not = so bail out
  883. ;if here the words are the same length, what about the rest of the chars.First get x to point to word.
  884. mov xl,r24
  885. mov xh,r25 ;x now point to start of buf1 word
  886. upcom:
  887. lpm r16,z+
  888. ld r17,x+ ;get one corresponding char from each word
  889. cp r16,r17 ;same word?
  890. brne outcom ;bail out if chars are different
  891. dec r20 ;count chars
  892. brne upcom ;still matching and not finished so keep going
  893. ;if here r20 is 0 so match must have been perfect so FOUND = 1
  894. clr FOUND
  895. inc FOUND
  896. outcom:
  897. pop r20 ;get old lngth of buf1 word back
  898. ret
  899. ;-------------------------------------------
  900. jmpNextWord: ;go to next word in the dictionary. Assume v=r22,23 contains next link word(not byte)
  901. ; and w = r24,25 contains RAM word start with len in r20
  902. ;exit with z pointing to next word ready for next COMPARE.
  903. clc
  904. rol r22
  905. rol r23 ;above 3 instructions change word address into byte address by doubling
  906. movw r30,r22 ;z now points to next word
  907. ret
  908. ;-----------------------------------------
  909.  
  910. doLatest: ;set up so first jump in dictionary is to top=LATEST and other flags set up.
  911. ; ldi vl, low(LATEST)
  912. ; ldi vh, high(LATEST)
  913. nop
  914. rcall getlatest ;from eeprom. Now on stack
  915. mypop2 vh,vl ;this is in bytes Need to halve it.
  916. ; rcall halve
  917. clr FOUND
  918. clr BOTTOM ;not yet found the match, not yet at the bottom. Either will stop search.
  919. clr STOP ;keep parsing words til this goes to a 1
  920. ret
  921. ;---------------------------------------------
  922. interpretLine: ;given line of words in buf one, search for words one by one. Don't do code
  923. ; or compile at this stage, just find and report that and go into next one.
  924. ; rcall getline0 ;change later to real getline via terminal
  925.  
  926. rcall pasteEOL
  927. ;takemeout '2'
  928.  
  929. ldi xl, low(buf1)
  930. ldi xh,high(buf1) ;last 3 statemnts are done onece. Now the main loop.
  931. clr FOUNDCOUNTER ;counts finds in line parsing.
  932.  
  933. nextWord:
  934. rcall dlowR
  935.  
  936. tst STOP
  937.  
  938. brne stopLine
  939. takemeout 'S'
  940. nop
  941. rcall word
  942. takemeout 'w'
  943. rcall findWord
  944. takemeout 'F'
  945. ;not done yet
  946. rcall dealWithWord ;go and run code STATE=0, or compile (STATE =1).{ c0de, comp1le}
  947. rjmp nextWord
  948. stopLine:
  949. takemeout 'E'
  950. ret
  951. ;-----------------------------------------------------------------
  952. findWord:
  953. rcall doLatest
  954. nop
  955. ;rcall dumpbuf1
  956.  
  957. upjmpf:
  958. rcall jmpNextWord
  959. takemeout 'f'
  960.  
  961. rcall compare
  962. tst FOUND
  963. brne stopsearchf ;if last compare got a match (FOUND=1) then stop searching
  964. tst vl
  965. brne upjmpf ;if v=0000 then we've hit the bottom of the dictionary
  966. tst vh
  967. brne upjmpf ;not found and not at bottom so keep going
  968. ;if here FOUND =0, ie no match yet and we've hit the bottom of the dictionary
  969. clr BOTTOM
  970. inc BOTTOM ;exit with FOUND=0 and BOTTOM =1
  971. stopsearchf:
  972. nop
  973. ret
  974. ;----------------------------
  975. test_interpretLine:
  976. rcall interpretLine
  977. til: rjmp til ;** with r24 pointing to 'S' and FOUND = r15 =1
  978. ;------------------------------
  979. dealWithWord: ;come here when it's time to compile or run code
  980. ;Good debugging spot. Enter here with Z pointing to CFA of word found. Y points to myStack. X points to just
  981. ; past the word we are seeking (w-s). r10 is 2nd letter of w-s. w = start adr of w-s. v is a link
  982. ; to the next word in dic. Either just below the found word or 0000 if we get to the bottome with no match
  983. ;
  984. nop
  985. tst FOUND
  986. breq notfound
  987. inc FOUNDCOUNTER
  988.  
  989. ;want to hop over filler bytes,0's added to keep codes on even byte boundaries
  990. ; so if r30 is odd at this stage inc it. odd is lsbit = 1.
  991. sbrs r30,0 ;skip next instruction if final bit lsb = 1
  992. rjmp downd
  993. ;if here lsb = 1 so we're on a padding byte and have to add 1 to get to a 2 byte boundary
  994. inc r30
  995. brcc downd
  996. inc r31 ;add one to z before converting to bytes
  997. ;have to ask at this point, is the word immediate? If so, bit 7 of r21 will be set.
  998. downd:
  999. sbrs r21,7
  1000. rjmp downdw ;not immediate so just go on with STATE test
  1001. rjmp executeme ;yes, immediate so execute every time.
  1002.  
  1003.  
  1004. downdw: tst STATE
  1005. breq executeme
  1006. rcall compilecode
  1007. rjmp outdww
  1008. executeme:
  1009. clc
  1010. ror zh
  1011. ror zl ;put z back into word values
  1012.  
  1013.  
  1014. rcall executeCode
  1015.  
  1016.  
  1017.  
  1018. .MESSAGE "Word found"
  1019. rjmp outdww
  1020. notfound:
  1021. nop
  1022. ; .MESSAGE "Word not found"
  1023. ; clr STOP
  1024. ; inc STOP ;stop parsing line
  1025. rcall numberh ; word not in dict so must be a number? Form = HHHH
  1026. ;now have to add 3 to x so it points past this word ready not next one
  1027. clc
  1028. inc r26
  1029. inc r26
  1030. inc r26
  1031. brcc outdww
  1032. inc r27 ;but only if overflow
  1033. nop
  1034. outdww:
  1035. ret ;with STOP =1 in not a number
  1036. ;------------------------------------------------------------------------
  1037. pasteEOL: ;when a line of text is TYPEd into buf1 it should end with CR=$0d. This gets replaced with ]}, a
  1038. ; special end of line word. When the word is invoked it casues a QUIT back to the waiting for input stage.
  1039. ; Start at buf1 start and inspect each char for a $0D. When found replace with a "$20 S $20 "
  1040.  
  1041. ldi xl, low(buf1)
  1042. ldi xh, high(buf1) ;pnt to start of buffer
  1043. clr r17
  1044. nxtChar:
  1045. inc r17 ;r17 is counter. Bail out when r17 > BUF1LENGTH
  1046. cpi r17, BUF1LENGTH -3
  1047. breq outProb
  1048. ld r16, x+
  1049. cpi r16, $0d
  1050. brne nxtChar
  1051. ;if here we've found a $0d in buf1 before the end, so replace with an EOL token. x points to just after it.
  1052. ldi r16,$20
  1053. st -x, r16 ;back up. Then go forward.
  1054. TAKEMEOUT 'p'
  1055. ; ldi r16, ']'
  1056. ldi r16,$20 ;This took about 4 day's work to insert this line. Why is it needed?
  1057. st x+, r16
  1058. ldi r16,'S'
  1059. st x+, r16
  1060. ; ldi r16, '}'
  1061. ; st x+, r16
  1062. ldi r16, $20
  1063. st x, r16
  1064. rjmp outpel
  1065.  
  1066.  
  1067. outProb:
  1068. takemeout 'O'
  1069. nop
  1070. .MESSAGE "Couldn't find $0d"
  1071. outpel:
  1072. ret
  1073.  
  1074. ;-------------------------------------
  1075. executeCode: ;with Z pointing to cfa. Not sure whether to jmp or call
  1076.  
  1077. ijmp
  1078. ret
  1079. ;---------------------------------------
  1080. test_fetch: ;do run thru of @
  1081. rcall getline0 ;change later to real getline via terminal
  1082. rcall pasteEOL
  1083. ldi xl, low(buf1)
  1084. ldi xh,high(buf1) ;last 3 statemnts are done onece. Now the main loop.
  1085.  
  1086. ldi r16,$62
  1087. mypush r16
  1088. ldi r16,$0
  1089. mypush r16 ;should now have adr $0062 on mystack
  1090. rcall fetch
  1091. tf1:
  1092. rjmp tf1
  1093. ;---------------------------------
  1094. test_cfetch: ;do run thru of @
  1095. rcall getline0 ;change later to real getline via terminal
  1096. rcall pasteEOL
  1097. ldi xl, low(buf1)
  1098. ldi xh,high(buf1) ;last 3 statemnts are done onece. Now the main loop.
  1099.  
  1100. ldi r16,$62
  1101. mypush r16
  1102. ldi r16,$0
  1103. mypush r16 ;should now have adr $62 on mystack
  1104. rcall cfetch
  1105. tcf1:
  1106. rjmp tcf1
  1107. ;----------------------------
  1108. test_store:
  1109. rcall getline0 ;change later to real getline via terminal
  1110. rcall pasteEOL
  1111. ldi xl, low(buf1)
  1112. ldi xh,high(buf1) ;last 3 statemnts are done onece. Now the main loop.
  1113. ldi r16,$62
  1114. ldi r17,$0
  1115. mypush2 r16,r17 ;should now have adr $62 on mystack
  1116. ldi r16, $AB
  1117. ldi r17, $CD
  1118. mypush2 r16,r17 ;now have $ABCD on mystack
  1119. rcall store
  1120. ts1:
  1121. rjmp ts1
  1122. ;------------------------
  1123. test_cstore:
  1124. rcall getline0 ;change later to real getline via terminal
  1125. rcall pasteEOL
  1126. ldi xl, low(buf1)
  1127. ldi xh,high(buf1) ;last 3 statemnts are done onece. Now the main loop.
  1128. ldi r16,$62
  1129. ldi r17,$0
  1130. mypush2 r16,r17 ;should now have adr $62 on mystack
  1131. ldi r16, $AB
  1132. ; ldi r17, $CD
  1133. mypush r16 ;now have $ABCD on mystack
  1134. rcall cstore
  1135.  
  1136. ts11:
  1137. rjmp ts11
  1138. ;Now put arith routines here. Are from AVR200. Just using 16*16 for * but get 32bit result.
  1139.  
  1140.  
  1141. ;***************************************************************************
  1142. ;*
  1143. ;* "mpy16s" - 16x16 Bit Signed Multiplication
  1144. ;*
  1145. ;* This subroutine multiplies signed the two 16-bit register variables
  1146. ;* mp16sH:mp16sL and mc16sH:mc16sL.
  1147. ;* The result is placed in m16s3:m16s2:m16s1:m16s0.
  1148. ;* The routine is an implementation of Booth's algorithm. If all 32 bits
  1149. ;* in the result are needed, avoid calling the routine with
  1150. ;* -32768 ($8000) as multiplicand
  1151. ;*
  1152. ;* Number of words :16 + return
  1153. ;* Number of cycles :210/226 (Min/Max) + return
  1154. ;* Low registers used :None
  1155. ;* High registers used :7 (mp16sL,mp16sH,mc16sL/m16s0,mc16sH/m16s1,
  1156. ;* m16s2,m16s3,mcnt16s)
  1157. ;*
  1158. ;***************************************************************************
  1159.  
  1160. ;***** Subroutine Register Variables
  1161.  
  1162. .def mc16sL =r16 ;multiplicand low byte
  1163. .def mc16sH =r17 ;multiplicand high byte
  1164. .def mp16sL =r18 ;multiplier low byte
  1165. .def mp16sH =r19 ;multiplier high byte
  1166. .def m16s0 =r18 ;result byte 0 (LSB)
  1167. .def m16s1 =r19 ;result byte 1
  1168. .def m16s2 =r20 ;result byte 2
  1169. .def m16s3 =r21 ;result byte 3 (MSB)
  1170. .def mcnt16s =r22 ;loop counter
  1171.  
  1172. ;***** Code
  1173. mpy16s: clr m16s3 ;clear result byte 3
  1174. sub m16s2,m16s2 ;clear result byte 2 and carry
  1175. ldi mcnt16s,16 ;init loop counter
  1176. m16s_1: brcc m16s_2 ;if carry (previous bit) set
  1177. add m16s2,mc16sL ; add multiplicand Low to result byte 2
  1178. adc m16s3,mc16sH ; add multiplicand High to result byte 3
  1179. m16s_2: sbrc mp16sL,0 ;if current bit set
  1180. sub m16s2,mc16sL ; sub multiplicand Low from result byte 2
  1181. sbrc mp16sL,0 ;if current bit set
  1182. sbc m16s3,mc16sH ; sub multiplicand High from result byte 3
  1183. asr m16s3 ;shift right result and multiplier
  1184. ror m16s2
  1185. ror m16s1
  1186. ror m16s0
  1187. dec mcnt16s ;decrement counter
  1188. brne m16s_1 ;if not done, loop more
  1189. ret
  1190. ;----------------------------------------------------------
  1191. ;***** Multiply Two Signed 16-Bit Numbers (-12345*(-4321))
  1192. test_mpy16s:
  1193. ldi mc16sL,low(-12345)
  1194. ldi mc16sH,high(-12345)
  1195. ldi mp16sL,low(-4321)
  1196. ldi mp16sH,high(-4321)
  1197. rcall mpy16s ;result: m16s3:m16s2:m16s1:m16s0
  1198. ;=$032df219 (53,342,745)
  1199. tmpy: rjmp tmpy
  1200.  
  1201. test_mpy16s0:
  1202. ldi mc16sL,low(123)
  1203. ldi mc16sH,high(123)
  1204. ldi mp16sL,low(147)
  1205. ldi mp16sH,high(147)
  1206. rcall mpy16s ;result: m16s3:m16s2:m16s1:m16s0
  1207. tmpy0: rjmp tmpy0
  1208. ;-----------------------
  1209. test_star:
  1210. ldi r16,-$7b
  1211. mypush r16
  1212. ldi r16,$00
  1213. mypush r16 ;that's decimal 123 on stack
  1214. ldi r16,$93
  1215. mypush r16
  1216. ldi r16,$00
  1217. mypush r16 ; and thats dec'147
  1218. rcall star
  1219. tsr: rjmp tsr
  1220.  
  1221. ;--------------------------
  1222. ;***************************************************************************
  1223. ;*
  1224. ;* "div16s" - 16/16 Bit Signed Division
  1225. ;*
  1226. ;* This subroutine divides signed the two 16 bit numbers
  1227. ;* "dd16sH:dd16sL" (dividend) and "dv16sH:dv16sL" (divisor).
  1228. ;* The result is placed in "dres16sH:dres16sL" and the remainder in
  1229. ;* "drem16sH:drem16sL".
  1230. ;*
  1231. ;* Number of words :39
  1232. ;* Number of cycles :247/263 (Min/Max)
  1233. ;* Low registers used :3 (d16s,drem16sL,drem16sH)
  1234. ;* High registers used :7 (dres16sL/dd16sL,dres16sH/dd16sH,dv16sL,dv16sH,
  1235. ;* dcnt16sH)
  1236. ;*
  1237. ;***************************************************************************
  1238.  
  1239. ;***** Subroutine Register Variables
  1240.  
  1241. .def d16s =r13 ;sign register
  1242. .def drem16sL=r14 ;remainder low byte
  1243. .def drem16sH=r15 ;remainder high byte
  1244. .def dres16sL=r16 ;result low byte
  1245. .def dres16sH=r17 ;result high byte
  1246. .def dd16sL =r16 ;dividend low byte
  1247. .def dd16sH =r17 ;dividend high byte
  1248. .def dv16sL =r18 ;divisor low byte
  1249. .def dv16sH =r19 ;divisor high byte
  1250. .def dcnt16s =r20 ;loop counter
  1251.  
  1252. ;***** Code
  1253.  
  1254. div16s: ;push r13 ;PB !!
  1255. ;push r14 ;PB !!
  1256. mov d16s,dd16sH ;move dividend High to sign register
  1257. eor d16s,dv16sH ;xor divisor High with sign register
  1258. sbrs dd16sH,7 ;if MSB in dividend set
  1259. rjmp d16s_1
  1260. com dd16sH ; change sign of dividend
  1261. com dd16sL
  1262. subi dd16sL,low(-1)
  1263. sbci dd16sL,high(-1)
  1264. d16s_1: sbrs dv16sH,7 ;if MSB in divisor set
  1265. rjmp d16s_2
  1266. com dv16sH ; change sign of divisor
  1267. com dv16sL
  1268. subi dv16sL,low(-1)
  1269. sbci dv16sL,high(-1)
  1270. d16s_2: clr drem16sL ;clear remainder Low byte
  1271. sub drem16sH,drem16sH;clear remainder High byte and carry
  1272. ldi dcnt16s,17 ;init loop counter
  1273.  
  1274. d16s_3: rol dd16sL ;shift left dividend
  1275. rol dd16sH
  1276. dec dcnt16s ;decrement counter
  1277. brne d16s_5 ;if done
  1278. sbrs d16s,7 ; if MSB in sign register set
  1279. rjmp d16s_4
  1280. com dres16sH ; change sign of result
  1281. com dres16sL
  1282. subi dres16sL,low(-1)
  1283. sbci dres16sH,high(-1)
  1284. d16s_4: ;pop r14 ;PB!!
  1285. ;pop r13 ;PB!!
  1286. ret ; return
  1287. d16s_5: rol drem16sL ;shift dividend into remainder
  1288. rol drem16sH
  1289. sub drem16sL,dv16sL ;remainder = remainder - divisor
  1290. sbc drem16sH,dv16sH ;
  1291. brcc d16s_6 ;if result negative
  1292. add drem16sL,dv16sL ; restore remainder
  1293. adc drem16sH,dv16sH
  1294. clc ; clear carry to be shifted into result
  1295. rjmp d16s_3 ;else
  1296. d16s_6: sec ; set carry to be shifted into result
  1297. rjmp d16s_3
  1298.  
  1299. ;-----------------------------------------------
  1300.  
  1301. test_div16s:
  1302. ;***** Divide Two Signed 16-Bit Numbers (-22,222/10)
  1303. ldi dd16sL,low(-22222)
  1304. ldi dd16sH,high(-22222)
  1305. ldi dv16sL,low(10)
  1306. ldi dv16sH,high(10)
  1307. rcall div16s ;result: $f752 (-2222)
  1308. ;remainder: $0002 (2)
  1309.  
  1310. forever:rjmp forever
  1311. ;----------------------------------
  1312. test_slashMod:
  1313. ldi r16,$12
  1314. mypush r16
  1315. ldi r16,$34
  1316. mypush r16
  1317. ldi r16,$56 ;NB this is $3412 not $1234
  1318. mypush r16
  1319. ldi r16,$00
  1320. mypush r16
  1321. rcall slashMod ;$3412 / $56 = $9b rem 0 works
  1322. tslm: rjmp tslm
  1323.  
  1324. ;---------------------------------------
  1325. ;From http://www.avr-asm-tutorial.net/avr_en/calc/CONVERT.html#hex2bin
  1326. ; Hex4ToBin2
  1327. ; converts a 4-digit-hex-ascii to a 16-bit-binary
  1328. ; In: Z points to first digit of a Hex-ASCII-coded number
  1329. ; Out: T-flag has general result:
  1330. ; T=0: rBin1H:L has the 16-bit-binary result, Z points
  1331. ; to the first digit of the Hex-ASCII number
  1332. ; T=1: illegal character encountered, Z points to the
  1333. ; first non-hex-ASCII character
  1334. ; Used registers: rBin1H:L (result), R0 (restored after
  1335. ; use), rmp
  1336. ; Called subroutines: Hex2ToBin1, Hex1ToBin1
  1337.  
  1338. .def rBin1H =r17
  1339. .def rBin1L = r16
  1340. .def rmp = r18
  1341. ;
  1342. Hex4ToBin2:
  1343. clt ; Clear error flag
  1344. rcall Hex2ToBin1 ; convert two digits hex to Byte
  1345. brts Hex4ToBin2a ; Error, go back
  1346. mov rBin1H,rmp ; Byte to result MSB
  1347. rcall Hex2ToBin1 ; next two chars
  1348. brts Hex4ToBin2a ; Error, go back
  1349. mov rBin1L,rmp ; Byte to result LSB
  1350. sbiw ZL,4 ; result ok, go back to start
  1351. Hex4ToBin2a:
  1352. ret
  1353. ;
  1354. ; Hex2ToBin1 converts 2-digit-hex-ASCII to 8-bit-binary
  1355. ; Called By: Hex4ToBin2
  1356. ;
  1357. Hex2ToBin1:
  1358. push R0 ; Save register
  1359. rcall Hex1ToBin1 ; Read next char
  1360. brts Hex2ToBin1a ; Error
  1361. swap rmp; To upper nibble
  1362. mov R0,rmp ; interim storage
  1363. rcall Hex1ToBin1 ; Read another char
  1364. brts Hex2ToBin1a ; Error
  1365. or rmp,R0 ; pack the two nibbles together
  1366. Hex2ToBin1a:
  1367. pop R0 ; Restore R0
  1368. ret ; and return
  1369. ;
  1370. ; Hex1ToBin1 reads one char and converts to binary
  1371. ;
  1372. Hex1ToBin1:
  1373. ld rmp,z+ ; read the char
  1374. subi rmp,'0' ; ASCII to binary
  1375. brcs Hex1ToBin1b ; Error in char
  1376. cpi rmp,10 ; A..F
  1377. brcs Hex1ToBin1c ; not A..F
  1378. cpi rmp,$30 ; small letters?
  1379. brcs Hex1ToBin1a ; No
  1380. subi rmp,$20 ; small to capital letters
  1381. Hex1ToBin1a:
  1382. subi rmp,7 ; A..F
  1383. cpi rmp,10 ; A..F?
  1384. brcs Hex1ToBin1b ; Error, is smaller than A
  1385. cpi rmp,16 ; bigger than F?
  1386. brcs Hex1ToBin1c ; No, digit ok
  1387. Hex1ToBin1b: ; Error
  1388. sbiw ZL,1 ; one back
  1389. set ; Set flag
  1390. Hex1ToBin1c:
  1391. ret ; Return
  1392. ;--------------------------------------
  1393. test_Hex4ToBin2:
  1394. pushz
  1395. ldi zl,$60
  1396. clr zh ;z now points to start of buf1
  1397. ldi r16,'0'
  1398. st z+,r16
  1399. ldi r16,'f'
  1400. st z+,r16
  1401. ldi r16,'2'
  1402. st z+,r16
  1403. ldi r16,'3'
  1404. st z+,r16
  1405. ldi zl,$60
  1406. clr zh ;z now points back to start of buf1
  1407. rcall Hex4ToBin2
  1408. popz
  1409. th4: rjmp th4
  1410. ;-------------------------------------
  1411. numberh: ;word not in dictionary. Try to convert it to hex.
  1412. pushz ;algorithm uses z, pity
  1413. movw zl,r24 ;r4,25 = w holds start of current word
  1414. ;z now points eg to '12ab'start. If t=0 then it coverts to real hex
  1415. rcall hex4ToBin2 ;try to convert
  1416. ;above call needs 4 hex digits to emerge with t=0 and binary in r16,17
  1417. ;want this. If t=0 stack r16,17 and carry on interpreting, else emerge with
  1418. ; t=1 and zpointing to first problem char
  1419. brtc gotHex
  1420. ; if here there's a problem that z is pointing to. Bail out of interpret line
  1421. clr STOP
  1422. inc STOP
  1423. rjmp outnh
  1424.  
  1425. gotHex: ;sucess.Real hex in r16,17
  1426. mypush2 r16,r17 ; so push num onto mystack
  1427. ;maybe we're compiling. If so, push num into dic preceded by a call to stackme_2
  1428. tst STATE
  1429. breq outnh ;STATE =0 means executing
  1430. ; rcall tic
  1431. ; .db "stackme_2" ;has to be in dic before a number. cfa of stackme_2 on stack
  1432. rcall compstackme_2
  1433. ; rcall compileme ;insert "rcall stackme_2"opcode into dic
  1434. rcall comma ;there's the number going in
  1435.  
  1436. outnh:
  1437. popz ; but will it be pointing to "right"place in buf1? Yes now OK
  1438.  
  1439. ret
  1440. ; numberh not working fully, ie doesn't point to right place after action.
  1441. ; also no action if not a number? DONE better save this first.
  1442. ;---------------------------------
  1443. ;eeroutines
  1444. eewritebyte: ;write what's in r16 to eeprom adr in r18,19
  1445. sbic EECR,EEPE
  1446. rjmp eewritebyte ;keep looping til ready to write
  1447. ;if here the previous write is all done and we can write the next byte to eeprom
  1448. out EEARH,r19
  1449. out EEARL,r18 ;adr done
  1450. out EEDR,r16 ;byte in right place now
  1451. sbi EECR,EEMPE
  1452. sbi EECR,EEPE ;last 2 instruc write eprom. Takes 3.4 ms
  1453. ret
  1454. ;test with %!
  1455. ;---------------------------------
  1456. eereadbyte: ; read eeprom byte at adr in r18,19 into r16
  1457. ; Wait for completion of previous write
  1458. sbic EECR,EEPE
  1459. rjmp eereadbyte
  1460. ; Set up address (r18:r17) in address register
  1461. out EEARH, r19
  1462. out EEARL, r18
  1463. ; Start eeprom read by writing EERE
  1464. sbi EECR,EERE
  1465. ; Read data from data register
  1466. in r16,EEDR
  1467. ret
  1468. ;------------------------------
  1469. setupforflashin: ;using here etc get appropriate page, offset,myhere values.
  1470. ldi r16,low(HERE)
  1471. ldi r17,high(HERE) ;get here, but from eeprom better?
  1472. mypush2 r16,r17
  1473. rcall stackme_2
  1474. .dw 0002
  1475. rcall star ;now have current HERE in bytes in flash. But what is myhere?
  1476. rcall stackme_2
  1477. .db $0040 ;64 bytes per page
  1478. rcall slashMod
  1479. ;offset on top pagenum under. eg pg 0047, offset 0012
  1480. mypop2 r9,r8 ;store offset (in bytes)
  1481. rcall stackme_2
  1482. .db $0040
  1483. rcall star ;pgnum*64 = byte adr of start of flash page
  1484. mypop2 r7,r6
  1485. mypush2 r8,r9 ;push back offset
  1486. rcall stackme_2
  1487. .dw buf2
  1488. nop
  1489. ;at this stage we have offset in r8,r9 (0012). Also byte adr of flash page
  1490. ; start in r6,r7.(11c0) Stk is (offset buf2Start --) (0012 00E0 --). Need to
  1491. ; add these two together to get myhere, the pointer to RAM here position.
  1492. rcall plus ;add offset to buf2 start to get myhere (00f2)
  1493. ; put my here in r4,r5 for time being.
  1494. mypop2 r5,r4 ;contains eg 00f2 <--myhere
  1495. pushz ;going to use z so save it
  1496. movw zl,r6 ;r6,7 have byte adr of flsh pg strt
  1497. pushx ;save x
  1498. ldi xl,low(buf2)
  1499. ldi xh,high(buf2) ;point x to start of buf2
  1500. ldi r18,128 ;r18=ctr. Two flash pages = 128 bytes
  1501. upflash:
  1502. lpm r16,z+ ;get byte from flash page
  1503. st x+, r16 ; and put into buf2
  1504. dec r18
  1505. brne upflash
  1506. ;done. Now have two flash pages in ram in buf2. Myhere points to where next
  1507. ; entry will go. Where's page num?
  1508. popx
  1509. popz ;as if nothing happened
  1510.  
  1511.  
  1512. ret
  1513.  
  1514.  
  1515.  
  1516. ;outsufi: rjmp outsufi
  1517. ;-----------------------------------
  1518. burneepromvars: ;send latest versions of eHERE and eLATEST to eeprom
  1519. ldi r16,low(HERE)
  1520. ldi r17,high(HERE)
  1521. mypush2 r16,r17
  1522. ;up top we have .equ eHERE = $0010
  1523. ldi r16,low(eHERE)
  1524. ldi r17,high(eHERE)
  1525. mypush2 r16,r17
  1526. ;now have n16 eadr on stack ready for e!
  1527. rcall percentstore
  1528.  
  1529. ;send latest versions of eLATEST to eeprom
  1530. ldi r16,low(LATEST)
  1531. ldi r17,high(LATEST)
  1532. mypush2 r16,r17
  1533. ;up top we have .equ eLATEST = $0010
  1534. ldi r16,low(eLATEST)
  1535. ldi r17,high(eLATEST)
  1536. mypush2 r16,r17
  1537. ;now have n16 eadr on stack ready for e!
  1538. rcall percentstore
  1539. ret
  1540. ;-------------------------------------------
  1541. coloncode: ;this is the classic colon defining word.
  1542. rcall setupforflashin ;get all the relevant vars and bring in flash to buf2
  1543. rcall relinkcode ; insert link into first cell
  1544. rcall create ;compile word preceeded by length
  1545. rcall leftbrac ;set state to 1, we're compiling
  1546. ret ;now every word gets compiled until we hit ";"
  1547. ;-------------------------
  1548. relinkcode: ;put LATEST into where myhere is pointing and update ptr = myhere
  1549. ;also create mylatest
  1550. rcall getlatest ;now on stack
  1551. mypopa ;latest in r16,17
  1552. pushz ;better save z
  1553. movw mylatest,myhere ;mylatest <-- myhere
  1554. movw zl,myhere ;z now points to next available spot in buf2
  1555. st z+,r17 ;problem. Don't work unless highbye first in mem.Why?
  1556. st z+,r16 ;now have new link in start of dic word
  1557. movw myhere,zl ;update myhere to point to length byte. (Not yet there.)
  1558. popz ;restore z
  1559. ret
  1560. ;-------------------------------------------------
  1561. create: ;put word after ":" into dictionary, aftyer link, preceeded by len
  1562. rcall word ;start with x pnting just after ":".End with len in r20, x pointing to
  1563. ; space just after word and start of word in w=r24,25
  1564. pushz ;save z. It's going to be used on ram dictionary
  1565. movw zl,myhere ;z now pnts to next spot in ram dic
  1566. st z+,r20 ; put len byte into ram dic
  1567. mov r18,r20 ;use r18 as ctr, don't wreck r20
  1568. pushx ;save x. It's going to be word ptr in buf1
  1569. movw xl,wl ;x now points to start of word. Going to be sent to buf2
  1570. sendbytes:
  1571. ld r16,x+ ;tx byte from buf1 to
  1572. st z+,r16 ; buf2
  1573. dec r18 ;repeat r20=r18=len times
  1574. brne sendbytes
  1575.  
  1576. sbrs r30,0 ;skip next instruction if final bit lsb = 1
  1577. rjmp downcr
  1578. ;if here lsb = 1 so we're on a padding byte and have to add 1 to get to a 2 byte boundary
  1579. clr r16
  1580. st z+,r16 ;insert padding byte
  1581. ;inc r30
  1582. ;brcc downcr
  1583. ;inc r31 ;add one to z before converting to bytes
  1584.  
  1585. downcr:
  1586. movw myhere,zl ;myhere now points to beyond word in dic
  1587. popx
  1588. popz
  1589. ret ;with word in dic
  1590. ;----------------------------------------------
  1591. leftbrac: ;classic turn on compiling
  1592. clr STATE
  1593. inc STATE ;state =1 ==> now compiling
  1594. ret
  1595. ;------------------------
  1596. compilecode: ;come here with STATE =1 ie compile, not execute. Want to put
  1597. ; eg rcall dup in code in dictionary but not to execute dup. If here
  1598. ; z points to byte address of word
  1599. mypush2 zl,zh
  1600. compileme:
  1601. mypush2 myhere,r5 ;push ptr to RAM dic
  1602. ;next is entry point for eg ' stackme2 already on stack and have to compile
  1603.  
  1604. ldi r16,low(buf2)
  1605. ldi r17,high(buf2) ;start of buf that conatins flash pg in RAM
  1606. mypush2 r16,r17
  1607. rcall minus ; myhere - buf2-start = offset in page
  1608. mypush2 SOFPG,r7 ;push start of flash page address
  1609. rcall plus ;SOFPG + offset = adr of next rcall in dic
  1610. ;if here we have two flash addresses on the stack. TOS = here. Next is there.
  1611. ;want to insert code for "rcall there w"hen I'm at here. eg current debugging indicates
  1612. ; here = $11EB and there is $1012 (cfa of "two"). First compute
  1613. ; relative branch "there - here -2". Then fiddle this val into the rcall opcode
  1614. rcall minus ;that;s there - here. Usu negative.
  1615. ;I got fffffffff..ffe27 for above vals. First mask off all those f's
  1616. rcall two ;stack a 2
  1617. rcall minus ;now have there-here -2 = fe24. When there,here in bytes.
  1618. mypopa ;bring fe26 into r16,17
  1619. clc
  1620. ror r17
  1621. ror r16 ;now a:= a/2
  1622. ldi r18,$ff
  1623. ldi r19,$0f ;mask
  1624. and r16,r18
  1625. and r17,r19
  1626. ; mypush2 r16,r17 ;now fe26 --> 0e26
  1627. ;the rcall opcode is Dxxx where xxx is the branch
  1628. ; mypopa ;bring fe26 into r16,17
  1629. ldi r19, $d0 ;mask
  1630. or r17,r19
  1631. mypush2 r16,r17 ;now have $de26 on stack which is (?) rcall two
  1632. rcall comma ;store this opcode into dic. myhere is ptr
  1633. ret
  1634. ;---------------------------
  1635. stackme_2: ;stacks on my stack next 16bit num. Address of 16bit number is on SP-stack
  1636. ; Used like this stackme_2 0034. Puts 0034 on myStack and increments past number on return stack.
  1637. pop r17
  1638. pop r16 ; they now contain eg 0x0804 which contain the 16bit num
  1639. movw zl,r16 ;z now points to cell that cobtains the number
  1640. clc
  1641. rol zl
  1642. rol zh ;double word address for z. lpm coming up
  1643.  
  1644.  
  1645.  
  1646. lpm r16,z+
  1647. lpm r17,z+ ;now have 16bit number in r16,17
  1648.  
  1649. st y+,r16
  1650. st y+, r17 ;mystack now contains the number
  1651.  
  1652. clc
  1653. ror zh
  1654. ror zl ;halve the z pointer to step past the number to return at the right place
  1655.  
  1656. push zl
  1657. push zh
  1658.  
  1659. ret
  1660. ;------------------------------flash write section--------------------
  1661.  
  1662. do_spm:
  1663. ;lds r16,SPMCSR
  1664. in r16,SPMCSR
  1665. andi r16,1
  1666. cpi r16,1
  1667. breq do_spm
  1668. mov r16,spmcsr_val
  1669. out SPMCSR,r16
  1670. spm
  1671. ret
  1672. ;-------------------------------------------------------------------
  1673. buf2ToFlashBuffer: ;send the 64 bytes, 32 words to flash page <-- Z pnts there.
  1674. push r30 ;save for later spm work.
  1675. push r19
  1676. push xl
  1677. push xh ;used as buf_ctr but may interfere with other uses
  1678. ldi XL,low(buf2) ;X pnts to buf1 that contains the 64 bytes.
  1679. ldi XH, high(buf2)
  1680. ;assume Z is already pointing to correct flash start of page.
  1681. flashbuf:
  1682. ldi buf_ctr,32 ;send 32 words
  1683. sendr0r1:
  1684. ld r16, x+ ;get first byte
  1685. mov r0,r16 ; into r0
  1686. ld r16, x+ ; and get the second of the pair into
  1687. mov r1,r16 ; into r1
  1688. ldi spmcsr_val,01 ;set up for write into spare buffer flash page
  1689. rcall do_spm ;that's r0,r1 gone in.
  1690. inc r30
  1691. inc r30
  1692. dec buf_ctr ;done 32 times?
  1693. brne sendr0r1
  1694. pop xh
  1695. pop xl
  1696. pop r19 ;dont need buf_ctr any more.
  1697. pop r30 ;for next spm job
  1698.  
  1699. ret
  1700. ;--------------------------------------------------------------------------
  1701. ;TODO just have 1 burn routine with buf different
  1702. buf3ToFlashBuffer: ;send the 64 bytes, 32 words to flash page <-- Z pnts there.
  1703. push r30 ;save for later spm work.
  1704. push r19 ;used as buf_ctr but may interfere with other uses
  1705. push xl
  1706. push xh
  1707. ldi XL,low(buf2+64) ;X pnts to buf1 that contains the 64 bytes.
  1708. ldi XH, high(buf2+64)
  1709. ;assume Z is already pointing to correct flash start of page.
  1710. rjmp flashbuf
  1711. ldi buf_ctr,32 ;send 32 words
  1712. sendr0r3:
  1713. ld r16, x+ ;get first byte
  1714. mov r0,r16 ; into r0
  1715. ld r16, x+ ; and get the second of the pair into
  1716. mov r1,r16 ; into r1
  1717. ldi spmcsr_val,01 ;set up for write into spare buffer flash page
  1718. rcall do_spm ;that's r0,r1 gone in.
  1719. inc r30
  1720. inc r30
  1721. dec buf_ctr ;done 32 times?
  1722. brne sendr0r3
  1723. pop r19 ;dont need buf_ctr any more.
  1724. pop r30 ;for next spm job
  1725. ret
  1726.  
  1727. erasePage: ; assume Z points to start of a flash page. Erase it.
  1728. ldi spmcsr_val,0x03 ;this is the page erase command
  1729. rcall do_spm
  1730. ret
  1731. ;------------------------------------------------------------------
  1732. writePage:
  1733. ldi spmcsr_val, 0x05 ;command that writes temp buffer to flash. 64 bytes
  1734. rcall do_spm
  1735. nop ; page now written. z still points to start of this page
  1736. ret
  1737. ;---------------------------------------------------------------
  1738. test_buf2ToFlashBuffer: ;(adr_flashbufstartinBytes -- )
  1739. ; rcall fillBuf
  1740. ; ldi ZH, $10
  1741. ; ldi ZL,$c0 ;z=$01c0. Start of page 67.
  1742. rcall gethere
  1743. rcall double ;want bytes not words for flash adr
  1744. mypopa ;flashPgStart byte adr now in r16,17
  1745.  
  1746.  
  1747. movw zl,r16 ;z <--start of flash buffer
  1748. rcall erasePage
  1749. rcall buf2ToFlashBuffer
  1750. rcall writePage
  1751. herettt:
  1752. rjmp herettt
  1753. ;----------------------
  1754. ; burnbuf2. Come here from ";". The pair r6,r7 point to start of flash pg (bytes)
  1755. burnbuf2and3:
  1756. movw zl,r6 ;z now pnts to start of flash buf
  1757. rcall erasePage
  1758. rcall buf2ToFlashBuffer
  1759. rcall writePage
  1760. ;now going to burn next ram buffer to next flash page. Bump Z by 64 bytes.
  1761. adiw zh:zl,63 ;z now points to start of next flash buffer
  1762. lpm r16,z+ ;advance z pointer by one.adiw only lets max of 63 to be added.
  1763. ;now z points to start of next 64 byte buffer. Time to put buf3 into it.
  1764. rcall erasePage
  1765. rcall buf3ToFlashBuffer
  1766. rcall writePage
  1767. ret
  1768. heret:
  1769. rjmp heret
  1770. ;-------------------------------------------------------------
  1771. updatevars: ;after doing a colon def we have to update sys vars
  1772. ;TODO new version of LATEST is just old version of HERE.
  1773. ;TODO rplace all this code with updatevars2
  1774. ; just shif HERE into LATEST in eeprom to update. Gen. tidy required.
  1775. mypush2 r4,r5 ;put myhere on stack (E8)
  1776. ldi r16,low(buf2)
  1777. ldi r17,high(buf2)
  1778. mypush2 r16,r17 ;start of buf2 on stack (E0)
  1779. rcall minus ;myhere-buf2 = offset. (e8-e0 = 08)
  1780. mypush2 SOFPG,r7 ; push onto stk start adr of flash page
  1781. rcall plus ;SOFG + offset = new HERE
  1782. ;now put also on stack new version of LATEST
  1783. mypush2 r2,r3 ;that's mylatest on stack
  1784. ldi r16,low(buf2)
  1785. ldi r17,high(buf2)
  1786. mypush2 r16,r17 ;start of buf2 on stack (E0)
  1787. rcall minus ;myhere-buf2 = offset. (e8-e0 = 08)
  1788. mypush2 SOFPG,r7 ; push onto stk start adr of flash page
  1789. rcall plus ;SOFG + offset = new LATEST
  1790. ; now have both LATEST (tos) and HERE on stack. Burn these into eeprom
  1791. ;up top we have .equ eLATEST = $0010
  1792. ;But it's too big. In bytes and causing probs. Solution=covert to words
  1793. rcall halve
  1794. ldi r16,low(eLATEST)
  1795. ldi r17,high(eLATEST)
  1796. mypush2 r16,r17
  1797. ;now have n16 eadr on stack ready for e!
  1798. rcall percentstore
  1799. ; TODO the value for HERE is prob in bytes too. Convert to words.
  1800. ;up top we have .equ eLATEST = $0010
  1801. ldi r16,low(eHERE)
  1802. ldi r17,high(eHERE)
  1803. mypush2 r16,r17
  1804. ;now have n16 eadr on stack ready for e!
  1805. rcall halve ;TODO check this
  1806. rcall percentstore
  1807. ret ;with stack clear and new vals for HERE and LATEST in eeprom
  1808. ;----------
  1809. ;;;;;;;;;;;;;;;;;;;;;;;;;;;Now serial stuff starts;;;;;;;;;;;;;;;;;;;;;;;;;
  1810. halfBitTime: ;better name for this delay. Half of 1/600
  1811. ;myDelay1200:
  1812. ;ldi r21,13 ; 13 works for m328 at 16Mhz
  1813. push r20
  1814. push r21
  1815. ldi r21,7 ;try 7 for tiny85 at 8Hmz
  1816. ldi r20,130 ;r20,21 at 130,7 give 833uS. Good for 600baud at 8Mhz
  1817. starthbt:
  1818. inc r20
  1819. nop
  1820. brne starthbt
  1821. dec r21
  1822. brne starthbt
  1823. pop r21
  1824. pop r20
  1825. ret
  1826. ;--------------------------------------------------
  1827. oneBitTime:
  1828. rcall halfBitTime
  1829. rcall halfBitTime
  1830. ret
  1831. ;-------------------------------------------------
  1832. sendAZero:
  1833. ;output 0 on Tx pin
  1834. cbi PORTB,TX_PIN ; send a zero out PB0
  1835. ret
  1836. ;-----------------------------------------------------
  1837.  
  1838. sendAOne:
  1839. ;output 1 on Tx pin
  1840. sbi PORTB,TX_PIN ; send a zero out PB0
  1841. ret
  1842. ;-----------------------------------------------------
  1843. sendStartBit:
  1844. ; send a 0 for one bit time
  1845. rcall sendAZero
  1846. rcall oneBitTime
  1847. ret
  1848. ;-------------------------------------------------------
  1849. sendNextDataBit: ;main output routine for serial tx
  1850. lsr serialByteReg ;push high bit into carry flag then inspect it
  1851. ;originally did lsl but found lsb first.
  1852. brcc gotzero ;if it's a 0 do nothing
  1853. rcall sendAOne ;must have been a 1 in carry
  1854. rjmp down
  1855. gotzero:
  1856. rcall sendAZero ;if here carry was a zero
  1857. down:
  1858. rcall oneBitTime ;so that 1 or 0 lasts 1/600 sec
  1859. ret
  1860. ;-------------------------------------------------------------
  1861. send8DataBits: ; send all bits in serialByteReg
  1862. ldi counterReg,8 ;8 data bits
  1863. sendBit:
  1864. rcall sendNextDataBit
  1865. dec counterReg
  1866. brne sendBit
  1867. ret
  1868. ;--------------------------------------------------------
  1869. sendStopBit:
  1870. ; send a 1 for one bit time
  1871. rcall sendAOne
  1872. rcall oneBitTime
  1873. ret
  1874. ;--------------------------------------------------------
  1875. sendSerialByte: ;main routine. Byte in serialByteReg = r16
  1876. .ifdef testing
  1877. mov r0, r16
  1878. .else
  1879. push counterReg
  1880. rcall sendStartBit
  1881. rcall send8DataBits
  1882. rcall sendStopBit
  1883. rcall sendStopBit ;two stops
  1884. pop counterReg
  1885. .endif
  1886. ret
  1887. ;**************************************************************
  1888. serialTest0: ;output series of 'AAAA..'s
  1889. ldi serialByteReg, 0x43 ;0x41
  1890. rcall sendSerialByte
  1891. rcall oneBitTime ; take a rest
  1892. ldi r16,$44
  1893. mypush r16
  1894. rcall emitcode
  1895.  
  1896. rjmp serialTest0 ;continue forever
  1897. ;---------------------------------------------------------
  1898. ;---------Now do SerialRx routines-------------------
  1899. waitForHigh: ;loop til RX is high
  1900. sbis PINB,RX_PIN ;test that pin for set (PB2)
  1901. rjmp waitForHigh ; loop if rx pin is low
  1902. ret
  1903. ;-----------------------------------------------
  1904. waitForLow: ;PRONBLEMs loop til RX is low. FIXED.
  1905. sbic PINB,2 ;test that pin for set (PB2)
  1906. rjmp waitForLow ; loop if rx pin is high
  1907. ret
  1908. ;---------------------------------------------------
  1909. waitForStartBit: ;loop til get a real start bit
  1910. rcall waitForHigh ;should be marking at start
  1911. rcall waitForLow ;gone low. might be noise
  1912. rcall halfBitTime ;is it still low in middle of bit time
  1913. sbic PINB,RX_PIN ;..well, is it?
  1914. rjmp waitForStartBit ;loop if level gone back high. Not a start bit.
  1915. ret ;we've got our start bit
  1916. ;----------------------------------------------------
  1917. checkForStopBit: ;at end, get carry flag to reflect level. Prob if c=0
  1918. rcall oneBitTime ; go into stop bit frame, halfway
  1919. sec ;should stay a 1 in C if stop bit OK
  1920. sbis PINB,RX_PIN ;don't clc if bit is high
  1921. clc ;but only if we have a weird low stop bit
  1922. ret ;with carry flag = stop bit. Should be a 1
  1923. ;-------------------------------------------------------------
  1924. get8Bits: ;get the 8 data bits. No frame stuff
  1925. clr rxbyte ;this will fill up with bits read from RX_PIN
  1926. push counterReg ;going to use this so save contents for later
  1927. ldi counterReg,8 ;because we're expecting 8 databits
  1928. nextBit:
  1929. rcall oneBitTime ;first enter here when mid-startbit
  1930. rcall rxABit ;get one bit
  1931. dec counterReg ;done?
  1932. brne nextBit ;no, round again
  1933. pop counterReg ;yes, finished, restor counter and get out
  1934. ret
  1935. ;---------------------------------------------------------------
  1936. rxABit: ;big serial input routine for one bit
  1937. clc ;assume a 0
  1938. sbic PINB,RX_PIN ; skip nxt if pin low
  1939. sec ;rx pin was high
  1940. ror rxbyte ;carry flag rolls into msb first
  1941. ret
  1942. ;********************************
  1943. getSerialByte: ;big routine. Serial ends up in rxByte
  1944. push counterReg
  1945. rcall waitForStartBit ;**change
  1946. rcall get8Bits
  1947. rcall checkForStopBit
  1948. pop counterReg
  1949. ret ;with rxByte containing serial bye
  1950. ;----------------------------------------------------
  1951. serialTest1: ;output A then reflect input. Worked OK
  1952. ldi serialByteReg, 0x36 ;0x41
  1953. rcall sendSerialByte
  1954. rcall oneBitTime ; take a rest
  1955. rcall getSerialByte
  1956. mov serialByteReg,rxByte ;output what's been read
  1957. rcall sendSerialByte
  1958. rjmp serialTest1
  1959. ;--------------------------------------------------------
  1960. ;----------Now doing buffer work. Want to and from 64 bytes----------
  1961. fillBuf:
  1962. ldi ZL,low(buf1) ;buf1 is my buffer
  1963. ldi ZH, high(buf1) ;Z now points to buf1
  1964. ldi counterReg,64 ;64 bytes in buffer
  1965. ldi r16,$30
  1966. storeB0:
  1967. st z+,r16
  1968. inc r16
  1969. dec counterReg
  1970. brne storeB0
  1971. herefb:
  1972. ; rjmp herefb
  1973. ret
  1974. ;----------------------------------------------------------
  1975. serialStrOut: ;X points to start of string,r17 has length
  1976. ld serialByteReg, x+
  1977.  
  1978. rcall sendSerialByte
  1979. dec r17 ;got to end of string?
  1980. brne serialStrOut
  1981. ret
  1982. ;----------------------------------
  1983. test_serialStrOut:
  1984. rcall fillBuf
  1985. ldi XL,low(buf1) ;buf1 start of str
  1986. ldi XH, high(buf1)
  1987. ldi r17,64 ;going to send len=r17 bytes
  1988. rcall serialStrOut
  1989. here2:
  1990. rjmp here2
  1991. ;--------------------------------------
  1992. waitForCharD: ;wait til eg a 'D' is pressed then do something.
  1993. ldi serialByteReg, '>' ;0x41
  1994. rcall sendSerialByte
  1995. rcall oneBitTime ; take a rest
  1996. rcall getSerialByte
  1997. mov serialByteReg,rxByte ;output what's been read
  1998. cpi rxByte, 'D'
  1999. brne waitForCharD
  2000. ldi serialByteReg, '*'
  2001. rcall sendSerialByte
  2002. rjmp waitForCharD
  2003. ;-----------------------------------------------------------
  2004. dumpbuf1:
  2005. ldi XL,low(buf1) ;buf1 start of str
  2006. ldi XH, high(buf1)
  2007. ldi r17,64 ;going to send len=r17 bytes
  2008. rcall serialStrOut
  2009. ret
  2010. ;-------------------------------------------------------------
  2011. test_dumpbuf1:
  2012. rcall fillBuf
  2013. rcall getSerialByte ;any one will do.
  2014. rcall dumpbuf1
  2015. rjmp test_dumpbuf1
  2016. ;----------------------------------------------------------
  2017. waitForDDump: ;wait til eg a 'D' is pressed then dump buf1
  2018. ldi serialByteReg, '>' ;0x41
  2019. rcall sendSerialByte
  2020. rcall oneBitTime ; take a rest
  2021. rcall getSerialByte
  2022. mov serialByteReg,rxByte ;output what's been read
  2023. cpi rxByte, 'D'
  2024. brne waitForDDump
  2025. rcall dumpbuf1
  2026. rjmp waitForCharD
  2027. ;---------------------------------------------------------------
  2028. rxStrEndCR: ;get a serial string that ends with CR
  2029. clr counterReg
  2030. ldi XL,low(buf1) ;buf1 is where str will go
  2031. ldi XH, high(buf1)
  2032. upsec:
  2033. rcall getSerialByte
  2034.  
  2035. st x+, rxByte ;char goes into buffer="buf1"
  2036.  
  2037. cpi rxByte,$0d ;is it CR = end of string?
  2038. breq fin
  2039. inc counterReg ;don't go over 64 bytes
  2040. cpi counterReg,64
  2041. brne upsec ;not too long and not CR so keep going
  2042. fin:
  2043. ret
  2044. ;---------------------------------------------
  2045. test_rxStrEndCR: ;just a test of above
  2046. rcall OK
  2047. rcall CR
  2048. rcall rxStrEndCR
  2049. rcall dumpbuf1
  2050. rcall CR
  2051. ; rcall waitForDDump
  2052. rjmp test_rxStrEndCR
  2053. ;------------------------------------------------------
  2054. test2_rxStrEndCR: ;want a diagnostic dump if testing. Works with .IFDEF
  2055. rcall rxStrEndCR
  2056. .IFDEF testing
  2057. rcall dumpbuf1
  2058. .ENDIF
  2059. rjmp test2_rxStrEndCR
  2060. ;------------------------------------------------------------
  2061. rxStrWithLen: ;expect len char char char.. for len chars
  2062. push counterReg
  2063. ldi XL,low(buf1) ;buf1 is where str will go
  2064. ldi XH, high(buf1)
  2065. rcall getSerialByte ; get length bye Must be less than 65
  2066. mov counterReg, rxByte ;save len in counter
  2067. cpi counterReg,65 ;
  2068. brlo allOK ;less than 65 so carry on. Branch if Lower
  2069. ldi counterReg,64 ; if len>64 then len=64. Buffer = buf1 only 64 bytes
  2070. allOK:
  2071. tst counterReg ;zero yet?
  2072. breq finrs
  2073. rcall getSerialByte ;next serial input byte
  2074. st x+, rxByte ;put into buffer
  2075. dec counterReg ;have we done len=counterReg bytes?
  2076. rjmp allOK
  2077. finrs:
  2078. pop counterReg
  2079. ret
  2080. ;---------------------------------------------------------------
  2081. test_rsStrWithLen: ;works ok with macro $05GHIJKLM. Sends GHIJK
  2082. ldi r16, '#'
  2083. rcall sendSerialByte
  2084. rcall rxStrWithLen
  2085. rcall dumpbuf1
  2086. rjmp test_rsStrWithLen
  2087. ;-----------------------------now start forth i/o words like emit------------------
  2088. emitcode: ; (n8 --)classic emit
  2089. mypop r16
  2090. rcall sendserialbyte
  2091. ret
  2092. ;------------------------------------------------
  2093. insertret: ;semi has to end new word with ret = $9508 opcode
  2094. pushx ;both xl,xh saved for later
  2095. movw xl,myhere ;myhere points to next available spot in ram dic
  2096. ldi r16,$08
  2097. st x+,r16 ;$08 part goes first
  2098. ldi r16,$95
  2099. st x+,r16 ;ret now in ram. Just tidy pointers
  2100. movw myhere,xl
  2101. popx ;so x back where it was and ret inserted.
  2102. ret
  2103. ;--------------------------------
  2104. equalcode: ;(n1 n2 -- flag) if n1 = n2 flag = 0001 else 0000
  2105. mypopa
  2106. mypopb ; now have TOS in r16,17, underneath that in r18,19
  2107. cp r16,r18 ;low bytes =?
  2108. brne zout ;not equal so go out
  2109. cp r17,r19 ;hi bytes =?
  2110. brne zout ;no, so out
  2111. ;if here both n16's are equal so push a 0001
  2112. rcall one
  2113. rjmp aout ;done
  2114. zout:
  2115. rcall zero ;not = so push a zero
  2116. aout:
  2117. ret ;with a flag on stack replacing to n16's
  2118. ;------------------------------
  2119. ;TODO eliminate below and replace with simpler RAM jmp code.
  2120. calcjumpcode: ;(to from -- opcode_for_rjmp to at from)
  2121. ;used when compiling. What is the rjmp opcode if
  2122. ; we know the from and to adr on stack. ( to fr --)
  2123. ldi r16, low(buf2)
  2124. ldi r17, high(buf2)
  2125. mypush2 r16,r17 ; (to fr $e0 --)
  2126. rcall dup ;t f $e0 $eo
  2127. rcall unrot ;t $e0 fr $e0
  2128. rcall minus ;t $e0 frOffset
  2129. rcall unrot ;frOffset t $e0
  2130. rcall minus ;frOffset toOffset
  2131. ;now apply these offsets in flash buffer. Add them to start of flash buffer adr
  2132. mypush2 SOFPG,r7 ; frOffset toOffset SOFPG
  2133. rcall dup ;frOffset toOffset SOFPG SOFPG
  2134. rcall unrot ;frOffset SOFPG toOffset SOFPG
  2135. rcall plus ;frOffset SOFPG toFlashAdr
  2136. rcall unrot ;toFlashAdr frOffset SOFPG
  2137. rcall plus ;toFlashAdr frFlashAdr
  2138. rcall minus ;to -from give last 3 nibbles in rjmp opcode +1
  2139. rcall one
  2140. rcall minus ; now have to - from -1
  2141. rcall stackme_2
  2142. .dw $0fff
  2143. rcall andd ; now have eg. 0f20. Want Cf20
  2144. rcall stackme_2
  2145. .dw $c000 ;should now have right opcode eg cf20
  2146. ret ;with correct rjmp kkk on stack. Ready to insert into RAM dic.
  2147. ;-------------------
  2148. stackmyhere: ;( --- adr) put RAM ptr myhere on stack
  2149. mypush2 myhere, r5
  2150. ret
  2151. ;---------------------------
  2152. begincode: ;when using BEGIN just stack current address.No dic entry
  2153. rcall stackmyhere ;put next adr on stack
  2154. ret
  2155. ;----------------------------
  2156. stkmyhere: ;put myhere on the stack, handy
  2157. mypush2 myhere,r5
  2158. ret
  2159. ;-----------------------------------
  2160. stkSOBuf2: ;stack start of buf2. Handy.
  2161. ldi r16,low(buf2)
  2162. ldi r17,high(buf2)
  2163. mypush2 r16,r17
  2164. ret ;with adr of buf2 on stk
  2165. ;--------------------------
  2166. stkSOFPG: ;put start of flash page on stack, In bytes.
  2167. mypush2 SOFPG,r7
  2168. ret ;with start of current flash page's adr on stack.
  2169. ;-------------------------------
  2170. stklatestadr: ;put e-adr of eLatest. Currently 012 in eeprom
  2171. ldi r16,low(eLATEST)
  2172. ldi r17,high(eLATEST)
  2173. mypush2 r16,r17
  2174. ret ;with 012 or adr of eLatest on stk
  2175. ;-------------------------------------
  2176. stkhereadr: ;same as above but for HERE
  2177. ldi r16,low(eHERE)
  2178. ldi r17,high(eHERE)
  2179. mypush2 r16,r17
  2180. ret ;with adr of ehere,current eeprom adr = $010
  2181. ;-------------------------------------------
  2182. updatevars2: ;better version of update vars. Come here after ";"
  2183. ;TODO check this version.DONE and eliminate other one.
  2184. rcall gethere ;the HERE val now on stack. It's a pointer to flash.
  2185. rcall stklatestadr ;usually 012
  2186. rcall percentstore
  2187. ;now with LATEST now containing old HERE. Next fix HERE
  2188. rcall stkmyhere ;current ptr to RAM dic's next free byte
  2189. rcall stkSOBuf2 ;start of buf2 adr
  2190. rcall minus ;gives distance into the buffer
  2191. rcall stkSOFPG ;will add distance to start of flashbuf
  2192. rcall plus ;got flash adr, but in bytes
  2193. rcall halve ;now adr in words
  2194. rcall stkhereadr ;usually %010 in eeprom
  2195. rcall percentstore ;eHERE now updated
  2196. ret ;with vals for HERE and LATEST in eeprom updated after ";"
  2197. ;--------------------
  2198. testOKCR:
  2199. rcall OK
  2200. rcall OK
  2201. rcall CR
  2202. rjmp testOKCR
  2203. ;--------------------
  2204. serialFill: ;main input routine from terminal. Output OK} then
  2205. ; wait until buf1 has string of words ( <64 chars?) ending in $0d
  2206. rcall CR
  2207. rcall OK
  2208. rcall rxStrEndCR
  2209. ret ; buf1 now filled with words from terminal
  2210.  
  2211. ;------------------------dump routines _______________
  2212. outnib: ;given $23 in r16, output the 3 as '3' = $33
  2213. push r18 ;going to use this
  2214. andi r16,$0f ; $3a --> $0a
  2215. cpi r16,$0a ;more than 10?
  2216. brge gothexo ;Nibble >= 10 jump down to gothex
  2217. ldi r18,$30 ; add $30 to 0..9
  2218. rjmp doneon
  2219. gothexo:
  2220. ldi r18,$37
  2221. doneon:
  2222. add r16,r18 ;now r16 nibble $03 is a '3'
  2223. rcall sendserialbyte ;print it
  2224. pop r18 ;used this as counter
  2225. ret ;note, it wrecks r16
  2226. ;--------------------------------------------
  2227. d16: ;dump contents of r16. Good for debugging.
  2228. push r16 ;keep contents for later
  2229. push r16 ;need this one after swap
  2230. swap r16 ;$34 wants 3 to come out first
  2231. rcall outnib ;print ascii eg '3'in above if r16 = $34
  2232. pop r16 ;get nice version back eg $34
  2233. rcall outnib ;print the '4'
  2234. pop r16 ;so r16 not wrecked.
  2235. ret ;with r16 printed in ascii
  2236. ;-----------------------------------
  2237. test_d16: ldi r16,$a5
  2238. rcall d16
  2239. ldi r16,$b6
  2240. rcall d16
  2241. rjmp test_d16
  2242. ;--------------------------------
  2243. d1617: ;dump r16 and r17 for debugging purposes
  2244. push r16
  2245. push r17 ;
  2246. push r16 ;just one min
  2247. mov r16, r17
  2248. rcall d16 ;that's r17 gone
  2249. pop r16
  2250. rcall d16 ;and then r16
  2251. pop r17
  2252. pop r16
  2253. ret ;with r17:r16 output in ascii
  2254. ;----------------------------------------
  2255. test_d1617:
  2256. ldi r16,$34
  2257. ldi r17,$1F
  2258. rcall d1617
  2259. rjmp test_d1617
  2260. ;-----------------------------------
  2261. dlowR: ;dump low registers. r0..r15 for debugging
  2262. push r16
  2263. push r18
  2264. pushx ;macro
  2265. clr xl
  2266. clr xh
  2267. ldi r18,16 ;r18 is a counter
  2268. prlow:
  2269. ld r16,x+ ;assume is x is 0 we'll get r0
  2270. rcall d16
  2271. rcall spacecode
  2272. dec r18
  2273. cpi r18,$07
  2274. breq doeseq7
  2275. tst r18
  2276. brne prlow
  2277. rjmp outprl
  2278. doeseq7:
  2279. ldi r16,'L'
  2280. rcall sendserialbyte
  2281. rcall spacecode
  2282. rjmp prlow
  2283.  
  2284. outprl:
  2285. popx ;macro
  2286. pop r18
  2287. pop r16
  2288. ret ;with all the registers r0 ..r15 output in ascii to terminal screen
  2289. ;----------------------------------
  2290. test_dlowR:
  2291. rcall CR
  2292. ldi r16,$02
  2293. mov r0,r16
  2294. ldi r16,$52
  2295. mov r5,r16
  2296. ldi r16,$f2
  2297. mov r15,r16
  2298. rcall dlowR
  2299. rcall CR
  2300. rjmp test_dlowR
  2301. ;-----------------------------
  2302. spacecode: ;output a space
  2303. push r16
  2304. ldi r16,$20
  2305. rcall sendserialbyte
  2306. pop r16
  2307. ret
  2308. ;-------------------------------
  2309. dhighR: ;dump high registers. r18..r25 for debugging
  2310. push r16
  2311. push r17
  2312. pushx ;macro
  2313. ldi xl,18
  2314. ; clr xl
  2315. clr xh
  2316. ldi r17,8 ;r18 is a counter
  2317. prhi:
  2318. ld r16,x+ ;assume is x is 18 we'll get r18
  2319. rcall d16
  2320. rcall spacecode
  2321. dec r17
  2322. cpi r17,5
  2323. breq doeseq21
  2324. tst r17
  2325. brne prhi
  2326. rjmp outprh
  2327. doeseq21:
  2328. ldi r16,'H'
  2329. rcall sendserialbyte
  2330. rcall spacecode
  2331. rjmp prhi
  2332.  
  2333. outprh:
  2334. popx ;macro
  2335. pop r17
  2336. pop r16
  2337. ret ;with all the registers r0 ..r15 output in ascii to terminal screen
  2338. ;----------------------------------
  2339. test_dhighR:
  2340. rcall CR
  2341. ldi r18,$88
  2342. ldi r19,$19
  2343. ldi r20,$88 ;
  2344. ldi r21,$88
  2345. ldi r22,$22
  2346. ldi r23,$23
  2347. ldi r24,$24
  2348. ldi r25,$25
  2349. rcall dhighR
  2350. rcall CR
  2351. rjmp test_dhighR
  2352. ;------------------------------------
  2353. dxyz: ;dump the three pointer regs x,y,z
  2354.  
  2355. push r16
  2356. push r17
  2357. movw r16,xl ;r17:16 gets xh:xl
  2358. rcall d1617
  2359. rcall spacecode
  2360. movw r16,yl
  2361. rcall d1617
  2362. rcall spacecode
  2363. movw r16,zl
  2364. rcall d1617
  2365. rcall spacecode
  2366. pop r17
  2367. pop r16
  2368. ret ;with x,y,z output in ascii as a tripple
  2369. ;--------------------------------------
  2370. test_dxyz:
  2371. rcall CR
  2372. ldi xl,$12
  2373. ldi xh,$34
  2374. ldi yl,$56
  2375. ldi yh,$78
  2376. ldi zl,$9A
  2377. ldi zh,$bc
  2378. rcall CR
  2379. rcall dxyz
  2380. rcall CR
  2381. rjmp test_dxyz
  2382. ;--------------------------------
  2383. ;mystack needs a DEPTH word.
  2384. depthcode: ; (--n16)
  2385. ;leave on mystack the number of items on the stack by bytes.
  2386. movw r16,yl ;now r16,17 has y pointer
  2387. ldi r18, low(myStackStart) ;
  2388. ldi r19, high(myStackStart) ;r18,19 probably contain $1A0, the start of mystack
  2389. mypush2 r16,r17
  2390. mypush2 r18,r19 ;setup for eg $1a6 - $1a0
  2391. rcall minus ;difference=depth = eg 0006 as above.
  2392. ret ; with depth on stack
  2393. ;-----------------------------------------
  2394. test_depthcode:
  2395. ldi r16,$01
  2396. ldi r17,$23
  2397. mypush2 r16,r17
  2398. mypush2 r16,r17
  2399. mypush2 r16,r17
  2400. rcall depthcode
  2401. uptd: mypopa ;depth now in r16,17
  2402. up2: rcall d1617
  2403. rjmp up2
  2404. ;------------------------------------
  2405. dotScode: ;classic .S, print stack non-destructively
  2406. push r16
  2407. push r18
  2408. pushx ;macro
  2409. rcall depthcode ;now depth = len of stk on the mystack top
  2410. ; rcall drop ;stk =eg 0006 . want just len = 06
  2411. mypop2 r17,r18 ;so r18 now has length in bytes we're printing
  2412. ldi xl, low(myStackStart)
  2413. ldi xh, high(myStackStart)
  2414.  
  2415. ; movw xl,yl ;use x as temp ptr. Keep y pointing to mystack top
  2416. upds:
  2417. ld r16,x+ ;get tos, Pre-decrement.
  2418. rcall d16 ;print it
  2419. rcall spacecode ;
  2420. dec r18
  2421. brne upds
  2422. ldi r16, ']'
  2423. rcall sendserialbyte
  2424. rcall spacecode
  2425. popx ;macro
  2426. pop r18
  2427. pop r16
  2428. ret ;with the stack items printed to term screen + ]
  2429. ;-----------------------------
  2430. test_dotScode:
  2431. ldi r16,$A1
  2432. ldi r17,$B2
  2433. mypush2 r16,r17
  2434. mypush2 r16,r17
  2435. mypush2 r16,r17
  2436. rcall dotScode
  2437. rcall drop
  2438. rcall drop
  2439. rcall drop
  2440. uptds:
  2441. rjmp uptds
Advertisement
Add Comment
Please, Sign In to add comment