]> Shamusworld >> Repos - rmac/blobdiff - op.c
Version bump for last commit. :-)
[rmac] / op.c
diff --git a/op.c b/op.c
index f0ec970cef2da8edc8984d374e226023c67ee1a7..6a7d51d6c45322bb213ff75769b2e6e53a0bbde1 100644 (file)
--- a/op.c
+++ b/op.c
@@ -2,7 +2,7 @@
 // Jaguar Object Processor assembler
 //
 // by James Hammons
-// (C) 2018 Underground Software
+// (C) 2019 Underground Software
 //
 
 #include "op.h"
 #include "sect.h"
 #include "token.h"
 
-// Macros to help define things (though largely unnecessary for this assembler)
-#define BITMAP    3100
-#define SCBITMAP  3101
-#define GPUOBJ    3102
-#define BRANCH    3103
-#define STOP      3104
-#define NOP       3105
-#define JUMP      3106
+#define DEF_MO
+#include "opkw.h"              // For MO_* macros
 
 // Function prototypes
-int HandleBitmap(void);
-int HandleScaledBitmap(void);
-int HandleGPUObject(void);
-int HandleBranch(void);
-int HandleStop(void);
-int HandleNOP(void);
-int HandleJump(void);
+static int HandleBitmap(void);
+static int HandleScaledBitmap(void);
+static int HandleGPUObject(void);
+static int HandleBranch(void);
+static int HandleStop(void);
+static int HandleNOP(void);
+static int HandleJump(void);
 
 // OP assembler vars.
 static uint8_t lastObjType;
@@ -43,7 +37,6 @@ static TOKEN fixupExpr[4] = { CONST, 0, 0, ENDEXPR };
 //static PTR fixupPtr = { .tk = (fixupExpr + 1) };             // C99 \o/
 static PTR fixupPtr = { (uint8_t *)(fixupExpr + 1) };  // meh, it works
 
-
 //
 // The main Object Processor assembler. Basically just calls the sub functions
 // to generate the appropriate code.
@@ -53,28 +46,32 @@ int GenerateOPCode(int state)
        if (!robjproc)
                return error("opcode only valid in OP mode");
 
+       // It's OK to call this before validating state. If the state is invalid, an
+       // error will be generated and no object file will be produced, so it
+       // doesn't matter if the line number symbols are a little off.
+       GENLINENOSYM();
+
        switch (state)
        {
-       case BITMAP:
+       case MO_BITMAP:
                return HandleBitmap();
-       case SCBITMAP:
+       case MO_SCBITMAP:
                return HandleScaledBitmap();
-       case GPUOBJ:
+       case MO_GPUOBJ:
                return HandleGPUObject();
-       case BRANCH:
+       case MO_BRANCH:
                return HandleBranch();
-       case STOP:
+       case MO_STOP:
                return HandleStop();
-       case NOP:
+       case MO_NOP:
                return HandleNOP();
-       case JUMP:
+       case MO_JUMP:
                return HandleJump();
        }
 
        return error("unknown OP opcode");
 }
 
-
 static inline void GetSymbolUCFromTokenStream(char * s)
 {
        strcpy(s, string[tok[1]]);
@@ -82,7 +79,6 @@ static inline void GetSymbolUCFromTokenStream(char * s)
        tok += 2;
 }
 
-
 static inline uint64_t CheckFlags(char * s)
 {
        GetSymbolUCFromTokenStream(s);
@@ -95,16 +91,16 @@ static inline uint64_t CheckFlags(char * s)
                return 0x04;
        else if (strcmp(scratchbuf, "RELEASE") == 0)
                return 0x08;
+
        return 0;
 }
 
-
 //
 // Define a bitmap object
 // Form: bitmap <data>, <xloc>, <yloc>, <dwidth>, <iwidth>, <iheight>, <bpp>,
 //              <pallete idx>, <flags>, <firstpix>, <pitch>
 //
-int HandleBitmap(void)
+static int HandleBitmap(void)
 {
        uint64_t xpos = 0;
        uint64_t ypos = 0;
@@ -183,7 +179,7 @@ int HandleBitmap(void)
                }
        }
 
-       at_eol();
+       ErrorIfNotAtEOL();
 
        uint64_t p1 = 0x00 | ((ypos * 2) << 3) | (iheight << 14) | (linkAddr << 21) | (dataAddr << 40);
        uint64_t p2 = xpos | (bpp << 12) | (pitch << 15) | (dwidth << 18) | (iwidth << 28) | (index << 38) | (flags << 45) | (firstpix << 49);
@@ -196,14 +192,13 @@ int HandleBitmap(void)
        return OK;
 }
 
-
 //
 // Define a scaled bitmap object
 // Form: scbitmap <data>, <xloc>, <yloc>, <dwidth>, <iwidth>, <iheight>,
 //                <xscale>, <yscale>, <remainder>, <bpp>, <pallete idx>,
 //                <flags>, <firstpix>, <pitch>
 //
-int HandleScaledBitmap(void)
+static int HandleScaledBitmap(void)
 {
        uint64_t xpos = 0;
        uint64_t ypos = 0;
@@ -308,7 +303,7 @@ int HandleScaledBitmap(void)
                }
        }
 
-       at_eol();
+       ErrorIfNotAtEOL();
 
        uint64_t p1 = 0x01 | ((ypos * 2) << 3) | (iheight << 14) | (linkAddr << 21) | (dataAddr << 40);
        uint64_t p2 = xpos | (bpp << 12) | (pitch << 15) | (dwidth << 18) | (iwidth << 28) | (index << 38) | (flags << 45) | (firstpix << 49);
@@ -324,36 +319,25 @@ int HandleScaledBitmap(void)
        return OK;
 }
 
-
 //
 // Insert GPU object
-// Form: gpuobj <line #>, <userdata> (bits 14-63 of this object)
+// Form: gpuobj <userdata> (bits 3-63 of this object)
 //
-int HandleGPUObject(void)
+static int HandleGPUObject(void)
 {
        uint64_t eval;
        uint16_t eattr;
        SYM * esym = 0;
 
-       if (expr(exprbuf, &eval, &eattr, &esym) != OK)
-               return ERROR;
-
-       if (!(eattr & DEFINED))
-               return error("bad expression in y position");
-
-       uint64_t ypos = eval;
-
-       CHECK_COMMA;
-
        if (expr(exprbuf, &eval, &eattr, &esym) != OK)
                return ERROR;
 
        if (!(eattr & DEFINED))
                return error("bad expression in data");
 
-       at_eol();
+       ErrorIfNotAtEOL();
 
-       uint64_t p1 = 0x02 | ((ypos * 2) << 3) | (eval << 14);
+       uint64_t p1 = 0x02 | (eval << 3);
 
        lastObjType = 2;
        D_quad(p1);
@@ -361,14 +345,13 @@ int HandleGPUObject(void)
        return OK;
 }
 
-
 //
 // Insert a branch object
 // Form: branch VC <condition (<, =, >)> <line #>, <link addr>
 //       branch OPFLAG, <link addr>
 //       branch SECHALF, <link addr>
 //
-int HandleBranch(void)
+static int HandleBranch(void)
 {
        char missingKeyword[] = "missing VC, OPFLAG, or SECHALF in branch";
        uint32_t cc = 0;
@@ -416,7 +399,7 @@ int HandleBranch(void)
        if (!(eattr & DEFINED))
                AddFixup(FU_QUAD | FU_OBJLINK, sloc, exprbuf);
 
-       at_eol();
+       ErrorIfNotAtEOL();
 
        uint64_t p1 = 0x03 | (cc << 14) | ((ypos * 2) << 3) | ((eval & 0x3FFFF8) << 21);
 
@@ -426,12 +409,11 @@ int HandleBranch(void)
        return OK;
 }
 
-
 //
 // Insert a stop object
 // Form: stop
 //
-int HandleStop(void)
+static int HandleStop(void)
 {
        lastObjType = 4;
        D_quad(4LL);
@@ -439,12 +421,11 @@ int HandleStop(void)
        return OK;
 }
 
-
 //
 // Insert a phrase sized "NOP" in the object list (psuedo-op)
 // Form: nop
 //
-int HandleNOP(void)
+static int HandleNOP(void)
 {
        uint64_t eval = (orgaddr + 8) & 0x3FFFF8;
        // This is "branch if VC > 2047". Branch addr is next phrase, so either way
@@ -457,12 +438,11 @@ int HandleNOP(void)
        return OK;
 }
 
-
 //
 // Insert an unconditional jump in the object list (psuedo-op)
 // Form: jump <link addr>
 //
-int HandleJump(void)
+static int HandleJump(void)
 {
        uint64_t eval;
        uint16_t eattr;
@@ -474,7 +454,7 @@ int HandleJump(void)
        if (!(eattr & DEFINED))
                AddFixup(FU_QUAD | FU_OBJLINK, sloc, exprbuf);
 
-       at_eol();
+       ErrorIfNotAtEOL();
 
        // This is "branch if VC < 2047", which pretty much guarantees the branch.
        uint64_t p1 = 0x03 | (1 << 14) | (0x7FF << 3) | ((eval & 0x3FFFF8) << 21);
@@ -484,4 +464,3 @@ int HandleJump(void)
 
        return OK;
 }
-