opcode.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright ©2021 The star-tex Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE-STAR-TEX file.
  4. package pkf
  5. import "fmt"
  6. // pkID is the version of the PK file format.
  7. const pkID = 89
  8. // opCode is a PK file format command identifier.
  9. type opCode uint8
  10. const (
  11. opXXX1 opCode = iota + 240 // Special command uint8-len large
  12. opXXX2 // Special command uint16-len large
  13. opXXX3 // Special command uint24-len large
  14. opXXX4 // Special command uint32-len large
  15. opYYY // Special command 32b large
  16. opPost // Beginning of the postamble
  17. opNOP // no-op
  18. opPre // Beginning of the preamble
  19. )
  20. func (op opCode) cmd() Cmd {
  21. switch op {
  22. case opXXX1:
  23. return &CmdXXX1{}
  24. case opXXX2:
  25. return &CmdXXX2{}
  26. case opXXX3:
  27. return &CmdXXX3{}
  28. case opXXX4:
  29. return &CmdXXX4{}
  30. case opYYY:
  31. return &CmdYYY{}
  32. case opPost:
  33. return &CmdPost{}
  34. case opNOP:
  35. return &CmdNOP{}
  36. case opPre:
  37. return &CmdPre{}
  38. default:
  39. panic(fmt.Errorf("pkf: unknown opcode 0x%x (%d)", op, op))
  40. }
  41. }