Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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 ret
Posts: 805
Threads: 135
Joined: Apr 2009
Reputation:
5
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 ret
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
britlion Wrote:boriel Wrote:I'm also wondering which one is faster!
I think they have to be....similar. Given they are byte for byte identical: :!: 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.
Posts: 805
Threads: 135
Joined: Apr 2009
Reputation:
5
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...
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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).
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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.
Posts: 805
Threads: 135
Joined: Apr 2009
Reputation:
5
boriel Wrote:I
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).
That's a new one for me. Huh.
Is there a list of these compiler directives somewhere?
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
britlion Wrote:boriel Wrote:I
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).
That's a new one for me. Huh.
Is there a list of these compiler directives somewhere? Not yet :oops:
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"
file2.asm
Code: _FILE2:
rla ; a = a * 2
...
...
Then you realized that if you join both files, the JP _FILE2 can be removed, so remove the JP_FILE2, and replace #include once by #require. The compiler will "include once" the sub.asm file at a later stage, so you can join file1.asm and file2.asm in a row:
file1.asm
Code: #require "SUB.asm"
..
call SUB_ASM
ld a, 5
; jp _FILE2 ;; removed; goes directly to _FILE2:
; Continue on file2.asm routine
file2.asm
Code: ; Ensures file1.asm goes here
#include once "file1.asm"
_FILE2:
rla ; a = a * 2
...
...
This technique is used with the print routines, and many others. This way, the code gets optimized and in a row, but also allows to discard chunks of code if they are not used (as commented above). So if file1.asm code is not used, it won't be included, (conditional defines, etc...)
Posts: 805
Threads: 135
Joined: Apr 2009
Reputation:
5
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...
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
Sorry, Britlion. I've been busy this week.
You can't jump to DECY because it's been declared as LOCAL.
Basically I would:
- Make DECY / INCY labels public (maybe renaming them to a less common name, like "Scan_INC_Y" or the like)
- Take DEC B / INC B out of these routines (Only DRAW uses them).
- In the file SPXXXXX.asm do:
SPPixelUp EQU Scan_INC_Y ; or whatever
#require "Scan_INC_Y.asm"
I will try to address it this weekend.
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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
ret
The dec b, and ex af, af' sequence on the left (marked with an asterisk *) can be ignored. But the SP routine on the right does an extra ADD a, 08 mine does not do :?:
Accoding to Speccy.org seems to be an optimization. Any ideas?
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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
ret
I think this one is clearer.
Both this 2 routines do the same. :?: The one on the right seems optimized (It's used in ZX Basic DRAW)
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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).
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
britlion Wrote:boriel Wrote:Britlion, seriously, this is FANTASTIC! :o
BTW: I've finally integrated the SPPixel routines within ZX Basic (Draw already uses them). I'm porting SPFill into the library as #include <SP/fill.bas>. Once it's done, I could try to include this one.
Way to go!
This will be harder to import, since it needs a chunk of extra data.... The SPFill is already included and both Draw and it uses the same routines finally!
Code: #include <SP/Fill.bas>
SPFill(127,87, USR "a") : REM Fills with UDG "a"
Update: It comes included in the 1.2.9s861
|