This commit is contained in:
Carsten Strotmann 2018-10-08 14:55:19 +00:00 committed by GitHub
commit ca5a93c38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 124 additions and 2 deletions

21
examples/hello.foc Normal file
View File

@ -0,0 +1,21 @@
[text-section] init
[code]
org $2000 ; start address of program
[end-code]
[text-section] text
create hello ," Hello World" \ the printable text
[include] "lib/core.foc"
\ Hauptprogramm
: main
hello count type \ print the text on screen
key \ wait for keypress
dos \ jump to DOS
;
[code]
run boot ; set the RUNVEC to start program
[end-code]

36
foco65
View File

@ -262,7 +262,7 @@ class BranchTarget:
class Words:
def __init__(self):
self.lst = []
self.aliases = {"cells": "2*", "cell": "2*", "not": "0="}
self.aliases = {"cells": "2*", "cell+": "2+", "not": "0="}
def __iter__(self):
return iter(self.lst)
@ -417,6 +417,9 @@ class Forth:
elif token == "cells":
x = self.pop(token)
self.push(2 * x)
elif token == "cell+":
x = self.pop(token)
self.push(x + 2)
elif token == "/":
x2 = self.pop(token)
x1 = self.pop(token)
@ -640,7 +643,7 @@ class Forth:
item_outputs = map(lambda i: i.output(section), self.items)
section_outputs.append("".join(item_outputs))
return "\n".join(section_outputs)
#####
boot_text = """
@ -1001,6 +1004,19 @@ while_end
jmp next
[end-code] ;
: 2+
[label] two_plus
[code]
clc
lda #2
adc pstack,x
sta pstack,x
lda #0
adc pstack+1,x
sta pstack+1,x
jmp next
[end-code] ;
: count ( addr1 -- addr2 u )
[code]
lda pstack,x
@ -1982,6 +1998,20 @@ m_star_done
[end-code] ;
"""
def resolve_includes(text):
i = text.find("[include]")
if (i > 0):
start = text.find('"',i+10)
end = text.find('"', start+1)
chunk1 = text[:i-1]
chunk2 = text[end+1:]
filename = text[start+1:end]
with open(filename, "rt") as f:
ntext = f.read()
text = resolve_includes(chunk1 + " " + ntext + " " + chunk2)
return text
parser = argparse.ArgumentParser()
parser.add_argument("--sections", "-s", metavar="STR", default="init,boot,data,text")
parser.add_argument("--pstack-bottom", "-p", metavar="ADDR", default="$600")
@ -1995,6 +2025,8 @@ boot_params = {"pstack_bottom": args.pstack_bottom,
with open(args.file, "rt") as f:
text = f.read()
text = resolve_includes(text)
f = Forth(args.sections.split(","))
try:

69
lib/core.foc Normal file
View File

@ -0,0 +1,69 @@
( Forth Words from the CORE word set )
( see http://www.forth200x.org/documents/forth16-1.pdf )
\ 6.1.1320 EMIT
\ print TOS as character on screen
: emit ( n -- )
[code]
lda pstack,x ; load char from stack
inx ; adjust stack pointer
inx ;
stx tmp ; save stack pointer
jsr do_ec ; jump to OS print char function
ldx tmp ; restore stack pointer
jmp next ; naechstes Forth-Wort
do_ec ; indirect jump to Atari OS
tax ; function to print char
lda $E407 ; on screen
pha
lda $E406
pha
txa
rts
[end-code] ;
\ 6.1.1750 KEY
\ read one character from keyboard
\ word waits for keypress
: key ( -- n )
[code]
lda #0
dex ; create space on stack
sta pstack,x ; clear high-byte
stx w ; save stack pointer
jsr do_gc ; jump to OS routine to read key
ldx w ; restore stack pointer
dex ; create space for low byte
sta pstack,x ; store key value in low byte
jmp next ; next Forth word
do_gc ; indirect jump to Atari OS
lda $E425 ; Routine to read char from
pha : keyboard
lda $E424
pha
rts
[end-code] ;
\ 6.1.0980 COUNT
\ Return the character string specification for the
\ counted string stored at c-addr1. c-addr2 is the
\ address of the first character after c-addr1.
\ u is the contents of the character at c-addr1,
\ which is the length in characters of the string at
\ c-addr2.
: count ( c-addr1 -- c-addr2 u )
dup c@ swap 1+ swap ;
\ 6.1.2310 TYPE
\ If u is greater than zero, display the character
\ string specified by c-addr and u.
: type ( c-addr u -- )
0 do dup i + c@ emit loop drop ;
\ Leave program and enter DOS via DOSVEC ($0A)
: dos
[code]
jmp ($0A)
[end-code] ;