Skip to content

DMA I O request

Yoshitaka Kuwata edited this page Jul 24, 2021 · 34 revisions

The entire memory map of 6502ctrl is occupied by ram. This means all 64KB memory is available for CPU to use, that include vectors($FFFA-$FFFF), zero page($00xx), and stack area($01xx). On the other hand, no input/output device is mapped in the memory of CPU. Therefore, all of the I/O should be requested via Direct Memory Access (DMA).

The following figure explains how 'WAI' instruction on W65C02 is used to DMA.

DMA

DMA CALL Procedure

  1. Place DMARQ address just before WAI instruction
  2. DMARQ memory chunk should include the following parameters;
    • DMA Number (byte)
    • DMA Command (byte)
    • DMA Request block address (word) (will be used in future inplementation)
    • DMA data (byte)
  3. Jump to WAI instruction
  4. DMA is carried out by supervisor, and the result will be stored in DMARQ area
  5. After the DMA, PC will be the next statement of WAI

Please make sure interrupt (IRQ) is disabled. Use 'SEI' instruction beforehand,

Example to put char to console

DMA_SIO = 1

DMA_RESET = 1	
DMA_READ = 2
DMA_WRITE = 3	
DMA_STATUS = 4

	;; putc
putc:	sta dmach
	bra putc1
	.word dmarq
putc1:	wai
	rts

dmarq:
	.byte DMA_SIO 		; dmano
	.byte DMA_WRITE		; write
	.word $ffff		; dma request block address (unused for SIO)
dmach:
	.byte 0			; dma data byte

Example to get char from console

DMA_SIO = 1

DMA_RESET = 1	
DMA_READ = 2
DMA_WRITE = 3	
DMA_STATUS = 4

	;; getc
	.word dmarq
getc:	wai
	lda dmach
	rts

dmarq:
	.byte DMA_SIO 		; dmano
	.byte DMA_READ		; read
	.word $ffff		; dma request block address (unused for SIO)
dmach:
	.byte 0			; dma data byte