terminal-simulator icon indicating copy to clipboard operation
terminal-simulator copied to clipboard

curious about this section of code

Open ronaldlw opened this issue 3 years ago • 5 comments

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

ronaldlw avatar Oct 10 '22 00:10 ronaldlw

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

larsbrinkhoff avatar Oct 10 '22 07:10 larsbrinkhoff

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 avatar Oct 10 '22 15:10 ronaldlw

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 avatar Oct 10 '22 15:10 ronaldlw

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?

ronaldlw avatar Oct 10 '22 22:10 ronaldlw

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.

larsbrinkhoff avatar Oct 14 '22 12:10 larsbrinkhoff