mkz80ins.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {
  2. Copyright (c) 2020 by Nikolay Nikolov
  3. Convert z80ins.dat to a set of .inc files for usage with
  4. the Free pascal compiler
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program mkz80ins;
  12. {$mode objfpc}{$H+}
  13. uses
  14. SysUtils,StrUtils;
  15. const
  16. Version = '1.0.0';
  17. HeaderStr = '{ don''t edit, this file is generated from z80ins.dat; to regenerate, run ''make insdat'' in the compiler directory }';
  18. type
  19. { TZ80InsDatOutputFiles }
  20. TZ80InsDatOutputFiles = class
  21. public
  22. OpFile: TextFile;
  23. NOpFile: TextFile;
  24. StdOpNames: TextFile;
  25. constructor Create;
  26. destructor Destroy;override;
  27. end;
  28. constructor TZ80InsDatOutputFiles.Create;
  29. begin
  30. AssignFile(OpFile,'z80op.inc');
  31. Rewrite(OpFile);
  32. Writeln(OpFile,HeaderStr);
  33. Writeln(OpFile,'(');
  34. AssignFile(NOpFile,'z80nop.inc');
  35. Rewrite(NOpFile);
  36. Writeln(NOpFile,HeaderStr);
  37. AssignFile(StdOpNames,'z80stdopnames.inc');
  38. Rewrite(StdOpNames);
  39. Writeln(StdOpNames,HeaderStr);
  40. Writeln(StdOpNames,'(');
  41. end;
  42. destructor TZ80InsDatOutputFiles.Destroy;
  43. begin
  44. CloseFile(OpFile);
  45. CloseFile(NOpFile);
  46. CloseFile(StdOpNames);
  47. inherited Destroy;
  48. end;
  49. var
  50. InsDatFile: TextFile;
  51. OutputFiles: TZ80InsDatOutputFiles=nil;
  52. S, op: string;
  53. FirstIns: Boolean=true;
  54. OpCount: Integer=0;
  55. begin
  56. writeln('FPC Z80 Instruction Table Converter Version ',Version);
  57. AssignFile(InsDatFile,'../z80/z80ins.dat');
  58. Reset(InsDatFile);
  59. try
  60. OutputFiles:=TZ80InsDatOutputFiles.Create;
  61. while not EoF(InsDatFile) do
  62. begin
  63. Readln(InsDatFile,S);
  64. S:=Trim(S);
  65. if AnsiStartsStr(';',S) then
  66. continue
  67. else if AnsiStartsStr('[',S) then
  68. begin
  69. op:=Copy(S,2,Length(S)-2);
  70. if not FirstIns then
  71. begin
  72. Writeln(OutputFiles.OpFile,',');
  73. Writeln(OutputFiles.StdOpNames,',');
  74. end;
  75. FirstIns:=False;
  76. Write(OutputFiles.OpFile,'A_'+op);
  77. Write(OutputFiles.StdOpNames,''''+LowerCase(op)+'''');
  78. end
  79. else if S<>'' then
  80. begin
  81. Inc(OpCount);
  82. end;
  83. end;
  84. Writeln(OutputFiles.OpFile,');');
  85. Writeln(OutputFiles.StdOpNames,');');
  86. Writeln(OutputFiles.NOpFile,OpCount,';');
  87. finally
  88. FreeAndNil(OutputFiles);
  89. CloseFile(InsDatFile);
  90. end;
  91. end.