Skip to content

Instantly share code, notes, and snippets.

@furrtek
Last active June 26, 2020 00:19
Show Gist options
  • Save furrtek/1ae9e023e0a7db030258bb7dfc7d0215 to your computer and use it in GitHub Desktop.
Save furrtek/1ae9e023e0a7db030258bb7dfc7d0215 to your computer and use it in GitHub Desktop.
Reads the RGB to YUV lookup ROM in the HuC6260
; YUVDUMP - furrtek 2020
; With help from David Shadoff and Chris Covell
; Reads the RGB to YUV lookup ROM in the HuC6260
; Ugly code is ulgy, I was a Z80 kid :(
; How to use:
; -Wire HuC6260 pin 58 to ground
; -Run this program from a flash cart
; -Press UP, wait for the screen to fill up
; Values shown are the high bytes for the 512 possible colors
; -Use LEFT/RIGHT to scroll
; -Turn off console, wire HuC6260 pin 58 and 59 to ground
; -Repeat
; Values shown are the low bytes for the 512 possible colors
; RGB colors are sequential in the format GGGRRRBBB
; ROM values are in the format 0UUUUUVVVVVYYYYY
.list
.mlist
.include "equ.asm"
.include "macro.asm"
BATWIDTH = 128
BATHEIGHT = 32
ASCII_VRAM = $1000 ; Keep space for BAT
; Work RAM in page 1
color_counter = $2000
disp_flag = $2002
read_flag = $2003
values_ptr = $2004
scroll_x = $2006
values_start = $2200
.bank $0
.org $E000 ; Page 7
.code
RESET:
sei ; Set interrupt disable
csh ; High-speed mode
cld ; No decimal mode
lda #$FF ; Map HW registers in page 0
tam #0
tax
lda #$F8 ; Map work RAM in page 1
tam #1
lda #$01 ; Map ROM bank 1 (font data) in page 2
tam #2
txs ; Stack pointer = $21FF
lda $0000 ; Clear VDC IRQs ?
lda #$07
sta $1402 ; Disable all 3 CPU interrupt sources
sta $1403 ; Ack timer IRQ
stz $0C01 ; Turn off timer
st0 #5 ; VDC CR
st1 #0 ; Display off
st2 #0
stz <$00 ; Clear zero page
tii $2000,$2001,$1FFF
; Init VDC
stw #vdc_table,<_si
cly
.initlp:
lda [_si],Y ; Select VDC reg
bmi .initdone
iny
sta <_vreg ; Maybe not needed when IRQs disabled
sta video_reg
lda [_si],Y ; Set VDC reg data
iny
sta video_data
lda [_si],Y
iny
sta video_data+1
bra .initlp
.initdone:
lda #%00000100 ; Set pixel clock frequency
sta color_ctrl
; Setup text palette
stw #$0000,color_reg
stw #%0000000_000_000_000,color_data
stw #$00FF,color_reg
stw #%0000000_111_111_111,color_data
; Copy font tiles from ROM to VRAM
stw #$1000,<_di
jsr set_write
stw #GfxFont,<_si
stw #$0800,<_cx
cly
.vrloop:
lda [_si],Y
sta video_data
iny
lda [_si],Y
sta video_data+1
iny
bne .vrnext
inc <_si+1
.vrnext:
decw <_cx
lda <_cl
ora <_ch
bne .vrloop
jsr clear_bat
stw #Txt_top,<_si
stw #$0082,<_di ; Position in BAT
jsr print
stw #Txt_index,<_si
stw #$0102,<_di ; Position in BAT
jsr print
lda #%00000101 ; IRQ2 and TIMER IRQs OFF, VDC IRQs ON
sta irq_disable
vreg #5
st1 #%10001000 ; BG and VBL IRQ ON
cli
SCREEN_ON
.mainloop:
; Wait for read done
bbr0 <disp_flag,.mainloop
stz <disp_flag
; Display ROM values
stw #values_start,values_ptr
stw #$0182,<_si ; Position in BAT
ldx #22 ; Column count
.displp:
lda <_si
sta <_di
lda <_si+1
sta <_di+1
jsr dispcol
addw #4,<_si
dex
bne .displp
jmp .mainloop
dispcol:
stw #24,<_cl ; Bytes per column
.displp:
cly
lda [values_ptr],y
pha
lsr a
lsr a
lsr a
lsr a
jsr print_digit
pla
incw <_di
jsr print_digit
clc
incw <values_ptr
clc
adcw #128-1,<_di; Next line in BAT
decw <_cx
lda <_ch
ora <_cl
bne .displp
rts
VDC_INT:
pha
phx
phy
lda video_reg ; Read VDC status
sta <_vsr ; Not needed
; Are we in reading mode ?
bbr0 <read_flag,.notreading
; Read YUV ROM value
cly
lda $0404
sta [values_ptr],y
incw <values_ptr
incw <color_counter
lda <color_counter+1
cmp #2
bne .continue
; Done
stz <read_flag
lda #1
sta <disp_flag
.continue:
; Set border color for next frame
stw #$0100,color_reg
stw <color_counter,color_data
jmp .noup
.notreading:
; Read joypad
lda #$01
sta $1000
lda #$03
sta $1000
pha
pla
pha
pla
lda #$01
sta $1000
pha
pla
pha
pla
lda $1000
tax
and #8
bne .noleft
; Scroll X
lda #7
sta <_vreg
sta video_reg
lda <scroll_x
sta video_data
lda <scroll_x+1
sta video_data+1
incw <scroll_x
.noleft:
txa
and #2
bne .noright
; Scroll X
lda #7
sta <_vreg
sta video_reg
lda <scroll_x
sta video_data
lda <scroll_x+1
sta video_data+1
decw <scroll_x
.noright:
txa
and #1
bne .noup
; Start reading
stwz color_counter
stw #values_start,values_ptr
; Set border color for first frame
stw #$0100,color_reg
stwz color_data
smb0 <read_flag
.noup:
.exit:
lda <_vreg ; Restore previous VDC register # stored by vreg macro
sta video_reg
ply
plx
pla
rti
clear_bat:
stw #$0000,<_di ; BAT start
jsr set_write
ldx #LOW(BATWIDTH * BATHEIGHT)
ldy #HIGH(BATWIDTH * BATHEIGHT)
.clrlp:
st1 #$20 ; Transparent tile
st2 #$01 ; Font starts at tile $100
dex
bne .clrlp
dey
bne .clrlp
rts
; _si points to null-terminated text
; _di is VRAM address
print:
jsr set_write
cly
ldx #$F0+(ASCII_VRAM/4096) ; Palette F
.loop1:
lda [_si],Y
beq .done
sta video_data
stx video_data+1
incw <_si
bra .loop1
.done:
rts
; a is value
; _di is VRAM address
print_digit:
phx
pha
jsr set_write
ldx #$F0+(ASCII_VRAM/4096) ; Palette F
pla
and #$0F
cmp #$0A
bcc .numbers ; Hex to ASCII
clc
adc #$07
.numbers:
adc #$30
sta video_data
stx video_data+1
plx
rts
; _di is VRAM address
set_write:
vreg #$00
lda <_di
sta video_data
lda <_di+1
sta video_data+1
vreg #$02
rts
Txt_top:
.db "YUVDUMP",0
Txt_index:
.db "0 18 30 48 60 78 90 A8 C0 D8 F0 108 120 138 150 168 180 198 1B0 1C8 1E0 1F8",0
vdc_table:
.db $05,$00,$00 ; CR
.db $06,$00,$00 ; RCR
.db $07,$00,$00 ; BXR
.db $08,$00,$00 ; BYR
.db $09,$20,$10 ; MWR - 128x32 BAT size
.db $0A,$02,$02 ; HSR Display size
.db $0B,$1F,$04 ; HDR
.db $0C,$07,$0D ; VPR
.db $0D,$DF,$00 ; VDW
.db $0E,$03,$00 ; VCR
.db $0F,$10,$00 ; DCR
.db $13,$00,$7F ; SATB
.db -1 ; End
; Vectors
.org $FFF8
.dw VDC_INT
.org $FFFE
.dw RESET
.bank $1
.org $4000 ; Page 2
GfxFont:
.incchr "parofont.pcx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment