--- Cut End -------------------------------------------------------- 7.8. The assembler code, corresponding to the C module ------------------------------------------------------ If someone is uncertain about the code, produced by the C compiler: get the corresponding ASM code and look, how compact and fast the C generated code is. To get the ASM code, shown below, first the above module PB3_TBC.C was compiled to PB3_TBC.OBJ (with the set-up of par. 7.4 !!), then with a disassembler for .OBJ-Files (OBJ2ASM.EXE) the following file PB3_TBC.ASM was gained. (You can instead order the IDE of the C compiler to produce equivalent ASM code, too. But with an external .OBJ disassembler, you are quite better sure, what the PB3_TBC.OBJ module really contains) --- Cut ------------------------------------------------------------ ;File PB3_TBC.ASM (disassembled from PB3_TBC.OBJ) _TEXT SEGMENT BYTE PUBLIC 'CODE' _TEXT ENDS _DATA SEGMENT WORD PUBLIC 'DATA' ;attention: no BSS segment, no DGROUP !! _DATA ENDS PUBLIC _addab PUBLIC _chst _TEXT SEGMENT assume cs: _TEXT assume ds: _DATA _addab: push bp mov bp,sp ; c = a + b: les bx,dword ptr [bp+006h] ; a mov ax,es:[bx] add ax,[bp+00Ah] ; + b les bx,dword ptr [bp+00Ch] mov es:[bx],ax ; c ;e = c + d: mov ax,es:[bx] ;c (line can be put out for optimization) add ax,$S1 ; + d mov dx,seg _DATA mov es,dx mov es:$S2,ax ; e ;return e: mov ax,seg _DATA ; (line can be put out for optimization) mov es,ax ; (line can be put out for optimization) mov ax,es:$S2 ; ax = e pop bp retf _chst: push bp mov bp,sp sub sp,+004h les bx,dword ptr [bp+00Eh] ; len(a$) cmp word ptr es:[bx],+000h ; nul? jz $L3 ; yes les bx,dword ptr [bp+006h] ; strseg(a$) - segment mov ax,es:[bx] les bx,dword ptr [bp+00Ah] ; strptr(a$) - offset mov dx,es:[bx] mov [bp-002h],ax ; own pointer mov [bp-004h],dx mov ax,[bp-004h] or ax,[bp-002h] ; pointer = 0? jz $L3 ; yes les bx,dword ptr [bp-004h] ; points to first string char mov byte ptr es:[bx],2Ah ; overwrite char with '*' $L3: mov sp,bp pop bp retf _TEXT ENDS _DATA SEGMENT $S1 dw 00001h ; initialized data $S2 dw 00000h ; uninitialized data (here NOT in the ; BSS segment!) _DATA ENDS END --- Cut End -------------------------------------------------------- 7.9. Usage of routines from external C libraries ------------------------------------------------ Although PB v3.x is much better adapted to C conventions than PB v2.1, it's mostly still NOT possible to immediately link .OBJ modules, corresponding to the normal C standard. Reason: C generates more than one data segment together with a DGROUP. To overcome this, one has to use C or ASM source code and to re-compile/re-assemble these sources with corresponding to the aspects of par. 7.3 and 7.4a. There are 2 possibilities: - With Borland C++ for the most runtime libraries the complete source ode is delivered with the standard distribution including instructions, how to change the sources, and including MAKE files to re-generate own versions of the library modules. - If for an .OBJ module no source code is available, it's mostly possible with small modules to get the corresponding ASM source code by using an .OBJ-disassembler. Then, after having adapted the definitions of the data segments correctly to the PB3 conventions, it can be re-assembled again. 7.10. Preparations if PB V2.1 is used ------------------------------------- The difference between PB v3.x and PB v2.1 is like follows: PB v2.1 does not know a "$ALIAS" instruction. AS PB v2.1 can not work with "_" (underscores), in the IDE of the C compiler additional switches have to be changed: - with segment names (see par 7.4a) "_" are not allowed - in the menu "Options / Compiler / Advanced Code Generation" one has to deactivate the switch "Generate underbars". PB v2.1 does not know the CDECL instruction. One therefore has to put instructions into the C source code, that the C functions have to be compiled corresponding to the PASCAL-conventions (this corresponds to the PB-convention). For this, e.g in the example of par 7.6 and 7.7, the following (changed) lines have to be used: DECLARE FUNCTION addab (a, BYVAL b, c) DECLARE SUB chst (word, word, integer) int pascal addab(int far *a, int b, int far *c) void pascal chst(unsigned far *stseg, unsigned far *stofs, int far *stlen) --- CrossPoint v3.11 R * Origin: PBSOUND, PBFILES (32MB), PBFAQ, PBRULES, PBHIVGA at: 2:2410/330.1) --------------- FIDO MESSAGE AREA==> TOPIC: 214 POWER BASIC Ref: F1200012 Date: 01/01/98 From: THOMAS GOHEL Time: 12:00am \/To: ALLE (Read 1 times) Subj: FAQ: PowerBASIC 13/16 (PDS to PB) ================================================================ 8. Hints about conversion of Sources from PDS to PowerBASIC 3.x ================================================================ (from Mark Junker@2:2437/47.21 / mjs@prg.hannover.sgh-net.de) Generally you can say that PDS-Sources can be converted into PB3- Sources. Exceptions are Sources which access foreign libraries and use of dimensioned elements in a TYPE-Structure. So, the following does not allow a conversion: - Foreign libraries (like VESA-LIB and everything else there is out there...) - Dimensioned elements in a TYPE-Structure Example: TYPE tTest TestElement1 AS LONG TestElement2(2 to 7) AS INTEGER TestElement3 AS LONG END TYPE - There may be no COMMON, but all variants of the COMMON SHARED- Command are allowed. Exception: - When COMMON is used to pass parameters to a file called by CHAIN. - When it is irrelevant that the variables behind the COMMON are available in all procedures. - Arrays with more than 8 Dimensions - REDIM PRESERVE is not flexible enough yet - More than 16 Parameters when calling a procedure When all of these things are not implemented, then the following things have to be changed while converting: Basic PDS: PowerBASIC 3: SSEG STRSEG SADD STRPTR SSEGADD STRPTR32 STRPTR32 is only availble from PB3.2 on VARSEG/VARPTR IMPORTANT: PB3 passes UNSIGNED values, PDS passes SIGNED values. This can be changed using $OPTION SIGNED OFF. Offset of a file opened with OPENPB starts every file, you choose, starts with '1'! at Zero (Standard) or at one. This can be changed with the following command: OPTION BINARY BASE 1 for the start at '1' DIM SHARED VarName% This command can be converted in two ways: - DIM VarName% SHARED VarName% - DIM VarName AS SHARED INTEGER SHARED VarName() AS STRING*3 Here we have the problem with Strings of fixed length, when they can't be SHARED in the main program. You may not make any Type-statements ('AS xxx') after SHARED. SHARED VarName as string will become: SHARED VarName$ or: SHARED VarName :'in SUBs ! You can SHARE IXED-LENGTH-STRING-Arrays like this: DIM VarName(MIN,DimNum) AS STRING*3 or DIM VarName(MAX,DimNum) AS STRING*3 where 'DimNum' is the number of Dimensions of the Array and the number must be entered in the program irectly. COMMON SHARED /Block/ VarN% All three variants of the COMMON- COMMON SHARED VarN% command must be replaced in the main program using PUBLIC and in the xternal module (under PB: UNIT) using an EXTERNAL You have to watch that the variable names MUST be identifyable, and without a Type. All Type-Structures 'AS xxx' are not valid in PB3. Die Block-statement (/Block/) is not needed, because everything is not chained to the name. (->Incompatibility!) COMMON VarN% Can only be converted if the variable after the COMMON will be passed to a program started with the CHAIN-Command, or the COMMON could be a COMMON SHARED i.E. It is not allowed to use ype-statements ('AS xxx'), like with the COMMON HARED. All Type-statements must be removed '$INCLUDE: 'filename.ext' $INCLUDE "filename.ext" '$DYNAMIC $DYNAMIC '$STATIC $STATIC CONST VarName$ = "xyz" The variable must be replaced in the CONST VarName# = 1.23 whole program with the specified value. CONST VarName! = 1.23 CONST VarName@ = 1.23 CONST VarName% = 123 Becomes CONST VarName& = 123 %VarName = 123 both times. If a Constant-Name is used twice, with different Datatypes, one of the two must be replaced in the entire source with 'VarName%' or 'VarName&'. IF x THEN : ' Test In PB only the ':' has to be something removed and it will be compiled without END IF problems. DIM x AS STRING*3 This FIXED-LENGTH-STRING can not be CALL Test(x) passed to a procedure without END problems, because PB needs a VARIABLE- SUB Test(x$) LENGTH-STRING or instead of the 'x$' an END SUB 'x AS STRING * 3' in the SUB-Header. You have to use a temporary way over a temporary String: It would be idle to write a converter for the Constants-Conversion, because this would be the main part when converting big projects. At the same time you can of course do the stuff with the COMMON SHAREDs and the DIM SHAREDs and of course with the META-Statements, as well as SSEG/SADD/SSEGADD. When interrupt calls are made with a CALL INTERRUPT or CALL INTERRUPTX, then you can rebuild the Routine 'INTERRUPTX' in the InLine-Assembler and then convert all calls of 'INTERRUPT' to 'INTERRUPTX' or directly do it in the InLine-Assembler or you can use the PowerBASIC 'CALL INTERRUPT'- Routine, where you will have to convert all register statements... --- CrossPoint v3.11 R * Origin: PBSOUND, PBFILES (32MB), PBFAQ, PBRULES, PBHIVGA at: 2:2410/330.1) --------------- FIDO MESSAGE AREA==> TOPIC: 214 POWER BASIC Ref: F1200013 Date: 01/01/98 From: THOMAS GOHEL Time: 12:00am \/To: ALLE (Read 1 times) Subj: FAQ: PowerBASIC 14/16 (Toolboxes) ================================================ 9. Available Shareware & Public Domain Solutions ================================================ There are many more Toolboxes, but I just want to present you a few of the most important. 9.1. PBSOUND for PowerBASIC 3.0/3.2 9.2. HiVGA for PowerBASIC 2.1/3.2 9.3. PBVISION for PowerBASIC 3.0/3.1 9.4. PBCompress for PowerBASIC 3.1 9.5. Personal Protocol/Communication Library for PowerBASIC 9.6. POW! - Sound Blaster Toolkit 9.7. PBGUI Toolkit for PowerBASIC 3.0 9.8. PBWizard 9.9. SVGA for PowerBASIC 9.10. MAXLIB for PowerBASIC v1.2 9.11. DWDOOR for PowerBASIC 3.x 9.12. Special-Power / Spezialtools for PowerBASIC 2.1/3.0 9.13. BWSB - Bells, Whistles and Sound Boards 9.14. Public Domain Sourcen from german programmers 9.15. Public Domain Sourcen welche oft bentigt werden 9.1. PBSOUND for PowerBASIC 3.0/3.2 ----------------------------------- Language: German / English Author : Thomas Gohel | Version : v1.90 Price : 40,-DM/80,-DM / $40/$80 (privat/commercial) Supply : PowerBASIC filearea: PBSOUND Fido-Request with Magic 'PBSOUND' at 2:2410/330 (33.6 & ISDN) InterNet: http://www.snafu.de/~pbsound/ File : PBSOUND.ZIP (v1.80) The recommended Operatingsystem for PBSOUND for PowerBASIC is MS-DOS in the Versions 5.0, 6.x, 7.0 or MS-Windows 95. Features: - support all Creative Labs Sound Blaster models, SB16 and SB32AWE incl. Upgradeboards such as WaveBlaster I+II and Roland SoundCanvas SCD10/15 - supports the internal PC-Speaker - playback from MIDI- and VOC-Files in the background and within the IDE - no size limits with VOC-files - playback/recording up to 44100, Stereo and 16bit with a SB16 or SB32AWE - support the SBPro/SB16 mixers - Speechsynthesis with SBTALKER.EXE - Online-Help for the PowerBASIC-IDE - PBPLAY, MIDI/VOC-player tool - PBREC, VOC-recording tool - PBSPEAK, VOC/WAV player for speaker - PBW2V, VOC<->WAV conversion program - with PBSOUND-library & EXE conception! - You can now create executable PowerBASIC files up to 4GigaByte with PBSOUND! - demo & introductoryprogram - complete with INSTALL & SETUP-Program - with source: to programming the CT-VOICE.DRV & the SBPro mixerchip 9.2. HiVGA for PowerBASIC 2.1/3.2 --------------------------------- Language: German / English Author : Matthaeus Stadler Version : v2.0 Price : 40,-DM Supply : PowerBASIC filearea: Toolkits (Deutschland) Fido-Request with Magic 'PBHIVGA' at 2:2410/330 (33.6 & ISDN) InterNet: http://www.snafu.de/~pbsound/ File : HIVGA20B.ZIP Features: - fast graphic routines for standard VGA, SVGA and VESA 256-, 32k and 65k colors, automatic VGA Adapter recognition. - basic graphic routines, splitscreen, scrolling, floodfill, GetImg, SetImg, sprite routines, bitmap scaling. - loads and saves PCX-, Targa-, HVS-files. - linking of bitmaps to the program .exe file. - mouse routines for all modes, scalable text, fading, color- cycling, color definition. - up to 4 pages in 320*200, several pages up to 1600*1200. - including user defined fonts (until 16x32) - possible usage of free VGA memory for graphics. - no functional restrictions in shareware version. - demo program with sourcecode included. 9.3. PBVISION for PowerBASIC 3.0/3.1