BBC BASIC for Windows
« DIBSection Help »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:01pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: DIBSection Help  (Read 879 times)
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx DIBSection Help
« Thread started on: Nov 1st, 2015, 7:50pm »

I have typed the code in the following link http://bb4w.wikispaces.com/Direct+screen+memory+access
Only to get the error "couldn't create DIBSection". I don't really understand the code but the error only occurs if hbitmap% =0 so can I set the value to the last bit in the DIBSection or is it causing an error because I only have the trial version? Can anyone help?
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: DIBSection Help
« Reply #1 on: Nov 3rd, 2015, 07:32am »

Hi Ric,

hbitmap% is returned by the call: you can't set it yourself. If it is 0 it means that the system failed to create the DIBSection. Either one of your parameters wasn't what was required, or potentially memory wasn't available.

Best wishes,

D
User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: DIBSection Help
« Reply #2 on: Nov 5th, 2015, 2:11pm »

Hi DDRM
I have now corrected the code (guilty of failing to transpose properly!!!!), as you are probably aware by now I am trying to create ASM routines to produce he graphics I require. And thus, is it possible to access bits% directly from assembly?
Regards Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: DIBSection Help
« Reply #3 on: Nov 5th, 2015, 2:30pm »

on Nov 5th, 2015, 2:11pm, Ric wrote:
Hi DDRM
I have now corrected the code (guilty of failing to transpose properly!!!!), as you are probably aware by now I am trying to create ASM routines to produce he graphics I require. And thus, is it possible to access bits% directly from assembly?
Regards Ric


Yes, for example:

Code:
mov eax, bits% 

or

Code:
mov eax, [^bits%] 


The former assumes that bits% is (and remains) constant; the latter allows for differing/variable values of bits% from one call of the machine code routine to the next.
« Last Edit: Nov 5th, 2015, 2:43pm by David Williams » User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: DIBSection Help
« Reply #4 on: Nov 5th, 2015, 3:11pm »

Thanks David,
This instruction obviously puts the value in eax into bits%, but the manual I am looking at would suggest that the instruction should put the value in bits% into eax. I am confused. can you point me in the right direction for a user guide for the assembly language.
Regards Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: DIBSection Help
« Reply #5 on: Nov 5th, 2015, 3:27pm »

David,

Thought about the instruction you posted a bit more, bits% is an array, does this matter?

the operation I would like to perform in to make bits%?(<variable>wink=<variable> simple in basic but when I try to perform this in asm I get a syntax or size error.

MOV bit%, ax

fails I know now because the variable is not allowed to be the destination operand, this is what I can not solve.

Do I need to transfer the memory location of bits% to a register and MOV to that location? I have tried this and it crashes bb4w!

HELP

Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: DIBSection Help
« Reply #6 on: Nov 5th, 2015, 4:17pm »

Ric, I've written the following bit of example code in a huge hurry (I'm about to go out). Perhaps you'll find it of some use?

Just copy and paste it into the BB4W IDE, and run it. It just displays a coloured pattern.

Code:
      ON ERROR PROCError(REPORT$ + " at line " + STR$ERL)

      ScrW% = 640
      ScrH% = 512
      PROCFixWndSz
      VDU 23,22,ScrW%;ScrH%;8,16,16,0

      bits% = FNCreateDIBSection

      DIM code% 127

      FOR I% = 0 TO 2 STEP 2
        P% = code%
        [OPT I%
  
        mov eax, [^bits%]    ; base address of DIBSection
        mov ecx, ScrW%*ScrH% ; no. of pixels to write
        mov edx, &12345678   ; colour
  
        .lp
        mov [eax], edx       ; write pixel to DIBSection
        add eax, 4           ; inc. addr by 4 bytes
        sub edx, &01020305
        dec ecx              ; dec loop counter
        jg lp                ; loop if > 0
  
        ret
  
        ]
      NEXT I%

      CALL code%

      SYS "InvalidateRect", @hwnd%, 0, 0
      *REFRESH
      END

      DEFFNCreateDIBSection
      LOCAL A%,B%,H%,O%
      DIM B% 19:!B%=44:B%!4=@vdu%!208:B%!8=@vdu%!212:B%!12=&200001
      SYS"CreateDIBSection",@memhdc%,B%,0,^A%,0,0TOH%
      IF H%=0 PROCError("Create DIBSection failed")
      SYS"SelectObject",@memhdc%,H%TOO%
      SYS"DeleteObject",O%
      CLS
      =A%

      DEF PROCFixWndSz
      LOCAL W%
      SYS"GetWindowLong",@hwnd%,-16 TO W%
      SYS"SetWindowLong",@hwnd%,-16,W% ANDNOT&40000 ANDNOT&10000
      ENDPROC

      DEF PROCError(s$)
      OSCLI "REFRESH ON"
      CLS : ON : VDU 7
      PRINT '" " + s$;
      REPEAT UNTIL INKEY(1)=0
      ENDPROC
 




David.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: DIBSection Help
« Reply #7 on: Nov 6th, 2015, 07:44am »

Here's a slightly neater, more efficient version of the code I put up yesterday. The program does a similar thing - just displays a colourful pattern. Copy, paste, and run:

Code:
      ON ERROR PROCError(REPORT$ + " at line " + STR$ERL)

      ScrW% = 512
      ScrH% = 512
      PROCFixWndSz
      VDU 23,22,ScrW%;ScrH%;8,16,16,0

      REM Create 32bpp (ARGB &AARRGGBB) DIBSection:
      bits% = FNCreateDIBSection

      DIM code% 127

      FOR I% = 0 TO 2 STEP 2
        P% = code%
        [OPT I%
  
        mov eax, [^bits%]    ; base address of DIBSection colour bits (pixels)
        mov ecx, ScrW%*ScrH% ; no. of pixels to write (4 bytes per pixel)
        mov edx, &00654321   ; initial (&AARRGGBB) colour
  
        .lp
        mov [eax + 4*ecx -4], edx ; write pixel to DIBSection
        sub edx, &00010101        ; update/modify colour
        loopnz lp                 ; ECX is automatically decremented & checked
  
        ret
  
        ]
      NEXT I%

      CALL code%

      SYS "InvalidateRect", @hwnd%, 0, 0
      *REFRESH
      END

      DEFFNCreateDIBSection
      LOCAL A%,B%,H%,O%
      DIM B% 19:!B%=44:B%!4=@vdu%!208:B%!8=@vdu%!212:B%!12=&200001
      SYS"CreateDIBSection",@memhdc%,B%,0,^A%,0,0TOH%
      IF H%=0 PROCError("Create DIBSection failed")
      SYS"SelectObject",@memhdc%,H%TOO%
      SYS"DeleteObject",O%
      CLS
      =A%

      DEF PROCFixWndSz
      LOCAL W%
      SYS"GetWindowLong",@hwnd%,-16 TO W%
      SYS"SetWindowLong",@hwnd%,-16,W% ANDNOT&40000 ANDNOT&10000
      ENDPROC

      DEF PROCError(s$)
      OSCLI "REFRESH ON"
      CLS : ON : VDU 7
      PRINT '" " + s$;
      REPEAT UNTIL INKEY(1)=0
      ENDPROC
 
User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: DIBSection Help
« Reply #8 on: Nov 6th, 2015, 08:42am »

Thanks once again David, hope your night out was OK. I went on a step learning curve last night, the code you sent to create the DIBSection was different to the one I was using which caused me a headache at first but once I realised it needed to be 32bpp suddenly the penny dropped. Another penny dropped in understanding that ie. eax was a 32bit register and that effects 4 double byte locations. So &00FFFFFF is white and not &FF &FF &FF which was the way I was doing it in basic. In the early nineties I did a degree in computer engineering would you believe, I don't recall any of this being on it , maybe I've just forgotten! Age! I am now set to create the sprite routines, so many thanks again to yourself and DDRM for your input, (I may need it againwink ).


PS. Is there a sensible manual I can download?
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
ady
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 55
xx Re: DIBSection Help
« Reply #9 on: Nov 6th, 2015, 09:01am »

PS. Is there a sensible manual I can download?

That's where ketman comes in, you can SEE what is happening instead of imagining or guessing, especially when it gets confusing
http://www.addogodfrey.clara.net/learn-32bit-X86-assembly-language.html
« Last Edit: Nov 6th, 2015, 09:02am by ady » User IP Logged

Ric
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 136
xx Re: DIBSection Help
« Reply #10 on: Nov 19th, 2015, 10:34am »

Thanks Ady,
I have tried to download Ketman Maximaster, but it will not run because of issues about 64 bit machine, have you come across this before and is there a solution?

Regards Ric
User IP Logged

It's always possible, but not necessarily how you first thought. Chin up and try again.
ady
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 55
xx Re: DIBSection Help
« Reply #11 on: Nov 20th, 2015, 10:19am »

It's quite a sophisticated program and unique as far as I am aware
I would reckon that you will need a 32 bit system to run it

XP32 is fine (alt-ENTER) lets you cycle to the full screen
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls