Help for MK-161 Forms programming

Hello all,

Can anyone help me?
I don't understand the meaning of the 8 bits of the flags in this page:
http://mk.semico.ru/d1_p16.htm

at paragraph 16.2.2.2.

I don't speak russian and the Google translation is really bad.

I am currently working on the MK-Compiler (a kind of pseudo basic for the MK-161) and the better I understand things, the more useful will be the compiler.

Thanks to all,

Guillaume.

PS: the MK-Compiler page:

Forums: 

Guillaume, thats 8 bytes, not bits. Each byte, but first, contains 8-bit offset to the particular data structure.

One of those structures is the action flags table (DE). It has bit fields. Those bit fields are explained in the paragraph 16.2.2.3.

Now about your compiler. MK-Compiler will be really helpful if you make it high-level, closer to the actual BASIC. Implement variables, to start with. MK-161/MK-152 is the powerful machine and in its 10000 steps can support the real programming language.

Forms programming is sophisticated and very low-level. Most of programs, that use forms, are written by manufactures. Visual computer tools to create/draw those forms also could be helpful. So your compiler could naturally evolve into Visual Basic. :-)

Hello AtH,

Sure that I wasn't clear, but I was talking about the action flags ! So it was the bit field that was my problem.
I made a mistake with the paragraph number : I wanted explanations on the 16.2.2.3 section.

I have used different systems to translate and now the bit field is clear for me.

About MK-Compiler:

What you say is clever, most of all about the forms that are really technical and hard to manage.
I have yet added some directives to ease the form programming (some tables are generated automatically).
For example here:

#OPTIM 0
#MKFiles 2

#reg a GrainNum		; how many grains of sand per run
#reg b PiValue		; resulting PI approximation (for display)
#reg c Total		; accumulator of grains of sand through the runs
#reg d InsideCircle	; accumulator of grains inside the quarter of circle
#reg e Duration		; duration of a run in HH.MMSS (for display)
#reg 7 Address		; address of the subprogram corresponding to the active element
#reg 0 Iter		; for looping
#reg 8 Running		; flag is calculation is running (for display)

CX 
	=PiValue =Total =InsideCircle
	SET \ActiveForm
	SET Running
1
	SET \FormEnable				; enable form functions
	SET \ActiveElement
$100
	SET GrainNum				; default = 10 grains per run

#NUM3 TFORM
	SET \FormTable				; form table address

$64 						; force redraw

DO
	SET \FormCommand			; exec one command

	GET \FormCommandStatus			; and get result
	!IF(x<>0)THEN				; if result<>0, more work required
		1 -
		!IF(x=0)THEN			; if result=1, action on one element
			#NUM2 JumpTable 
				SET \PPtr	; set pointer to start of table
			GET \ActiveElement	; index in the table
			EXEC \GetTableWordBCD	; and get address according to the element
			=Address 
				GOSUB (Address)	; and call address
		ENDIF

		$64				; send "force redraw" as command
	!ELSE					; if result=0 
		REPEAT				; just wait for a key
			GET \NextKey
			NOT
		UNTIL(x<>0)
		NOT				; send key as command
	ENDIF
LOOP						; infinite loop to new command

JumpTable:						; the jump table
#DAF 
	Dummy					; dummy address as the system manages this element
	Calculation				; ENTER on "Run!" in the menu
	ProgramEnd				; ENTER on "Exit!" in the menu
#END

Title:  #TEXT0 "PI Monte Carlo"
Grains: #TEXT0 "Grains of sand :"
Run:	#TEXT0 "Run !"
Approx: #DB $B9 $20 $7E 0 #END		; PI ~
Exit:	#TEXT0 "Exit !"
Time:	#TEXT0 "Time :"
Calc:	#TEXT0 "C A L C U L A T I N G"


Note:						; subprogram to make a sound
	ENT $20 EXEC \Sound			; ENTERs the frequency, 20/10 sec for duration
	REPEAT
		GET \SOUND			; is sound terminated?
	UNTIL(x=0)				; if not equal to zero, go on
	RTN

Calculation:
	$64 STO Running				; running<>0 for "Calculating"
	SET \FormCommand			; and force redraw of the interface
	GET \TIME HMS> =Duration		; start time saved
	@GrainNum =Iter				; for the loop
	SUM Total				; update the accumulator with new grains
	FOR Iter				; for every grain
		RAN X^2 RAN X^2 + 1 -		; compare 1 with random x^2+y^2
		!IF(x<0)THEN			; if <1 then
			4 SUM InsideCircle	; 4 on the accumulator
		ENDIF
	NEXT
	@InsideCircle @Total / =PiValue		; inside/total = PI
	GET \TIME HMS> 
	@Duration - >HMS =Duration		; newtime-starttime = duration
	$523 Gosub Note				; marvellous music to say it's done
	$880 Gosub Note
	$699 Gosub Note
	CX STO Running				; and clear flag
Dummy:
	RTN

ProgramEnd:					; if Exit! selected, just stop.
	STOP

TForm: #FormTable 0 #End

#DefineForm 0 3

	#FormFlags 5 13 13			; one link and two functions
	#FormOutput >>
	#FormInput 254 0 0 1 0 2		; fist link to "Enter a number", the other don't move
	#FormRight 1 >>
	#FormLeft 2 0 1				; cycling with left and right
	#FormMainProgram
		#TYPE 0				; normal font
		#TAB 36 0			; title position
		#TXTP 16 Title			; "PI Monte Carlo"
		#TAB 8 52			; bottom line start
		#SQU 3 112 1			; and draw line
		#TAB 8 10			; upper line start
		#SQU 3 112 1			; and draw line
		#TAB 10 12			; text position
		#TXTP 16 Grains			; "Grains of sand :"
		#TAB 84 12			; number position
		#PREXP 16 GrainNum		; and display register
		#TAB 10 32			; text position
		#TXTP 16 Approx			; "PI~"
		#TAB 30 32
		#PREXP 16 PiValue		; and display register
		#TAB 10 42
		#TXTP 16 Time			; "Time : "
		#TAB 50 42
		#PRFORM 16 Duration 2 4		; and display duration
		#TAB 10 54
		#TXTP 16 Exit			; "Exit !"
		#TAB 10 22
		#JNEZ Running Calculating	; test register Running
		#TXTP 16 Run			; if 0, display menu "Run !"
		#END
	Calculating:
		#TXTP 16 Calc			; if not 0, display "C A L C U L A T I N G"
		#END

	#FormElements
	
	#FormElementProgram 0
		#LDADR GrainNum			; prepare pointer to GrainNum if a number is entered
		#TAB 8 11			; upper point
		#JM ReverseVideo
	#FormElementProgram 1
		#TAB 8 21			; upper point
		#JM ReverseVideo
	#FormElementProgram 2
		#TAB 8 53			; upper point
	ReverseVideo:
		#SQU 3 112 10			; reverse video rectangle to mark "selected"
		#END

But I am thinking of a higher structure to make little menus easely with links to other menu or subprogram.

Guillaume.

Thank you! We need something to ease form design.

Usually visual tools have two different file formats.
1. The source file. Text file, describing how everything is on the display.
2. The target file. It's the source file, compiled into OS-specific binary resource.

Your MK-Basic code could be OS-specific part of the visual tool (file 2). Also target file could be .mkl one.

Ideally there should be file (file 1), describing popular types of menu items and connections between them. And the tool, that compiles human-readable menu description (file 1) into .mkl or MK-Basic code. Perfect tool will also allow to edit source menu file (file 1) by a novice in a visual way, with a mouse.

Hello,

I have added some new features to ease Menu programming. For example, this simple source code:

#MKFiles 2

#MENU
	#STRING 1 "My Title"
	#ACTION "Music !" MyProg
	#ACTION "Exit..." MyEnd
#ENDMENU

#MENUMAINLOOP 7

MyProg:
	$440 ENT $20 EXEC \Sound
	RTN

MyEnd:
	STOP

Creates a menu with a title and two active entries that will run two subprograms.
The first one plays a single note (Music!) and the second stops the program (Exit).

The structure between #MENU and #ENDMENU describes the menu.

The instruction #MENUMAINLOOP 7 inclue all the instructions to manage the menu (using register 7 as indirect register to call routines).

Then you just have to write your routines ! (myprog and myend).

It will be possible to have several menus linked together.

This source assembles to a 165 steps program.

This new MK-Compiler is not yet available (I'm working on it and debugging!) This will be version 1.03 when finished.

Guillaume.

Hello again,

The work advances !
Remember the previous message with the "Pi MonteCarlo" source ?
Here is the new one, very simple, with the #MENU/#ENDMENU structure:

#MKFiles 2

;--------------------
; Register definitons
;--------------------

#reg a GrainNum		; how many grains of sand per run
#reg b PiValue		; resulting PI approximation (for display)
#reg c Total		; accumulator of grains of sand through the runs
#reg d InsideCircle	; accumulator of grains inside the quarter of circle
#reg e Duration		; duration of a run in HH.MMSS (for display)
#reg 7 Address		; address of the subprogram corresponding to the active element
#reg 0 Iter		; for looping
#reg 8 Running		; flag is calculation is running (for display)

;--------------------
; Menu description
;--------------------

#MENU
	#STRING 1 "PI MonteCarlo"	; The title in big font
	#HLINE				; separator
	#INPUTD "Grains of sand :" 84 GrainNum
					; one "input" line to set GrainNum
	#?ACTION "Run !" Calculation Running "C A L C U L A T I N G"
					; one "action" line (will go to Calculation)
					; and with different text
					; according to register "Running"
	#OUTPUTD 0 "PI =" 32 PiValue	; one "output" line showing register PiValue
	#OUTPUTF 0 "Time :" 50 Duration 2 4
					; one "output" formatted line to display time
	#HLINE				; separator
	#ACTION "Exit !" ProgramEnd	; one "action" line (will go to ProgramEnd)
#ENDMENU

;--------------------
; My initializations
;--------------------

CX 
	=PiValue =Total =InsideCircle
	=Duration
	SET Running
$100
	SET GrainNum				; default = 100 grains per run

;--------------------
; The main loop here
;--------------------

#MENUMAINLOOP Address

;--------------------
; My subprograms
;--------------------

Note:						; subprogram to make a sound
	ENT $20 EXEC \Sound			; ENTERs the frequency, 20/10 sec for duration
	REPEAT
		GET \SOUND			; is sound terminated?
	UNTIL(x=0)				; if not equal to zero, go on
	RTN

Calculation:
	1 STO Running				; running<>0 for "Calculating"
	#REDRAW					; and force redraw of the interface
	GET \TIME HMS> =Duration		; start time saved
	@GrainNum =Iter				; for the loop
	SUM Total				; update the accumulator with new grains
	FOR Iter				; for every grain
		RAN X^2 RAN X^2 + 1 -		; compare 1 with random x^2+y^2
		IF(x<0)THEN			; if <1 then
			4 SUM InsideCircle	; 4 on the accumulator
		ENDIF
	NEXT
	@InsideCircle @Total / =PiValue		; inside/total = PI
	GET \TIME HMS> 
	@Duration - >HMS =Duration		; newtime-starttime = duration
	$523 Gosub Note				; marvellous music to say it's done
	$880 Gosub Note
	$699 Gosub Note
	CX STO Running				; and clear flag
	RTN

ProgramEnd:					; if Exit! selected, just stop.
	STOP

Here are some copies of the interface, first, I select "Grains of sand" to change the default 100 to 2000:

Then I use ENTER on the "Run !" line, and it turns to "Calculating" while the program is running:

At the end, a sound is played and the calculation is over, you can see the PI approximation and the time (22 seconds), then you can run it again or select Exit to quit the program:

This works with version 1.03 of the MK-Compiler on my page:

MK-161 page

Guillaume.