Mutex: Difference between revisions

Content added Content deleted
(→‎{{header|6502 Assembly}}: formatting for better readability)
Line 37: Line 37:


main:
main:

;if your time-sensitive function has parameters, pre-load them into global memory here.
;if your time-sensitive function has parameters, pre-load them into global memory here.
;The only thing the NMI should have to do is write the data to the hardware registers.
;The only thing the NMI should have to do is write the data to the hardware registers.

jsr waitframe
jsr waitframe
LDA #$01 ;there's not enough time for a second vblank to occur between these two calls to waitframe().
LDA #$01 ;there's not enough time for a second vblank to occur between these two calls to waitframe().
Line 46: Line 46:


halt:
halt:
jmp halt ;we're done - trap the cpu. NMI will still occur but nothing of interest happens since the mutex is locked.
jmp halt



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
nmi: ;every 1/60th of a second the CPU jumps here automatically.
nmi: ;every 1/60th of a second the CPU jumps here automatically.
pha
pha
Line 70: Line 72:
LDA #$01
LDA #$01
STA vblankflag ;allow waitframe() to exit
STA vblankflag ;allow waitframe() to exit



pla
pla
Line 78: Line 79:
pla ;popAll
pla ;popAll
rti
rti
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

waitframe:
waitframe:
pha
pha
Line 88: Line 89:
pla
pla
rts</lang>
rts</lang>

=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
<code>LOCK</code> is a prefix that can be added to instructions that read a value then write back to it, such as <code>INC</code> and <code>DEC</code>. This prefix "locks" the memory bus, preventing other CPUs (if any) from accessing the same memory location at the same time as the CPU executing the "locked" instruction. The lock lasts until the locked instruction is complete, at which point the lock is released. This isn't used much on the original 8086, and there are a few limitations to the usage of the <code>LOCK</code> prefix:
<code>LOCK</code> is a prefix that can be added to instructions that read a value then write back to it, such as <code>INC</code> and <code>DEC</code>. This prefix "locks" the memory bus, preventing other CPUs (if any) from accessing the same memory location at the same time as the CPU executing the "locked" instruction. The lock lasts until the locked instruction is complete, at which point the lock is released. This isn't used much on the original 8086, and there are a few limitations to the usage of the <code>LOCK</code> prefix: