tari

decoder.s

Jun 8th, 2010
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. | Assembly Source File
  2. | Created 8/16/09; 23:25:14
  3.  
  4. ||Refer to http://www.z80.info/decoding.htm
  5. ||General things:
  6. |============useful definitions=============
  7. AMS_jumptable = 0xC8
  8.  
  9. |============text segment (code)============
  10. .text
  11. .xdef asm_main
  12.  
  13. |Helper for LUTs- just throw the index in d0 and pass the label for the LUT
  14. |LUT format: entries are 16-bit offsets from the address of the entry
  15. |Only the lowest 6 bits in d0 mean anything- set bit 6 will screw things over
  16. .macro goLUT lut
  17. lea \lut(PC), a0
  18. lsl.w #1, d0 |shift is cheaper than multiply
  19. adda.w (a0, d0.b), a0
  20. jsr a0
  21. .endm
  22. .macro goLUTb lut |goLUT, but uses jmp rather than jsr
  23. lea \lut(PC), a0
  24. lsl.w #1, d0
  25. adda.w (a0, d0.b), a0
  26. jmp a0
  27. .endm
  28.  
  29. |global registers:
  30. |a5 is emulated PC (gotcha: need to handle when this gets outside the z80's
  31. | address range (can I throw an exception when a5 is past a point?)
  32. |a6-> cpuState structure
  33. asm_main:
  34. | get a5 and a6 initialized from the caller
  35. |gogogo!
  36.  
  37. rts
  38.  
  39. |decode handlers may use any registers they wish, excepting the globals (a5-a7)
  40. |Instruction to decode is passed in on d7, and handlers
  41. | should return the T-state count in d7.
  42. |a5 is set to the byte following what was gotting into d7, and should point to the
  43. | next instruction when returning.
  44. decodeInstr: |instruction is passed as d7 (clear except for lsb)
  45. move.b d7,d0
  46. lsr #6,d0
  47. goLUT _xLUT
  48. |do something else
  49.  
  50. |Checks emulated condition, returns nz if condition is true.
  51. |d7 contains condition code
  52. checkCondition:
  53. lsr.b #1, d7 |bit 0 of condition is reset to negate condition- get in C
  54. move.b _conditionsLUT(PC, d7.b), d7
  55. btst.b d7, reg_F(a6) |check emulated flag
  56. bcs _checkCondition_noInvert
  57. eor.b #4, ccr |flip Z flag
  58. _checkCondition_noInvert:
  59. rts
  60.  
  61. |============data segment===================
  62. .data
  63. .even
  64. _conditionsLUT: |table of bit numbers for flags in z80
  65. .byte 6 |Z
  66. .byte 0 |C
  67. .byte 2 |P/V
  68. .byte 7 |S
  69.  
  70. _xLUT: |LUT for handlers of X-values
  71. .word _hX0
  72. .word _hX1
  73. .word _hX2
  74. .word _hX3
  75.  
  76. _X0ZLUT:
  77. .word _hX0Z0
  78. .word _hX0Z1
  79. .word _hX0Z2
  80. .word _hX0Z3
  81. .word _hX0Z4
  82. .word _hX0Z5
  83. .word _hX0Z6
  84. .word _hX0Z7
  85.  
  86. _X0Z0LUT:
  87. .word _hX0Z0NOP
  88. .word _hX0Z0EXAF
  89. .word _hX0Z0DJNZ
  90. .word _hX0Z0JR
Add Comment
Please, Sign In to add comment