Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | Assembly Source File
- | Created 8/16/09; 23:25:14
- ||Refer to http://www.z80.info/decoding.htm
- ||General things:
- |============useful definitions=============
- AMS_jumptable = 0xC8
- |============text segment (code)============
- .text
- .xdef asm_main
- |Helper for LUTs- just throw the index in d0 and pass the label for the LUT
- |LUT format: entries are 16-bit offsets from the address of the entry
- |Only the lowest 6 bits in d0 mean anything- set bit 6 will screw things over
- .macro goLUT lut
- lea \lut(PC), a0
- lsl.w #1, d0 |shift is cheaper than multiply
- adda.w (a0, d0.b), a0
- jsr a0
- .endm
- .macro goLUTb lut |goLUT, but uses jmp rather than jsr
- lea \lut(PC), a0
- lsl.w #1, d0
- adda.w (a0, d0.b), a0
- jmp a0
- .endm
- |global registers:
- |a5 is emulated PC (gotcha: need to handle when this gets outside the z80's
- | address range (can I throw an exception when a5 is past a point?)
- |a6-> cpuState structure
- asm_main:
- | get a5 and a6 initialized from the caller
- |gogogo!
- rts
- |decode handlers may use any registers they wish, excepting the globals (a5-a7)
- |Instruction to decode is passed in on d7, and handlers
- | should return the T-state count in d7.
- |a5 is set to the byte following what was gotting into d7, and should point to the
- | next instruction when returning.
- decodeInstr: |instruction is passed as d7 (clear except for lsb)
- move.b d7,d0
- lsr #6,d0
- goLUT _xLUT
- |do something else
- |Checks emulated condition, returns nz if condition is true.
- |d7 contains condition code
- checkCondition:
- lsr.b #1, d7 |bit 0 of condition is reset to negate condition- get in C
- move.b _conditionsLUT(PC, d7.b), d7
- btst.b d7, reg_F(a6) |check emulated flag
- bcs _checkCondition_noInvert
- eor.b #4, ccr |flip Z flag
- _checkCondition_noInvert:
- rts
- |============data segment===================
- .data
- .even
- _conditionsLUT: |table of bit numbers for flags in z80
- .byte 6 |Z
- .byte 0 |C
- .byte 2 |P/V
- .byte 7 |S
- _xLUT: |LUT for handlers of X-values
- .word _hX0
- .word _hX1
- .word _hX2
- .word _hX3
- _X0ZLUT:
- .word _hX0Z0
- .word _hX0Z1
- .word _hX0Z2
- .word _hX0Z3
- .word _hX0Z4
- .word _hX0Z5
- .word _hX0Z6
- .word _hX0Z7
- _X0Z0LUT:
- .word _hX0Z0NOP
- .word _hX0Z0EXAF
- .word _hX0Z0DJNZ
- .word _hX0Z0JR
Add Comment
Please, Sign In to add comment