;;  FICHERO PARA LA INCLUSIąN DE LAS FUNCIONES DE GRAPH.LIB
;;              NAVI DJ.     VILAMARXANT 1996

extrn DBorraPantalla:near
extrn DPonPixel:near
extrn DCogePixel:near
extrn DLinea:near
extrn DCreaVirtual:near
extrn DDestVirtual:near
extrn DCopiaPantalla:near
extrn DTrataError:near
extrn DCargaSprite:near
extrn DDibujaSprite:near
extrn DDestSprite:near
extrn DVaciaMEM:near
extrn DfDibujaSprite:near
extrn DfLinea:near
extrn DfPonPixel:near
extrn DfCogePixel:near
extrn DfBorraPantalla:near
extrn DCogeColor:near
extrn DPonColor:near
extrn DCogePaleta:near
extrn DPonPaleta:near
extrn DFadeDown:near
extrn DCargaPaleta:near
extrn DFadeUp:near
extrn DFadeTo:near
extrn DBlackOut:near
extrn DCargaCel:near
extrn DCargaAnima:near
extrn DPonFrameAnima:near
extrn DfPonFrameAnima:near
extrn DDestAnima:near
extrn DInsertaDirSprite:near
extrn DInsertaDirAnima:near
extrn DSegmentoSprite:near
extrn DSegmentoAnima:near
extrn DSegmentoPal:near
extrn DSegmentoPV:near
extrn DInsertaDirPV:near
extrn DInsertaDirPal:near
extrn DDescompPuntos:near
extrn DDescompWorm:near
extrn DfCaja:near
extrn DCaja:near
extrn DfRectangulo:near
extrn DRectangulo:near
extrn DPoligono:near
extrn DfPoligono:near
extrn DCreaSprite:near
extrn DCambiaSprites:near
extrn DGetImagen:near
extrn DfGetImagen:near
extrn DCirculo:near
extrn DfCirculo:near
extrn DLeePCX:near
extrn DDestPaleta:near
extrn DLeeBMP:near
extrn DPlayFLI:near
extrn DInicGRAPH:near
extrn DEndGRAPH:near
extrn DCargaFuente:near
extrn DCambiaTipo:near
extrn DQueTipo:near
extrn DEscLetra:near
extrn DCogeFuenteDOS:near
extrn DSetCursor:near
extrn DGetCursor:near
extrn DEscribe:near
extrn DLeeLetra:near
extrn DLeeLetraEcho:near
extrn DLeeByte:near
extrn DLeeCadena:near
extrn DLeeWord:near
extrn DEscByte:near
extrn DEscWord:near
extrn DWrite:near
extrn DNuevoArchivo:near
extrn DLeeEntrada:near
extrn DLeeTrozo:near
extrn DLongitudFile:near
extrn DFlipCopy:near
extrn DFlip:near
extrn DSegmentoFuente:near
extrn DSetStart:near
extrn DDoblaLineas:near
extrn DSetVSPixels:near
extrn DPideXMS:near
extrn DLiberaXMS:near
extrn DGetAddress:near
extrn DMaximaXMS:near
extrn DGuardaFlat:near
extrn DCargaFlat:near
extrn DCargaBloque:near
extrn DCargaMapa:near
extrn DDestBloque:near
extrn DDestMapa:near
extrn DDibujaMapa:near
extrn DPosMapa:near
extrn DInsertaDirBloque:near
extrn DInsertaDirMapa:near
extrn DSegmentoBloque:near
extrn DSegmentoMapa:near
extrn DResetGRAPH:near
extrn DModoGrafico:near
extrn DModoTexto:near
extrn DCreaMapa:near
extrn DCreaBloque:near
extrn DDestFuente:near
extrn DInsertaDirFuente:near
extrn DGetSysInfo:near

extrn Aleatorio:near

extrn LERROR:near                       ;  La variable de errores.
extrn Registro:near                     ;  El n§ de campo total.

INCLUDELIB GRAPH

;;  Funciones y macros adicionales de utilidad.

LiberaMEM       PROC                    ;  Funci¢n que libera la memoria
                MOV     BX, SS          ; reservada por el DOS a nuestro
                MOV     AX, ES          ; programa y que no es utilizada.
                SUB     BX, AX          ;  ES debe contener el PSP.
                MOV     AX, SP
                ADD     AX, 15d
                MOV     CL, 4
                SHR     AX, CL
                ADD     BX, AX
                MOV     AH, 4Ah
                INT     21h
                RET
LiberaMEM       ENDP

WaitVR          MACRO                   ;  Espera el retrazo vertical.
                PUSH    DX 
                PUSH    AX
                MOV     DX,03DAh
        @@St1:  IN      AL,DX
                TEST    AL,08h
                JZ    @@St1
        @@St2:  IN      AL,DX
                TEST    AL,08h
                JNZ   @@St2
                POP     AX 
                POP     DX
                ENDM

;;  ­Cuanto se hechan en falta este par de instrucciones!

XPUSH          MACRO regmem            ; apilar lista de registros
                 IRP rm, <regmem>
                   PUSH rm
                 ENDM
               ENDM

XPOP           MACRO regmem            ; desapilar lista de registros
                 IRP rm, <regmem>
                   POP rm
                 ENDM
               ENDM

;;  Aqui est n las MACROS de llamada de todas las funciones y procedimientos.

CargaAnima      MACRO
                XPUSH   <DS, BP, ES>
                CALL    WORD PTR CS:[DCargaAnima]
                XPOP    <ES, BP, DS>
                ENDM
                
PonFrameAnima   MACRO
                XPUSH   <ES, DS>
                PUSHA
                CALL    WORD PTR CS:[DPonFrameAnima]
                POPA
                XPOP    <DS, ES>
                ENDM

fPonFrameAnima  MACRO
                XPUSH   <ES, DS>
                PUSHA
                CALL    WORD PTR CS:[DfPonFrameAnima]
                POPA
                XPOP    <DS, ES>
                ENDM

DestAnima       MACRO
                PUSH    ES
                PUSHA
                CALL    WORD PTR CS:[DDestAnima]
                POPA
                POP     ES
                ENDM


CogeColor       MACRO
                PUSH    DX
                CALL    WORD PTR CS:[DCogeColor]
                POP     DX
                ENDM

PonColor        MACRO
                PUSH    DX
                CALL    WORD PTR CS:[DPonColor]
                POP     DX
                ENDM

CogePaleta      MACRO
                XPUSH   <ES, DI>
                CALL    WORD PTR CS:[DCogePaleta]
                XPOP    <DI, ES>
                ENDM

PonPaleta       MACRO
                XPUSH   <ES, DI>
                CALL    WORD PTR CS:[DPonPaleta]
                XPOP    <DI, ES>
                ENDM

CargaPaleta     MACRO
                XPUSH   <DS, BX, CX, ES>
                CALL    WORD PTR CS:[DCargaPaleta]
                XPOP    <ES, CX, BX, DS>
                ENDM

FadeDown        MACRO
                PUSHA
                CALL    WORD PTR CS:[DFadeDown]
                POPA
                ENDM

FadeUp          MACRO
                PUSHA
                CALL    WORD PTR CS:[DFadeUp]
                POPA
                ENDM

FadeTo          MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DFadeTo]
                POP     ES
                POPA
                ENDM

BlackOut        MACRO
                XPUSH   <DX, CX>
                CALL    WORD PTR CS:[DBlackOut]
                XPOP    <CX, DX>
                ENDM

DestPaleta      MACRO
                XPUSH   <BX, ES>
                CALL    WORD PTR CS:[DDestPaleta]
                XPOP    <ES, BX>
                ENDM

PonPixel        MACRO
                PUSH    ES
                PUSHA
                CALL    WORD PTR CS:[DPonPixel]
                POPA
                POP     ES
                ENDM

fPonPixel       MACRO
                PUSH    ES
                PUSHA
                CALL    WORD PTR CS:[DfPonPixel]
                POPA
                POP     ES
                ENDM

BorraPantalla   MACRO
                PUSHAD
                PUSH    ES
                CALL    WORD PTR CS:[DBorraPantalla]
                POP     ES
                POPAD
                ENDM

fBorraPantalla  MACRO
                PUSHAD
                PUSH    ES
                CALL    WORD PTR CS:[DfBorraPantalla]
                POP     ES
                POPAD
                ENDM

CogePixel       MACRO
                XPUSH   <ES, DI, SI>
                CALL    WORD PTR CS:[DCogePixel]
                XPOP    <SI, DI, ES>
                ENDM

fCogePixel      MACRO
                XPUSH   <ES, DI, SI>
                CALL    WORD PTR CS:[DfCogePixel]
                XPOP    <SI, DI, ES>
                ENDM

Rectangulo      MACRO
                PUSHA
                CALL    WORD PTR CS:[DRectangulo]
                POPA
                ENDM

fRectangulo     MACRO
                PUSHA
                CALL    WORD PTR CS:[DfRectangulo]
                POPA
                ENDM

Circulo         MACRO
                PUSHA
                CALL    WORD PTR CS:[DCirculo]
                POPA
                ENDM

fCirculo        MACRO
                PUSHA
                CALL    WORD PTR CS:[DfCirculo]
                POPA
                ENDM

ModoGrafico     MACRO
                CALL    WORD PTR CS:[DModoGrafico]
                ENDM

ModoTexto       MACRO
                CALL    WORD PTR CS:[DModoTexto]
                ENDM

Linea           MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DLinea]
                POP     ES
                POPA
                ENDM

fLinea          MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DfLinea]
                POP     ES
                POPA
                ENDM

Caja            MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DCaja]
                POP     ES
                POPA
                ENDM

fCaja           MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DfCaja]
                POP     ES
                POPA
                ENDM

Poligono        MACRO
                PUSHA
                PUSH    DS
                CALL    WORD PTR CS:[DPoligono]
                POP     DS
                POPA
                ENDM

fPoligono       MACRO
                PUSHA
                PUSH    DS
                CALL    WORD PTR CS:[DfPoligono]
                POP     DS
                POPA
                ENDM


CreaVirtual     MACRO
                XPUSH   <BX, CX, DX>
                CALL    WORD PTR CS:[DCreaVirtual]
                XPOP    <DX, CX, BX>
                ENDM

CopiaPantalla   MACRO
                PUSHA
                XPUSH   <DS, ES>
                CALL    WORD PTR CS:[DCopiaPantalla]
                XPOP    <ES, DS>
                POPA
                ENDM

DestVirtual     MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DDestVirtual]
                POP     ES
                POPA
                ENDM


SegmentoPV      MACRO
                XPUSH   <AX, BX>
                CALL    WORD PTR CS:[DSegmentoPV]
                XPOP    <BX, AX>
                ENDM

SegmentoPal     MACRO
                XPUSH   <AX, BX>
                CALL    WORD PTR CS:[DSegmentoPal]
                XPOP    <BX, AX>
                ENDM

SegmentoSprite  MACRO
                XPUSH   <AX, BX>
                CALL    WORD PTR CS:[DSegmentoSprite]
                XPOP    <BX, AX>
                ENDM

SegmentoAnima   MACRO
                XPUSH   <AX, BX>
                CALL    WORD PTR CS:[DSegmentoAnima]
                XPOP    <BX, AX>
                ENDM

VaciaMEM        MACRO
                XPUSH   <AX, CX>
                CALL    WORD PTR CS:[DVaciaMEM]
                XPOP    <CX, AX>
                ENDM

TrataError      MACRO
                CALL    WORD PTR CS:[DTrataError]
                ENDM

InsertaDirPV    MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirPV]
                POP     BX
                ENDM

InsertaDirPal   MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirPal]
                POP     BX
                ENDM

InsertaDirSprite MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirSprite]
                POP     BX
                ENDM

InsertaDirAnima MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirAnima]
                POP     BX
                ENDM


CargaSprite     MACRO
                XPUSH   <DS, BP, ES>
                CALL    WORD PTR CS:[DCargaSprite]
                XPOP    <ES, BP, DS>
                ENDM

DestSprite      MACRO
                PUSH    ES
                PUSHA
                CALL    WORD PTR CS:[DDestSprite]
                POPA
                POP     ES
                ENDM

CambiaSprites   MACRO
                PUSHA
                CALL   CS:[DCambiaSprites]
                POPA
                ENDM

CreaSprite      MACRO
                CALL    WORD PTR CS:[DCreaSprite]
                ENDM

DibujaSprite    MACRO
                XPUSH   <DS, ES>
                PUSHA
                CALL    WORD PTR CS:[DDibujaSprite]
                POPA
                XPOP    <ES, DS>
                ENDM

fDibujaSprite   MACRO
                XPUSH   <DS, ES>
                PUSHA
                CALL    WORD PTR CS:[DfDibujaSprite]
                POPA
                XPOP    <ES, DS>
                ENDM

CargaCEL        MACRO
                XPUSH   <DS, ES>
                PUSHA
                CALL    WORD PTR CS:[DCargaCEL]
                POPA
                XPOP    <ES, DS>
                ENDM

GetImagen       MACRO
                XPUSH   <DS, ES, BX, CX, DX, DI, SI>
                CALL    WORD PTR CS:[DGetImagen]
                XPOP    <SI, DI, DX, CX, BX, ES, DS>
                ENDM

fGetImagen      MACRO
                XPUSH   <DS, ES, BX, CX, DX, DI, SI>
                CALL    WORD PTR CS:[DfGetImagen]
                XPOP    <SI, DI, DX, CX, BX, ES, DS>
                ENDM

DescompPuntos   MACRO
                PUSHAD
                CALL    WORD PTR CS:[DDescompPuntos]
                POPAD
                ENDM

DescompWorm     MACRO
                PUSHAD
                PUSH    ES
                CALL    WORD PTR CS:[DDescompWorm]
                POP     ES
                POPAD
                ENDM

LeePCX          MACRO
                CALL    WORD PTR CS:[DLeePCX]
                ENDM

;;  Nuevas en GRAPH 2.0

LeeBMP          MACRO
                CALL    WORD PTR CS:[DLeeBMP]
                ENDM

InicGRAPH       MACRO
                CALL    WORD PTR CS:[DInicGRAPH]
                ENDM

EndGRAPH        MACRO
                CALL    WORD PTR CS:[DEndGRAPH]
                ENDM

CambiaTipo      MACRO
                CALL    WORD PTR CS:[DCambiaTipo]
                ENDM

QueTipo         MACRO
                CALL    WORD PTR CS:[DQueTipo]
                ENDM

SetCursor       MACRO
                CALL    WORD PTR CS:[DSetCursor]
                ENDM

GetCursor       MACRO
                CALL    WORD PTR CS:[DGetCursor]
                ENDM

CargaFuente     MACRO
                XPUSH   <DS, CX, ES, DI>
                CALL    WORD PTR CS:[DCargaFuente]
                XPOP    <DI, ES, CX, DS>
                ENDM

CogeFuenteDOS   MACRO
                XPUSH   <ES, BP, DS, BX, CX, DX, SI, DI>
                CALL    WORD PTR CS:[DCogeFuenteDOS]
                XPOP    <DI, SI, DX, CX, BX, DS, BP, ES>
                ENDM

EscLetra        MACRO
                XPUSH   <ES, BP, DS>
                PUSHA
                CALL    WORD PTR CS:[DEscLetra]
                POPA
                XPOP    <DS, BP, ES>
                ENDM

Escribe         MACRO
                XPUSH   <DX, AX, SI>
                CALL    WORD PTR CS:[DEscribe]
                XPOP    <SI, AX, DX>
                ENDM

LeeLetra        MACRO
                CALL    WORD PTR CS:[DLeeLetra]
                ENDM

LeeLetraEcho    MACRO
                PUSH    CX
                CALL    WORD PTR CS:[DLeeLetraEcho]
                POP     CX
                ENDM

LeeByte         MACRO
                PUSHA
                XPUSH   <DS, ES>
                CALL    WORD PTR CS:[DLeeByte]
                XPOP    <ES, DS>
                POPA
                ENDM

LeeCadena       MACRO
                CALL    WORD PTR CS:[DLeeCadena]
                ENDM

LeeWord         MACRO
                PUSHA
                XPUSH   <DS, ES>
                CALL    WORD PTR CS:[DLeeWord]
                XPOP    <ES, DS>
                POPA
                ENDM

EscByte         MACRO
                PUSHA
                PUSH    DS
                CALL    WORD PTR CS:[DEscByte]
                POP     DS
                POPA
                ENDM

EscWord         MACRO
                PUSHA
                PUSH    DS
                CALL    WORD PTR CS:[DEscWord]
                POP     DS
                POPA
                ENDM

Write           MACRO
                PUSHA
                CALL    WORD PTR CS:[DWrite]
                POPA
                ENDM

NuevoArchivo    MACRO
                XPUSH   <CX, DI, ES>
                CALL    WORD PTR CS:[DNuevoArchivo]
                XPOP    <ES, DI, CX>
                ENDM

LeeEntrada      MACRO
                PUSH    DS
                PUSHA
                CALL    WORD PTR CS:[DLeeEntrada]
                POPA
                POP     DS
                ENDM

LeeTrozo        MACRO
                PUSH    DS
                PUSHA
                CALL    WORD PTR CS:[DLeeTrozo]
                POPA
                POP     DS
                ENDM

LongitudFile    MACRO
                XPUSH   <DS, AX, BX, CX, DX>
                CALL    WORD PTR CS:[DLongitudFile]
                XPOP    <DX, CX, BX, AX, DS>
                ENDM

FlipCopy        MACRO
                XPUSH   <DS, ES>
                PUSHA
                CALL    WORD PTR CS:[DFlipCopy]
                POPA
                XPOP    <ES, DS>
                ENDM

Flip            MACRO
                PUSHA
                CALL    WORD PTR CS:[DFlip]
                POPA
                ENDM

SegmentoFuente  MACRO
                PUSHA
                CALL    WORD PTR CS:[DSegmentoFuente]
                POPA
                ENDM

DoblaLineas     MACRO
                PUSH    DX
                CALL    WORD PTR CS:[DDoblaLineas]
                POP     DX
                ENDM

SetStart        MACRO
                XPUSH   <DX, AX>
                CALL    WORD PTR CS:[DSetStart]
                XPOP    <AX, DX>
                ENDM

SetVSPixels     MACRO
                PUSH    DX
                CALL    WORD PTR CS:[DSetVSPixels]
                POP     DX
                ENDM

PideXMS         MACRO
                PUSH    AX
                CALL    WORD PTR CS:[DPideXMS]
                POP     AX
                ENDM

LiberaXMS       MACRO
                PUSHA
                CALL    WORD PTR CS:[DLiberaXMS]
                POPA
                ENDM

GetAddress      MACRO
                PUSH    AX
                CALL    WORD PTR CS:[DGetAddress]
                POP     AX
                ENDM

MaximaXMS       MACRO
                CALL    WORD PTR CS:[DMaximaXMS]
                ENDM

GuardaFlat      MACRO
                XPUSH   <DS, GS, EDI, ES, SI>
                CALL    WORD PTR CS:[DGuardaFlat]
                XPOP    <SI, ES, EDI, GS, DS>
                ENDM

CargaFlat       MACRO
                PUSHA
                XPUSH   <DS, GS, EDI, EDX>
                CALL    WORD PTR CS:[DCargaFlat]
                XPOP    <EDX, EDI, GS, DS>
                POPA
                ENDM

CargaBloque     MACRO
                XPUSH   <DI, SI, DX, CX, BX, DS, ES>
                CALL    WORD PTR CS:[DCargaBloque]
                XPOP    <ES, DS, BX, CX, DX, SI, DI>
                ENDM

CargaMapa       MACRO
                XPUSH   <DI, SI, DX, CX, BX, DS, ES>
                CALL    WORD PTR CS:[DCargaMapa]
                XPOP    <ES, DS, BX, CX, DX, SI, DI>
                ENDM

DestBloque      MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DDestBloque]
                POP     ES
                POPA
                ENDM

DestMapa        MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DDestMapa]
                POP     ES
                POPA
                ENDM

DibujaMapa      MACRO
                PUSHAD
                XPUSH   <ES, DS, GS, FS>
                CALL    WORD PTR CS:[DDibujaMapa]
                XPOP    <FS, GS, DS, ES>
                POPAD
                ENDM

PosMapa         MACRO
                XPUSH   <BP, DS>
                CALL    WORD PTR CS:[DPosMapa]
                XPOP    <DS, BP>
                ENDM

InsertaDirBloque MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirBloque]
                POP     BX
                ENDM

InsertaDirMapa  MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirMapa]
                POP     BX
                ENDM

ResetGRAPH      MACRO
                CALL    WORD PTR CS:[DResetGRAPH]
                ENDM

SegmentoBloque  MACRO
                XPUSH   <AX, BX>
                CALL    WORD PTR CS:[DSegmentoBloque]
                XPOP    <BX, AX>
                ENDM

SegmentoMapa    MACRO
                XPUSH   <AX, BX>
                CALL    WORD PTR CS:[DSegmentoMapa]
                XPOP    <BX, AX>
                ENDM

PlayFLI         MACRO
                XPUSH   <DS, ES>
                PUSHAD
                CALL    WORD PTR CS:[DPlayFli]
                POPAD
                XPOP    <ES, DS>
                ENDM

CreaMapa        MACRO
                XPUSH   <BX, CX, DX>
                CALL    WORD PTR CS:[DCreaMapa]
                XPOP    <DX, CX, BX>
                ENDM

CreaBloque      MACRO
                XPUSH   <BX, CX, DX>
                CALL    WORD PTR CS:[DCreaBloque]
                XPOP    <DX, CX, BX>
                ENDM

DestFuente      MACRO
                PUSHA
                PUSH    ES
                CALL    WORD PTR CS:[DDestFuente]
                POP     ES
                POPA
                ENDM

InsertaDirFuente MACRO
                PUSH    BX
                CALL    WORD PTR CS:[DInsertaDirFuente]
                POP     BX
                ENDM

GetSysInfo      MACRO
                CALL    WORD PTR CS:[DGetSysInfo]
                ENDM
