-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathchat-host.mu4
46 lines (34 loc) · 1.41 KB
/
chat-host.mu4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2025 David Frech. (Read the LICENSE for details.)
| This code interfaces between the protocol (low-level) code and the
| interact code.
loading S08 Chat (host)
hex
: c.setup-chunk ( buf a u - u) swap cx.addr swap m ! ;
| For chunked read and write, if chunk count is 0, don't do anything.
: c.read ( buf a u)
c.setup-chunk ?if dup cx.read-n for b> m& next then ;
: c.write ( buf a u)
c.setup-chunk ?if for m* cx.write-1 next then ;
: flash-chunk-until-error ( len - status)
for m* cx.flash-1 dup 0c0 xor if rdrop ^ then drop next
0c0 ;
| Helper for c.flash. Set an address, and write a byte there.
: chat-c! ( b a) cx.addr cx.write-1 ;
: c.flash ( buf a u cmd - status)
30 \eq FSTAT chat-c! ( clear flash errors)
\m flash-command chat-c!
c.setup-chunk flash-chunk-until-error
00 \m flash-command chat-c! ;
: c.stacked-pc [ @ram #ram + 2 - #] cx.addr 2 cx.read-n w> ;
: c.hello ( - in-ram? #chunk)
resync ( exit BDM loop, if running; resync chat protocol)
cx.version 4 cx.read-n b> b> b> b> 3210>
cr ." Chat firmware version "
radix preserve hex sep preserve -sep <# 4# 4# #> type
c.stacked-pc @flash u< dup if ." (running in RAM)" then
( Copy flash routine to RAM.) copy-flash-routine
#256 ;
: chat
chat-via c.hello cx.status cx.run c.read c.write c.flash ;