Get character under cursor in BASIC?

Door BokanoiD

Rookie (27)

afbeelding van BokanoiD

11-06-2013, 12:34

Hi all,

I'm having fun playing around in BASIC again after a 20+ years break... Wink
So, to get going again on my recently acquired MSX2 I'm currently making a little program to entertain my two sons, one who I have pushing random buttons to produce colours and sounds and one of which is old enough to just start learning how to read...

I was thinking to do text that scrolls onto the screen, which I know how to do in assembly but I'm kinda stumped how to do this in MSX BASIC. In pseudo code it would look something like

- read character on position X on screen - write found character at position X-1 - do this from column 1 to 40 so every character is copied over to the previous position so we get a coarse scroll (no soft scroll on MSX2 unfortunately)
- read data table (or string would work too I guess) with offset - write new character at location on column 40
- start from the top for looping scroller.

(Someone will probably reply 'YOUR DOIN IT WRONG' please do! Wink)

All of this translates rather well to MSX's powerful BASIC, EXCEPT I can't for the life of me figure out how to READ a character on screen. It's probably possible using VPEEK(), but I couldn't figure out WHERE to peek using the BASIC reference manual that I had. It's probably very simple but I can't find it. Sad


Aangemeld of registreer om reacties te plaatsen

Van flyguille

Prophet (3028)

afbeelding van flyguille

11-06-2013, 17:09

If I remember correctly, the character number that represents the cursor is = 255, and always is that value, just happens that its pattern is rendered in realtime as the cursor is moved over the screen. The BIOS must save the real character value in a variable in RAM.

Van flyguille

Prophet (3028)

afbeelding van flyguille

11-06-2013, 17:11

a nice effect, if you print chr$(255), you will see the cursor to get replicated one and again.

Van assembler

Champion (404)

afbeelding van assembler

11-06-2013, 17:51

Depending on which screen mode you're working, the base address will be:
Screen 0: 0
Screen 1: 6144

Address for x,y will be: x+y*(width)+base

In this case width always will be 80 or 40 in screen 0 and 32 in screen 1,regardless of the width set with the basic-command "width".

If you want to read:
-position (0,0) in screen 0 width 80: a=vpeek(0+0*80+0)
-position (15,4) in screen 0 width 40: a=vpeek(15+4*40+0)
-position (12,10) in screen 1: a=vpeek(12+10*32+6144)

But trying to make an scroll this way in basic is going to be very slooooow.

Van BokanoiD

Rookie (27)

afbeelding van BokanoiD

11-06-2013, 20:30

@flyguille: yeah, found that last character as well, but no way to read it in a variable ofcourse.

@assembler: thanks, that sounds like what I needed to know. Smile I know it'll be real slow in BASIC, but I'll see how it'll turn out. Smile

Van flyguille

Prophet (3028)

afbeelding van flyguille

11-06-2013, 22:05

??? you can't read it!, it is the character 255 always because the CURSOR is already PLACED there (so, in the VDP's NAME_TABLE, you will find a chr$(255) but its pattern is a REVERSED COPY of the real charater's pattern that was there BEFORE placing the cursor on it), you needs to find out what character NUMBER is hiding the actual cursor position, looks for that information in a BIOS's variable placed in RAM (over F380h).

Sorry, I can't be more precise with the variable address at RAM, my MSX2 broked several years ago (like 8), since more recent times than that, I am far away from the msx scene, but sometimes I take a round visiting MRC, I am busy as programmer with this, , but I am sure any MSX fanatic can tell you what is the variable address.

Van Manuel

Ascended (18853)

afbeelding van Manuel

11-06-2013, 23:19

You can make it smooth, even in basic, e.g. by using the set adjust registers Tongue

Van Poltergeist

Champion (278)

afbeelding van Poltergeist

12-06-2013, 12:07

For speed you might want to use KunBasic...
I suppose you already know what to put on screen (unless it's random). If that's the case, you might want to look at the Mid$ function. No need for vpeek and vpokes, but just print a part of a string to screen...

@Flyguille: I don't think BokanoiD refers to the hardwarecursor, but uses it more like "the x,y coordinates I'm using now". Otherwise, you are right...

Van flyguille

Prophet (3028)

afbeelding van flyguille

12-06-2013, 13:41

I just replied reading the title of the thread without reading the post. Big smile

Van umaiboux

Resident (43)

afbeelding van umaiboux

12-06-2013, 15:35

110 ' DOWN
120 GOSUB 1000
130 A$=INPUT$(1)
140 FOR I=1 TO 24
150 LOCATE 0,0:PRINT CHR$(&H1B);"L";
160 NEXT
170 ' UP
180 GOSUB 1000
190 A$=INPUT$(1)
200 FOR I=1 TO 24
210 LOCATE 0,0:PRINT CHR$(&H1B);"M";
220 NEXT
230 ' LEFT
240 B$="1     2     3     4     5     6     7     8     9     "
250 A$=INPUT$(1)
260 FOR I=1 TO 15
270 LOCATE 0,0:PRINT MID$(B$,I,39);
280 NEXT
290 ' RIGHT
300 B$="A     B     C     4     5     6     7     8     9     "
310 A$=INPUT$(1)
320 FOR I=15 TO 1 STEP -1
330 LOCATE 0,0:PRINT MID$(B$,I,39);
340 NEXT
999 END
1000 '
1010 FOR I=1 TO 100
1020 LOCATE RND(1)*40,RND(1)*23:PRINT "*";
1030 NEXT