@hwnd%

Discussions related to graphics (2D and 3D), animation and games programming
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I now have my basic terrain rendering program working in BBCSDL32. Thankyou Richard. Starting to convert to BBCSDL64 has thrown up quite a few errors, so ill start with the first.

Code: Select all

 
 3522 DIM code%% NOTEND AND 2047, code%% (2048*40)-1
 3523 DIM ]^O% 2048, ]^L% -1
 3524 ]^P% = code%%
 3525 FOR I% = 0 TO 2 STEP 2
 3526
 3527   [
 3528   opt I%
 3529
 3530   .float4_to_8
 3531
 3532   fld              DWORD [float4]
Not sure about the DIM statements and what they do, but it syntax errors at line 3532.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Mon 09 Mar 2026, 20:19 it syntax errors at line 3532.

Code: Select all

 
 3532   fld              DWORD [float4]
I'm no expert in 64-bit assembly language, but my understanding is that the memory operand can't be an absolute address (pointer), because it would require 8 bytes; very few instructions can take an 8-byte absolute address for the same reason. What you have to use instead is a relative address, which needs only four bytes - the same number as the absolute address would in 32-bit code:

Code: Select all

 
 3532   fld              DWORD [rel float4]
I discussed earlier in the thread the technique of using relative pointers rather than absolute ones, to keep the size as 32-bits, and this is an example of the CPU itself adopting the same strategy.
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Could you please confirm whether this code is correct. At the moment i am only trying to compile two lines of asm.

Code: Select all

3522 DIM code%% NOTEND AND 2047, code%% 2048
 3523 DIM ]^O% 2048, ]^L% -1
 3524 ]^P% = code%%
 
I have copied it from the differences in x64, sort of!
I have looked back through the thread to where you mention pointers/relative address, but i dont understand what they are.
I've tried all of these

Code: Select all

fld DWORD [rel float4]
fld rel DWORD [float4]
fld DWORD PTR [float4]
fldDWORD_PTR [float4]
fld DWORD PTR [float4] gives the error "missing #", the rest cause a syntax error.
How does relative addressing work?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Mon 09 Mar 2026, 22:03 Could you please confirm whether this code is correct.

Code: Select all

 3522 DIM code%% NOTEND AND 2047, code%% 2048
 3523 DIM ]^O% 2048, ]^L% -1
 3524 ]^P% = code%%
 
I don't think line 3523 can be right, since setting O% ('code origin') is only relevant when you're using OPT 4-7 or 12-15, in order to assemble the code so that it will run at a different address from where it is stored in memory. I'm sure you're not doing that so I would delete that line.
I've tried all of these
I don't know why, because I listed the correct syntax in my previous reply:

Code: Select all

fld DWORD [rel float4]
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

does the word "rel" need to be replaced with something or do i put exactly what you have quoted?
I have tried "fld DWORD [rip + float4]" which doesnt seem to cause an error but i cant work out how to implement that in "fld DWORD rotMatrixA[eax]"
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Mon 09 Mar 2026, 23:06 does the word "rel" need to be replaced with something or do i put exactly what you have quoted?
REL stands for RELATIVE. It is telling the assembler to encode the memory operand as a relative (32-bit) address rather than an absolute (64-bit) address, as I previously explained:

Code: Select all

0000026FE4471C27 D9 05 EB FF FF FF               fld dword [rel memory]
You might wonder why it's needed, given that a relative address is the only permitted encoding for this particular instruction, but that's not true of all instructions. For example if you are loading eax indirectly you have a choice of using an absolute address or a relative address:

Code: Select all

0000026FE4471C18 A1 18 1C 47 E4 6F 02            mov eax,[memory]
0000026FE4471C1F 00 00
0000026FE4471C21 8B 05 F1 FF FF FF               mov eax,[rel memory]
These instructions will have the same effect, but the lengths are different: 9 bytes for the absolute version and 6 bytes for the relative version.

I would say, though, that this isn't an x86-64 assembly language support forum, and I'm not any kind of expert in it, so to spare me (and the rest of the forum members) from getting too overwhelmed with queries not directly related to BBC BASIC I would suggest you seek advice from a site specialising in assembly language.
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Thanks, I have revisited the assembly required to run my code and apart from one section, I could convert to basic given the introduction of *FLOAT 32 for the time being. Some of the time reliant code can wait until later assuming porting of the basic code to 64bit goes well.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I have tried hard to convert the code to create the swapchain in to 64bit, I have looked up all member sizes for the structures and amended the variable type to suit (ie 4byte or 8byte) and have looked up D3D11CreateDeviceAndSwapChain and done the same to the SYS statement. But i still get failure when trying to create the SwapChain. As far as i can tell, the other parts are loading correctly. Plewase can you have a look and see if ive missed anything obvious.

Code: Select all

    1 DIM SDL_SysWMinfo{     \
    2 \    version%,     \
    3 \    subsystem%,   \
    4 \    window%%,      \ The window handle
    5 \    hdc%%,         \ The window device context
    6 \    hinstance%%    \ The instance handle
    7 \ }
    8
    9 SYS "SDL_GetWindowWMInfo", @hwnd% , SDL_SysWMinfo{}
   10 PRINT SDL_SysWMinfo.window%%
   11 PRINT @hwnd%
   12
   13 SYS "SDL_LoadObject","D3D11.DLL" TO D3D11%%
   14 IF D3D11%% = 0 THEN ERROR 0, "DirectX11 is not installed"
   15 SYS "SDL_LoadFunction", D3D11%%, "D3D11CreateDeviceAndSwapChain" TO D3D11CreateDeviceAndSwapChain%%
   16 PRINT D3D11CreateDeviceAndSwapChain%%
   17
   18 DIM DXGI_RATIONAL{Numerator%,Denominator%}
   19
   20 DIM DXGI_MODE_DESC{Width%,Height%,RefreshRate{}=DXGI_RATIONAL{}, \
   21 \ Format%,ScanlineOrdering%,Scaling%}
   22
   23 DIM DXGI_SAMPLE_DESC{Count%,Quality%}
   24
   25 DIM DXGI_SWAP_CHAIN_DESC{BufferDesc{}=DXGI_MODE_DESC{}, \
   26 \ SampleDesc{}=DXGI_SAMPLE_DESC{},BufferUsage%,BufferCount%, \
   27 \ OutputWindow%%,Windowed%,SwapEffect%,Flags%}
   28
   29 DXGI_USAGE_RENDER_TARGET_OUTPUT         = 1 << (1 + 4)
   30 DXGI_FORMAT_R8G8B8A8_UNORM              = 28
   31 D3D_DRIVER_TYPE_HARDWARE%               = 1
   32 D3D11_SDK_VERSION%                      = 7
   33 NULL%                                   = 0
   34 NULL%%                                  = 0
   35
   36 DIM scd{} = DXGI_SWAP_CHAIN_DESC{}
   37 scd.BufferCount%                        = 1
   38 scd.BufferDesc.Width%                   = 600
   39 scd.BufferDesc.Height%                  = 400
   40 scd.BufferDesc.Format%                  = DXGI_FORMAT_R8G8B8A8_UNORM
   41 scd.BufferDesc.RefreshRate.Numerator%   = 60
   42 scd.BufferDesc.RefreshRate.Denominator% = 1
   43 scd.BufferUsage%                        = DXGI_USAGE_RENDER_TARGET_OUTPUT
   44 scd.OutputWindow%%                      = SDL_SysWMinfo.window%%
   45 scd.SampleDesc.Count%                   = 4
   46 scd.SampleDesc.Quality%                 = 0
   47 scd.Windowed%                           = 1
   48
   49 SYS D3D11CreateDeviceAndSwapChain%%, NULL%%, D3D_DRIVER_TYPE_HARDWARE%, NULL%%, NULL%, NULL%%, NULL%, D3D11_SDK_VERSION%, scd{}, ^SwapChain%%, ^Dev%%, NULL%%, ^DevCon%% TO hRESULT%
   50 IF hRESULT% <> 0 THEN ERROR 100, "CreateDeviceAndSwapChain failed: "+STR$~hRESULT%
   51 PRINT "success"
Thanks in advance

This is as small as i can make the code to create the swapchain
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Wed 11 Mar 2026, 19:42 Please can you have a look and see if ive missed anything obvious.
There's nothing "obvious" that immediately leaps out at me, but there is a suspicious structure here:

Code: Select all

   20 DIM DXGI_MODE_DESC{Width%,Height%,RefreshRate{}=DXGI_RATIONAL{}, \
   21 \ Format%,ScanlineOrdering%,Scaling%}
If I'm counting correctly, this structure is an odd number of DWORDs long (two for Width & Height, two for the RefreshRate and three more, making a total of seven DWORDs) which is likely to throw out the alignment of anything following it in a 64-bit 'parent' structure.

Try padding it out to an even number (obviously you must do this only in the 64-bit version, it would break 32-bit operation):

Code: Select all

   20 DIM DXGI_MODE_DESC{Width%,Height%,RefreshRate{}=DXGI_RATIONAL{}, \
   21 \ Format%,ScanlineOrdering%,Scaling%,Padding%}
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Thank you, I'll get on it tomorrow evening. I assume then that all the structures need to be treated this way.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023