"Псевдо-бейсик" для МК-161

Французский товарищ продолжает испытывать русскую машинку :) Гийому удалось доработать существующий транслятор с ЯВУ (псевдо-бейсика, затрудняюсь найти подходящее название) (MK-Compiler) для старых моделей к МК-161.

Что сделано:
- все существовавшие инструкции транслируются
- пересылка в калькулятор через RS-232 работает

Не хватает:
- псевдокоманды: FOR, NEXT, WHILE... (тут я не понял до конца о чем речь)
- сегменты программы (двоичные данные, например)
- директивы инициализации данных (TEXT, DW, DB, etc).

Соответственно, у Гийома возник вопрос, интересно ли это кому-нибудь и есть ли смысл продолжать работы?

Пример

Программа

do
  enter			; can be 0 or 1
  #num table + GPRG	; get one byte into the table
  $1000 +		; because in BINARY zone
  sto e
  0 exec \cls		; clear screen
  $50 enter set \x0y0	; set x0,y0 = 50,50
  rcl e exec \putgb	; draw selected graphic (bigA if 0 and smallA if 1)
  graph			; graphic page
  repeat
	get \nextkey	; a key?
	not		; if no key then 255, so not(255)=0
  until(x<>0)
  stop			; end of program
loop


table:
#DAL bigA smallA #end

#binary			; swap to BINARY zone

bigA:
#defgraph
	.........
	..*****..
	..*****..
	.**...**.
	.**...**.
	.*******.
	.*******.
	.**...**.
	.**...**.
	.**...**.
	.........
#end

#block 1		; each block = 64 bytes

smallA:
#defgraph
	.***.
	*...*
	*****
	*...*
	*...*
#end

#program		; back to PROGRAM zone

Генерирует такой код:

     PROGAM ZONE
  Step  | Code | Keys
-------------------------
  0000  |  0E  | ENTER 
  0001  |  00  | 0
  0002  |  00  | 0
  0003  |  03  | 3
  0004  |  07  | 7
  0005  |  10  | + 
  0006  |  28  | K GPRG 
  0007  |  01  | 1
  0008  |  00  | 0
  0009  |  00  | 0
  0010  |  00  | 0
  0011  |  10  | + 
  0012  |  4E  | STO e
  0013  |  00  | 0 
  0014  |  F4  | PP STO 
  0015  |  90  | 9 0
  0016  |  10  | 1 0
  0017  |  05  | 5
  0018  |  00  | 0
  0019  |  0E  | ENTER 
  0020  |  F4  | PP STO 
  0021  |  90  | 9 0
  0022  |  00  | 0 0
  0023  |  6E  | RCL e
  0024  |  F4  | PP STO 
  0025  |  90  | 9 0
  0026  |  16  | 1 6
  0027  |  56  | K GRAPH 
  0028  |  F6  | PP RCL 
  0029  |  90  | 9 0
  0030  |  29  | 2 9
  0031  |  3A  | K NOT 
  0032  |  57  | F X<>0 
  0033  |  28  | 2 8
  0034  |  50  | STOP 
  0035  |  51  | GOTO 
  0036  |  00  | 0 0
  0037  |  00  | AL(0)
  0038  |  40  | AL(64)

     BINARY ZONE
  Step  | Code | Comment
-------------------------
  1000  |  09  | Width
  1001  |  0B  | Height
  1002  |  00  | byte
  1003  |  00  | byte
  1004  |  F8  | byte
  1005  |  03  | byte
  1006  |  FE  | byte
  1007  |  03  | byte
  1008  |  66  | byte
  1009  |  00  | byte
  1010  |  66  | byte
  1011  |  00  | byte
  1012  |  66  | byte
  1013  |  00  | byte
  1014  |  FE  | byte
  1015  |  03  | byte
  1016  |  F8  | byte
  1017  |  03  | byte
  1018  |  00  | byte
  1019  |  00  | byte

  1064  |  05  | Width
  1065  |  05  | Height
  1066  |  1E  | byte
  1067  |  05  | byte
  1068  |  05  | byte
  1069  |  05  | byte
  1070  |  1E  | byte
-------------------------

  Addr  |  Name
-------------------------
  0037  |  TABLE
B 1000  |  BIGA
B 1064  |  SMALLA
-------------------------

   Reg  |  Name
-------------------------
  9000  |  \X0Y0
  9010  |  \CLS
  9016  |  \PUTGB
  9029  |  \NEXTKEY
-------------------------

Мне лично это было бы интересно. Можно вконтакте в группу написать, чтобы охватить бОльшую целевую группу

Добавил пример. Тут возникли некоторые сложности с языком, для непосредственного участия Гийома придется писать по-английски (по французски, видимо, только мы вдвоем с ним поймем). Соответственно, вконтакт отпадает.

А почему мнемоника такая странная — STOP вместо R/S ? EDIT. Прошёл по ссылке, разобрался. Ваш знакомый независимо от Новосибирска разработал латинскую версию ЯМК, не зная наших ГОСТов. Не хочет доработать до совместимости с официальной латинской мнемоникой МК-161? Тогда больше людей будет его код понимать.

В Контакте можно писать на английском языке. Приглашаю туда, тема компилируемого Бейсика интересная. Он должен работать быстрее Каллисто — хотя за это придётся жертвовать автономностью.

Если нетрудно, дайте товарищу прямые ссылки на описание латинской нотации. Он нашу тему просматривает через гуглопереводчик.

[quote=AtH]Direct link to the original Latin mnemonics for MK-161:
[/quote]

Thanks a lot !

I have adapted my listing to the Latin Reference.
The programmer still can use "INPUT", "STOP" or "R/S" but in the listing, there will always be "R/S". I changed the X<>0 to X!=0, the STO/RCL with M/RM etc... Again the programmer can still use STO, RCL, etc...

Here is the new listing:

     PROGAM ZONE
  Step  | Code | Keys
-------------------------
  0000  |  0E  | ENT 
  0001  |  00  | 0
  0002  |  00  | 0
  0003  |  04  | 4
  0004  |  08  | 8
  0005  |  10  | + 
  0006  |  28  | K PRGM 
  0007  |  01  | 1
  0008  |  00  | 0
  0009  |  00  | 0
  0010  |  00  | 0
  0011  |  10  | + 
  0012  |  4E  | M e
  0013  |  00  | 0 
  0014  |  F4  | PP M 
  0015  |  90  | 9 0
  0016  |  10  | 1 0
  0017  |  02  | 2
  0018  |  00  | 0
  0019  |  40  | M 0
  0020  |  05  | 5
  0021  |  06  | 6
  0022  |  3B  | K RAN 
  0023  |  12  | * 
  0024  |  01  | 1
  0025  |  02  | 2
  0026  |  00  | 0
  0027  |  3B  | K RAN 
  0028  |  12  | * 
  0029  |  F4  | PP M 
  0030  |  90  | 9 0
  0031  |  00  | 0 0
  0032  |  6E  | RM e
  0033  |  F4  | PP M 
  0034  |  90  | 9 0
  0035  |  16  | 1 6
  0036  |  5D  | F L0 
  0037  |  20  | 2 0
  0038  |  56  | K GRPH 
  0039  |  F6  | PP RM 
  0040  |  90  | 9 0
  0041  |  29  | 2 9
  0042  |  3A  | K NOT 
  0043  |  57  | F X!=0 
  0044  |  39  | 3 9
  0045  |  50  | R/S 
  0046  |  51  | GOTO 
  0047  |  00  | 0 0
  0048  |  00  | AL(0)
  0049  |  09  | AL(9)
  0050  |  12  | AL(18)

Guillaume.

Thank you, Guillaume. Your code is now readable by MK-161 owners.

Personally I prefer Oberon-style FX#0 mnemonics. But MK-161 designers choosed to use FX!=0 from one old Russian standard. May be we should respect their choice.

Hello,

You can find the MK-Compiler for download (free) at:

(français): http://gtello.pagesperso-orange.fr/mk161_f.htm
(english): http://gtello.pagesperso-orange.fr/mk161_e.htm

The english page is not fully translated from french, sorry for that.

Guillaume.

Hello,

I have added some instructions to ease the FORM programming (menus etc) with MK-Compiler.
I have taken the example for the SEMICO page and I wrote it for MK-Compiler with the new instructions.

Here is the new source code:

; MK-Compiler adaptation of original "primgui_1.mkl"
; from SEMICO / Russia
; http://mk.semico.ru/prog/mk/primprog/gui/primgui1.mkl

CX
2 EXEC \Cls				; clear screen
1 SET \FormEnable			; allow form functions
0 SET \ActiveForm			; active form = 0
SET \ActiveElement			; active element = 0
#NUM TFORM SET \FormTable		; set form table address

$64					; command force redraw

; here the main loop
; a command is executed (stating with redraw to have the menu)
; then each command returns a value:

; if 0: nothing to do, wait for a key press
; if 1: execute program for active element
; else error.


DO
	EXEC \FormCommand		; execute command
	GET \FormCommandStatus		; status of last command
	STO a

	IF(x<>0)THEN			; if not 0 then more action required

		1 -
	
		IF(x<>0)THEN		; if not 1, then error
			#NUM Err_Txt
			EXEC \CPrintStringP	; display "ERROR" in comment line
			CX ENT ENT ENT	; clear stack
			RCL a		; and recall error code
			R/S		; STOP
		ENDIF

		#NUM Jump_Table		; else if 1, exec user program
		SET \PPtr		; set program pointer at start of table
		GET \ActiveElement	; get active element
		EXEC \GetTableWordBCD	; and its address in the table
		STO a			; store address
		GOSUB (a)		; call address
		$64			; command force redraw
	ELSE
		REPEAT			; wait for a key
			GET \NextKey
			NOT
		UNTIL(x<>0)
		NOT			; back to key that is the command
	ENDIF
LOOP

Err_Txt:	
	#TEXTN "Error"

; here the jump table for every active element
; the program just play a different sound for each line selected


Jump_Table:	
	#DAF 
		Prog_Elem0 Prog_Elem1 Prog_Elem2 
		Prog_Elem3 Prog_Elem4 Prog_Elem5
	#END

Prog_Elem0:	
	$110		; frequency
Make_Sound: ENT
	$50		; duration 0.5 sec
	EXEC \Sound
	RTN

Prog_Elem1:	
	$220
	GOTO Make_Sound

Prog_Elem2:	
	$440
	GOTO Make_Sound

Prog_Elem3:	
	$880
	GOTO Make_Sound

Prog_Elem4:	
	$1760
	GOTO Make_Sound

Prog_Elem5:	
	$3520
	GOTO Make_Sound

	; table form
TFORM:

#Formtable 0 #END	; one form with id=0

#DefineForm 0 6		; form id=0 has 6 elements

	#FormFlags  13 13 13 13 13 13
	#FormInput  >>
	#FormOutput 0 0 0 1 0 2 0 3 0 4 0 5
	#FormLeft   5 0 1 2 3 4
	#FormRight  1 2 3 4 5 0

	#FormMainProgram
		#TYPE 0			; font normal
		#TAB  32 0		; position...
		#TXTP 16 Line_M		; ...for title string
		#TAB  0 9		; start point...
		#SQU  0 127 1		; ...for a line
		#TAB  2 10		; position...
		#TXTP 16 Line_0		; ... for option 0 string
		#TAB  2 19
		#TXTP 16 Line_1
		#TAB  2 28
		#TXTP 16 Line_2
		#TAB  2 37
		#TXTP 16 Line_3
		#TAB  2 46
		#TXTP 16 Line_4
		#TAB  2 55
		#TXTP 16 Line_5
	#END

	#FormElements
	
	#FormElementProgram 0
		#TAB 0 10
		#JM Reverse_Video
	#FormElementProgram 1	
		#TAB 0 19
		#JM Reverse_Video
	#FormElementProgram 2	
		#TAB 0 28
		#JM Reverse_Video
	#FormElementProgram 3	
		#TAB 0 37
		#JM Reverse_Video
	#FormElementProgram 4	
		#TAB 0 46
		#JM Reverse_Video
	#FormElementProgram 5	
		#TAB 0 55

	Reverse_Video:
		#SQU 3 64 9		; mode XOR to reverse screen rectangle
	#END

Line_M:	#TEXT0 "Main Menu"
Line_0:	#TEXT0 "Note 1"
Line_1:	#TEXT0 "Note 2"
Line_2:	#TEXT0 "Note 3"
Line_3:	#TEXT0 "Note 4"
Line_4:	#TEXT0 "Note 5"
Line_5:	#TEXT0 "Note 6"

You can find the MK-Compiler for download (free) at:

(français): http://gtello.pagesperso-orange.fr/mk161_f.htm
(english): http://gtello.pagesperso-orange.fr/mk161_e.htm

The english page is not fully translated from french, sorry for that.

Guillaume.

Hi!
That's very impressive!

Sorry, maybe I missed something from the manual/help file, is .LST file the only format compiler produces?

PROGAM ZONE
Step | Code | Keys
-------------------------
0000 | 0D | CX
0001 | 02 | 2
0002 | F4 | PP M
0003 | 90 | 9 0
0004 | 10 | 1 0
0005 | 01 | 1
0006 | F4 | PP M
...

Just thinking, how to run it on an eMkatic MK161 emulator?

Thanks !
For now, the LST file is the only one produced because the MK-Compiler can send the program directly to the calculator without using "mk-v126.exe".
But just ask... I can add some things.
What format would you like?

I don't know the eMkatic MK161 emulator.
Where can I download it? Is it free?

News: I am working on optimizations to save some bytes with #NUM and the internal forward jumps in IF/ELSE and WHILE.

Guillaume.

[quote=Vitasam]Hi!
That's very impressive!

Sorry, maybe I missed something from the manual/help file, is .LST file the only format compiler produces?

PROGAM ZONE
Step | Code | Keys
-------------------------
0000 | 0D | CX
0001 | 02 | 2
0002 | F4 | PP M
0003 | 90 | 9 0
0004 | 10 | 1 0
0005 | 01 | 1
0006 | F4 | PP M
...

Just thinking, how to run it on an eMkatic MK161 emulator?[/quote]

Thanks Vitasam!
Great advice from you.

I modified MK-Compiler and it can output MKP, MKB and MKD files to load in the eMKatic emulator.

You must use MK-Compiler V1.02 to get this.
Have a look at my page for details :
http://gtello.pagesperso-orange.fr/mk161_e.htm#emul

Guillaume.

So, you've found eMKatic emulator, good!
I will try your compiler.

Уважаемый ant-tv сейчас переводит английскую страничку Guillaume Tello на русский язык.

Hello,

In fact, you can use R/S if you want. If you prefer STOP you can use it. And you can even call it INPUT if your stop is to enter a value. The 3 mnemonics will assemble to "50". This makes the code more readable (on my opinion) as you can understand why the program stops.

I use the same for /-/, you can call it CHS (change sign), both assemble to "0B".

Again for STO and RCL, when you use them with registers above 9000, I prefer SET and GET:

SET \x0y0 is equivalent to STO \x0y0 but more readable.

And even I use the word EXEC when storing a value starts an action:

STO \putgp is equivalent to EXEC \putgp as storing executes the "put graphic from program memory".

That was my choice !

Guillaume