Skip to content

Commit 86ee5dc

Browse files
committed
gfxlib: palette [get] using
- when mapping 32 & 64 bit functions for PALETTE [GET] USING, check the data type pointed to choose one of LONG PTR, LONGINT PTR, INTEGER PTR - tests/gfx/palette.bas added to test PALETTE GET [USING] - add tests for BYREF pointer variables for palettes and image buffers
1 parent f081eea commit 86ee5dc

File tree

6 files changed

+345
-6
lines changed

6 files changed

+345
-6
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Version 1.06.0
7474
- #880: Overload binary operators now support covariant arguments, overloaded procedure resolution changed especially with respect to CONST and non-CONST parameters
7575
- Fix for debugging lines in include files but not in procedures. Filename debugging information added for module level statements in included files.
7676
- #699: fix new[0] causing infinite loop when calling constructor/destructor list
77+
- #883: when mapping 32 & 64 bit functions for PALETTE [GET] USING, check the data type pointed to and choose one of LONG PTR, LONGINT PTR, INTEGER PTR
7778

7879

7980
Version 1.05.0

src/compiler/parser-quirk-gfx.bas

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ end function
879879
''
880880
function cGfxPalette as integer
881881
dim as ASTNODE ptr arrayexpr, attexpr, rexpr, gexpr, bexpr
882-
dim as integer isget
882+
dim as integer isget, dptrsize
883883

884884
function = FALSE
885885

@@ -892,7 +892,19 @@ function cGfxPalette as integer
892892
errReport( FB_ERRMSG_EXPECTEDIDENTIFIER )
893893
exit function
894894
end if
895-
function = rtlGfxPaletteUsing( arrayexpr, isget )
895+
896+
'' Choose either the 32 or 64-bit version
897+
898+
assert( typeIsPtr( astGetDataType( arrayexpr ) ) )
899+
900+
'' get the size of the data pointed to
901+
dptrsize = typeGetSize( typeDeref( astGetDataType( arrayexpr ) ) )
902+
903+
if( dptrsize <> typeGetSize( FB_DATATYPE_LONG ) and dptrsize <> typeGetSize( FB_DATATYPE_LONGINT ) ) then
904+
dptrsize = typeGetSize( FB_DATATYPE_INTEGER )
905+
end if
906+
907+
function = rtlGfxPaletteUsing( arrayexpr, isget, (dptrsize = typeGetSize( FB_DATATYPE_LONGINT )) )
896908
else
897909
attexpr = NULL
898910
rexpr = NULL

src/compiler/rtl-gfx.bas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,15 +2015,16 @@ end function
20152015
function rtlGfxPaletteUsing _
20162016
( _
20172017
byval arrayexpr as ASTNODE ptr, _
2018-
byval isget as integer _
2018+
byval isget as integer, _
2019+
byval is64bit as integer _
20192020
) as integer
20202021

20212022
dim as ASTNODE ptr proc = any
20222023
dim as FBSYMBOL ptr f = any
20232024

20242025
function = FALSE
20252026

2026-
if( typeGetSize( astGetDataType( arrayexpr ) ) = 8 ) then
2027+
if( is64bit ) then
20272028
if( isget ) then
20282029
f = PROCLOOKUP( GFXPALETTEGETUSING64 )
20292030
else

src/compiler/rtl.bi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,8 @@ declare function rtlGfxPalette _
16551655
declare function rtlGfxPaletteUsing _
16561656
( _
16571657
byval arrayexpr as ASTNODE ptr, _
1658-
byval isget as integer _
1658+
byval isget as integer, _
1659+
byval is64bit as integer _
16591660
) as integer
16601661

16611662
declare function rtlGfxPut _

tests/gfx/image-expr.bas

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ SUITE( fbc_tests.gfx.image_expr )
125125
CU_ASSERT( hImageIsFilledWithColor( a, rgb(255,0,0) ) )
126126
hResetImageToBlack( a )
127127

128-
'' TODO: Palette Using
128+
'' Palette Get Using is in tests/gfx/palette.bas
129129

130130
CU_ASSERT( hImageIsFilledWithColor( b, rgb(255,0,0) ) )
131131
put a, (0, 0), b, pset
@@ -212,6 +212,12 @@ SUITE( fbc_tests.gfx.image_expr )
212212
'' @array(0)
213213
line @array(0), (0, 0) - (SCREEN_W-1, SCREEN_H-1), rgb(255,0,0), bf
214214
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(255,0,0) ) )
215+
216+
'' byref pointer = @array(0)
217+
var array0idx = @array(0)
218+
var byref array0 = array0idx
219+
line array0, (0, 0) - (SCREEN_W-1, SCREEN_H-1), rgb(0,0,255), bf
220+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,0,255) ) )
215221
end scope
216222

217223
'' array on heap:
@@ -235,6 +241,12 @@ SUITE( fbc_tests.gfx.image_expr )
235241
'' @array(0)
236242
line @array(0), (0, 0) - (SCREEN_W-1, SCREEN_H-1), rgb(255,0,0), bf
237243
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(255,0,0) ) )
244+
245+
'' byref pointer = @array(0)
246+
var array0idx = @array(0)
247+
var byref array0 = array0idx
248+
line array0, (0, 0) - (SCREEN_W-1, SCREEN_H-1), rgb(0,0,255), bf
249+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,0,255) ) )
238250
end scope
239251

240252
'' dynamic array, descriptor on stack:
@@ -258,6 +270,12 @@ SUITE( fbc_tests.gfx.image_expr )
258270
'' @array(0)
259271
line @array(0), (0, 0) - (SCREEN_W-1, SCREEN_H-1), rgb(255,0,0), bf
260272
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(255,0,0) ) )
273+
274+
'' byref pointer = @array(0)
275+
var array0idx = @array(0)
276+
var byref array0 = array0idx
277+
line array0, (0, 0) - (SCREEN_W-1, SCREEN_H-1), rgb(0,0,255), bf
278+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,0,255) ) )
261279
end scope
262280

263281
'' array field:
@@ -304,6 +322,11 @@ SUITE( fbc_tests.gfx.image_expr )
304322
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array(0)
305323
CU_ASSERT( hImageIsFilledWithColor( array(0), rgb(0,255,0) ) )
306324

325+
'' GET into pointer from byref array access
326+
var byref array0 = array(0)
327+
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array0
328+
CU_ASSERT( hImageIsFilledWithColor( array(0), rgb(0,255,0) ) )
329+
307330
imagedestroy( array(0) )
308331
end scope
309332

@@ -365,6 +388,12 @@ SUITE( fbc_tests.gfx.image_expr )
365388
'' @array(0)
366389
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), @array(0)
367390
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
391+
392+
'' byref pointer = @array(0)
393+
var array0idx = @array(0)
394+
var byref array0 = array0idx
395+
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array0
396+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
368397
end sub
369398

370399
private sub hTestUdtWithMatchingCastArrayTarget( )
@@ -376,9 +405,20 @@ SUITE( fbc_tests.gfx.image_expr )
376405
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array
377406
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
378407

408+
'' array(0)
409+
'' not tested, cast() is known to be used in this case
410+
379411
'' @array(0)
380412
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), @array(0)
381413
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
414+
415+
'' byref pointer = @array(0)
416+
var array0idx = @array(0)
417+
var byref array0 = array0idx
418+
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array0
419+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
420+
421+
382422
end sub
383423

384424
'' GET from screen into some array...
@@ -433,6 +473,15 @@ SUITE( fbc_tests.gfx.image_expr )
433473
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
434474
end scope
435475

476+
'' byref pointer = @array(0)
477+
scope
478+
dim array(0 to IMAGE_BUFFER_SIZE-1) as ubyte
479+
var array0idx = @array(0)
480+
var byref array0 = array0idx
481+
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array0
482+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
483+
end scope
484+
436485
'' @array(1)
437486
scope
438487
dim array(0 to IMAGE_BUFFER_SIZE+1-1) as ubyte
@@ -540,6 +589,15 @@ SUITE( fbc_tests.gfx.image_expr )
540589
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
541590
end scope
542591

592+
'' byref pointer = @array(0)
593+
scope
594+
dim array(0 to (IMAGE_BUFFER_SIZE\4)-1) as ulong
595+
var array0idx = @array(0)
596+
var byref array0 = array0idx
597+
get (0, 0) - (SCREEN_W-1, SCREEN_H-1), array0
598+
CU_ASSERT( hImageIsFilledWithColor( @array(0), rgb(0,255,0) ) )
599+
end scope
600+
543601
'' array(1)
544602
scope
545603
dim array(0 to (IMAGE_BUFFER_SIZE\4)+1-1) as ulong

0 commit comments

Comments
 (0)