Added assembler code files that were left out of the code import

This commit is contained in:
adamdunkels 2006-06-18 07:45:36 +00:00
parent 710b372a2d
commit 3552d70176
13 changed files with 3959 additions and 0 deletions

View file

@ -0,0 +1,16 @@
;---------------------------------------------------------------------
.importzp ptr1, ptr2, ptr3, ptr4, sreg
.importzp sp
.import _vnc_draw_datalen
.import _vnc_draw_dataptr
.import _vnc_draw_bitmapptr
.import _vnc_draw_x
.import _vnc_draw_y
;---------------------------------------------------------------------
.bss
;---------------------------------------------------------------------
.data
;---------------------------------------------------------------------
.code

View file

@ -0,0 +1,986 @@
;---------------------------------------------------------------------
.importzp ptr1, ptr2, ptr3, ptr4, sreg
.importzp sp
.import pushax
.import incsp2
.import _ctk_80col_screencolors
.import _ctk_80col_screenpattern
.import _ctk_80col_lefttab
.import _ctk_80col_righttab
.import _ctk_80col_cursx
.import _ctk_80col_cursy
.import _ctk_80col_color
.import _ctk_80col_underline
.import _ctk_80col_reversed
.import _ctk_80col_yscreenaddr
.import _ctk_80col_yhiresaddr
.import _ctk_80col_windowparams
.import _ctk_80col_bitmapptr
.import _ctk_80col_versionstring
.import _ctk_80col_versionstring_len
.import _ctk_80col_theme
.export _ctk_80col_cclear
.export _ctk_80col_chline
.export _ctk_80col_cputc
.export _ctk_80col_cputsn
.export _ctk_80col_clear_line
.export _ctk_80col_draw_bitmapline
.export _ctk_80col_draw_windowborders
;---------------------------------------------------------------------
ptr5 = sreg
;; Offsets in the theme struct
ulcornerpattern = 8
titlebarpattern = ulcornerpattern+8
urcornerpattern = titlebarpattern+8
rborderpattern = urcornerpattern+8
lrcornerpattern = rborderpattern+8
lowerborderpattern = lrcornerpattern+8
llcornerpattern = lowerborderpattern+8
lborderpattern = llcornerpattern+8
buttonleftpattern = lborderpattern+8
buttonrightpattern = buttonleftpattern+8
.bss
tmp01: .res 1
tmpl: .res 1
tmpf: .res 1
tmpc: .res 1
tmpw: .res 1
tmpptr: .res 2
tmpy: .res 1
tmph: .res 1
;; Window border parameters
w: .res 1
wpw = 0
h: .res 1
wph = 1
clipy1: .res 1
wpclipy1 = 2
clipy2: .res 1
wpclipy2 = 3
color1: .res 1
wpcolor1 = 4
color2: .res 1
wpcolor2 = 5
titlecolor: .res 1
wptitlecolor = 6
titlelen: .res 1
wptitlelen = 7
title: .res 2
wptitle = 8
;---------------------------------------------------------------------
.data
;---------------------------------------------------------------------
.code
setupptrs:
;; Find hires address.
lda _ctk_80col_cursy
asl
tax
lda _ctk_80col_yhiresaddr,x
sta ptr2
lda _ctk_80col_yhiresaddr+1,x
sta ptr2+1
;; Add X coordinate to the hires address.
lda #0
sta ptr1+1
lda _ctk_80col_cursx
asl
rol ptr1+1
; asl
; rol ptr1+1
asl
rol ptr1+1
clc
adc ptr2
and #$f8
sta ptr2
lda ptr2+1
adc ptr1+1
sta ptr2+1
;; Find screen address.
lda _ctk_80col_cursy
asl
tax
lda _ctk_80col_cursx
lsr
clc
adc _ctk_80col_yscreenaddr,x
sta ptr1
lda _ctk_80col_yscreenaddr+1,x
adc #0
sta ptr1+1
;; Turn off interrupts, prepare $01 to store color data in RAM
;; under I/O area.
sei
lda $01
sta tmp01
and #$f8
sta $01
rts
;---------------------------------------------------------------------
restore01:
lda tmp01
sta $01
cli
rts
;---------------------------------------------------------------------
_ctk_80col_cclear:
sta tmpl
cmp #0
bne @norts
rts
@norts:
jsr setupptrs
ldy tmpl
lda _ctk_80col_color
:
sta (ptr1),y
dey
bpl :-
;; Store either $00 or $ff in hires memory, depending on the
;; reversed flag
ldx tmpl
lda _ctk_80col_reversed
beq @noff
lda #$ff
@noff:
sta tmpf
@loop1:
ldy #7
lda tmpf
@loop2:
sta (ptr2),y
dey
bpl @loop2
lda ptr2
clc
adc #8
sta ptr2
bcc @noinc
inc ptr2+1
@noinc:
inc _ctk_80col_cursx
dex
bpl @loop1
jmp restore01
;---------------------------------------------------------------------
_ctk_80col_chline:
sta tmpl
cmp #0
bne @norts
rts
@norts:
jsr setupptrs
;; Store horizontal line pattern in hires memory
ldx tmpl
@loop1:
ldy #0
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$ff
sta (ptr2),y
iny
lda #$ff
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
lda ptr2
clc
adc #8
sta ptr2
bcc @noinc
inc ptr2+1
@noinc:
inc _ctk_80col_cursx
dex
bne @loop1
jmp restore01
;---------------------------------------------------------------------
_ctk_80col_cputc:
sta tmpc
jsr setupptrs
;; Turn on font ROM
lda tmp01
and #$f8
ora #$01
sta $01
lda #0
sta ptr1+1
;; Convert from PETSCII to screen encoding
lda tmpc
eor #$e0
clc
adc #$20
bpl @cont
adc #$40
bpl @cont
eor #$a0
@cont:
ldx _ctk_80col_reversed
beq :+
eor #$80
:
;; Convert to address in character ROM
asl
rol ptr1+1
asl
rol ptr1+1
asl
rol ptr1+1
sta ptr1
lda #$d8
adc ptr1+1
sta ptr1+1
lda _ctk_80col_cursx
and #1
beq @left
;; Print on hires screen, bottom-up. If we should underline,
;; we do this by eor:ing the bottom line with #$ff
ldy #7
lda (ptr1),y
ldx _ctk_80col_underline
beq @rightnounderline
eor #$ff
@rightnounderline:
tax
lda (ptr2),y
and #$f0
ora _ctk_80col_righttab,x
sta (ptr2),y
dey
@rightloop:
lda (ptr1),y
tax
lda (ptr2),y
and #$f0
ora _ctk_80col_righttab,x
sta (ptr2),y
dey
bpl @rightloop
inc _ctk_80col_cursx
jmp restore01
@left:
;; Print on hires screen, bottom-up. If we should underline,
;; we do this by eor:ing the bottom line with #$ff
ldy #7
lda (ptr1),y
ldx _ctk_80col_underline
beq @nounderline
eor #$ff
@nounderline:
tax
lda (ptr2),y
and #$0f
ora _ctk_80col_lefttab,x
sta (ptr2),y
dey
@loop:
lda (ptr1),y
tax
lda (ptr2),y
and #$0f
ora _ctk_80col_lefttab,x
sta (ptr2),y
dey
bpl @loop
inc _ctk_80col_cursx
jmp restore01
;---------------------------------------------------------------------
_ctk_80col_cputsn:
sta tmpl
cmp #0
bne :+
jmp incsp2
:
jsr setupptrs
;; Turn on font ROM
lda tmp01
and #$f8
ora #$01
sta $01
;; Output each character from the string
lda #0
sta tmpc
ldy #0
lda (sp),y
sta ptr3
iny
lda (sp),y
sta ptr3+1
@loop1:
lda #0
sta ptr1+1
ldy tmpc
lda (ptr3),y
bne :+
jmp @end
:
;; Convert from PETSCII to screen encoding
eor #$e0
clc
adc #$20
bpl @cont
adc #$40
bpl @cont
eor #$a0
@cont:
ldx _ctk_80col_reversed
beq :+
eor #$80
:
;; Convert to address in character ROM
asl
rol ptr1+1
asl
rol ptr1+1
asl
rol ptr1+1
sta ptr1
lda #$d8
adc ptr1+1
sta ptr1+1
lda _ctk_80col_cursx
and #1
beq @left
;; Print on hires screen, bottom-up. If we should underline,
;; we do this by eor:ing the bottom line with #$ff
ldy #7
lda (ptr1),y
ldx _ctk_80col_underline
beq @rightnounderline
eor #$ff
@rightnounderline:
tax
lda (ptr2),y
and #$f0
ora _ctk_80col_righttab,x
sta (ptr2),y
dey
@rightloop:
lda (ptr1),y
tax
lda (ptr2),y
and #$f0
ora _ctk_80col_righttab,x
sta (ptr2),y
dey
bpl @rightloop
lda ptr2
clc
adc #8
sta ptr2
bcc :+
inc ptr2+1
:
inc _ctk_80col_cursx
jmp @loopend
@left:
;; Print on hires screen, bottom-up. If we should underline,
;; we do this by eor:ing the bottom line with #$ff
ldy #7
lda (ptr1),y
ldx _ctk_80col_underline
beq @nounderline
eor #$ff
@nounderline:
tax
lda (ptr2),y
and #$0f
ora _ctk_80col_lefttab,x
sta (ptr2),y
dey
@loop:
lda (ptr1),y
tax
lda (ptr2),y
and #$0f
ora _ctk_80col_lefttab,x
sta (ptr2),y
dey
bpl @loop
inc _ctk_80col_cursx
@loopend:
inc tmpc
lda tmpc
cmp tmpl
beq :+
jmp @loop1
:
@end:
jsr restore01
jmp incsp2
;---------------------------------------------------------------------
_ctk_80col_clear_line:
sta tmpl
asl
tax
lda _ctk_80col_yscreenaddr,x
sta ptr1
lda _ctk_80col_yscreenaddr+1,x
sta ptr1+1
lda _ctk_80col_yhiresaddr,x
sta ptr2
lda _ctk_80col_yhiresaddr+1,x
sta ptr2+1
sei
lda $01
sta tmp01
and #$f8
sta $01
ldy #39
ldx tmpl
lda _ctk_80col_screencolors,x
:
sta (ptr1),y
dey
bpl :-
lda tmpl
asl
asl
asl
tax
ldy #0
:
lda _ctk_80col_screenpattern,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+1,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+2,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+3,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+4,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+5,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+6,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+7,x
sta (ptr2),y
iny
bne :-
inc ptr2+1
:
lda _ctk_80col_screenpattern,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+1,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+2,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+3,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+4,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+5,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+6,x
sta (ptr2),y
iny
lda _ctk_80col_screenpattern+7,x
sta (ptr2),y
iny
cpy #$40
bne :-
lda tmpl
cmp #24
bne :+
sta _ctk_80col_cursy
lda #2
sta _ctk_80col_cursx
jsr restore01
lda #<_ctk_80col_versionstring
ldx #>_ctk_80col_versionstring
jsr pushax
lda _ctk_80col_versionstring_len
jmp _ctk_80col_cputsn
:
jmp restore01
;---------------------------------------------------------------------
_ctk_80col_draw_bitmapline:
sta tmpl
cmp #0
bne :+
rts
:
jsr setupptrs
ldy #0
lda _ctk_80col_color
:
sta (ptr1),y
iny
cpy tmpl
bne :-
lda _ctk_80col_bitmapptr
sta ptr1
lda _ctk_80col_bitmapptr+1
sta ptr1+1
ldy #0
ldx #0
:
lda (ptr1),y
sta (ptr2),y
iny
inx
cpx #8
bne :-
ldx #0
dec tmpl
bne :-
jmp restore01
;---------------------------------------------------------------------
_ctk_80col_draw_windowborders:
jsr setupptrs
lda _ctk_80col_windowparams + wpclipy1
beq :+
jmp @nofirstline
:
;; Draw first line of the border, including the window title
;; Start with filling color memory
lda _ctk_80col_windowparams + wpw
sta tmpw
ldy #0
lda _ctk_80col_windowparams + wptitlecolor
:
sta (ptr1),y
iny
cpy tmpw
bcc :-
dec tmpw
;; Set color for upper right corner
sta (ptr1),y
iny
sta (ptr1),y
;; Turn on font ROM for drawing the title
lda tmp01
and #$f8
ora #$01
sta $01
;; Use a temporary pointer (ptr3) rather than ptr2 so we can
;; reuse it later.
lda ptr2
sta ptr3
lda ptr2+1
sta ptr3+1
;; Draw upper left corner
ldy #7
:
lda _ctk_80col_theme+ulcornerpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
clc
adc #$8
sta ptr3
bcc :+
inc ptr3+1
:
;; Draw window title bar pattern
@titlebarloop:
ldy #7
:
lda _ctk_80col_theme+titlebarpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
clc
adc #$8
sta ptr3
bcc :+
inc ptr3+1
:
;; Loop until we are three characters away from right border
;; to avoid flickering since we would be overwriting the close
;; button.
dec tmpw
bpl @titlebarloop
;; Draw upper right corner piece
ldy #7
:
lda _ctk_80col_theme+urcornerpattern,y
sta (ptr3),y
dey
bpl :-
@nofirstline:
ldx _ctk_80col_windowparams + wph
inx
stx tmph
;; Draw left and right borders
;; Fill color memory (pointer in ptr1, setup by setupptrs)
;; First check how much we actually should draw by inspecting
;; the clipy1 and clipy2 fields in the _ctk_80col_windowparams
;; structure
lda #1
sta tmpy
ldx _ctk_80col_windowparams + wpclipy1
@clipy1loop:
cpx #0
beq @clipy1loopend
lda ptr1
clc
adc #$28
sta ptr1
bcc :+
inc ptr1+1
:
lda ptr3
clc
adc #$40
sta ptr3
lda ptr3+1
adc #1
sta ptr3+1
inc tmpy
dex
jmp @clipy1loop
@clipy1loopend:
lda ptr1
clc
adc #$28
sta ptr1
bcc :+
inc ptr1+1
:
ldx tmpy
ldy _ctk_80col_windowparams + wpw
iny
sty tmpw
@bordercloop:
cpx _ctk_80col_windowparams + wpclipy2
beq @bordercloopend
ldy tmpw
lda _ctk_80col_windowparams + wpcolor2
sta (ptr1),y
ldy #0
lda _ctk_80col_windowparams + wpcolor1
sta (ptr1),y
lda ptr1
clc
adc #$28
sta ptr1
bcc :+
inc ptr1+1
:
inx
cpx tmph
bcc @bordercloop
beq @bordercloop
@bordercloopend:
;; Fill color memory for lower border, if clipy2 allows
cpx _ctk_80col_windowparams + wpclipy2
beq @noclowerborder
lda ptr1
sec
sbc #$28
sta ptr1
bcs :+
dec ptr1+1
:
ldy _ctk_80col_windowparams + wpw
lda _ctk_80col_windowparams + wpcolor2
@lbordercloop:
sta (ptr1),y
dey
bne @lbordercloop
@noclowerborder:
;; Draw right border
ldx tmpy
@rborderloop:
cpx _ctk_80col_windowparams + wpclipy2
beq @rborderloopend
lda ptr3
clc
adc #$40
sta ptr3
lda ptr3+1
adc #1
sta ptr3+1
ldy #7
:
lda _ctk_80col_theme+rborderpattern,y
sta (ptr3),y
dey
bpl :-
inx
cpx tmph
bne @rborderloop
@rborderloopend:
cpx _ctk_80col_windowparams + wpclipy2
beq @norbordercorner
lda ptr3
clc
adc #$40
sta ptr3
lda ptr3+1
adc #1
sta ptr3+1
;; Draw lower right corner, if clipy2 allows it
ldy #7
:
lda _ctk_80col_theme+lrcornerpattern,y
sta (ptr3),y
dey
bpl :-
@norbordercorner:
stx tmpy
;; Draw lower border
ldx _ctk_80col_windowparams + wpw
@lowerborderloop:
lda ptr3
sec
sbc #$8
sta ptr3
bcs :+
dec ptr3+1
:
lda tmpy
cmp _ctk_80col_windowparams + wpclipy2
beq @nolowerborder
ldy #7
:
lda _ctk_80col_theme+lowerborderpattern,y
sta (ptr3),y
dey
bpl :-
@nolowerborder:
dex
bne @lowerborderloop
lda ptr3
sec
sbc #$8
sta ptr3
bcs :+
dec ptr3+1
:
ldx tmpy
cpx tmph
bne @nolbordercorner
;; Draw lower left corner, if clipy2 allows it
ldy #7
:
lda _ctk_80col_theme+llcornerpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
sec
sbc #$40
sta ptr3
lda ptr3+1
sbc #1
sta ptr3+1
@nolbordercorner:
;; Draw left border
@lborderloop:
cpx #1
beq @lborderloopend
cpx _ctk_80col_windowparams + wpclipy1
bcc @lborderloopend
ldy #7
:
lda _ctk_80col_theme+lborderpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
sec
sbc #$40
sta ptr3
lda ptr3+1
sbc #1
sta ptr3+1
dex
jmp @lborderloop
@lborderloopend:
jmp restore01
;---------------------------------------------------------------------

View file

@ -0,0 +1,934 @@
;---------------------------------------------------------------------
.importzp ptr1, ptr2, ptr3, ptr4, sreg
.importzp sp
.import incsp2
.import _ctk_hires_cursx
.import _ctk_hires_cursy
.import _ctk_hires_color
.import _ctk_hires_underline
.import _ctk_hires_reversed
.import _ctk_hires_yscreenaddr
.import _ctk_hires_yhiresaddr
.import _ctk_hires_windowparams
.import _ctk_hires_bitmapptr
.import _ctk_hires_theme
.export _ctk_hires_cclear
.export _ctk_hires_chline
.export _ctk_hires_cputc
.export _ctk_hires_cputsn
.export _ctk_hires_draw_buttonleft
.export _ctk_hires_draw_buttonright
.export _ctk_hires_draw_windowborders
.export _ctk_hires_draw_bitmapline
;---------------------------------------------------------------------
ptr5 = sreg
;; Offsets in the theme struct
ulcornerpattern = 8
titlebarpattern = ulcornerpattern+8
urcornerpattern = titlebarpattern+8
rborderpattern = urcornerpattern+8
lrcornerpattern = rborderpattern+8
lowerborderpattern = lrcornerpattern+8
llcornerpattern = lowerborderpattern+8
lborderpattern = llcornerpattern+8
buttonleftpattern = lborderpattern+8
buttonrightpattern = buttonleftpattern+8
.bss
tmp01: .res 1
tmpl: .res 1
tmpf: .res 1
tmpc: .res 1
tmpw: .res 1
tmpptr: .res 2
tmpy: .res 1
tmph: .res 1
;; Window border parameters
w: .res 1
wpw = 0
h: .res 1
wph = 1
clipy1: .res 1
wpclipy1 = 2
clipy2: .res 1
wpclipy2 = 3
color1: .res 1
wpcolor1 = 4
color2: .res 1
wpcolor2 = 5
titlelen: .res 1
wptitlelen = 6
title: .res 2
wptitle = 7
;---------------------------------------------------------------------
.data
;---------------------------------------------------------------------
.code
setupptrs:
;; Find hires address.
lda _ctk_hires_cursy
asl
tax
lda _ctk_hires_yhiresaddr,x
sta ptr2
lda _ctk_hires_yhiresaddr+1,x
sta ptr2+1
;; Add X coordinate to the hires address.
lda #0
sta ptr1+1
lda _ctk_hires_cursx
asl
rol ptr1+1
asl
rol ptr1+1
asl
rol ptr1+1
clc
adc ptr2
sta ptr2
lda ptr2+1
adc ptr1+1
sta ptr2+1
;; Find screen address.
lda _ctk_hires_cursy
asl
tax
lda _ctk_hires_yscreenaddr,x
clc
adc _ctk_hires_cursx
sta ptr1
lda _ctk_hires_yscreenaddr+1,x
adc #0
sta ptr1+1
;; Turn off interrupts, prepare $01 to store color data in RAM
;; under I/O area.
sei
lda $01
sta tmp01
and #$f8
sta $01
rts
;---------------------------------------------------------------------
restore01:
lda tmp01
sta $01
cli
rts
;---------------------------------------------------------------------
_ctk_hires_cclear:
sta tmpl
cmp #0
bne @norts
rts
@norts:
jsr setupptrs
;; Store color value in color memory
ldy tmpl
dey
lda _ctk_hires_color
@loop0:
sta (ptr1),y
dey
bpl @loop0
;; Store either $00 or $ff in hires memory, depending on the
;; reversed flag
ldx tmpl
lda _ctk_hires_reversed
beq @noff
lda #$ff
@noff:
sta tmpf
@loop1:
ldy #7
lda tmpf
@loop2:
sta (ptr2),y
dey
bpl @loop2
lda ptr2
clc
adc #8
sta ptr2
bcc @noinc
inc ptr2+1
@noinc:
inc _ctk_hires_cursx
dex
bne @loop1
jmp restore01
;---------------------------------------------------------------------
_ctk_hires_chline:
sta tmpl
cmp #0
bne @norts
rts
@norts:
jsr setupptrs
;; Store color value in color memory
ldy tmpl
dey
lda _ctk_hires_color
@loop0:
sta (ptr1),y
dey
bpl @loop0
;; Store horizontal line pattern in hires memory
ldx tmpl
@loop1:
ldy #0
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$ff
sta (ptr2),y
iny
lda #$ff
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
iny
lda #$00
sta (ptr2),y
lda ptr2
clc
adc #8
sta ptr2
bcc @noinc
inc ptr2+1
@noinc:
inc _ctk_hires_cursx
dex
bne @loop1
jmp restore01
;---------------------------------------------------------------------
_ctk_hires_cputc:
sta tmpc
jsr setupptrs
ldy #0
lda _ctk_hires_color
sta (ptr1),y
;; Turn on font ROM
lda tmp01
and #$f8
ora #$01
sta $01
lda #0
sta ptr1+1
;; Convert from PETSCII to screen encoding
lda tmpc
eor #$e0
clc
adc #$20
bpl @cont
adc #$40
bpl @cont
eor #$a0
@cont:
ldx _ctk_hires_reversed
beq :+
eor #$80
:
;; Convert to address in character ROM
asl
rol ptr1+1
asl
rol ptr1+1
asl
rol ptr1+1
sta ptr1
lda #$d8
adc ptr1+1
sta ptr1+1
;; Print on hires screen, bottom-up. If we should underline,
;; we do this by eor:ing the bottom line with #$ff
ldy #7
lda (ptr1),y
ldx _ctk_hires_underline
beq @nounderline
eor #$ff
@nounderline:
sta (ptr2),y
dey
@loop:
lda (ptr1),y
sta (ptr2),y
dey
bpl @loop
inc _ctk_hires_cursx
jmp restore01
;---------------------------------------------------------------------
_ctk_hires_cputsn:
sta tmpl
cmp #0
bne :+
rts
:
jsr setupptrs
ldy tmpl
dey
lda _ctk_hires_color
@loop0:
sta (ptr1),y
dey
bpl @loop0
;; Turn on font ROM
lda tmp01
and #$f8
ora #$01
sta $01
;; Output each character from the string
lda #0
sta tmpc
ldy #0
lda (sp),y
sta ptr3
iny
lda (sp),y
sta ptr3+1
@loop1:
lda #0
sta ptr1+1
ldy tmpc
lda (ptr3),y
beq @end
;; Convert from PETSCII to screen encoding
eor #$e0
clc
adc #$20
bpl @cont
adc #$40
bpl @cont
eor #$a0
@cont:
ldx _ctk_hires_reversed
beq :+
eor #$80
:
;; Convert to address in character ROM
asl
rol ptr1+1
asl
rol ptr1+1
asl
rol ptr1+1
sta ptr1
lda #$d8
adc ptr1+1
sta ptr1+1
;; Print on hires screen, bottom-up. If we should underline,
;; we do this by eor:ing the bottom line with #$ff
ldy #7
lda (ptr1),y
ldx _ctk_hires_underline
beq @nounderline
eor #$ff
@nounderline:
sta (ptr2),y
dey
@loop:
lda (ptr1),y
sta (ptr2),y
dey
bpl @loop
inc _ctk_hires_cursx
lda ptr2
clc
adc #8
sta ptr2
bcc :+
inc ptr2+1
:
inc tmpc
lda tmpc
cmp tmpl
bne @loop1
@end:
jsr restore01
jmp incsp2
;---------------------------------------------------------------------
_ctk_hires_draw_windowborders:
jsr setupptrs
lda _ctk_hires_windowparams + wpclipy1
beq :+
jmp @nofirstline
:
;; Draw first line of the border, including the window title
;; Start with filling color memory
ldy _ctk_hires_windowparams + wpw
iny
lda _ctk_hires_windowparams + wpcolor1
sta (ptr1),y
dey
dey
dey
sty tmpw
ldy _ctk_hires_windowparams + wptitlelen
iny
iny
iny
:
sta (ptr1),y
iny
cpy tmpw
bcc :-
inc tmpw
;; Set color for upper left corner
ldy #0
lda _ctk_hires_windowparams + wpcolor1
sta (ptr1),y
;; Turn on font ROM for drawing the title
lda tmp01
and #$f8
ora #$01
sta $01
;; Use a temporary pointer (ptr3) rather than ptr2 so we can
;; reuse it later.
lda ptr2
sta ptr3
lda ptr2+1
sta ptr3+1
;; Draw upper left corner
ldy #7
:
lda _ctk_hires_theme+ulcornerpattern,y
sta (ptr3),y
dey
bpl :-
;; Draw first empty char left of the title
ldy #8
lda #0
:
; sta (ptr3),y
iny
cpy #$10
bne :-
lda ptr3
clc
adc #$10
sta ptr3
bcc :+
inc ptr3+1
:
dec tmpw
;; Draw the title
lda _ctk_hires_windowparams + wptitle
sta ptr4
lda _ctk_hires_windowparams + wptitle+1
sta ptr4+1
lda #0
sta tmpc
@titleloop:
lda #0
sta ptr5+1
ldy tmpc
lda (ptr4),y
;; Convert from PETSCII to screen encoding
eor #$e0
clc
adc #$20
bpl @cont
adc #$40
bpl @cont
eor #$a0
@cont:
;; Convert to address in character ROM
asl
rol ptr5+1
asl
rol ptr5+1
asl
rol ptr5+1
sta ptr5
lda #$d8
adc ptr5+1
sta ptr5+1
;; Print on hires screen, character by character, bottom-up.
ldy #7
:
lda (ptr5),y
; sta (ptr3),y
dey
bpl :-
lda ptr3
clc
adc #8
sta ptr3
bcc :+
inc ptr3+1
:
dec tmpw
inc tmpc
lda tmpc
cmp _ctk_hires_windowparams + wptitlelen
bne @titleloop
;; Draw empty char after the title
ldy #7
lda #0
:
; sta (ptr3),y
dey
bpl :-
lda ptr3
clc
adc #$8
sta ptr3
bcc :+
inc ptr3+1
:
dec tmpw
;; Draw window title bar pattern
@titlebarloop:
ldy #7
:
lda _ctk_hires_theme+titlebarpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
clc
adc #$8
sta ptr3
bcc :+
inc ptr3+1
:
;; Loop until we are three characters away from right border
;; to avoid flickering since we would be overwriting the close
;; button.
dec tmpw
lda tmpw
cmp #3
bcs @titlebarloop
lda ptr3
clc
adc #$18
sta ptr3
bcc :+
inc ptr3+1
:
;; Draw upper right corner piece
ldy #7
:
lda _ctk_hires_theme+urcornerpattern,y
sta (ptr3),y
dey
bpl :-
@nofirstline:
ldx _ctk_hires_windowparams + wph
inx
stx tmph
;; Draw left and right borders
;; Fill color memory (pointer in ptr1, setup by setupptrs)
;; First check how much we actually should draw by inspecting
;; the clipy1 and clipy2 fields in the _ctk_hires_windowparams
;; structure
lda #1
sta tmpy
ldx _ctk_hires_windowparams + wpclipy1
@clipy1loop:
cpx #0
beq @clipy1loopend
lda ptr1
clc
adc #$28
sta ptr1
bcc :+
inc ptr1+1
:
lda ptr3
clc
adc #$40
sta ptr3
lda ptr3+1
adc #1
sta ptr3+1
inc tmpy
dex
jmp @clipy1loop
@clipy1loopend:
lda ptr1
clc
adc #$28
sta ptr1
bcc :+
inc ptr1+1
:
ldx tmpy
ldy _ctk_hires_windowparams + wpw
iny
sty tmpw
@bordercloop:
cpx _ctk_hires_windowparams + wpclipy2
beq @bordercloopend
ldy tmpw
lda _ctk_hires_windowparams + wpcolor2
sta (ptr1),y
ldy #0
lda _ctk_hires_windowparams + wpcolor1
sta (ptr1),y
lda ptr1
clc
adc #$28
sta ptr1
bcc :+
inc ptr1+1
:
inx
cpx tmph
bcc @bordercloop
beq @bordercloop
@bordercloopend:
;; Fill color memory for lower border, if clipy2 allows
cpx _ctk_hires_windowparams + wpclipy2
beq @noclowerborder
lda ptr1
sec
sbc #$28
sta ptr1
bcs :+
dec ptr1+1
:
ldy _ctk_hires_windowparams + wpw
lda _ctk_hires_windowparams + wpcolor2
@lbordercloop:
sta (ptr1),y
dey
bne @lbordercloop
@noclowerborder:
;; Draw right border
ldx tmpy
@rborderloop:
cpx _ctk_hires_windowparams + wpclipy2
beq @rborderloopend
lda ptr3
clc
adc #$40
sta ptr3
lda ptr3+1
adc #1
sta ptr3+1
ldy #7
:
lda _ctk_hires_theme+rborderpattern,y
sta (ptr3),y
dey
bpl :-
inx
cpx tmph
bne @rborderloop
@rborderloopend:
cpx _ctk_hires_windowparams + wpclipy2
beq @norbordercorner
lda ptr3
clc
adc #$40
sta ptr3
lda ptr3+1
adc #1
sta ptr3+1
;; Draw lower right corner, if clipy2 allows it
ldy #7
:
lda _ctk_hires_theme+lrcornerpattern,y
sta (ptr3),y
dey
bpl :-
@norbordercorner:
stx tmpy
;; Draw lower border
ldx _ctk_hires_windowparams + wpw
@lowerborderloop:
lda ptr3
sec
sbc #$8
sta ptr3
bcs :+
dec ptr3+1
:
lda tmpy
cmp _ctk_hires_windowparams + wpclipy2
beq @nolowerborder
ldy #7
:
lda _ctk_hires_theme+lowerborderpattern,y
sta (ptr3),y
dey
bpl :-
@nolowerborder:
dex
bne @lowerborderloop
lda ptr3
sec
sbc #$8
sta ptr3
bcs :+
dec ptr3+1
:
ldx tmpy
cpx tmph
bne @nolbordercorner
;; Draw lower left corner, if clipy2 allows it
ldy #7
:
lda _ctk_hires_theme+llcornerpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
sec
sbc #$40
sta ptr3
lda ptr3+1
sbc #1
sta ptr3+1
@nolbordercorner:
;; Draw left border
@lborderloop:
cpx #1
beq @lborderloopend
cpx _ctk_hires_windowparams + wpclipy1
bcc @lborderloopend
ldy #7
:
lda _ctk_hires_theme+lborderpattern,y
sta (ptr3),y
dey
bpl :-
lda ptr3
sec
sbc #$40
sta ptr3
lda ptr3+1
sbc #1
sta ptr3+1
dex
jmp @lborderloop
@lborderloopend:
jmp restore01
;---------------------------------------------------------------------
_ctk_hires_draw_buttonleft:
jsr setupptrs
ldy #0
lda _ctk_hires_color
sta (ptr1),y
:
lda _ctk_hires_theme+buttonleftpattern,y
sta (ptr2),y
iny
cpy #8
bne :-
jmp restore01
;---------------------------------------------------------------------
_ctk_hires_draw_buttonright:
jsr setupptrs
ldy #0
lda _ctk_hires_color
sta (ptr1),y
:
lda _ctk_hires_theme+buttonrightpattern,y
sta (ptr2),y
iny
cpy #8
bne :-
jmp restore01
;---------------------------------------------------------------------
_ctk_hires_draw_bitmapline:
sta tmpl
cmp #0
bne :+
rts
:
jsr setupptrs
ldy #0
lda _ctk_hires_color
:
sta (ptr1),y
iny
cpy tmpl
bne :-
lda _ctk_hires_bitmapptr
sta ptr1
lda _ctk_hires_bitmapptr+1
sta ptr1+1
ldy #0
ldx #0
:
lda (ptr1),y
sta (ptr2),y
iny
inx
cpx #8
bne :-
ldx #0
dec tmpl
bne :-
jmp restore01
;---------------------------------------------------------------------

View file

@ -0,0 +1,149 @@
;---------------------------------------------------------------------
;; The 1351 mouse code was taken from the CC65 libraries,
;; written by Ullrich von Bassewitz
;---------------------------------------------------------------------
.macpack generic
.import _ctk_mouse_joyx, _ctk_mouse_joyy
.import _ctk_mouse_firebutton
.export _ctk_mouse_1351
;---------------------------------------------------------------------
.bss
OldValue: .res 1 ; Temp for MoveCheck routine
NewValue: .res 1 ; Temp for MoveCheck routine
YCorr: .res 1 ; Correction for Y coordinate
OldPotX: .res 1 ; Old hw counter values
OldPotY: .res 1
SID_ADConv1 = $D419
SID_ADConv2 = $D41A
CIA1_PRA = $DC00
CIA1_PRB = $DC01
CIA1_DDRB = $DC03
;---------------------------------------------------------------------
.data
XMin: .word 0 ; X1 value of bounding box
YMin: .word 0 ; Y1 value of bounding box
XMax: .word 319 ; X2 value of bounding box
YMax: .word 199 ; Y2 value of bounding box
;---------------------------------------------------------------------
.code
;---------------------------------------------------------------------
;---------------------------------------------------------------------
;; Most of the mouse code is taken from the CC65 libraries written by
;; Ullrich von Bassewitz
MoveCheck:
sty OldValue
sta NewValue
ldx #$00
sub OldValue ; a = mod64 (new - old)
and #%01111111
cmp #%01000000 ; if (a > 0)
bcs @L1 ;
lsr a ; a /= 2;
beq @L2 ; if (a != 0)
ldy NewValue ; y = NewValue
rts ; return
@L1: ora #%11000000 ; else or in high order bits
cmp #$FF ; if (a != -1)
beq @L2
sec
ror a ; a /= 2
dex ; high byte = -1 (X = $FF)
ldy NewValue
rts
@L2: txa ; A = $00
rts
;---------------------------------------------------------------------
_ctk_mouse_1351:
lda SID_ADConv1 ; Get mouse X movement
ldy OldPotX
jsr MoveCheck ; Calculate movement vector
sty OldPotX
; Calculate the new X coordinate (--> a/y)
add _ctk_mouse_joyx
tay ; Remember low byte
txa
adc _ctk_mouse_joyx+1
tax
; Limit the X coordinate to the bounding box
cpy XMin
sbc XMin+1
bpl @L1
ldy XMin
ldx XMin+1
jmp @L2
@L1: txa
cpy XMax
sbc XMax+1
bmi @L2
ldy XMax
ldx XMax+1
@L2: sty _ctk_mouse_joyx
stx _ctk_mouse_joyx+1
; Calculate the Y movement vector
lda SID_ADConv2 ; Get mouse Y movement
ldy OldPotY
jsr MoveCheck ; Calculate movement
sty OldPotY
; Calculate the new Y coordinate (--> a/y)
sta OldValue
lda _ctk_mouse_joyy
sub OldValue
tay
stx OldValue
lda _ctk_mouse_joyy+1
sbc OldValue
tax
cpy YMin
sbc YMin+1
bpl @L3
ldy YMin
ldx YMin+1
jmp @L4
@L3: txa
cpy YMax
sbc YMax+1
bmi @L4
ldy YMax
ldx YMax+1
@L4: sty _ctk_mouse_joyy
stx _ctk_mouse_joyy+1
;; Get mouse button
lda #$7F
sta CIA1_PRA
lda CIA1_PRB ; Read joystick #0
ldx #0
and #$1F
eor #$1F
ora _ctk_mouse_firebutton
sta _ctk_mouse_firebutton
lda #0
sta CIA1_PRA
sta CIA1_DDRB
rts
;---------------------------------------------------------------------

View file

@ -0,0 +1,48 @@
;---------------------------------------------------------------------
;; The 1351 mouse code was taken from the CC65 libraries,
;; written by Ullrich von Bassewitz
;---------------------------------------------------------------------
.macpack generic
.import _ctk_mouse_joyx, _ctk_mouse_joyy
.import _ctk_mouse_firebutton
.export _ctk_mouse_asm_irq
.import _ctk_mouse_joy, _ctk_mouse_1351
;---------------------------------------------------------------------
;---------------------------------------------------------------------
.code
;---------------------------------------------------------------------
_ctk_mouse_asm_irq:
lda #0
sta _ctk_mouse_firebutton
jsr _ctk_mouse_joy
;; jsr_ctk_mouse_1351
; lda _ctk_mouse_joybutton
; ora _ctk_mouse_1351button
; sta _ctk_mouse_firebutton
lda _ctk_mouse_joyy
clc
adc #$32
sta $d001
sta $d003
lda _ctk_mouse_joyx
clc
adc #$18
sta $d000
sta $d002
lda #0
adc _ctk_mouse_joyx+1
and #1
beq :+
lda #3
:
sta $d010
jmp $ea31

View file

@ -0,0 +1,135 @@
;---------------------------------------------------------------------
.macpack generic
.import _ctk_mouse_joyx, _ctk_mouse_joyy
.import _ctk_mouse_firebutton
.export _ctk_mouse_joy
;---------------------------------------------------------------------
.bss
lastjoydy: .res 1
lastjoydx: .res 1
joydycnt: .res 1
joydxcnt: .res 1
;---------------------------------------------------------------------
.code
;---------------------------------------------------------------------
_ctk_mouse_joy:
ldy $dc02
lda #0
sta $dc02
lda $dc00
sty $dc02
ldy #0
ldx #0
lsr
bcs nodey
dey
nodey:
lsr
bcs noiny
iny
noiny:
lsr
bcs nodex
dex
nodex:
lsr
bcs noinx
inx
noinx:
and #1
eor #1
ora _ctk_mouse_firebutton
sta _ctk_mouse_firebutton
cpy lastjoydy
sty lastjoydy
bne noydy
tya
pha
inc joydycnt
lda joydycnt
cmp #$1f
bmi nostajoydycnt
lda #$20
sta joydycnt
nostajoydycnt:
lsr
lsr
lsr
lsr
tay
pla
asldeyloop:
asl
dey
bpl asldeyloop
tay
jmp ydy
noydy:
lda #0
sta joydycnt
ydy:
tya
clc
adc _ctk_mouse_joyy
cmp #240
bcc :+
lda #0
:
cmp #200
bcc :+
lda #199
:
sta _ctk_mouse_joyy
cpx lastjoydx
stx lastjoydx
bne noxdx
txa
pha
inc joydxcnt
lda joydxcnt
cmp #$1f
bmi nostajoydxcnt
lda #$20
sta joydxcnt
nostajoydxcnt:
lsr
lsr
lsr
lsr
tax
pla
asldexloop:
asl
dex
bpl asldexloop
tax
jmp xdx
noxdx:
lda #0
sta joydxcnt
xdx:
txa
clc
adc _ctk_mouse_joyx
sta _ctk_mouse_joyx
php
lda #$ff
cpx #0
bmi nolda02
lda #0
nolda02:
plp
adc _ctk_mouse_joyx+1
sta _ctk_mouse_joyx+1
rts

View file

@ -0,0 +1,245 @@
;---------------------------------------------------------------------
.importzp ptr1
.importzp sp
.import __ZP_START__
.import _mtarch_asm_threadstack
.import _mtarch_asm_threadsp
.import _mtarch_asm_threadspreg
.import _mtarch_asm_threadzp
.export _mtarch_asm_exec
.export _mtarch_yield
.export _mtarch_asm_start
.export _mtarch_pstart, _mtarch_pstop
;---------------------------------------------------------------------
.bss
kernelsp: .res 2
kernelspreg: .res 1
oldirq: .res 2
zpsize = 32
.code
;---------------------------------------------------------------------
;; Switch to thread defined by threadsp, threadstack and threadspreg.
;; The kernel stack is swapped onto the threadstack, and the
;; sp and spreg are saved to the local variables "kernelsp" and
;; "kernelspreg". Also, the zeropage variables are saved.
_mtarch_asm_exec:
sei
;; Save current stack pointer
lda sp
sta kernelsp
lda sp+1
sta kernelsp+1
tsx
stx kernelspreg
lda _mtarch_asm_threadzp
sta ptr1
lda _mtarch_asm_threadzp+1
sta ptr1+1
ldy #0
:
lda <__ZP_START__,y
tax
lda (ptr1),y
sta <__ZP_START__,y
txa
sta (ptr1),y
iny
cpy #zpsize
bne :-
lda _mtarch_asm_threadstack
sta ptr1
lda _mtarch_asm_threadstack+1
sta ptr1+1
ldy kernelspreg ; determine the smallest of the two stack pointers,
cpy _mtarch_asm_threadspreg ; as we only need to swap the used part of the stack
bcc :+
ldy _mtarch_asm_threadspreg
:
lda $0100,y
tax
lda (ptr1),y
sta $0100,y
txa
sta (ptr1),y
iny
bne :-
lda _mtarch_asm_threadsp
sta sp
lda _mtarch_asm_threadsp+1
sta sp+1
ldx _mtarch_asm_threadspreg
txs
; jsr _mtarch_pstart
lda $0314
sta oldirq
lda $0315
sta oldirq+1
lda #<irq
sta $0314
lda #>irq
sta $0315
pla
tay
pla
tax
pla
rti
;; Switch from thread defined by threadsp, threadstack and threadspreg.
;; The kernel stack is swapped back from the threadstack, and the
;; sp and spreg are restored from the local variables "kernelsp" and
;; "kernelspreg".
yield:
sei
lda sp
sta _mtarch_asm_threadsp
lda sp+1
sta _mtarch_asm_threadsp+1
tsx
stx _mtarch_asm_threadspreg
lda _mtarch_asm_threadzp
sta ptr1
lda _mtarch_asm_threadzp+1
sta ptr1+1
ldy kernelspreg ; determine the smallest of the two stack pointers,
cpy _mtarch_asm_threadspreg ; as we only need to swap the used part of the stack
bcc :+
ldy _mtarch_asm_threadspreg
:
lda <__ZP_START__,y
tax
lda (ptr1),y
sta <__ZP_START__,y
txa
sta (ptr1),y
iny
cpy #zpsize
bne :-
lda _mtarch_asm_threadstack
sta ptr1
lda _mtarch_asm_threadstack+1
sta ptr1+1
ldy #0
:
lda $0100,y
tax
lda (ptr1),y
sta $0100,y
txa
sta (ptr1),y
iny
bne :-
lda kernelsp
sta sp
lda kernelsp+1
sta sp+1
ldx kernelspreg
txs
cli
rts
;---------------------------------------------------------------------
;; Simulate an IRQ by pushing CPU status and CPu registers
;; onto the stack. Then call the yield function to yield the
;; process.
_mtarch_yield:
php
pha
txa
pha
tya
pha
tsx
; the rts adds 1 to the PC
; saved on the stack. We want
lda $0105,x ; the stack to look like is would
clc ; do inside of an interrupt.
adc #1 ; (this is what the 'rts' does,
sta $0105,x ; but not the 'rti')
lda $0106,x
adc #0
sta $0106,x
jmp yield
;---------------------------------------------------------------------
_mtarch_asm_start:
lda _mtarch_asm_threadzp
sta ptr1
lda _mtarch_asm_threadzp+1
sta ptr1+1
ldy #0
:
lda <__ZP_START__,y
sta (ptr1),y
iny
cpy #zpsize
bne :-
rts
;---------------------------------------------------------------------
irq:
lda oldirq
sta $0314
lda oldirq+1
sta $0315
jmp yield
;---------------------------------------------------------------------
;; Setup preemption IRQ
_mtarch_pstart:
sei
lda $0314
sta oldirq
lda $0315
sta oldirq+1
lda #<irq
sta $0314
lda #>irq
sta $0315
cli
rts
;---------------------------------------------------------------------
_mtarch_pstop:
sei
lda oldirq
sta $0314
lda oldirq+1
sta $0315
cli
rts
;---------------------------------------------------------------------

View file

@ -0,0 +1,7 @@
.import __curunit
.constructor saveunit, 32
.code
saveunit:
lda $ba
sta __curunit
rts

View file

@ -0,0 +1,505 @@
.export _c64_dio_asm_init
.export _c64_dio_asm_read_block
.export _c64_dio_asm_write_block
.export _c64_dio_asm_track, _c64_dio_asm_sector
.export _c64_dio_asm_ptr
.importzp ptr1, ptr2
;; job code $80 read, $90 write
ciout = $ffa8
listen = $ffb1
second = $ff93
unlsn = $ffae
nbytes = 34
esc = $42
blockread = 1
blockwrite = 2
errok = 0
errerr = 1
.data
_c64_dio_asm_track: .byte 0
_c64_dio_asm_sector: .byte 0
_c64_dio_asm_ptr: .byte 0,0
.code
;---------------------------------------
_c64_dio_asm_read_block:
lda #blockread
jsr send
lda _c64_dio_asm_track
jsr send
lda _c64_dio_asm_sector
jsr send
jsr recv
cmp #errok
bne readerr
lda _c64_dio_asm_ptr
sta ptr1
lda _c64_dio_asm_ptr+1
sta ptr1+1
ldy #0
readl:
jsr recv
sta (ptr1),y
iny
bne readl
clc
lda #0
tax
rts
readerr:
; sta $07c0
jsr recv
; sta $07c1
ldx #0
rts
;---------------------------------------
_c64_dio_asm_write_block:
lda #blockwrite
jsr send
lda _c64_dio_asm_track
jsr send
lda _c64_dio_asm_sector
jsr send
lda _c64_dio_asm_ptr
sta ptr1
lda _c64_dio_asm_ptr+1
sta ptr1+1
ldy #0
writel:
lda (ptr1),y
jsr send
iny
bne writel
jsr recv
cmp #errok
bne writeerr
lda #0
tax
rts
writeerr:
; sta $07c0
jsr recv
; sta $07c1
ldx #0
rts
;---------------------------------------
_c64_dio_asm_init:
sta devnr
lda #$00
sta drvmem
lda #$05
sta drvmem+1
lda #<drive
sta ptr1
lda #>drive
sta ptr1+1
; lda devnr
; ldx #<icmd
; ldy #>icmd
; jsr drvcmd
; jsr unlsn
mwl:
lda devnr
ldx #<mwcmd
ldy #>mwcmd
jsr drvcmd
ldy #0
lda (ptr1),y
jsr ciout
iny
cpy #nbytes
bne *-8
jsr unlsn
lda drvmem
clc
adc #nbytes
sta drvmem
lda drvmem+1
adc #0
sta drvmem+1
lda ptr1
clc
adc #nbytes
sta ptr1
tax
lda ptr1+1
adc #0
sta ptr1+1
cpx #<driveend
sbc #>driveend
bcc mwl
lda devnr
ldx #<mecmd
ldy #>mecmd
jsr drvcmd
jsr unlsn
rts
;---------------------------------------
drvcmd:
stx ptr2
sty ptr2+1
jsr listen
lda #$6f
jsr second
ldy #0
lda (ptr2),y
sta drvcmdcmp+1
inc ptr2
bne *+4
inc ptr2+1
ldy #0
lda (ptr2),y
jsr ciout
iny
drvcmdcmp: cpy #0
bne *-8
rts
;---------------------------------------
devnr: .byte 8
mwcmd: .byte 6
.byte $4d, $2d, $57
drvmem: .word $0500
.byte nbytes
.byte 0
mecmd: .byte 2
.byte $55, $33
.byte 0
;---------------------------------------
send:
sta ptr2
ldx #7
sendl:
lsr ptr2
lda $dd00
and #$df
ora #$10
bcc *+4
eor #$30
sta $dd00
lda #$c0
bit $dd00
bne *-3
lda $dd00
and #$cf
sta $dd00
lda $dd00
and #$c0
eor #$c0
bne *-7
dex
bpl sendl
ldx $d020
lda #1
sta $d020
stx $d020
rts
;---------------------------------------
recv:
ldx $d020
lda #0
sta $d020
stx $d020
ldx #7
recvl:
lda $dd00
and #$c0
eor #$c0
beq *-7
asl a
lda $dd00
and #$df
ora #$10
bcs *+4
eor #$30
sta $dd00
ror ptr2
lda #$c0
bit $dd00
beq *-3
lda $dd00
and #$cf
sta $dd00
dex
bpl recvl
lda ptr2
rts
;---------------------------------------
;---------------------------------------
;the code residing in the drive:
;---------------------------------------
dtmp = $46
dtmp2 = $97
dbuf = $0300
dbufcmd = $00
dbuftrack = $06
dbufsect = $07
retries = 4
bretries = 2
;---------------------------------------
drive :
.org $0500
cld
tsx
stx dstack
sei
jsr ledoff
drivel:
jsr dload
jsr ledoff
cli
jmp drivel
;---------------------------------------
ledon:
lda $1c00
ora #$08
sta $1c00
rts
ledoff:
lda $1c00
and #$f7
sta $1c00
rts
;---------------------------------------
drecv:
ldx #7
drecvl:
lda $1800
bmi atn
and #5
beq *-7
lsr a
lda #2
bcc *+4
lda #8
sta $1800
ror dtmp
lda $1800
bmi atn
and #5
eor #5
beq *-9
lda #0
sta $1800
dex
bpl drecvl
lda dtmp
rts
;---------------------------------------
atn:
ldx dstack
txs
cli
rts
;---------------------------------------
dsend:
sta dtmp
ldx #7
dsendl:
lsr dtmp
lda #2
bcs *+4
lda #8
sta $1800
lda $1800
bmi atn
and #5
eor #5
bne *-9
sta $1800
lda #5
bit $1800
bne *-3
dex
bpl dsendl
rts
;---------------------------------------
dload:
ldy #0
jsr drecv
sta dcmd
jsr ledon
jsr drecv
sta dbuftrack
jsr drecv
sta dbufsect
lda dcmd
cmp #blockwrite
bne dblockread
dblockwrite:
ldy #0
drecvpl:
jsr drecv
sta dbuf,y
iny
bne drecvpl
jmp dputsect
dblockread:
jsr dgetsect
dsendpage:
ldy #0
dsendpl:
lda dbuf,y
jsr dsend
iny
bne dsendpl
rts
;---------------------------------------
dgetsect:
; stx dbuftrack
; sty dbufsect
ldx #retries
dgetsectl:
lda #$80
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
sei
cmp #1
beq dgsnoerr
cpx #0
beq dgsserr
dex
cpx #bretries
bcs dgetsectl
pha
lda #$c0
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
pla
cpx #0
bne dgetsectl
dgsserr:
pha
lda #errerr
jsr dsend
pla
jsr dsend
rts
dgsnoerr:
lda #errok
jsr dsend
rts
;---------------------------------------
dputsect:
; stx dbuftrack
; sty dbufsect
ldx #retries
dputsectl:
lda #$90
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
sei
cmp #1
beq dpsnoerr
cpx #0
beq dpsserr
dex
cpx #bretries
bcs dputsectl
pha
lda #$c0
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
pla
cpx #0
bne dputsectl
dpsserr:
pha
lda #errerr
jsr dsend
pla
jsr dsend
rts
dpsnoerr:
lda #errok
jsr dsend
rts
;---------------------------------------
led: .byte 0,0
dstack: .byte 0
dcmd: .byte 0
.RELOC
driveend:

View file

@ -0,0 +1,571 @@
;;
;;
;; 1541 CFS implementation
;;
;; Architecture:
;;
;; Functionality split between C64 and 1541: 1541 performs
;; directory lookup and finding files. 1541 communicates track/sector
;; address of file, C64 requests data to be read from track/sector.
;;
;; Example: reading directory
;;
;; C64: DIR
;; 1541: directory entries in CFS format
;;
;; Example: opening file
;;
;; C64: FILE filename
;; 1541: track/sector
;;
;; Example: reading file
;;
;; C64: track/sector, length
;; 1541: length, data, track/sector
.export _c64_dio_asm_init
.export _c64_dio_asm_read_block
.export _c64_dio_asm_write_block
.export _c64_dio_asm_track, _c64_dio_asm_sector
.export _c64_dio_asm_ptr
.importzp ptr1, ptr2
;; job code $80 read, $90 write
ciout = $ffa8
listen = $ffb1
second = $ff93
unlsn = $ffae
nbytes = 34
esc = $42
blockread = 1
blockwrite = 2
errok = 0
errerr = 1
.data
_c64_dio_asm_track: .byte 0
_c64_dio_asm_sector: .byte 0
_c64_dio_asm_ptr: .byte 0,0
.code
;---------------------------------------
_cfs_1541_read:
;; First send READ command to drive
lda #READ_CMD
jsr send
;; If drive do not respond we must download drive code
cmp #ERR_NOT_RESPONDING
bne notload
jsr download
lda #read
jsr send
notload:
;; Send file descriptor and number of bytes to read
lda _cfs_1541_fd
jsr send
lda _cfs_1541_bytes
jsr send
lda _cfs_1541_ptr
sta ptr1
lda _cfs_1541_ptr + 1
sta ptr1 + 1
;; Read bytes from drive
ldy #0
:
jsr recv
sta (ptr1),y
iny
cpy _cfs_1541_bytes
bne -
;; Read the number of bytes that were actually read from the file
jsr recv
;; Return the number of bytes read
rts
;---------------------------------------
_c64_dio_asm_read_block:
lda #BLOCKREAD_CMD
jsr send
lda _c64_dio_asm_track
jsr send
lda _c64_dio_asm_sector
jsr send
jsr recv
cmp #errok
bne readerr
lda _c64_dio_asm_ptr
sta ptr1
lda _c64_dio_asm_ptr+1
sta ptr1+1
ldy #0
readl:
jsr recv
sta (ptr1),y
iny
bne readl
clc
lda #0
tax
rts
readerr:
; sta $07c0
jsr recv
; sta $07c1
ldx #0
rts
;---------------------------------------
_c64_dio_asm_write_block:
lda #blockwrite
jsr send
lda _c64_dio_asm_track
jsr send
lda _c64_dio_asm_sector
jsr send
lda _c64_dio_asm_ptr
sta ptr1
lda _c64_dio_asm_ptr+1
sta ptr1+1
ldy #0
writel:
lda (ptr1),y
jsr send
iny
bne writel
jsr recv
cmp #errok
bne writeerr
lda #0
tax
rts
writeerr:
; sta $07c0
jsr recv
; sta $07c1
ldx #0
rts
;---------------------------------------
_c64_dio_asm_init:
sta devnr
lda #$00
sta drvmem
lda #$05
sta drvmem+1
lda #<drive
sta ptr1
lda #>drive
sta ptr1+1
; lda devnr
; ldx #<icmd
; ldy #>icmd
; jsr drvcmd
; jsr unlsn
mwl:
lda devnr
ldx #<mwcmd
ldy #>mwcmd
jsr drvcmd
ldy #0
lda (ptr1),y
jsr ciout
iny
cpy #nbytes
bne *-8
jsr unlsn
lda drvmem
clc
adc #nbytes
sta drvmem
lda drvmem+1
adc #0
sta drvmem+1
lda ptr1
clc
adc #nbytes
sta ptr1
tax
lda ptr1+1
adc #0
sta ptr1+1
cpx #<driveend
sbc #>driveend
bcc mwl
lda devnr
ldx #<mecmd
ldy #>mecmd
jsr drvcmd
jsr unlsn
rts
;---------------------------------------
drvcmd:
stx ptr2
sty ptr2+1
jsr listen
lda #$6f
jsr second
ldy #0
lda (ptr2),y
sta drvcmdcmp+1
inc ptr2
bne *+4
inc ptr2+1
ldy #0
lda (ptr2),y
jsr ciout
iny
drvcmdcmp: cpy #0
bne *-8
rts
;---------------------------------------
devnr: .byte 8
mwcmd: .byte 6
.byte $4d, $2d, $57
drvmem: .word $0500
.byte nbytes
.byte 0
mecmd: .byte 2
.byte $55, $33
.byte 0
;---------------------------------------
send:
sta ptr2
ldx #7
sendl:
lsr ptr2
lda $dd00
and #$df
ora #$10
bcc *+4
eor #$30
sta $dd00
lda #$c0
bit $dd00
bne *-3
lda $dd00
and #$cf
sta $dd00
lda $dd00
and #$c0
eor #$c0
bne *-7
dex
bpl sendl
ldx $d020
lda #1
sta $d020
stx $d020
rts
;---------------------------------------
recv:
ldx $d020
lda #0
sta $d020
stx $d020
ldx #7
recvl:
lda $dd00
and #$c0
eor #$c0
beq *-7
asl a
lda $dd00
and #$df
ora #$10
bcs *+4
eor #$30
sta $dd00
ror ptr2
lda #$c0
bit $dd00
beq *-3
lda $dd00
and #$cf
sta $dd00
dex
bpl recvl
lda ptr2
rts
;---------------------------------------
;---------------------------------------
;the code residing in the drive:
;---------------------------------------
dtmp = $46
dtmp2 = $97
dbuf = $0300
dbufcmd = $00
dbuftrack = $06
dbufsect = $07
retries = 10
bretries = 2
;---------------------------------------
drive :
.org $0500
cld
tsx
stx dstack
sei
jsr ledoff
drivel:
jsr dload
jsr ledoff
cli
jmp drivel
;---------------------------------------
ledon:
lda $1c00
ora #$08
sta $1c00
rts
ledoff:
lda $1c00
and #$f7
sta $1c00
rts
;---------------------------------------
drecv:
ldx #7
drecvl:
lda $1800
bmi atn
and #5
beq *-7
lsr a
lda #2
bcc *+4
lda #8
sta $1800
ror dtmp
lda $1800
bmi atn
and #5
eor #5
beq *-9
lda #0
sta $1800
dex
bpl drecvl
lda dtmp
rts
;---------------------------------------
atn:
ldx dstack
txs
cli
rts
;---------------------------------------
dsend:
sta dtmp
ldx #7
dsendl:
lsr dtmp
lda #2
bcs *+4
lda #8
sta $1800
lda $1800
bmi atn
and #5
eor #5
bne *-9
sta $1800
lda #5
bit $1800
bne *-3
dex
bpl dsendl
rts
;---------------------------------------
dload:
ldy #0
jsr drecv
sta dcmd
jsr ledon
jsr drecv
sta dbuftrack
jsr drecv
sta dbufsect
lda dcmd
cmp #blockwrite
bne dblockread
dblockwrite:
ldy #0
drecvpl:
jsr drecv
sta dbuf,y
iny
bne drecvpl
jmp dputsect
dblockread:
jsr dgetsect
dsendpage:
ldy #0
dsendpl:
lda dbuf,y
jsr dsend
iny
bne dsendpl
rts
;---------------------------------------
dgetsect:
; stx dbuftrack
; sty dbufsect
ldx #retries
dgetsectl:
lda #$80
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
sei
cmp #1
beq dgsnoerr
cpx #0
beq dgsserr
dex
cpx #bretries
bcs dgetsectl
pha
lda #$c0
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
pla
cpx #0
bne dgetsectl
dgsserr:
pha
lda #errerr
jsr dsend
pla
jsr dsend
rts
dgsnoerr:
lda #errok
jsr dsend
rts
;---------------------------------------
dputsect:
; stx dbuftrack
; sty dbufsect
ldx #retries
dputsectl:
lda #$90
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
sei
cmp #1
beq dpsnoerr
cpx #0
beq dpsserr
dex
cpx #bretries
bcs dputsectl
pha
lda #$c0
sta dbufcmd
cli
:
lda dbufcmd
bmi :-
pla
cpx #0
bne dputsectl
dpsserr:
pha
lda #errerr
jsr dsend
pla
jsr dsend
rts
dpsnoerr:
lda #errok
jsr dsend
rts
;---------------------------------------
led: .byte 0,0
dstack: .byte 0
dcmd: .byte 0
.RELOC
driveend:

View file

@ -0,0 +1,17 @@
;---------------------------------------------------------------------
.export _cs8900a_rxtxreg
.export _cs8900a_txcmd
.export _cs8900a_txlen
.export _cs8900a_packetpp
.export _cs8900a_ppdata
;---------------------------------------------------------------------
_cs8900a_rxtxreg = $de08
_cs8900a_txcmd = $de0c
_cs8900a_txlen = $de0e
_cs8900a_packetpp = $de02
_cs8900a_ppdata = $de04

View file

@ -0,0 +1,329 @@
;; The following code is written and is copyrighted by
;; Groepaz/Hitmen
;; Small changes by Adam Dunkels (renamed ss232 -> rs232)
;----------------------------------------------------------------------------------------------
; silver surfer polling mode driver for cc65
; - work from here to create a full featured driver with interupts.
; gpz fixed 20020828: fatal bug fixed in _rs232_params
;----------------------------------------------------------------------------------------------
rs16550base = $de08
fifo_rxd = rs16550base+$00 ;8 (r)
fifo_txd = rs16550base+$00 ;8 (w)
fifo_dll = rs16550base+$00 ;8 (r/w)
fifo_dlm = rs16550base+$01 ;9 (r/w)
fifo_ier = rs16550base+$01 ;9
fifo_fcr = rs16550base+$02 ;a (w)
fifo_iir = rs16550base+$02 ;a (r)
fifo_lcr = rs16550base+$03 ;b
fifo_mcr = rs16550base+$04 ;c
fifo_lsr = rs16550base+$05 ;d
fifo_msr = rs16550base+$06 ;e (r)
fifo_scratch = rs16550base+$07 ;f (r/w)
.export _rs232_init
.export _rs232_done
.export _rs232_params
.export _rs232_put
.export _rs232_get
.importzp ptr1, ptr2
.import popa, popax
;----------------------------------------------------------------------------------------------
; Error codes. Beware: The codes must match the codes in the C header file
ErrNotInitialized = $01
ErrBaudTooFast = $02
ErrBaudNotAvail = $03
ErrNoData = $04
ErrOverflow = $05
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_init (char hacked);
;/* Initialize the serial port, install the interrupt handler. The parameter
; * has no effect for now and should be set to 0.
; */
;----------------------------------------------------------------------------------------------
.code
_rs232_init:
; enable ssurfer-port
lda $de01
ora #$01
sta $de01
; disable nmi's from ssurfer
lda #%00000000
sta fifo_ier
; activate dtr
lda #%00000001
sta fifo_mcr
lda #$00 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_done (void);
;/* Close the port, deinstall the interrupt hander. You MUST call this function
; * before terminating the program, otherwise the machine may crash later. If
; * in doubt, install an exit handler using atexit(). The function will do
; * nothing, if it was already called.
; */
;----------------------------------------------------------------------------------------------
_rs232_done:
; disable nmi's from ssurfer
lda #%00000000
sta fifo_ier
; deactivate dtr
sta fifo_mcr
; disable ssurfer-port
lda $de01
and #$fe
sta $de01
lda #$00 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
;/* Set the port parameters. Use a combination of the #defined values above. */
;----------------------------------------------------------------------------------------------
.data
_rs232_baudrates:
.word (7372800 / ( 50 * 16))
.word (7372800 / ( 110 * 16))
.word (7372800 / ( 269 * 8))
.word (7372800 / ( 300 * 16))
.word (7372800 / ( 600 * 16))
.word (7372800 / ( 1200 * 16))
.word (7372800 / ( 2400 * 16))
.word (7372800 / ( 4800 * 16))
.word (7372800 / ( 9600 * 16))
.word (7372800 / ( 19200 * 16))
.word (7372800 / ( 38400 * 16))
.word (7372800 / ( 57600 * 16))
.word (7372800 / ( 115200 * 16))
.word (7372800 / ( 230400 * 16))
.bss
_rs232_tmp1:
.res 1
.code
_rs232_params:
sta _rs232_tmp1 ; save parity
; reset fifo
lda #%10000111
sta fifo_fcr
; that delay thing really needed ?!
; (original datasheet mentions a delay here)
; ldy #$00
; dey
; bny *-1
; set dlab
lda #%10000011 ; we assmume 8n1
sta fifo_lcr
jsr popa
tay ; save param
; set baudrate
clc
lsr a
lsr a
lsr a
lsr a
asl a
tax
lda _rs232_baudrates,x
sta fifo_dll
lda _rs232_baudrates+1,x
sta fifo_dlm
tya ; param
and #$0f
ora _rs232_tmp1 ; parity
; reset dlab
sta fifo_lcr
lda #$00 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
; check if byte available, returns AKKU=0 if none
ss_getlsr:
lda fifo_lsr
and #$01
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_get (char* b);
;/* Get a character from the serial port. If no characters are available, the
; * function will return RS_ERR_NO_DATA, so this is not a fatal error.
; */
;----------------------------------------------------------------------------------------------
; get byte (non blocking, returns byte in A or CARRY=1 - error)
_rs232_get:
sta ptr1
stx ptr1+1
jsr ss_getlsr ; check if byte available
; bne sk32 ; yes
bne sk33 ; yes
; activate rts
lda #%00000011
sta fifo_mcr
sk32:
; deactivate rts
; lda #%00000001
; sta fifo_mcr
jsr ss_getlsr ; check if byte available
bne sk33 ; yes
; deactivate rts
lda #%00000001
sta fifo_mcr
lda #ErrNoData ; no data
ldx #0
rts
sk33:
; deactivate rts
lda #%00000001
sta fifo_mcr
; get byte
ldy #$00
lda fifo_rxd
sta (ptr1),y
lda #0 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_put (char b);
;/* Send a character via the serial port. There is a transmit buffer, but
; * transmitting is not done via interrupt. The function returns
; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
; */
;----------------------------------------------------------------------------------------------
_rs232_put:
tax
; transmit buf ready?
lda fifo_lsr
and #%00100000
bne @sk1
@sk2:
lda #ErrOverflow ; overflow
ldx #$00
rts
@sk1:
; reciever ready?
lda fifo_msr
and #%00010000
beq @sk2
stx fifo_txd
lda #$00 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_pause (void);
;/* Assert flow control and disable interrupts. */
;----------------------------------------------------------------------------------------------
_rs232_pause:
; activate rts
lda #%00000011
sta fifo_mcr
lda #$00 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_unpause (void);
;/* Re-enable interrupts and release flow control */
;----------------------------------------------------------------------------------------------
_rs232_unpause:
; deactivate rts
lda #%00000001
sta fifo_mcr
lda #$00 ; ok
tax
rts
;----------------------------------------------------------------------------------------------
;unsigned char __fastcall__ rs232_status (unsigned char* status,
; unsigned char* errors);
;/* Return the serial port status. */
;----------------------------------------------------------------------------------------------
_rs232_status:
sta ptr2
stx ptr2+1
jsr popax
sta ptr1
stx ptr1+1
ldy #$00
; Get status
lda fifo_iir
and #%00000001
sta _rs232_tmp1
lda fifo_msr
lsr a
and #%01010000
ora _rs232_tmp1
sta _rs232_tmp1
lda fifo_lsr
and #%00101110
ora _rs232_tmp1
sta (ptr1),y
; Get errors
lda #$00 ; ok
sta (ptr2),y
lda #$00 ; ok
tax
rts

View file

@ -0,0 +1,17 @@
;---------------------------------------------------------------------
.export _cs8900a_rxtxreg
.export _cs8900a_txcmd
.export _cs8900a_txlen
.export _cs8900a_packetpp
.export _cs8900a_ppdata
;---------------------------------------------------------------------
_cs8900a_rxtxreg = $de00
_cs8900a_txcmd = $de04
_cs8900a_txlen = $de06
_cs8900a_packetpp = $de0a
_cs8900a_ppdata = $de0c