Closed DerelictDrone closed 1 month ago
Self read/write works btw, here's an example program for using internal memory first and then an external memory device, like how ZCPU read/write works
@inputs ExternalMem:wirelink
@outputs Hispeed:number
@persist Memory:array Ptr:number InternalMem:wirelink
@strict
Memory = array()
InternalMem = wirelink()
Ptr = 1
event readCell(Address:number) {
if(Address > 128) {
returnReadValue(ExternalMem[Address-128])
} else {
returnReadValue(Memory[Address,number])
}
}
event writeCell(Address:number, Value:number) {
if(Address > 128) {
ExternalMem[Address-128] = Value
} else {
Memory[Address] = Value
}
}
event tick() {
Hispeed = InternalMem[Ptr]
InternalMem[Ptr] = Ptr
Ptr++
Ptr = Ptr%256
}
Isn't read/write cell functions deprecated for some reason?
Isn't read/write cell functions deprecated for some reason?
Don't all of the memory devices such as the RAM gates and EEPROM and DHDD and the highspeed read/write gates use these to function.
Isn't read/write cell functions deprecated for some reason?
xwl:readCell(n) and xwl:writeCell(nn) are, because they were replaced by wirelink's [] operator.
Wirelink [] still calls ReadCell and WriteCell on entities, this just adds events that are executed when something calls ReadCell and WriteCell on this E2's chip
Just FYI, you can pass an event constructor to E2Lib.registerEvent
for this that runs on the chip initialization if the event is present (which passes the e2's context). That's what chipUsed
does. So you don't need a redundant registered_events
check slowing the runtime down. I didn't see the rest, maybe could've been written simpler if you knew this
Just FYI, you can pass an event constructor to
E2Lib.registerEvent
for this that runs on the chip initialization if the event is present (which passes the e2's context). That's whatchipUsed
does. So you don't need a redundantregistered_events
check slowing the runtime down. I didn't see the rest, maybe could've been written simpler if you knew this
I had a constructor and destructor like chipUsed does, but tried to cache any previously existing readcell/writecell(non-strict, error if they existed previously in strict), my reasoning being to potentially save anyone who's trying to run E2 scripts using another entity from overwriting and then losing that entity's original readcell or writecell.
Constructor/destructors were removed here, in this commit if you wanted to see them.
Part of wirelink.lua
Adds events for read, and write
Three functions for use inside of these events.
Returns Value when exiting a readCell event, also clears hispeed error flag
If nonzero, indicates that the request couldn't be satisfied, doesn't error your chip but may raise errors in things like ZCPU which use return of nil/false from read/write to indicate out of range or other errors.