English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 01 February 2022, 13:50   #261
Nightshft
Registered User
 
Nightshft's Avatar
 
Join Date: Mar 2018
Location: Austria
Posts: 617
Tried it. Works super fine. Thanks a lot Rob!
Nightshft is offline  
Old 09 February 2022, 21:20   #262
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
Quote:
Originally Posted by Stejjie View Post
How do you get text to wrap in a window you've opened, rather than have it "fall off" the edge? I'm sure I used to know, but can't remember for the life of me!
There's an OS call to get the length of a string, in pixels, if printed to a given RastPort. You could use it to implement wrapping by testing whether the line would fit in the window or whether it needs to be split.

http://amigadev.elowar.com/read/ADCD.../node0485.html
E-Penguin is offline  
Old 30 May 2024, 12:38   #263
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Hi everyone ! A couple of noobs questions !

1) Regarding UsePath
- does it make the code any faster or is that just to save the coder time ? I thought the latter was pretty obvious but I read the former somewhere in a Blitz guide...

- can I use it with a complex expression, like the following one in which Enemy is a list of newtypes and chord is a newtype ? Doesn't seem to work.

UsePath Enemy()\chord

The program runs but the value returned is incorrect.

- is it possible to "reset" UsePath ?

2) A more general question when using lists, newtypes etc... Is it possible / useful / advised to optimize by reducing the number of sub-levels ? I guess each indirection level is cpu cycles consuming ? (not sure indirection is the right English term)

3) Regarding the TED editor
- Sometimes I have to write a line of code which exceeded the max number of allowed characters. Is it possible to split a line of code into several lines ?

4) Updating text
- Playing with FNS library to display bitmap fonts. I guess, in order to update some text at a given position, I should blit a black rectangle over the already existing text ? Is there a faster way ? Or maybe I should use Shapes or Sprites (in which case, maybe the FNS lib is not the solution ?!)

5) CLS
I get the message "command only available from the Amiga mode" when using this command from a Statement. BUT this is invoked from my main game loop which is in Blitz mode. And if I call CLS from the main loop, it works ?!
Alternatively : how am I supposed to clear the bitmap in Blitz mode then ?

Thanks everyone :-)

Last edited by mahen; 30 May 2024 at 13:17.
mahen is offline  
Old 30 May 2024, 21:52   #264
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,377
Quote:
Originally Posted by mahen View Post
Hi everyone ! A couple of noobs questions !

1) Regarding UsePath
- does it make the code any faster or is that just to save the coder time ? I thought the latter was pretty obvious but I read the former somewhere in a Blitz guide...
I haven't benchmarked it, but I expect it's just a compiler directive that makes the code quicker to write but doesn't make a difference to the executable.

Quote:
- can I use it with a complex expression, like the following one in which Enemy is a list of newtypes and chord is a newtype ? Doesn't seem to work.

UsePath Enemy()\chord

The program runs but the value returned is incorrect.
Yes, this should work. I've done this in AmiBlitz 3 anyway without issues. It's possible that Blitz 2 has a bug in that area though... Are you sure you're still using the backslash to reference the field?

Code:
UsePath Enemy()\chord

NPrint \x

Quote:
- is it possible to "reset" UsePath ?
Yes, sort of. the UseLastPath command will step the current path back to the previous path used. I'm not sure if it works to get rid of the first path set entirely, but that doesn't really make sense to do anyway.

Quote:
2) A more general question when using lists, newtypes etc... Is it possible / useful / advised to optimize by reducing the number of sub-levels ? I guess each indirection level is cpu cycles consuming ? (not sure indirection is the right English term)
In general, yes, traversing more levels will take more CPU time. Whether that makes a big difference depends on how tight you are for CPU cycles in your main loop. If you're accessing particular sublevels a lot in a short space in time, perhaps using a pointer to them would make sense.

Quote:
3) Regarding the TED editor
- Sometimes I have to write a line of code which exceeded the max number of allowed characters. Is it possible to split a line of code into several lines ?
Are you using the original TED editor? Switch to SuperTED, which allows longer lines I think. Even if it doesn't, it's a much better editor. AmiBlitz 3 allows lines to be split across multiple lines by using special characters to tell the compiler to combine lines, though I might suggest that there's most likely a way of making the line shorter within the constraints of Blitz too.

Quote:
4) Updating text
- Playing with FNS library to display bitmap fonts. I guess, in order to update some text at a given position, I should blit a black rectangle over the already existing text ? Is there a faster way ? Or maybe I should use Shapes or Sprites (in which case, maybe the FNS lib is not the solution ?!)
That's probably the quickest way alright, and as far as I know, there's no way to automatically draw the background. With the standard Print command you can set a jammode to blank the background, but the standard Print system comes with its own limitations.

Quote:
5) CLS
I get the message "command only available from the Amiga mode" when using this command from a Statement. BUT this is invoked from my main game loop which is in Blitz mode. And if I call CLS from the main loop, it works ?!
Ah yes, this is a funny one. What's happening is that the Blitz or Amiga mode is applied by the compiler based on where they are in the listing itself, not the program flow when running. So if your program flow jumps in and out of a section in Blitz mode (e.g. using Gosub or a procedure), you can hit against this error. You need to position the Blitz and Amiga commands in such a way that code is always in the desired mode, both in terms of program flow and the code listing.

Quote:
Alternatively : how am I supposed to clear the bitmap in Blitz mode then ?
You can draw a giant rectangle in colour 0. From memory, there are also issues with CLS in certain circumstances and I think I used this method as an alternative to using CLS.
Daedalus is online now  
Old 31 May 2024, 08:45   #265
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Daedalus : wow, that was extremely helpful ! THANK YOU !

Quote:
Originally Posted by Daedalus View Post
Are you sure you're still using the backslash to reference the field?
Code:
UsePath Enemy()\chord NPrint \x
Oh my. Nope ! For a silly reason : the Blitz2_guide I use (found on Aminet) which contains the documentation in Amiga Guide format is not displayed properly and all backslashes are missing...

I have to check whether it's an issue in the .guide or in the Multiview / datatypes provided with OS 3.2.x.

Quote:
If you're accessing particular sublevels a lot in a short space in time, perhaps using a pointer to them would make sense.
OK ! I have to check how to use pointers in Blitz then.

Also, I think I'll optimize by pre-computing some calculations involving * and / at the relevant time. More memory used but faster code. In general, I should look for a way to profile my code.

Quote:
Are you using the original TED editor? Switch to SuperTED, which allows longer lines I think. Even if it doesn't, it's a much better editor. AmiBlitz 3 allows lines to be split across multiple lines by using special characters to tell the compiler to combine lines, though I might suggest that there's most likely a way of making the line shorter within the constraints of Blitz too.
Yep, using SuperTED 2.52. I like it, it's very fast on my machine. And I figured out there were some nice goodies which were not enabled by default, like the debugger (man, I spent hours pin-pointing issues which I would have found instantly !).
Quote:
You need to position the Blitz and Amiga commands in such a way that code is always in the desired mode, both in terms of program flow and the code listing.
Ohhhhh ! Okay that kinda makes sense. A given procedure could be theorically invoked from different parts of the code which could be in different modes... I guess the compiler could check that but well, no big deal
Quote:
You can draw a giant rectangle in colour 0. From memory, there are also issues with CLS in certain circumstances and I think I used this method as an alternative to using CLS.
Thank you, I'll try that ! I should look up some double-buffer examples.

Thank you again so much for your help. There more I tinker with Blitz 2 the more I think I would have been a HUGE fan of it back in the days. I only had AmigaBasic.

BTW I quickly gave AmiBlitz 3 a try, but I guess my machine being on the lower end side, it's not optimal. (030@50)

Last edited by mahen; 31 May 2024 at 08:50.
mahen is offline  
Old 31 May 2024, 10:39   #266
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,377
Quote:
Originally Posted by mahen View Post
Oh my. Nope ! For a silly reason : the Blitz2_guide I use (found on Aminet) which contains the documentation in Amiga Guide format is not displayed properly and all backslashes are missing...

I have to check whether it's an issue in the .guide or in the Multiview / datatypes provided with OS 3.2.x.
That's an issue with versions of the AmigaGuide datatype from OS 3.0 on unfortunately. Backslashes need to be escaped with a second backslash to be displayed properly, but then you get double backslashes when viewed on OS2. I guess that version is just pretty old. It might be worth digging the version out that's included in AmiBlitz 3... Some things will be changed but 99% is the same, and AFAIK all the formatting is fixed.

Quote:
OK ! I have to check how to use pointers in Blitz then.
If you've used them in another language it should be pretty straightforward

Quote:
Also, I think I'll optimize by pre-computing some calculations involving * and / at the relevant time. More memory used but faster code. In general, I should look for a way to profile my code.
There are a few techniques that can be used, most of which aren't Blitz-specific, such as poking background colours for fractions of a frame, counting frames with an interrupt for longer things, or setting up a timer.

Quote:
Ohhhhh ! Okay that kinda makes sense. A given procedure could be theorically invoked from different parts of the code which could be in different modes... I guess the compiler could check that but well, no big deal
Yeah, the compiler is a bit primitive in that regard and only works from top to bottom. It affects compiler directives and other things too, like how procedures having to be defined before they're called.

Quote:
BTW I quickly gave AmiBlitz 3 a try, but I guess my machine being on the lower end side, it's not optimal. (030@50)
Ah, yes, it will be a little sluggish then. You've probably got the optimal installation now then.
Daedalus is online now  
Old 31 May 2024, 13:27   #267
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Hi ! I'm a bit lost regarding the pointers...
I could find very little information about them actually.

In the BB manual, there is only this :
Quote:
Using Pointers
When doing many operations on a particular subfield in a NewType a temporary pointer
variable of the same subfield type can be created and that used instead of the larger (and
slower) path name:
UsePath a(i)\alien\pos
replaced by:
UsePath *a
*a.pos=a(i)\alien
What I'm trying to achieve is this (because given my current code there are slowdowns induced by a specific area) :

I have a list of the Enemy newtype.
This newtype contains a look-up table initialized when it's created. (an array) called precalcSat which contains intermediate RGB values. (in this test, 1 enemy = a copper bar of variable size and colour)

Instead of invoking the following from my main loop :
Enemies()\precalcSat[i]
I'd like to use a pointer to the beginning of the precalcSat array.
I tried :
*pt = Enemis()\precalcSat[0]
and tried accessing to pt(i) but to no avail. Tried many different syntaxes.

Thanks a lot

(for some reason using this LUT doesn't speed up the code as much as expected. But it's better when removing those accesses)

Last edited by mahen; 31 May 2024 at 13:32.
mahen is offline  
Old 31 May 2024, 13:41   #268
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,377
So you're creating that pointer outside the main loop? You have to be careful because in a dynamic list array, the elements aren't necessarily contiguous so you can't use pointer arithmetic to jump around. However, the contents of the Newtype should allow that sort of navigation.
Quote:
*pt = Enemis()\precalcSat[0]
and tried accessing to pt(i) but to no avail. Tried many different syntaxes.
Did you pre-declare the pointer elsewhere? What type is it? Your assignment here won't work because it's setting the pointer address to the value of precalcSat[0], which I'm assuming is a byte value?

To get the address of a variable, use the & symbol:

Code:
*pt = &Enemis()\precalcSat[0]

NPrint "Sat value 2: ", peek.b(*pt + 2)
Assuming the array is defined as bytes. The example from the documents uses the root of a Newtype, not an individual entry, which returns the address of that Newtype and so doesn't need the & symbol.

Regarding the LUT speedup, it's indeed possible the problem is memory accesses. What type of variables are you using, and on which CPU? By default Blitz uses "quick" types, which are a fixed-point, 32-bit type, and despite their name are actually quite slow to deal with, especially on the 68000. You're better of using a word type (16-bit integer) for things like array indices and anywhere else that integers work.
Daedalus is online now  
Old 31 May 2024, 13:51   #269
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Hi !

Yep, I use words as the default type !

But if I only plan to use the content of the precalcSat array (which itself is part of a Newtype list), values will be contiguous anyway, so no issue ?

Nope, I didn't pre-declare the pointer. I thought pointers were longs ?

Thank you !

edit : 030@50 setup, btw !

Edit : so I tried this
*pt = Enemies()\precalcSat[0]
And Peek.w(*pt+i)
But it doesn't return the right value... hm...

Last edited by mahen; 31 May 2024 at 14:11.
mahen is offline  
Old 10 June 2024, 11:59   #270
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Hi ! I have new questions :-)

1) When using the dual playfield mode : is it possible to have some kind of "mask" or "window" so that, for instance, the background is only visible in the center of the screen and not in the border ?

(otherwise, the easy solution is just to make sure the foreground has a colour different from 0 so that it gets opaque).

Just asking as I'm aiming at very lightweight 2*1 bit playfields. If I have so sacrifice one colour to add opacity, well, I'll have to switch to 2 bits playfields ;-)


2) Also, another question : is there somewhere an example of "CustomSprites" ? (sprites multiplexing). As usual, the manual is pretty... obscure to me

Last edited by mahen; 10 June 2024 at 12:53.
mahen is offline  
Old 10 June 2024, 17:26   #271
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,377
Sorry, could've sworn I replied to this...

Quote:
Originally Posted by mahen View Post
But if I only plan to use the content of the precalcSat array (which itself is part of a Newtype list), values will be contiguous anyway, so no issue ?
Yes, each instance of the array will be contiguous, just the elements of the lists (so each instance of the array) can move relative to each other.

Quote:
Nope, I didn't pre-declare the pointer. I thought pointers were longs ?
Yep, pointers are longs, but if you want to treat the pointer as if it's the thing it points to (typically a Newtype), you need to declare it as that type. For example, *myscreen.Screen = Screen(...). The address of the Screen struct / Newtype will be a longword but you can access the fields at that address using *myscreen\Width for example.

Quote:
Edit : so I tried this
*pt = Enemies()\precalcSat[0]
And Peek.w(*pt+i)
But it doesn't return the right value... hm...
What's happened there is that you've assigned the value stored in the array element 0 as the address of the pointer. This isn't where the array lives which is what the & symbol does.

Also, if it's an array of words, you need to skip 2 bytes at a time:
Code:
Peek.w(*pt + (i * 2))
Though, as suggested elsewhere, using a left shift there will be faster than a multiply (if slightly harder to follow):
Code:
Peek.w(*pt + (i LSL 1))
Quote:
Originally Posted by mahen View Post
1) When using the dual playfield mode : is it possible to have some kind of "mask" or "window" so that, for instance, the background is only visible in the center of the screen and not in the border ?
Hmmm, I don't know. It might be possible by fidding with some low-level stuff, but there isn't a simple way to do it in Blitz as far as I know.

Quote:
(otherwise, the easy solution is just to make sure the foreground has a colour different from 0 so that it gets opaque).
This is probably how I would do it.

Quote:
2) Also, another question : is there somewhere an example of "CustomSprites" ? (sprites multiplexing). As usual, the manual is pretty... obscure to me
I don't have an example to hand, but from memory it's simple enough. The manual is particularly weak in this are, though the basic info is there once you get used to the quirks of how it was written. Essentially what you need to do is reserve the space needed when you declare the display using InitCopList. For Custom... commands, you add positive values for this space.

The manual lists (4 x numsprites + 2) as the amount of space needed, so for 8 sprites it should be 4 x 8 + 2, which is 34. Use this value with InitCoplist. If you have any other custom copper commands, you'll need to calculate their offsets on the coplist, but for simplicity just use one to start with.

Once that's done, you declare your sprite break Y position with CustomSprites. The CCOffset is to accommodate other Custom... commands, so leave that at 0. Then you should be able to use a second set of sprite channels numbered 8-15 in the area below the declared Y position.
Daedalus is online now  
Old 11 June 2024, 11:16   #272
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Thank you so much for the replies !!

I have yet another issue :-) with dual playfields.
I have 2*2 bits bitmaps, and hence, a 8 colours copperlist.

I understood the first 4 colours of the palette were for the "back playfield" and the following 4 for the "front playfield".

I can indeed use AGAPalRGB to define the first 4 correctly.
However, altering colours 4-7 of my palette make no difference at all to the front playfield. For instance, I blit some aliens in the foreground, and they always appear in a kind of dark blue which does NOT belong to the palette at all.

Any idea ?

(out of curiosity, I tried to swap the playfields, and, obviously, it has the same consequences : I cannot alter the values of the front playfield - which used to be the back one).

BTW, when invoking DisplayBitmap I specify the foreground, then the background. I have probably overlooked something obvious

I have read somewhere there could be an offset of 16. Tried that to no avail.

EDIT : anyway, it's not good. Because actually it appears that, DisplayBitmap must be invoked with the background THEN the foreground (which is not what I read in the manual).
So... The first colours of my palette would be for the foreground. Which is not what I had read... Sigh ! In both cases, I cannot alter the colours of the other playfield so the problem remains.

Last edited by mahen; 11 June 2024 at 11:31.
mahen is offline  
Old 11 June 2024, 12:01   #273
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Stumbled upon this : https://eab.abime.net/showthread.php?t=104666
Which probably answers my issues.

"you need to bear in mind that the palettes will overlap by default, since AGA defaults to OCS/ECS compatibility mode. This means that the palette for the second playfield starts at 8, not 16, so your first picture will use pens 0-15, the second will use pens 8-23. Use DisplayControls to adjust BPLCON3 (I can't remember the exact bits) to adjust the offset so that the second playfield uses pens 16-31."

I'm not 100% conviced yet, though. As I use 4 colours playfields, the overlap should not be an issue...
Also, it doesn't explain why, for the moment, I can see stuff in a dark blue which does NOT belong to my palette (I tried to set the whole palette to white to make sure), or why for fore/background seem to be inverted.
mahen is offline  
Old 11 June 2024, 13:35   #274
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,377
Yeah, I think the foreground and background are mixed up in the manual. What you need to keep in mind is that the offset doesn't care about how many bitplanes you use - it's always 8. So in your case, where you have colours 0-3 for your first field, the second field will use colours 8-12, leaving colours 4-7 doing nothing. Sprite colours then are offset to 16.

When you set up your display and your palette, you need to take this into account - specify 16 colours even if you're only using 2+2 bitplanes so that the entries in the palette are available to you.
Daedalus is online now  
Old 11 June 2024, 14:04   #275
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Thanks !
Hmm...

Still no luck. Then I "upgraded" my CopList to 16 colours instead of 8 and... The background which used to be invisible suddenly showed the right colours. Even though I have 2 2 bits bitmaps...

Is 8+8 colours dual playfield illegal ? Mysterious stuff !
mahen is offline  
Old 11 June 2024, 14:08   #276
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,377
Yeah, that's the expected behaviour. Sorry, I should have been clearer - both the palette and the display (which means the Coplist declaration) need to have enough colours to cover the palette entries you need, regardless of bitplanes used. You'll need to set both to 32 colours to use sprites, for example, because they use palette entries 16-31.
Daedalus is online now  
Old 11 June 2024, 14:11   #277
mahen
Registered User
 
Join Date: Apr 2008
Location: France
Age: 41
Posts: 467
Ah, okay, it makes sense then ! I guess that won't make me lose the benefit of having lightweight bitmaps (2 bitplanes) in terms of speed of blitting & memory !

thanks again
mahen is offline  
Old 13 June 2024, 02:13   #278
Cobe
Registered User
 
Join Date: Jan 2014
Location: Belgrade / Serbia
Age: 41
Posts: 1,008
Quote:
Originally Posted by mahen View Post
1) When using the dual playfield mode : is it possible to have some kind of "mask" or "window" so that, for instance, the background is only visible in the center of the screen and not in the border ?

(otherwise, the easy solution is just to make sure the foreground has a colour different from 0 so that it gets opaque).

Just asking as I'm aiming at very lightweight 2*1 bit playfields. If I have so sacrifice one colour to add opacity, well, I'll have to switch to 2 bits playfields
Mask/window no.. But
If by a center and not in the boder you mean exactly not smaller than other playfiled you could poke bplcon3 border balnk.
Cobe is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
[blitz basic] How much amiga-blitz friendly is this? saimon69 Coders. Blitz Basic 105 21 April 2022 19:45
Blitz Basic (1) Retro1234 Coders. Blitz Basic 9 18 February 2016 17:54
Blitz basic 2 Help Havie Coders. Blitz Basic 30 08 September 2013 09:15
Blitz Basic 2 anyone? jobro request.Apps 12 28 November 2005 18:15
Blitz Basic 2 LaundroMat Retrogaming General Discussion 5 24 July 2001 08:10

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:13.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.18448 seconds with 14 queries