Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 259
» Latest member: DonaldDeade
» Forum threads: 1,074
» Forum posts: 6,434

Full Statistics

Online Users
There are currently 191 online users.
» 0 Member(s) | 189 Guest(s)
Bing, Google

Latest Threads
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 338
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 300
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,601
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 557
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 893
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 333
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,066
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,888
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 419
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,812

 
  sprites like MJ's Trabajo Basura (not unregr. Fourspriter)
Posted by: nitrofurano - 10-29-2011, 10:45 PM - Forum: Wishlist - Replies (19)

not unregretting that awesome Fourspriter, what about that technique used on MojonTwin's Trabajo Basura? <!-- m --><a class="postlink" href="http://www.mojontwins.com/juegos_mojonos/trabajo-basura-dire-job/">http://www.mojontwins.com/juegos_mojono ... -dire-job/</a><!-- m -->
it seems to be very similar to most of the sprites used on zx-spectrum games - how would we use this kind of sprites from a zxbasic-compiler library?

Print this item

  asm context issue?
Posted by: britlion - 10-25-2011, 09:41 PM - Forum: Help & Support - Replies (3)

Code:
asm
sub a,3
end asm

I think this is expecting sub to be the basic context subroutine, not the asm subtract command, so fails to compile?

zxb 1.2.8-s758

Print this item

  bezier and cubic curves
Posted by: nitrofurano - 10-25-2011, 04:33 PM - Forum: Help & Support - Replies (1)

finally i coded some snipets - two of them are about drawing bezier and cubic curves - btw, if someone can help them being faster, or part of the library, be welcome! Smile

beziercurve.bas

Code:
dim x0,y0,x1,y1,x2,y2,x3,y3 as float
dim stpv,xi,xo,yi,yo,ir,i as float
dim xr1,yr1,xr2,yr2 as float
dim xsn,ycs as float
dim xa,ya,xb,yb,xc,yc as float
dim tw,t as float
x0=20:y0=30:x1=50:y1=80:x2=150:y2=40:x3=110:y3=10
xa=(x3)-(3*x2)+(3*x1)-(x0)
ya=(y3)-(3*y2)+(3*y1)-(y0)

xb=(3*x2)-(6*x1)+(3*x0)
yb=(3*y2)-(6*y1)+(3*y0)

xc=(3*x1)-(3*x0)
yc=(3*y1)-(3*y0)

stpv=32
for tw=0 to stpv

  t=tw/stpv

  x=(((((xa*t)+xb)*t)+xc)*t)+x0
  y=(((((ya*t)+yb)*t)+yc)*t)+y0

  if tw=0 then:xo=x:yo=y:end if

  plot xo,yo:draw x-xo,y-yo   :'- line (xo,yo,x,y):
  xo=x:yo=y

next

pause 0

cubiccurve.bas
Code:
dim x0,y0,x1,y1,x2,y2,x3,y3 as float
dim stpv,xi,xo,yi,yo,ir,i as float
dim xr1,yr1,xr2,yr2 as float
dim xsn,ycs as float
x0=20:y0=30:x1=50:y1=80:x2=150:y2=40
xr1=x1-x0:yr1=y2-y1

x3=x0+x2-x1:y3=y0+y2-y1

xr2=x2-x1:yr2=y3-y2
stpv=32

for i=0 to stpv

  ir=i*(1.570796/stpv)

  xsn=(xr1*sin(ir))-(xr2*cos(ir))

  ycs=(yr1*(cos(ir)*-1))-(yr2*sin(ir))

  xi=x3+xsn:yi=y3+ycs

  if i=0 then:xo=xi:yo=yi:end if

  if i<>0 then:
    plot xo,yo:draw xi-xo,yi-yo  :'- line (xo,yo,xi,yi)
    end if
  xo=xi
  yo=yi

  next i

pause 0

circlefill.bas
Code:
dim x,y,r,xl as ubyte
dim yd as float
x=50:y=60:r=40
for yd=0 to r
  xl=int((sin(acs(yd/r)))*r)
  plot x-xl,y+yd:draw xl*2,0
  if yd<>0 then:plot x-xl,y-yd:draw xl*2,0:end if
  next yd
pause 0

boxfill.bas
Code:
dim x1,y1,x2,y2 as integer
x1=20:y1=30:x2=50:y2=80
for y=y1 to y2
  plot x1,y:draw x2-x1,0
  next y
pause 0

box.bas
Code:
dim x1,y1,x2,y2 as integer
x1=20:y1=30:x2=50:y2=80
plot x1,y1
draw x2-x1,0
draw 0,y2-y1
draw x1-x2,0
draw 0,y1-y2
pause 0

line.bas
Code:
dim x1,y1,x2,y2 as integer
x1=20:y1=30:x2=50:y2=80
plot x1,y1
draw x2-x1,y2-y1
pause 0

Print this item

  Attribute Address
Posted by: britlion - 10-25-2011, 01:32 AM - Forum: How-To & Tutorials - No Replies

To unearth an aside I hadn't ever responded to in an old topic...I got playing.

boriel Wrote:There's already such a function in attr.asm library, but this one uses a different approach:
Code:
__ATTR_ADDR:
    ; calc start address in DE (as (32 * d) + e)
    ; Contributed by Santiago Romero at http://www.speccy.org
    ld h, 0
    ld l, d
    add hl, hl   ; HL = HL*2
    add hl, hl   ; HL = HL*4
    add hl, hl   ; HL = HL*8
    add hl, hl   ; HL = HL*16
    add hl, hl   ; HL = HL*32

    ;; Note: *THIS IS WRONG*
    ; the addition of 6144 could be optimized to
    ; ld a, 18h
    ; add a, h
    ; ld h, a
    ; this saves 3 T-States  (The above calculation misses E register)
    
    ;; adds 6144 for attribute start
    ld d, 18h ; DE = 6144 + E. Note: 6144 is the screen size (before attr zone)
    add hl, de

    ld de, (SCREEN_ADDR)    ; Adds the screen address
    add hl, de
    
    ; Return current screen address in HL
    ret
Please check which one is faster (I'm not sure): This function takes 102 T-States (RET Included), your takes 67 (RET Included). With the commented optimization it will take 99 T-States.

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
asm
; This function returns the address into HL of the screen address
; x,y in character grid notation.
; Original code was extracted by BloodBaz - Adapted for ZX BASiC by Britlion from Na_TH_AN's fourspriter
         ld e, a    ; X comes in A register (fastcall). Saves X in E register
         pop hl    ; ret Address
         pop af    ; Get Y in A [F not used]
         ld d, a    ; Saves Y in D register, So DE register stores YX coords.    
         push hl   ; Put RET address back in the Stack
         ;; 39 T-States up to here, but we don't count this to be fair with the above
         ;; So 0 T-States. Start counting them from here
         ;; At this point, A already has Y coord
         rrca      
         rrca
         rrca               ; Multiply by 32
         ld      l,a        ; Pass to L
         and     3          ; Mask with 00000011
         ;; 23 T-States up to here
         ;; The following must be changed, start form 0 and add (SCREEN_ADDRESS) later
         ; add     a,88       ; 88 * 256 = 22528 - start of attributes.
         add     a,24       ; 24 * 256 = 6144 - start of attributes from address 0x0000h
         ld      h,a        ; Put it in the High Byte
         ld      a,l        ; We get y value *32
         and     224        ; Mask with 11100000
         ;; The following can be optimized ???
         ; ld      l,a        ; Put it in L
         ; ld      a,d   ; xpos
         ; add     a,l        ; Add it to the Low byte
         add  a, e        ; add xpos
         ld      l,a        ; Put it back in L, and we're done. HL=Address.
         ;; 53 T-States up to here
         ld de, (SCREEN_ADDRESS)
         add hl, de  ;; Total T-States = 84 T-States
         ;; (implicit RET)  + 10 T-States = 94 T-States
end asm
END FUNCTION
So this function, adapted for a configurable screen address is 8 T-states faster than the original in ZX Basic (only 5 if the commented optimization is done) :?:


Just to be completely oddball, I started toying with this.
Code:
takes Y value in D, and X value in E returns attr address

4 AND A ; clear carry flag (this may optimise out if we know it's cleared?)

7 LD H,22
4 LD A,D
; we know left three bits are zero, since d <= 23 so rotate around:
4 RLCA
4 RLCA
4 RLCA

; now it /could/ get interesting we have to rotate potential 1's into H, simultaneously turning that 22 into the 88 H needs to point to address 22528.
4 RLA
8 RL H
4 RLA
8 RL H
4 add a,l
4 ld l,a

63 T states.

I haven't tested this, and it's after midnight. So it might not work. But I think that doing left shifts all the way might be faster?

I think this shaves about 40 T states of each Attr lookup in the current assembly. More if it can be assured it doesn't need to clear the carry flag.

This method does demand that screen address is on 1K boundaries, so as to be divided by 4 and stored in H. The default of 16384 for a screeen mem start fits (attr=22528).

Print this item

  what about a contest related with Boriel's zxbasic-compiler?
Posted by: nitrofurano - 10-21-2011, 10:31 PM - Forum: Help & Support - Replies (2)

i think would be great if, regularly (like once or twice per year), we can have some kind of contest for divulgate (and specific about) Boriel's zxbasic-compiler, and to have more people testing and contributing to this awesome project - what do you all think, and what can help making this contest popular in the zx-spectrum retro-development scene?

Print this item

  playing sound samples
Posted by: nitrofurano - 10-14-2011, 12:00 PM - Forum: Wishlist - Replies (10)

interesting would be a kind of command for playing samples, just like this type-in example found at wos repository:
http://www.worldofspectrum.org/infoseeki...id=0024188
ftp://ftp.worldofspectrum.org/pub/sincla...ampler.txt

since i knew from some magazine snippets from 80's, it seems to be not that hard to be implemented
the idea would be, somehow, we could convert a kind of .wav (or .flac, .aiff, .ogg, .mp3, .raw, etc., like from SoX or Audacity) into a kind of 8khz/1bit sound sample raw binary to be added as defb values, and play it from some zxbasiccompiler library

what do you all think? thanks!

Print this item

  Version 1.2.8 Released!
Posted by: boriel - 10-10-2011, 08:02 PM - Forum: ZX Basic Compiler - Replies (4)

This version is (IMHO) tested enough, and so, released as Stable.
You can download it here

NOTE: This is revision 1.2.8 s758
If you already have it, you don't need to download it again.

Changelog since 1.2.7:
* Code rearranged and reestructured for future refactorizations.
*! Complete rewritten backend (or almost!) to fix a bug in code
:generation which was being suboptimal. Now generated code is
:much faster and take less memory than before!
*+ Added support for Bitwise syntax (|, &, ~)
*! Fixed some bugs in ASM
*! Fixed some bugs in the peephole optimizer (-O3)
*! Fixed a bug with line continuation comments /' ...
*! Fixed bugs in ASM parser regarding to comments
*+ Added ATTRADDR function in <attrib.bas>
*! Many more bugs fixed related to STRING memory leak
*! Fixed a bug related to parameters.
* Some optimizations for code size and speed for FLOAT types
* Optimization for STRING parameters
* Optimization for 32 bit values
*! Fixed a bug for Uinteger/Integer arrays assignation
*! Fixed 2 bugs in CAST operation and type conversion
*! Fixed a bug in OVER attribute during PRINT
* Added PONG game example
*! Fixed a bug in POKE
*! PRINT optimized and slighty faster. Now fully compatible with
:SINCLAIR BASIC (no Out of Screen error on program exit)
*! CSRLN and POS optimized to this new PRINT SCHEME!
... and much much more

Print this item

  reading simultaneous keys pressed
Posted by: nitrofurano - 10-08-2011, 05:49 PM - Forum: Help & Support - Replies (6)

i forgot how to read simultaneous keys pressed on zx-spectrum - is it from port 254? and only port 254? and how?
and how can we read them in a zxbasic-compiler snippet?
thanks! Smile

Print this item

  equivalent of waitvbl (from Amos and sdlBasic) needed
Posted by: nitrofurano - 10-08-2011, 05:07 PM - Forum: Help & Support - Replies (2)

i tried this code

Code:
#include <print64.bas>
10 ink 7:paper 0:border 2: bright 1:flash 0:cls
20 let x=10:let y=10
30 printat64(y,x):print64("X")
100 let a$=inkey$
200 if a$="w" or a$="W" or a$="7" or a$=chr$(11) then printat64(y,x):print64(" "):y=y-1:printat64(y,x):print64("X"):end if
210 if a$="s" or a$="S" or a$="6" or a$=chr$(10) then printat64(y,x):print64(" "):y=y+1:printat64(y,x):print64("X"):end if
220 if a$="a" or a$="A" or a$="5" or a$=chr$(8) then printat64(y,x):print64(" "):x=x-1:printat64(y,x):print64("X"):end if
230 if a$="d" or a$="D" or a$="8" or a$=chr$(9) then printat64(y,x):print64(" "):x=x+1:printat64(y,x):print64("X"):end if
1000 goto 100

but it runs too fast, and i only need to synchronize it with the display frequence (50hz or 60hz)
i think zxspectrum uses this with some z80 interrupt instruction? which one, and how can we use it inside 'asm/endasm'?

Print this item

  interesting performance differences with sub/endsub
Posted by: nitrofurano - 10-08-2011, 02:22 PM - Forum: Help & Support - No Replies

i were trying to make some experiences with display memory byte sequence references from coco2 (pmode 4) and msx1 (screen 2)
first i tried these:

coco2-pmode4 with sub/endsub (around 49 seconds):

Code:
dim a1, a2, v1, i as integer
sub vpokeln(a1,v1)
  let a2=16384 +  ((a1 band 31) bor ((a1 band 224)*8) bor ((a1 band 1792)/8) bor (a1 band 6144))
  if a1>=0 and a1<=6143 then: poke a2,v1:end if
  end sub
out 254,6
for i=400 to 6000
  vpokeln(i,40)
  next i
pause 0

msx1-screen2 with sub/endsub (around 60 seconds):
Code:
dim a1, a2, v1, i as integer
sub vpokech(a1,v1)
  let a2=16384+(((a1 band 7)*256) bor ((a1 band 248)/8) bor ((a1 band 1792)/8) bor (a1 band 6144))
  if a1>=0 and a1<=6143 then: poke a2,v1:end if
  end sub
out 254,6
for i=400 to 6000
  vpokech(i,40)
  next i
pause 0

but when i don't use sub/endsub, i got these results as benchmark:

coco2-pmode4 without sub/endsub (around 3 seconds):
Code:
dim i as integer
out 254,6
for i=400 to 6000
  poke 16384+((i band 31) bor ((i band 224)*8) bor ((i band 1792)/8) bor (i band 6144)),40
  next i
pause 0

msx1-screen2 with sub/endsub (around 7 seconds):
Code:
dim i as integer
out 254,6
for i=400 to 6000
  poke 16384+(((i band 7)*256) bor ((i band 248)/8) bor ((i band 1792)/8) bor (i band 6144)),40
  next i
pause 0

and i used the original zx-spectrum byte sequence display, i got this:

with sub/endsub (around 30 seconds):
Code:
dim a1, a2, v1, i as integer
sub vpokezx(a1,v1)
  let a2=16384+a1
  if a1>=0 and a1<=6143 then: poke a2,v1:end if
  end sub
out 254,6
for i=400 to 6000
  vpokezx(i,40)
  next i
pause 0

without sub/endsub (around 0.25 seconds or less):
Code:
dim i as integer
out 254,6
for i=400 to 6000
  poke 16384+i,40
  next i
pause 0

the question: what is causing so large performances differences from my expectations (i expected faster on the slower ones), and should i do for optimizing this?

Print this item