conio and most other stuff working now

This commit is contained in:
mrdudz
2015-11-29 01:14:59 +01:00
parent 88e7b5776a
commit 9fbf8a4299
35 changed files with 2205 additions and 737 deletions

View File

@@ -1,8 +1,10 @@
.export reset, irq, nmi ; FIXME
; .export reset, irq, nmi ; FIXME
.export _main
.include "gamate.inc"
.zeropage
.include "gamate.inc"
.zeropage
addr: .word 0
psa: .word 0
@@ -16,7 +18,7 @@ cursor: .byte 0
controlslast: .byte 0
controlsedge: .byte 0
.data
.data
temp_x: .byte 0
temp_y: .byte 0
temp_a: .byte 0
@@ -27,405 +29,414 @@ psy: .byte 0
xpos: .byte 0
ypos: .byte 0
.code
.code
chars:
.incbin "cga2.chr"
hex2asc: .byte "0123456789abcdef"
;-------------------------------------------------------------------------------
.export IRQStub
.proc nmi
inc nmi_count
rts
inc nmi_count
rts
.endproc
.proc irq
inc irq_count
rts
.proc IRQStub
inc irq_count
rts
.endproc
.proc reset
lda #>audio_base
sta writeaddr+1
sta readaddr+1
lda #<audio_base
sta writeaddr
sta readaddr
;-------------------------------------------------------------------------------
lda #$10
sta editbuffer1+6
lda #$e
sta editbuffer2+5
lda #$ff
sta editbuffer2+3
lda #$ff
sta editbuffer2+4
lda #$0f
sta editbuffer2
lda #$0f
sta editbuffer2+1
lda #$0e
sta editbuffer2+2
lda #$38
sta editbuffer1+7
.proc _main
lda #>AUDIO_BASE
sta writeaddr+1
sta readaddr+1
lda #<AUDIO_BASE
sta writeaddr
sta readaddr
lda #0
sta lcd_x_pos
sta lcd_y_pos
sta irq_count
sta cursor
lda #1
sta nmi_count
cli
lda #lcd_mode_y_increment
sta lcd_mode
lda #$10
sta editbuffer1+6
lda #$e
sta editbuffer2+5
lda #$ff
sta editbuffer2+3
lda #$ff
sta editbuffer2+4
lda #$0f
sta editbuffer2
lda #$0f
sta editbuffer2+1
lda #$0e
sta editbuffer2+2
lda #$38
sta editbuffer1+7
jsr printy
lda #0
sta LCD_XPOS
sta LCD_YPOS
sta irq_count
sta cursor
lda #1
sta nmi_count
cli
lda #LCD_MODE_INC_Y
sta LCD_MODE
lda #1
sta nmi_enable
jsr printy
lda #1
sta ZP_NMI_ENABLE
loop:
lda irq_count
lda irq_count
loop1:
cmp irq_count
beq loop1
lda irq_count
and #7
bne loop1
cmp irq_count
beq loop1
lda irq_count
and #7
bne loop1
lda #lcd_mode_y_increment
sta lcd_mode
lda #LCD_MODE_INC_Y
sta LCD_MODE
ldx #3
ldy #32
lda irq_count
jsr printhex
ldx #3
ldy #32
lda irq_count
jsr printhex
lda cursor
ldy #0
cmp #20
bcc firstline
sec
sbc #20
ldy #24
lda cursor
ldy #0
cmp #20
bcc firstline
sec
sbc #20
ldy #24
firstline:
sta lcd_x
sty lcd_y
lda #' '
jsr printsign
sta LCD_X
sty LCD_Y
lda #' '
jsr printsign
norclearcursor:
jsr inputs
lda irq_count
and #8
bne nocursor
lda cursor
ldy #0
cmp #20
bcc firstline2
sec
sbc #20
ldy #24
jsr inputs
lda irq_count
and #8
bne nocursor
lda cursor
ldy #0
cmp #20
bcc firstline2
sec
sbc #20
ldy #24
firstline2:
sta lcd_x
sty lcd_y
lda #'x'
jsr printsign
sta LCD_X
sty LCD_Y
lda #'x'
jsr printsign
nocursor:
lda #lcd_mode_y_increment
sta lcd_mode
jsr printy
jmp loop
lda #LCD_MODE_INC_Y
sta LCD_MODE
jsr printy
jmp loop
.endproc
.proc printy
ldy #0
ldy #0
loop1:
tya
pha
asl
tax
lda readaddr,y
ldy #8
jsr printhex
pla
tay
iny
cpy #10
bne loop1
tya
pha
asl
tax
lda readaddr,y
ldy #8
jsr printhex
pla
tay
iny
cpy #10
bne loop1
loop2:
tya
pha
tya
sec
sbc #10
asl
tax
lda readaddr,y
ldy #16
jsr printhex
pla
tay
iny
cpy #20
bne loop2
tya
pha
tya
sec
sbc #10
asl
tax
lda readaddr,y
ldy #16
jsr printhex
pla
tay
iny
cpy #20
bne loop2
ldx #0
ldy #32
lda nmi_count
jsr printhex
ldx #0
ldy #32
lda nmi_count
jsr printhex
rts
rts
.endproc
;-------------------------------------------------------------------------------
.proc inputs
lda controlslast
eor controls
and controlslast
eor #$ff
sta controlsedge
and #up
bne notup
lda controlslast
eor JOY_DATA
and controlslast
eor #$ff
sta controlsedge
and #JOY_DATA_UP
bne notup
lda cursor
lsr
tay
bcs uplow
lda readaddr,y
clc
adc #$10
sta readaddr,y
jmp notup
lda cursor
lsr
tay
bcs uplow
lda readaddr,y
clc
adc #$10
sta readaddr,y
jmp notup
uplow:lda readaddr,y
clc
adc #1
sta readaddr,y
clc
adc #1
sta readaddr,y
notup:lda controlsedge
and #down
bne notdown
lda cursor
lsr
tay
bcs downlow
lda readaddr,y
sec
sbc #$10
sta readaddr,y
jmp notdown
and #JOY_DATA_DOWN
bne notdown
lda cursor
lsr
tay
bcs downlow
lda readaddr,y
sec
sbc #$10
sta readaddr,y
jmp notdown
downlow:
lda readaddr,y
sec
sbc #1
sta readaddr,y
lda readaddr,y
sec
sbc #1
sta readaddr,y
notdown:lda controlsedge
and #left
bne notleft
lda cursor
beq notleft
dec cursor
and #JOY_DATA_LEFT
bne notleft
lda cursor
beq notleft
dec cursor
notleft:lda controlsedge
and #right
bne notright
lda cursor
cmp #40
beq notright
inc cursor
and #JOY_DATA_RIGHT
bne notright
lda cursor
cmp #40
beq notright
inc cursor
notright:lda controlsedge
and #start
bne notstart
lda #0
sta audio_base
sta audio_base+1
sta audio_base+2
sta audio_base+3
sta audio_base+4
sta audio_base+5
sta audio_base+6
sta audio_base+8
sta audio_base+9
sta audio_base+10
sta audio_base+11
sta audio_base+12
sta audio_base+13
sta audio_base+7
and #JOY_DATA_START
bne notstart
lda #0
sta AUDIO_BASE
sta AUDIO_BASE+1
sta AUDIO_BASE+2
sta AUDIO_BASE+3
sta AUDIO_BASE+4
sta AUDIO_BASE+5
sta AUDIO_BASE+6
sta AUDIO_BASE+8
sta AUDIO_BASE+9
sta AUDIO_BASE+10
sta AUDIO_BASE+11
sta AUDIO_BASE+12
sta AUDIO_BASE+13
sta AUDIO_BASE+7
notstart:lda controlsedge
and #select
bne notselect
lda editbuffer1
sta audio_base
lda editbuffer1+1
sta audio_base+1
lda editbuffer1+2
sta audio_base+2
lda editbuffer1+3
sta audio_base+3
lda editbuffer1+4
sta audio_base+4
lda editbuffer1+5
sta audio_base+5
lda editbuffer1+6
sta audio_base+6
lda editbuffer2
sta audio_base+8
lda editbuffer2+1
sta audio_base+9
lda editbuffer2+2
sta audio_base+10
lda editbuffer2+3
sta audio_base+11
lda editbuffer2+4
sta audio_base+12
lda editbuffer2+5
sta audio_base+13
lda editbuffer1+7
sta audio_base+7
and #JOY_DATA_SELECT
bne notselect
lda editbuffer1
sta AUDIO_BASE
lda editbuffer1+1
sta AUDIO_BASE+1
lda editbuffer1+2
sta AUDIO_BASE+2
lda editbuffer1+3
sta AUDIO_BASE+3
lda editbuffer1+4
sta AUDIO_BASE+4
lda editbuffer1+5
sta AUDIO_BASE+5
lda editbuffer1+6
sta AUDIO_BASE+6
lda editbuffer2
sta AUDIO_BASE+8
lda editbuffer2+1
sta AUDIO_BASE+9
lda editbuffer2+2
sta AUDIO_BASE+10
lda editbuffer2+3
sta AUDIO_BASE+11
lda editbuffer2+4
sta AUDIO_BASE+12
lda editbuffer2+5
sta AUDIO_BASE+13
lda editbuffer1+7
sta AUDIO_BASE+7
notselect:lda controlsedge
and #button_a
bne notbuttona
ldy #0
ldy #0
and #JOY_DATA_FIRE_A
bne notbuttona
ldy #0
ldy #0
writea:lda editbuffer1,y
sta (writeaddr),y
iny
cpy #8
bne writea
sta (writeaddr),y
iny
cpy #8
bne writea
writeb:lda editbuffer2-8,y
sta (writeaddr),y
iny
cpy #16
bne writeb
sta (writeaddr),y
iny
cpy #16
bne writeb
notbuttona:lda controlsedge
and #button_b
bne notbuttonb
ldy #0
and #JOY_DATA_FIRE_B
bne notbuttonb
ldy #0
reada:lda (readaddr),y
sta editbuffer1,y
iny
cpy #8
bne reada
sta editbuffer1,y
iny
cpy #8
bne reada
readb:lda (readaddr),y
sta editbuffer2-8,y
iny
cpy #16
bne readb
sta editbuffer2-8,y
iny
cpy #16
bne readb
notbuttonb:
lda controls
sta controlslast
rts
lda JOY_DATA
sta controlslast
rts
.endproc
;-------------------------------------------------------------------------------
.proc printstring
sta psa
stx psa+1
ldx #0
stx psx
sty psy
sta psa
stx psa+1
ldx #0
stx psx
sty psy
printstring2:
ldy #0
lda (psa),y
beq printstring1
ldx psx
stx lcd_x
ldy psy
sty lcd_y
jsr printsign
inc psx
lda psa
clc
adc #1
sta psa
lda psa+1
adc #0
sta psa+1
jmp printstring2
ldy #0
lda (psa),y
beq printstring1
ldx psx
stx LCD_X
ldy psy
sty LCD_Y
jsr printsign
inc psx
lda psa
clc
adc #1
sta psa
lda psa+1
adc #0
sta psa+1
jmp printstring2
printstring1:
rts
rts
.endproc
.proc printstringy
sta psa
stx psa+1
sta psa
stx psa+1
printstring2:
ldy #0
lda (psa),y
beq printstring1
jsr printsign
lda psa
clc
adc #1
sta psa
lda psa+1
adc #0
sta psa+1
jmp printstring2
ldy #0
lda (psa),y
beq printstring1
jsr printsign
lda psa
clc
adc #1
sta psa
lda psa+1
adc #0
sta psa+1
jmp printstring2
printstring1:
rts
rts
.endproc
.proc printhex
pha
lsr
lsr
lsr
lsr
and #$0f
stx temp_x
tax
lda hex2asc,x
ldx temp_x
stx lcd_x
sty lcd_y
jsr printsign
pla
and #$0f
inx
stx temp_x
tax
lda hex2asc,x
ldx temp_x
stx lcd_x
sty lcd_y
jmp printsign
pha
lsr
lsr
lsr
lsr
and #$0f
stx temp_x
tax
lda hex2asc,x
ldx temp_x
stx LCD_X
sty LCD_Y
jsr printsign
pla
and #$0f
inx
stx temp_x
tax
lda hex2asc,x
ldx temp_x
stx LCD_X
sty LCD_Y
jmp printsign
.endproc
.proc printsign
sty temp_y
stx temp_x
sta temp_a
lda temp_a
sta addr
lda #0
sta addr+1
asl addr
rol addr+1
asl addr
rol addr+1
asl addr
rol addr+1
lda addr
clc
adc #<chars
sta addr
lda addr+1
adc #>chars
sta addr+1
ldx #8
ldy #0
sty temp_y
stx temp_x
sta temp_a
lda temp_a
sta addr
lda #0
sta addr+1
asl addr
rol addr+1
asl addr
rol addr+1
asl addr
rol addr+1
lda addr
clc
adc #<chars
sta addr
lda addr+1
adc #>chars
sta addr+1
ldx #8
ldy #0
printsign1:
lda (addr),y
sta lcd_data
iny
dex
bne printsign1
ldx temp_x
ldy temp_y
rts
lda (addr),y
sta LCD_DATA
iny
dex
bne printsign1
ldx temp_x
ldy temp_y
rts
.endproc