gtBASIC

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

It was an absolute art-form back in the day, something that doesn't happen much anymore, (except in embedded or tiny-demo programming).

The next release will have compressed, scrollable and screen to screen blits which should help a lot in this area.
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

Well, All levels coded, all AI coded, Mario's death animation done, 90% of collision coding done. Just a little scoring code and Kong's death animation left.

BUT I only have 1006 bytes available.

More efficiency searching needed.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

There's some low hanging fruit that you can try:

1) DIM statements will create 16bit word arrays by default, if your array only needs values between 0-255 then use the % modifier on the variable name to create 8bit byte arrays.

2) If you have an array of strings and the array is constant, i.e. read only, then use the CONST modifier on the array, this will substantially reduce the size of the string array.

3) If you reference the same read only string in multiple places, always use the CONST modifier, this will collapse all instances of that string to just one physical memory copy.

4) If you're not using any of the string functions, such as LEFT$ MID$ etc, then use the pragma 'free STRINGWORKAREA', this will save 2*96 byte offscreen segments.

5) If any of your sprites or blits reference the same image data, then make sure you LOAD them from one singular place, that way image data will be stored as just one physical copy. All this means is, don't duplicate an image by copying it into a different folder or giving it a different name, the compiler is smart enough to collapse instances of the same image data as long as the folder/file names are not different.

6) Splitting your graphics up into re-usable tiles, (which it sounds like you have already started), is a great way to save memory.

7) Don't be afraid to use GOSUB and CALL, any duplicated code should always be a subroutine.

8) Leverage as much of the runtime as possible, i.e. use as many of the inbuilt gtBASIC commands as possible, it will usually be very difficult to compete with the runtime in terms of speed and especially code size.

9) Use GOSUB <n> or GOTO <n> in a similar way to modern switch statements, this will produce much smaller code than large IF ELSEIF ELSE chains.

10 Use the inbuilt assembler for bespoke code that the runtime does poorly with in terms of efficiency, (e.g. your vines routine in Pitfall I would expect to have been done in assembly).

That's all I can think of now, if you get stuck then send me the source code and I'll find ways to compress it.
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

One thing I have noticed with V0 Basic is that function/subroutine calls that call a 2nd function do not seem to be able to pass through parameters from subroutine 1 to subroutine 2.

In this code the construction of MarioXPos2 and MarioYPos2 fails.

'===============================================================================
' C H E C K I F M A R I O C O L L I D E S W I T H O B J E C T
'===============================================================================

PROC IsMarioCollision, MarioXPos, MarioYPos, ObjectType
LOCAL I, MarioXPos2, MarioYPos2, ObjYPos, ObjYPos2, ObjXPos, ObjXPos2

MarioXPos2 = MarioXPos + 9
MarioYPos2 = MarioYPos + 13

CALL IsObjectCollision, MarioXPos, MarioYPos, MarioXPos2, MarioYPos2, ObjectType

ENDPROC

PROC IsObjectCollision, SourceXPos, SourceYPos, SourceXPos2, SourceYPos2, ObjectType
LOCAL I, ObjYPos, ObjYPos2, ObjXPos, ObjXPos2

ObjectHit = -1

FOR I = 0 TO TableCounts(4) - 1
IF (ObjectType >= 0) AND (ObjectControl(I, 0) <> ObjectType) THEN GOTO SkipCollision

ObjXPos = ObjectControl(I, 1)
ObjXPos2 = ObjectControl(I, 1) + ObjectControl(I, 3)

ObjYPos = ObjectControl(I, 2)
ObjYPos2 = ObjectControl(I, 2) + ObjectControl(I, 4)

IF (ObjXPos < SourceXPos2) AND (ObjXPos2 > SourceXPos) AND (ObjYPos < SourceYPos2) AND (ObjYPos2 > SourceYPos) THEN ObjectHit = I

IF ObjectHit >= 0 THEN I = TableCounts(4)

SkipCollision:
NEXT I

ENDPROC
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

Another issue I am having is I am trying to draw an 24 pixel wide image and it's mirror to form the whole
I have broken the left 24 pixels into 4 images 6 X 25 pixels in size.
I then load the 4 images noflip then the load them again flipx.

When I draw the whole image none of the tiles are flipped

LOAD BLIT, Images/Kong_High_X1.tga, KONG_HIGH1, NoFlip
LOAD BLIT, Images/Kong_High_X2.tga, KONG_HIGH2, NoFlip
LOAD BLIT, Images/Kong_High_X3.tga, KONG_HIGH3, NoFlip
LOAD BLIT, Images/Kong_High_X4.tga, KONG_HIGH4, NoFlip
LOAD BLIT, Images/Kong_High_X4.tga, KONG_HIGH5, FlipX
LOAD BLIT, Images/Kong_High_X3.tga, KONG_HIGH6, FlipX
LOAD BLIT, Images/Kong_High_X2.tga, KONG_HIGH7, FlipX
LOAD BLIT, Images/Kong_High_X1.tga, KONG_HIGH8, FlipX

OK, figured it out. You have to load with FlipX and use FlipX again when displaying.
Post Reply