Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:03 01 Aug 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 : Position on screen established from length of string?

Author Message
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 01:24am 20 Sep 2020
Copy link to clipboard 
Print this post

I am experimenting with converting some old business stuff written in QuickBasic to work on CMM2. One of my original subroutines sets up a grid for the user to answer with a string. Without going into detail I wish to locate the cursor to the end of a question string. Trouble is in QuickBasic PRINT@ could be set by characters (using LEN(), whereas in CMM2 it is by pixels. The nearest approximation is each character is 7.5 pixels wide. Is there another was of converting the length of string to the number of pixels it occupies?
Edited 2020-09-20 11:29 by Herry
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:09am 20 Sep 2020
Copy link to clipboard 
Print this post

MM.INFO(FONTWIDTH) will give you the width of the current font.

LEN(txt$) * MM.INFO(FONTWIDTH) gives you what you asked for.

Jim
VK7JH
MMedit
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 02:22am 20 Sep 2020
Copy link to clipboard 
Print this post

Brilliant. I have made my program work with the standard font by applying a width of 7.5 pixels per character (thank goodness they are not proportional fonts!) but I confess to worrying about other fonts. Your solution is perfect. I think I'll make it a user defined function
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 02:43am 20 Sep 2020
Copy link to clipboard 
Print this post

  Herry said  Brilliant. I have made my program work with the standard font by applying a width of 7.5 pixels per character (thank goodness they are not proportional fonts!) but I confess to worrying about other fonts. Your solution is perfect. I think I'll make it a user defined function


I don't think CMM2 font widths have a fractional part. Maybe it is 8, that's the default font's width. (though some characters may have some of the 8 columns as blank space)
Edited 2020-09-20 12:45 by capsikin
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:09am 20 Sep 2020
Copy link to clipboard 
Print this post

  Herry said   (thank goodness they are not proportional fonts!)


FontTweak can produce proportional fonts.
They can look nice...

Jim
VK7JH
MMedit
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 05:10am 20 Sep 2020
Copy link to clipboard 
Print this post

  Herry said  I am experimenting with converting some old business stuff written in QuickBasic to work on CMM2. One of my original subroutines sets up a grid for the user to answer with a string. Without going into detail I wish to locate the cursor to the end of a question string. Trouble is in QuickBasic PRINT@ could be set by characters (using LEN(), whereas in CMM2 it is by pixels. The nearest approximation is each character is 7.5 pixels wide. Is there another was of converting the length of string to the number of pixels it occupies?

Herry ...

Because MMBasic on the CMM2 only ever outputs graphics there is no true text mode like we are all familiar with from DOS Qbasic and hence no "LOCATE" or "PRINT@"

The following commands from the manual should help:
Predefined Read Only Variables:
==============================


MM.INFO(FONTHEIGHT)
MM.INFO(FONTWIDTH)

Integers representing the height and width of the current font (in pixels).

MM.INFO(HPOS)
MM.INFO(VPOS)

The current horizontal and vertical position (in pixels) following the last graphics or print command.

MM.INFO(MODE)
Returns the video mode as a floating point number e.g. 1.8, 2.16, etc.

1 = 800 x 600 pixels
2 = 640 x 400 pixels
3 = 320 x 200 pixels
4 = 480 x 432 pixels
5 = 240 x 216 pixels
6 = 256 x 240 pixels
7 = 320 x 240 pixels
8 = 640 x 480 pixels
9 = 1024 x 768 pixels (12-bit mode not available)
10 = 848 x 480 pixels (widescreen format)
11 = 1280 x 720 pixels (only .8 and .16 bit colour)
12 = 960 x 540 pixels (only .8 and .16 bit colour)

.8 = 8 bit colour
.12 = 12 bit colour
.16 = 16 bit colour

eg. 7.12 is "mode 7, 320x240 pixels, 12 bit colour"

MM.HRES
MM.VRES

Integers representing the horizontal and vertical resolution of the VGA
display in pixels.

Commands:
========


LEN( string$ )
Returns the number of characters in 'string$'.

TEXT x, y, string$ [,alignment$] [, font] [, scale] [, c] [, bc]
Displays a string on the VGA monitor starting at 'x' and 'y'.
‘string$’ is the string to be displayed. Numeric data should be converted to a
string and formatted using the Str$() function.
' alignment$' is a string expression or string variable consisting of 0, 1 or 2
letters where the first letter is the horizontal alignment around 'x' and can be
L, C or R for LEFT, CENTER, RIGHT and the second letter is the vertical
alignment around 'y' and can be T, M or B for TOP, MIDDLE, BOTTOM.
The default alignment is left/top.
A third letter can be used in the alignment string to indicate the rotation of
the text. This can be 'N' for normal orientation, 'V' for vertical text with each
character under the previous running from top to bottom, 'I' the text will be
inverted (ie, upside down), 'U' the text will be rotated counter clockwise by
90º and 'D' the text will be rotated clockwise by 90º
'font' and 'scale' are optional and default to that set by the FONT command.
'c' is the drawing colour and 'bc' is the background colour. They are optional
and default to the current foreground and background colours.
See the chapter "Basic Drawing Commands" for a definition of the colours
and graphics coordinates.

I wrote you a little program to demonstrate.  Its crude, but hopefully the comments will help you follow what I have done.  Tested under V5.05.06b9 with the new screen resolutions.  If you run it under a previous version and select an invalid mode number it will chuck you out with an error message.
'HerryText.BAS
'Ways To locate the cursor
'Demo by Womble 20 SEPT 2020
'
'

DO
  print "Choose a number between 1 and 12"
  INPUT i
  i = INT(i)
LOOP UNTIL i <= 12
MODE i,8
CLS
'Default COLOUR is WHITE on BLACK
print "Firmware Version = ",MM.INFO(VERSION)
'Print stuff in Yellow on Black
COLOUR RGB(YELLOW),RGB(BLACK)
print "Video Mode ", STR$(MM.INFO(MODE)),
SELECT CASE  INT(MM.INFO(MODE))
  CASE 1
     print " 800x600"
  CASE 2
     print " 640x400"
   CASE 3
     print " 320x200"
  CASE 4
     print " 480x432"
  CASE 5
     print " 240x216"
  CASE 6
     print " 256x240"
  CASE 7
     print " 320x240"
  CASE 8
     print " 640x480"
  CASE 9
     print " 1024x768"
  CASE 10
     print " 848x480"
  CASE 11
     print " 1280x720"
  CASE 12
     print " 960x540"
  CASE ELSE
     print "no idea what mode we are in"
     END   'abort out of program
END SELECT

'change font here to see what happens
print "we are using the DEFAULT font"
'
print "Font Height", STR$(MM.INFO(FONTHEIGHT))
print "Font Width", STR$(MM.INFO(FONTWIDTH))

'Display something in the middle of the screen
'Text alignment is Centre Middle expressed as "CM"
TEXT(MM.HRES/2),(MM.VRES/2),"THE MIDDLE OF THE SCREEN","CM"
'Save the current cursor location
xCursor$ = STR$(MM.INFO(HPOS))
yCursor$ = STR$(MM.INFO(VPOS))
'print a little underline _ cursor in red
COLOUR RGB(RED),RGB(BLACK)
PRINT  "__"
'Display the cursor position centered in the middle of the screen, aligned CENTER TOP "CT"
'on the penultimate line of the screen
DisplayText$ = "Cursor X,Y was at = " + xCursor$ + "," + yCursor$
TEXT(MM.HRES/2),(MM.VRES-((MM.INFO(FONTHEIGHT)*2))),DisplayText$,"CT"
COLOUR RGB(GREEN),RGB(BLACK)
'Exit message 4 lines up
TEXT(MM.HRES/2),(MM.VRES-((MM.INFO(FONTHEIGHT)*4))),"ENTER SOME TEXT TO EXIT","CT"
DO
  INPUT getmeout$
LOOP UNTIL getmeout$ <> ""


END
'program ends here


Hope that helps.  It certainly helped me writing it  

Regards

Womble

EDIT: TassyJim, if you want this for the Wecome Tape help yourself
Edited 2020-09-20 15:13 by Womble
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 06:28am 20 Sep 2020
Copy link to clipboard 
Print this post

I am using PRINT@ extensively!  

But I found setting up a user defined function more puzzling than I thought.  There is no DEFFN. I was hoping to be able, where X is the character count, to use WD(X) to be X * MM.INFO(FONTWIDTH)so I wrote...

FUNCTION (Y)
Y=Y*MM.INFO(FONTWIDTH)
END FUNCTION

No doubt this is  
Edited 2020-09-20 16:28 by Herry
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 06:43am 20 Sep 2020
Copy link to clipboard 
Print this post

  Quote  CLS
PRINT @(Xpos(10),Xpos(15)) "We are here"

FUNCTION Xpos(x)
Xpos = x *
MM.INFO(FONTWIDTH)
END FUNCTION

FUNCTION Ypos(x)
Ypos = x *
MM.INFO(FONTWIDTH)
END FUNCTION

VK7JH
MMedit
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 07:00am 20 Sep 2020
Copy link to clipboard 
Print this post

Those darned brackets. Yes, my syntax all wrong... All good now. So thanks. (I think it all started with the Z80 (for me anyway) or the 8088
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 12:52am 21 Sep 2020
Copy link to clipboard 
Print this post

  Herry said  I am using PRINT@ extensively!

Apologies, You are quite correct  

PRINT@( (MM.INFO(FONTWIDTH)*x),(MM.INFO(FONTHEIGHT)*y) )"";

where x is the character column, and y is the character row

Looks to me to be functionally equivalent to QBASIC LOCATE [row%],[column%]
although with the row and column values reversed, and without the extra gubbins LOCATE can do.

I need to read the manual more
 
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