Jump to content
IGNORED

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


Lee Stewart

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
Link to comment
Share on other sites

This from Rob Van Orden (until he gets set up here)---

 

GPLLNK and XMLLNK ROUTINES

 

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

 

 

GPLLNK

Completed Not Completed

----------------------------

SQR >26 LSCS >16

EXP >28 LSCCS >18

LOG >2A PWRUP >20

COS >2C BEEP >34

SIN >2E HONK >36

TAN >30 GETSTR >38

ATN >32 BITREV >3B

INT >22 CADDSR >3D

POW >24 LLCCS >4A

CNS >14

 

XMLLNK

Floating Point Other Apps

----------------------------

FADD >06 CSN >10

FSUB >07 CFI >12

FMULT >08 VPUSHG >17

FDIV >09 VPOP >18

FCOMP >0A CIF >23

SADD >0B

SSUB >0C

SMULT >OD

SDIV >OE

SCOMP >0F

 

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
Link to comment
Share on other sites

OK, here's my BLOCKS file I promised: 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

Link to comment
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.

Link to comment
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:

 

!A

 

Which reads in English as "store in A".

 

To fetch, precede the variable with an @:

 

@A

 

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:

 

: MyWord LOCALS ... ... ... ;

 

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:

 

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 !

 

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:

 

: 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

 

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

 

Mark

Link to comment
Share on other sites

Rod...

 

Regarding implementation of GPLLNK and XMLLNK routines you mentioned as not implemented that, in fact, are implemented,

  • GPLLNK---
    • CNS (convert FP number to string)---Mark wrote his own routine for this. It might be interesting to see which is faster.

    [*]XMLLNK---

    • CSN (convert string to FP number) TF: vdpstr>fp (uses XMLLNK routine)
    • CFI (convert FP number to integer) TF: FP>S (uses XMLLNK routine)
    • CIF (convert integer to FP number) TF: S>FP (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.)

...lee

Link to comment
Share on other sites

Rod...

 

Regarding implementation of GPLLNK and XMLLNK routines you mentioned as not implemented that, in fact, are implemented,

  • GPLLNK---
    • CNS (convert FP number to string)---Mark wrote his own routine for this. It might be interesting to see which is faster.

 

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:

  • Add
  • Subtract
  • Multiply
  • Divide
  • Convert FP to string
  • Convert string to FP

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

floating-point.pdf

fp.txt

Link to comment
Share on other sites

...

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

 

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

 

...lee

Link to comment
Share on other sites

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

 

 

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 - <http://www.powertran...from Source.zip>, and look in fp.asm. It also has trigometric functions which from memory are based on lookup tables.

 

Stuart.

 

 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.

Link to comment
Share on other sites

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

 

Mark

 

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.

Link to comment
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.

 

L10-float and math routines geneve os.txt

Edited by InsaneMultitasker
Link to comment
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

Link to comment
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.

 

This looks complete in that it can completely replace the console GPL and XML routines for floating point and transcendental math. It does 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:

 

* caller's task block

SYS1 EQU >F0A0

SYS2 EQU >F0C0

INTREG EQU >F080

MAPPER EQU >F110

TSKMAP EQU >8114

SYSREG EQU >F0E0

 

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):

  1. No scratchpad memory is used, so nothing in TF gets trashed.
  2. No VDP RAM usage that I can discern---should be faster.
  3. No GPL is executed TICD---should be faster.
  4. No console XML routines are executed TICD. This is not all that good, considering console ROM is on a 16-bit bus (I think).

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

Link to comment
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.

 

This looks complete in that it can completely replace the console GPL and XML routines for floating point and transcendental math. It does 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:

 

 

 

 

 

* caller's task block

SYS1 EQU >F0A0

SYS2 EQU >F0C0

INTREG EQU >F080

MAPPER EQU >F110

TSKMAP EQU >8114

SYSREG EQU >F0E0

 

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):

  1. No scratchpad memory is used, so nothing in TF gets trashed.
  2. No VDP RAM usage that I can discern---should be faster.
  3. No GPL is executed TICD---should be faster.
  4. No console XML routines are executed TICD. This is not all that good, considering console ROM is on a 16-bit bus (I think).

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

 

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.

 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

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.

 

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

You could probably convert these routines fairly easily once you get past the initial memory mapping code.

  • Like 1
Link to comment
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 TI Intern because I really hate black box calculations and because I am curious to see whether the MDOS assembly code so kindly posted by @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

Link to comment
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

 

* With some success here and there, I might add. I had my moments!

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...