Memory layout of a data structure: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 47:
 
The common practice is to have "soft" ports in zero page which get written to the memory-mapped location of the actual hardware interface by only a single subroutine that is run at a fixed interval. All other routines only ever update the "soft" port. (Hardware ports such as this example are typically write-only so the only way to non-destructively write to individual bits is through this indirect method.)
=={{header|68000 Assembly}}==
Thanks to the low-level nature of assembly, this task is actually rather straightforward. Using <code>equ</code> directives we can easily abstract the bit numbers with convenient labels without having to remember what they are.
 
<lang 68000devpac>BIT_0 equ $1
BIT_1 equ $2
BIT_2 equ $4
BIT_3 equ $8
BIT_4 equ $10
BIT_5 equ $20
BIT_6 equ $40
BIT_7 equ $80
 
BIT_8 equ $100
BIT_9 equ $200
 
RS232_9_TD equ BIT_3
RS232_9_RD equ BIT_2
RS232_9_RTS equ BIT_7
RS232_9_CTS equ BIT_8
RS232_9_DSR equ BIT_6
RS232_9_SG equ BIT_5
RS232_9_CD equ BIT_1</lang>
 
With these aliases defined, we can easily write these constants, or any combination thereof, to the memory-mapped RS232 port.
 
(Disclaimer: I have no idea how this protocol actually works. So there's a good chance that these values should '''not''' be combined this way when working with actual RS232 hardware. But that's not really important to this task. I'm just showing how you can define constants and write them to the port.)
 
<lang 68000devpac>rs232_9pin_port equ $A00000
;I chose $A00000 arbitrarily as an example, its actual address depends on the wiring.
 
MOVE.W #RS232_9_CTS,rs232_9pin_port
MOVE.W #RS232_9_CTS|RS232_9_RD|RS232_9_SG,rs232_9pin_port ;bitwise OR can be used at compile time to combine the labels.</lang>
 
 
1,489

edits