perfectconsulting / gsforth-rom Goto Github PK
View Code? Open in Web Editor NEWSubroutine Thread Forth for the BBC Micro (ROM Version)
Subroutine Thread Forth for the BBC Micro (ROM Version)
Some thoughts on GSFORTH.
*command matcher should be case insensative, so *gsforth works as well as *GSFORTH. For a single startup command there's sample code on the Wiki.
I'm sure a macro would be worked out to do the word header. I've used a similar macro for storing linked strings on the Z80. Something that would let you do:
OSWORD_NFA ;osword ( yx a -- )
>FWORD 'osword'
and it would store length, left(string,len-1),right(string+CHR$128),lastNFA
osword should be ( xy a --) not (y x a -- y x a), so you call it with block action osword, not block 256 / block 256 \ action osword. It should take a control block address and a function number, and swallow them. OSWORD only returns information in the control block, not the registers. (OSWORD 0 is a special case and should be called with a different method). Probably:
OSWORD_NFA ;osword ( yx a -- )
.DB $06^$80,'oswor',$64^$80
.DW OSBYTE_NFA
OSWORD_CFA
>CHK_STK_MIN 2,OSWORD
STX SCRATCH1 ; save psp
LDA STK+1,X
PHA
LDY STK+4,X
LDA STK+3,X
TAX
PLA
JSR OSWORD
LDX SCRATCH1 ; get psp
INX ; drop
INX
INX ; drop
INX
RTS
You could probably then create SOUND something like:
: sound ( dur pitch vol chan -- )
sp@ inc 7 osword 4drop ;
osfile probably needs to use the same add-a-CR code as oscli and (open) does.
I couldn't work out what osargs was doing until it clicked you was passing raw register values. It probably should be closer to the API than the raw 6502 code, to do osargs ( d-data channel action -- d-data return ), so you call it with something like 0 0 handle 0 osargs drop ( read PTR ) ptrhi ptrlo handle 1 osargs drop ( write PTR ) 0 0 0 0 osargs ( read filing system number ).
Probably something like:
OSARGS_NFA ; ( datahi datalo channel action -- datahi datalo return )
.DB $06^$80,'osarg',$73^$80
.DW OSFIND_NFA
OSARGS_CFA
>CHK_STK_MIN 4,OSARGS
STX SCRATCH1
LDY STK+3,X ;channel
LDA STK+1,X ;action
INX
INX
INX
INX ;->data
JSR OSARGS
LDX SCRATCH1
INX ;drop action
INX
STA STK+1,X ;store return
LDA #0
STA STK+2,X
RTS
In ?eof you're depending on Y being preserved over the call to OSBYTE. In some specific situations you may find accidently that Y just happens to be preserved, but you can't rely on that, Y is returned undefined - all OSBYTE calls <&80 ignore Y and return Y undefined. You'll need to SCRATCH the psp over the call.
OSGBPB returns data, so osgbpb shouldn't swallow the stack parameters. ptr is needed for the next call, num is needs to discover how much has been transfered. Maybe something like:
OSGBPB_NFA ;osgbpb ( d-seq d-num d-addr fh mode -- d-seq d-num d-addr cycle retval )
>FWORD 'osgbpb'
OSGBPB_CFA
>CHK_STK_MIN 8,OSGBPB
STX SCRATCH1
LDA STK+3,X
STA STK+4,X ; Move fh to XY+0 for control block
LDA STK+1,X
INX
INX
INX ; Point to control block
LDY #$00
JSR OSGBPB
LDX SCRATCH1
STA STK+1,X ; Return value
LDA STK+4,X
STA STK+3,X ; Move return XY+0 to fh location
LDA #0
STA STK+4,X
RTS
Following the symantics of naming FORTH words, escape? should be ?escape. ?xxxx means 'ask if something', so it should be ?escape to be 'ask if escape pending', similar to ?eof, ?key, ?buffer, etc.
A lot of optimisation could be done where
JSR xxxxx
RTS
can be replaced with:
JMP xxxxx
as long as the machine stack is not changed in the routine being called.
I haven't seen anything in the code that makes it specific to a BBC Model B, it works fine on a Model A, a Master, a Compact, an Electron.
FIRST should be read from OSBYTE &83. Probably something like:
; seed first
LDA #$83
JSR OSBYTE
TYA
LDY #USER_DP+1
STA (UP),Y
DEY
TXA
STA (UP),Y
; seed limit
LDA #$84
...etc.
Keep up the good work. It's reminded me I really need to finish updating my BBC 'C' compiler which has similar issues.
The word 0> ignores the high byte and only compares the low byte:
255 0> .
-1 ok.
256 0> .
0 ok.
As a work around I use 0 > instead of 0>
Your Forth implementation is the fastest Forth on the BBC Micro I am aware of!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.