1
0
mirror of https://github.com/cc65/cc65.git synced 2024-08-16 12:29:03 +00:00
cc65/libsrc/atari7800/cputc.s

173 lines
2.8 KiB
ArmAsm
Raw Normal View History

2022-04-04 12:18:40 +00:00
;
; Mark Keates, Christian Groessler, Piotr Fusik, Karri Kaksonen
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
;
.export _cputc
.export _textcolor
.import _gotoxy, _gotox, _gotoy, pusha0
2022-04-04 12:18:40 +00:00
.import pushax
.import _screen
.import CURS_X, CURS_Y
.include "atari7800.inc"
.include "extzp.inc"
2022-04-04 12:18:40 +00:00
.data
;-----------------------------------------------------------------------------
; Holder of the text colour offset
2022-04-06 10:27:47 +00:00
; 0 = red, 42 = green, 84 = white
2022-04-04 12:18:40 +00:00
;
txtcolor:
.byte 0
.code
2022-04-06 10:27:47 +00:00
;---------------------------------------------------------------------------
; 8x16 routine
umula0:
ldy #8 ; Number of bits
lda #0
lsr ptr7800 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptrtmp
tax
lda ptrtmp+1 ; hi byte of left op
adc ptr7800+1
sta ptr7800+1
txa
@L1: ror ptr7800+1
ror a
ror ptr7800
dey
bne @L0
tax
lda ptr7800 ; Load the result
rts
2022-04-04 12:18:40 +00:00
;-----------------------------------------------------------------------------
; Change the text colour
;
; Logical colour names are
; 0 = red
; 1 = green
; 2 = white
;
; The routine will also return the previous textcolor
;
.proc _textcolor
beq @L2
sec
sbc #1
beq @L1
2022-04-06 10:27:47 +00:00
lda #84
2022-04-04 12:18:40 +00:00
jmp @L2
@L1: lda #42
@L2: ldy txtcolor
2022-04-06 10:27:47 +00:00
sta txtcolor ; Store new textcolor
2022-04-04 12:18:40 +00:00
tya
bne @L3
2022-04-06 10:27:47 +00:00
rts ; Old colour was 0
2022-04-04 12:18:40 +00:00
@L3: sec
sbc #42
bne @L4
lda #1
2022-04-06 10:27:47 +00:00
rts ; Old colour was 1
2022-04-04 12:18:40 +00:00
@L4: lda #2
2022-04-06 10:27:47 +00:00
rts ; Old colour was 2
2022-04-04 12:18:40 +00:00
.endproc
;-----------------------------------------------------------------------------
; Put a character on screen
;
; The code will handle newlines that wrap to start of screen
;
.proc _cputc
cmp #$0A ; LF
2022-04-06 10:27:47 +00:00
bne @L4
@L1: lda #0 ; newline
2022-04-04 12:18:40 +00:00
jsr _gotox
lda CURS_Y
cmp #(screenrows-1)
2022-04-06 10:27:47 +00:00
bne @L2
2022-04-04 12:18:40 +00:00
lda #0
2022-04-06 10:27:47 +00:00
beq @L3
@L2: clc
2022-04-04 12:18:40 +00:00
adc #1
2022-04-06 10:27:47 +00:00
@L3: jmp _gotoy
2022-04-04 12:18:40 +00:00
2022-04-06 10:27:47 +00:00
@L4:
cmp #$20 ; ' '
bne @L5
lda #$00
jmp @L10
2022-04-04 12:18:40 +00:00
@L5:
cmp #$3F ; '?'
bne @L6
2022-04-06 10:27:47 +00:00
lda #$02
jmp @L9
2022-04-04 12:18:40 +00:00
@L6:
cmp #$7C ; '|'
bne @L7
2022-04-06 10:27:47 +00:00
lda #$06
jmp @L9
2022-04-04 12:18:40 +00:00
@L7:
cmp #$41 ; >= 'A'
bcc @L8
2022-04-06 10:27:47 +00:00
and #$5F ; make upper case
2022-04-04 12:18:40 +00:00
sec
2022-04-06 10:27:47 +00:00
sbc #($41 - 17)
jmp @L9
2022-04-04 12:18:40 +00:00
@L8:
2022-04-06 10:27:47 +00:00
sec ; >= '*'
sbc #($2A - 1)
@L9:
clc
2022-04-04 12:18:40 +00:00
adc txtcolor
2022-04-06 10:27:47 +00:00
@L10:
2022-04-04 12:18:40 +00:00
asl
pha
2022-04-06 10:27:47 +00:00
lda #0
sta ptr7800+1
sta ptrtmp+1
lda CURS_Y ; Find position on screen buffer
sta ptr7800
2022-04-04 12:18:40 +00:00
lda #charsperline
2022-04-06 10:27:47 +00:00
sta ptrtmp
jsr umula0
2022-04-04 12:18:40 +00:00
clc
adc CURS_X
bcc @L11
inx
2022-04-06 10:27:47 +00:00
@L11: adc #<(_screen)
sta ptr7800
2022-04-06 10:27:47 +00:00
bcc @L12
inx
@L12: clc
txa
adc #>(_screen)
sta ptr7800+1
2022-04-04 12:18:40 +00:00
2022-04-06 10:27:47 +00:00
pla ; Print character on screen
2022-04-04 12:18:40 +00:00
ldy #0
sta (ptr7800),y
2022-04-06 10:27:47 +00:00
lda CURS_X ; Increment cursor
cmp #(charsperline-1)
beq @L1
clc
adc #1
jmp _gotox
2022-04-04 12:18:40 +00:00
.endproc