Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  1. package disasm
  2. import (
  3. "encoding/binary"
  4. "fmt"
  5. "sort"
  6. "strconv"
  7. )
  8. const (
  9. M68K_CPU_TYPE_68000 Type = iota
  10. M68K_CPU_TYPE_68010
  11. M68K_CPU_TYPE_68EC020
  12. M68K_CPU_TYPE_68020
  13. M68K_CPU_TYPE_68EC030
  14. M68K_CPU_TYPE_68030
  15. M68K_CPU_TYPE_68EC040
  16. M68K_CPU_TYPE_68LC040
  17. M68K_CPU_TYPE_68040
  18. M68K_CPU_TYPE_SCC68070
  19. )
  20. const (
  21. dasm68000 = 1
  22. dasm68010 = 2
  23. dasm68020 = 4
  24. dasm68030 = 8
  25. dasm68040 = 16
  26. dasmAll = dasm68000 | dasm68010 | dasm68020 | dasm68030 | dasm68040
  27. )
  28. type dasmOpcode struct {
  29. dasmHandler func(*dasmInfo) string
  30. mask uint16
  31. match uint16
  32. eaMask uint16
  33. cpuTypes uint16
  34. }
  35. type dasmInfo struct {
  36. cpuType uint16
  37. bus AddressBus
  38. pc int32
  39. ir uint16
  40. helper string
  41. }
  42. func NewAddressBus(mem []byte) FunBar {
  43. return FunBar(mem)
  44. }
  45. type FunBar []byte
  46. func (f FunBar) read(address int32, s *Size) int32 {
  47. return s.read(f[address:])
  48. }
  49. func (f FunBar) write(address int32, s *Size, value int32) {
  50. s.write(f[address:], value)
  51. }
  52. func (f FunBar) reset() {
  53. panic("no funbar reset!")
  54. }
  55. type AddressBus interface {
  56. read(address int32, s *Size) int32
  57. write(address int32, s *Size, value int32)
  58. reset()
  59. }
  60. var (
  61. dasmTable = make([]func(*dasmInfo) string, 0x10000)
  62. dasmSupportedTypes = make([]uint16, 0x10000)
  63. g3bitQDataTable = []int32{8, 1, 2, 3, 4, 5, 6, 7}
  64. g5bitQDataTable = []int32{32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
  65. gCCTable = []string{"t", "f", "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi", "ge", "lt", "gt", "le"}
  66. gCPCCTable = []string{"f", "eq", "ogt", "oge", "olt", "ole", "ogl", "or", "un", "ueq", "ugt", "uge", "ult", "ule", "ne", "t", "sf", "seq", "gt", "ge", "lt", "le", "glgle", "ngle", "ngl", "nle", "nlt", "nge", "ngt", "sne", "st", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"}
  67. gMMURegs = []string{"tc", "drp", "srp", "crp", "cal", "val", "sccr", "acr"}
  68. gMMUCond = []string{"bs", "bc", "ls", "lc", "ss", "sc", "as", "ac", "ws", "wc", "is", "ic", "gs", "gc", "cs", "cc"}
  69. gFPUDataFormatTable = []string{".l", ".s", ".x", ".p", ".w", ".d", ".b", ".p"}
  70. )
  71. func (d *dasmInfo) readImm(advance *Size) int32 {
  72. result := d.bus.read(d.pc, advance)
  73. d.pc += advance.align
  74. return result
  75. }
  76. func (d *dasmInfo) getImmStrSigned(size *Size) string {
  77. return size.SignedHexString(d.readImm(size))
  78. }
  79. func (d *dasmInfo) getImmStrUnsigned(size *Size) string {
  80. return size.HexString(d.readImm(size))
  81. }
  82. func (d *dasmInfo) getEaModeStr(size *Size) string {
  83. // Make string of effective address mode
  84. switch d.ir & 0x3f {
  85. case 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07: // data register direct
  86. return fmt.Sprintf("D%d", y(d.ir))
  87. case 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f: // address register direct
  88. return fmt.Sprintf("A%d", y(d.ir))
  89. case 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17: // address register indirect
  90. return fmt.Sprintf("(A%d)", y(d.ir))
  91. case 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f: // address register indirect with postincrement
  92. return fmt.Sprintf("(A%d)+", y(d.ir))
  93. case 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27: // address register indirect with predecrement
  94. return fmt.Sprintf("-(A%d)", y(d.ir))
  95. case 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f: // address register indirect with displacement
  96. return fmt.Sprintf("(%s,A%d)", Word.SignedHexString(d.readImm(Word)), y(d.ir))
  97. case 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37:
  98. // address register indirect with index
  99. mode := ""
  100. extension := d.readImm(Word)
  101. if extension&0x100 != 0 {
  102. if extension&0xE4 == 0xC4 || extension&0xE2 == 0xC0 {
  103. return ""
  104. }
  105. base := int32(0)
  106. if extension&0x30 > 16 {
  107. if extension&0x30 == 0x30 {
  108. base = d.readImm(Long)
  109. } else {
  110. base = d.readImm(Word)
  111. }
  112. }
  113. outer := int32(0)
  114. if extension&3 > 1 && extension&71 < 68 {
  115. if extension&3 == 3 && extension&71 < 68 {
  116. outer = d.readImm(Long)
  117. } else {
  118. outer = d.readImm(Word)
  119. }
  120. }
  121. baseReg, indexReg := "", ""
  122. if extension&128 == 0 {
  123. baseReg = fmt.Sprintf("A%d", y(d.ir))
  124. }
  125. if extension&64 == 0 {
  126. indexReg = "D"
  127. if extension&0x8000 != 0 {
  128. indexReg = "A"
  129. }
  130. indexReg += strconv.Itoa(int((extension >> 12) & 7))
  131. if extension&0x800 != 0 {
  132. indexReg += Long.ext
  133. } else {
  134. indexReg += Word.ext
  135. }
  136. if extension>>uint64(9)&3 != 0 {
  137. indexReg += "*" + strconv.Itoa(int(1<<((extension>>9)&3)))
  138. }
  139. }
  140. preindex := extension&7 > 0 && extension&7 < 4
  141. postindex := extension&7 > 4
  142. comma := false
  143. if base != 0 {
  144. if extension&0x30 == 0x30 {
  145. mode += Long.SignedHexString(base)
  146. } else {
  147. mode += Word.SignedHexString(base)
  148. }
  149. comma = true
  150. }
  151. if baseReg[0] != 0 {
  152. mode += baseReg
  153. comma = true
  154. }
  155. if postindex {
  156. mode += "]"
  157. comma = true
  158. }
  159. if indexReg[0] != 0 {
  160. if comma {
  161. mode += ","
  162. }
  163. mode += indexReg
  164. comma = true
  165. }
  166. if preindex {
  167. mode += "]"
  168. comma = true
  169. }
  170. if outer != 0 {
  171. if comma {
  172. mode += ","
  173. }
  174. mode += Word.SignedHexString(outer)
  175. }
  176. return mode
  177. }
  178. if extension&0xFF == 0 {
  179. mode = fmt.Sprintf("(A%d,", y(d.ir))
  180. if extension&0x8000 != 0 {
  181. mode += "A"
  182. } else {
  183. mode += "D"
  184. }
  185. mode += strconv.Itoa(int((extension >> 12) & 7))
  186. if extension&0x800 != 0 {
  187. mode += Long.ext
  188. } else {
  189. mode += Word.ext
  190. }
  191. } else {
  192. mode = fmt.Sprintf("(%s,A%d,", Byte.SignedHexString(extension), y(d.ir))
  193. if extension&0x8000 != 0 {
  194. mode += "A"
  195. } else {
  196. mode += "D"
  197. }
  198. mode += strconv.Itoa(int((extension >> 12) & 7))
  199. if extension&0x800 != 0 {
  200. mode += Long.ext
  201. } else {
  202. mode += Word.ext
  203. }
  204. }
  205. if (extension>>9)&3 != 0 {
  206. mode += fmt.Sprintf("*%d", 1<<uint64(extension>>uint64(9)&3))
  207. }
  208. return mode
  209. case 56:
  210. // absolute short address
  211. return fmt.Sprintf("$%x.w", d.readImm(Word))
  212. case 57:
  213. // absolute long address
  214. return fmt.Sprintf("$%x.l", d.readImm(Long))
  215. case 58:
  216. // program counter with displacement
  217. tempValue := d.readImm(Word)
  218. d.helper = fmt.Sprintf("; ($%x)", tempValue+d.pc-2)
  219. return fmt.Sprintf("(%s,PC)", Word.SignedHexString(tempValue))
  220. case 59:
  221. // program counter with index
  222. mode := ""
  223. extension := d.readImm(Word)
  224. if extension&0x100 != 0 {
  225. if extension&0xE4 == 0xC4 || extension&0xE2 == 0xC0 {
  226. return ""
  227. }
  228. base := int32(0)
  229. if extension&0x30 > 0x10 {
  230. if extension&0x30 == 0x30 {
  231. base = d.readImm(Long)
  232. } else {
  233. base = d.readImm(Word)
  234. }
  235. }
  236. outer := int32(0)
  237. if extension&3 > 1 && extension&71 < 68 {
  238. if extension&3 == 3 && extension&71 < 68 {
  239. outer = d.readImm(Long)
  240. } else {
  241. outer = d.readImm(Word)
  242. }
  243. }
  244. baseReg := ""
  245. if extension&128 == 0 {
  246. baseReg = "PC"
  247. }
  248. indexReg := ""
  249. if extension&64 == 0 {
  250. indexReg = "D"
  251. if extension&0x8000 != 0 {
  252. indexReg = "A"
  253. }
  254. indexReg += strconv.Itoa(int((extension >> 12) & 7))
  255. if extension&0x800 != 0 {
  256. indexReg += Long.ext
  257. } else {
  258. indexReg += Word.ext
  259. }
  260. if extension>>uint64(9)&3 != 0 {
  261. indexReg += "*" + strconv.Itoa(int(1<<((extension>>9)&3)))
  262. }
  263. }
  264. preindex := extension&7 > 0 && extension&7 < 4
  265. postindex := extension&7 > 4
  266. comma := false
  267. mode = "("
  268. if preindex || postindex {
  269. mode += "["
  270. }
  271. if base != 0 {
  272. mode += Word.SignedHexString(base)
  273. comma = true
  274. }
  275. if baseReg != "" {
  276. if comma {
  277. mode += ","
  278. }
  279. mode += baseReg
  280. comma = true
  281. }
  282. if postindex {
  283. mode += "]"
  284. comma = true
  285. }
  286. if indexReg != "" {
  287. if comma {
  288. mode += ","
  289. }
  290. mode += indexReg
  291. comma = true
  292. }
  293. if preindex {
  294. mode += "]"
  295. comma = true
  296. }
  297. if outer != 0 {
  298. if comma {
  299. mode += ","
  300. }
  301. mode += Word.SignedHexString(outer)
  302. }
  303. return mode
  304. }
  305. if extension&0xFF == 0 {
  306. mode = "(PC,"
  307. if extension&0x8000 != 0 {
  308. mode += "A"
  309. } else {
  310. mode += "D"
  311. }
  312. mode += strconv.Itoa(int((extension >> 12) & 7))
  313. if extension&0x800 != 0 {
  314. mode += Long.ext
  315. } else {
  316. mode += Word.ext
  317. }
  318. } else {
  319. mode = fmt.Sprintf("(%s,PC,", Byte.SignedHexString(extension))
  320. if extension&0x8000 != 0 {
  321. mode += "A"
  322. } else {
  323. mode += "D"
  324. }
  325. mode += strconv.Itoa(int((extension >> 12) & 7))
  326. if extension&0x800 != 0 {
  327. mode += Long.ext
  328. } else {
  329. mode += Word.ext
  330. }
  331. }
  332. if (extension>>9)&3 != 0 {
  333. mode += fmt.Sprintf("*%d", 1<<uint64(extension>>uint64(9)&3))
  334. }
  335. return mode
  336. case 60:
  337. // Immediate
  338. return d.getImmStrUnsigned(size)
  339. default:
  340. return fmt.Sprintf("INVALID %x", d.ir&0x3f)
  341. }
  342. }
  343. // func d68000Illegal(d *dasmInfo) string {
  344. // return fmt.Sprintf("dc.w $%04x; ILLEGAL", d.ir)
  345. // }
  346. func d68000_illegal(d *dasmInfo) string {
  347. return fmt.Sprintf("dc.w $%04x; ILLEGAL", d.ir)
  348. }
  349. func d68000_a_line(d *dasmInfo) string {
  350. return fmt.Sprintf("dc.w $%04x; opcode 1010", d.ir)
  351. }
  352. func d68000_f_line(d *dasmInfo) string {
  353. return fmt.Sprintf("dc.w $%04x; opcode 1111", d.ir)
  354. }
  355. func d68000_abcd_rr(d *dasmInfo) string {
  356. return fmt.Sprintf("abcd D%d, D%d", y(d.ir), x(d.ir))
  357. }
  358. func d68000_abcd_mm(d *dasmInfo) string {
  359. return fmt.Sprintf("abcd -(A%d), -(A%d)", y(d.ir), x(d.ir))
  360. }
  361. func d68000_add_er_8(d *dasmInfo) string {
  362. return fmt.Sprintf("add.b %s, D%d", d.getEaModeStr(Byte), x(d.ir))
  363. }
  364. func d68000_add_er_16(d *dasmInfo) string {
  365. return fmt.Sprintf("add.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  366. }
  367. func d68000_add_er_32(d *dasmInfo) string {
  368. return fmt.Sprintf("add.l %s, D%d", d.getEaModeStr(Long), x(d.ir))
  369. }
  370. func d68000_add_re_8(d *dasmInfo) string {
  371. return fmt.Sprintf("add.b D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  372. }
  373. func d68000_add_re_16(d *dasmInfo) string {
  374. return fmt.Sprintf("add.w D%d, %s", x(d.ir), d.getEaModeStr(Word))
  375. }
  376. func d68000_add_re_32(d *dasmInfo) string {
  377. return fmt.Sprintf("add.l D%d, %s", x(d.ir), d.getEaModeStr(Long))
  378. }
  379. func d68000_adda_16(d *dasmInfo) string {
  380. return fmt.Sprintf("adda.w %s, A%d", d.getEaModeStr(Word), x(d.ir))
  381. }
  382. func d68000_adda_32(d *dasmInfo) string {
  383. return fmt.Sprintf("adda.l %s, A%d", d.getEaModeStr(Long), x(d.ir))
  384. }
  385. func d68000_addi_8(d *dasmInfo) string {
  386. return fmt.Sprintf("addi.b %s, %s", d.getImmStrSigned(Byte), d.getEaModeStr(Byte))
  387. }
  388. func d68000_addi_16(d *dasmInfo) string {
  389. return fmt.Sprintf("addi.w %s, %s", d.getImmStrSigned(Word), d.getEaModeStr(Word))
  390. }
  391. func d68000_addi_32(d *dasmInfo) string {
  392. return fmt.Sprintf("addi.l %s, %s", d.getImmStrSigned(Long), d.getEaModeStr(Long))
  393. }
  394. func d68000_addq_8(d *dasmInfo) string {
  395. return fmt.Sprintf("addq.b #%d, %s", g3bitQDataTable[x(d.ir)], d.getEaModeStr(Byte))
  396. }
  397. func d68000_addq_16(d *dasmInfo) string {
  398. return fmt.Sprintf("addq.w #%d, %s", g3bitQDataTable[x(d.ir)], d.getEaModeStr(Word))
  399. }
  400. func d68000_addq_32(d *dasmInfo) string {
  401. return fmt.Sprintf("addq.l #%d, %s", g3bitQDataTable[x(d.ir)], d.getEaModeStr(Long))
  402. }
  403. func d68000_addx_rr_8(d *dasmInfo) string {
  404. return fmt.Sprintf("addx.b D%d, D%d", y(d.ir), x(d.ir))
  405. }
  406. func d68000_addx_rr_16(d *dasmInfo) string {
  407. return fmt.Sprintf("addx.w D%d, D%d", y(d.ir), x(d.ir))
  408. }
  409. func d68000_addx_rr_32(d *dasmInfo) string {
  410. return fmt.Sprintf("addx.l D%d, D%d", y(d.ir), x(d.ir))
  411. }
  412. func d68000_addx_mm_8(d *dasmInfo) string {
  413. return fmt.Sprintf("addx.b -(A%d), -(A%d)", y(d.ir), x(d.ir))
  414. }
  415. func d68000_addx_mm_16(d *dasmInfo) string {
  416. return fmt.Sprintf("addx.w -(A%d), -(A%d)", y(d.ir), x(d.ir))
  417. }
  418. func d68000_addx_mm_32(d *dasmInfo) string {
  419. return fmt.Sprintf("addx.l -(A%d), -(A%d)", y(d.ir), x(d.ir))
  420. }
  421. func d68000_and_er_8(d *dasmInfo) string {
  422. return fmt.Sprintf("and.b %s, D%d", d.getEaModeStr(Byte), x(d.ir))
  423. }
  424. func d68000_and_er_16(d *dasmInfo) string {
  425. return fmt.Sprintf("and.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  426. }
  427. func d68000_and_er_32(d *dasmInfo) string {
  428. return fmt.Sprintf("and.l %s, D%d", d.getEaModeStr(Long), x(d.ir))
  429. }
  430. func d68000_and_re_8(d *dasmInfo) string {
  431. return fmt.Sprintf("and.b D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  432. }
  433. func d68000_and_re_16(d *dasmInfo) string {
  434. return fmt.Sprintf("and.w D%d, %s", x(d.ir), d.getEaModeStr(Word))
  435. }
  436. func d68000_and_re_32(d *dasmInfo) string {
  437. return fmt.Sprintf("and.l D%d, %s", x(d.ir), d.getEaModeStr(Long))
  438. }
  439. func d68000_andi_8(d *dasmInfo) string {
  440. return fmt.Sprintf("andi.b %s, %s", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  441. }
  442. func d68000_andi_16(d *dasmInfo) string {
  443. return fmt.Sprintf("andi.w %s, %s", d.getImmStrUnsigned(Word), d.getEaModeStr(Word))
  444. }
  445. func d68000_andi_32(d *dasmInfo) string {
  446. return fmt.Sprintf("andi.l %s, %s", d.getImmStrUnsigned(Long), d.getEaModeStr(Long))
  447. }
  448. func d68000_andi_to_ccr(d *dasmInfo) string {
  449. return fmt.Sprintf("andi %s, CCR", d.getImmStrUnsigned(Byte))
  450. }
  451. func d68000_andi_to_sr(d *dasmInfo) string {
  452. return fmt.Sprintf("andi %s, SR", d.getImmStrUnsigned(Word))
  453. }
  454. func d68000_asr_s_8(d *dasmInfo) string {
  455. return fmt.Sprintf("asr.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  456. }
  457. func d68000_asr_s_16(d *dasmInfo) string {
  458. return fmt.Sprintf("asr.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  459. }
  460. func d68000_asr_s_32(d *dasmInfo) string {
  461. return fmt.Sprintf("asr.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  462. }
  463. func d68000_asr_r_8(d *dasmInfo) string {
  464. return fmt.Sprintf("asr.b D%d, D%d", x(d.ir), y(d.ir))
  465. }
  466. func d68000_asr_r_16(d *dasmInfo) string {
  467. return fmt.Sprintf("asr.w D%d, D%d", x(d.ir), y(d.ir))
  468. }
  469. func d68000_asr_r_32(d *dasmInfo) string {
  470. return fmt.Sprintf("asr.l D%d, D%d", x(d.ir), y(d.ir))
  471. }
  472. func d68000_asr_ea(d *dasmInfo) string {
  473. return fmt.Sprintf("asr.w %s", d.getEaModeStr(Word))
  474. }
  475. func d68000_asl_s_8(d *dasmInfo) string {
  476. return fmt.Sprintf("asl.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  477. }
  478. func d68000_asl_s_16(d *dasmInfo) string {
  479. return fmt.Sprintf("asl.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  480. }
  481. func d68000_asl_s_32(d *dasmInfo) string {
  482. return fmt.Sprintf("asl.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  483. }
  484. func d68000_asl_r_8(d *dasmInfo) string {
  485. return fmt.Sprintf("asl.b D%d, D%d", x(d.ir), y(d.ir))
  486. }
  487. func d68000_asl_r_16(d *dasmInfo) string {
  488. return fmt.Sprintf("asl.w D%d, D%d", x(d.ir), y(d.ir))
  489. }
  490. func d68000_asl_r_32(d *dasmInfo) string {
  491. return fmt.Sprintf("asl.l D%d, D%d", x(d.ir), y(d.ir))
  492. }
  493. func d68000_asl_ea(d *dasmInfo) string {
  494. return fmt.Sprintf("asl.w %s", d.getEaModeStr(Word))
  495. }
  496. func d68000_bcc_8(d *dasmInfo) string {
  497. return fmt.Sprintf("b%-2s $%x", gCCTable[(d.ir>>8)&15], d.pc+int32(int8(d.ir)))
  498. }
  499. func d68000_bcc_16(d *dasmInfo) string {
  500. return fmt.Sprintf("b%-2s $%x", gCCTable[d.ir>>uint64(8)&15], d.pc+d.readImm(Word))
  501. }
  502. func d68020_bcc_32(d *dasmInfo) string {
  503. return fmt.Sprintf("b%-2s $%x; (2+)", gCCTable[d.ir>>uint64(8)&15], d.pc+d.readImm(Long))
  504. }
  505. func d68000_bchg_r(d *dasmInfo) string {
  506. return fmt.Sprintf("bchg D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  507. }
  508. func d68000_bchg_s(d *dasmInfo) string {
  509. return fmt.Sprintf("bchg %s, %s", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  510. }
  511. func d68000_bclr_r(d *dasmInfo) string {
  512. return fmt.Sprintf("bclr D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  513. }
  514. func d68000_bclr_s(d *dasmInfo) string {
  515. return fmt.Sprintf("bclr %s, %s", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  516. }
  517. func d68010_bkpt(d *dasmInfo) string {
  518. return fmt.Sprintf("bkpt #%d; (1+)", y(d.ir))
  519. }
  520. func d68020_bfchg(d *dasmInfo) string {
  521. extension := d.readImm(Word)
  522. offset := ""
  523. width := ""
  524. if extension&0x800 != 0 {
  525. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  526. } else {
  527. offset = fmt.Sprintf("%d", (extension>>6)&31)
  528. }
  529. if extension&32 != 0 {
  530. width = fmt.Sprintf("D%d", extension&7)
  531. } else {
  532. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  533. }
  534. return fmt.Sprintf("bfchg %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  535. }
  536. func d68020_bfclr(d *dasmInfo) string {
  537. extension := d.readImm(Word)
  538. offset := ""
  539. width := ""
  540. if extension&0x800 != 0 {
  541. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  542. } else {
  543. offset = fmt.Sprintf("%d", (extension>>6)&31)
  544. }
  545. if extension&32 != 0 {
  546. width = fmt.Sprintf("D%d", extension&7)
  547. } else {
  548. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  549. }
  550. return fmt.Sprintf("bfclr %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  551. }
  552. func d68020_bfexts(d *dasmInfo) string {
  553. extension := d.readImm(Word)
  554. offset := ""
  555. width := ""
  556. if extension&0x800 != 0 {
  557. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  558. } else {
  559. offset = fmt.Sprintf("%d", (extension>>6)&31)
  560. }
  561. if extension&32 != 0 {
  562. width = fmt.Sprintf("D%d", extension&7)
  563. } else {
  564. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  565. }
  566. return fmt.Sprintf("bfexts %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  567. }
  568. func d68020_bfextu(d *dasmInfo) string {
  569. extension := d.readImm(Word)
  570. offset := ""
  571. width := ""
  572. if extension&0x800 != 0 {
  573. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  574. } else {
  575. offset = fmt.Sprintf("%d", (extension>>6)&31)
  576. }
  577. if extension&32 != 0 {
  578. width = fmt.Sprintf("D%d", extension&7)
  579. } else {
  580. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  581. }
  582. return fmt.Sprintf("bfextu %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  583. }
  584. func d68020_bfffo(d *dasmInfo) string {
  585. extension := d.readImm(Word)
  586. offset := ""
  587. width := ""
  588. if extension&0x800 != 0 {
  589. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  590. } else {
  591. offset = fmt.Sprintf("%d", (extension>>6)&31)
  592. }
  593. if extension&32 != 0 {
  594. width = fmt.Sprintf("D%d", extension&7)
  595. } else {
  596. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  597. }
  598. return fmt.Sprintf("bfffo %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  599. }
  600. func d68020_bfins(d *dasmInfo) string {
  601. extension := d.readImm(Word)
  602. offset := ""
  603. width := ""
  604. if extension&0x800 != 0 {
  605. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  606. } else {
  607. offset = fmt.Sprintf("%d", (extension>>6)&31)
  608. }
  609. if extension&32 != 0 {
  610. width = fmt.Sprintf("D%d", extension&7)
  611. } else {
  612. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  613. }
  614. return fmt.Sprintf("bfins %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  615. }
  616. func d68020_bfset(d *dasmInfo) string {
  617. extension := d.readImm(Word)
  618. offset := ""
  619. width := ""
  620. if extension&0x800 != 0 {
  621. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  622. } else {
  623. offset = fmt.Sprintf("%d", (extension>>6)&31)
  624. }
  625. if extension&32 != 0 {
  626. width = fmt.Sprintf("D%d", extension&7)
  627. } else {
  628. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  629. }
  630. return fmt.Sprintf("bfset %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  631. }
  632. func d68020_bftst(d *dasmInfo) string {
  633. var offset string
  634. var width string
  635. extension := d.readImm(Word)
  636. if extension&0x800 != 0 {
  637. offset = fmt.Sprintf("D%d", (extension>>6)&7)
  638. } else {
  639. offset = fmt.Sprintf("%d", (extension>>6)&31)
  640. }
  641. if extension&32 != 0 {
  642. width = fmt.Sprintf("D%d", extension&7)
  643. } else {
  644. width = fmt.Sprintf("%d", g5bitQDataTable[extension&31])
  645. }
  646. return fmt.Sprintf("bftst %s {%s:%s}; (2+)", d.getEaModeStr(Byte), offset, width)
  647. }
  648. func d68000_bra_8(d *dasmInfo) string {
  649. return fmt.Sprintf("bra $%x", d.pc+int32(int8(d.ir)))
  650. }
  651. func d68000_bra_16(d *dasmInfo) string {
  652. return fmt.Sprintf("bra $%x", d.pc+int32(int16(d.readImm(Word))))
  653. }
  654. func d68020_bra_32(d *dasmInfo) string {
  655. return fmt.Sprintf("bra $%x; (2+)", d.pc+d.readImm(Long))
  656. }
  657. func d68000_bset_r(d *dasmInfo) string {
  658. return fmt.Sprintf("bset D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  659. }
  660. func d68000_bset_s(d *dasmInfo) string {
  661. return fmt.Sprintf("bset %s, %s", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  662. }
  663. func d68000_bsr_8(d *dasmInfo) string {
  664. return fmt.Sprintf("bsr $%x", d.pc+int32(int8(d.ir)))
  665. }
  666. func d68000_bsr_16(d *dasmInfo) string {
  667. return fmt.Sprintf("bsr $%x", d.pc+int32(int16(d.readImm(Word))))
  668. }
  669. func d68020_bsr_32(d *dasmInfo) string {
  670. return fmt.Sprintf("bsr $%x; (2+)", d.pc+d.readImm(Long))
  671. }
  672. func d68000_btst_r(d *dasmInfo) string {
  673. return fmt.Sprintf("btst D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  674. }
  675. func d68000_btst_s(d *dasmInfo) string {
  676. return fmt.Sprintf("btst %s, %s", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  677. }
  678. func d68020_callm(d *dasmInfo) string {
  679. return fmt.Sprintf("callm %s, %s; (2)", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  680. }
  681. func d68020_cas_8(d *dasmInfo) string {
  682. extension := d.readImm(Word)
  683. return fmt.Sprintf("cas.b D%d, D%d, %s; (2+)", extension&7, extension>>uint64(6)&7, d.getEaModeStr(Byte))
  684. }
  685. func d68020_cas_16(d *dasmInfo) string {
  686. extension := d.readImm(Word)
  687. return fmt.Sprintf("cas.w D%d, D%d, %s; (2+)", extension&7, extension>>uint64(6)&7, d.getEaModeStr(Word))
  688. }
  689. func d68020_cas_32(d *dasmInfo) string {
  690. extension := d.readImm(Word)
  691. return fmt.Sprintf("cas.l D%d, D%d, %s; (2+)", extension&7, (extension>>6)&7, d.getEaModeStr(Long))
  692. }
  693. func d68020_cas2_16(d *dasmInfo) string {
  694. extension := d.readImm(Long)
  695. return fmt.Sprintf("cas2.w D%d:D%d, D%d:D%d, (%c%d):(%c%d); (2+)", (extension>>16)&7, extension&7, (extension>>22)&7, (extension>>6)&7,
  696. func() int32 {
  697. if Long.IsNegative(extension) {
  698. return int32('A')
  699. }
  700. return int32('D')
  701. }(), extension>>uint64(28)&7, func() int32 {
  702. if extension&0x8000 != 0 {
  703. return int32('A')
  704. }
  705. return int32('D')
  706. }(), extension>>uint64(12)&7)
  707. }
  708. func d68020_cas2_32(d *dasmInfo) string {
  709. extension := d.readImm(Long)
  710. return fmt.Sprintf("cas2.l D%d:D%d, D%d:D%d, (%c%d):(%c%d); (2+)", extension>>uint64(16)&7, extension&7, extension>>uint64(22)&7, extension>>uint64(6)&7, func() int32 {
  711. if Long.IsNegative(extension) {
  712. return int32('A')
  713. }
  714. return int32('D')
  715. }(), extension>>uint64(28)&7, func() int32 {
  716. if extension&0x8000 != 0 {
  717. return int32('A')
  718. }
  719. return int32('D')
  720. }(), extension>>uint64(12)&7)
  721. }
  722. func d68000_chk_16(d *dasmInfo) string {
  723. return fmt.Sprintf("chk.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  724. }
  725. func d68020_chk_32(d *dasmInfo) string {
  726. return fmt.Sprintf("chk.l %s, D%d; (2+)", d.getEaModeStr(Long), x(d.ir))
  727. }
  728. func d68020_chk2_cmp2_8(d *dasmInfo) string {
  729. extension := d.readImm(Word)
  730. return fmt.Sprintf("%s.b %s, %c%d; (2+)", func() string {
  731. if extension&0x800 != 0 {
  732. return "chk2"
  733. }
  734. return "cmp2"
  735. }(), d.getEaModeStr(Byte), func() int32 {
  736. if extension&0x8000 != 0 {
  737. return int32('A')
  738. }
  739. return int32('D')
  740. }(), (extension>>12)&7)
  741. }
  742. func d68020_chk2_cmp2_16(d *dasmInfo) string {
  743. extension := d.readImm(Word)
  744. return fmt.Sprintf("%s.w %s, %c%d; (2+)", func() string {
  745. if extension&0x800 != 0 {
  746. return "chk2"
  747. }
  748. return "cmp2"
  749. }(), d.getEaModeStr(Word), func() int32 {
  750. if extension&0x8000 != 0 {
  751. return int32('A')
  752. }
  753. return int32('D')
  754. }(), extension>>uint64(12)&7)
  755. }
  756. func d68020_chk2_cmp2_32(d *dasmInfo) string {
  757. extension := d.readImm(Word)
  758. return fmt.Sprintf("%s.l %s, %c%d; (2+)", func() string {
  759. if extension&0x800 != 0 {
  760. return "chk2"
  761. }
  762. return "cmp2"
  763. }(), d.getEaModeStr(Long), func() int32 {
  764. if extension&0x8000 != 0 {
  765. return int32('A')
  766. }
  767. return int32('D')
  768. }(), (extension>>12)&7)
  769. }
  770. func d68040_cinv(d *dasmInfo) string {
  771. switch (d.ir >> 3) & 3 {
  772. case 0:
  773. return "cinv (illegal scope); (4)"
  774. case 1:
  775. return fmt.Sprintf("cinvl %d, (A%d); (4)", (d.ir>>6)&3, y(d.ir))
  776. case 2:
  777. return fmt.Sprintf("cinvp %d, (A%d); (4)", (d.ir>>6)&3, y(d.ir))
  778. default:
  779. return fmt.Sprintf("cinva %d; (4)", (d.ir>>6)&3)
  780. }
  781. }
  782. func d68000_clr_8(d *dasmInfo) string {
  783. return fmt.Sprintf("clr.b %s", d.getEaModeStr(Byte))
  784. }
  785. func d68000_clr_16(d *dasmInfo) string {
  786. return fmt.Sprintf("clr.w %s", d.getEaModeStr(Word))
  787. }
  788. func d68000_clr_32(d *dasmInfo) string {
  789. return fmt.Sprintf("clr.l %s", d.getEaModeStr(Long))
  790. }
  791. func d68000_cmp_8(d *dasmInfo) string {
  792. return fmt.Sprintf("cmp.b %s, D%d", d.getEaModeStr(Byte), x(d.ir))
  793. }
  794. func d68000_cmp_16(d *dasmInfo) string {
  795. return fmt.Sprintf("cmp.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  796. }
  797. func d68000_cmp_32(d *dasmInfo) string {
  798. return fmt.Sprintf("cmp.l %s, D%d", d.getEaModeStr(Long), x(d.ir))
  799. }
  800. func d68000_cmpa_16(d *dasmInfo) string {
  801. return fmt.Sprintf("cmpa.w %s, A%d", d.getEaModeStr(Word), x(d.ir))
  802. }
  803. func d68000_cmpa_32(d *dasmInfo) string {
  804. return fmt.Sprintf("cmpa.l %s, A%d", d.getEaModeStr(Long), x(d.ir))
  805. }
  806. func d68000_cmpi_8(d *dasmInfo) string {
  807. return fmt.Sprintf("cmpi.b %s, %s", d.getImmStrSigned(Byte), d.getEaModeStr(Byte))
  808. }
  809. func d68020_cmpi_pcdi_8(d *dasmInfo) string {
  810. return fmt.Sprintf("cmpi.b %s, %s; (2+)", d.getImmStrSigned(Byte), d.getEaModeStr(Byte))
  811. }
  812. func d68020_cmpi_pcix_8(d *dasmInfo) string {
  813. return fmt.Sprintf("cmpi.b %s, %s; (2+)", d.getImmStrSigned(Byte), d.getEaModeStr(Byte))
  814. }
  815. func d68000_cmpi_16(d *dasmInfo) string {
  816. return fmt.Sprintf("cmpi.w %s, %s", d.getImmStrSigned(Word), d.getEaModeStr(Word))
  817. }
  818. func d68020_cmpi_pcdi_16(d *dasmInfo) string {
  819. return fmt.Sprintf("cmpi.w %s, %s; (2+)", d.getImmStrSigned(Word), d.getEaModeStr(Word))
  820. }
  821. func d68020_cmpi_pcix_16(d *dasmInfo) string {
  822. return fmt.Sprintf("cmpi.w %s, %s; (2+)", d.getImmStrSigned(Word), d.getEaModeStr(Word))
  823. }
  824. func d68000_cmpi_32(d *dasmInfo) string {
  825. return fmt.Sprintf("cmpi.l %s, %s", d.getImmStrSigned(Long), d.getEaModeStr(Long))
  826. }
  827. func d68020_cmpi_pcdi_32(d *dasmInfo) string {
  828. return fmt.Sprintf("cmpi.l %s, %s; (2+)", d.getImmStrSigned(Long), d.getEaModeStr(Long))
  829. }
  830. func d68020_cmpi_pcix_32(d *dasmInfo) string {
  831. return fmt.Sprintf("cmpi.l %s, %s; (2+)", d.getImmStrSigned(Long), d.getEaModeStr(Long))
  832. }
  833. func d68000_cmpm_8(d *dasmInfo) string {
  834. return fmt.Sprintf("cmpm.b (A%d)+, (A%d)+", y(d.ir), x(d.ir))
  835. }
  836. func d68000_cmpm_16(d *dasmInfo) string {
  837. return fmt.Sprintf("cmpm.w (A%d)+, (A%d)+", y(d.ir), x(d.ir))
  838. }
  839. func d68000_cmpm_32(d *dasmInfo) string {
  840. return fmt.Sprintf("cmpm.l (A%d)+, (A%d)+", y(d.ir), x(d.ir))
  841. }
  842. func d68020_cpbcc_16(d *dasmInfo) string {
  843. extension := d.readImm(Word)
  844. new_pc := d.pc + int32(int16(d.readImm(Word)))
  845. return fmt.Sprintf("%db%-4s %s; %x (extension = %x) (2-3)", x(d.ir), gCPCCTable[d.ir&63], d.getImmStrSigned(Word), new_pc, extension)
  846. }
  847. func d68020_cpbcc_32(d *dasmInfo) string {
  848. extension := d.readImm(Word)
  849. new_pc := d.pc + d.readImm(Long)
  850. return fmt.Sprintf("%db%-4s %s; %x (extension = %x) (2-3)", x(d.ir), gCPCCTable[d.ir&63], d.getImmStrSigned(Word), new_pc, extension)
  851. }
  852. func d68020_cpdbcc(d *dasmInfo) string {
  853. extension1 := d.readImm(Word)
  854. extension2 := d.readImm(Word)
  855. new_pc := d.pc + int32(int16(d.readImm(Word)))
  856. return fmt.Sprintf("%ddb%-4s D%d,%s; %x (extension = %x) (2-3)", x(d.ir), gCPCCTable[extension1&63], y(d.ir), d.getImmStrSigned(Word), new_pc, extension2)
  857. }
  858. func d68020_cpgen(d *dasmInfo) string {
  859. return fmt.Sprintf("%dgen %s; (2-3)", x(d.ir), d.getImmStrUnsigned(Long))
  860. }
  861. func d68020_cprestore(d *dasmInfo) string {
  862. if x(d.ir) == 1 {
  863. return fmt.Sprintf("frestore %s", d.getEaModeStr(Byte))
  864. } else {
  865. return fmt.Sprintf("%drestore %s; (2-3)", x(d.ir), d.getEaModeStr(Byte))
  866. }
  867. }
  868. func d68020_cpsave(d *dasmInfo) string {
  869. if x(d.ir) == 1 {
  870. return fmt.Sprintf("fsave %s", d.getEaModeStr(Byte))
  871. } else {
  872. return fmt.Sprintf("%dsave %s; (2-3)", x(d.ir), d.getEaModeStr(Byte))
  873. }
  874. }
  875. func d68020_cpscc(d *dasmInfo) string {
  876. extension1 := d.readImm(Word)
  877. extension2 := d.readImm(Word)
  878. return fmt.Sprintf("%ds%-4s %s; (extension = %x) (2-3)", x(d.ir), gCPCCTable[extension1&63], d.getEaModeStr(Byte), extension2)
  879. }
  880. func d68020_cptrapcc_0(d *dasmInfo) string {
  881. extension1 := d.readImm(Word)
  882. extension2 := d.readImm(Word)
  883. return fmt.Sprintf("%dtrap%-4s; (extension = %x) (2-3)", x(d.ir), gCPCCTable[extension1&63], extension2)
  884. }
  885. func d68020_cptrapcc_16(d *dasmInfo) string {
  886. extension1 := d.readImm(Word)
  887. extension2 := d.readImm(Word)
  888. return fmt.Sprintf("%dtrap%-4s %s; (extension = %x) (2-3)", x(d.ir), gCPCCTable[extension1&63], d.getImmStrUnsigned(Word), extension2)
  889. }
  890. func d68020_cptrapcc_32(d *dasmInfo) string {
  891. extension1 := d.readImm(Word)
  892. extension2 := d.readImm(Word)
  893. return fmt.Sprintf("%dtrap%-4s %s; (extension = %x) (2-3)", x(d.ir), gCPCCTable[extension1&63], d.getImmStrUnsigned(Long), extension2)
  894. }
  895. func d68040_cpush(d *dasmInfo) string {
  896. switch (d.ir >> 3) & 3 {
  897. case 0:
  898. return fmt.Sprintf("cpush (illegal scope); (4)")
  899. case 1:
  900. return fmt.Sprintf("cpushl %d, (A%d); (4)", d.ir>>uint64(6)&3, y(d.ir))
  901. case 2:
  902. return fmt.Sprintf("cpushp %d, (A%d); (4)", d.ir>>uint64(6)&3, y(d.ir))
  903. default:
  904. return fmt.Sprintf("cpusha %d; (4)", d.ir>>uint64(6)&3)
  905. }
  906. }
  907. func d68000_dbra(d *dasmInfo) string {
  908. return fmt.Sprintf("dbra D%d, $%x", y(d.ir), d.pc+int32(int16(d.readImm(Word))))
  909. }
  910. func d68000_dbcc(d *dasmInfo) string {
  911. return fmt.Sprintf("db%-2s D%d, $%x", gCCTable[d.ir>>uint64(8)&15], y(d.ir), d.pc+int32(int16(d.readImm(Word))))
  912. }
  913. func d68000_divs(d *dasmInfo) string {
  914. return fmt.Sprintf("divs.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  915. }
  916. func d68000_divu(d *dasmInfo) string {
  917. return fmt.Sprintf("divu.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  918. }
  919. func d68020_divl(d *dasmInfo) string {
  920. extension := d.readImm(Word)
  921. if extension&1024 != 0 {
  922. return fmt.Sprintf("div%c.l %s, D%d:D%d; (2+)", func() int32 {
  923. if extension&0x800 != 0 {
  924. return int32('s')
  925. }
  926. return int32('u')
  927. }(), d.getEaModeStr(Long), extension&7, extension>>uint64(12)&7)
  928. } else if extension&7 == extension>>uint64(12)&7 {
  929. return fmt.Sprintf("div%c.l %s, D%d; (2+)", func() int32 {
  930. if extension&0x800 != 0 {
  931. return int32('s')
  932. }
  933. return int32('u')
  934. }(), d.getEaModeStr(Long), extension>>uint64(12)&7)
  935. } else {
  936. return fmt.Sprintf("div%cl.l %s, D%d:D%d; (2+)", func() int32 {
  937. if extension&0x800 != 0 {
  938. return int32('s')
  939. }
  940. return int32('u')
  941. }(), d.getEaModeStr(Long), extension&7, extension>>uint64(12)&7)
  942. }
  943. }
  944. func d68000_eor_8(d *dasmInfo) string {
  945. return fmt.Sprintf("eor.b D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  946. }
  947. func d68000_eor_16(d *dasmInfo) string {
  948. return fmt.Sprintf("eor.w D%d, %s", x(d.ir), d.getEaModeStr(Word))
  949. }
  950. func d68000_eor_32(d *dasmInfo) string {
  951. return fmt.Sprintf("eor.l D%d, %s", x(d.ir), d.getEaModeStr(Long))
  952. }
  953. func d68000_eori_8(d *dasmInfo) string {
  954. return fmt.Sprintf("eori.b %s, %s", d.getImmStrUnsigned(Byte), d.getEaModeStr(Byte))
  955. }
  956. func d68000_eori_16(d *dasmInfo) string {
  957. return fmt.Sprintf("eori.w %s, %s", d.getImmStrUnsigned(Word), d.getEaModeStr(Word))
  958. }
  959. func d68000_eori_32(d *dasmInfo) string {
  960. return fmt.Sprintf("eori.l %s, %s", d.getImmStrUnsigned(Long), d.getEaModeStr(Long))
  961. }
  962. func d68000_eori_to_ccr(d *dasmInfo) string {
  963. return fmt.Sprintf("eori %s, CCR", d.getImmStrUnsigned(Byte))
  964. }
  965. func d68000_eori_to_sr(d *dasmInfo) string {
  966. return fmt.Sprintf("eori %s, SR", d.getImmStrUnsigned(Word))
  967. }
  968. func d68000_exg_dd(d *dasmInfo) string {
  969. return fmt.Sprintf("exg D%d, D%d", x(d.ir), y(d.ir))
  970. }
  971. func d68000_exg_aa(d *dasmInfo) string {
  972. return fmt.Sprintf("exg A%d, A%d", x(d.ir), y(d.ir))
  973. }
  974. func d68000_exg_da(d *dasmInfo) string {
  975. return fmt.Sprintf("exg D%d, A%d", x(d.ir), y(d.ir))
  976. }
  977. func d68000_ext_16(d *dasmInfo) string {
  978. return fmt.Sprintf("ext.w D%d", y(d.ir))
  979. }
  980. func d68000_ext_32(d *dasmInfo) string {
  981. return fmt.Sprintf("ext.l D%d", y(d.ir))
  982. }
  983. func d68020_extb_32(d *dasmInfo) string {
  984. return fmt.Sprintf("extb.l D%d; (2+)", y(d.ir))
  985. }
  986. var fpu_ukn = "FPU (?)"
  987. var float_mnemonics = map[int32]string{
  988. 0: "fmove", 1: "fint", 2: "fsinh", 3: "fintrz",
  989. 4: "fsqrt", 6: "flognp1", 8: "fetoxml", 9: "ftanh1",
  990. 10: "fatan", 12: "fasin", 13: "fatanh", 14: "fsin",
  991. 15: "ftan", 16: "fetox", 17: "ftwotox", 18: "ftentox",
  992. 20: "flogn", 21: "flog10", 22: "flog2", 24: "fabs",
  993. 25: "fcosh", 26: "fneg", 28: "facos", 29: "fcos",
  994. 30: "fgetexp", 31: "fgetman", 32: "fdiv", 33: "fmod",
  995. 34: "fadd", 35: "fmul", 36: "fsgldiv", 37: "frem",
  996. 38: "fscale", 39: "fsglmul", 40: "fsub", 0x30: "fsincos",
  997. 49: "fsincos", 50: "fsincos", 51: "fsincos", 52: "fsincos",
  998. 53: "fsincos", 54: "fsincos", 55: "fsincos", 56: "fcmp",
  999. 58: "ftst", 65: "fssqrt", 69: "fdsqrt", 88: "fsabs",
  1000. 90: "fsneg", 92: "fdabs", 94: "fdneg", 96: "fsdiv",
  1001. 98: "fsadd", 99: "fsmul", 100: "fddiv", 102: "fdadd",
  1002. 103: "fdmul", 104: "fssub", 108: "fdsub",
  1003. }
  1004. func d68040_fpu(d *dasmInfo) string {
  1005. w2 := d.readImm(Word)
  1006. src := (w2 >> 10) & 7
  1007. destReg := (w2 >> 7) & 7
  1008. if (w2>>13)&7 == 2 && (w2>>10)&7 == 7 {
  1009. // special override for FMOVECR
  1010. return fmt.Sprintf("fmovecr #$%0x, fp%d", w2&127, destReg)
  1011. }
  1012. switch (w2 >> 13) & 0x07 {
  1013. case 0, 2:
  1014. if mnemonic, ok := float_mnemonics[w2&0x7f]; ok {
  1015. if w2&0x4000 != 0 {
  1016. return fmt.Sprintf("%s%s %s, FP%d", mnemonic, gFPUDataFormatTable[src], d.getEaModeStr(Long), destReg)
  1017. }
  1018. return fmt.Sprintf("%s.x FP%d, FP%d", mnemonic, src, destReg)
  1019. }
  1020. return fpu_ukn
  1021. case 3:
  1022. switch (w2 >> 10) & 0x07 {
  1023. case 3:
  1024. // packed decimal w/fixed k-factor
  1025. return fmt.Sprintf("fmove%s FP%d, %s {#%d}", gFPUDataFormatTable[w2>>uint64(10)&7], destReg, d.getEaModeStr(Long), int32(int8(w2&127)))
  1026. case 7:
  1027. // packed decimal w/dynamic k-factor (register)
  1028. return fmt.Sprintf("fmove%s FP%d, %s {D%d}", gFPUDataFormatTable[w2>>uint64(10)&7], destReg, d.getEaModeStr(Long), (w2>>4)&7)
  1029. default:
  1030. return fmt.Sprintf("fmove%s FP%d, %s", gFPUDataFormatTable[w2>>uint64(10)&7], destReg, d.getEaModeStr(Long))
  1031. }
  1032. case 4:
  1033. // ea to control
  1034. if w2&4096 != 0 {
  1035. return fmt.Sprintf("fmovem.l %s, fpcr", d.getEaModeStr(Long))
  1036. }
  1037. if w2&0x800 != 0 {
  1038. return fmt.Sprintf("fmovem.l %s, /fpsr", d.getEaModeStr(Long))
  1039. }
  1040. if w2&1024 != 0 {
  1041. return fmt.Sprintf("fmovem.l %s, /fpiar", d.getEaModeStr(Long))
  1042. }
  1043. case 5:
  1044. // control to ea
  1045. if w2&4096 != 0 {
  1046. return fmt.Sprintf("fmovem.l fpcr, %s", d.getEaModeStr(Long))
  1047. }
  1048. if w2&0x800 != 0 {
  1049. return fmt.Sprintf("fmovem.l /fpsr, %s", d.getEaModeStr(Long))
  1050. }
  1051. if w2&1024 != 0 {
  1052. return fmt.Sprintf("fmovem.l /fpiar, %s", d.getEaModeStr(Long))
  1053. }
  1054. case 6:
  1055. if (w2>>11)&1 != 0 {
  1056. // memory to FPU, list
  1057. // dynamic register list
  1058. return fmt.Sprintf("fmovem.x %s, D%d", d.getEaModeStr(Long), (w2>>4)&7)
  1059. } else {
  1060. // static register list
  1061. str := fmt.Sprintf("fmovem.x %s, ", d.getEaModeStr(Long))
  1062. for i := 0; i < 8; i++ {
  1063. if w2&(1<<i) != 0 {
  1064. if (w2>>12)&1 != 0 {
  1065. // postincrement or control
  1066. str += fmt.Sprintf("FP%d ", 7-i)
  1067. } else {
  1068. // predecrement
  1069. str += fmt.Sprintf("FP%d ", i)
  1070. }
  1071. }
  1072. }
  1073. return str
  1074. }
  1075. case 7:
  1076. if (w2>>11)&1 != 0 {
  1077. // FPU to memory, list
  1078. // dynamic register list
  1079. return fmt.Sprintf("fmovem.x D%d, %s", w2>>uint64(4)&7, d.getEaModeStr(Long))
  1080. } else {
  1081. // static register list
  1082. str := "fmovem.x "
  1083. for i := 0; i < 8; i++ {
  1084. if w2&(1<<i) != 0 {
  1085. if (w2>>12)&1 != 0 {
  1086. // postincrement or control
  1087. str += fmt.Sprintf("FP%d ", 7-i)
  1088. } else {
  1089. // predecrement
  1090. str += fmt.Sprintf("FP%d ", i)
  1091. }
  1092. }
  1093. }
  1094. return str + ", " + d.getEaModeStr(Long)
  1095. }
  1096. }
  1097. return fpu_ukn
  1098. }
  1099. func d68000_jmp(d *dasmInfo) string {
  1100. return fmt.Sprintf("jmp %s", d.getEaModeStr(Long))
  1101. }
  1102. func d68000_jsr(d *dasmInfo) string {
  1103. return fmt.Sprintf("jsr %s", d.getEaModeStr(Long))
  1104. }
  1105. func d68000_lea(d *dasmInfo) string {
  1106. return fmt.Sprintf("lea %s, A%d", d.getEaModeStr(Long), x(d.ir))
  1107. }
  1108. func d68000_link_16(d *dasmInfo) string {
  1109. return fmt.Sprintf("link A%d, %s", y(d.ir), d.getImmStrSigned(Word))
  1110. }
  1111. func d68020_link_32(d *dasmInfo) string {
  1112. return fmt.Sprintf("link A%d, %s; (2+)", y(d.ir), d.getImmStrSigned(Long))
  1113. }
  1114. func d68000_lsr_s_8(d *dasmInfo) string {
  1115. return fmt.Sprintf("lsr.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1116. }
  1117. func d68000_lsr_s_16(d *dasmInfo) string {
  1118. return fmt.Sprintf("lsr.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1119. }
  1120. func d68000_lsr_s_32(d *dasmInfo) string {
  1121. return fmt.Sprintf("lsr.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1122. }
  1123. func d68000_lsr_r_8(d *dasmInfo) string {
  1124. return fmt.Sprintf("lsr.b D%d, D%d", x(d.ir), y(d.ir))
  1125. }
  1126. func d68000_lsr_r_16(d *dasmInfo) string {
  1127. return fmt.Sprintf("lsr.w D%d, D%d", x(d.ir), y(d.ir))
  1128. }
  1129. func d68000_lsr_r_32(d *dasmInfo) string {
  1130. return fmt.Sprintf("lsr.l D%d, D%d", x(d.ir), y(d.ir))
  1131. }
  1132. func d68000_lsr_ea(d *dasmInfo) string {
  1133. return fmt.Sprintf("lsr.w %s", d.getEaModeStr(Long))
  1134. }
  1135. func d68000_lsl_s_8(d *dasmInfo) string {
  1136. return fmt.Sprintf("lsl.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1137. }
  1138. func d68000_lsl_s_16(d *dasmInfo) string {
  1139. return fmt.Sprintf("lsl.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1140. }
  1141. func d68000_lsl_s_32(d *dasmInfo) string {
  1142. return fmt.Sprintf("lsl.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1143. }
  1144. func d68000_lsl_r_8(d *dasmInfo) string {
  1145. return fmt.Sprintf("lsl.b D%d, D%d", x(d.ir), y(d.ir))
  1146. }
  1147. func d68000_lsl_r_16(d *dasmInfo) string {
  1148. return fmt.Sprintf("lsl.w D%d, D%d", x(d.ir), y(d.ir))
  1149. }
  1150. func d68000_lsl_r_32(d *dasmInfo) string {
  1151. return fmt.Sprintf("lsl.l D%d, D%d", x(d.ir), y(d.ir))
  1152. }
  1153. func d68000_lsl_ea(d *dasmInfo) string {
  1154. return fmt.Sprintf("lsl.w %s", d.getEaModeStr(Long))
  1155. }
  1156. func d68000_move_8(d *dasmInfo) string {
  1157. d.ir = x(d.ir) | d.ir>>3&0x38
  1158. return fmt.Sprintf("move.b %s, %s", d.getEaModeStr(Byte), d.getEaModeStr(Byte))
  1159. }
  1160. func d68000_move_16(d *dasmInfo) string {
  1161. d.ir = x(d.ir) | d.ir>>3&0x38
  1162. return fmt.Sprintf("move.w %s, %s", d.getEaModeStr(Word), d.getEaModeStr(Word))
  1163. }
  1164. func d68000_move_32(d *dasmInfo) string {
  1165. d.ir = x(d.ir) | d.ir>>3&0x38
  1166. return fmt.Sprintf("move.l %s, %s", d.getEaModeStr(Long), d.getEaModeStr(Long))
  1167. }
  1168. func d68000_movea_16(d *dasmInfo) string {
  1169. return fmt.Sprintf("movea.w %s, A%d", d.getEaModeStr(Word), x(d.ir))
  1170. }
  1171. func d68000_movea_32(d *dasmInfo) string {
  1172. return fmt.Sprintf("movea.l %s, A%d", d.getEaModeStr(Long), x(d.ir))
  1173. }
  1174. func d68000_move_to_ccr(d *dasmInfo) string {
  1175. return fmt.Sprintf("move %s, CCR", d.getEaModeStr(Byte))
  1176. }
  1177. func d68010_move_fr_ccr(d *dasmInfo) string {
  1178. return fmt.Sprintf("move CCR, %s; (1+)", d.getEaModeStr(Byte))
  1179. }
  1180. func d68000_move_fr_sr(d *dasmInfo) string {
  1181. return fmt.Sprintf("move SR, %s", d.getEaModeStr(Word))
  1182. }
  1183. func d68000_move_to_sr(d *dasmInfo) string {
  1184. return fmt.Sprintf("move %s, SR", d.getEaModeStr(Word))
  1185. }
  1186. func d68000_move_fr_usp(d *dasmInfo) string {
  1187. return fmt.Sprintf("move USP, A%d", y(d.ir))
  1188. }
  1189. func d68000_move_to_usp(d *dasmInfo) string {
  1190. return fmt.Sprintf("move A%d, USP", y(d.ir))
  1191. }
  1192. func d68010_movec(d *dasmInfo) string {
  1193. var reg_name, processor string
  1194. extension := d.readImm(Word)
  1195. switch extension & 4095 {
  1196. case (0):
  1197. reg_name = "SFC"
  1198. processor = "1+"
  1199. case (1):
  1200. reg_name = "DFC"
  1201. processor = "1+"
  1202. case (0x800):
  1203. reg_name = "USP"
  1204. processor = "1+"
  1205. case (2049):
  1206. reg_name = "VBR"
  1207. processor = "1+"
  1208. case (2):
  1209. reg_name = "CACR"
  1210. processor = "2+"
  1211. case (2050):
  1212. reg_name = "CAAR"
  1213. processor = "2,3"
  1214. case (2051):
  1215. reg_name = "MSP"
  1216. processor = "2+"
  1217. case (2052):
  1218. reg_name = "ISP"
  1219. processor = "2+"
  1220. case (3):
  1221. reg_name = "TC"
  1222. processor = "4+"
  1223. case (4):
  1224. reg_name = "ITT0"
  1225. processor = "4+"
  1226. case (5):
  1227. reg_name = "ITT1"
  1228. processor = "4+"
  1229. case (6):
  1230. reg_name = "DTT0"
  1231. processor = "4+"
  1232. case (7):
  1233. reg_name = "DTT1"
  1234. processor = "4+"
  1235. case 2053:
  1236. reg_name = "MMUSR"
  1237. processor = "4+"
  1238. case (2054):
  1239. reg_name = "URP"
  1240. processor = "4+"
  1241. case (2055):
  1242. reg_name = "SRP"
  1243. processor = "4+"
  1244. default:
  1245. reg_name = Word.SignedHexString(extension & 4095)
  1246. processor = "?"
  1247. }
  1248. if d.ir&1 != 0 {
  1249. return fmt.Sprintf("movec %c%d, %s; (%s)", func() int32 {
  1250. if extension&0x8000 != 0 {
  1251. return int32('A')
  1252. }
  1253. return int32('D')
  1254. }(), extension>>uint64(12)&7, reg_name, processor)
  1255. } else {
  1256. return fmt.Sprintf("movec %s, %c%d; (%s)", reg_name, func() int32 {
  1257. if extension&0x8000 != 0 {
  1258. return int32('A')
  1259. }
  1260. return int32('D')
  1261. }(), extension>>uint64(12)&7, processor)
  1262. }
  1263. }
  1264. func d68000_movem_pd_16(d *dasmInfo) string {
  1265. data := d.readImm(Word)
  1266. buffer := ""
  1267. for i := 0; i < 8; i++ {
  1268. if data&(1<<(15-i)) != 0 {
  1269. first := i
  1270. rl := 0
  1271. for i < 7 && data&(1<<(15-(i+1))) != 0 {
  1272. i++
  1273. rl++
  1274. }
  1275. if len(buffer) > 0 {
  1276. buffer += "/"
  1277. }
  1278. buffer += fmt.Sprintf("D%d", first)
  1279. if rl > 0 {
  1280. buffer += fmt.Sprintf("-D%d", first+rl)
  1281. }
  1282. }
  1283. }
  1284. for i := 0; i < 8; i++ {
  1285. if data&(1<<(7-i)) != 0 {
  1286. first := i
  1287. rl := 0
  1288. for i < 7 && data&(1<<(7-(i+1))) != 0 {
  1289. i++
  1290. rl++
  1291. }
  1292. if len(buffer) > 0 {
  1293. buffer += "/"
  1294. }
  1295. buffer += fmt.Sprintf("A%d", first)
  1296. if rl > 0 {
  1297. buffer += fmt.Sprintf("-A%d", first+rl)
  1298. }
  1299. }
  1300. }
  1301. return fmt.Sprintf("movem.w %s, %s", buffer, d.getEaModeStr(Word))
  1302. }
  1303. func d68000_movem_pd_32(d *dasmInfo) string {
  1304. data := d.readImm(Word)
  1305. buffer := ""
  1306. for i := 0; i < 8; i++ {
  1307. if data&(1<<(15-i)) != 0 {
  1308. first := i
  1309. rl := 0
  1310. for i < 7 && data&(1<<(15-(i+1))) != 0 {
  1311. i++
  1312. rl++
  1313. }
  1314. if len(buffer) > 0 {
  1315. buffer += "/"
  1316. }
  1317. buffer += fmt.Sprintf("D%d", first)
  1318. if rl > 0 {
  1319. buffer += fmt.Sprintf("-D%d", first+rl)
  1320. }
  1321. }
  1322. }
  1323. for i := 0; i < 8; i++ {
  1324. if data&(1<<(7-i)) != 0 {
  1325. first := i
  1326. rl := 0
  1327. for i < 7 && data&(1<<(7-(i+1))) != 0 {
  1328. i++
  1329. rl++
  1330. }
  1331. if len(buffer) > 0 {
  1332. buffer += "/"
  1333. }
  1334. buffer += fmt.Sprintf("A%d", first)
  1335. if rl > 0 {
  1336. buffer += fmt.Sprintf("-A%d", first+rl)
  1337. }
  1338. }
  1339. }
  1340. return fmt.Sprintf("movem.l %s, %s", buffer, d.getEaModeStr(Long))
  1341. }
  1342. // d68000_movem_er_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:0xE27
  1343. func d68000_movem_er_16(d *dasmInfo) string {
  1344. data := d.readImm(Word)
  1345. buffer := ""
  1346. for i := 0; i < 8; i++ {
  1347. if data&(1<<i) != 0 {
  1348. first := i
  1349. rl := 0
  1350. for i < 7 && data&(1<<(i+1)) != 0 {
  1351. i++
  1352. rl++
  1353. }
  1354. if len(buffer) > 0 {
  1355. buffer += "/"
  1356. }
  1357. buffer += fmt.Sprintf("D%d", first)
  1358. if rl > 0 {
  1359. buffer += fmt.Sprintf("-D%d", first+rl)
  1360. }
  1361. }
  1362. }
  1363. for i := 0; i < 8; i++ {
  1364. if data&(1<<(i+8)) != 0 {
  1365. first := i
  1366. rl := 0
  1367. for i < 7 && data&(1<<(i+8+1)) != 0 {
  1368. i++
  1369. rl++
  1370. }
  1371. if len(buffer) > 0 {
  1372. buffer += "/"
  1373. }
  1374. buffer += fmt.Sprintf("A%d", first)
  1375. if rl > 0 {
  1376. buffer += fmt.Sprintf("-A%d", first+rl)
  1377. }
  1378. }
  1379. }
  1380. return fmt.Sprintf("movem.w %s, %s", d.getEaModeStr(Word), buffer)
  1381. }
  1382. // d68000_movem_er_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2315
  1383. func d68000_movem_er_32(d *dasmInfo) string {
  1384. data := d.readImm(Word)
  1385. buffer := ""
  1386. for i := 0; i < 8; i++ {
  1387. if data&(1<<i) != 0 {
  1388. first := i
  1389. rl := 0
  1390. for i < 7 && data&(1<<(i+1)) != 0 {
  1391. i++
  1392. rl++
  1393. }
  1394. if len(buffer) > 0 {
  1395. buffer += "/"
  1396. }
  1397. buffer += fmt.Sprintf("D%d", first)
  1398. if rl > 0 {
  1399. buffer += fmt.Sprintf("-D%d", first+rl)
  1400. }
  1401. }
  1402. }
  1403. for i := 0; i < 8; i++ {
  1404. if data&(1<<(i+8)) != 0 {
  1405. first := i
  1406. rl := 0
  1407. for i < 7 && data&(1<<uint64(i+8+1)) != 0 {
  1408. i++
  1409. rl++
  1410. }
  1411. if len(buffer) > 0 {
  1412. buffer += "/"
  1413. }
  1414. buffer += fmt.Sprintf("A%d", first)
  1415. if rl > 0 {
  1416. buffer += fmt.Sprintf("-A%d", first+rl)
  1417. }
  1418. }
  1419. }
  1420. return fmt.Sprintf("movem.l %s, %s", d.getEaModeStr(Long), buffer)
  1421. }
  1422. func d68000_movem_re_16(d *dasmInfo) string {
  1423. data := d.readImm(Word)
  1424. buffer := ""
  1425. for i := 0; i < 8; i++ {
  1426. if data&(1<<i) != 0 {
  1427. first := i
  1428. rl := 0
  1429. for i < 7 && data&(1<<uint64(i+1)) != 0 {
  1430. i++
  1431. rl++
  1432. }
  1433. if len(buffer) > 0 {
  1434. buffer += "/"
  1435. }
  1436. buffer += fmt.Sprintf("D%d", first)
  1437. if rl > 0 {
  1438. buffer += fmt.Sprintf("-D%d", first+rl)
  1439. }
  1440. }
  1441. }
  1442. for i := 0; i < 8; i++ {
  1443. if data&(1<<(i+8)) != 0 {
  1444. first := i
  1445. rl := 0
  1446. for i < 7 && data&(1<<uint64(i+8+1)) != 0 {
  1447. i++
  1448. rl++
  1449. }
  1450. if len(buffer) > 0 {
  1451. buffer += "/"
  1452. }
  1453. buffer += fmt.Sprintf("A%d", first)
  1454. if rl > 0 {
  1455. buffer += fmt.Sprintf("-A%d", first+rl)
  1456. }
  1457. }
  1458. }
  1459. return fmt.Sprintf("movem.w %s, %s", buffer, d.getEaModeStr(Word))
  1460. }
  1461. // d68000_movem_re_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2411
  1462. func d68000_movem_re_32(d *dasmInfo) string {
  1463. data := d.readImm(Word)
  1464. buffer := ""
  1465. for i := 0; i < 8; i++ {
  1466. if data&(1<<(i)) != 0 {
  1467. first := i
  1468. rl := 0
  1469. for i < 7 && data&(1<<(i+1)) != 0 {
  1470. i++
  1471. rl++
  1472. }
  1473. if len(buffer) > 0 {
  1474. buffer += "/"
  1475. }
  1476. buffer += fmt.Sprintf("D%d", first)
  1477. if rl > 0 {
  1478. buffer += fmt.Sprintf("-D%d", first+rl)
  1479. }
  1480. }
  1481. }
  1482. for i := 0; i < 8; i++ {
  1483. if data&(1<<(i+8)) != 0 {
  1484. first := i
  1485. rl := 0
  1486. for i < 7 && data&(1<<uint64(i+8+1)) != 0 {
  1487. i++
  1488. rl++
  1489. }
  1490. if len(buffer) > 0 {
  1491. buffer += "/"
  1492. }
  1493. buffer += fmt.Sprintf("A%d", first)
  1494. if rl > 0 {
  1495. buffer += fmt.Sprintf("-A%d", first+rl)
  1496. }
  1497. }
  1498. }
  1499. return fmt.Sprintf("movem.l %s, %s", buffer, d.getEaModeStr(Long))
  1500. }
  1501. func d68000_movep_re_16(d *dasmInfo) string {
  1502. return fmt.Sprintf("movep.w D%d, ($%x,A%d)", x(d.ir), d.readImm(Word), y(d.ir))
  1503. }
  1504. func d68000_movep_re_32(d *dasmInfo) string {
  1505. return fmt.Sprintf("movep.l D%d, ($%x,A%d)", x(d.ir), d.readImm(Word), y(d.ir))
  1506. }
  1507. func d68000_movep_er_16(d *dasmInfo) string {
  1508. return fmt.Sprintf("movep.w ($%x,A%d), D%d", d.readImm(Word), y(d.ir), x(d.ir))
  1509. }
  1510. func d68000_movep_er_32(d *dasmInfo) string {
  1511. return fmt.Sprintf("movep.l ($%x,A%d), D%d", d.readImm(Word), y(d.ir), x(d.ir))
  1512. }
  1513. func d68010_moves_8(d *dasmInfo) string {
  1514. extension := d.readImm(Word)
  1515. if extension&0x800 != 0 {
  1516. return fmt.Sprintf("moves.b %c%d, %s; (1+)", func() int32 {
  1517. if extension&0x8000 != 0 {
  1518. return int32('A')
  1519. }
  1520. return int32('D')
  1521. }(), extension>>uint64(12)&7, d.getEaModeStr(Byte))
  1522. } else {
  1523. return fmt.Sprintf("moves.b %s, %c%d; (1+)", d.getEaModeStr(Byte), func() int32 {
  1524. if extension&0x8000 != 0 {
  1525. return int32('A')
  1526. }
  1527. return int32('D')
  1528. }(), (extension>>12)&7)
  1529. }
  1530. }
  1531. func d68010_moves_16(d *dasmInfo) string {
  1532. extension := d.readImm(Word)
  1533. if extension&0x800 != 0 {
  1534. return fmt.Sprintf("moves.w %c%d, %s; (1+)", func() int32 {
  1535. if extension&0x8000 != 0 {
  1536. return int32('A')
  1537. }
  1538. return int32('D')
  1539. }(), extension>>uint64(12)&7, d.getEaModeStr(Word))
  1540. } else {
  1541. return fmt.Sprintf("moves.w %s, %c%d; (1+)", d.getEaModeStr(Word), func() int32 {
  1542. if extension&0x8000 != 0 {
  1543. return int32('A')
  1544. }
  1545. return int32('D')
  1546. }(), (extension>>12)&7)
  1547. }
  1548. }
  1549. func d68010_moves_32(d *dasmInfo) string {
  1550. extension := d.readImm(Word)
  1551. if extension&0x800 != 0 {
  1552. return fmt.Sprintf("moves.l %c%d, %s; (1+)", func() int32 {
  1553. if extension&0x8000 != 0 {
  1554. return int32('A')
  1555. }
  1556. return int32('D')
  1557. }(), extension>>uint64(12)&7, d.getEaModeStr(Long))
  1558. } else {
  1559. return fmt.Sprintf("moves.l %s, %c%d; (1+)", d.getEaModeStr(Long), func() int32 {
  1560. if extension&0x8000 != 0 {
  1561. return int32('A')
  1562. }
  1563. return int32('D')
  1564. }(), extension>>uint64(12)&7)
  1565. }
  1566. }
  1567. // d68000_moveq - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2512
  1568. func d68000_moveq(d *dasmInfo) string {
  1569. return fmt.Sprintf("moveq #%s, D%d", Byte.SignedHexString(int32(d.ir)), x(d.ir))
  1570. }
  1571. // d68040_move16_pi_pi - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2517
  1572. func d68040_move16_pi_pi(d *dasmInfo) string {
  1573. return fmt.Sprintf("move16 (A%d)+, (A%d)+; (4)", y(d.ir), d.readImm(Word)>>uint64(12)&7)
  1574. }
  1575. // d68040_move16_pi_al - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2523
  1576. func d68040_move16_pi_al(d *dasmInfo) string {
  1577. return fmt.Sprintf("move16 (A%d)+, %s; (4)", y(d.ir), d.getImmStrUnsigned(Long))
  1578. }
  1579. // d68040_move16_al_pi - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2529
  1580. func d68040_move16_al_pi(d *dasmInfo) string {
  1581. return fmt.Sprintf("move16 %s, (A%d)+; (4)", d.getImmStrUnsigned(Long), y(d.ir))
  1582. }
  1583. // d68040_move16_ai_al - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2535
  1584. func d68040_move16_ai_al(d *dasmInfo) string {
  1585. return fmt.Sprintf("move16 (A%d), %s; (4)", y(d.ir), d.getImmStrUnsigned(Long))
  1586. }
  1587. // d68040_move16_al_ai - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2541
  1588. func d68040_move16_al_ai(d *dasmInfo) string {
  1589. return fmt.Sprintf("move16 %s, (A%d); (4)", d.getImmStrUnsigned(Long), y(d.ir))
  1590. }
  1591. // d68000_muls - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2547
  1592. func d68000_muls(d *dasmInfo) string {
  1593. return fmt.Sprintf("muls.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  1594. }
  1595. // d68000_mulu - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:0xFF2
  1596. func d68000_mulu(d *dasmInfo) string {
  1597. return fmt.Sprintf("mulu.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  1598. }
  1599. // d68020_mull - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:0xFF7
  1600. func d68020_mull(d *dasmInfo) string {
  1601. extension := d.readImm(Word)
  1602. if extension&1024 != 0 {
  1603. return fmt.Sprintf("mul%c.l %s, D%d:D%d; (2+)", func() int32 {
  1604. if extension&0x800 != 0 {
  1605. return int32('s')
  1606. }
  1607. return int32('u')
  1608. }(), d.getEaModeStr(Long), extension&7, extension>>uint64(12)&7)
  1609. } else {
  1610. return fmt.Sprintf("mul%c.l %s, D%d; (2+)", func() int32 {
  1611. if extension&0x800 != 0 {
  1612. return int32('s')
  1613. }
  1614. return int32('u')
  1615. }(), d.getEaModeStr(Long), extension>>uint64(12)&7)
  1616. }
  1617. }
  1618. // d68000_nbcd - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:0x1009
  1619. func d68000_nbcd(d *dasmInfo) string {
  1620. return fmt.Sprintf("nbcd %s", d.getEaModeStr(Byte))
  1621. }
  1622. // d68000_neg_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2574
  1623. func d68000_neg_8(d *dasmInfo) string {
  1624. return fmt.Sprintf("neg.b %s", d.getEaModeStr(Byte))
  1625. }
  1626. // d68000_neg_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2579
  1627. func d68000_neg_16(d *dasmInfo) string {
  1628. return fmt.Sprintf("neg.w %s", d.getEaModeStr(Word))
  1629. }
  1630. // d68000_neg_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2584
  1631. func d68000_neg_32(d *dasmInfo) string {
  1632. return fmt.Sprintf("neg.l %s", d.getEaModeStr(Long))
  1633. }
  1634. // d68000_negx_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2589
  1635. func d68000_negx_8(d *dasmInfo) string {
  1636. return fmt.Sprintf("negx.b %s", d.getEaModeStr(Byte))
  1637. }
  1638. // d68000_negx_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2594
  1639. func d68000_negx_16(d *dasmInfo) string {
  1640. return fmt.Sprintf("negx.w %s", d.getEaModeStr(Word))
  1641. }
  1642. // d68000_negx_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2599
  1643. func d68000_negx_32(d *dasmInfo) string {
  1644. return fmt.Sprintf("negx.l %s", d.getEaModeStr(Long))
  1645. }
  1646. // d68000_nop - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2604
  1647. func d68000_nop(d *dasmInfo) string {
  1648. return fmt.Sprintf("nop")
  1649. }
  1650. // d68000_not_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2609
  1651. func d68000_not_8(d *dasmInfo) string {
  1652. return fmt.Sprintf("not.b %s", d.getEaModeStr(Byte))
  1653. }
  1654. // d68000_not_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2614
  1655. func d68000_not_16(d *dasmInfo) string {
  1656. return fmt.Sprintf("not.w %s", d.getEaModeStr(Word))
  1657. }
  1658. // d68000_not_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2619
  1659. func d68000_not_32(d *dasmInfo) string {
  1660. return fmt.Sprintf("not.l %s", d.getEaModeStr(Long))
  1661. }
  1662. // d68000_or_er_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2624
  1663. func d68000_or_er_8(d *dasmInfo) string {
  1664. return fmt.Sprintf("or.b %s, D%d", d.getEaModeStr(Byte), x(d.ir))
  1665. }
  1666. // d68000_or_er_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2629
  1667. func d68000_or_er_16(d *dasmInfo) string {
  1668. return fmt.Sprintf("or.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  1669. }
  1670. // d68000_or_er_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2634
  1671. func d68000_or_er_32(d *dasmInfo) string {
  1672. return fmt.Sprintf("or.l %s, D%d", d.getEaModeStr(Long), x(d.ir))
  1673. }
  1674. // d68000_or_re_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2639
  1675. func d68000_or_re_8(d *dasmInfo) string {
  1676. return fmt.Sprintf("or.b D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  1677. }
  1678. // d68000_or_re_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2644
  1679. func d68000_or_re_16(d *dasmInfo) string {
  1680. return fmt.Sprintf("or.w D%d, %s", x(d.ir), d.getEaModeStr(Word))
  1681. }
  1682. // d68000_or_re_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2649
  1683. func d68000_or_re_32(d *dasmInfo) string {
  1684. return fmt.Sprintf("or.l D%d, %s", x(d.ir), d.getEaModeStr(Long))
  1685. }
  1686. // d68000_ori_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2654
  1687. func d68000_ori_8(d *dasmInfo) string {
  1688. var str []byte
  1689. return fmt.Sprintf("ori.b %s, %s", str, d.getEaModeStr(Byte))
  1690. }
  1691. // d68000_ori_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2660
  1692. func d68000_ori_16(d *dasmInfo) string {
  1693. return fmt.Sprintf("ori.w %s, %s", d.getImmStrUnsigned(Word), d.getEaModeStr(Word))
  1694. }
  1695. // d68000_ori_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2666
  1696. func d68000_ori_32(d *dasmInfo) string {
  1697. return fmt.Sprintf("ori.l %s, %s", d.getImmStrUnsigned(Long), d.getEaModeStr(Long))
  1698. }
  1699. // d68000_ori_to_ccr - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2672
  1700. func d68000_ori_to_ccr(d *dasmInfo) string {
  1701. return fmt.Sprintf("ori %s, CCR", d.getImmStrUnsigned(Byte))
  1702. }
  1703. // d68000_ori_to_sr - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2677
  1704. func d68000_ori_to_sr(d *dasmInfo) string {
  1705. return fmt.Sprintf("ori %s, SR", d.getImmStrUnsigned(Word))
  1706. }
  1707. func d68020_pack_rr(d *dasmInfo) string {
  1708. return fmt.Sprintf("pack D%d, D%d, %s; (2+)", y(d.ir), x(d.ir), d.getImmStrUnsigned(Word))
  1709. }
  1710. func d68020_pack_mm(d *dasmInfo) string {
  1711. return fmt.Sprintf("pack -(A%d), -(A%d), %s; (2+)", y(d.ir), x(d.ir), d.getImmStrUnsigned(Word))
  1712. }
  1713. func d68000_pea(d *dasmInfo) string {
  1714. return fmt.Sprintf("pea %s", d.getEaModeStr(Long))
  1715. }
  1716. func d68040_pflush(d *dasmInfo) string {
  1717. ext := ""
  1718. if d.ir&8 == 0 {
  1719. ext = "n"
  1720. }
  1721. if d.ir&16 != 0 {
  1722. return fmt.Sprintf("pflusha%s", ext)
  1723. }
  1724. return fmt.Sprintf("pflush%s(A%d)", ext, y(d.ir))
  1725. }
  1726. func d68000_reset(d *dasmInfo) string {
  1727. return "reset"
  1728. }
  1729. func d68000_ror_s_8(d *dasmInfo) string {
  1730. return fmt.Sprintf("ror.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1731. }
  1732. func d68000_ror_s_16(d *dasmInfo) string {
  1733. return fmt.Sprintf("ror.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1734. }
  1735. func d68000_ror_s_32(d *dasmInfo) string {
  1736. return fmt.Sprintf("ror.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1737. }
  1738. func d68000_ror_r_8(d *dasmInfo) string {
  1739. return fmt.Sprintf("ror.b D%d, D%d", x(d.ir), y(d.ir))
  1740. }
  1741. func d68000_ror_r_16(d *dasmInfo) string {
  1742. return fmt.Sprintf("ror.w D%d, D%d", x(d.ir), y(d.ir))
  1743. }
  1744. func d68000_ror_r_32(d *dasmInfo) string {
  1745. return fmt.Sprintf("ror.l D%d, D%d", x(d.ir), y(d.ir))
  1746. }
  1747. func d68000_ror_ea(d *dasmInfo) string {
  1748. return fmt.Sprintf("ror.w %s", d.getEaModeStr(Long))
  1749. }
  1750. func d68000_rol_s_8(d *dasmInfo) string {
  1751. return fmt.Sprintf("rol.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1752. }
  1753. func d68000_rol_s_16(d *dasmInfo) string {
  1754. return fmt.Sprintf("rol.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1755. }
  1756. func d68000_rol_s_32(d *dasmInfo) string {
  1757. return fmt.Sprintf("rol.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1758. }
  1759. func d68000_rol_r_8(d *dasmInfo) string {
  1760. return fmt.Sprintf("rol.b D%d, D%d", x(d.ir), y(d.ir))
  1761. }
  1762. func d68000_rol_r_16(d *dasmInfo) string {
  1763. return fmt.Sprintf("rol.w D%d, D%d", x(d.ir), y(d.ir))
  1764. }
  1765. func d68000_rol_r_32(d *dasmInfo) string {
  1766. return fmt.Sprintf("rol.l D%d, D%d", x(d.ir), y(d.ir))
  1767. }
  1768. func d68000_rol_ea(d *dasmInfo) string {
  1769. return fmt.Sprintf("rol.w %s", d.getEaModeStr(Long))
  1770. }
  1771. func d68000_roxr_s_8(d *dasmInfo) string {
  1772. return fmt.Sprintf("roxr.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1773. }
  1774. func d68000_roxr_s_16(d *dasmInfo) string {
  1775. return fmt.Sprintf("roxr.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1776. }
  1777. func d68000_roxr_s_32(d *dasmInfo) string {
  1778. return fmt.Sprintf("roxr.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1779. }
  1780. func d68000_roxr_r_8(d *dasmInfo) string {
  1781. return fmt.Sprintf("roxr.b D%d, D%d", x(d.ir), y(d.ir))
  1782. }
  1783. func d68000_roxr_r_16(d *dasmInfo) string {
  1784. return fmt.Sprintf("roxr.w D%d, D%d", x(d.ir), y(d.ir))
  1785. }
  1786. func d68000_roxr_r_32(d *dasmInfo) string {
  1787. return fmt.Sprintf("roxr.l D%d, D%d", x(d.ir), y(d.ir))
  1788. }
  1789. func d68000_roxr_ea(d *dasmInfo) string {
  1790. return fmt.Sprintf("roxr.w %s", d.getEaModeStr(Long))
  1791. }
  1792. func d68000_roxl_s_8(d *dasmInfo) string {
  1793. return fmt.Sprintf("roxl.b #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1794. }
  1795. func d68000_roxl_s_16(d *dasmInfo) string {
  1796. return fmt.Sprintf("roxl.w #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1797. }
  1798. func d68000_roxl_s_32(d *dasmInfo) string {
  1799. return fmt.Sprintf("roxl.l #%d, D%d", g3bitQDataTable[x(d.ir)], y(d.ir))
  1800. }
  1801. func d68000_roxl_r_8(d *dasmInfo) string {
  1802. return fmt.Sprintf("roxl.b D%d, D%d", x(d.ir), y(d.ir))
  1803. }
  1804. func d68000_roxl_r_16(d *dasmInfo) string {
  1805. return fmt.Sprintf("roxl.w D%d, D%d", x(d.ir), y(d.ir))
  1806. }
  1807. func d68000_roxl_r_32(d *dasmInfo) string {
  1808. return fmt.Sprintf("roxl.l D%d, D%d", x(d.ir), y(d.ir))
  1809. }
  1810. func d68000_roxl_ea(d *dasmInfo) string {
  1811. return fmt.Sprintf("roxl.w %s", d.getEaModeStr(Long))
  1812. }
  1813. func d68010_rtd(d *dasmInfo) string {
  1814. return fmt.Sprintf("rtd %s; (1+)", d.getImmStrSigned(Word))
  1815. }
  1816. func d68000_rte(d *dasmInfo) string {
  1817. return "rte"
  1818. }
  1819. func d68020_rtm(d *dasmInfo) string {
  1820. return fmt.Sprintf("rtm %c%d; (2+)",
  1821. func() int32 {
  1822. if d.ir&8 != 0 {
  1823. return int32('A')
  1824. }
  1825. return int32('D')
  1826. }(), y(d.ir))
  1827. }
  1828. func d68000_rtr(d *dasmInfo) string {
  1829. return "rtr"
  1830. }
  1831. func d68000_rts(d *dasmInfo) string {
  1832. return "rts"
  1833. }
  1834. func d68000_sbcd_rr(d *dasmInfo) string {
  1835. return fmt.Sprintf("sbcd D%d, D%d", y(d.ir), x(d.ir))
  1836. }
  1837. func d68000_sbcd_mm(d *dasmInfo) string {
  1838. return fmt.Sprintf("sbcd -(A%d), -(A%d)", y(d.ir), x(d.ir))
  1839. }
  1840. func d68000_scc(d *dasmInfo) string {
  1841. return fmt.Sprintf("s%-2s %s", gCCTable[d.ir>>uint64(8)&15], d.getEaModeStr(Byte))
  1842. }
  1843. func d68000_stop(d *dasmInfo) string {
  1844. return fmt.Sprintf("stop %s", d.getImmStrSigned(Word))
  1845. }
  1846. func d68000_sub_er_8(d *dasmInfo) string {
  1847. return fmt.Sprintf("sub.b %s, D%d", d.getEaModeStr(Byte), x(d.ir))
  1848. }
  1849. func d68000_sub_er_16(d *dasmInfo) string {
  1850. return fmt.Sprintf("sub.w %s, D%d", d.getEaModeStr(Word), x(d.ir))
  1851. }
  1852. func d68000_sub_er_32(d *dasmInfo) string {
  1853. return fmt.Sprintf("sub.l %s, D%d", d.getEaModeStr(Long), x(d.ir))
  1854. }
  1855. func d68000_sub_re_8(d *dasmInfo) string {
  1856. return fmt.Sprintf("sub.b D%d, %s", x(d.ir), d.getEaModeStr(Byte))
  1857. }
  1858. // d68000_sub_re_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2932
  1859. func d68000_sub_re_16(d *dasmInfo) string {
  1860. return fmt.Sprintf("sub.w D%d, %s", x(d.ir), d.getEaModeStr(Word))
  1861. }
  1862. // d68000_sub_re_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2937
  1863. func d68000_sub_re_32(d *dasmInfo) string {
  1864. return fmt.Sprintf("sub.l D%d, %s", x(d.ir), d.getEaModeStr(Long))
  1865. }
  1866. // d68000_suba_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2942
  1867. func d68000_suba_16(d *dasmInfo) string {
  1868. return fmt.Sprintf("suba.w %s, A%d", d.getEaModeStr(Word), x(d.ir))
  1869. }
  1870. // d68000_suba_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2947
  1871. func d68000_suba_32(d *dasmInfo) string {
  1872. return fmt.Sprintf("suba.l %s, A%d", d.getEaModeStr(Long), x(d.ir))
  1873. }
  1874. // d68000_subi_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2952
  1875. func d68000_subi_8(d *dasmInfo) string {
  1876. var str []byte
  1877. return fmt.Sprintf("subi.b %s, %s", str, d.getEaModeStr(Byte))
  1878. }
  1879. // d68000_subi_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2958
  1880. func d68000_subi_16(d *dasmInfo) string {
  1881. return fmt.Sprintf("subi.w %s, %s", d.getImmStrSigned(Word), d.getEaModeStr(Word))
  1882. }
  1883. // d68000_subi_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2964
  1884. func d68000_subi_32(d *dasmInfo) string {
  1885. return fmt.Sprintf("subi.l %s, %s", d.getImmStrSigned(Long), d.getEaModeStr(Long))
  1886. }
  1887. // d68000_subq_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2970
  1888. func d68000_subq_8(d *dasmInfo) string {
  1889. return fmt.Sprintf("subq.b #%d, %s", g3bitQDataTable[x(d.ir)], d.getEaModeStr(Byte))
  1890. }
  1891. // d68000_subq_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2975
  1892. func d68000_subq_16(d *dasmInfo) string {
  1893. return fmt.Sprintf("subq.w #%d, %s", g3bitQDataTable[x(d.ir)], d.getEaModeStr(Word))
  1894. }
  1895. // d68000_subq_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2980
  1896. func d68000_subq_32(d *dasmInfo) string {
  1897. return fmt.Sprintf("subq.l #%d, %s", g3bitQDataTable[x(d.ir)], d.getEaModeStr(Long))
  1898. }
  1899. // d68000_subx_rr_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2985
  1900. func d68000_subx_rr_8(d *dasmInfo) string {
  1901. return fmt.Sprintf("subx.b D%d, D%d", y(d.ir), x(d.ir))
  1902. }
  1903. // d68000_subx_rr_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2990
  1904. func d68000_subx_rr_16(d *dasmInfo) string {
  1905. return fmt.Sprintf("subx.w D%d, D%d", y(d.ir), x(d.ir))
  1906. }
  1907. // d68000_subx_rr_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:2995
  1908. func d68000_subx_rr_32(d *dasmInfo) string {
  1909. return fmt.Sprintf("subx.l D%d, D%d", y(d.ir), x(d.ir))
  1910. }
  1911. // d68000_subx_mm_8 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:3000
  1912. func d68000_subx_mm_8(d *dasmInfo) string {
  1913. return fmt.Sprintf("subx.b -(A%d), -(A%d)", y(d.ir), x(d.ir))
  1914. }
  1915. // d68000_subx_mm_16 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:3005
  1916. func d68000_subx_mm_16(d *dasmInfo) string {
  1917. return fmt.Sprintf("subx.w -(A%d), -(A%d)", y(d.ir), x(d.ir))
  1918. }
  1919. func d68000_subx_mm_32(d *dasmInfo) string {
  1920. return fmt.Sprintf("subx.l -(A%d), -(A%d)", y(d.ir), x(d.ir))
  1921. }
  1922. func d68000_swap(d *dasmInfo) string {
  1923. return fmt.Sprintf("swap D%d", y(d.ir))
  1924. }
  1925. func d68000_tas(d *dasmInfo) string {
  1926. return fmt.Sprintf("tas %s", d.getEaModeStr(Byte))
  1927. }
  1928. func d68000_trap(d *dasmInfo) string {
  1929. return fmt.Sprintf("trap #$%x", d.ir&15)
  1930. }
  1931. func d68020_trapcc_0(d *dasmInfo) string {
  1932. return fmt.Sprintf("trap%-2s; (2+)", gCCTable[d.ir>>uint64(8)&15])
  1933. }
  1934. func d68020_trapcc_16(d *dasmInfo) string {
  1935. return fmt.Sprintf("trap%-2s %s; (2+)", gCCTable[d.ir>>uint64(8)&15], d.getImmStrUnsigned(Word))
  1936. }
  1937. func d68020_trapcc_32(d *dasmInfo) string {
  1938. return fmt.Sprintf("trap%-2s %s; (2+)", gCCTable[d.ir>>uint64(8)&15], d.getImmStrUnsigned(Long))
  1939. }
  1940. func d68000_trapv(d *dasmInfo) string {
  1941. return "trapv"
  1942. }
  1943. func d68000_tst_8(d *dasmInfo) string {
  1944. return fmt.Sprintf("tst.b %s", d.getEaModeStr(Byte))
  1945. }
  1946. func d68020_tst_pcdi_8(d *dasmInfo) string {
  1947. return fmt.Sprintf("tst.b %s; (2+)", d.getEaModeStr(Byte))
  1948. }
  1949. func d68020_tst_pcix_8(d *dasmInfo) string {
  1950. return fmt.Sprintf("tst.b %s; (2+)", d.getEaModeStr(Byte))
  1951. }
  1952. func d68020_tst_i_8(d *dasmInfo) string {
  1953. return fmt.Sprintf("tst.b %s; (2+)", d.getEaModeStr(Byte))
  1954. }
  1955. func d68000_tst_16(d *dasmInfo) string {
  1956. return fmt.Sprintf("tst.w %s", d.getEaModeStr(Word))
  1957. }
  1958. func d68020_tst_a_16(d *dasmInfo) string {
  1959. return fmt.Sprintf("tst.w %s; (2+)", d.getEaModeStr(Word))
  1960. }
  1961. func d68020_tst_pcdi_16(d *dasmInfo) string {
  1962. return fmt.Sprintf("tst.w %s; (2+)", d.getEaModeStr(Word))
  1963. }
  1964. func d68020_tst_pcix_16(d *dasmInfo) string {
  1965. return fmt.Sprintf("tst.w %s; (2+)", d.getEaModeStr(Word))
  1966. }
  1967. func d68020_tst_i_16(d *dasmInfo) string {
  1968. return fmt.Sprintf("tst.w %s; (2+)", d.getEaModeStr(Word))
  1969. }
  1970. func d68000_tst_32(d *dasmInfo) string {
  1971. return fmt.Sprintf("tst.l %s", d.getEaModeStr(Long))
  1972. }
  1973. func d68020_tst_a_32(d *dasmInfo) string {
  1974. return fmt.Sprintf("tst.l %s; (2+)", d.getEaModeStr(Long))
  1975. }
  1976. // d68020_tst_pcdi_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:3120
  1977. func d68020_tst_pcdi_32(d *dasmInfo) string {
  1978. return fmt.Sprintf("tst.l %s; (2+)", d.getEaModeStr(Long))
  1979. }
  1980. // d68020_tst_pcix_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:3126
  1981. func d68020_tst_pcix_32(d *dasmInfo) string {
  1982. return fmt.Sprintf("tst.l %s; (2+)", d.getEaModeStr(Long))
  1983. }
  1984. // d68020_tst_i_32 - transpiled function from /home/jens/projects/Musashi/m68kdasm.c:3132
  1985. func d68020_tst_i_32(d *dasmInfo) string {
  1986. return fmt.Sprintf("tst.l %s; (2+)", d.getEaModeStr(Long))
  1987. }
  1988. func d68000_unlk(d *dasmInfo) string {
  1989. return fmt.Sprintf("unlk A%d", y(d.ir))
  1990. }
  1991. func d68020_unpk_rr(d *dasmInfo) string {
  1992. return fmt.Sprintf("unpk D%d, D%d, %s; (2+)", y(d.ir), x(d.ir), d.getImmStrUnsigned(Word))
  1993. }
  1994. func d68020_unpk_mm(d *dasmInfo) string {
  1995. return fmt.Sprintf("unpk -(A%d), -(A%d), %s; (2+)", y(d.ir), x(d.ir), d.getImmStrUnsigned(Word))
  1996. }
  1997. func d68851_p000(d *dasmInfo) string {
  1998. modes := d.readImm(Word)
  1999. // PFLUSH: 001xxx0xxxxxxxxx
  2000. // PLOAD: 001000x0000xxxxx
  2001. // PVALID1: 0010100000000000
  2002. // PVALID2: 0010110000000xxx
  2003. // PMOVE 1: 010xxxx000000000
  2004. // PMOVE 2: 011xxxx0000xxx00
  2005. // PMOVE 3: 011xxxx000000000
  2006. // PTEST: 100xxxxxxxxxxxxx
  2007. // PFLUSHR: 1010000000000000
  2008. // do this after fetching the second PMOVE word so we properly get the 3rd if necessary
  2009. str := d.getEaModeStr(Long)
  2010. if modes&0xfde0 == 0x2000 {
  2011. if modes&200 != 0 {
  2012. // PLOAD
  2013. return fmt.Sprintf("pload #%d, %s", (modes>>10)&7, str)
  2014. }
  2015. return fmt.Sprintf("pload %s, #%d", str, (modes>>10)&7)
  2016. }
  2017. if modes&0xe200 == 0x2000 {
  2018. // PFLUSH
  2019. return fmt.Sprintf("pflushr %x, %x, %s", modes&31, (modes>>5)&15, str)
  2020. }
  2021. if modes == 0xa000 {
  2022. // PFLUSHR
  2023. return fmt.Sprintf("pflushr %s", str)
  2024. }
  2025. if modes == 0x2800 {
  2026. // PVALID (FORMAT 1)
  2027. return fmt.Sprintf("pvalid VAL, %s", str)
  2028. }
  2029. if modes&0xfff8 == 0x2c00 {
  2030. // PVALID (FORMAT 2)
  2031. return fmt.Sprintf("pvalid A%d, %s", modes&15, str)
  2032. }
  2033. if modes&0xe000 == 0x8000 {
  2034. // PTEST
  2035. return fmt.Sprintf("ptest #%d, %s", modes&31, str)
  2036. }
  2037. switch (modes >> 13) & 7 {
  2038. case 0, 2:
  2039. if modes&0x100 != 0 {
  2040. if modes&0x200 != 0 {
  2041. // MC68030/040 form with FD bit
  2042. // MC68881 form, FD never set
  2043. return fmt.Sprintf("pmovefd %s, %s", gMMURegs[(modes>>10)&7], str)
  2044. }
  2045. return fmt.Sprintf("pmovefd %s, %s", str, gMMURegs[(modes>>10)&7])
  2046. } else {
  2047. if modes&0x200 != 0 {
  2048. return fmt.Sprintf("pmove %s, %s", gMMURegs[modes>>uint64(10)&7], str)
  2049. }
  2050. return fmt.Sprintf("pmove %s, %s", str, gMMURegs[modes>>uint64(10)&7])
  2051. }
  2052. case 3:
  2053. if modes&512 != 0 {
  2054. // MC68030 to/from status reg
  2055. return fmt.Sprintf("pmove mmusr, %s", str)
  2056. }
  2057. return fmt.Sprintf("pmove %s, mmusr", str)
  2058. default:
  2059. return fmt.Sprintf("pmove [unknown form] %s", str)
  2060. }
  2061. }
  2062. func d68851_pbcc16(d *dasmInfo) string {
  2063. return fmt.Sprintf("pb%s %x", gMMUCond[d.ir&15], d.pc+int32(int16(d.readImm(Word))))
  2064. }
  2065. func d68851_pbcc32(d *dasmInfo) string {
  2066. return fmt.Sprintf("pb%s %x", gMMUCond[d.ir&15], d.pc+int32(d.readImm(Long)))
  2067. }
  2068. func d68851_pdbcc(d *dasmInfo) string {
  2069. return fmt.Sprintf("pb%s %x", gMMUCond[uint16(d.readImm(Word))&0x0f], d.pc+d.readImm(Word))
  2070. }
  2071. func d68851_p001(d *dasmInfo) string {
  2072. // PScc: 0000000000xxxxxx
  2073. return "MMU 001 group"
  2074. }
  2075. func compare_nof_true_bits(a uint16, b uint16) bool {
  2076. // Used by qsort
  2077. a = a&0xaaaa>>1 + a&0x5555
  2078. a = a&0xcccc>>2 + a&0x3333
  2079. a = a&0xf0f0>>4 + a&0x0f0f
  2080. a = a&0xff00>>8 + a&0x00ff
  2081. b = b&0xaaaa>>1 + b&0x5555
  2082. b = b&0xcccc>>2 + b&0x3333
  2083. b = b&0xf0f0>>4 + b&0x0f0f
  2084. b = b&0xff00>>8 + b&0x00ff
  2085. // reversed to get greatest to least sorting
  2086. return b-a <= 0
  2087. }
  2088. func init() {
  2089. // build the opcode handler jump table
  2090. sort.SliceStable(dasmOpcodeTable, func(i, j int) bool {
  2091. return compare_nof_true_bits(dasmOpcodeTable[i].mask, dasmOpcodeTable[j].mask)
  2092. })
  2093. for i := 0; i < 0x10000; i++ {
  2094. // default to illegal
  2095. dasmTable[i] = d68000_illegal
  2096. opcode := uint16(i)
  2097. // search through opcode info for a match
  2098. for _, ostruct := range dasmOpcodeTable {
  2099. if opcode&ostruct.mask == ostruct.match {
  2100. // match opcode mask and allowed ea modes
  2101. // Handle destination ea for move instructions
  2102. if validEA(opcode, ostruct.eaMask) {
  2103. dasmTable[i] = ostruct.dasmHandler
  2104. }
  2105. }
  2106. }
  2107. }
  2108. }
  2109. func Disassemble(cpuType Type, pc int32, bus AddressBus) (string, int32) {
  2110. d := &dasmInfo{pc: pc, helper: "", bus: bus}
  2111. d.ir = uint16(d.readImm(Word))
  2112. return dasmTable[d.ir](d), d.pc - pc
  2113. }
  2114. type Size struct {
  2115. size int32
  2116. align int32
  2117. mask uint32
  2118. bits uint32
  2119. msb uint32
  2120. fmt string
  2121. ext string
  2122. write func([]byte, int32)
  2123. read func([]byte) int32
  2124. }
  2125. var operands = []*Size{Byte, Word, Long}
  2126. // Byte is an M68K operand
  2127. var Byte = &Size{
  2128. size: 1,
  2129. align: 2,
  2130. mask: 0x000000ff,
  2131. bits: 8,
  2132. msb: 0x00000080,
  2133. fmt: "$%02x",
  2134. ext: ".b",
  2135. write: func(sclice []byte, value int32) {
  2136. sclice[0] = byte(value)
  2137. },
  2138. read: func(slice []byte) int32 {
  2139. return int32(slice[0])
  2140. },
  2141. }
  2142. // Word is an M68K operand type
  2143. var Word = &Size{
  2144. size: 2,
  2145. align: 2,
  2146. mask: 0x0000ffff,
  2147. bits: 16,
  2148. msb: 0x00008000,
  2149. fmt: "$%04x",
  2150. ext: ".w",
  2151. write: func(slice []byte, value int32) {
  2152. binary.BigEndian.PutUint16(slice, uint16(value))
  2153. },
  2154. read: func(slice []byte) int32 {
  2155. return int32(binary.BigEndian.Uint16(slice))
  2156. },
  2157. }
  2158. // Long is an M68K operand type
  2159. var Long = &Size{
  2160. size: 4,
  2161. align: 4,
  2162. mask: 0xffffffff,
  2163. bits: 32,
  2164. msb: 0x80000000,
  2165. fmt: "$%08x",
  2166. ext: ".b",
  2167. write: func(sclice []byte, value int32) {
  2168. binary.BigEndian.PutUint32(sclice, uint32(value))
  2169. },
  2170. read: func(slice []byte) int32 {
  2171. return int32(binary.BigEndian.Uint32(slice))
  2172. },
  2173. }
  2174. // IsNegative tests an operand of a specifc size if it is negative
  2175. func (s *Size) IsNegative(value int32) bool {
  2176. return s.msb&uint32(value) != 0
  2177. }
  2178. // HexString returns an unsingned hex string with leading zeroes
  2179. func (s *Size) HexString(value int32) string {
  2180. v := uint32(value) & s.mask
  2181. return fmt.Sprintf(s.fmt, v)
  2182. }
  2183. // SignedHexString returns a signed hex with leading zeroes (-$0001)
  2184. func (s *Size) SignedHexString(value int32) string {
  2185. if uint32(value) == s.msb {
  2186. return s.HexString(value)
  2187. } else if s.IsNegative(value) {
  2188. return "-" + s.HexString(-value)
  2189. }
  2190. return s.HexString(value)
  2191. }
  2192. func (s *Size) set(value int32, target *int32) {
  2193. result := (uint32(*target) & ^s.mask) | (uint32(value) & s.mask)
  2194. *target = int32(result)
  2195. }
  2196. func x(ir uint16) uint16 { return (ir >> 9) & 0x7 }
  2197. func y(ir uint16) uint16 { return ir & 0x7 }
  2198. func validEA(opcode, mask uint16) bool {
  2199. if mask == 0 {
  2200. return true
  2201. }
  2202. switch opcode & 0x3f {
  2203. case 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07:
  2204. return (mask & eaMaskDataRegister) != 0
  2205. case 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f:
  2206. return (mask & eaMaskAddressRegister) != 0
  2207. case 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17:
  2208. return (mask & eaMaskIndirect) != 0
  2209. case 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f:
  2210. return (mask & eaMaskPostIncrement) != 0
  2211. case 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27:
  2212. return (mask & eaMaskPreDecrement) != 0
  2213. case 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f:
  2214. return (mask & eaMaskDisplacement) != 0
  2215. case 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37:
  2216. return (mask & eaMaskIndex) != 0
  2217. case 0x38:
  2218. return (mask & eaMaskAbsoluteShort) != 0
  2219. case 0x39:
  2220. return (mask & eaMaskAbsoluteLong) != 0
  2221. case 0x3a:
  2222. return (mask & eaMaskPCDisplacement) != 0
  2223. case 0x3b:
  2224. return (mask & eaMaskPCIndex) != 0
  2225. case 0x3c:
  2226. return (mask & eaMaskImmediate) != 0
  2227. }
  2228. return false
  2229. }
  2230. // EA Masks
  2231. const (
  2232. eaMaskDataRegister = 0x0800
  2233. eaMaskAddressRegister = 0x0400
  2234. eaMaskIndirect = 0x0200
  2235. eaMaskPostIncrement = 0x0100
  2236. eaMaskPreDecrement = 0x0080
  2237. eaMaskDisplacement = 0x0040
  2238. eaMaskIndex = 0x0020
  2239. eaMaskAbsoluteShort = 0x0010
  2240. eaMaskAbsoluteLong = 0x0008
  2241. eaMaskImmediate = 0x0004
  2242. eaMaskPCDisplacement = 0x0002
  2243. eaMaskPCIndex = 0x0001
  2244. )
  2245. type Type int32