jeffpar / pcjs.v1

PCjs Machines 1.0 (archived)
https://github.com/jeffpar/pcjs.org
GNU General Public License v3.0
475 stars 92 forks source link

Initialize config programmatically skipping machine.xml, XSL and CSS #64

Open mihailik opened 6 years ago

mihailik commented 6 years ago

It would be great if embedPCx86 could be fired with some extra parameters, to avoid the whole roundtrip fetching/parsing/resolving/transforming machine.xml and XSL (and CSS too).

For example a JS function is passed instead of sXMLFile argument, and PCx86 logic would call into it skipping whole processXML and the rest.




I think I got a general idea how the logic works there, except still very hazy about binding HTML elements to components.

Maybe you can direct me towards relevant parts of the code, and I can try to implement such a shortcut JS functionality?

jeffpar commented 6 years ago

Would that save much? Every machine XML file refers in turn to ROM images (and usually 1 or more disk images) that must be preloaded before the machine can be allowed to start. How are you envisioning those resources being stored and supplied to embedXXX()?

The XML serves two purposes: defining component appearance and defining component initialization properties. Using an XSL file, each XML component tag is transformed into a set of HTML tags -- usually just DIVs -- that collectively describe the machine's appearance. For each component, one of the DIVs is usually what I consider the "object" DIV -- ie, a DIV with a class suffix "-object" and a data-value attribute containing all the parameters used to initialize an object of the appropriate class.

See the static init() function in any of the component class files; they're all very similar. The init() function calls getComponentParms() to extract the data-value attributes from the object DIV, passes them to the component's constructor, and then calls bindComponentControls() with the new object and the DIV. That function looks through all the DIV's child elements that have a "-binding" class and calls the object's setBinding() function. At a minimum, setBinding() will simply record the HTML control (button, list, or whatever) and add whatever onclick, onchange, etc, handlers it needs.