BIO2 refactor (#24) - [merged] #105

Closed
opened 2019-10-12 11:44:40 +03:00 by icex2 · 26 comments
icex2 commented 2019-10-12 11:44:40 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 10:44

Merges bio2-refactor -> master

Refactor the BIO2 code so that it can be used for additional games, see: iidxhook8 for example usage.

Specifically it addresses how other games (not IIDX) retrieve the port BIO2(VIDEO)(COM#) from device name instead of registry entry, and allows multiple ports to be opened (for DRS).

In GitLab by @xyen on Oct 12, 2019, 10:44 _Merges bio2-refactor -> master_ Refactor the BIO2 code so that it can be used for additional games, see: iidxhook8 for example usage. Specifically it addresses how other games (not IIDX) retrieve the port `BIO2(VIDEO)(COM#)` from device name instead of registry entry, and allows multiple ports to be opened (for DRS).
icex2 commented 2019-10-12 12:28:38 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 11:28

added 1 commit

  • 77211132 - bio2emu: Add missing CM hooks for device index retrieval

Compare with previous version

In GitLab by @xyen on Oct 12, 2019, 11:28 added 1 commit <ul><li>77211132 - bio2emu: Add missing CM hooks for device index retrieval</li></ul> [Compare with previous version](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1049&start_sha=a492cee93e58da01189e767c15920238c46f17af)
icex2 commented 2019-10-12 12:37:58 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 11:37

added 1 commit

  • b6216c69 - bio2emu: Add missing CM hooks for device index retrieval

Compare with previous version

In GitLab by @xyen on Oct 12, 2019, 11:37 added 1 commit <ul><li>b6216c69 - bio2emu: Add missing CM hooks for device index retrieval</li></ul> [Compare with previous version](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1050&start_sha=7721113208ba5a969d1657e30a88ab1ddf90a7b6)
icex2 commented 2019-10-12 20:03:16 +03:00 (Migrated from github.com)

Nit: Empty line between control block and other control blocks or lines.

Nit: Empty line between control block and other control blocks or lines.
icex2 commented 2019-10-12 20:03:24 +03:00 (Migrated from github.com)

Nit: Empty line between control block and other control blocks or lines.

Nit: Empty line between control block and other control blocks or lines.
icex2 commented 2019-10-12 20:05:42 +03:00 (Migrated from github.com)

Have all static (const) vars at the top of the file. Feel free to create multiple blocks with them to introduce grouping for stuff that kinda belongs together.

Have all static (const) vars at the top of the file. Feel free to create multiple blocks with them to introduce grouping for stuff that kinda belongs together.
icex2 commented 2019-10-12 20:15:21 +03:00 (Migrated from github.com)

I see the point for this start init, do some other init, end init block thing. However, I suggest merging them to a single call to avoid such state machines requiring a specific order (feels like a D3D API with BeginScene ... EndScene).
Suggestion (Note: not tested nor compiled, just a draft):

void bio2emu_port_init(struct bio2emu_port** bio2_emu, size_t num_bio2_emu)
{
    array_init(&bio2_active_ports);

    // BIO2 seems like ACIO with just 1 device
    ac_io_emu_init(&bio2_emu->acio, bio2_emu->wport);
    rs232_hook_add_fd(bio2_emu->acio.fd);

    for (int i = 0; i < num_bio2_emu; i++) {
        *array_append(struct bio2emu_port*, &bio2_active_ports) = bio2_emu[i];
    }

    bio2emu_setupapi_hook_init(&bio2_active_ports);
}

iohook is doing something similar with a list of IO hooks to insert on init.

I see the point for this start init, do some other init, end init block thing. However, I suggest merging them to a single call to avoid such state machines requiring a specific order (feels like a D3D API with BeginScene ... EndScene). Suggestion (Note: not tested nor compiled, just a draft): ``` void bio2emu_port_init(struct bio2emu_port** bio2_emu, size_t num_bio2_emu) { array_init(&bio2_active_ports); // BIO2 seems like ACIO with just 1 device ac_io_emu_init(&bio2_emu->acio, bio2_emu->wport); rs232_hook_add_fd(bio2_emu->acio.fd); for (int i = 0; i < num_bio2_emu; i++) { *array_append(struct bio2emu_port*, &bio2_active_ports) = bio2_emu[i]; } bio2emu_setupapi_hook_init(&bio2_active_ports); } ``` iohook is doing something similar with a list of IO hooks to insert on init.
icex2 commented 2019-10-12 20:16:59 +03:00 (Migrated from github.com)

Please fix the naming with proper namespacing: iidxhook8_bi2a_light
Also consider all structs above this one.

Please fix the naming with proper namespacing: iidxhook8_bi2a_light Also consider all structs above this one.
icex2 commented 2019-10-12 20:18:18 +03:00 (Migrated from github.com)

That's good to have. We should use this more often, especially on packed structs.

That's good to have. We should use this more often, especially on packed structs.
icex2 commented 2019-10-12 20:18:42 +03:00 (Migrated from github.com)

Forward declaration?

Forward declaration?
icex2 commented 2019-10-12 20:19:17 +03:00 (Migrated from github.com)

Good comment to have.

Good comment to have.
icex2 commented 2019-10-12 20:21:12 +03:00 (Migrated from github.com)

Please use the PR template as it provides good guidance for providing information on what needs to be done (also as checkboxes).

Please use the PR template as it provides good guidance for providing information on what needs to be done (also as checkboxes).
icex2 commented 2019-10-12 20:49:03 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 19:49

Commented on src/main/iidxhook8/dllmain.c line 152

I prefer not to do it like this, the purpose of having it split up like this is to allow the end user to do something like this:

bio2emu_init_start();
drs_bi2a_main_init(&bio2_emu1, iidxhook8_config_io.disable_poll_limiter);
drs_bi2a_lighting_init(&bio2_emu2);
bio2emu_init_end();
In GitLab by @xyen on Oct 12, 2019, 19:49 Commented on [src/main/iidxhook8/dllmain.c line 152](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-2652fef86a3a811b7b9013de2364403dR152) I prefer not to do it like this, the purpose of having it split up like this is to allow the end user to do something like this: ```cpp bio2emu_init_start(); drs_bi2a_main_init(&bio2_emu1, iidxhook8_config_io.disable_poll_limiter); drs_bi2a_lighting_init(&bio2_emu2); bio2emu_init_end(); ```
icex2 commented 2019-10-12 20:55:33 +03:00 (Migrated from github.com)

Ok, I see. Then, I would still just unwrap the setupapi call in bio2emu_init_end as it doesn't really do anything else. It makes it more clear when you can read it explicitly that you have to do the setupapi hook call at the end. Also, do you really have to do it at the end? I mean, does the order matter for the setupapi hook call?

Ok, I see. Then, I would still just unwrap the setupapi call in bio2emu_init_end as it doesn't really do anything else. It makes it more clear when you can read it explicitly that you have to do the setupapi hook call at the end. Also, do you really have to do it at the end? I mean, does the order matter for the setupapi hook call?
icex2 commented 2019-10-12 21:00:29 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:00

Commented on src/main/iidxhook8/dllmain.c line 152

Technically, as soon as you hook setupapi, the array could potentially be used, and I'd prefer not to have to deal with locks inside of IO code. I suppose though at this point in init, the IO thread doesn't even exist yet, so it should be safe to move the setupapi call earlier.

In GitLab by @xyen on Oct 12, 2019, 20:00 Commented on [src/main/iidxhook8/dllmain.c line 152](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-2652fef86a3a811b7b9013de2364403dR152) Technically, as soon as you hook setupapi, the array could potentially be used, and I'd prefer not to have to deal with locks inside of IO code. I suppose though at this point in init, the IO thread doesn't even exist yet, so it should be safe to move the setupapi call earlier.
icex2 commented 2019-10-12 21:02:51 +03:00 (Migrated from github.com)

You want to keep this calls close together for sure. However, the hook bootstrap has to ensure this code gets executed as early as possible to avoid such issues. I just want us to avoid introducing dependencies like call orders that are not required. Because when I look at your start-end block, I got the impression that end must always be at the end.

You want to keep this calls close together for sure. However, the hook bootstrap has to ensure this code gets executed as early as possible to avoid such issues. I just want us to avoid introducing dependencies like call orders that are not required. Because when I look at your start-end block, I got the impression that end must always be at the end.
icex2 commented 2019-10-12 21:17:15 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/bio2emu/setupapi.c line 206

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/bio2emu/setupapi.c line 206](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-3c217ff3b68d72db3dd5de0ab497212dR206) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#2ad46f6d320896c6603d86fbef106b1688595e73_206_237)
icex2 commented 2019-10-12 21:17:15 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/bio2emu/setupapi.c line 209

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/bio2emu/setupapi.c line 209](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-3c217ff3b68d72db3dd5de0ab497212dR209) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#2ad46f6d320896c6603d86fbef106b1688595e73_209_237)
icex2 commented 2019-10-12 21:17:16 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/iidxhook8/bi2a.h line 110

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/iidxhook8/bi2a.h line 110](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-ac02ca76ecec73a09edecf98ad64ea9bR110) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#fcc7d8da37a41c5ea5f11a53cdda053c74ae9e2d_110_109)
icex2 commented 2019-10-12 21:17:16 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/iidxhook8/bi2a.h line 93

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/iidxhook8/bi2a.h line 93](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-ac02ca76ecec73a09edecf98ad64ea9bL93) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#fcc7d8da37a41c5ea5f11a53cdda053c74ae9e2d_93_93)
icex2 commented 2019-10-12 21:17:16 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/iidxhook8/dllmain.c line 152

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/iidxhook8/dllmain.c line 152](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-2652fef86a3a811b7b9013de2364403dR152) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#06b9ed9a6f9af2bd1cc0a7cf2e113e0e74d69f25_152_152)
icex2 commented 2019-10-12 21:17:16 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/bio2emu/setupapi.c line 350

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/bio2emu/setupapi.c line 350](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-3c217ff3b68d72db3dd5de0ab497212dR350) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#2ad46f6d320896c6603d86fbef106b1688595e73_350_365)
icex2 commented 2019-10-12 21:17:17 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

added 3 commits

  • 1c415eb2 - bio2emu: Remove requirement for bio2emu_init_end to be called
  • 0c1bbe08 - iidxhook8: Rename bi2a structs to be more clear
  • 0f04d5ef - bio2emu: cleanup setupapi code a bit

Compare with previous version

In GitLab by @xyen on Oct 12, 2019, 20:17 added 3 commits <ul><li>1c415eb2 - bio2emu: Remove requirement for bio2emu_init_end to be called</li><li>0c1bbe08 - iidxhook8: Rename bi2a structs to be more clear</li><li>0f04d5ef - bio2emu: cleanup setupapi code a bit</li></ul> [Compare with previous version](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079)
icex2 commented 2019-10-12 21:17:17 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

Commented on src/main/iidxhook8/bi2a.h line 113

changed this line in version 4 of the diff

In GitLab by @xyen on Oct 12, 2019, 20:17 Commented on [src/main/iidxhook8/bi2a.h line 113](https://github.com/djhackersdev/bemanitools/compare/073392407ad2a8b235f928a134f3a996e9bc8a14..b6216c696e7f0f7a87f1ef644d33a34401e7f079#diff-ac02ca76ecec73a09edecf98ad64ea9bR113) changed this line in [version 4 of the diff](/djhackers/bemanitools/merge_requests/4/diffs?diff_id=1051&start_sha=b6216c696e7f0f7a87f1ef644d33a34401e7f079#fcc7d8da37a41c5ea5f11a53cdda053c74ae9e2d_113_113)
icex2 commented 2019-10-12 21:17:36 +03:00 (Migrated from github.com)

In GitLab by @xyen on Oct 12, 2019, 20:17

resolved all threads

In GitLab by @xyen on Oct 12, 2019, 20:17 resolved all threads
icex2 commented 2019-10-12 21:36:19 +03:00 (Migrated from github.com)

All right, lgtm now.

All right, lgtm now.
icex2 commented 2019-10-12 21:36:24 +03:00 (Migrated from github.com)

merged

merged
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/djhackersdev_bemanitools#105