Shortenned the VIC-20's cputc() by 17 bytes.

Changed to a modified table look-up method to convert PetSCII to screen-codes.
This commit is contained in:
Greg King 2020-10-13 07:55:20 -04:00
parent 4905329ff6
commit e72e44d14f
1 changed files with 41 additions and 40 deletions

View File

@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; 1998-08-06, Ullrich von Bassewitz
; 2020-10-09, Greg King
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
@ -39,69 +40,64 @@ _cputcxy:
jsr gotoxy ; Set cursor, drop x and y
pla ; Restore C
; Plot a character - also used as internal function
; Plot a character -- also used as an internal function
_cputc: cmp #$0A ; CR?
bne L1
lda #0
sta CURS_X
beq plot ; Recalculate pointers
L1: cmp #$0D ; LF?
_cputc: cmp #$0D ; Is it CBM '\n'?
beq newline ; Recalculate pointers
cmp #$0A ; Is it CBM '\r'?
beq cr
; Printable char of some sort
; Printable char. of some sort
; Convert it from PetSCII into a screen-code
cmp #' '
bcc cputdirect ; Other control char
cmp #$FF ; BASIC token?
bne convert
lda #$DE ; Pi symbol
convert:
tay
bmi L10
cmp #$60
bcc L2
and #$DF
bne cputdirect ; Branch always
L2: and #$3F
lsr a ; Divide by 256/8
lsr a
lsr a
lsr a
lsr a
tax ; .X = %00000xxx
tya
eor pet_to_screen,x
cputdirect:
jsr putchar ; Write the character to the screen
; Advance cursor position
; Advance the cursor position
advance:
iny
cpy #XSIZE
bne L3
jsr newline ; new line
ldy #0 ; + cr
jsr newline ; Wrap around
cr: ldy #$00 ; Do carriage-return
L3: sty CURS_X
rts
; Move down by one full screen-line. Note: this routine doesn't scroll.
;
; (Both screen RAM and color RAM are aligned to page boundaries.
; Therefore, the lower bytes of their addresses have the same values.
; Shorten the code by taking advantage of that fact.)
newline:
clc
lda #XSIZE
adc SCREEN_PTR
sta SCREEN_PTR
bcc L4
inc SCREEN_PTR+1
clc
L4: lda #XSIZE
adc CRAM_PTR
sta CRAM_PTR
bcc L5
inc SCREEN_PTR+1
inc CRAM_PTR+1
L5: inc CURS_Y
rts
; Handle character if high bit set
L10: and #$7F
cmp #$7F ; PI?
bne L11
lda #$5E ; Load screen code for PI
L11: ora #$40
bne cputdirect
; Set cursor position, calculate RAM pointers
@ -111,14 +107,19 @@ plot: ldy CURS_X
jmp PLOT ; Set the new cursor
; Write one character to the screen without doing anything else, return X
; position in Y
; Write one character to the screen without doing anything else,
; return the X position in .Y
putchar:
ora RVS ; Set revers bit
ldy CURS_X
sta (SCREEN_PTR),y ; Set char
sta (SCREEN_PTR),y ; Set char.
lda CHARCOLOR
sta (CRAM_PTR),y ; Set color
rts
.rodata
pet_to_screen:
.byte %10000000,%00000000,%01000000,%00100000 ; PetSCII -> screen-code
.byte %01000000,%11000000,%10000000,%10000000