converting_20programs_20from_20risc_20os_20to_20windows
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
converting_20programs_20from_20risc_20os_20to_20windows [2018/03/31 13:19] – external edit 127.0.0.1 | converting_20programs_20from_20risc_20os_20to_20windows [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Converting programs from RISC OS to Windows===== | =====Converting programs from RISC OS to Windows===== | ||
- | //by Richard Russell, October 2009//\\ \\ The conversion of **WIMP-based** BBC BASIC programs (i.e. programs having a Graphical User Interface) from **RISC OS** to **Windows** is a very broad subject, and it would be virtually impossible to provide a comprehensive guide. Therefore this article takes the form of a Case Study, dealing specifically with the conversion of one program: **BasCalc**. BasCalc is a relatively simple application, | + | //by Richard Russell, October 2009//\\ \\ The conversion of **WIMP-based** BBC BASIC programs (i.e. programs having a Graphical User Interface) from **RISC OS** to **Windows** is a very broad subject, and it would be virtually impossible to provide a comprehensive guide. Therefore this article takes the form of a Case Study, dealing specifically with the conversion of one program: **BasCalc**. BasCalc is a relatively simple application, |
+ | |||
+ | <code bb4w> | ||
10 REM >BASCalc Source code | 10 REM >BASCalc Source code | ||
20 REM (C)1999 PAUL VIGAY | 20 REM (C)1999 PAUL VIGAY | ||
Line 8: | Line 10: | ||
50 REM create your own applications. A limited number of comments have been inserted for you! | 50 REM create your own applications. A limited number of comments have been inserted for you! | ||
60 version$=" | 60 version$=" | ||
- | The first line to require a change is this one:\\ \\ | + | </ |
+ | |||
+ | The first line to require a change is this one: | ||
+ | |||
+ | <code bb4w> | ||
70 DIM pb1% 256 : task%=& | 70 DIM pb1% 256 : task%=& | ||
70 DIM pb1% 256 : task%=& | 70 DIM pb1% 256 : task%=& | ||
- | The RISC OS path specification isn't appropriate for Windows. Under Windows it could be set to an absolute or relative path, but for convenience here we simply set it to **@dir$**, which in BB4W is a pre-defined ' | + | </ |
+ | |||
+ | The RISC OS path specification isn't appropriate for Windows. Under Windows it could be set to an absolute or relative path, but for convenience here we simply set it to **@dir$**, which in BB4W is a pre-defined ' | ||
+ | |||
+ | <code bb4w> | ||
80 SYS " | 80 SYS " | ||
80 SYS " | 80 SYS " | ||
- | Windows has no direct equivalent to **Wimp_Initialise** so here we replace the call with one which sets the window title.\\ \\ | + | </ |
+ | |||
+ | Windows has no direct equivalent to **Wimp_Initialise** so here we replace the call with one which sets the window title. | ||
+ | |||
+ | <code bb4w> | ||
90 PROCinit | 90 PROCinit | ||
100 ON ERROR PROCerror | 100 ON ERROR PROCerror | ||
Line 24: | Line 38: | ||
110 REPEAT | 110 REPEAT | ||
120 | 120 | ||
- | Because Windows is a // | + | </ |
+ | |||
+ | Because Windows is a // | ||
+ | |||
+ | <code bb4w> | ||
130 CASE reason% OF | 130 CASE reason% OF | ||
140 WHEN 2: | 140 WHEN 2: | ||
Line 49: | Line 67: | ||
190 WHEN 17: end%=TRUE | 190 WHEN 17: end%=TRUE | ||
290 | 290 | ||
- | There are no essential changes here, but for neatness lines 140-150 and 190-280 have been deleted. These perform operations needed to support RISC OS which are not required under Windows. It would do no harm, other than leaving ' | + | </ |
+ | |||
+ | There are no essential changes here, but for neatness lines 140-150 and 190-280 have been deleted. These perform operations needed to support RISC OS which are not required under Windows. It would do no harm, other than leaving ' | ||
+ | |||
+ | <code bb4w> | ||
300 UNTIL end% | 300 UNTIL end% | ||
310 PROCmsgend: | 310 PROCmsgend: | ||
Line 56: | Line 78: | ||
300 UNTIL end% | 300 UNTIL end% | ||
310 QUIT | 310 QUIT | ||
- | Here we can simply replace the calls to **Wimp_CloseDown** and **PROCmsgend** with QUIT. In a more complex program it may well be necessary to perform some ' | + | </ |
+ | |||
+ | Here we can simply replace the calls to **Wimp_CloseDown** and **PROCmsgend** with QUIT. In a more complex program it may well be necessary to perform some ' | ||
+ | |||
+ | <code bb4w> | ||
330 | 330 | ||
340 DEF PROCmouseclick | 340 DEF PROCmouseclick | ||
Line 67: | Line 93: | ||
350 LOCAL i% | 350 LOCAL i% | ||
360 i%=pb%!16 | 360 i%=pb%!16 | ||
- | For the mouse-click processing the information required by the Windows version is much simpler than by the RISC OS version, basically it's a single value (here **i%**) to indicate what **control** (**icon** in RISC OS-speak) was clicked. Again, there' | + | </ |
+ | |||
+ | For the mouse-click processing the information required by the Windows version is much simpler than by the RISC OS version, basically it's a single value (here **i%**) to indicate what **control** (**icon** in RISC OS-speak) was clicked. Again, there' | ||
+ | |||
+ | <code bb4w> | ||
380 CASE b% OF | 380 CASE b% OF | ||
390 WHEN 1,4:CASE w% OF | 390 WHEN 1,4:CASE w% OF | ||
Line 114: | Line 144: | ||
600 ENDCASE | 600 ENDCASE | ||
670 ENDPROC | 670 ENDPROC | ||
- | The only necessary change to this code is the substitution of the calls to **Wimp_SetCaretPosition** (lines 470 and 580) with a suitable Windows equivalent. In fact, since these calls are non-essential, | + | </ |
+ | |||
+ | The only necessary change to this code is the substitution of the calls to **Wimp_SetCaretPosition** (lines 470 and 580) with a suitable Windows equivalent. In fact, since these calls are non-essential, | ||
+ | |||
+ | <code bb4w> | ||
680 | 680 | ||
690 DEF PROCkeypressed | 690 DEF PROCkeypressed | ||
Line 124: | Line 158: | ||
700 LOCAL icon% | 700 LOCAL icon% | ||
710 icon%=pb%!4 | 710 icon%=pb%!4 | ||
- | Here we have a very similar situation to **PROCmouseclick**; | + | </ |
+ | |||
+ | Here we have a very similar situation to **PROCmouseclick**; | ||
+ | |||
+ | <code bb4w> | ||
720 CASE window% OF | 720 CASE window% OF | ||
730 WHEN window%(2): | 730 WHEN window%(2): | ||
Line 154: | Line 192: | ||
820 ENDCASE | 820 ENDCASE | ||
890 ENDPROC | 890 ENDPROC | ||
- | Once again the only essential change is the substitution or removal of **Wimp_SetCaretPosition** (line 830) but here the superfluous **CASE window% OF** and **CASE key% OF** constructs (lines 720-730 and 830-880) and the **WHEN 13** (in line 740) have been deleted. The **Wimp_ProcessKey** has no equivalent in Windows (it is related to the co-operative nature of RISC OS).\\ \\ | + | </ |
+ | |||
+ | Once again the only essential change is the substitution or removal of **Wimp_SetCaretPosition** (line 830) but here the superfluous **CASE window% OF** and **CASE key% OF** constructs (lines 720-730 and 830-880) and the **WHEN 13** (in line 740) have been deleted. The **Wimp_ProcessKey** has no equivalent in Windows (it is related to the co-operative nature of RISC OS). | ||
+ | |||
+ | <code bb4w> | ||
900 | 900 | ||
910 DEF PROCmenu | 910 DEF PROCmenu | ||
Line 194: | Line 236: | ||
1070 ENDCASE | 1070 ENDCASE | ||
1080 ENDPROC | 1080 ENDPROC | ||
- | This is the first major change. Since the means of displaying and processing a //context// menu is quite different, **PROCmenu** has been substantially re-written. In Windows the context menu is displayed by clicking the //right// mouse button.\\ \\ | + | </ |
+ | |||
+ | This is the first major change. Since the means of displaying and processing a //context// menu is quite different, **PROCmenu** has been substantially re-written. In Windows the context menu is displayed by clicking the //right// mouse button. | ||
+ | |||
+ | <code bb4w> | ||
1090 | 1090 | ||
1100 DEF PROCinit | 1100 DEF PROCinit | ||
Line 221: | Line 267: | ||
1210 SYS " | 1210 SYS " | ||
1220 ENDPROC | 1220 ENDPROC | ||
- | Here the changes consist mostly of (optional) deletions. The allocation of buffers in lines 1120 to 1150 is not required (along with most of line 1110); **PROCmsgload** can be dispensed with (as we will see later, the most convenient way of emulating the RISC OS **MessageTrans** facility does not require initialisation) and Windows looks after its iconbar (task bar) without user involvement.\\ \\ A couple of additions have also been made: **showfull%=FALSE** (line 1180) and **PROCsizewindow** (line 1190) initialise the size of the window, and **SYS " | + | </ |
+ | |||
+ | Here the changes consist mostly of (optional) deletions. The allocation of buffers in lines 1120 to 1150 is not required (along with most of line 1110); **PROCmsgload** can be dispensed with (as we will see later, the most convenient way of emulating the RISC OS **MessageTrans** facility does not require initialisation) and Windows looks after its iconbar (task bar) without user involvement.\\ \\ A couple of additions have also been made: **showfull%=FALSE** (line 1180) and **PROCsizewindow** (line 1190) initialise the size of the window, and **SYS " | ||
+ | |||
+ | <code bb4w> | ||
1230 | 1230 | ||
1240 DEF FNiconbar(A$) | 1240 DEF FNiconbar(A$) | ||
Line 267: | Line 317: | ||
1640 bhandle%=pb%!28: | 1640 bhandle%=pb%!28: | ||
1650 ENDPROC | 1650 ENDPROC | ||
- | This code is specific to RISC OS and can be **deleted in its entirety**. The program will still work correctly if it is left, but doing so will waste a substantial amount of memory and potentially cause confusion to somebody reading the code.\\ \\ | + | </ |
+ | |||
+ | This code is specific to RISC OS and can be **deleted in its entirety**. The program will still work correctly if it is left, but doing so will waste a substantial amount of memory and potentially cause confusion to somebody reading the code. | ||
+ | |||
+ | <code bb4w> | ||
1660 | 1660 | ||
1670 DEF PROCui(window%, | 1670 DEF PROCui(window%, | ||
Line 277: | Line 331: | ||
1680 SYS " | 1680 SYS " | ||
1690 ENDPROC | 1690 ENDPROC | ||
- | Here the original code has been substituted with a Windows near-equivalent.\\ \\ | + | </ |
+ | |||
+ | Here the original code has been substituted with a Windows near-equivalent. | ||
+ | |||
+ | <code bb4w> | ||
1700 | 1700 | ||
1710 REM Setup messagetrans | 1710 REM Setup messagetrans | ||
Line 290: | Line 348: | ||
1800 SYS " | 1800 SYS " | ||
1810 ENDPROC | 1810 ENDPROC | ||
- | This code is not required and may be **deleted**.\\ \\ | + | </ |
+ | |||
+ | This code is not required and may be **deleted**. | ||
+ | |||
+ | <code bb4w> | ||
1820 | 1820 | ||
1830 REM decode tag$ into relevant text from Messages file | 1830 REM decode tag$ into relevant text from Messages file | ||
Line 305: | Line 367: | ||
1860 SYS " | 1860 SYS " | ||
1890 = $$msgtext% | 1890 = $$msgtext% | ||
- | A convenient way of emulating the RISC OS **MessageTrans** facility is to use a file in the Windows ' | + | </ |
+ | |||
+ | A convenient way of emulating the RISC OS **MessageTrans** facility is to use a file in the Windows ' | ||
+ | |||
+ | <code bb4w> | ||
1900 | 1900 | ||
1910 DEF FNgetstring(a%) | 1910 DEF FNgetstring(a%) | ||
Line 313: | Line 379: | ||
1950 | 1950 | ||
1960 DEF PROCstring0(a%, | 1960 DEF PROCstring0(a%, | ||
- | These routines may be **deleted**. BBC BASIC for Windows supports NUL-terminated strings natively using the **$$** syntax.\\ \\ | + | </ |
+ | |||
+ | These routines may be **deleted**. BBC BASIC for Windows supports NUL-terminated strings natively using the **$$** syntax. | ||
+ | |||
+ | <code bb4w> | ||
1970 | 1970 | ||
1980 DEF PROCerror | 1980 DEF PROCerror | ||
Line 332: | Line 402: | ||
2030 IF E%=2 OR end%=TRUE end%=TRUE: | 2030 IF E%=2 OR end%=TRUE end%=TRUE: | ||
2040 ENDPROC | 2040 ENDPROC | ||
- | The only alterations required here are to delete the **PROCmsgend: | + | </ |
+ | |||
+ | The only alterations required here are to delete the **PROCmsgend: | ||
+ | |||
+ | <code bb4w> | ||
2050 | 2050 | ||
2060 DEF FNerror(E%, | 2060 DEF FNerror(E%, | ||
Line 343: | Line 417: | ||
2070 SYS " | 2070 SYS " | ||
2090 =E% | 2090 =E% | ||
- | Here **SYS " | + | </ |
+ | |||
+ | Here **SYS " | ||
+ | |||
+ | <code bb4w> | ||
2100 | 2100 | ||
2110 DEF PROCmenucreate | 2110 DEF PROCmenucreate | ||
Line 416: | Line 494: | ||
2290 SYS " | 2290 SYS " | ||
2300 ENDPROC | 2300 ENDPROC | ||
- | This is another case where the RISC OS and Windows code is quite different. Also, an extra menu item (**Show full**) has been added to the Windows version as a more convenient way of switching between the two window sizes.\\ \\ | + | </ |
+ | |||
+ | This is another case where the RISC OS and Windows code is quite different. Also, an extra menu item (**Show full**) has been added to the Windows version as a more convenient way of switching between the two window sizes. | ||
+ | |||
+ | <code bb4w> | ||
2590 | 2590 | ||
2600 DEF PROCloadwindows | 2600 DEF PROCloadwindows | ||
Line 470: | Line 552: | ||
2755 window%(2) = !window% | 2755 window%(2) = !window% | ||
2760 ENDPROC | 2760 ENDPROC | ||
- | Once again the Windows version is quite different. Although it's possible in Windows to create a dialogue window using a template (which would be more similar to the RISC OS version) it's conventional in BB4W to incorporate the various controls using inline code as shown. | + | </ |
+ | |||
+ | Once again the Windows version is quite different. Although it's possible in Windows to create a dialogue window using a template (which would be more similar to the RISC OS version) it's conventional in BB4W to incorporate the various controls using inline code as shown. | ||
+ | |||
+ | <code bb4w> | ||
2780 | 2780 | ||
2790 DEF PROCcalc | 2790 DEF PROCcalc | ||
Line 493: | Line 579: | ||
.... | .... | ||
4230 =a$ | 4230 =a$ | ||
- | Lines 2780 to 4230 inclusive are the ' | + | </ |
+ | |||
+ | Lines 2780 to 4230 inclusive are the ' | ||
+ | |||
+ | <code bb4w> | ||
4240 | 4240 | ||
4250 DEF PROCinsertcode(a$) | 4250 DEF PROCinsertcode(a$) | ||
Line 505: | Line 595: | ||
4270 IF a$<>"" | 4270 IF a$<>"" | ||
4280 ENDPROC | 4280 ENDPROC | ||
- | The **SYS " | + | </ |
+ | |||
+ | The **SYS " | ||
+ | |||
+ | <code bb4w> | ||
4290 | 4290 | ||
4300 DEF PROCloadchoices | 4300 DEF PROCloadchoices | ||
Line 526: | Line 620: | ||
4320 SYS " | 4320 SYS " | ||
4330 ENDPROC | 4330 ENDPROC | ||
- | The Windows code is again quite different. In addition to loading the user's preference as regards the **decimals** setting, his most recent choice for the window size is also loaded.\\ \\ | + | </ |
+ | |||
+ | The Windows code is again quite different. In addition to loading the user's preference as regards the **decimals** setting, his most recent choice for the window size is also loaded. | ||
+ | |||
+ | <code bb4w> | ||
4430 | 4430 | ||
4440 DEF PROCsavechoices | 4440 DEF PROCsavechoices | ||
Line 544: | Line 642: | ||
4470 SYS " | 4470 SYS " | ||
4480 ENDPROC | 4480 ENDPROC | ||
- | Here the user's most recent window size setting is saved in addition to the number of decimal places.\\ \\ Finally here are the **FNwimp_poll**, | + | </ |
+ | |||
+ | Here the user's most recent window size setting is saved in addition to the number of decimal places.\\ \\ Finally here are the **FNwimp_poll**, | ||
+ | |||
+ | <code bb4w> | ||
DEF FNwimp_poll(pb%) | DEF FNwimp_poll(pb%) | ||
LOCAL click%, reason%, fg%, L% | LOCAL click%, reason%, fg%, L% | ||
Line 612: | Line 714: | ||
SYS " | SYS " | ||
ENDPROC | ENDPROC | ||
- | Here is what **BASCalc.ini** looks like; it may be compared with the equivalent RISC OS message file:\\ \\ | + | </ |
+ | |||
+ | Here is what **BASCalc.ini** looks like; it may be compared with the equivalent RISC OS message file: | ||
+ | |||
+ | < | ||
[messages] | [messages] | ||
# Messages file for !BASCalc | # Messages file for !BASCalc | ||
Line 657: | Line 763: | ||
decimals=8 | decimals=8 | ||
showfull=-1 | showfull=-1 | ||
+ | </ |
converting_20programs_20from_20risc_20os_20to_20windows.1522502351.txt.gz · Last modified: 2024/01/05 00:18 (external edit)