![]() |
PutTile16x16 Pixels + Attributes - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: How-To & Tutorials (https://www.boriel.com/forum/forumdisplay.php?fid=13) +---- Thread: PutTile16x16 Pixels + Attributes (/showthread.php?tid=227) Pages:
1
2
|
PutTile16x16 Pixels + Attributes - LCD - 05-29-2010 This will put Tiles of 2x2 characters with attributes on screen, and is not restricted to use a particular number of tiles, as it uses a memory pointer to the adress of tile in memory, and it is almost fast enough for games (until someone will write a ASM version) Note: Lines(23) is used for screen adress calculation. I used only 24 bytes for this table (without bAND function I need a Table for this). not using a array but InLine ASM DEFB data can save 3 bytes. POKE and PEEK UINTEGER use two-Byte transfer, so this is much faster than transfer of a single byte. Screen adress calculation is splited (so variable A had to be created) because of a calculation problem. Usualy I would write these lines: Code: a=peek(@lines+y+3) Code: scr=peek(@lines+y+3)<<5+x+16384 also if y is not uinteger but ubyte type, scr value is calculated wrong, so even if y is in range of ubyte, do not change it as binary shifts on Ubyte also results in a ubyte. Code: Dim lines(23) As uByte => { _ Re: PutTile16x16 Pixels + Attributes - britlion - 05-29-2010 PutTile? I'm wondering if the latest version of the fourspriter code might be able to rework for that. Hmm. Maybe. It uses data in an akward format - but it's /really/ fast. It uses PUSH and POP to write its four character squares. Of course, I got it tied up in knots and handed it to Boriel to fix :-) When that happens: Call a Genius, I always say. Re: PutTile16x16 Pixels + Attributes - boriel - 05-29-2010 britlion Wrote:PutTile? I'm wondering if the latest version of the fourspriter code might be able to rework for that. Hmm. Maybe. It uses data in an akward format - but it's /really/ fast. It uses PUSH and POP to write its four character squares.Sorry, I did't understood very well :oops: Did you already passed me the FINAL version of fourspriter to be included in the library?? Re: PutTile16x16 Pixels + Attributes - britlion - 05-29-2010 Nope. It's a little bit broken - though the actual sprite code should be solid. The only problem it has is when sprites overlap, right now. I'm not sure of the best solution: 1> Instead of Sprite 1: Erase-Print, Sprite 2: Erase-Print.... etc; could do Erase-Erase-Erase-Erase-print-print-print-print (as the original fourspriter does) 2> Outside the sprite printing loop, flag sprites that overlap, and turn one of them off while overlapping. I was looking at doing version 2, because it keeps the main loop faster; but it is less elegant. On the plus side, it does mean that a collision detection function could be implemented very easily. [What I was talking about was using the Fourspriter fast push-pop code as part of a 4 character Put-Tiles function, as listed here] Re: PutTile16x16 Pixels + Attributes - LCD - 05-29-2010 britlion, if you can adapt the fast fourspriter routine, it would be great. Re: PutTile16x16 Pixels + Attributes - britlion - 05-30-2010 I'm sure it wouldn't be too hard to rip part of that for that purpose. Though the data would have to be stored in 16 bit sections - so you'd need the data for the top line of both characters, then the data for the second line of two characters, and then the 16 bits for the third line and so on. Re: PutTile16x16 Pixels + Attributes - LCD - 05-30-2010 britlion Wrote:I'm sure it wouldn't be too hard to rip part of that for that purpose.Great. Anyway, the data format looks exactly the same as for my routine, POKE UINTEGER stores two byte too. Looking forward to see it. Re: PutTile16x16 Pixels + Attributes - britlion - 05-31-2010 Here's a start point for you, LCD: (We'll need these functions! for the FourSpriter version anyway - and that will be quite long, if fast....) Code: FUNCTION scrAddress(x as uByte, y as uByte) as Uinteger Code: FUNCTION attrAddress (x as uByte, y as uByte) as uInteger Re: PutTile16x16 Pixels + Attributes - boriel - 05-31-2010 There's already such a function in attr.asm library, but this one uses a different approach: Code: __ATTR_ADDR: The problem here is __ATTR_ADDR is taking into account a configurable SCREEN_ADDRESS variable (previously discussed here). So if you want your program to work in a variable screen address, you should work considering 0 offset an adding (SCREEN_ADDRESS) at the end, so should change it this way: Code: FUNCTION FASTCALL attrAddress(x as uByte, y as uByte) as Uinteger : REM Will issue a Warning Re: PutTile16x16 Pixels + Attributes - LCD - 05-31-2010 britlion Wrote:Here's a start point for you, LCD:Currently just tested by filling screen completly with tiles 8 times: 131 Frames with my table 128 Frames with your screen/attr calculation. Not bad after all, because the now only the drawing needs optimisations. Re: PutTile16x16 Pixels + Attributes - britlion - 05-31-2010 boriel Wrote: I haven't looked yet, but I will. Could the assembler/compiler optimize this by KNOWING if the screen address is changed ever? I would consider it unusual code to move it on the spectrum? (I know, multi-platform). One optimization would be spectrum specific. If screen address=16384, then go short on the code :-) Incidentally, I was looking at some asm: Code: poke Uinteger @ptDatapoint+3,value becomes: Can't the assembler deal with Code: ld hl, __LABEL__ptDataPoint+3 Being able to do that would reduce the code quite a lot, I would think - if the assembler could code the actual value there, instead of the base and then inc three times. Re: PutTile16x16 Pixels + Attributes - boriel - 05-31-2010 LCD Wrote:Then I suggest you to use the 2nd routine if you want SCREEN_ADDRESS relocation. In fact, Drawing routines can also be made relocatable just by modifying the PLOT.ASM low-level routine. :wink:britlion Wrote:Here's a start point for you, LCD:Currently just tested by filling screen completly with tiles 8 times: Re: PutTile16x16 Pixels + Attributes - britlion - 05-31-2010 Wait, wait.... Boriel - the "attradrress" function you timed there is actually the SCREEN address code I listed above, not the attribute code... I'm actually also still hopelessly confused with the changes you made to get the values out with pop. I've stared at that stack, and I don't see how two pops gets you values 5,6 and 7,8. Surely that gets you values 1,2 and 3,4. Guess I still haven't quite got the hang of how you stack variables. To the point where I'm writing putTile, and poking the screen address into a memory value instead of try to work out where it is. (in IX-3,4 apparently...) Finally, how can you fastcall with multiple parameters??? Re: PutTile16x16 Pixels + Attributes - boriel - 05-31-2010 britlion Wrote:Wait, wait....Not exactly. I just copied by mistake the comment line of the SCREEN address function, but the function body is actually the ATTR address. Quote:I'm actually also still hopelessly confused with the changes you made to get the values out with pop. I've stared at that stack, and I don't see how two pops gets you values 5,6 and 7,8. Surely that gets you values 1,2 and 3,4.By values 5,6 etc... you mean (IX + 5) and (IX + 6)... don't you? :roll: Well, I think I've somewhat already explained it here. Now, this is important: FASTCALL convention call is like STDCALL but:
Re: PutTile16x16 Pixels + Attributes - britlion - 05-31-2010 Oh, so it's not passing the first value in the stack - stdcall passes it in the register AND in the stack, which is a little confusing. So we CAN use FASTCALL, even if the compiler complains to shortcut that, and use a shorter stack. I think I see. There's the confusion - fastcall would say "hey, you can't do that!" and so I sort of went with that. |