Improving the Memory Manager

Taking a step back to review the Memory Manager that displays the data in memory chips and allows for editing of the data, I realized that several improvements could be made.

  • Display the data in 16bit or 8bit chunks in binary or hex
  • Create a data input popup that captures keyboard input without using an LineEdit box
  • Set up different text areas for Address, Data, and ASCII

I got most of this done today. Having separate Labels in an HBox means that the text may be colored differently, the hand pointer may only show over the data that may be edited, and the offset of points into the data area is zero.

Memory Manager

The new popup for entering data works great! Rather than using a LineEdit, it has a Label that prompts you to type the value on the keyboard and the digits shift left as they are entered into the value in say: 0b00000000 for binary and 0x00 for hex. Some simple tests of the Scan Code values (ASCII) determine the validity of characters.


Much of this was fun to code and I came up with some quite compact solutions for number conversions.

func _on_NumberInputPanel_popup_hide():
	var v = $NumberInputPanel.txt.text
	if v[0] != "0": # No entry was made
	var x = 0
	if mode == BIN:
		for i in v.length():
			if i > 1: # Skip the prefix 0b
				x *= 2
				if v[i] == "1":
					x += 1
		x = v.hex_to_int() # Godot function
	data.bytes[current_addr] = x % 0x100
	if data.width == 16:
		data.bytes[current_addr + 1] = x / 0x100

func int2bin(x: int) -> String:
	var b = ""
	for n in data.width:
		b = String(x % 2) + b
		x /= 2
	return b


One weird bug appeared that took me a while to fix. A property that I set in the Popup to indicate Hex or Binary was mysteriously resetting as I entered values from the keyboard.

The cause of this was that the Popup is used by other Memory Parts (ROM and RAM) so there was no linkage to which Part was using the Popup. So when the Popup is Opened, I simply tag a property with what object opened it and check that before acting on the keyboard input. Otherwise, the properties are in the default state for the inactive ones, yet the attached script still runs in the Parts that are in the Parts Factory autoload.

I spotted the cause by looking at the reference ID of the object when break-pointing the code at the point of failure and realizing that it belonged to another place in the scene.

Another weird bug was that the Popup insisted in expanding to a certain size when it opened, but it was bigger than the internal items. The only fix I could come up with was to set the rectangle size to zero after it popped up on the next frame to force it to resize again, this time correctly.


  • Just a few things to do to complete the Memory Manager
  • Add labelling ability for Part pins

Comments Forum

More Devlog entries

Most recent first