From 2a76e3d48f5424d22fe877baa72200608a318a07 Mon Sep 17 00:00:00 2001 From: kris Date: Thu, 25 Apr 2019 16:26:38 +0100 Subject: [PATCH] Add a HEADER opcode that emits the 7-byte video header, used to select the playback mode (HGR/DHGR). --- transcoder/opcodes.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/transcoder/opcodes.py b/transcoder/opcodes.py index e822cd1..bc58091 100644 --- a/transcoder/opcodes.py +++ b/transcoder/opcodes.py @@ -11,6 +11,7 @@ def _op_cmds(): """Construct names of player opcodes.""" op_cmds = [ + "HEADER", "TERMINATE", "NOP", "ACK", @@ -45,7 +46,7 @@ class Opcode: @staticmethod def emit_command(opcode: "Opcode") -> Iterator[int]: - # Emit address of next opcode + # Emit address of opcode yield opcode._START >> 8 yield opcode._START & 0xff @@ -56,6 +57,35 @@ class Opcode: pass +class Header(Opcode): + """Video header opcode.""" + COMMAND = OpcodeCommand.HEADER + + def __init__(self, mode: "video.Mode"): + self.video_mode = mode + + def __data_eq__(self, other): + return self.video_mode == other.video_mode + + @staticmethod + def emit_command(opcode: "Opcode") -> Iterator[int]: + # This is special in that it does not explicitly vector to the next + # opcode + return + + def emit_data(self) -> Iterator[int]: + # Pad bytes to same size as Tick opcode, to make it easier to schedule + # ACK opcodes. + yield 0xff + yield 0xff + yield 0xff + yield 0xff + yield 0xff + yield 0xff + + yield self.video_mode.value + + class Nop(Opcode): """NOP pad opcode that does nothing except vector to the next one.""" COMMAND = OpcodeCommand.NOP @@ -158,6 +188,7 @@ def _fill_opcode_addresses(): _OPCODE_ADDRS = _parse_symbol_table() _OPCODE_CLASSES = { + OpcodeCommand.HEADER: Header, OpcodeCommand.TERMINATE: Terminate, OpcodeCommand.NOP: Nop, OpcodeCommand.ACK: Ack,