350 lines
10 KiB
NASM
350 lines
10 KiB
NASM
;
|
|
; This is the video output driver for 40 column PETSCII machines
|
|
; Each 2x2 pixel block is mapped to a single PETSCII character
|
|
;
|
|
|
|
SCREEN_COLS = 40
|
|
SCREEN_ROWS = 25
|
|
|
|
ROW_TILE = 0
|
|
ROW_REGS = 1
|
|
ROW_FLAGS = 2
|
|
ROW_FILENAME = 3
|
|
|
|
|
|
VIDEO_TOP = (SCREEN_ROWS-16)
|
|
VIDEO_LEFT = (SCREEN_COLS - (64/2)) / 2
|
|
|
|
VIDEO_START = SCREEN_RAM + SCREEN_COLS * VIDEO_TOP + VIDEO_LEFT
|
|
|
|
; 00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11
|
|
; 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11
|
|
petpixels = [ $20, $6c, $7b, $62, $7c, $e1, $ff, $fe, $7e, $7f, $61, $fc, $e2, $fb, $ec, $a0 ]
|
|
|
|
.section data
|
|
qpix .byte petpixels
|
|
.endsection data
|
|
|
|
.section code
|
|
|
|
VideoInit .proc
|
|
rts
|
|
.endproc
|
|
|
|
VideoDraw .proc
|
|
ldx #0
|
|
stx scrdirty
|
|
lda #<VIDEO_START
|
|
sta zptr1
|
|
lda #>VIDEO_START
|
|
sta zptr1+1
|
|
- lda c8screen, x
|
|
and #%11_00_11_00
|
|
sta zptr2
|
|
lda c8screen+8, x
|
|
and #%11_00_11_00
|
|
lsr a
|
|
lsr a
|
|
ora zptr2
|
|
sta zptr2
|
|
lda c8screen, x
|
|
and #%00_11_00_11
|
|
asl a
|
|
asl a
|
|
sta zptr2+1
|
|
lda c8screen+8, x
|
|
and #%00_11_00_11
|
|
ora zptr2+1
|
|
sta zptr2+1
|
|
and #$0f
|
|
tay
|
|
lda qpix, y
|
|
ldy #3
|
|
sta (zptr1), y
|
|
lda zptr2+1
|
|
lsr a
|
|
lsr a
|
|
lsr a
|
|
lsr a
|
|
tay
|
|
lda qpix, y
|
|
ldy #1
|
|
sta (zptr1), y
|
|
lda zptr2
|
|
and #$0f
|
|
tay
|
|
lda qpix, y
|
|
ldy #2
|
|
sta (zptr1), y
|
|
lda zptr2
|
|
lsr a
|
|
lsr a
|
|
lsr a
|
|
lsr a
|
|
tay
|
|
lda qpix, y
|
|
ldy #0
|
|
sta (zptr1), y
|
|
lda #4
|
|
clc
|
|
adc zptr1
|
|
sta zptr1
|
|
tya
|
|
adc zptr1+1
|
|
sta zptr1+1
|
|
inx
|
|
txa
|
|
and #7
|
|
bne -
|
|
lda #(SCREEN_COLS-32)
|
|
clc
|
|
adc zptr1
|
|
sta zptr1
|
|
tya
|
|
adc zptr1+1
|
|
sta zptr1+1
|
|
txa
|
|
clc
|
|
adc #8 ; skip every other row since we are processing two rows at a time
|
|
tax
|
|
beq +
|
|
jmp -
|
|
+ rts
|
|
.endproc
|
|
|
|
ShowFlags .proc
|
|
ldx #0
|
|
lda eflags
|
|
sta tmpflags
|
|
- rol tmpflags
|
|
bcc +
|
|
lda flags, x
|
|
bne next
|
|
+ lda #' '
|
|
next sta SCREEN_RAM+SCREEN_COLS*(ROW_FLAGS+1)-8, x
|
|
inx
|
|
cpx #8
|
|
bne -
|
|
rts
|
|
.section data
|
|
.enc "screen"
|
|
flags .text "pltr321s"
|
|
.enc "none"
|
|
.endsection data
|
|
.section bss
|
|
tmpflags .byte ?
|
|
.endsection bss
|
|
.endproc
|
|
|
|
ClearLine .proc
|
|
ldy #0
|
|
clc
|
|
jsr myPLOT
|
|
lda #' '
|
|
ldx #SCREEN_COLS
|
|
- jsr myCHROUT
|
|
dex
|
|
bne -
|
|
rts
|
|
.endproc
|
|
|
|
ShowRegisters .proc
|
|
lda #0
|
|
ldx #ROW_REGS
|
|
tay
|
|
clc
|
|
jsr myPLOT
|
|
ldx #0
|
|
- txa
|
|
pha
|
|
lda reg.v, x
|
|
jsr HexByteOut
|
|
pla
|
|
tax
|
|
inx
|
|
cmp #$0f
|
|
bmi -
|
|
lda reg.i+1
|
|
jsr HexByteOut
|
|
lda reg.i
|
|
jsr HexByteOut
|
|
lda reg.pc+1
|
|
jsr HexByteOut
|
|
lda reg.pc
|
|
jsr HexByteOut
|
|
rts
|
|
.endproc
|
|
|
|
ShowTimers .proc
|
|
.enc "screen"
|
|
lda #'d'
|
|
ldx reg.dt
|
|
bne +
|
|
clc
|
|
adc #' '-'d'
|
|
+ sta SCREEN_RAM+SCREEN_COLS*ROW_FLAGS
|
|
lda #'s'
|
|
ldx reg.st
|
|
bne +
|
|
clc
|
|
adc #' '-'s'
|
|
+ sta SCREEN_RAM+SCREEN_COLS*ROW_FLAGS+1
|
|
rts
|
|
.enc "none"
|
|
.endproc
|
|
|
|
HexByteOut .proc
|
|
tay
|
|
lsr a
|
|
lsr a
|
|
lsr a
|
|
lsr a
|
|
tax
|
|
lda hexdigits, x
|
|
jsr myCHROUT
|
|
tya
|
|
and #$0f
|
|
tax
|
|
lda hexdigits, x
|
|
jsr myCHROUT
|
|
rts
|
|
.section data
|
|
.enc "screen"
|
|
hexdigits .text "0123456789abcdef"
|
|
.enc "none"
|
|
.endsection data
|
|
|
|
.endproc
|
|
|
|
myPLOT .proc
|
|
pha
|
|
txa
|
|
ldx #0
|
|
stx cursorpos+1
|
|
asl a
|
|
asl a
|
|
asl a
|
|
sta cursorpos
|
|
asl a
|
|
rol cursorpos+1
|
|
asl a
|
|
rol cursorpos+1
|
|
clc
|
|
adc cursorpos
|
|
sta cursorpos
|
|
clc
|
|
tya
|
|
adc cursorpos
|
|
sta cursorpos
|
|
lda #>SCREEN_RAM
|
|
adc cursorpos+1
|
|
sta cursorpos+1
|
|
pla
|
|
rts
|
|
.endproc
|
|
|
|
myCHROUT .proc
|
|
pha
|
|
sta chr
|
|
tya
|
|
pha
|
|
ldy #0
|
|
lda chr
|
|
sta (cursorpos), y
|
|
inc cursorpos
|
|
bne +
|
|
inc cursorpos+1
|
|
+ pla
|
|
tay
|
|
pla
|
|
rts
|
|
chr .byte ?
|
|
.endproc
|
|
|
|
mySTROUT .proc
|
|
sta zptr1
|
|
sty zptr1+1
|
|
ldy #0
|
|
- lda (zptr1), y
|
|
beq +
|
|
sta (cursorpos), y
|
|
iny
|
|
bne -
|
|
inc cursorpos+1
|
|
rts
|
|
+ tya
|
|
clc
|
|
adc cursorpos
|
|
sta cursorpos
|
|
lda #0
|
|
adc cursorpos+1
|
|
sta cursorpos+1
|
|
rts
|
|
.endproc
|
|
|
|
HeartBeat .proc
|
|
lda step
|
|
clc
|
|
adc #1
|
|
and #size(glyphs)-1
|
|
sta step
|
|
tax
|
|
lda glyphs, x
|
|
sta SCREEN_RAM+SCREEN_COLS-1
|
|
jsr ShowTimers
|
|
|
|
lda eflags
|
|
and #EF_REGS
|
|
beq +
|
|
jsr ShowRegisters
|
|
+ lda eflags
|
|
and #EF_LOAD
|
|
beq +
|
|
nop
|
|
+ lda eflags
|
|
eor preveflags
|
|
beq +
|
|
jsr ShowFlags
|
|
lda eflags
|
|
eor preveflags
|
|
and #EF_REGS
|
|
beq +
|
|
ldx #ROW_REGS
|
|
jsr ClearLine
|
|
+ lda eflags
|
|
sta preveflags
|
|
rts
|
|
|
|
.section data
|
|
glyphs .byte $7b, $7e, $7c, $6c
|
|
.endsection data
|
|
.section bss
|
|
step .byte ?
|
|
preveflags .byte ?
|
|
.endsection
|
|
.endproc
|
|
|
|
ShowTitle .proc
|
|
lda #0
|
|
tax
|
|
tay
|
|
jsr myPLOT
|
|
ldy #>title
|
|
lda #<title
|
|
jsr mySTROUT
|
|
rts
|
|
.endproc
|
|
.endsection code
|
|
|
|
.section zp
|
|
cursorpos .word ?
|
|
.endsection zp
|
|
|
|
.section data
|
|
.enc "screen"
|
|
title .null " chipty5 chip-8 emulator for the 6502 "
|
|
.enc "none"
|
|
.endsection data
|
|
|
|
; vim: syntax=64tass
|