1
0
mirror of https://github.com/emkay/parser-6502.git synced 2024-06-01 01:41:34 +00:00
parser-6502/parsers/instruction.js
2016-10-11 17:01:15 -07:00

45 lines
953 B
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(instructionName())
const args = s(
mona.maybe(
mona.and(
mona.spaces(),
parameters()
)
)
)
const nl = s(mona.eol())
return mona.value({
instruction: i,
args: args
})
})
}
module.exports = instruction