Jump to content
SteveB

Fast String replace?

Recommended Posts

Hi,

I am thinking of a XB game where I prepare the screen in an array of strings to be displayed using DISPLAY AT or the XB256 DISPLY function (Foreground/Background). What is the best and fastest way to update the strings? I need to be able to overwrite n=len(substr$) characters in a string DL$(i) starting at position p. The size of the DL strings will always remain constant, so no checking is needed. Does anybody has an assembly routine for this? Or can this somehow be done with VREAD/VWRITE more easy? I want to be able to compile the program with JEWEL. 

 

Any hints are appreciated!

 

Steve

Share this post


Link to post
Share on other sites

I don't know if this ever made it out the door as a commercial product but it looks like a match:

 

87:01:05. String Master alpha testing completed
by Richard M. Mitchell
Alpha testing has now been completed for an upcoming Bytemaster software release, String Master. Thepackage is a set of Assembly Language routines, accessible from Extended Basic, that provide macroequivalents of XB functions, thereby greatly reducing program development time and program run time.String Master's speed and practical design provide an environment that is conducive to creativeprogramming.

 

String Master is useful for database applications, program development, text handling, screen windowingand many other applications. Routines are designed to provide optimization of usage of system memory.Over 28 routines are included in the package, with most designed for handling string arrays. Unlike the255-byte limitation of traditional string handling through string variables, many String Master functionsallow string arrays to provide access to string data with the only limitation being available memory.

  • Like 1

Share this post


Link to post
Share on other sites

String Master did make it out into the wild in limited numbers, I think I may even have a copy of it somewhere. I remember that my disk was very strange, as only the portions of the disk with programs on it were actually initialized. . .

  • Like 3

Share this post


Link to post
Share on other sites

Wasn't the code for it released in "The Smart Programmer" after Richard Mitchell took over publication from Craig Miller? I may have a notebook with all of the copies in it.

  • Like 1

Share this post


Link to post
Share on other sites

How fast do you need it to be?

Post 62 I think has a download that will let you move the joystick left and right to select a track.  It updates the entire screen pretty quick.

Until I saw this post, I had forgotten about this project.  I think I got sidetracked trying to figure out how to make the track multi direction scroll for a larger course.

Then dropped the ball on it :(  I guess I have a lot of projects to revisit someday...

 

Well, this is the entire screen...  It kinda looks like you want to loop through a fixed count of chars to layout..   1 row at a time? 

What I am doing is a full row at a time in one per-defined string saved in an data statement.  I have done 5 rows in a data statement as well.

It depends on my needs.  Actually.  I don't remember how many rows I am doing with this?  I lost the laptop that was on... So, thankfully I can download this myself.  Not the latest ver.  but better than nothing!

 

From a quick look at the read statement, looks like I read 6 times to fill the screen. 

I know I have used various ROW at a time sizes depending on content and memory requirements.

Blank rows take 28 bytes, if I have several blank rows, I would rather have more read/data elements.  Data  "","","hello this is a test",""  vs 112 chars.  Like I said, I use what is needed at the time.

 

Edited by 1980gamer
Add info
  • Like 1

Share this post


Link to post
Share on other sites

Check out Yesterday's News - YN_03_10 - post 297.

It contains String Master.

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites
17 hours ago, SteveB said:

Hi,

I am thinking of a XB game where I prepare the screen in an array of strings to be displayed using DISPLAY AT or the XB256 DISPLY function (Foreground/Background). What is the best and fastest way to update the strings? I need to be able to overwrite n=len(substr$) characters in a string DL$(i) starting at position p. The size of the DL strings will always remain constant, so no checking is needed. Does anybody has an assembly routine for this? Or can this somehow be done with VREAD/VWRITE more easy? I want to be able to compile the program with JEWEL. 

 

Any hints are appreciated!

 

Steve

It's not clear to me whether you want to actually change the strings or whether you want to overwrite the string that is displayed on screen.

Share this post


Link to post
Share on other sites

I want to do the first, change some characters in the string, but the second might be a complete different solution I might consider as an alternative.

 

I have a complex background and a large player, 5 chars wide and 7 chars high. I can't use sprites as the player is not solid filled and must not show the background characters shining through. So I thought of preparing 7 strings with the background charachters and then replace 5 in each with my player, depending on the position. Doing this with each line like

DL$(i) = seg$(BG$(i),1,pos-1) & PL$(i) & seg$(BG$(i),pos+5,27-pos)

might be a little slow, even compiled. Changing the character from pos to pos+4 should be somehow faster. But still I would have to initialize the DL$ with the BG$ with every iteration.

 

So the option refresh the part of the screen with VWRITE and then write the player with VWRITE or DISPLAY AT or DISPLY could be more efficient.

 

What do you think?

Share this post


Link to post
Share on other sites

If your background is a static play field, it will be more efficient to just restore the background at the player position, and then draw the player at the new position.  Not sure what the fastest option for getting tiles updated on the screen from XB is, DISPLAY AT maybe?  You could certainly make this very fast with a simple (and very small) assembly routine.

 

Try to avoid reading VRAM.  IMO, VRAM should be thought of as write-only, and keep your game map and data stored in your program.  If there is a way to make sure your game map is in 32K RAM (instead of being stored in VRAM), then that will help with performance.  I don't know how XB uses VRAM when the 32K is installed, but I'm sure someone else here can give the details.

 

I don't recall how Owen's maps were stored for his adventure game (Beryl Reichart (spelling is certainly wrong)), but it was efficient enough to have 4x4 or 8x8 screen pages of map data, plus game code.  If you search back in the form, you can find the thread with the details and the assembly routines (they will need to be modified, but it will be a starting point).

 

You could also layer sprites to mask out the background, i.e. make the player not have transparent parts.  If you don't use sprites for any other reason, a 4-tile wide 2-color player is possible, and it could be up to 6-tiles wide (5 layered sprites on one scan line) with 1-tile on each side being 1-color with transparency (which may be fine for the edges of the player graphic?)

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 10/31/2021 at 12:41 PM, SteveB said:

I want to do the first, change some characters in the string, but the second might be a complete different solution I might consider as an alternative.

 

I have a complex background and a large player, 5 chars wide and 7 chars high. I can't use sprites as the player is not solid filled and must not show the background characters shining through. So I thought of preparing 7 strings with the background charachters and then replace 5 in each with my player, depending on the position. Doing this with each line like


DL$(i) = seg$(BG$(i),1,pos-1) & PL$(i) & seg$(BG$(i),pos+5,27-pos)

might be a little slow, even compiled. Changing the character from pos to pos+4 should be somehow faster. But still I would have to initialize the DL$ with the BG$ with every iteration.

 

So the option refresh the part of the screen with VWRITE and then write the player with VWRITE or DISPLAY AT or DISPLY could be more efficient.

 

What do you think?

Here's a quick stab at doing what you want. CALL LINK("WINDOW") in line 400 lets you select the area where the 5x7 character is printed.

I use a simple background, so CALL VCHAR can be used to fill in the vacated squares. Depending on your requirements, you could make a 224 byte long string that is the background for 7 rows. You could print the background every time, then print the player atop the background.

What might work even better could be to have a 32 element array containing each of the 32 columns. You could move the player and use CALL LINK("DISPLY",ROW,COL,A$(col),32) to print vertically downward to replace your complex background on the 7 vacated squares.

This should work if you are just moving left to right, but it gets tricky if you will be moving up and down as well.

 

10 CALL HCHAR(1,1,46,768)
20 A$="ABCDEabcdeFGHIJfghijKLMNOklmnoPQRST"  
40 FOR C=2 TO 28 :: GOSUB 400 :: CALL VCHAR(1,C-1,46,7):: NEXT C
42 FOR C=27 TO 1 STEP -1 :: GOSUB 400 :: CALL VCHAR(1,C+5,46,7):: NEXT C
50 GOTO 40  
400 CALL LINK("WINDOW",1,C,7,C+4):: CALL LINK("DISPLY",1,C,A$,0):: RETURN  

 

(The video is not compiled).

57PLAYER.GIF.37f5808e826f50ad02cbbffd356c1b56.GIF

 

Edited by senior_falcon
  • Like 7

Share this post


Link to post
Share on other sites

This is great! My background is more complex ... but IIRC CALL LINK("DISPLY" ...) can also write downwards and I can replace the CALL VCHAR to display the complex background.

 

My problem is still that my "player" does not fill the complete square and is not static. So I have to use CALL CHARs and might need to fill empty spots with background chars, all without flicker ...

 

Thank you!

 

Steve

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...