MilliForth-6502: 最小的 6502 真实编程语言
agsb / milliForth-6502 Public
- Notifications You must be signed in to change notification settings
- Fork 3
- Star 41
最小的 6502 真实编程语言。基于 x86 的 milliForth。
License
GPL-2.0 license 41 stars 3 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings
Additional navigation options
agsb/milliForth-6502
main BranchesTags Go to file Code
Folders and files
Name| Name| Last commit message| Last commit date
---|---|---|---
Latest commit
History
277 Commits
docs| docs
scrs| scrs
tsts| tsts
.gitignore| .gitignore
6502.z1| 6502.z1
65C02.z1| 65C02.z1
LICENSE| LICENSE
Makefile| Makefile
README.md| README.md
The_words_in_MTC_Forth.v4.pdf| The_words_in_MTC_Forth.v4.pdf
b2h.py| b2h.py
clean| clean
disclaimer| disclaimer
do1| do1
do2| do2
do3| do3
doit| doit
mk| mk
my_bf.FORTH| my_bf.FORTH
my_hello_world.FORTH| my_hello_world.FORTH
my_tests.FORTH| my_tests.FORTH
sector-6502.a65| sector-6502.a65
sector-6502.cfg| sector-6502.cfg
sector-6502.s| sector-6502.s
sector-65C02.cfg| sector-65C02.cfg
sector-65C02.s| sector-65C02.s
View all files
Repository files navigation
适用于 6502 的 milliForth
"截至目前,这是有史以来最小的真正的编程语言,仅占用 328 字节的 Forth。" milliForth1 是对 sectorForth2 的回顾,并且比 sector Lisp3 更小。
miniForth4 是另一个用于小于 512 字节的引导扇区的 Forth。
字节?
是的,字节。但这些是针对 x86 16 位 CPU 的。对于经典的 6502 8 位 CPU 来说,最小能到什么程度呢?
这是两种本质上不同的 CPU,一个是基于复杂寄存器和操作码的 16 位 x86,另一个是使用零页作为通用寄存器,使用第一页作为硬件堆栈的 8 位 6502。
内部解释器
适用于 6502 的 FIG-Forth (1980) 使用间接线程代码 (ITC) 作为内部解释器。
miniForth、sectorforth 和 milliForth 使用直接线程代码 (DTC)。
这个用于 6502 的 Forth,~~将会~~已经使用两种模型完成:
使用经典的直接线程代码 (DTC)
以及
使用最小线程代码 (MTC)
(稍后我们将比较两者,~~但 DTC 会以更小的尺寸胜出~~)
这个项目也用于验证标准的直接线程代码,以对比最小线程代码的变体。
最小线程代码是内部解释器的另一种模型,其中字典的组织方式是将原始单词分组在复合单词之前,定义一个“临界点”,可以由此决定单词的引用是将被执行还是被推入返回堆栈。PS. MTC 是 TachyonForth 内部解释器的简化形式。
为 6502 编码
侧重于尺寸而非性能。
编译使用 ca65 V2.19 - Git 7979f8a41 完成。
6502 CPU 的模拟使用 run6502 完成。
6502 的方式是使用零页和大量的 lda/sta 字节。
DTC 和 MTC 都使用 my_hello_world.FORTH 运行,数据如下。
MTC, Instructions: 35796948, Cycles: 148802145, SIZE: 582
DTC, Instructions: 35211469, Cycles: 148450585, SIZE: 596
compiling my_hello_world.FORTH, overhead MTC / DTC
Instructions: 1.66%
Cycles: 0.24%
(*) 感谢 peterferrie 的明智修改!
变更:
- 按照 Forth-19945:FALSE 是 $0000,TRUE 是 $FFFF;
- 所有 tib(80 字节)、pic(16 个单元格)、数据(36 个单元格)和返回(36 个单元格)堆栈都在 $200 页;
- tib 和 pic 向前增长,堆栈向后增长;
- 只有 immediate 标志用作 $80,没有更多标志;
- 没有行编辑器、没有退格键、没有取消行、没有低位 ASCII 验证;
- 没有堆栈溢出或下溢检查;
备注:
- 6502 是一个字节处理器,无需在偶数名称的末尾添加“pad”;
- 硬件堆栈($100 页)不作为 Forth 堆栈使用,可以自由使用;
- 使用 32 字节的_零页_;
- 没有多用户、没有多任务、没有更快;
- 仅在单词定义的末尾更新 latest;
- 重新定义一个单词不会更改以前的用法;
- 堆栈像硬件堆栈一样移动;
- 单词必须位于空格之间,之前和之后都要有;
- 最好使用 7 位 ASCII 字符;
- 接近 ANSI X3.215-19945
注释
查看注释6了解更多信息。 2024 年 8 月 24 日,将 dtc 和 mtc 代码合并到一个带有标志的 sector-6502.s 文件中 2024 年 8 月 16 日:DTC 和 MTC 两种模型都可以使用 my_hello_world.FORTH; 2024 年 8 月 11 日:返回到直接线程代码; 2024 年 6 月 11 日:适用于最小线程间接代码; 2024 年 1 月 24 日:使用标准直接线程代码编写; 2023 年 11 月 14 日,6502 代码的大小为 624 字节,没有 ascii-7、没有 key、没有 emit、没有 2/,许多错误
编码
此版本包括:
primitives:
s@ return the address of user structure
+ adds two values at top of data stack
nand logic not and the two values at top of data stack
@ fetch a value of cell wich address at top of data stack
! store a value into a cell wich address at top of data stack
0# test if top of data stack is not zero
: starts compilng a new word
; stops compiling a new word
exit ends a word
key get a char from default terminal (system dependent)
emit put a char into default terminal (system dependent)
internals:
spush, spull, rpull, rpush, (stack code)
copyfrom, copyinto, (heap code)
incr, decr, add, etc (register mimics)
cold, warm, quit, token, skip, scan, getline, (boot and terminal)
parse, find, compile, execute, (outer interpreter)
unnest, next, nest, (dtc inner)
unnest, next, nest, pick, jump, (mtc inner)
ps. next is not the FOR NEXT loop
externals:
getch, putch, byes (depends on system, used minimal for emulator )
extensions: (selectable)
2/ shift right one bit
exec jump to address at top of spt
:$ jump to (ipt)
;$ jump to next
extras: (selectable)
bye ends the Forth, return to system
abort restart the Forth
.S list cells in data stack
.R list cells in return stack
. show cell at top of data stack
words extended list the words in dictionary
dump list contents of dictionary in binary
A my_hello_world.FORTH alternate version with dictionary for use;
The sp@ and rp@ are now derived from s@ in the my_hello_world.FORTH
内存
$000 page zero ; cpu reserved
$100 hardware stack ; cpu reserved
$200 TIB ; terminal input buffer, 80 bytes
$298* data stack ; data stack, 36 cells, backwards
$2E0* return stack ; return stack, 36 cells, backwards
$2E0 PIC ; reserved for scratch, 16 cells
$300 _main_ ; start of Forth
$??? _ends_ ; end of code and primitives of Forth
$??? _init_ ; start of compound dictionary
_init_ is the page (MSB) of _ends_ + 1
堆栈
“当堆向前移动时,堆栈向后移动” Push 是“存储并减少”。Pull 是“增加并获取”。
常见的 Forth 内存模型组织:
tib->...<-spt, user forth dictionary, here->pad...<-rpt,
然后向后堆栈允许使用空闲空间... 此 6502 Forth 内存模型被阻止在 256 字节的页面中:
page0, page1, page2, core ... forth dictionary ...here...
在 page2 中,没有“rush over”
|tib 40 cells> <spt 36 cells| <rpt 36 cells|pic 16 cells> | .
语言
"SectorFORTH was an extensive guide throughout the process of implementing milliFORTH, and milliFORTH's design actually converged on sectorFORTH unintentionally in a few areas. That said, the language implemented is intentionally very similar, being the 'minimal FORTH'." For Forth language primer see Starting Forth For Forth from inside howto see JonasForth
使用
** 16/08/2024 DTC 和 MTC 模型运行正常,使用 lib6502 进行模拟和测试 ** 包含一个用于使用 ca65 编译的粗略小型脚本。
; for make it
sh mk a sector-6502
; for clear it
sh mk x sector-6502
尺寸取自 main: 到 ends: 使用 sector-6502.lbl 文件
备注
原始文件被编辑为少于 80 字节的行 bf.FORTH 和 hello_world.FORTH 来自原始 milliForth1 my_hello_world.FORTH 适用于 miiliforth-6502
参考文献
脚注
- The original milliForth: https://github.com/fuzzballcat/milliForth ↩ ↩2
- The inspirational sectorForth: https://github.com/cesarblum/sectorforth/ ↩
- Mind-blowing sectorLISP: https://justine.lol/sectorlisp2/, https://github.com/jart/sectorlisp ↩
- The miniforth: https://github.com/meithecatte/miniforth ↩
- Forth standart ANSI X3.215-1994: http://www.forth.org/svfig/Win32Forth/DPANS94.txt ↩ ↩2
- Notes and Times: https://github.com/agsb/milliForth-6502/blob/main/Notes.md ↩
关于
最小的 6502 真实编程语言。基于 x86 的 milliForth。
主题
assembler forth 6502 6502-assembly
资源
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Contributors 2
Languages
- Assembly 62.3%
- AngelScript 32.6%
- Forth 3.2%
- Python 1.4%
- Other 0.5%
Footer
Footer navigation
You can’t perform that action at this time.