larsbrinkhoff / terminal-simulator

Simulation of VT52 and VT100 terminal hardware.
GNU General Public License v3.0
113 stars 17 forks source link

curious about this section of code #44

Closed ronaldlw closed 1 year ago

ronaldlw commented 1 year ago

I'm just poking around the code and am wondering why there's a mix of case and if / else if structures here? https://github.com/larsbrinkhoff/terminal-simulator/blob/85854592cbca9c2e24c7473f82c102c76af8e0e7/common/sdl.c#L326-L354

larsbrinkhoff commented 1 year ago

The case statements select between various event types. The if statements check other properties of the events.

ronaldlw commented 1 year ago

Hrm.. So, the case is switched on ev.type and the if statements are all if ev.type == something, so wouldn't you just add case statements for those?

Sorry, brushing up on my c skills, it's been awhile :) making sure I understand.

ronaldlw commented 1 year ago

also totally lost trying to figure out what these are doing?

https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L13-L14

https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L56-L57

https://github.com/larsbrinkhoff/terminal-simulator/blob/d5e3ae99850865ccf52c7285d32eedc89442df63/vt100/cpu.c#L478

It looks like a function definition prototype and also an array definition.. and seems to be accessed both ways as well?

ronaldlw commented 1 year ago

Ok, I think I figured this out. device_in and device_out are arrays of 256 pointers to functions to handle each port, right? Very tricky :)

also totally lost trying to figure out what these are doing?

https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L13-L14

https://github.com/larsbrinkhoff/terminal-simulator/blob/5aacb3a7a6ed90da9d6aaba8d4875307fe353045/vt100/sys.c#L56-L57

https://github.com/larsbrinkhoff/terminal-simulator/blob/d5e3ae99850865ccf52c7285d32eedc89442df63/vt100/cpu.c#L478

It looks like a function definition prototype and also an array definition.. and seems to be accessed both ways as well?

larsbrinkhoff commented 1 year ago

So, the case is switched on ev.type and the if statements are all if ev.type == something, so wouldn't you just add case statements for those?

Oh, in the default case? Yes, maybe so!

Ok, I think I figured this out. device_in and device_out are arrays of 256 pointers to functions to handle each port, right?

Yes, that's right. I don't think it's overly tricky. It's mostly that C syntax make the definitions look strange.