QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

Example for all EMS routines

March 9 2002 at 1:27 PM
  (no login)


Response to EMS routines using CALL ABSOLUTE routines

 
This example adds yet another assembly routine, PutPixel, which is the equivalent of the following:
DEF SEG = &hA000
A& = Y * 64
B& = A& * 4
POKE X + A& + B&, C
(Note that Y*64 + Y*64*4 equals Y*320)

DEFINT A-Z

'________________________________________________________________________

DIM SHARED AsmString(10) AS STRING * 50, AsmPointer(10), AsmSegment(10)

AsmPrepare

'________________________________________________________________________

CLS

'********* Look for EMS *********

IF EmsInstalled THEN
PRINT "No EMS available"
END
END IF

'********* Get EMS page segment *********

IF EmsPageFrameSegment(EmsSegment) THEN
PRINT "error2"
END
END IF

PRINT "Ems Page Frame segment:" + HEX$(EmsSegment)

'********* Get EMS page count *********

Status = EmsPages(Total, Available)
IF Status THEN
PRINT "Error EmsPages: "; HEX$(Status)
END
END IF

PRINT "Total EMS:"; Total; "16K Pages"
PRINT "Available EMS:"; Available; "16K Pages"

'********* Show number of used handles *********

Status = EmsNumHandles(Handles)
IF Status THEN
PRINT "Error EmsNumHandles: "; HEX$(Status)
GOTO EndThis
END IF

PRINT "EmsNumHandles"; Handles

'********* Create handle *********

Status = EmsAllocate(256, NewHandle)
IF Status THEN
PRINT "Error EmsAllocate: "; HEX$(Status)
GOTO EndThis
END IF

'********* Create Handle *********

PRINT "NewHandle:"; NewHandle

Status = EmsPages(Total, Available)
IF Status THEN
PRINT "Error EmsPages: "; HEX$(Status)
GOTO EndThis
END IF

PRINT "Total EMS:"; Total; "16K Pages"
PRINT "Available EMS:";
IF Available = 1024 THEN PRINT " >";
PRINT Available; "16K Pages"

'********* Create Handle *********

Status = EmsNumPages(NewHandle, NumPages)
IF Status THEN
PRINT "Error EmsNumPages:"; HEX$(Status)
GOTO EndThis
END IF

PRINT "NumPages:"; NumPages; "16K Pages"

'________________________________________________________________________

i$ = INPUT$(1)
SCREEN 13

mag! = 1

FOR A = 0 TO 63
Mandel mag!, -1.9, 4, 48

Status = EmsMap(NewHandle, A * 4, 4)
IF Status THEN
PRINT "Error EmsMap:"; HEX$(Status)
GOTO EndThis
END IF

MemCopy &HA000, 0, EmsSegment, 0, 64000
mag! = mag! / 1.1
IF LEN(INKEY$) THEN GOTO EndThis
NEXT

A = 0
aa = 1
DO UNTIL LEN(INKEY$)
Status = EmsMap(NewHandle, A * 4, 4)
IF Status THEN
PRINT "Error EmsMap:"; HEX$(Status)
GOTO EndThis
END IF

WAIT &H3DA, 8, 8
WAIT &H3DA, 8
MemCopy EmsSegment, 0, &HA000, 0, 64000
A = A + aa
IF A = 63 OR A = 0 THEN aa = -aa
LOOP


EndThis:

'********* Release handle *********

EmsRelease (NewHandle)

'
'
END

'________________________________________________________________________



MemCopyAsmData:
DATA 0,1E8B760C8B460A8EC08B7E088B4E068B460E8ED8F3A41F
EmsInstalledAsmData:
DATA 1,B440CD67B0008B7E068905
EmsPageFrameSegmentAsmData:
DATA 2,B441CD67B0008B7E0689058B7E08891D
EmsPagesAsmData:
DATA 3,B442CD67B0008B7E0689058B7E0A89158B7E08891D
EmsAllocateAsmData:
DATA 4,8B5E0AB443CD67B0008B7E0689058B7E088915
EmsReleaseAsmData:
DATA 5,B4458B5606CD67
EmsNumPagesAsmData:
DATA 6,8B560AB44CCD67B0008B7E0689058B7E08891D
EmsMapAsmData:
DATA 7,8B560C8B5E0A8B4E0830C0B444CD6780FC007507FEC043E2F2B00030C08B7E068905
EmsNumHandlesAsmData:
DATA 8,B44BCD6730C08B7E0689058B7E08891D
PutPixelAsmData:
DATA 9,B800A08EC08B460A8B5E0889C7C1E30689D8C1E00201C301DF8A4606AA
DATA -1


SUB AsmPrepare STATIC
DO
READ Number
IF Number = -1 THEN EXIT SUB

AsmSegment(Number) = VARSEG(AsmString(Number))
AsmPointer(Number) = VARPTR(AsmString(Number))

'55 PUSH BP
'89E5 MOV BP,SP
'...user routine
'5D POP BP
'CB RETF

READ AsmHex$
AsmHex$ = "5589E5" + AsmHex$ + "5DCB"

asmbytes = LEN(AsmHex$) \ 2

DEF SEG = AsmSegment(Number)

FOR A = 0 TO asmbytes - 1
POKE AsmPointer(Number) + A, VAL("&h" + MID$(AsmHex$, A * 2 + 1, 2))
NEXT
LOOP
END SUB

'Create a handle and allocate EMS pages to the handle
'
'MOV BX,[BP+0A] ;NumPages
'MOV AH,43
'INT 67
'MOV AL,00
'MOV DI,[BP+06] ;Status
'MOV [DI],AX
'MOV DI,[BP+08] ;Handle
'MOV [DI],DX
'
'IN: WORD number of logical pages to allocate
'OUT: WORD handle if successfull
'
FUNCTION EmsAllocate (NumPages, Handle) STATIC
RESTORE EmsAllocateAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(BYVAL NumPages, Handle, Status, AsmPointer(Number))

EmsAllocate = Status
END FUNCTION

'Get EMS manager status
'
'MOV AH,40
'INT 67
'MOV AL,00
'MOV BX,[BP+06] ;Status
'MOV [BX],AX
'
FUNCTION EmsInstalled STATIC
RESTORE EmsInstalledAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(Status, AsmPointer(Number))

EmsInstalled = Status
END FUNCTION

'Assign up to 4 EMS pages to the EMS page frame segment.
'
'MOV DX,[BP+0C] ;Handle
'MOV BX,[BP+0A] ;Page
'MOV CX,[BP+08] ;NumPages
'XOR AL,AL
';000B
'MOV AH,44
'INT 67
'CMP AH,00
'JNZ 001B
'INC AL
'INC BX
'LOOP 000B
'MOV AL,00
';001B
'MOV DI,[BP+06] ;Status
'MOV [DI],AX
'
'IN: WORD handle
' WORD logical page number or FFFFh to unmap (QEMM)
' WORD number of physical pages (1-4)
'
FUNCTION EmsMap (Handle, Page, NumPages) STATIC
RESTORE EmsMapAsmData
READ Number

A = NumPages
IF A > 4 THEN A = 4
IF A < 1 THEN A = 1

DEF SEG = AsmSegment(Number)
CALL Absolute(BYVAL Handle, BYVAL Page, BYVAL A, Status, AsmPointer(Number))
EmsMap = Status
END FUNCTION

'Get number of handles in use of the program
'
'MOV AH,4B
'INT 67
'MOV DI,[BP+06] ;Status
'MOV [DI],AX
'MOV DI,[BP+08] ;NumHandles
'MOV [DI],BX
'
'OUT: WORD number of handles
'
FUNCTION EmsNumHandles (Numhandles) STATIC
RESTORE EmsNumHandlesAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(Numhandles, Status, AsmPointer(Number))

EmsNumHandles = Status
END FUNCTION

'Get pages owned by a handle
'
'MOV DX,[BP+0A]
'MOV AH,4C
'INT 67
'MOV AL,00
'MOV DI,[BP+06]
'MOV [DI],AX
'MOV DI,[BP+08]
'MOV [DI],BX
'
'IN: WORD handle
'OUT: WORD number of logical pages
'
FUNCTION EmsNumPages (Handle, NumPages) STATIC
RESTORE EmsNumPagesAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(BYVAL Handle, NumPages, Status, AsmPointer(Number))

EmsNumPages = Status
END FUNCTION

'Get the page frame segment
'
'MOV AH,41
'INT 67
'MOV AL,00
'MOV DI,[BP+06] ;Status
'MOV [DI],AX
'MOV DI,[BP+08] ;PageFrameSeg
'MOV [DI],BX
'
'OUT: WORD segment of page frame
'
FUNCTION EmsPageFrameSegment (PageFrameSeg) STATIC
RESTORE EmsPageFrameSegmentAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(PageFrameSeg, Status, AsmPointer(Number))

EmsPageFrameSegment = Status
END FUNCTION

'Get the total and free number of EMS pages
'
'MOV AH,42
'INT 67
'MOV AL,00
'MOV DI,[BP+06] ;Status
'MOV [DI],AX
'MOV DI,[BP+08] ;AvailablePages
'MOV [DI],BX
'MOV DI,[BP+0A] ;TotalPages
'MOV [DI],DX
'
'OUT: WORD number of unallocated pages
' WORD total number of pages
'
FUNCTION EmsPages (TotalPages, AvailablePages) STATIC
RESTORE EmsPagesAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(TotalPages, AvailablePages, Status, AsmPointer(Number))

EmsPages = Status
END FUNCTION

'Discard a handle and Release memory
'
'MOV AH,45
'MOV DX,[BP+06] ;Handle
'INT 67
'
'IN: WORD handle
'
SUB EmsRelease (Handle) STATIC
RESTORE EmsReleaseAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(BYVAL Handle, AsmPointer(Number))
END SUB

SUB Mandel (MagX!, CenX!, Bailout!, Maxiter)
MagY! = MagX! * .75
FOR j = 1 TO 100
v! = (j / 100) * MagY!
FOR i = 0 TO 319
u! = (i - 160) / 160 * MagX! + CenX!

X! = u!: Y! = v!
C = 0
FOR k = 1 TO Maxiter
xx! = X! * X!
yy! = Y! * Y!
IF xx! + yy! > Bailout! THEN C = k: EXIT FOR
Y! = 2 * X! * Y! + v!
X! = xx! - yy! + u!
NEXT
PutPixel i, 100 - j, C
PutPixel i, 99 + j, C
NEXT
NEXT
END SUB

'Copy in memory
'
'PUSH DS
'MOV SI,[BP+0C] ;SrcPtr
'MOV AX,[BP+0A] ;DstSeg
'MOV ES,AX
'MOV DI,[BP+08] ;DstPtr
'MOV CX,[BP+06] ;NumBytes
'MOV AX,[BP+0E] ;SrcSeg
'MOV DS,AX
'REPZ
'MOVSB
'POP DS
'
'IN: WORD Source segment
' WORD Source pointer
' WORD Destination segment
' WORD Destination pointer
' WORD Number of bytes to copy
'
SUB MemCopy (SrcSeg, SrcPtr, DstSeg, DstPtr, NumBytes&) STATIC
RESTORE MemCopyAsmData
READ Number

IF NumBytes& > 32767 THEN
A = NumBytes& - 65536
ELSE
A = NumBytes&
END IF

DEF SEG = AsmSegment(Number)
CALL Absolute(BYVAL SrcSeg, BYVAL SrcPtr, BYVAL DstSeg, BYVAL DstPtr, BYVAL A, AsmPointer(Number))
END SUB

'Put a pixel faster than PSET. (SCREEN 13 only)
'
'MOV AX, A000
'MOV ES, AX
'MOV AX,[BP+0A] ;Y
'MOV BX,[BP+08] ;X
'MOV DI, AX
'SHL BX, 6
'MOV AX, BX
'SHL AX, 2
'ADD BX, AX
'ADD DI, BX
'MOV AL,[BP+06] ;C
'STOSB
'
'IN: WORD X
' WORD Y
' WORD C
'
SUB PutPixel (X, Y, C)
RESTORE PutPixelAsmData
READ Number

DEF SEG = AsmSegment(Number)
CALL Absolute(BYVAL X, BYVAL Y, BYVAL C, AsmPointer(Number))
END SUB



 
 Respond to this message   
 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement