Auto-Allocation: Semaphores
The auto-allocation algorithm gives special treatment to semaphores. Semaphores get auto-allocated to RAM above address 32, one bit at a time. A new byte gets allocated each time the previous one has been filled. To address auto-allocated semaphores you use only the semaphore’s name (label) without a base address. SPLat/PC takes care of the base address automatically.
Example (simple semaphores with auto-allocation):
MySem0: defSEM ;First semaphore bit
...
SetS MySem0 ;Note: no base address
...
GoIfST MySem0,Sem0IsTrue
If you use an argument in a defSEM directive it will allocate that many contiguous bits to semaphores. This is consistent with MultiTrack and jndexing.
Example (indexed semaphores with manual allocation):
This example is how you would do it if you are using indexed addressing without MultiTrack. This technique is not recommended for new programs, because MultiTrack and jndexing, along with auto-allocation (previous example), provides a much more elegant way of doing it.
MySemArray: defByte 6 ;Set aside 6 bytes
MySem0: EQU 0 ;First semaphore bit
...
MySem7: EQU 7 ;Last semaphore bit
...
iSetS MySem0,MySemArray
The above iSetS will set semaphore represented by bit 0 of the I’th byte in the array, where I is the index register. (The program would have to be written to be very sure I is in the range 0 to 5 or something bad might happen!)