![]() |
|
Fill Routine - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: How-To & Tutorials (https://forum.boriel.com/forumdisplay.php?fid=13) +---- Thread: Fill Routine (/showthread.php?tid=439) |
Re: Fill Routine - boriel - 2012-04-07 I'm also wondering which one is faster! ![]() Except for the inc b/dec b (used to update pixel coords in BC for later use), which sub is faster? e.g. Here is DRAW incY: Notes: Line 292 (inc b) can be removed out, this is a DRAW requirement and can be done outside the sub The routine sets Carry on F', to signal the ATTR position must be also updated. Code: 288 ;; Given an HL screen position, calculates
289 ;; the above position
290 ;; Also updates BC coords
291 __INCY:
292 inc b
293 ld a, h
294 dec h
295 and 7
296 ret nz
297 ex af, af' ; Sets carry on F'
298 scf ; which flags ATTR must be updated
299 ex af, af'
300 ld a, 8
301 add a, h
302 ld h, a
303 ld a, l
304 sub 32
305 ld l, a
306 ret nc
307 ld a, h
308 sub 8
309 ld h, a
310 retRe: Fill Routine - britlion - 2012-04-08 boriel Wrote:I'm also wondering which one is faster! I think they have to be....similar. Given they are byte for byte identical: Code: ;
; enter: HL = valid screen address
; exit : Carry = moved off screen ;; Given an HL screen position, calculates
; HL = moves one pixel up ;; the above position
; used : AF, HL ;; Also updates BC coords
__INCY:
SPPixelUp: inc b
ld a,h ld a, h
dec h dec h
and $07 and 7
ret nz ret nz
ex af, af' ; Sets carry on F'
scf ; which flags ATTR must be updated
ex af, af'
ld a,$08 ld a, 8
add a,h add a, h
ld h,a ld h, a
ld a,l ld a, l
sub $20 sub 32
ld l,a ld l, a
ret nc ret nc
ld a,h ld a, h
sub $08 sub 8
ld h,a ld h, a
cp $40
ret retRe: Fill Routine - boriel - 2012-04-08 britlion Wrote::!:boriel Wrote:I'm also wondering which one is faster! hock: Well, don't remember if I did them on my own, or took them from speccy.org (probably from there). Anyway, getting the next/previous scanline is quite standard: ZX Spectrum have few registers, and usually HL is used for "pokeing" the screen. So, yes: except for the INC B and attibute flag, this routine is identical. I think I'm going to remove the INC B out of it, and make them independent (separated in their own files). So they can be included by the Fill routine, and so. Re: Fill Routine - britlion - 2012-04-08 boriel Wrote:britlion Wrote:Since DRAW is alwaws packed with ZX BASIC I guess it would be rather easy to replace them so no duplicated code is included and so, some precious bytes saved! Boriel: Why is it always packed with ZX Basic? One thing Hisoft Basic did well was paring down the runtime modules to a minimum - they were only included in the final code if they were called. I suspect ZX Basic could be more modular, with more code separated out and INCLUDE ONCEd, so that it's only packed in if it's needed. If people are going to make full sized games, they are going to need every last byte! INCY/DECY are classic examples of code that could be included from SPPack and from Draw - but only if one parent is included; and INCLUDE ONCEd so that they only get glued in once if both are needed... Re: Fill Routine - boriel - 2012-04-08 I meant 'packed' (bundled?) not compiled. Whenever you use DRAW, these routines are compiled with your program. Otherwise they are not. I think we both are saying the same... ![]() The asm directive for this is #require "file.asm", which will include the file ONCE at the end of the compilation (include once does it in place). Re: Fill Routine - boriel - 2012-04-08 Another question: why the CP $40 at the end of the SP INC y routine?? Update: After examining the code, I guess it signals C carry if out of screen. Hmmm. Will try to integrate both routines in a single (common) one. Re: Fill Routine - britlion - 2012-04-10 boriel Wrote:I That's a new one for me. Huh. Is there a list of these compiler directives somewhere? Re: Fill Routine - boriel - 2012-04-10 britlion Wrote:Not yet :oops:boriel Wrote:I Anyway, it's safe to use include once always. But some times you want a library to be "included once later". Let's suppose we have the following files: file1.asm Code: ...
call SUB_ASM
ld a, 5
jp _FILE2
; Continue on file2.asm routine
#include once "SUB.asm"Code: _FILE2:
rla ; a = a * 2
...
...file1.asm Code: #require "SUB.asm"
..
call SUB_ASM
ld a, 5
; jp _FILE2 ;; removed; goes directly to _FILE2:
; Continue on file2.asm routineCode: ; Ensures file1.asm goes here
#include once "file1.asm"
_FILE2:
rla ; a = a * 2
...
...Re: Fill Routine - britlion - 2012-04-19 So, without a handy list of compiler directives, what's the best way of making sure draw is in? Couldn't see a way to compile a jump to DECY... Re: Fill Routine - boriel - 2012-04-19 Sorry, Britlion. I've been busy this week. You can't jump to DECY because it's been declared as LOCAL. Basically I would:
Re: Fill Routine - boriel - 2012-05-30 I'm puzzled. The __DECY routine and the one in our code *differ* hock: I now remember where did I took these routines from this Speccy Tutorial Code: __DECY: SPPixelDown:
* dec b inc h
inc h ld a,h
ld a, h and $07
and 7 ret nz
ret nz ld a,h
* ex af, af' sub $08
* scf ld h,a
* ex af, af' ld a,l
ld a, l add a,$20
add a, 32 ld l,a
ld l, a ret nc
ret c ld a,h
ld a, h add a,$08
sub 8 ld h,a
ld h, a cp $58
ret ccf
retAccoding to Speccy.org seems to be an optimization. Any ideas? Re: Fill Routine - boriel - 2012-05-30 Update (cleaned up): Code: __DECY: SPPixelDown:
inc h inc h
ld a, h ld a, h
and 7 and 7
ret nz ret nz
ld a, h
sub 8
ld h, a
ld a, l ld a, l
add a, 32 add a, 32
ld l, a ld l, a
ret c ret nc
ld a, h ld a, h
sub 8 add a, 8
ld h, a ld h, a
ret cp $58
ccf
retBoth this 2 routines do the same. :?: The one on the right seems optimized (It's used in ZX Basic DRAW) Re: Fill Routine - boriel - 2012-06-01 Update2: I got it. Both routines do the same. The one on the left is smaller (more optimized), but there is a chance that after the ADD A, 32 it returns with the RET C. Since the fill routine uses the Carry flag to signal out of screen, this should never happen. So the routine is rewritten like the one on the left. :mrgreen: So now I'm ready to integrate this into the ZX BASIC library
Re: Fill Routine - boriel - 2012-06-02 Okay, I've finally imported it into ZX Basic. BTW should it be called SPPFill or SPFill ? Even better, I think it should be better to use the name patern SPFill (case sensitive). HOWTO: Put BeepFX Sound into ZXB code - boriel - 2012-06-03 britlion Wrote:The SPFill is already included and both Draw and it uses the same routines finally!boriel Wrote:Britlion, seriously, this is FANTASTIC! :o Code: #include <SP/Fill.bas>
SPFill(127,87, USR "a") : REM Fills with UDG "a" |