Re: nxtBasic: A New Compiler for Basic Code on the X16
Posted: Tue Jul 16, 2024 10:20 pm
That's close, but upside down. I'm converting it from a C64 2bpp sprite. Looks like it's gonna be easier and better to just redo it from scratch.
That's close, but upside down. I'm converting it from a C64 2bpp sprite. Looks like it's gonna be easier and better to just redo it from scratch.
I see another need. Right now AddSprite loads the sprite image into a specific sprite slot. There is no means to just load a sprite image without also taking up a sprite and no way to change the sprite image. I need to change the image to animate the sprite. For now I'm just going to use "AddSprite" to load each frame into separate sprites and use VPOKE to change the image from frame to frame. It would be nice to build that in. Even cooler would be able to pass a loop of frames, an interval at which to change them, and let an interrupt just cycle the animation until I tell it to stop.
I imagined 'changing' spriteimages would just be hiding and showing sprits, but I guess there is a marrit for changing the image data aswell. A sprite-animation-cycle routine would also be pretty nice I think I'll have a look at that one!I see another need. Right now AddSprite loads the sprite image into a specific sprite slot. There is no means to just load a sprite image without also taking up a sprite and no way to change the sprite image. I need to change the image to animate the sprite. For now I'm just going to use "AddSprite" to load each frame into separate sprites and use VPOKE to change the image from frame to frame. It would be nice to build that in. Even cooler would be able to pass a loop of frames, an interval at which to change them, and let an interrupt just cycle the animation until I tell it to stop.
If I add functions to "basic-functions.s" will they just "magically" become available to the compiler? If so I will take a crack at writing what I want, send it to you, and you can accept it if you like it.
func "SPRITE_SET_IMG(INT,INT,INT)":"SetSpriteMemOffset" ;SPRITE_SET_IMG index,verab-ank,vera-address SetSpriteMemOffset: ;Read vera-address and store it in temp jsr PopBuffer lda WorkBuffer sta temp lda WorkBuffer+1 sta temp+1 ;Read vera-bank and store it in temp2 jsr PopBuffer lda WorkBuffer sta temp ;always only one byte as the value is <256 ;Read sprite index jsr PopBuffer lda WorkBuffer ;This subroutine will set the vera registers to the sprite ;attributes of the spriteindex in 'A' jsr SetVeraToSpriteIndex ;to some bitshifting to compose the address part of the ;image data and use sta VERA_data0 to write it to the sprite ;lattributes rts endfunc:And be aware of the assembly language: I'm using a custom build assembler, do you'll be missing some fancy stuff the well known brands offer. Just check the existing source to see what you can use
unartic wrote: ↑Wed Jul 17, 2024 6:18 amI imagined 'changing' spriteimages would just be hiding and showing sprits, but I guess there is a marrit for changing the image data aswell. A sprite-animation-cycle routine would also be pretty nice I think I'll have a look at that one!I see another need. Right now AddSprite loads the sprite image into a specific sprite slot. There is no means to just load a sprite image without also taking up a sprite and no way to change the sprite image. I need to change the image to animate the sprite. For now I'm just going to use "AddSprite" to load each frame into separate sprites and use VPOKE to change the image from frame to frame. It would be nice to build that in. Even cooler would be able to pass a loop of frames, an interval at which to change them, and let an interrupt just cycle the animation until I tell it to stop.
If I add functions to "basic-functions.s" will they just "magically" become available to the compiler? If so I will take a crack at writing what I want, send it to you, and you can accept it if you like it.
Yes, everything you add to basc-functions.s will become available to you on the basic-side. I'm planning to actualy add a second file (like user-def.s) in which anyone can add their own basic functions to keep them seperate from the files that are updates by new releases. I haven'd documented this part yet, but here are some things to note:
Syntax is like this:
func "BASICNAME(ARGTYPES) as RETURNTYPE":"ASMLABEL"
ASMLABEL:
;do you asm stuff here
rts
endfunc:
- BASICNAME: this is the function/statement name you'll use on the basic side
- Arg types: can be any list of variable types, seperated by a komma. Values can be: STRING INT or FLOAT (if you'll check you will see optional parameter support and support for more then one type per argument. For now I would keep away from it)
- If you want to return something you add 'AS' and then the type, like: AS STRING
Reading arguments:
- Arguments are read in reverse order.
Call jsr PopBuffer to read an argument. It will bestored in 'WorkBuffer' (1024 byte buffer)
The length will be returned in WorkBufferLen (2 bytes)
The type will be returned in WorkBufferType (1=int, 2=string, 3=float)
For returning you have to setup WorkBuffer, WorkBufferLen and WorkBufferType and call: jsr PushBuffer
So for changing the image data offset of a sprite index, it could look like this:
func "SPRITE_SET_IMG(INT,INT,INT)":"SetSpriteMemOffset" ;SPRITE_SET_IMG index,verab-ank,vera-address SetSpriteMemOffset: ;Read vera-address and store it in temp jsr PopBuffer lda WorkBuffer sta temp lda WorkBuffer+1 sta temp+1 ;Read vera-bank and store it in temp2 jsr PopBuffer lda WorkBuffer sta temp ;always only one byte as the value is <256 ;Read sprite index jsr PopBuffer lda WorkBuffer ;This subroutine will set the vera registers to the sprite ;attributes of the spriteindex in 'A' jsr SetVeraToSpriteIndex ;to some bitshifting to compose the address part of the ;image data and use sta VERA_data0 to write it to the sprite ;lattributes rts endfunc:And be aware of the assembly language: I'm using a custom build assembler, do you'll be missing some fancy stuff the well known brands offer. Just check the existing source to see what you can use
I'm actually cool dropping them entirely. I needed them to prove SPRITE_SET_IMG worked. I will always know where I loaded my sprite images.unartic wrote: ↑Fri Jul 19, 2024 6:43 am Nice!
I think it is best to merge SPRITE_GET_IMG_BANK and SPRITE_GET_IMG_ADDR into: SPRITEGETIMGOFFSET
You can then return the address bit in the WorkBuffer as done in your current version. For the bank there is no need to have a seperate function (slower and takes op ram).
The SYS functions alows to communicate three extra bytes with basic (like pseudo proc registers A, X and Y). You can use one of these to return the vera bank:
lda VeraBank ;(or wherever it is)
sta ProcReg
In basic the bank can then be returned with GETA()
(ProcReg+1 = GETX() and ProcReg+2 = GETY())
Maybe it is even good enough to make a CopySpriteMemOffset(indexSrc,indexDest) which copies the memory offset address from one sprite to another. That would be way quicker then communicating it back in basic and using it again.
The developer can then load 'all' sprite images from which some could be dummy's just to load the image data and then use CopySpriteMemOffset to change the address offset.
Alternativly, we could also use the pseudo processor registers each time ADDSPRITE is used to 'return' the bank and address of the image data offset. If the developer need it, it can save these after ADDSPRITE for later use. That would also be a lot better performing.