From c4a49faf487faf538dd1a581b460235aa752312d Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 14 Sep 2001 09:52:30 +0000 Subject: [PATCH] Working in P500 code git-svn-id: svn://svn.cc65.org/cc65/trunk@919 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/cbm510/Makefile | 2 + libsrc/cbm510/clrscr.s | 36 ++++++++++++++++ libsrc/cbm510/crt0.s | 72 ++++++++++++++++++++++--------- libsrc/cbm510/io.inc | 4 ++ libsrc/cbm510/kirq.s | 14 +++--- libsrc/cbm510/kplot.s | 95 +++++++++++++++++++++++------------------ libsrc/cbm510/peeksys.s | 50 ++++++++++++++++++++++ 7 files changed, 204 insertions(+), 69 deletions(-) create mode 100644 libsrc/cbm510/clrscr.s create mode 100644 libsrc/cbm510/peeksys.s diff --git a/libsrc/cbm510/Makefile b/libsrc/cbm510/Makefile index aceeffcac..8958f4b1e 100644 --- a/libsrc/cbm510/Makefile +++ b/libsrc/cbm510/Makefile @@ -15,6 +15,7 @@ OBJS = _scrsize.o \ banking.o \ break.o \ cgetc.o \ + clrscr.o \ color.o \ crt0.o \ kbhit.o \ @@ -22,6 +23,7 @@ OBJS = _scrsize.o \ kplot.o \ kscnkey.o \ kudtim.o \ + peeksys.o \ pokesys.o all: $(OBJS) diff --git a/libsrc/cbm510/clrscr.s b/libsrc/cbm510/clrscr.s new file mode 100644 index 000000000..73a6c4be1 --- /dev/null +++ b/libsrc/cbm510/clrscr.s @@ -0,0 +1,36 @@ +; +; Ullrich von Bassewitz, 14.09.2001 +; + + .export _clrscr + .import plot + + .include "zeropage.inc" + .include "io.inc" + +; ------------------------------------------------------------------------ +; void __fastcall__ clrscr (void); + +.proc _clrscr + + lda #0 + sta CURS_X + 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 + +.endproc + + + diff --git a/libsrc/cbm510/crt0.s b/libsrc/cbm510/crt0.s index 1b0deb8c9..3abfbbbc0 100644 --- a/libsrc/cbm510/crt0.s +++ b/libsrc/cbm510/crt0.s @@ -5,24 +5,24 @@ ; .export _exit - .import initlib, donelib - .import push0, _main - .import __BSS_RUN__, __BSS_SIZE__ - .import irq, nmi + .import _clrscr, initlib, donelib + .import push0, _main + .import __BSS_RUN__, __BSS_SIZE__ + .import irq, nmi .import k_irq, k_nmi, k_plot, k_udtim, k_scnkey - .include "zeropage.inc" - .include "io.inc" + .include "zeropage.inc" + .include "io.inc" ; ------------------------------------------------------------------------ ; Define and export the ZP variables for the CBM510 runtime - .exportzp sp, sreg, regsave - .exportzp ptr1, ptr2, ptr3, ptr4 - .exportzp tmp1, tmp2, tmp3, tmp4 - .exportzp regbank, zpspace - .exportzp vic, sid, IPCcia, cia, acia, tpi1, tpi2 + .exportzp sp, sreg, regsave + .exportzp ptr1, ptr2, ptr3, ptr4 + .exportzp tmp1, tmp2, tmp3, tmp4 + .exportzp regbank, zpspace + .exportzp vic, sid, cia1, cia2, acia, tpi1, tpi2 .exportzp ktab1, ktab2, ktab3, ktab4, time, RecvBuf, SendBuf .zeropage @@ -90,8 +90,8 @@ Head: .byte $03,$00,$11,$00,$0a,$00,$81,$20,$49,$b2,$30,$20,$a4,$20,$34,$00 vic: .word $d800 sid: .word $da00 -IPCcia: .word $db00 -cia: .word $dc00 +cia1: .word $db00 +cia2: .word $dc00 acia: .word $dd00 tpi1: .word $de00 tpi2: .word $df00 @@ -119,7 +119,7 @@ Back: ldx spsave ; actually used here: sei - lda #$01 + lda #$00 sta ExecReg ; This is the actual starting point of our code after switching banks for @@ -176,9 +176,37 @@ L3: lda (ptr1),y 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 + lda ExecReg sta IndReg ; Zero the BSS segment. We will do that here instead calling the routine @@ -216,9 +244,9 @@ Z4: ; Setup the C stack lda #<$FF81 - sta sp - lda #>$FF81 - sta sp+1 + sta sp + lda #>$FF81 + sta sp+1 ; We expect to be in page 2 now @@ -235,6 +263,10 @@ Z4: ; 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 + + jsr _clrscr + ; Call module constructors jsr initlib @@ -365,8 +397,8 @@ reset_size = * - reset ; Code for a few simpler kernal calls goes here k_iobase: - ldx cia - ldy cia+1 + ldx cia2 + ldy cia2+1 rts k_screen: diff --git a/libsrc/cbm510/io.inc b/libsrc/cbm510/io.inc index fcd6829ae..2e475419a 100644 --- a/libsrc/cbm510/io.inc +++ b/libsrc/cbm510/io.inc @@ -151,4 +151,8 @@ VIC_BG_COLOR3 = $24 +; Out video memory address + +VIDEO_RAM = $F800 + diff --git a/libsrc/cbm510/kirq.s b/libsrc/cbm510/kirq.s index 25af77784..62174a678 100644 --- a/libsrc/cbm510/kirq.s +++ b/libsrc/cbm510/kirq.s @@ -5,12 +5,12 @@ ; .export irq, nmi, k_irq, k_nmi - .import k_scnkey, k_udtim, k_rs232 - .importzp tpi1 + .import k_scnkey, k_udtim, k_rs232 + .importzp tpi1 - .include "zeropage.inc" - .include "io.inc" - .include "page3.inc" + .include "zeropage.inc" + .include "io.inc" + .include "page3.inc" ; ------------------------------------------------------------------------- @@ -19,8 +19,8 @@ ; Bit 7 6 5 4 3 2 1 0 ; | | | | ^ 50 Hz ; | | | ^ SRQ IEEE 488 -; | | ^ cia -; | ^ IRQB ext. Port +; | | ^ cia2 +; | ^ cia1 IRQB ext. Port ; ^ acia diff --git a/libsrc/cbm510/kplot.s b/libsrc/cbm510/kplot.s index 552759ffa..bf1dff323 100644 --- a/libsrc/cbm510/kplot.s +++ b/libsrc/cbm510/kplot.s @@ -8,54 +8,58 @@ .importzp crtc .include "zeropage.inc" - + .include "io.inc" + + +; ------------------------------------------------------------------------ +; .proc k_plot - bcc set - ldx CURS_Y - ldy CURS_X + bcc set + ldx CURS_Y + ldy CURS_X rts -set: stx CURS_Y - sty CURS_X - +set: stx CURS_Y + sty CURS_X + + lda LineLSBTab,x + sta CharPtr + lda LineMSBTab,x + sta CharPtr+1 + .if 0 - lda LineLSBTab,x - sta CharPtr - lda LineMSBTab,x - sta CharPtr+1 - - lda IndReg + lda IndReg pha - lda #$0F - sta IndReg + lda #$0F + sta IndReg - ldy #$00 + ldy #$00 clc sei - sta (crtc),y - lda CharPtr - adc CURS_X + sta (crtc),y + lda CharPtr + adc CURS_X iny - sta (crtc),y + sta (crtc),y dey - lda #$0E - sta (crtc),y + 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 + lda (crtc),y + and #$F8 + sta sedt1 + lda CharPtr+1 + adc #$00 + and #$07 + ora sedt1 + sta (crtc),y cli pla - sta IndReg -.endif + sta IndReg +.endif rts .endproc @@ -64,16 +68,23 @@ set: stx CURS_Y .rodata -LineLSBTab: - .byte $00,$50,$A0,$F0,$40,$90,$E0,$30 - .byte $80,$D0,$20,$70,$C0,$10,$60,$B0 - .byte $00,$50,$A0,$F0,$40,$90,$E0,$30 - .byte $80 +.macro LineLoTab + .repeat 25, I + .byte <(VIDEO_RAM + I * 40) + .endrep +.endmacro + +LineLSBTab: LineLoTab + ; ------------------------------------------------------------------------- ; High bytes of the start address of the screen lines -LineMSBTab: - .byte $D0,$D0,$D0,$D0,$D1,$D1,$D1,$D2 - .byte $D2,$D2,$D3,$D3,$D3,$D4,$D4,$D4 - .byte $D5,$D5,$D5,$D5,$D6,$D6,$D6,$D7 - .byte $D7 +.macro LineHiTab + .repeat 25, I + .byte >(VIDEO_RAM + I * 40) + .endrep +.endmacro + +LineMSBTab: LineHiTab + + diff --git a/libsrc/cbm510/peeksys.s b/libsrc/cbm510/peeksys.s new file mode 100644 index 000000000..e3110603e --- /dev/null +++ b/libsrc/cbm510/peeksys.s @@ -0,0 +1,50 @@ +; +; Ullrich von Bassewitz, 14.09.2001 +; + + .export _peekbsys, _peekwsys + .importzp ptr1 + + .include "zeropage.inc" + + +; ------------------------------------------------------------------------ +; unsigned char __fastcall__ peekbsys (unsigned addr); + +.proc _peekbsys + + sta ptr1 ; Store argument pointer + stx ptr1+1 + ldx IndReg + lda #$0F + sta IndReg + ldy #$00 + lda (ptr1),y + stx IndReg + ldx #$00 ; Extend to word + rts + +.endproc + +; ------------------------------------------------------------------------ +; unsigned __fastcall__ peekwsys (unsigned addr); + +.proc _peekwsys + + sta ptr1 ; Store argument pointer + stx ptr1+1 + ldx IndReg + lda #$0F + sta IndReg + ldy #$00 + lda (ptr1),y ; Get low byte + pha + iny + lda (ptr1),y ; Get high byte + stx IndReg + tax ; High byte -> X + pla ; Low byte -> A + rts + +.endproc +