Qbasicnews.com
April 03, 2020, 07:36:27 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: ASM in QB problem  (Read 3732 times)
Z!re
*/-\*
*****
Posts: 4599


« on: March 31, 2004, 09:28:34 AM »

First the ASM programs (The first row is the machine code used in QB, and then the program in ASM code):
Code to initialize VESA
Code:
5589E5B8034FCD108B5E0689075DCA0200

push bp
mov bp, sp
mov ax, 04f03h
int 10h
mov bx, [bp+06]
mov [bx], ax
pop bp
retf 2


That one works perfectly, and returns 4Fh on my computer (VESA detected)

Then I call this:
Code:
5589E5B8024F8B5E06CD105DCB

push bp
mov bp, sp
mov ax, 4f02h
mov bx, [bp+6]
int 10h
pop bp
retf

Which is supposed to change the resolution to the value passed
QB 7.1 code (change SSEG to VARSEG and SADD to VARPTR in QB 4.5)
Code:
qbasicasm$="5589E5B8024F8B5E06CD105DCB"
[...] 'transform it to machine code...
Res=&H101
DEF SEG SSEG(asmmach$)
 Call Absolute(Res, SADD(asmmach$))
DEF SEG


That crashes or returns nothing (IE. Does nothing)

So i tried changing it directly:
Code:
5589E5B8024FBB0101CD108B5E0689075DCA0200


push bp
mov bp, sp
mov ax, 04f02h
mov bx, 0101h
int 10h
mov bx, [bp+06]
mov [bx], ax
pop bp
retf 2


Change resolution to mode 101h (640x480x8bit) and return if it was successful (AH = 4f is supported, AL=1 is successfull 0 if failed.... it might be the other way around on AH and AL.. doesent really matter)

That crashes...


So.. any help ould be greatly appreciated...
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #1 on: March 31, 2004, 10:24:28 AM »

Ok, I got the direct way of setting a resolution to work (*cough.* misspelled string name)... but the code to set to a custom mode:

Code:
5589E5B8024F8B5E06CD105DCB

push bp
mov bp, sp
mov ax, 4f02h
mov bx, [bp+6]
int 10h
pop bp
retf


It crashes...

Only difference from the direct set is the mov bx,[bp+6] part.. (mov bx, 101h)
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #2 on: March 31, 2004, 10:44:24 AM »

You need to use retf 2 because you're passing an integer...also, the mode needs to be passed BYVAL for that code to work.

Code:
asm$ = "5589E5B8024F8B5E06CD105DCA0200"
FOR i = 1 TO LEN(asm$) STEP 2
  asmmach$ = asmmach$ + CHR$(VAL("&H" + MID$(asm$, i, 2)))
NEXT

Res% = &H101
DEF SEG = SSEG(asmmach$)
CALL Absolute(BYVAL Res%, SADD(asmmach$))


That works fine for me...but why not just use Call Interrupt?
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #3 on: March 31, 2004, 11:03:36 AM »

Thanx.

I'm writing (trying to) my own graphics routines, and don't want to include them in the code, they should be replacable.


So you have to use retf 2 (or how many bytes passed) both when passing, and returning? or only when passing?

EDIT:
How would I pass a resolution to it, and make it return a value?

call absolute(byval resolution, Failed%, sadd(asm$))
if failed% <> &h4f then print "Failed to set resolution"

I can't get the ASM code to work... I think I messed up though... :oops:
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #4 on: March 31, 2004, 12:56:44 PM »

I don't really get what you mean by "don't want to include them in the code"...if you want to make a library, call absolute is not the way to go. You're better off using an assembler and linking the assembled object files to your program.

Anyhow, the only way to "return" a value with call absolute is to place it in the address of a variable passed by reference. I believe this is what you're trying to do:

Code:
55            PUSH    BP
89E5          MOV     BP,SP
B8024F        MOV     AX,4F02
8B5E08        MOV     BX,[BP+08]
CD10          INT     10
8B5E06        MOV     BX,[BP+06]
8907          MOV     [BX],AX
5D            POP     BP
CA0400        RETF    0004



Here's how you'd do the same thing with TASM or MASM:

Code:
.model medium, basic
.code

public  setmode
setmode proc mode:word

mov ax, 4f02h
mov bx, mode
int 10h
; whatever's in ax gets returned by the function
ret

setmode endp
end


QB code would look like:
Code:
DECLARE FUNCTION setmode% (BYVAL mode%)
status% = setmode%(&H101)
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #5 on: March 31, 2004, 02:56:25 PM »

Thanx, it worked, I had switched place on bp+8 and bp+6


It's for Novix...

I'm making the gfx routines external asm files, that are loaded at startup...

So you can change them to more optimized code later on, without having to recompile Novix
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #6 on: March 31, 2004, 07:57:18 PM »

I see. Kind of like a ghetto dll... Smiley
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #7 on: March 31, 2004, 08:00:20 PM »

hehe..... Ghetto?.... lol



I'm reading in on various library/dll formats....

There must be a way to get highres in qb, and use existing drivers...


I'm herby declaring that there exist a way... :king:
Logged
adosorken
*/-\*
*****
Posts: 3655



WWW
« Reply #8 on: March 31, 2004, 08:12:24 PM »

Any particular reason you're opting for gross-ass CALL ABSOLUTE and not nice slender CALL INTERRUPT? It's all interrupts anyways... Smiley
Logged

I'd knock on wood, but my desk is particle board.
Z!re
*/-\*
*****
Posts: 4599


« Reply #9 on: March 31, 2004, 08:22:01 PM »

I don't know...

I have machine code...

(Compiled asm)

Is there anyother way to execute it?.. other than absolute...




(You know Nek, it would be easier to talk if you hadn't blocked me on msn.... :wink: or if you came online)
Logged
adosorken
*/-\*
*****
Posts: 3655



WWW
« Reply #10 on: March 31, 2004, 10:03:32 PM »

Hey, I'm online right now but I don't see you anywhere! Tongue
Logged

I'd knock on wood, but my desk is particle board.
Z!re
*/-\*
*****
Posts: 4599


« Reply #11 on: April 01, 2004, 06:19:23 AM »

That would be because I'm GMT+1.... so you where online at 2AM :lol:

But is there any other way to execute ASM in qb? Ans is it faster then Call Absolute?
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #12 on: April 01, 2004, 08:07:00 AM »

Quote from: "Z!re"
That would be because I'm GMT+1.... so you where online at 2AM :lol:

But is there any other way to execute ASM in qb? Ans is it faster then Call Absolute?


SuperPut. :*)


And I would use Plasma's ASM convention instead of referencing the stack using BP offsets. :*)

I should know, I used to do that until Blitz showed some "clean" code here. :*)

And if you  want to have an ASM to Opcode converter, you can PM Plasma. :*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Z!re
*/-\*
*****
Posts: 4599


« Reply #13 on: April 01, 2004, 09:15:11 AM »

I don't get it, SuperPut overwrites a part of memory where PUT resides, how does that help me? :Huh:


I want the asm code in external files, (They are actually com files.. just noticed Tongue ...)

I load them, and then execute them when needed...

IE: I load each ASM program into a string, and use call absolute on it when needed...

This is because I want them to be changeable, without having to recompile the entire program with a new lib/new source...
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #14 on: April 01, 2004, 09:22:16 AM »

Well, you can make a loader from a file and call the routine as needed. Muck like a DLL. :*)

And List 2 op would help you speed up the process. :*) ask Plaz.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!