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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 262
» Latest member: Stephanwer
» Forum threads: 1,074
» Forum posts: 6,434

Full Statistics

Online Users
There are currently 184 online users.
» 0 Member(s) | 181 Guest(s)
Applebot, Bing, Google

Latest Threads
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 345
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,607
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: 339
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,069
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: 421
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,817

 
  Clearing Screen
Posted by: LCD - 03-24-2012, 09:03 PM - Forum: How-To & Tutorials - Replies (5)

I adapted some Screen clearing routines posted on WOS here: <!-- m --><a class="postlink" href="http://www.worldofspectrum.org/forums/showthread.php?t=38426">http://www.worldofspectrum.org/forums/s ... hp?t=38426</a><!-- m --> for ZXBC. Maybe useful for other coders:

Code:
sub ShiftClearScr()
    asm
        ld b,8        ;'8 bits to rotate out per byte
    CLSNloop:
        call clearscreennice
        djnz CLSNloop
        jr CLSNEnd
    clearscreennice:
        ld hl,16383    ;'just before display file
    CLSNcloop:
        inc hl
        ld a,h
        cp 88        ;'into address 22528 yet?
        ret z        ;'yep return
        sla (hl)    ;'nope, shift the byte
        jr CLSNcloop    ;'keep going
    CLSNEnd:
    end asm
end sub
Code:
sub SpiralTrailClearScr()
    asm
        ei
        ld      hl,patterns01
loop1:
        halt
        
        ld      a,(hl)  
        inc     hl    
        
        or      a  
        jp      z,end02  
        
        ld      c,a  
        and     127  
        ld      d,a  
        
        ld      b,3  
        ld      e,0  
                
loop2:
        ld      a,(de)

        bit     7,c  
        jr      z,tmp1  

        or      (hl)    
        jr      tmp2  

tmp1:
    and     (hl)

tmp2:
    ld      (de),a
        inc     e  
        jr      nz,loop2  
        
        ld      a,d  
        add     a,8  
        ld      d,a  
        djnz    loop2
        
        inc     hl  
        jr      loop1  
        
        jp end02
                  
patterns01:
        db      64+128,128,64+128,64,64+128,32,64+128,16
        db      64+128,8,64,127,64+128,4,64,191
        db      64+128,2,64,223,64+128,1,64,239
        db      65+128,1,64,247,66+128,1,64,251
        db      67+128,1,64,253,68+128,1,64,254
        db      69+128,1,65,254,70+128,1,66,254
        db      71+128,1,67,254,71+128,2,68,254
        db      71+128,4,69,254,71+128,8,70,254
        db      71+128,16,71,254,71+128,32,71,253
        db      71+128,64,71,251,71+128,128,71,247
        db      70+128,128,71,239,69+128,128,71,223
        db      68+128,128,71,191,67+128,128,71,127
        db      66+128,128,70,127,65+128,128,69,127
        db      65+128,64,68,127,65+128,32,67,127
        db      65+128,16,66,127,65+128,8,65,127
        db      65+128,4,65,191,65+128,2,65,223
        db      66+128,2,65,239,67+128,2,65,247
        db      68+128,2,65,251,69+128,2,65,253
        db      70+128,2,66,253,70+128,4,67,253
        db      70+128,8,68,253,70+128,16,69,253
        db      70+128,32,70,253,70+128,64,70,251
        db      69+128,64,70,247,68+128,64,70,239
        db      67+128,64,70,223,66+128,64,70,191
        db      66+128,32,69,191,66+128,16,68,191
        db      66+128,8,67,191,66+128,4,66,191    
        db      67+128,4,66,223,68+128,4,66,239    
        db      69+128,4,66,247,69+128,8,66,251    
        db      69+128,16,67,251,69+128,32,68,251
        db      68+128,32,69,251,67+128,32,69,247  
        db      67+128,16,69,239,67+128,8,69,223    
        db      68+128,8,68,223,68+128,16,67,223    
        db      67,239,67,247,68,247,68,239
        
        db      0
    end02:
    end asm
end sub
Code:
sub SpiralClearScr()
    asm
                ei  
                ld      hl,patterns
loop01:
                halt

                ld      a,(hl)
                inc     hl

                or      a
                jp      z,clearend2

                ld      d,a

                ld      c,(hl)
                inc     hl

                ld      b,3
                ld      e,0

loop02:          ld      a,(de)
                and     c
                ld      (de),a
                inc     e
                jr      nz,loop02

                ld      a,d
                add     a,8
                ld      d,a
                djnz    loop02

                jr      loop01

                jp clearend2

patterns:
                db      64,127, 64,191, 64,223, 64,239
                db      64,247, 64,251, 64,253, 64,254
                db      65,254, 66,254, 67,254, 68,254
                db      69,254, 70,254, 71,254, 71,253
                db      71,251, 71,247, 71,239, 71,223
                db      71,191, 71,127, 70,127, 69,127
                db      68,127, 67,127, 66,127, 65,127
                db      65,191, 65,223, 65,239, 65,247
                db      65,251, 65,253, 66,253, 67,253
                db      68,253, 69,253, 70,253, 70,251
                db      70,247, 70,239, 70,223, 70,191
                db      69,191, 68,191, 67,191, 66,191
                db      66,223, 66,239, 66,247, 66,251
                db      67,251, 68,251, 69,251, 69,247
                db      69,239, 69,223, 68,223, 67,223
                db      67,239, 67,247, 68,247, 68,239

                db      0
clearend2:
    end asm
end sub
Code:
sub RandomClearScr()
    asm
            ld hl,0        ;'point hl somewhere in ROM
            ld b,6        ;'using 48k ROM you need 5 or more repeats to empty screen
        CLSloop1:
            call CLSStart1
            djnz CLSloop1
            jr CLSend1
        CLSStart1:
            ld de,16383    ;'start of display file-1
        CLScloop:
            inc de        ;'move into and through display file
            inc hl        ;'and ROM
            ld a,d        ;'are we out of display file and into attributes yet?
            cp 88
            ret z            ;'yep return
            ld a,(de)    ;'nope, AND the data together and give the fadeaway effect
            and (hl)
            ld (de),a
            jr CLScloop    ;'keep going
        CLSend1:
    end asm
end sub

Print this item

  first attempt on trying to make an msx1 .rom from zxbasic
Posted by: nitrofurano - 03-18-2012, 03:41 PM - Forum: Wishlist - Replies (8)

hi again!

Finally, i tried my first attempt, unsuccessfully, on trying to create a .rom msx file with Boriel's zxbasic compiler, based on what i started at <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:MSX">http://www.boriel.com/wiki/en/index.php/ZX_BASIC:MSX</a><!-- m --> . The idea for this test is only trying a simple thing like having a grey background and a red border, and clean the screen, nothing more, only for testing.

This can be frustrating at first, but maybe approaches like this can help on extending the target hardware, and how can help it being more flexible, as Boriel also wanted.

i tried with this:

code.bas

Code:
# include "lib/msx_color.bas"
# include "lib/msx1_cls.bas"
msxcolor(3,14,8)
msx1cls()
lp1:
  goto lp1

lib/msx_color.bas
Code:
sub msxcolor(vink,vpaper,vborder as ubyte)
  poke 0F3E9h,vink      :rem- forclr
  poke 0F3EAh,vpaper    :rem- bakclr
  poke 0F3EBh,vborder   :rem- borclr
  end sub

lib/msx1_cls.bas
Code:
sub msx1cls():
  asm
    call 00c3h   ;-cls
    end asm
  end sub

compileandcreaterom.sh (a bash script for creating the .rom file - sorry, i'm linux-only...)
Code:
#!/bin/bash
#- compiles a Boriel's zxbasic code to a 8kb msx .rom file
zxb.py code.bas
echo -e '\x41\x42\x04\x80\c' > _tmp.bin
cat code.bin >> _tmp.bin
echo -e 'somedescriptionoftheromfilehere' >> _tmp.bin
for i in {1..8192}; do echo -e '\x00\c' >> _tmp.bin; done
split -b 8k _tmp.bin
mv xaa code.rom
rm xab xac code.bin _tmp.bin
openmsx code.rom

maybe the .rom doesn't run because zxbasic-compiler puts some zxspectrum-based "garbage", that lacks this .rom can be executed, which i don't know how to optimize or walk around on this?

if someone here also have experience on coding on msx, any help is welcome.

btw, Boriel, how far were successful your attempts on creating amstrad-cpc with a similar method?

Print this item

  proportional text writing
Posted by: nitrofurano - 03-09-2012, 10:56 PM - Forum: Library - Replies (6)

i started to try proportional text writing on zxbasic - it's far incomplete (not printing from strings yet) and slow

test.bas

Code:
#include "lib/NaftaRegular_charmap.bas"
dim i,j,adr,v,vq,vq2,x,y,x1,x2,c,c1,xps as uinteger
border 6:paper 7:ink 1: bright 1:cls
x=3:y=109
for c1=0 to 52
  x1=int(x/8)
  x2=7-(x mod 8)
  for j=0 to 11
    i= ((y+j)*32)+x1
    adr=(16384+((i band 31) bor ((i band 224)*8) bor ((i band 1793)/8) bor (i band 6144)))
    v=peek(uinteger, adr)
    vq2=(peek(@naftaregularcharmap+(12*c1)+j))*(2^x2)
    vqbs= ((vq2 band 65280)/256) bor ((vq2 band 255)*256)
    poke uinteger adr,v bor vqbs
    next j
  x=x+peek(@naftaregularcharmapspacing+c1)  
  next c1
pause 0

lib/NaftaRegular_charmap.bas
Code:
goto naftaregularcharmapend

naftaregularcharmap:
asm
  defb 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,080h,080h,080h,080h,000h,080h,000h,000h,000h,000h
  defb 0a0h,0a0h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,050h,0f8h,050h,050h,0f8h,050h,000h,000h,000h,000h
  defb 040h,040h,0e0h,0c0h,0c0h,060h,060h,0e0h,040h,040h,000h,000h
  defb 000h,000h,048h,0b0h,050h,028h,034h,048h,000h,000h,000h,000h
  defb 000h,000h,020h,050h,064h,094h,088h,076h,000h,000h,000h,000h
  defb 080h,080h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  defb 020h,040h,040h,080h,080h,080h,080h,080h,080h,040h,040h,020h
  defb 080h,040h,040h,020h,020h,020h,020h,020h,020h,040h,040h,080h
  defb 000h,040h,0e0h,0a0h,000h,000h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,040h,0e0h,040h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,000h,000h,000h,040h,040h,080h,000h,000h
  defb 000h,000h,000h,000h,000h,0c0h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,000h,000h,000h,080h,000h,000h,000h,000h
  defb 000h,000h,010h,020h,020h,040h,040h,080h,000h,000h,000h,000h
  defb 000h,000h,060h,090h,090h,090h,090h,060h,000h,000h,000h,000h
  defb 000h,000h,0c0h,040h,040h,040h,040h,040h,000h,000h,000h,000h
  defb 000h,000h,060h,010h,010h,020h,040h,0f0h,000h,000h,000h,000h
  defb 000h,000h,060h,010h,020h,010h,010h,0e0h,000h,000h,000h,000h
  defb 000h,000h,020h,060h,060h,0a0h,0f0h,020h,000h,000h,000h,000h
  defb 000h,000h,060h,040h,060h,010h,010h,0e0h,000h,000h,000h,000h
  defb 000h,000h,020h,040h,0e0h,090h,090h,060h,000h,000h,000h,000h
  defb 000h,000h,0f0h,010h,020h,020h,040h,040h,000h,000h,000h,000h
  defb 000h,000h,060h,090h,060h,090h,090h,060h,000h,000h,000h,000h
  defb 000h,000h,060h,090h,090h,070h,020h,040h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,080h,000h,000h,080h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,040h,000h,000h,040h,040h,080h,000h,000h
  defb 000h,000h,000h,000h,040h,080h,040h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,0e0h,000h,0e0h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,080h,040h,080h,000h,000h,000h,000h,000h
  defb 000h,000h,060h,090h,020h,040h,000h,040h,000h,000h,000h,000h
  defb 000h,000h,03ch,042h,099h,0a9h,0a9h,0beh,040h,03ch,000h,000h
  defb 000h,000h,010h,028h,028h,044h,07ch,082h,000h,000h,000h,000h
  defb 000h,000h,0c0h,0a0h,0c0h,0a0h,0a0h,0c0h,000h,000h,000h,000h
  defb 000h,000h,038h,040h,080h,080h,040h,038h,000h,000h,000h,000h
  defb 000h,000h,0e0h,090h,088h,088h,090h,0e0h,000h,000h,000h,000h
  defb 000h,000h,0c0h,080h,0c0h,080h,080h,0c0h,000h,000h,000h,000h
  defb 000h,000h,0c0h,080h,0c0h,080h,080h,080h,000h,000h,000h,000h
  defb 000h,000h,038h,040h,080h,08ch,044h,03ch,000h,000h,000h,000h
  defb 000h,000h,088h,088h,0f8h,088h,088h,088h,000h,000h,000h,000h
  defb 000h,000h,080h,080h,080h,080h,080h,080h,000h,000h,000h,000h
  defb 000h,000h,040h,040h,040h,040h,040h,040h,040h,080h,000h,000h
  defb 000h,000h,0a0h,0c0h,0c0h,0a0h,0a0h,090h,000h,000h,000h,000h
  defb 000h,000h,080h,080h,080h,080h,080h,0c0h,000h,000h,000h,000h
  defb 000h,000h,044h,044h,06ch,0aah,092h,092h,000h,000h,000h,000h
  defb 000h,000h,084h,0c4h,0a4h,094h,08ch,084h,000h,000h,000h,000h
  defb 000h,000h,030h,048h,084h,084h,048h,030h,000h,000h,000h,000h
  defb 000h,000h,0c0h,0a0h,0a0h,0c0h,080h,080h,000h,000h,000h,000h
  defb 000h,000h,030h,048h,084h,084h,048h,030h,00ch,003h,000h,000h
  defb 000h,000h,0c0h,0a0h,0a0h,0c0h,0a0h,098h,000h,000h,000h,000h
  defb 000h,000h,060h,080h,040h,020h,010h,0e0h,000h,000h,000h,000h
  defb 000h,000h,0f8h,020h,020h,020h,020h,020h,000h,000h,000h,000h
  defb 000h,000h,088h,088h,088h,088h,088h,070h,000h,000h,000h,000h
  defb 000h,000h,082h,044h,044h,028h,028h,010h,000h,000h,000h,000h
  defb 000h,000h,0a2h,055h,055h,02ah,02ah,014h,000h,000h,000h,000h
  defb 000h,000h,090h,090h,060h,060h,090h,090h,000h,000h,000h,000h
  defb 000h,000h,088h,050h,020h,020h,020h,020h,000h,000h,000h,000h
  defb 000h,000h,0fch,008h,010h,020h,040h,0fch,000h,000h,000h,000h
  defb 0c0h,080h,080h,080h,080h,080h,080h,080h,080h,080h,080h,0c0h
  defb 000h,000h,080h,040h,040h,020h,020h,010h,000h,000h,000h,000h
  defb 0c0h,040h,040h,040h,040h,040h,040h,040h,040h,040h,040h,0c0h
  defb 000h,040h,0a0h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,000h,000h,000h,000h,000h,0fch,000h,000h
  defb 000h,080h,040h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,060h,020h,0e0h,0f0h,000h,000h,000h,000h
  defb 080h,080h,080h,080h,0a0h,0d0h,090h,0e0h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,060h,080h,080h,060h,000h,000h,000h,000h
  defb 010h,010h,010h,010h,050h,0b0h,090h,070h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,060h,0f0h,080h,060h,000h,000h,000h,000h
  defb 000h,030h,040h,040h,0e0h,040h,040h,040h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,03ch,048h,048h,070h,098h,064h,098h,060h
  defb 080h,080h,080h,080h,0a0h,0d0h,090h,090h,000h,000h,000h,000h
  defb 000h,000h,080h,000h,080h,080h,080h,080h,000h,000h,000h,000h
  defb 000h,000h,040h,000h,040h,040h,040h,040h,040h,040h,040h,080h
  defb 080h,080h,080h,080h,0a0h,0c0h,0a0h,090h,000h,000h,000h,000h
  defb 080h,080h,080h,080h,080h,080h,080h,080h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,0a4h,0dah,092h,092h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,0a0h,0d0h,090h,090h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,060h,090h,090h,060h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,0a0h,0d0h,090h,0e0h,080h,080h,080h,080h
  defb 000h,000h,000h,000h,050h,0b0h,090h,070h,010h,010h,010h,010h
  defb 000h,000h,000h,000h,0a0h,0c0h,080h,080h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,060h,040h,030h,0e0h,000h,000h,000h,000h
  defb 000h,000h,040h,040h,0e0h,040h,040h,060h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,090h,090h,0b0h,050h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,088h,050h,050h,020h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,0aah,054h,054h,028h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,090h,060h,060h,090h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,088h,050h,050h,020h,020h,040h,040h,080h
  defb 000h,000h,000h,000h,0f0h,020h,040h,0f0h,000h,000h,000h,000h
  defb 020h,040h,040h,040h,040h,080h,040h,040h,040h,040h,040h,020h
  defb 080h,080h,080h,080h,080h,080h,080h,080h,080h,080h,080h,080h
  defb 080h,040h,040h,040h,040h,020h,040h,040h,040h,040h,040h,080h
  defb 000h,000h,000h,000h,050h,0a0h,000h,000h,000h,000h,000h,000h
  defb 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  end asm

naftaregularcharmapspacing:
asm
  defb 4,2,4,6,4,7,8,2,4,4,4,4,3,3,2,5
  defb 5,3,5,5,5,5,5,5,5,5,2,3,3,4,3,5
  defb 9,8,4,6,6,3,3,7,6,2,3,5,3,8,7,7
  defb 4,7,5,5,6,6,8,9,5,6,7,3,5,3,4,7
  defb 3,5,5,4,5,5,5,8,5,2,3,5,2,8,5,5
  defb 5,5,4,5,4,5,6,8,5,6,5,4,2,4,5,4
  end asm

naftaregularcharmapkerning:
asm
  defb "VA"
  defb 0FEh
  defb "AV"
  defb 0FEh
  end asm

naftaregularcharmapend:

Print this item

  BiFrost Multicolour engine.
Posted by: britlion - 03-07-2012, 08:09 PM - Forum: ZX Basic Compiler - Replies (52)

Not my work - but Einar Saukas has been tweaking ZXODUS.

<!-- m --><a class="postlink" href="http://www.worldofspectrum.org/forums/showthread.php?t=38179">http://www.worldofspectrum.org/forums/s ... hp?t=38179</a><!-- m -->

He's managed to shoehorn it working into ZX Basic too Smile

Print this item

  Sprinter 2000 Bios 2.12 Documentation
Posted by: LCD - 03-02-2012, 03:02 PM - Forum: Documentation - No Replies

Yesterday I found a old printout of the Sprinter 2000 BIOS 2.12 functions, I did the printout before the site folded. Unfortunaly the Informations are not available anywhere else on the Internet, so I scanned them to DJVU format and even if it looks like some thing was cropped out, I think, this informations will be very useful for making a Sprinter Target in ZXBC. So I uploaded it here:
<!-- m --><a class="postlink" href="http://min.us/mbk23elfOF">http://min.us/mbk23elfOF</a><!-- m -->
I do not have BIOS 3.0 functions...
I used DJVU because it produces files in size on 1/10 of PDF at much higher quality.
A very good reader for DJVU format can be downloaded here:
<!-- m --><a class="postlink" href="http://code.google.com/p/windjview-subpix/">http://code.google.com/p/windjview-subpix/</a><!-- m -->

Print this item

  Fill Routine
Posted by: britlion - 02-27-2012, 10:22 PM - Forum: How-To & Tutorials - Replies (36)

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

Print this item

  DEFB bug
Posted by: britlion - 02-27-2012, 09:54 PM - Forum: Help & Support - Replies (1)

You can enter hex as 80h or as $80.

But defb ddh doesn't seem to work. Was happy as defb $dd

Print this item

  Odd error
Posted by: britlion - 02-27-2012, 06:57 PM - Forum: Bug Reports - Replies (5)

This might be another float bug. I wrote up the distance algorithm na_th_an showed us. It seems to work - but in this test program, it's the floating point values that go wrong...

If you set your emulator to full speed, you see it looking for the biggest error it can find, showing larger errors as it finds them. Eventually it hits distance (250,56) which my function says is > 255 (so returns 255). The value calculated from square rooting in floats is...er 0. So that's an error of 255, apparently. Except the correct answer would be 256.1952 Is the int (256) returning 0 for some reason? On a float?

When I'm happy with this funtion, it will go in the function library as a code snippet.


Code:
FUNCTION fastcall distance (a as ubyte, b as ubyte) as uByte

' returns a fast approximation of SQRT (a^2 + b^2) - the distance formula, generated from taylor series expansion.

asm
POP DE ; return address
; First parameter in A
POP BC ; second parameter -> B

LD C,A ; Put second parameter in C for safekeeping.
LD HL,0

ADD A,B

LD L,A ; Put result in HL
RL H   ; Pull in carry bit if necessary.

LD A,B ; get original
CP C   ; compare with C
JP NC, distance_Cbigger
LD C,A ; B was smaller, so we replace the value in C with the smaller value in A
distance_Cbigger:
; C was smaller, so we leave it alone.

SRL C ; C=C/2

XOR A
LD B,A
SBC HL,BC ; take half our smallest from HL

SRL C
AND A ; Clear carry flag.
SBC HL,BC

SRL C
SRL C
AND A ; Clear carry flag.
ADD HL,BC

LD A,H
AND A
JP NZ, distance_toobig

LD A,L ; Get result.
EX DE,HL ; return address is in DE.
JP (HL)

distance_toobig:
; If the answer turns out to be > 255, we'll return 255.
LD A,255
EX DE,HL ; return address is in DE.
JP (HL)

END ASM

END FUNCTION

CLS
DIM i,imax as uByte
dim j,jmax as uByte
dim answer,realanswer as uByte
dim errorval,errorvalmax as float
imax=0
jmax=0
errorvalmax=0

for j=1 to 250
for i=1 to 250

answer=distance(i,j)
realanswer=SQR(CAST(float,i)*i+CAST(float,j)*j)
errorval=ABS(CAST(float,realanswer)-answer)

if errorval>errorvalmax then
PRINT i;" ";j;" ";answer;" ";INT realanswer; "   ";int errorval
imax=i
jmax=j
errorvalmax=errorval
end if
border j
next i
next j

Print this item

  mod with type float
Posted by: britlion - 02-27-2012, 06:49 PM - Forum: Bug Reports - Replies (1)

This seems to work backwards, giving division instead of remainder.

Code:
dim i as float
For i = 1 to 255
print int i
if i mod 22=0 then
pause 1
pause 0
cls
end if

next i

If you change the dim i as float to dim i as uinteger, it works perfectly, pausing each screen.

Print this item

  USR function (*solved*)
Posted by: britlion - 02-26-2012, 03:18 PM - Forum: Bug Reports - Replies (7)

We seem to have a regression with the latest version:

print USR "A" falls over:

Traceback (most recent call last):
File "zxb.py", line 312, in <module>
File "zxb.py", line 246, in main
File "zxbtrad.pyc", line 316, in traverse
File "zxbtrad.pyc", line 1286, in traverse
File "zxbtrad.pyc", line 593, in traverse
UnboundLocalError: local variable 'suffix' referenced before assignment
Build Failed!

Print this item