From 8bf62586733093dbf4676d7838ca1f7b528f7df7 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 25 Sep 2020 17:31:06 -0400 Subject: [PATCH] Add word TICKS Adding a delay such as the 20ms one we have in AVR programmer's initialization routine is tricky without a word like TICKS. This implementation is highly inaccurate, but more accurate and reliable than a "ballpark" DO..LOOP... --- blk/160 | 2 +- blk/282 | 4 ++++ blk/321 | 13 +++++++++++++ blk/441 | 2 +- blk/461 | 9 +++++++++ cvm/forth.bin | Bin 5345 -> 5355 bytes cvm/vm.c | 5 ++++- cvm/xcomp.fs | 11 ++++++----- doc/dict.txt | 12 ++++++++---- recipes/pcat/blk/612 | 2 +- 10 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 blk/321 create mode 100644 blk/461 diff --git a/blk/160 b/blk/160 index 20afd35..f462242 100644 --- a/blk/160 +++ b/blk/160 @@ -10,7 +10,7 @@ VARIABLE aspprevx : asprdy ( -- ) BEGIN 0 0 0 0xf0 _cmd 1 AND NOT UNTIL ; : asp$ ( spidevid -- ) ( RESET pulse ) DUP (spie) 0 (spie) (spie) - ( wait >20ms ) 5000 0 DO LOOP + ( wait >20ms ) 220 TICKS ( enable prog ) 0xac (spix) DROP 0x53 _x DROP 0 _xc DROP 0 _x DROP ; : asperase 0 0 0x80 0xac _cmd asprdy ; diff --git a/blk/282 b/blk/282 index 6b007b0..8b0c70b 100644 --- a/blk/282 +++ b/blk/282 @@ -1 +1,5 @@ VARIABLE lbluflw VARIABLE lblexec +( see comment at TICKS' definition ) +( 7.373MHz target: 737t. outer: 37t inner: 16t ) +( tickfactor = (737 - 37) / 16 ) +CREATE tickfactor 44 , diff --git a/blk/321 b/blk/321 new file mode 100644 index 0000000..334b18c --- /dev/null +++ b/blk/321 @@ -0,0 +1,13 @@ +( The word below is designed to wait the proper 100us per tick + at 500kHz when tickfactor is 1. If the CPU runs faster, + tickfactor has to be adjusted accordingly. "t" in comments + below means "T-cycle", which at 500kHz is worth 2us. ) +CODE TICKS + HL POP, chkPS, + ( we pre-dec to compensate for initialization ) + BEGIN, + HL DECd, ( 6t ) + IFZ, ( 12t ) JPNEXT, THEN, + A tickfactor @ LDri, ( 7t ) + BEGIN, A DECr, ( 4t ) JRNZ, ( 12t ) AGAIN, + JR, ( 12t ) AGAIN, ( outer: 37t inner: 16t ) diff --git a/blk/441 b/blk/441 index 73ae535..ccb89dc 100644 --- a/blk/441 +++ b/blk/441 @@ -10,4 +10,4 @@ size of stack. This allows for some interesting optimization. For example, in SWAP, no need to pop, chkPS, then push, we can chkPS and then proceed to optimized swapping in PS. -To assemble, load blocks 445 through 460 +To assemble, load blocks 445 through 461 diff --git a/blk/461 b/blk/461 new file mode 100644 index 0000000..2be56ea --- /dev/null +++ b/blk/461 @@ -0,0 +1,9 @@ +( See comment in B321. TODO: test on real hardware. in qemu, + the resulting delay is more than 10x too long. ) +CODE TICKS 1 chkPS, ( n=100us ) + SI DX MOVxx, ( protect IP ) + AX POPx, BX 100 MOVxI, BX MULx, + CX DX MOVxx, ( high ) DX AX MOVxx, ( low ) + AX 0x8600 MOVxI, ( 86h, WAIT ) 0x15 INT, + DX SI MOVxx, ( restore IP ) +;CODE diff --git a/cvm/forth.bin b/cvm/forth.bin index 88ecc99390a7ecbccadc1b090a908ba5c10628bc..eaa38a29bc9e2b2d1e03ce4a5dbe8301deeb6a9d 100644 GIT binary patch literal 5355 zcma)AZA_cj6+Z84V;f_G32A5>NNqlXZ9W35AA}OHUt`A9uq@3dC{ZXxKtrpg zYqxrfrY=%DBqXFvq*^8Niz%t{FYUjkTcT)E)lQqX>_?_7`$)TF>Z)pu+C9&`IElJH zMdE$$Irn_sbIv{IycQ9eTKBB?gY{VGzdhdgXd*9S7YQDm2|2JZf_+#yr9{l&Yf#3uIOta_L9X6<5%BiqZDv$HqLT~}wem+#W}XgoHYkC%#5+}U)VxU&A? z4BwtUEU3rZpG~Vpd2S@C78U8;@hrD|nM7B&iD!MaY;)2yn_H3{o;?bQBA zQ;x3<(NsSb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6V*bLFNO(g!Ex?S+*6^eRVxF{Sox4tB=IBB z{$sP__1QerX4@*3hXaR>oWZ&E)n}%Br|KUVy<;==)6Yyyz7^na1_Rl3@++Vn3_5Y_ z`4+B{A|Txg;xlfp;%t^q6*3Q~1LBBY4n_Fg<1|`?5!3U|Ej%NuP!?Y-Uofh@On2aZ z!bu1ZO$#m~4+pSSMcL&m^*a-7q3m^!y}C)=n87|}46Y@NS-|DR(*Q%&Y8X_MxcRp0 z<|_TZu+w>ri8K>++e^wntd5)Nou4W+)F=!t5~R$-no0Bta`T4)zE0u|k3!E^t1Wpe zK(o|uEDd3K!3eFf@KXw5mc2QZ3CXWfQ9!Uck;?e7(fZ;jEZQw2nL;XEtq|Ji5@P2n zc;^%nf42ut(bpoG9nPiF$j28ktJ=`69l3J_juHALAgFw2^KQR9uc&kj! #include #include +#include #include "vm.h" // Port for block reads. Each read or write has to be done in 5 IO writes: @@ -263,6 +264,7 @@ static void MINUS2() { push(pop()-2); } static void PLUS2() { push(pop()+2); } static void RSHIFT() { word u = pop(); push(pop()>>u); } static void LSHIFT() { word u = pop(); push(pop()<R -0x07 CODE >R -0x08 CODE R> +0x04 CODE (n) +0x05 CODE (s) +0x06 CODE >R +0x07 CODE R> +0x08 CODE 2>R 0x09 CODE 2R> 0x0a CODE EXECUTE 0x0b CODE ROT @@ -68,6 +68,7 @@ H@ 4 + XCURRENT ! ( make next CODE have 0 prev field ) 0x34 CODE 2- 0x35 CODE RSHIFT 0x36 CODE LSHIFT +0x37 CODE TICKS 353 LOAD ( xcomp core low ) : (emit) 0 PC! ; : (key) 0 PC@ ; diff --git a/doc/dict.txt b/doc/dict.txt index 88892dc..61d50f4 100644 --- a/doc/dict.txt +++ b/doc/dict.txt @@ -242,9 +242,6 @@ S= a1 a2 -- f Returns whether string a1 == a2. call to (print). C -- a Address of variable containing current pos in input buffer. @@ -270,7 +267,6 @@ BLK( -- a Beginning addr of blk buf. BLK) -- a Ending addr of blk buf. COPY s d -- Copy contents of s block to d block. FLUSH -- Write current block to disk if dirty. -FREEBLKS? a b -- List free blocks between blocks a and b. LIST n -- Prints the contents of the block n on screen in the form of 16 lines of 64 columns. LOAD n -- Interprets Forth code from block n @@ -279,3 +275,11 @@ LOADR n1 n2 -- Load block range between n1 and n2, inclusive. LOADR+ n1 n2 -- Relative ranged load. WIPE -- Empties current block WIPED? -- f Whether current block is empty + +# Other + +DUMP n a -- Prints n bytes at addr a in a hexdump format. + Prints in chunks of 8 bytes. Doesn't do partial + lines. Output is designed to fit in 32 columns. +TICKS n -- Wait for approximately 0.1 millisecond. Don't + use with n=0. diff --git a/recipes/pcat/blk/612 b/recipes/pcat/blk/612 index 0bfb8c8..a393528 100644 --- a/recipes/pcat/blk/612 +++ b/recipes/pcat/blk/612 @@ -3,7 +3,7 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 30 LOAD ( 8086 asm ) 262 LOAD ( xcomp ) 270 LOAD ( xcomp overrides ) -445 460 LOADR ( 8086 boot code ) +445 461 LOADR ( 8086 boot code ) 353 LOAD ( xcomp core low ) 604 LOAD ( KEY/EMIT drivers ) 606 608 LOADR ( BLK drivers )