cgetc.o \
clrscr.o \
color.o \
+ conio.o \
+ cputc.o \
crt0.o \
kbhit.o \
kirq.o \
sta CURS_Y
jsr plot ; Set cursor to top left corner
- ldx #4
- ldy #$00
lda #$20 ; Screencode for blank
-L1: sta (CharPtr),y
- iny
- bne L1
- inc CharPtr+1
- dex
- bne L1
-
- jmp plot ; Set screen pointer again
+ ldx #$00
+ ldy #$00
+ jsr clearpage
+ jsr clearpage
+ jsr clearpage
+ ldx #<(40*25)
+ jsr clearpage ; Clear remainder of last page
+ jmp plot ; Set screen pointer again
.endproc
+.proc clearpage
+@L1: sta (SCREEN_PTR),y
+ iny
+ dex
+ bne @L1
+ inc SCREEN_PTR+1
+ rts
+
+.endproc
--- /dev/null
+;
+; Ullrich von Bassewitz, 14.09.2001
+;
+; Low level stuff for screen output/console input
+;
+
+ .exportzp CURS_X, CURS_Y
+
+ .include "zeropage.inc"
+
--- /dev/null
+;
+; Ullrich von Bassewitz, 14.09.2001
+;
+; void cputcxy (unsigned char x, unsigned char y, char c);
+; void cputc (char c);
+;
+
+ .export _cputcxy, _cputc, cputdirect, putchar
+ .export newline, plot
+ .import popa, _gotoxy
+ .import xsize, revers
+
+ .include "zeropage.inc"
+ .include "../cbm/cbm.inc"
+
+; ------------------------------------------------------------------------
+;
+
+_cputcxy:
+ pha ; Save C
+ jsr popa ; Get Y
+ jsr _gotoxy ; Set cursor, drop x
+ pla ; Restore C
+
+; Plot a character - also used as internal function
+
+_cputc: cmp #$0A ; CR?
+ bne L1
+ lda #0
+ sta CURS_X
+ beq plot ; Recalculate pointers
+
+L1: cmp #$0D ; LF?
+ beq newline ; Recalculate pointers
+
+; Printable char of some sort
+
+ cmp #' '
+ bcc cputdirect ; Other control char
+ tay
+ bmi L10
+ cmp #$60
+ bcc L2
+ and #$DF
+ bne cputdirect ; Branch always
+L2: and #$3F
+
+cputdirect:
+ jsr putchar ; Write the character to the screen
+
+; Advance cursor position
+
+advance:
+ iny
+ cpy xsize
+ bne L3
+ jsr newline ; new line
+ ldy #0 ; + cr
+L3: sty CURS_X
+ rts
+
+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 CRAM_PTR+1
+L5: inc CURS_Y
+ rts
+
+; Handle character if high bit set
+
+L10: and #$7F
+ cmp #$7E ; PI?
+ bne L11
+ lda #$5E ; Load screen code for PI
+ bne cputdirect
+L11: ora #$40
+ bne cputdirect
+
+; Set cursor position, calculate RAM pointers
+
+plot: ldy CURS_X
+ ldx CURS_Y
+ clc
+ jmp PLOT ; Set the new cursor
+
+; Write one character to the screen without doing anything else, return X
+; position in Y
+
+putchar:
+ ora revers ; Set revers bit
+ ldy CURS_X
+ sta (SCREEN_PTR),y ; Set char
+ ldx IndReg
+ lda #$0F
+ sta IndReg
+ lda CHARCOLOR
+ sta (CRAM_PTR),y ; Set color
+ stx IndReg
+ rts
+
iny
bne L3
-; Reprogram the VIC so that the text screen is at $F800 in the execution bank
-
-; Place the VIC video RAM into bank 0
-; CA (STATVID) = 0
-
- ldy #tpiCtrlReg
- lda (tpi1),y
- and #$CF
- ora #$20
- sta (tpi1),y
-
-; Set bit 14/15 of the VIC address range to the high bits of VIDEO_RAM
-; PC6/PC7 (VICBANKSEL 0/1) = 11
-
- ldy #tpiPortC
- lda (tpi2),y
- and #$3F
- ora #((>VIDEO_RAM) & $C0)
- sta (tpi2),y
-
-; Set bits 10-13 of the VIC address range to address F800
-
- ldy #VIC_VIDEO_ADR
- lda (vic),y
- and #$0F
- ora #(((>VIDEO_RAM) & $3F) << 2)
- sta (vic),y
-
; Set the indirect segment to bank we're executing in
lda ExecReg
; This code is in page 2, so we may now start calling subroutines safely,
; since the code we execute is no longer in the stack page.
-; Clear the video memory
+
+; Clear the video memory. We will do this before switching the video to bank 0
+; to avoid garbage when doing so.
jsr _clrscr
+; Reprogram the VIC so that the text screen is at $F800 in the execution bank
+; This is done in three steps:
+
+ lda #$0F ; We need access to the system bank
+ sta IndReg
+
+; Place the VIC video RAM into bank 0
+; CA (STATVID) = 0
+
+ ldy #tpiCtrlReg
+ lda (tpi1),y
+ sta vidsave+0
+ and #$CF
+ ora #$20
+ sta (tpi1),y
+
+; Set bit 14/15 of the VIC address range to the high bits of VIDEO_RAM
+; PC6/PC7 (VICBANKSEL 0/1) = 11
+
+ ldy #tpiPortC
+ lda (tpi2),y
+ sta vidsave+1
+ and #$3F
+ ora #((>VIDEO_RAM) & $C0)
+ sta (tpi2),y
+
+; Set bits 10-13 of the VIC address range to address F800
+
+ ldy #VIC_VIDEO_ADR
+ lda (vic),y
+ sta vidsave+2
+ and #$0F
+ ora #(((>VIDEO_RAM) & $3F) << 2)
+ sta (vic),y
+
+; Switch back to the execution bank
+
+ lda ExecReg
+ sta IndReg
+
; Call module constructors
jsr initlib
_exit: jsr donelib ; Run module destructors
+; We need access to the system bank now
+
+ lda #$0F
+ sta IndReg
+
+; Switch back the video to the system bank
+
+ ldy #tpiCtrlReg
+ lda vidsave+0
+ sta (tpi1),y
+
+ ldy #tpiPortC
+ lda vidsave+1
+ sta (tpi2),y
+
+ ldy #VIC_VIDEO_ADR
+ lda vidsave+2
+ sta (vic),y
+
; Clear the start of the zero page, since it will be interpreted as a
; (garbage) BASIC program otherwise. This is also the default entry for
; the break vector.
; Setup the welcome code at the stack bottom in the system bank. Use
; the F4/F5 vector to access the system bank
- lda #$0F
- sta IndReg
ldy #$00
sty $F4
iny
.data
spsave: .res 1
-
+vidsave:.res 3
; Out video memory address
VIDEO_RAM = $F800
-
+COLOR_RAM = $D400
.include "zeropage.inc"
.include "io.inc"
-
-
+
+ .macpack generic
+
; ------------------------------------------------------------------------
;
.proc k_plot
- bcc set
- ldx CURS_Y
- ldy CURS_X
- rts
+ bcs get
-set: stx CURS_Y
+ stx CURS_Y
sty CURS_X
- lda LineLSBTab,x
- sta CharPtr
- lda LineMSBTab,x
- sta CharPtr+1
-
-.if 0
- lda IndReg
- pha
- lda #$0F
- sta IndReg
-
- ldy #$00
- clc
- sei
- sta (crtc),y
- lda CharPtr
- adc CURS_X
- iny
- sta (crtc),y
- dey
- lda #$0E
- sta (crtc),y
- iny
- lda (crtc),y
- and #$F8
- sta sedt1
- lda CharPtr+1
- adc #$00
- and #$07
- ora sedt1
- sta (crtc),y
- cli
-
- pla
- sta IndReg
-.endif
+ lda LineLSBTab,x
+ sta SCREEN_PTR
+ sta CRAM_PTR
+ lda LineMSBTab,x
+ sta SCREEN_PTR+1
+ sub #>VIDEO_RAM
+ add #>COLOR_RAM
+ sta CRAM_PTR+1
+
+get: ldx CURS_Y
+ ldy CURS_X
+
rts
+
.endproc
; -------------------------------------------------------------------------
PgmKeyPtr = $C2
sedsal = $C4
sedeal = $C6
-CharPtr = $C8
+SCREEN_PTR = $C8
CURS_Y = $CA
CURS_X = $CB
GrafMode = $CC
BitTable = $E2
BlinkOn = $E6
BlinkCounter = $E7
-ColorRamPtr = $E8
+CRAM_PTR = $E8
TempColor = $EA
BlinkSwitch = $EB
CHARCOLOR = $EC