Re: 關於 PICFORTH
|
||||
---|---|---|---|---|
新會員
|
使用 patch -p1
=== patch picforth.fs 1.2.5 ========= --- picforth.fs Wed Dec 29 20:31:50 2004 +++ \temp\picforth-1.2.5\picforth.fs Tue Oct 16 16:46:58 2007 @@ -171,7 +171,7 @@ bank0 host - +70 data-org \ tcompile is the equivalent of state for the cross-compiler : set true swap ! ; @@ -187,12 +187,22 @@ variable current-bank : bank ( a -- n ) 180 and ; +: chkfile ( a -- tf) + dup + 7b and 00 xor 0= \ 0 4 and fb =0 + over + 76 and 02 xor 0= \ a b 2 3 and f6 , xor 02 =0 + or swap + 70 and 70 xor 0= + or +; : check-bank ( a -- a ) tcompile? if exit then \ The compiler takes care of banks + dup chkfile 0<> if exit then dup bank current-bank @ <> if - s" wrong bank may be selected" warning - then ; + s" wrong bank may be selected" warning + then ; \ We are not being strict here. At this time, we assume that all the \ code fits in 8kwords (13 bits addressing) and that main data fits in one @@ -446,9 +456,10 @@ : nop 000 cs, ; : retfie 009 cs, ; : check-default-bank ( -- ) - current-bank @ if - s" call, goto or return with possible non-0 bank selected" warning - then ; +\ current-bank @ if +\ s" call, goto or return with possible non-0 bank selected" warning +\ then ; +; : return check-default-bank 008 cs, ; : sleep 063 cs, ; @@ -1046,7 +1057,7 @@ : t-name ( addr -- ) 3 cells + @ count ; : t-previous ( addr -- addr' ) 2 cells + @ ; : t-length ( addr -- n ) 1 cells + @ ; - +: t-bank ( bank -- bank' ) 4 cells + @ ; \ Code bank handling variable current-cbank @@ -1290,12 +1301,17 @@ target + + + \ Temporary variables udata variable tmp1 variable tmp2 idata +20 set-stack-size + host \ Words to manipulate temporary variables @@ -1375,41 +1391,80 @@ \ Adjust the current bank so that it can appropriately select the right \ address in memory - +: rp0bcf ( -- ) reg-rp0 bcf ; +: rp1bcf ( -- ) reg-rp1 bcf ; +: bank0chk ( bank -- ) + case + 80 of rp0bsf endof + 100 of rp1bsf endof + 180 of rp0bsf rp1bsf endof + endcase +; +: bank1chk ( bank -- ) + case + 00 of rp0bcf endof + 100 of rp0bcf rp1bsf endof + 180 of rp1bsf endof + endcase +; + +: bank2chk ( banf -- ) + case + 00 of rp1bcf endof + 80 of rp1bcf rp0bsf endof + 180 of rp0bsf endof + endcase +; + +: bank3chk ( bank -- ) + case + 00 of rp1bcf rp0bcf endof + 80 of rp1bcf endof + 100 of rp0bcf endof + endcase +; + : adjust-bank ( a -- a ) + dup chkfile 0<> if exit then \ a suspend-warnings >r - case dup bank dup current-bank ! - 80 of rp0bsf endof - 100 of rp1bsf endof - 180 of rp0bsf rp1bsf endof - endcase +\ 0= if + case dup bank dup current-bank @ \ a ba ba cba + 00 of bank0chk endof \ a ba ba + 80 of bank1chk endof + 100 of bank2chk endof + 180 of bank3chk endof +\ 00 of rp1bcf rp0bcf endof +\ 80 of rp1bcf rp0bsf endof +\ 100 of rp1bsf rp0bcf endof +\ 180 of rp1bsf rp0bsf endof + endcase \ a ba + current-bank ! \ a +\ else + +\ then r> restore-warnings ; \ Select the right bank and returned a trimmed address in the page : select-bank ( a -- a' ) adjust-bank 7f and ; - -: rp0bcf ( -- ) reg-rp0 bcf ; -: rp1bcf ( -- ) reg-rp1 bcf ; - : restore-bank ( -- ) - suspend-warnings >r - case current-bank @ - 80 of rp0bcf endof - 100 of rp1bcf endof - 180 of rp1bcf rp0bcf endof - endcase - 0 current-bank ! - r> restore-warnings +\ suspend-warnings >r +\ case current-bank @ +\ 80 of rp0bcf endof +\ 100 of rp1bcf endof +\ 180 of rp1bcf rp0bcf endof +\ endcase +\ 0 current-bank ! +\ r> restore-warnings ; : const-! ( addr -- ) const? if kill-const dup 0= if - drop select-bank clrf restore-bank + drop select-bank clrf restore-bank else - movlw select-bank movwf restore-bank + movlw select-bank movwf restore-bank then else meta> popw select-bank movwf restore-bank @@ -2234,7 +2289,7 @@ meta \ Address of main program -: main ( -- ) 0 set-vector init-picforth ; +: main ( -- ) 30 set-stack-size 30 data-org 0 set-vector init-picforth ; \ ---------------------------------------------------------------------- \ Tables @@ -2485,7 +2540,9 @@ c00 of .op" btfss" endof endcase dup .file ." ," 380 and 7 rshift .bconst -; + ; + + \ Control operations @@ -2600,4 +2657,4 @@ \ Reserve space for jump to main (4 bytes, because of the need to erase \ 4 bytes at a time on 16F8xxA devices) -4 org + ========================end =======================
發表於: 2007/10/16 21:53
|
|||
|
Re: 關於 PICFORTH
|
||||
---|---|---|---|---|
中級會員
|
感覺這個好冷門喔, 比起那個PIC Basic用的人還要少
不過期待你的結果.
發表於: 2007/10/20 15:43
|
|||
|
Re: 關於 PICFORTH
|
||||
---|---|---|---|---|
新會員
|
好玩麻
這是 201 lab6 的題目 我覺得 可以較省code 用 asm 寫 常常 bank 忘了切
: init
發表於: 2007/10/21 9:44
|
|||
|
Re: 關於 PICFORTH
|
||||
---|---|---|---|---|
版主
|
原始程式是比較小,但實際編譯過的 Machine Code 還是會比用組合語言的方式還要大些,你可以看一下最後的反組譯後的程式,依樣還是要切換 BANK 的。
發表於: 2007/10/22 13:16
|
|||
|
Re: 關於 PICFORTH
|
||||
---|---|---|---|---|
中級會員
|
BANK都肯定是要切煥的,畢竟到最後都要成為機器代碼運行,他只是說寫的時候不用顯式切換.
發表於: 2007/10/22 20:34
|
|||
|
Re: 關於 PICFORTH
|
||||
---|---|---|---|---|
新會員
|
切 bank 是 mcu 的硬體設計 誰也沒辦法改變
會比c小 用 asm 寫 常忘了切bank 我試過比較 會比asm 大一點 畢竟 asm 完全控制程序 但又有點累
發表於: 2007/10/23 1:41
|
|||
|