nmos6502inl.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. {
  2. Copyright (c) 2020 by Sven Barth
  3. Generates MOS Technology 6502 inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nmos6502inl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl, aasmbase;
  22. type
  23. TMOS6502InlineNode = class(tcginlinenode)
  24. // function pass_typecheck_cpu:tnode;override;
  25. // function first_cpu : tnode;override;
  26. // procedure pass_generate_code_cpu;override;
  27. end;
  28. implementation
  29. uses
  30. compinnr,
  31. aasmdata,
  32. aasmcpu,
  33. symdef,
  34. defutil,
  35. hlcgobj,
  36. pass_2,
  37. ncal,
  38. cgbase, cgobj, cgutils,
  39. cpubase;
  40. // function TMOS6502InlineNode.pass_typecheck_cpu : tnode;
  41. // begin
  42. // Result:=nil;
  43. // case inlinenumber of
  44. // in_z80_inport:
  45. // begin
  46. // CheckParameters(1);
  47. // resultdef:=u8inttype;
  48. // end;
  49. // in_z80_outport:
  50. // begin
  51. // CheckParameters(2);
  52. // resultdef:=voidtype;
  53. // end;
  54. // else
  55. // Result:=inherited pass_typecheck_cpu;
  56. // end;
  57. // end;
  58. // function TMOS6502InlineNode.first_cpu : tnode;
  59. // begin
  60. // Result:=nil;
  61. // case inlinenumber of
  62. // in_z80_inport:
  63. // expectloc:=LOC_REGISTER;
  64. // in_z80_outport:
  65. // expectloc:=LOC_VOID;
  66. // else
  67. // Result:=inherited first_cpu;
  68. // end;
  69. // end;
  70. // procedure TMOS6502InlineNode.pass_generate_code_cpu;
  71. //
  72. // procedure inport;
  73. // var
  74. // portnumber : tnode;
  75. // dreg : tregister;
  76. // ref : treference;
  77. // begin
  78. // portnumber:=left;
  79. // secondpass(portnumber);
  80. // if (portnumber.location.loc=LOC_CONSTANT) and
  81. // (portnumber.location.value>=0) and
  82. // (portnumber.location.value<=$ff) then
  83. // begin
  84. // { data needs to be put into A }
  85. // dreg:=NR_A;
  86. // reference_reset_base(ref,NR_NO,portnumber.location.value,ctempposinvalid,1,[]);
  87. // current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_IN,dreg,ref));
  88. // end
  89. // else
  90. // begin
  91. // { data can be put anywhere, but port number must be in C }
  92. // hlcg.getcpuregister(current_asmdata.CurrAsmList,NR_C);
  93. // dreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_8);
  94. // hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portnumber.resultdef,u8inttype,portnumber.location,NR_C);
  95. // reference_reset_base(ref,NR_C,0,ctempposinvalid,1,[]);
  96. // current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_IN,dreg,ref));
  97. // hlcg.ungetcpuregister(current_asmdata.CurrAsmList,NR_C);
  98. // end;
  99. // location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  100. // location.register:=dreg;
  101. // end;
  102. //
  103. // procedure outport;
  104. // var
  105. // portnumber,
  106. // portdata : tnode;
  107. // dreg : tregister;
  108. // ref : treference;
  109. // begin
  110. // portnumber:=tcallparanode(tcallparanode(left).right).left;
  111. // portdata:=tcallparanode(left).left;
  112. // secondpass(portdata);
  113. // secondpass(portnumber);
  114. // if (portnumber.location.loc=LOC_CONSTANT) and
  115. // (portnumber.location.value>=0) and
  116. // (portnumber.location.value<=$ff) then
  117. // begin
  118. // { data needs to reside in A }
  119. // dreg:=NR_A;
  120. // hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portdata.resultdef,u8inttype,portdata.location,dreg);
  121. // hlcg.getcpuregister(current_asmdata.CurrAsmList,dreg);
  122. // reference_reset_base(ref,NR_NO,portnumber.location.value,ctempposinvalid,1,[]);
  123. // current_asmdata.currasmlist.concat(taicpu.op_ref_reg(A_OUT,ref,dreg));
  124. // hlcg.ungetcpuregister(current_asmdata.CurrAsmList,dreg);
  125. // end
  126. // else
  127. // begin
  128. // { data can reside anywhere, but port number must be in C }
  129. // hlcg.getcpuregister(current_asmdata.CurrAsmList,NR_C);
  130. // dreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_8);
  131. // hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portdata.resultdef,u8inttype,portdata.location,dreg);
  132. // hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portnumber.resultdef,u8inttype,portnumber.location,NR_C);
  133. // reference_reset_base(ref,NR_C,0,ctempposinvalid,1,[]);
  134. // current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_OUT,ref,dreg));
  135. // hlcg.ungetcpuregister(current_asmdata.CurrAsmList,NR_C);
  136. // end;
  137. // end;
  138. //
  139. // begin
  140. // case inlinenumber of
  141. // in_z80_inport:
  142. // inport;
  143. // in_z80_outport:
  144. // outport;
  145. // else
  146. // inherited pass_generate_code_cpu;
  147. // end;
  148. // end;
  149. begin
  150. cinlinenode:=TMOS6502InlineNode;
  151. end.