Skip to content

Commit

Permalink
vdp: print hex to the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
InPermutation committed Oct 4, 2020
1 parent 40538f6 commit 387f8f0
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions vdp.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@
VDP_VRAM = $4000
VDP_REG = $4001

VDP_WRITE_VRAM_BIT = $40
VDP_REGISTER_BITS = $80

VDP_NAME_TABLE_BASE = $0000
VDP_PATTERN_TABLE_BASE = $0800

.macro vdp_write_vram
lda #<(\1)
sta VDP_REG
lda #(VDP_WRITE_VRAM_BIT | >\1)
sta VDP_REG
.endm

vdp_reset:
jsr vdp_reg_reset
jsr vdp_initialize_pattern_table
jsr vdp_initialize_name_table
jsr vdp_enable_display
rts

vdp_reg_reset:
pha
phx

Expand All @@ -20,11 +38,51 @@ vdp_reg_reset_loop:
inx
cpx #(vdp_end_register_inits - vdp_register_inits)
bne vdp_reg_reset_loop
plx
pla
rts

vdp_initialize_pattern_table:
; initialize the pattern table to the 16 hex digits
pha
phx
vdp_write_vram VDP_PATTERN_TABLE_BASE
ldx #0
vdp_pattern_table_loop:
lda vdp_hex_digits,x
sta VDP_VRAM
inx
cpx #(vdp_end_hex_digits - vdp_hex_digits)
bne vdp_pattern_table_loop
plx
pla
rts

vdp_initialize_name_table:
; initialize to "0123456789ABCDEF"
pha
phx
vdp_write_vram VDP_NAME_TABLE_BASE
lda #0
vdp_name_table_loop:
sta VDP_VRAM
ina
cmp #$10
bne vdp_name_table_loop
plx
pla
rts

vdp_enable_display:
pha
lda vdp_register_1
ora #%01000000 ; enable the active display
sta VDP_REG
lda #(VDP_REGISTER_BITS | 1)
sta VDP_REG
pla
rts

vdp_register_inits:
vdp_register_0: .byte %00000000 ; 0 0 0 0 0 0 M3 EXTVDP
vdp_register_1: .byte %10010000 ;16k Bl IE M1 M2 0 Siz MAG
Expand All @@ -36,3 +94,21 @@ vdp_register_6: .byte $00 ; Sprite pattern generator (currently unused)
vdp_register_7: .byte $B4 ; FG/BG. 4=>Dark blue, B=>Light yellow
vdp_end_register_inits:

vdp_hex_digits:
.byte $70,$88,$98,$A8,$C8,$88,$70,$00 ; 0
.byte $20,$60,$20,$20,$20,$20,$70,$00 ; 1
.byte $70,$88,$08,$30,$40,$80,$F8,$00 ; 2
.byte $F8,$08,$10,$30,$08,$88,$70,$00 ; 3
.byte $10,$30,$50,$90,$F8,$10,$10,$00 ; 4
.byte $F8,$80,$F0,$08,$08,$88,$70,$00 ; 5
.byte $38,$40,$80,$F0,$88,$88,$70,$00 ; 6
.byte $F8,$08,$10,$20,$40,$40,$40,$00 ; 7
.byte $70,$88,$88,$70,$88,$88,$70,$00 ; 8
.byte $70,$88,$88,$78,$08,$10,$E0,$00 ; 9
.byte $20,$50,$88,$88,$F8,$88,$88,$00 ; A
.byte $F0,$88,$88,$F0,$88,$88,$F0,$00 ; B
.byte $70,$88,$80,$80,$80,$88,$70,$00 ; C
.byte $F0,$88,$88,$88,$88,$88,$F0,$00 ; D
.byte $F8,$80,$80,$F0,$80,$80,$F8,$00 ; E
.byte $F8,$80,$80,$F0,$80,$80,$80,$00 ; F
vdp_end_hex_digits:

0 comments on commit 387f8f0

Please sign in to comment.