Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optimiser -o3 bug found (*solved*)
#1
Hi Boriel,

I have found a bug with -o3 optimiser (-o2 works well)
In following code (not fully finished yet) in -o3 mode not all chess Figures are displayed. The figures are named in german as they are just placeholders for graphics that will be added later.

Oh, just noticed that also the binary operator shortcuts (|, &, ...) are not working too (yet).

Code:
' Blind King (c) 2010 By LCD, written using BorIDE and ZXBC
FUNCTION attrAddress(x as uByte, y as uByte) as uInteger              
';; This function returns the memory address of the Character Position
';; x,y in the attribute screen memory.
';; Adapted from code by Jonathan Cauldwell - Adapted for ZX BASiC by Britlion from Na_TH_AN's fourspriter
asm
    ld      a,(IX+7)        ;ypos
    rrca
    rrca
    rrca               ;' Multiply by 32
    ld      l,a        ;' Pass to L
    and     3          ;' Mask with 00000011
    add     a,88       ;' 88 * 256 = 22528 - start of attributes.
    ld      h,a        ;' Put it in the High Byte
    ld      a,l        ;' We get y value *32
    and     224        ;' Mask with 11100000
    ld      l,a        ;' Put it in L
    ld      a,(IX+5)   ;' xpos
    add     a,l        ;' Add it to the Low byte
    ld      l,a        ;' Put it back in L, and we're done. HL=Address.
end asm

END FUNCTION
FUNCTION scrAddress(x as uByte, y as uByte) as Uinteger
asm
;' This fn 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

         ; x Arrives in A, y is in stack.
         and     31
         ld      l,a
         ld      a,(IX+7) ; Y value
         ld      d,a
         and     24
         add     a,64
         ld      h,a
         ld      a,d
         and     7
         rrca
         rrca
         rrca
         or      l
         ld      l,a
              
end asm
END FUNCTION
sub putblock(x as Ubyte,y as ubyte,wid as ubyte,hgt as ubyte,adr as Uinteger)
    dim scr,attribute as Uinteger
    dim x1,y1 as Ubyte
    dim a as Ubyte
    poke uinteger @putblock1+7,wid
    poke uinteger @putblock2+7,wid
    for y1=0 to hgt-1
        scr=scrAddress(x,y+y1)
        for a=0 to 7
            poke uinteger @putblock1+1,adr
            poke uinteger @putblock1+4,scr
            putblock1:
            asm
                ld hl,1
                ld de,2
                ld bc,3
                ldir
            end asm
            adr=adr+wid
            scr=scr+256
        next a
    next y1
    attribute=attrAddress(x,y)
    for y1=0 to hgt-1
        poke uinteger @putblock2+1,adr
        poke uinteger @putblock2+4,attribute
        adr=adr+wid
        attribute=attribute+32
        putblock2:
        asm
            ld hl,4
            ld de,5
            ld bc,6
            ldir
        end asm
    next y1
End sub
function ScanField(x as integer,y as integer,mask as ubyte) as ubyte
    if x>=0 and x<8 and y>=0 and y<8 then
        adr=@overlay+(y<<3)+x
        return peek adr band mask
    Else
        return 0
    end if
end function
sub SetField(x as uinteger,y as uinteger,fig as ubyte)
    dim adr as uinteger
    adr=@overlay+(y<<3)+x
    poke adr,(peek adr) bor fig
end sub



function ScanDiagonal(x as ubyte,y as ubyte) as ubyte
    dim dist,found,d1,d2,d3,d4 as ubyte
  while found=0
        
    end while
'This scans diagonal fields from x,y until figure or end of field for queen or bishop

end Function
function ScanStraight(x as ubyte,y as ubyte) as ubyte
'This scans straight fields until figure or end of field for queen or rook

end Function
function ScanNear(x as ubyte,y as ubyte) as ubyte
'This scans next fields of x,y until figure for king or pawn
  dim result as ubyte
  if ScanField(x-1,y-1,7)=1 or ScanField(x+1,y-1,7)=1 then result=1:end if
    if ScanField(x-1,y-1,7)=6 or ScanField(x,y-1,7)=6 or ScanField(x+1,y-1,7)=6 or ScanField(x-1,y,7)=6 or ScanField(x+1,y,7)=6 or ScanField(x-1,y+1,7)=6 or ScanField(x,y+1,7)=6 or ScanField(x+1,y+1,7)=6 then result=result bor 32:end if
    return result
end Function
function ScanKnight(x as ubyte,y as ubyte) as ubyte
'This scans field x,y if attacked by knight
    dim result as ubyte
    if ScanField(x-1,y-2,7)=3 or ScanField(x+1,y-2,7)=3    or ScanField(x-1,y+2,7)=3 or ScanField(x+1,y+2,7)=3    or ScanField(x-2,y-1,7)=3 or ScanField(x+2,y-1,7)=3    or ScanField(x-2,y+1,7)=3 or ScanField(x+2,y+1,7)=3 then result=3:end if
    return result    
end Function

function ScanFields(x as ubyte,y as ubyte) as ubyte
'This scans all fields, first: diagonal for queen or bishop until figure or end of field
print at 0,24;ScanNear(x,y);"  ";
print at 1,24;ScanKnight(x,y);"  ";




end Function


paper 0:ink 6:bright 1:flash 0:border 2:cls
'print at 0,0;"\{i7}\{p1}Blind King 2010 By LCD"
dim x,y,x1,y1,col,a,left,posx,posy as ubyte
dim scr,adr as uinteger

print at 23,0;"Press any key to start battle"
pause 0
randomize
cls
adr=@chessboard
for y=0 to 7
    for x=0 to 7
        col=peek(adr)
        for y1=0 to 2
            scr=attrAddress(x*3,y*3+y1)
            poke scr,col:poke scr+1,col:poke scr+2,col
        next y1
        adr=adr+1
    next x
next y
' Setup field

left=8 'Bauern
while left>0
    x=int(rnd*7.9999)
    y=int(rnd*6.9999)
    if ScanField(x,y,7)=0 then
        SetField(x,y,1)
        left=left-1
    end If
end while
    
left=2 'Türme
while left>0
    x=int(rnd*7.9999)
    y=int(rnd*6.9999)
    if ScanField(x,y,7)=0 then
        SetField(x,y,2)
        left=left-1
    end If
end while

left=2 'Springer
while left>0
    x=int(rnd*7.9999)
    y=int(rnd*6.9999)
    if ScanField(x,y,7)=0 then
        SetField(x,y,3)
        left=left-1
    end If
end while

left=2 'Läufer
while left>0
    x=int(rnd*7.9999)
    y=int(rnd*6.9999)
    if ScanField(x,y,7)=0 then
        SetField(x,y,4)
        left=left-1
    end If
end while

left=1 'Dame
while left>0
    x=int(rnd*7.9999)
    y=int(rnd*6.9999)
    if ScanField(x,y,7)=0 then
        SetField(x,y,5)
        left=left-1
    end If
end while
left=1 'König
while left>0
    x=int(rnd*7.9999)
    y=int(rnd*6.9999)
    if ScanField(x,y,7)=0 then
        SetField(x,y,6)
        left=left-1
    end If
end while


' Display field (test)
for y=0 to 7
    for x=0 to 7
        a=ScanField(x,y,7)
        x1=x*3+1
        y1=y*3+1
        if a=1 then print at y1,x1;"B";:end If
        if a=2 then print at y1,x1;"T";:end If
        if a=3 then print at y1,x1;"S";:end If
        if a=4 then print at y1,x1;"L";:end If
        if a=5 then print at y1,x1;"D";:end If
        if a=6 then print at y1,x1;"K";:end If
    next x
next y


posx=7:posy=7


Mainloop:
x1=posx*3+1
y1=posy*3+1
print at y1,x1;"F";

if inkey$="o" and posx>0 then print at y1,x1;" ";:posx=posx-1:ScanFields(posx,posy):end if
if inkey$="p" and posx<7 then print at y1,x1;" ";:posx=posx+1:ScanFields(posx,posy):end if
if inkey$="q" and posy>0 then print at y1,x1;" ";:posy=posy-1:ScanFields(posx,posy):end if
if inkey$="a" and posy<7 then print at y1,x1;" ";:posy=posy+1:ScanFields(posx,posy):end if
goto Mainloop


'pause 0
End




chessboard:
asm
    defb 32,64,32,64,32,64,32,64
    defb 64,32,64,32,64,32,64,32
    defb 32,64,32,64,32,64,32,64
    defb 64,32,64,32,64,32,64,32
    defb 32,64,32,64,32,64,32,64
    defb 64,32,64,32,64,32,64,32
    defb 32,64,32,64,32,64,32,64
    defb 64,32,64,32,64,32,64,32
    

end asm

overlay:
'0=Leer
'1=Bauer
'2=Turm
'3=Springer
'4=Läufer
'5=Königin
'6=König


'+128=hidden
'+64=White field
'+32=Black field
asm
    defb 56,80,56,80,56,80,56,80
    defb 80,56,80,56,80,56,80,56
    defb 56,80,56,80,56,80,56,80
    defb 80,56,80,56,80,56,80,56
    defb 56,80,56,80,56,80,56,80
    defb 80,56,80,56,80,56,80,56
    defb 56,80,56,80,56,80,56,80
    defb 80,56,80,56,80,56,80,56
end asm
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#2
LCD Wrote:Hi Boriel,

I have found a bug with -o3 optimiser (-o2 works well)
In following code (not fully finished yet) in -o3 mode not all chess Figures are displayed. The figures are named in german as they are just placeholders for graphics that will be added later.
There seems to be another bug in the peephole optimizer. Will check it out...

LCD Wrote:Oh, just noticed that also the binary operator shortcuts (|, &, ...) are not working too (yet).
Damn! :evil: I forgot to include them! :oops: (fixing)
Reply
#3
I think I catched it! Please, download version 1.2.8s682 and tell me if -O3 works now (it should). :roll:
Reply
#4
All my tests seem to be working fine with the new version, and as a bonus my main game project will now compile again with -O3! It didn't before (I'm not sure if I mentioned it or not), but I hadn't tried compiling it with -O3 in earlier versions so I didn't know if it was a regression or not. Regardless, it's fixed! Thumbs up! :-)
Reply
#5
Confirmation: Chessboard Attacks now compiles with -o3 and no other problems arisen until now. Great, Boriel!!! Thank you.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)