FAQ  •  Register  •  Login

Fill Routine

<<

britlion

Posts: 762

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Feb 27, 2012 10:22 pm

Fill Routine

I FINALLY (I've been meaning to for years) Got around to making Alvin Albrecht's Fill routine work in ZX BASIC, I think.

http://dl.dropbox.com/u/4903664/SPFill.zip

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..."
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Wed Feb 29, 2012 12:02 pm

Re: Fill Routine

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...)
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Wed Feb 29, 2012 1:24 pm

Re: Fill Routine

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 :)
<<

britlion

Posts: 762

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Wed Feb 29, 2012 1:31 pm

Re: Fill Routine

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.
<<

boriel

Site Admin

Posts: 1448

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Feb 29, 2012 1:31 pm

Re: Fill Routine

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 :)

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.
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Thu Mar 01, 2012 10:26 am

Re: Fill Routine

Good to know :) I found about it using a debugger (I found ld sp, ix just after returning from a Sub).
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Wed Mar 07, 2012 11:48 am

Re: Fill Routine

I've updated my vector drawing/displaying package. Release here: http://www.mojontwins.com/mojoniaplus/v ... f=12&t=891
Short tutorial (albeit in spanish) here: http://tcyr.wordpress.com/2012/03/07/su ... redux-3-0/
<<

britlion

Posts: 762

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Wed Mar 07, 2012 2:53 pm

Re: Fill Routine

Very nice, Na_th_an!
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Wed Mar 07, 2012 4:39 pm

Re: Fill Routine

Only possible thanks to your work :)
<<

slenkar

Posts: 282

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Wed Mar 07, 2012 7:02 pm

Re: Fill Routine

good idea to draw background screens that way
<<

boriel

Site Admin

Posts: 1448

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Mar 07, 2012 7:26 pm

Re: Fill Routine

:shock: 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 :?: :?:). So ...
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Thu Mar 08, 2012 11:05 am

Re: Fill Routine

As always, feel free to use whatever I produce in the compiler library :)

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.
<<

slenkar

Posts: 282

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Fri Mar 09, 2012 6:00 pm

Re: Fill Routine

Nathan I like your avatar at ojodepez-fanzine.net/
<<

boriel

Site Admin

Posts: 1448

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Mar 18, 2012 1:42 am

Re: Fill Routine

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!
<<

britlion

Posts: 762

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Apr 07, 2012 10:25 am

Re: Fill Routine

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.
Next

Return to How-To & Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO