]> git.sur5r.net Git - cc65/commitdiff
more cleanup and fixing
authormrdudz <mrdudz@users.noreply.github.com>
Sun, 12 Jul 2015 14:40:52 +0000 (16:40 +0200)
committermrdudz <mrdudz@users.noreply.github.com>
Sun, 12 Jul 2015 14:40:52 +0000 (16:40 +0200)
14 files changed:
asminc/pce.inc
cfg/pce.cfg
include/pce.h
libsrc/pce/_scrsize.s [deleted file]
libsrc/pce/call.s [deleted file]
libsrc/pce/clock.s
libsrc/pce/condes.s [deleted file]
libsrc/pce/conio.s
libsrc/pce/crt0.s
libsrc/pce/joy/pce-stdjoy.s
libsrc/pce/readme.txt
libsrc/pce/scrsize.s [new file with mode: 0644]
testcode/lib/pce/Makefile [new file with mode: 0644]
testcode/lib/pce/conio.c

index 40e356caef5499a7315650358cace537543b22f8..6d1541d64c942fc7865a3b2f615c5204ce0b6d0a 100644 (file)
@@ -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
index 566554b2e00730adee48e7794c1d4655781fb6ac..adb420f32bf70285f3ad12e8f7bcda21c11fe468 100644 (file)
@@ -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__;
 }
index 70d5800d0da7c51c30d18d9939a722b86bc2efaa..912e0157be786a34f971fc378567f477bfb38b05 100644 (file)
 /*                                                                           */
 /*****************************************************************************/
 
-
-
 #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/_scrsize.s b/libsrc/pce/_scrsize.s
deleted file mode 100644 (file)
index 6e2b84a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-;
-; Screen size variables
-;
-
-                .export _screensize
-_screensize:
-                ldx     xsize
-                ldy     ysize
-                rts
-
-.rodata
-                .export xsize, ysize
-
-xsize:          .byte 64
-ysize:          .byte 28
diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s
deleted file mode 100644 (file)
index db120a7..0000000
+++ /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
index 5f360916c180999ecdb253aa60b5be894f688689..4271fdc61ecce448e6e20a92025119e9ea4baaa8 100644 (file)
@@ -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 (file)
index aa28833..0000000
+++ /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
index 60801e1729053d0680e6d7da430410ddee837db1..9f113f5154dfb0c17d9bff0c1c81d215eb1d6149 100644 (file)
@@ -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
 
 ;----------------------------------------------------------------------------
index 06454998b0a5fa166dbb838af2a6ace78edfebed..eab27ba5c342786651ba886c58c2f40ded4707c6 100644 (file)
@@ -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
index 6bc6bdf57f20ac57d5fde767ec08cfc33b09da83..1aa98e16dc92ced814fbecc62114e779ca839f4b 100644 (file)
 
 ; 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
index e99b5512260c58c3ad2f0d8101e25c94256840cf..cd91de97a4acd938e449778a3bcf76d29f122104 100644 (file)
@@ -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
new file mode 100644 (file)
index 0000000..6e2b84a
--- /dev/null
@@ -0,0 +1,15 @@
+;
+; Screen size variables
+;
+
+                .export _screensize
+_screensize:
+                ldx     xsize
+                ldy     ysize
+                rts
+
+.rodata
+                .export xsize, ysize
+
+xsize:          .byte 64
+ysize:          .byte 28
diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile
new file mode 100644 (file)
index 0000000..3640741
--- /dev/null
@@ -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
+
index 306eb1ebbe00981bd6dcebc792ed927b1de13923..0c5c89c57a7551081c2c10eadc20b199e0ca4cc9 100644 (file)
@@ -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);