Можно портануть к нам в ПЗУ новый маленький Бейсик!

Советский компьютер Радио-86РК (1986) и его клоны

Moderator: Shaos

User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by Shaos »

Вот чего нашёл :mrgreen:
https://hackaday.io/project/194248-one-kilobyte-tiny-basic-for-the-8080
This project is a birthday present for the Intel 8080. I wanted to investigate writing a BASIC interpreter in assembly language and decided to fit a BASIC interpreter into 1K. It’s not the only sub-1K BASIC that I’ve come across, but as far as I can see it is the most feature rich and also makes efficient use of memory for storing programs. It is probably fast compared to other Tiny BASICs because programs are tokenised. The set of features is similar to Palo Alto Tiny BASIC (PATB) but the syntax is slightly different in a few places. It supports GOSUB/RETURN, FOR/NEXT loops, and functions RND, ABS and USR. It has a single array variable @. Since it fits in 1K, it is about 60% of the size of the smallest PATB implementation. It is written in 8080 assembly language, and developed on a bespoke 8080 emulator. It hasn’t been run on a real 8080 yet. If anybody has a working 8080 system I’d be really interested in seeing it running.
Репа с сырцами (GPLv3): https://github.com/WillStevens/basic1K
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: новый маленький Бейсик!

Post by Shaos »

Бейсик целочисленный (16-битные переменные A...Z) плюс имеется один массив @, который способен занять всю доступную память:

Code: Select all

10 FOR I=1 TO 10
20 LET @(I)=I*255
30 NEXT
40 FOR I=1 TO 10
50 PRINT I," : ",@(I)
60 NEXT
Сама программа сидит в начале адресного пространства (там ожидается ПЗУ 1К) и использует RST для пущей компактности (там даже короткие джампы в пределах 256-байтовой страницы делаются через RST) - далее она ожидает как минимум 1К ОЗУ (как я понял)
The following statements are supported:

PRINT <expression>
LET <var> = <expression>
IF <expression> <statement>
GOTO <expression>
GOSUB <expression>
RETURN
INPUT <var>
FOR <var> = <expression> TO <expression> [STEP <expression>]
NEXT
END

and additionally, these commands can be issued if not prefixed by a line number:

LIST
RUN
NEW

<var> is a letter A-Z. A single array called @ is supported, its elements are @( <expression> ). The array uses all remaining memory after the program - it will eventually collide with the stack. Two system variables are available in ^ (address of start of array) and _ (current state of Random Number Generator). ^ can be used to work out how much free memory there is by subtracting it from the highest RAM address, and then subtracting 8+however much stack the program is likely to use (a few tens of bytes typically).

Signed 16-bit integer arithmetic is supported, with no overflow detection. Operators are + - * /.

Comparison operators are = <> < > <= >=. The result of a comparison is 1 if true, 0 if false.

Three functions taking a single parameter are available: ABS, USR and RND. The USR(x) function calls the address x. The RND(x) function returns a random number between 0 and x-1.

Program editing features are minimal - lines can be deleted by typing the line number by itself. Unlike in most BASIC implementations, overwriting a line is not permitted, a line must be deleted and then re-entered.
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by Shaos »

Вообще RST там через макросы заведены - можно наверное и в наш расширенный монитор этот бейсик попробовать затолкать (заменив RST-ы на CALL-ы с раздуванием размера кода за пределы 1КБ) ну и надо будет переписать PutChar и GetLine на РК-шные аналоги. Ещё надо будет деление переписать - оно там щас через вычитание сделано. Ну и функций/директив добавить - типа PEEK/POKE, POINT, MOVETO/LINETO, SAVE/LOAD и т.д.
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: новый маленький Бейсик!

Post by Shaos »

Shaos wrote:... далее она ожидает как минимум 1К ОЗУ (как я понял)
кстати я спросил у автора сколько максимум ОЗУ он могёт и автор сказал, что вплоть до 63КБ :mrgreen:
The RAM size has been set to 1K during development only because I have a lot of old 2K RAM chips and it is nice to be able to have the BASIC interpreter and any of the example programs all fit under 2K.

RAM_BASE and RAM_TOP can be set to anything up to 63K. Maximum BASIC program size is RAM size minus 64 bytes for variables, minus 8 bytes for a small buffer used by the INPUT statement, minus stack space used by the interpreter and by FOR/NEXT and GOSUB/RETURN, minus a few bytes needed to be able to run direct mode commands without colliding with the stack. So on 1K RAM system this is about 900 bytes and with 63K about 62.9K.
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
shiny
Maniac
Posts: 324
Joined: 14 Oct 2023 06:59

Re: Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by shiny »

Кстати, RC2014 BASIC не подойдет?
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by Shaos »

shiny wrote:Кстати, RC2014 BASIC не подойдет?
он большой
и вроде тоже на базе микрософтовского как и "микрон"
а тут суть в том, что бейсик совсем маленький - как раз в расширенный монитор воткнуть ;)
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by Shaos »

Сегодня у килобайтного бейсика случился апдейт:

Code: Select all

; 2024-03-15 Realised during testing that 
;     ExpEvaluate can sometimes try to return
;     when stack isn't a return address.
;     Realised that ExpEvaluate must either
;     succeed or fail, with no backtrack.
;     This required substantial changes to
;     PrintSub, especially a change to how it
;     knows if it has just had a comma. This
;     is now done based on parity of H.
;     To be retested.
;
;     Had an idea that operators and statements
;     could reside on different pages, creating
;     more space for both, and perhaps removing
;     the need for some of the Jumps out of
;     page 2 to statement implementation.
https://github.com/WillStevens/basic1K/commit/29d91cfeab713e40998a19481c25ac72b74299e4
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by Shaos »

Вчера случился мелкий апдейт в комментариях - в частности в исходнике было явно указано, что он покрывается лицензией GPLv3:

https://github.com/WillStevens/basic1K/commit/0e6e6d98153ac8d6859ff86cf0a883734b4c634e
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24086
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Можно портануть к нам в ПЗУ новый маленький Бейсик!

Post by Shaos »

Зарелизилась версия 1.0.0 - вот что добавилось с прошлого раза:

Code: Select all

;2024-03-23 
;     Changed INPUT so that it doesn't display
;     a prompt. It was confusing to have the
;     > prompt as is used in direct mode. Instead
;     programs that need a prompt before input
;     can use the multistatement line
;     PRINT "?", INPUT A
; 2024-03-25 Found a fix for problem where
;     -32768/2 has wrong sign. It costs 3 bytes
;     so need to find 2 byte saving before Ready
;     and 1 byte saving after Ready
; 2024-03-26 In the process of making major
;     rearrangements to save several bytes and 
;     fix the bug mentioned above.
; 2024-03-27 Major rearrangements have been done.
;      Net reault is to save 5 bytes, but need
;      to carefully check whether any same-page
;      assumptions are violated
; 2024-03-28 Found and fixed several bugs related
;			 to above changes. Execution of ? token
;			 seems to take too long, implying a
;			 remaining bug. 9 bytes free now, 5 of 
;			 which are contiguous at the end of the
;			 program.
; 2024-03-29 Two bugs to fix : prompt appears
; 		 twice after entering first line. 
;			 detection of syntax errors is slow
; 2024-04-01 Fixed several bugs introduced above.
;      Need to run all tests again.
; 2024-04-03 Changed newline behaviour so that
;      VT100 terminals require LNM reset rather
;      than set.
; 2024-04-04 Reclaimed 2 bytes in
;      DigitClassNotEnd. Used those two bytes to
;      add a colon token. It can be used as a 
;      statement separator in multi-statement
;      lines.
You do not have the required permissions to view the files attached to this post.
Я тут за главного - если что шлите мыло на me собака shaos точка net