Jump to content
Lee Stewart

TurboForth V1.2 (Beta)--Evolution & Arcana

Recommended Posts

All...

We have had quite a discussion on the YaHoo! TurboForth forum regarding floating point math and transcendental functions using it. I want to bring some of it over here, particularly because I am having trouble posting there.

Rob Van Orden, Willsy and I have been going at the TF code pretty hot and heavy. In a bit, I will post the TF BLOCKS file we have been working on. Right now, a glass of wine and my Love beckon!

Feel free to jump in anytime! ;-)

...lee Edited by Lee Stewart

Share this post


Link to post
Share on other sites
Yep folks - it's hotting up pretty good, and I'm really appreciative of the help that Lee and Rod have given (and as always, our big Bob Carmany!).

TF V1.2 (when it's fiiiiiiiiiiiiiinally released) is going to be a humdinger I think!

Share this post


Link to post
Share on other sites
FWIW, here's a list of the thangs that have changed (so far, the fat aint sung yet!) since V1.1:

[attachment=256043:V1.2-ReleaseNote.pdf]

Share this post


Link to post
Share on other sites
[b]This from Rob Van Orden (until he gets set up here)---[/b]

GPLLNK and XMLLNK ROUTINES

I think we should bring onboard some of the XMLLNK routines. Here is a listing of everything so far:


[font=courier new,courier,monospace]GPLLNK[/font]
[font=courier new,courier,monospace]Completed Not Completed[/font]
[font=courier new,courier,monospace]----------------------------[/font]
[font=courier new,courier,monospace]SQR >26 LSCS >16[/font]
[font=courier new,courier,monospace]EXP >28 LSCCS >18[/font]
[font=courier new,courier,monospace]LOG >2A PWRUP >20[/font]
[font=courier new,courier,monospace]COS >2C BEEP >34[/font]
[font=courier new,courier,monospace]SIN >2E HONK >36[/font]
[font=courier new,courier,monospace]TAN >30 GETSTR >38[/font]
[font=courier new,courier,monospace]ATN >32 BITREV >3B[/font]
[font=courier new,courier,monospace]INT >22 CADDSR >3D[/font]
[font=courier new,courier,monospace]POW >24 LLCCS >4A[/font]
[font=courier new,courier,monospace] CNS >14[/font]

[font=courier new,courier,monospace]XMLLNK[/font]
[font=courier new,courier,monospace]Floating Point Other Apps[/font]
[font=courier new,courier,monospace]----------------------------[/font]
[font=courier new,courier,monospace]FADD >06 CSN >10[/font]
[font=courier new,courier,monospace]FSUB >07 CFI >12[/font]
[font=courier new,courier,monospace]FMULT >08 VPUSHG >17[/font]
[font=courier new,courier,monospace]FDIV >09 VPOP >18[/font]
[font=courier new,courier,monospace]FCOMP >0A CIF >23[/font]
[font=courier new,courier,monospace]SADD >0B[/font]
[font=courier new,courier,monospace]SSUB >0C[/font]
[font=courier new,courier,monospace]SMULT >OD[/font]
[font=courier new,courier,monospace]SDIV >OE[/font]
[font=courier new,courier,monospace]SCOMP >0F[/font]

I think it would be worth it to implement XMLLNK in a similar fashion as the GPLLNK stuff. Here are a few routines there which are not floating point. Also, I'm thinking we should finish off the GPLLNK routines other than the transcendentals.....

I am curious about the speed involved with running the ROM routines for floating point against the TF floating point routines. Has anyone ever done that?

ROD VAN ORDEN
San Diego, California Edited by Lee Stewart

Share this post


Link to post
Share on other sites
OK, here's my BLOCKS file I promised: [attachment=256083:BLOCKS-LES.zip]

I should note that when you load block 36 for floating-point math routines, blocks 51 & 52 (with my version of the transcendental functions) will also be loaded.

Also, after Mark posts the next build of TF v1.2 (beta), we will need to change a couple of hard-wired references to TF inner interpreter routines that appear in a couple of blocks in the BLOCKS file.

...lee

Share this post


Link to post
Share on other sites
Thanks Lee. It would be great to have the rest of the GPLLNK and all of the XMLLNK routines available under TF. I'm itching to help, but I'm still not quite ready to tackle TF at a deeper level yet. My first priority once I'm there is to create a graphical bitmap library, which IMHO will really round up TF nicely. Since it does not look like there are any serious contenders for the TF game challenge for the Faire, I'll probably delay creating a game and focus on adding utilities to TF instead. More to come.

Share this post


Link to post
Share on other sites
Regarding utilities etc, here's an updated LOCALS extension. It's a very very simple implementation that gives you four local variables in your word definitions - A B C & D. To store a value (from the stack) into a local, simply precede the variable with an ! symbol. I.e:

[code]!A[/code]

Which reads in English as "store in A".

To fetch, precede the variable with an @:

[code]@A[/code]

Which reads "Fetch from A".

If you want to use locals in your definition, just say so, by putting the word LOCALS as the first word in your definition:

[code]: MyWord LOCALS ... ... ... ;[/code]

If you find that you are resorting to 'stackrobatics' to move values around on the stack, or having to stash stuff away on the return stack, local variables can be the answer you are looking for, rather than using global variables.

Here is the code that implements local variables support. It replaces the earlier incarnation on block 41 of the V1.2 blocks disk. Please update your disk. It's not much code:

[code]
FALSE WARN !
FALSE VALUE _locals $2FF8 VALUE lsTop
: lsPush [ 4 CELLS ] LITERAL +TO lsTop ;
: lsPop [ -4 CELLS ] LITERAL +TO lsTop ;

: !A ( n-) lsTop ! ; : @A ( -n) lsTop @ ;
: !B ( n-) lsTop 2+ ! ; : @B ( -n) lsTop 2+ @ ;
: !C ( n-) lsTop 4 + ! ; : @C ( -n) lsTop 4 + @ ;
: !D ( n-) lsTop 6 + ! ; : @D ( -n) lsTop 6 + @ ;

: LOCALS ( -) COMPILE lsPush TRUE TO _locals ; IMMEDIATE

: ; _locals IF COMPILE lsPop THEN [COMPILE] ;
FALSE TO _locals ; IMMEDIATE
CR .( Locals support loaded.)
TRUE WARN ![/code]

As you can see, VERY little code to implement such a useful feature, and no need to resort to assembly language etc!

Here is a test routine:

[code]
: TEST2 LOCALS
CR ." Inside TEST2:"
!D !C !B !A
5 0 DO
CR 2 SPACES ." A=" @A .
." B=" @B .
." C=" @C .
." D=" @D .
LOOP
;

: TEST LOCALS
CR ." Inside TEST:"
!D !C !B !A
10 0 DO
CR ." A=" @A .
." B=" @B .
." C=" @C .
." D=" @D .
I 4 = IF
7 8 9 10 TEST2
CR ." Back inside TEST:"
THEN
LOOP
;

1 2 3 4 TEST
[/code]

Sorry for the OT Lee. But I don't want to spam the board with TF threads!

Mark

Share this post


Link to post
Share on other sites
[quote name='Willsy' timestamp='1345812486' post='2585093']
...
Sorry for the OT Lee. But I don't want to spam the board with TF threads!

Mark
[/quote]

No prob. Perhaps, I should change the topic to something more general?

Share this post


Link to post
Share on other sites
Rod...

Regarding implementation of GPLLNK and XMLLNK routines you mentioned as not implemented that, in fact, are implemented,[list]
[*]GPLLNK---
[list]
[*]CNS (convert FP number to string)---Mark wrote his own routine for this. It might be interesting to see which is faster.
[/list][*]XMLLNK---
[list]
[*]CSN (convert string to FP number) TF: [b]vdpstr>fp[/b] (uses XMLLNK routine)
[*]CFI (convert FP number to integer) TF: [b]FP>S[/b] (uses XMLLNK routine)
[*]CIF (convert integer to FP number) TF: [b]S>FP[/b] (the XMLLNK routine, 23h, referenced in the E/A manual cannot be used without putting it somewhere else. 2600h is where the E/A module puts it; but, I believe TF uses that space or considers it free space for programs. It looks like Mark got at it another way. I haven't looked that closely at it, yet.)
[/list]
[/list]
...lee

Share this post


Link to post
Share on other sites
[quote name='Lee Stewart' timestamp='1345837688' post='2585353']
[quote name='Willsy' timestamp='1345812486' post='2585093']
...
Sorry for the OT Lee. But I don't want to spam the board with TF threads!

Mark
[/quote]

No prob. Perhaps, I should change the topic to something more general?
[/quote]

Please do. It's much easier to discuss TF here than on Yahoo.

Share this post


Link to post
Share on other sites
[quote name='Willsy' timestamp='1345812486' post='2585093']
...
Sorry for the OT Lee. But I don't want to spam the board with TF threads!

Mark
[/quote]

OK, now nothing is OT unless, of course, it somehow does not relate to TurboForth. :ponder:

...lee

Share this post


Link to post
Share on other sites
[quote name='Lee Stewart' timestamp='1345842473' post='2585435']
Rod...

Regarding implementation of GPLLNK and XMLLNK routines you mentioned as not implemented that, in fact, are implemented,[list]
[*]GPLLNK---
[list]
[*]CNS (convert FP number to string)---Mark wrote his own routine for this. It might be interesting to see which is faster.
[/list]
[/list]
[/quote]

It just uses GPL to convert the FP value to an ASCII displayable string. I'm afraid I'm not clever enough to really properly understand radix 100. I wish I did.

If anyone wants a project or collaboration, I would donate a leg/arm/kidney for a suite of FP routines (radix 100 or some other format - I suspect radix 100 is easier to deal with than the IEEE FP number formats) written in assembly language. We'd probably only need:[list]
[*]Add
[*]Subtract
[*]Multiply
[*]Divide
[*]Convert FP to string
[*]Convert string to FP
[/list]
I *presume* SIN TAN et al can be built in terms of the above primitives?

I would then take the assembly code and build it into a Forth library. It would be much neater, with no reliance on ROM and GPL routines. The ROM and GPL routines are completely fine in terms of their functionality, but interfacing with them is a pain, and their performance (being GPL) leaves something to be desired.

Floating point seems to be one of the last bastions in 4A software development; nobody has really gone near the subject (to my knowledge, at least) - probably because it's bloody difficult! IIRC even the C99 FP routines interfaced to the GPL/ROM routines in the console.

As a further aside, attached is the source code and manual for the TF FP package. I will leave Lee to document the transcendals library, as I consider it to be his baby now! Lee, if you want an Open Office template (I can send you FP manual as an open office doc) just holler.

Mark
[attachment=256200:floating-point.pdf]
[attachment=256201:fp.txt]

Share this post


Link to post
Share on other sites
[quote name='Willsy' timestamp='1345887500' post='2585800']
...
As a further aside, attached is the source code and manual for the TF FP package. I will leave Lee to document the transcendals library, as I consider it to be his baby now! Lee, if you want an Open Office template (I can send you FP manual as an open office doc) just holler.

Mark
[/quote]

Uh-oh! What have I done? :-o Yeah, send me the template.

...lee

Share this post


Link to post
Share on other sites
[quote name='Lee Stewart' timestamp='1345893865' post='2585830']
Uh-oh! What have I done? :-o Yeah, send me the template.
[/quote]

PM waiting for you :grin:

Share this post


Link to post
Share on other sites
[quote name='Willsy' timestamp='1345887500' post='2585800']
If anyone wants a project or collaboration, I would donate a leg/arm/kidney for a suite of FP routines (radix 100 or some other format - I suspect radix 100 is easier to deal with than the IEEE FP number formats) written in assembly language.

Mark

[/quote]

I'm sure you've been pointed to FP routines before, Mark? You could for example base it on the routines in the Powertran Cortex Basic - <[url="http://www.powertrancortex.com/downloads/EPROM%20Build%20from%20Source.zip"]http://www.powertran...from Source.zip[/url]>, and look in fp.asm. It also has trigometric functions which from memory are based on lookup tables.

Stuart.

[CODE]
TITL 'FLOATING POINT ROUTINES - CORTEX BASIC REV. 1.1'
IDT 'FP'
*
* FAD ;ADD TO FPAC
* FSD ;SUBTRACT FROM FPAC
* FMD ;MULTIPLY FPAC
* FDD ;DIVIDE FPAC
* FLDD ;LOAD FPAC
* FSRD ;STORE FPAC
* FNEG ;NEGATE FPAC
* FCLR ;CLEAR FPAC
* FNRM ;NORMALIZE FPAC
* FSCL ;SCALE FPAC
* FLOAT ;FLOAT FPAC
* FADDI ;3 WRD ADDITION
* FSUBI ;3 WRD SUBTRACTION
*
* THE FLOATING POINT ACCUMULATOR IS THE FIRST 3
* WORDS OF THE FLOATING POINT REGISTERS (R0,R1,R2).
*
* ALL FLOATING POINT OPERATIONS ASSUME NORMALIZED
* NUMBERS AS INPUTS AND ALL RESULTS ARE NORMALIZED.
*
* THE FORM OF A FLOATING POINT NUMBER IS AS FOLLOWS:
*
* 1ST WORD SCCC CCCC MMMM MMMM
* 2ND WORD MMMM MMMM MMMM MMMM
* 3RD WORD MMMM MMMM MMMM MMMM
*
* WHERE S = SIGN BIT
* C = 7 BIT, EXCESS >40 CHARACTERISTIC
* M = 40 BIT UNSIGNED MAGNITUDE MANTISSA
* 0 <= M < 1
*
* A NUMBER IS NORMALIZED WHEN THE 1ST HEX DIGIT
* OF THE MANTISSA IS NON-ZERO.
*
* A TRUE ZERO (ALL ZERO'S) IS USED FOR ZERO.
[/CODE]

Share this post


Link to post
Share on other sites
Oh wow! Thanks Stuart. It does ring a bell, now you mention it!

I'll have a good look. How familiar are you with the code?

Mark

Share this post


Link to post
Share on other sites
[quote name='Willsy' timestamp='1345925303' post='2586074']
I'll have a good look. How familiar are you with the code?

Mark
[/quote]

Familiar enough to have converted the XOPs and TMS9995 MID instructions it uses to BLWPs for the 4A (I could give you a copy of the 4A version Monday when I get home). I could sort of follow how most of the floating point stuff works, but would have had great trouble trying to write it myself! I had several eureka moments doing the conversion when the function behind some bits of code suddenly fell into place ... usually late at night when you're trying to forget about it and get to sleep ...

Stuart.

Share this post


Link to post
Share on other sites
For what its worth the Geneve OS contains floating point routines many conversion and trig functions. All 9900 (9995) code written or updated by JP Hoddie, Paul Charleton, others. I believe these same routines may be common to Myarc XB II and Myarc advanced BASIC.

[attachment=256247:L10-float and math routines geneve os.txt] Edited by InsaneMultitasker

Share this post


Link to post
Share on other sites
I am sorely tempted to convert all the floating point math to using radix 256. It would add up to 3 decimal digits and it would use all the real estate of the 8 bytes currently used to store a floating point number. Perhaps I won't get further than looking at it. Anybody else looked into it?

...lee

Share this post


Link to post
Share on other sites
Hey Lee and everybody!

I finally made it onto AtariAge....!

And, Lee, thanks for all your inputs on XMLLNK during the past few days. Some of this is not easy stuff, but
I have been learning a great deal about TurboForth and Forth, in general......!

Rod Van Orden
San Diego, California

Share this post


Link to post
Share on other sites
[quote name='InsaneMultitasker' timestamp='1345954295' post='2586297']
For what its worth the Geneve OS contains floating point routines many conversion and trig functions. All 9900 (9995) code written or updated by JP Hoddie, Paul Charleton, others. I believe these same routines may be common to Myarc XB II and Myarc advanced BASIC.
[/quote]

This looks complete in that it can completely replace the console GPL and XML routines for floating point and transcendental math. It [i]does [/i]take a hair more than 6KB assembled. I am not acquainted with MDOS, so I do not understand exactly how we would roll the task block stuff into TF:

[indent=1][font=courier new,courier,monospace]* caller's task block[/font][/indent]
[indent=1][font=courier new,courier,monospace]SYS1 EQU >F0A0[/font][/indent]
[indent=1][font=courier new,courier,monospace]SYS2 EQU >F0C0[/font][/indent]
[indent=1][font=courier new,courier,monospace]INTREG EQU >F080[/font][/indent]
[indent=1][font=courier new,courier,monospace]MAPPER EQU >F110[/font][/indent]
[indent=1][font=courier new,courier,monospace]TSKMAP EQU >8114[/font][/indent]
[indent=1][font=courier new,courier,monospace]SYSREG EQU >F0E0[/font][/indent]

I guess the above TSKMAP is in a DSR not available to the TI-99/4A, so, again, I am almost clueless as to how to manage the block in the TI-99/4A. I would guess that somewhere in there is the offset into the MATH## table for the required function. But...

A couple of niceties (I think):[list=1]
[*]No scratchpad memory is used, so nothing in TF gets trashed.
[*]No VDP RAM usage that I can discern---should be faster.
[*]No GPL is executed TICD---should be faster.
[*]No console XML routines are executed TICD. This is not all that good, considering console ROM is on a 16-bit bus (I think).
[/list]
Considering (4), a faster system than the current GPL/XML console routines might be one in which the GPL math routines (transcendentals and CNS [Convert Number to String]) are all written in assembly. This, of course, uses the traditional, faster scratchpad RAM, which will require cleanup for TF. Comments?

...lee

Share this post


Link to post
Share on other sites
[quote name='Lee Stewart' timestamp='1346356578' post='2589523']
[quote name='InsaneMultitasker' timestamp='1345954295' post='2586297']
For what its worth the Geneve OS contains floating point routines many conversion and trig functions. All 9900 (9995) code written or updated by JP Hoddie, Paul Charleton, others. I believe these same routines may be common to Myarc XB II and Myarc advanced BASIC.
[/quote]

This looks complete in that it can completely replace the console GPL and XML routines for floating point and transcendental math. It [i]does [/i]take a hair more than 6KB assembled. I am not acquainted with MDOS, so I do not understand exactly how we would roll the task block stuff into TF:





[indent=1][font=courier new,courier,monospace]* caller's task block[/font][/indent]
[indent=1][font=courier new,courier,monospace]SYS1 EQU >F0A0[/font][/indent]
[indent=1][font=courier new,courier,monospace]SYS2 EQU >F0C0[/font][/indent]
[indent=1][font=courier new,courier,monospace]INTREG EQU >F080[/font][/indent]
[indent=1][font=courier new,courier,monospace]MAPPER EQU >F110[/font][/indent]
[indent=1][font=courier new,courier,monospace]TSKMAP EQU >8114[/font][/indent]
[indent=1][font=courier new,courier,monospace]SYSREG EQU >F0E0[/font][/indent]

I guess the above TSKMAP is in a DSR not available to the TI-99/4A, so, again, I am almost clueless as to how to manage the block in the TI-99/4A. I would guess that somewhere in there is the offset into the MATH## table for the required function. But...

A couple of niceties (I think):[list=1]
[*]No scratchpad memory is used, so nothing in TF gets trashed.
[*]No VDP RAM usage that I can discern---should be faster.
[*]No GPL is executed TICD---should be faster.
[*]No console XML routines are executed TICD. This is not all that good, considering console ROM is on a 16-bit bus (I think).
[/list]
Considering (4), a faster system than the current GPL/XML console routines might be one in which the GPL math routines (transcendentals and CNS [Convert Number to String]) are all written in assembly. This, of course, uses the traditional, faster scratchpad RAM, which will require cleanup for TF. Comments?

...lee
[/quote]

The Geneve employs eight 1-byte mapper registers starting at 0xF110 in native mode, 0x8000 in TI mode. 64K of RAM is visible to the system from 0x0000-0xFFFF, split into eight 8K pages, each mapped to the page referenced in the associated mapper address. In native mode, XOP calls provide access to keyboard, video, math, and I/O libraries contained within the OS. In TI mode, everything looks and operates like a TI with the benefit of the V9938 graphics chip and RAM for cartridge/ROM/GROM spaces.

When an XOP is called a context switch occurs. The OS does some fancy footwork to figure out which XOP was called and what routine pages to map into the visible 64K space. The mapper registers are saved, referenced, and restored as needed.

SYS1,SYS2,INTREG, and SYSREG are workspaces. Where the TI contains fast scratchpad RAM at 0x8300-0x83FF, the Geneve's equivalent fast RAM is at 0xF000-0xF0FF. Thus the fastest RAM is used for XOP library routines.
[code]
MOV @4(R13),R13 GET POINTER TO NUMBER
MOV R13,R4 MAP IT IN
SRL R4,13
MOVB @TSKMAP(R4),@MAPPER+5 first page with callers data
INC R4 point to next 8k chunk
ANDI R4,>0007 mask to 3 bit page number (local pages = 8x8k window)
MOVB @TSKMAP(R4),@MAPPER+6 map it into visible space
ANDI R13,>1FFF shed the local page bits
AI R13,>A000 and force R13 into the A000 bank
[/code]
The above code determines which page the callers argument or buffer is located. By stripping down R13, the routine determines where the argument is located and maps two consecutive pages into local, visible memory. Two pages are required so that if the callers data spans an 8k boundary, no further manipulation is needed in the routines.

TSKMAP is a little trickier. On the Geneve, the RAM betwenn 0x8000-0x83FF is fully decoded unlike the TI. Thus some routines, variables, and even code are often stored here for OS and TI mode use.

Next, each OS task or program has its own header for multitasking, interrupts, and info passing. In this snippet we find the task map is DORG'd to 0x8114. The calling XOP or interrupt saves some or all of its calling memory map registers so the called routine knows how to reference its caller.

[code]
File:HDS2.MDOS.HEAD.OSTASK Page: 3 Date: 10-30-04 Time: 01:50:13
DORG >8100
TSKTBL BYTE 00 TASK ID #
MAXDRV BYTE 'G' MAXIMUM ALIAS LETTER USER CAN SPECIFY
STATE BYTE >FF PROCESS STATE
SLICE BYTE 6 NUMBER OF SLICES LEFT UNTIL SWAPPED OUT
PNAME TEXT ' ' NAME OF THIS TASK
UWP DATA >F000 USER WORKSPACE POINTER
UPC DATA >0400 USER PROGRAM COUNTER
UST DATA >0002 USER STATUS REGISTER
MEMLST DATA 0 POINTER TO MEMORY LIST
TSKMAP DATA 0,0,0,0 SAVED MEMORY MAP USED DURING XOPS AND INTERRUPTS
CURDRV DATA ALIASA POINTER TO CURRENT DRIVE ENTRY
[/code]
You could probably convert these routines fairly easily once you get past the initial memory mapping code.

Share this post


Link to post
Share on other sites
[quote name='InsaneMultitasker' timestamp='1346378653' post='2589750']
You could probably convert these routines fairly easily once you get past the initial memory mapping code.
[/quote]

Easy for you to say! :o

Wow! A lot to ponder. Thanks for the good info.

...lee

Share this post


Link to post
Share on other sites
Someone on this forum has probably already done this; but, I decided to work through at least one of the transcendental function calculations in the 4A console's GROM listed in Heiner Martin's [i]TI Intern[/i] because I really hate black box calculations and because I am curious to see whether the MDOS assembly code so kindly posted by [member='insanemultitasker'] is the same. I chose the arctangent routine (ATN) and have worked completely through it. I will post the math when I have it cleaned up. Suffice it to say for now that the two routines use the same ten coefficients so it's likely the routines are the same.

...lee

Share this post


Link to post
Share on other sites
Well, I'll just go look up *what* an Arctangent is, then I'll be right with ya! :P

Seriously, I should have listened more in maths class at school. I was more concerned with trying to be John Lennon and getting my hands up girls bra's and down girls knickers*!

I don't know what American is for Knickers, sorry! :-D

[size=2]* With some success here and there, I might add. I had my moments![/size]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...