#include <stdio.h>
typedef unsigned char uint8_t;
typedef signed char int8_t;
#define OPCODE_JMP 0xE9
//define usr protocol bit
//FS RE COUNT HEAD
//D7D6 D5D4 D3D2D1 D0
//11 10 100 1
enum PVS {
PHD = 0, CNT, REV, FST, STR
};
uint8_t dmap[][8] = {
#define UN_USED 255
{0, 1, UN_USED, UN_USED, UN_USED, UN_USED, UN_USED, UN_USED},
{0, 1, 10, 11, 100, 101, 110, 111},
{10, 10, 10, 11, UN_USED, UN_USED, UN_USED, UN_USED},
{0, 2, 4, 6, UN_USED, UN_USED, UN_USED, UN_USED},
{'%', '0', 'd', 0, UN_USED, UN_USED, UN_USED, UN_USED}
};
#define _B2D(_r, _b) dmap[_r][_b]
#define PHD(_op) _B2D(PHD, (uint8_t)(_op & 0x01)) //0/1
#define CNT(_op) _B2D(CNT, ((_op & 0x0f) >> 1)) //000-111
#define REV(_op) _B2D(REV, ((_op & 0x30) >> 4)) //00-11
#define FST(_op) _B2D(FST, ((_op & 0xc0) >> 6)) + 0x30 //00-11
#define MAKEWORD(_h, _l) (_h << 8 | _l)
#define MAKEDWORD(_H, _L) (_H << 16 | _L)
int parse_cmd(uint8_t c)
{
int pvs, i;
pvs = MAKEDWORD(MAKEWORD(FST(c), REV(c)),
MAKEWORD(CNT(c), (PHD(c))));
#define CASTU8(_int) ((uint8_t *)&_int)
for(dmap[STR][1] = CASTU8(pvs)[FST], i = CASTU8(pvs)[PHD];
i <= CASTU8(pvs)[CNT]; i++) {
printf(CASTU8(dmap[STR]), i);
if(0 == i % CASTU8(pvs)[REV]) printf("\n");
}
return pvs;
}
int main(int argc, char *argv[])
{
int pvs, i;
uint8_t *p;
double pi = 3.1415926;
//test pi
for(p = (uint8_t *)&pi, i = 0; i < sizeof(double); i++) {
printf("[%d:]0x%x\n", i + 1, p[i]);
parse_cmd(p[i]);
}
//end of OPCODE_JMP
parse_cmd(OPCODE_JMP);
return 0;
}