--------------- FIDO MESSAGE AREA==> TOPIC: 214 POWER BASIC Ref: E1400009 Date: 01/01/97 From: THOMAS GOHEL Time: 12:00am \/To: ALLE (Read 3 times) Subj: FAQ: PowerBASIC 10/16 (Assembler Part 2)00:00:0001/01/97 5.10. Parameter return with the InLine-Assembler ----------------------------------------------- In opposite to true Assembler the return of a variable works slightly different in the PowerBASIC InLine-Assemble. PowerBASIC 3.0 for example does not allow the direct return from the InLine-Assembler to the FUNCTION, this is only possible with a little trick. Example: High% = &h1234 Low% = &h4578 PRINT HEX$(Demo1&(High%, Low%)) FUNCTION Demo1&(BYVAL High%, BYVAL Low%) LOCAL Dummy& ! mov dx, High% ! mov ax, Low% ! mov Dummy&[02], dx ! mov Dummy&[00], ax Demo1& = Dummy& END FUNCTION From PowerBASIC 3.1 on you can directly pass the return value to the FUNCTION, only with 32bit (and bigger) values have to be passed using a little trick: Example: High% = &h1234 Low% = &h4578 PRINT HEX$(Demo2&(High%, Low%)) FUNCTION Demo2&(BYVAL High%, BYVAL Low%) ! mov dx, High% ! mov ax, Low% ! mov FUNCTION[02], dx ! mov FUNCTION[00], ax END FUNCTION 5.11. Parameter return in Interrupt-Procedures --------------------------------------------- Very hard is the passing of variables from within an own Interruptroutine, because you can guess that the Datasegment isn't the same as the one used by PowerBASIC. But the developers of PowerBASIC have left us a big back door here. The addressing using the Codesegment, which is usually the same! Yet this trick only works with the InLine-Assembler, to pass from/ to true PowerBASIC-Routines you will have to recopy this variable. Example: ! mov ax, &h1234 ! mov Demo, ax ! mov bx, Demo ! retn Demo: ! dw 0 Should you look at this thing with a Debugger, you will notice that PowerBASIC will add the Prefix &h2E (addressing using the Codesegment) in front of the access to the variable and the '!dw 0' field will hold the value &H1234. 5.12. Creating 32Bit-Pointers ----------------------------- Often 32Bit Pointers are needed for some Interrupt-Procedures to call old Interrupt-Handlers or Devicedrivers like CTVDSK/CT-VOICE and HIMEM/ MSCDEX. Because the creation of a 32Bit Pointer was described in a previous Chapter, here is the actual Syntax: Example: ! jmp dword Demo& ! jmp dword ptr Demo& ! call dword Demo& ! call dword ptr Demo& The pointers can also be taken from the Codesegment! 5.13. Converting from REG to InLine-Assembler --------------------------------------------- The conversion from REG- to InLine-Assemblersources is also relatively simple. Instrad of the REG-Command, which buffers the Contents of the Processorregisters in an internal REG-Array, an access over the InLine- Assembler causes a direct manipulation of the Processorregister. The REG-Command passes the REG-Values when CALL INTERRUPT is executed. Please not this difference and you will have not as many problems. You can translate all other commands 1:1: Example: REG 1, &h12345 -> ! mov ax, &h1234 REG 2, &hFF -> ! mov bl, &hFF REG 3, &h22 * 256 -> ! mov ch, &h22 REG 4, &hAABB -> ! mov dh, &hAA ! mov dl, &hBB REG 9, Demo% -> ! mov es, Demo% CALL INTERRUPT &h21 -> ! int &h21 Low?? = REG(1) AND 255 -> ! mov low??, al High?? = REG(1) \ 256 -> ! mov High??, ah 5.14. Converting from A86 to InLine-Assembler --------------------------------------------- Usually a translation of A86-Sources can be done without problems. Remove the Stackborder and include the Assemblerlines into the InLine- Assembler. It will be best ig you create a FUNCTION call that passes the variables BYVAL, the rest is done by PowerBASIC. --- CrossPoint v3.11 R * Origin: PBSOUND, PBFILES (20MB), PBFAQ, PBRULES, PBHIVGA at: 2:2410/330.1) --------------- FIDO MESSAGE AREA==> TOPIC: 214 POWER BASIC Ref: E1400010 Date: 01/01/97 From: THOMAS GOHEL Time: 12:00am \/To: ALLE (Read 3 times) Subj: FAQ: PowerBASIC 11/16 (Pointer) ======================================= 6. Hints for Pointers in PowerBASIC 3.2 ======================================= Shortindex: 6.1. Pointers in general 6.2. What are pointers, and what are they for? 6.3. PowerBASIC-Pointers and dynamic strings 6.4. PowerBASIC-Pointers and fixed length strings 6.5. PowerBASIC-Pointer and FLEX-Strings 6.6. PowerBASIC-Pointer and TYPE structures 6.7. A little Demonstration (source) 6.1. Pointers in general ------------------------ Pointers in BASIC have been the cause for many discussions so far. PowerBASICS's Dynamic Memory-Managment has been an argument why Pointers in BASIC (if not impossible) don't make any sense. The following paragraphs will show that this is wrong. Dynamic Memory- Managment (which by the way is a real advantage of this language) and pointers are a possible combination. For the understanding of the follwing, knowledge of the interna of BASIC and DOS helps a lot 6.2. What are pointers, and what are they for ? ----------------------------------------------- Pointers do what their name says: they point. They allow interpreting every single byte of your computers memory up to 1 Megabyte. All you have to do is to assign any memory adress to the pointer. Pointers are useful to get to areas of the memory that are outside of PowerBASIC's Dynamic-Memory- Managment and they let you directly get hold of the Pointers that are given back by some DOS-Functions like: - Directory Table Area - Drive Parameter Block - DOS Info Block - PSP - Environment Block - and and and ... With pointers you can forget all those tiresome "old friends" like DEF SEG/POKE/PEEK or DEF SEG = PEEKI(...)! 6.3. PowerBASIC-Pointers and dynamic strings -------------------------------------------- String-Pointers to dynamic strings are defined in PowerBASIC with: DIM Pointer AS STRING PTR The Pointer is assigned as follows Pointer = VARPTR32(Demo1$) Example: '*************************************************************** ' ' Demosource showing how to handle pointers and dynamic strings ' '*************************************************************** DIM Pointer1 AS STRING PTR ' defining string pointer for ' dynamic strings Pointer1 = VARPTR32(Demo1$) ' assign the pointer CLS PRINT "Adress: Demo1$: Pointer1:" Demo1$ = "123456" PRINT HEX$(VARPTR32(Demo1$)), Demo1$, @Pointer1 Demo1$ = "654321" PRINT HEX$(VARPTR32(Demo1$)), Demo1$, @Pointer1 Demo1$ = "!Test!" PRINT HEX$(VARPTR32(Demo1$)), Demo1$, @Pointer1 6.4. PowerBASIC-Pointers and fixed length strings