home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / general / asminc.cpp next >
Encoding:
C/C++ Source or Header  |  1993-06-27  |  7.0 KB  |  251 lines

  1. // ------------------------------------------------------------------
  2. // File:        ASMINC.CPP
  3. // Path:        ...\REHACK\GENERAL\ASMINC.CPP
  4. // Version:        0.01
  5. // Author:        Pat Reilly
  6. // CIS Id:        71333,2764
  7. // Created On:    6/26/93
  8. // Modified On:
  9. // Description: This program goes through the base classes for REHACK and
  10. //            prints (to STDOUT) an assembly .INC format which has the proper
  11. //            offsets to difference class members and constants. For instance,
  12. //            an equate is printed for the bool enum (see TYPES.HPP) like:
  13. //                bool         equ <N>
  14. //            where <N> is sizeof(bool). Also the Point class' members will
  15. //            have entries:
  16. //                PointX    equ  <X>
  17. //                PointY    equ  <Y>
  18. //            Whenever new classes are added, or existing ones modified, the
  19. //            class should have void makeInc() declared as a friend (so it can
  20. //            access protected members) and members and constants should be
  21. //            added to the makeInc() function so that they can be included in
  22. //            this output.
  23. //
  24. //            To use this program, just compile it, then execute it, using
  25. //            DOS' redirection to send the output to the file REHACK.INC.
  26. //                    asminc > rehack.inc
  27. //
  28. //            All REHACK assembly modules that require information from the
  29. //            rest of the classes should INCLUDE rehack.inc.
  30. //
  31. //            The member information is the offset to that member from a base
  32. //            address. For example; if you have a Point instance which has an
  33. //            address stored in DS:BX, then the offset to the 'x' member would
  34. //            be:
  35. //                    mov        [bx+PointX], 4
  36. //                    mov        [bx+PointY], 3
  37. //            This example will set the Point to (4,3).
  38. // Tabs:        4
  39. // ------------------------------------------------------------------
  40.  
  41.  
  42. #include "..\GENERAL\TYPES.HPP"
  43. #include "..\GENERAL\MISC.HPP"
  44. #include "..\EVENT\EVENT.HPP"
  45. #include "..\EVENT\EVENTQ.HPP"
  46. #include "..\WINDOW\WINDOW.HPP"
  47. #include <stdio.h>
  48. #include <stddef.h>
  49.  
  50. // This file creates an asm .INC file for REHACK. When building the program,
  51. //    this program should be executed so that the offsets within structures
  52. //    are correct for the asm files.
  53.  
  54.  
  55. // Function makeEquate
  56. //
  57. //        This function accepts a string name, and an unsigned value for its
  58. //    offset within a class/structure, and prints it to STDOUT (cout). Output
  59. //    format is:
  60. //            <name>       equ <ofs>
  61.  
  62. void makeEquate(const char* name, unsigned ofs)
  63. {
  64.     printf("%-30s equ %u\n", name, ofs);
  65. }
  66.  
  67. // Function makeEquateStr
  68. //
  69. //        This function accepts 2 strings and prints them as an equate:
  70. //            <name>      equ <str>
  71.  
  72. void makeEquateStr(const char* name, const char* str)
  73. {
  74.     printf("%-30s equ %-s\n", name, str);
  75. }
  76.  
  77. // Function makeCommentStr
  78. //
  79. //        This function accepts a string and prints it as a comment:
  80. //            ; <str>
  81.  
  82. void makeCommentStr(const char* str)
  83. {
  84.     printf("; %s\n", str);
  85. }
  86.  
  87. // Function makeSpace
  88. //
  89. //        This function prints a newline.
  90.  
  91. void makeSpace()
  92. {
  93.     printf("\n");
  94. }
  95.  
  96. // Function makeHeader
  97. //    Prints a standard REHACK header.
  98.  
  99. void makeHeader()
  100. {
  101.     printf("; File:        REHACK.INC\n");
  102.     printf("; Path:        ..\\GENERAL\\REHACK.INC\n");
  103.     printf("; Version:     0.01\n");
  104.     printf("; Author:      Generated by ASMINC.EXE\n");
  105.     printf("; CIS Id:      Not applicable\n");
  106.     printf("; Created on:  " __DATE__ "\n");
  107.     printf("; Modified on:\n");
  108.     printf("; Description: INCLUDE file for all .ASM modules\n");
  109.     printf("; Tabs:        None.\n");
  110. }
  111.  
  112. // Macro makeMember
  113. //    Takes a Name (should NOT be enclosed in quotes), a class, and a member of
  114. //    that class and calls makeEquate to print an equate that equates the offset
  115. //    to that member to Name.
  116.  
  117. #define makeMember(Name, Class, Member)    makeEquate(#Name, offsetof(Class, Member))
  118.  
  119. // Macro makeConstant
  120. //    Takes a Name (should NOT be enclosed in quotes) and calls makeEquate to
  121. //    equate the constant's value to its name.
  122.  
  123. #define makeConstant(Name) makeEquate(#Name, Name)
  124.  
  125. // Macro makeComment
  126. //    Takes a Str (should NOT be enclosed in quotes) and calls makeCommentStr
  127. //    to print it out as a comment.
  128.  
  129. #define makeComment(Str) makeCommentStr(#Str)
  130.  
  131. // Function makeInc
  132. //
  133. //        This function prints a list of equates, comments and newlines for
  134. //    inclusion in REHACK .asm files.
  135.  
  136. void makeInc()
  137. {
  138.     // Print REHACK header.
  139.     makeHeader();
  140.  
  141.     // TYPES.HPP
  142.     makeSpace();
  143.     makeComment(TYPES.HPP);
  144.     makeSpace();
  145.  
  146.     makeEquateStr("bool", (sizeof(bool) == sizeof(char)) ? "DB" : "DW");
  147.     makeConstant(false);
  148.     makeConstant(true);
  149.  
  150.     // MISC.HPP
  151.     makeSpace();
  152.     makeComment(MISC.HPP);
  153.     makeSpace();
  154.  
  155.     makeMember(PointX, Point, x);
  156.     makeMember(PointY, Point, y);
  157.  
  158.     makeMember(RectTopLeftX, Rect, topLeft.x);
  159.     makeMember(RectTopLeftY, Rect, topLeft.y);
  160.     makeMember(RectBottomRightX, Rect, bottomRight.x);
  161.     makeMember(RectBottomRightY, Rect, bottomRight.y);
  162.  
  163.     // EVENT.HPP
  164.     makeSpace();
  165.     makeComment(EVENT.HPP);
  166.     makeSpace();
  167.  
  168.     makeConstant(LeftBtn);
  169.     makeConstant(RightBtn);
  170.     makeConstant(CenterBtn);
  171.  
  172.     makeMember(PosDeviceEventButtons, PosDeviceEvent, buttons);
  173.     makeMember(PosDeviceEventDblClicked, PosDeviceEvent, dblClicked);
  174.     makeMember(PosDeviceEventLocation, PosDeviceEvent, location);
  175.  
  176.     makeMember(KeyCodeCode, KeyCode, code);
  177.     makeMember(KeyCodeScan, KeyCode, scan);
  178.  
  179.     makeMember(KeyEventValue, KeyEvent, value);
  180.     makeMember(KeyEventCharScan, KeyEvent, charScanValue);
  181.  
  182.     makeMember(MsgEventId, MsgEvent, id);
  183.     makeMember(MsgEventPointer, MsgEvent, pointerValue);
  184.     makeMember(MsgEventLong, MsgEvent, longValue);
  185.     makeMember(MsgEventShort, MsgEvent, shortValue);
  186.     makeMember(MsgEventPoint, MsgEvent, pointValue);
  187.  
  188.     makeConstant(IdNull);
  189.     makeConstant(IdCancel);
  190.     makeConstant(IdQuit);
  191.  
  192.     makeConstant(PosDeviceBtnDown);
  193.     makeConstant(PosDeviceBtnUp);
  194.     makeConstant(PosDeviceMove);
  195.     makeConstant(PosDevice);
  196.     makeConstant(KeyDown);
  197.     makeConstant(KeyUp);
  198.     makeConstant(Key);
  199.     makeConstant(Broadcast);
  200.     makeConstant(Message);
  201.  
  202.     makeMember(EventType, Event, type);
  203.     makeMember(EventTicks, Event, ticks);
  204.     makeMember(EventPosDevice, Event, posDevice);
  205.     makeMember(EventKey, Event, key);
  206.     makeMember(EventMsg, Event, msg);
  207.  
  208.     // EVENTQ.HPP
  209.     makeSpace();
  210.     makeComment(EVENTQ.HPP);
  211.     makeSpace();
  212.  
  213.     makeConstant(StdEventQueueSize);
  214.  
  215.     makeMember(EventQueueBuffer, EventQueue, buffer);
  216.     makeMember(EventQueueHead, EventQueue, head);
  217.     makeMember(EventQueueTail, EventQueue, tail);
  218.  
  219.     // WINDOW\WINDOW.HPP
  220.     makeSpace();
  221.     makeComment(WINDOW.HPP);
  222.     makeSpace();
  223.  
  224.     makeConstant(vfVisible);
  225.     makeConstant(vfFocused);
  226.     makeConstant(vfDisabled);
  227.     makeConstant(vfModal);
  228.     makeConstant(vfFocusable);
  229.     makeConstant(vfPassFirstClick);
  230.  
  231.     makeMember(VisibleBounds, Visible, bounds);
  232.     makeMember(VisibleFlags, Visible, flags);
  233.     makeMember(VisibleOwner, Visible, owner);
  234.     makeMember(VisibleNext, Visible, next);
  235.     makeMember(VisibleModalReturnValue, Visible, modalReturnValue);
  236.  
  237.     makeMember(WindowBottomObj, Window, bottomObject);
  238.     makeMember(WindowCurrentObj, Window, currentObject);
  239.  
  240.     // GAME\GAME.HPP
  241.     makeSpace();
  242.     makeComment(GAME.HPP);
  243.     makeSpace();
  244. }
  245.  
  246. int main()
  247. {
  248.     makeInc();
  249.     return 0;
  250. }
  251.