32 constant MAX_EVENTHANDLERS 0 cell +field eventhandler.eventid cell +field eventhandler.xt constant /EVENTHANDLER MAX_EVENTHANDLERS /EVENTHANDLER * constant EVENTHANDLERS_SIZE create eventhandlers EVENTHANDLERS_SIZE allot eventhandlers EVENTHANDLERS_SIZE erase : (translate) ( index-u -- eventhandler-addr ) /EVENTHANDLER * eventhandlers + ; : (eventhandler-set?) ( eventhandler-addr -- flag ) eventhandler.xt @ 0<> ; : (set-eventhandler) ( handler-xt eventid-u eventhandler-addr -- ) tuck eventhandler.eventid ! eventhandler.xt ! ; : eventhandlers.remove ( index-u -- ) (translate) /EVENTHANDLER erase ; : eventhandlers.append ( handler-xt eventid-u -- index-u ) MAX_EVENTHANDLERS 0 DO I (translate) dup (eventhandler-set?) invert IF (set-eventhandler) UNLOOP EXIT ELSE drop THEN LOOP true abort" no free eventhandler slots!" ;