Just... Don't?DavidS wrote: ↑Thu Jul 11, 2019 3:46 pmHow do I do that? How do I create a window, handle menus, handle Window Manager events, handle messages, etc in a way that is OS independant without using libraries, while maintaining compatibility with RISC OS?RichardRussell wrote: ↑Thu Jul 11, 2019 8:38 amUnless you want to use embedded assembler code, it ought to be relatively easy to write it in 'generic' BBC BASIC so that it will run in BBC BASIC for Windows, BBC BASIC for SDL 2.0 and Matrix Brandy, as well as ARM BASIC V. It won't show off the full potential of the language, since it wouldn't be benefitting from the enhancements in my versions, but at least it means your submission can be tested on more common platforms.
By doing everything in BASIC! BBC BASIC is more than capable of implementing the full set of GUI features that you describe without calling upon any OS functionality. As I think you know, both IDEs supplied with BBC BASIC for SDL 2.0, my 'SDLIDE' and Andy Parkes' 'BBCEdit', are written entirely in BBC BASIC; that way I achieve the level of cross-platform compatibilty that I want (Windows, MacOS, Linux). Those IDEs have menus and toolbars and status bars and a program editor pane and....
Your message crossed with mine, but we're both saying the same thing. Yes BBC BASIC (including the ARM BASIC preferred by DavidS) exposes everything needed such as mouse and keyboard activity, and the graphics functionality already support things like viewports. My versions do have a few enhancements that help (such as being notified of mouse clicks with an 'interrupt' rather than having to poll) but these are things I'm sure David could work around.ZXDunny wrote: ↑Thu Jul 11, 2019 4:29 pmI mean, what is a window? It's a region of memory that you draw to. The only OS-dependent code would be getting and displaying that surface and BBC BASIC uses SDL2 for that, I'd imagine. Everything else such as mouse movement/clicks, keyboard usage should be exposed to the user in any decent BASIC. Does BASIC-V allow you to track the mouse?
A Menu is just another window with some text on it. You can draw fancy shadows and stuff on it if you like, too. There's no limit to what you can do if you're prepared to start writing pixels. And you can do all that without calling the OS.
If you are happy to accept an existing program, rather than something written specifically for the challenge, then my SDLIDE.bbc meets the requirements as I understand them:ScriptBasic wrote: ↑Thu Jul 11, 2019 5:11 pmAny chance the both of you could collaborate on a submission?
The syntax colouring and indentation are BBC BASIC-specific, of course, and there is a line-length limit of about 250 characters. Apart from that it will probably be OK with source code for a different BASIC (e.g. ScriptBasic), you did ask for a 'code editor' after all. But it's not really suitable for general purpose text editing, for example it will be confused by lines starting with a numeric digit because it will assume it's a line number, and it doesn't like high-bit-set characters unless in quoted strings. So, the answer is "to an extent".
You can do whatever you like with my program (SDLIDE.bbc) and the associated library (dlglib.bbc). Both are written entirely in BBC BASIC and there is no reliance on any external GUI library, framework or toolkit. There are only a few direct calls to the OS, for things such as accessing the clipboard (which is obviously useful for interworking with other apps) and these are mostly non-essential. The program and library will run in both BBC BASIC for SDL 2.0 (on Windows, MacOS and Linux) and BBC BASIC for Windows which demonstrates the degree of OS-independence.ScriptBasic wrote: ↑Thu Jul 11, 2019 11:42 pmThe goal is to show how desktop GUI is done. The editor challenge is just the stage for that goal.
I don't want to pick on you in particularly but this kind of statement drive me crazy.I would really like to see a comparable ScriptBasic solution, i.e. one which doesn't call upon any off-the-shelf GUI library. That would be a better demonstration of the capabilities of the language than anything I've seen so far.
You should have posed that in the other thread. I think ScriptBasics challenge is quite suitable to any language.
Nope. Anything using HTML, CSS, Javascript has been specifically disallowed.You should have posed that in the other thread. I think ScriptBasics challenge is quite suitable to any language.
Being off topic I will answer in your RISC OS challenge thread.And albeit off topic:
The challenge you speak of is limited by what Linux can provide AS AN OS (not a tone of libraries), if the limits were on the RISC OS side much more could be tested. Same reason that OpenGL is left out of that one, as OpenGL is not part of the OS in either case (though both can do it).
Sorry, but you are missing the point. The whole purpose of a challenge, surely, is to be able to make some judgement about the strengths and weaknesses of one language compared with another. An excellent example is Rosetta Code, which lists implementations of many programming 'tasks' in many different languages, and by comparing those implementations one can assess the suitability of a language for a task.
I hope you are not including me in that generalisation. I am absolutely clear about that distinction. Indeed I'm not even sure it's possible to have spent more than 37 years intimately concerned with the specification and implementation of a programming language, on multiple platforms, OSes and CPUs, without having such an understanding.I noticed that those in "interpreter land", especially in "BASIC land" almost never make a distinction between the language they are promoting and the libraries/modules etc that come with the run-time system that implements it.
No. I am not.Sorry, but you are missing the point.
Exactly.Now imagine the situation when the task in question is available in an off-the-shelf 'external' library, which works very well, and you allow that to be used. Inevitably virtually every implementation, in every language, is going to consist of code which loads that library, calls the relevant function(s) and returns the results. What does that tell you about the suitability of the language to the task? Nothing! It tells you only how it calls functions in a library.
I don't mean to.I hope you are not including me in that generalisation. I am absolutely clear about that distinction. Indeed I'm not even sure it's possible to have spent more than 37 years intimately concerned with the specification and implementation of a programming language, on multiple platforms, OSes and CPUs, without having such an understanding.
It's all in the context. If you ask me to code some particular task 'in BBC BASIC' you don't mean that I am not allowed to use the libraries that are supplied as standard with that language (especially given that they are themselves coded in BBC BASIC), do you? That would be as silly as asking for a solution in C that didn't call the CRT, which would disallow even (for example) the square root function! On the other hand if you are talking about comparing the syntax of the WHILE loop between one 'language' and another, then you are clearly using the term in a more precise sense.Heater wrote: ↑Fri Jul 12, 2019 3:16 pmIt's just that when someone uses the word "language" to refer to the programming language and the run-time environment it operates in and all the features that implementation provides via modules/extensions whatever, then they start to fall into that generalization.
John said that my native BBC BASIC program appears to meet the terms of the challenge, so that is apparently not the case.
Obviously most of my editions of BBC BASIC don't run on an ARM CPU (Windows, MacOS and Linux, with the exception of Raspbian) or run in 64-bits on an ARM (iOS) so in those cases the question is meaningless. The only 32-bit ARM editions are for Raspbian and (currently) Android; in those editions the subset of the ARM instruction set supported by the assembler is similar (but not identical) to that in ARM BASIC V. There is currently no support for Neon instructions or any of the other extensions; I would like there to be but it needs somebody with a better understanding of the CPU than I have to add them.What subset of the ARM AARCH32 ISA does your BBC BASIC support for assembly?
As far as I know, yes. If there are differences between the way ARM BASIC V uses them and the way (6502) BASIC 4 does, quite possibly I haven't incorporated those changes. Not having ever owned or used a RISC OS machine I have very little experience of ARM BASIC.And to verify, your assembler uses the same OPT, O%, P%, and L% meanings (and OPT flags) as RISC OS BBC BASIC V, correct?
Well I will already tell you it is a little more work than doing it inside of an existing Window Manager.ScriptBasic wrote: ↑Fri Jul 12, 2019 5:37 pmIUP has an OpenGL forms API that reminds me what you guys are thinking of doing in BBC BASIC. I'm looking forward to see what you guys come up with.
There's an assembler 'Hello world!' program supplied with BBCSDL which should give you an idea of whether it will be suitable. Apart from the selection of appropriate source code for the CPU (64-bit x86, 32-bit x86 or 32-bit ARM) hopefully it will hold no surprises. You can ignore, for your purposes, the unfamiliar 64-bit integers code%% and limit%%, they are irrelevant for 32-bit ARM:
Code: Select all
ON ERROR IF ERR=17 CHAIN @lib$+"../examples/tools/touchide" ELSE MODE 3 : PRINT REPORT$ : END
VDU 23,22,640;500;8,20,16,128+8
OFF
DIM limit%% -1, code%% 100, limit%% -1
FOR pass% = 8 TO 11 STEP 3
IF @platform% AND &40 THEN
]^P% = code%%
]^L% = limit%%
[opt pass%
.hello
sub rsp,40
mov rbp,"oswrch"
lea rbx,[rel asciiz]
.loop
mov al,[rbx] ; get next char
inc rbx ; bump pointer
cmp al,0 ; is it a NUL?
jz done ; if so, exit
movzx ecx,al ; for Windows &
mov edi,ecx ; System V ABIs
call rbp ; output char
jmp loop ; continue
;
.done
add rsp,40
ret
;
.asciiz
db "Hello world!"
dw &0A0D
db 0
]
ELSE
P% = code%%
L% = limit%%
[opt 0:nop:]
CASE P%?-1 OF
WHEN &90:
[opt pass%
.hello
push esi
mov esi,asciiz ; pointer to text string
.loop
lodsb ; get next character
cmp al,0 ; is it a NUL ?
jz done ; if so, exit
call "oswrch" ; output character
jmps loop ; continue
;
.done
pop esi
ret
;
.asciiz
db "Hello world!"
dw &0A0D
db 0
]
WHEN &E1:
[opt pass%
.hello
push {r8-r9,lr}
ldr r8,oswrch
adr r9,asciiz ; pointer to text string
.loop
ldrb r0,[r9],#1 ; get next character
cmp r0,#0 ; is it a NUL ?
popeq {r8-r9,pc} ; if so, exit
blx r8 ; output character
b loop ; continue
;
.asciiz
equs "Hello world!"
equw &0A0D
equb 0
;
align
.oswrch
equd "oswrch"
]
ENDCASE
ENDIF
NEXT pass%
PRINT
CALL hello
My understanding is that SWIs are kernel calls in Linux and therefore not usable from user-mode code; is that not right? Certainly I've made no specific provision for them, I'm assuming that all calls into Linux will be via functions in the C runtime library or other shared libraries that are available to a program running with ordinary user permissions (which BBC BASIC normally will be).
In x86-64 mode 32-bit registers are still the default (whenever you write to one the high 32-bits of the equivalent 64-bit register are zeroed). I presume this was done because it's also the convention used by most C-compilers: an int is 32-bits even in 64-bit mode. So you save a prefix byte by accessing a 32-bit register rather than a 64-bit one, if you don't need the full 64-bits. I think the code I posted is optimal in this respect:Interesting mix of 64 and 32 bit regs used.
Code: Select all
000000000D40231C .hello
000000000D40231C 48 83 EC 28 sub rsp,40
000000000D402320 48 BD 50 1F 41 00 00 mov rbp,"oswrch"
000000000D402327 00 00 00
000000000D40232A 48 8D 1D 1A 00 00 00 lea rbx,[rel asciiz]
000000000D402331 .loop
000000000D402331 8A 03 mov al,[rbx] ; get next char
000000000D402333 48 FF C3 inc rbx ; bump pointer
000000000D402336 3C 00 cmp al,0 ; is it a NUL?
000000000D402338 74 0C jz done ; if so, exit
000000000D40233A 0F B6 C8 movzx ecx,al ; for Windows &
000000000D40233D 89 CF mov edi,ecx ; System V ABIs
000000000D40233F FF D5 call rbp ; output char
000000000D402341 E9 EB FF FF FF jmp loop ; continue
000000000D402346 ;
000000000D402346 .done
000000000D402346 48 83 C4 28 add rsp,40
000000000D40234A C3 ret
000000000D40234B ;
000000000D40234B .asciiz
000000000D40234B 48 65 6C 6C 6F 20 77 db "Hello world!"
000000000D402352 6F 72 6C 64 21
000000000D402357 0D 0A dw &0A0D
000000000D402359 00 db 0