Browse Source

Implement JP, JR, OR, OUT.

master
Ben Kurtovic 9 years ago
parent
commit
5fab99ee17
2 changed files with 251 additions and 13 deletions
  1. +153
    -1
      src/assembler/instructions.inc.c
  2. +98
    -12
      src/assembler/instructions.yml

+ 153
- 1
src/assembler/instructions.inc.c View File

@@ -7,7 +7,7 @@
`make` should trigger a rebuild when it is modified; if not, use:
`python scripts/update_asm_instructions.py`.

@AUTOGEN_DATE Tue May 19 07:10:15 2015 UTC
@AUTOGEN_DATE Wed May 20 06:24:37 2015 UTC
*/

/* @AUTOGEN_INST_BLOCK_START */
@@ -730,6 +730,73 @@ INST_FUNC(inir)
INST_RETURN(2, 0xED, 0xB2)
}

INST_FUNC(jp)
{
INST_TAKES_ARGS(
AT_CONDITION|AT_IMMEDIATE|AT_INDEXED|AT_INDIRECT,
AT_IMMEDIATE|AT_OPTIONAL,
AT_NONE
)
if (INST_NARGS == 1 && INST_TYPE(0) == AT_IMMEDIATE) {
if (INST_IMM(0).mask & IMM_U16)
INST_RETURN(3, 0xC3, INST_IMM_U16_B1(INST_IMM(0)), INST_IMM_U16_B2(INST_IMM(0)))
INST_ERROR(ARG_VALUE)
}
if (INST_NARGS == 2 && INST_TYPE(0) == AT_CONDITION && INST_TYPE(1) == AT_IMMEDIATE) {
if (INST_COND(0) == COND_NZ && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xC2, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_Z && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xCA, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_NC && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xD2, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_C && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xDA, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_PO && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xE2, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_PE && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xEA, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_P && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xF2, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
if (INST_COND(0) == COND_M && INST_IMM(1).mask & IMM_U16)
INST_RETURN(3, 0xFA, INST_IMM_U16_B1(INST_IMM(1)), INST_IMM_U16_B2(INST_IMM(1)))
INST_ERROR(ARG_VALUE)
}
if (INST_NARGS == 1 && INST_TYPE(0) == AT_INDIRECT &&
(INST_INDIRECT(0).type == AT_REGISTER && INST_INDIRECT(0).addr.reg == REG_HL)) {
INST_RETURN(1, 0xE9)
}
if (INST_NARGS == 1 && INST_TYPE(0) == AT_INDEXED) {
INST_RETURN(3, INST_INDEX_PREFIX(0), 0xE9, INST_INDEX(0).offset)
}
INST_ERROR(ARG_TYPE)
}

INST_FUNC(jr)
{
INST_TAKES_ARGS(
AT_CONDITION|AT_IMMEDIATE,
AT_IMMEDIATE|AT_OPTIONAL,
AT_NONE
)
if (INST_NARGS == 1 && INST_TYPE(0) == AT_IMMEDIATE) {
if (INST_IMM(0).mask & IMM_REL)
INST_RETURN(2, 0x18, INST_IMM(0).sval - 2)
INST_ERROR(ARG_VALUE)
}
if (INST_NARGS == 2 && INST_TYPE(0) == AT_CONDITION && INST_TYPE(1) == AT_IMMEDIATE) {
if (INST_COND(0) == COND_NZ && INST_IMM(1).mask & IMM_REL)
INST_RETURN(2, 0x20, INST_IMM(1).sval - 2)
if (INST_COND(0) == COND_Z && INST_IMM(1).mask & IMM_REL)
INST_RETURN(2, 0x28, INST_IMM(1).sval - 2)
if (INST_COND(0) == COND_NC && INST_IMM(1).mask & IMM_REL)
INST_RETURN(2, 0x30, INST_IMM(1).sval - 2)
if (INST_COND(0) == COND_C && INST_IMM(1).mask & IMM_REL)
INST_RETURN(2, 0x38, INST_IMM(1).sval - 2)
INST_ERROR(ARG_VALUE)
}
INST_ERROR(ARG_TYPE)
}

INST_FUNC(ld)
{
INST_TAKES_ARGS(
@@ -1151,6 +1218,53 @@ INST_FUNC(nop)
INST_RETURN(1, 0x00)
}

INST_FUNC(or)
{
INST_TAKES_ARGS(
AT_IMMEDIATE|AT_INDEXED|AT_INDIRECT|AT_REGISTER,
AT_NONE,
AT_NONE
)
if (INST_TYPE(0) == AT_REGISTER) {
if (INST_REG(0) == REG_A)
INST_RETURN(1, 0xB7)
if (INST_REG(0) == REG_B)
INST_RETURN(1, 0xB0)
if (INST_REG(0) == REG_C)
INST_RETURN(1, 0xB1)
if (INST_REG(0) == REG_D)
INST_RETURN(1, 0xB2)
if (INST_REG(0) == REG_E)
INST_RETURN(1, 0xB3)
if (INST_REG(0) == REG_H)
INST_RETURN(1, 0xB4)
if (INST_REG(0) == REG_IXH)
INST_RETURN(2, INST_IX_PREFIX, 0xB4)
if (INST_REG(0) == REG_IYH)
INST_RETURN(2, INST_IY_PREFIX, 0xB4)
if (INST_REG(0) == REG_L)
INST_RETURN(1, 0xB5)
if (INST_REG(0) == REG_IXL)
INST_RETURN(2, INST_IX_PREFIX, 0xB5)
if (INST_REG(0) == REG_IYL)
INST_RETURN(2, INST_IY_PREFIX, 0xB5)
INST_ERROR(ARG_VALUE)
}
if (INST_TYPE(0) == AT_IMMEDIATE) {
if (INST_IMM(0).mask & IMM_U8)
INST_RETURN(2, 0xF6, INST_IMM(0).uval)
INST_ERROR(ARG_VALUE)
}
if (INST_TYPE(0) == AT_INDIRECT &&
(INST_INDIRECT(0).type == AT_REGISTER && INST_INDIRECT(0).addr.reg == REG_HL)) {
INST_RETURN(1, 0xB6)
}
if (INST_TYPE(0) == AT_INDEXED) {
INST_RETURN(3, INST_INDEX_PREFIX(0), 0xB6, INST_INDEX(0).offset)
}
INST_ERROR(ARG_TYPE)
}

INST_FUNC(otdr)
{
INST_TAKES_NO_ARGS
@@ -1163,6 +1277,40 @@ INST_FUNC(otir)
INST_RETURN(2, 0xED, 0xB3)
}

INST_FUNC(out)
{
INST_TAKES_ARGS(
AT_PORT,
AT_IMMEDIATE|AT_REGISTER,
AT_NONE
)
if (INST_TYPE(0) == AT_PORT && INST_TYPE(1) == AT_REGISTER) {
if (INST_PORT(0).type == AT_IMMEDIATE && INST_REG(1) == REG_A)
INST_RETURN(2, 0xD3, INST_PORT(0).port.imm.uval)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_A)
INST_RETURN(2, 0xED, 0x79)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_B)
INST_RETURN(2, 0xED, 0x41)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_C)
INST_RETURN(2, 0xED, 0x49)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_D)
INST_RETURN(2, 0xED, 0x51)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_E)
INST_RETURN(2, 0xED, 0x59)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_H)
INST_RETURN(2, 0xED, 0x61)
if (INST_PORT(0).type == AT_REGISTER && INST_REG(1) == REG_L)
INST_RETURN(2, 0xED, 0x69)
INST_ERROR(ARG_VALUE)
}
if (INST_TYPE(0) == AT_PORT && INST_TYPE(1) == AT_IMMEDIATE) {
if (INST_PORT(0).type == AT_REGISTER && (INST_IMM(1).mask & IMM_U8 && INST_IMM(1).uval == 0))
INST_RETURN(2, 0xED, 0x71)
INST_ERROR(ARG_VALUE)
}
INST_ERROR(ARG_TYPE)
}

INST_FUNC(outd)
{
INST_TAKES_NO_ARGS
@@ -1258,6 +1406,8 @@ static ASMInstParser lookup_parser(uint32_t key)
HANDLE(indr)
HANDLE(ini)
HANDLE(inir)
HANDLE(jp)
HANDLE(jr)
HANDLE(ld)
HANDLE(ldd)
HANDLE(lddr)
@@ -1265,8 +1415,10 @@ static ASMInstParser lookup_parser(uint32_t key)
HANDLE(ldir)
HANDLE(neg)
HANDLE(nop)
HANDLE(or)
HANDLE(otdr)
HANDLE(otir)
HANDLE(out)
HANDLE(outd)
HANDLE(outi)
HANDLE(reti)


+ 98
- 12
src/assembler/instructions.yml View File

@@ -484,13 +484,53 @@ inir:
args: no
return: [0xED, 0xB2]

# jp:
# args: yes
# return: TODO
jp:
args: yes
cases:
- type: [immediate]
cases:
- cond: [u16]
return: [0xC3, u16]
- type: [condition, immediate]
cases:
- cond: [nz, u16]
return: [0xC2, u16]
- cond: [z, u16]
return: [0xCA, u16]
- cond: [nc, u16]
return: [0xD2, u16]
- cond: [c, u16]
return: [0xDA, u16]
- cond: [po, u16]
return: [0xE2, u16]
- cond: [pe, u16]
return: [0xEA, u16]
- cond: [p, u16]
return: [0xF2, u16]
- cond: [m, u16]
return: [0xFA, u16]
- type: [indirect_hl_or_indexed]
cases:
- cond: [_]
return: [0xE9]

# jr:
# args: yes
# return: TODO
jr:
args: yes
cases:
- type: [immediate]
cases:
- cond: [rel]
return: [0x18, rel]
- type: [condition, immediate]
cases:
- cond: [nz, rel]
return: [0x20, rel]
- cond: [z, rel]
return: [0x28, rel]
- cond: [nc, rel]
return: [0x30, rel]
- cond: [c, rel]
return: [0x38, rel]

ld:
args: yes
@@ -722,9 +762,33 @@ nop:
args: no
return: [0x00]

# or:
# args: yes
# return: TODO
or:
args: yes
cases:
- type: [register]
cases:
- cond: [a]
return: [0xB7]
- cond: [b]
return: [0xB0]
- cond: [c]
return: [0xB1]
- cond: [d]
return: [0xB2]
- cond: [e]
return: [0xB3]
- cond: [h|ih]
return: [0xB4]
- cond: [l|il]
return: [0xB5]
- type: [immediate]
cases:
- cond: [u8]
return: [0xF6, u8]
- type: [indirect_hl_or_indexed]
cases:
- cond: [_]
return: [0xB6]

otdr:
args: no
@@ -734,9 +798,31 @@ otir:
args: no
return: [0xED, 0xB3]

# out:
# args: yes
# return: TODO
out:
args: yes
cases:
- type: [port, register]
cases:
- cond: [imm, a]
return: [0xD3, u8]
- cond: [reg.c, a]
return: [0xED, 0x79]
- cond: [reg.c, b]
return: [0xED, 0x41]
- cond: [reg.c, c]
return: [0xED, 0x49]
- cond: [reg.c, d]
return: [0xED, 0x51]
- cond: [reg.c, e]
return: [0xED, 0x59]
- cond: [reg.c, h]
return: [0xED, 0x61]
- cond: [reg.c, l]
return: [0xED, 0x69]
- type: [port, immediate]
cases:
- cond: [reg.c, u8.0]
return: [0xED, 0x71]

outd:
args: no


Loading…
Cancel
Save