From 891cb97b2f0c0e6816b63ab7cb167ec17e67603d Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 12 Jul 2015 14:27:24 +0200 Subject: [PATCH] more cleanup, joystick works again --- libsrc/pce/pcengine.inc => asminc/pce.inc | 51 ++-- cfg/pce.cfg | 70 ++---- include/pce.h | 167 +++++++------ libsrc/pce/call.s | 12 +- libsrc/pce/clock.s | 13 +- libsrc/pce/clrscr.s | 2 +- libsrc/pce/color.s | 84 ++++--- libsrc/pce/condes.s | 6 - libsrc/pce/conio.s | 199 +++++++--------- libsrc/pce/cputc.s | 126 ++++------ libsrc/pce/crt0.s | 10 +- libsrc/pce/ctype.s | 161 +++++++++++++ libsrc/pce/gotoxy.s | 17 +- libsrc/pce/joy/pce-stdjoy.s | 162 +++++++++++++ libsrc/pce/joy_stat_stddrv.s | 14 ++ libsrc/pce/joy_stddrv.s | 13 + libsrc/pce/joytokbd.s | 275 ---------------------- libsrc/pce/kplot.s | 47 ++-- libsrc/pce/libref.s | 8 + libsrc/pce/pce-stdjoy.s | 191 --------------- libsrc/pce/psg.s | 44 ++-- libsrc/pce/readme.txt | 31 +++ libsrc/pce/revers.s | 6 +- libsrc/pce/vce.s | 2 +- libsrc/pce/vdc.s | 2 +- testcode/lib/conio.c | 10 - testcode/lib/pce/conio.c | 58 +++++ 27 files changed, 842 insertions(+), 939 deletions(-) rename libsrc/pce/pcengine.inc => asminc/pce.inc (74%) create mode 100644 libsrc/pce/ctype.s create mode 100644 libsrc/pce/joy/pce-stdjoy.s create mode 100644 libsrc/pce/joy_stat_stddrv.s create mode 100644 libsrc/pce/joy_stddrv.s delete mode 100644 libsrc/pce/joytokbd.s create mode 100644 libsrc/pce/libref.s delete mode 100644 libsrc/pce/pce-stdjoy.s create mode 100644 libsrc/pce/readme.txt delete mode 100644 testcode/lib/conio.c create mode 100644 testcode/lib/pce/conio.c diff --git a/libsrc/pce/pcengine.inc b/asminc/pce.inc similarity index 74% rename from libsrc/pce/pcengine.inc rename to asminc/pce.inc index a0ef03f6a..40e356cae 100644 --- a/libsrc/pce/pcengine.inc +++ b/asminc/pce.inc @@ -1,12 +1,17 @@ +; +; PCE definitions. By Groepaz/Hitmem. +; -; Write VDC register - .macro VREG arg1,arg2 - st0 #arg1 - st1 #<(arg2) - st2 #>(arg2) - .endmacro +;; FIXME: optimize zeropage usage -_tickcount= $20 +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 ;2 +CRAM_PTR = $34 ;2 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR = $38 +_tickcount = $39 ;2 screenrows = (224/8) charsperline = (512/8) @@ -15,14 +20,6 @@ xsize = charsperline CH_HLINE = 7 CH_VLINE = 7 -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 -CRAM_PTR = $34 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR=$38 - ; huc6270 - Video Display Controller (vdc) VDC_MAWR = 0 ; Memory Address Write Register @@ -45,9 +42,9 @@ VDC_DESR =16 ; (DMA) Destination Register VDC_LENR =17 ; (DMA) Length Register VDC_SATB =18 ; Sprite Attribute Table -VDC_CTRL = $0000 -VDC_DATA_LO = $0002 -VDC_DATA_HI = $0003 +VDC_CTRL = $0000 +VDC_DATA_LO = $0002 +VDC_DATA_HI = $0003 ; huc6260 - Video Color Encoder (vce) @@ -61,18 +58,17 @@ VCE_ADDR_HI = $0403 ; MSB of byte offset into palette VCE_DATA_LO = $0404 ; LSB of 16-bit palette data VCE_DATA_HI = $0405 ; MSB of 16-bit palette data -TIMER_COUNT = $0c00 -TIMER_CTRL = $0c01 +TIMER_COUNT = $0c00 +TIMER_CTRL = $0c01 -JOY_CTRL = $1000 +JOY_CTRL = $1000 -IRQ_MASK = $1402 -IRQ_STATUS = $1403 +IRQ_MASK = $1402 +IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 CDR_MEM_ENABLE = $1807 - ;; lda abs .macro ldaio arg1 .byte $ad @@ -88,3 +84,10 @@ CDR_MEM_ENABLE = $1807 .byte $9c .word arg1 .endmacro + +; Write VDC register +.macro VREG arg1,arg2 + st0 #arg1 + st1 #<(arg2) + st2 #>(arg2) +.endmacro diff --git a/cfg/pce.cfg b/cfg/pce.cfg index f848fd737..566554b2e 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,62 +1,32 @@ +# linker config to produce simple NEC PC-Engine cartridge (.pce) + SYMBOLS { __STACKSIZE__: type = weak, value = $0300; # 3 pages stack } -MEMORY { - - ZP: start = $00, size = $1A, type = rw, define = yes; - - # INES Cartridge Header - #HEADER: start = $0, size = $10, file = %O ,fill = yes; - - # 2 16K ROM Banks - # - startup - # - code - # - rodata - # - data (load) - # 1 8k CHR Bank - ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; - # Hardware Vectors at End of 2nd 8K ROM - ROMV: start = $fff6, size = $a, file = %O,fill = yes; -# ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; - - - # standard 2k SRAM (-zeropage) - # $0100-$0200 cpu stack - # $0200-$0500 3 pages for ppu memory write buffer - # $0500-$0800 3 pages for cc65 parameter stack - #SRAM: start = $0500, size = $0300, define = yes; +MEMORY { + # FIXME: is this correct? the first 3? bytes cant be used? + ZP: start = $03, size = $1A, type = rw, define = yes; - # additional 8K SRAM Bank - # - data (run) - # - bss - # - heap -# RAM: start = $2200, size = $1000, define = yes; -# RAM2: start = $3200, size = $0e00, define = yes; - RAM: start = $2200, size = $1e00, define = yes; + # reset-bank and hardware vectors + ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; + ROMV: start = $fff6, size = $a, file = %O,fill = yes; + # first RAM page (also contains stack and zeropage) + RAM: start = $2200, size = $1e00, define = yes; } -SEGMENTS { - #HEADER: load = HEADER, type = wprot; - - #aSTARTUP: load = ROM0, type = wprot, define = yes; - STARTUP: load = ROM0, type = ro, define = yes; - - INIT: load = ROM0, type = ro, define = yes, optional = yes; - CODE: load = ROM0, type = ro, define = yes; - RODATA: load = ROM0, type = ro, define = yes; - - DATA: load = ROM0, run= RAM, type = rw, define = yes; -# BSS: load = RAM2, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - - VECTORS: load = ROMV, type = rw, define = yes; - #CHARS: load = ROM2, type = rw; - - - ZEROPAGE: load = ZP, type = zp, define = yes; +SEGMENTS { + STARTUP: load = ROM0, type = ro, define = yes; + INIT: load = ROM0, type = ro, define = yes, optional = yes; + CODE: load = ROM0, type = ro, define = yes; + RODATA: load = ROM0, type = ro, define = yes; + DATA: load = ROM0, run= RAM, type = rw, define = yes; + BSS: load = RAM, type = bss, define = yes; + VECTORS: load = ROMV, type = rw, define = yes; + ZEROPAGE: load = ZP, type = zp, define = yes; } + FEATURES { CONDES: segment = STARTUP, type=constructor, diff --git a/include/pce.h b/include/pce.h index 8135679a2..70d5800d0 100644 --- a/include/pce.h +++ b/include/pce.h @@ -1,74 +1,99 @@ -#define CH_CROSS 0x10 - -#define CH_RTEE 0x17 -#define CH_LTEE 0x0f - -#define CH_ULCORNER 0x10 -#define CH_URCORNER 0x10 -#define CH_LLCORNER 0x10 -#define CH_LRCORNER 0x10 - - -#define TV_NTSC 0 -#define TV_PAL 1 -#define get_tv() 0 - -#define CLOCKS_PER_SEC 50 // ??? -#define CLK_TCK 50 // ?!? - -//#ifndef CH_ENTER -#define CH_ENTER '\n' -//#endif - -#define CH_STOP 0x08 - -#define CH_F1 0x14 -#define CH_F3 0x15 -#define CH_F5 0x16 -#define CH_F7 0x17 - -#define CH_CURS_UP 0x01 -#define CH_CURS_DOWN 0x02 - -#ifndef CH_CURS_LEFT -#define CH_CURS_LEFT 0x03 +/*****************************************************************************/ +/* */ +/* pce.h */ +/* */ +/* PC-Engine system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 2015 Groepaz/Hitmen */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _PCE_H +#define _PCE_H + + + +/* Check for errors */ +#if !defined(__PCE__) +# error This module may only be used when compiling for the PCE! #endif -#ifndef CH_CURS_RIGHT -#define CH_CURS_RIGHT 0x04 +/* FIXME: the respective characters are not present in the VGA charset (yet) */ +#define CH_CROSS 0x10 + +#define CH_RTEE 0x17 +#define CH_LTEE 0x0f + +#define CH_ULCORNER 0x10 +#define CH_URCORNER 0x10 +#define CH_LLCORNER 0x10 +#define CH_LRCORNER 0x10 + +/* Color defines (CBM compatible, for conio) */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_VIOLET 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +#define CLOCKS_PER_SEC 50 // ??? +#define CLK_TCK 50 // ?!? + +#define TV_NTSC 0 +#define TV_PAL 1 +#define TV_OTHER 2 + +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 + +/* The addresses of the static drivers */ +extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ + +#define JOY_FIRE_B 5 +#define JOY_START 6 +#define JOY_SELECT 7 + +/* FIXME: not implemented */ +void waitvblank (void); +/* Wait for the vertical blanking */ + +/* FIXME: not implemented */ +unsigned char get_tv (void); +/* Return the video mode the machine is using. */ + + +/* End of pce.h */ #endif - -#define CH_ESC 8 - -#define CH_DEL 20 - -/* Color defines */ -#define COLOR_BLACK 0x00 -#define COLOR_WHITE 0x01 -#define COLOR_RED 0x02 -#define COLOR_CYAN 0x03 -#define COLOR_VIOLET 0x04 -#define COLOR_GREEN 0x05 -#define COLOR_BLUE 0x06 -#define COLOR_YELLOW 0x07 -#define COLOR_ORANGE 0x08 -#define COLOR_BROWN 0x09 -#define COLOR_LIGHTRED 0x0A -#define COLOR_GRAY1 0x0B -#define COLOR_GRAY2 0x0C -#define COLOR_LIGHTGREEN 0x0D -#define COLOR_LIGHTBLUE 0x0E -#define COLOR_GRAY3 0x0F - -#define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 - -/* -void __fastcall__ waitvblank(void); - -unsigned char __fastcall__ cpeekcharxy(unsigned char x,unsigned char y); -unsigned char __fastcall__ cpeekchar(void); -unsigned char __fastcall__ cpeekcolxy(unsigned char x,unsigned char y); -unsigned char __fastcall__ cpeekcol(void); -*/ diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s index 34fbac08b..db120a72f 100644 --- a/libsrc/pce/call.s +++ b/libsrc/pce/call.s @@ -1,19 +1,17 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; CC65 runtime: call function via pointer in ax ; - .export callax + .export callax .code callax: - sta vec - stx vec+1 - jmp (vec) ; jump there + sta vec + stx vec+1 + jmp (vec) ; jump there .bss vec: - .res 2 \ No newline at end of file + .res 2 \ No newline at end of file diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 60096c81d..5f360916c 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -1,17 +1,15 @@ ; -; Ullrich von Bassewitz, 21.09.1998 -; ; clock_t clock (void); ; - .include "pcengine.inc" + .include "pce.inc" - .export _clock + .export _clock .importzp sreg - -.proc _clock - ldy #0 ; Byte 3 is always zero +.proc _clock + + ldy #0 ; Byte 3 is always zero sty sreg+1 sty sreg @@ -20,4 +18,3 @@ rts .endproc - diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 0a2b8b62d..93628ddd8 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" .export _clrscr _clrscr: diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 8d80114fc..0ec35f5b3 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -1,59 +1,57 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); ; unsigned char __fastcall__ bordercolor (unsigned char color); ; - .export _textcolor, _bgcolor, _bordercolor + .export _textcolor, _bgcolor, _bordercolor - .include "pcengine.inc" + .include "pce.inc" _textcolor: - ldx CHARCOLOR ; get old value - sta CHARCOLOR ; set new value - txa - rts + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts _bgcolor: - ldx BGCOLOR ; get old value - sta BGCOLOR ; set new value - asl a - tay + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay - stz VCE_ADDR_LO - stz VCE_ADDR_HI - lda colors,y - sta VCE_DATA_LO - lda colors+1,y - sta VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI - txa - rts + txa + rts _bordercolor: - lda #0 - txa - rts - - .export colors - -colors: ; G R B - .word ((0<<6)+(0<<3)+(0)) ; 0 black - .word ((7<<6)+(7<<3)+(7)) ; 1 white - .word ((0<<6)+(7<<3)+(0)) ; 2 red - .word ((7<<6)+(0<<3)+(7)) ; 3 cyan - .word ((0<<6)+(5<<3)+(7)) ; 4 violett - .word ((7<<6)+(0<<3)+(0)) ; 5 green - .word ((0<<6)+(0<<3)+(7)) ; 6 blue - .word ((7<<6)+(7<<3)+(0)) ; 7 yellow - .word ((5<<6)+(7<<3)+(0)) ; 8 orange - .word ((3<<6)+(4<<3)+(3)) ; 9 brown - .word ((4<<6)+(7<<3)+(4)) ; a light red - .word ((3<<6)+(3<<3)+(3)) ; b dark grey - .word ((4<<6)+(4<<3)+(4)) ; c middle grey - .word ((7<<6)+(4<<3)+(4)) ; d light green - .word ((4<<6)+(4<<3)+(7)) ; e light blue - .word ((6<<6)+(6<<3)+(6)) ; f light gray + lda #0 + txa + rts + + .export colors + +colors: ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray diff --git a/libsrc/pce/condes.s b/libsrc/pce/condes.s index dd7bd30b3..aa28833c2 100644 --- a/libsrc/pce/condes.s +++ b/libsrc/pce/condes.s @@ -94,9 +94,3 @@ getbyt: ;;getbyt_: lda $FFFF,y rts - -;; callax doesnt work? why?! -;_callax: -; sta @l+1 -; stx @l+2 -;@l: jmp $dead diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 0a66cf454..60801e172 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,122 +1,105 @@ - .include "pcengine.inc" - .import vce_init - .import psg_init - .import vdc_init + .include "pce.inc" - .export initconio - .export _conio_init + .import vce_init + .import psg_init + .import vdc_init - .constructor initconio, 24 + .export initconio + .export _conio_init - .macpack longbranch + .constructor initconio, 24 + + .macpack longbranch initconio: - ;; jsr vdc_init - jsr vce_init - jsr psg_init - jsr conio_init - jsr set_palette - - st0 #VDC_RCR - st1 #<$0088 - st2 #>$0088 - rts - - .import colors +;; jsr vdc_init + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette + + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts + + .import colors set_palette: + stz VCE_ADDR_LO + stz VCE_ADDR_HI - ; Make palette (use VGA palette?) - ; stz VCE_ADDR_LO - ; stz VCE_ADDR_HI - ; clx - ; cly - vce_loop: ;; stx VCE_DATA_LO - ;; sty VCE_DATA_HI - ; inx - ; cpx #$00 - ; bne vce_loop - ; iny - ; cpy #$02 - ; bne vce_loop - - - stz VCE_ADDR_LO - stz VCE_ADDR_HI - - ldx #0 + ldx #0 @lp: - .repeat 16 - lda colors,x - sta VCE_DATA_LO - lda colors+1,x - sta VCE_DATA_HI - .endrepeat - - inx - inx - cpx #16*2;*5 - jne @lp - - stz VCE_ADDR_LO - stz VCE_ADDR_HI - stz VCE_DATA_LO - stz VCE_DATA_HI - -; so it will get linked in + .repeat 16 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + .endrepeat + + inx + inx + cpx #16*2 + jne @lp + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI + + ; so it will get linked in _conio_init: - rts + rts ;---------------------------------------------------------------------------- ; ;---------------------------------------------------------------------------- - .importzp ptr1 - + .importzp ptr1 conio_init: - - ; Load font - st0 #VDC_MAWR - st1 #<$2000 - st2 #>$2000 - - ; ptr to font data - lda #font - sta ptr1+1 - - st0 #VDC_VWR ; VWR - ldy #$80 ; 128 chars - charloop: ldx #$08 ; 8 bytes/char - lineloop: - ;;lda [$00] ; read font byte - lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 - - clc ; increment font pointer - lda ptr1 - adc #$01 - sta ptr1 - lda ptr1+1 - adc #$00 - sta ptr1+1 - dex - bne lineloop ; next bitplane 0 byte - ldx #$08 ; fill bitplane 2/3 with 0 - fillloop: st1 #$00 - st2 #$00 - dex - bne fillloop ; next byte - dey - bne charloop ; next character - - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR - - - rts - - .rodata -font: .include "vga.inc" + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 + + ; ptr to font data + lda #font + sta ptr1+1 + + st0 #VDC_VWR ; VWR + ldy #$80 ; 128 chars +charloop: ldx #$08 ; 8 bytes/char +lineloop: + lda (ptr1) + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 + + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 +fillloop: st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character + + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR + + + rts + + .rodata +font: + .include "vga.inc" diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index 8a02a3499..ec63b7565 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -1,81 +1,59 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - .import popa, _gotoxy - .import PLOT - - .importzp tmp3,tmp4 - - .include "pcengine.inc" + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + .importzp tmp3,tmp4 + .include "pce.inc" _cputcxy: - pha ; Save C - jsr popa ; Get Y - jsr _gotoxy ; Set cursor, drop x - pla ; Restore C + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C ; Plot a character - also used as internal function -_cputc: cmp #$0d ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers -L1: cmp #$0a ; LF? - beq newline ; Recalculate pointers +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers ; Printable char of some sort cputdirect: - jsr putchar ; Write the character to the screen + jsr putchar ; Write the character to the screen ; Advance cursor position advance: - ldy CURS_X - iny - cpy #xsize - bne L3 - jsr newline ; new line - ldy #0 ; + cr -L3: sty CURS_X - jmp plot - ;rts + ldy CURS_X + iny + cpy #xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot newline: -; lda #xsize -; clc -; adc SCREEN_PTR -; sta SCREEN_PTR -; bcc L4 -; inc SCREEN_PTR+1 -;; clc -;L4:; lda #xsize - ; adc CRAM_PTR - ; sta CRAM_PTR - ; bcc L5 - ; inc CRAM_PTR+1 -;L5: - - inc CURS_Y - -; jmp plot -; rts + inc CURS_Y ; Set cursor position, calculate RAM pointers -plot: ldy CURS_X - ldx CURS_Y - clc - jmp PLOT ; Set the new cursor +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor @@ -84,34 +62,32 @@ plot: ldy CURS_X putchar: - ora RVS ; Set revers bit + ora RVS ; Set revers bit + + tax - tax + st0 #VDC_MAWR ; Memory Adress Write - st0 #VDC_MAWR ; Memory Adress Write + lda SCREEN_PTR + staio VDC_DATA_LO - lda SCREEN_PTR - staio VDC_DATA_LO + lda SCREEN_PTR+1 + staio VDC_DATA_HI - lda SCREEN_PTR+1 - staio VDC_DATA_HI + st0 #VDC_VWR ; VWR - st0 #VDC_VWR ; VWR + txa + staio VDC_DATA_LO ; character - txa - staio VDC_DATA_LO ; character + lda CHARCOLOR - ;;st2 #$32 ; attrib ?! - lda CHARCOLOR - - ;;lda #2 - asl a - asl a - asl a - asl a + asl a + asl a + asl a + asl a - and #$f0 - ora #$02 - staio VDC_DATA_HI + and #$f0 + ora #$02 + staio VDC_DATA_HI - rts + rts diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index c6c0dabb8..06454998b 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -24,7 +24,7 @@ .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated .import __BSS_SIZE__ - .include "pcengine.inc" + .include "pce.inc" .importzp sp .importzp ptr1,ptr2 @@ -84,10 +84,9 @@ start: sta IRQ_MASK ; Interrupts off stz IRQ_STATUS ; Acknowledge timer - ;; i dont know why the heck this one doesnt - ;; work when called from a constructor :/ - .import vdc_init - jsr vdc_init + ;; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ + .import vdc_init + jsr vdc_init ;; jsr joy_init @@ -167,6 +166,7 @@ start: jsr initlib + ;; FIXME: this should be called from a constructor instead .import initconio jsr initconio diff --git a/libsrc/pce/ctype.s b/libsrc/pce/ctype.s new file mode 100644 index 000000000..fa9a65c8b --- /dev/null +++ b/libsrc/pce/ctype.s @@ -0,0 +1,161 @@ +; +; Stefan Haubenthal with minor changes from Ullrich von Bassewitz, 2003-05-02 +; +; Character specification table. +; + + .include "ctype.inc" + +; The tables are readonly, put them into the rodata segment + +.rodata + +; The following 256 byte wide table specifies attributes for the isxxx type +; of functions. Doing it by a table means some overhead in space, but it +; has major advantages: +; +; * It is fast. If it were'nt for the slow parameter passing of cc65, one +; could even define macros for the isxxx functions (this is usually +; done on other platforms). +; +; * It is highly portable. The only unportable part is the table itself, +; all real code goes into the common library. +; +; * We save some code in the isxxx functions. + + +__ctype: + .repeat 2 + .byte CT_CTRL ; 0/00 ___ctrl_@___ + .byte CT_CTRL ; 1/01 ___ctrl_A___ + .byte CT_CTRL ; 2/02 ___ctrl_B___ + .byte CT_CTRL ; 3/03 ___ctrl_C___ + .byte CT_CTRL ; 4/04 ___ctrl_D___ + .byte CT_CTRL ; 5/05 ___ctrl_E___ + .byte CT_CTRL ; 6/06 ___ctrl_F___ + .byte CT_CTRL ; 7/07 ___ctrl_G___ + .byte CT_CTRL ; 8/08 ___ctrl_H___ + .byte CT_CTRL | CT_OTHER_WS | CT_SPACE_TAB + ; 9/09 ___ctrl_I___ + .byte CT_CTRL | CT_OTHER_WS ; 10/0a ___ctrl_J___ + .byte CT_CTRL | CT_OTHER_WS ; 11/0b ___ctrl_K___ + .byte CT_CTRL | CT_OTHER_WS ; 12/0c ___ctrl_L___ + .byte CT_CTRL | CT_OTHER_WS ; 13/0d ___ctrl_M___ + .byte CT_CTRL ; 14/0e ___ctrl_N___ + .byte CT_CTRL ; 15/0f ___ctrl_O___ + .byte CT_CTRL ; 16/10 ___ctrl_P___ + .byte CT_CTRL ; 17/11 ___ctrl_Q___ + .byte CT_CTRL ; 18/12 ___ctrl_R___ + .byte CT_CTRL ; 19/13 ___ctrl_S___ + .byte CT_CTRL ; 20/14 ___ctrl_T___ + .byte CT_CTRL ; 21/15 ___ctrl_U___ + .byte CT_CTRL ; 22/16 ___ctrl_V___ + .byte CT_CTRL ; 23/17 ___ctrl_W___ + .byte CT_CTRL ; 24/18 ___ctrl_X___ + .byte CT_CTRL ; 25/19 ___ctrl_Y___ + .byte CT_CTRL ; 26/1a ___ctrl_Z___ + .byte CT_CTRL ; 27/1b ___ctrl_[___ + .byte CT_CTRL ; 28/1c ___ctrl_\___ + .byte CT_CTRL ; 29/1d ___ctrl_]___ + .byte CT_CTRL ; 30/1e ___ctrl_^___ + .byte CT_CTRL ; 31/1f ___ctrl_____ + .byte CT_SPACE | CT_SPACE_TAB ; 32/20 ___SPACE___ + .byte CT_NONE ; 33/21 _____!_____ + .byte CT_NONE ; 34/22 _____"_____ + .byte CT_NONE ; 35/23 _____#_____ + .byte CT_NONE ; 36/24 _____$_____ + .byte CT_NONE ; 37/25 _____%_____ + .byte CT_NONE ; 38/26 _____&_____ + .byte CT_NONE ; 39/27 _____'_____ + .byte CT_NONE ; 40/28 _____(_____ + .byte CT_NONE ; 41/29 _____)_____ + .byte CT_NONE ; 42/2a _____*_____ + .byte CT_NONE ; 43/2b _____+_____ + .byte CT_NONE ; 44/2c _____,_____ + .byte CT_NONE ; 45/2d _____-_____ + .byte CT_NONE ; 46/2e _____._____ + .byte CT_NONE ; 47/2f _____/_____ + .byte CT_DIGIT | CT_XDIGIT ; 48/30 _____0_____ + .byte CT_DIGIT | CT_XDIGIT ; 49/31 _____1_____ + .byte CT_DIGIT | CT_XDIGIT ; 50/32 _____2_____ + .byte CT_DIGIT | CT_XDIGIT ; 51/33 _____3_____ + .byte CT_DIGIT | CT_XDIGIT ; 52/34 _____4_____ + .byte CT_DIGIT | CT_XDIGIT ; 53/35 _____5_____ + .byte CT_DIGIT | CT_XDIGIT ; 54/36 _____6_____ + .byte CT_DIGIT | CT_XDIGIT ; 55/37 _____7_____ + .byte CT_DIGIT | CT_XDIGIT ; 56/38 _____8_____ + .byte CT_DIGIT | CT_XDIGIT ; 57/39 _____9_____ + .byte CT_NONE ; 58/3a _____:_____ + .byte CT_NONE ; 59/3b _____;_____ + .byte CT_NONE ; 60/3c _____<_____ + .byte CT_NONE ; 61/3d _____=_____ + .byte CT_NONE ; 62/3e _____>_____ + .byte CT_NONE ; 63/3f _____?_____ + + .byte CT_NONE ; 64/40 _____@_____ + .byte CT_UPPER | CT_XDIGIT ; 65/41 _____A_____ + .byte CT_UPPER | CT_XDIGIT ; 66/42 _____B_____ + .byte CT_UPPER | CT_XDIGIT ; 67/43 _____C_____ + .byte CT_UPPER | CT_XDIGIT ; 68/44 _____D_____ + .byte CT_UPPER | CT_XDIGIT ; 69/45 _____E_____ + .byte CT_UPPER | CT_XDIGIT ; 70/46 _____F_____ + .byte CT_UPPER ; 71/47 _____G_____ + .byte CT_UPPER ; 72/48 _____H_____ + .byte CT_UPPER ; 73/49 _____I_____ + .byte CT_UPPER ; 74/4a _____J_____ + .byte CT_UPPER ; 75/4b _____K_____ + .byte CT_UPPER ; 76/4c _____L_____ + .byte CT_UPPER ; 77/4d _____M_____ + .byte CT_UPPER ; 78/4e _____N_____ + .byte CT_UPPER ; 79/4f _____O_____ + .byte CT_UPPER ; 80/50 _____P_____ + .byte CT_UPPER ; 81/51 _____Q_____ + .byte CT_UPPER ; 82/52 _____R_____ + .byte CT_UPPER ; 83/53 _____S_____ + .byte CT_UPPER ; 84/54 _____T_____ + .byte CT_UPPER ; 85/55 _____U_____ + .byte CT_UPPER ; 86/56 _____V_____ + .byte CT_UPPER ; 87/57 _____W_____ + .byte CT_UPPER ; 88/58 _____X_____ + .byte CT_UPPER ; 89/59 _____Y_____ + .byte CT_UPPER ; 90/5a _____Z_____ + .byte CT_NONE ; 91/5b _____[_____ + .byte CT_NONE ; 92/5c _____\_____ + .byte CT_NONE ; 93/5d _____]_____ + .byte CT_NONE ; 94/5e _____^_____ + .byte CT_NONE ; 95/5f _UNDERLINE_ + .byte CT_NONE ; 96/60 ___grave___ + .byte CT_LOWER | CT_XDIGIT ; 97/61 _____a_____ + .byte CT_LOWER | CT_XDIGIT ; 98/62 _____b_____ + .byte CT_LOWER | CT_XDIGIT ; 99/63 _____c_____ + .byte CT_LOWER | CT_XDIGIT ; 100/64 _____d_____ + .byte CT_LOWER | CT_XDIGIT ; 101/65 _____e_____ + .byte CT_LOWER | CT_XDIGIT ; 102/66 _____f_____ + .byte CT_LOWER ; 103/67 _____g_____ + .byte CT_LOWER ; 104/68 _____h_____ + .byte CT_LOWER ; 105/69 _____i_____ + .byte CT_LOWER ; 106/6a _____j_____ + .byte CT_LOWER ; 107/6b _____k_____ + .byte CT_LOWER ; 108/6c _____l_____ + .byte CT_LOWER ; 109/6d _____m_____ + .byte CT_LOWER ; 110/6e _____n_____ + .byte CT_LOWER ; 111/6f _____o_____ + .byte CT_LOWER ; 112/70 _____p_____ + .byte CT_LOWER ; 113/71 _____q_____ + .byte CT_LOWER ; 114/72 _____r_____ + .byte CT_LOWER ; 115/73 _____s_____ + .byte CT_LOWER ; 116/74 _____t_____ + .byte CT_LOWER ; 117/75 _____u_____ + .byte CT_LOWER ; 118/76 _____v_____ + .byte CT_LOWER ; 119/77 _____w_____ + .byte CT_LOWER ; 120/78 _____x_____ + .byte CT_LOWER ; 121/79 _____y_____ + .byte CT_LOWER ; 122/7a _____z_____ + .byte CT_NONE ; 123/7b _____{_____ + .byte CT_NONE ; 124/7c _____|_____ + .byte CT_NONE ; 125/7d _____}_____ + .byte CT_NONE ; 126/7e _____~_____ + .byte CT_OTHER_WS ; 127/7f ____DEL____ + .endrepeat + + diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index cfb59efe2..24f917cd6 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -1,19 +1,16 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy - .import popa, plot + .export _gotoxy + .import popa, plot - .include "pcengine.inc" + .include "pce.inc" _gotoxy: - - sta CURS_Y ; Set Y - jsr popa ; Get X - sta CURS_X ; Set X - jmp plot ; Set the cursor position + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s new file mode 100644 index 000000000..6bc6bdf57 --- /dev/null +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -0,0 +1,162 @@ + +; +; Standard joystick driver for the PCEngine +; + + .include "joy-kernel.inc" + .include "joy-error.inc" + + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _pce_stdjoy_joy + +; Driver signature + + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number + +; Library reference + + .addr $0000 + +; 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 + .byte $20 ; JOY_RIGHT + .byte $02 ; JOY_FIRE A ; FIXME: is this correct? + .byte $01 ; JOY_FIRE B ; FIXME: is this correct? + .byte $04 ; JOY_START ; FIXME: is this correct? + .byte $08 ; JOY_SELECT ; FIXME: is this correct? + +; Jump table. + + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READJOY + .addr 0 ; IRQ entry unused + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 4 ; Number of joysticks we support + + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #JOY_ERR_OK + +; rts ; Run into DEINSTALL instead + +; ------------------------------------------------------------------------ +; DEINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; +;unsigned char __fastcall__ joy_count (void); + +COUNT: + lda #JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; +;unsigned char __fastcall__ joy_read (unsigned char joystick); + +READJOY: + pha + jsr read_joy + pla + tax ; Joystick number into X + + ; return value from buffer + +joy1: + lda padbuffer,x + ldx #0 + rts + +read_joy: + ; reset multitap counter + lda #$01 + sta $1000 + pha + pla + nop + nop + + lda #$03 + sta $1000 + pha + pla + nop + nop + + cly +nextpad: + lda #$01 + sta $1000 ; sel = 1 + pha + pla + nop + nop + + lda $1000 + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value + + stz $1000 + pha + pla + nop + nop + + lda $1000 + and #$0F + ora padbuffer, y ; second half of new value + + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts + +.bss + +padbuffer: + .res 4 + diff --git a/libsrc/pce/joy_stat_stddrv.s b/libsrc/pce/joy_stat_stddrv.s new file mode 100644 index 000000000..3972569ed --- /dev/null +++ b/libsrc/pce/joy_stat_stddrv.s @@ -0,0 +1,14 @@ +; +; Address of the static standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const void joy_static_stddrv[]; +; + + .export _joy_static_stddrv + .import _pce_stdjoy_joy + +.rodata + +_joy_static_stddrv := _pce_stdjoy_joy diff --git a/libsrc/pce/joy_stddrv.s b/libsrc/pce/joy_stddrv.s new file mode 100644 index 000000000..e0ed6957e --- /dev/null +++ b/libsrc/pce/joy_stddrv.s @@ -0,0 +1,13 @@ +; +; Name of the standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const char joy_stddrv[]; +; + + .export _joy_stddrv + +.rodata + +_joy_stddrv: .asciiz "pce-stdjoy.joy" diff --git a/libsrc/pce/joytokbd.s b/libsrc/pce/joytokbd.s deleted file mode 100644 index 1e8258e08..000000000 --- a/libsrc/pce/joytokbd.s +++ /dev/null @@ -1,275 +0,0 @@ -; -; File generated by cc65 v 2.9.5 -; - .fopt compiler,"cc65 v 2.9.5" - .autoimport on - .case on - .debuginfo off - .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 - .macpack longbranch - .import _joy_masks - .import _joy_read - .import _clock - .export _kbhit - .export _cgetc - -.segment "DATA" - -__lastkey: - .byte $00 -__chardelay: - .dword $00000000 -_rptkey: - .byte $00 - -; --------------------------------------------------------------- -; void _getkey (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc __getkey - -.segment "CODE" - - jsr decsp2 - ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L003F - lda #$00 - jsr _joy_read - ldy #$01 - sta (sp),y - ldx #$00 - lda #$00 - ldy #$00 - sta (sp),y - ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+4 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0010 - ldx #$00 - lda #$0A - ldy #$00 - sta (sp),y - jmp L003A -L0010: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0016 - ldx #$00 - lda #$01 - ldy #$00 - sta (sp),y - jmp L003A -L0016: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+2 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L001C - ldx #$00 - lda #$03 - ldy #$00 - sta (sp),y - jmp L003A -L001C: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+3 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0022 - ldx #$00 - lda #$04 - ldy #$00 - sta (sp),y - jmp L003A -L0022: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+1 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0028 - ldx #$00 - lda #$02 - ldy #$00 - sta (sp),y - jmp L003A -L0028: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+7 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L002E - ldx #$00 - lda #$14 - ldy #$00 - sta (sp),y - jmp L003A -L002E: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+5 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0034 - ldx #$00 - lda #$15 - ldy #$00 - sta (sp),y - jmp L003A -L0034: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+6 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L003A - ldx #$00 - lda #$16 - ldy #$00 - sta (sp),y -L003A: ldy #$00 - ldx #$00 - lda (sp),y - cmp #$00 - jsr boolne - jeq L003F - ldy #$00 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _rptkey - jsr toseqax - jeq L0043 - lda __chardelay+3 - sta sreg+1 - lda __chardelay+2 - sta sreg - ldx __chardelay+1 - lda __chardelay - jsr pusheax - jsr _clock - jsr tosugteax - jeq L0043 - jmp L003F -L0043: ldy #$00 - ldx #$00 - lda (sp),y - sta _rptkey - jsr _clock - ldy #$06 - jsr inceaxy - sta __chardelay - stx __chardelay+1 - ldy sreg - sty __chardelay+2 - ldy sreg+1 - sty __chardelay+3 - ldy #$00 - ldx #$00 - lda (sp),y - sta __lastkey -L003F: jsr incsp2 - rts - -.endproc - -; --------------------------------------------------------------- -; unsigned char __fastcall__ kbhit (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _kbhit - -.segment "CODE" - - jsr __getkey - ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L004E - ldx #$00 - lda #$00 - jmp L0052 - jmp L0052 -L004E: ldx #$00 - lda #$01 - jmp L0052 -L0052: rts - -.endproc - -; --------------------------------------------------------------- -; unsigned char __fastcall__ cgetc (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _cgetc - -.segment "CODE" - - jsr decsp1 -L0056: ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L0057 - jsr __getkey - jmp L0056 -L0057: ldx #$00 - lda __lastkey - ldy #$00 - sta (sp),y - ldx #$00 - lda #$00 - sta __lastkey - ldy #$00 - ldx #$00 - lda (sp),y - jmp L0055 -L0055: jsr incsp1 - rts - -.endproc - diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index f050d78ef..beb151a7b 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -1,41 +1,32 @@ - .export PLOT + .export PLOT - .include "pcengine.inc" + .include "pce.inc" PLOT: + bcs @getpos - bcs @getpos - - tya - clc - adc _plotlo,x - sta SCREEN_PTR - - lda _plothi,x - adc #0 - sta SCREEN_PTR+1 - - ;clc - ;adc _colplot,x - ;sta CRAM_PTR - - ;lda #$23 - ;sta CRAM_PTR+1 + tya + clc + adc _plotlo,x + sta SCREEN_PTR + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 @getpos: - ldx CURS_Y - ldy CURS_X - rts + ldx CURS_Y + ldy CURS_X + rts _plotlo: - .repeat screenrows,line - .byte <($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat _plothi: - .repeat screenrows,line - .byte >($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat diff --git a/libsrc/pce/libref.s b/libsrc/pce/libref.s new file mode 100644 index 000000000..e4afa7eb1 --- /dev/null +++ b/libsrc/pce/libref.s @@ -0,0 +1,8 @@ +; +; Oliver Schmidt, 2013-05-31 +; + + .export joy_libref + .import _exit + +joy_libref := _exit diff --git a/libsrc/pce/pce-stdjoy.s b/libsrc/pce/pce-stdjoy.s deleted file mode 100644 index 60c77db1e..000000000 --- a/libsrc/pce/pce-stdjoy.s +++ /dev/null @@ -1,191 +0,0 @@ - -; -; Standard joystick driver for the PCEngine -; -; Ullrich von Bassewitz, 2002-12-20 -; - - ;;.include "zeropage.inc" - - ;;.include "joy-kernel.inc" - - ;;.include "joy-error.inc" - JOY_ERR_OK=0; - .include "pcengine.inc" - - .macpack generic - -; ------------------------------------------------------------------------ -; Header. Includes jump table - -.segment "CODE" - -; Driver signature - -;; .byte $6A, $6F, $79 ; "joy" -;; .byte $00 ; Driver API version number - -; 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 - .byte $20 ; JOY_RIGHT - .byte $04 ; ? JOY_FIRE - .byte $02 ; ? Future expansion - .byte $01 ; ? Future expansion - .byte $08 ; ? Future expansion - -; Jump table. - -;; .word INSTALL -;; .word DEINSTALL -;; .word COUNT -;; .word READ - -; ------------------------------------------------------------------------ -; Constants - -JOY_COUNT = 4 ; Number of joysticks we support - - -; ------------------------------------------------------------------------ -; Data. - - -.code - - -;extern const char joy_stddrv[]; - - .export _joy_stddrv -_joy_stddrv: - .byte 0 - - - .export _joy_load_driver - .export _joy_unload - -;unsigned char __fastcall__ joy_unload (void); -;unsigned char __fastcall__ joy_load_driver (const char* driver); -_joy_load_driver: -_joy_unload: - -; ------------------------------------------------------------------------ -; INSTALL routine. Is called after the driver is loaded into memory. If -; possible, check if the hardware is present and determine the amount of -; memory available. -; Must return an JOY_ERR_xx code in a/x. -; - -INSTALL: - lda #JOY_ERR_OK - -; rts ; Run into DEINSTALL instead - -; ------------------------------------------------------------------------ -; DEINSTALL routine. Is called before the driver is removed from memory. -; Can do cleanup or whatever. Must not return anything. -; - -DEINSTALL: - rts - - -; ------------------------------------------------------------------------ -; COUNT: Return the total number of available joysticks in a/x. -; -;unsigned char __fastcall__ joy_count (void); - - .export _joy_count - -_joy_count: -COUNT: - lda #JOY_COUNT - rts - -; ------------------------------------------------------------------------ -; READ: Read a particular joystick passed in A. -; -;unsigned char __fastcall__ joy_read (unsigned char joystick); - - .export _joy_read - -_joy_read: -READ: - pha - jsr read_joy - pla - tax ; Joystick number into X - - ; return value from buffer - -joy1: - lda padbuffer,x - ldx #0 - rts - -.code - -read_joy: - ; reset multitap counter - lda #$01 - sta $1000 - pha - pla - nop - nop - - lda #$03 - sta $1000 - pha - pla - nop - nop - - cly -nextpad: - lda #$01 - sta $1000 ; sel = 1 - pha - pla - nop - nop - - lda $1000 - asl a - asl a - asl a - asl a - sta padbuffer, y ; store new value - - stz $1000 - pha - pla - nop - nop - - lda $1000 - and #$0F - ora padbuffer, y ; second half of new value - - eor #$FF - sta padbuffer, y ; store new value - - iny - cpy #$05 - bcc nextpad - rts - -.bss - -padbuffer: - .res 4 - diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index ebf35d952..431f58834 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,29 +1,29 @@ - - .include "pcengine.inc" - .export psg_init + .include "pce.inc" + + .export psg_init psg_init: - clx - stx $0800 ; Select channel + clx + stx $0800 ; Select channel psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control - cly + cly psg_clear_waveform: stz $0806 ; Clear waveform byte - iny - cpy #$20 - bne psg_clear_waveform + iny + cpy #$20 + bne psg_clear_waveform + + inx + cpx #$06 + bne psg_clear_loop + rts - inx - cpx #$06 - bne psg_clear_loop - rts - diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt new file mode 100644 index 000000000..e99b55122 --- /dev/null +++ b/libsrc/pce/readme.txt @@ -0,0 +1,31 @@ + +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 + +revers() is a dummy function, actual reverse output is not supported yet + +waitvblank() 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 + +-------------------------------------------------------------------------------- + +a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) + +run the compiled binary like this: + +> mednafen -force_module pce + +joypad keys are mapped like this: + +w/s/a/d up/down/left/right +numpad 2 (?) button +numpad 3 (?) button +enter (start) button diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index d1358a52b..c39a9f843 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,5 @@ - .export _revers + .export _revers _revers: - lda #0 - rts + lda #0 + rts diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 1f96c062c..461fd1e75 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" .export vce_init diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index 47efdff55..d1ead937e 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" HIRES = 1 diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c deleted file mode 100644 index 6a7bb2341..000000000 --- a/testcode/lib/conio.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include - -void main(void) -{ - clrscr(); -// cprintf("hello world"); - cputs("hello world"); - for(;;); -} \ No newline at end of file diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c new file mode 100644 index 000000000..306eb1ebb --- /dev/null +++ b/testcode/lib/pce/conio.c @@ -0,0 +1,58 @@ + +#include +#include +#include + +static int datavar = 10; + +void main(void) +{ + int stackvar = 42; + int i, j; + + joy_install(&joy_static_stddrv); + + clrscr(); + + cputs("hello world"); + cputsxy(0, 2, "colors:" ); + for (i = 0; i < 16; ++i) { + textcolor(i); + cputc('X'); + } + textcolor(1); + + gotoxy(0,4); + cprintf("datavar: %02x\n\r", datavar); + cprintf("stackvar: %02x\n\r", stackvar); + + j = joy_count(); + gotoxy(0,10); + cprintf("Found %d Joysticks.", j); + + for(;;) + { + gotoxy(13,4); + cprintf("%02x", datavar); + gotoxy(13,5); + cprintf("%02x", stackvar); + ++datavar; ++stackvar; + + gotoxy(0,8); + cprintf("clock: %08x", clock()); + for (i = 0; i < 4; ++i) + { + gotoxy(0, 12 + i); + j = joy_read (i); + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s", + i, j, + (j & joy_masks[JOY_UP])? " up " : " ---- ", + (j & joy_masks[JOY_DOWN])? " down " : " ---- ", + (j & joy_masks[JOY_LEFT])? " left " : " ---- ", + (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", + (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); + } + } + for(;;); +} \ No newline at end of file -- 2.39.5