Original Progress Thread

Porting Richard Russell's BBC BASIC (Z80) to the TI-83+ and TI-84+ series calculators.

Moderator: benryves

User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Good news; with a significant amount of help and advice from the extremely generous Richard Russell -- including the recovery of a text file over 20 years old that documents exactly how the host interface should interact with BBC BASIC -- I now have a relocated version of BBC BASIC that can sit on a single app page and simply needs a 768 byte scratch memory to operate.

To make life easier, I'm going to use a fixed jump table from $4000..$40FF that BBC BASIC will use to call the host interface code. BBC BASIC will then live above $4100. By adopting this rigid structure I can perform the relocation on CP/M using the original Microsoft M80 and L80 tools, so I can then copy it back to Windows, strip out the CP/M-specific header and trim off the unused footer and embed it directly into the program.

In short; BBC BASIC now runs from an app page and host interaction is made significantly easier and practical (no more emulated BBC Micro entry points required, which also means no more RAM execution protection problems). It's also a more recent version (3.00, 1987) than the Tube version I was experimenting with earlier.

Now I just need to get cracking on actually putting together a working host interface, but now that I've seen it running in an emulator I know that it's possible! :)
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

benryves wrote:To make life easier, I'm going to use a fixed jump table from $4000..$40FF that BBC BASIC will use to call the host interface code.
Wait a minute, isn’t that area partly occupied by the signature?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

This will be a two-page app (BBC BASIC is approaching 16KB, so I don't think I'd be able to fit it in one), with the signature, bcall branch table and host interface code on the first page and BBC BASIC, its jump table and register-preserving routine wrappers on the second page.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Here we go; BBC BASIC running as a two-page app. :)

Image

There's still a large amount work to do on this. There are some bits that I'd value your input on how they should be approached; for example, the large number of variations of PLOT are more than a little daunting. Should I aim for to cover as much of that as possible, or do you think it would be better to aim for routines that people would be more familiar with from TI-BASIC helpers? (Sprites?)

BBC BASIC can handle people trying to call the BBC Micro's jump table at $FF80..FFFF -- would you like some of the BBC Micro OS calls to be emulated?

Then there's the question of MODE -- in the absence of different screen resolutions, maybe this could do something more exotic, such as switch between black-and-white and greyscale modes.

The functions and statements that are open to custom implementations are ADVAL, POINT, CLG, COLOUR, DRAW, ENVEL, GCOL, MODE, MOVE, PLOT and SOUND.

I plan on using the AT routines that I'm currently using for keyboard input to return the mouse position with ADVAL.

I also plan on using exposing data transfer over the link port via the file I/O routines, by the special file names ":TILP", ":AT" and ":I2C", transferring data using the TI link port, AT and I²C protocols respectively.

Let me know what you think; I'd like to make this as good as I possibly can!
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I think I've implemented all of the core host interface entry points now.

Image Image Image

On the left demonstrates OSLOAD and OSSAVE, used to save and load entire programs. When you have a program in memory you can save it to disk with the SAVE "FILENAME". You can then load it back from disk with LOAD "FILENAME", or load then run it from disk with CHAIN "FILENAME".

In the middle demonstrates reading keys. GET and GET$ block, so they won't continue until a key is pressed. GET returns the ASCII value of the pressed key, GET$ returns a one-character string of the pressed character.

INKEY() and INKEY$() do much the same thing, but they have a timeout parameter (measured in centiseconds). If no key is pressed in the prescribed time, they return -1 and "" respectively. If a negative value is passed, it checks the state of the pressed key and returns true for pressed and false for released -- but I haven't implemented this bit yet.

On the right is a demonstration of some of the file related statements.

Files are currently all treated as program variables, and there is no special header on them. I'd like to keep it this way, as raw access to the TI-OS files seems "right". I was, however, wondering whether I should use extensions and handle various different file types. For example, I could also handle AppVars and use .8XV to differentiate them from programs (.8XP). If tokenised BBC BASIC programs could be identified they could appear as a .BBC files. This could also allow for more interesting things, such as a screen-shotting program like this:

Code: Select all

GBUF = &9340
PIC = OPENOUT "PIC1.8XI"
FOR I = 0 TO (EXT# PIC) - 1
  BPUT# PIC, GBUF?I
NEXT I
CLOSE# PIC
Let me know what you think. :)
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

I think you need to be able to identify BBC basic programs as separate, then make a keyhook to execute them from the PRGM menu directly.

This BBC basic project looks awesome! How does the performance compare with TI-Basic?
You know your hexadecimal output routine is broken when it displays the character 'G'.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Dwedit wrote:I think you need to be able to identify BBC basic programs as separate, then make a keyhook to execute them from the PRGM menu directly.
BBC BASIC has a provision to run a program automatically when you start it, so this would work very nicely. :) Good idea!
How does the performance compare with TI-Basic?
It certainly feels faster, though I've not yet done any proper benchmarking. If the language doesn't perform as fast as you'd like it to, though, you can take advantage of its built-in Z80 assembler to mix assembly and BASIC code (the CP/M version has a sample program that illustrates shell-sorting on string arrays).

(Due to copyright concerns and wanting to make sure I'm doing the correct thing, I am not going to release any early beta versions until I have sent a copy of the final software to Richard Russell for approval).
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I think I'm going to rewrite all the file I/O stuff from scratch (or as near as possible); trying to hack support for various TI variables by extension on top of something that only really was supposed to work with AppVars isn't exactly going too smoothly. :)

So, what I'm intending on doing is using an extension to define the type of a file. For example:
  • FILE.8XP - a named, variable-sized TI-OS program, shows up on the PRGM menu.
  • FILE.8XV - a named, variable-sized TI-OS AppVar.
  • PIC0.8XI - a numbered, fixed-sized TI-OS Pic variable.
  • FILE.DEV - a device file.
I'm not sure whether using 8X?-type extensions is a good idea; what if there was a (theoretical) TI-83 port? Should I use .PRG, .VAR and .PIC-type extensions (or would that be confusing)? BBC BASIC doesn't typically use extensions; if I tried to open FILE for reading what should it do? Default to FILE.8XP?

As for .DEV files, here are the ones I intend on supporting (as I've already written the code to support them, so it's easy to copy):
  • TILP.DEV - data over the TI's link port using the Texas Instruments protocol.
  • AT.DEV - AT (PS/2) protocol.
  • SIRCS.DEV - Sony IR remote control protocol.
  • I2C:D0.DEV - I²C bus protocol (in this case, slave address $D0, DS1307 clock).
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Well, I've gone for the extension method; I've been very busy with work recently so not had much time to invest in the project but have rewritten all of the file handling routines (they're now a lot more robust!)

Image

Here's a little screen-shotting program in BBC BASIC, writing to "PIC3.PIC" (which correponds to, well, Pic3).
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Pretty slick stuff ben!
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Cheers, tr1p1ea. :)

One for assembly fans;

Image

(*Insert usual disclaimer about it looking smoother on hardware*).

Code: Select all

 10 DIM SCROLL% 3
 20 P%=SCROLL%
 30 [
 40 OPT 0
 50 OUT (16),A
 60 RET
 70 ]
 80 REPEAT
 90   A%=&40+(TIME MOD 64)
100   CALL SCROLL%
110 UNTIL INKEY(0)>0
120 A%=&40:CALL SCROLL%
  • DIM SCROLL% 3 allocates 3 bytes of memory and stores a pointer to it in SCROLL%.
  • P%=SCROLL% sets the program counter for assembly output to this pointer.
  • OPT 0 disables the assembler's text output.
  • CALL SCROLL% loads A% into the accumulator (and other registers as applicable) and CALLs the Z80 assembly code previously generated and pointed to by SCROLL%
I'm going to focus on assembling the documentation so I can verify that the package is releasable (containing the requisite licence and copyright information). Having something to play with would probably help with the vague design questions I've put forth in the past! :)
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

Would it be possible to make a TI-Basic style menu interface, so instead of there only being a virtual keyboard, you get a PRGM menu with Basic commands?
You know your hexadecimal output routine is broken when it displays the character 'G'.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

2nd+0 brings up a list of all statements which you can scroll up and down in to paste them at the current cursor location (much like the CATALOG menu).

The way I'm handling keypad input is not really like the way the TI-OS handles it at all. Pressing a key inserts the alphabetic character on it, and 2nd/Alpha work as modifiers (so holding 2nd and pressing LN inserts a lower-case s). Alpha+key usually inserts the character printed on the key (Alpha+4=4).

Would you recommend I switch to a more conventional TI-OS-style input method?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I've been rather busy with work lately, so I've not had much chance to work on BBC BASIC. That said, I've added some features.

Image

The COLOUR statement can be used to change the colour of text. If the most significant bit is set it changes the background colour, if reset it changes the foreground colour (that is, 0..127 set the foreground colour and 128..255 set the background colour). Currently any non-zero colour is taken as black, but I'm going to recommend 127/255 are used as black for future compatibility (eg a future greyscale mode might have 0..31 as white, 32..63 as light grey, 64..95 as dark grey and 96..255 as black).

Americans, have no fear, as this version of BBC BASIC also supports the COLOR statement. (However, it doesn't have XOR, sticking to the British EOR).

The above screenshot also demonstrates the useful LIST IF statement, which can be used to search for keywords or strings in program lines when LISTing.

Image

This screenshot shows a feature borrowed from the BBC Micro: copy key editing. By pressing a cursor key when entering a line of code, the cursor splits into two - a read cursor and a write cursor. The write cursor remains on the end of the line you were editing (a solid block), but the read cursor can be moved to any location on the screen. Pressing the COPY key (in this case, I've commandeered the XTθn key for this purpose) reads the character that is under the read cursor and copies it to the write cursor, then increments both.

I've also implemented ADVAL, which lets you poll a mouse connected to your calculator. Most of the work I've done recently has been compiling the documentation together, though, so here's a snippet:
ADVAL positive argument

If the argument is positive, ADVAL returns a value related to the distance that the mouse has been moved.
  • ADVAL(1) returns the distance travelled in the X-direction.
  • ADVAL(2) returns the distance travelled in the Y-direction.
  • ADVAL(3) returns the amount that the scroll-wheel has been rotated.
The value returned corresponds to the total distance travelled in a particular axis since the last time that axis was checked using ADVAL.

Code: Select all

mouseX%= 0 
mouseY%= 0
REPEAT
  mouseX%= mouseX% + ADVAL(1)
  mouseY%= mouseY% + ADVAL(2)
UNTIL FALSE
ADVAL zero argument

ADVAL(0) returns a value in the range 0 to 7 corresponding to the state of the three mouse buttons. You can check the state of individual buttons using the AND operator.

Code: Select all

buttons%= ADVAL(0)
leftPressed%= buttons% AND 1
rightPressed%= buttons% AND 2
middlePressed%= buttons% AND 4
Another addition is *REFRESH; a useful one copied from BBC BASIC for Windows. Normally, drawing commands output directly to the LCD; by stating *REFRESH OFF only the graph buffer is updated. You can then copy the data to the screen by calling *REFRESH, or *REFRESH ON to restore the original behaviour.

Fortunately, BBC BASIC calls an entry point in the host interface prior to displaying errors, so we can make sure that *REFRESH is back ON, the text isn't the same background and foreground colour and the screen is on (and so on and so forth) before displaying error messages. :)
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Ahh good ol' "Colour" :).

I am quite impressed with the copy keys editing (well just the slickness of the editor altogether to be perfectly honest). Being able to draw to the buffer and update later is a must havefeature imo.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
Post Reply