mbbsemu / MBBSEmu

The MajorBBS Emulation Project is an Open Source, Cross-Platform emulator for easily running The MajorBBS & Worldgroup Modules
https://www.mbbsemu.com
MIT License
126 stars 14 forks source link

Lords of Cyberspace / Blademaster modules #593

Closed Blixxky closed 8 months ago

Blixxky commented 8 months ago

Lords of Cyberspace: Everything loads properly until you actually get into the module user side. Then any command responds, but instantly clears the screen. The launch command is "jack" to jack in. It does nothing. ? is for help, it lists the commands and clears the screen instantly.

Blademaster: This module gets further, and you can interact, but it appears you cannot move around using num pad, and eventually the entire BBS crashes:

Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. at MBBSEmu.Memory.ProtectedModeMemoryCore.VirtualToPhysical(UInt16 segment, UInt16 offset) at MBBSEmu.Memory.AbstractMemoryCore.GetWord(UInt16 segment, UInt16 offset) at MBBSEmu.CPU.CpuCore.GetOperandValueUInt16(OpKind opKind, EnumOperandType operandType) at MBBSEmu.CPU.CpuCore.Op_Cmp() at MBBSEmu.CPU.CpuCore.Tick() at MBBSEmu.HostProcess.ExecutionUnits.ExecutionUnit.Execute(FarPtr entryPoint, UInt16 channelNumber, Boolean simulateCallFar, Boolean bypassState, Queue1 initialStackValues, UInt16 initialStackPointer) at MBBSEmu.Module.MbbsModule.Execute(FarPtr entryPoint, UInt16 channelNumber, Boolean simulateCallFar, Boolean bypassSetState, Queue1 initialStackValues, UInt16 initialStackPointer) at MBBSEmu.HostProcess.MbbsHost.Run(String moduleName, FarPtr routine, UInt16 channelNumber, Boolean simulateCallFar, Queue1 initialStackValues) at MBBSEmu.HostProcess.MbbsHost.CallModuleRoutine(String routine, Action1 preRunCallback, UInt16 channel) at MBBSEmu.HostProcess.MbbsHost.RemoveSession(UInt16 channel) at MBBSEmu.HostProcess.MbbsHost.RemoveSessions(Predicate`1 match) at MBBSEmu.HostProcess.MbbsHost.WorkerThread()

enusbaum commented 8 months ago

Looking into Lords of Cyberspace (MUICYBER), I'm able to recreate the issue locally. Looking at the code for the module, it's calling btuxnf(usrnum, 0, 19); at the beginning of the user input processing, as well as using stpans() (used to strip ANSI coding from a string), which both are not currently implemented and just stubbed out.

I suspect the screen clearing issue is related to one of these two issues. I can see both the help menu and the redraw being sent in Wireshark.

image image

enusbaum commented 8 months ago

It looks like when the user hits "ENTER", its actually queueing up two CR_TERMINATED_STRING_AVAILABLE events in the queue. I suspect this is our routine handling <CR><LF> on Telnet input as two separate events vs. the one that it is. The first time through, when hitting ?<ENTER>, the first entry into STTROU passes in ?<NULL> as the INPUT string. The second one is just <NULL>.

I suspect this has been a bug for a while, but other modules ignore the input since it's null? Super weird. Going to see how it's double queueing that status to see if it fixes this.

image

enusbaum commented 8 months ago

The issue was being cause by BTUCHI intercepting the <ENTER> and queueing up the CR_TERMINATED_STRING_AVAILABLE status:

https://github.com/mbbsemu/MBBSEmu/blob/66a6f3e482f6868c5e6170f07b27a69b6a6b2a1d/MBBSEmu/HostProcess/MbbsHost.cs#L714-L718

This would result in a second CR_TERMINATED_STRING_AVAILABLE being also queued during ProcessIncomingCharacter() in MbbsHost.cs:

https://github.com/mbbsemu/MBBSEmu/blob/66a6f3e482f6868c5e6170f07b27a69b6a6b2a1d/MBBSEmu/HostProcess/MbbsHost.cs#L929-L930

I've changed the line in ProcessIncomingCharacter() to not queue a second status if there's already a CR_TERMINATED_STRING_AVAILABLE in the Status Queue and everything is working as intended within LoC:

image