English Amiga Board


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

 
 
Thread Tools
Old 08 June 2018, 22:13   #1
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 36
Posts: 3,437
Best way to write stuff on screen

So, in a game many times you need to write stuff on screen like score, number of lives, ammo left, speed of a car, distance to a goal, bombs to be defused, etc.

What's the fastest way to write stuff on screen?

On Quasarius I write score everytime the score changes using a simple Print command on a 1 bitplane bitmap (and use the Copper to change the color of the font so it looks nicer). This was actually slower than I first thought... I guess Blitz probaly changes each digit for a string and then blit each one as a normal Blit command. I've read somewhere that string commands are very slow on Bitz too... though all of this is just a wild guess.

On Roadtrip I made 16x16 digits with just 1 bitplane (Again, using copper to add color to them), and then I "block" (fast blit) one digit per frame. Because the score is basically all the time rising very fast and you don't stop to look at the score too much, you don't notice the score change each digit per frame (At least I hope so ), instead of the whole number at once. This was actually very fast, but besides not changing the whole value at once, you also have to cope with huge digits (16x16 is kinda big, and with Block you can't do anything smaller than 16 pixels wide)

On Roadtrip I also draw speed and time on screen, and that was made using 16x16 sprites. Maybe I could use 8x8 sprites and this would be good too for smaller characters on screen, but 16x16 worked well for Roadtrip. Problem is, Roadtrip was coded in a way I could use sprites there, but that may not always be an option.You still have to convert the score variable (usually a LONG) to String, which isn't very fast (But I can't think of any other way to do it)


Anyone has any other good ideas?


It really feels so weird to have to BLIT on a bitmap to be able to show info on screen, but I don't think there's any other way to do it on Amiga, I'd guess. When I used to code on MSX I could just write text to screen with ease, since the best screen mode for games was a hybrid mode of graphics and text (And you had something that looked like a Tile mode and sprites... ) On Amiga all you have is a big bitmap and a slow blitter to manipulate it
Shatterhand is offline  
Old 08 June 2018, 23:57   #2
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
The blitter is faster than copying with the CPU.

Draw the characters 0-9 as Shapes and blit them as needed. If you store the score as an array of binary coded decimal, you can look at the digits one at a time to determine each decimal characters to display. The 68000 supports BCD natively but you probably have to use asm directly.

From the 68000 data sheet. Dunno how to transform it to blitz
Code:
 
LEA Number1,A0 A0 points at first string
LEA Number2,A1 A1 points at second string
MOVE #8,D0 Nine digits to add
MOVE #$04,CCR Clear X-bit and Z-bit of the CCR
LOOP ABCD -(A0),-(A1) Add a pair of digits
DBRA D0,LOOP Repeat until 9 digits added
E-Penguin is offline  
Old 09 June 2018, 00:07   #3
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 36
Posts: 3,437
I see ASM I have a headache. I am nearly sure Bliting a 16 pixels wide shape is faster than blitting 2 8 pixels wide shape, and this is something to consider.

I have no idea of how to store the score as an array of binary coded decimal, but I can see how faster this would make the whole thing.. not having to convert stuff to String would be great. But I have no idea of how to do it.
Shatterhand is offline  
Old 09 June 2018, 00:30   #4
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
This gets very deep very quickly but there's discussion on a fast bcd algorithm vs one that's table based. In both cases you give it a binary number and out pops a set of decimal numbers.

http://eab.abime.net/showthread.php?t=54585

The table approach seems to be faster but requires a fair amount of memory. Personally I'd try to get bcd working as it seems a nice compromise. I'll have a go tomorrow night.
E-Penguin is offline  
Old 09 June 2018, 00:33   #5
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
Quote:
Originally Posted by Shatterhand View Post
I am nearly sure Bliting a 16 pixels wide shape is faster than blitting 2 8 pixels wide shape, and this is something to consider.
You could store digit pairs and blit two at a time. You'd need 100 shapes (00 - 99) so starts to eat precious chip memory.
E-Penguin is offline  
Old 09 June 2018, 00:37   #6
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 36
Posts: 3,437
Quote:
Originally Posted by E-Penguin View Post
You'd need 100 shapes (00 - 99) so starts to eat precious chip memory.
Yes, that's the problem.

I must admit the more I use Blitz Basic, the more it feels really limited without resorting to ASM anyway. I am still baffled at the low performance while testing collisions (as we discussed on the other thread)... sometimes I wonder if is the Amiga really that unpowered or is just Blitz not fast enough to do anything more than... Skidmarks
Shatterhand is offline  
Old 09 June 2018, 00:51   #7
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
You can wrap up asm as statements or functions though and hide away the scary bits.
E-Penguin is offline  
Old 09 June 2018, 01:06   #8
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
Quote:
Originally Posted by E-Penguin View Post
You could store digit pairs and blit two at a time. You'd need 100 shapes (00 - 99) so starts to eat precious chip memory.
I'm a fool - blit 16-pixel wide bobs with the right hand 8 pixels set to colour 0, the transparent one. Only blit characters which have changed that frame.
E-Penguin is offline  
Old 09 June 2018, 01:41   #9
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 36
Posts: 3,437
Quote:
Originally Posted by E-Penguin View Post
I'm a fool - blit 16-pixel wide bobs with the right hand 8 pixels set to colour 0, the transparent one. Only blit characters which have changed that frame.
But the next digit will have an 8 pixel gap before it. I mean, it can work, but it may look kinda silly
Shatterhand is offline  
Old 09 June 2018, 02:31   #10
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,446
You can blit 16 pixel wide bobs at 8 pixel intervals, if the second 8 pixels are colour 0, they're transparent for normal blitting.
Daedalus is offline  
Old 09 June 2018, 03:15   #11
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,929
"Block" is the fastest blit, but limits you to multiples of 16 pixels.
I don't know if the ExcessOnOff parameter for Blit saves you any cycles, but you could try that out.
There is also the FNS library which has its own text output routines.
idrougge is offline  
Old 09 June 2018, 03:35   #12
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 36
Posts: 3,437
Quote:
Originally Posted by E-Penguin View Post
You can wrap up asm as statements or functions though and hide away the scary bits.
I know bananas about ASM.... I saw x86 asm at college, and all I did was add some values from a register and store them on another register, nothing else. Everytime I see ASM I just get scared and I have no idea of what to do with it

Quote:
There is also the FNS library which has its own text output routines.
Have to check this out. Must admit I have never used any libraries with Blitz, and there are lots of interesting stuff out there to discover.
Shatterhand is offline  
Old 09 June 2018, 12:24   #13
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 547
Quote:
Originally Posted by idrougge View Post
There is also the FNS library which has its own text output routines.
I found the font editor and example fonts in BUM09, but not the actual FNS library, where can it be found? I can't see it in my otherlibs folder.

Do you happen to have a good collection of libraries for BB2 you could share?
MickGyver is offline  
Old 11 June 2018, 00:07   #14
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,929
I think the FNS library should be preinstalled into deflibs if you run the Blitz version from the Ultimate Blitz CD. At least it is on my installation and I can't remember installing it. Otherwise, it should be part of the Blitz support suite.

Last edited by idrougge; 11 June 2018 at 00:14.
idrougge is offline  
Old 16 June 2018, 15:00   #15
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
I've been trying to get bcd arithmetic working but it seems to cause a guru. It looks as if the address registers are being messed up, although I'm using pure asm in a statement. Does anyone know if the blitz debugger adds padding to variables? I wonder whether the address loaded is wrong
Code:
 
lea score(pc), a0

...
score: dc.l $01234567
(a0) never seems to contain what I think it should.

Any asm-in-blitz experts?
E-Penguin is offline  
Old 16 June 2018, 16:27   #16
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,929
Try ?score to access the score label.

Do not touch A4 or above, and end the statement with AsmExit.
idrougge is offline  
Old 16 July 2019, 17:28   #17
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
I'm determined to get BCD arithmetic working. So I've written a blitz library. It compile but again crashes the amiga (in WinUAE at least).

I'm using the example given in the m68k handbook, plus a bit of fiddling to get the address into the right registers.

Code:
#LIBNUM = 50
!libheader {#LIBNUM,0,0,0,0}

!astatement
!args {#long, #long, #byte}
!libs
!subs {_AddBCD,0,0}
!name {"AddBCD","Num1,Num2,Size"}

!libfin

_AddBCD:
  MOVE.l d0,a0 ; num1 in d0 to a0
  ADDA d2,a0  ;  increment a0 by the length of the string
  MOVE.l d1,a1 ; num2 in d1 to a1
  ADDA d2,a1  ; increment a1 by the length of the string
  SUBI #1, d2 ; decrement the string length

  MOVE #$04,CCR ; clear the flags
_AddBCD_loop:
  ABCD -(A0),-(A1) ; predecrement addresses, A0 = A0 + A1
  DBRA D2, _AddBCD_loop ; decrement loop counter and go again if not zero
RTS
I expect this to start at the "end" of a string of bytes and work its way down, adding up as it goes.

Code:
Dim va.b(4)
Dim vb.b(4)

AddBCD &va(0), &vb(0), 4 ; address of va(0), address of vb(0), 4 bytes to process
What am I doing wrong?
E-Penguin is offline  
Old 16 July 2019, 18:46   #18
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 174
> !args {#long, #long, #byte}
I presume this means that arguments in d0/d1/d2 are LW/LW/B.
In that case add d2,<anything> has a good chance of not working. There's no size specified and most assemblers default to .w. Furthermore, adda doesn't work with .b, only .w/.l. And then, DBcc works only with .w.
So anything non-zero in d2 bits 8-15 will cause problems.

Personal rant, nothing against you ;P, since it's relevant: I never understood why people don't supply size, if there is more than one option, and rely on default, which can backfire if you compile with a different assembler; also never understood why to supply size when there's only one option, e.g. moveq.l.

> move #4,ccr
This is not needed since sub #1,d2 will clear all relevant flags (=> x) unless d2 is 0, in which case the code won't work properly anyway (it will repeat the look 64K times, which I think is not intended). This doesn't include other potential byte/word problems with DBcc.

I'd change args to long/long/word and then use something like this:
Code:
  move.l d0,a0
  adda.w d2,a0
  move.l d1,a1
  adda.w d2,a1
  subq.w #1,d2
  bcs.b done  ; d2 was 0
;  blo.b done  ; this alias works too, whichever you or blitz prefers (unsigned)
;  blt.b done  ; or if you want max. 32KB long strings (signed)
loop:
  abcd -(a0),-(a1)
  dbf d2,loop
done:
  rts
Almost forgot, never used blitz so I can't really help with that part.
a/b is offline  
Old 16 July 2019, 19:17   #19
ross
Per aspera ad astra

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 49
Posts: 2,425
Just a little addition to a/b post (that is completely right).

Maybe your source specify this instruction:
MOVE #$04,CCR ; clear the flags

because
ABCD
can use the
Z
flag for successful test for zero results in multiple-precision operations
(Z is cleared only if the result is non-zero, unchanged otherwise).

With #$04 in CCR you set X=0 (so no carry added in first ADD) and Z=1 (so if all multiple operations leave Z as is, you are sure that all partials are zero).

A hint, there is a better (and faster) way without resorting to use MOVE to CCR:
sub.w d0,d0
ross is offline  
Old 16 July 2019, 20:10   #20
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 871
Thanks. I built that and still got weird crashes. So I found a disassembler and went to town. It looks to me like blitz is putting the wrong address register in the ABCD instruction:

Code:
LAB_0000:
	MOVEA.L	D0,A0
	ADDA.W	D2,A0
	MOVEA.L	D1,A1
	ADDA.W	D2,A1
	SUBQ.W	#1,D2
	BCS.W	LAB_0002
LAB_0001:
	ABCD	-(A5),-(A0)
	DBF	D2,LAB_0001
LAB_0002:
	RTS
	MOVEQ	#0,D0
	RTS
	END
a5 is supposed to be restored at the end of a library call so this does explain the weird behavior.

So, I swapped A5 for A0, and re-built the lib using vasm.

Unfortunately blitz now doesn't recognize the library.

I'll keep trying!
E-Penguin 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
Smooth H-scrolling platform game in AMOS, screen copy vs screen offset? Damiga Coders. AMOS 30 19 March 2015 19:06
Amiga 600 not booting... Yellow screen, and Red screen when turning PSU off jbenam support.Hardware 34 20 March 2011 23:10
Stuff for sale amiga a1200 plus more retro stuff blast MarketPlace 23 22 June 2010 20:05
I've got some Amiga stuff...I want your SNES stuff! Fingerlickin_B MarketPlace 14 20 February 2009 02:33
Amiga stuff for trade for Atari Stuff 8bitguy1 MarketPlace 0 12 February 2009 06:36

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 04:23.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.09099 seconds with 13 queries