CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

MPLIB.CPP (2946B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 #include "types.h"
     17 #include "mgenord.h"
     18 #include "magic.h"
     19 #include "rtq.h"
     20 #include <mem.h>
     21 #include <i86.h>
     22 #include <assert.h>
     23 #include "mplib.h"
     24 
     25 #define CHUNNEL_INT 0x48
     26 
     27 typedef union REGS REGISTERS;
     28 
     29 void
     30 Yield(void)
     31 {
     32    REGISTERS   regs;
     33 
     34    regs.w.ax = 0x1680;
     35    int386(0x2f, &regs, &regs);
     36 }
     37 
     38 void
     39 PostWindowsMessage(void)
     40 {
     41    REGISTERS regs;
     42 
     43    regs.x.eax = DPMIAPI_POST_WINDOWS_ORD << 16 | MGENVXD_DEVICE_ID;
     44    regs.x.ebx = 0;
     45    regs.x.ecx = 0;
     46    int386(CHUNNEL_INT, &regs, &regs);
     47 }
     48 
     49 int MGenGetQueueCtr(int qNo)
     50 {
     51    REGISTERS   regs;
     52 
     53    regs.x.eax = MGENVXD_GETQUEUECTR_ORD << 16 | MGENVXD_DEVICE_ID;
     54    regs.x.ebx = qNo;
     55    int386(CHUNNEL_INT, &regs, &regs);
     56 
     57    return regs.x.eax;
     58 }
     59 
     60 RTQ_NODE *MGenMoveTo(int qFrom, int qTo)
     61 {
     62    REGISTERS   regs;
     63 
     64    regs.x.eax = MGENVXD_MOVENODE_ORD << 16 | MGENVXD_DEVICE_ID;
     65    regs.x.ebx = qFrom;
     66    regs.x.ecx = qTo;
     67    int386(CHUNNEL_INT, &regs, &regs);
     68 
     69    return (RTQ_NODE *) regs.x.eax;
     70 }
     71 
     72 RTQ_NODE *MGenGetNode(int q)
     73 {
     74    REGISTERS   regs;
     75 
     76    regs.x.eax = MGENVXD_GETNODE_ORD << 16 | MGENVXD_DEVICE_ID;
     77    regs.x.ebx = q;
     78    int386(CHUNNEL_INT, &regs, &regs);
     79 
     80    return (RTQ_NODE *) regs.x.eax;
     81 }
     82 
     83 RTQ_NODE *MGenGetMasterNode(unsigned *size)
     84 {
     85    REGISTERS   regs;
     86 
     87    regs.x.eax = MGENVXD_MASTERNODE_ORD << 16 | MGENVXD_DEVICE_ID;
     88    int386(CHUNNEL_INT, &regs, &regs);
     89    *size = regs.x.ecx;
     90 
     91    return (RTQ_NODE *) regs.x.eax;
     92 }
     93 
     94 int MGenFlushNodes(int qFrom, int qTo)
     95 {
     96    REGISTERS   regs;
     97 
     98    regs.x.eax = MGENVXD_FLUSHNODE_ORD << 16 | MGENVXD_DEVICE_ID;
     99    regs.x.ebx = qFrom;
    100    regs.x.ecx = qTo;
    101    int386(CHUNNEL_INT, &regs, &regs);
    102 
    103    return regs.x.eax;
    104 }
    105 
    106 int MGenMCount(unsigned lowerOrderBits, unsigned upperOrderBits)
    107 {
    108    REGISTERS   regs;
    109 
    110    regs.x.eax = MGENVXD_MCOUNT_ORD << 16 | MGENVXD_DEVICE_ID;
    111    regs.x.ebx = lowerOrderBits;
    112    regs.x.ecx = upperOrderBits;
    113    int386(CHUNNEL_INT, &regs, &regs);
    114 
    115    return regs.x.eax;
    116 }
    117 
    118 int MGenSanityCheck(void)
    119 {
    120    REGISTERS   regs;
    121 
    122    regs.x.eax = MGENVXD_SANITYCHECK_ORD << 16 | MGENVXD_DEVICE_ID;
    123    int386(CHUNNEL_INT, &regs, &regs);
    124 
    125    return regs.x.eax;
    126 }
    127