Jump to content

Recommended Posts

Posted (edited)

 

Here is again the French casual coder, but passionate 😊
Who want to participate to NANO COSMOS development ? (CV Basic)

 

For now, I am in stress with the lake of string$ in CVBasic
I would like to generate random name of planets & people

 

In another basic I would have done that :

 

Dim t$(10)

Restore database

For i=1 to 20

Read t$(i)

Next i

'

Planetname$=t$(random(10))+t$(random(10))

Print planetname$

'

Database:

DATA TRAN,TOR,JU,PI,TER,NO,VA,SI,RIUS,SA

DATA NEW,GA,MARS,TI,TAN,NEP,TUNE,PLU,TON,LA

 

No string in CV... How can i do with CV ? (With putting data in ROM)

 

I have a suggession from Nanochess in private :

"You need to use DATA BYTE with strings.

And keep a small 8-bit array to copy strings.

And copy to screen from that 8-bit array."

 

Ok, but I do not unterstand. Who can give me an example ?
You will be in the greetings of my game ;)

 

Thanks

Edited by drfloyd
Link to comment
https://forums.atariage.com/topic/367024-cv-basic-cvbasic-help-for-a-noob/
Share on other sites

Posted (edited)

I don't know how CV BASIC does it, but IntyBASIC has the same shortcomings when it comes to strings. That is kind of funny as people tend to suggest creating text adventures, without them knowing how difficult it is to handle string data.

 

In one of the Intellivision games I'm developing, I have made a structure like this:

 

mystring01: DATA number, "TEXT", 255
mystring02: DATA number,"MORE TEXT",255

 

Then I have another structure:
 

mystrings:
DATA VARPTR mystring01(0)
DATA VARPTR mystring02(0)

 

In the code, I'm using #addr = mystrings(i) + 1 (to skip the first numeric value) and a WHILE loop to plot the string:
 

#where = SCREENADDR(x,y) : REM macro on the Intellivision
WHILE (PEEK(#addr)<>255)
  #data = PEEK(#addr)*8 + BGCOL + FGCOL
  REM The later two are STIC specific, so you don't need them on the ColecoVision
  POKE #where,#data
  #addr = #addr + 1
  #where = #where + 1
WEND

 

I can't PRINT such strings, I have to plot them directly to screen memory. As you see, I'm using an odd data value (255) to indicate end of string. At first I wanted to use 0, but that is SPACE on the Intellivision, meaning my strings could not have spaces.

 

I don't even want to start thinking about keeping strings in RAM, comparing them, concatenating them, dynamically change them and so on. I'm not sure if there is a C compiler better suited for that as well, or if you should not do string heavy programs on a video games console.

Edited by carlsson
  • Like 1

something like this works:

 

t = 0
REM get length of word to print
length = #LOCATIONS(1)
REM get start of word to print
start = #LOCATIONS(0)
REM end of loop is one less than length of the word.
FOR #c = $1800 TO $1800 + length - 1
    REM get ascii value for letter
    t = #WORDS(start)
    REM print the int value read
    print at 320 + start * 32, t
    REM poke the ascii vaule on the screen
    VPOKE #c, t      
    REM increment the point in the word table
    start = start + 1
NEXT #c
REM Same but for next word
  length = #LOCATIONS(3)
  start = #LOCATIONS(2)
FOR #c = $1820 TO $1820 + length - 1
    t = #WORDS(start)
    print at 320 + start * 32, t
    VPOKE #c, t      
    start = start + 1
NEXT #c
REM loop forever
while 1 = 1
wend
REM word list in ascii values
#WORDS:
    DATA  72,69,76,76,79
    DATA  76,69,79
REM location data odd value is where word starts, even value is the length
#LOCATIONS:
    DATA 0,5,5,3    

I made a brief example.

 

	'
	' Example of string building
	'
	' by Oscar Toledo G.
	'
	' Creation date: May/23/2024.
	'

	FOR #c = 4 TO 740 STEP 32

		d = RANDOM(10)
		e = RANDOM(10)

		#d = #c
		c = d
		GOSUB point_to_word
		GOSUB show_word

		c = e
		GOSUB point_to_word
		GOSUB show_word
	NEXT #c

	WHILE 1: WEND

point_to_word:	PROCEDURE
	RESTORE planet_names
	WHILE c
		DO
			READ BYTE f
		LOOP WHILE f <> 0
		c = c - 1
	WEND
	END

show_word:	PROCEDURE
	DO
		READ BYTE f
		IF f THEN VPOKE $1800 + #d, f: #d = #d + 1
	LOOP WHILE f <> 0
	END

planet_names:
	DATA BYTE "TRAN",0
	DATA BYTE "TOR",0
	DATA BYTE "JU",0
	DATA BYTE "PI",0
	DATA BYTE "TER",0
	DATA BYTE "NO",0
	DATA BYTE "VA",0
	DATA BYTE "SI",0
	DATA BYTE "RIUS",0
	DATA BYTE "SA",0
	DATA BYTE "NEW",0
	DATA BYTE "GA",0
	DATA BYTE "MARS",0
	DATA BYTE "TI",0
	DATA BYTE "TAN",0
	DATA BYTE "NEP",0
	DATA BYTE "TUNE",0
	DATA BYTE "PLU",0
	DATA BYTE "TON",0
	DATA BYTE "LA",0

 

Posted (edited)

Hi Nano,
With your example, i have tried to simplify as possible for reading name of people in a table :

 

restore heroes
' **** my choice
hero=5
' ******go to mu choice
for i=1 to hero
do
read byte f
loop while f<>0
next i
m=0
' ******* display
do
	read byte f		
	vpoke $1800+m,f
	m=m+1
loop while f<>0
while 1
wend
' ******** table
heroes:
DATA BYTE 0
DATA BYTE "PETER",0
DATA BYTE "SAM",0
DATA BYTE "TEDDY",0
DATA BYTE "ROGER",0
DATA BYTE "NANOCHESS",0

 

it works.

If a choose 1, it display PETER,

5, it display NANOCHESS

 

(Don't know if it if possible to simplify this code, perhaps)


The only problem is with the display:
at $1800 it's ok, it display at 0,0 
but if i choose $1832 for exemple, to display a column 0, line 1 (in my logic)..... No,  it display at another strange position :
image.thumb.png.b52b9023cab1a1c699f6de4883b66de3.png

 

Do not understand the display position

 

Edited by drfloyd

Each character is a tile , when you print something at one place, you replace the previous tile. 

 

The "transparency"  just means that it is affected by the background or border color.   If you change the border color the part of your text where the color is "0" will become the color you choosed for the border/background.

 

If you chosed color 1 for instance (which is black) , if you change to background color it will stay black.

 

In fact the transparency was here because it was planed a kind of video incrustation capabilities for the VDP  ,  if you choosed a color 0  and if you send a video source from a VHS for instance , you would have seen the VHS video every where the color is "0".   

 

 

  • Like 1
24 minutes ago, drfloyd said:


Other question :
image.png.2ebad4616ecaa4d344a4fd0e5a42dbab.png

 

Why i have only a total of 781 bytes ?

There are several things that the Z80 should care about while your game runs.

 

Subtract the following work data from the original 1024 bytes of RAM:

  • 64 bytes for stack (GOSUB/RETURN/video interrupt)
  • 33 bytes for music player.
  • 146 bytes for support variables (128 are the sprite table).
15 minutes ago, drfloyd said:

ok, thanks

 

it's a un new difficulty for my game, but I beleive in my project, even with 781 octets ! :)

 

781 bytes it is huge ,  it is more than 6 times what you would have if you are doing your game on a Atari VCS. 😃   

 

And if you really don't have enough RAM , you can have still the possibility to use the free VDP RAM to store your variables.  (using VPOKE and VPEEK i think in CVBasic)

  • Like 1
1 hour ago, drfloyd said:

I heard about free VRAM....

Is is really free RAM ? If a remember if about 3 or 4Kb ???
Is it slow ? (no very important for me, as it is not an action game)

 

Perhaps could be interesting.... if someone give an example

 

In the normal mode you have 1K of VRAM free between $1c00 and $1fff. You can access it using VPOKE and VPEEK.

  • 3 weeks later...
Posted (edited)

Another (stupid) question ?

 

How can a make variables as constants ? (in oder to not use RAM)

Exemple :

 

dim dmo(10)
restore liste

for i=1 to 10
 read dmo(i)
next i

liste:
data 5,7,8,5,4,7,8,9,8,7

 

I want dmo(10) do not use RAM, as values are fixed.
 

Edited by drfloyd
1 hour ago, drfloyd said:

cannot understand, could you please give me an exemple ?

FOR a = 1 TO 5

	PRINT 32 + a * 32, <>liste(a)

NEXT a

WHILE 1: WEND

	' Must be DATA BYTE because the label name doesn't start with #
liste:	DATA BYTE 1,2,3,4,5

 

Any label is ready to be read as an array.

 

  • Like 1

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...