Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:13 21 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM V4.7 User Defined Fonts

Author Message
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 08:35am 31 Jul 2015
Copy link to clipboard 
Print this post

MMBasic 4.7 for the Micromite, "MM", has 2 built-in fonts, and does not support loading other fonts from the SD card unlike the MM+.

However any device running MMBasic 4.7 B23 or later can load different fonts using CFunctions.

In the example below, the 2 built-in fonts are replaced by a 7 Segment font and a Dot-matrix font, and then the usual MMBasic TEXT and FONT commands can be used to write to the LCD Panel using the new font.

You do NOT need to compile/write 'C' code or CFunctions to use this loadable font feature. Pre-compiled fonts are available for download from http://www.mmbasic.org/fonts/index.html.

To use loadable fonts in MM MMBasic, you must download and append the InstallFont CFunction from http://www.mmbasic.org/fonts/InstallFont.bas onto the end of your MMBasic program, then download and append your chosen font from http://www.mmbasic.org/fonts/index.html onto the end of your MMBasic program.

To install the font, you first obtain the address of the font CFunction using PEEK(CFUNADDR FontName) and then call InstallFont with that address and the font index, ie 1 or 2. Thereafter, you just use the usual MMBasic 4.7 TEXT, and FONT commands, eg

DIM FontAddr%=PEEK(CFUNADDR SevenSegNumFontPlus)
DIM Retrn%=InstallFont(FontAddr%, 1)


I will be adding further pre-compiled fonts at http://www.mmbasic.org/fonts/index.html, but please feel free to contact me if you want a specific font compiled.

I will also be updating the CFunction Tutorials to include a chapter on how to compile CFunction fonts - it really is very, very simple, and requires NO C language experience/knowledge - in fact if I get the time I might add a utility to CFuncGen which will take in a font file and generate the font CFunction.

The example MMBasic program which demonstrates font CFunctions is shown below - copy and paste to try it out. The test program is also available from http://www.mmbasic.org/fonts/CFunctionFontExample.bas - NB watch out for the Bulletin board changing the code below

OPTION EXPLICIT
OPTION DEFAULT None
CPU 48

PRINT "CFunction Font Example - (c) Peter Carnegie 2015"
PRINT

'OPTION LCDPANEL ILI9341,L,2,23,24
PRINT "Don't forget to issue OPTION LCDPANEL ....."
PRINT "at the command prompt"
PRINT

PRINT "Installing SevenSegNumFontPlus as Font 1"
'Get Address of SevenSegNumFontPlus font
DIM FontAddr%=PEEK(CFUNADDR SevenSegNumFontPlus)
DIM Retrn%=InstallFont(FontAddr%, 1)

'Get Address of DotMatrix_M_Slash font
PRINT "Installing DotMatrix_M_Slash as Font 2"
FontAddr%=PEEK(CFUNADDR DotMatrix_M_Slash)
Retrn%=InstallFont(FontAddr%, 2)

'Use Font 2 and scale x2
Font 2,2

'Yellow FG, Dark Blue BG
Colour &HFFFF00,&H000066

'Clearscreen
CLS

'Draw a Red Frame
Box 0,0,MM.HRes-4,MM.VRes-4,4,&HFF0000,-1

Text (MM.HRes/2)-115,(MM.VRes/2)-100,"ILI9341"

Text (MM.HRes/2)-140,(MM.VRes/2)+60,STR$(MM.HRes)+" "+STR$(MM.VRes),,1,1

Text MM.Hres/2 - 20,(MM.VRes/2)+60,"x"

DIM I%

'Countdown
FOR I%=9 TO 0 STEP -1
Text (MM.Hres/2)-40, (MM.VRes/2)-35,STR$(I%),,1,2,&H00FF00,&H000066
PAUSE 900
NEXT I%

CLS

'Draw a Red Frame
Box 0,0,MM.HRes-4,MM.VRes-4,4,&HFF0000,-1

'Calculate the width in pixels of TIME$
'The 7Segment font is 32 pixels wide
DIM WT%=LEN(TIME$) * 32

'Calculate the width in pixels of TIME$
'The 7Segment font is 32 pixels wide
DIM WD%=LEN(DATE$) * 32

'7Segment Font is 50 Pixels high
DIM H%=50

DO
Text (MM.Hres/2)-(WT%/2), (MM.VRes/2)+H%,TIME$,,1,1,&HffFF00,&H000066
Text (MM.Hres/2)-(WD%/2), (MM.VRes/2)-H%,DATE$,,2,2,&HffFF00,&H000066
PAUSE 500
LOOP

END


'******************************************************************************
'
'Created : 2015-07-31 12:23:30 UTC
'Author : Peter Carnegie
'Generator : CFuncGen Ver 2.1.5.0
'
CFUNCTION InstallFont
00000000
27bdfff8 afbe0004 03a0f021 afc40008 afc5000c 8fc2000c 8c430004 8c420000
00021880 3c029d00 34420054 8c420000 00621021 2442fffc 00402021 8fc20008
8c430004 8c420000 ac820000 00001021 00001821 03c0e821 8fbe0004 27bd0008
03e00008 00000000
END CFUNCTION 'MIPS32 M4K
'
'******************************************************************************



'******************************************************************************
'
'Created : 2015-07-31 12:22:19 UTC
'Author : Peter Carnegie
'Generator : CFuncGen Ver 2.1.5.0
'
CFUNCTION SevenSegNumFontPlus
00000000
0b303220 00000000 00000000 00feff00 00ffff01 80ffff03 60ffff01 f0feff0c
f801001e f801003f f801003f f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f 7800003e 18000038
08000020 00000000 00000020 18000038 7800003e f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f000001e 60feff0c 00ffff01 80ffff03 00ffff01
00feff00 00000000 00000000 00000000 00000000 00000000 00000000 00000000
60000000 f0000000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
78000000 18000000 08000000 00000000 00000000 18000000 78000000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f0000000 60000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00feff00
00ffff01 80ffff03 60ffff01 f0feff00 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 78000000 18feff01 88ffff03 e0ffff0f c0ffff27 00ffff39
0000003e 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f
0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000001e
00feff0c 00ffff01 80ffff03 00ffff01 00feff00 00000000 00000000 00000000
00000000 00feff00 00ffff01 80ffff03 60ffff01 f0feff00 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 78000000 18feff01 88ffff03 e0ffff0f
c0ffff07 18ffff01 78000000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f0000000 60feff00 00ffff01 80ffff03 00ffff01 00feff00 00000000
00000000 00000000 00000000 00000000 00000000 00000000 60000000 f000000c
f801001e f801003f f801003f f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f 7800003e 18feff39
88ffff23 e0ffff0f c0ffff07 18ffff01 78000000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f0000000 60000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00feff00 00ffff01 80ffff03
00ffff01 00feff0c 0000001e 0000003f 0000003f 0000003f 0000003f 0000003f
0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f
0000003e 00feff39 80ffff23 e0ffff0f c0ffff07 18ffff01 78000000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f0000000 60feff00 00ffff01
80ffff03 00ffff01 00feff00 00000000 00000000 00000000 00000000 00feff00
00ffff01 80ffff03 00ffff01 00feff0c 0000001e 0000003f 0000003f 0000003f
0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f 0000003f
0000003f 0000003f 0000003e 00feff39 80ffff23 e0ffff0f c0ffff27 18ffff39
7800003e f801003f f801003f f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f f801003f f000001e
60feff0c 00ffff01 80ffff03 00ffff01 00feff00 00000000 00000000 00000000
00000000 00feff00 00ffff01 80ffff03 60ffff01 f0feff00 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 78000000 18000000 08000000 00000000
00000000 18000000 78000000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f0000000 60000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00feff00 00ffff01 80ffff03 60ffff01 f0feff0c
f801001e f801003f f801003f f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f 7800003e 18feff39
88ffff23 e0ffff0f c0ffff27 18ffff39 7800003e f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f000001e 60feff0c 00ffff01 80ffff03 00ffff01
00feff00 00000000 00000000 00000000 00000000 00feff00 00ffff01 80ffff03
60ffff01 f0feff0c f801001e f801003f f801003f f801003f f801003f f801003f
f801003f f801003f f801003f f801003f f801003f f801003f f801003f f801003f
7800003e 18feff39 88ffff23 e0ffff0f c0ffff07 18ffff01 78000000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000 f8010000
f8010000 f8010000 f8010000 f8010000 f8010000 f0000000 60feff00 00ffff01
80ffff03 00ffff01 00feff00 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00e00000 00f00100 00f80300 00f80300 00f80300 00f00100 00e00000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00e00000 00f00100
00f80300 00f80300 00f80300 00f00100 00e00000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
END CFUNCTION 'MIPS32 M4K
'
CFUNCTION DotMatrix_M_Slash
00000000
5f201610 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 80010000 00008001 80018001 80010000
00008001 80018001 80010000 00008001 00000000 80010000 00008001 300c0000
0000300c 300c300c 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 300c0000 0000300c 300c300c b66d0000 0000b66d 300c300c
b66d0000 0000b66d 300c300c 300c0000 0000300c 80010000 00008001 b60db60d
00600000 00000060 b00db00d 06000000 00000600 b06db06d 80010000 00008001
006c0000 0000006c 066c066c 30000000 00003000 80018001 000c0000 0000000c
36603660 36000000 00003600 000c0000 0000000c 80618061 80610000 00008061
000c000c 86610000 00008661 30603060 860d0000 0000860d b0010000 0000b001
b001b001 30000000 00003000 80018001 00000000 00000000 00000000 00000000
00000000 30000000 00003000 80018001 80010000 00008001 80018001 80010000
00008001 80018001 30000000 00003000 000c0000 0000000c 80018001 80010000
00008001 80018001 80010000 00008001 80018001 000c0000 0000000c 00000000
00000000 86618661 b00d0000 0000b00d b66db66d b00d0000 0000b00d 86618661
00000000 00000000 00000000 00000000 80018001 80010000 00008001 b66db66d
80010000 00008001 80018001 00000000 00000000 00000000 00000000 00000000
00000000 00000000 800d800d 800d0000 0000800d 80018001 000c0000 0000000c
00000000 00000000 00000000 00000000 00000000 b00db00d 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 800d800d 800d0000 0000800d 00000000 00000000
06000600 30000000 00003000 80018001 000c0000 0000000c 00600060 00000000
00000000 b00d0000 0000b00d 1e601e60 66600000 00006660 86618661 06660000
00000666 06780678 b00d0000 0000b00d 80010000 00008001 800d800d 80010000
00008001 80018001 80010000 00008001 80018001 b00d0000 0000b00d b06d0000
0000b06d 06000600 06000000 00000600 b00db00d 00600000 00000060 00600060
b66d0000 0000b66d b06d0000 0000b06d 06000600 06000000 00000600 b00db00d
06000000 00000600 06000600 b06d0000 0000b06d 06600000 00000660 06600660
06600000 00000660 b66db66d 06000000 00000600 06000600 06000000 00000600
b66d0000 0000b66d 00600060 00600000 00000060 b06db06d 06000000 00000600
06000600 b06d0000 0000b06d b00d0000 0000b00d 00600060 00600000 00000060
b06db06d 06600000 00000660 06600660 b00d0000 0000b00d b66d0000 0000b66d
06000600 06000000 00000600 30003000 80010000 00008001 000c000c 00600000
00000060 b00d0000 0000b00d 06600660 06600000 00000660 b00db00d 06600000
00000660 06600660 b00d0000 0000b00d b00d0000 0000b00d 06600660 06600000
00000660 b60db60d 06000000 00000600 06000600 b00d0000 0000b00d 00000000
00000000 00000000 80010000 00008001 00000000 80010000 00008001 00000000
00000000 00000000 00000000 00000000 00000000 80010000 00008001 00000000
80010000 00008001 000c000c 00000000 00000000 00000000 00000000 30003000
80010000 00008001 000c000c 80010000 00008001 30003000 00000000 00000000
00000000 00000000 00000000 b00d0000 0000b00d 00000000 b00d0000 0000b00d
00000000 00000000 00000000 00000000 00000000 000c000c 80010000 00008001
30003000 80010000 00008001 000c000c 00000000 00000000 b00d0000 0000b00d
06600660 06000000 00000600 30003000 80010000 00008001 00000000 80010000
00008001 b00d0000 0000b00d 06600660 36600000 00003660 86618661 36600000
00003660 00600060 b60d0000 0000b60d b00d0000 0000b00d 06600660 06600000
00000660 b66db66d 06600000 00000660 06600660 06600000 00000660 b06d0000
0000b06d 06600660 06600000 00000660 b06db06d 06600000 00000660 06600660
b06d0000 0000b06d b00d0000 0000b00d 06600660 00600000 00000060 00600060
00600000 00000060 06600660 b00d0000 0000b00d b06d0000 0000b06d 06600660
06600000 00000660 06600660 06600000 00000660 06600660 b06d0000 0000b06d
b66d0000 0000b66d 00600060 00600000 00000060 b06db06d 00600000 00000060
00600060 b66d0000 0000b66d b66d0000 0000b66d 00600060 00600000 00000060
b06db06d 00600000 00000060 00600060 00600000 00000060 b00d0000 0000b00d
06600660 00600000 00000060 b661b661 06600000 00000660 06600660 b00d0000
0000b00d 06600000 00000660 06600660 06600000 00000660 b66db66d 06600000
00000660 06600660 06600000 00000660 b00d0000 0000b00d 80018001 80010000
00008001 80018001 80010000 00008001 80018001 b00d0000 0000b00d 06000000
00000600 06000600 06000000 00000600 06000600 06600000 00000660 06600660
b00d0000 0000b00d 06600000 00000660 30603060 80610000 00008061 006c006c
80610000 00008061 30603060 06600000 00000660 00600000 00000060 00600060
00600000 00000060 00600060 00600000 00000060 00600060 b66d0000 0000b66d
06600000 00000660 366c366c 86610000 00008661 86618661 06600000 00000660
06600660 06600000 00000660 06600000 00000660 066c066c 86610000 00008661
36603660 06600000 00000660 06600660 06600000 00000660 b00d0000 0000b00d
06600660 06600000 00000660 06600660 06600000 00000660 06600660 b00d0000
0000b00d b06d0000 0000b06d 06600660 06600000 00000660 b06db06d 00600000
00000060 00600060 00600000 00000060 b00d0000 0000b00d 06600660 06600000
00000660 06600660 86610000 00008661 30603060 860d0000 0000860d b06d0000
0000b06d 06600660 06600000 00000660 b06db06d 80610000 00008061 30603060
06600000 00000660 b00d0000 0000b00d 06600660 00600000 00000060 b00db00d
06000000 00000600 06600660 b00d0000 0000b00d b66d0000 0000b66d 80018001
80010000 00008001 80018001 80010000 00008001 80018001 80010000 00008001
06600000 00000660 06600660 06600000 00000660 06600660 06600000 00000660
06600660 b00d0000 0000b00d 06600000 00000660 06600660 06600000 00000660
300c300c 300c0000 0000300c 80018001 80010000 00008001 06600000 00000660
06600660 06600000 00000660 86618661 86610000 00008661 366c366c 06600000
00000660 06600000 00000660 06600660 300c0000 0000300c 80018001 300c0000
0000300c 06600660 06600000 00000660 06600000 00000660 06600660 06600000
00000660 300c300c 80010000 00008001 80018001 80010000 00008001 b66d0000
0000b66d 06000600 30000000 00003000 80018001 000c0000 0000000c 00600060
b66d0000 0000b66d b0010000 0000b001 80018001 80010000 00008001 80018001
80010000 00008001 80018001 b0010000 0000b001 00000000 00000000 00600060
000c0000 0000000c 80018001 30000000 00003000 06000600 00000000 00000000
800d0000 0000800d 80018001 80010000 00008001 80018001 80010000 00008001
80018001 800d0000 0000800d 80010000 00008001 300c300c 06600000 00000660
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 b66d0000
0000b66d b0010000 0000b001 b001b001 80010000 00008001 30003000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 b00d0000
0000b00d 06000600 b60d0000 0000b60d 06600660 b60d0000 0000b60d 00600000
00000060 00600060 b0610000 0000b061 066c066c 06600000 00000660 06600660
b06d0000 0000b06d 00000000 00000000 00000000 b00d0000 0000b00d 00600060
00600000 00000060 00600060 b00d0000 0000b00d 06000000 00000600 06000600
b60d0000 0000b60d 06600660 06600000 00000660 36603660 860d0000 0000860d
00000000 00000000 00000000 b00d0000 0000b00d 06600660 b06d0000 0000b06d
00600060 b00d0000 0000b00d 30000000 00003000 80018001 b00d0000 0000b00d
80018001 80010000 00008001 80018001 80010000 00008001 b60d0000 0000b60d
06600660 06600000 00000660 36603660 860d0000 0000860d 06000600 b00d0000
0000b00d 00600000 00000060 00600060 b0610000 0000b061 066c066c 06600000
00000660 06600660 06600000 00000660 80010000 00008001 00000000 80010000
00008001 80018001 80010000 00008001 80018001 80010000 00008001 80010000
00008001 00000000 80010000 00008001 80018001 80010000 00008001 80018001
000c0000 0000000c 00600000 00000060 00600060 30600000 00003060 80618061
006c0000 0000006c 80618061 30600000 00003060 80010000 00008001 80018001
80010000 00008001 80018001 80010000 00008001 80018001 30000000 00003000
00000000 00000000 00000000 306c0000 0000306c 86618661 86610000 00008661
86618661 86610000 00008661 00000000 00000000 00000000 b06d0000 0000b06d
06600660 06600000 00000660 06600660 06600000 00000660 00000000 00000000
00000000 b00d0000 0000b00d 06600660 06600000 00000660 06600660 b00d0000
0000b00d b06d0000 0000b06d 06600660 06600000 00000660 066c066c b0610000
0000b061 00600060 00600000 00000060 b00d0000 0000b00d 06600660 06600000
00000660 36603660 860d0000 0000860d 06000600 06000000 00000600 00000000
00000000 00000000 b0610000 0000b061 006c006c 00600000 00000060 00600060
00600000 00000060 00000000 00000000 00000000 b60d0000 0000b60d 00600060
b00d0000 0000b00d 06000600 b06d0000 0000b06d 80010000 00008001 80018001
b00d0000 0000b00d 80018001 80010000 00008001 80018001 30000000 00003000
00000000 00000000 00000000 06600000 00000660 06600660 06600000 00000660
06600660 b60d0000 0000b60d 00000000 00000000 00000000 06600000 00000660
06600660 06600000 00000660 300c300c 80010000 00008001 00000000 00000000
00000000 06600000 00000660 06600660 86610000 00008661 86618661 300c0000
0000300c 00000000 00000000 00000000 06600000 00000660 300c300c 80010000
00008001 300c300c 06600000 00000660 00000000 00000000 00000000 06600000
00000660 06600660 b60d0000 0000b60d 06000600 b00d0000 0000b00d 00000000
00000000 00000000 b66d0000 0000b66d 30003000 80010000 00008001 000c000c
b66d0000 0000b66d 30000000 00003000 80018001 80010000 00008001 000c000c
80010000 00008001 80018001 30000000 00003000 80010000 00008001 80018001
80010000 00008001 80018001 80010000 00008001 80018001 80010000 00008001
000c0000 0000000c 80018001 80010000 00008001 30003000 80010000 00008001
80018001 000c0000 0000000c 860d0000 0000860d 30603060 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000
END CFUNCTION 'MIPS32 M4K
'
'******************************************************************************


When you run the demo program, on an ILI9341, you should see


Hopefully this new MMBasic 4.7 capability will be interesting and useful

PeterEdited by G8JCF 2015-08-01
The only Konstant is Change
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9603
Posted: 12:51am 01 Aug 2015
Copy link to clipboard 
Print this post

Awesome!
Smoke makes things work. When the smoke gets out, it stops!
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2440
Posted: 03:48am 01 Aug 2015
Copy link to clipboard 
Print this post

pretty cool

i wonder if this could be added to mmbasic as a built-in function, where in addition to the CFUNCTION command there is a variant called CFONT FontName that is specific to font data. then have InstallFont(FontName, slot)

cheers,
rob :-)Edited by robert.rozee 2015-08-02
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 05:09am 01 Aug 2015
Copy link to clipboard 
Print this post

Thank you @G

@RR
MM+ has the "Load Font filename as #NBR" command. It may be possible to adopt and adapt that command into MM for MX170 to Load a font from a Font CFunction, eg Load CFont CfunctionName as #Slot where CFont is the flag to MMBasic to find a CFunction called CFunctionName and install that font into #Slot which would get rid of the need for CFunction InstallFont and the little bit of fiddling with Peek(CFUNADDR CFunctionName). However Flash in the MX170 is very, very, very tight.

Peter
The only Konstant is Change
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2440
Posted: 05:36am 01 Aug 2015
Copy link to clipboard 
Print this post

it would be good if the font could be used in-situ, without any need for making a duplicate.

are custom functions still held as both a text version (within the basic listing) as well as being stored as a 'compiled' version that is actually run? i can remember there being some talk long ago about having the custom function compiled into memory, then de-compiled back into source code whenever the editor (or list) is called.


cheers,
rob :-)
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9603
Posted: 03:59pm 01 Aug 2015
Copy link to clipboard 
Print this post

  G8JCF said  However Flash in the MX170 is very, very, very tight.


Indeed - that was why I was amazed you could do it at all!
Smoke makes things work. When the smoke gets out, it stops!
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 07:21am 02 Aug 2015
Copy link to clipboard 
Print this post

I've used the CFunction capability as another way to do DATA.
Micromites and Maximites! - Beginning Maximite
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 12:35pm 02 Aug 2015
Copy link to clipboard 
Print this post

@CG
Indeed CFunctions are also a way to do DATA type statements as U've found, but they are not as flexible as MMBasic Data statements in that the content of a CFunction is always just a series of 4 byte words and interpreting them as float, integer, & string is more tricky than simply using MMBasic's READ function, and now with the option to supply a label/line-number to the RESTORE command, the DATA/READ/RESTORE set is quite a powerful feature.

@G
S/W Architecture, S/W Architecture, S/W Engineering, S/W Engineering !! The trick was to have a table of pointers in RAM and NOT in Flash, that way, CFunctions (and even MMBasic using POKE) can override the vectors with new vectors - the actual cost in Flash was very small, just a couple of extra words to deal with the extra level of indirection - but what a pay-off for that small investment !

@RR
You are correct, for every byte in the executable CFunction, MMBasic stores 2 other bytes representing the ascii hex of the byte, ie binary 00000001, is represented by ascii 3031. I've gone through the source quite a few times trying to find a way around this, and there is no easy way of eliminating this "duplication". It could be done of course, but would, IMHO, require quite a fundamental change to the code - essentially, MMBasic source code in its entirety is loaded first into RAM,and then tokenised/parsed from RAM into Flash, with the CFunction binary being parsed and tacked onto the end of the mmbasic program in flash as the last step. I think that if we made it a rule that CFunctions MUST ALWAYS be appended after all other MMBasic code, then it should be possible for the save to flash to recognise when it hits the first CFunction keyword, to stop saving the MMBasic code to flash, and start parsing the ascii-hex into binary and tacking the binary onto the end thereby NOT saving the ascii-hex version of the CFunction(s). Then the LIST command would need to be changed to recognise that when it came to the end of the MMBasic code lines to check if there are CFunctions and if so, to convert those bytes to ascii-hex, format, and display them - of course any comments/user-formatting would have been lost, but that doesn't matter for CFunction(s). This doesn't help with getting larger programs because for so long as the whole MMBasic program has to loaded into RAM in its entirety first before saving to flash we're stuck with fact that the CFunction(s) start off as ascii-hex. A more radical approach of having 2 different AUTOSAVE/LOAD commands would be beneficial, eg Keep AUTOSAVE/LOAD as current, ie save MMBasic to Flash, but then have another AUTOSAVE, eg AUTOSAVE CFUNCTION, which tells MMBasic that what is being loaded in are only CFunctions, then when load is complete, MMBasic does the ascii-hex to binary conversion and save to flash locating the CFunction binary on the end of the previously saved MMBasic. This mechanism would permits much bigger MMBasic programs and much bigger CFunctions, but would require the discipline of ALWAYS AUTOSAVEing MMBasic code lines first, and then AUTOSAVE CFUNCTION second. The NEW command, and LIST command night need to be changed as well, eg NEW would clear out both the MMBasic and CFunction flash, but one might want to have NEW CFUNCTION which just clears out the CFunctions. Similarly LIST ALL could list the MMBasic program lines followed by the CFunction lines, and LIST CFUNCTION could list out just the CFunction lines. Finally the built-in editor would need quite a few changes to deal with the changes - CFunctions and the built-in editor don't really jive.

So, it could all be done, but in the list of priorities ......

Peter


The only Konstant is Change
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 02:37pm 02 Aug 2015
Copy link to clipboard 
Print this post

  G8JCF said   @CG
Indeed CFunctions are also a way to do DATA type statements as U've found, but they are not as flexible as MMBasic Data statements in that the content of a CFunction is always just a series of 4 byte words and interpreting them as float, integer, & string is more tricky than simply using MMBasic's READ function, and now with the option to supply a label/line-number to the RESTORE command, the DATA/READ/RESTORE set is quite a powerful feature.


I needed to store a graphic logo for LCD display on a MM (not MM+) based project. I read out the CFunction data as 32 bits, converted to 4 bytes and used that. This was before Line number for RESTORE. That project was why I suggested to Geoff the line number for RESTORE.
Micromites and Maximites! - Beginning Maximite
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 02:53pm 02 Aug 2015
Copy link to clipboard 
Print this post

@CG

Very well done, why BASIC's didn't support RESTORE LineNumber/Lable (in hindsight) is a complete mystery !

Also, another innovative use of CFunctions

Thank you

Peter
The only Konstant is Change
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2440
Posted: 03:06am 03 Aug 2015
Copy link to clipboard 
Print this post

  G8JCF said  
@RR
You are correct, for every byte in the executable CFunction, MMBasic stores 2 other bytes representing the ascii hex of the byte, ie binary 00000001, is represented by ascii 3031.


going in the direction from a listing in the editor, to sitting at the ">" prompt, is relatively easy - just discard any cfunction data from the basic listing (but keep the cfunction declaration). this would be made easier by perhaps introducing rules that dictate:
(1) any cfunctions must always be located at the end of the basic listing,
(2) cfunctions can not have any basic statements interspersed within or between them,
(3) comments are limited to only the lines before the cfunction statement.


going the other way is a little more tricky. after starting up the editor and decoding basic tokens back into text, a second process would be required to insert (into the listing in the editor) a 'decompilation' of previously stored custom functions.


i'm thinking of something like:


do
print "hello world"
loop

' this is the first custom function
cfunction abc
00000000
01020304 05060708 090A0B0C
end cfunction

' this is the second custom function
cfunction def
00000000
12345678 12345678 12345678
end cfunction


being stored in flash as something like:


do
print "hello world"
loop

' this is the first custom function
cfunction abc
<pointer to address 1>

'this is the second custom function
cfunction def
<pointer to address 2>

and:


<@1> 01020304 05060708 090A0B0C
<@2> 12345678 12345678 12345678


does this make sense?

i do, however, agree that the effort required may not justify doing all this, and that said effort may well be better expended on other parts of mmbasic.

it may be a worthy project for some of the other forum members to experiment with implementing, with any successes fed back to geoff. i have been highly impressed with the way this has been working with the MX470 version of mmbasic and LCD support.


cheers,
rob :-)
Edited by robert.rozee 2015-08-04
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025