1
0
mirror of https://github.com/emkay/parser-6502.git synced 2024-12-20 23:30:57 +00:00
parser-6502/parsers/instruction.js
Michael Matuzak e8ca1f9bcd yep
2016-10-11 17:59:26 -07:00

53 lines
1.1 KiB
JavaScript

const mona = require('mona')
const parameters = require('./parameters').parameters
const instructions = [
'adc', 'and', 'asl',
'bcc', 'bcs', 'beq', 'bit', 'bmi', 'bne', 'bpl', 'brk', 'bvc', 'bvs',
'clc', 'cld', 'cli', 'clv', 'cmp', 'cpx', 'cpy',
'dec', 'dex', 'dey',
'eor',
'inc', 'inx', 'iny',
'jmp', 'jsr',
'lda', 'ldx', 'ldy', 'lsr',
'nop',
'ora',
'pha', 'php', 'pla', 'plp',
'rol', 'ror', 'rti', 'rts',
'sbc', 'sec', 'sed', 'sei', 'sta', 'stx', 'sty',
'tax', 'tay', 'tsx', 'txa', 'txs', 'tya'
]
function instructionName () {
return mona.oneOf(instructions)
}
function instruction () {
return mona.sequence((s) => {
const i = s(
mona.followedBy(
instructionName(),
mona.maybe(mona.eol())
)
)
const args = s(
mona.maybe(
mona.and(
mona.spaces(),
mona.followedBy(
parameters(),
mona.maybe(mona.eol())
)
)
)
)
return mona.value({
instruction: i,
args: args
})
})
}
module.exports = instruction