This is a really brain-dead script to brute-force convert M6800 source code to non-optimal M6809 source code, without any optimization.

Format
Perl
Post date
2018-09-17 19:56
Zeitraum der Veröffentlichung
Unbegrenzt
  1. #!/usr/bin/env perl
  2. # Script to convert M6800 source code to non-optimal M6809 source code.
  3. # By Joel Matthew Rees, Amagasaki, Japan, September 2018.
  4. # Copyright 2018 Joel Matthew Rees
  5. #
  6. # Permission to use current version for personal research, entertainment,
  7. # and other non-commercial purposes hereby granted,
  8. # on condition that authorship and copyright notice are left intact.
  9. # For other uses, contact the author on social media.
  10. use v5.010.000;
  11. use warnings;
  12. use strict;
  13. # print $ARGV[ 1 ];
  14. # Including stuff we don't need, in case I get ambitious.
  15. # Not including 6801 at this point.
  16. # Branches are completely unchanged going from 6800 to 6809:
  17. my $branchlist = "BCC|BCS|BEQ|BGE|BGT|BHI|BLE|BLS|BLT|BMI|BNE|BPL|BRA|BVC|BVS";
  18. # These implicit ops are unchanged from 6800 to 6809:
  19. my $implist = "DAA|NOP|RTS";
  20. # 16-bit pseudo-binary, unchanged from 6800 to 6809:
  21. my $jumplist ="JMP|JSR";
  22. # 8-bit binary ops are unchanged going from 6800 to 6809,
  23. # but we'll eliminate optional space for sociability:
  24. my $binop8list = "ADC|ADD|AND|BIT|CMP|EOR|SBC|SUB";
  25. # 8-bit unary ops are unchanged going from 6800to 6809,
  26. # but we'll eliminate optional space for sociability:
  27. my $unoplist = "ASL|ASR|CLR|COM|DEC|INC|LSR|LSL|NEG|ROL|ROR|TST";
  28. # These binary 8-bits have one too many As from 6800 to 6809:
  29. my $binopLDORST8list = "LDA|ORA|STA";
  30. # These loads and stores are unchanged from 6800 to 6809,
  31. # except for optional space:
  32. my $binopLDST16list = "LDS|LDX|STS|STX";
  33. # Form changes to CMPX
  34. my $binop16list = "CPX";
  35. # Push and pop (pull) are generalized:
  36. # (6800 had no pshx! -- But fixed in 6801.)
  37. my $pushmepullyoulist = "PSH|PUL";
  38. # Transfers are generalized:
  39. my $transferlist = "TAB|TAP|TBA|TPA|TSX|TXS";
  40. # These convert to LEA instructions:
  41. my $lealist = "DES|DEX|INS|INX";
  42. # Processor status bit handling is generalized:
  43. # my $flaghandlerlist = "CLC|CLI|CLV|SEC|SEI|SEV";
  44. my $flaghandleroplist = "CL|SE";
  45. my $flaghandlerbitlist = "[CIV]";
  46. # Special handling for inter-accumulator:
  47. my $b2alist = "ABA|CBA|SBA";
  48. # Interrupt stuff, form remains the same, different register set,
  49. # flag working on by hand:
  50. my $interruptstufflist = "RTI|SWI";
  51. # Interrupt wait, form changes, semantics change,
  52. # flag for working on by hand:
  53. my $waitstufflist = "WAI";
  54. while ( my $line = <> )
  55. {
  56. if ( $line =~ m/^(\w*)\s+FCC\s+(\d+),(.*)$/ )
  57. {
  58. my $label = $1;
  59. my $symlength = $2;
  60. my $strfield = $3;
  61. my $symbol = substr( $strfield, 0, $symlength );
  62. my $leftovers = substr( $strfield, $symlength );
  63. my $strlength = length( $symbol );
  64. if ( $strlength < $symlength )
  65. {
  66. print "$label\tFCC error\t'$symbol' not complete to "
  67. . "$symlength characters (only $strlength). ****error***";
  68. }
  69. else
  70. {
  71. my $fullsymbol = $symbol;
  72. if ( $leftovers =~ m/^(\S+)(.*)$/ )
  73. {
  74. $fullsymbol .= $1;
  75. $leftovers = $2;
  76. }
  77. print "$label\tFCC\t'$symbol'\t; '$fullsymbol'";
  78. }
  79. if ( length( $leftovers ) > 0 )
  80. {
  81. print " : $leftovers";
  82. }
  83. print "\n";
  84. }
  85. elsif ( $line =~ m/^(\w*)\s+(${pushmepullyoulist})\s*(A|B)\s*(.*)$/ )
  86. {
  87. my $label = $1;
  88. my $operator = $2;
  89. my $operand = $3;
  90. my $comments = $4;
  91. print "$label\t${operator}S $operand\t; $comments\n";
  92. }
  93. elsif ( $line =~ m/^(\w*)\s+(${binopLDORST8list})\s*(A|B)\s+(.*)$/ )
  94. {
  95. my $label = $1;
  96. my $operator = $2;
  97. my $operand = $3;
  98. my $comments = $4; # Fudging, comments includes memory operand.
  99. my $op2letter = substr( $operator, 0, 2 );
  100. print "$label\t${op2letter}$operand $comments\n";
  101. }
  102. elsif ( $line =~ m/^(\w*)\s+(${lealist})(.*)$/ )
  103. {
  104. my $label = $1;
  105. my $operator = $2;
  106. my $comments = $3;
  107. if ( $operator =~ m/IN(\w)/ )
  108. { $operator = "LEA$1 1,$1";
  109. }
  110. elsif ( $operator =~ m/DE(\w)/ )
  111. { $operator = "LEA$1 -1,$1";
  112. }
  113. print "$label\t${operator}\t; $comments\n";
  114. }
  115. elsif ( $line =~ m/^(\w*)\s+(${unoplist})\s*(A|B)(.*)$/ )
  116. {
  117. my $label = $1;
  118. my $operator = $2;
  119. my $operand = $3;
  120. my $comments = $4;
  121. print "$label\t$operator$operand\t;$comments\n";
  122. }
  123. elsif ( $line =~ m/^(\w*)\s+(${unoplist})\s+(.*)$/ )
  124. {
  125. my $label = $1;
  126. my $operator = $2;
  127. my $operand = $3; # Fudging, operand includes any comments.
  128. print "$label\t$operator $operand\n";
  129. }
  130. elsif ( $line =~ m/^(\w*)\s+(${b2alist})(.*)$/ )
  131. {
  132. my $label = $1;
  133. my $operator = $2;
  134. my $comments = $3;
  135. my $realoperator = $operator;
  136. print "$label\tPSHS B\t; ** emulating $operator:\n";
  137. if ( $operator eq "ABA" )
  138. { $realoperator = "ADDA";
  139. }
  140. elsif ( $operator eq "CBA" )
  141. { $realoperator = "CMPA";
  142. }
  143. elsif ( $operator eq "SBA" )
  144. { $realoperator = "SUBA";
  145. }
  146. print "\t$realoperator ,S+\t; $comments\n";
  147. }
  148. elsif ( $line =~ m/^(\w*)\s+(${binop8list})\s*(A|B)\s+(.+)$/ )
  149. {
  150. my $label = $1;
  151. my $operator = $2;
  152. my $operand = $3;
  153. my $comments = $4; # Fudging, comments includes memory operand.
  154. print "$label\t${operator}$operand $comments\n";
  155. }
  156. elsif ( $line =~ m/^(\w*)\s+(${transferlist})(.*)$/ )
  157. {
  158. my $label = $1;
  159. my $operator = $2;
  160. my $comments = $3;
  161. my $source = substr( $operator, 1, 1 );
  162. my $destination = substr( $operator, 2, 1 );
  163. if ( $source eq "P" )
  164. { $source = "CCR";
  165. }
  166. if ( $destination eq "P" )
  167. { $destination = "CCR";
  168. }
  169. print "$label\tTFR $source,$destination\t; $operator : $comments\n";
  170. }
  171. elsif ( $line =~ m/^(\w*)\s+(${flaghandleroplist})($flaghandlerbitlist)(.*)$/ )
  172. { # Bits: EFHINZVC, thus I is 0x10, V is 0x02, and C is 0x01.
  173. my $label = $1;
  174. my $operator = $2;
  175. my $bit = $3;
  176. my $comments = $4;
  177. my $realbits =
  178. ( $bit eq "C" )
  179. ? "\$01"
  180. : ( $bit eq "V" )
  181. ? "\$02"
  182. : ( $bit eq "I" )
  183. ? "\$10"
  184. : $bit;
  185. my $realoperator = $operator;
  186. if ( $operator eq "CL" )
  187. { $realoperator = "ANDCC";
  188. $realbits = "~" . $realbits;
  189. }
  190. elsif ( $operator eq "SE" )
  191. { $realoperator = "ORCC"
  192. }
  193. print "$label\t$realoperator #$realbits\t; ${operator}${bit} : $comments\n";
  194. }
  195. elsif ( $line =~ m/^(\w*)\s+($binop16list)\s+(.+)$/ )
  196. {
  197. my $label = $1;
  198. my $operator = $2;
  199. my $operand = $3; # Fudging, operand includes any comments.
  200. my $reg16bit = substr( $operator, 2, 1 );
  201. print "$label\tCMP$reg16bit\t$operand\n";
  202. }
  203. elsif ( $line =~ m/^(\w*)\s+(${branchlist})\s+(\*[+-]\$?[0-9A-Fa-f]+)(.*)$/ )
  204. {
  205. my $label = $1;
  206. my $operator = $2;
  207. my $operand = $3;
  208. my $comments = $4;
  209. print "$label\t$operator $operand\t; $comments\n"
  210. . "\t****WARNING**** HARD OFFSET: $operand ****\n";
  211. }
  212. elsif ( $line =~ m/^(\w*)\s+(${interruptstufflist})(.*)$/ )
  213. {
  214. my $label = $1;
  215. my $operator = $2;
  216. my $operand = $3; # Fudging, operand includes any comments.
  217. print "$label\t$operator$operand\n"
  218. . "\t****WARNING**** Interrupt routines must change!! ****\n";
  219. }
  220. elsif ( $line =~ m/^(\w*)\s+(${waitstufflist})(.*)$/ )
  221. {
  222. my $label = $1;
  223. my $operator = $2;
  224. my $operand = $3; # Fudging, operand includes any comments.
  225. print "$label\tC$operator #\$EF\t; $operand\n"
  226. . "\t****WARNING**** WAI must change to CWAI!! ****\n";
  227. }
  228. else
  229. {
  230. print $line;
  231. }
  232. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text