Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fill Routine
#1
I FINALLY (I've been meaning to for years) Got around to making Alvin Albrecht's Fill routine work in ZX BASIC, I think.

<!-- m --><a class="postlink" href="http://dl.dropbox.com/u/4903664/SPFill.zip">http://dl.dropbox.com/u/4903664/SPFill.zip</a><!-- m -->

Compile SPPFill.bas and it pulls in all the other bits, which I've hacked to ignore timex modes.


Boriel - I think this, with a bit of clean up, should possibly go into the compiler as available.

Thanks, Na_th_an for reminding me of SPLIB2, which made me see this again, and go "Right, I'm gonna do this this time..."
Reply
#2
Now THIS is what I was looking for! Thanks, man, now it's time to port SUVLEIR to pure, native ZX Basic, and I'm giving you tons of credits for it! (I was using SUVLEIR in a ZXBasic project, but I *had* to use that ugly, external binary compiled with z88dk from my BASIC code using ugly POKEs and CALLs...)
Reply
#3
I'm having problems. A call to the routine seems to mess up something (maybe some register should be preserved?). My routine is simple, quoting the interesting bit:

Code:
    While (endOfDrawing > binAddress)
        cmd = Peek (binAddress)
        binAddress = binAddress + 1
        
        If cmd < 192 Then
            x = Peek (binAddress)
            binAddress = binAddress + 1
            y = 191 - cmd
            dx = x: dx = dx - cx ' ZX Basic doesn't like type mix
            dy = y: dy = dy - cy ' ZX Basic doesn't like type mix
            Draw dx, dy
            cx = x
            cy = y
        ElseIf cmd = 192 Then
            x = Peek (binAddress)
            y = 191 - Peek (binAddress + 1)
            binAddress = binAddress + 2
            Plot x, y
            cx = x
            cy = y
        ElseIf cmd = 193 Then
            x = Peek (binAddress)
            y = Peek (binAddress + 1)
            ex = Peek (binAddress + 2)
            binAddress = binAddress + 3
            SPPFill (x, y, @gpPatterns + (ex << 3))
        End If
    Wend

Notice the call to SPPFill towards the end of the code. If I comment that line, the vector drawing renders OK (albeit, without fills), but if I leave it uncommented, it somehow messes something so binAddress goes elsewhere and it draws random lines until the program crashes.

I've found that somehow ZX Basic doens't like IX messed with, so if I do:

Code:
Asm
   push ix
End Asm
SPPFill (x, y, @gpPatterns + (ex << 3))
Asm
   pop ix
End Asm

It just works! Not a big deal, but I just wanted you to know.

I might have something to publish very soon Smile
Reply
#4
Ah yes. ZX Basic points IX into the stack, and uses it as a stack reference (variable x is IX+a etc). Since SPPFill uses that I should push and pop it in there, I think. I'll experiment when I have a little time.
Reply
#5
na_th_an Wrote:I've found that somehow ZX Basic doens't like IX messed with, so if I do:

Code:
Asm
   push ix
End Asm
SPPFill (x, y, @gpPatterns + (ex << 3))
Asm
   pop ix
End Asm

It just works! Not a big deal, but I just wanted you to know.

I might have something to publish very soon Smile
That's it. ZX Basic requires IX register to be preserved before exiting/entering BASIC functions. It's used to manage the stack frame: the parameters, for example, are loaded using (IX+n), etc.
Reply
#6
Good to know Smile I found about it using a debugger (I found ld sp, ix just after returning from a Sub).
Reply
#7
I've updated my vector drawing/displaying package. Release here: <!-- m --><a class="postlink" href="http://www.mojontwins.com/mojoniaplus/viewtopic.php?f=12&t=891">http://www.mojontwins.com/mojoniaplus/v ... f=12&t=891</a><!-- m -->
Short tutorial (albeit in spanish) here: <!-- m --><a class="postlink" href="http://tcyr.wordpress.com/2012/03/07/suvleir-3-0-super-ultra-vector-library-experience-inspire-redux-3-0/">http://tcyr.wordpress.com/2012/03/07/su ... redux-3-0/</a><!-- m -->
Reply
#8
Very nice, Na_th_an!
Reply
#9
Only possible thanks to your work Smile
Reply
#10
good idea to draw background screens that way
Reply
#11
Confusedhock: I'm still *shocked* (just arrived from work, a hard day...)
This library *should* go integrated with the compiler. May I :?:

BTW as stated before, I've started 2.x branch. This would need extensive compile testing... (if someone dares).
The 2.x branch aims to be a new different and extensively rewritten compiler (it might even transform your spectrum into a Commodore VIC-20 :?: :?Smile. So ...
Reply
#12
As always, feel free to use whatever I produce in the compiler library Smile

If you like, I can try the new compiler branch. I'm developing a series of tutorials and I can try to compile everything with the new version and report how it goes.
Reply
#13
Nathan I like your avatar at ojodepez-fanzine.net/
Reply
#14
britlion Wrote:Boriel - I think this, with a bit of clean up, should possibly go into the compiler as available.

Thanks, Na_th_an for reminding me of SPLIB2, which made me see this again, and go "Right, I'm gonna do this this time..."
Thanks, for this!
I'm about to do so, however, notice there are ASM routines called inc and dec screen position. Very (almost identical) routines are already packeted with the optimized DRAW routine (It's really very optimized!). I think it would be a good idea to replace SPPixelUP: body with a simple call to INCY / DECY routines, or vice versa, replace DRAW INC/DEC y routines with these ones.

They are almost identical, except some flag check.
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!
Reply
#15
You could also add extra labels to the inbuilt functions, so they are collected with SPPixelUp and down? This way at least the labelling is consistent with the whole SPLIB2 system, should it be implemented in full.
(in short, replace two of Albrecht's routines with the inbuilt ones, but be able to jump to them using the same naming convention as he has in everything else)

There may be more of his routines that can be replaced, of course.

Edit: Oh, there is a difference: exit : Carry = moved off screen

So we'd need to replace the routine with

SPPixelUp:
call INCY
CP $40
ret

This would be shorter, it's true; though it buries an extra call and some flagging in it.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)