From: mrdudz Date: Sun, 29 Nov 2015 19:04:10 +0000 (+0100) Subject: more cleanup X-Git-Tag: V2.16~178^2~11 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b39a8b7a618c049ec1c885d7af53fbee44494c18;p=cc65 more cleanup --- diff --git a/asminc/gamate.inc b/asminc/gamate.inc index 167c9b1e1..4e7fee2b0 100644 --- a/asminc/gamate.inc +++ b/asminc/gamate.inc @@ -51,20 +51,14 @@ COLOR_GREY2 = 1 COLOR_GREY1 = 2 COLOR_BLACK = 3 -;------------------------------------------------------------------------------- ; bios zp usage: -; -; 06/07 address of character set bitplane 1 -; 08/09 address of character set bitplane 2 -; 0a nmi $4800 echo -; 0b irq counter -; 0c nmi call cart nmi -; 0e/0f/10/11 big endian irq counter -; 15/16/17 ?/xpos/ypos -; -; e8 nmi reset to $ff -; - ZP_NMI_4800 = $0a -ZP_NMI_ENABLE = $0c +ZP_IRQ_COUNT = $0b +ZP_IRQ_CTRL = $0c + +ZP_IRQ_CNT1 = $0e +ZP_IRQ_CNT2 = $0f +ZP_IRQ_CNT3 = $10 +ZP_IRQ_CNT4 = $11 +ZP_NMI_FLAG = $e8 diff --git a/cfg/gamate.cfg b/cfg/gamate.cfg index d7c87b455..90ced1ea5 100644 --- a/cfg/gamate.cfg +++ b/cfg/gamate.cfg @@ -8,7 +8,8 @@ SYMBOLS { MEMORY { # 0000-03ff is RAM # FIXME: what zp range can we actually use? - ZP: start = $0020, size = $e0; + # $0a-$11 is used by IRQ/NMI, $e8 is used by NMI + ZP: start = $0012, size = $e8 - $12; CPUSTACK: start = $0100, size =$100; RAM: start = $0200, size = $200 - __STACKSIZE__, define = yes; diff --git a/include/gamate.h b/include/gamate.h index 7d5c02a9a..7b1c04a81 100644 --- a/include/gamate.h +++ b/include/gamate.h @@ -41,7 +41,8 @@ /* base clock cpu clock/32 ? -0/1: 1. channel(right): 12 bit frequency: right frequency 0 nothing, 1 high; 3 23khz; 4 17,3; 10 6,9; 15 4.6; $60 720hz; $eff 18,0; $fff 16,9 hz) +0/1: 1. channel(right): 12 bit frequency: right frequency 0 nothing, 1 high; + 3 23khz; 4 17,3; 10 6,9; 15 4.6; $60 720hz; $eff 18,0; $fff 16,9 hz) (delay clock/32) 2/3: 2. channel(left): 12 bit frequency 4/5: 3. channel(both): 12 bit frequency @@ -132,6 +133,26 @@ #define LCD_READ 0x5006 /* read from RAM (no auto inc?) */ #define LCD_DATA 0x5007 /* write to RAM */ +/* BIOS zeropage usage */ + +/* locations 0x0a-0x0c, 0x0e-0x11 and 0xe8 are in use by the BIOS IRQ/NMI handlers */ +#define ZP_NMI_4800 0x0a /* content of I/O reg 4800 gets copied here each NMI */ + +#define ZP_IRQ_COUNT 0x0b /* increments once per IRQ, used elsewhere in the + BIOS for synchronisation purposes */ +#define ZP_IRQ_CTRL 0x0c /* if 0 then cartridge irq stubs will not get called */ + +/* each of the following 4 increments by 1 per IRQ - it is _not_ a 32bit + counter (see code at $ffa6 in BIOS) + these are not used elsewhere in the bios and can be (re)setted as needed by + the user. +*/ +#define ZP_IRQ_CNT1 0x0e +#define ZP_IRQ_CNT2 0x0f +#define ZP_IRQ_CNT3 0x10 +#define ZP_IRQ_CNT4 0x11 + +#define ZP_NMI_FLAG 0xe8 /* set to 0xff each NMI */ /* constants for the conio implementation */ #define COLOR_BLACK 0x03 diff --git a/include/time.h b/include/time.h index 33bcbb569..22e24a56e 100644 --- a/include/time.h +++ b/include/time.h @@ -103,8 +103,8 @@ unsigned _clocks_per_sec (void); # define CLK_TCK 60 /* POSIX */ # define CLOCKS_PER_SEC 60 /* ANSI */ #elif defined(__GAMATE__) -# define CLK_TCK 60 /* POSIX */ /* FIXME */ -# define CLOCKS_PER_SEC 60 /* ANSI */ /* FIXME */ +# define CLK_TCK 135 /* POSIX */ /* FIXME */ +# define CLOCKS_PER_SEC 135 /* ANSI */ /* FIXME */ #elif defined(__GEOS__) # define CLK_TCK 1 /* POSIX */ # define CLOCKS_PER_SEC 1 /* ANSI */ diff --git a/libsrc/gamate/clrscr.s b/libsrc/gamate/clrscr.s index c96fc4eda..31a7a1874 100644 --- a/libsrc/gamate/clrscr.s +++ b/libsrc/gamate/clrscr.s @@ -6,10 +6,10 @@ .export _clrscr _clrscr: ldy #$0 + tya rowloop: sty LCD_X - lda #0 sta LCD_Y ldx #$0 diff --git a/libsrc/gamate/cputc.s b/libsrc/gamate/cputc.s index 0ebd659b2..7c95ba8fc 100644 --- a/libsrc/gamate/cputc.s +++ b/libsrc/gamate/cputc.s @@ -65,16 +65,6 @@ plot: ldy CURS_X ; position in Y putchar: - -; FIXME -; ora RVS ; Set revers bit - -; sty temp_y -; stx temp_x -; sta temp_a - -; lda temp_a - sta ptr3 txa @@ -139,8 +129,6 @@ putchar: bne @copylp2 @skip_plane2: - - pla tax ldy CURS_X diff --git a/libsrc/gamate/crt0.s b/libsrc/gamate/crt0.s index 5df5ad38c..ead45b7ea 100644 --- a/libsrc/gamate/crt0.s +++ b/libsrc/gamate/crt0.s @@ -17,8 +17,12 @@ Start: sei cld + ldx #0 + stx ZP_IRQ_CTRL ; disable calling cartridge IRQ/NMI handler + ; Setup stack and memory mapping - ldx #$FF ; Stack top ($01FF) + ;ldx #$FF ; Stack top ($01FF) + dex txs ; Clear the BSS data @@ -36,6 +40,8 @@ Start: ; Call module constructors jsr initlib + lda #1 + sta ZP_IRQ_CTRL ; enable calling cartridge IRQ/NMI handler cli ; allow IRQ only after constructors have run ; Pass an empty command line diff --git a/libsrc/gamate/extzp.inc b/libsrc/gamate/extzp.inc index 3e24d6e45..b6f08bcad 100644 --- a/libsrc/gamate/extzp.inc +++ b/libsrc/gamate/extzp.inc @@ -1,7 +1,7 @@ ; ; extzp.inc for the Gamate ; -; Groepaz/Hitmen, 2015-11-19 +; Groepaz/Hitmen, 2015-11-27 ; ; Assembler include file that imports the runtime zero page locations used ; by the Gamate runtime, ready for usage in asm code. diff --git a/libsrc/gamate/extzp.s b/libsrc/gamate/extzp.s index d3189dcdd..41f559233 100644 --- a/libsrc/gamate/extzp.s +++ b/libsrc/gamate/extzp.s @@ -1,5 +1,5 @@ ; -; Groepaz/Hitmen, 2015-11-19 +; Groepaz/Hitmen, 2015-11-27 ; ; zeropage locations for exclusive use by the library ; diff --git a/libsrc/gamate/irq.s b/libsrc/gamate/irq.s index 4adbcb405..862307f58 100644 --- a/libsrc/gamate/irq.s +++ b/libsrc/gamate/irq.s @@ -30,9 +30,10 @@ doneirq: ; -> guess 16384 clock cycles = 135,28hz (might be audio signal 1/512?) IRQStub: - pha - tya - pha + ; A and Y are saved by the BIOS + ;pha + ;tya + ;pha ldy #<(__INTERRUPTOR_COUNT__ * 2) beq @L1 @@ -45,7 +46,7 @@ IRQStub: pla tax -@L1: pla - tay - pla +@L1: ;pla + ;tay + ;pla rts diff --git a/libsrc/gamate/nmi.s b/libsrc/gamate/nmi.s index 918431340..61db62416 100644 --- a/libsrc/gamate/nmi.s +++ b/libsrc/gamate/nmi.s @@ -3,5 +3,19 @@ ; .export NMIStub + .segment "INIT" + NMIStub: - rts \ No newline at end of file + ; A is saved by the BIOS + ;pha + ;txa + ;pha + ;tya + ;pha + + ;pla + ;tay + ;pla + ;tax + ;pla + rts diff --git a/testcode/lib/gamate/audiotest.s b/testcode/lib/gamate/audiotest.s index 1b5d22767..6eab34b22 100644 --- a/testcode/lib/gamate/audiotest.s +++ b/testcode/lib/gamate/audiotest.s @@ -1,38 +1,40 @@ - +; ; original audiotest.s by PeT (mess@utanet.at) +; +; cl65 -t gamate -o audiotest.bin audiotest.s +; .include "gamate.inc" .zeropage -addr: .word 0 -psa: .word 0 - -.word 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 ; get out of sensitiv area - -readaddr: .word 0 -editbuffer1: .byte 0,0,0,0, 0,0,0,0 ;0,1,2,3,4,5,6,7 -writeaddr: .word 0 -editbuffer2: .byte 0,0,0,0, 0,0,0,0 ;8,9,$a,$b,$c,$d,$e,$f -cursor: .byte 0 -controlslast: .byte 0 -controlsedge: .byte 0 - -.data -temp_x: .byte 0 -temp_y: .byte 0 -temp_a: .byte 0 -irq_count: .byte 0 -nmi_count: .byte 0 -psx: .byte 0 -psy: .byte 0 -xpos: .byte 0 -ypos: .byte 0 - - .code +addr: .word 0 +psa: .word 0 +readaddr: .word 0 +editbuffer1: .byte 0,0,0,0, 0,0,0,0 +writeaddr: .word 0 +editbuffer2: .byte 0,0,0,0, 0,0,0,0 +cursor: .byte 0 +controlslast: .byte 0 +controlsedge: .byte 0 + + .bss +temp_x: .byte 0 +temp_y: .byte 0 +temp_a: .byte 0 +irq_count: .byte 0 +nmi_count: .byte 0 +psx: .byte 0 +psy: .byte 0 +xpos: .byte 0 +ypos: .byte 0 + + .rodata chars: .incbin "cga2.chr" hex2asc: .byte "0123456789abcdef" + .code + ;------------------------------------------------------------------------------- .export IRQStub, NMIStub @@ -41,7 +43,7 @@ hex2asc: .byte "0123456789abcdef" rts .endproc -.proc IRQStub +.proc IRQStub inc irq_count rts .endproc @@ -50,141 +52,144 @@ hex2asc: .byte "0123456789abcdef" .export Start .proc Start - lda #>AUDIO_BASE - sta writeaddr+1 - sta readaddr+1 - lda #AUDIO_BASE + sta writeaddr+1 + sta readaddr+1 + lda #chars - sta addr+1 - ldx #8 - ldy #0 + adc #chars + sta addr+1 + ldx #8 + ldy #0 printsign1: - lda (addr),y - sta LCD_DATA + lda (addr),y + sta LCD_DATA iny dex - bne printsign1 - ldx temp_x - ldy temp_y + bne printsign1 + ldx temp_x + ldy temp_y rts .endproc - diff --git a/testcode/lib/gamate/lcdtest.s b/testcode/lib/gamate/lcdtest.s index 3ac8f968b..3a8d72226 100644 --- a/testcode/lib/gamate/lcdtest.s +++ b/testcode/lib/gamate/lcdtest.s @@ -1,35 +1,39 @@ - +; ; original lcdtest.s by PeT (mess@utanet.at) +; +; cl65 -t gamate -o lcdtest.bin lcdtest.s +; .include "gamate.inc" .zeropage -addr: .word 0 -psa: .word 0 - - .data -temp_x: .byte 0 -temp_y: .byte 0 -temp_a: .byte 0 -irq_count: .byte 0 -nmi_count: .byte 0 -psx: .byte 0 -psy: .byte 0 -count: .word 0 -counted: .word 0 -xpos: .byte 0 -ypos: .byte 0 - -.code - -chars: - .incbin "cga2.chr" +addr: .word 0 +psa: .word 0 + + .bss +temp_x: .byte 0 +temp_y: .byte 0 +temp_a: .byte 0 +irq_count: .byte 0 +nmi_count: .byte 0 +psx: .byte 0 +psy: .byte 0 +count: .word 0 +counted: .word 0 +xpos: .byte 0 +ypos: .byte 0 + + .rodata + +chars: .incbin "cga2.chr" hex2asc: .byte "0123456789abcdef" format: .byte "IrqNmiCountXposYpos", 0 xdesc: .byte "0123456789abcdefghijklmnopqrstuv", 0 ydesc: .byte "0123456789ABCDEFGHIJKLMNOPQRSTUV", 0 + .code + ;------------------------------------------------------------------------------- .export IRQStub, NMIStub @@ -57,278 +61,295 @@ ydesc: .byte "0123456789ABCDEFGHIJKLMNOPQRSTUV", 0 .export Start .proc Start + sei + lda #0 + sta ZP_IRQ_CTRL lda #0 - sta LCD_XPOS - sta LCD_YPOS + sta LCD_XPOS + sta LCD_YPOS cli - lda #LCD_MODE_INC_Y - sta LCD_MODE + lda #LCD_MODE_INC_Y + sta LCD_MODE - lda #0 - sta LCD_X - lda #xdesc - ldy #0 - jsr printstring - - lda #LCD_XPOS_PLANE2 - sta LCD_X - lda #xdesc - ldy #128 - jsr printstring + lda #0 + sta LCD_X + lda #xdesc + ldy #0 + jsr printstring - lda #0 - sta LCD_X - lda #ydesc - ldy #0 - sty LCD_Y - jsr printstringy - -; lda #$90;(LCD_XPOS_PLANE2|(128/8)) - lda #(LCD_XPOS_PLANE2|(128/8)) - sta LCD_X - lda #ydesc - ldy #0 - sty LCD_Y - jsr printstringy - - lda #format - ldy #8 - jsr printstring + lda #LCD_XPOS_PLANE2 + sta LCD_X + lda #xdesc + ldy #128 + jsr printstring - lda #0 - sta LCD_MODE - lda #24/8 - sta LCD_X - lda #24 - sta LCD_Y - lda #'X' - jsr printsign - lda #$80 - sta LCD_MODE - lda #32/8 - sta LCD_X - lda #32 - sta LCD_Y - lda #'Y' - jsr printsign - lda #$c0 - sta LCD_MODE - lda #40/8 - sta LCD_X - lda #40 - sta LCD_Y - lda #'Z' - jsr printsign + lda #0 + sta LCD_X + lda #ydesc + ldy #0 + sty LCD_Y + jsr printstringy - lda #0 - sta LCD_MODE - lda #LCD_XPOS_PLANE2|(48/8) - sta LCD_X - lda #48 - sta LCD_Y - lda #'x' - jsr printsign - lda #$80 - sta LCD_MODE - lda #(LCD_XPOS_PLANE2|(56/8)) - sta LCD_X - lda #56 - sta LCD_Y - lda #'y' - jsr printsign - lda #$c0 - sta LCD_MODE - lda #(LCD_XPOS_PLANE2|(64/8)) - sta LCD_X - lda #64 - sta LCD_Y - lda #'z' - jsr printsign - - lda #LCD_MODE_INC_Y|1 - sta LCD_MODE - lda #16/8 - sta LCD_X - lda #72 - sta LCD_Y - lda #'V' - jsr printsign - lda #LCD_MODE_INC_Y|2 - sta LCD_MODE - lda #24/8 - sta LCD_X - lda #72 - sta LCD_Y - lda #'V' - jsr printsign - lda #LCD_MODE_INC_Y|4 - sta LCD_MODE - lda #32/8 - sta LCD_X - lda #72 - sta LCD_Y - lda #'V' - jsr printsign - lda #LCD_MODE_INC_Y|8 - sta LCD_MODE - lda #40/8 - sta LCD_X - lda #72 - sta LCD_Y - lda #'V' - jsr printsign - - - lda #1 - sta ZP_NMI_ENABLE - -loop: lda count + lda #(LCD_XPOS_PLANE2|(128/8)) ; ??? + sta LCD_X + lda #ydesc + ldy #0 + sty LCD_Y + jsr printstringy + + lda #format + ldy #8 + jsr printstring + + lda #0 + sta LCD_MODE + lda #24/8 + sta LCD_X + lda #24 + sta LCD_Y + lda #'X' + jsr printsign + + lda #$80 + sta LCD_MODE + lda #32/8 + sta LCD_X + lda #32 + sta LCD_Y + lda #'Y' + jsr printsign + + lda #$c0 + sta LCD_MODE + lda #40/8 + sta LCD_X + lda #40 + sta LCD_Y + lda #'Z' + jsr printsign + + lda #0 + sta LCD_MODE + lda #LCD_XPOS_PLANE2|(48/8) + sta LCD_X + lda #48 + sta LCD_Y + lda #'x' + jsr printsign + + lda #$80 + sta LCD_MODE + lda #(LCD_XPOS_PLANE2|(56/8)) + sta LCD_X + lda #56 + sta LCD_Y + lda #'y' + jsr printsign + + lda #$c0 + sta LCD_MODE + lda #(LCD_XPOS_PLANE2|(64/8)) + sta LCD_X + lda #64 + sta LCD_Y + lda #'z' + jsr printsign + + lda #LCD_MODE_INC_Y|1 + sta LCD_MODE + lda #16/8 + sta LCD_X + lda #72 + sta LCD_Y + lda #'V' + jsr printsign + + lda #LCD_MODE_INC_Y|2 + sta LCD_MODE + lda #24/8 + sta LCD_X + lda #72 + sta LCD_Y + lda #'V' + jsr printsign + + lda #LCD_MODE_INC_Y|4 + sta LCD_MODE + lda #32/8 + sta LCD_X + lda #72 + sta LCD_Y + lda #'V' + jsr printsign + + lda #LCD_MODE_INC_Y|8 + sta LCD_MODE + lda #40/8 + sta LCD_X + lda #72 + sta LCD_Y + lda #'V' + jsr printsign + + lda #1 + sta ZP_IRQ_CTRL + +loop: + lda count clc - adc #1 - sta count - lda count+1 - adc #1 - sta count+1 - lda irq_count - cmp irq_count - beq loop + adc #1 + sta count + lda count+1 + adc #0 + sta count+1 - jsr inputs - lda #LCD_MODE_INC_Y - sta LCD_MODE - jsr printy + lda irq_count + cmp irq_count + beq loop + jsr inputs + lda #LCD_MODE_INC_Y + sta LCD_MODE + jsr printy - jmp loop + jmp loop .endproc ;------------------------------------------------------------------------------- .proc printy - ldx #0 - ldy #16 - lda irq_count - jsr printhex - - ldx #3 - ldy #16 - lda nmi_count - jsr printhex - - ldx #6 - ldy #16 - lda counted+1 - jsr printhex - ldx #8 - ldy #16 - lda counted - jsr printhex - - ldx #11 - ldy #16 - lda xpos - jsr printhex - ldx #14 - ldy #16 - lda ypos - jsr printhex + ldx #0 + ldy #16 + lda irq_count + jsr printhex + + ldx #3 + ldy #16 + lda nmi_count + jsr printhex + + ldx #6 + ldy #16 + lda counted+1 + jsr printhex + ldx #8 + ldy #16 + lda counted + jsr printhex + + ldx #11 + ldy #16 + lda xpos + jsr printhex + ldx #14 + ldy #16 + lda ypos + jsr printhex rts .endproc .proc inputs - lda JOY_DATA - and #JOY_DATA_UP - bne notup - dec ypos - lda ypos - sta LCD_YPOS -notup:lda JOY_DATA - and #JOY_DATA_DOWN - bne notdown - inc ypos - lda ypos - sta LCD_YPOS -notdown:lda JOY_DATA - and #JOY_DATA_LEFT - bne notleft - dec xpos - lda xpos - sta LCD_XPOS -notleft:lda JOY_DATA - and #JOY_DATA_RIGHT - bne notright - inc xpos - lda xpos - sta LCD_XPOS -notright:lda JOY_DATA - and #JOY_DATA_START - bne notstart -notstart:lda JOY_DATA - and #JOY_DATA_SELECT - bne notselect -notselect:lda JOY_DATA - and #JOY_DATA_FIRE_A - bne notbuttona -notbuttona:lda JOY_DATA - and #JOY_DATA_FIRE_B - bne notbuttonb -notbuttonb:rts + lda JOY_DATA + and #JOY_DATA_UP + bne notup + dec ypos + lda ypos + sta LCD_YPOS +notup: + lda JOY_DATA + and #JOY_DATA_DOWN + bne notdown + inc ypos + lda ypos + sta LCD_YPOS +notdown: + lda JOY_DATA + and #JOY_DATA_LEFT + bne notleft + dec xpos + lda xpos + sta LCD_XPOS +notleft: + lda JOY_DATA + and #JOY_DATA_RIGHT + bne notright + inc xpos + lda xpos + sta LCD_XPOS +notright: + lda JOY_DATA + and #JOY_DATA_START + bne notstart +notstart: + lda JOY_DATA + and #JOY_DATA_SELECT + bne notselect +notselect: + lda JOY_DATA + and #JOY_DATA_FIRE_A + bne notbuttona +notbuttona: + lda JOY_DATA + and #JOY_DATA_FIRE_B + bne notbuttonb +notbuttonb: + rts .endproc ;------------------------------------------------------------------------------- .proc printstring - sta psa - stx psa+1 - ldx #0 - stx psx - sty psy + sta psa + stx psa+1 + ldx #0 + stx psx + sty psy printstring2: - ldy #0 - lda (psa),y - beq printstring1 - ldx psx - stx LCD_X - ldy psy - sty LCD_Y - jsr printsign - inc psx - lda psa + ldy #0 + lda (psa),y + beq printstring1 + ldx psx + stx LCD_X + ldy psy + sty LCD_Y + jsr printsign + inc psx + lda psa clc - adc #1 - sta psa - lda psa+1 - adc #0 - sta psa+1 - jmp printstring2 + adc #1 + sta psa + lda psa+1 + adc #0 + sta psa+1 + jmp printstring2 printstring1: rts .endproc .proc printstringy - sta psa - stx psa+1 + sta psa + stx psa+1 printstring2: - ldy #0 - lda (psa),y - beq printstring1 - jsr printsign - lda psa + ldy #0 + lda (psa),y + beq printstring1 + jsr printsign + lda psa clc - adc #1 - sta psa - lda psa+1 - adc #0 - sta psa+1 - jmp printstring2 + adc #1 + sta psa + lda psa+1 + adc #0 + sta psa+1 + jmp printstring2 printstring1: rts .endproc @@ -340,24 +361,24 @@ printstring1: lsr lsr lsr - and #$0f - stx temp_x + and #$0f + stx temp_x tax - lda hex2asc,x - ldx temp_x - stx LCD_X - sty LCD_Y - jsr printsign + lda hex2asc,x + ldx temp_x + stx LCD_X + sty LCD_Y + jsr printsign pla - and #$0f + and #$0f inx - stx temp_x + stx temp_x tax - lda hex2asc,x - ldx temp_x - stx LCD_X - sty LCD_Y - jmp printsign + lda hex2asc,x + ldx temp_x + stx LCD_X + sty LCD_Y + jmp printsign .endproc .proc printsign