1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Fixed bugs; and, improved the efficiency of some pce library functions.

This commit is contained in:
Greg King 2015-11-26 15:06:20 -05:00 committed by Oliver Schmidt
parent 959eff34a3
commit 39694d0aaa
16 changed files with 158 additions and 229 deletions

View File

@ -2,32 +2,39 @@
; clock_t clock (void); ; clock_t clock (void);
; ;
.export _clock
.constructor initclock .constructor initclock
.export _clock
.forceimport ticktock ; make sure that tickcount changes .forceimport ticktock ; make sure that tickcount changes
.importzp sreg .importzp tickcount, sreg
.include "extzp.inc"
.proc _clock
lda tickcount+3
sta sreg+1
lda tickcount+2
sta sreg
ldx tickcount+1
lda tickcount
rts
.endproc
; Make the process clock start at zero. ; Make the process clock start at zero.
.segment "ONCE" .segment "ONCE"
initclock: initclock:
lda #0 ldx #4 - 1
ldx #3 @lp: stz tickcount,x
@lp: sta tickcount,x
dex dex
bpl @lp bpl @lp
rts rts
; ------------------------------------------------------------------------
.code
; This function might be interrupted while it is reading the several bytes of
; the clock. They are read again if that happens. (We do not want to stop
; interrupts because that might cause glitches in interrupt-driven graphics
; and sound.)
.proc _clock
lda tickcount
ldy tickcount+3
sty sreg+1
ldy tickcount+2
sty sreg
ldx tickcount+1
cmp tickcount
bne _clock ; clock changed; reread it
rts
.endproc

View File

@ -12,20 +12,15 @@
.include "extzp.inc" .include "extzp.inc"
_clrscr: _clrscr:
st0 #VDC_MAWR VREG VDC_MAWR, $0000
st1 #<$0000
st2 #>$0000
st0 #VDC_VWR st0 #VDC_VWR
ldy #$40 ldy #$40
rowloop: rowloop:
ldx #$80 ldx #$80
colloop: colloop:
lda #' ' ; low byte of char. index st1 #' ' ; low byte of char. index
sta VDC_DATA_LO st2 #$02 ; background color, high nybble of char. index
lda #$02 ; background color, high nybble of char. index
sta VDC_DATA_HI
dex dex
bne colloop bne colloop
dey dey

View File

@ -21,6 +21,7 @@ _textcolor:
rts rts
_bgcolor: _bgcolor:
and #$0F
ldx BGCOLOR ; get old value ldx BGCOLOR ; get old value
sta BGCOLOR ; set new value sta BGCOLOR ; set new value
asl a asl a

View File

@ -1,36 +1,27 @@
.constructor initconio, 24 .constructor initconio, 24
.import vce_init
.import psg_init
.import vdc_init .import vdc_init
.import psg_init
.import colors .import colors
.importzp ptr1, tmp1 .importzp ptr1, tmp1
.include "pce.inc" .include "pce.inc"
.include "extzp.inc" .include "extzp.inc"
.macpack longbranch
.segment "ONCE" .segment "ONCE"
initconio: initconio:
jsr vce_init jsr vdc_init
jsr psg_init jsr psg_init
jsr conio_init jsr load_font
jsr set_palette
st0 #VDC_CR
st1 #<$0088
st2 #>$0088
rts
set_palette: set_palette:
stz VCE_ADDR_LO stz VCE_ADDR_LO
stz VCE_ADDR_HI stz VCE_ADDR_HI
ldx #0 clx
@lp: @lp: ldy #16 ; size of a palette
ldy #16 ; size of a pallette
@lp1: @lp1: lda colors,x
lda colors,x
sta VCE_DATA_LO sta VCE_DATA_LO
lda colors+1,x lda colors+1,x
sta VCE_DATA_HI sta VCE_DATA_HI
@ -39,58 +30,34 @@ set_palette:
inx inx
inx inx
cpx #16 * 2 cpx #16 * 2 ; 16 palettes
jne @lp bne @lp
; Set background to black. sty BGCOLOR ; white on black
iny
stz VCE_ADDR_LO sty CHARCOLOR
stz VCE_ADDR_HI
stz VCE_DATA_LO
stz VCE_DATA_HI
VREG VDC_CR, $0088 ; enable background and vertical-blank interrupt
rts rts
;---------------------------------------------------------------------------- ; Load the conio font into the VDC.
; The character tiles use only two colors from each pallette. Color zero load_font:
; comes from pallette zero; color one is different in each pallette. The VREG VDC_MAWR, $2000
; color of a character is set by choosing one of the 16 pallettes. st0 #VDC_VWR
conio_init: stz tmp1 ; #%00000000
; Load font bsr copy ; make normal characters
st0 #VDC_MAWR
st1 #<$2000
st2 #>$2000
; pointer to font data dec tmp1 ; #%11111111
lda #<font ; bsr copy ; make reversed characters
; rts ; (fall through)
; Point to the font data.
copy: lda #<font
ldx #>font
sta ptr1 sta ptr1
lda #>font stx ptr1+1
sta ptr1+1
st0 #VDC_VWR ; VWR
lda #0
sta tmp1
jsr copy
lda #<font
sta ptr1
lda #>font
sta ptr1+1
lda #$FF
sta tmp1
jsr copy
ldx #0 ; white on black
stx BGCOLOR
inx
stx CHARCOLOR
rts
copy:
ldy #$80 ; 128 chars ldy #$80 ; 128 chars
charloop: charloop:
ldx #$08 ; 8 bytes/char ldx #$08 ; 8 bytes/char
@ -98,23 +65,21 @@ lineloop:
lda (ptr1) lda (ptr1)
eor tmp1 eor tmp1
sta VDC_DATA_LO ; bitplane 0 sta VDC_DATA_LO ; bitplane 0
stz VDC_DATA_HI ; bitplane 1 st2 #>$0000 ; bitplane 1
clc ; increment font pointer inc ptr1 ; increment font pointer
lda ptr1 bne @noC
adc #$01 inc ptr1+1
sta ptr1 @noC: dex
lda ptr1+1
adc #$00
sta ptr1+1
dex
bne lineloop ; next bitplane-0 byte bne lineloop ; next bitplane-0 byte
ldx #$08 ; fill bitplanes 2 and 3 with 0 ldx #$08 ; fill bitplanes 2 and 3 with 0
fillloop: fillloop:
st1 #<$0000 st1 #<$0000
st2 #>$0000 st2 #>$0000
dex dex
bne fillloop ; next byte bne fillloop ; next byte
dey dey
bne charloop ; next character bne charloop ; next character

View File

@ -5,6 +5,7 @@
.export _cputcxy, _cputc, cputdirect, putchar .export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot .export newline, plot
.forceimport initconio ; force conio initiation
.import gotoxy .import gotoxy
.import PLOT .import PLOT
@ -23,9 +24,8 @@ _cputcxy:
_cputc: cmp #$0D ; CR? _cputc: cmp #$0D ; CR?
bne L1 bne L1
lda #0 stz CURS_X
sta CURS_X bra plot ; Recalculate pointer
beq plot ; Recalculate pointer
L1: cmp #$0A ; LF? L1: cmp #$0A ; LF?
beq newline ; Recalculate pointer beq newline ; Recalculate pointer
@ -35,20 +35,16 @@ L1: cmp #$0A ; LF?
cputdirect: cputdirect:
jsr putchar ; Write the character to the screen jsr putchar ; Write the character to the screen
; Advance cursor position ; Move the cursor (rightwards) to the next position.
advance: advance:
ldy CURS_X ldy CURS_X
iny iny
cpy xsize cpy xsize
bne L3 bne L3
jsr newline ; new line inc CURS_Y ; new line
ldy #0 ; + CR cly ; + CR
L3: sty CURS_X L3: sty CURS_X
jmp plot
newline:
inc CURS_Y
; Set cursor position; calculate VRAM pointer. ; Set cursor position; calculate VRAM pointer.
@ -57,24 +53,22 @@ plot: ldy CURS_X
clc clc
jmp PLOT ; Set the new cursor jmp PLOT ; Set the new cursor
newline:
inc CURS_Y
bra plot
; Write one character to the screen without doing anything else. ; Write one character to the screen without doing anything else.
putchar: putchar:
ora RVS ; Set revers bit ora RVS ; Set reverse bit
tax st0 #VDC_MAWR ; Memory-Address Write
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
st0 #VDC_MAWR ; Memory Address Write st0 #VDC_VWR
lda SCREEN_PTR
sta VDC_DATA_LO
lda SCREEN_PTR+1
sta VDC_DATA_HI
st0 #VDC_VWR ; VWR
txa
sta VDC_DATA_LO ; character sta VDC_DATA_LO ; character
lda CHARCOLOR ; pallette number lda CHARCOLOR ; pallette number
@ -82,14 +76,7 @@ putchar:
asl a asl a
asl a asl a
asl a asl a
ora #>$0200 ; high nybble of char. index
ora #$02
sta VDC_DATA_HI sta VDC_DATA_HI
rts rts
;-------------------------------------------------------------------------------
; force the init constructor to be imported
.import initconio
conio_init = initconio

View File

@ -1,18 +1,19 @@
; ;
; Startup code for cc65 (PCEngine version) ; Start-up code for cc65 (PC-Engine version)
; ;
; by Groepaz/Hitmen <groepaz@gmx.net>, ; by Groepaz/Hitmen <groepaz@gmx.net>,
; based on code by Ullrich von Bassewitz <uz@cc65.org>. ; based on code by Ullrich von Bassewitz <uz@cc65.org>
; ;
; 2018-02-11, Greg King ; 2018-02-24, Greg King
; ;
.export _exit .export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup .export __STARTUP__ : absolute = 1 ; Mark as start-up
.import initlib, donelib .import initlib, donelib
.import push0, _main .import push0, _main
.import IRQStub .import IRQStub, __nmi
.importzp sp
; Linker-generated ; Linker-generated
.import __CARTSIZE__ .import __CARTSIZE__
@ -23,20 +24,18 @@
.include "pce.inc" .include "pce.inc"
.include "extzp.inc" .include "extzp.inc"
.importzp sp
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Place the startup code in a special segment. ; Place the start-up code in a special segment.
.segment "STARTUP" .segment "STARTUP"
; Initialize CPU ; Initialize the CPU.
start: sei start: sei
nop nop
csh ; Set high-speed CPU mode csh ; Set high-speed CPU mode
nop nop
; Set up stack and memory mapping. ; Set up the stack and the memory mapping.
ldx #$FF ; Stack top ($21FF) ldx #$FF ; Stack top ($21FF)
txs txs
@ -62,18 +61,19 @@ start: sei
;lda #$00 ; (The reset default) ;lda #$00 ; (The reset default)
;tam #%10000000 ; $E000-$FFFF Hucard/Syscard bank 0 ;tam #%10000000 ; $E000-$FFFF Hucard/Syscard bank 0
; Initialize hardware ; Initialize the hardware.
stz TIMER_CTRL ; Timer off stz TIMER_CTRL ; Timer off
lda #$07 lda #%00000111
sta IRQ_MASK ; Interrupts off sta IRQ_MASK ; Interrupts off
stz IRQ_STATUS ; Acknowledge timer
; FIXME; I don't know why the heck this one doesn't work when called from a constructor. :/ ; FIXME; I don't know why the heck this one doesn't work when called from a constructor. -Groepaz :-/
.if 0 ; It now seems to work (at least, in Mednafen). -Greg King
.import vdc_init .import vdc_init
jsr vdc_init jsr vdc_init
.endif
; Turn on background and VD interrupt/IRQ1 ; Allow interrupts from the VDC.
lda #$05 lda #%00000101
sta IRQ_MASK ; IRQ1 = on sta IRQ_MASK ; IRQ1 = on
; Copy the .data segment to RAM ; Copy the .data segment to RAM
@ -89,10 +89,11 @@ start: sei
sta sp sta sp
stx sp+1 stx sp+1
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
cli ; allow IRQ only after constructors have run stz IRQ_STATUS ; Clear IRQs
cli ; Allow IRQ only after constructors have run
; Pass an empty command line ; Pass an empty command line
jsr push0 ; argc jsr push0 ; argc
@ -101,14 +102,12 @@ start: sei
ldy #4 ; Argument size ldy #4 ; Argument size
jsr _main ; Call the user's code jsr _main ; Call the user's code
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: jsr donelib ; Run module destructors _exit: jsr donelib
; reset the PCEngine (start over) ; Reset the PCEngine (start over).
jmp start jmp start
_nmi: rti
.export initmainargs .export initmainargs
initmainargs: initmainargs:
rts rts
@ -121,5 +120,5 @@ initmainargs:
.word IRQStub ; $FFF6 IRQ2 (External IRQ, BRK) .word IRQStub ; $FFF6 IRQ2 (External IRQ, BRK)
.word IRQStub ; $FFF8 IRQ1 (VDC) .word IRQStub ; $FFF8 IRQ1 (VDC)
.word IRQStub ; $FFFA Timer .word IRQStub ; $FFFA Timer
.word _nmi ; $FFFC NMI .word __nmi ; $FFFC NMI
.word start ; $FFFE reset .word start ; $FFFE reset

View File

@ -17,10 +17,3 @@ _gotoxy:
jsr popa ; Get X jsr popa ; Get X
sta CURS_X ; Set X sta CURS_X ; Set X
jmp plot ; Set the cursor position jmp plot ; Set the cursor position
;-------------------------------------------------------------------------------
; force the init constructor to be imported
.import initconio
conio_init = initconio

View File

@ -2,7 +2,7 @@
; IRQ handling (PCE version) ; IRQ handling (PCE version)
; ;
.export initirq, doneirq, IRQStub .export initirq, doneirq, IRQStub, __nmi
.import __INTERRUPTOR_COUNT__, callirq_y .import __INTERRUPTOR_COUNT__, callirq_y
@ -45,4 +45,4 @@ IRQStub:
pla pla
plx plx
@L1: ply @L1: ply
rti __nmi: rti

View File

@ -36,6 +36,10 @@
JOY_COUNT = 4 ; Number of joysticks we support JOY_COUNT = 4 ; Number of joysticks we support
.bss
padbuffer: .res JOY_COUNT
.code .code
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
@ -67,7 +71,7 @@ UNINSTALL:
COUNT: COUNT:
lda #<JOY_COUNT lda #<JOY_COUNT
ldx #>JOY_COUNT clx ; ldx #>JOY_COUNT
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
@ -85,7 +89,6 @@ READJOY:
joy1: joy1:
lda padbuffer,x lda padbuffer,x
ldx #0
rts rts
read_joy: read_joy:
@ -134,11 +137,6 @@ nextpad:
sta padbuffer,y ; store new value sta padbuffer,y ; store new value
iny iny
cpy #$05 cpy #.sizeof(padbuffer)
bcc nextpad bcc nextpad
rts rts
.bss
padbuffer:
.res 4

View File

@ -4,16 +4,15 @@
.include "pce.inc" .include "pce.inc"
.include "extzp.inc" .include "extzp.inc"
PLOT: PLOT: bcs @getpos
bcs @getpos
tya tya
;clc ; already cleared ;clc ; already cleared
adc _plotlo,x adc plotlo,x
sta SCREEN_PTR sta SCREEN_PTR
lda _plothi,x cla
adc #0 adc plothi,x
sta SCREEN_PTR+1 sta SCREEN_PTR+1
@getpos: @getpos:
ldx CURS_Y ldx CURS_Y
@ -22,18 +21,10 @@ PLOT:
.rodata .rodata
_plotlo: plotlo: .repeat screenrows,line
.repeat screenrows,line
.byte <($0000+(line*$80)) .byte <($0000+(line*$80))
.endrepeat .endrepeat
_plothi: plothi: .repeat screenrows,line
.repeat screenrows,line
.byte >($0000+(line*$80)) .byte >($0000+(line*$80))
.endrepeat .endrepeat
;-------------------------------------------------------------------------------
; force the init constructor to be imported
.import initconio
conio_init = initconio

View File

@ -4,8 +4,8 @@
.segment "ONCE" .segment "ONCE"
psg_init: psg_init:
clx
stz PSG_GLOBAL_PAN ; Silence global balance stz PSG_GLOBAL_PAN ; Silence global balance
ldx #6 - 1
psg_clear_loop: psg_clear_loop:
stx PSG_CHAN_SELECT ; Select channel stx PSG_CHAN_SELECT ; Select channel
@ -17,14 +17,12 @@ psg_clear_loop:
stz PSG_LFO_FREQ ; Clear LFO frequency stz PSG_LFO_FREQ ; Clear LFO frequency
stz PSG_LFO_CTRL ; Clear LFO control stz PSG_LFO_CTRL ; Clear LFO control
cly ldy #$20
psg_clear_waveform: psg_clear_waveform:
stz PSG_CHAN_DATA ; Clear waveform byte stz PSG_CHAN_DATA ; Clear waveform byte
iny dey
cpy #$20
bne psg_clear_waveform bne psg_clear_waveform
inx dex
cpx #$06 bpl psg_clear_loop
bne psg_clear_loop
rts rts

View File

@ -1,24 +1,23 @@
; ;
; Ullrich von Bassewitz, 07.08.1998 ; 1998-08-07, Ullrich von Bassewitz
; 2015-11-23, Greg King
; ;
; unsigned char revers (unsigned char onoff); ; unsigned char __fastcall__ revers (unsigned char onoff);
; ;
.export _revers .export _revers
.include "extzp.inc" .importzp RVS
.proc _revers .proc _revers
ldx #$00 ; Assume revers off cmp #$01 ; False or true?
tay ; Test onoff cla
beq L1 ; Jump if off ror a ; Either $00 or $80
ldx #$80 ; Load on value ldy RVS ; Load old value
ldy #$00 ; Assume old value is zero sta RVS ; Set new value
L1: lda RVS ; Load old value tya
stx RVS ; Set new value asl a
beq L2 ; Jump if old value zero rol a ; Either $00 or $01
iny ; Make old value = 1 clx
L2: ldx #$00 ; Load high byte of result
tya ; Load low byte, set CC
rts rts
.endproc .endproc

View File

@ -1,6 +1,5 @@
.interruptor ticktock, 24 .interruptor ticktock
.include "pce.inc"
.include "extzp.inc" .include "extzp.inc"
ticktock: ticktock:

View File

@ -7,9 +7,10 @@ vce_init:
; Set CTA to zero ; Set CTA to zero
stz VCE_ADDR_LO stz VCE_ADDR_LO
stz VCE_ADDR_HI stz VCE_ADDR_HI
ldy #$01
ldy #$01 ; Only background palettes
vce_clear_bank: vce_clear_bank:
ldx #$00 clx ; ldx #<$0100 ; <(16 * 16)
vce_clear_color: vce_clear_color:
stz VCE_DATA_LO ; Clear color (LSB) stz VCE_DATA_LO ; Clear color (LSB)
stz VCE_DATA_HI ; Clear color (MSB) stz VCE_DATA_HI ; Clear color (MSB)

View File

@ -8,33 +8,25 @@ HIRES = 1
vdc_init: vdc_init:
lda VDC_CTRL lda VDC_CTRL
VREG $00, $0000 ; MAWR VREG VDC_CR , $0000 ; disable display and interrupts
VREG $01, $0000 ; MARR VREG VDC_BXR, $0000 ; no scrolling
VREG $05, $0000 ; CR VREG VDC_BYR, $0000
VREG $06, $0000 ; RCR VREG VDC_MWR, $0070 ; 128 x 64 tiles (1024 x 512 pixels)
VREG $07, $0000 ; BXR VREG VDC_VSR, $1702 ; CRTC
VREG $08, $0000 ; BYR VREG VDC_VDR, $00DF ; CRTC - VDS
VREG $09, $0070 ; MWR VREG VDC_VCR, $000C ; CRTC - VDE
VREG $0C, $1702 ; CRTC - VSR VREG VDC_DCR, $0000
VREG $0D, $00DF ; CRTC - VDS
VREG $0E, $000C ; CRTC - VDE
VREG $0F, $0000 ; DCR
.if HIRES .if HIRES
VREG VDC_HSR, $0C02 ; CRTC
VREG $0A, $0C02 ; CRTC - HSR VREG VDC_HDR, $043C ; CRTC - HDS
VREG $0B, $043C ; CRTC - HDS
lda #$06 lda #$06
sta VCE_CTRL
.else .else
VREG VDC_HSR, $0202 ; CRTC
VREG $0A, $0202 ; CRTC - HSR VREG VDC_HDR, $041F ; CRTC - HDS
VREG $0B, $041F ; CRTC - HDS
lda #$04 lda #$04
sta VCE_CTRL
.endif .endif
sta VCE_CTRL
lda VDC_CTRL lda VDC_CTRL
rts rts

View File

@ -1,5 +1,9 @@
;----------------------------------------------------------------------------
; VGA font for the PC-Engine conio implementation
; VGA charset for the PC-Engine conio implementation ; The character tiles use only two colors from each pallette. Color zero
; comes from pallette zero; color one is different in each pallette. The
; color of a character is set by choosing one of the 16 pallettes.
.byte $00, $00, $00, $00, $00, $00, $00, $00 .byte $00, $00, $00, $00, $00, $00, $00, $00