Subversion Repositories Games.Carmageddon

Rev

Rev 18 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "drmem.h"
  2. #include "brender/brender.h"
  3. #include "errors.h"
  4. #include "harness/trace.h"
  5. #include <stdlib.h>
  6.  
  7. br_allocator gAllocator = { "Death Race", DRStdlibAllocate, DRStdlibFree, DRStdlibInquire, Claim4ByteAlignment };
  8. int gNon_fatal_allocation_errors = 0;
  9. char* gMem_names[247] = {
  10.     "",
  11.     "BR_MEMORY_SCRATCH",
  12.     "BR_MEMORY_PIXELMAP",
  13.     "BR_MEMORY_PIXELS",
  14.     "BR_MEMORY_VERTICES",
  15.     "BR_MEMORY_FACES",
  16.     "BR_MEMORY_GROUPS",
  17.     "BR_MEMORY_MODEL",
  18.     "BR_MEMORY_MATERIAL",
  19.     "BR_MEMORY_MATERIAL_INDEX",
  20.     "BR_MEMORY_ACTOR",
  21.     "BR_MEMORY_PREPARED_VERTICES",
  22.     "BR_MEMORY_PREPARED_FACES",
  23.     "BR_MEMORY_LIGHT",
  24.     "BR_MEMORY_CAMERA",
  25.     "BR_MEMORY_BOUNDS",
  26.     "BR_MEMORY_CLIP_PLANE",
  27.     "BR_MEMORY_STRING",
  28.     "BR_MEMORY_REGISTRY",
  29.     "BR_MEMORY_TRANSFORM",
  30.     "BR_MEMORY_RESOURCE_CLASS",
  31.     "BR_MEMORY_FILE",
  32.     "BR_MEMORY_ANCHOR",
  33.     "BR_MEMORY_POOL",
  34.     "BR_MEMORY_RENDER_MATERIAL",
  35.     "BR_MEMORY_DATAFILE",
  36.     "BR_MEMORY_IMAGE",
  37.     "BR_MEMORY_IMAGE_ARENA",
  38.     "BR_MEMORY_IMAGE_SECTIONS",
  39.     "BR_MEMORY_IMAGE_NAMES",
  40.     "BR_MEMORY_EXCEPTION_HANDLER",
  41.     "BR_MEMORY_RENDER_DATA",
  42.     "BR_MEMORY_TOKEN",
  43.     "BR_MEMORY_TOKEN_MAP",
  44.     "BR_MEMORY_OBJECT",
  45.     "BR_MEMORY_OBJECT_DATA",
  46.     "BR_MEMORY_DRIVER",
  47.     "BR_MEMORY_LEXER",
  48.     "BR_MEMORY_OBJECT_LIST",
  49.     "BR_MEMORY_OBJECT_LIST_ENTRY",
  50.     "BR_MEMORY_ENABLED_ACTORS",
  51.     "BR_MEMORY_FMT_RESULTS",
  52.     "BR_MEMORY_PREPARED_MODEL",
  53.     "BR_MEMORY_ORDER_TABLE",
  54.     "BR_MEMORY_TOKEN_VALUE",
  55.     "BR_MEMORY_TOKEN_TEMPLATE",
  56.     "",
  57.     "",
  58.     "",
  59.     "",
  60.     "",
  61.     "",
  62.     "",
  63.     "",
  64.     "",
  65.     "",
  66.     "",
  67.     "",
  68.     "",
  69.     "",
  70.     "",
  71.     "",
  72.     "",
  73.     "",
  74.     "",
  75.     "",
  76.     "",
  77.     "",
  78.     "",
  79.     "",
  80.     "",
  81.     "",
  82.     "",
  83.     "",
  84.     "",
  85.     "",
  86.     "",
  87.     "",
  88.     "",
  89.     "",
  90.     "",
  91.     "",
  92.     "",
  93.     "",
  94.     "",
  95.     "",
  96.     "",
  97.     "",
  98.     "",
  99.     "",
  100.     "",
  101.     "",
  102.     "",
  103.     "",
  104.     "",
  105.     "",
  106.     "",
  107.     "",
  108.     "",
  109.     "",
  110.     "",
  111.     "",
  112.     "",
  113.     "",
  114.     "",
  115.     "",
  116.     "",
  117.     "",
  118.     "",
  119.     "",
  120.     "",
  121.     "",
  122.     "",
  123.     "",
  124.     "",
  125.     "",
  126.     "",
  127.     "",
  128.     "",
  129.     "",
  130.     "",
  131.     "",
  132.     "",
  133.     "",
  134.     "",
  135.     "",
  136.     "",
  137.     "",
  138.     "",
  139.     "kMem_intf_pix_copy",
  140.     "kMem_intf_pal_copy",
  141.     "kMem_nodes_array",
  142.     "kMem_sections_array",
  143.     "kMem_key_names",
  144.     "kMem_columns_z",
  145.     "kMem_columns_x",
  146.     "kMem_non_car_list",
  147.     "kMem_simp_level",
  148.     "kMem_crush_data",
  149.     "kMem_crush_neighbours",
  150.     "kMem_temp_fs",
  151.     "kMem_error_pix_copy",
  152.     "kMem_error_pal_copy",
  153.     "kMem_flic_pal",
  154.     "kMem_flic_data",
  155.     "kMem_flic_data_2",
  156.     "kMem_queued_flic",
  157.     "kFlic_panel_pixels",
  158.     "kMem_translations",
  159.     "kMem_translations_text",
  160.     "kMem_cur_pal_pixels",
  161.     "kMem_render_pal_pixels",
  162.     "kMem_scratch_pal_pixels",
  163.     "kMem_shade_table_copy",
  164.     "kMem_rear_screen_pixels",
  165.     "kMem_rolling_letters",
  166.     "kMem_intf_copy_areas",
  167.     "kMem_strip_image",
  168.     "kMem_strip_image_perm",
  169.     "kMem_damage_clauses",
  170.     "kMem_undamaged_vertices",
  171.     "kMem_race_text_chunk",
  172.     "kMem_race_text_str",
  173.     "kMem_oppo_array",
  174.     "kMem_oppo_text_chunk",
  175.     "kMem_oppo_text_str",
  176.     "kMem_br_font",
  177.     "kMem_br_font_wid",
  178.     "kMem_br_font_enc",
  179.     "kMem_br_font_glyphs",
  180.     "kMem_oppo_car_spec",
  181.     "kMem_misc_string",
  182.     "kMem_mac_host_buffer_1",
  183.     "kMem_mac_host_buffer_2",
  184.     "kMem_mac_net_details",
  185.     "kMem_back_pixels",
  186.     "kMem_quit_vfy_pixels",
  187.     "kMem_quit_vfy_pal",
  188.     "kMem_net_min_messages",
  189.     "kMem_net_mid_messages",
  190.     "kMem_net_max_messages",
  191.     "kMem_net_pid_details",
  192.     "kMem_net_car_spec",
  193.     "kMem_dynamic_message",
  194.     "kMem_player_list_join",
  195.     "kMem_player_list_leave",
  196.     "kMem_oppo_new_nodes",
  197.     "kMem_oppo_new_sections",
  198.     "kMem_cop_car_spec",
  199.     "kMem_oppo_bit_per_node",
  200.     "kMem_ped_action_list",
  201.     "kMem_ped_sequences",
  202.     "kMem_ped_array_stain",
  203.     "kMem_ped_array",
  204.     "kMem_ped_instructions",
  205.     "kMem_ped_new_instruc",
  206.     "kMem_pipe_model_geometry",
  207.     "kMem_powerup_array",
  208.     "kMem_powerup_float_parms",
  209.     "kMem_powerup_int_parms",
  210.     "kMem_drugs_palette",
  211.     "kMem_pratcam_flic_array",
  212.     "kMem_pratcam_flic_data",
  213.     "kMem_pratcam_sequence_array",
  214.     "kMem_pratcam_pixelmap",
  215.     "kMem_video_pixels",
  216.     "kMem_funk_prox_array",
  217.     "kMem_new_mat_id",
  218.     "kMem_new_mat_id_2",
  219.     "kMem_new_mat_id_3",
  220.     "kMem_special_volume",
  221.     "kMem_special_screen",
  222.     "kMem_new_special_vol",
  223.     "kMem_saved_game",
  224.     "kMem_new_save_game",
  225.     "kMem_stor_space_pix",
  226.     "kMem_stor_space_tab",
  227.     "kMem_stor_space_mat",
  228.     "kMem_stor_space_mod",
  229.     "kMem_stor_space_save",
  230.     "kMem_funk_spec",
  231.     "kMem_groove_spec",
  232.     "kMem_non_car_spec",
  233.     "kMem_S3_scan_name",
  234.     "kMem_S3_sound_header",
  235.     "kMem_S3_sample",
  236.     "kMem_S3_mac_channel",
  237.     "kMem_S3_mac_path",
  238.     "kMem_S3_sentinel",
  239.     "kMem_S3_outlet",
  240.     "kMem_S3_channel",
  241.     "kMem_S3_descriptor",
  242.     "kMem_S3_reverse_buffer",
  243.     "kMem_S3_source",
  244.     "kMem_S3_DOS_SOS_channel",
  245.     "kMem_S3_PC_DOS_path",
  246.     "kMem_S3_DOS_SOS_patch",
  247.     "kMem_S3_DOS_SOS_song_structure",
  248.     "kMem_S3_DOS_SOS_song_data",
  249.     "kMem_S3_Windows_95_load_WAV_file",
  250.     "kMem_S3_Windows_95_create_temp_buffer_space_to_reverse_sample",
  251.     "kMem_S3_Windows_95_path",
  252.     "kMem_DOS_HMI_file_open",
  253.     "kMem_abuse_text",
  254.     "kMem_action_replay_buffer",
  255.     "kMem_misc",
  256.     NULL,
  257. };
  258. br_resource_class gStainless_classes[118];
  259.  
  260. // IDA: void __cdecl SetNonFatalAllocationErrors()
  261. void SetNonFatalAllocationErrors(void) {
  262.     LOG_TRACE("()");
  263.  
  264.     gNon_fatal_allocation_errors = 1;
  265. }
  266.  
  267. // IDA: void __cdecl ResetNonFatalAllocationErrors()
  268. void ResetNonFatalAllocationErrors(void) {
  269.     LOG_TRACE("()");
  270.  
  271.     gNon_fatal_allocation_errors = 0;
  272. }
  273.  
  274. // IDA: int __cdecl AllocationErrorsAreFatal()
  275. int AllocationErrorsAreFatal(void) {
  276.     return gNon_fatal_allocation_errors == 0;
  277. }
  278.  
  279. // IDA: void __cdecl MAMSInitMem()
  280. void MAMSInitMem(void) {
  281.     //int i; // Pierre-Marie Baty -- unused variable
  282.     //FILE* f; // Pierre-Marie Baty -- unused variable
  283.     //tPath_name the_path; // Pierre-Marie Baty -- unused variable
  284.     LOG_TRACE("()");
  285. }
  286.  
  287. // IDA: void __usercall PrintMemoryDump(int pFlags@<EAX>, char *pTitle@<EDX>)
  288. void PrintMemoryDump(int pFlags, char* pTitle) {
  289.     LOG_TRACE("(%d, \"%s\")", pFlags, pTitle);
  290. }
  291.  
  292. // IDA: void* __cdecl DRStdlibAllocate(br_size_t size, br_uint_8 type)
  293. void* DRStdlibAllocate(br_size_t size, br_uint_8 type) {
  294.     void* p;
  295.     //int i; // Pierre-Marie Baty -- unused variable
  296.     char s[256];
  297.  
  298.     if (size == 0) {
  299.         return NULL;
  300.     }
  301.     p = malloc(size);
  302.     if (p == NULL && !gNon_fatal_allocation_errors) {
  303.         PrintMemoryDump(0, "AT ERROR TIME");
  304.         sprintf(s, "%s/%d", gMem_names[type], (int)size);
  305.         FatalError(kFatalError_OOMCarmageddon_S, s);
  306.     }
  307.     return p;
  308. }
  309.  
  310. // IDA: void __cdecl DRStdlibFree(void *mem)
  311. void DRStdlibFree(void* mem) {
  312.     //int i; // Pierre-Marie Baty -- unused variable
  313.     free(mem);
  314. }
  315.  
  316. // IDA: br_size_t __cdecl DRStdlibInquire(br_uint_8 type)
  317. br_size_t DRStdlibInquire(br_uint_8 type) {
  318.     return 0;
  319. }
  320.  
  321. // IDA: br_uint_32 __cdecl Claim4ByteAlignment(br_uint_8 type)
  322. br_uint_32 Claim4ByteAlignment(br_uint_8 type) {
  323.     return 4;
  324. }
  325.  
  326. // IDA: void __cdecl InstallDRMemCalls()
  327. void InstallDRMemCalls(void) {
  328.     BrAllocatorSet(&gAllocator);
  329. }
  330.  
  331. // IDA: void __usercall MAMSUnlock(void **pPtr@<EAX>)
  332. void MAMSUnlock(void** pPtr) {
  333.     DRStdlibFree(*pPtr);
  334.     *pPtr = NULL;
  335. }
  336.  
  337. // IDA: void __usercall MAMSLock(void **pPtr@<EAX>)
  338. void MAMSLock(void** pPtr) {
  339.     LOG_TRACE("(%p)", pPtr);
  340. }
  341.  
  342. // IDA: void __cdecl CreateStainlessClasses()
  343. void CreateStainlessClasses(void) {
  344.     int i;
  345.  
  346.     for (i = 129; i < 246; i++) {
  347.         gStainless_classes[i - 129].res_class = i;
  348.         if (!BrResClassAdd(&gStainless_classes[i - 129])) {
  349.             FatalError(kFatalError_OOMCarmageddon_S, gStainless_classes[i - 129].identifier);
  350.         }
  351.     }
  352. }
  353.  
  354. // IDA: void __cdecl CheckMemory()
  355. void CheckMemory(void) {
  356. }
  357.