BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
The VGA file is not a bitmap, it is a memory dump created using BSAVE.
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
I may be mistaken but I thought the 'Put' statement needs a bmp format image (buffer).
If that is the case then dodicats code stood no chance of working for you. It uses the 'Put' command to put your data into an image buffer.
I am reduced to guessing and its my guess that its the .vga format file that is the source of the problem.
Additional info:
Part way down the page is discussed image buffer format In QB dialect it is the old style header.
http://www.freebasic.net/wiki/wikka.php ... nalFormats
Then there is the 'imageinfo' command to get image info. In QB you have to access it via __imageinfo:
http://www.freebasic.net/wiki/wikka.php ... gImageInfo
It seems to me that you will surely need to load the data and then convert it into an image buffer that fb(qb) can use.
If that is the case then dodicats code stood no chance of working for you. It uses the 'Put' command to put your data into an image buffer.
I am reduced to guessing and its my guess that its the .vga format file that is the source of the problem.
Additional info:
Part way down the page is discussed image buffer format In QB dialect it is the old style header.
http://www.freebasic.net/wiki/wikka.php ... nalFormats
Then there is the 'imageinfo' command to get image info. In QB you have to access it via __imageinfo:
http://www.freebasic.net/wiki/wikka.php ... gImageInfo
It seems to me that you will surely need to load the data and then convert it into an image buffer that fb(qb) can use.
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
Have you ever tried to load the image file directly on the screen?
Code: Select all
#lang "qb"
Screen 12
Bload "mtn.vga"
Sleep
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
QBASIC's BSAVE format has a 7 byte header: &HFD, followed by the memory segment and pointer of the memory saved (VARSEG:VARPTR), followed by a 16-bit unsigned integer for the size.
If you BSAVE'd a full Screen 13 using something like:Then the file would look like 'FD 00 A0 00 00 00 FA' (or CHR$(&HFD) + MKI$(&HA000) + MKI$(0) + MKI$(64000)), followed by 64000 bytes (320*200 8-bit pixels) making up the image.
FB's BLOAD does support QBASIC BSAVE files, but it interprets them as chunks of memory, not as images.
This means you can't just do:
(For some reason this just gives me a white screen.)
But you can do this:
There is also, apparently, support for QB SCREEN 13 images that have been saved to arrays using GET. These have an additional four-byte header holding the dimensions of the image (width*8, then height, for SCREEN 13).
This is almost compatible with FB's old-style header, except FB stores the bytes per pixel in the lower 3 bits of the width.
For the QB SCREEN 13 images, this is effectively 0, which FB's PUT interprets as the bytes per pixel of the target screen.
Therefore, if you save a QB SCREEN 13 image with code like this:
You can actually load it in FB with code like this:
If you BSAVE'd a full Screen 13 using something like:
Code: Select all
SCREEN 13
DEF SEG = &HA000
BSAVE "TEST.BSV", 0, 64000
FB's BLOAD does support QBASIC BSAVE files, but it interprets them as chunks of memory, not as images.
This means you can't just do:
Code: Select all
screen 13
bload "TEST.BSV"
But you can do this:
Code: Select all
screen 13
screenlock
bload "TEST.BSV", screenptr()
screenunlock
sleep
This is almost compatible with FB's old-style header, except FB stores the bytes per pixel in the lower 3 bits of the width.
For the QB SCREEN 13 images, this is effectively 0, which FB's PUT interprets as the bytes per pixel of the target screen.
Therefore, if you save a QB SCREEN 13 image with code like this:
Code: Select all
SCREEN 13
CONST w = 13, h = 13, size = 4 + w * h
DIM a(1 TO (size+1)\2) AS INTEGER
GET (0, 0)-(w - 1, h - 1), a(1)
DEF SEG = VARSEG(a(1))
BSAVE "TEST.BSV", VARPTR(a(1)), size
Code: Select all
screen 13
dim as integer a(1 to 99999)
bload "TEST.BSV", @a(1)
put (0, 0), a(1)
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
If your file (saved by bsave) is not necessarily a bitmap, and you don't know it's size, then you could estimate the size before bload.davidshq wrote:The VGA file is not a bitmap, it is a memory dump created using BSAVE.
Code: Select all
#lang "qb"
#include "file.bi"
#if __FB_LANG__ <> "qb"
#define __sizeof sizeof
#define __typeof typeof
#endif
Type datatype As double
Screen 20
Dim As Integer k
Dim As Integer n
k=123
Dim As datatype a(1 To k)
Print "Original, size= ";k
For n =1 To k
a(n)=(Rnd*n)
Print a(n);
Next n
Print
Dim As Integer size,mem
size=__sizeof(__typeof(a))*(Ubound(a)-Lbound(a)+1)
dim as string filename
filename="something.vga"
Bsave filename,@a(Lbound(a)),size
'estimate the file size
if fileexists(filename) then
mem=filelen("something.vga")
mem= mem/__sizeof(datatype)-1
else
print filename; " not found"
sleep
end
end if
print
print "Estimated size from bsave = "; mem
print
dim as datatype b(1 to mem) 'to recieve the file
Bload "something.vga",@b(Lbound(b))
Print "Bsaved then Bloaded"
Print
For n=Lbound(b) To Ubound(b)
Print b(n);
Next n
'''Put(0,0),@b(1)
Kill "something.vga"
Sleep
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
The estimate of file size also works for bitmaps (#lang qb or fb)/32/64 bit.
Code: Select all
#lang "qb"
#include "file.bi"
#if __FB_LANG__ <> "qb"
#define __sizeof sizeof
#define __typeof typeof
#define __ulong ulong
#define __ubyte ubyte
#endif
Sub Tree(x1 As Single,y1 As Single,size As Single,angle As Single,depth As Single,colb As __ulong=0,colL As __ulong=0)
Dim As Single spread,scale,x2,y2
spread=25
scale=.76
#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
x2=x1-.25*size*Cos(angle*.01745329)
y2=y1-.25*size*Sin(angle*.01745329)
Static As Integer count,fx,fy,sz,z
If count=0 Then fx=x1:fy=y1:sz=size:z=2^(depth+1)-1
Line (x1,y1)-(x2,y2),colb
If count=0 Then fx=x2:fy=y2:sz=size
count=count+1
If count>z Then count=0
If incircle(fx,fy,(.45*sz),x2,y2)=0 Then Circle (x2,y2),.01*sz,colL
If depth>0 Then
Tree(x2, y2, size * Scale, angle - Spread, depth - 1,colB,colL)
Tree(x2, y2, size * Scale, angle + Spread, depth - 1,colB,colL)
End If
End Sub
Type datatype As __ubyte
Screen 19
'draw on the screen
line(20,20)-(300,300),7,bf
Tree(180,250,200,80,12,0,6)
'======================
Dim As Integer n
dim as string filename
filename="tree.bmp"
bsave "tree.bmp",0
cls
Dim As __ulong mem
'estimate the file size
if fileexists(filename) then
mem=filelen(filename)
mem= mem/__sizeof(datatype)-1
else
print filename; " not found"
sleep
end
end if
print
locate 22
print "Estimated size from bsave = "; mem
print
redim as datatype b(1 to mem) 'to recieve the file
Bload filename,@b(Lbound(b)) 'fill the array
Print "Bsaved then Bloaded and put on screen by an array"
Print
Put(0,0),@b(1)
Kill "tree.bmp"
Sleep
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
Maybe you can also share the/a file causing the problem you describe so BLOAD could be fixed so that it doesn't cause any crash anymore, no matter what file is passed to it.
Do you have checked BLOAD's return code? Be sure it returns zero (0) (if it does not crash beforehand).
Do you have checked BLOAD's return code? Be sure it returns zero (0) (if it does not crash beforehand).
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
@sancho2 - Thanks for the thread links, I'll take a look.
@fxm - I did now, it loads but it isn't loaded correctly e.g., it looks like static.
@counting_pine - Still looks like static even with your code. :-/
@dodicat - When I run that I get a response of Original, size = 123 followed by a long series of numbers, the first few are: 0.7055475115776062 1.066848039627075
It is the same result from bsave.
@St_W - I've uploaded two examples:
http://www.davemackey.net/share_files/MTN.VGA
http://www.davemackey.net/share_files/FACE1.VGA
Thanks everyone for your help!
@fxm - I did now, it loads but it isn't loaded correctly e.g., it looks like static.
@counting_pine - Still looks like static even with your code. :-/
@dodicat - When I run that I get a response of Original, size = 123 followed by a long series of numbers, the first few are: 0.7055475115776062 1.066848039627075
It is the same result from bsave.
@St_W - I've uploaded two examples:
http://www.davemackey.net/share_files/MTN.VGA
http://www.davemackey.net/share_files/FACE1.VGA
Thanks everyone for your help!
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
Both files begin with FD as Counting Pine described in his post. But like you I get random dots instead of any kind of image.
You say this is a project you are migrating? Do you have the code which was used to create the vga files?
You say this is a project you are migrating? Do you have the code which was used to create the vga files?
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
@sancho - Unfortunately, I do not have the code that made the original images. FYI, I have been able to convert the files to jpg using deark, so it seems the data is valid...I had hoped I could have the image drawn on screen for nostalgia, but it looks like the easy solution now is to just use the jpg.
Dave
Dave
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
Hi davidshq,
just a warning: .jpg cannot be loaded with BLoad (only with .bmp possible).
Except you are going to use (yet) another Library to load .jpg.
just a warning: .jpg cannot be loaded with BLoad (only with .bmp possible).
Except you are going to use (yet) another Library to load .jpg.
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
But have you any original QB (Quick Basic) code which loads that image (QB instructions around the screen mode used, around the image loading, ...)?davidshq wrote:@sancho - Unfortunately, I do not have the code that made the original images.
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
I tried DEARK and XNconvert with face1.vga.
The format is not recognised.
.vga, files seem to be os/2 bitmaps.
So Quickbasic 7 (pds version) would do this OK.
If I load the file as prevoiusly coded viz:
I get a 5 X 65 (approx) spread of pixels, some of which are missing.
In other words, the PUT array from FreeBASIC's bload doesn't do this time.
The format is not recognised.
.vga, files seem to be os/2 bitmaps.
So Quickbasic 7 (pds version) would do this OK.
If I load the file as prevoiusly coded viz:
Code: Select all
#lang "qb"
#include "file.bi"
#if __FB_LANG__ <> "qb"
#define __sizeof sizeof
#define __typeof typeof
#define __ulong ulong
#define __ubyte ubyte
#define __screenunlock screenunlock
#define __screenlock screenlock
#define __getmouse getmouse
#define __zstring zstring
#define __ptr ptr
#endif
declare function puts cdecl alias "puts"(byval as __zstring __ptr) as long
Sub Magnify()
#define resetwheel(w,fl) fl=w
#define wheel(w,f) w-f
dim mx as long
dim my as long
dim mw as long
dim newx as single
dim newy as single
dim button as long
__Getmouse mx,my,mw,button
Static As Integer flag,pmw
mw=(mw/2)
If button=4 Then resetwheel(mw,flag)
Dim As long array(1 To 6561),count
pmw=wheel(mw,flag)
if pmw<=1 then exit sub
For z As Integer=1 To 2
For x As Integer=mx-40 To mx+40
For y As Integer=my-40 To my+40
count+=1
If z=1 Then array(count)=Point(x,y)
If z=2 Then
NewX=pmw*(x-mx)+mx: NewY=pmw*(y-my)+my
line(newx-pmw/2,newy-pmw/2)-(newx+pmw/2,newy+pmw/2),array(count),bf
End If
Next y
Next x
count=0
Next z
Line(mx-pmw*40,my-pmw*40)-(mx+pmw*40,my+pmw*40),5,B
End Sub
Screen 19
color ,7+8
Type datatype As __ulong
Dim As Integer n
Dim As long mem
dim as string filename
filename="face1.vga"
if fileexists(filename) then
mem=filelen(filename)
mem= mem/__sizeof(datatype)-1
else
print filename; " not found"
sleep
end
end if
puts "Estimated size = " & mem
dim as datatype b(1 to mem) 'to recieve the file
Bload filename,@b(Lbound(b))
dim accum as string
For n=Lbound(b) To Ubound(b)
' puts str$(b(n))
accum+=str$(b(n))
Next n
puts accum
do
__screenlock
cls
Put(400,300),@b(1)
draw string(10,10),"Use mouse wheel to magnify:",0
'line(350,300)-(350,365),0
magnify
__screenunlock
sleep 1,1
loop until inkey$ =chr$(27)
'Kill "something.vga"
Sleep
In other words, the PUT array from FreeBASIC's bload doesn't do this time.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
OK, the files are actually Screen 12 images, which uses a different format.
Instead of 1 byte per pixel, each row is divided up into 4 planes. Each plane contains a whole row of data using 1 bit per pixel, and then the planes are combined together. Roughly speaking, in the EGA palette, the planes represent 4 channels: blue, green, red and intensity (grey).
Anyway, the images work fine in QBASIC with GET/PUT in SCREEN 12:
FB has no native support for this kind of image, so we have to roll our own code:
(A final important detail when unpacking planes: the bits for each pixel are stored in the byte from most to least significant.)
Instead of 1 byte per pixel, each row is divided up into 4 planes. Each plane contains a whole row of data using 1 bit per pixel, and then the planes are combined together. Roughly speaking, in the EGA palette, the planes represent 4 channels: blue, green, red and intensity (grey).
Anyway, the images work fine in QBASIC with GET/PUT in SCREEN 12:
Code: Select all
SCREEN 12
CONST file = "mtn.vga"
DIM a(999) AS LONG 'roughly 4KB
DEF SEG = VARSEG(a(0))
BLOAD file, VARPTR(a(0))
PUT (0, 0), a(0)
(A final important detail when unpacking planes: the bits for each pixel are stored in the byte from most to least significant.)
Code: Select all
dim as short wid, hei
dim as integer x, y, pln
dim as ubyte pixels
screen 12
open "face1.vga" for binary as #1
get #1, 7+1, wid
get #1, 9+1, hei
for y = 0 to hei-1
for pln = 0 to 3
for x = 0 to wid-1
if (x and 7) = 0 then
get #1, 11 + (y*4+pln)*((wid+7)\8) + x\8 + 1, pixels
end if
if pixels and &h80 then pset (x, y), (point(x, y) or 1 shl pln)
pixels shl= 1
next x
next pln
next y
close #1
sleep
Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION
Thanks! That works perfectly! Is it okay if I use it in this closed source program?