From 9e1d39a409b02cba9277ec1231863a2c7f99b100 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 12 Jul 2015 16:40:52 +0200 Subject: [PATCH] more cleanup and fixing --- asminc/pce.inc | 4 +- cfg/pce.cfg | 23 +-- include/pce.h | 8 +- libsrc/pce/call.s | 17 --- libsrc/pce/clock.s | 8 +- libsrc/pce/condes.s | 96 ------------ libsrc/pce/conio.s | 3 - libsrc/pce/crt0.s | 221 ++++++++++++--------------- libsrc/pce/joy/pce-stdjoy.s | 5 - libsrc/pce/readme.txt | 31 +++- libsrc/pce/{_scrsize.s => scrsize.s} | 0 testcode/lib/pce/Makefile | 12 ++ testcode/lib/pce/conio.c | 5 +- 13 files changed, 162 insertions(+), 271 deletions(-) delete mode 100644 libsrc/pce/call.s delete mode 100644 libsrc/pce/condes.s rename libsrc/pce/{_scrsize.s => scrsize.s} (100%) create mode 100644 testcode/lib/pce/Makefile diff --git a/asminc/pce.inc b/asminc/pce.inc index 40e356cae..6d1541d64 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -11,7 +11,7 @@ CRAM_PTR = $34 ;2 CHARCOLOR = $36 RVS = $37 BGCOLOR = $38 -_tickcount = $39 ;2 +_tickcount = $39 ;4 screenrows = (224/8) charsperline = (512/8) @@ -74,11 +74,13 @@ CDR_MEM_ENABLE = $1807 .byte $ad .word arg1 .endmacro + ;; sta abs .macro staio arg1 .byte $8d .word arg1 .endmacro + ;; stz abs .macro stzio arg1 .byte $9c diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 566554b2e..adb420f32 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -28,13 +28,18 @@ SEGMENTS { } FEATURES { - CONDES: segment = STARTUP, - type=constructor, - label=__CONSTRUCTOR_TABLE__, - count=__CONSTRUCTOR_COUNT__; - - CONDES: segment = STARTUP, - type=destructor, - label=__DESTRUCTOR_TABLE__, - count=__DESTRUCTOR_COUNT__; + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; +# FIXME: interruptor support is missing +# CONDES: type = interruptor, +# label = __INTERRUPTOR_TABLE__, +# count = __INTERRUPTOR_COUNT__, +# segment = RODATA, +# import = __CALLIRQ__; } diff --git a/include/pce.h b/include/pce.h index 70d5800d0..912e0157b 100644 --- a/include/pce.h +++ b/include/pce.h @@ -28,13 +28,9 @@ /* */ /*****************************************************************************/ - - #ifndef _PCE_H #define _PCE_H - - /* Check for errors */ #if !defined(__PCE__) # error This module may only be used when compiling for the PCE! @@ -69,8 +65,8 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F -#define CLOCKS_PER_SEC 50 // ??? -#define CLK_TCK 50 // ?!? +#define CLOCKS_PER_SEC 50 // FIXME: is this correct? +#define CLK_TCK 50 // FIXME: is this correct? #define TV_NTSC 0 #define TV_PAL 1 diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s deleted file mode 100644 index db120a72f..000000000 --- a/libsrc/pce/call.s +++ /dev/null @@ -1,17 +0,0 @@ -; -; CC65 runtime: call function via pointer in ax -; - - .export callax - -.code - -callax: - sta vec - stx vec+1 - jmp (vec) ; jump there - -.bss - -vec: - .res 2 \ No newline at end of file diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 5f360916c..4271fdc61 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -9,10 +9,10 @@ .proc _clock - ldy #0 ; Byte 3 is always zero - sty sreg+1 - sty sreg - + lda _tickcount+3 + sta sreg+1 + lda _tickcount+2 + sta sreg ldx _tickcount+1 lda _tickcount rts diff --git a/libsrc/pce/condes.s b/libsrc/pce/condes.s deleted file mode 100644 index aa28833c2..000000000 --- a/libsrc/pce/condes.s +++ /dev/null @@ -1,96 +0,0 @@ -; -; Ullrich von Bassewitz, 20.11.2000 -; -; CC65 runtime: Support for calling module constructors/destructors -; -; The condes routine must be called with the table address in a/x and the -; size of the table in y. The current implementation limits the table size -; to 254 bytes (127 vectors) but this shouldn't be problem for now and may -; be changed later. -; -; libinit and libdone call condes with the predefined module constructor and -; destructor tables, they must be called from the platform specific startup -; code. - - - .export initlib, donelib, condes - - .import callax - .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ - .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ - - - -.code - -; -------------------------------------------------------------------------- -; Initialize library modules - -.proc initlib - - lda #<__CONSTRUCTOR_TABLE__ - ldx #>__CONSTRUCTOR_TABLE__ - ldy #<(__CONSTRUCTOR_COUNT__*2) - bne condes - rts - -.endproc - - -; -------------------------------------------------------------------------- -; Cleanup library modules - -.proc donelib - - lda #<__DESTRUCTOR_TABLE__ - ldx #>__DESTRUCTOR_TABLE__ - ldy #<(__DESTRUCTOR_COUNT__*2) - bne condes - rts - -.endproc - - -; -------------------------------------------------------------------------- -; Generic table call handler - -.proc condes - - sta getbyt+1 - stx getbyt+2 - sty index - -loop: ldy index - beq done - dey - jsr getbyt - tax - dey - jsr getbyt - sty index - jsr callax -.ifpc02 - bra loop -.else - jmp loop -.endif - -done: rts - -.endproc - - -; -------------------------------------------------------------------------- -; Data. The getbyte routine is placed in the data segment cause it's patched -; at runtime. - -.bss - -index: .byte 0 - -.data - -getbyt: -;;getbyt_: - lda $FFFF,y - rts diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 60801e172..9f113f515 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -5,7 +5,6 @@ .import vdc_init .export initconio - .export _conio_init .constructor initconio, 24 @@ -46,8 +45,6 @@ set_palette: stz VCE_DATA_LO stz VCE_DATA_HI - ; so it will get linked in -_conio_init: rts ;---------------------------------------------------------------------------- diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 06454998b..eab27ba5c 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -7,37 +7,38 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .export __STARTUP__ : absolute = 1 ; Mark as startup - .import initlib, donelib - .import push0, _main, zerobss - .import initheap - .import tmp1,tmp2,tmp3 - - .import __RAM_START__, __RAM_SIZE__ ; Linker generated -;; .import __SRAM_START__, __SRAM_SIZE__ ; Linker generated - .import __ROM0_START__, __ROM0_SIZE__ ; Linker generated - .import __ROM_START__, __ROM_SIZE__ ; Linker generated - .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ ; Linker generated - .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ ; Linker generated - .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ ; Linker generated - .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated - .import __BSS_SIZE__ - - .include "pce.inc" - - .importzp sp - .importzp ptr1,ptr2 + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup + + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 + + ; Linker generated + .import __RAM_START__, __RAM_SIZE__ + .import __ROM0_START__, __ROM0_SIZE__ + .import __ROM_START__, __ROM_SIZE__ + .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ + .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ + .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ + .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ + .import __BSS_SIZE__ + + .include "pce.inc" + + .importzp sp + .importzp ptr1,ptr2 ; ------------------------------------------------------------------------ ; Create an empty LOWCODE segment to avoid linker warnings -.segment "LOWCODE" + .segment "LOWCODE" ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. -.segment "STARTUP" + .segment "STARTUP" start: @@ -47,32 +48,32 @@ start: sei nop - csh ; set high speed CPU mode + csh ; set high speed CPU mode nop cld nop ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) + ldx #$FF ; Stack top ($21FF) txs ; at startup all MPRs are set to 0, so init them lda #$ff - tam #1 ; 0000-1FFF = Hardware page + tam #%00000001 ; 0000-1FFF = Hardware page lda #$F8 - tam #2 ; 2000-3FFF = Work RAM + tam #%00000010 ; 2000-3FFF = Work RAM ;lda #$F7 - ;tam #2 ; 4000-5FFF = Save RAM + ;tam #%00000100 ; 4000-5FFF = Save RAM ;lda #1 - ;tam #3 ; 6000-7FFF Page 2 + ;tam #%00001000 ; 6000-7FFF Page 2 ;lda #2 - ;tam #4 ; 8000-9FFF Page 3 + ;tam #%00010000 ; 8000-9FFF Page 3 ;lda #3 - ;tam #5 ; A000-BFFF Page 4 + ;tam #%00100000 ; A000-BFFF Page 4 ;lda #4 - ;tam #6 ; C000-DFFF Page 5 + ;tam #%01000000 ; C000-DFFF Page 5 ;lda #0 - ;tam #7 ; e000-fFFF hucard/syscard bank 0 + ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 ; Clear work RAM (2000-3FFF) stz <$00 @@ -88,110 +89,87 @@ start: .import vdc_init jsr vdc_init -;; jsr joy_init - ; Turn on background and VD interrupt/IRQ1 - lda #$05 sta IRQ_MASK ; IRQ1=on cli -; Clear the BSS data + ; Clear the BSS data + jsr zerobss - jsr zerobss - -; Copy the .data segment to RAM - - lda #<(__DATA_LOAD__) - ;;lda #<(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__) - ;;lda #<(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) - sta ptr1 - lda #>(__DATA_LOAD__) - ;;lda #>(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) - sta ptr1+1 - lda #<(__DATA_RUN__) - ;;lda #<(__SRAM_START__) - sta ptr2 - lda #>(__DATA_RUN__) - ;;lda #>(__SRAM_START__) - sta ptr2+1 - - ldx #>(__DATA_SIZE__) + ; Copy the .data segment to RAM + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y - iny - bne @l1 + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 - dex - bne @l2 + dex + bne @l2 - ; copy remaining bytes + ; copy remaining bytes @s1: - - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y - iny - cpy #<(__DATA_SIZE__) - bne @l3 - -; setup the stack + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 -; lda #<(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp -; lda #>(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 ; Set argument stack ptr + ; setup the stack + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 -; Init the Heap - jsr initheap + ; Init the Heap + jsr initheap -;jmp * + ; Call module constructors + jsr initlib -; Call module constructors + ;; FIXME: this should be called from a constructor instead + .import initconio + jsr initconio - jsr initlib + ; Pass an empty command line + jsr push0 ; argc + jsr push0 ; argv - ;; FIXME: this should be called from a constructor instead - .import initconio - jsr initconio - -; Pass an empty command line - - -;jmp * - - jsr push0 ; argc - jsr push0 ; argv -go: - ldy #4 ; Argument size - jsr _main ; call the users code - -; Call module destructors. This is also the _exit entry. + ldy #4 ; Argument size + jsr _main ; call the users code + ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors - -; reset the PCEngine + jsr donelib ; Run module destructors - jmp start + ; reset the PCEngine (start over) + jmp start ; ------------------------------------------------------------------------ ; System V-Blank Interupt +; FIXME: hooks should be provided so the user can abuse the IRQ ; ------------------------------------------------------------------------ _irq1: @@ -201,10 +179,13 @@ _irq1: inc _tickcount - bne @s + bne @s1 inc _tickcount+1 -@s: - + bne @s1 + inc _tickcount+2 + bne @s1 + inc _tickcount+3 +@s1: ; Acknowlege interrupt ldaio VDC_CTRL @@ -227,14 +208,10 @@ initmainargs: ; ------------------------------------------------------------------------ ; hardware vectors ; ------------------------------------------------------------------------ - .segment "VECTORS" - ;;.org $fff6 - - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer - .word _nmi ; $fffc NMI - .word start ; $fffe reset - - + .segment "VECTORS" + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 6bc6bdf57..1aa98e16d 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -25,11 +25,6 @@ ; Button state masks (8 values) -;extern const unsigned char joy_masks[8]; - - .export _joy_masks - -_joy_masks: .byte $10 ; JOY_UP .byte $40 ; JOY_DOWN .byte $80 ; JOY_LEFT diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index e99b55122..cd91de97a 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -1,19 +1,23 @@ +PC-Engine (PCE) target support for cc65. this is still work in progress and +a couple of things need to be fixed: +-------------------------------------------------------------------------------- -joystick support should get verified on real hw, the masks for buttons may be -wrong. - -clock() does not work for unknown reasons - -get_tv() is a dummy function and always returns 0 +joystick support should get verified on real hw + - the masks for buttons may be wrong. + - 6 button gamepads are different and need slightly different code revers() is a dummy function, actual reverse output is not supported yet waitvblank() is missing +get_tv() is missing some graphical petscii chars should get added to the charset conio-init should get initialized from a constructor rather than always get -called from crt0 +called from crt0 (which for some reason doesnt work) -> see conio.s, it should +get linked if _any_ of the conio function is used + +interruptor support in crt0 (and cfg) is missing -------------------------------------------------------------------------------- @@ -29,3 +33,16 @@ w/s/a/d up/down/left/right numpad 2 (?) button numpad 3 (?) button enter (start) button + +-------------------------------------------------------------------------------- +some useful resources on PCE coding: + +http://blog.blockos.org/?tag=pc-engine +http://pcedev.blockos.org/viewforum.php?f=5 +http://www.romhacking.net/?page=documents&category=&platform=4&game=&author=&perpage=20&level=&title=&desc=&docsearch=Go +http://archaicpixels.com/Main_Page + +http://www.magicengine.com/mkit/doc.html + +https://github.com/uli/huc +http://www.zeograd.com/parse.php?src=hucf \ No newline at end of file diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/scrsize.s similarity index 100% rename from libsrc/pce/_scrsize.s rename to libsrc/pce/scrsize.s diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile new file mode 100644 index 000000000..364074180 --- /dev/null +++ b/testcode/lib/pce/Makefile @@ -0,0 +1,12 @@ + +all: conio.pce + +conio.pce: conio.c + ../../../bin/cl65 -t pce conio.c ../../../joy/pce-stdjoy.joy --mapfile conio.map -o conio.pce + +clean: + $(RM) conio.pce + +test: conio.pce + mednafen -force_module pce conio.pce + diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 306eb1ebb..0c5c89c57 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -9,6 +9,7 @@ void main(void) { int stackvar = 42; int i, j; + clock_t clk; joy_install(&joy_static_stddrv); @@ -39,7 +40,9 @@ void main(void) ++datavar; ++stackvar; gotoxy(0,8); - cprintf("clock: %08x", clock()); + clk = clock(); + cprintf("clock: %08lx", clk); + for (i = 0; i < 4; ++i) { gotoxy(0, 12 + i); -- 2.39.5