I started working with Peters update of Marcus' update of Peter's 1-Wire code. Its great. Found some minor code typos and some commentary need cleaning up. I would appreciate someone to pound on it some more and see if it can be crunched.
Peter's improvements made the code several orders of magnitude faster than the same code in Spin and a whole lot easier to work with.
I started working with Peters update of Marcus' update of Peter's 1-Wire code. Its great. Found some minor code typos and some commentary need cleaning up. I would appreciate someone to pound on it some more and see if it can be crunched.
Peter's improvements made the code several orders of magnitude faster than the same code in Spin and a whole lot easier to work with.
... Enjoy! BBR
thanks Brian,
included most of your comments in the source document.
And fixed the bug you reported in the print routine.
And Peter made some enhancements again as well.
I did a quick hack last night on some Forth code I borrowed to play the game of life and it worked well. Now I've just tidied it up a little
EDIT: Couldn't help but modify it again so that the bits in each cell are displayed vertically for 32 lines and now the "lines" constant is used for the width. In this way we can also specify the width at runtime<br> video
<br>The code size is 541 bytes including pattern setups with 284 byte in dictionary space.
The nextgen function executes in 57.6ms and the .universe function takes another 17.4ms (non-buffered).
EDIT: Updated the latest EXPLORER binary to include LIFE - runs at sedate 115200 baud - just type "demo"
TACHYON [~
DECIMAL
FORGET LIFE.fth
pub LIFE.fth PRINT" Conway's Game of Life for the Propeller V1.0 150601.1100 " ;
{
Adapted from code at:
http://www.forth-ev.de/wiki/doku.php/projects:4e4th:4e4th:start:beispiele
Optimized for cell widths so 32 wide for the Propeller
Modified so that lines print horizontally to optimize the cell width vertically
}
pub CELLS 2* 2* ;
100 == #lines
8 CELLS == bits/cell \ = number of columns
BUFFERS == universe
pub line ( n -- a-addr ) CELLS universe + ;
pub lrot3 ( x1 x2 x3 -- x4 x5 x6 )
1 ROL ROT 1 ROL ROT 1 ROL ROT
;
TABLE #bits 0 | 1 | 1 | 2 | 1 | 2 | 2 | 3 | 0 | 1 | 1 | 2 | 1 | 2 | 2 | 3 |
pub countbits ( x -- n ) \ count number of bits=1 in bit0..2
>N #bits + C@
;
pub alive ( x1 x2 x3 -- flag )
\ return whether cell at bit1 in line1 is alive in next generation
OVER 2 AND 0= INVERT >R
countbits
SWAP countbits + \ note: cell itself is counted, too. correction below.
SWAP countbits +
DUP 3 = SWAP 4 = R> AND OR
;
pub doline ( x1 x2 x3 -- x1 x2 x3 x4 )
0 bits/cell FOR
>R 3RD 3RD 3RD alive 2 AND R> OR 1 ROL >R
lrot3 R>
NEXT
;
pub nextgen ( -- )
0 line @ #lines 1- line @ OVER ( s: line0 x1 x2 )
#lines 1- 0 DO
I 1+ line @ ( s: line0 x1 x2 x3 )
doline I line !
ROT DROP ( s: line0 x2 x3 )
LOOP
ROT doline #lines 1- line ! \ special treatment for last line
3DROP
;
pub .lines ( bit -- )
MASK #lines 0 DO
I line @ OVER AND IF "*" ELSE BL THEN (EMIT)
LOOP DROP
;
pub .universe ( -- ) \ print current life state to console
OFF CURSOR
home PRINT" Conway's Game of Life - Tachyon Forth" CR
"-" #lines 2+ EMITS CR
bits/cell 0 DO "|" (EMIT) I .lines "|" (EMIT) CR LOOP
"-" #lines 2+ EMITS
;
--- set terminal screen width for matrix
pub wide ' #lines 1+ ! ;
pub life CLS BEGIN .universe nextgen KEY UNTIL CR ;
--- PATTERN CREATION ---
pub void ( -- ) universe #lines CELLS ERASE ;
pub seed ( x1 .. xn n -- ) 0 DO I line ! LOOP ;
--- some well known patterns:
pub glider ( -- ) 7 1 2 3 seed ;
pub fpent ( -- ) 4 $0C 6 3 seed ;
pub lwss ( -- ) $0F $11 1 $12 4 seed ;
pub diehard $47 $C0 2 3 seed ;
pub acorn $67 8 $20 3 seed ;
TABLE memory 128 CELLS ALLOT
pub .memory #lines 0 DO I CELLS memory + @ CR "$" EMIT .LONG SPACE I .DEC ." line !" LOOP CR ;
--- create a random pattern as a seed
--- usage: random life
pub random #lines 0 DO RND DUP I line ! I CELLS memory + ! LOOP ;
--- Copy a pattern of longs from memory (such as ROM)
--- Usage: $E000 copy life
pub copy ( src -- ) #lines 0 DO DUP @ I line ! 4 + LOOP DROP ;
pub reload #lines 0 DO I CELLS memory + @ I line ! LOOP ;
pub demo $E000 copy life ;
]~ END
(This post should just about crack the 250,000 views mark! )
Congratulations Peter! You have cracked the 250K views
Thanks, I thought it was crazy when once it had 10,000 views, and that was after only 2 months!
As for the game of life, how wide can you set your serial terminal screen? 128 characters? How about 476 wide!
For my 1920x1080 screen that means that characters must be around 4 pixels wide including spacing!!!
I have difficulties loading EXTEND.FTH (150527-0000) into Tachyon 2.5 . There are non-ASCII characters in it, but that might not be the issue. The problem seems rather that the Tachyon 2.5 kernel cannot properly deal with comments within comments, e.g. the (link) comments within the {} comment ("Description" section) upset it and it then attempts to interpret subsequent words.
Should I be using a different version of EXTEND.FTH or the Tachyon kernel or am I doing something wrong?
I have difficulties loading EXTEND.FTH (150527-0000) into Tachyon 2.5 . There are non-ASCII characters in it, but that might not be the issue. The problem seems rather that the Tachyon 2.5 kernel cannot properly deal with comments within comments, e.g. the (link) comments within the {} comment ("Description" section) upset it and it then attempts to interpret subsequent words.
Should I be using a different version of EXTEND.FTH or the Tachyon kernel or am I doing something wrong?
Just checked the files in the Dropbox and they are fine. There shouldn't be any problems with nested { } comments either. Make sure you have set a line delay of around 15ms as there is no handshaking. Other than that, all should just work I use minicom on Linux or Teraterm on Windows and normally just copy&paste. There's also the complete Explorer binary image available which already includes EXTEND.fth.
I was just killing time and nosing around a little, when I came across Ray's comment
Congratulations Peter! You have cracked the 250K views
Congratulations from me also. With all of your hard work and dedication, you have built a thread that will be remembered for a long time. Besides the pride that is obtained from one's hard work, there should be some kind of award or reward for this achievement.
I was just killing time and nosing around a little, when I came across Ray's comment
Congratulations from me also. With all of your hard work and dedication, you have built a thread that will be remembered for a long time. Besides the pride that is obtained from one's hard work, there should be some kind of award or reward for this achievement.
My hat is off to you
Thanks Bruce, all of us are making the forum what it is, but I think we could certainly do with more contributors like yourself though who are actively using the Props to get real work done. I've just been trying to make the Prop a lot easier for many to get into but it's a bit like a marketing exercise where you know the product's good and that it is a great solution, but like trying to steer people into thinking about using Linux instead of Windows, it's an uphill battle (does it run Office 360? !$%^&#@!).
But I find the Tachyon thread a bit of a mystery too, it's like there are only so many people out there who have put their Forth hand up so to speak yet the steady volume of views seems to indicate that there are a lot of interested lurkers too. I've had experience in the past where it turns out that some university's EE dept somewhere might use it in their course material with embedded system control and robotics etc, so there could be a ton of anonymous students using it and occasionally they will contact me directly.
I found out a long time ago that unless you are in the mainstream, you will not gain wide "recognition". So if this was an Arduino programmed in C then I could possibly be "famous"
BTW. Telnet into tachyonforth.com to port 10001 and talk to Tachyon or just type "demo" to run Conway's Game of Life (defaults to 64 wide by 32 lines). Hit CR to exit and specify other widths and parameters or just play with Tachyon. Remember that this is mostly just running from one cog while running the network and filesystem software, and the only "enhancement" is a 64kB EEPROM rather than a 32kB.
Just checked the files in the Dropbox and they are fine. There shouldn't be any problems with nested { } comments either. Make sure you have set a line delay of around 15ms as there is no handshaking. Other than that, all should just work I use minicom on Linux or Teraterm on Windows and normally just copy&paste. There's also the complete Explorer binary image available which already includes EXTEND.fth.
pub EXTEND.fth ." Primary extensions to TACHYON kernel"
}
IFDEF EXPLORER
pub EXTEND.fth ." Tachyon Forth Propeller hardware debugger and explorer"
}
." - 150527-0000" ;
\ CREATE SMALL \ define SMALL before a load to specify a SMALL build to limit the sections included IFNDEF SMALL
\ CREATE EXPLORER \ make an hardware explorer version - more verbose etc
( link to the latest Tachyon kernel web document )
{
CONTENTS<EE><BF><BF>
DESCRIPTION
NOTES
CHANGELOG (link)
( PIN I/O OPERATIONS )
maybe cut&paste is the solution? Perhaps that filters non-ASCII characters (UTF-8 sequences?) like the one above, in the CONTENTS line.
So far I tried minicom (even with a line delay of 250ms, even though that's a bit much 'retro' for my taste -- no chance in getting software flow control?) on Raspberian to talk to the Prop on the RPi Propeller hat board. Let me try a few other things ...
I don't think I can use the binaries (at least earlier attempts were unsuccessful), as the RPi hat board uses a 6MHz crystal for some reason which throws off the UART timing.
There's also a 6MHz Explorer binary in the dropbox files too that you could use, it just happens to still be a V2.4 but otherwise no difference although I will update them both shortly.
BTW, I have no problem downloading to a standard 80MHz Prop at 2M baud with 10ms line delay so 250ms is never ever required. Software handshaking is of no use because PC UARTs and USB bridges have such huge FIFOs in both directions and XON/XOFF characters just end up in a queue rather than being processed the moment they are deserialized. There is always the possibility of a handshake line but most Prop systems don't support it and that would reduce the number of I/O available already. Anyway, 15ms line delay is easy to set, there is never any real need to set it any slower as Tachyon does not wait until the end of line to interpret/compile, it will do it word by word.
I've been playing again with improving compilation speeds of large blocks of source such as EXTEND.fth etc. Normally I just set my terminal for 15ms line delay and paste EXTEND into it, this works even at 2M baud. However it would be nice if we could somehow employ soft handshaking despite the huge FIFOs that these PC or USB serial ports have.
So I figured that as long as I had a buffer that was big enough so that even after an XOFF got delayed in the PC port's queue it would eventually get through and pause the transmit data being sent to the Prop without losing any characters in the meantime. I therefore reasoned that the 2K BUFFERS area wouldn't be used during any major block loading so what I could do was make the TACHYON word switch the receive buffer to BUFFERS and set the internal size for 2K. However to make it work effectively the serial receive routine would have to send an XOFF not at the 2K boundary but probably closer to the 1K boundary to allow for long transmit and receive FIFO queues.
The other thing that helped a bit too in earlier versions was preprocessing the text stream in the serial receive cog. It would interpret tilde commands such as [~ and ]~ to set modes so comments and extras spaces would not be buffered etc. The feature was removed because it had to be smart enough to know when and how to do this which didn't always work. If I simply get it to remove extra spaces and simple line comments then this should help.
The aim now is to reduce the line delay to an absolute minimum or preferably none at all and to test this with various terminals to make sure they respond well enough to soft handshaking.
Peter - some of the PC UART and USB chips claim to have hardware support for XON/XOFF. So the FIFO depth shouldn't matter in that case right? But they may depend on software doing the escaping/de-escaping of data. I know that I implemented both nRTS/nCTS and XON/XOFF in an embedded hardware UART so that we could say that only 2 signal lines were necessary even though the final products probably always used 4 signals. Believe it or not in a quite complicated signal processing application is was always basic serial comms {UARTs, I2C, and SPI} that seemed to present the biggest challenge for customers. (Versus TCXOs, LNAs, antenna design,... Not that these weren't without problems.)
Have you tried XON/XOFF with any of the popular USB interface chips from SiLabs or FTDI?
Peter - some of the PC UART and USB chips claim to have hardware support for XON/XOFF. So the FIFO depth shouldn't matter in that case right? But they may depend on software doing the escaping/de-escaping of data. I know that I implemented both nRTS/nCTS and XON/XOFF in an embedded hardware UART so that we could say that only 2 signal lines were necessary even though the final products probably always used 4 signals. Believe it or not in a quite complicated signal processing application is was always basic serial comms {UARTs, I2C, and SPI} that seemed to present the biggest challenge for customers. (Versus TCXOs, LNAs, antenna design,... Not that these weren't without problems.)
Have you tried XON/XOFF with any of the popular USB interface chips from SiLabs or FTDI?
I ran some tests yesterday on an FT232R in Linux and found that after I send an XOFF I can still expect to see another 900 or so characters arrive before it pauses So even if they did respond to the XOFF the moment it was deserialized, it would still have to take into account the transmit FIFO. I will run some more tests with different devices and ports but it is as I expected, that I would need to send an XOFF when the buffer was down to 1k free.
TACHYON UPDATE
Tachyon V2.6 has rearranged the buffer areas so that the receive buffer is followed by the 2k BUFFERS region which now ends at $7F00. When the TACHYON word is encountered it simply changes the buffer size constant which is now handled dynamically so during serial source code load it will allocate at least 2k for serial receive. I still have to implement the software handshake part of it but essentially it will send an XOFF once it is down to 1k free in this mode. An XON gets sent probably when there are less than 512 bytes left. This will mean that line delay can be reduced to zero. At present I can run at 2M baud with 6ms line delay without problems and it takes 38 seconds for the full EXTEND.fth (111,700 characters) to download and compile. Average time to compile a "line" of source is around 10ms by my estimations.
Since Google docs have been troublesome lately due to the size and number of them I like to open I have decided to download them in .odt format so I can use them with LibreOffice and keep copies of this in Dropbox too. The reason I use document format rather than simple text is that I can dress up and highlight the code as needed and include diagrams and even photos. One thing I notice besides being faster to use of course is that when I copy and paste into the Spin IDE it ends up being better formatted in that the code lines up. Before the pasted code indentation used to be all messed up and looked like a dog's breakfast.
EDIT: source code error reporting has finally been improved, it used to annoy me if it spat out an error but I never got around to improving it until now.
If I paste in code it will identify the word that it found the error in and also the word and the rest of the line like this:
pub FINPUT
FILE@ error in FINPUT at FILE@ IF ukey W@ fkey W! ' FGET ukey W! THEN *error*
----------------------------------------------------------------
So I tried to paste in a word I grabbed from EASYFILE as a test and here it reports correctly the name of the definition (in FINPUT) and which word (at FILE@) followed by the remainder of the line. It automatically discards the rest of the load, and exits any compilation mode. The tabbing allows it to break free of the line numbers when it's in TACHYON block load mode (no echo, line numbers and messages).
I think we were using the Silicon Labs CP2103, but I'm not sure how well tested it was. I've since changed jobs and don't have access to the system anymore so I can't run a test. Getting software flow control to be bullet proof could be a challenge - e.g. if an XON is ever lost or corrupted what are the chances that both the host and device have implemented recovery mechanisms? (e.g. timeouts etcetera) Hopefully we're talking about pretty reliable setups with short wires where this isn't a high probability event, but I always figured that it was a marketing checklist item.
EDIT: source code error reporting has finally been improved, it used to annoy me if it spat out an error but I never got around to improving it until now.
If I paste in code it will identify the word that it found the error in and also the word and the rest of the line like this:
pub FINPUT
FILE@ error in FINPUT at FILE@ IF ukey W@ fkey W! ' FGET ukey W! THEN *error*
----------------------------------------------------------------
So I tried to paste in a word I grabbed from EASYFILE as a test and here it reports correctly the name of the definition (in FINPUT) and which word (at FILE@) followed by the remainder of the line. It automatically discards the rest of the load, and exits any compilation mode. The tabbing allows it to break free of the line numbers when it's in TACHYON block load mode (no echo, line numbers and messages).[/QUOTE]
I am trying to learn TSCHYON and I am following the introduction.I got Tachyon loaded into the Prop and Teraterm working.
After Tachyon is loaded I copied and pasted EXTEND.FTH.The last 2 lines was backup and ok.
Earlier I played with Tachyon then Version2.0 and today I loaded Tacyhon V2.6.
Now when I type(after ok) .I2CBUS ,I get an error message" error in COLD at .I2CBUS
I am trying to learn TSCHYON and I am following the introduction.I got Tachyon loaded into the Prop and Teraterm working.
After Tachyon is loaded I copied and pasted EXTEND.FTH.The last 2 lines was backup and ok.
Earlier I played with Tachyon then Version2.0 and today I loaded Tacyhon V2.6.
Now when I type(after ok) .I2CBUS ,I get an error message" error in COLD at .I2CBUS
How can I correct this?
Thank You
Siri
Tachyon has been changing fast and the Intro has not been keeping up with the source.
Your best bet is to always check the source.
.I2CBUS is gone and replaced with
pub lsi2c
PRINT" Scanning I2C bus"
SignI2C
i2csig
BEGIN DUP C@
WHILE
DUP C@ 1 AND CR IF ." Fast" ELSE ." Slow" THEN
SPACE DUP C@ .DEVICE PRINT" at $" DUP C@ .BYTE PRINT" : "
I2CSTART DUP C@ 1 OR SI2C!
16 FOR 0 SI2C@ .BYTE SPACE NEXT \ and list first 8 bytes we read
1 SI2C@ DROP I2CSTOP \ then a dummy nak read
1+
REPEAT
DROP
;
lsi2c Scanning I2C bus
Fast EEPROM or RTC #0 at $A1: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ok
The error you received is from the new error reporting for a word not being found in the dictionary
I know this sounds dumb but what shall I do with code.Shall I cut and paste to the Teraterm terminal.
Pllease educate me.DP
Thanks
Siri
Just use the word: lsi2c instead of the word: .I2CBUS which has been removed.
I included the code for lsi2c so you could see how I found what I was looking for in EXTEND.fth
V2.6 is a work in progress so the error reporting is being refined so that if you are not in the middle of a definition it will report the old way with a short message on the current line. The "error in ... at ..." is mainly for block mode when large blocks of source code such as EXTEND.fth are pasted in and the TACHYON word triggers the block mode where only line numbers, errors, and messages are reported back until an END exits this mode and reports on the load.
@D.P. - if you would like to edit the Intro doc or at least comment on sections or insert suggestions then I am more than happy for you to do so
EDIT: The error reporting has been updated for interactive and block modes. The latest Explorer binary includes this along with the additional 1-wire suite and Conway's Game of Life which btw makes me think that I could write a breakout brick game over serial.
V2.6 is a work in progress so the error reporting is being refined so that if you are not in the middle of a definition it will report the old way with a short message on the current line. The "error in ... at ..." is mainly for block mode when large blocks of source code such as EXTEND.fth are pasted in and the TACHYON word triggers the block mode where only line numbers, errors, and messages are reported back until an END exits this mode and reports on the load.
@D.P. - if you would like to edit the Intro doc or at least comment on sections or insert suggestions then I am more than happy for you to do so
EDIT: The error reporting has been updated for interactive and block modes. The latest Explorer binary includes this along with the additional 1-wire suite and Conway's Game of Life which btw makes me think that I could write a breakout brick game over serial.
I'm looking at the document now. I will start with little additions and subtractions.
I'm looking at the document now. I will start with little additions and subtractions.
Great, because that might tie in nicely to the latest EXPLORER version I'm doing which includes a lot of the little nick-nacky devices that many like to interface. Besides all the stuff that is already built in there are the interfaces for various sensors etc.
Just a quick summary of some of these devices and some of their control words.
PING ( trig echo -- us ) return with ping time in microseconds
DISTANCE ( trig echo -- mm ) return with ping time in millimetres.
--USAGE: #P16 #P17 DISTANCE . 1030 ok
DHT22
DHT ( -- rh% 'C ) return with scaled relative humidity and temperature
--USAGE: #P18 DHT SWAP . SPACE . 466 279 ok
WS2812.SHOW ( buf cnt pin -- ) Update string of WS2812 RGB LEDs on pin from buf for cnt
VOLTS@ ( ch -- voltage ) Read back scaled voltage from pin of MCP3208
VOLTS ( volts pin -- ) Output a voltage onto the pin as a duty-mode RC DAC.
- Waveform generator using RC DAC
- Frequency using counters - HZ KHZ MHZ
-- To drive a piezo transducer differential from 2 I/O USAGE: #P19 APIN #P20 BPIN #P19 LOW #P20 LOW --- sets up P19 and P20 as counter outputs
2500 HZ --- play a tone
MUTE --- stop the tone
or how about a ismple proximity sensor, the closer you get the more it complains!
--- Generates a differential output frequency
pub HZ2 5 CTRMODE HZCON #10000 */ FRQ ;
--- simple proximity alert
pub PROX
#P19 APIN #P20 BPIN --- setup piezo to be driven differentially
#P19 LOW #P20 LOW
BEGIN #P16 #P17 DISTANCE 2000 SWAP - 2* 0 MAX HZ2 50 ms 0 HZ2 100 ms ESC? UNTIL
MUTE
;
- Also various RTC chips, 1-wire devices, I2C devices,
- Character LCD displays
--To print the ping distance onto an LCD USAGE: LCD PRINT" LCD DEMO" CR #P16 #P17 DISTANCE PRINT PRINT" mm"
- Keypad scanning
Maybe even a simple TV display
While testing out various drivers that I am now building into the Explorer image I wondered how it would look if I mirrored the universe from a Game of Life onto a matrix of WS2812 LEDs while updating over a serial terminal. Of course I couldn't do a screen recording with this so I taped the matrix onto the terminal screen and printed a black square to place over the matrix so I could video it. This is the result and while it looks interesting it also demonstrates just how easy it is to interface devices in Tachyon Forth and how fast it runs without the need to dedicate a cog for every little driver as the WS2812 just runs in the main Tachyon cog as does the serial transmit etc. The proximity alert using a ping sensor and a piezo transducer is also a lot of fun too, and only a handful of lines too. Sounds very R2D2ish as you move around.
--- Generates a differential output frequency
pub HZ2 5 CTRMODE HZCON #10000 */ FRQ ;
--- simple proximity alert
pub PROX
#P19 APIN #P20 BPIN --- setup piezo to be driven differentially
#P19 LOW #P20 LOW
BEGIN
#P16 #P17 DISTANCE
DUP 1000 SWAP - 2* 0 MAX HZ2 50 ms 0 HZ2 20 / 200 MIN ms
ESC?
UNTIL
;
Using a DHT22 humidity and temperature sensor is also a piece of cake, I just pass the pin number to the routine and print the x10 results.
18 DHT . SPACE . 222 664 ok
When I first wrote Tachyon I had a the 512x384 VGA graphics object built in so I could test out Tachyon's operation and performance. Sadly that had to go early on as it chewed up most of the hub memory but I always wanted to get around to building in a simple VGA text as that would only need one or two K for buffers. So as an initial test I have incorporated the 32x15 VGA text object and Tachyon can load cog 2 with this object and then reuse the binary's hub memory for the buffer.
You can just use this device as Tachyon's character output like this:
VGA PRINT" HELLO WORLD" CON
or just type VGA to switch the output from the terminal console to VGA and interact there and it will scroll up automatically on the last row.
EDIT: updated now using circuit components (RESISTOR LED NPN etc) and Turtle like graphics ( 4 RIGHT 3 DOWN 4 LEFT 3 UP etc) which automatically selects the correct symbols to draw boxes.
EDIT: Just added BIG font which draws 5x7 characters using a text symbol as a "dot". This allows up to 2 lines of 5 big characters.
This is the Forth code to interface to the VGA cog. (Timed DEMO which takes 40ms)
TACHYON [~
FORGET VGA.fth
: VGA.fth PRINT" VGA text driver 150622-0000" ;
--- COGINIT ( code pars cog -- ret )
16 == vgapins
BYTE color,row,col --- current palette color, row and column
TABLE colors 64 ALLOT
TABLE colorsav 64 ALLOT
--- turn the display on or off
pub SCREENSAVER OFF
pub DISPLAY ( on/off -- ) IF colorsav @ IF colorsav colors 64 CMOVE THEN ELSE colors @ IF colors colorsav 64 CMOVE colors 64 ERASE THEN THEN ;
TABLE vgapars
0 , 1 , --- 0:status 1:enable
vgapins 7 + , --- 2:pins
%1000 , --- 3:mode
@VGA , colors , --- 4:screen 5:colors
32 , 15 , --- 6:cols 7:rows
1 , 1 , --- 8:hx 9:vx
0 , 0 , --- 10:ho 11:vo
512 , 10 , 75 , 43 , --- 12:hd 13:hf 14:hs 15:hb
480 , 11 , 2 , 31 , --- 16:vd 17:vf 18:vs 19:vb
CLKFREQ 2 >> , --- 20:rate
{
'' long vga_status '0/1/2 = off/visible/invisible read-only
'' long vga_enable '0/non-0 = off/on write-only
'' long vga_pins '%pppttt = pins write-only
'' long vga_mode '%tihv = tile,interlace,hpol,vpol write-only
'' long vga_screen 'pointer to screen (words) write-only
'' long vga_colors 'pointer to colors (longs) write-only
'' long vga_ht 'horizontal tiles write-only
'' long vga_vt 'vertical tiles write-only
'' long vga_hx 'horizontal tile expansion write-only
'' long vga_vx 'vertical tile expansion write-only
'' long vga_ho 'horizontal offset write-only
'' long vga_vo 'vertical offset write-only
'' long vga_hd 'horizontal display ticks write-only
'' long vga_hf 'horizontal front porch ticks write-only
'' long vga_hs 'horizontal sync ticks write-only
'' long vga_hb 'horizontal back porch ticks write-only
'' long vga_vd 'vertical display lines write-only
'' long vga_vf 'vertical front porch lines write-only
'' long vga_vs 'vertical sync lines write-only
'' long vga_vb 'vertical back porch lines write-only
'' long vga_rate 'tick rate (Hz) write-only
}
--- address a vga parameter
pub @VP ( reg -- addr ) 2* 2* vgapars + ;
pub screen 4 @VP @ ;
pub cols 6 @VP @ ;
pub rows 7 @VP @ ;
--- test - reverses all colors
pub REVERSE colors 64 ADO I @ INVERT I ! 4 +LOOP ;
TABLE palette
--- RRGGBB RRGGBB
%001000 | %000000 | --- 0 green on black
%101000 | %000000 | --- 1 yel on black
%111111 | %000001 | --- 2 white on dark blue
%111100 | %010100 | --- 3 yel on tan
%100000 | %000000 | --- 4 red on black
%001111 | %000101 | --- 5 cyan on teal
%001000 | %101110 | --- 6 green on green gray
%101010 | %000100 | --- 7 white on dark green
pub CL 7 AND color C! ;
pub SCREEN! ( word addr -- ) 2* screen + W! ;
pub setcolors ( ptr -- )
8 0 DO
\ DUP I 2* + W@ W>B 2* 2* SWAP 2* 2* SWAP
DUP I 2* + C@ 2* 2* --- fore
OVER I 2* 1+ + C@ 2* 2* --- back
( ptr fore back )
OVER DUP 24 SHL SWAP 8 SHL + --- fore << 24 + fore << 8
OVER DUP 16 SHL + +
( ptr fore back col1 )
colors I 2* 2* 2* + !
SWAP DUP 24 SHL SWAP 16 SHL +
( ptr back col2 )
SWAP DUP 8 SHL + +
colors I 2* 2* 2* 4 + + !
LOOP
DROP
;
pri clear
$220
pri vfill ( word -- )
screen W!
screen DUP 2+ rows cols * 1- 2* CMOVE
pri home
col C~ row C~
;
pub XY ( x y -- )
row C! col C!
;
pri scroll
screen DUP cols 2* + SWAP rows 1- cols 2* * CMOVE
rows 1- cols 2* * screen + cols 2* ADO $220 I W! 2 +LOOP
;
pri newline
col C~
row C++
row C@ rows => IF scroll row C-- THEN
;
BYTE vflg
LONG vgaboot
pub !VGA
boot @ vgaboot @ <> 0EXIT --- only load vga cog if needed
boot @ vgaboot !
@VGA vgapars 2 COGINIT DROP
palette setcolors
clear
;
pub VCHAR ( ch -- )
>B
DUP 1 AND color C@ 2* + --- (color << 1 + c & 1 )
10 <<
$200 +
SWAP 1 ANDN +
DUP row C@ cols * col C@ + SCREEN!
DROP
col C++ col C@ cols => IF newline THEN
;
pri vtab
BEGIN BL VCHAR col C@ 7 AND 0= UNTIL
;
pub VCTL ( ctl -- )
vflg C@ 0= IF
SWITCH
$1B CASE vflg C~~ BREAK
$01 CASE home BREAK
$09 CASE vtab BREAK
$08 CASE col C@ IF col C-- THEN BREAK
$0D CASE col C~ BREAK
$0A CASE newline BREAK
$0C CASE clear BREAK
THEN
SWITCH@ VCHAR vflg C~
;
pub VEMIT ( ch -- )
DUP BL < IF VCTL ELSE VCHAR THEN
;
--- make the VGA display the current output device
pub VGA !VGA ' VEMIT uemit W! ;
--- EXTRAS ---
TABLE waves $81 | $82 | $85 | $86 |
: .LA ( long -- ) BL FOR DUP 30 SHR 3 AND waves + C@ EMIT 2* NEXT DROP ;
--- simple logic analyser display - usage: $4000 14 LA or home $4000 14 LA
: LA ( addr longs -- ) 2* 2* VGA ADO I @ .LA 4 +LOOP CON ;
: LADEMO
$FF80
VGA 2 CL CLS VGA PRINT" TACHYON LOGIC ANALYSER" CR
0 CL
PRINT" Address = " DUP .LONG CR
7 CL
12 LA
VGA home CR 13 1 DO CR I $10 PRINTNUM LOOP
CON
;
{ testing
: LAB ( addr -- )
8 0 DO I MASK ( addr mask ) OVER 32 ADO I C@ OVER AND
;
: VSYN BEGIN 16 PIN@ 0= UNTIL ;
: OVERLAY ( buffer -- ) screen BEGIN VSYN OVER 4 @VP ! 5 ms VSYN DUP 4 @VP ! 5 ms ESC? UNTIL 2DROP ;
}
--- CIRCUIT COMPONENTS ---
: DIODE $A6 VCHAR $A7 VCHAR ;
: NPN $1C VCHAR $1E VCHAR ;
: PNP $1C VCHAR $1F VCHAR ;
: PHOTO $1D VCHAR $1E VCHAR ;
: INDUCTOR $B7 VCHAR $B8 VCHAR ;
: WIRE $90 + VCHAR ;
: LED $A6 VCHAR $A8 VCHAR ;
: CAP $AB VCHAR ;
: RESISTOR $BD VCHAR $BE VCHAR ;
: PORT ( dir -- ) 1 AND $BA + VCHAR ;
: GND $18 VCHAR ;
: VCC $17 VCHAR ;
}
--- experimenting with Turtle like drawing using text symbols
BYTE tdir
pri LEFT1
tdir C@ SWITCH
8 CASE row C++ $9E VCHAR BREAK
2 CASE row C-- $9C VCHAR BREAK
$90 VCHAR
;
pub LEFT FOR LEFT1 4 tdir C! -2 col C+! NEXT ;
pri RIGHT1
tdir C@ SWITCH
2 CASE row C-- $9D VCHAR BREAK
8 CASE row C++ $9F VCHAR BREAK
$90 VCHAR
;
pub RIGHT FOR RIGHT1 6 tdir C! NEXT ;
pri UP1
tdir C@ SWITCH
6 CASE col C-- $9C VCHAR BREAK
4 CASE $9D VCHAR BREAK
$91 VCHAR
;
pub UP FOR UP1 8 tdir C! col C-- row C-- NEXT ;
pri DOWN1
tdir C@ SWITCH
6 CASE $9E VCHAR BREAK
4 CASE $9F VCHAR BREAK
$91 VCHAR
;
pub DOWN FOR DOWN1 2 tdir C! col C-- row C++ NEXT ;
pub BOX ( width height -- ) OVER RIGHT DUP DOWN SWAP LEFT UP 1 RIGHT ;
pub DEMO
VGA CLS 7 CL
9 1 XY PRINT" TACHYON FORTH"
8 0 XY 14 3 BOX
0 3 XY 0 CL $100 0 DO I CL I VCHAR LOOP
--- draw a circuit
1 CL VCC
CR 13 WIRE 0 WIRE RESISTOR 0 WIRE LED 0 WIRE 11 WIRE 0 WIRE 1 PORT PRINT" rst"
CR 0 PORT 0 WIRE RESISTOR 0 WIRE CAP 0 WIRE NPN
CR TAB GND
16 11 XY 2 CL 8 4 BOX
5 CL 17 12 XY 6 2 BOX
CON
;
]~ END
EDIT: Here is a simple waveform display that will display up to 15 longs (without scrolling) as logic analyser waveforms using the Parallax font.
TABLE waves $81 | $82 | $85 | $86 |
: .LA ( long -- ) BL FOR DUP 30 SHR 3 AND waves + C@ EMIT 2* NEXT DROP ;
--- simple logic analyser display - usage: $4000 14 LA - or - home $4000 14 LA
: LA ( addr longs -- ) 2* 2* VGA ADO I @ .LA 4 +LOOP CON ;
I am surprised just how versatile a simple 32x15 video can be after also adding in the big digit mode for some of my applications. Since I can also "plot" points on the screen using those big dots I thought I'd have a go at a game like BREAKOUT. So I've spent the past hour just writing some basics to draw up the screen and created the outline of the ball actions.
At this point I might or might not have more time to do too much but here's the code where if you find the link at the bottom of it you can go to the online Google code doc and join in bringing this game to life.
How about it?
EDIT: By using programmable fonts in addition to the font table I can increase the ball movement resolution by 16 times. My special characters access the top of BUFFERS for a dynamically drawn ball pattern based on the last 4/5 bits of ball x and y which now have a range/resolution of 512x480 although I will probably drop that to 128x120.
TACHYON [~
FORGET BREAKOUT.FTH
pub BREAKOUT.FTH PRINT" BREAKOUT GAME using 32x15 VGA text 150625.1400 " ;
14 == audio --- square wave output audio
TIMER duration
pri SILENCE
audio FLOAT --- the background timer cog can't directly access the sound CTR
REVERSE
;
pri !SOUND
audio APIN
MUTE
0 duration TIMEOUT --- setup duration timer
' SILENCE duration ALARM --- timeout will mute sound
;
--- hitting a wall sound
pub BONK
REVERSE --- let the screen flash briefly
300 HZ 50 duration TIMEOUT
;
--- palette to suit game
TABLE gamepal
--- RRGGBB RRGGBB
%100000 | %000000 | --- red on black
%001000 | %000000 | --- green on black
%000010 | %000000 | --- blue
%111100 | %000000 | --- yel
%100010 | %000000 | --- mag
%001010 | %000000 | --- cyan
%010101 | %000000 | --- gry
%101010 | %000000 | --- white
0 == red
1 == grn
2 == blu
3 == yel
4 == mag
5 == cyan
6 == gry
7 == wht
BYTE bx,by,bdir
pub BALL
red CL bx C@ by C@ XY 15 VCHAR
;
3 == backwall
--- initialize the brick wall
pub !BRICKS
0 backwall XY 32 4 * 0 DO I 7 AND CL 14 VCHAR LOOP
;
--- check if there is a brick here and remove, return with result
pub BRICK? ( x y -- brick )
cols * + 2* screen +
DUP C@ 14 = --- is it a brick? ( addr brick )
BL ROT C! --- remove the brick
DUP IF BONK THEN --- make a sound
;
--- check and remove brick if ball direction "hits" this brick
--- return if there was a brick there
pub ?BRICK ( -- )
bdir C@ SWITCH
7 CASE bx C@ 1- by C@ 1- BRICK? IF 1 bdir C! THEN BREAK
;
pub ?BALL
bdir C@ SWITCH
7 CASE BREAK
9 CASE BREAK
1 CASE BREAK
3 CASE BREAK
;
pri !BALL bdir C~ 16 bx C! 7 by C! BALL ;
BYTE px,py
pub PADDLE ( -- )
yel CL
0 py C@ XY BL FOR BL VCHAR NEXT
px C@ py C@ XY 14 VCHAR 14 VCHAR 14 VCHAR
;
--- PADDLE MOVEMENTS
pub L px C-- px C@ $FF = IF px C~ THEN PADDLE ;
pub R px C++ px C@ 29 > IF 29 px C! THEN PADDLE ;
--- check to see if the ball has hit the paddle and change it's direction based on the edge hit
pub ?PADDLE
;
pri !PADDLE 13 py C! 15 px C! PADDLE ;
--- game control keys ---
pub GAMEKEY
SWITCH
"Z" CASE L BREAK
"X" CASE R BREAK
$1B CASE CON CONSOLE BREAK
;
pub SPLASH
VGA CLS
--- draw boxes within boxes
7 0 DO I I XY 7 I - CL 30 I 2* - 15 I 2* - BOX 50 ms LOOP
7 7 XY VGA PRINT" TACHYON BREAKOUT"
1 second 8 FOR REVERSE 100 ms NEXT
;
pub BREAKOUT
!VGA !SOUND
gamepal setcolors
2 seconds SPLASH
CLS !PADDLE !BALL !BRICKS
7 14 XY 2 CL PRINT" TACHYON BREAKOUT "
BEGIN
KEY GAMEKEY
?BALL
?BRICK
?PADDLE
AGAIN
;
ALIAS BREAKOUT START
{ Edit this online at:
https://docs.google.com/document/d/1qThzvhYGafeseKTnCaH1OMZC-dFfy0mKKE-DXlCpBfg/edit?usp=sharing
}
END
I managed to get enough time to check out the pixel plotting using a programmable character for the ball so that the ball was much smaller than a tile and had a much finer movement resolution of 128x120.
This game is more about an interactive tutorial both in Tachyon programming and methods as well as writing and testing a simple video games. So anyone who wants to contribute can and anyone who wants to follow along can.
Here's the screenshot of the game at present where I am just testing ball movements and scoring etc.
Basically to start programming this game I created a simple brick wall with a nothing more than a one-liner.
--- initialize the brick wall
pub !BRICKS 0 backwall XY cols 4 * 0 DO I 7 AND CL 14 VCHAR LOOP ; --- 4 rows of colored bricks/tiles from backwall (gap)
The first brick is laid at the XY coordinates of 0 and backwall which is a constant of 4, so starting from the left hand side on the 5th row (0,1,2,3,4) bricks are drawn.
cols 4 * 0 DO --- will setup the loop to draw 4 rows of bricks where cols are the number of tiles in a column (32)
I 7 AND CL --- will grab the last 3 bits of the loop index I and set the tile color with CL from a palette of 8 different combinations
14 VCHAR --- writes the value 14 which is represented as a rounded square in the font table, to the next character position in the screen as VCHAR increments the column position and generates a newline at end-of-line.
LOOP of course increments the loop index I until it is equal to the limit cols 4 *.
The paddle is implemented very simply too.
BYTE px,py
pub PADDLE ( -- )
yel CL
0 py C@ XY cols FOR BL VCHAR NEXT --- erase the whole paddle row
px C@ py C@ XY $84 VCHAR $8D VCHAR --- draw the paddle
;
--- PADDLE MOVEMENTS
pub L px C@ IF px C-- PADDLE THEN ;
pub R px C@ cols 2 - < IF px C++ PADDLE THEN ;
For testing purposes the main loop reads the serial terminal characters so the Z and X move the paddle left and right while 0..9 are used to manually control the ball movement.
Since Forth is interactive it is very simple to test out various ideas even with one-liners, no need to compile.
The next thing to do is to implement simple ball bounce, and then more complex variations too.
I managed to get enough time to check out the pixel plotting using a programmable character for the ball so that the ball was much smaller than a tile and had a much finer movement resolution of 128x120.
This game is more about an interactive tutorial both in Tachyon programming and methods as well as writing and testing a simple video games. So anyone who wants to contribute can and anyone who wants to follow along can.
Here's the screenshot of the game at present where I am just testing ball movements and scoring etc.
Basically to start programming this game I created a simple brick wall with a nothing more than a one-liner.
--- initialize the brick wall
pub !BRICKS 0 backwall XY cols 4 * 0 DO I 7 AND CL 14 VCHAR LOOP ; --- 4 rows of colored bricks/tiles from backwall (gap)
The first brick is laid at the XY coordinates of 0 and backwall which is a constant of 4, so starting from the left hand side on the 5th row (0,1,2,3,4) bricks are drawn.
cols 4 * 0 DO --- will setup the loop to draw 4 rows of bricks where cols are the number of tiles in a column (32)
I 7 AND CL --- will grab the last 3 bits of the loop index I and set the tile color with CL from a palette of 8 different combinations
14 VCHAR --- writes the value 14 which is represented as a rounded square in the font table, to the next character position in the screen as VCHAR increments the column position and generates a newline at end-of-line.
LOOP of course increments the loop index I until it is equal to the limit cols 4 *.
The paddle is implemented very simply too.
BYTE px,py
pub PADDLE ( -- )
yel CL
0 py C@ XY cols FOR BL VCHAR NEXT --- erase the whole paddle row
px C@ py C@ XY $84 VCHAR $8D VCHAR --- draw the paddle
;
--- PADDLE MOVEMENTS
pub L px C@ IF px C-- PADDLE THEN ;
pub R px C@ cols 2 - < IF px C++ PADDLE THEN ;
For testing purposes the main loop reads the serial terminal characters so the Z and X move the paddle left and right while 0..9 are used to manually control the ball movement.
Since Forth is interactive it is very simple to test out various ideas even with one-liners, no need to compile.
The next thing to do is to implement simple ball bounce, and then more complex variations too.
Neat stuff, will be testing with you. Can you tell us what terminal/emulator setup you are using?
Neat stuff, will be testing with you. Can you tell us what terminal/emulator setup you are using?
You reminded me that I mentioned in an earlier post that I said I could write a game like breakout for an ANSI compatible serial terminal such as minicom or Teraterm. This one however is written using the 32x15 VGA object embedded in V2.7 or the VGA Explorer binary.
I chose the simple 32x15 text mode as that had a small memory footprint of less than 1k so the video buffer is actually the hub memory that was occupied by the object's binary. But 15 lines of text would hardly make for smooth ball movement so I worked out that I could write a character value > $FF into a tile that would map past the font tables and wrap back into RAM at $7E80 with a character value of $3FA in this case. This allowed me to generate my own 16x32 patterns which I could then do so dynamically for the ball movement resulting in up to 512x480 resolution although that has been reduced to 128x120 with a ball that is 4x4 pixels.
The ball plotting then has to draw a programmable character and insert that in the correct position on the screen with this code.
--- plot ball as 4x4 block - 190us
pub BPLOT ( x y -- )
OVER 2 SHR OVER 3 SHR XY
$3FA VCHAR! --- maps to programmable char at $7E80
SWAP 3 AND 3 SHL $AA SWAP SHL --- generate a dot in the correct x position
$7E80 128 ERASE
SWAP 7 AND 4 SHL $7E80 + 2DUP !
4 + 2DUP ! 4 + 2DUP ! 4 + !
;
Because font characters are interleaved I end up using all 128 bytes (of two "font" characters) rather than 64 bytes (16x32) to keep it simple.
The ball movement is controlled by a single digit to indicate direction as viewed on a numeric keypad so that 7 is up and left while 3 is down and right etc. I use the serial terminal as the keyboard input so at present the digits 0...9 are used to manually control the ball for testing. This is the case statement that checks which key has been pressed.
pub GAMEKEY
SWITCH
"Z" CASE L BREAK
"X" CASE R BREAK
"R" CASE REVERSE BREAK
SWITCH@ "0" "9" WITHIN IF SWITCH@ $0F AND bdir C! BREAK
$1B CASE GAMEOVER CON CONSOLE BREAK
;
So you can see the second last line where the switch value to tested for a digit manually and used to set the ball direction bdir.
Of course I could just dive into it and get it working but I'm using this as a slowmo into developing apps written in Tachyon and getting immediate results along the way. As in the case of the brick wall, all it takes in many instances is nothing more than one well thought out one-liner such as !VGA 0 4 XY cols 4 * 0 DO I 7 AND CL 14 VCHAR LOOP which when entered from a freshly booted system would immediately draw the brick wall as simple as that.
BTW, I could easily add serial output to this game as is to display on an ANSI terminal at the same time, even if VGA itself isn't used.
Comments
Peter's improvements made the code several orders of magnitude faster than the same code in Spin and a whole lot easier to work with.
... Enjoy! BBR
thanks Brian,
included most of your comments in the source document.
And fixed the bug you reported in the print routine.
And Peter made some enhancements again as well.
https://docs.google.com/document/d/1wJSI3-ozTeEEtfLECTXEzE20lFyVLavdwmCv_z7Ftg0/pub
EDIT: Couldn't help but modify it again so that the bits in each cell are displayed vertically for 32 lines and now the "lines" constant is used for the width. In this way we can also specify the width at runtime<br>
<br>The code size is 541 bytes including pattern setups with 284 byte in dictionary space.
The nextgen function executes in 57.6ms and the .universe function takes another 17.4ms (non-buffered).
EDIT: Updated the latest EXPLORER binary to include LIFE - runs at sedate 115200 baud - just type "demo"
(This post should just about crack the 250,000 views mark! )
Thanks, I thought it was crazy when once it had 10,000 views, and that was after only 2 months!
As for the game of life, how wide can you set your serial terminal screen? 128 characters? How about 476 wide!
For my 1920x1080 screen that means that characters must be around 4 pixels wide including spacing!!!
Should I be using a different version of EXTEND.FTH or the Tachyon kernel or am I doing something wrong?
Just checked the files in the Dropbox and they are fine. There shouldn't be any problems with nested { } comments either. Make sure you have set a line delay of around 15ms as there is no handshaking. Other than that, all should just work I use minicom on Linux or Teraterm on Windows and normally just copy&paste. There's also the complete Explorer binary image available which already includes EXTEND.fth.
I was just killing time and nosing around a little, when I came across Ray's comment
Congratulations from me also. With all of your hard work and dedication, you have built a thread that will be remembered for a long time. Besides the pride that is obtained from one's hard work, there should be some kind of award or reward for this achievement.
My hat is off to you
Thanks Bruce, all of us are making the forum what it is, but I think we could certainly do with more contributors like yourself though who are actively using the Props to get real work done. I've just been trying to make the Prop a lot easier for many to get into but it's a bit like a marketing exercise where you know the product's good and that it is a great solution, but like trying to steer people into thinking about using Linux instead of Windows, it's an uphill battle (does it run Office 360? !$%^&#@!).
But I find the Tachyon thread a bit of a mystery too, it's like there are only so many people out there who have put their Forth hand up so to speak yet the steady volume of views seems to indicate that there are a lot of interested lurkers too. I've had experience in the past where it turns out that some university's EE dept somewhere might use it in their course material with embedded system control and robotics etc, so there could be a ton of anonymous students using it and occasionally they will contact me directly.
I found out a long time ago that unless you are in the mainstream, you will not gain wide "recognition". So if this was an Arduino programmed in C then I could possibly be "famous"
BTW. Telnet into tachyonforth.com to port 10001 and talk to Tachyon or just type "demo" to run Conway's Game of Life (defaults to 64 wide by 32 lines). Hit CR to exit and specify other widths and parameters or just play with Tachyon. Remember that this is mostly just running from one cog while running the network and filesystem software, and the only "enhancement" is a 64kB EEPROM rather than a 32kB.
So far I tried minicom (even with a line delay of 250ms, even though that's a bit much 'retro' for my taste -- no chance in getting software flow control?) on Raspberian to talk to the Prop on the RPi Propeller hat board. Let me try a few other things ...
I don't think I can use the binaries (at least earlier attempts were unsuccessful), as the RPi hat board uses a 6MHz crystal for some reason which throws off the UART timing.
Tachyon 2.5 on Propeller Hat is up&running, hurray!
There's also a 6MHz Explorer binary in the dropbox files too that you could use, it just happens to still be a V2.4 but otherwise no difference although I will update them both shortly.
BTW, I have no problem downloading to a standard 80MHz Prop at 2M baud with 10ms line delay so 250ms is never ever required. Software handshaking is of no use because PC UARTs and USB bridges have such huge FIFOs in both directions and XON/XOFF characters just end up in a queue rather than being processed the moment they are deserialized. There is always the possibility of a handshake line but most Prop systems don't support it and that would reduce the number of I/O available already. Anyway, 15ms line delay is easy to set, there is never any real need to set it any slower as Tachyon does not wait until the end of line to interpret/compile, it will do it word by word.
So I figured that as long as I had a buffer that was big enough so that even after an XOFF got delayed in the PC port's queue it would eventually get through and pause the transmit data being sent to the Prop without losing any characters in the meantime. I therefore reasoned that the 2K BUFFERS area wouldn't be used during any major block loading so what I could do was make the TACHYON word switch the receive buffer to BUFFERS and set the internal size for 2K. However to make it work effectively the serial receive routine would have to send an XOFF not at the 2K boundary but probably closer to the 1K boundary to allow for long transmit and receive FIFO queues.
The other thing that helped a bit too in earlier versions was preprocessing the text stream in the serial receive cog. It would interpret tilde commands such as [~ and ]~ to set modes so comments and extras spaces would not be buffered etc. The feature was removed because it had to be smart enough to know when and how to do this which didn't always work. If I simply get it to remove extra spaces and simple line comments then this should help.
The aim now is to reduce the line delay to an absolute minimum or preferably none at all and to test this with various terminals to make sure they respond well enough to soft handshaking.
Have you tried XON/XOFF with any of the popular USB interface chips from SiLabs or FTDI?
I ran some tests yesterday on an FT232R in Linux and found that after I send an XOFF I can still expect to see another 900 or so characters arrive before it pauses
TACHYON UPDATE
Tachyon V2.6 has rearranged the buffer areas so that the receive buffer is followed by the 2k BUFFERS region which now ends at $7F00. When the TACHYON word is encountered it simply changes the buffer size constant which is now handled dynamically so during serial source code load it will allocate at least 2k for serial receive. I still have to implement the software handshake part of it but essentially it will send an XOFF once it is down to 1k free in this mode. An XON gets sent probably when there are less than 512 bytes left. This will mean that line delay can be reduced to zero. At present I can run at 2M baud with 6ms line delay without problems and it takes 38 seconds for the full EXTEND.fth (111,700 characters) to download and compile. Average time to compile a "line" of source is around 10ms by my estimations.
Since Google docs have been troublesome lately due to the size and number of them I like to open I have decided to download them in .odt format so I can use them with LibreOffice and keep copies of this in Dropbox too. The reason I use document format rather than simple text is that I can dress up and highlight the code as needed and include diagrams and even photos. One thing I notice besides being faster to use of course is that when I copy and paste into the Spin IDE it ends up being better formatted in that the code lines up. Before the pasted code indentation used to be all messed up and looked like a dog's breakfast.
EDIT: source code error reporting has finally been improved, it used to annoy me if it spat out an error but I never got around to improving it until now.
If I paste in code it will identify the word that it found the error in and also the word and the rest of the line like this: So I tried to paste in a word I grabbed from EASYFILE as a test and here it reports correctly the name of the definition (in FINPUT) and which word (at FILE@) followed by the remainder of the line. It automatically discards the rest of the load, and exits any compilation mode. The tabbing allows it to break free of the line numbers when it's in TACHYON block load mode (no echo, line numbers and messages).
.
.
.
EDIT: source code error reporting has finally been improved, it used to annoy me if it spat out an error but I never got around to improving it until now.
If I paste in code it will identify the word that it found the error in and also the word and the rest of the line like this: So I tried to paste in a word I grabbed from EASYFILE as a test and here it reports correctly the name of the definition (in FINPUT) and which word (at FILE@) followed by the remainder of the line. It automatically discards the rest of the load, and exits any compilation mode. The tabbing allows it to break free of the line numbers when it's in TACHYON block load mode (no echo, line numbers and messages).[/QUOTE]
Oh thank you so much for this addition.
dp
After Tachyon is loaded I copied and pasted EXTEND.FTH.The last 2 lines was backup and ok.
Earlier I played with Tachyon then Version2.0 and today I loaded Tacyhon V2.6.
Now when I type(after ok) .I2CBUS ,I get an error message" error in COLD at .I2CBUS
How can I correct this?
Thank You
Siri
Tachyon has been changing fast and the Intro has not been keeping up with the source.
Your best bet is to always check the source.
.I2CBUS is gone and replaced with The error you received is from the new error reporting for a word not being found in the dictionary
Pllease educate me.DP
Thanks
Siri
Just use the word: lsi2c instead of the word: .I2CBUS which has been removed.
I included the code for lsi2c so you could see how I found what I was looking for in EXTEND.fth
@D.P. - if you would like to edit the Intro doc or at least comment on sections or insert suggestions then I am more than happy for you to do so
EDIT: The error reporting has been updated for interactive and block modes. The latest Explorer binary includes this along with the additional 1-wire suite and Conway's Game of Life which btw makes me think that I could write a breakout brick game over serial.
I'm looking at the document now. I will start with little additions and subtractions.
Great, because that might tie in nicely to the latest EXPLORER version I'm doing which includes a lot of the little nick-nacky devices that many like to interface. Besides all the stuff that is already built in there are the interfaces for various sensors etc.
Just a quick summary of some of these devices and some of their control words.
PING ( trig echo -- us ) return with ping time in microseconds
DISTANCE ( trig echo -- mm ) return with ping time in millimetres.
--USAGE: #P16 #P17 DISTANCE . 1030 ok
DHT22
DHT ( -- rh% 'C ) return with scaled relative humidity and temperature
--USAGE: #P18 DHT SWAP . SPACE . 466 279 ok
WS2812.SHOW ( buf cnt pin -- ) Update string of WS2812 RGB LEDs on pin from buf for cnt
VOLTS@ ( ch -- voltage ) Read back scaled voltage from pin of MCP3208
VOLTS ( volts pin -- ) Output a voltage onto the pin as a duty-mode RC DAC.
- Waveform generator using RC DAC
- Frequency using counters - HZ KHZ MHZ
-- To drive a piezo transducer differential from 2 I/O USAGE:
#P19 APIN #P20 BPIN #P19 LOW #P20 LOW --- sets up P19 and P20 as counter outputs
2500 HZ --- play a tone
MUTE --- stop the tone
or how about a ismple proximity sensor, the closer you get the more it complains! - Also various RTC chips, 1-wire devices, I2C devices,
- Character LCD displays
--To print the ping distance onto an LCD USAGE: LCD PRINT" LCD DEMO" CR #P16 #P17 DISTANCE PRINT PRINT" mm"
- Keypad scanning
Maybe even a simple TV display
Using a DHT22 humidity and temperature sensor is also a piece of cake, I just pass the pin number to the routine and print the x10 results.
18 DHT . SPACE . 222 664 ok
Link to the VGA Explorer binary.
You can just use this device as Tachyon's character output like this:
VGA PRINT" HELLO WORLD" CON
or just type VGA to switch the output from the terminal console to VGA and interact there and it will scroll up automatically on the last row.
EDIT: updated now using circuit components (RESISTOR LED NPN etc) and Turtle like graphics ( 4 RIGHT 3 DOWN 4 LEFT 3 UP etc) which automatically selects the correct symbols to draw boxes.
EDIT: Just added BIG font which draws 5x7 characters using a text symbol as a "dot". This allows up to 2 lines of 5 big characters.
This is the Forth code to interface to the VGA cog. (Timed DEMO which takes 40ms)
EDIT: Here is a simple waveform display that will display up to 15 longs (without scrolling) as logic analyser waveforms using the Parallax font.
At this point I might or might not have more time to do too much but here's the code where if you find the link at the bottom of it you can go to the online Google code doc and join in bringing this game to life.
How about it?
EDIT: By using programmable fonts in addition to the font table I can increase the ball movement resolution by 16 times. My special characters access the top of BUFFERS for a dynamically drawn ball pattern based on the last 4/5 bits of ball x and y which now have a range/resolution of 512x480 although I will probably drop that to 128x120.
This game is more about an interactive tutorial both in Tachyon programming and methods as well as writing and testing a simple video games. So anyone who wants to contribute can and anyone who wants to follow along can.
Here's the screenshot of the game at present where I am just testing ball movements and scoring etc.
Attachment not found.
Editable source code document link
Basically to start programming this game I created a simple brick wall with a nothing more than a one-liner.
--- initialize the brick wall
pub !BRICKS 0 backwall XY cols 4 * 0 DO I 7 AND CL 14 VCHAR LOOP ; --- 4 rows of colored bricks/tiles from backwall (gap)
The first brick is laid at the XY coordinates of 0 and backwall which is a constant of 4, so starting from the left hand side on the 5th row (0,1,2,3,4) bricks are drawn.
cols 4 * 0 DO --- will setup the loop to draw 4 rows of bricks where cols are the number of tiles in a column (32)
I 7 AND CL --- will grab the last 3 bits of the loop index I and set the tile color with CL from a palette of 8 different combinations
14 VCHAR --- writes the value 14 which is represented as a rounded square in the font table, to the next character position in the screen as VCHAR increments the column position and generates a newline at end-of-line.
LOOP of course increments the loop index I until it is equal to the limit cols 4 *.
The paddle is implemented very simply too.
For testing purposes the main loop reads the serial terminal characters so the Z and X move the paddle left and right while 0..9 are used to manually control the ball movement.
Since Forth is interactive it is very simple to test out various ideas even with one-liners, no need to compile.
The next thing to do is to implement simple ball bounce, and then more complex variations too.
Neat stuff, will be testing with you. Can you tell us what terminal/emulator setup you are using?
You reminded me that I mentioned in an earlier post that I said I could write a game like breakout for an ANSI compatible serial terminal such as minicom or Teraterm. This one however is written using the 32x15 VGA object embedded in V2.7 or the VGA Explorer binary.
I chose the simple 32x15 text mode as that had a small memory footprint of less than 1k so the video buffer is actually the hub memory that was occupied by the object's binary. But 15 lines of text would hardly make for smooth ball movement so I worked out that I could write a character value > $FF into a tile that would map past the font tables and wrap back into RAM at $7E80 with a character value of $3FA in this case. This allowed me to generate my own 16x32 patterns which I could then do so dynamically for the ball movement resulting in up to 512x480 resolution although that has been reduced to 128x120 with a ball that is 4x4 pixels.
The ball plotting then has to draw a programmable character and insert that in the correct position on the screen with this code. Because font characters are interleaved I end up using all 128 bytes (of two "font" characters) rather than 64 bytes (16x32) to keep it simple.
The ball movement is controlled by a single digit to indicate direction as viewed on a numeric keypad so that 7 is up and left while 3 is down and right etc. I use the serial terminal as the keyboard input so at present the digits 0...9 are used to manually control the ball for testing. This is the case statement that checks which key has been pressed.
pub GAMEKEY
SWITCH
"Z" CASE L BREAK
"X" CASE R BREAK
"R" CASE REVERSE BREAK
SWITCH@ "0" "9" WITHIN IF SWITCH@ $0F AND bdir C! BREAK
$1B CASE GAMEOVER CON CONSOLE BREAK
;
So you can see the second last line where the switch value to tested for a digit manually and used to set the ball direction bdir.
Of course I could just dive into it and get it working but I'm using this as a slowmo into developing apps written in Tachyon and getting immediate results along the way. As in the case of the brick wall, all it takes in many instances is nothing more than one well thought out one-liner such as !VGA 0 4 XY cols 4 * 0 DO I 7 AND CL 14 VCHAR LOOP which when entered from a freshly booted system would immediately draw the brick wall as simple as that.
BTW, I could easily add serial output to this game as is to display on an ANSI terminal at the same time, even if VGA itself isn't used.