
setup_hdma:
	sep #$20 : .as
	rep #$10 : .xl
	stz $420b
	stz $420c

	lda #$02		;A to B; direct; 2x single reg
	sta $4320		;we use ch. 2 for color data
	lda #$22		;2122 = CG RAM
	sta $4321		;dest: CG RAM
	lda #^hdma_pal
	ldy #!hdma_pal
	sty $4322
	sta $4324

	lda #$00		;A to B; direct; 1x single reg
	sta $4310		;ch. 1 for color address
	lda #$21		;2121 = CG addr
	sta $4311		;dest: CG Address
	lda #^hdma_cg_addr
	ldy #!hdma_cg_addr
	sty $4312
	sta $4314

	lda #$00		;A to B; direct; 1x single reg
	sta $4330		;ch. 3 for mode switch
	lda #$05		;2105 = BG mode
	sta $4331
	lda #^hdma_mode
	ldy #!hdma_mode
	sty $4332
	sta $4334

	lda #$03		;A to B; direct; 2x 2x single reg
	sta $4340		;ch. 4 for scroll
	lda #$0d		;210d = BG1HOFS
	sta $4341
	lda #^hdma_scroll
	ldy #!hdma_scroll
	sty $4342
	sta $4344

	lda #$01		;A to B; direct; 1x two reg
	sta $4350		;ch. 5 for color math
	lda #$31		;2131 + 2132 = math, color constant
	sta $4351
	lda #^hdma_math
	ldy #!hdma_math
	sty $4352
	sta $4354

	lda #$3a
	sta $420c		;enable HDMA ch. 1+3+4+5
	jsr waitblank
	lda #$3e
	sta $420c		;enable HDMA ch. 2 too
	lda #$81		;VBlank NMI + Auto Joypad Read
	sta $4200		;enable V-BLANK NMI
	rts


